1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-19 02:29:40 +00:00

bhyve: Allocate mmio_hint array based on number of guest CPUs.

This avoids an instance of hardcoding VM_MAXCPU in userspace.

Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D34489

(cherry picked from commit 730510dc1a)
This commit is contained in:
John Baldwin 2022-03-09 15:38:49 -08:00
parent 66b4bdd5ad
commit 2412b82929
3 changed files with 9 additions and 6 deletions

View File

@ -1421,7 +1421,7 @@ main(int argc, char *argv[])
exit(4);
}
init_mem();
init_mem(guest_ncpus);
init_inout();
kernemu_dev_init();
init_bootrom(ctx);

View File

@ -68,7 +68,8 @@ RB_HEAD(mmio_rb_tree, mmio_rb_range) mmio_rb_root, mmio_rb_fallback;
* consecutive addresses in a range, it makes sense to cache the
* result of a lookup.
*/
static struct mmio_rb_range *mmio_hint[VM_MAXCPU];
static struct mmio_rb_range **mmio_hint;
static int mmio_ncpu;
static pthread_rwlock_t mmio_rwlock;
@ -349,8 +350,8 @@ unregister_mem(struct mem_range *memp)
assert((mr->flags & MEM_F_IMMUTABLE) == 0);
RB_REMOVE(mmio_rb_tree, &mmio_rb_root, entry);
/* flush Per-vCPU cache */
for (i=0; i < VM_MAXCPU; i++) {
/* flush Per-vCPU cache */
for (i = 0; i < mmio_ncpu; i++) {
if (mmio_hint[i] == entry)
mmio_hint[i] = NULL;
}
@ -365,9 +366,11 @@ unregister_mem(struct mem_range *memp)
}
void
init_mem(void)
init_mem(int ncpu)
{
mmio_ncpu = ncpu;
mmio_hint = calloc(ncpu, sizeof(*mmio_hint));
RB_INIT(&mmio_rb_root);
RB_INIT(&mmio_rb_fallback);
pthread_rwlock_init(&mmio_rwlock, NULL);

View File

@ -52,7 +52,7 @@ struct mem_range {
#define MEM_F_RW 0x3
#define MEM_F_IMMUTABLE 0x4 /* mem_range cannot be unregistered */
void init_mem(void);
void init_mem(int ncpu);
int emulate_mem(struct vmctx *, int vcpu, uint64_t paddr, struct vie *vie,
struct vm_guest_paging *paging);