Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1642891pxy; Mon, 2 Aug 2021 06:57:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTOMkpWlz24afL4e2cDmz1fkwANkTXoFiXzss9VlzTd2KFnTflIMJ8QFRXhK5LR4MBWqOL X-Received: by 2002:a05:6e02:1c0b:: with SMTP id l11mr556478ilh.126.1627912622351; Mon, 02 Aug 2021 06:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912622; cv=none; d=google.com; s=arc-20160816; b=LxvSZZBF53bMNUIrjsyWlgtzkO8qJ13rrjbVB7mv4AwWO/wtfbuixVAYWrcnrMJNIP 2ZnID4tvb/4yXZ8ZXw+kXqXAAYZux0VgO+kmX3F9Y0lUi3b5TVFE1sXsxvT/Dq7vVDEg xdj7IZ6DxOEnE09bD+9ad971dDcrZxft+d94uLoOG0tbISEaXAXnoowI93m7k+Kr7HPr lfHpShpbD5Xwou3lfTpPLdPNY9TbT/NODJiIRmS+YEClPX6GTKaa7w6JAEUqimiYsiZT ZHLD+FCUqrUuNh5g1nuLZz9UYMxbl0wpp4OQ19drh91JbbTARQOsvdBGigrq9Rs2ApHD VQIg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XhuLm2bpWZBmm79aLeSKeD0KSg+qqVhNxIlIfupnEWs=; b=XrOJe2MCelnlqXI45gOcMPopYsrsv71h1GDVOTDuyG0ZBr3wlF1OpN8sbCGnOvykzY BmcUUKc06IpxashXg3cvoQgxSgpN6qqmyrg4DNTuy/wVF7yRX2mA3b5WCF+3UwUvHlBr 5rVcpZMAiqRS+aUASalI54bN2WdbSdgGEn5bLw0yEIzTXKQi4JNDjPhLVlTyhxFaKOLn 3zbUt/jjxIMAUcCtpvV+cmK9cXxrne9/+T9wL5kIxmoWISiwDpcsNsCq2l8xAEjL2bdW Hby5XSVO1hFYWYba6TS+3OeEq33rS7frmiIuM1S+vSlT5kXqvbBwVO9cLWE7JzeI4SXz eqMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dQFM5HqI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c14si13744993ilq.3.2021.08.02.06.56.51; Mon, 02 Aug 2021 06:57:02 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dQFM5HqI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234599AbhHBNyG (ORCPT + 99 others); Mon, 2 Aug 2021 09:54:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:57350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234592AbhHBNsh (ORCPT ); Mon, 2 Aug 2021 09:48:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E420E61107; Mon, 2 Aug 2021 13:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912108; bh=TUWF7pC9bbQD+WsDAERejsnRof4qp+LWg45M6s2YuWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dQFM5HqIPHFPWpy5ZioNI5Z5X8CP/ZDnqz5ox6Rgxh00KylLNQqPOdSiXIEd2ZkWe 3vlyzxpHvh/lClvcGQufgu7tPOKuc93acnllAXGuN1EkhfIoI6i15r/9IsILWyYkf1 qfNJUjV1CMcHA8KAI8QUBg5dROAwuu9aZOKarb3Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Levitsky , Paolo Bonzini , Zubin Mithra Subject: [PATCH 4.14 02/38] KVM: x86: determine if an exception has an error code only when injecting it. Date: Mon, 2 Aug 2021 15:44:24 +0200 Message-Id: <20210802134334.913798979@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802134334.835358048@linuxfoundation.org> References: <20210802134334.835358048@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maxim Levitsky commit b97f074583736c42fb36f2da1164e28c73758912 upstream. A page fault can be queued while vCPU is in real paged mode on AMD, and AMD manual asks the user to always intercept it (otherwise result is undefined). The resulting VM exit, does have an error code. Signed-off-by: Maxim Levitsky Message-Id: <20210225154135.405125-2-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini Signed-off-by: Zubin Mithra Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -400,8 +400,6 @@ static void kvm_multiple_exception(struc if (!vcpu->arch.exception.pending && !vcpu->arch.exception.injected) { queue: - if (has_error && !is_protmode(vcpu)) - has_error = false; if (reinject) { /* * On vmentry, vcpu->arch.exception.pending is only @@ -6624,13 +6622,20 @@ static void update_cr8_intercept(struct kvm_x86_ops->update_cr8_intercept(vcpu, tpr, max_irr); } +static void kvm_inject_exception(struct kvm_vcpu *vcpu) +{ + if (vcpu->arch.exception.error_code && !is_protmode(vcpu)) + vcpu->arch.exception.error_code = false; + kvm_x86_ops->queue_exception(vcpu); +} + static int inject_pending_event(struct kvm_vcpu *vcpu) { int r; /* try to reinject previous events if any */ if (vcpu->arch.exception.injected) { - kvm_x86_ops->queue_exception(vcpu); + kvm_inject_exception(vcpu); return 0; } @@ -6675,7 +6680,7 @@ static int inject_pending_event(struct k kvm_update_dr7(vcpu); } - kvm_x86_ops->queue_exception(vcpu); + kvm_inject_exception(vcpu); } else if (vcpu->arch.smi_pending && !is_smm(vcpu)) { vcpu->arch.smi_pending = false; enter_smm(vcpu);