From nobody Mon Feb 9 16:02:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) 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=1575452674; cv=none; d=zohomail.com; s=zohoarc; b=cD0B3ZsHaWZr6o9aVDpU3MKLybkw3p6BWX0kqbJaPBHRn1yX2cdopI/2zonjGtYtqPebiMjb61COruAua34PNDnm1vlTU+oZUU8XAotWaIHiBRT7Ony6e1eyA5hqn3UwlcbeJ5PJbYxqU/Kq2yUACKySZxHtCeE8RHtzRkATrw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575452674; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lc65bwbnNhcG3a84K3GLERLeqky3mwhf+eTtjUMSCfQ=; b=Dz1UU4n5aiK4cNQxRa8GJdrk5crMk8yZgWREkuN1+4S+kXSgeXDY2dOuDKE6X8Z5CfstlE0iRMtEbALJ7YW4zMgy9QIp1MxktIK/SA6qgMJzmdUmMLa9QL4gXKzDoNASHD//8ighEXiaemziwR+XXAtrRb8jz+m6ZYKjUghZ6Ck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) 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 1575452674924429.39266224932874; Wed, 4 Dec 2019 01:44:34 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1icRCF-0003yh-HM; Wed, 04 Dec 2019 09:43:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1icRCE-0003yU-V7 for xen-devel@lists.xenproject.org; Wed, 04 Dec 2019 09:43:46 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 902b5acc-167a-11ea-aea8-bc764e2007e4; Wed, 04 Dec 2019 09:43:45 +0000 (UTC) X-Inumbo-ID: 902b5acc-167a-11ea-aea8-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1575452626; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UjxfZ5DAfYsDXEEc3ZAUZf3h9tTy3ZWaxc1BJtVU4Ks=; b=LCN7/IesC1NWoLsa3BKsPFGUoBtCv57Rx2l5OwZSWMXFBRlzfCoHn10u IiMmhkWSsOIx7iKgdqJpJo/lB29P0wwxQsN2psFheWSxhsEDZwSAhCh2s vac6fKCic+FpGgeMfEcQl3I57YjdBNIu2N6PEwF0E0a8WS4EsXiMuM8j3 Y=; Authentication-Results: esa2.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: none (zohomail.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; Received-SPF: None (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Sw9aki1fwRvtHFacX0TPics9rvEHo6lkWTD/HftQeXkFxpQmrLryMz068PctApOKhATeimLuQG YkH42aRyK+pUX2dAgDW/023ZgWr6X184k06SMQQMzRIiCL5TMIqUP/tz5hFvBvAb8mFUkZ0wv3 4H50P+CPnXytnB8zkbeJLhLfS2YJdVZTXklfBGU9l87QReiP408AuaVPHtRqoj7wEuVMrWUmdW 5XJNDuNdJR2dHE890xFwBqTgrZUb7v/8Ii/zZmvRiIyNSzfGx3yI18S0p25Wo6FmfzVfqzyw4Q /Ac= X-SBRS: 2.7 X-MesageID: 9179623 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,277,1571716800"; d="scan'208";a="9179623" From: Andrew Cooper To: Xen-devel Date: Wed, 4 Dec 2019 09:43:32 +0000 Message-ID: <20191204094335.24603-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191204094335.24603-1-andrew.cooper3@citrix.com> References: <20191204094335.24603-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/4] x86/svm: Clean up construct_vmcb() 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?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The vmcb is zeroed on allocate - drop all explicit writes of 0. Move hvm_update_guest_efer() to co-locate it with the other control register updates. Move the BUILD_BUG_ON() into build_assertions(), and add some offset checks for fields after the large blocks of reserved fields (as these are the most likely to trigger from a mis-edit). Take the opportunity to fold 6 adjacent res* fields into one. Finally, drop all trailing whitespace in the file. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/hvm/svm/vmcb.c | 75 ++++++++++++----------------------= ---- xen/include/asm-x86/hvm/svm/vmcb.h | 7 +--- 2 files changed, 25 insertions(+), 57 deletions(-) diff --git a/xen/arch/x86/hvm/svm/vmcb.c b/xen/arch/x86/hvm/svm/vmcb.c index 1fef0da22c..fa13fc0b6b 100644 --- a/xen/arch/x86/hvm/svm/vmcb.c +++ b/xen/arch/x86/hvm/svm/vmcb.c @@ -30,7 +30,7 @@ #include #include =20 -struct vmcb_struct *alloc_vmcb(void)=20 +struct vmcb_struct *alloc_vmcb(void) { struct vmcb_struct *vmcb; =20 @@ -56,18 +56,15 @@ static int construct_vmcb(struct vcpu *v) struct svm_vcpu *svm =3D &v->arch.hvm.svm; struct vmcb_struct *vmcb =3D svm->vmcb; =20 - /* Build-time check of the size of VMCB AMD structure. */ - BUILD_BUG_ON(sizeof(*vmcb) !=3D PAGE_SIZE); - - vmcb->_general1_intercepts =3D=20 + vmcb->_general1_intercepts =3D GENERAL1_INTERCEPT_INTR | GENERAL1_INTERCEPT_NMI | GENERAL1_INTERCEPT_SMI | GENERAL1_INTERCEPT_INIT | GENERAL1_INTERCEPT_CPUID | GENERAL1_INTERCEPT_INVD | - GENERAL1_INTERCEPT_HLT | GENERAL1_INTERCEPT_INVLPG |=20 + GENERAL1_INTERCEPT_HLT | GENERAL1_INTERCEPT_INVLPG | GENERAL1_INTERCEPT_INVLPGA | GENERAL1_INTERCEPT_IOIO_PROT | GENERAL1_INTERCEPT_MSR_PROT | GENERAL1_INTERCEPT_SHUTDOWN_EVT| GENERAL1_INTERCEPT_TASK_SWITCH; - vmcb->_general2_intercepts =3D=20 + vmcb->_general2_intercepts =3D GENERAL2_INTERCEPT_VMRUN | GENERAL2_INTERCEPT_VMMCALL | GENERAL2_INTERCEPT_VMLOAD | GENERAL2_INTERCEPT_VMSAVE | GENERAL2_INTERCEPT_STGI | GENERAL2_INTERCEPT_CLGI | @@ -105,12 +102,6 @@ static int construct_vmcb(struct vcpu *v) =20 /* Virtualise EFLAGS.IF and LAPIC TPR (CR8). */ vmcb->_vintr.fields.intr_masking =3D 1; - =20 - /* Initialise event injection to no-op. */ - vmcb->eventinj.bytes =3D 0; - - /* TSC. */ - vmcb->_tsc_offset =3D 0; =20 /* Don't need to intercept RDTSC if CPU supports TSC rate scaling */ if ( v->domain->arch.vtsc && !cpu_has_tsc_ratio ) @@ -119,10 +110,6 @@ static int construct_vmcb(struct vcpu *v) vmcb->_general2_intercepts |=3D GENERAL2_INTERCEPT_RDTSCP; } =20 - /* Guest EFER. */ - v->arch.hvm.guest_efer =3D 0; - hvm_update_guest_efer(v); - /* Guest segment limits. */ vmcb->cs.limit =3D ~0u; vmcb->es.limit =3D ~0u; @@ -131,14 +118,6 @@ static int construct_vmcb(struct vcpu *v) vmcb->fs.limit =3D ~0u; vmcb->gs.limit =3D ~0u; =20 - /* Guest segment bases. */ - vmcb->cs.base =3D 0; - vmcb->es.base =3D 0; - vmcb->ss.base =3D 0; - vmcb->ds.base =3D 0; - vmcb->fs.base =3D 0; - vmcb->gs.base =3D 0; - /* Guest segment AR bytes. */ vmcb->es.attr =3D 0xc93; /* read/write, accessed */ vmcb->ss.attr =3D 0xc93; @@ -147,29 +126,13 @@ static int construct_vmcb(struct vcpu *v) vmcb->gs.attr =3D 0xc93; vmcb->cs.attr =3D 0xc9b; /* exec/read, accessed */ =20 - /* Guest IDT. */ - vmcb->idtr.base =3D 0; - vmcb->idtr.limit =3D 0; - - /* Guest GDT. */ - vmcb->gdtr.base =3D 0; - vmcb->gdtr.limit =3D 0; - - /* Guest LDT. */ - vmcb->ldtr.sel =3D 0; - vmcb->ldtr.base =3D 0; - vmcb->ldtr.limit =3D 0; - vmcb->ldtr.attr =3D 0; - /* Guest TSS. */ vmcb->tr.attr =3D 0x08b; /* 32-bit TSS (busy) */ - vmcb->tr.base =3D 0; vmcb->tr.limit =3D 0xff; =20 v->arch.hvm.guest_cr[0] =3D X86_CR0_PE | X86_CR0_ET; + hvm_update_guest_efer(v); hvm_update_guest_cr(v, 0); - - v->arch.hvm.guest_cr[4] =3D 0; hvm_update_guest_cr(v, 4); =20 paging_update_paging_modes(v); @@ -212,8 +175,6 @@ static int construct_vmcb(struct vcpu *v) vmcb->_pause_filter_thresh =3D SVM_PAUSETHRESH_INIT; } =20 - vmcb->cleanbits.bytes =3D 0; - return 0; } =20 @@ -268,7 +229,7 @@ static void vmcb_dump(unsigned char ch) { struct domain *d; struct vcpu *v; - =20 + printk("*********** VMCB Areas **************\n"); =20 rcu_read_lock(&domlist_read_lock); @@ -297,14 +258,26 @@ void __init setup_vmcb_dump(void) =20 static void __init __maybe_unused build_assertions(void) { - struct segment_register sreg; + struct vmcb_struct vmcb; + + /* Build-time check of the VMCB layout. */ + BUILD_BUG_ON(sizeof(vmcb) !=3D PAGE_SIZE); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _pause_filter_thresh) !=3D 0= x03c); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _vintr) !=3D 0= x060); + BUILD_BUG_ON(offsetof(struct vmcb_struct, eventinj) !=3D 0= x0a8); + BUILD_BUG_ON(offsetof(struct vmcb_struct, es) !=3D 0= x400); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _cpl) !=3D 0= x4cb); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _cr4) !=3D 0= x548); + BUILD_BUG_ON(offsetof(struct vmcb_struct, rsp) !=3D 0= x5d8); + BUILD_BUG_ON(offsetof(struct vmcb_struct, rax) !=3D 0= x5f8); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _g_pat) !=3D 0= x668); =20 /* Check struct segment_register against the VMCB segment layout. */ - BUILD_BUG_ON(sizeof(sreg) !=3D 16); - BUILD_BUG_ON(sizeof(sreg.sel) !=3D 2); - BUILD_BUG_ON(sizeof(sreg.attr) !=3D 2); - BUILD_BUG_ON(sizeof(sreg.limit) !=3D 4); - BUILD_BUG_ON(sizeof(sreg.base) !=3D 8); + BUILD_BUG_ON(sizeof(vmcb.es) !=3D 16); + BUILD_BUG_ON(sizeof(vmcb.es.sel) !=3D 2); + BUILD_BUG_ON(sizeof(vmcb.es.attr) !=3D 2); + BUILD_BUG_ON(sizeof(vmcb.es.limit) !=3D 4); + BUILD_BUG_ON(sizeof(vmcb.es.base) !=3D 8); BUILD_BUG_ON(offsetof(struct segment_register, sel) !=3D 0); BUILD_BUG_ON(offsetof(struct segment_register, attr) !=3D 2); BUILD_BUG_ON(offsetof(struct segment_register, limit) !=3D 4); diff --git a/xen/include/asm-x86/hvm/svm/vmcb.h b/xen/include/asm-x86/hvm/s= vm/vmcb.h index 5c710286f7..e37220edf2 100644 --- a/xen/include/asm-x86/hvm/svm/vmcb.h +++ b/xen/include/asm-x86/hvm/svm/vmcb.h @@ -406,12 +406,7 @@ struct vmcb_struct { u32 _exception_intercepts; /* offset 0x08 - cleanbit 0 */ u32 _general1_intercepts; /* offset 0x0C - cleanbit 0 */ u32 _general2_intercepts; /* offset 0x10 - cleanbit 0 */ - u32 res01; /* offset 0x14 */ - u64 res02; /* offset 0x18 */ - u64 res03; /* offset 0x20 */ - u64 res04; /* offset 0x28 */ - u64 res05; /* offset 0x30 */ - u32 res06; /* offset 0x38 */ + u32 res01[10]; u16 _pause_filter_thresh; /* offset 0x3C - cleanbit 0 */ u16 _pause_filter_count; /* offset 0x3E - cleanbit 0 */ u64 _iopm_base_pa; /* offset 0x40 - cleanbit 1 */ --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel