From nobody Thu May 2 19:35:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1586866510; cv=none; d=zohomail.com; s=zohoarc; b=YLnbb0q3Ow09po3OT5URi1DbU+kPy9NGQfOjxSaU0mZTaLB7Yv1GAU7I/ke2vH11tT7kwDmNsjA9ismOumJ7Izdor6DF5NCwtw8nSxwkexyIyw8OTaToBc/xdCfib/5Ox080vkBOtsqVH2HWpORbRJR3fHsZ7KHEWzpr58YfC7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586866510; 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=Ua1YG2ew4Kno0swoW4LnfCs5XUZNV5d8zZQvA37lVUg=; b=THMjjvZy8V5jD5qju2JorE2rdl0IfGwrsNWMOnnNxyEoPaf6dEem4JVWQ3oXDOu5mIr/tJ4z74WlB2rHnM/QBn9V+dj0F+KBdtUNAuc6s+0xi5R7I08MJZKwuzyeCneQPCYl1KaFzYOtKgU6kB8NMG3U4L09UyGYNc8+Wl7YdEY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none 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 1586866510848603.0236172208081; Tue, 14 Apr 2020 05:15:10 -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 1jOKSb-00029M-5F; Tue, 14 Apr 2020 12:14:37 +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 1jOKSa-00029B-3S for xen-devel@lists.xenproject.org; Tue, 14 Apr 2020 12:14:36 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 80d2288a-7e49-11ea-8928-12813bfff9fa; Tue, 14 Apr 2020 12:14:35 +0000 (UTC) X-Inumbo-ID: 80d2288a-7e49-11ea-8928-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1586866476; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=kgWPLuNDZlpjxPv12VjGHkKvWtekNwVRANDpyMTHKGo=; b=ONcagt/ZcR0MtaoHKXlpJQF9PaExFECOS8nUuDzXTPHfRHKWRCm/O0A8 XHUnZOZJtAxPdtNvuFSYbgqAU7kpDn/Zkuuu9WCQ+BBmhOvRadMLt5LKG h9NBziS34xrXK63bXhyq4G6DJmEt1zgtj8PjRISvpnZyjyBnXYaUnYT38 4=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com 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; Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: JcXBX/xzh2A5GRXFwQsJvmtN95l6wgl2UkLOT6Sy55EMN4kNaRLu/hOmcqGvAE46WzB7z/A3bM quygnqwB3NoXUjkT0yc6R4tdCr0Jm1n5YWGtPcVWOsE3pJvJ++LIm2hjWV6fv0EimPYRmov31v geGB2UA0V752BJ3qaWzHjLolQjDSfJnSe6M0ukVS0wGDGEMaqCM2djVHQF/NRegUlabkTf0mhQ 0qLbNZa8jf2PFlKV1C1H8ctSnu0m/4h7CdfHgHLMOoqNjCahCV55qs1oFok2RZGSCJX01wexn4 OgA= X-SBRS: 2.7 X-MesageID: 15621407 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,382,1580792400"; d="scan'208";a="15621407" From: Andrew Cooper To: Xen-devel Subject: [PATCH] x86/svm: Don't use vmcb->tlb_control as if it is a boolean Date: Tue, 14 Apr 2020 13:14:29 +0100 Message-ID: <20200414121429.10196-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-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: Andrew Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) svm_asid_handle_vmrun() treats tlb_control as if it were boolean, but this = has been superseded by new additions to the SVM spec. Introduce an enum containing all legal values, and update svm_asid_handle_vmrun() to use appropriate constants. While adjusting this, take the opportunity to fix up two coding style issue= s, and trim the include list. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 N.B. Deliberately not updating the code to use TLB_CTRL_FLUSH_ASID. The safety of the current ASID logic depends on flusing everything when the ASID wraps. --- xen/arch/x86/hvm/svm/asid.c | 14 ++++++-------- xen/include/asm-x86/hvm/svm/vmcb.h | 13 ++++++++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/hvm/svm/asid.c b/xen/arch/x86/hvm/svm/asid.c index e554e25213..b7a737fdc1 100644 --- a/xen/arch/x86/hvm/svm/asid.c +++ b/xen/arch/x86/hvm/svm/asid.c @@ -15,12 +15,9 @@ * this program; If not, see . */ =20 -#include -#include -#include -#include #include #include +#include =20 void svm_asid_init(const struct cpuinfo_x86 *c) { @@ -44,19 +41,20 @@ void svm_asid_handle_vmrun(void) struct hvm_vcpu_asid *p_asid =3D nestedhvm_vcpu_in_guestmode(curr) ? &vcpu_nestedhvm(curr).nv_n2asid : &curr->arch.hvm.n1asid; - bool_t need_flush =3D hvm_asid_handle_vmenter(p_asid); + bool need_flush =3D hvm_asid_handle_vmenter(p_asid); =20 /* ASID 0 indicates that ASIDs are disabled. */ if ( p_asid->asid =3D=3D 0 ) { vmcb_set_guest_asid(vmcb, 1); - vmcb->tlb_control =3D 1; + vmcb->tlb_control =3D TLB_CTRL_FLUSH_ALL; return; } =20 - if (vmcb_get_guest_asid(vmcb) !=3D p_asid->asid) + if ( vmcb_get_guest_asid(vmcb) !=3D p_asid->asid ) vmcb_set_guest_asid(vmcb, p_asid->asid); - vmcb->tlb_control =3D need_flush; + + vmcb->tlb_control =3D need_flush ? TLB_CTRL_FLUSH_ALL : TLB_CTRL_NO_FL= USH; } =20 /* diff --git a/xen/include/asm-x86/hvm/svm/vmcb.h b/xen/include/asm-x86/hvm/s= vm/vmcb.h index e5ed38369e..c2e1972feb 100644 --- a/xen/include/asm-x86/hvm/svm/vmcb.h +++ b/xen/include/asm-x86/hvm/svm/vmcb.h @@ -302,6 +302,17 @@ enum VMEXIT_EXITCODE VMEXIT_INVALID =3D -1 }; =20 +enum +{ + /* Available on all SVM-capable hardware. */ + TLB_CTRL_NO_FLUSH =3D 0, + TLB_CTRL_FLUSH_ALL =3D 1, + + /* Available with the FlushByASID feature. */ + TLB_CTRL_FLUSH_ASID =3D 3, + TLB_CTRL_FLUSH_ASID_NONGLOBAL =3D 7, +}; + typedef union { struct @@ -419,7 +430,7 @@ struct vmcb_struct { u64 _msrpm_base_pa; /* offset 0x48 - cleanbit 1 */ u64 _tsc_offset; /* offset 0x50 - cleanbit 0 */ u32 _guest_asid; /* offset 0x58 - cleanbit 2 */ - u8 tlb_control; /* offset 0x5C */ + u8 tlb_control; /* offset 0x5C - TLB_CTRL_* */ u8 res07[3]; vintr_t _vintr; /* offset 0x60 - cleanbit 3 */ intstat_t int_stat; /* offset 0x68 */ --=20 2.11.0