From patchwork Wed Dec 4 09:43:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11272581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 436EB138C for ; Wed, 4 Dec 2019 09:44:55 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 124A0206DF for ; Wed, 4 Dec 2019 09:44:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="LCN7/Ies" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 124A0206DF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Inumbo-ID: 902b5acc-167a-11ea-aea8-bc764e2007e4 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) 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 (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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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é --- 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 -struct vmcb_struct *alloc_vmcb(void) +struct vmcb_struct *alloc_vmcb(void) { struct vmcb_struct *vmcb; @@ -56,18 +56,15 @@ static int construct_vmcb(struct vcpu *v) struct svm_vcpu *svm = &v->arch.hvm.svm; struct vmcb_struct *vmcb = svm->vmcb; - /* Build-time check of the size of VMCB AMD structure. */ - BUILD_BUG_ON(sizeof(*vmcb) != PAGE_SIZE); - - vmcb->_general1_intercepts = + vmcb->_general1_intercepts = GENERAL1_INTERCEPT_INTR | GENERAL1_INTERCEPT_NMI | GENERAL1_INTERCEPT_SMI | GENERAL1_INTERCEPT_INIT | GENERAL1_INTERCEPT_CPUID | GENERAL1_INTERCEPT_INVD | - GENERAL1_INTERCEPT_HLT | GENERAL1_INTERCEPT_INVLPG | + 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 = + vmcb->_general2_intercepts = 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) /* Virtualise EFLAGS.IF and LAPIC TPR (CR8). */ vmcb->_vintr.fields.intr_masking = 1; - - /* Initialise event injection to no-op. */ - vmcb->eventinj.bytes = 0; - - /* TSC. */ - vmcb->_tsc_offset = 0; /* 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 |= GENERAL2_INTERCEPT_RDTSCP; } - /* Guest EFER. */ - v->arch.hvm.guest_efer = 0; - hvm_update_guest_efer(v); - /* Guest segment limits. */ vmcb->cs.limit = ~0u; vmcb->es.limit = ~0u; @@ -131,14 +118,6 @@ static int construct_vmcb(struct vcpu *v) vmcb->fs.limit = ~0u; vmcb->gs.limit = ~0u; - /* Guest segment bases. */ - vmcb->cs.base = 0; - vmcb->es.base = 0; - vmcb->ss.base = 0; - vmcb->ds.base = 0; - vmcb->fs.base = 0; - vmcb->gs.base = 0; - /* Guest segment AR bytes. */ vmcb->es.attr = 0xc93; /* read/write, accessed */ vmcb->ss.attr = 0xc93; @@ -147,29 +126,13 @@ static int construct_vmcb(struct vcpu *v) vmcb->gs.attr = 0xc93; vmcb->cs.attr = 0xc9b; /* exec/read, accessed */ - /* Guest IDT. */ - vmcb->idtr.base = 0; - vmcb->idtr.limit = 0; - - /* Guest GDT. */ - vmcb->gdtr.base = 0; - vmcb->gdtr.limit = 0; - - /* Guest LDT. */ - vmcb->ldtr.sel = 0; - vmcb->ldtr.base = 0; - vmcb->ldtr.limit = 0; - vmcb->ldtr.attr = 0; - /* Guest TSS. */ vmcb->tr.attr = 0x08b; /* 32-bit TSS (busy) */ - vmcb->tr.base = 0; vmcb->tr.limit = 0xff; v->arch.hvm.guest_cr[0] = X86_CR0_PE | X86_CR0_ET; + hvm_update_guest_efer(v); hvm_update_guest_cr(v, 0); - - v->arch.hvm.guest_cr[4] = 0; hvm_update_guest_cr(v, 4); paging_update_paging_modes(v); @@ -212,8 +175,6 @@ static int construct_vmcb(struct vcpu *v) vmcb->_pause_filter_thresh = SVM_PAUSETHRESH_INIT; } - vmcb->cleanbits.bytes = 0; - return 0; } @@ -268,7 +229,7 @@ static void vmcb_dump(unsigned char ch) { struct domain *d; struct vcpu *v; - + printk("*********** VMCB Areas **************\n"); rcu_read_lock(&domlist_read_lock); @@ -297,14 +258,26 @@ void __init setup_vmcb_dump(void) 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) != PAGE_SIZE); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _pause_filter_thresh) != 0x03c); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _vintr) != 0x060); + BUILD_BUG_ON(offsetof(struct vmcb_struct, eventinj) != 0x0a8); + BUILD_BUG_ON(offsetof(struct vmcb_struct, es) != 0x400); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _cpl) != 0x4cb); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _cr4) != 0x548); + BUILD_BUG_ON(offsetof(struct vmcb_struct, rsp) != 0x5d8); + BUILD_BUG_ON(offsetof(struct vmcb_struct, rax) != 0x5f8); + BUILD_BUG_ON(offsetof(struct vmcb_struct, _g_pat) != 0x668); /* Check struct segment_register against the VMCB segment layout. */ - BUILD_BUG_ON(sizeof(sreg) != 16); - BUILD_BUG_ON(sizeof(sreg.sel) != 2); - BUILD_BUG_ON(sizeof(sreg.attr) != 2); - BUILD_BUG_ON(sizeof(sreg.limit) != 4); - BUILD_BUG_ON(sizeof(sreg.base) != 8); + BUILD_BUG_ON(sizeof(vmcb.es) != 16); + BUILD_BUG_ON(sizeof(vmcb.es.sel) != 2); + BUILD_BUG_ON(sizeof(vmcb.es.attr) != 2); + BUILD_BUG_ON(sizeof(vmcb.es.limit) != 4); + BUILD_BUG_ON(sizeof(vmcb.es.base) != 8); BUILD_BUG_ON(offsetof(struct segment_register, sel) != 0); BUILD_BUG_ON(offsetof(struct segment_register, attr) != 2); BUILD_BUG_ON(offsetof(struct segment_register, limit) != 4); diff --git a/xen/include/asm-x86/hvm/svm/vmcb.h b/xen/include/asm-x86/hvm/svm/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 */