Skip to contentSkip to conversation

x86/shim: don't reserve 640k - 1M region in E820

PATCH In review Sergey Dyasli 3 participants 12 messages Oct 28, 2019 – Oct 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/shim: don't reserve 640k - 1M region in E820

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

Fix this by skipping the region type change for pv-shim mode.

---
The condition can be relaxed to be just !pvh_boot if there are no plans to support VGA MMIO / ROMs for PVH guests.

CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Wei Liu <[email protected]>
CC "Roger Pau Monné" <[email protected]>
CC Juergen Gross <[email protected]>
---
 xen/arch/x86/e820.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/e820.c +3 -2
index 8e8a2c4e1b..54c2ae70c4 100644
@@ -318,9 +318,10 @@ static int __init copy_e820_map(struct e820entry * biosmap, unsigned int nr_map)
 
         /*
          * Some BIOSes claim RAM in the 640k - 1M region.
-         * Not right. Fix it up.
+         * Not right. Fix it up, except for pv-shim case.
          */
-        if (type == E820_RAM) {
+        if ( !(pv_shim && pvh_boot) && type == E820_RAM )
+        {
             if (start < 0x100000ULL && end > 0xA0000ULL) {
                 if (start < 0xA0000ULL)
                     add_memory_region(start, 0xA0000ULL-start, type);
Signature · 7 lines
2.17.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 4 lines · Sergey Dyasli

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

This is a PVH property according to your description and according to my understanding. Why would you then ...

Quoted 1 line

Fix this by skipping the region type change for pv-shim mode.

... alter behavior for shim mode only, rather than when booted in PVH mode in general?

Jan

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

#2 lore raw
Quoted 6 lines · Jan Beulich
Quoted 4 lines · Sergey Dyasli

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

Quoted 7 lines

This is a PVH property according to your description and according to my understanding. Why would you then ...

Quoted 1 line

Fix this by skipping the region type change for pv-shim mode.

... alter behavior for shim mode only, rather than when booted in PVH mode in general?

This is just me being cautious.

My original email does have this text after ---
"The condition can be relaxed to be just !pvh_boot if there are no plans to support VGA MMIO / ROMs for PVH guests."

I wanted to check with the community about this first.

Thanks,
Sergey

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

#3 lore raw
Quoted 12 lines · Sergey Dyasli
Quoted 11 lines · Jan Beulich
Quoted 4 lines · Sergey Dyasli

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

This is a PVH property according to your description and according to my understanding. Why would you then ...

Quoted 1 line

Fix this by skipping the region type change for pv-shim mode.

Quoted 8 lines
Quoted 2 lines

... alter behavior for shim mode only, rather than when booted in PVH mode in general?

This is just me being cautious.

My original email does have this text after ---
"The condition can be relaxed to be just !pvh_boot if there are no plans to support VGA MMIO / ROMs for PVH guests."

I doubt emulated ones are intended to be supported, but of course a graphics card could be passed through. Iirc passthrough is a pending work item still anyway for PVH, so dealing with the case right now may not even be necessary.

Jan

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

#4 lore raw
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Sergey Dyasli
Quoted 11 lines · Jan Beulich
Quoted 4 lines · Sergey Dyasli

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

This is a PVH property according to your description and according to my understanding. Why would you then ...

Quoted 1 line

Fix this by skipping the region type change for pv-shim mode.

... alter behavior for shim mode only, rather than when booted in PVH mode in general?

This is just me being cautious.

Quoted 7 lines
Quoted 3 lines

My original email does have this text after ---
"The condition can be relaxed to be just !pvh_boot if there are no plans to support VGA MMIO / ROMs for PVH guests."

I doubt emulated ones are intended to be supported, but of course a graphics card could be passed through. Iirc passthrough is a pending work item still anyway for PVH, so dealing with the case right now may not even be necessary.

The bug is Xen blindly presuming that a missing hole "must be a firmware bug".

I can believe that there may have been systems decades ago which got this wrong, but tbh I doubt it applies to 64bit-capable systems, considering how standardised things were by then.

I'd just delete this whole piece of logic and call it done.

~Andrew

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

#5 lore raw
Quoted 24 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Sergey Dyasli
Quoted 11 lines · Jan Beulich
Quoted 4 lines · Sergey Dyasli

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

This is a PVH property according to your description and according to my understanding. Why would you then ...

Quoted 1 line

Fix this by skipping the region type change for pv-shim mode.

... alter behavior for shim mode only, rather than when booted in PVH mode in general?

This is just me being cautious.

Quoted 7 lines
Quoted 3 lines

My original email does have this text after ---
"The condition can be relaxed to be just !pvh_boot if there are no plans to support VGA MMIO / ROMs for PVH guests."

I doubt emulated ones are intended to be supported, but of course a graphics card could be passed through. Iirc passthrough is a pending work item still anyway for PVH, so dealing with the case right now may not even be necessary.

Quoted 8 lines

The bug is Xen blindly presuming that a missing hole "must be a firmware bug".

I can believe that there may have been systems decades ago which got this wrong, but tbh I doubt it applies to 64bit-capable systems, considering how standardised things were by then.

I'd just delete this whole piece of logic and call it done.

Well, I could see use being less aggressive here, but firmware (if there is firmware, i.e. everything except PVH) claiming there to be RAM immediately below the 1M boundary is a pretty good sign of something being wrong. There _ought_ to be ROM at that address. Otoh there were even ways in older chipsets to make RAM appear at address ranges not used by option ROMs, so the logic we currently have goes too far potentially even on bare metal.

So while I'm all for relaxing, I don't think I can support outright deletion.

Jan

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

#6 lore raw
Quoted 40 lines · Jan Beulich
Quoted 23 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Sergey Dyasli
Quoted 11 lines · Jan Beulich
Quoted 4 lines · Sergey Dyasli

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

This is a PVH property according to your description and according to my understanding. Why would you then ...

Quoted 1 line

Fix this by skipping the region type change for pv-shim mode.

... alter behavior for shim mode only, rather than when booted in PVH mode in general?

This is just me being cautious.

Quoted 7 lines
Quoted 3 lines

My original email does have this text after ---
"The condition can be relaxed to be just !pvh_boot if there are no plans to support VGA MMIO / ROMs for PVH guests."

I doubt emulated ones are intended to be supported, but of course a graphics card could be passed through. Iirc passthrough is a pending work item still anyway for PVH, so dealing with the case right now may not even be necessary.

Quoted 8 lines

The bug is Xen blindly presuming that a missing hole "must be a firmware bug".

I can believe that there may have been systems decades ago which got this wrong, but tbh I doubt it applies to 64bit-capable systems, considering how standardised things were by then.

I'd just delete this whole piece of logic and call it done.

Well, I could see use being less aggressive here, but firmware (if there is firmware, i.e. everything except PVH) claiming there to be RAM immediately below the 1M boundary is a pretty good sign of something being wrong. There _ought_ to be ROM at that address. Otoh there were even ways in older chipsets to make RAM appear at address ranges not used by option ROMs, so the logic we currently have goes too far potentially even on bare metal.

Quoted 2 lines

So while I'm all for relaxing, I don't think I can support outright deletion.

For now, how about cpu_has_hypervisor ?

Whatever the virtual environment, we should trust the provided memory map.

~Andrew

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

#7 lore raw
Quoted 41 lines · Andrew Cooper
Quoted 40 lines · Jan Beulich
Quoted 23 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Sergey Dyasli
Quoted 11 lines · Jan Beulich
Quoted 4 lines · Sergey Dyasli

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

This is a PVH property according to your description and according to my understanding. Why would you then ...

Quoted 1 line

Fix this by skipping the region type change for pv-shim mode.

... alter behavior for shim mode only, rather than when booted in PVH mode in general?

This is just me being cautious.

Quoted 7 lines
Quoted 3 lines

My original email does have this text after ---
"The condition can be relaxed to be just !pvh_boot if there are no plans to support VGA MMIO / ROMs for PVH guests."

I doubt emulated ones are intended to be supported, but of course a graphics card could be passed through. Iirc passthrough is a pending work item still anyway for PVH, so dealing with the case right now may not even be necessary.

Quoted 8 lines

The bug is Xen blindly presuming that a missing hole "must be a firmware bug".

I can believe that there may have been systems decades ago which got this wrong, but tbh I doubt it applies to 64bit-capable systems, considering how standardised things were by then.

I'd just delete this whole piece of logic and call it done.

Well, I could see use being less aggressive here, but firmware (if there is firmware, i.e. everything except PVH) claiming there to be RAM immediately below the 1M boundary is a pretty good sign of something being wrong. There _ought_ to be ROM at that address. Otoh there were even ways in older chipsets to make RAM appear at address ranges not used by option ROMs, so the logic we currently have goes too far potentially even on bare metal.

Quoted 6 lines
Quoted 2 lines

So while I'm all for relaxing, I don't think I can support outright deletion.

For now, how about cpu_has_hypervisor ?

Whatever the virtual environment, we should trust the provided memory map.

Hmm, yes, this sounds reasonable.

Jan

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

#8 lore raw
In reply to Andrew Cooper
Quoted 41 lines · Andrew Cooper
Quoted 40 lines · Jan Beulich
Quoted 23 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Sergey Dyasli
Quoted 11 lines · Jan Beulich
Quoted 4 lines · Sergey Dyasli

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

This is a PVH property according to your description and according to my understanding. Why would you then ...

Quoted 1 line

Fix this by skipping the region type change for pv-shim mode.

... alter behavior for shim mode only, rather than when booted in PVH mode in general?

This is just me being cautious.

Quoted 7 lines
Quoted 3 lines

My original email does have this text after ---
"The condition can be relaxed to be just !pvh_boot if there are no plans to support VGA MMIO / ROMs for PVH guests."

I doubt emulated ones are intended to be supported, but of course a graphics card could be passed through. Iirc passthrough is a pending work item still anyway for PVH, so dealing with the case right now may not even be necessary.

Quoted 8 lines

The bug is Xen blindly presuming that a missing hole "must be a firmware bug".

I can believe that there may have been systems decades ago which got this wrong, but tbh I doubt it applies to 64bit-capable systems, considering how standardised things were by then.

I'd just delete this whole piece of logic and call it done.

Well, I could see use being less aggressive here, but firmware (if there is firmware, i.e. everything except PVH) claiming there to be RAM immediately below the 1M boundary is a pretty good sign of something being wrong. There _ought_ to be ROM at that address. Otoh there were even ways in older chipsets to make RAM appear at address ranges not used by option ROMs, so the logic we currently have goes too far potentially even on bare metal.

Quoted 6 lines
Quoted 2 lines

So while I'm all for relaxing, I don't think I can support outright deletion.

For now, how about cpu_has_hypervisor ?

Whatever the virtual environment, we should trust the provided memory map.

Unfortunately, this plan has failed: init_e820() is called way before early_cpu_init() and testing cpu_has_hypervisor is meaningless there.

I guess I'll go for !pvh_boot check for now.

--
Thanks,
Sergey

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

#9 lore raw
Quoted 44 lines · Sergey Dyasli
Quoted 43 lines · Andrew Cooper
Quoted 42 lines · Jan Beulich
Quoted 23 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Sergey Dyasli
Quoted 11 lines · Jan Beulich
Quoted 4 lines · Sergey Dyasli

Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode.

This is a PVH property according to your description and according to my understanding. Why would you then ...

Quoted 1 line

Fix this by skipping the region type change for pv-shim mode.

... alter behavior for shim mode only, rather than when booted in PVH mode in general?

This is just me being cautious.

Quoted 7 lines
Quoted 3 lines

My original email does have this text after ---
"The condition can be relaxed to be just !pvh_boot if there are no plans to support VGA MMIO / ROMs for PVH guests."

I doubt emulated ones are intended to be supported, but of course a graphics card could be passed through. Iirc passthrough is a pending work item still anyway for PVH, so dealing with the case right now may not even be necessary.

Quoted 8 lines

The bug is Xen blindly presuming that a missing hole "must be a firmware bug".

I can believe that there may have been systems decades ago which got this wrong, but tbh I doubt it applies to 64bit-capable systems, considering how standardised things were by then.

I'd just delete this whole piece of logic and call it done.

Well, I could see use being less aggressive here, but firmware (if there is firmware, i.e. everything except PVH) claiming there to be RAM immediately below the 1M boundary is a pretty good sign of something being wrong. There _ought_ to be ROM at that address. Otoh there were even ways in older chipsets to make RAM appear at address ranges not used by option ROMs, so the logic we currently have goes too far potentially even on bare metal.

So while I'm all for relaxing, I don't think I can support outright deletion.

Quoted 7 lines
Quoted 3 lines

For now, how about cpu_has_hypervisor ?

Whatever the virtual environment, we should trust the provided memory map.

Unfortunately, this plan has failed: init_e820() is called way before early_cpu_init() and testing cpu_has_hypervisor is meaningless there.

I guess I'll go for !pvh_boot check for now.

Opencode it with cpuid_ecx(1) for now, as we've done elsewhere.

I've got a patch in my not-progressing-very-quickly series to remove the boot time mapping at 0 which cleans up early CPUID handling so this can turn into cpu_has_hypervisor, but that is definitely post-4.13 material right now.

~Andrew

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

#10 lore raw
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Sergey Dyasli
Quoted 3 lines · Andrew Cooper

For now, how about cpu_has_hypervisor ?

Whatever the virtual environment, we should trust the provided memory map.

Unfortunately, this plan has failed: init_e820() is called way before early_cpu_init() and testing cpu_has_hypervisor is meaningless there.

Quoted 8 lines
Quoted 1 line

I guess I'll go for !pvh_boot check for now.

Opencode it with cpuid_ecx(1) for now, as we've done elsewhere.

I've got a patch in my not-progressing-very-quickly series to remove the boot time mapping at 0 which cleans up early CPUID handling so this can turn into cpu_has_hypervisor, but that is definitely post-4.13 material right now.

Looking closely at early_cpu_init(), I don't see anything there that would prevent placing it near the top of __start_xen(). It works for pv-shim, but I need to also do some bare metal testing with this change.

Do you know of anything that would prevent it?

--
Thanks,
Sergey

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

#11 lore raw
Quoted 16 lines · Sergey Dyasli
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Sergey Dyasli
Quoted 3 lines · Andrew Cooper

For now, how about cpu_has_hypervisor ?

Whatever the virtual environment, we should trust the provided memory map.

Unfortunately, this plan has failed: init_e820() is called way before early_cpu_init() and testing cpu_has_hypervisor is meaningless there.

Quoted 7 lines
Quoted 1 line

I guess I'll go for !pvh_boot check for now.

Opencode it with cpuid_ecx(1) for now, as we've done elsewhere.

I've got a patch in my not-progressing-very-quickly series to remove the boot time mapping at 0 which cleans up early CPUID handling so this can turn into cpu_has_hypervisor, but that is definitely post-4.13 material right now.

Quoted 5 lines

Looking closely at early_cpu_init(), I don't see anything there that would prevent placing it near the top of __start_xen(). It works for pv-shim, but I need to also do some bare metal testing with this change.

Do you know of anything that would prevent it?

Yes - microcode loading.  That sequence of things in __start_xen() is very position sensitive.

~Andrew

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