From patchwork Tue Dec 3 22:30:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11271919 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 D6B386C1 for ; Tue, 3 Dec 2019 22:32:46 +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 A665120684 for ; Tue, 3 Dec 2019 22:32:46 +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="MQ2j9VqW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A665120684 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 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 X-Inumbo-ID: a20b8d42-161c-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 a20b8d42-161c-11ea-aea8-bc764e2007e4; Tue, 03 Dec 2019 22:31:22 +0000 (UTC) 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 (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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" VT-x updates RF before vmexit, so eflags written into the outgoing TSS happens 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é 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 base, uint32_t limit) 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 = current; struct cpu_user_regs *regs = guest_cpu_user_regs(); @@ -2988,7 +2988,7 @@ void hvm_task_switch( eflags &= ~X86_EFLAGS_NT; tss.eip = regs->eip + insn_len; - tss.eflags = eflags; + tss.eflags = eflags | extra_eflags; tss.eax = regs->eax; tss.ecx = regs->ecx; tss.edx = 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 = (uint32_t)vmcb->exitinfo2; - 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; } 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 = -1; - hvm_task_switch(exit_qualification, reasons[source], ecode, inst_len); + hvm_task_switch(exit_qualification, reasons[source], ecode, inst_len, + 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 enable); 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); enum hvm_access_type { hvm_access_insn_fetch,