xen: mapcache: Assert mapcache existance
Assert that the mapcache was created prior to being used. Signed-off-by: Edgar E. Iglesias <edgar.iglesias@amd.com> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Edgar E. Iglesias committed
Jul 23, 2025 at 11:29 UTC
3038c84daa5ae2983ad3b711f6fefdd40234d506
1 file changed
+10
hw/xen/xen-mapcache.c
+10
@@ -464,6 +464,8 @@ uint8_t *xen_map_cache(MemoryRegion *mr,
464
MapCache *mc = mapcache;
465
uint8_t *p;
466
467
+ assert(mapcache);
468
+
469
if (grant) {
470
mc = is_write ? mapcache_grants_rw : mapcache_grants_ro;
471
}
@@ -530,6 +532,8 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
532
{
533
ram_addr_t addr;
534
535
+ assert(mapcache);
536
+
537
addr = xen_ram_addr_from_mapcache_single(mapcache, ptr);
538
if (addr == RAM_ADDR_INVALID) {
539
addr = xen_ram_addr_from_mapcache_single(mapcache_grants_ro, ptr);
@@ -652,6 +656,8 @@ static void xen_invalidate_map_cache_entry_bh(void *opaque)
656
657
void coroutine_mixed_fn xen_invalidate_map_cache_entry(uint8_t *buffer)
658
{
659
+ assert(mapcache);
660
+
661
if (qemu_in_coroutine()) {
662
XenMapCacheData data = {
663
.co = qemu_coroutine_self(),
@@ -709,6 +715,8 @@ static void xen_invalidate_map_cache_single(MapCache *mc)
715
716
void xen_invalidate_map_cache(void)
717
{
718
+ assert(mapcache);
719
+
720
/* Flush pending AIO before destroying the mapcache */
721
bdrv_drain_all();
722
@@ -776,6 +784,8 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr,
784
{
785
uint8_t *p;
786
787
+ assert(mapcache);
788
+
789
mapcache_lock(mapcache);
790
p = xen_replace_cache_entry_unlocked(mapcache, old_phys_addr,
791
new_phys_addr, size);