[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 10/17] xen: mapcache: Break out xen_map_cache_init_single()
From: |
Edgar E. Iglesias |
Subject: |
[PATCH v4 10/17] xen: mapcache: Break out xen_map_cache_init_single() |
Date: |
Tue, 30 Apr 2024 18:49:32 +0200 |
From: "Edgar E. Iglesias" <edgar.iglesias@amd.com>
Break out xen_map_cache_init_single() in preparation for
adding multiple map caches.
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@amd.com>
---
hw/xen/xen-mapcache.c | 53 ++++++++++++++++++++++++++-----------------
1 file changed, 32 insertions(+), 21 deletions(-)
diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c
index dd08cd296b..72a7e25e3e 100644
--- a/hw/xen/xen-mapcache.c
+++ b/hw/xen/xen-mapcache.c
@@ -93,23 +93,44 @@ static inline int test_bits(int nr, int size, const
unsigned long *addr)
return 0;
}
-void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)
+static MapCache *xen_map_cache_init_single(phys_offset_to_gaddr_t f,
+ void *opaque,
+ unsigned long max_size)
{
unsigned long size;
- struct rlimit rlimit_as;
+ MapCache *mc;
+
+ mc = g_new0(MapCache, 1);
+
+ mc->phys_offset_to_gaddr = f;
+ mc->opaque = opaque;
+ qemu_mutex_init(&mc->lock);
+
+ QTAILQ_INIT(&mc->locked_entries);
- mapcache = g_new0(MapCache, 1);
+ mc->max_mcache_size = max_size;
- mapcache->phys_offset_to_gaddr = f;
- mapcache->opaque = opaque;
- qemu_mutex_init(&mapcache->lock);
+ mc->nr_buckets =
+ (((mc->max_mcache_size >> XC_PAGE_SHIFT) +
+ (1UL << (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)) - 1) >>
+ (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT));
- QTAILQ_INIT(&mapcache->locked_entries);
+ size = mc->nr_buckets * sizeof(MapCacheEntry);
+ size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1);
+ trace_xen_map_cache_init(mc->nr_buckets, size);
+ mc->entry = g_malloc0(size);
+ return mc;
+}
+
+void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)
+{
+ struct rlimit rlimit_as;
+ unsigned long max_mcache_size;
if (geteuid() == 0) {
rlimit_as.rlim_cur = RLIM_INFINITY;
rlimit_as.rlim_max = RLIM_INFINITY;
- mapcache->max_mcache_size = MCACHE_MAX_SIZE;
+ max_mcache_size = MCACHE_MAX_SIZE;
} else {
getrlimit(RLIMIT_AS, &rlimit_as);
rlimit_as.rlim_cur = rlimit_as.rlim_max;
@@ -119,24 +140,14 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void
*opaque)
" memory is not infinity");
}
if (rlimit_as.rlim_max < MCACHE_MAX_SIZE + NON_MCACHE_MEMORY_SIZE) {
- mapcache->max_mcache_size = rlimit_as.rlim_max -
- NON_MCACHE_MEMORY_SIZE;
+ max_mcache_size = rlimit_as.rlim_max - NON_MCACHE_MEMORY_SIZE;
} else {
- mapcache->max_mcache_size = MCACHE_MAX_SIZE;
+ max_mcache_size = MCACHE_MAX_SIZE;
}
}
+ mapcache = xen_map_cache_init_single(f, opaque, max_mcache_size);
setrlimit(RLIMIT_AS, &rlimit_as);
-
- mapcache->nr_buckets =
- (((mapcache->max_mcache_size >> XC_PAGE_SHIFT) +
- (1UL << (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)) - 1) >>
- (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT));
-
- size = mapcache->nr_buckets * sizeof (MapCacheEntry);
- size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1);
- trace_xen_map_cache_init(mapcache->nr_buckets, size);
- mapcache->entry = g_malloc0(size);
}
static void xen_remap_bucket(MapCache *mc,
--
2.40.1
- [PATCH v4 00/17] xen: Support grant mappings, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 03/17] xen: mapcache: Refactor lock functions for multi-instance, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 04/17] xen: mapcache: Refactor xen_map_cache for multi-instance, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 01/17] softmmu: let qemu_map_ram_ptr() use qemu_ram_ptr_length(), Edgar E. Iglesias, 2024/04/30
- [PATCH v4 02/17] xen: let xen_ram_addr_from_mapcache() return -1 in case of not found entry, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 12/17] xen: mapcache: Unmap first entries in buckets, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 09/17] xen: mapcache: Break out xen_invalidate_map_cache_single(), Edgar E. Iglesias, 2024/04/30
- [PATCH v4 13/17] softmmu: Pass RAM MemoryRegion and is_write xen_map_cache(), Edgar E. Iglesias, 2024/04/30
- [PATCH v4 08/17] xen: mapcache: Refactor xen_invalidate_map_cache_entry_unlocked, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 10/17] xen: mapcache: Break out xen_map_cache_init_single(),
Edgar E. Iglesias <=
- [PATCH v4 05/17] xen: mapcache: Refactor xen_remap_bucket for multi-instance, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 07/17] xen: mapcache: Refactor xen_replace_cache_entry_unlocked, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 06/17] xen: mapcache: Break out xen_ram_addr_from_mapcache_single, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 11/17] xen: mapcache: Make MCACHE_BUCKET_SHIFT runtime configurable, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 15/17] xen: mapcache: Remove assumption of RAMBlock with 0 offset, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 14/17] xen: Add xen_mr_is_memory(), Edgar E. Iglesias, 2024/04/30
- [PATCH v4 17/17] hw/arm: xen: Enable use of grant mappings, Edgar E. Iglesias, 2024/04/30
- [PATCH v4 16/17] xen: mapcache: Add support for grant mappings, Edgar E. Iglesias, 2024/04/30