Received: by 10.223.176.46 with SMTP id f43csp1885362wra; Thu, 25 Jan 2018 01:27:06 -0800 (PST) X-Google-Smtp-Source: AH8x226NMprelNgDkv1sZ4mgV+np6ObHuUbcfp1bTuDpOS+BHf7T1MllnE5WuhtZ2+62rzt0tTXK X-Received: by 10.99.115.94 with SMTP id d30mr3642557pgn.172.1516872426732; Thu, 25 Jan 2018 01:27:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516872426; cv=none; d=google.com; s=arc-20160816; b=Hc6QGtY+zPpkvC2xQGbgHlgeYTzQvN3XvNISG1ugpI6G1d+U/4FVmmz9lXg8yE0KAR aLN712/euDuM/KW+KpI7p24bdHPJObjFOwVaK6CUYuj0V5nzKlhpUO9K9c0p1OGA97WQ eb/BqeIkMSAsmLIQBjIhqg2G20arI7GVGog7EyDAjA2jfQOKvWqMb1UntvCeMeel0L5g mb3+6bLv2ihws/bCFR69z/+Z0StShgbQv/cIjkBJjgeAMlbmb9u/vApVDHpgmJTa6Xkt wZp3lCtv8h26BPd+jA9km/VsqwQNebaUUNgJuf3u3vn0qLbR5Mff9VR0hT6vA94sHJDI FZUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:subject:cc:to:from:date:message-id :mime-version:dkim-signature:arc-authentication-results; bh=KfjfnuYCSkwzvp+YXX6ynVXW4f56oqk8QN0RxrAavgM=; b=vNfRMoF6rwGvwaqBCwXXk00W97jPQuo7nzZ8Svt2Rina5zYroiGfuWy8KDR1XaNtKM dd2ajR5Bs2hr2ggsfsTaes/kjuAJ2Z9KAu3lo02+4CJOyQ/FVO/xeKyHLKf6o9wvOJY0 E14AdQ5hMD1V54n2Ls++tZHKXtfhb+SnGbADRiXBC0boYZSOK2XEIbpKD46UUNIh89no NIlI5e4QfuhTkq4h2qTfVM10OcHF2iKwKGHpSB1q3YgrW0Aj9MlBKkEafKyUuqOclWwZ U+jWtljk5mfZ24nLE+sMM/bh5r8tFWWFi8tIXlL90xF05bwiMrjmz0WHLpsSbeJ6bl/T mOhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=Es53RDOK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16si4326677pfk.293.2018.01.25.01.26.52; Thu, 25 Jan 2018 01:27:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=Es53RDOK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751754AbeAYJZc (ORCPT + 99 others); Thu, 25 Jan 2018 04:25:32 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:42082 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751735AbeAYJZ0 (ORCPT ); Thu, 25 Jan 2018 04:25:26 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0P9PKOV011424; Thu, 25 Jan 2018 09:25:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : to : cc : subject : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=KfjfnuYCSkwzvp+YXX6ynVXW4f56oqk8QN0RxrAavgM=; b=Es53RDOKPwUn5xAumL05dlAinv4oJkEGiDYCyjdaz2R+PC88ayt5aomotFG8THyO305e mCihEAnziXANluyoEMYLHrZQIbTqKyvKN0PtJdBqJ/C7mcA/NFJjObUCZaDZMLQIDvHX 3AN4QoyLUw8GwVfc0fl/zSKONOO4Y4llIwTnGy/DDzxxaBqbIdiTt/e2DGK9fcAQKI7C wcUppy7LPAk56DYoLNtIi4nP62lHIvdCKOxcuvSdD5CUCcJlsWo7Ugo3dGjcWQSCbW11 bx3EZHKAxs0ngAMpHzYYTvti4sLcWXHpW9huLr0+O/UGHT4l+he8NiL+ERAZsMjnE+0D AA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2fqcjw0044-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Jan 2018 09:25:20 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0P9PJKg025968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 25 Jan 2018 09:25:19 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w0P9PIW4009983; Thu, 25 Jan 2018 09:25:18 GMT MIME-Version: 1.0 Message-ID: <4693d8ab-1c86-44b6-b24f-009ee8766c1e@default> Date: Thu, 25 Jan 2018 01:25:18 -0800 (PST) From: Liran Alon To: Cc: , , , , Subject: Re: [PATCH AUTOSEL for 4.14 006/100] KVM: nVMX/nSVM: Don't intercept #UD when running L2 X-Mailer: Zimbra on Oracle Beehive Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8784 signatures=668655 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801250130 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Alexander.Levin@microsoft.com wrote: > From: Liran Alon >=20 > [ Upstream commit ac9b305caa0df6f5b75d294e4b86c1027648991e ] >=20 > When running L2, #UD should be intercepted by L1 or just forwarded > directly to L2. It should not reach L0 x86 emulator. > Therefore, set intercept for #UD only based on L1 exception-bitmap. >=20 > Also add WARN_ON_ONCE() on L0 #UD intercept handlers to make sure > it is never reached while running L2. >=20 > This improves commit ae1f57670703 ("KVM: nVMX: Do not emulate #UD > while > in guest mode") by removing an unnecessary exit from L2 to L0 on #UD > when L1 doesn't intercept it. >=20 > In addition, SVM L0 #UD intercept handler doesn't handle correctly > the > case it is raised from L2. In this case, it should forward the #UD to > guest instead of x86 emulator. As done in VMX #UD intercept handler. > This commit fixes this issue as-well. >=20 > Signed-off-by: Liran Alon > Reviewed-by: Nikita Leshenko > Reviewed-by: Konrad Rzeszutek Wilk > Signed-off-by: Konrad Rzeszutek Wilk > Reviewed-by: Paolo Bonzini > Reviewed-by: Wanpeng Li > Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 > Signed-off-by: Sasha Levin > --- > arch/x86/kvm/svm.c | 9 ++++++++- > arch/x86/kvm/vmx.c | 9 ++++----- > 2 files changed, 12 insertions(+), 6 deletions(-) >=20 > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index 6a8284f72328..c8be4e6d365b 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -362,6 +362,7 @@ static void recalc_intercepts(struct vcpu_svm > *svm) > { > =09struct vmcb_control_area *c, *h; > =09struct nested_state *g; > +=09u32 h_intercept_exceptions; > =20 > =09mark_dirty(svm->vmcb, VMCB_INTERCEPTS); > =20 > @@ -372,9 +373,14 @@ static void recalc_intercepts(struct vcpu_svm > *svm) > =09h =3D &svm->nested.hsave->control; > =09g =3D &svm->nested; > =20 > +=09/* No need to intercept #UD if L1 doesn't intercept it */ > +=09h_intercept_exceptions =3D > +=09=09h->intercept_exceptions & ~(1U << UD_VECTOR); > + > =09c->intercept_cr =3D h->intercept_cr | g->intercept_cr; > =09c->intercept_dr =3D h->intercept_dr | g->intercept_dr; > -=09c->intercept_exceptions =3D h->intercept_exceptions | > g->intercept_exceptions; > +=09c->intercept_exceptions =3D > +=09=09h_intercept_exceptions | g->intercept_exceptions; > =09c->intercept =3D h->intercept | g->intercept; > } > =20 > @@ -2189,6 +2195,7 @@ static int ud_interception(struct vcpu_svm > *svm) > { > =09int er; > =20 > +=09WARN_ON_ONCE(is_guest_mode(&svm->vcpu)); > =09er =3D emulate_instruction(&svm->vcpu, EMULTYPE_TRAP_UD); > =09if (er =3D=3D EMULATE_USER_EXIT) > =09=09return 0; > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index ef16cf0f7cfd..36628ed362d8 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -1891,7 +1891,7 @@ static void update_exception_bitmap(struct > kvm_vcpu *vcpu) > { > =09u32 eb; > =20 > -=09eb =3D (1u << PF_VECTOR) | (1u << UD_VECTOR) | (1u << MC_VECTOR) | > +=09eb =3D (1u << PF_VECTOR) | (1u << MC_VECTOR) | > =09 (1u << DB_VECTOR) | (1u << AC_VECTOR); > =09if ((vcpu->guest_debug & > =09 (KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP)) =3D=3D > @@ -1909,6 +1909,8 @@ static void update_exception_bitmap(struct > kvm_vcpu *vcpu) > =09 */ > =09if (is_guest_mode(vcpu)) > =09=09eb |=3D get_vmcs12(vcpu)->exception_bitmap; > +=09else > +=09=09eb |=3D 1u << UD_VECTOR; > =20 > =09vmcs_write32(EXCEPTION_BITMAP, eb); > } > @@ -5919,10 +5921,7 @@ static int handle_exception(struct kvm_vcpu > *vcpu) > =09=09return 1; /* already handled by vmx_vcpu_run() */ > =20 > =09if (is_invalid_opcode(intr_info)) { > -=09=09if (is_guest_mode(vcpu)) { > -=09=09=09kvm_queue_exception(vcpu, UD_VECTOR); > -=09=09=09return 1; > -=09=09} > +=09=09WARN_ON_ONCE(is_guest_mode(vcpu)); > =09=09er =3D emulate_instruction(vcpu, EMULTYPE_TRAP_UD); > =09=09if (er =3D=3D EMULATE_USER_EXIT) > =09=09=09return 0; > --=20 > 2.11.0 Just wanted stable maintainers to note that Jim, Paolo & myself decided eve= ntually to revert this commit along with commit ae1f57670703 on upstream KV= M. However, it is true that this commit makes commit ae1f57670703 more comp= lete. Therefore we have 2 options here: 1) Apply this backport and sometime in the future also apply the reverts of= both these commits with Paolo's commit which reverts them. 2) Don't apply this backport but do revert commit ae1f57670703. -Liran