From patchwork Mon Jun 17 12:54:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 10999221 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66EDB14B6 for ; Mon, 17 Jun 2019 12:56:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 568902875A for ; Mon, 17 Jun 2019 12:56:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B0232890F; Mon, 17 Jun 2019 12:56:53 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2165A2875A for ; Mon, 17 Jun 2019 12:56:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hcr9q-0002Lk-JP; Mon, 17 Jun 2019 12:54:46 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hcr9o-0002Lf-Nb for xen-devel@lists.xenproject.org; Mon, 17 Jun 2019 12:54:44 +0000 X-Inumbo-ID: 1396042f-90ff-11e9-8980-bc764e045a96 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 1396042f-90ff-11e9-8980-bc764e045a96; Mon, 17 Jun 2019 12:54:43 +0000 (UTC) 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 ~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: PLSOq16NuV9vyrTibMrM2sT10ts7W+SDnc76MZHBG4CbMxsleI+xpkCSDqRzLZ7GiDE3aXXX3E F64IGkogs2+FkkrO1DWCoxzsrtzOqhSgCOjNs2Mkvsn3aEKY1kWTKItkeukAFX6c+b8wwXHM+5 h27zDklHo0wIu0738P37LUro88u6d3zc4FE/KtD3IRqG+DM1vRMMizQ+fd0QeAok9J/YPwwBzq rI04K5Fb1T5JpAvujHzGybeaIfZIrI2gBVqD15pQcDGOWTE7ZZ52oW4F0GVzqFw5JiHbpXG5wA 9Ic= X-SBRS: 2.7 X-MesageID: 1819360 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.63,385,1557201600"; d="scan'208";a="1819360" From: Andrew Cooper To: Xen-devel Date: Mon, 17 Jun 2019 13:54:39 +0100 Message-ID: <1560776079-9866-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/svm: Fix svm_vmcb_dump() when used in current context 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: Jan Beulich , Wei Liu , Andrew Cooper , Suravee Suthikulpanit , Boris Ostrovsky , Brian Woods , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP VMExit doesn't switch all state. The FS/GS/TS/LDTR/GSBASE segment information, and SYSCALL/SYSENTER MSRs may still be cached in hardware, rather than up-to-date in the VMCB. Export svm_sync_vmcb() via svmdebug.h so svm_vmcb_dump() can use it, and bring the VMCB into sync in current context. As a minor optimisation, switch svm_sync_vmcb() to use svm_vm{load,save}_pa(), as svm->vmcb_pa is always in correct, and this avoids a redundant __pa() translation behind the scenes. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Acked-by: Brian Woods --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Boris Ostrovsky CC: Suravee Suthikulpanit CC: Brian Woods --- xen/arch/x86/hvm/svm/svm.c | 6 +++--- xen/arch/x86/hvm/svm/svmdebug.c | 9 +++++++++ xen/include/asm-x86/hvm/svm/svmdebug.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index cd6a6b3..0eac9ce 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -627,21 +627,21 @@ static void svm_cpuid_policy_changed(struct vcpu *v) cp->extd.ibpb ? MSR_INTERCEPT_NONE : MSR_INTERCEPT_RW); } -static void svm_sync_vmcb(struct vcpu *v, enum vmcb_sync_state new_state) +void svm_sync_vmcb(struct vcpu *v, enum vmcb_sync_state new_state) { struct svm_vcpu *svm = &v->arch.hvm.svm; if ( new_state == vmcb_needs_vmsave ) { if ( svm->vmcb_sync_state == vmcb_needs_vmload ) - svm_vmload(svm->vmcb); + svm_vmload_pa(svm->vmcb_pa); svm->vmcb_sync_state = new_state; } else { if ( svm->vmcb_sync_state == vmcb_needs_vmsave ) - svm_vmsave(svm->vmcb); + svm_vmsave_pa(svm->vmcb_pa); if ( svm->vmcb_sync_state != vmcb_needs_vmload ) svm->vmcb_sync_state = new_state; diff --git a/xen/arch/x86/hvm/svm/svmdebug.c b/xen/arch/x86/hvm/svm/svmdebug.c index d35e405..4293d8d 100644 --- a/xen/arch/x86/hvm/svm/svmdebug.c +++ b/xen/arch/x86/hvm/svm/svmdebug.c @@ -29,6 +29,15 @@ static void svm_dump_sel(const char *name, const struct segment_register *s) void svm_vmcb_dump(const char *from, const struct vmcb_struct *vmcb) { + struct vcpu *curr = current; + + /* + * If we are dumping the VMCB currently in context, some guest state may + * still be cached in hardware. Retrieve it. + */ + if ( vmcb == curr->arch.hvm.svm.vmcb ) + svm_sync_vmcb(curr, vmcb_in_sync); + printk("Dumping guest's current state at %s...\n", from); printk("Size of VMCB = %zu, paddr = %"PRIpaddr", vaddr = %p\n", sizeof(struct vmcb_struct), virt_to_maddr(vmcb), vmcb); diff --git a/xen/include/asm-x86/hvm/svm/svmdebug.h b/xen/include/asm-x86/hvm/svm/svmdebug.h index 658cdd3..330c1d9 100644 --- a/xen/include/asm-x86/hvm/svm/svmdebug.h +++ b/xen/include/asm-x86/hvm/svm/svmdebug.h @@ -22,6 +22,7 @@ #include #include +void svm_sync_vmcb(struct vcpu *v, enum vmcb_sync_state new_state); void svm_vmcb_dump(const char *from, const struct vmcb_struct *vmcb); bool svm_vmcb_isvalid(const char *from, const struct vmcb_struct *vmcb, const struct vcpu *v, bool verbose);