x86/shim: minor fixes to the pv-shim mode
cover x86/shim: minor fixes to the pv-shim mode
Hello,
This series includes some miscellaneous fixes for the pv-shim mode, specially regarding the handling of the memory map.
Thanks, Roger.
Roger Pau Monne (4):
x86/e820: introduce a function to remove ranges from e820 x86/e820: do not fixup memmap in copy_e820_map
x86/e820: assume memmap provided when booted as a Xen guest is correct x86/shim: only mark special pages as RAM in pvshim mode
xen/arch/x86/e820.c | 87 +++++++++++++++++++++++++++------ xen/arch/x86/guest/xen.c | 42 ---------------- xen/arch/x86/pv/shim.c | 43 ++++++++++++++++ xen/common/page_alloc.c | 4 +- xen/include/asm-x86/e820.h | 2 + xen/include/asm-x86/guest/xen.h | 13 ----- xen/include/asm-x86/pv/shim.h | 12 +++++ 7 files changed, 130 insertions(+), 73 deletions(-)
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/4 x86/e820: introduce a function to remove ranges from e820
This function is based on the Linux e820__range_remove function, modified to fit Xen coding style.
---
--- xen/arch/x86/e820.c | 56 ++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/e820.h | 2 ++ 2 files changed, 58 insertions(+)
xen/arch/x86/e820.c +56 -0
@@ -599,6 +599,62 @@ int __init e820_add_range(return 1 ; } +uint64_t __init e820_remove_range (struct e820map *e820,uint64_t start, +uint64_t end,uint32_t type,bool check_type) +{ +unsigned int i; +uint64_t real_removed_size =0 ; + +ASSERT (end > start); + +for ( i =0 ; i < e820->nr_map; i++ ) + { +struct e820entry *entry = &e820->map[i]; +uint64_t final_start, final_end, entry_end; + +if ( check_type && entry->type != type ) +continue ; + + entry_end = entry->addr + entry->size; + +/* Completely covered? */ +if ( entry->addr >= start && entry_end <= end ) + { + real_removed_size += entry->size; +memset (entry,0 ,sizeof (*entry)); +continue ; + } + +/* Is the new range completely covered? */ +if (entry->addr < start && entry_end > end) { +e820_add_range (e820, end, entry_end, entry->type); + entry->size = start - entry->addr; + real_removed_size += end - start; +continue ; + } + +/* Partially covered: */ + final_start =max (start, entry->addr); + final_end =min (end, entry_end); +if ( final_start >= final_end ) +continue ; + + real_removed_size += final_end - final_start; + +/* +* Left range could be head or tail, so need to update +* the size first: +*/ + entry->size -= final_end - final_start; +if ( entry->addr < final_start ) +continue ; + + entry->addr = final_end; + } + +return real_removed_size; +} +int __init e820_change_range_type (struct e820map *e820,uint64_t s,uint64_t e,uint32_t orig_type,uint32_t new_type)
xen/include/asm-x86/e820.h +2 -0
@@ -31,6 +31,8 @@ extern int e820_change_range_type( uint32_t orig_type, uint32_t new_type);extern int e820_add_range (struct e820map *,uint64_t s,uint64_t e,uint32_t type); +extern uint64_t e820_remove_range (struct e820map *e820,uint64_t start, +uint64_t end,uint32_t type,bool check_type);extern unsigned long init_e820 (const char *,struct e820map *);extern struct e820map e820;extern struct e820map e820_raw;
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/4] x86/e820: introduce a function to remove ranges from e820
Quoted 36 lines · Roger Pau Monne
This function is based on the Linux
e820__range_removefunction, modified to fit Xen coding style.Signed-off-by Roger Pau Monné <[email protected]>---
--- xen/arch/x86/e820.c | 56 ++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/e820.h | 2 ++ 2 files changed, 58 insertions(+)xen/arch/x86/e820.c +18
-0@@ -599,6 +599,62 @@ int __init e820_add_range(return 1 ; } +uint64_t __init e820_remove_range (struct e820map *e820,uint64_t start, +uint64_t end,uint32_t type,bool check_type) +{ +unsigned int i; +uint64_t real_removed_size =0 ; + +ASSERT (end > start); + +for ( i =0 ; i < e820->nr_map; i++ ) + { +struct e820entry *entry = &e820->map[i]; +uint64_t final_start, final_end, entry_end; + +if ( check_type && entry->type != type ) +continue ; + + entry_end = entry->addr + entry->size; +
xen/arch/x86/e820.c int __init e820_add_range( · line 629
Quoted 10 lines
xen/arch/x86/e820.c +10
-0+/* Completely covered? */ +if ( entry->addr >= start && entry_end <= end ) + { + real_removed_size += entry->size; +memset (entry,0 ,sizeof (*entry)); +continue ; + } + +/* Is the new range completely covered? */ +if (entry->addr < start && entry_end > end) {
One remaining piece of Linux style. Can be fixed on commit.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/4 x86/e820: do not fixup memmap in copy_e820_map
In reply to Roger Pau MonneAnd instead introduce a new helper to mark the low 1MB VGA/ROM region as reserved. Note this might be a slight change from current functionality where copy_e820_map would just leave a hole in the [640KB, 1MB) region if it was found to be reported as RAM in the memory map.
No functional change expected overall.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
--- xen/arch/x86/e820.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
xen/arch/x86/e820.c +12 -14
@@ -320,20 +320,6 @@ static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)if (start > end)return -1 ; -/* -* Some BIOSes claim RAM in the 640k - 1M region. -* Not right. Fix it up. -*/ -if (type ==E820_RAM ) { -if (start <0x100000ULL && end >0xA0000ULL ) { -if (start <0xA0000ULL ) -add_memory_region (start,0xA0000ULL -start, type); -if (end <=0x100000ULL ) -continue ; - start =0x100000ULL ; - size = end - start; - } - }add_memory_region (start, size, type); }while (biosmap++,--nr_map);return 0 ;
@@ -510,6 +496,12 @@ static void __init reserve_dmi_region(void) } } +static void __init reserve_vga_region (void ) +{ +/* Remove any RAM regions from the VGA hole. */ +e820_remove_range (&e820,KB (640 ),MB (1 ) -1 ,E820_RAM , true); +} +static void __init machine_specific_memory_setup (struct e820map *raw) {unsigned long mpt_limit, ro_mpt_limit;
@@ -545,6 +537,12 @@ static void __init machine_specific_memory_setup(struct e820map *raw)reserve_dmi_region (); +/* +* Some BIOSes claim RAM in the 640k - 1M region. +* Not right. Fix it up. +*/ +reserve_vga_region (); + top_of_ram =mtrr_top_of_ram ();if ( top_of_ram )clip_to_limit (top_of_ram,"MTRRs do not cover all of memory." );
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/4] x86/e820: do not fixup memmap in copy_e820_map
Quoted 8 lines · Roger Pau Monne
And instead introduce a new helper to mark the low 1MB VGA/ROM region as reserved. Note this might be a slight change from current functionality where
copy_e820_mapwould just leave a hole in the [640KB, 1MB) region if it was found to be reported as RAM in the memory map.No functional change expected overall.
Signed-off-by Roger Pau Monné <[email protected]>
I think your commit message is stale from the private v1.
Otherwise, LGTM.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/4 x86/e820: assume memmap provided when booted as a Xen guest is correct
In reply to Roger Pau MonneThis implies there's no need to forcefully reserve the VGA MMIO region, since the memory map provided will be correct.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
--- xen/arch/x86/e820.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
xen/arch/x86/e820.c +6 -5
@@ -537,11 +537,12 @@ static void __init machine_specific_memory_setup(struct e820map *raw)reserve_dmi_region (); -/* -* Some BIOSes claim RAM in the 640k - 1M region. -* Not right. Fix it up. -*/ -reserve_vga_region (); +if ( !xen_guest ) +/* +* Some BIOSes claim RAM in the 640k - 1M region. +* Not right. Fix it up. +*/ +reserve_vga_region (); top_of_ram =mtrr_top_of_ram ();if ( top_of_ram )
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/4] x86/e820: assume memmap provided when booted as a Xen guest is correct
Quoted 18 lines · Roger Pau Monne
This implies there's no need to forcefully reserve the VGA MMIO region, since the memory map provided will be correct.
Reported-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>--- xen/arch/x86/e820.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)xen/arch/x86/e820.c +0
-0
xen/arch/x86/e820.c static void __init machine_specific_memory_setup(struct e820map *raw) · line 540
Quoted 9 lines
xen/arch/x86/e820.c +1
-5@@ -537,11 +537,12 @@ static void __init machine_specific_memory_setup(struct e820map *raw)reserve_dmi_region (); -/* -* Some BIOSes claim RAM in the 640k - 1M region. -* Not right. Fix it up. -*/ -reserve_vga_region (); +if ( !xen_guest )
Having thought on this some more, how about using !cpu_has_hypervisor here? Booting PVH under Xen isn't the only case where we won't have a legacy VGA range. HyperV gen-2 VMs are the next most obvious candidate.
~Andrew
xen/arch/x86/e820.c static void __init machine_specific_memory_setup(struct e820map *raw) · line 548
Quoted 8 lines
xen/arch/x86/e820.c +5
-0+/* +* Some BIOSes claim RAM in the 640k - 1M region. +* Not right. Fix it up. +*/ +reserve_vga_region (); top_of_ram =mtrr_top_of_ram ();if ( top_of_ram )
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/4] x86/e820: assume memmap provided when booted as a Xen guest is correct
Quoted 22 lines · Andrew Cooper
Quoted 21 lines · Roger Pau Monne
This implies there's no need to forcefully reserve the VGA MMIO region, since the memory map provided will be correct.
Reported-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>--- xen/arch/x86/e820.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)xen/arch/x86/e820.c +0
-0@@ -537,11 +537,12 @@ static void __init machine_specific_memory_setup(struct e820map *raw)reserve_dmi_region ();
Quoted 10 lines
xen/arch/x86/e820.c static void __init machine_specific_memory_setup(struct e820map *raw) · line 540
Quoted 6 lines
xen/arch/x86/e820.c +1
-5-/* -* Some BIOSes claim RAM in the 640k - 1M region. -* Not right. Fix it up. -*/ -reserve_vga_region (); +if ( !xen_guest )Having thought on this some more, how about using !cpu_has_hypervisor here? Booting PVH under Xen isn't the only case where we won't have a legacy VGA range. HyperV gen-2 VMs are the next most obvious candidate.
I think it's OK to assume that the memory map provided by an hypervisor must be correct, let me send v2.
Note that booting the Xen kernel under HyperV gen-2 is quite trivial, the main problem is getting the dom0 kernel to work in Xen PV mode while using the HyperV extensions.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/4 x86/shim: only mark special pages as RAM in pvshim mode
In reply to Roger Pau MonneWhen running Xen as a guest it's not necessary to mark such pages as RAM because they won't be assigned to the initial domain memory map.
While there move the functions to the PV shim specific file and rename them accordingly.
No functional change expected.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
--- xen/arch/x86/e820.c | 4 +-- xen/arch/x86/guest/xen.c | 42 -------------------------------- xen/arch/x86/pv/shim.c | 43 +++++++++++++++++++++++++++++++++ xen/common/page_alloc.c | 4 +-- xen/include/asm-x86/guest/xen.h | 13 ---------- xen/include/asm-x86/pv/shim.h | 12 +++++++++ 6 files changed, 59 insertions(+), 59 deletions(-)
xen/arch/x86/e820.c +2 -2
@@ -755,8 +755,8 @@ unsigned long __init init_e820(const char *str, struct e820map *raw)machine_specific_memory_setup (raw); -if ( xen_guest ) -hypervisor_fixup_e820 (&e820); +if ( pv_shim ) +pv_shim_fixup_e820 (&e820);printk ("%s RAM map:\n" , str);print_e820_memory_map (e820.map, e820.nr_map);
xen/arch/x86/guest/xen.c +0 -42
54 lines not on this page · raw message
xen/arch/x86/pv/shim.c +43 -0
55 lines not on this page · raw message
xen/common/page_alloc.c +2 -2
@@ -348,9 +348,9 @@ void __init init_boot_pages(paddr_t ps, paddr_t pe) } } -if ( xen_guest ) +if ( pv_shim ) { - badpage =hypervisor_reserved_pages (&array_size); + badpage =pv_shim_reserved_pages (&array_size);if ( badpage ) {for ( i =0 ; i < array_size; i++ )
xen/include/asm-x86/guest/xen.h +0 -13
@@ -36,8 +36,6 @@ void hypervisor_setup(void);void hypervisor_ap_setup (void );int hypervisor_alloc_unused_page (mfn_t *mfn);int hypervisor_free_unused_page (mfn_t mfn); -void hypervisor_fixup_e820 (struct e820map *e820); -const struct platform_bad_page *hypervisor_reserved_pages (unsigned int *size);uint32_t hypervisor_cpuid_base (void );void hypervisor_resume (void );
@@ -60,17 +58,6 @@ static inline void hypervisor_ap_setup(void)ASSERT_UNREACHABLE (); } -static inline void hypervisor_fixup_e820 (struct e820map *e820) -{ -ASSERT_UNREACHABLE (); -} - -static inline const struct platform_bad_page *hypervisor_reserved_pages (unsigned int *size) -{ -ASSERT_UNREACHABLE (); -return NULL ; -} -#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */
xen/include/asm-x86/pv/shim.h +12 -0
@@ -43,6 +43,8 @@ void pv_shim_online_memory(unsigned int nr, unsigned int order);void pv_shim_offline_memory (unsigned int nr,unsigned int order);domid_t get_initial_domain_id (void );uint64_t pv_shim_mem (uint64_t avail); +void pv_shim_fixup_e820 (struct e820map *e820); +const struct platform_bad_page *pv_shim_reserved_pages (unsigned int *size);#else
@@ -91,6 +93,16 @@ static inline uint64_t pv_shim_mem(uint64_t avail)ASSERT_UNREACHABLE (); return 0; } +static inline void pv_shim_fixup_e820 (struct e820map *e820) +{ +ASSERT_UNREACHABLE (); +} +static inline const struct platform_bad_page +*pv_shim_reserved_pages (unsigned int *s) +{ +ASSERT_UNREACHABLE (); +return NULL ; +}#endif
Signature · 7 lines
2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 4/4] x86/shim: only mark special pages as RAM in pvshim mode
Quoted 10 lines · Roger Pau Monne
When running Xen as a guest it's not necessary to mark such pages as RAM because they won't be assigned to the initial domain memory map.
While there move the functions to the PV shim specific file and rename them accordingly.
No functional change expected.
Reported-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 4/4] x86/shim: only mark special pages as RAM in pvshim mode
Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Roger Pau Monne
When running Xen as a guest it's not necessary to mark such pages as RAM because they won't be assigned to the initial domain memory map.
While there move the functions to the PV shim specific file and rename them accordingly.
Quoted 6 lines
Quoted 4 lines
No functional change expected.
Reported-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Andrew Cooper <[email protected]>
I think this one can go in (if no one objects) regardless of the rest of the series.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel