x86: improve reporting through XENMEM_machine_memory_map
PATCH 1/1 x86: improve reporting through XENMEM_machine_memory_map
Since Dom0 derives machine address ranges usable for assigning PCI device resources from the output of this sub-hypercall, Xen should make sure it properly reports all ranges not suitable for this (as either reserved or unusable):
- RAM regions excluded via command line option
- memory regions used by Xen itself (LAPIC, IOAPICs)
While the latter should generally already be excluded by the BIOS provided E820 table, this apparently isn't always the case at least for IOAPICs, and with Linux having got changed to account for this it seems to make sense to also do so in Xen.
Generally the HPET range should also be excluded here, but since it isn't being reflected in Dom0's iomem_caps (and can't be, as it's a sub-page range) I wasn't sure whether adding explicit code for doing so would be reasonable.
xen/arch/x86/e820.c +6 -1
@@ -373,7 +373,12 @@ static void __init clip_to_limit(uint64_ ((e820.map[i].addr + e820.map[i].size) <= limit) )continue ; old_limit = e820.map[i].addr + e820.map[i].size; -if ( e820.map[i].addr < limit ) +if (e820_change_range_type (&e820,max (e820.map[i].addr, limit), + old_limit,E820_RAM ,E820_UNUSABLE ) ) + { + i =0 ; + } +else if ( e820.map[i].addr < limit ) { e820.map[i].size = limit - e820.map[i].addr; }
xen/arch/x86/mm.c +70 -10
105 lines not on this page · raw message
xen/common/rangeset.c +23 -0
@@ -251,6 +251,29 @@ int rangeset_contains_range(return contains; } +int rangeset_report_ranges ( +struct rangeset *r,unsigned long s,unsigned long e, +int (*cb)(unsigned long s,unsigned long e,void *),void *ctxt) +{ +struct range *x; +int rc =0 ; + +spin_lock (&r->lock); + +for ( x =find_range (r, s); rc ==0 && x !=NULL ; x =next_range (r, x) ) + { +if ( x->s > e ) +break ; +if ( s > x->e ) +continue ; + rc =cb (max (x->s, s),min (x->e, e), ctxt); + } + +spin_unlock (&r->lock); + +return rc; +} +int rangeset_add_singleton (struct rangeset *r,unsigned long s) {
xen/include/xen/rangeset.h +3 -0
@@ -53,6 +53,9 @@ int __must_check rangeset_remove_range( struct rangeset *r, unsigned long s, unsigned long e);int __must_check rangeset_contains_range (struct rangeset *r,unsigned long s,unsigned long e); +int rangeset_report_ranges ( +struct rangeset *r,unsigned long s,unsigned long e, +int (*cb)(unsigned long s,unsigned long e,void *),void *ctxt);/* Add/remove/query a single number. */ int __must_check rangeset_add_singleton(