From nobody Wed Apr 26 14:13:58 2023 X-Original-To: dev-commits-src-all@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 4Q617q11pyz46ZMm; Wed, 26 Apr 2023 14:13:59 +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 4Q617q0R2Gz4MKV; Wed, 26 Apr 2023 14:13:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682518439; 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=YZIb1O+D1YKbgYwi42aOdG2TaJm7KX1MHk0vXszeUn4=; b=x5zrzvLi/SnJViBefFVVLjid7lKl1ysVg8ANyXaKi1jjjMshyPTZXdBQ63+c118bCxz1W9 Js1rq6GgfU+dR7JWWFLWrG3JjPdwrItr+YkxYIWZWXlkJcRRUCA/LNbcYY24Tx4QD5OyqZ FbAGwC2ppPR00M4iBqFQHYol92/2Aojaktgh9XwdI/o1OFLo4dCa1KWnGSzGHMHk9MfRo7 i3ol1UhOzyYgNqkMhbnnDPzp+SrBE0QES6lzjy7jrZeXT5Y4lbzfs3TFnHcFY2m0pEHvyS zvtDvW1y/IxM5tcRbvGAeb87UB9hZDboqXdgZBQConPXTSY62Rb0MAiCXJ0T9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682518439; 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=YZIb1O+D1YKbgYwi42aOdG2TaJm7KX1MHk0vXszeUn4=; b=H2DPO9tYsrpbAO9Xt2ZFndAJlPM7fgZD6+NKgI0HCgIKoYe87rjv+Pz9B4HMulccM+3Kat bOO9aew7gYeyPetgFxaipr2lKNI4KytTpvfumRgpcQlJMaMyvtsYmhVZnNsyQN9g5Bx2k+ NUwB8e4+QNdM9q5e1X7RoxKCSlcs0/0lEB4mOFBzBIIW9UWzDuhRhgSeWm8bItrLXIC0Uq WiW+mLdjV6I/2zrd1qhoKY7SHSc0pcZzHK/BLrDmF4d8UODRgTwQSa1+eFQy+er3qXjdKR hbgkvccqJqzK67vJgy11gomMT0/FSQEGEqrnE1efm0ifJKqjQdkGAREGsVtPew== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682518439; a=rsa-sha256; cv=none; b=LyhGN7jQWPrleUZ363Js/YUs9K6DT9N2bNKmSaRGZO1Y0J6abkbv/fF3h/tQ3hWUXUUQ8n wK+qmQO0LsHVKs9Bn7nlx4rYXS3GgEuARaWha3QWfmQoyyH0Brv0z1i7Jj1Ji7CARgtqg6 Egin9LFbLbWaPoEBGoGJeampLJAHpVoLWd+sunFJXsWxMQEllsjtG/92p5JosvArUN1aTX qSs0DwWwnHUR/wDVKWpvV68Y6NY/zCkKHMT57oXg25Ub2ugeOHDHnKbxfJqiduShQ2/W78 1yPkEDEtAwnCQlVMxKDt443Jbhxv9PPH9WRroMJgPpr3kkwYzyH928R00L0koA== 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 4Q617p6c1Mzcqk; Wed, 26 Apr 2023 14:13:58 +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 33QEDwH6086648; Wed, 26 Apr 2023 14:13:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33QEDwI6086647; Wed, 26 Apr 2023 14:13:58 GMT (envelope-from git) Date: Wed, 26 Apr 2023 14:13:58 GMT Message-Id: <202304261413.33QEDwI6086647@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 74ac712f72cf - main - vmm: Dynamically allocate a couple of per-CPU state save areas List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 74ac712f72cfd6d7b3db3c9d3b72ccf2824aa183 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=74ac712f72cfd6d7b3db3c9d3b72ccf2824aa183 commit 74ac712f72cfd6d7b3db3c9d3b72ccf2824aa183 Author: Mark Johnston AuthorDate: 2023-04-26 14:08:42 +0000 Commit: Mark Johnston CommitDate: 2023-04-26 14:08:42 +0000 vmm: Dynamically allocate a couple of per-CPU state save areas This avoids bloating the BSS when MAXCPU is large. No functional change intended. PR: 269572 Reviewed by: corvink, rew Tested by: rew MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39805 --- sys/amd64/vmm/amd/svm.c | 11 ++++++----- sys/amd64/vmm/intel/vmx.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/sys/amd64/vmm/amd/svm.c b/sys/amd64/vmm/amd/svm.c index d995b68ebdc6..0af7342128f2 100644 --- a/sys/amd64/vmm/amd/svm.c +++ b/sys/amd64/vmm/amd/svm.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -123,10 +124,8 @@ SYSCTL_UINT(_hw_vmm_svm, OID_AUTO, num_asids, CTLFLAG_RDTUN, &nasid, 0, /* Current ASID generation for each host cpu */ static struct asid asid[MAXCPU]; -/* - * SVM host state saved area of size 4KB for each core. - */ -static uint8_t hsave[MAXCPU][PAGE_SIZE] __aligned(PAGE_SIZE); +/* SVM host state saved area of size 4KB for each physical core. */ +static uint8_t *hsave; static VMM_STAT_AMD(VCPU_EXITINTINFO, "VM exits during event delivery"); static VMM_STAT_AMD(VCPU_INTINFO_INJECTED, "Events pending at VM entry"); @@ -167,6 +166,7 @@ svm_modcleanup(void) { smp_rendezvous(NULL, svm_disable, NULL, NULL); + kmem_free(hsave, (mp_maxid + 1) * PAGE_SIZE); return (0); } @@ -214,7 +214,7 @@ svm_enable(void *arg __unused) efer |= EFER_SVM; wrmsr(MSR_EFER, efer); - wrmsr(MSR_VM_HSAVE_PA, vtophys(hsave[curcpu])); + wrmsr(MSR_VM_HSAVE_PA, vtophys(&hsave[curcpu * PAGE_SIZE])); } /* @@ -269,6 +269,7 @@ svm_modinit(int ipinum) svm_npt_init(ipinum); /* Enable SVM on all CPUs */ + hsave = kmem_malloc((mp_maxid + 1) * PAGE_SIZE, M_WAITOK | M_ZERO); smp_rendezvous(NULL, svm_enable, NULL, NULL); return (0); diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c index 32e53de4e8ee..55ed5fdf1a00 100644 --- a/sys/amd64/vmm/intel/vmx.c +++ b/sys/amd64/vmm/intel/vmx.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -134,7 +135,7 @@ SYSCTL_NODE(_hw_vmm, OID_AUTO, vmx, CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, NULL); int vmxon_enabled[MAXCPU]; -static char vmxon_region[MAXCPU][PAGE_SIZE] __aligned(PAGE_SIZE); +static uint8_t *vmxon_region; static uint32_t pinbased_ctls, procbased_ctls, procbased_ctls2; static uint32_t exit_ctls, entry_ctls; @@ -618,6 +619,7 @@ vmx_modcleanup(void) nmi_flush_l1d_sw = 0; smp_rendezvous(NULL, vmx_disable, NULL, NULL); + kmem_free(vmxon_region, (mp_maxid + 1) * PAGE_SIZE); return (0); } @@ -638,8 +640,8 @@ vmx_enable(void *arg __unused) load_cr4(rcr4() | CR4_VMXE); - *(uint32_t *)vmxon_region[curcpu] = vmx_revision(); - error = vmxon(vmxon_region[curcpu]); + *(uint32_t *)&vmxon_region[curcpu * PAGE_SIZE] = vmx_revision(); + error = vmxon(&vmxon_region[curcpu * PAGE_SIZE]); if (error == 0) vmxon_enabled[curcpu] = 1; } @@ -649,7 +651,7 @@ vmx_modresume(void) { if (vmxon_enabled[curcpu]) - vmxon(vmxon_region[curcpu]); + vmxon(&vmxon_region[curcpu * PAGE_SIZE]); } static int @@ -953,6 +955,8 @@ vmx_modinit(int ipinum) vmx_msr_init(); /* enable VMX operation */ + vmxon_region = kmem_malloc((mp_maxid + 1) * PAGE_SIZE, + M_WAITOK | M_ZERO); smp_rendezvous(NULL, vmx_enable, NULL, NULL); vmx_initialized = 1;