[PATCH v3] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped

Stefano Stabellini posted 1 patch 3 years, 1 month ago
Test gitlab-ci failed
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20210312231632.5666-1-sstabellini@kernel.org
xen/common/kernel.c           |  4 ++++
xen/include/public/features.h | 14 ++++++++++++++
2 files changed, 18 insertions(+)
[PATCH v3] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
Posted by Stefano Stabellini 3 years, 1 month ago
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 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(+)

diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 7a345ae45e..d77756a81e 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 ( !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;
diff --git a/xen/include/public/features.h b/xen/include/public/features.h
index 1613b2aab8..9ee2f760ef 100644
--- a/xen/include/public/features.h
+++ b/xen/include/public/features.h
@@ -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__ */
-- 
2.17.1


Re: [PATCH v3] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
Posted by Julien Grall 3 years, 1 month ago
Hi Stefano,

On 12/03/2021 23:16, 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: Julien Grall <jgrall@amazon.com>

Cheers,

-- 
Julien Grall

Re: [PATCH v3] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
Posted by Jan Beulich 3 years, 1 month ago
On 13.03.2021 00:16, 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

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

Jan

Re: [PATCH v3] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
Posted by Stefano Stabellini 3 years, 1 month ago
On Mon, 15 Mar 2021, Jan Beulich wrote:
> On 13.03.2021 00:16, 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
> 
> 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.

Re: [PATCH v3] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
Posted by Jan Beulich 3 years, 1 month ago
On 15.03.2021 21:01, Stefano Stabellini wrote:
> On Mon, 15 Mar 2021, Jan Beulich wrote:
>> On 13.03.2021 00:16, 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
>>
>> 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

Re: [PATCH v3] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
Posted by Stefano Stabellini 3 years, 1 month ago
On Tue, 16 Mar 2021, Jan Beulich wrote:
> On 15.03.2021 21:01, Stefano Stabellini wrote:
> > On Mon, 15 Mar 2021, Jan Beulich wrote:
> >> On 13.03.2021 00:16, 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
> >>
> >> 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.

Re: [PATCH v3] xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped
Posted by Julien Grall 3 years, 1 month ago
Hi Stefano,

On 17/03/2021 00:04, Stefano Stabellini wrote:
> On Tue, 16 Mar 2021, Jan Beulich wrote:
>> On 15.03.2021 21:01, Stefano Stabellini wrote:
>>> On Mon, 15 Mar 2021, Jan Beulich wrote:
>>>> On 13.03.2021 00:16, 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
>>>>
>>>> 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.

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

Cheers,

-- 
Julien Grall