From patchwork Mon Jan 9 11:03:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9504363 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2A82B60710 for ; Mon, 9 Jan 2017 11:18:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37442282ED for ; Mon, 9 Jan 2017 11:18:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BC5F2848D; Mon, 9 Jan 2017 11:18:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A37FA282ED for ; Mon, 9 Jan 2017 11:18:39 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQXwH-0003it-QJ; Mon, 09 Jan 2017 11:16:33 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQXwG-0003hM-Jr for xen-devel@lists.xen.org; Mon, 09 Jan 2017 11:16:32 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id EB/B8-15112-F0173785; Mon, 09 Jan 2017 11:16:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXpe/sDj C4NAGcYslHxezODB6HN39mymAMYo1My8pvyKBNePwm8vsBZv0Ks59Z29gfKrcxcjJISHgL3F/ 710WEJtNQF9i94tPTCC2iIC6xOmOi6xdjFwczAJbGSVu7TjCDJIQFnCRePRuHVgDi4CKROudQ 2ANvAJeEk/6vjFBDJWTOH/8J1g9J1B82p8TjCC2kICnxMKHL5ghbDWJa/2X2CF6BSVOznwCNp NZQELi4IsXzBMYeWchSc1CklrAyLSKUaM4tagstUjXyEQvqSgzPaMkNzEzR9fQwEwvN7W4ODE 9NScxqVgvOT93EyMweBiAYAfjynWBhxglOZiURHkdowoihPiS8lMqMxKLM+KLSnNSiw8xynBw KEnw5uUXRwgJFqWmp1akZeYAwxgmLcHBoyTCOxskzVtckJhbnJkOkTrFqCglznsDJCEAksgoz YNrg8XOJUZZKWFeRqBDhHgKUotyM0tQ5V8xinMwKgnzLgKZwpOZVwI3/RXQYiagxZF2YItLEh FSUg2MLNxv17a5LN/O4+rp9iy0daW5DKdrrtcshgOX0+bdvvHIeItMydHjC/Yf/L/MzetWRM+ eoKex4QU/Zm5tlVO52HruVmBAxf6NPfJyq/QjRVnlFVIC/cLf7br8VHiW7sbaraoyKqfvaF3d oHN20eMN4o+c9y+3X7PoaJHo0m06MctW2s/TKrnQo8RSnJFoqMVcVJwIAPKuLR6YAgAA X-Env-Sender: prvs=175ce6123=Andrew.Cooper3@citrix.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1483960586!68499925!3 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46828 invoked from network); 9 Jan 2017 11:16:31 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 9 Jan 2017 11:16:31 -0000 X-IronPort-AV: E=Sophos;i="5.33,339,1477958400"; d="scan'208";a="407515705" From: Andrew Cooper To: Xen-devel Date: Mon, 9 Jan 2017 11:03:31 +0000 Message-ID: <1483959822-30484-15-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1483959822-30484-1-git-send-email-andrew.cooper3@citrix.com> References: <1483959822-30484-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Boris Ostrovsky , Suravee Suthikulpanit , Jan Beulich Subject: [Xen-devel] [PATCH v2 14/25] x86/svm: Improvements using named features X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This avoids calling into hvm_cpuid() to obtain information which is directly available. In particular, this avoids the need to overload flag_dr_dirty because of hvm_cpuid() being unavailable in svm_save_dr(). flag_dr_dirty is returned to a boolean (as it was before c/s c097f549 which introduced the need to overload it). While returning it to type bool, remove the use of bool_t for the adjacent fields. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Reviewed-by: Boris Ostrovsky --- CC: Jan Beulich CC: Boris Ostrovsky CC: Suravee Suthikulpanit v2: * Fix commit message. * Return flag_dr_dirty to being a boolean. --- xen/arch/x86/hvm/svm/svm.c | 33 ++++++++------------------------- xen/include/asm-x86/hvm/vcpu.h | 10 +++++----- 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 6fb1cbc..e9c6d69 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -173,7 +173,7 @@ static void svm_save_dr(struct vcpu *v) v->arch.hvm_vcpu.flag_dr_dirty = 0; vmcb_set_dr_intercepts(vmcb, ~0u); - if ( flag_dr_dirty & 2 ) + if ( v->domain->arch.cpuid->extd.dbext ) { svm_intercept_msr(v, MSR_AMD64_DR0_ADDRESS_MASK, MSR_INTERCEPT_RW); svm_intercept_msr(v, MSR_AMD64_DR1_ADDRESS_MASK, MSR_INTERCEPT_RW); @@ -196,8 +196,6 @@ static void svm_save_dr(struct vcpu *v) static void __restore_debug_registers(struct vmcb_struct *vmcb, struct vcpu *v) { - unsigned int ecx; - if ( v->arch.hvm_vcpu.flag_dr_dirty ) return; @@ -205,8 +203,8 @@ static void __restore_debug_registers(struct vmcb_struct *vmcb, struct vcpu *v) vmcb_set_dr_intercepts(vmcb, 0); ASSERT(v == current); - hvm_cpuid(0x80000001, NULL, NULL, &ecx, NULL); - if ( test_bit(X86_FEATURE_DBEXT & 31, &ecx) ) + + if ( v->domain->arch.cpuid->extd.dbext ) { svm_intercept_msr(v, MSR_AMD64_DR0_ADDRESS_MASK, MSR_INTERCEPT_NONE); svm_intercept_msr(v, MSR_AMD64_DR1_ADDRESS_MASK, MSR_INTERCEPT_NONE); @@ -217,9 +215,6 @@ static void __restore_debug_registers(struct vmcb_struct *vmcb, struct vcpu *v) wrmsrl(MSR_AMD64_DR1_ADDRESS_MASK, v->arch.hvm_svm.dr_mask[1]); wrmsrl(MSR_AMD64_DR2_ADDRESS_MASK, v->arch.hvm_svm.dr_mask[2]); wrmsrl(MSR_AMD64_DR3_ADDRESS_MASK, v->arch.hvm_svm.dr_mask[3]); - - /* Can't use hvm_cpuid() in svm_save_dr(): v != current. */ - v->arch.hvm_vcpu.flag_dr_dirty |= 2; } write_debugreg(0, v->arch.debugreg[0]); @@ -1359,11 +1354,7 @@ static void svm_init_erratum_383(struct cpuinfo_x86 *c) static int svm_handle_osvw(struct vcpu *v, uint32_t msr, uint64_t *val, bool_t read) { - unsigned int ecx; - - /* Guest OSVW support */ - hvm_cpuid(0x80000001, NULL, NULL, &ecx, NULL); - if ( !test_bit((X86_FEATURE_OSVW & 31), &ecx) ) + if ( !v->domain->arch.cpuid->extd.osvw ) return -1; if ( read ) @@ -1622,8 +1613,6 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) switch ( msr ) { - unsigned int ecx; - case MSR_IA32_SYSENTER_CS: *msr_content = v->arch.hvm_svm.guest_sysenter_cs; break; @@ -1701,15 +1690,13 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) break; case MSR_AMD64_DR0_ADDRESS_MASK: - hvm_cpuid(0x80000001, NULL, NULL, &ecx, NULL); - if ( !test_bit(X86_FEATURE_DBEXT & 31, &ecx) ) + if ( !v->domain->arch.cpuid->extd.dbext ) goto gpf; *msr_content = v->arch.hvm_svm.dr_mask[0]; break; case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK: - hvm_cpuid(0x80000001, NULL, NULL, &ecx, NULL); - if ( !test_bit(X86_FEATURE_DBEXT & 31, &ecx) ) + if ( !v->domain->arch.cpuid->extd.dbext ) goto gpf; *msr_content = v->arch.hvm_svm.dr_mask[msr - MSR_AMD64_DR1_ADDRESS_MASK + 1]; @@ -1783,8 +1770,6 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) switch ( msr ) { - unsigned int ecx; - case MSR_IA32_SYSENTER_CS: vmcb->sysenter_cs = v->arch.hvm_svm.guest_sysenter_cs = msr_content; break; @@ -1862,15 +1847,13 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) break; case MSR_AMD64_DR0_ADDRESS_MASK: - hvm_cpuid(0x80000001, NULL, NULL, &ecx, NULL); - if ( !test_bit(X86_FEATURE_DBEXT & 31, &ecx) || (msr_content >> 32) ) + if ( !v->domain->arch.cpuid->extd.dbext || (msr_content >> 32) ) goto gpf; v->arch.hvm_svm.dr_mask[0] = msr_content; break; case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK: - hvm_cpuid(0x80000001, NULL, NULL, &ecx, NULL); - if ( !test_bit(X86_FEATURE_DBEXT & 31, &ecx) || (msr_content >> 32) ) + if ( !v->domain->arch.cpuid->extd.dbext || (msr_content >> 32) ) goto gpf; v->arch.hvm_svm.dr_mask[msr - MSR_AMD64_DR1_ADDRESS_MASK + 1] = msr_content; diff --git a/xen/include/asm-x86/hvm/vcpu.h b/xen/include/asm-x86/hvm/vcpu.h index 7b411a8..17ab9c0 100644 --- a/xen/include/asm-x86/hvm/vcpu.h +++ b/xen/include/asm-x86/hvm/vcpu.h @@ -162,12 +162,12 @@ struct hvm_vcpu { spinlock_t tm_lock; struct list_head tm_list; - u8 flag_dr_dirty; - bool_t debug_state_latch; - bool_t single_step; + bool flag_dr_dirty; + bool debug_state_latch; + bool single_step; - bool_t hcall_preempted; - bool_t hcall_64bit; + bool hcall_preempted; + bool hcall_64bit; struct hvm_vcpu_asid n1asid;