Skip to contentSkip to conversation

VT-d: fix !HVM build

PATCH In review Jan Beulich 3 participants 4 messages Apr 22, 2022 – May 20, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VT-d: fix !HVM build

EPT is of no interest when !HVM. While I'm observing gcc11 to fully eliminate the function, older gcc's DCE looks to not be as good. Aid the compiler in eliminating the accesses of opt_hap_{2mb,1gb}, which otherwise cause undefined symbol errors when linking.

While there adjust types.

Fixes c479415610f0 ("x86/P2M: p2m.c is HVM-only")
xen/drivers/passthrough/vtd/iommu.c +6 -3
@@ -2155,14 +2155,17 @@ static int cf_check intel_iommu_lookup_p
     return 0;
 }
 
-static int __init vtd_ept_page_compatible(struct vtd_iommu *iommu)
+static bool __init vtd_ept_page_compatible(const struct vtd_iommu *iommu)
 {
-    u64 ept_cap, vtd_cap = iommu->cap;
+    uint64_t ept_cap, vtd_cap = iommu->cap;
+
+    if ( !IS_ENABLED(CONFIG_HVM) )
+        return false;
 
     /* EPT is not initialised yet, so we must check the capability in
      * the MSR explicitly rather than use cpu_has_vmx_ept_*() */
     if ( rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP, ept_cap) != 0 ) 
-        return 0;
+        return false;
 
     return (ept_has_2mb(ept_cap) && opt_hap_2mb) <= cap_sps_2mb(vtd_cap) &&
            (ept_has_1gb(ept_cap) && opt_hap_1gb) <= cap_sps_1gb(vtd_cap);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Jan Beulich

EPT is of no interest when !HVM. While I'm observing gcc11 to fully eliminate the function, older gcc's DCE looks to not be as good. Aid the compiler in eliminating the accesses of opt_hap_{2mb,1gb}, which otherwise cause undefined symbol errors when linking.

I've just reproduced it on GCC 11, using CONFIG_UBSAN as well.

Quoted 6 lines

While there adjust types.

Fixes c479415610f0 ("x86/P2M: p2m.c is HVM-only")

the commit message tweaked.

#2 lore raw

Ping: [PATCH] VT-d: fix !HVM build

In reply to Jan Beulich
Quoted 10 lines · Jan Beulich

EPT is of no interest when !HVM. While I'm observing gcc11 to fully eliminate the function, older gcc's DCE looks to not be as good. Aid the compiler in eliminating the accesses of opt_hap_{2mb,1gb}, which otherwise cause undefined symbol errors when linking.

While there adjust types.

Fixes c479415610f0 ("x86/P2M: p2m.c is HVM-only")

I guess I'll put this in (as being simple enough) if I don't hear anything back by the end of the week.

Jan

Quoted 25 lines
xen/drivers/passthrough/vtd/iommu.c +6 -3
@@ -2155,14 +2155,17 @@ static int cf_check intel_iommu_lookup_p
     return 0;
 }
 
-static int __init vtd_ept_page_compatible(struct vtd_iommu *iommu)
+static bool __init vtd_ept_page_compatible(const struct vtd_iommu *iommu)
 {
-    u64 ept_cap, vtd_cap = iommu->cap;
+    uint64_t ept_cap, vtd_cap = iommu->cap;
+
+    if ( !IS_ENABLED(CONFIG_HVM) )
+        return false;
 
     /* EPT is not initialised yet, so we must check the capability in
      * the MSR explicitly rather than use cpu_has_vmx_ept_*() */
     if ( rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP, ept_cap) != 0 ) 
-        return 0;
+        return false;
 
     return (ept_has_2mb(ept_cap) && opt_hap_2mb) <= cap_sps_2mb(vtd_cap) &&
            (ept_has_1gb(ept_cap) && opt_hap_1gb) <= cap_sps_1gb(vtd_cap);
Reviewed-by
#3 lore raw

RE: Ping: [PATCH] VT-d: fix !HVM build

Quoted 9 lines

From: Jan Beulich <[email protected]>
Sent: Thursday, May 19, 2022 8:20 PM

Quoted 5 lines · Jan Beulich

EPT is of no interest when !HVM. While I'm observing gcc11 to fully eliminate the function, older gcc's DCE looks to not be as good. Aid the compiler in eliminating the accesses of opt_hap_{2mb,1gb}, which otherwise cause undefined symbol errors when linking.

Quoted 8 lines
Quoted 5 lines

While there adjust types.

Fixes c479415610f0 ("x86/P2M: p2m.c is HVM-only")

I guess I'll put this in (as being simple enough) if I don't hear anything back by the end of the week.

Quoted 30 lines

Jan

xen/drivers/passthrough/vtd/iommu.c static int cf_check intel_iommu_lookup_p · line 2158

Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -2155,14 +2155,17 @@ static int cf_check intel_iommu_lookup_p
     return 0;
 }
 
-static int __init vtd_ept_page_compatible(struct vtd_iommu *iommu)
+static bool __init vtd_ept_page_compatible(const struct vtd_iommu

*iommu)

Quoted 4 lines
xen/drivers/passthrough/vtd/iommu.c +2 -1
 {
-    u64 ept_cap, vtd_cap = iommu->cap;
+    uint64_t ept_cap, vtd_cap = iommu->cap;
+

xen/drivers/passthrough/vtd/iommu.c static int cf_check intel_iommu_lookup_p

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +3 -1
+    if ( !IS_ENABLED(CONFIG_HVM) )
+        return false;
 
     /* EPT is not initialised yet, so we must check the capability in
      * the MSR explicitly rather than use cpu_has_vmx_ept_*() */
     if ( rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP, ept_cap) != 0 )
-        return 0;
+        return false;
 
     return (ept_has_2mb(ept_cap) && opt_hap_2mb) <=

cap_sps_2mb(vtd_cap) &&

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +0 -0
            (ept_has_1gb(ept_cap) && opt_hap_1gb) <= cap_sps_1gb(vtd_cap);