xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
@ 2021-02-26 22:52 Stefano Stabellini
  2021-03-01  9:10 ` Jan Beulich
  2021-03-01  9:26 ` Julien Grall
  0 siblings, 2 replies; 3+ messages in thread
From: Stefano Stabellini @ 2021-02-26 22:52 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, Stefano Stabellini, jbeulich, andrew.cooper3, julien

Introduce two feature flags to tell the domain whether it is
direct-mapped or not. It allows the guest kernel to make informed
decisions on things such as swiotlb-xen enablement.

The introduction of both flags (XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped) allows the guest kernel to avoid any
guesswork if one of the two is present, or fallback to the current
checks if neither of them is present.

XENFEAT_direct_mapped is always set for not auto-translated guests.

For auto-translated guests, only Dom0 on ARM is direct-mapped. Also,
see is_domain_direct_mapped() which refers to auto-translated guests:
xen/include/asm-arm/domain.h:is_domain_direct_mapped
xen/include/asm-x86/domain.h:is_domain_direct_mapped

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
CC: jbeulich@suse.com
CC: andrew.cooper3@citrix.com
CC: julien@xen.org
---
Changes in v2:
- code style improvements
- better comments
- better commit message
- not auto_translated domains are direct_mapped
---
 xen/common/kernel.c           |  4 ++++
 xen/include/public/features.h | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 7a345ae45e..431447326c 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -560,6 +560,10 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
                              (1U << XENFEAT_hvm_callback_vector) |
                              (has_pirq(d) ? (1U << XENFEAT_hvm_pirqs) : 0);
 #endif
+            if ( is_domain_direct_mapped(d) || !paging_mode_translate(d) )
+                fi.submap |= (1U << XENFEAT_direct_mapped);
+            else
+                fi.submap |= (1U << XENFEAT_not_direct_mapped);
             break;
         default:
             return -EINVAL;
diff --git a/xen/include/public/features.h b/xen/include/public/features.h
index 1613b2aab8..4aebfd359a 100644
--- a/xen/include/public/features.h
+++ b/xen/include/public/features.h
@@ -114,6 +114,18 @@
  */
 #define XENFEAT_linux_rsdp_unrestricted   15
 
+/*
+ * A direct-mapped (or 1:1 mapped) domain is a domain for which its
+ * local pages have gfn == mfn. If a domain is direct-mapped,
+ * XENFEAT_direct_mapped is set; otherwise XENFEAT_not_direct_mapped
+ * is set.
+ *
+ * Not auto_translated domains are always direct-mapped. Also see
+ * XENFEAT_auto_translated_physmap.
+ */
+#define XENFEAT_not_direct_mapped         16
+#define XENFEAT_direct_mapped             17
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
  2021-02-26 22:52 [PATCH v2] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped Stefano Stabellini
@ 2021-03-01  9:10 ` Jan Beulich
  2021-03-01  9:26 ` Julien Grall
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2021-03-01  9:10 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: Stefano Stabellini, andrew.cooper3, julien, xen-devel

On 26.02.2021 23:52, Stefano Stabellini wrote:
> Introduce two feature flags to tell the domain whether it is
> direct-mapped or not. It allows the guest kernel to make informed
> decisions on things such as swiotlb-xen enablement.
> 
> The introduction of both flags (XENFEAT_direct_mapped and
> XENFEAT_not_direct_mapped) allows the guest kernel to avoid any
> guesswork if one of the two is present, or fallback to the current
> checks if neither of them is present.
> 
> XENFEAT_direct_mapped is always set for not auto-translated guests.
> 
> For auto-translated guests, only Dom0 on ARM is direct-mapped. Also,
> see is_domain_direct_mapped() which refers to auto-translated guests:
> xen/include/asm-arm/domain.h:is_domain_direct_mapped
> xen/include/asm-x86/domain.h:is_domain_direct_mapped
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
preferably with one cosmetic aspect taken care of:

> --- a/xen/common/kernel.c
> +++ b/xen/common/kernel.c
> @@ -560,6 +560,10 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
>                               (1U << XENFEAT_hvm_callback_vector) |
>                               (has_pirq(d) ? (1U << XENFEAT_hvm_pirqs) : 0);
>  #endif
> +            if ( is_domain_direct_mapped(d) || !paging_mode_translate(d) )

While I realize the left side of the || is what you're after,
I'd generally see the more common/universal/whatever-you-want-
to-call-it condition be checked first, and the most special
purpose one last. IOW I'd prefer if both side of the || could
be swapped.

Jan


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
  2021-02-26 22:52 [PATCH v2] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped Stefano Stabellini
  2021-03-01  9:10 ` Jan Beulich
@ 2021-03-01  9:26 ` Julien Grall
  1 sibling, 0 replies; 3+ messages in thread
From: Julien Grall @ 2021-03-01  9:26 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel
  Cc: Stefano Stabellini, jbeulich, andrew.cooper3

Hi Stefano,

On 26/02/2021 22:52, Stefano Stabellini wrote:
> Introduce two feature flags to tell the domain whether it is
> direct-mapped or not. It allows the guest kernel to make informed
> decisions on things such as swiotlb-xen enablement.
> 
> The introduction of both flags (XENFEAT_direct_mapped and
> XENFEAT_not_direct_mapped) allows the guest kernel to avoid any
> guesswork if one of the two is present, or fallback to the current
> checks if neither of them is present.
> 
> XENFEAT_direct_mapped is always set for not auto-translated guests.
> 
> For auto-translated guests, only Dom0 on ARM is direct-mapped. Also,
> see is_domain_direct_mapped() which refers to auto-translated guests:
> xen/include/asm-arm/domain.h:is_domain_direct_mapped
> xen/include/asm-x86/domain.h:is_domain_direct_mapped
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
> CC: jbeulich@suse.com
> CC: andrew.cooper3@citrix.com
> CC: julien@xen.org
> ---
> Changes in v2:
> - code style improvements
> - better comments
> - better commit message
> - not auto_translated domains are direct_mapped
> ---
>   xen/common/kernel.c           |  4 ++++
>   xen/include/public/features.h | 12 ++++++++++++
>   2 files changed, 16 insertions(+)
> 
> diff --git a/xen/common/kernel.c b/xen/common/kernel.c
> index 7a345ae45e..431447326c 100644
> --- a/xen/common/kernel.c
> +++ b/xen/common/kernel.c
> @@ -560,6 +560,10 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
>                                (1U << XENFEAT_hvm_callback_vector) |
>                                (has_pirq(d) ? (1U << XENFEAT_hvm_pirqs) : 0);
>   #endif
> +            if ( is_domain_direct_mapped(d) || !paging_mode_translate(d) )
> +                fi.submap |= (1U << XENFEAT_direct_mapped);
> +            else
> +                fi.submap |= (1U << XENFEAT_not_direct_mapped);
>               break;
>           default:
>               return -EINVAL;
> diff --git a/xen/include/public/features.h b/xen/include/public/features.h
> index 1613b2aab8..4aebfd359a 100644
> --- a/xen/include/public/features.h
> +++ b/xen/include/public/features.h
> @@ -114,6 +114,18 @@
>    */
>   #define XENFEAT_linux_rsdp_unrestricted   15
>   
> +/*
> + * A direct-mapped (or 1:1 mapped) domain is a domain for which its
> + * local pages have gfn == mfn. If a domain is direct-mapped,
> + * XENFEAT_direct_mapped is set; otherwise XENFEAT_not_direct_mapped
> + * is set.

An OS developper may interpret it as there will always be one of the two 
flags set. However, this will not be the case for existing Xen release.

In addion to that, in the past, we removed support for some XENFEAT_* 
because they were broken. Although, it is unlikely the case here.

Therefore, I think we want to explain that it may be possible to have 
neither of the two flags set and what to do.

Cheers,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-01  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26 22:52 [PATCH v2] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped Stefano Stabellini
2021-03-01  9:10 ` Jan Beulich
2021-03-01  9:26 ` Julien Grall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).