From nobody Wed Mar 09 23:57:31 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id ABBDE1A122DA; Wed, 9 Mar 2022 23:57:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KDTdl4CVxz4c8k; Wed, 9 Mar 2022 23:57:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646870251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XPPToVMisvpu7HHJAjQW19LWuyHOsqE3Tcx7zgqj6zc=; b=AEygGfu2WYXaZDY2FaaKXzTI2LUgceB2R5T5Q9FB6DbSja7muVe9NT5JHe5j2kelm3qUOU GozaJGf04RZ87MpKX16Rv8S2uCSdpsl5nqyfXJUtu+cOuHATmmI1asRwuZkIlCPAJOfmm3 z6bBs4SMPsHjev7Yhir679RA/torr5Mg4jpzEgin971hm95U81kg+SOEQzk41Ok4MUrgIc cHcFKdk1NXjU4byYZ86+xlrVMXOyk/TvVnP68DWAWNMJeDWFI7fWH3uq4uiRx1Dce/KS47 W3fAQR3qNVzhodFD6PBOl2p1oIYMfqI3mu51wTTdWVhP3qHPhiyHheJ4LHgCYA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6A9381A72B; Wed, 9 Mar 2022 23:57:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 229NvV0G004716; Wed, 9 Mar 2022 23:57:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 229NvVJV004715; Wed, 9 Mar 2022 23:57:31 GMT (envelope-from git) Date: Wed, 9 Mar 2022 23:57:31 GMT Message-Id: <202203092357.229NvVJV004715@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 730510dc1ab2 - main - bhyve: Allocate mmio_hint array based on number of guest CPUs. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 730510dc1ab2049d707706241d9a6e73a6952a4e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646870251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XPPToVMisvpu7HHJAjQW19LWuyHOsqE3Tcx7zgqj6zc=; b=fZJVuYmHrL/gyZ6yFxmcndu3nreWKEriAfp+Or4S0TvEV0hGvwt28n9U7DIU1VzHohgi6i f16y4tCehZuaJaMF1eyUBcJ4zbwhpdBceMHBGhcqIH4SZQTrYJs68aixLHqG0rFifLVLCR 4c6Fw+9br2DXpPEHeto6NbSCDwbBgsn3Ciz9jB+1Nie/3EAwQU5hGRt8dVg9WeIAXecXXj uU/uFRM0JGvObIU8ziGU0newQaSyWDDxtkvvP3+/e+zCtbA4t7gxNdUet7aTqEEsbACQsy HalNG+0MK7woGdR8u1bE0/RENClbcMBWx7YNxtDN58vEEh8SQGTnw6CiRiSCHg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646870251; a=rsa-sha256; cv=none; b=otTVZLWhQc+O3pZZpCGEtHvAOkDwesOZKF5B5Qx+Za5pt7R9R6kVjkZNSNl5n5ev610t9L zvH1hKQSd2pcLBovalVPGNDdqgUbE7MdPUNMXvwLkEdT5EwsapWDwgcfZXu/AMoUlBItgi 79WtGxuOIG7duDvkZitLtc4mPFzmu2Z+b9cjm9MqDz7pwAR13wVboDv7ajqjOPe48qSWyQ yQIFjiK4nzeZ1huQobrezVYZ1fSRl6JazDYNHDqfEcKijhzWiIueDqatJglaY/tsEUrPEi k8nCqarpqrDJmERnfo+t8F/HtYV0S4s958lHZrJpV1Umq2i9wLmna0pPd7mqJg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=730510dc1ab2049d707706241d9a6e73a6952a4e commit 730510dc1ab2049d707706241d9a6e73a6952a4e Author: John Baldwin AuthorDate: 2022-03-09 23:38:49 +0000 Commit: John Baldwin CommitDate: 2022-03-09 23:38:49 +0000 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 --- usr.sbin/bhyve/bhyverun.c | 2 +- usr.sbin/bhyve/mem.c | 9 ++++++--- usr.sbin/bhyve/mem.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index 734239b38a8b..0f3c6e60e1d9 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -1445,7 +1445,7 @@ main(int argc, char *argv[]) exit(4); } - init_mem(); + init_mem(guest_ncpus); init_inout(); kernemu_dev_init(); init_bootrom(ctx); diff --git a/usr.sbin/bhyve/mem.c b/usr.sbin/bhyve/mem.c index 49a468305769..0a1c4e29972b 100644 --- a/usr.sbin/bhyve/mem.c +++ b/usr.sbin/bhyve/mem.c @@ -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; @@ -352,7 +353,7 @@ unregister_mem(struct mem_range *memp) RB_REMOVE(mmio_rb_tree, &mmio_rb_root, entry); /* flush Per-vCPU cache */ - for (i=0; i < VM_MAXCPU; i++) { + for (i = 0; i < mmio_ncpu; i++) { if (mmio_hint[i] == entry) mmio_hint[i] = NULL; } @@ -367,9 +368,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); diff --git a/usr.sbin/bhyve/mem.h b/usr.sbin/bhyve/mem.h index 38d773c43fdb..965079107476 100644 --- a/usr.sbin/bhyve/mem.h +++ b/usr.sbin/bhyve/mem.h @@ -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);