From: Hanweidong Date: Tue, 2 Apr 2013 13:22:41 +0000 (+0000) Subject: xen-mapcache: pass the right size argument to test_bits X-Git-Tag: qemu-xen-4.2.2-rc2~4 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=bf8e2e756e3e98b8388068173e24d99d1e09d2dd;p=qemu-upstream-4.2-testing.git xen-mapcache: pass the right size argument to test_bits Compute the correct size for test_bits(). qemu_get_ram_ptr() and qemu_safe_ram_ptr() will call xen_map_cache() with size is 0 if the requested address is in the RAM. Then xen_map_cache() will pass the size 0 to test_bits() for checking if the corresponding pfn was mapped in cache. But test_bits() will always return 1 when size is 0 without any bit testing. Actually, for this case, test_bits should check one bit. So this patch introduced a __test_bit_size which is greater than 0 and a multiple of XC_PAGE_SIZE, then test_bits can work correctly with __test_bit_size >> XC_PAGE_SHIFT as its size. upstream-commit-id: 044d4e1aae539bd4214175bd9591b3de7986cf18 Signed-off-by: Zhenguo Wang Signed-off-by: Weidong Han Signed-off-by: Stefano Stabellini --- diff --git a/xen-mapcache.c b/xen-mapcache.c index f18dd98b7..7a1d159b7 100644 --- a/xen-mapcache.c +++ b/xen-mapcache.c @@ -198,6 +198,7 @@ uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, target_phys_addr_t address_index; target_phys_addr_t address_offset; target_phys_addr_t __size = size; + target_phys_addr_t __test_bit_size = size; bool translated = false; tryagain: @@ -206,9 +207,23 @@ tryagain: trace_xen_map_cache(phys_addr); + /* __test_bit_size is always a multiple of XC_PAGE_SIZE */ + if (size) { + __test_bit_size = size + (phys_addr & (XC_PAGE_SIZE - 1)); + + if (__test_bit_size % XC_PAGE_SIZE) { + __test_bit_size += XC_PAGE_SIZE - (__test_bit_size % XC_PAGE_SIZE); + } + } else { + __test_bit_size = XC_PAGE_SIZE; + } + if (mapcache->last_entry != NULL && mapcache->last_entry->paddr_index == address_index && - !lock && !__size) { + !lock && !__size && + test_bits(address_offset >> XC_PAGE_SHIFT, + __test_bit_size >> XC_PAGE_SHIFT, + mapcache->last_entry->valid_mapping)) { trace_xen_map_cache_return(mapcache->last_entry->vaddr_base + address_offset); return mapcache->last_entry->vaddr_base + address_offset; } @@ -227,7 +242,8 @@ tryagain: 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, + !test_bits(address_offset >> XC_PAGE_SHIFT, + __test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping))) { pentry = entry; entry = entry->next; @@ -239,13 +255,15 @@ tryagain: } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index != address_index || entry->size != __size || - !test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT, + !test_bits(address_offset >> XC_PAGE_SHIFT, + __test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { xen_remap_bucket(entry, __size, address_index); } } - if(!test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT, + if(!test_bits(address_offset >> XC_PAGE_SHIFT, + __test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { mapcache->last_entry = NULL; if (!translated && mapcache->phys_offset_to_gaddr) {