From nobody Wed May 8 13:20:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1603720293; cv=none; d=zohomail.com; s=zohoarc; b=NJQAVS13Weeye0IR0MI8NvVxeNDfEIfmgueOJ5faANBlKKQ2XHTlMO1QI68u98kNx69SModHV4IXi4sCl2DF5usJRm7/a2OLuf3uFHTDRKk7fDpTWzRVAyyXqVEGs1Y6HDT+xqt4o0Xt+4OAO56A6bcU02yVuAMUfN6TJXbcnfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603720293; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=cZEgJVmSrpiANttPWL+aMIQIgWb/en4/y3t8LBOnvjQ=; b=Rt7iWeSkSpRbbIZTzC9J9SxILLlmlTZ3n5k0gZKrdBPIAyhstsqBzjY4RZ8QxG/bp831ctoQ1sDdcRwfnMNGIe2bKztnkgCaMwMq4iY2Eq2SLvZatUIWdDzDWFZPWDklc7cdSnDPUU5VC/uvaN8nOOsC3JcSEGz/2re6lomFfGI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1603720293720594.5505857769615; Mon, 26 Oct 2020 06:51:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.12338.32150 (Exim 4.92) (envelope-from ) id 1kX2u0-0007kx-6P; Mon, 26 Oct 2020 13:51:12 +0000 Received: by outflank-mailman (output) from mailman id 12338.32150; Mon, 26 Oct 2020 13:51:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kX2u0-0007kq-1f; Mon, 26 Oct 2020 13:51:12 +0000 Received: by outflank-mailman (input) for mailman id 12338; Mon, 26 Oct 2020 13:51:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kX2tx-0007kk-UA for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 13:51:10 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e895d521-8cdd-46f6-ad31-ddcdb911d708; Mon, 26 Oct 2020 13:51:08 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kX2tx-0007kk-UA for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 13:51:10 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e895d521-8cdd-46f6-ad31-ddcdb911d708; Mon, 26 Oct 2020 13:51:08 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e895d521-8cdd-46f6-ad31-ddcdb911d708 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1603720268; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Kige2qC+WVChCsv8oUthNVYbRyRDIDCpAo5fVpsVfGU=; b=RqTtGMZA1Fxq00PUkHlt7TRoM21mOB7pbO8X65dZdAbdgo1c2E23TCMW XOu4/DTxp8PDzNYn9aEQp869wNvxQIsbMgU406mJUIq4bfGQgWgRtxQqq kDi4XdFQtALITKByDfEpkBgEvDenChi6FZEm8zXgY0FnhNqEC9a/sfgKt 4=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: qNdgpFi9PYMhsprorFVrqIiX9PvX/m7CbJkn/iv/QpiWqC0vNd+NguKcQHoZKTCVqg+ch4F2bA bCkh1U6PjZYKnUN4KgHYMsDncR6UIThnDcWTCuNI6Ll8PTqCRI5/pQBS0ODaQD+uSmv4EtsHNa LFGnP5H37dnS51EVCO0kA4xy27CeRNfd1Txe5c1HUcHKhUK+HMg9sbioGMkWVwk+YUgEEkvGPf 39sSELdfS+ANib7WUZaTcn5ku2jv0Lm5u8bKoNMyqRVMnKBe64PmPBNqcd8ta+w1uLRel/6bla 6Bk= X-SBRS: None X-MesageID: 30026597 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.77,419,1596513600"; d="scan'208";a="30026597" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH] x86/svm: Merge hsa and host_vmcb to reduce memory overhead Date: Mon, 26 Oct 2020 13:50:43 +0000 Message-ID: <20201026135043.15560-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) The format of the Host State Area is, and has always been, a VMCB. It is explicitly safe to put the host VMSAVE data in. This removes 4k of memory allocation per pCPU. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu --- xen/arch/x86/hvm/svm/svm.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index cfea5b5523..9ec9ad0646 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -72,11 +72,10 @@ static void svm_update_guest_efer(struct vcpu *); static struct hvm_function_table svm_function_table; =20 /* - * Physical addresses of the Host State Area (for hardware) and vmcb (for = Xen) - * which contains Xen's fs/gs/tr/ldtr and GSBASE/STAR/SYSENTER state when = in - * guest vcpu context. + * Host State Area. This area is used by the processor in non-root mode, = and + * contains Xen's fs/gs/tr/ldtr and GSBASE/STAR/SYSENTER state required to + * leave guest vcpu context. */ -static DEFINE_PER_CPU_READ_MOSTLY(paddr_t, hsa); static DEFINE_PER_CPU_READ_MOSTLY(paddr_t, host_vmcb); #ifdef CONFIG_PV static DEFINE_PER_CPU(struct vmcb_struct *, host_vmcb_va); @@ -1436,15 +1435,8 @@ static bool svm_event_pending(const struct vcpu *v) =20 static void svm_cpu_dead(unsigned int cpu) { - paddr_t *this_hsa =3D &per_cpu(hsa, cpu); paddr_t *this_vmcb =3D &per_cpu(host_vmcb, cpu); =20 - if ( *this_hsa ) - { - free_domheap_page(maddr_to_page(*this_hsa)); - *this_hsa =3D 0; - } - #ifdef CONFIG_PV if ( per_cpu(host_vmcb_va, cpu) ) { @@ -1462,7 +1454,6 @@ static void svm_cpu_dead(unsigned int cpu) =20 static int svm_cpu_up_prepare(unsigned int cpu) { - paddr_t *this_hsa =3D &per_cpu(hsa, cpu); paddr_t *this_vmcb =3D &per_cpu(host_vmcb, cpu); nodeid_t node =3D cpu_to_node(cpu); unsigned int memflags =3D 0; @@ -1471,16 +1462,6 @@ static int svm_cpu_up_prepare(unsigned int cpu) if ( node !=3D NUMA_NO_NODE ) memflags =3D MEMF_node(node); =20 - if ( !*this_hsa ) - { - pg =3D alloc_domheap_page(NULL, memflags); - if ( !pg ) - goto err; - - clear_domain_page(page_to_mfn(pg)); - *this_hsa =3D page_to_maddr(pg); - } - if ( !*this_vmcb ) { pg =3D alloc_domheap_page(NULL, memflags); @@ -1597,7 +1578,7 @@ static int _svm_cpu_up(bool bsp) write_efer(read_efer() | EFER_SVME); =20 /* Initialize the HSA for this core. */ - wrmsrl(MSR_K8_VM_HSAVE_PA, per_cpu(hsa, cpu)); + wrmsrl(MSR_K8_VM_HSAVE_PA, per_cpu(host_vmcb, cpu)); =20 /* check for erratum 383 */ svm_init_erratum_383(c); --=20 2.11.0