Skip to contentSkip to conversation

x86/pagewalk: Remove opt_allow_superpage check from guest_can_use_l2_superpages()

PATCH In review Andrew Cooper 3 participants 5 messages Jul 25, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/pagewalk: Remove opt_allow_superpage check from guest_can_use_l2_superpages()

The purpose of guest_walk_tables() is to match the behaviour of real hardware.

A PV guest can have 2M superpages in its pagetables, via the M2P and the initial initrd mapping, even if it isn't permitted to create arbitrary 2M superpage mappings.

guest_can_use_l2_superpages() checking opt_allow_superpage is a piece of PV guest policy enforcement, rather than its intended purpose of meaning "would hardware tolerate finding an L2 superpage with these control settings?"

---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/include/asm-x86/guest_pt.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
xen/include/asm-x86/guest_pt.h +7 -5
index 72126d5..08031c8 100644
@@ -205,15 +205,17 @@ static inline guest_l4e_t guest_l4e_from_gfn(gfn_t gfn, u32 flags)
 static inline bool guest_can_use_l2_superpages(const struct vcpu *v)
 {
     /*
+     * PV guests use Xen's paging settings.  Being 4-level, 2M
+     * superpages are unconditionally supported.
+     *
      * The L2 _PAGE_PSE bit must be honoured in HVM guests, whenever
      * CR4.PSE is set or the guest is in PAE or long mode.
      * It's also used in the dummy PT for vcpus with CR0.PG cleared.
      */
-    return (is_pv_vcpu(v)
-            ? opt_allow_superpage
-            : (GUEST_PAGING_LEVELS != 2
-               || !hvm_paging_enabled(v)
-               || (v->arch.hvm_vcpu.guest_cr[4] & X86_CR4_PSE)));
+    return (is_pv_vcpu(v) ||
+            GUEST_PAGING_LEVELS != 2 ||
+            !hvm_paging_enabled(v) ||
+            (v->arch.hvm_vcpu.guest_cr[4] & X86_CR4_PSE));
 }
 
 static inline bool guest_can_use_l3_superpages(const struct domain *d)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Andrew Cooper

The purpose of guest_walk_tables() is to match the behaviour of real hardware.

A PV guest can have 2M superpages in its pagetables, via the M2P and the initial initrd mapping, even if it isn't permitted to create arbitrary 2M superpage mappings.

Can the domain builder (or Xen?) really give a guest superpage mappings for its initrd? Wouldn't that cause problems for live migration?

In any case this patch looks correct: the presence of superpages in PV pagetables is decided by the PV MM rules, so the walker should accept them.

Quoted 44 lines

guest_can_use_l2_superpages() checking opt_allow_superpage is a piece of PV guest policy enforcement, rather than its intended purpose of meaning "would hardware tolerate finding an L2 superpage with these control settings?"

---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/include/asm-x86/guest_pt.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
xen/include/asm-x86/guest_pt.h +7 -5
index 72126d5..08031c8 100644
@@ -205,15 +205,17 @@ static inline guest_l4e_t guest_l4e_from_gfn(gfn_t gfn, u32 flags)
 static inline bool guest_can_use_l2_superpages(const struct vcpu *v)
 {
     /*
+     * PV guests use Xen's paging settings.  Being 4-level, 2M
+     * superpages are unconditionally supported.
+     *
      * The L2 _PAGE_PSE bit must be honoured in HVM guests, whenever
      * CR4.PSE is set or the guest is in PAE or long mode.
      * It's also used in the dummy PT for vcpus with CR0.PG cleared.
      */
-    return (is_pv_vcpu(v)
-            ? opt_allow_superpage
-            : (GUEST_PAGING_LEVELS != 2
-               || !hvm_paging_enabled(v)
-               || (v->arch.hvm_vcpu.guest_cr[4] & X86_CR4_PSE)));
+    return (is_pv_vcpu(v) ||
+            GUEST_PAGING_LEVELS != 2 ||
+            !hvm_paging_enabled(v) ||
+            (v->arch.hvm_vcpu.guest_cr[4] & X86_CR4_PSE));
 }
 
 static inline bool guest_can_use_l3_superpages(const struct domain *d)
Signature · 1 line
2.1.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 11 lines · Tim Deegan
Quoted 5 lines · Andrew Cooper

The purpose of guest_walk_tables() is to match the behaviour of real hardware.

A PV guest can have 2M superpages in its pagetables, via the M2P and the initial initrd mapping, even if it isn't permitted to create arbitrary 2M superpage mappings.

Can the domain builder (or Xen?) really give a guest superpage mappings for its initrd? Wouldn't that cause problems for live migration?

I can see superpage mapping when constructing Dom0 (kernel or initrd, haven't checked).

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
In reply to Tim Deegan
Quoted 9 lines · Tim Deegan
Quoted 5 lines · Andrew Cooper

The purpose of guest_walk_tables() is to match the behaviour of real hardware.

A PV guest can have 2M superpages in its pagetables, via the M2P and the initial initrd mapping, even if it isn't permitted to create arbitrary 2M superpage mappings.

Can the domain builder (or Xen?) really give a guest superpage mappings for its initrd? Wouldn't that cause problems for live migration?

From Wei's work, dom0 definitely ends up calling put_page_type() on a L2 superpage.

Looking at the dom0 construction code more closely, it appears that Xen creates the initial p2m in the guest using superpages.

I will s/initrd/initial p2m/ in the commit message. I don't believe the domain builder has any way of creating such mappings for a domU, so the migration aspect is less important.

Quoted 5 lines

In any case this patch looks correct: the presence of superpages in PV pagetables is decided by the PV MM rules, so the walker should accept them.

Thanks.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#4 lore raw
In reply to Andrew Cooper
Quoted 11 lines · Andrew Cooper

The purpose of guest_walk_tables() is to match the behaviour of real hardware.

A PV guest can have 2M superpages in its pagetables, via the M2P and the initial initrd mapping, even if it isn't permitted to create arbitrary 2M superpage mappings.

guest_can_use_l2_superpages() checking opt_allow_superpage is a piece of PV guest policy enforcement, rather than its intended purpose of meaning "would hardware tolerate finding an L2 superpage with these control settings?"

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel