Skip to content

Commit bfa3f55

Browse files
edgariglMichael Tokarev
authored andcommitted
xen: mapcache: Split mapcache_grants by ro and rw
Today, we don't track write-abiliy in the cache, if a user requests a readable mapping followed by a writeable mapping on the same page, the second lookup will incorrectly hit the readable entry. Split mapcache_grants by ro and rw access. Grants will now have separate ways in the cache depending on writeability. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Signed-off-by: Edgar E. Iglesias <[email protected]> (cherry picked from commit 88fb705) Signed-off-by: Michael Tokarev <[email protected]>
1 parent a03d7d6 commit bfa3f55

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

hw/xen/xen-mapcache.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ typedef struct MapCache {
7575
} MapCache;
7676

7777
static MapCache *mapcache;
78-
static MapCache *mapcache_grants;
78+
static MapCache *mapcache_grants_ro;
79+
static MapCache *mapcache_grants_rw;
7980
static xengnttab_handle *xen_region_gnttabdev;
8081

8182
static inline void mapcache_lock(MapCache *mc)
@@ -176,9 +177,12 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)
176177
* Grant mappings must use XC_PAGE_SIZE granularity since we can't
177178
* map anything beyond the number of pages granted to us.
178179
*/
179-
mapcache_grants = xen_map_cache_init_single(f, opaque,
180-
XC_PAGE_SHIFT,
181-
max_mcache_size);
180+
mapcache_grants_ro = xen_map_cache_init_single(f, opaque,
181+
XC_PAGE_SHIFT,
182+
max_mcache_size);
183+
mapcache_grants_rw = xen_map_cache_init_single(f, opaque,
184+
XC_PAGE_SHIFT,
185+
max_mcache_size);
182186

183187
setrlimit(RLIMIT_AS, &rlimit_as);
184188
}
@@ -456,9 +460,13 @@ uint8_t *xen_map_cache(MemoryRegion *mr,
456460
bool is_write)
457461
{
458462
bool grant = xen_mr_is_grants(mr);
459-
MapCache *mc = grant ? mapcache_grants : mapcache;
463+
MapCache *mc = mapcache;
460464
uint8_t *p;
461465

466+
if (grant) {
467+
mc = is_write ? mapcache_grants_rw : mapcache_grants_ro;
468+
}
469+
462470
if (grant && !lock) {
463471
/*
464472
* Grants are only supported via address_space_map(). Anything
@@ -523,7 +531,10 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
523531

524532
addr = xen_ram_addr_from_mapcache_single(mapcache, ptr);
525533
if (addr == RAM_ADDR_INVALID) {
526-
addr = xen_ram_addr_from_mapcache_single(mapcache_grants, ptr);
534+
addr = xen_ram_addr_from_mapcache_single(mapcache_grants_ro, ptr);
535+
}
536+
if (addr == RAM_ADDR_INVALID) {
537+
addr = xen_ram_addr_from_mapcache_single(mapcache_grants_rw, ptr);
527538
}
528539

529540
return addr;
@@ -626,7 +637,8 @@ static void xen_invalidate_map_cache_entry_single(MapCache *mc, uint8_t *buffer)
626637
static void xen_invalidate_map_cache_entry_all(uint8_t *buffer)
627638
{
628639
xen_invalidate_map_cache_entry_single(mapcache, buffer);
629-
xen_invalidate_map_cache_entry_single(mapcache_grants, buffer);
640+
xen_invalidate_map_cache_entry_single(mapcache_grants_ro, buffer);
641+
xen_invalidate_map_cache_entry_single(mapcache_grants_rw, buffer);
630642
}
631643

632644
static void xen_invalidate_map_cache_entry_bh(void *opaque)

0 commit comments

Comments
 (0)