Skip to contentSkip to conversation

xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped

PATCH Superseded Stefano Stabellini 3 participants 7 messages Mar 12, 2021 – Mar 17, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped

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

---
Changes in v3:
- swap 2 conditions of ||
- improve in-code comment to cover existing assumptions

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 | 14 ++++++++++++++
 2 files changed, 18 insertions(+)
xen/common/kernel.c +4 -0
index 7a345ae45e..d77756a81e 100644
@@ -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 ( !paging_mode_translate(d) || is_domain_direct_mapped(d) )
+                fi.submap |= (1U << XENFEAT_direct_mapped);
+            else
+                fi.submap |= (1U << XENFEAT_not_direct_mapped);
             break;
         default:
             return -EINVAL;
xen/include/public/features.h +14 -0
index 1613b2aab8..9ee2f760ef 100644
@@ -114,6 +114,20 @@
  */
 #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.
+ *
+ * If neither flag is set (e.g. older Xen releases) the assumptions are:
+ * - not auto_translated domains (x86 only) are always direct-mapped
+ * - on x86, auto_translated domains are not direct-mapped
+ * - on ARM, Dom0 is direct-mapped, DomUs are not
+ */
+#define XENFEAT_not_direct_mapped         16
+#define XENFEAT_direct_mapped             17
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1
#1 lore raw

Hi Stefano,

Quoted 9 lines · Stefano Stabellini

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.

Quoted 8 lines

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

Cheers,

Signature · 1 line
Julien Grall
#2 lore raw
In reply to Stefano Stabellini
Quoted 16 lines · Stefano Stabellini

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

Quoted 4 lines

Any particular reason my previously given R-b isn't here?

Jan

#3 lore raw
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Stefano Stabellini

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

Quoted 6 lines
Quoted 4 lines

Any particular reason my previously given R-b isn't here?

Hi Jan,

I reworded part of the comment in the public header, and I decided to err on the side of caution and not add your R-b given this change compared to the previous version.

#4 lore raw
Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Stefano Stabellini

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

Quoted 5 lines
Quoted 1 line

Any particular reason my previously given R-b isn't here?

I reworded part of the comment in the public header, and I decided to err on the side of caution and not add your R-b given this change compared to the previous version.

I see. FAOD, despite me not being overly happy with the "older Xen assumptions" part of the comment, feel free to add it back.

Jan

#5 lore raw
Quoted 24 lines · Jan Beulich
Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Stefano Stabellini

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

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Any particular reason my previously given R-b isn't here?

I reworded part of the comment in the public header, and I decided to err on the side of caution and not add your R-b given this change compared to the previous version.

I see. FAOD, despite me not being overly happy with the "older Xen assumptions" part of the comment, feel free to add it back.

Thank you!

Julien, please go ahead and commit it to your for-next/4.16 branch when it is convenient.

#6 lore raw

Hi Stefano,

Quoted 31 lines · Stefano Stabellini
Quoted 30 lines · Jan Beulich
Quoted 28 lines · Stefano Stabellini
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Stefano Stabellini

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

Quoted 6 lines
Quoted 4 lines

Any particular reason my previously given R-b isn't here?

I reworded part of the comment in the public header, and I decided to err on the side of caution and not add your R-b given this change compared to the previous version.

Quoted 7 lines
Quoted 2 lines

I see. FAOD, despite me not being overly happy with the "older Xen assumptions" part of the comment, feel free to add it back.

Thank you!

Julien, please go ahead and commit it to your for-next/4.16 branch when it is convenient.

I have committed it to my for-next/4.16 branch. I will merge the branch after the tree has re-opened.

Cheers,

Signature · 1 line
Julien Grall