From nobody Thu Apr 18 18:37:55 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=hygon.cn ARC-Seal: i=1; a=rsa-sha256; t=1585046391; cv=none; d=zohomail.com; s=zohoarc; b=LDF8fgPEPApKm6EaU5JEmO8QxRkzxDWmUyoq4Dqc713VPVg4tgemJS3sxdtIHH3P1OQFzG95aVDcUN3DVQ7ZoDB42QDAbQ/XP101DQ66lCGRRN7RCa2Hjbnd2f+G4yIPpQfl6MbG/yxBf13SX8d/i0FSMjVYB3UcF3fWjqRAwoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585046391; 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=R3D2aesFd2FV60vMlxK64kLAHX7QxIfl0deMZoU6ujw=; b=b0FhY9E8BND6Nhj9hYPYPGI+H3Z/yifoy0gDvgfeEwbOTFmbHHzggGovnTlM4Bdbh+YwCtKssnyud3EmiCpZ0xTZ8bjfs1d6V/swYPeEop+u0vqcEdtfrQaR78g2uaatYxmqrLLRsXQE4xDIeWmtj3yvj8rFFzUS4IUMO+m6WWo= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1585046391252351.20173708668676; Tue, 24 Mar 2020 03:39:51 -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 1jGgxo-0003KY-OD; Tue, 24 Mar 2020 10:39:16 +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 1jGgxn-0003KO-Ca for xen-devel@lists.xenproject.org; Tue, 24 Mar 2020 10:39:15 +0000 Received: from spam1.hygon.cn (unknown [110.188.70.11]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b2339f24-6dbb-11ea-83be-12813bfff9fa; Tue, 24 Mar 2020 10:39:12 +0000 (UTC) Received: from MK-DB.hygon.cn ([172.23.18.60]) by spam1.hygon.cn with ESMTP id 02OAcPqe007139; Tue, 24 Mar 2020 18:38:25 +0800 (GMT-8) (envelope-from puwen@hygon.cn) Received: from cncheex01.Hygon.cn ([172.23.18.10]) by MK-DB.hygon.cn with ESMTP id 02OAcIIJ083274; Tue, 24 Mar 2020 18:38:19 +0800 (GMT-8) (envelope-from puwen@hygon.cn) Received: from ubuntu1604-2.higon.com (172.23.18.44) by cncheex01.Hygon.cn (172.23.18.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1466.3; Tue, 24 Mar 2020 18:38:00 +0800 X-Inumbo-ID: b2339f24-6dbb-11ea-83be-12813bfff9fa From: Pu Wen To: Date: Tue, 24 Mar 2020 18:37:26 +0800 Message-ID: <20200324103726.3406-1-puwen@hygon.cn> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.23.18.44] X-ClientProxiedBy: cncheex02.Hygon.cn (172.23.18.12) To cncheex01.Hygon.cn (172.23.18.10) X-MAIL: spam1.hygon.cn 02OAcPqe007139 X-DNSRBL: Subject: [Xen-devel] [PATCH v2] SVM: Add union intstat_t for offset 68h in vmcb struct 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: Pu Wen , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Jan Beulich , Andrew Cooper Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" According to chapter "Appendix B Layout of VMCB" in the new version (v3.32) AMD64 APM[1], bit 1 of the VMCB offset 68h is defined as GUEST_INTERRUPT_MASK. In current xen codes, it use whole u64 interrupt_shadow to setup interrupt shadow, which will misuse other bit in VMCB offset 68h as part of interrupt_shadow. Add union intstat_t for VMCB offset 68h and fix codes to only use bit 0 as intr_shadow according to the new APM description. Reference: [1] https://www.amd.com/system/files/TechDocs/24593.pdf Signed-off-by: Pu Wen --- v1->v2: - Copy the whole int_stat in nsvm_vmcb_prepare4vmrun() and nsvm_vmcb_prepare4vmexit(). - Dump all 64 bits of int_stat in svm_vmcb_dump(). xen/arch/x86/hvm/svm/nestedsvm.c | 8 ++++---- xen/arch/x86/hvm/svm/svm.c | 8 ++++---- xen/arch/x86/hvm/svm/svmdebug.c | 4 ++-- xen/include/asm-x86/hvm/svm/vmcb.h | 13 ++++++++++++- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nested= svm.c index 3bd2a119d3..bbd06e342e 100644 --- a/xen/arch/x86/hvm/svm/nestedsvm.c +++ b/xen/arch/x86/hvm/svm/nestedsvm.c @@ -507,8 +507,8 @@ static int nsvm_vmcb_prepare4vmrun(struct vcpu *v, stru= ct cpu_user_regs *regs) n2vmcb->_vintr.fields.intr_masking =3D 1; } =20 - /* Shadow Mode */ - n2vmcb->interrupt_shadow =3D ns_vmcb->interrupt_shadow; + /* Interrupt state */ + n2vmcb->int_stat =3D ns_vmcb->int_stat; =20 /* Exit codes */ n2vmcb->exitcode =3D ns_vmcb->exitcode; @@ -1057,8 +1057,8 @@ nsvm_vmcb_prepare4vmexit(struct vcpu *v, struct cpu_u= ser_regs *regs) if (!(svm->ns_hostflags.fields.vintrmask)) ns_vmcb->_vintr.fields.intr_masking =3D 0; =20 - /* Shadow mode */ - ns_vmcb->interrupt_shadow =3D n2vmcb->interrupt_shadow; + /* Interrupt state */ + ns_vmcb->int_stat =3D n2vmcb->int_stat; =20 /* Exit codes */ ns_vmcb->exitcode =3D n2vmcb->exitcode; diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 32d8d847f2..888f504a94 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -116,7 +116,7 @@ void __update_guest_eip(struct cpu_user_regs *regs, uns= igned int inst_len) regs->rip +=3D inst_len; regs->eflags &=3D ~X86_EFLAGS_RF; =20 - curr->arch.hvm.svm.vmcb->interrupt_shadow =3D 0; + curr->arch.hvm.svm.vmcb->int_stat.intr_shadow =3D 0; =20 if ( regs->eflags & X86_EFLAGS_TF ) hvm_inject_hw_exception(TRAP_debug, X86_EVENT_NO_EC); @@ -432,7 +432,7 @@ static unsigned int svm_get_interrupt_shadow(struct vcp= u *v) struct vmcb_struct *vmcb =3D v->arch.hvm.svm.vmcb; unsigned int intr_shadow =3D 0; =20 - if ( vmcb->interrupt_shadow ) + if ( vmcb->int_stat.intr_shadow ) intr_shadow |=3D HVM_INTR_SHADOW_MOV_SS | HVM_INTR_SHADOW_STI; =20 if ( vmcb_get_general1_intercepts(vmcb) & GENERAL1_INTERCEPT_IRET ) @@ -446,7 +446,7 @@ static void svm_set_interrupt_shadow(struct vcpu *v, un= signed int intr_shadow) struct vmcb_struct *vmcb =3D v->arch.hvm.svm.vmcb; u32 general1_intercepts =3D vmcb_get_general1_intercepts(vmcb); =20 - vmcb->interrupt_shadow =3D + vmcb->int_stat.intr_shadow =3D !!(intr_shadow & (HVM_INTR_SHADOW_MOV_SS|HVM_INTR_SHADOW_STI)); =20 general1_intercepts &=3D ~GENERAL1_INTERCEPT_IRET; @@ -2945,7 +2945,7 @@ void svm_vmexit_handler(struct cpu_user_regs *regs) * retired. */ general1_intercepts &=3D ~GENERAL1_INTERCEPT_IRET; - vmcb->interrupt_shadow =3D 1; + vmcb->int_stat.intr_shadow =3D 1; =20 vmcb_set_general1_intercepts(vmcb, general1_intercepts); break; diff --git a/xen/arch/x86/hvm/svm/svmdebug.c b/xen/arch/x86/hvm/svm/svmdebu= g.c index 366a003f21..5aa9d410ba 100644 --- a/xen/arch/x86/hvm/svm/svmdebug.c +++ b/xen/arch/x86/hvm/svm/svmdebug.c @@ -51,9 +51,9 @@ void svm_vmcb_dump(const char *from, const struct vmcb_st= ruct *vmcb) printk("iopm_base_pa =3D %#"PRIx64" msrpm_base_pa =3D %#"PRIx64" tsc_o= ffset =3D %#"PRIx64"\n", vmcb_get_iopm_base_pa(vmcb), vmcb_get_msrpm_base_pa(vmcb), vmcb_get_tsc_offset(vmcb)); - printk("tlb_control =3D %#x vintr =3D %#"PRIx64" interrupt_shadow =3D = %#"PRIx64"\n", + printk("tlb_control =3D %#x vintr =3D %#"PRIx64" int_stat =3D %#"PRIx6= 4"\n", vmcb->tlb_control, vmcb_get_vintr(vmcb).bytes, - vmcb->interrupt_shadow); + vmcb->int_stat.raw); printk("event_inj %016"PRIx64", valid? %d, ec? %d, type %u, vector %#x= \n", vmcb->event_inj.raw, vmcb->event_inj.v, vmcb->event_inj.ev, vmcb->event_inj.type, diff --git a/xen/include/asm-x86/hvm/svm/vmcb.h b/xen/include/asm-x86/hvm/s= vm/vmcb.h index b9e389d481..d8a3285752 100644 --- a/xen/include/asm-x86/hvm/svm/vmcb.h +++ b/xen/include/asm-x86/hvm/svm/vmcb.h @@ -316,6 +316,17 @@ typedef union uint64_t raw; } intinfo_t; =20 +typedef union +{ + struct + { + u64 intr_shadow: 1; + u64 guest_intr_mask:1; + u64 resvd: 62; + }; + uint64_t raw; +} intstat_t; + typedef union { u64 bytes; @@ -414,7 +425,7 @@ struct vmcb_struct { u8 tlb_control; /* offset 0x5C */ u8 res07[3]; vintr_t _vintr; /* offset 0x60 - cleanbit 3 */ - u64 interrupt_shadow; /* offset 0x68 */ + intstat_t int_stat; /* offset 0x68 */ u64 exitcode; /* offset 0x70 */ union { struct { --=20 2.23.0