From nobody Thu May 2 21:07:22 2024 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=1575412341; cv=none; d=zohomail.com; s=zohoarc; b=lEgPB9mbw2CBl6CG8EIGjqBnXyks5hzox78G5igJhLjm1gfMzp1kJIW7XUwEopTPBrFglsqChZIj+YrBwG+foxpiM8Q8rFDgpR+vzQIEPOWDPtfd1pjpQqZgA7IDArVrAp7pSKiUh1Id7tFLPrTDO84u4Npm1GUEFL05kD1eK1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575412341; 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=2f6mnbtpxQMO6c297HkRqgFWaah1h89IvAJtVHP+/68=; b=UROUdEaGYKMixLRoHy+4SQY1tUmUO214oJeYmJFciKynkcL/fjeuoP1JIrrLd7VrB2NjismeH2LckAhHmPBnZCQiD3KpTuNmKI5Dpsiq0UyMyOYqX+TeKOjLmZhG4DF5S1VmmfL0I/KrRIAwV0+2BUrjQ47NdFx024KptZyd0Vo= 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 1575412341208946.0778215402265; Tue, 3 Dec 2019 14:32:21 -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 1icGhY-00087n-St; Tue, 03 Dec 2019 22:31:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1icGhX-000870-Jf for xen-devel@lists.xenproject.org; Tue, 03 Dec 2019 22:31:23 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a20b8d42-161c-11ea-aea8-bc764e2007e4; Tue, 03 Dec 2019 22:31:22 +0000 (UTC) X-Inumbo-ID: a20b8d42-161c-11ea-aea8-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1575412283; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Hem8Hhsba0SGjlUNwoELtBwvIxUFS1JBuZ9YIWk22f4=; b=MQ2j9VqWxMR2WLgxD1fHI1u+s7wWW3/KxHJ7F0j0qKQW4YyPiqTyate1 pxxqyWXNHEngk0ola1Ob35uwiEU867bgh+zUDYXf1EW6z4aitvgIZMFkg 4zsUqC0WvjwaUnAyBzhy7+OXPv++OS5GD5T9gcQH8Is0o8WhevANDRfMV g=; 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: 15O0xs/lAX3KfFwM6s6RzB3YXJkSiQsQsEtEtnVq5d1L61aX5HEdhh057BVrGhjnk8oWHpW0GB Y3Vj7eYZXnW0Q5J3qFMzgmpiK8TOX938d8lcjIVkchao7fztu6gPI1wc5QRMppApM+UiaJveWC PyH+PxY0oaIJ85+JUz/ue+yeQqLxSvNitugZiicB8AJ8TP3SHLcRlQyY+LkQmHKia3CAI09vK3 GjPe8ghJCLnwEVTXHx+fS/czuTl9yBru2RecWPuGNEcidtJmXE21XlAxFxLKURv4iA0Ffv95W6 PeA= X-SBRS: 2.7 X-MesageID: 9160237 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,275,1571716800"; d="scan'208";a="9160237" From: Andrew Cooper To: Xen-devel Date: Tue, 3 Dec 2019 22:30:46 +0000 Message-ID: <20191203223046.15011-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/svm: Fix handling of EFLAGS.RF on task switch 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: Juergen Gross , Kevin Tian , Jan Beulich , Wei Liu , Andrew Cooper , Jun Nakajima , =?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) VT-x updates RF before vmexit, so eflags written into the outgoing TSS happ= ens to be correct. SVM does not update RF before vmexit, and instead provides = it via a bit in exitinfo2. In practice, needing RF set in the outgoing state occurs when a task gate is used to handle faults. Extend hvm_task_switch() with an extra_eflags parameter which gets fed into the outgoing TSS, and fill it in suitably from the SVM vmexit information. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Reviewed-by: Kevin Tian --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Jun Nakajima CC: Kevin Tian CC: Juergen Gross Kevin: There is no help in the SDM about this. RF is not mentioned in the list of state either modified or unmodified by hardware on a task switch vmexit. This conclusion has been drawn from looking at the actual VMExit state given an XTF test poking every corner of TASK_SWITCH VMExits. Juergen: I know its getting stupidly late in the day, but this, like the previous fixes, want backporting. OTOH, the likelihood of not fixing it causing harm to VMs is minimal, unlike the earlier task switch fixes. --- xen/arch/x86/hvm/hvm.c | 4 ++-- xen/arch/x86/hvm/svm/svm.c | 3 ++- xen/arch/x86/hvm/vmx/vmx.c | 3 ++- xen/include/asm-x86/hvm/hvm.h | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 7f556171bd..47573f71b8 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2913,7 +2913,7 @@ void hvm_prepare_vm86_tss(struct vcpu *v, uint32_t ba= se, uint32_t limit) =20 void hvm_task_switch( uint16_t tss_sel, enum hvm_task_switch_reason taskswitch_reason, - int32_t errcode, unsigned int insn_len) + int32_t errcode, unsigned int insn_len, unsigned int extra_eflags) { struct vcpu *v =3D current; struct cpu_user_regs *regs =3D guest_cpu_user_regs(); @@ -2988,7 +2988,7 @@ void hvm_task_switch( eflags &=3D ~X86_EFLAGS_NT; =20 tss.eip =3D regs->eip + insn_len; - tss.eflags =3D eflags; + tss.eflags =3D eflags | extra_eflags; tss.eax =3D regs->eax; tss.ecx =3D regs->ecx; tss.edx =3D regs->edx; diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 0fb1908c18..6ae43999ff 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -2812,7 +2812,8 @@ void svm_vmexit_handler(struct cpu_user_regs *regs) if ( (vmcb->exitinfo2 >> 44) & 1 ) errcode =3D (uint32_t)vmcb->exitinfo2; =20 - hvm_task_switch(vmcb->exitinfo1, reason, errcode, insn_len); + hvm_task_switch(vmcb->exitinfo1, reason, errcode, insn_len, + (vmcb->exitinfo2 & (1ul << 48)) ? X86_EFLAGS_RF : = 0); break; } =20 diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 7450cbe40d..bafc3b30c5 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -3963,7 +3963,8 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) else ecode =3D -1; =20 - hvm_task_switch(exit_qualification, reasons[source], ecode, inst_l= en); + hvm_task_switch(exit_qualification, reasons[source], ecode, inst_l= en, + 0 /* EFLAGS.RF already updated. */); break; } case EXIT_REASON_CPUID: diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 17fb7efa6e..1d7b66f927 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -296,7 +296,7 @@ void hvm_set_rdtsc_exiting(struct domain *d, bool_t ena= ble); enum hvm_task_switch_reason { TSW_jmp, TSW_iret, TSW_call_or_int }; void hvm_task_switch( uint16_t tss_sel, enum hvm_task_switch_reason taskswitch_reason, - int32_t errcode, unsigned int insn_len); + int32_t errcode, unsigned int insn_len, unsigned int extra_eflags); =20 enum hvm_access_type { hvm_access_insn_fetch, --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel