Skip to contentSkip to conversation

x86/paging: restrict physical address width reported to guests

PATCH In review Jan Beulich 2 participants 4 messages Sep 29, 2021 – Oct 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/paging: restrict physical address width reported to guests

Modern hardware may report more than 48 bits of physical address width. For paging-external guests our P2M implementation does not cope with larger values. Telling the guest of more available bits means misleading it into perhaps trying to actually put some page there (like was e.g. intermediately done in OVMF for the shared info page).

While there also convert the PV check to a paging-external one (which in our current code base are synonyms of one another anyway).

Fixes 5dbd60e16a1f ("x86/shadow: Correct guest behaviour when creating PTEs above maxphysaddr")
xen/include/asm-x86/paging.h +11 -4
@@ -401,11 +401,18 @@ static always_inline unsigned int paging
 {
     unsigned int bits = paging_mode_hap(d) ? hap_paddr_bits : paddr_bits;
 
-    if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) &&
-         !is_pv_domain(d) )
+    if ( paging_mode_external(d) )
     {
-        /* Shadowed superpages store GFNs in 32-bit page_info fields. */
-        bits = min(bits, 32U + PAGE_SHIFT);
+        if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) )
+        {
+            /* Shadowed superpages store GFNs in 32-bit page_info fields. */
+            bits = min(bits, 32U + PAGE_SHIFT);
+        }
+        else
+        {
+            /* Both p2m-ept and p2m-pt only support 4-level page tables. */
+            bits = min(bits, 48U);
+        }
     }
 
     return bits;
#1 lore raw

Ping: [PATCH] x86/paging: restrict physical address width reported to guests

Quoted 11 lines · Jan Beulich

Modern hardware may report more than 48 bits of physical address width. For paging-external guests our P2M implementation does not cope with larger values. Telling the guest of more available bits means misleading it into perhaps trying to actually put some page there (like was e.g. intermediately done in OVMF for the shared info page).

While there also convert the PV check to a paging-external one (which in our current code base are synonyms of one another anyway).

Fixes 5dbd60e16a1f ("x86/shadow: Correct guest behaviour when creating PTEs above maxphysaddr")

Anyone?

Thanks, Jan

Quoted 27 lines
xen/include/asm-x86/paging.h +11 -4
@@ -401,11 +401,18 @@ static always_inline unsigned int paging
 {
     unsigned int bits = paging_mode_hap(d) ? hap_paddr_bits : paddr_bits;
 
-    if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) &&
-         !is_pv_domain(d) )
+    if ( paging_mode_external(d) )
     {
-        /* Shadowed superpages store GFNs in 32-bit page_info fields. */
-        bits = min(bits, 32U + PAGE_SHIFT);
+        if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) )
+        {
+            /* Shadowed superpages store GFNs in 32-bit page_info fields. */
+            bits = min(bits, 32U + PAGE_SHIFT);
+        }
+        else
+        {
+            /* Both p2m-ept and p2m-pt only support 4-level page tables. */
+            bits = min(bits, 48U);
+        }
     }
 
     return bits;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jan Beulich
Quoted 11 lines · Jan Beulich

Modern hardware may report more than 48 bits of physical address width. For paging-external guests our P2M implementation does not cope with larger values. Telling the guest of more available bits means misleading it into perhaps trying to actually put some page there (like was e.g. intermediately done in OVMF for the shared info page).

While there also convert the PV check to a paging-external one (which in our current code base are synonyms of one another anyway).

Fixes 5dbd60e16a1f ("x86/shadow: Correct guest behaviour when creating PTEs above maxphysaddr")
Quoted 12 lines
xen/include/asm-x86/paging.h +1 -3
@@ -401,11 +401,18 @@ static always_inline unsigned int paging
 {
     unsigned int bits = paging_mode_hap(d) ? hap_paddr_bits : paddr_bits;
 
-    if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) &&
-         !is_pv_domain(d) )
+    if ( paging_mode_external(d) )
     {
-        /* Shadowed superpages store GFNs in 32-bit page_info fields. */

xen/include/asm-x86/paging.h static always_inline unsigned int paging · line 414

Quoted 10 lines
xen/include/asm-x86/paging.h +9 -1
-        bits = min(bits, 32U + PAGE_SHIFT);
+        if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) )
+        {
+            /* Shadowed superpages store GFNs in 32-bit page_info fields. */
+            bits = min(bits, 32U + PAGE_SHIFT);
+        }
+        else
+        {
+            /* Both p2m-ept and p2m-pt only support 4-level page tables. */
+            bits = min(bits, 48U);

It would be nice if there was a way to not have to manually change the values here if we ever support 5-level page tables for example, but I don't know of any way.

Thanks, Roger.

#3 lore raw
Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Jan Beulich

Modern hardware may report more than 48 bits of physical address width. For paging-external guests our P2M implementation does not cope with larger values. Telling the guest of more available bits means misleading it into perhaps trying to actually put some page there (like was e.g. intermediately done in OVMF for the shared info page).

Quoted 7 lines
Quoted 5 lines

While there also convert the PV check to a paging-external one (which in our current code base are synonyms of one another anyway).

Fixes 5dbd60e16a1f ("x86/shadow: Correct guest behaviour when creating PTEs above maxphysaddr")

Thanks.

Quoted 17 lines
Quoted 17 lines
xen/include/asm-x86/paging.h +6 -4
@@ -401,11 +401,18 @@ static always_inline unsigned int paging
 {
     unsigned int bits = paging_mode_hap(d) ? hap_paddr_bits : paddr_bits;
 
-    if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) &&
-         !is_pv_domain(d) )
+    if ( paging_mode_external(d) )
     {
-        /* Shadowed superpages store GFNs in 32-bit page_info fields. */
-        bits = min(bits, 32U + PAGE_SHIFT);
+        if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) )
+        {
+            /* Shadowed superpages store GFNs in 32-bit page_info fields. */
+            bits = min(bits, 32U + PAGE_SHIFT);
+        }
Quoted 8 lines

xen/include/asm-x86/paging.h static always_inline unsigned int paging · line 414

Quoted 4 lines
xen/include/asm-x86/paging.h +4 -0
+        else
+        {
+            /* Both p2m-ept and p2m-pt only support 4-level page tables. */
+            bits = min(bits, 48U);

It would be nice if there was a way to not have to manually change the values here if we ever support 5-level page tables for example, but I don't know of any way.

Well, I have a vague plan, along the lines of "IOMMU: have vendor code announce supported page sizes": Once the value isn't constant anymore, vendor code needs to supply it.

Jan