Xen Patch Queue
Hi Anthony,
This is my current patch queue for Xen patches.
Please pull.
Alex
The following changes since commit eb47d7c5d96060040931c42773ee07e61e547af9:
Peter Maydell (1):
hw/9118.c: Implement active-low interrupt support
are available in the git repository at:
git://repo.or.cz/qemu/agraf.git xen-next
Anthony PERARD (2):
xen: Add xc_domain_add_to_physmap to xen_interface.
xen: Introduce VGA sync dirty bitmap support
Stefano Stabellini (8):
xen: fix qemu_map_cache with size != MCACHE_BUCKET_SIZE
xen: remove qemu_map_cache_unlock
xen: remove xen_map_block and xen_unmap_block
exec.c: refactor cpu_physical_memory_map
xen: mapcache performance improvements
cirrus_vga: reset lfb_addr after a pci config write if the BAR is unmapped
xen: only track the linear framebuffer
xen: fix interrupt routing
Steven Smith (1):
xen: Add the Xen platform pci device
Makefile.target | 2 + configure | 29 ++++- cpu-common.h | 1 + exec.c | 88 +++++++------- hw/cirrus_vga.c | 5 +- hw/hw.h | 3 + hw/pc.h | 1 - hw/pc_piix.c | 10 +- hw/pci_ids.h | 2 + hw/piix_pci.c | 66 +++++----- hw/xen_common.h | 14 ++ hw/xen_platform.c | 340 +++++++++++++++++++++++++++++++++++++++++++++++++++ trace-events | 4 + xen-all.c | 281 ++++++++++++++++++++++++++++++++++++++++++ xen-mapcache-stub.c | 8 -- xen-mapcache.c | 141 ++++++++++------------ xen-mapcache.h | 16 --- 17 files changed, 826 insertions(+), 185 deletions(-) create mode 100644 hw/xen_platform.c
PATCH 1/11 xen: Add xc_domain_add_to_physmap to xen_interface.
From: Anthony PERARD <[email protected]>
This function will be used to support sync dirty bitmap.
This come with a check against every Xen release, and special implementation for Xen version that doesn't have this specific call.
This function will not be usable with Xen 3.3 because the behavior is different.
--- configure | 29 ++++++++++++++++++++++++++++- hw/xen_common.h | 14 ++++++++++++++ 2 files changed, 42 insertions(+), 1 deletions(-)
configure +28 -1
@@ -1210,6 +1210,7 @@ int main(void) { xc = xc_interface_open(0, 0, 0); xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); xc_gnttab_open(NULL, 0); + xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); return 0; } EOF
@@ -1228,10 +1229,14 @@ EOF # error HVM_MAX_VCPUS not defined #endif int main(void) { + struct xen_add_to_physmap xatp = { + .domid = 0, .space = XENMAPSPACE_gmfn, .idx = 0, .gpfn = 0, + }; xs_daemon_open(); xc_interface_open(); xc_gnttab_open(); xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_memory_op(0, XENMEM_add_to_physmap, &xatp); return 0; } EOF
@@ -1240,7 +1245,29 @@ EOF xen_ctrl_version=400 xen=yes - # Xen 3.3.0, 3.4.0 + # Xen 3.4.0 + elif ( + cat > $TMPC <<EOF +#include <xenctrl.h> +#include <xs.h> +int main(void) { + struct xen_add_to_physmap xatp = { + .domid = 0, .space = XENMAPSPACE_gmfn, .idx = 0, .gpfn = 0, + }; + xs_daemon_open(); + xc_interface_open(); + xc_gnttab_open(); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_memory_op(0, XENMEM_add_to_physmap, &xatp); + return 0; +} +EOF + compile_prog "" "$xen_libs" + ) ; then + xen_ctrl_version=340 + xen=yes + + # Xen 3.3.0 elif ( cat > $TMPC <<EOF #include <xenctrl.h>
hw/xen_common.h +14 -0
@@ -71,6 +71,20 @@ static inline int xc_domain_populate_physmap_exact (xc_handle, domid, nr_extents, extent_order, mem_flags, extent_start); } +static inline int xc_domain_add_to_physmap (int xc_handle,uint32_t domid, +unsigned int space,unsigned long idx, +xen_pfn_t gpfn) +{ +struct xen_add_to_physmap xatp = { + .domid = domid, + .space = space, + .idx = idx, + .gpfn = gpfn, + }; + +return xc_memory_op (xc_handle, XENMEM_add_to_physmap, &xatp); +} +/* Xen 4.1 */ #else
Signature · 1 line
1.6.0.2
PATCH 2/11 xen: Introduce VGA sync dirty bitmap support
In reply to Alexander GrafFrom: Anthony PERARD <[email protected]>
This patch introduces phys memory client for Xen.
Only sync dirty_bitmap and set_memory are actually implemented. migration_log will stay empty for the moment.
Xen can only log one range for bit change, so only the range in the first call will be synced.
--- trace-events | 1 + xen-all.c | 267 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 268 insertions(+), 0 deletions(-)
trace-events +1 -0
@@ -396,6 +396,7 @@ disable milkymist_vgafb_memory_write(uint32_t addr, uint32_t value) "addr %08x v # xen-all.c disable xen_ram_alloc(unsigned long ram_addr, unsigned long size) "requested: %#lx, size %#lx" +disable xen_client_set_memory(uint64_t start_addr, unsigned long size, unsigned long phys_offset, bool log_dirty) "%#"PRIx64" size %#lx, offset %#lx, log_dirty %i" # xen-mapcache.c disable qemu_map_cache(uint64_t phys_addr) "want %#"PRIx64""
xen-all.c +267 -0
297 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 3/11 xen: fix qemu_map_cache with size != MCACHE_BUCKET_SIZE
In reply to Alexander GrafFrom: Stefano Stabellini <[email protected]>
Fix the implementation of qemu_map_cache: correctly support size arguments different from 0 or MCACHE_BUCKET_SIZE.
The new implementation supports locked mapcache entries with size multiple of MCACHE_BUCKET_SIZE. qemu_invalidate_entry can correctly find and unmap these "large" mapcache entries given that the virtual address passed to qemu_invalidate_entry is the same returned by qemu_map_cache when the locked mapcache entry was created.
--- xen-mapcache.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 65 insertions(+), 12 deletions(-)
xen-mapcache.c +65 -12
@@ -43,14 +43,16 @@typedef struct MapCacheEntry {target_phys_addr_t paddr_index;uint8_t *vaddr_base; - DECLARE_BITMAP(valid_mapping, MCACHE_BUCKET_SIZE >> XC_PAGE_SHIFT); +unsigned long *valid_mapping;uint8_t lock; +target_phys_addr_t size;struct MapCacheEntry *next; }MapCacheEntry ;typedef struct MapCacheRev {uint8_t *vaddr_req;target_phys_addr_t paddr_index; +target_phys_addr_t size;QTAILQ_ENTRY (MapCacheRev) next; }MapCacheRev ;
@@ -68,6 +70,15 @@ typedef struct MapCache {static MapCache *mapcache; +static inline int test_bits (int nr,int size,const unsigned long *addr) +{ +unsigned long res =find_next_zero_bit (addr, size + nr, nr); +if (res >= nr + size) +return 1 ; +else +return 0 ; +} +void qemu_map_cache_init (void ) {unsigned long size;
@@ -115,11 +126,15 @@ static void qemu_remap_bucket(MapCacheEntry *entry, err =qemu_mallocz (nb_pfn *sizeof (int ));if (entry->vaddr_base !=NULL ) { -if (munmap (entry->vaddr_base, size) !=0 ) { +if (munmap (entry->vaddr_base, entry->size) !=0 ) {perror ("unmap fails" );exit (-1 ); } } +if (entry->valid_mapping !=NULL ) { +qemu_free (entry->valid_mapping); + entry->valid_mapping =NULL ; + }for (i =0 ; i < nb_pfn; i++) { pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT -XC_PAGE_SHIFT )) + i;
@@ -134,6 +149,9 @@ static void qemu_remap_bucket(MapCacheEntry *entry, entry->vaddr_base = vaddr_base; entry->paddr_index = address_index; + entry->size = size; + entry->valid_mapping = (unsigned long *)qemu_mallocz (sizeof (unsigned long ) * +BITS_TO_LONGS (size >>XC_PAGE_SHIFT ));bitmap_zero (entry->valid_mapping, nb_pfn);for (i =0 ; i < nb_pfn; i++) {
@@ -151,32 +169,47 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, uMapCacheEntry *entry, *pentry =NULL ;target_phys_addr_t address_index = phys_addr >>MCACHE_BUCKET_SHIFT ;target_phys_addr_t address_offset = phys_addr & (MCACHE_BUCKET_SIZE -1 ); +target_phys_addr_t __size = size;trace_qemu_map_cache (phys_addr); -if (address_index == mapcache->last_address_index && !lock) { +if (address_index == mapcache->last_address_index && !lock && !__size) {trace_qemu_map_cache_return (mapcache->last_address_vaddr + address_offset);return mapcache->last_address_vaddr + address_offset; } +/* size is always a multiple of MCACHE_BUCKET_SIZE */ +if ((address_offset + (__size %MCACHE_BUCKET_SIZE )) >MCACHE_BUCKET_SIZE ) + __size +=MCACHE_BUCKET_SIZE ; +if (__size %MCACHE_BUCKET_SIZE ) + __size +=MCACHE_BUCKET_SIZE - (__size %MCACHE_BUCKET_SIZE ); +if (!__size) + __size =MCACHE_BUCKET_SIZE ; + entry = &mapcache->entry[address_index % mapcache->nr_buckets]; -while (entry && entry->lock && entry->paddr_index != address_index && entry->vaddr_base) { +while (entry && entry->lock && entry->vaddr_base && + (entry->paddr_index != address_index || entry->size != __size || + !test_bits (address_offset >>XC_PAGE_SHIFT , size >>XC_PAGE_SHIFT , + entry->valid_mapping))) { pentry = entry; entry = entry->next; }if (!entry) { entry =qemu_mallocz (sizeof (MapCacheEntry)); pentry->next = entry; -qemu_remap_bucket (entry, size ? :MCACHE_BUCKET_SIZE , address_index); +qemu_remap_bucket (entry, __size, address_index); }else if (!entry->lock) {if (!entry->vaddr_base || entry->paddr_index != address_index || - !test_bit (address_offset >>XC_PAGE_SHIFT , entry->valid_mapping)) { -qemu_remap_bucket (entry, size ? :MCACHE_BUCKET_SIZE , address_index); + entry->size != __size || + !test_bits (address_offset >>XC_PAGE_SHIFT , size >>XC_PAGE_SHIFT , + entry->valid_mapping)) { +qemu_remap_bucket (entry, __size, address_index); } } -if (!test_bit (address_offset >>XC_PAGE_SHIFT , entry->valid_mapping)) { +if (!test_bits (address_offset >>XC_PAGE_SHIFT , size >>XC_PAGE_SHIFT , + entry->valid_mapping)) { mapcache->last_address_index =-1 ;trace_qemu_map_cache_return (NULL );return NULL ;
@@ -189,6 +222,7 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, u entry->lock++; reventry->vaddr_req = mapcache->last_address_vaddr + address_offset; reventry->paddr_index = mapcache->last_address_index; + reventry->size = entry->size;QTAILQ_INSERT_HEAD (&mapcache->locked_entries, reventry, next); }
@@ -231,13 +265,16 @@ void qemu_map_cache_unlock(void *buffer)ram_addr_t qemu_ram_addr_from_mapcache (void *ptr) { +MapCacheEntry *entry =NULL , *pentry =NULL ;MapCacheRev *reventry;target_phys_addr_t paddr_index; +target_phys_addr_t size;int found =0 ; QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {if (reventry->vaddr_req == ptr) { paddr_index = reventry->paddr_index; + size = reventry->size; found =1 ;break ; }
@@ -252,7 +289,17 @@ ram_addr_t qemu_ram_addr_from_mapcache(void *ptr)return 0 ; } -return paddr_index <<MCACHE_BUCKET_SHIFT ; + entry = &mapcache->entry[paddr_index % mapcache->nr_buckets]; +while (entry && (entry->paddr_index != paddr_index || entry->size != size)) { + pentry = entry; + entry = entry->next; + } +if (!entry) { +DPRINTF ("Trying to find address %p that is not in the mapcache!\n" , ptr); +return 0 ; + } +return (reventry->paddr_index <<MCACHE_BUCKET_SHIFT ) + + ((unsigned long ) ptr - (unsigned long ) entry->vaddr_base); }void qemu_invalidate_entry (uint8_t *buffer)
@@ -260,6 +307,7 @@ void qemu_invalidate_entry(uint8_t *buffer)MapCacheEntry *entry =NULL , *pentry =NULL ;MapCacheRev *reventry;target_phys_addr_t paddr_index; +target_phys_addr_t size;int found =0 ;if (mapcache->last_address_vaddr == buffer) {
@@ -269,6 +317,7 @@ void qemu_invalidate_entry(uint8_t *buffer) QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {if (reventry->vaddr_req == buffer) { paddr_index = reventry->paddr_index; + size = reventry->size; found =1 ;break ; }
@@ -284,7 +333,7 @@ void qemu_invalidate_entry(uint8_t *buffer)qemu_free (reventry); entry = &mapcache->entry[paddr_index % mapcache->nr_buckets]; -while (entry && entry->paddr_index != paddr_index) { +while (entry && (entry->paddr_index != paddr_index || entry->size != size)) { pentry = entry; entry = entry->next; }
@@ -298,10 +347,11 @@ void qemu_invalidate_entry(uint8_t *buffer) } pentry->next = entry->next; -if (munmap (entry->vaddr_base,MCACHE_BUCKET_SIZE ) !=0 ) { +if (munmap (entry->vaddr_base, entry->size) !=0 ) {perror ("unmap fails" );exit (-1 ); } +qemu_free (entry->valid_mapping);qemu_free (entry); }
@@ -328,13 +378,16 @@ void qemu_invalidate_map_cache(void)continue ; } -if (munmap (entry->vaddr_base,MCACHE_BUCKET_SIZE ) !=0 ) { +if (munmap (entry->vaddr_base, entry->size) !=0 ) {perror ("unmap fails" );exit (-1 ); } entry->paddr_index =0 ; entry->vaddr_base =NULL ; + entry->size =0 ; +qemu_free (entry->valid_mapping); + entry->valid_mapping =NULL ; } mapcache->last_address_index =-1 ;
Signature · 1 line
1.6.0.2
PATCH 4/11 xen: remove qemu_map_cache_unlock
In reply to Alexander GrafFrom: Stefano Stabellini <[email protected]>
There is no need for qemu_map_cache_unlock, just use qemu_invalidate_entry instead.
--- exec.c | 2 +- xen-mapcache-stub.c | 4 ---- xen-mapcache.c | 33 --------------------------------- xen-mapcache.h | 1 - 4 files changed, 1 insertions(+), 39 deletions(-)
exec.c +1 -1
@@ -3146,7 +3146,7 @@ void qemu_put_ram_ptr(void *addr)xen_unmap_block (block->host, block->length); block->host =NULL ; }else { -qemu_map_cache_unlock (addr); +qemu_invalidate_entry (addr); } } }
xen-mapcache-stub.c +0 -4
@@ -22,10 +22,6 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, ureturn qemu_get_ram_ptr (phys_addr); } -void qemu_map_cache_unlock (void *buffer) -{ -} -ram_addr_t qemu_ram_addr_from_mapcache (void *ptr) {return -1 ;
xen-mapcache.c +0 -33
@@ -230,39 +230,6 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, ureturn mapcache->last_address_vaddr + address_offset; } -void qemu_map_cache_unlock (void *buffer) -{ -MapCacheEntry *entry =NULL , *pentry =NULL ; -MapCacheRev *reventry; -target_phys_addr_t paddr_index; -int found =0 ; - - QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { -if (reventry->vaddr_req == buffer) { - paddr_index = reventry->paddr_index; - found =1 ; -break ; - } - } -if (!found) { -return ; - } -QTAILQ_REMOVE (&mapcache->locked_entries, reventry, next); -qemu_free (reventry); - - entry = &mapcache->entry[paddr_index % mapcache->nr_buckets]; -while (entry && entry->paddr_index != paddr_index) { - pentry = entry; - entry = entry->next; - } -if (!entry) { -return ; - } -if (entry->lock >0 ) { - entry->lock--; - } -} -ram_addr_t qemu_ram_addr_from_mapcache (void *ptr) {MapCacheEntry *entry =NULL , *pentry =NULL ;
xen-mapcache.h +0 -1
@@ -14,7 +14,6 @@void qemu_map_cache_init (void );uint8_t *qemu_map_cache (target_phys_addr_t phys_addr,target_phys_addr_t size,uint8_t lock); -void qemu_map_cache_unlock (void *phys_addr);ram_addr_t qemu_ram_addr_from_mapcache (void *ptr);void qemu_invalidate_entry (uint8_t *buffer);void qemu_invalidate_map_cache (void );
Signature · 1 line
1.6.0.2
PATCH 5/11 xen: remove xen_map_block and xen_unmap_block
In reply to Alexander GrafFrom: Stefano Stabellini <[email protected]>
Replace xen_map_block with qemu_map_cache with the appropriate locking and size parameters.
Replace xen_unmap_block with qemu_invalidate_entry.
--- exec.c | 19 ++++--------------- xen-mapcache-stub.c | 4 ---- xen-mapcache.c | 31 ------------------------------- xen-mapcache.h | 15 --------------- 4 files changed, 4 insertions(+), 65 deletions(-)
exec.c +4 -15
@@ -53,6 +53,7 @@#endif #else /* !CONFIG_USER_ONLY */ #include "xen-mapcache.h" +#include "trace.h" #endif //#define DEBUG_TB_INVALIDATE
@@ -3088,7 +3089,7 @@ void *qemu_get_ram_ptr(ram_addr_t addr)if (block->offset ==0 ) {return qemu_map_cache (addr,0 ,1 ); }else if (block->host ==NULL ) { - block->host =xen_map_block (block->offset, block->length); + block->host =qemu_map_cache (block->offset, block->length,1 ); } }return block->host + (addr - block->offset);
@@ -3117,7 +3118,7 @@ void *qemu_safe_ram_ptr(ram_addr_t addr)if (block->offset ==0 ) {return qemu_map_cache (addr,0 ,1 ); }else if (block->host ==NULL ) { - block->host =xen_map_block (block->offset, block->length); + block->host =qemu_map_cache (block->offset, block->length,1 ); } }return block->host + (addr - block->offset);
@@ -3135,19 +3136,7 @@ void qemu_put_ram_ptr(void *addr)trace_qemu_put_ram_ptr (addr);if (xen_mapcache_enabled ()) { -RAMBlock *block; - - QLIST_FOREACH(block, &ram_list.blocks, next) { -if (addr == block->host) { -break ; - } - } -if (block && block->host) { -xen_unmap_block (block->host, block->length); - block->host =NULL ; - }else { -qemu_invalidate_entry (addr); - } +qemu_invalidate_entry (block->host); } }
xen-mapcache-stub.c +0 -4
@@ -34,7 +34,3 @@ void qemu_invalidate_map_cache(void)void qemu_invalidate_entry (uint8_t *buffer) { } -uint8_t *xen_map_block (target_phys_addr_t phys_addr,target_phys_addr_t size) -{ -return NULL ; -}
xen-mapcache.c +0 -31
@@ -362,34 +362,3 @@ void qemu_invalidate_map_cache(void)mapcache_unlock (); } - -uint8_t *xen_map_block (target_phys_addr_t phys_addr,target_phys_addr_t size) -{ -uint8_t *vaddr_base; -xen_pfn_t *pfns; -int *err; -unsigned int i; -target_phys_addr_t nb_pfn = size >>XC_PAGE_SHIFT ; - -trace_xen_map_block (phys_addr, size); - phys_addr >>=XC_PAGE_SHIFT ; - - pfns =qemu_mallocz (nb_pfn *sizeof (xen_pfn_t)); - err =qemu_mallocz (nb_pfn *sizeof (int )); - -for (i =0 ; i < nb_pfn; i++) { - pfns[i] = phys_addr + i; - } - - vaddr_base =xc_map_foreign_bulk (xen_xc, xen_domid,PROT_READ |PROT_WRITE , - pfns, err, nb_pfn); -if (vaddr_base ==NULL ) { -perror ("xc_map_foreign_bulk" ); -exit (-1 ); - } - -qemu_free (pfns); -qemu_free (err); - -return vaddr_base; -}
xen-mapcache.h +0 -15
@@ -9,27 +9,12 @@#ifndef XEN_MAPCACHE_H #define XEN_MAPCACHE_H -#include <sys/mman.h> -#include "trace.h" -void qemu_map_cache_init (void );uint8_t *qemu_map_cache (target_phys_addr_t phys_addr,target_phys_addr_t size,uint8_t lock);ram_addr_t qemu_ram_addr_from_mapcache (void *ptr);void qemu_invalidate_entry (uint8_t *buffer);void qemu_invalidate_map_cache (void ); -uint8_t *xen_map_block (target_phys_addr_t phys_addr,target_phys_addr_t size); - -static inline void xen_unmap_block (void *addr,ram_addr_t size) -{ -trace_xen_unmap_block (addr, size); - -if (munmap (addr, size) !=0 ) { -hw_error ("xen_unmap_block: %s" ,strerror (errno)); - } -} - -#define mapcache_lock () ((void)0)#define mapcache_unlock () ((void)0)
Signature · 1 line
1.6.0.2
PATCH 6/11 exec.c: refactor cpu_physical_memory_map
In reply to Alexander GrafFrom: Stefano Stabellini <[email protected]>
Introduce qemu_ram_ptr_length that takes an address and a size as parameters rather than just an address.
Refactor cpu_physical_memory_map so that we call qemu_ram_ptr_length only once rather than calling qemu_get_ram_ptr one time per page. This is not only more efficient but also tries to simplify the logic of the function.
Currently we are relying on the fact that all the pages are mapped contiguously in qemu's address space: we have a check to make sure that the virtual address returned by qemu_get_ram_ptr from the second call on is consecutive. Now we are making this more explicit replacing all the calls to qemu_get_ram_ptr with a single call to qemu_ram_ptr_length passing a size argument.
--- cpu-common.h | 1 + exec.c | 51 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 17 deletions(-)
cpu-common.h +1 -0
@@ -65,6 +65,7 @@ void qemu_ram_free_from_ptr(ram_addr_t addr);void qemu_ram_remap (ram_addr_t addr,ram_addr_t length);/* This should only be used for ram local to a device. */ void *qemu_get_ram_ptr (ram_addr_t addr); +void *qemu_ram_ptr_length (target_phys_addr_t addr,target_phys_addr_t *size);/* Same but slower, to use for migration, where the order of * RAMBlocks must not change. */ void *qemu_safe_ram_ptr (ram_addr_t addr);
exec.c +34 -17
84 lines not on this page · raw message
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 06/11] exec.c: refactor cpu_physical_memory_map
Quoted 9 lines · Alexander Graf
From: Stefano Stabellini <[email protected]>
Introduce
qemu_ram_ptr_lengththat takes an address and a size as parameters rather than just an address.Refactor
cpu_physical_memory_mapso that we callqemu_ram_ptr_lengthonly once rather than callingqemu_get_ram_ptrone time per page. This is not only more efficient but also tries to simplify the logic of the function.
This change breaks cpu_physical_memory_map() in the case where the passed in physical memory address corresponds to a RAM block which has been mapped in at multiple physical addresses. Specifically, for Versatile Express this means we abort() when framebuffer_update_display() calls cpu_physical_memory_map() for an address which is in the second mapped area.
exec.c void *qemu_safe_ram_ptr(ram_addr_t addr) · line 3136
Quoted 3 lines
exec.c +3
-0+/* Return a host pointer to guest's ram. Similar to qemu_get_ram_ptr +* but takes a size argument */ +void *qemu_ram_ptr_length (target_phys_addr_t addr,target_phys_addr_t *size)
qemu_get_ram_ptr() takes a ramaddr_t, not a target_phys_addr_t; so should this, because we're just looking through the ram_list without doing physaddr to ramaddr translation.
Conceptually size should also be a ram_addr_t*, although if you do that you can't just pass the plen pointer through to it.
The old implementation of cpu_physical_memory_map() worked because it created the address to pass to qemu_get_ram_ptr() from the p->phys_offset it got from phys_page_find(). The new implementation needs to do something similar, not just pass a target_phys_addr_t to qemu_ram_ptr_length().
exec.c void *qemu_safe_ram_ptr(ram_addr_t addr) · line 3155
Quoted 5 lines
exec.c +5
-0+fprintf (stderr,"Bad ram offset %" PRIx64"\n" , (uint64_t )addr); +abort (); + + *size =0 ; +return NULL ;
There doesn't seem much point in having code following an abort().
-- PMM
Re: [Qemu-devel] [PATCH 06/11] exec.c: refactor cpu_physical_memory_map
Quoted 26 lines · Peter Maydell
Quoted 9 lines · Alexander Graf
From: Stefano Stabellini <[email protected]>
Introduce
qemu_ram_ptr_lengththat takes an address and a size as parameters rather than just an address.Refactor
cpu_physical_memory_mapso that we callqemu_ram_ptr_lengthonly once rather than callingqemu_get_ram_ptrone time per page. This is not only more efficient but also tries to simplify the logic of the function.This change breaks
cpu_physical_memory_map()in the case where the passed in physical memory address corresponds to a RAM block which has been mapped in at multiple physical addresses. Specifically, for Versatile Express this means weabort()whenframebuffer_update_display()callscpu_physical_memory_map()for an address which is in the second mapped area.exec.c void *qemu_safe_ram_ptr(ram_addr_t addr) · line 3136
Quoted 3 lines
exec.c +3
-0+/* Return a host pointer to guest's ram. Similar to qemu_get_ram_ptr +* but takes a size argument */ +void *qemu_ram_ptr_length (target_phys_addr_t addr,target_phys_addr_t *size)
qemu_get_ram_ptr()takes aramaddr_t, not atarget_phys_addr_t; so should this, because we're just looking through theram_listwithout doing physaddr to ramaddr translation.
Quoted 9 lines
Conceptually size should also be a ram_addr_t*, although if you do that you can't just pass the plen pointer through to it.
The old implementation of
cpu_physical_memory_map()worked because it created the address to pass toqemu_get_ram_ptr()from thep->phys_offsetit got fromphys_page_find(). The new implementation needs to do something similar, not just pass atarget_phys_addr_ttoqemu_ram_ptr_length().
Thanks for the detailed explanation of the problem, I think I understand what I have to do to fix.
However I would like to have a repro of the bug before sending any patches, so that I am sure that the solution works correctly. However I am not very familiar with ARM emulation in Qemu: could you please let me know which target I have to compile, which machine I have to emulate and what other steps do I have to take in order to see this issue?
Many thanks in advance.
Quoted 7 lines
exec.c void *qemu_safe_ram_ptr(ram_addr_t addr) · line 3155
Quoted 5 lines
exec.c +5
-0+fprintf (stderr,"Bad ram offset %" PRIx64"\n" , (uint64_t )addr); +abort (); + + *size =0 ; +return NULL ;There doesn't seem much point in having code following an
abort().
right, I'll remove it
Re: [Qemu-devel] [PATCH 06/11] exec.c: refactor cpu_physical_memory_map
Quoted 8 lines · Stefano Stabellini
Thanks for the detailed explanation of the problem, I think I understand what I have to do to fix.
However I would like to have a repro of the bug before sending any patches, so that I am sure that the solution works correctly. However I am not very familiar with ARM emulation in Qemu: could you please let me know which target I have to compile, which machine I have to emulate and what other steps do I have to take in order to see this issue?
You'll need this not-yet-applied patch which adds cp15 perf reg support:
http://patchwork.ozlabs.org/patch/92423/
I've temporarily put a test kernel and initrd here:
http://people.linaro.org/~pmaydell/linaro-20110228.tar.gz
configure qemu with --target-list=arm-softmmu
and then you can run:
./arm-softmmu/qemu-system-arm -kernel linaro-20110228/vmlinuz-2.6.37-1003-linaro-vexpress -initrd linaro-20110228/initrd.img-2.6.37-1003-linaro-vexpress -M vexpress-a9 -cpu cortex-a9 -serial stdio -m 1024 -append 'root=/dev/mmcblk0p2 rw mem=1024M raid=noautodetect console=ttyAMA0,38400n8 rootwait vmalloc=256MB devtmpfs.mount=0'
At the moment this aborts when the kernel tries to initialise the display; if you fix the problem it ought to display a penguin on the graphics window (although it will drop you into an initramfs prompt because you don't have a root filesystem sd card image).
-- PMM
Re: [Qemu-devel] [PATCH 06/11] exec.c: refactor cpu_physical_memory_map
Quoted 26 lines · Peter Maydell
Quoted 8 lines · Stefano Stabellini
Thanks for the detailed explanation of the problem, I think I understand what I have to do to fix.
However I would like to have a repro of the bug before sending any patches, so that I am sure that the solution works correctly. However I am not very familiar with ARM emulation in Qemu: could you please let me know which target I have to compile, which machine I have to emulate and what other steps do I have to take in order to see this issue?You'll need this not-yet-applied patch which adds cp15 perf reg support:
http://patchwork.ozlabs.org/patch/92423/
I've temporarily put a test kernel and initrd here:
http://people.linaro.org/~pmaydell/linaro-20110228.tar.gzconfigure qemu with --target-list=arm-softmmu
and then you can run:./arm-softmmu/qemu-system-arm -kernel linaro-20110228/vmlinuz-2.6.37-1003-linaro-vexpress -initrd linaro-20110228/initrd.img-2.6.37-1003-linaro-vexpress -M vexpress-a9 -cpu cortex-a9 -serial stdio -m 1024 -append 'root=/dev/mmcblk0p2 rw mem=1024M raid=noautodetect console=ttyAMA0,38400n8 rootwait vmalloc=256MB devtmpfs.mount=0'
Quoted 4 lines
At the moment this aborts when the kernel tries to initialise the display; if you fix the problem it ought to display a penguin on the graphics window (although it will drop you into an initramfs prompt because you don't have a root filesystem sd card image).
Thanks, I managed to test my fix succesfully.
See the patch "qemu_ram_ptr_length: take ram_addr_t as arguments" I have just sent.
PATCH 7/11 xen: mapcache performance improvements
In reply to Alexander GrafFrom: Stefano Stabellini <[email protected]>
Use qemu_invalidate_entry in cpu_physical_memory_unmap.
Do not lock mapcache entries in qemu_get_ram_ptr if the address falls in the ramblock with offset == 0. We don't need to do that because the callers of qemu_get_ram_ptr either try to map an entire block, other from the main ramblock, or until the end of a page to implement a single read or write in the main ramblock.
If we don't lock mapcache entries in qemu_get_ram_ptr we don't need to call qemu_invalidate_entry in qemu_put_ram_ptr anymore because we can leave with few long lived block mappings requested by devices.
Also move the call to qemu_ram_addr_from_mapcache at the beginning of qemu_ram_addr_from_host.
--- exec.c | 28 ++++++++++------------------ 1 files changed, 10 insertions(+), 18 deletions(-)
exec.c +10 -18
@@ -3085,9 +3085,10 @@ void *qemu_get_ram_ptr(ram_addr_t addr)if (xen_mapcache_enabled ()) {/* We need to check if the requested address is in the RAM * because we don't want to map the entire memory in QEMU. +* In that case just map until the end of the page. */ if (block->offset ==0 ) { -return qemu_map_cache (addr,0 ,1 ); +return qemu_map_cache (addr,0 ,0 ); }else if (block->host ==NULL ) { block->host =qemu_map_cache (block->offset, block->length,1 ); }
@@ -3114,9 +3115,10 @@ void *qemu_safe_ram_ptr(ram_addr_t addr)if (xen_mapcache_enabled ()) {/* We need to check if the requested address is in the RAM * because we don't want to map the entire memory in QEMU. +* In that case just map until the end of the page. */ if (block->offset ==0 ) { -return qemu_map_cache (addr,0 ,1 ); +return qemu_map_cache (addr,0 ,0 ); }else if (block->host ==NULL ) { block->host =qemu_map_cache (block->offset, block->length,1 ); }
@@ -3159,10 +3161,6 @@ void *qemu_ram_ptr_length(target_phys_addr_t addr, target_phys_addr_t *size)void qemu_put_ram_ptr (void *addr) {trace_qemu_put_ram_ptr (addr); - -if (xen_mapcache_enabled ()) { -qemu_invalidate_entry (block->host); - } }int qemu_ram_addr_from_host (void *ptr,ram_addr_t *ram_addr)
@@ -3170,6 +3168,11 @@ int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)RAMBlock *block;uint8_t *host = ptr; +if (xen_mapcache_enabled ()) { + *ram_addr =qemu_ram_addr_from_mapcache (ptr); +return 0 ; + } + QLIST_FOREACH(block, &ram_list.blocks, next) {/* This case append when the block is not mapped. */ if (block->host ==NULL ) {
@@ -3181,11 +3184,6 @@ int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr) } } -if (xen_mapcache_enabled ()) { - *ram_addr =qemu_ram_addr_from_mapcache (ptr); -return 0 ; - } -return -1 ; }
@@ -4086,13 +4084,7 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len, } }if (xen_mapcache_enabled ()) { -uint8_t *buffer1 = buffer; -uint8_t *end_buffer = buffer + len; - -while (buffer1 < end_buffer) { -qemu_put_ram_ptr (buffer1); - buffer1 +=TARGET_PAGE_SIZE ; - } +qemu_invalidate_entry (buffer); }return ; }
Signature · 1 line
1.6.0.2
PATCH 8/11 cirrus_vga: reset lfb_addr after a pci config write if the BAR is unmapped
In reply to Alexander GrafFrom: Stefano Stabellini <[email protected]>
If the cirrus_vga PCI BAR is unmapped than we should not only reset map_addr but also lfb_addr, otherwise we'll keep trying to map the old lfb_addr in map_linear_vram.
--- hw/cirrus_vga.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
hw/cirrus_vga.c +4 -1
@@ -3088,8 +3088,11 @@ static void pci_cirrus_write_config(PCIDevice *d,CirrusVGAState *s = &pvs->cirrus_vga;pci_default_write_config (d, address, val, len); -if (s->vga.map_addr && d->io_regions[0 ].addr ==PCI_BAR_UNMAPPED ) +if (s->vga.map_addr && d->io_regions[0 ].addr ==PCI_BAR_UNMAPPED ) { s->vga.map_addr =0 ; + s->vga.lfb_addr =0 ; + s->vga.lfb_end =0 ; + }cirrus_update_memory_access (s); }
Signature · 1 line
1.6.0.2
PATCH 9/11 xen: only track the linear framebuffer
In reply to Alexander GrafFrom: Stefano Stabellini <[email protected]>
Xen can only do dirty bit tracking for one memory region, so we should explicitly avoid trying to track anything but the vga vram region.
--- xen-all.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
xen-all.c +14 -0
@@ -215,6 +215,7 @@ static int xen_add_to_physmap(XenIOState *state,int rc =0 ;XenPhysmap *physmap =NULL ;target_phys_addr_t pfn, start_gpfn; +RAMBlock *block;if (get_physmapping (state, start_addr, size)) {return 0 ;
@@ -223,6 +224,19 @@ static int xen_add_to_physmap(XenIOState *state,return -1 ; } +/* Xen can only handle a single dirty log region for now and we want +* the linear framebuffer to be that region. +* Avoid tracking any regions that is not videoram and avoid tracking +* the legacy vga region. */ + QLIST_FOREACH(block, &ram_list.blocks, next) { +if (!strcmp (block->idstr,"vga.vram" ) && block->offset == phys_offset + && start_addr >0xbffff ) { + goto go_physmap; + } + } +return -1 ; + +go_physmap:DPRINTF ("mapping vram to %llx - %llx, from %llx\n" , start_addr, start_addr + size, phys_offset);
Signature · 1 line
1.6.0.2
PATCH 10/11 xen: fix interrupt routing
In reply to Alexander GrafFrom: Stefano Stabellini <[email protected]>
Compared to the last version I only added a comment to the code.
- remove i440FX-xen and i440fx_write_config_xen
we don't need to intercept pci config writes to i440FX anymore;
- introduce PIIX3-xen and piix3_write_config_xen
we do need to intercept pci config write to the PCI-ISA bridge to update the PCI link routing;
- set the number of PIIX3-xen interrupts line to 128;
--- hw/pc.h | 1 - hw/pc_piix.c | 6 +---- hw/piix_pci.c | 66 +++++++++++++++++++++++++++++--------------------------- 3 files changed, 35 insertions(+), 38 deletions(-)
hw/pc.h +0 -1
@@ -176,7 +176,6 @@ struct PCII440FXState;typedef struct PCII440FXState PCII440FXState ;PCIBus *i440fx_init (PCII440FXState **pi440fx_state,int *piix_devfn,qemu_irq *pic,ram_addr_t ram_size); -PCIBus *i440fx_xen_init (PCII440FXState **pi440fx_state,int *piix3_devfn,qemu_irq *pic,ram_addr_t ram_size);void i440fx_init_memory_mappings (PCII440FXState *d);/* piix4.c */
hw/pc_piix.c +1 -5
@@ -124,11 +124,7 @@ static void pc_init1(ram_addr_t ram_size, isa_irq =qemu_allocate_irqs (isa_irq_handler, isa_irq_state,24 );if (pci_enabled) { -if (!xen_enabled ()) { - pci_bus =i440fx_init (&i440fx_state, &piix3_devfn, isa_irq, ram_size); - }else { - pci_bus =i440fx_xen_init (&i440fx_state, &piix3_devfn, isa_irq, ram_size); - } + pci_bus =i440fx_init (&i440fx_state, &piix3_devfn, isa_irq, ram_size); }else { pci_bus =NULL ; i440fx_state =NULL ;
hw/piix_pci.c +34 -32
114 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 11/11 xen: Add the Xen platform pci device
In reply to Alexander GrafFrom: Steven Smith <[email protected]>
Introduce a new emulated PCI device, specific to fully virtualized Xen guests. The device is necessary for PV on HVM drivers to work.
--- Makefile.target | 2 + hw/hw.h | 3 + hw/pc_piix.c | 4 + hw/pci_ids.h | 2 + hw/xen_platform.c | 340 +++++++++++++++++++++++++++++++++++++++++++++++++++++ trace-events | 3 + 6 files changed, 354 insertions(+), 0 deletions(-) create mode 100644 hw/xen_platform.c
Makefile.target +2 -0
@@ -218,6 +218,8 @@ obj-$(CONFIG_NO_XEN) += xen-stub.o obj-i386-$(CONFIG_XEN_MAPCACHE) += xen-mapcache.o obj-$(CONFIG_NO_XEN_MAPCACHE) += xen-mapcache-stub.o +obj-i386-$(CONFIG_XEN) += xen_platform.o + # Inter-VM PCI shared memory CONFIG_IVSHMEM = ifeq ($(CONFIG_KVM), y)
hw/hw.h +3 -0
@@ -780,6 +780,9 @@ extern const VMStateDescription vmstate_ptimer;#define VMSTATE_INT32_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) +#define VMSTATE_UINT8_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t) +#define VMSTATE_UINT16_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
hw/pc_piix.c +4 -0
@@ -136,6 +136,10 @@ static void pc_init1(ram_addr_t ram_size,pc_vga_init (pci_enabled? pci_bus:NULL ); +if (xen_enabled ()) { +pci_create_simple (pci_bus,-1 ,"xen-platform" ); + } +/* init basic PC hardware */ pc_basic_device_init (isa_irq, &rtc_state,xen_enabled ());
hw/pci_ids.h +2 -0
@@ -109,3 +109,5 @@#define PCI_DEVICE_ID_INTEL_82371AB 0x7111#define PCI_DEVICE_ID_INTEL_82371AB_2 0x7112#define PCI_DEVICE_ID_INTEL_82371AB_3 0x7113 + +#define PCI_VENDOR_ID_XENSOURCE 0x5853
hw/xen_platform.c new file +340 -0
340 lines not on this page · raw message
trace-events +3 -0
@@ -407,3 +407,6 @@ disable xen_unmap_block(void* addr, unsigned long size) "%p, size %#lx" # exec.c disable qemu_put_ram_ptr(void* addr) "%p" + +# hw/xen_platform.c +disable xen_platform_log(char *s) "xen platform: %s"
Signature · 1 line
1.6.0.2
Quoted 5 lines · Alexander Graf
Hi Anthony,
This is my current patch queue for Xen patches.
Please pull.
Pulled. Thanks.
Regards,
Anthony Liguori
Quoted 49 lines
Alex
The following changes since commit
eb47d7c5d96060040931c42773ee07e61e547af9:
Peter Maydell (1):
hw/9118.c: Implement active-low interrupt supportare available in the git repository at:
git://repo.or.cz/qemu/agraf.gitxen-nextAnthony PERARD (2):
xen: Addxc_domain_add_to_physmaptoxen_interface.
xen: Introduce VGA sync dirty bitmap supportStefano Stabellini (8):
xen: fixqemu_map_cachewith size !=MCACHE_BUCKET_SIZE
xen: removeqemu_map_cache_unlock
xen: removexen_map_blockandxen_unmap_block
exec.c: refactorcpu_physical_memory_map
xen: mapcache performance improvements
cirrus_vga: resetlfb_addrafter a pci config write if the BAR is unmapped
xen: only track the linear framebuffer
xen: fix interrupt routingSteven Smith (1):
xen: Add the Xen platform pci deviceMakefile.target | 2 + configure | 29 ++++- cpu-common.h | 1 + exec.c | 88 +++++++------- hw/cirrus_vga.c | 5 +- hw/hw.h | 3 + hw/pc.h | 1 - hw/pc_piix.c | 10 +- hw/pci_ids.h | 2 + hw/piix_pci.c | 66 +++++----- hw/xen_common.h | 14 ++ hw/xen_platform.c | 340 +++++++++++++++++++++++++++++++++++++++++++++++++++ trace-events | 4 + xen-all.c | 281 ++++++++++++++++++++++++++++++++++++++++++ xen-mapcache-stub.c | 8 -- xen-mapcache.c | 141 ++++++++++------------ xen-mapcache.h | 16 --- 17 files changed, 826 insertions(+), 185 deletions(-)create mode 100644
hw/xen_platform.c