Skip to contentSkip to conversation

x86/pv: Fix construction of 32bit dom0's

PATCH In review Wei Liu 3 participants 6 messages Feb 14, 2019

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH v2 1/1 x86/pv: Fix construction of 32bit dom0's

From: Andrew Cooper <[email protected]>

dom0_construct_pv() has logic to transition dom0 into a compat domain when booting an ELF32 image.

One aspect which is missing is the CPUID policy recalculation, meaning that a 32bit dom0 sees a 64bit policy, which differ by the Long Mode feature flag in particular. Another missing item is the x87_fip_width initialisation.

Update dom0_construct_pv() to use switch_compat(), rather than retaining the opencoding. Position the call to switch_compat() such that the compat32 local variable can disappear entirely.

The 32bit monitor table is now created by setup_compat_l4(), avoiding the need to for manual creation later. Furthermore, the L3 table creation is redundant with the logic inside the main mapping loop, so can be dropped as well.

---
v2:
1. Retain ABI-compatibility code and add comment referring to xen.h.
2. Add BUILD_BUG_ON

---
 xen/arch/x86/pv/dom0_build.c | 40 ++++++++++++++--------------------------
 xen/arch/x86/pv/domain.c     |  4 +++-
 2 files changed, 17 insertions(+), 27 deletions(-)
xen/arch/x86/pv/dom0_build.c +14 -26
index 837ef7bca1..cef2d42254 100644
@@ -285,7 +285,7 @@ int __init dom0_construct_pv(struct domain *d,
                              module_t *initrd,
                              char *cmdline)
 {
-    int i, cpu, rc, compatible, compat32, order, machine;
+    int i, cpu, rc, compatible, order, machine;
     struct cpu_user_regs *regs;
     unsigned long pfn, mfn;
     unsigned long nr_pages;
@@ -354,14 +354,18 @@ int __init dom0_construct_pv(struct domain *d,
 
     /* compatibility check */
     compatible = 0;
-    compat32   = 0;
     machine = elf_uval(&elf, elf.ehdr, e_machine);
     printk(" Xen  kernel: 64-bit, lsb, compat32\n");
     if ( elf_32bit(&elf) && parms.pae == XEN_PAE_BIMODAL )
         parms.pae = XEN_PAE_EXTCR3;
     if ( elf_32bit(&elf) && parms.pae && machine == EM_386 )
     {
-        compat32 = 1;
+        if ( unlikely(rc = switch_compat(d)) )
+        {
+            printk("Dom0 failed to switch to compat: %d\n", rc);
+            return rc;
+        }
+
         compatible = 1;
     }
     if (elf_64bit(&elf) && machine == EM_X86_64)
@@ -392,16 +396,6 @@ int __init dom0_construct_pv(struct domain *d,
         }
     }
 
-    if ( compat32 )
-    {
-        d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 1;
-        d->arch.pv.xpti = false;
-        d->arch.pv.pcid = false;
-        v->vcpu_info = (void *)&d->shared_info->compat.vcpu_info[0];
-        if ( setup_compat_arg_xlat(v) != 0 )
-            BUG();
-    }
-
     nr_pages = dom0_compute_nr_pages(d, &parms, initrd_len);
 
     if ( parms.pae == XEN_PAE_EXTCR3 )
@@ -425,8 +419,6 @@ int __init dom0_construct_pv(struct domain *d,
         parms.p2m_base = UNSET_ADDR;
     }
 
-    domain_set_alloc_bitsize(d);
-
     /*
      * Why do we need this? The number of page-table frames depends on the
      * size of the bootstrap address space. But the size of the address space
@@ -606,23 +598,19 @@ int __init dom0_construct_pv(struct domain *d,
     {
         maddr_to_page(mpt_alloc)->u.inuse.type_info = PGT_l4_page_table;
         l4start = l4tab = __va(mpt_alloc); mpt_alloc += PAGE_SIZE;
+        clear_page(l4tab);
+        init_xen_l4_slots(l4tab, _mfn(virt_to_mfn(l4start)),
+                          d, INVALID_MFN, true);
+        v->arch.guest_table = pagetable_from_paddr(__pa(l4start));
     }
     else
     {
-        page = alloc_domheap_page(d, MEMF_no_owner | MEMF_no_scrub);
-        if ( !page )
-            panic("Not enough RAM for domain 0 PML4\n");
-        page->u.inuse.type_info = PGT_l4_page_table|PGT_validated|1;
-        l4start = l4tab = page_to_virt(page);
+        /* Monitor table already created by switch_compat(). */
+        l4start = l4tab = __va(pagetable_get_paddr(v->arch.guest_table));
+        /* See public/xen.h on why the following is needed. */
         maddr_to_page(mpt_alloc)->u.inuse.type_info = PGT_l3_page_table;
         l3start = __va(mpt_alloc); mpt_alloc += PAGE_SIZE;
     }
-    clear_page(l4tab);
-    init_xen_l4_slots(l4tab, _mfn(virt_to_mfn(l4start)),
-                      d, INVALID_MFN, true);
-    v->arch.guest_table = pagetable_from_paddr(__pa(l4start));
-    if ( is_pv_32bit_domain(d) )
-        v->arch.guest_table_user = v->arch.guest_table;
 
     l4tab += l4_table_offset(v_start);
     pfn = alloc_spfn;
xen/arch/x86/pv/domain.c +3 -1
index 7e84b04082..80467691c2 100644
@@ -70,7 +70,7 @@ static int setup_compat_l4(struct vcpu *v)
     l4_pgentry_t *l4tab;
     mfn_t mfn;
 
-    pg = alloc_domheap_page(v->domain, MEMF_no_owner);
+    pg = alloc_domheap_page(v->domain, MEMF_no_owner | MEMF_no_scrub);
     if ( pg == NULL )
         return -ENOMEM;
 
@@ -102,6 +102,8 @@ int switch_compat(struct domain *d)
     struct vcpu *v;
     int rc;
 
+    BUILD_BUG_ON(offsetof(struct shared_info, vcpu_info) != 0);
+
     if ( is_hvm_domain(d) || d->tot_pages != 0 )
         return -EACCES;
     if ( is_pv_32bit_domain(d) )
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 14.02.19 at 12:10, <[email protected]> wrote:

From: Andrew Cooper <[email protected]>

dom0_construct_pv() has logic to transition dom0 into a compat domain when booting an ELF32 image.

One aspect which is missing is the CPUID policy recalculation, meaning that a 32bit dom0 sees a 64bit policy, which differ by the Long Mode feature flag in particular. Another missing item is the x87_fip_width initialisation.

Quoted 7 lines

Update dom0_construct_pv() to use switch_compat(), rather than retaining the opencoding. Position the call to switch_compat() such that the compat32 local variable can disappear entirely.

The 32bit monitor table is now created by setup_compat_l4(), avoiding the need to for manual creation later. Furthermore, the L3 table creation is redundant with the logic inside the main mapping loop, so can be dropped as well.

This last sentence is no longer applicable afaict.

Quoted 2 lines

With that line dropped

Jan

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

author
#2 lore raw
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 14.02.19 at 12:10, <[email protected]> wrote:

From: Andrew Cooper <[email protected]>

dom0_construct_pv() has logic to transition dom0 into a compat domain when booting an ELF32 image.

One aspect which is missing is the CPUID policy recalculation, meaning that a 32bit dom0 sees a 64bit policy, which differ by the Long Mode feature flag in particular. Another missing item is the x87_fip_width initialisation.

Update dom0_construct_pv() to use switch_compat(), rather than retaining the opencoding. Position the call to switch_compat() such that the compat32 local variable can disappear entirely.

Quoted 5 lines
Quoted 3 lines

The 32bit monitor table is now created by setup_compat_l4(), avoiding the need to for manual creation later. Furthermore, the L3 table creation is redundant with the logic inside the main mapping loop, so can be dropped as well.

This last sentence is no longer applicable afaict.

Good catch.

I think the subject line also needs fixing. It should read:

x86/pv: Fix construction of 32bit dom0

i.e. the possessive form is wrong.

Quoted 6 lines
Quoted 3 lines

With that line dropped

Thanks.

Wei.

Quoted 4 lines

Jan

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

#3 lore raw
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 14.02.19 at 12:54, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 14.02.19 at 12:10, <[email protected]> wrote:

From: Andrew Cooper <[email protected]>

dom0_construct_pv() has logic to transition dom0 into a compat domain when booting an ELF32 image.

One aspect which is missing is the CPUID policy recalculation, meaning that a 32bit dom0 sees a 64bit policy, which differ by the Long Mode feature flag in particular. Another missing item is the x87_fip_width initialisation.

Update dom0_construct_pv() to use switch_compat(), rather than retaining the opencoding. Position the call to switch_compat() such that the compat32 local variable can disappear entirely.

Quoted 5 lines
Quoted 3 lines

The 32bit monitor table is now created by setup_compat_l4(), avoiding the need to for manual creation later. Furthermore, the L3 table creation is redundant with the logic inside the main mapping loop, so can be dropped as well.

This last sentence is no longer applicable afaict.

Quoted 7 lines

Good catch.

I think the subject line also needs fixing. It should read:

x86/pv: Fix construction of 32bit dom0

i.e. the possessive form is wrong.

Perhaps. I was under the impression that Andrew meant plural.

Jan

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

#4 lore raw
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 14.02.19 at 12:54, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 14.02.19 at 12:10, <[email protected]> wrote:

From: Andrew Cooper <[email protected]>

dom0_construct_pv() has logic to transition dom0 into a compat domain when booting an ELF32 image.

One aspect which is missing is the CPUID policy recalculation, meaning that a 32bit dom0 sees a 64bit policy, which differ by the Long Mode feature flag in particular. Another missing item is the x87_fip_width initialisation.

Quoted 7 lines

Update dom0_construct_pv() to use switch_compat(), rather than retaining the opencoding. Position the call to switch_compat() such that the compat32 local variable can disappear entirely.

The 32bit monitor table is now created by setup_compat_l4(), avoiding the need to for manual creation later. Furthermore, the L3 table creation is redundant with the logic inside the main mapping loop, so can be dropped as well.

This last sentence is no longer applicable afaict.

Quoted 8 lines
Quoted 7 lines

Good catch.

I think the subject line also needs fixing. It should read:

x86/pv: Fix construction of 32bit dom0

i.e. the possessive form is wrong.

Perhaps. I was under the impression that Andrew meant plural.

I did, because in practice this is "fix running 32bit PV XTF tests when your working on Xen in PVH mode".

~Andrew

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

author
#5 lore raw
Quoted 25 lines · Andrew Cooper
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 14.02.19 at 12:54, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 14.02.19 at 12:10, <[email protected]> wrote:

From: Andrew Cooper <[email protected]>

dom0_construct_pv() has logic to transition dom0 into a compat domain when booting an ELF32 image.

One aspect which is missing is the CPUID policy recalculation, meaning that a 32bit dom0 sees a 64bit policy, which differ by the Long Mode feature flag in particular. Another missing item is the x87_fip_width initialisation.

Quoted 8 lines
Quoted 7 lines

Update dom0_construct_pv() to use switch_compat(), rather than retaining the opencoding. Position the call to switch_compat() such that the compat32 local variable can disappear entirely.

The 32bit monitor table is now created by setup_compat_l4(), avoiding the need to for manual creation later. Furthermore, the L3 table creation is redundant with the logic inside the main mapping loop, so can be dropped as well.

This last sentence is no longer applicable afaict.

Good catch.

I think the subject line also needs fixing. It should read:

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

x86/pv: Fix construction of 32bit dom0

i.e. the possessive form is wrong.

Perhaps. I was under the impression that Andrew meant plural.

I did, because in practice this is "fix running 32bit PV XTF tests when your working on Xen in PVH mode".

Okay, I will leave the subject line as-is.

Wei.

Quoted 2 lines

~Andrew

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