Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4002878pxb; Tue, 2 Nov 2021 02:16:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDynEgU488Xm4ZAdkfBwpLyRFCX3AcsC++ZjFNPAYqcnrp+12B0wNlL8pa7owZ80DyyNG7 X-Received: by 2002:a05:6638:37a4:: with SMTP id w36mr13085887jal.135.1635844619479; Tue, 02 Nov 2021 02:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635844619; cv=none; d=google.com; s=arc-20160816; b=CvIOLIo9V/8XULXnCq9ky6wTjNTd3A7NvEKxz7rdRDgdcWdas4vynEZ2m4ZfLdEVho 63eR7pa+Jdtn/vpta8TmEBfrNFAdA5wDIKj5UGlq1nsOW8LpcbRL537d/fhBo7Ab8qv5 +EZ6y78umFSTcrfwFi8JH12WRmadrFqG4jpK5Y8mHwCxkc19pR5woJWyAF71q8ckEbeQ 6f6lIpKNQSR2JZDPwOzo+E282RLDfLpwFKSbymmV7O2T8XvdLzxGK02qLgauFiduVpa1 GANdBXlzK2oGBpc/KyIIQSRZq6RDCpXnF467y8WtxC3uLo04qzpMr3DTOBZGiUgDqa/1 Yphg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=I34IiGCmpm25oNi/vSYUlE3HKtfMa/5vtp3II3eAi3U=; b=vE4wxb0YE98iuXfKU4vV/uLLabBspRC2jjTOPFYl9TBq6XD8TLIGEA0gcJCkSral9L d77RDzSJDHZwjuDbBSq6LwU6OwD0jP3Jx4pQuMfMIxrVo+SH5RE0KeLaFH26KJf/dVKo M5ClKbPh+/sA7taohhwYOXfJg6BDtFg6GSrIkAYy0cgLvLGjUTy/lfZkGf9Ny/EtjeRN iVgyFGFh/+1GT3naKKNDvS3TaFfWuekaUQv9EipzmlTcws+UA5EU/CZ4LhuCEaEJzioZ I79zff6RtNzH1k1sNLXHIBr+eSx4PmApmidnIe8ql4q40+4zkHmPWG17/cTk5r6qwFpo UyqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si12938711ils.73.2021.11.02.02.16.47; Tue, 02 Nov 2021 02:16:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230508AbhKBJSM (ORCPT + 99 others); Tue, 2 Nov 2021 05:18:12 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:50987 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230353AbhKBJSK (ORCPT ); Tue, 2 Nov 2021 05:18:10 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R971e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=houwenlong93@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0Uuk1u78_1635844533; Received: from localhost(mailfrom:houwenlong93@linux.alibaba.com fp:SMTPD_---0Uuk1u78_1635844533) by smtp.aliyun-inc.com(127.0.0.1); Tue, 02 Nov 2021 17:15:34 +0800 From: Hou Wenlong To: kvm@vger.kernel.org Cc: Sean Christopherson , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] KVM: x86: Handle 32-bit wrap of EIP for EMULTYPE_SKIP with flat code seg Date: Tue, 2 Nov 2021 17:15:29 +0800 Message-Id: <093eabb1eab2965201c9b018373baf26ff256d85.1635842679.git.houwenlong93@linux.alibaba.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Truncate the new EIP to a 32-bit value when handling EMULTYPE_SKIP as the decode phase does not truncate _eip. Wrapping the 32-bit boundary is legal if and only if CS is a flat code segment, but that check is implicitly handled in the form of limit checks in the decode phase. Opportunstically prepare for a future fix by storing the result of any truncation in "eip" instead of "_eip". Fixes: 1957aa63be53 ("KVM: VMX: Handle single-step #DB for EMULTYPE_SKIP on EPT misconfig") Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ac83d873d65b..3d7fc5c21ceb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8124,7 +8124,12 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, * updating interruptibility state and injecting single-step #DBs. */ if (emulation_type & EMULTYPE_SKIP) { - kvm_rip_write(vcpu, ctxt->_eip); + if (ctxt->mode != X86EMUL_MODE_PROT64) + ctxt->eip = (u32)ctxt->_eip; + else + ctxt->eip = ctxt->_eip; + + kvm_rip_write(vcpu, ctxt->eip); if (ctxt->eflags & X86_EFLAGS_RF) kvm_set_rflags(vcpu, ctxt->eflags & ~X86_EFLAGS_RF); return 1; -- 2.31.1