From nobody Mon May 6 22:12:23 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1556210782; cv=none; d=zoho.com; s=zohoarc; b=ntCDQ4NOQ/XEsswsPEozKgStgaCsNw0LxH+MLlqIhcaLx3pUsacpKO0I6nM4UboMK1oK8KcKuWA6U+oIAr6uQF7JfNbdD2ogWJOz9q055lLlOShquYyFvEqTlRBlw9R63vq6ueXnVSgNJRse5AgDJM/TjchsSi49j3Jfz60CJrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556210782; 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:ARC-Authentication-Results; bh=p70j6lIlSvbtDFxYBmtWTL/bj0nT0+5gj6FGsS5iP/s=; b=gIfjEfhNjoF5tWPC0+lxeiPQ7YeQJ6k7IzLmnY2WMr5/NOw8z+CzWyPpR0w6XBnBRb9wz1cNytnKGyx/jL6eBqizFHKYv4EmCpFQVES5xWKLjU4KC+H3DXYmBYvueZCXnH5XIdbR3URdK+pzorQv18Ecp3dXNbaqrKdPLYCyaBU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 155621078197740.80980044240971; Thu, 25 Apr 2019 09:46:21 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJhUT-000886-Ga; Thu, 25 Apr 2019 16:44:53 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJhUS-000881-1D for xen-devel@lists.xenproject.org; Thu, 25 Apr 2019 16:44:52 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7087484e-6779-11e9-af66-ef0685a7421a; Thu, 25 Apr 2019 16:44:49 +0000 (UTC) X-Inumbo-ID: 7087484e-6779-11e9-af66-ef0685a7421a X-IronPort-AV: E=Sophos;i="5.60,394,1549929600"; d="scan'208";a="84423919" From: Andrew Cooper To: Xen-devel Date: Thu, 25 Apr 2019 17:44:45 +0100 Message-ID: <1556210685-2549-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/vvmx: Simplify per-CPU memory allocations X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , Wei Liu , Jan Beulich , Andrew Cooper , Jun Nakajima , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" * Use XFREE() instead of opencoding it in nvmx_cpu_dead() * Avoid redundant evaluations of per_cpu() * Don't allocate vvmcs_buf at all if it isn't going to be used. It is nev= er touched on hardware lacking the VMCS Shadowing feature. Signed-off-by: Andrew Cooper Acked-by: Kevin Tian Reviewed-by: Wei Liu --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Jun Nakajima CC: Kevin Tian --- xen/arch/x86/hvm/vmx/vvmx.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 991445e..7bca572 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -40,21 +40,25 @@ static bool nvmx_vcpu_in_vmx(const struct vcpu *v) =20 int nvmx_cpu_up_prepare(unsigned int cpu) { - if ( per_cpu(vvmcs_buf, cpu) !=3D NULL ) - return 0; + uint64_t **vvmcs_buf; =20 - per_cpu(vvmcs_buf, cpu) =3D xzalloc_array(u64, VMCS_BUF_SIZE); + if ( cpu_has_vmx_vmcs_shadowing && + (vvmcs_buf =3D &per_cpu(vvmcs_buf, cpu)) =3D=3D NULL ) + { + void *ptr =3D xzalloc_array(uint64_t, VMCS_BUF_SIZE); =20 - if ( per_cpu(vvmcs_buf, cpu) !=3D NULL ) - return 0; + if ( !ptr ) + return -ENOMEM; =20 - return -ENOMEM; + *vvmcs_buf =3D ptr; + } + + return 0; } =20 void nvmx_cpu_dead(unsigned int cpu) { - xfree(per_cpu(vvmcs_buf, cpu)); - per_cpu(vvmcs_buf, cpu) =3D NULL; + XFREE(per_cpu(vvmcs_buf, cpu)); } =20 int nvmx_vcpu_initialise(struct vcpu *v) --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel