x86/PVH: Dom0 building adjustments
cover x86/PVH: Dom0 building adjustments
The code building PVH Dom0 made use of sequences of P2M changes which are disallowed as of XSA-378. First of all population of the first Mb of memory needs to be redone. Then, largely as a workaround, checking introduced by XSA-378 needs to be slightly relaxed.
Note that with these adjustments I get Dom0 to start booting on my development system, but the Dom0 kernel then gets stuck. Since it was the first time for me to try PVH Dom0 in this context (see below for why I was hesitant), I cannot tell yet whether this is due further fallout from the XSA, or some further unrelated problem. Dom0's BSP is in VPF_blocked state while all APs are still in VPF_down. The 'd' debug key, unhelpfully, doesn't produce any output, so it's non-trivial to check whether (like PV likes to do) Dom0 has panic()ed without leaving any (visible) output.
[And there was another rather basic issue to fight first (patch
will be submitted separately): vPCI wasn't aware of hidden PCI devices, hitting an ASSERT(). Obviously I couldn't afford not having a functioning serial console.]
In the course I ran into an oom condition while populating Dom0's RAM. Hence next some re-work of dom0_compute_nr_pages(). In turn in the course of putting that together I did notice that PV Dom0, when run in shadow mode, wouldn't have its shadow allocation properly set.
1: PVH: de-duplicate mappings for first Mb of Dom0 memory 2: P2M: relax guarding of MMIO entries
3: PVH: improve Dom0 memory size calculation
4: PV: properly set shadow allocation for Dom0
Jan
PATCH 1/4 x86/PVH: de-duplicate mappings for first Mb of Dom0 memory
One of the changes comprising the fixes for XSA-378 disallows replacing MMIO mappings by unintended (for this purpose) code paths. This means we need to be more careful about the mappings put in place in this range - mappings should be created exactly once:
- iommu_hwdom_init() comes first; it should avoid the first Mb,
- pvh_populate_p2m() should insert identity mappings only into ranges not populated as RAM,
- pvh_setup_acpi() should again avoid the first Mb, which was already dealt with at that point.
---
Note: Conflicts with the previously submitted "IOMMU/x86: perform PV
Dom0 mappings in batches".
xen/arch/x86/hvm/dom0_build.c +28 -11
@@ -430,17 +430,6 @@ static int __init pvh_populate_p2m(strucint rc;#define MB1_PAGES PFN_DOWN(MB(1)) -/* -* Memory below 1MB is identity mapped initially. RAM regions are -* populated and copied below, replacing the respective mappings. -*/ - rc =modify_identity_mmio (d,0 ,MB1_PAGES , true); -if ( rc ) - { -printk ("Failed to identity map low 1MB: %d\n" , rc); -return rc; - } -/* Populate memory map. */ for ( i =0 ; i < d->arch.nr_e820; i++ ) {
@@ -472,6 +461,23 @@ static int __init pvh_populate_p2m(struc } } +/* Non-RAM regions of space below 1MB get identity mapped. */ +for ( i = rc =0 ; i <MB1_PAGES ; ++i ) + { +p2m_type_t p2mt; + +if (mfn_eq (get_gfn_query (d, i, &p2mt),INVALID_MFN ) ) + rc =set_mmio_p2m_entry (d,_gfn (i),_mfn (i),PAGE_ORDER_4K ); +else +ASSERT (p2mt == p2m_ram_rw); +put_gfn (d, i); +if ( rc ) + { +printk ("Failed to identity map PFN %x: %d\n" , i, rc); +return rc; + } + } +if ( cpu_has_vmx &&paging_mode_hap (d) && !vmx_unrestricted_guest (v) ) {/*
@@ -1095,6 +1101,17 @@ static int __init pvh_setup_acpi(struct nr_pages =PFN_UP ((d->arch.e820[i].addr & ~PAGE_MASK ) + d->arch.e820[i].size); +/* Memory below 1MB has been dealt with by pvh_populate_p2m(). */ +if ( pfn <PFN_DOWN (MB (1 )) ) + { +if ( pfn + nr_pages <=PFN_DOWN (MB (1 )) ) +continue ; + +/* This shouldn't happen, but is easy to deal with. */ + nr_pages -=PFN_DOWN (MB (1 )) - pfn; + pfn =PFN_DOWN (MB (1 )); + } + rc =modify_identity_mmio (d, pfn, nr_pages, true);if ( rc ) {
xen/drivers/passthrough/x86/iommu.c +7 -1
@@ -337,7 +337,13 @@ void __hwdom_init arch_iommu_hwdom_init( max_pfn = (GB (4 ) >>PAGE_SHIFT ) -1 ; top =max (max_pdx,pfn_to_pdx (max_pfn) +1 ); -for ( i =0 ; i < top; i++ ) +/* +* First Mb will get mapped in one go by pvh_populate_p2m(). Avoid +* setting up potentially conflicting mappings here. +*/ + i =paging_mode_translate (d) ?PFN_DOWN (MB (1 )) :0 ; + +for ( ; i < top; i++ ) {unsigned long pfn =pdx_to_pfn (i);int rc;
Re: [PATCH 1/4] x86/PVH: de-duplicate mappings for first Mb of Dom0 memory
Quoted 2 lines · Jan Beulich
One of the changes comprising the fixes for XSA-378 disallows replacing MMIO mappings by unintended (for this purpose) code paths.
I'd drop the brackets. All it does is confuse the sentence.
Quoted 8 lines
This means we
need to be more careful about the mappings put in place in this range - mappings should be created exactly once:
-iommu_hwdom_init()comes first; it should avoid the first Mb,
-pvh_populate_p2m()should insert identity mappings only into ranges not populated as RAM,
-pvh_setup_acpi()should again avoid the first Mb, which was already dealt with at that point.
This really is a mess. It also seems very fragile.
Why is iommu_hwdom_init() separate in the first place? It only does mappings up to 4G in the first place, and with this change, it is now [1M-4G)
All IOMMU modifications should be as a side effect of regular p2m/guest physmap operations. I suppose this is another breakage from the PV side of things.
xen/arch/x86/hvm/dom0_build.c static int __init pvh_setup_acpi(struct · line 1110
Quoted 11 lines
xen/arch/x86/hvm/dom0_build.c +7
-0@@ -1095,6 +1101,17 @@ static int __init pvh_setup_acpi(struct nr_pages =PFN_UP ((d->arch.e820[i].addr & ~PAGE_MASK ) + d->arch.e820[i].size); +/* Memory below 1MB has been dealt with by pvh_populate_p2m(). */ +if ( pfn <PFN_DOWN (MB (1 )) ) + { +if ( pfn + nr_pages <=PFN_DOWN (MB (1 )) ) +continue ; + +/* This shouldn't happen, but is easy to deal with. */
I'm not sure this comment is helpful.
Under PVH, there is nothing special about the 1M boundary, and we can reasonably have something else here or crossing the boundary.
Preferably with this removed, Acked-by: Andrew Cooper <[email protected]>, but only because this is an emergency fix. I really don't think it is an improvement to the logic.
~Andrew
Re: [PATCH 1/4] x86/PVH: de-duplicate mappings for first Mb of Dom0 memory
Quoted 15 lines · Andrew Cooper
Quoted 2 lines · Jan Beulich
One of the changes comprising the fixes for XSA-378 disallows replacing MMIO mappings by unintended (for this purpose) code paths.
I'd drop the brackets. All it does is confuse the sentence.
Quoted 8 lines
This means we
need to be more careful about the mappings put in place in this range - mappings should be created exactly once:
-iommu_hwdom_init()comes first; it should avoid the first Mb,
-pvh_populate_p2m()should insert identity mappings only into ranges not populated as RAM,
-pvh_setup_acpi()should again avoid the first Mb, which was already dealt with at that point.
Quoted 1 line
This really is a mess. It also seems very fragile.
So it seems to me.
Quoted 3 lines
Why is
iommu_hwdom_init()separate in the first place? It only does mappings up to 4G in the first place, and with this change, it is now [1M-4G)
I guess we'll want to wait for Roger to return to shed some light on this.
Quoted 14 lines
xen/arch/x86/hvm/dom0_build.c static int __init pvh_setup_acpi(struct · line 1110
Quoted 11 lines
xen/arch/x86/hvm/dom0_build.c +7
-0@@ -1095,6 +1101,17 @@ static int __init pvh_setup_acpi(struct nr_pages =PFN_UP ((d->arch.e820[i].addr & ~PAGE_MASK ) + d->arch.e820[i].size); +/* Memory below 1MB has been dealt with by pvh_populate_p2m(). */ +if ( pfn <PFN_DOWN (MB (1 )) ) + { +if ( pfn + nr_pages <=PFN_DOWN (MB (1 )) ) +continue ; + +/* This shouldn't happen, but is easy to deal with. */ I'm not sure this comment is helpful.
Quoted 2 lines
Under PVH, there is nothing special about the 1M boundary, and we can reasonably have something else here or crossing the boundary.
As long as we have this special treatment of the low Mb, the boundary is meaningful imo. I'd see the comment go away when the handling in general gets streamlined.
Quoted 2 lines
Preferably with this removed, Acked-by: Andrew Cooper <[email protected]>, but only because this is an emergency fix.
Thanks. I see. You'll like patch 2 even less; at least I do. And I'm not really certain that change is enough to cover all possible systems.
Quoted 1 line
I really don't think it is an improvement to the logic.
Yet I suppose you also have no immediate suggestions towards doing better? Of course right here a full rework is out of scope. But if there were smaller bits that - if adjusted - would make you feel better about the change as a whole, I'd be happy to consider making adjustments.
Jan
Re: [PATCH 1/4] x86/PVH: de-duplicate mappings for first Mb of Dom0 memory
Quoted 41 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
Quoted 2 lines · Jan Beulich
One of the changes comprising the fixes for XSA-378 disallows replacing MMIO mappings by unintended (for this purpose) code paths.
I'd drop the brackets. All it does is confuse the sentence.
Quoted 8 lines
This means we
need to be more careful about the mappings put in place in this range - mappings should be created exactly once:
-iommu_hwdom_init()comes first; it should avoid the first Mb,
-pvh_populate_p2m()should insert identity mappings only into ranges not populated as RAM,
-pvh_setup_acpi()should again avoid the first Mb, which was already dealt with at that point.Quoted 1 line
This really is a mess. It also seems very fragile.
So it seems to me.
Quoted 3 lines
Why is
iommu_hwdom_init()separate in the first place? It only does mappings up to 4G in the first place, and with this change, it is now [1M-4G)I guess we'll want to wait for Roger to return to shed some light on this.
Quoted 14 lines
xen/arch/x86/hvm/dom0_build.c static int __init pvh_setup_acpi(struct · line 1110
Quoted 11 lines
xen/arch/x86/hvm/dom0_build.c +7
-0@@ -1095,6 +1101,17 @@ static int __init pvh_setup_acpi(struct nr_pages =PFN_UP ((d->arch.e820[i].addr & ~PAGE_MASK ) + d->arch.e820[i].size); +/* Memory below 1MB has been dealt with by pvh_populate_p2m(). */ +if ( pfn <PFN_DOWN (MB (1 )) ) + { +if ( pfn + nr_pages <=PFN_DOWN (MB (1 )) ) +continue ; + +/* This shouldn't happen, but is easy to deal with. */ I'm not sure this comment is helpful.
Quoted 6 lines
Quoted 2 lines
Under PVH, there is nothing special about the 1M boundary, and we can reasonably have something else here or crossing the boundary.
As long as we have this special treatment of the low Mb, the boundary is meaningful imo. I'd see the comment go away when the handling in general gets streamlined.
I should have added: And as long as Dom0's E820 map gets cloned from the host's, which will necessarily consider the 1Mb boundary special.
Jan
Re: [PATCH 1/4] x86/PVH: de-duplicate mappings for first Mb of Dom0 memory
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 13 lines
xen/arch/x86/hvm/dom0_build.c static int __init pvh_setup_acpi(struct · line 1110
Quoted 11 lines
xen/arch/x86/hvm/dom0_build.c +7
-0@@ -1095,6 +1101,17 @@ static int __init pvh_setup_acpi(struct nr_pages =PFN_UP ((d->arch.e820[i].addr & ~PAGE_MASK ) + d->arch.e820[i].size); +/* Memory below 1MB has been dealt with by pvh_populate_p2m(). */ +if ( pfn <PFN_DOWN (MB (1 )) ) + { +if ( pfn + nr_pages <=PFN_DOWN (MB (1 )) ) +continue ; + +/* This shouldn't happen, but is easy to deal with. */ I'm not sure this comment is helpful.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Under PVH, there is nothing special about the 1M boundary, and we can reasonably have something else here or crossing the boundary.
As long as we have this special treatment of the low Mb, the boundary is meaningful imo. I'd see the comment go away when the handling in general gets streamlined.
I should have added: And as long as Dom0's E820 map gets cloned from the host's, which will necessarily consider the 1Mb boundary special.
Not when you're booting virtualised in the first place.
~Andrew
Re: [PATCH 1/4] x86/PVH: de-duplicate mappings for first Mb of Dom0 memory
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 15 lines
xen/arch/x86/hvm/dom0_build.c static int __init pvh_setup_acpi(struct · line 1110
Quoted 11 lines
xen/arch/x86/hvm/dom0_build.c +7
-0@@ -1095,6 +1101,17 @@ static int __init pvh_setup_acpi(struct nr_pages =PFN_UP ((d->arch.e820[i].addr & ~PAGE_MASK ) + d->arch.e820[i].size); +/* Memory below 1MB has been dealt with by pvh_populate_p2m(). */ +if ( pfn <PFN_DOWN (MB (1 )) ) + { +if ( pfn + nr_pages <=PFN_DOWN (MB (1 )) ) +continue ; + +/* This shouldn't happen, but is easy to deal with. */ I'm not sure this comment is helpful.
Under PVH, there is nothing special about the 1M boundary, and we can reasonably have something else here or crossing the boundary.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
As long as we have this special treatment of the low Mb, the boundary is meaningful imo. I'd see the comment go away when the handling in general gets streamlined.
I should have added: And as long as Dom0's E820 map gets cloned from the host's, which will necessarily consider the 1Mb boundary special.
Not when you're booting virtualised in the first place.
You mean when Xen itself runs in PVH (not HVM) mode, and then in turn has a PVH Dom0? And if the underlying Xen has not in turn cloned the E820 from the host's? That's surely too exotic a case to warrant removing this comment. If you insist, I can mention that case as a possible exception.
Jan
Re: [PATCH 1/4] x86/PVH: de-duplicate mappings for first Mb of Dom0 memory
Quoted 20 lines · Jan Beulich
Quoted 19 lines · Andrew Cooper
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 13 lines
xen/arch/x86/hvm/dom0_build.c static int __init pvh_setup_acpi(struct · line 1110
Quoted 11 lines
xen/arch/x86/hvm/dom0_build.c +7
-0@@ -1095,6 +1101,17 @@ static int __init pvh_setup_acpi(struct nr_pages =PFN_UP ((d->arch.e820[i].addr & ~PAGE_MASK ) + d->arch.e820[i].size); +/* Memory below 1MB has been dealt with by pvh_populate_p2m(). */ +if ( pfn <PFN_DOWN (MB (1 )) ) + { +if ( pfn + nr_pages <=PFN_DOWN (MB (1 )) ) +continue ; + +/* This shouldn't happen, but is easy to deal with. */ I'm not sure this comment is helpful.
Quoted 2 lines
Under PVH, there is nothing special about the 1M boundary, and we can reasonably have something else here or crossing the boundary.
As long as we have this special treatment of the low Mb, the boundary is meaningful imo. I'd see the comment go away when the handling in general gets streamlined.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
I should have added: And as long as Dom0's E820 map gets cloned from the host's, which will necessarily consider the 1Mb boundary special.
Not when you're booting virtualised in the first place.
You mean when Xen itself runs in PVH (not HVM) mode, and then in turn has a PVH Dom0? And if the underlying Xen has not in turn cloned the E820 from the host's? That's surely too exotic a case to warrant removing this comment. If you insist, I can mention that case as a possible exception.
It's a long way from exotic.
Also the magic surrounding the 1M boundary is disappearing on real hardware with legacy BIOS support being dropped from platforms.
The comment is misleading and should be dropped. The logic is still perfectly clear given the outer comment.
~Andrew
Re: [PATCH 1/4] x86/PVH: de-duplicate mappings for first Mb of Dom0 memory
In reply to Jan BeulichOn Tue, Aug 31, 2021 at 03:14:06PM +0200, Jan Beulich wrote:
Sorry for the delay, and likely not being of much help right now.
Quoted 18 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 2 lines
One of the changes comprising the fixes for XSA-378 disallows replacing MMIO mappings by unintended (for this purpose) code paths.
I'd drop the brackets. All it does is confuse the sentence.
Quoted 8 lines
This means we
need to be more careful about the mappings put in place in this range - mappings should be created exactly once:
-iommu_hwdom_init()comes first; it should avoid the first Mb,
-pvh_populate_p2m()should insert identity mappings only into ranges not populated as RAM,
-pvh_setup_acpi()should again avoid the first Mb, which was already dealt with at that point.Quoted 1 line
This really is a mess. It also seems very fragile.
Quoted 8 lines
So it seems to me.
Quoted 3 lines
Why is
iommu_hwdom_init()separate in the first place? It only does mappings up to 4G in the first place, and with this change, it is now [1M-4G)I guess we'll want to wait for Roger to return to shed some light on this.
iommu_hwdom_init should cover from [0, max_pdx], or 4G if max_pdx is below that.
IIRC first PVH dom0 implementations used to have a behavior more similar to PV in iommu_hwdom_init, as they would get almost everything below 4GB that's not RAM identity mapped in the (IOMMU) page tables.
PVH dom0 has since diverged, and now iommu_hwdom_init just identity maps reserved regions. We could likely move this somewhere else, but given it's still shared with PV dom0 (by using the same command line option, dom0-iommu=map-reserved) I think it would just make option handling more confusing.
One way to simplify things would be to rely on the hardware provided memory map to correctly have the regions in the low 1M marked as reserved, so that iommu_hwdom_init would identity map them. Then we would just need a bit of special handling to duplicate the data in RAM regions for the low 1M but we could avoid a lot of complexity. This however requires trusting the hardware is not missing required regions in the low 1M.
Another option might be to slightly modify hwdom_iommu_map so that for PVH it returns true for all non-RAM regions in the low 1M. That would avoid having to add another loop in pvh_populate_p2m to map those.
Thanks, Roger.
PATCH 2/4 x86/P2M: relax guarding of MMIO entries
In reply to Jan BeulichOne of the changes comprising the fixes for XSA-378 disallows replacing MMIO mappings by unintended (for this purpose) code paths. At least in the case of PVH Dom0 hitting an RMRR covered by an E820 ACPI region, this is too strict. Generally short-circuit requests establishing the same kind of mapping that's already in place.
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
While there, also add a log message to the other domain_crash() invocation that did prevent PVH Dom0 from coming up after the XSA-378 changes.
xen/arch/x86/mm/p2m.c +50 -5
@@ -958,9 +958,13 @@ guest_physmap_add_entry(struct domain *dif (p2m_is_special (ot) ) {/* Don't permit unmapping grant/foreign/direct-MMIO this way. */ -domain_crash (d);p2m_unlock (p2m); - +printk (XENLOG_G_ERR +"%pd: GFN %lx (%lx:%u:%u) -> (%lx:%u:%u) not permitted\n" , + d,gfn_x (gfn) + i, +mfn_x (omfn), ot, a, +mfn_x (mfn) + i, t, p2m->default_access); +domain_crash (d);return -EPERM ; }else if (p2m_is_ram (ot) && !p2m_is_paged (ot) )
@@ -1302,9 +1306,50 @@ static int set_typed_p2m_entry(struct do }if (p2m_is_special (ot) ) { -gfn_unlock (p2m, gfn, order); -domain_crash (d); -return -EPERM ; +bool done = false, bad = true; + +/* Special-case (almost) identical mappings. */ +if (mfn_eq (mfn, omfn) && gfn_p2mt == ot ) + { +/* +* For MMIO allow X to differ in the requests (to cover for +* set_identity_p2m_entry() and set_mmio_p2m_entry() differing in +* the way they specify "access"). For the hardware domain put (or +* leave) in place the more permissive of the two possibilities, +* while for DomU-s go with the more restrictive variant. +*/ +if ( gfn_p2mt == p2m_mmio_direct && + access <= p2m_access_rwx && + (access ^ a) == p2m_access_x ) + { +if (is_hardware_domain (d) ) + access |= p2m_access_x; +else + access &= ~p2m_access_x; + bad = access == p2m_access_n; + } + +if ( access == a ) + done = true; + } + +if ( done ) + { +gfn_unlock (p2m, gfn, order); +return 0 ; + } + +if ( bad ) + { +gfn_unlock (p2m, gfn, order); +printk (XENLOG_G_ERR +"%pd: GFN %lx (%lx:%u:%u:%u) -> (%lx:%u:%u:%u) not permitted\n" , + d, gfn_l, +mfn_x (omfn), cur_order, ot, a, +mfn_x (mfn), order, gfn_p2mt, access); +domain_crash (d); +return -EPERM ; + } }else if (p2m_is_ram (ot) ) {
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 12 lines · Jan Beulich
One of the changes comprising the fixes for XSA-378 disallows replacing MMIO mappings by unintended (for this purpose) code paths. At least in the case of PVH Dom0 hitting an RMRR covered by an E820 ACPI region, this is too strict. Generally short-circuit requests establishing the same kind of mapping that's already in place.
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Quoted 6 lines
While there, also add a log message to the other
domain_crash()invocation that did prevent PVH Dom0 from coming up after the XSA-378 changes.Fixes 753cb68e6530 ("x86/p2m: guard (in particular) identity mapping entries")Signed-off-by Jan Beulich <[email protected]>
Btw, I had meant to have this post-commit-message remark here:
TBD: This could be generalized to all of R, W, and X. Dealing with just X
is merely the minimum I found is immediately necessary.
Jan
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
In reply to Jan BeulichQuoted 2 lines · Jan Beulich
One of the changes comprising the fixes for XSA-378 disallows replacing MMIO mappings by unintended (for this purpose) code paths.
Drop the brackets.
Quoted 10 lines
At least in
the case of PVH Dom0 hitting an RMRR covered by an E820 ACPI region, this is too strict. Generally short-circuit requests establishing the same kind of mapping that's already in place.Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
Quoted 10 lines
While there, also add a log message to the other
domain_crash()invocation that did prevent PVH Dom0 from coming up after the XSA-378 changes.Fixes 753cb68e6530 ("x86/p2m: guard (in particular) identity mapping entries")Signed-off-by Jan Beulich <[email protected]>
xen/arch/x86/mm/p2m.c guest_physmap_add_entry(struct domain *d · line 963
Quoted 8 lines
xen/arch/x86/mm/p2m.c +2
-2@@ -958,9 +958,13 @@ guest_physmap_add_entry(struct domain *dif (p2m_is_special (ot) ) {/* Don't permit unmapping grant/foreign/direct-MMIO this way. */ -domain_crash (d);p2m_unlock (p2m); - + printk(XENLOG_G_ERR + "%pd: GFN %lx (%lx:%u:%u) -> (%lx:%u:%u) not permitted\n",
type and access need to be rendered in hex, or you need to use 0x prefixes to distinguish the two bases.
Also, use commas rather than colons. Visually, this is ambiguous with PCI BDFs, and commas match tuple notation in most programming languages which is the construct you're trying to represent.
Same below.
Quoted 15 lines
xen/arch/x86/mm/p2m.c +5
-3+ d,gfn_x (gfn) + i, +mfn_x (omfn), ot, a, + mfn_x(mfn) + i, t, p2m->default_access); +domain_crash (d);return -EPERM ; }else if (p2m_is_ram (ot) && !p2m_is_paged (ot) )@@ -1302,9 +1306,50 @@ static int set_typed_p2m_entry(struct do }if (p2m_is_special (ot) ) { -gfn_unlock (p2m, gfn, order); -domain_crash (d); -return -EPERM ; +bool done = false, bad = true;
xen/arch/x86/mm/p2m.c static int set_typed_p2m_entry(struct do · line 1319
Quoted 10 lines
xen/arch/x86/mm/p2m.c +10
-0+ +/* Special-case (almost) identical mappings. */ +if (mfn_eq (mfn, omfn) && gfn_p2mt == ot ) + { +/* +* For MMIO allow X to differ in the requests (to cover for +* set_identity_p2m_entry() and set_mmio_p2m_entry() differing in +* the way they specify "access"). For the hardware domain put (or +* leave) in place the more permissive of the two possibilities, +* while for DomU-s go with the more restrictive variant.
This comment needs to identify clearly that it is a temporary bodge intended to be removed.
~Andrew
Quoted 37 lines
xen/arch/x86/mm/p2m.c +33
-0+*/ +if ( gfn_p2mt == p2m_mmio_direct && + access <= p2m_access_rwx && + (access ^ a) == p2m_access_x ) + { +if (is_hardware_domain (d) ) + access |= p2m_access_x; +else + access &= ~p2m_access_x; + bad = access == p2m_access_n; + } + +if ( access == a ) + done = true; + } + +if ( done ) + { +gfn_unlock (p2m, gfn, order); +return 0 ; + } + +if ( bad ) + { +gfn_unlock (p2m, gfn, order); +printk (XENLOG_G_ERR +"%pd: GFN %lx (%lx:%u:%u:%u) -> (%lx:%u:%u:%u) not permitted\n" , + d, gfn_l, +mfn_x (omfn), cur_order, ot, a, +mfn_x (mfn), order, gfn_p2mt, access); +domain_crash (d); +return -EPERM ; + } }else if (p2m_is_ram (ot) ) {
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 9 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
True, but what do you do.
Quoted 5 lines
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
And how do we know that that's what is going to work? We should strictly accumulate for Dom0. And what we do for DomU is moot for the moment, until PCI passthrough becomes a thing for PVH. Hence I've opted to be restrictive there - I'd rather see things break (and getting adjusted) when this future work actually gets carried out, than leave things permissive for no-one to notice that it's too permissive, leading to an XSA.
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/mm/p2m.c +0
-0@@ -958,9 +958,13 @@ guest_physmap_add_entry(struct domain *dif (p2m_is_special (ot) ) {/* Don't permit unmapping grant/foreign/direct-MMIO this way. */
Quoted 8 lines
xen/arch/x86/mm/p2m.c guest_physmap_add_entry(struct domain *d · line 963
Quoted 5 lines
xen/arch/x86/mm/p2m.c +2
-2-domain_crash (d);p2m_unlock (p2m); - + printk(XENLOG_G_ERR + "%pd: GFN %lx (%lx:%u:%u) -> (%lx:%u:%u) not permitted\n",type and access need to be rendered in hex, or you need to use 0x prefixes to distinguish the two bases.
Will use %#lx then.
Quoted 5 lines
Also, use commas rather than colons. Visually, this is ambiguous with PCI BDFs, and commas match tuple notation in most programming languages which is the construct you're trying to represent.
Same below.
Sure, will do.
Quoted 13 lines
Quoted 13 lines
xen/arch/x86/mm/p2m.c +6
-3@@ -1302,9 +1306,50 @@ static int set_typed_p2m_entry(struct do }if (p2m_is_special (ot) ) { -gfn_unlock (p2m, gfn, order); -domain_crash (d); -return -EPERM ; +bool done = false, bad = true; + +/* Special-case (almost) identical mappings. */ +if (mfn_eq (mfn, omfn) && gfn_p2mt == ot ) + { +/*
Quoted 8 lines
xen/arch/x86/mm/p2m.c static int set_typed_p2m_entry(struct do · line 1319
Quoted 5 lines
xen/arch/x86/mm/p2m.c +5
-0+* For MMIO allow X to differ in the requests (to cover for +* set_identity_p2m_entry() and set_mmio_p2m_entry() differing in +* the way they specify "access"). For the hardware domain put (or +* leave) in place the more permissive of the two possibilities, +* while for DomU-s go with the more restrictive variant. This comment needs to identify clearly that it is a temporary bodge intended to be removed.
Okay.
Jan
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
Quoted 8 lines
True, but what do you do.
Quoted 5 lines
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
And how do we know that that's what is going to work?
Because it's the pre-existing behaviour.
Quoted 7 lines
We should
strictly accumulate for Dom0. And what we do for DomU is moot for the moment, until PCI passthrough becomes a thing for PVH. Hence I've opted to be restrictive there - I'd rather see things break (and getting adjusted) when this future work actually gets carried out, than leave things permissive for no-one to notice that it's too permissive, leading to an XSA.
Restricting execute permissions is something unique to virt. It doesn't exist in a non-virtualised system, as I and D side reads are indistinguishable outside of the core.
Furthermore, it is inexpressible on some systems/configurations.
Introspection is the only technology which should be restricting execute permissions in the p2m, and only when it takes responsibility for dealing with the fallout.
~Andrew
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
True, but what do you do.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
And how do we know that that's what is going to work?
Because it's the pre-existing behaviour.
Valid point. But for the DomU case there simply has not been any pre-existing behavior. Hence my desire to be restrictive initially there.
Quoted 12 lines
Quoted 7 lines
We should
strictly accumulate for Dom0. And what we do for DomU is moot for the moment, until PCI passthrough becomes a thing for PVH. Hence I've opted to be restrictive there - I'd rather see things break (and getting adjusted) when this future work actually gets carried out, than leave things permissive for no-one to notice that it's too permissive, leading to an XSA.Restricting execute permissions is something unique to virt. It doesn't exist in a non-virtualised system, as I and D side reads are indistinguishable outside of the core.
Quoted 5 lines
Furthermore, it is inexpressible on some systems/configurations.
Introspection is the only technology which should be restricting execute permissions in the p2m, and only when it takes responsibility for dealing with the fallout.
IOW are you saying that the calls to set_identity_p2m_entry() (pre-dating XSA-378) were wrong to use p2m_access_rw? Because that's what's getting the way here.
Plus, as a side note, then we don't even have e.g. IOMMUF_executable.
Jan
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
True, but what do you do.
Quoted 5 lines
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
And how do we know that that's what is going to work?
Because it's the pre-existing behaviour.
Valid point. But for the DomU case there simply has not been any pre-existing behavior. Hence my desire to be restrictive initially there.
Further to this: Using the last-value-set approach also puts us at risk of running into a similar issue again when the ordering of some operations changes elsewhere.
Jan
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
In reply to Jan BeulichQuoted 40 lines · Jan Beulich
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
True, but what do you do.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
And how do we know that that's what is going to work?
Because it's the pre-existing behaviour.
Valid point. But for the DomU case there simply has not been any pre-existing behavior. Hence my desire to be restrictive initially there.
Quoted 14 lines
Quoted 7 lines
We should
strictly accumulate for Dom0. And what we do for DomU is moot for the moment, until PCI passthrough becomes a thing for PVH. Hence I've opted to be restrictive there - I'd rather see things break (and getting adjusted) when this future work actually gets carried out, than leave things permissive for no-one to notice that it's too permissive, leading to an XSA.Restricting execute permissions is something unique to virt. It doesn't exist in a non-virtualised system, as I and D side reads are indistinguishable outside of the core.
Furthermore, it is inexpressible on some systems/configurations.
Quoted 7 lines
Quoted 3 lines
Introspection is the only technology which should be restricting execute permissions in the p2m, and only when it takes responsibility for dealing with the fallout.
IOW are you saying that the calls to
set_identity_p2m_entry()(pre-dating XSA-378) were wrong to usep2m_access_rw? Because that's what's getting the way here.
I did wonder this before, because I saw some messages on a couple of systems about mappings override, and I'm not sure why we need to use p2m_access_rw. My first thought was to suggest to switch to use the default access type for the domain, like set_mmio_p2m_entry does.
I have to admit I'm not sure I see the point of preventing execution, but it's possible I'm missing something.
Thanks, Roger.
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 49 lines · Roger Pau Monné
Quoted 40 lines · Jan Beulich
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
True, but what do you do.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
And how do we know that that's what is going to work?
Because it's the pre-existing behaviour.
Valid point. But for the DomU case there simply has not been any pre-existing behavior. Hence my desire to be restrictive initially there.
Quoted 14 lines
Quoted 7 lines
We should
strictly accumulate for Dom0. And what we do for DomU is moot for the moment, until PCI passthrough becomes a thing for PVH. Hence I've opted to be restrictive there - I'd rather see things break (and getting adjusted) when this future work actually gets carried out, than leave things permissive for no-one to notice that it's too permissive, leading to an XSA.Restricting execute permissions is something unique to virt. It doesn't exist in a non-virtualised system, as I and D side reads are indistinguishable outside of the core.
Furthermore, it is inexpressible on some systems/configurations.
Quoted 7 lines
Quoted 3 lines
Introspection is the only technology which should be restricting execute permissions in the p2m, and only when it takes responsibility for dealing with the fallout.
IOW are you saying that the calls to
set_identity_p2m_entry()(pre-dating XSA-378) were wrong to usep2m_access_rw? Because that's what's getting the way here.
Quoted 7 lines
I did wonder this before, because I saw some messages on a couple of systems about mappings override, and I'm not sure why we need to use
p2m_access_rw. My first thought was to suggest to switch to use the default access type for the domain, likeset_mmio_p2m_entrydoes.I have to admit I'm not sure I see the point of preventing execution, but it's possible I'm missing something.
Well, what good can come from allowing execution from, say, the IO-APIC or LAPIC pages? Or other MMIO-mapped register space? Insn fetches might even trip bad hardware behavior in such a case by being the wrong granularity. It's imo really only ROM space which ought to have execution permitted.
The issue isn't just with execution, though, and as a result I may need to change the logic here to also include at least W. As of one of the XSA-378 changes we may now pass just p2m_access_r to iommu_identity_mapping(), if the ACPI tables on an AMD system were saying so. (We may also pass p2m_access_w, but I sincerely hope no firmware would specify write but no read access.)
Similarly in "IOMMU/x86: restrict IO-APIC mappings for PV Dom0" I now pass p2m_access_r to set_identity_p2m_entry().
I suppose an underlying issue is the mixed purpose of using p2m_access_*, which possibly has been against the intentions in the first place. We cannot, for example, express r/o access to an MMIO page without using p2m_access_r (or p2m_access_rx), as there's no suitable p2m type to express this via type alone. We may need to split p2m_mmio_direct into multiple types (up to 7), I guess, if we wanted to remove this (ab)use of p2m_access_*.
Jan
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 55 lines · Jan Beulich
Quoted 54 lines · Roger Pau Monné
Quoted 40 lines · Jan Beulich
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
True, but what do you do.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
And how do we know that that's what is going to work?
Because it's the pre-existing behaviour.
Valid point. But for the DomU case there simply has not been any pre-existing behavior. Hence my desire to be restrictive initially there.
Quoted 14 lines
Quoted 7 lines
We should
strictly accumulate for Dom0. And what we do for DomU is moot for the moment, until PCI passthrough becomes a thing for PVH. Hence I've opted to be restrictive there - I'd rather see things break (and getting adjusted) when this future work actually gets carried out, than leave things permissive for no-one to notice that it's too permissive, leading to an XSA.Restricting execute permissions is something unique to virt. It doesn't exist in a non-virtualised system, as I and D side reads are indistinguishable outside of the core.
Furthermore, it is inexpressible on some systems/configurations.
Quoted 7 lines
Quoted 3 lines
Introspection is the only technology which should be restricting execute permissions in the p2m, and only when it takes responsibility for dealing with the fallout.
IOW are you saying that the calls to
set_identity_p2m_entry()(pre-dating XSA-378) were wrong to usep2m_access_rw? Because that's what's getting the way here.I did wonder this before, because I saw some messages on a couple of systems about mappings override, and I'm not sure why we need to use
p2m_access_rw. My first thought was to suggest to switch to use the default access type for the domain, likeset_mmio_p2m_entrydoes.
Quoted 5 lines
Quoted 2 lines
I have to admit I'm not sure I see the point of preventing execution, but it's possible I'm missing something.
Well, what good can come from allowing execution from, say, the IO-APIC or LAPIC pages? Or other MMIO-mapped register space?
map_mmio_regions does already map BARs with execute permissions, so it's just some MMIO regions that get mapped without execution permissions, which makes all this confusing.
Quoted 3 lines
Insn
fetches might even trip bad hardware behavior in such a case by being the wrong granularity.
Normal reads could also trigger such bad hardware behavior, so I'm not sure preventing execution provides Xen any more safety.
Quoted 10 lines
It's imo really only ROM space which
ought to have execution permitted.The issue isn't just with execution, though, and as a result I may need to change the logic here to also include at least W. As of one of the XSA-378 changes we may now pass just
p2m_access_rtoiommu_identity_mapping(), if the ACPI tables on an AMD system were saying so. (We may also passp2m_access_w, but I sincerely hope no firmware would specify write but no read access.)
Quoted 2 lines
Similarly in "IOMMU/x86: restrict IO-APIC mappings for PV Dom0" I now pass
p2m_access_rtoset_identity_p2m_entry().
Not really I think, as PVH dom0 is the only user of the set_identity_p2m_entry call in arch_iommu_hwdom_init, and we should never identity map the IO-APIC range in that case because a set of emulated IO-APIC replacements are provided and those require ranges to be unmapped so that accesses can be trapped.
Quoted 8 lines
I suppose an underlying issue is the mixed purpose of using p2m_access_*, which possibly has been against the intentions in the first place. We cannot, for example, express r/o access to an MMIO page without using
p2m_access_r(orp2m_access_rx), as there's no suitable p2m type to express this via type alone. We may need to splitp2m_mmio_directinto multiple types (up to 7), I guess, if we wanted to remove this (ab)use of p2m_access_*.
My main complaint is mostly with the fact that some MMIO ranges are mapped without execute permissions when mapped by set_identity_p2m_entry vs map_mmio_regions that will map them with the default permissions and that has execution set.
If the mappings from arch_iommu_hwdom_init for example would use the default permissions that could solve quite a lot of the issues there AFAIC.
Roger.
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 8 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
The issue isn't just with execution, though, and as a result I may need to change the logic here to also include at least W. As of one of the XSA-378 changes we may now pass just
p2m_access_rtoiommu_identity_mapping(), if the ACPI tables on an AMD system were saying so. (We may also passp2m_access_w, but I sincerely hope no firmware would specify write but no read access.)
Quoted 8 lines
Quoted 2 lines
Similarly in "IOMMU/x86: restrict IO-APIC mappings for PV Dom0" I now pass
p2m_access_rtoset_identity_p2m_entry().Not really I think, as PVH dom0 is the only user of the
set_identity_p2m_entrycall inarch_iommu_hwdom_init, and we should never identity map the IO-APIC range in that case because a set of emulated IO-APIC replacements are provided and those require ranges to be unmapped so that accesses can be trapped.
Correct, this would be only a latent issue for now. The code passes that value, but that path is not going to be taken (until, perhaps, a future change).
Quoted 8 lines
Quoted 7 lines
I suppose an underlying issue is the mixed purpose of using p2m_access_*, which possibly has been against the intentions in the first place. We cannot, for example, express r/o access to an MMIO page without using
p2m_access_r(orp2m_access_rx), as there's no suitable p2m type to express this via type alone. We may need to splitp2m_mmio_directinto multiple types (up to 7), I guess, if we wanted to remove this (ab)use of p2m_access_*.
Quoted 4 lines
My main complaint is mostly with the fact that some MMIO ranges are mapped without execute permissions when mapped by
set_identity_p2m_entryvsmap_mmio_regionsthat will map them with the default permissions and that has execution set.
Right - as said in a reply to Andrew, we may need to drop some p2m_access_t parameters in favor of using default permissions. But at least for AMD's IOMMU-unity-mapped ranges we will need to have a way to express at least r/o.
Jan
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
In reply to Jan BeulichQuoted 16 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
True, but what do you do.
Quoted 3 lines
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
And how do we know that that's what is going to work?
Because it's the pre-existing behaviour.
Valid point. But for the DomU case there simply has not been any pre-existing behavior. Hence my desire to be restrictive initially there.
But you're conflating a feature (under question anyway, because I gave you an example where I expect this will collide in a regular domU already), with an emergency bugfix to unbreak staging caused by an unexpected interaction in a security hotfix.
At an absolute minimum, this patch needs splitting in two to separate the bugfix from the proposed feature.
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
We should
strictly accumulate for Dom0. And what we do for DomU is moot for the moment, until PCI passthrough becomes a thing for PVH. Hence I've opted to be restrictive there - I'd rather see things break (and getting adjusted) when this future work actually gets carried out, than leave things permissive for no-one to notice that it's too permissive, leading to an XSA.Restricting execute permissions is something unique to virt. It doesn't exist in a non-virtualised system, as I and D side reads are indistinguishable outside of the core.
Quoted 7 lines
Quoted 5 lines
Furthermore, it is inexpressible on some systems/configurations.
Introspection is the only technology which should be restricting execute permissions in the p2m, and only when it takes responsibility for dealing with the fallout.
IOW are you saying that the calls to
set_identity_p2m_entry()(pre-dating XSA-378) were wrong to usep2m_access_rw?
Yes.
Quoted 2 lines
Because that's
what's getting the way here.
On a real machine, you really can write some executable code into an E820 reserved region and jump to it. You can also execute code from real BARs is you happen to know that they are prefetchable (or you're a glutton for UC reads...)
And there is the WPBT ACPI table which exists specifically to let firmware inject drivers/applications into a windows environment, and may come out of the SPI ROM in the first place.
Is it sensible to execute an E820 reserved region, or unmarked BAR? Probably not.
Should it work, because that's how real hardware behaves? Absolutely.
Any restrictions beyond that want handling by some kind of introspection agent which has a policy of what to do with legal-but-dodgy-looking actions.
Quoted 1 line
Plus, as a side note, then we don't even have e.g.
IOMMUF_executable.
Just as I vs D side reads are indistinguishable outside of the CPU core, the same is in principle true for PCI devices which execute code (e.g. GPU shaders). Reads on the bus are just reads.
That said, the latest SIOV spec does appear to include the ER (Execution Request) bit for use with PASSID/Shared-Virtual-Memory, which interacts with the EPT-X/ia32-NX bits, and goes as far as having SMEP/SMAP bits in the IOMMU configuration. I'm not sure if this is in released hardware yet, but it's clearly on the horizon. I can't spot any execute related controls in the AMD IOMMU spec, although it does have user/supervisor for PASSID/SVM.
~Andrew
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Further permit "access" to differ in the "executable" attribute. While ideally only ROM regions would get mapped with X set, getting there is quite a bit of work. Therefore, as a temporary measure, permit X to vary. For Dom0 the more permissive of the types will be used, while for DomU it'll be the more restrictive one.
Split behaviour between dom0 and domU based on types alone cannot possibly be correct.
True, but what do you do.
Quoted 5 lines
DomU's need to execute ROMs too, and this looks like will malfunction if a ROM ends up in the region that HVMLoader relocated RAM from.
As this is a temporary bodge emergency bugfix, don't try to be clever - just take the latest access.
And how do we know that that's what is going to work?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Because it's the pre-existing behaviour.
Valid point. But for the DomU case there simply has not been any pre-existing behavior. Hence my desire to be restrictive initially there.
But you're conflating a feature (under question anyway, because I gave you an example where I expect this will collide in a regular domU already),
I don't think your example fits: hvmloader moving RAM will first convert the p2m slot to non-present. Then a ROM page can get mapped there quite fine. A direct transition (without going through n/p) would not work independent of the change here: The MFNs would differ, as would the p2m types.
Quoted 5 lines
with an emergency bugfix to unbreak staging caused by an unexpected interaction in a security hotfix.
At an absolute minimum, this patch needs splitting in two to separate the bugfix from the proposed feature.
Well, okay, I will split the patch, despite not being convinced this will do us any good - we'd backport just the part you consider a bug fix, but not the part you deem a feature (and which I consider part of the bug fix).
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
We should
strictly accumulate for Dom0. And what we do for DomU is moot for the moment, until PCI passthrough becomes a thing for PVH. Hence I've opted to be restrictive there - I'd rather see things break (and getting adjusted) when this future work actually gets carried out, than leave things permissive for no-one to notice that it's too permissive, leading to an XSA.
Actually I think I was missing an important aspect here: The code in question gets used not only for PVH, but also for HVM, where pass- through is a thing. Hence I'll restrict the "feature" part to Dom0 for now.
Quoted 27 lines
Quoted 11 lines
Quoted 9 lines
Restricting execute permissions is something unique to virt. It doesn't exist in a non-virtualised system, as I and D side reads are indistinguishable outside of the core.
Furthermore, it is inexpressible on some systems/configurations.
Introspection is the only technology which should be restricting execute permissions in the p2m, and only when it takes responsibility for dealing with the fallout.
IOW are you saying that the calls to
set_identity_p2m_entry()(pre-dating XSA-378) were wrong to usep2m_access_rw?Yes.
Quoted 2 lines
Because that's
what's getting the way here.On a real machine, you really can write some executable code into an E820 reserved region and jump to it. You can also execute code from real BARs is you happen to know that they are prefetchable (or you're a glutton for UC reads...)
And there is the WPBT ACPI table which exists specifically to let firmware inject
drivers/applicationsinto a windows environment, and may come out of the SPI ROM in the first place.
Quoted 7 lines
Is it sensible to execute an E820 reserved region, or unmarked BAR? Probably not.
Should it work, because that's how real hardware behaves? Absolutely.
Any restrictions beyond that want handling by some kind of introspection agent which has a policy of what to do with legal-but-dodgy-looking actions.
IOW you suggest we remove p2m_access_t parameters from various functions, going with just default access? Of course, as pointed out in another reply, we'll need to split p2m_mmio_direct into multiple types then, at the very least to honor the potential r/o restriction of AMD IOMMU unity mapped regions. (FAOD all of this isn't a short term plan anyway, at least afaic.)
Jan
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 11 lines
Quoted 9 lines
Restricting execute permissions is something unique to virt. It doesn't exist in a non-virtualised system, as I and D side reads are indistinguishable outside of the core.
Furthermore, it is inexpressible on some systems/configurations.
Introspection is the only technology which should be restricting execute permissions in the p2m, and only when it takes responsibility for dealing with the fallout.
IOW are you saying that the calls to
set_identity_p2m_entry()(pre-dating XSA-378) were wrong to usep2m_access_rw?Yes.
Quoted 2 lines
Because that's
what's getting the way here.On a real machine, you really can write some executable code into an E820 reserved region and jump to it. You can also execute code from real BARs is you happen to know that they are prefetchable (or you're a glutton for UC reads...)
And there is the WPBT ACPI table which exists specifically to let firmware inject
drivers/applicationsinto a windows environment, and may come out of the SPI ROM in the first place.Is it sensible to execute an E820 reserved region, or unmarked BAR? Probably not.
Quoted 6 lines
Quoted 4 lines
Should it work, because that's how real hardware behaves? Absolutely.
Any restrictions beyond that want handling by some kind of introspection agent which has a policy of what to do with legal-but-dodgy-looking actions.
IOW you suggest we remove
p2m_access_tparameters from various functions, going with just default access?
p2m_access_t was very obviously a bodge when introduced, and I doubt it would pass today's review standards.
It is definitely a mis-design, given its ill-specified and overlapping semantics with respect to the p2m type.
Quoted 5 lines
Of course, as pointed out in another
reply, we'll need to splitp2m_mmio_directinto multiple types then, at the very least to honor the potential r/o restriction of AMD IOMMU unity mapped regions. (FAOD all of this isn't a short term plan anyway, at least afaic.)
I don't think that will be necessary.
IVMDs are almost non-existent, and given how many other areas of the AMD IOMMU spec are totally unused, I wouldn't be surprised if r/o unity mappings were in that category too. There's no obvious usecase for r/o, as anything critical enough in the platform to have an IVMD in the first place will also be non-trivial enough to require bidirectional communication somehow.
The unity mapping only says "this device requires read-only access". It doesn't say "this must be mapped read-only", and it is legitimate to map a r/o unity mapping as r/w.
If such a case actually exists, there's clearly one agent in the system with r/w access into the r/o range, and mapping it r/w is equivalent to the "IOMMU not enabled in the first place" case which is the default case for most software for the past decade-and-a-bit.
In other words, I don't think the r/o unit maps on their own are a good enough reasons to split the type. If we gain other reasons then fine, but this seems like chunk of complexity with no real users.
~Andrew
Re: [PATCH 2/4] x86/P2M: relax guarding of MMIO entries
Quoted 57 lines · Andrew Cooper
Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 11 lines
Quoted 9 lines
Restricting execute permissions is something unique to virt. It doesn't exist in a non-virtualised system, as I and D side reads are indistinguishable outside of the core.
Furthermore, it is inexpressible on some systems/configurations.
Introspection is the only technology which should be restricting execute permissions in the p2m, and only when it takes responsibility for dealing with the fallout.
IOW are you saying that the calls to
set_identity_p2m_entry()(pre-dating XSA-378) were wrong to usep2m_access_rw?Yes.
Quoted 2 lines
Because that's
what's getting the way here.On a real machine, you really can write some executable code into an E820 reserved region and jump to it. You can also execute code from real BARs is you happen to know that they are prefetchable (or you're a glutton for UC reads...)
And there is the WPBT ACPI table which exists specifically to let firmware inject
drivers/applicationsinto a windows environment, and may come out of the SPI ROM in the first place.Is it sensible to execute an E820 reserved region, or unmarked BAR? Probably not.
Quoted 6 lines
Quoted 4 lines
Should it work, because that's how real hardware behaves? Absolutely.
Any restrictions beyond that want handling by some kind of introspection agent which has a policy of what to do with legal-but-dodgy-looking actions.
IOW you suggest we remove
p2m_access_tparameters from various functions, going with just default access?
p2m_access_twas very obviously a bodge when introduced, and I doubt it would pass today's review standards.It is definitely a mis-design, given its ill-specified and overlapping semantics with respect to the p2m type.
Quoted 5 lines
Of course, as pointed out in another
reply, we'll need to splitp2m_mmio_directinto multiple types then, at the very least to honor the potential r/o restriction of AMD IOMMU unity mapped regions. (FAOD all of this isn't a short term plan anyway, at least afaic.)I don't think that will be necessary.
IVMDs are almost non-existent, and given how many other areas of the AMD IOMMU spec are totally unused, I wouldn't be surprised if r/o unity mappings were in that category too. There's no obvious usecase for r/o, as anything critical enough in the platform to have an IVMD in the first place will also be non-trivial enough to require bidirectional communication somehow.
Quoted 3 lines
The unity mapping only says "this device requires read-only access". It doesn't say "this must be mapped read-only", and it is legitimate to map a r/o unity mapping as r/w.
Well, imo that's extending what "Write permission. 1b=writeable, 0b=not writeable" and "Read permission. 1b=readable, 0b=not readable" in the spec say. "Permission" to me doesn't mean what you say.
Nevertheless I would perhaps not insist (as I've already made clear I don't see a strong need to support w/o mappings), if ...
Quoted 8 lines
If such a case actually exists, there's clearly one agent in the system with r/w access into the r/o range, and mapping it r/w is equivalent to the "IOMMU not enabled in the first place" case which is the default case for most software for the past decade-and-a-bit.
In other words, I don't think the r/o unit maps on their own are a good enough reasons to split the type. If we gain other reasons then fine, but this seems like chunk of complexity with no real users.
... there wasn't already a 2nd use for this: The IO-APIC mappings (see my respective pending patch).
Jan
PATCH 3/4 x86/PVH: improve Dom0 memory size calculation
In reply to Jan BeulichAssuming that the accounting for IOMMU page tables will also take care of the P2M needs was wrong: dom0_paging_pages() can determine a far higher value, high enough for the system to run out of memory while setting up Dom0. Hence in the case of shared page tables the larger of the two values needs to be used (without shared page tables the sum of both continues to be applicable).
While there also account for two further aspects in the PV case: With "iommu=dom0-passthrough" no IOMMU page tables would get allocated, so none need accounting for. And if shadow mode is to be enabled, setting aside a suitable amount for the P2M pool to get populated is also necessary (i.e. similar to the non-shared-page-tables case of PVH).
xen/arch/x86/dom0_build.c +22 -8
@@ -318,7 +318,7 @@ unsigned long __init dom0_compute_nr_pag struct domain *d, struct elf_dom_parms *parms, unsigned long initrd_len) { nodeid_t node; -unsigned long avail =0 , nr_pages, min_pages, max_pages; +unsigned long avail =0 , nr_pages, min_pages, max_pages, iommu_pages =0 ;bool need_paging;/* The ordering of operands is to work around a clang5 issue. */
@@ -337,18 +337,23 @@ unsigned long __init dom0_compute_nr_pag avail -= d->max_vcpus -1 ;/* Reserve memory for iommu_dom0_init() (rough estimate). */ -if (is_iommu_enabled (d) ) +if (is_iommu_enabled (d) && !iommu_hwdom_passthrough ) {unsigned int s;for ( s =9 ; s <BITS_PER_LONG ; s +=9 ) - avail -= max_pdx >> s; + iommu_pages += max_pdx >> s; + + avail -= iommu_pages; } - need_paging =is_hvm_domain (d) && - (!iommu_use_hap_pt (d) || !paging_mode_hap (d)); + need_paging =is_hvm_domain (d) + ? !iommu_use_hap_pt (d) || !paging_mode_hap (d) + : opt_dom0_shadow;for ( ; ; need_paging = false ) { +unsigned long paging_pages; + nr_pages =get_memsize (&dom0_size, avail); min_pages =get_memsize (&dom0_min_size, avail); max_pages =get_memsize (&dom0_max_size, avail);
@@ -377,11 +382,20 @@ unsigned long __init dom0_compute_nr_pag nr_pages =min (nr_pages, max_pages); nr_pages =min (nr_pages, avail); -if ( !need_paging ) -break ; + paging_pages =paging_mode_enabled (d) || need_paging + ?dom0_paging_pages (d, nr_pages) :0 ;/* Reserve memory for shadow or HAP. */ - avail -=dom0_paging_pages (d, nr_pages); +if ( !need_paging ) + { +if ( paging_pages <= iommu_pages ) +break ; + + avail -= paging_pages - iommu_pages; + } +else + avail -= paging_pages; + iommu_pages = paging_pages; } if ( is_pv_domain(d) &&
Re: [PATCH 3/4] x86/PVH: improve Dom0 memory size calculation
Quoted 6 lines · Jan Beulich
Assuming that the accounting for IOMMU page tables will also take care of the P2M needs was wrong:
dom0_paging_pages()can determine a far higher value, high enough for the system to run out of memory while setting up Dom0. Hence in the case of shared page tables the larger of the two values needs to be used (without shared page tables the sum of both continues to be applicable).
I'm afraid that I can't follow this at all.
What causes the system to run out of RAM while constructing dom0?
Quoted 31 lines
While there also account for two further aspects in the PV case: With "iommu=dom0-passthrough" no IOMMU page tables would get allocated, so none need accounting for. And if shadow mode is to be enabled, setting aside a suitable amount for the P2M pool to get populated is also necessary (i.e. similar to the non-shared-page-tables case of PVH).
Signed-off-by Jan Beulich <[email protected]>xen/arch/x86/dom0_build.c +2
-3@@ -318,7 +318,7 @@ unsigned long __init dom0_compute_nr_pag struct domain *d, struct elf_dom_parms *parms, unsigned long initrd_len) { nodeid_t node; -unsigned long avail =0 , nr_pages, min_pages, max_pages; +unsigned long avail =0 , nr_pages, min_pages, max_pages, iommu_pages =0 ;bool need_paging;/* The ordering of operands is to work around a clang5 issue. */ @@ -337,18 +337,23 @@ unsigned long __init dom0_compute_nr_pag avail -= d->max_vcpus -1 ;/* Reserve memory for iommu_dom0_init() (rough estimate). */ -if (is_iommu_enabled (d) ) +if (is_iommu_enabled (d) && !iommu_hwdom_passthrough ) {unsigned int s;for ( s =9 ; s <BITS_PER_LONG ; s +=9 ) - avail -= max_pdx >> s;
xen/arch/x86/dom0_build.c unsigned long __init dom0_compute_nr_pag · line 352
Quoted 10 lines
xen/arch/x86/dom0_build.c +6
-2+ iommu_pages += max_pdx >> s; + + avail -= iommu_pages; } - need_paging =is_hvm_domain (d) && - (!iommu_use_hap_pt (d) || !paging_mode_hap (d)); + need_paging =is_hvm_domain (d) + ? !iommu_use_hap_pt (d) || !paging_mode_hap (d) + : opt_dom0_shadow;
As per patch 4, this condition needs adjusting.
~Andrew
Quoted 32 lines
xen/arch/x86/dom0_build.c +14
-3for ( ; ; need_paging = false ) { +unsigned long paging_pages; + nr_pages =get_memsize (&dom0_size, avail); min_pages =get_memsize (&dom0_min_size, avail); max_pages =get_memsize (&dom0_max_size, avail);@@ -377,11 +382,20 @@ unsigned long __init dom0_compute_nr_pag nr_pages =min (nr_pages, max_pages); nr_pages =min (nr_pages, avail); -if ( !need_paging ) -break ; + paging_pages =paging_mode_enabled (d) || need_paging + ?dom0_paging_pages (d, nr_pages) :0 ;/* Reserve memory for shadow or HAP. */ - avail -=dom0_paging_pages (d, nr_pages); +if ( !need_paging ) + { +if ( paging_pages <= iommu_pages ) +break ; + + avail -= paging_pages - iommu_pages; + } +else + avail -= paging_pages; + iommu_pages = paging_pages; } if ( is_pv_domain(d) &&
Re: [PATCH 3/4] x86/PVH: improve Dom0 memory size calculation
Quoted 11 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
Assuming that the accounting for IOMMU page tables will also take care of the P2M needs was wrong:
dom0_paging_pages()can determine a far higher value, high enough for the system to run out of memory while setting up Dom0. Hence in the case of shared page tables the larger of the two values needs to be used (without shared page tables the sum of both continues to be applicable).I'm afraid that I can't follow this at all.
What causes the system to run out of RAM while constructing dom0?
Without any "dom0_mem=" we set aside 128Mb. In my .config that was in use I default to "dom0_mem=-255". Yet this was still far from enough to cover the gap between the original IOMMU page table accounting and the value returned from dom0_paging_pages(). Since this is what also gets used to actually populate Dom0's P2M pool, with the P2M pool populated there wasn't enough RAM anymore to reach the Dom0 size which dom0_compute_nr_pages() did establish.
Putting it in a simplified formula, what we did so far when sharing page tables was
RAM = total - IOMMU
but what we need is
RAM = total - max(IOMMU, P2M)
In the non-shared case we already correctly did
RAM = total - (IOMMU + P2M)
Jan
PATCH 4/4 x86/PV: properly set shadow allocation for Dom0
In reply to Jan BeulichLeaving shadow setup just to the L1TF tasklet means running Dom0 on a minimally acceptable shadow memory pool, rather than what normally would be used (also, for example, for PVH). Populate the pool before triggering the tasklet, on a best effort basis (again like done for PVH).
xen/arch/x86/mm/shadow/common.c +1 -1
@@ -1298,7 +1298,7 @@ int shadow_set_allocation(struct domain {struct page_info *sp; -ASSERT (paging_locked_by_me (d)); +ASSERT (paging_locked_by_me (d) || system_state < SYS_STATE_active);if ( pages >0 ) {
xen/arch/x86/pv/dom0_build.c +11 -0
@@ -21,6 +21,7 @@#include <asm/page.h> #include <asm/pv/mm.h> #include <asm/setup.h> +#include <asm/shadow.h> /* Allow ring-3 access in long mode as guest cannot use ring 1 ... */ #define BASE_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
@@ -933,7 +934,17 @@ int __init dom0_construct_pv(struct doma#ifdef CONFIG_SHADOW_PAGING if ( opt_dom0_shadow ) { +bool preempted; +printk ("Switching dom0 to using shadow paging\n" ); + +do { + preempted = false; +shadow_set_allocation (d,dom0_paging_pages (d, nr_pages), + &preempted); +process_pending_softirqs (); + }while ( preempted ); +tasklet_schedule (&d->arch.paging.shadow.pv_l1tf_tasklet); }#endif
Re: [PATCH 4/4] x86/PV: properly set shadow allocation for Dom0
Quoted 4 lines · Jan Beulich
xen/arch/x86/pv/dom0_build.c +0
-0@@ -933,7 +934,17 @@ int __init dom0_construct_pv(struct doma#ifdef CONFIG_SHADOW_PAGING if ( opt_dom0_shadow ) {
xen/arch/x86/pv/dom0_build.c int __init dom0_construct_pv(struct doma · line 946
Quoted 10 lines
xen/arch/x86/pv/dom0_build.c +9
-0+bool preempted; +printk ("Switching dom0 to using shadow paging\n" ); + +do { + preempted = false; +shadow_set_allocation (d,dom0_paging_pages (d, nr_pages), + &preempted); +process_pending_softirqs (); + }while ( preempted );
This isn't correct. The shadow pool is needed even without opt_dom0_shadow, because some downstreams have elected not to retain upstream's security vulnerability in default setting of opt_pv_l1tf_hwdom.
Also, dom0_paging_pages() isn't a trivial calculation, so should be called once and cached.
~Andrew
Re: [PATCH 4/4] x86/PV: properly set shadow allocation for Dom0
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
xen/arch/x86/pv/dom0_build.c +5
-0@@ -933,7 +934,17 @@ int __init dom0_construct_pv(struct doma#ifdef CONFIG_SHADOW_PAGING if ( opt_dom0_shadow ) { +bool preempted; +printk ("Switching dom0 to using shadow paging\n" ); + + do { + preempted = false;
Quoted 8 lines
xen/arch/x86/pv/dom0_build.c int __init dom0_construct_pv(struct doma · line 946
Quoted 4 lines
xen/arch/x86/pv/dom0_build.c +4
-0+shadow_set_allocation (d,dom0_paging_pages (d, nr_pages), + &preempted); +process_pending_softirqs (); + }while ( preempted );This isn't correct. The shadow pool is needed even without
opt_dom0_shadow, because some downstreams have elected not to retain upstream's security vulnerability in default setting ofopt_pv_l1tf_hwdom.
Are you suggesting to set up a (perhaps large) shadow pool just in case we need to enable shadow mode on Dom0? And all of this memory to then remain unused in the majority of cases?
Plus even if so, I'd view this as a 2nd, independent step, largely orthogonal to the handling of "dom0=shadow". If somebody really wanted that, I think this should be driven by an explicit setting of the shadow pool size, indicating the admin is willing to waste the memory.
I'm further puzzled by "not to retain upstream's security vulnerability" - are you saying upstream is vulnerable in some way, while perhaps you (XenServer) are not? In general I don't think I view downstream decisions as a driving factor for what upstream does, when the result is deliberately different behavior from upstream.
Quoted 2 lines
Also,
dom0_paging_pages()isn't a trivial calculation, so should be called once and cached.
Sure, can do that. You did notice though that all I did is take PVH's similar code?
Jan
Re: [PATCH 4/4] x86/PV: properly set shadow allocation for Dom0
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
Leaving shadow setup just to the L1TF tasklet means running Dom0 on a minimally acceptable shadow memory pool, rather than what normally would be used (also, for example, for PVH). Populate the pool before triggering the tasklet, on a best effort basis (again like done for PVH).
Signed-off-by Jan Beulich <[email protected]>
Quoted 6 lines · Jan Beulich
The code building PVH Dom0 made use of sequences of P2M changes which are disallowed as of XSA-378. First of all population of the first Mb of memory needs to be redone. Then, largely as a workaround, checking introduced by XSA-378 needs to be slightly relaxed.
Quoted 9 lines
Note that with these adjustments I get Dom0 to start booting on my development system, but the Dom0 kernel then gets stuck. Since it was the first time for me to try PVH Dom0 in this context (see below for why I was hesitant), I cannot tell yet whether this is due further fallout from the XSA, or some further unrelated problem. Dom0's BSP is in
VPF_blockedstate while all APs are still inVPF_down. The 'd' debug key, unhelpfully, doesn't produce any output, so it's non-trivial to check whether (like PV likes to do) Dom0 has panic()ed without leaving any (visible) output.
Correction: I did mean '0' here, producing merely
(XEN) '0' pressed -> dumping Dom0's registers (XEN) *** Dumping Dom0 vcpu#0 state: *** (XEN) *** Dumping Dom0 vcpu#1 state: *** (XEN) *** Dumping Dom0 vcpu#2 state: *** (XEN) *** Dumping Dom0 vcpu#3 state: ***
'd' output supports the "system is idle" that was also visible from 'q' output.
Jan
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
The code building PVH Dom0 made use of sequences of P2M changes which are disallowed as of XSA-378. First of all population of the first Mb of memory needs to be redone. Then, largely as a workaround, checking introduced by XSA-378 needs to be slightly relaxed.
Quoted 6 lines
Quoted 6 lines
Note that with these adjustments I get Dom0 to start booting on my development system, but the Dom0 kernel then gets stuck. Since it was the first time for me to try PVH Dom0 in this context (see below for why I was hesitant), I cannot tell yet whether this is due further fallout from the XSA, or some further unrelated problem.
Iff you have some time could you check without the XSA applied? I have to admit I haven't been testing staging, so it's possible some breakage as slipped in (however osstest seemed fine with it).
Quoted 4 lines
Quoted 4 lines
Dom0's BSP is in
VPF_blockedstate while all APs are still inVPF_down. The 'd' debug key, unhelpfully, doesn't produce any output, so it's non-trivial to check whether (like PV likes to do) Dom0 has panic()ed without leaving any (visible) output.
Not sure it would help much, but maybe you can post the Xen+Linux output?
Do you have iommu debug/verbose enabled to catch iommu faults?
Quoted 10 lines
Correction: I did mean '0' here, producing merely
(XEN) '0' pressed -> dumping Dom0's registers (XEN) *** Dumping Dom0 vcpu#0 state: *** (XEN) *** Dumping Dom0 vcpu#1 state: *** (XEN) *** Dumping Dom0 vcpu#2 state: *** (XEN) *** Dumping Dom0 vcpu#3 state: ***
'd' output supports the "system is idle" that was also visible from 'q' output.
Can you dump the state of the VMCS and see where the IP points to in Linux?
Thanks, Roger.
Quoted 15 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
The code building PVH Dom0 made use of sequences of P2M changes which are disallowed as of XSA-378. First of all population of the first Mb of memory needs to be redone. Then, largely as a workaround, checking introduced by XSA-378 needs to be slightly relaxed.
Quoted 6 lines
Quoted 6 lines
Note that with these adjustments I get Dom0 to start booting on my development system, but the Dom0 kernel then gets stuck. Since it was the first time for me to try PVH Dom0 in this context (see below for why I was hesitant), I cannot tell yet whether this is due further fallout from the XSA, or some further unrelated problem.
Quoted 3 lines
Iff you have some time could you check without the XSA applied? I have to admit I haven't been testing staging, so it's possible some breakage as slipped in (however osstest seemed fine with it).
Well, I'd rather try to use the time to find the actual issue. From osstest being fine I'm kind of inferring this might be machine specific, or this might be due to yet some other of the overly many patches I'm carrying. So if I can't infer anything from the stack once I can actually dump that, I may indeed need to bisect my pile, which would then also include the XSA-378 patches (as I didn't have time to re-base so far).
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Dom0's BSP is in
VPF_blockedstate while all APs are still inVPF_down. The 'd' debug key, unhelpfully, doesn't produce any output, so it's non-trivial to check whether (like PV likes to do) Dom0 has panic()ed without leaving any (visible) output.Not sure it would help much, but maybe you can post the Xen+Linux output?
There's no Linux output yet by that point (and either "earlyprintk=xen" doesn't work in PVH mode, or it's even too early for that). All Xen has to say is
(XEN) Dom0 callback via changed to Direct Vector 0xf3 (XEN) vmx.c:3265:d0v0 RDMSR 0x0000064e unimplemented (XEN) vmx.c:3265:d0v0 RDMSR 0x00000034 unimplemented
Quoted 1 line
Do you have iommu debug/verbose enabled to catch iommu faults?
I'll try to remember to check that, but since Linux hasn't brought up APs yet I don't think there's any device activity just yet.
Quoted 8 lines
Quoted 8 lines
Correction: I did mean '0' here, producing merely
(XEN) '0' pressed -> dumping Dom0's registers (XEN) *** Dumping Dom0 vcpu#0 state: *** (XEN) *** Dumping Dom0 vcpu#1 state: *** (XEN) *** Dumping Dom0 vcpu#2 state: *** (XEN) *** Dumping Dom0 vcpu#3 state: ***
Quoted 5 lines
Quoted 2 lines
'd' output supports the "system is idle" that was also visible from 'q' output.
Can you dump the state of the VMCS and see where the IP points to in Linux?
Both that and the register dumping I have meanwhile working tell me that it's the HLT in default_idle(). IOW Dom0 gives the impression of also being idle, at the first glance. The stack pointer, however, is farther away from the stack top than I would have expected, so it may still have entered default_idle() for other reasons.
The VMCS also told me that the last VM entry was to deliver an interrupt at vector 0xf3 (i.e. the "callback" one).
Jan
Quoted 6 lines · Jan Beulich
Quoted 1 line · Roger Pau Monné
Do you have iommu debug/verbose enabled to catch iommu faults?
I'll try to remember to check that, but since Linux hasn't brought up APs yet I don't think there's any device activity just yet.
No IOMMU faults, as expected.
Jan
Quoted 36 lines · Jan Beulich
Quoted 15 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
The code building PVH Dom0 made use of sequences of P2M changes which are disallowed as of XSA-378. First of all population of the first Mb of memory needs to be redone. Then, largely as a workaround, checking introduced by XSA-378 needs to be slightly relaxed.
Quoted 6 lines
Quoted 6 lines
Note that with these adjustments I get Dom0 to start booting on my development system, but the Dom0 kernel then gets stuck. Since it was the first time for me to try PVH Dom0 in this context (see below for why I was hesitant), I cannot tell yet whether this is due further fallout from the XSA, or some further unrelated problem.
Quoted 3 lines
Iff you have some time could you check without the XSA applied? I have to admit I haven't been testing staging, so it's possible some breakage as slipped in (however osstest seemed fine with it).
Well, I'd rather try to use the time to find the actual issue. From osstest being fine I'm kind of inferring this might be machine specific, or this might be due to yet some other of the overly many patches I'm carrying. So if I can't infer anything from the stack once I can actually dump that, I may indeed need to bisect my pile, which would then also include the XSA-378 patches (as I didn't have time to re-base so far).
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Dom0's BSP is in
VPF_blockedstate while all APs are still inVPF_down. The 'd' debug key, unhelpfully, doesn't produce any output, so it's non-trivial to check whether (like PV likes to do) Dom0 has panic()ed without leaving any (visible) output.Not sure it would help much, but maybe you can post the Xen+Linux output?
Quoted 7 lines
There's no Linux output yet by that point (and either "earlyprintk=xen" doesn't work in PVH mode, or it's even too early for that). All Xen has to say is
(XEN) Dom0 callback via changed to Direct Vector
0xf3(XEN) vmx.c:3265:d0v0 RDMSR0x0000064eunimplemented (XEN) vmx.c:3265:d0v0 RDMSR0x00000034unimplemented
Weird, I don't see why earlyprintk=xen shouldn't work in PVH mode, unless it's not properly wired up. Certainly needs checking and fixing, or else we won't be able to make much progress I think.
Quoted 20 lines
Quoted 1 line
Do you have iommu debug/verbose enabled to catch iommu faults?
I'll try to remember to check that, but since Linux hasn't brought up APs yet I don't think there's any device activity just yet.
Quoted 8 lines
Quoted 8 lines
Correction: I did mean '0' here, producing merely
(XEN) '0' pressed -> dumping Dom0's registers (XEN) *** Dumping Dom0 vcpu#0 state: *** (XEN) *** Dumping Dom0 vcpu#1 state: *** (XEN) *** Dumping Dom0 vcpu#2 state: *** (XEN) *** Dumping Dom0 vcpu#3 state: ***
Quoted 5 lines
Quoted 2 lines
'd' output supports the "system is idle" that was also visible from 'q' output.
Can you dump the state of the VMCS and see where the IP points to in Linux?
Quoted 8 lines
Both that and the register dumping I have meanwhile working tell me that it's the HLT in
default_idle(). IOW Dom0 gives the impression of also being idle, at the first glance. The stack pointer, however, is farther away from the stack top than I would have expected, so it may still have entereddefault_idle()for other reasons.The VMCS also told me that the last VM entry was to deliver an interrupt at vector
0xf3(i.e. the "callback" one).
That's all quite weird. Did dom0 setup the vCPU timer? What version of Linux are you using?
It seems to get stuck very early (or either fail to output anything while booting), which seems unlikely to be related to your specific hardware.
Thanks, Roger.
Quoted 41 lines · Roger Pau Monné
Quoted 40 lines · Jan Beulich
Quoted 15 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
The code building PVH Dom0 made use of sequences of P2M changes which are disallowed as of XSA-378. First of all population of the first Mb of memory needs to be redone. Then, largely as a workaround, checking introduced by XSA-378 needs to be slightly relaxed.
Quoted 6 lines
Quoted 6 lines
Note that with these adjustments I get Dom0 to start booting on my development system, but the Dom0 kernel then gets stuck. Since it was the first time for me to try PVH Dom0 in this context (see below for why I was hesitant), I cannot tell yet whether this is due further fallout from the XSA, or some further unrelated problem.
Quoted 3 lines
Iff you have some time could you check without the XSA applied? I have to admit I haven't been testing staging, so it's possible some breakage as slipped in (however osstest seemed fine with it).
Well, I'd rather try to use the time to find the actual issue. From osstest being fine I'm kind of inferring this might be machine specific, or this might be due to yet some other of the overly many patches I'm carrying. So if I can't infer anything from the stack once I can actually dump that, I may indeed need to bisect my pile, which would then also include the XSA-378 patches (as I didn't have time to re-base so far).
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Dom0's BSP is in
VPF_blockedstate while all APs are still inVPF_down. The 'd' debug key, unhelpfully, doesn't produce any output, so it's non-trivial to check whether (like PV likes to do) Dom0 has panic()ed without leaving any (visible) output.Not sure it would help much, but maybe you can post the Xen+Linux output?
There's no Linux output yet by that point (and either "earlyprintk=xen" doesn't work in PVH mode, or it's even too early for that). All Xen has to say is
Quoted 7 lines
Quoted 3 lines
(XEN) Dom0 callback via changed to Direct Vector
0xf3(XEN) vmx.c:3265:d0v0 RDMSR0x0000064eunimplemented (XEN) vmx.c:3265:d0v0 RDMSR0x00000034unimplementedWeird, I don't see why earlyprintk=xen shouldn't work in PVH mode, unless it's not properly wired up. Certainly needs checking and fixing, or else we won't be able to make much progress I think.
Right - I'm intending to check this, including whether at least xen_raw_console_write() would work.
Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
Quoted 8 lines
Correction: I did mean '0' here, producing merely
(XEN) '0' pressed -> dumping Dom0's registers (XEN) *** Dumping Dom0 vcpu#0 state: *** (XEN) *** Dumping Dom0 vcpu#1 state: *** (XEN) *** Dumping Dom0 vcpu#2 state: *** (XEN) *** Dumping Dom0 vcpu#3 state: ***
Quoted 5 lines
Quoted 2 lines
'd' output supports the "system is idle" that was also visible from 'q' output.
Can you dump the state of the VMCS and see where the IP points to in Linux?
Both that and the register dumping I have meanwhile working tell me that it's the HLT in
default_idle(). IOW Dom0 gives the impression of also being idle, at the first glance. The stack pointer, however, is farther away from the stack top than I would have expected, so it may still have entereddefault_idle()for other reasons.
Quoted 4 lines
Quoted 2 lines
The VMCS also told me that the last VM entry was to deliver an interrupt at vector
0xf3(i.e. the "callback" one).That's all quite weird. Did dom0 setup the vCPU timer?
Ah - I had meant to check active timers, but then forgot. Otoh I thought I could observe vCPU0 waking up from HLT, as RIP in the registers dumped has been pointing either at it or right past it. Now that I write this I'm wondering though whether that's an artifact rather than reflection of something that's really happening, in particular because of this
(XEN) RSP = 0xffffffff81c03eb8 (0xffffffff81c03eb8) RIP = 0xffffffff814be422 (0xffffffff814be423)
in the VMCS dump.
Quoted 1 line
What version of Linux are you using?
5.13.2; didn't get around to switching to 5.14 yet, but I also don't expect this to make a difference.
Quoted 3 lines
It seems to get stuck very early (or either fail to output anything while booting), which seems unlikely to be related to your specific hardware.
Well, it can't be extremely early - I see the ACPI IRQ getting set up (from "iommu=debug" output mentioning GSI 9), and I see PCI device BARs being played with (from debug messages I had added to vPCI to monitor what P2M adjustments are being requested). As said on another sub-thread, I get all the way through start_kernel() and rest_init(), just that apparently some of the steps don't do what they're supposed to do.
I'm meanwhile wondering whether I'm using a badly configured kernel, i.e. whether there are any Kconfig settings which I ought to enable, but which aren't "select"-ed nor have proper "depends on". What I did is simply take my XEN_PV=y config, replacing that by XEN_PVH=y. I did observe that this let XEN_DOM0 go off, but according to my checking (at the time) nothing this crucial should have been affected by that.
Jan
Quoted 6 lines · Jan Beulich
The code building PVH Dom0 made use of sequences of P2M changes which are disallowed as of XSA-378. First of all population of the first Mb of memory needs to be redone. Then, largely as a workaround, checking introduced by XSA-378 needs to be slightly relaxed.
Quoted 9 lines
Note that with these adjustments I get Dom0 to start booting on my development system, but the Dom0 kernel then gets stuck. Since it was the first time for me to try PVH Dom0 in this context (see below for why I was hesitant), I cannot tell yet whether this is due further fallout from the XSA, or some further unrelated problem. Dom0's BSP is in
VPF_blockedstate while all APs are still inVPF_down. The '0' debug key, unhelpfully, doesn't produce any output, so it's non-trivial to check whether (like PV likes to do) Dom0 has panic()ed without leaving any (visible) output.
Having made '0' work at least partly, I can now see that Dom0's vCPU0 enters its idle loop after having gone through all normal initialization. Clearly certain things must not have worked as intended (no APs booted, no drivers loaded afaict), but I'm having a hard time seeing how to find out what that might be when there's no output at all. PV Dom0 does not require any special command line option to do output to both the VGA console and through hvc_xen (making its output also go to the serial log) - is this perhaps different for PVH? I couldn't find anything under docs/ ...
Jan
Quoted 17 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
The code building PVH Dom0 made use of sequences of P2M changes which are disallowed as of XSA-378. First of all population of the first Mb of memory needs to be redone. Then, largely as a workaround, checking introduced by XSA-378 needs to be slightly relaxed.
Quoted 9 lines
Note that with these adjustments I get Dom0 to start booting on my development system, but the Dom0 kernel then gets stuck. Since it was the first time for me to try PVH Dom0 in this context (see below for why I was hesitant), I cannot tell yet whether this is due further fallout from the XSA, or some further unrelated problem. Dom0's BSP is in
VPF_blockedstate while all APs are still inVPF_down. The '0' debug key, unhelpfully, doesn't produce any output, so it's non-trivial to check whether (like PV likes to do) Dom0 has panic()ed without leaving any (visible) output.
Quoted 10 lines
Having made '0' work at least partly, I can now see that Dom0's vCPU0 enters its idle loop after having gone through all normal initialization. Clearly certain things must not have worked as intended (no APs booted, no drivers loaded afaict), but I'm having a hard time seeing how to find out what that might be when there's no output at all. PV Dom0 does not require any special command line option to do output to both the VGA console and through
hvc_xen(making its output also go to the serial log) - is this perhaps different for PVH? I couldn't find anything under docs/ ...
Did you add earlyprintk=xen to the dom0 boot parameters?
Juergen
Quoted 29 lines · Juergen Gross
Quoted 17 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
The code building PVH Dom0 made use of sequences of P2M changes which are disallowed as of XSA-378. First of all population of the first Mb of memory needs to be redone. Then, largely as a workaround, checking introduced by XSA-378 needs to be slightly relaxed.
Quoted 9 lines
Note that with these adjustments I get Dom0 to start booting on my development system, but the Dom0 kernel then gets stuck. Since it was the first time for me to try PVH Dom0 in this context (see below for why I was hesitant), I cannot tell yet whether this is due further fallout from the XSA, or some further unrelated problem. Dom0's BSP is in
VPF_blockedstate while all APs are still inVPF_down. The '0' debug key, unhelpfully, doesn't produce any output, so it's non-trivial to check whether (like PV likes to do) Dom0 has panic()ed without leaving any (visible) output.Quoted 10 lines
Having made '0' work at least partly, I can now see that Dom0's vCPU0 enters its idle loop after having gone through all normal initialization. Clearly certain things must not have worked as intended (no APs booted, no drivers loaded afaict), but I'm having a hard time seeing how to find out what that might be when there's no output at all. PV Dom0 does not require any special command line option to do output to both the VGA console and through
hvc_xen(making its output also go to the serial log) - is this perhaps different for PVH? I couldn't find anything under docs/ ...
Quoted 1 line
Did you add earlyprintk=xen to the dom0 boot parameters?
Yes (I did mention this before) - no difference at all. I guess I'll try again, just in case I made a stupid mistake.
Jan