Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1565136pxb; Thu, 4 Feb 2021 17:01:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJxj+2ap9n2BQEt+b6ZMsxNPPRNjgSRGqTl8CkoFDfDw9ZKCWQM12WN5li5NTaFCzVXhUfPW X-Received: by 2002:a17:906:388b:: with SMTP id q11mr1643423ejd.421.1612486909982; Thu, 04 Feb 2021 17:01:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612486909; cv=none; d=google.com; s=arc-20160816; b=UUCLZWVlbH0/syGQc9c+tJlimByY66Lx1R8nYGMdvrkcRaaeKl21bk9kGml6J00F1V 4tfWZkTMqcBUbzXd7a+r1n/PvLQ1uH1xNx8/Cyox7HdP0gqSLleenktFdkF3n7VmNQz4 pqsfLKNl0bH87BJJYhSvC6LJqmEvFG6Lhpnl4KrZiPi+gwctnBid1YBDpggzTYjn6ykY Pkp+M1XWVCtxjtpfCoG+Wvex2iGo5eZ+1Tj7JmBtB3nqSABd6Lm+MaLwihgAhOzItzpg 3K+t6GlcBwJPMPKCmc+XNKbG6RR0L9K/4XYW6qlbnbELTpeJJXWQLsvDI4ZtcrCsvV/E v4yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=EEzkB6KBykSa84B36mWQtsqm2CNIxmUYCcv/2V8Jq/g=; b=XDPdupr2B+LPyJ8V6usuOYWiVJAGRIFzNEtVUXdnZ4RSpQlH3JEly8wS2oV1yI7Rmd knqRBr40YU8868MnVALAD21lraYDQxtpgEyTIWQfgo6z/AmJqmODNJb0LIeC4ZclJ4UV oPmlKvdNdFd+pS+AdUwMjPHS+nGANA5xDoeSyKHrBG0gBCEMrPsbL2KR92FilU8bhYQc KiXMDdLmqS2eqUIUuMzUCHeZOsUbZFVRM90nF2v14MheBlNnU90CMlgmTdXhifF/XlT0 D3tk9c1CxwFJaVScSVdCWmViKQCr34x8rhBEngRINi7yC64EmYNnBtiqTkEn0YafCfu7 di+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SKF4eIuV; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si4024480ejx.656.2021.02.04.17.01.24; Thu, 04 Feb 2021 17:01:49 -0800 (PST) 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=@google.com header.s=20161025 header.b=SKF4eIuV; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238132AbhBDQoj (ORCPT + 99 others); Thu, 4 Feb 2021 11:44:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238025AbhBDQnL (ORCPT ); Thu, 4 Feb 2021 11:43:11 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6496EC06178A for ; Thu, 4 Feb 2021 08:42:31 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id e9so2127695pjj.0 for ; Thu, 04 Feb 2021 08:42:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=EEzkB6KBykSa84B36mWQtsqm2CNIxmUYCcv/2V8Jq/g=; b=SKF4eIuVg/lLzlwuixMf3U19cEbR9jy4AizAJnOQ5pIYJ6jmpBaBxa9QlsnHGf6Bgz qmGU1X98u0+ztfSTetCoYS72vf1RvBZWpiewzgf2K3IlnY+Wr3rQqEcZL+VuV+//4tZd yt4/4fKsA9TwIm4IKznxWjgZ5TlAIMWPfwUBC/tzb2DN+VCfketn4VHOpd3HwlhP0/kd nc8S2COcuhYY7v8vAi6mVfVW/4G/zQN8to3yVEhT0R8bZj+VvjCKSoBHXhvO10S2Zo0O II/pCsLZohgRnSRBiEPTg9h3krsg6mxl3q1Qh6qCb2I/x0W+pNwWtoB0szPDSZsZADRv Wg+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=EEzkB6KBykSa84B36mWQtsqm2CNIxmUYCcv/2V8Jq/g=; b=MjNn9XmGLW77KyLkfBVtT/ZpdIVmA0mMPwOvPDxG3PR6nF0BsdZuwCEMOyR63LiU3I h7/6OoBdhSKvUOumvou/cu4nb5BaUL45oSaDenzbk3n3F+PJvOv3uLIgobRnKR7v7Sy9 M+U1C3ZM9a9KPUY93tJFnc2xOzUoSTryJOnqzpnNI4+sIbViLShPxRAbujNs89Tdi3CX 6YjAO6h4L+eD1rZ64EYI+WmViItZf/1197z7MAX/LurBU8V5PQw3svEYPyOdQmupIIon UP0kDFzuncS9A/ld93DMwb/RiYDkYRn00H32jkFrOnhuEVX09qy6YNVizCjf0ALWFnfz ZZDg== X-Gm-Message-State: AOAM531A1TjxI0n1cupxoyJqBAVs2hdn2kon/WrLjXu7y3dtvSB9w630 rH1o0DNBXHYF52+mfcDPuC+4qg== X-Received: by 2002:a17:90b:ed0:: with SMTP id gz16mr341695pjb.7.1612456950755; Thu, 04 Feb 2021 08:42:30 -0800 (PST) Received: from google.com ([2620:15c:f:10:f16f:a28e:552e:abea]) by smtp.gmail.com with ESMTPSA id bo1sm4822871pjb.7.2021.02.04.08.42.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 08:42:29 -0800 (PST) Date: Thu, 4 Feb 2021 08:42:23 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Yang Weijiang , jmattson@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, yu.c.zhang@linux.intel.com Subject: Re: [PATCH v15 04/14] KVM: x86: Add #CP support in guest exception dispatch Message-ID: References: <20210203113421.5759-1-weijiang.yang@intel.com> <20210203113421.5759-5-weijiang.yang@intel.com> <5b822165-9eff-bfa9-000f-ae51add59320@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5b822165-9eff-bfa9-000f-ae51add59320@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 04, 2021, Paolo Bonzini wrote: > On 03/02/21 22:46, Sean Christopherson wrote: > > > > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > > index dbca1687ae8e..0b6dab6915a3 100644 > > --- a/arch/x86/kvm/vmx/nested.c > > +++ b/arch/x86/kvm/vmx/nested.c > > @@ -2811,7 +2811,7 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu, > > /* VM-entry interruption-info field: deliver error code */ > > should_have_error_code = > > intr_type == INTR_TYPE_HARD_EXCEPTION && prot_mode && > > - x86_exception_has_error_code(vector); > > + x86_exception_has_error_code(vcpu, vector); > > if (CC(has_error_code != should_have_error_code)) > > return -EINVAL; > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 28fea7ff7a86..0288d6a364bd 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -437,17 +437,20 @@ EXPORT_SYMBOL_GPL(kvm_spurious_fault); > > #define EXCPT_CONTRIBUTORY 1 > > #define EXCPT_PF 2 > > > > -static int exception_class(int vector) > > +static int exception_class(struct kvm_vcpu *vcpu, int vector) > > { > > switch (vector) { > > case PF_VECTOR: > > return EXCPT_PF; > > + case CP_VECTOR: > > + if (vcpu->arch.cr4_guest_rsvd_bits & X86_CR4_CET) > > + return EXCPT_BENIGN; > > + return EXCPT_CONTRIBUTORY; > > case DE_VECTOR: > > case TS_VECTOR: > > case NP_VECTOR: > > case SS_VECTOR: > > case GP_VECTOR: > > - case CP_VECTOR: This removal got lost when squasing. arch/x86/kvm/x86.c: In function ‘exception_class’: arch/x86/kvm/x86.c:455:2: error: duplicate case value 455 | case CP_VECTOR: | ^~~~ arch/x86/kvm/x86.c:446:2: note: previously used here 446 | case CP_VECTOR: | ^~~~ > > return EXCPT_CONTRIBUTORY; > > default: > > break; > > @@ -588,8 +591,8 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu, > > kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); > > return; > > } > > - class1 = exception_class(prev_nr); > > - class2 = exception_class(nr); > > + class1 = exception_class(vcpu, prev_nr); > > + class2 = exception_class(vcpu, nr); > > if ((class1 == EXCPT_CONTRIBUTORY && class2 == EXCPT_CONTRIBUTORY) > > || (class1 == EXCPT_PF && class2 != EXCPT_BENIGN)) { > > /* > > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > > index a14da36a30ed..dce756ffb577 100644 > > --- a/arch/x86/kvm/x86.h > > +++ b/arch/x86/kvm/x86.h > > @@ -120,12 +120,16 @@ static inline bool is_la57_mode(struct kvm_vcpu *vcpu) > > #endif > > } > > > > -static inline bool x86_exception_has_error_code(unsigned int vector) > > +static inline bool x86_exception_has_error_code(struct kvm_vcpu *vcpu, > > + unsigned int vector) > > { > > static u32 exception_has_error_code = BIT(DF_VECTOR) | BIT(TS_VECTOR) | > > BIT(NP_VECTOR) | BIT(SS_VECTOR) | BIT(GP_VECTOR) | > > BIT(PF_VECTOR) | BIT(AC_VECTOR) | BIT(CP_VECTOR); > > > > + if (vector == CP_VECTOR && (vcpu->arch.cr4_guest_rsvd_bits & X86_CR4_CET)) > > + return false; > > + > > return (1U << vector) & exception_has_error_code; > > } > > > > > > > > > > Squashed, thanks. I made a small change to the last hunk: > > if (!((1U << vector) & exception_has_error_code)) > return false; > > if (vector == CP_VECTOR) > return !(vcpu->arch.cr4_guest_rsvd_bits & X86_CR4_CET); > > return true; Ha, I guessed wrong, that was my first pass at it :-)