Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4786867pxb; Thu, 14 Oct 2021 11:56:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzh+wwJXVOUwPazQyDxr65vFPvYjSjCfX2hrwXw4PbeCT8F0XOeJJPLlinDCO9lRseMh1CN X-Received: by 2002:a62:2f07:0:b0:44c:e43e:be75 with SMTP id v7-20020a622f07000000b0044ce43ebe75mr6988411pfv.0.1634237816409; Thu, 14 Oct 2021 11:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634237816; cv=none; d=google.com; s=arc-20160816; b=z5ebdiglnIV/0Y0sPLKLTfPqgEKgz+Eyu84jdvCV0VR47VYzddiP+WP4MGV/gfwaUj g63ill3SNYKBOZ2n/RpdbcfS8EDiravcQs+qDj6nll6VC0tENhgd45WwawbxZRwPcCrE IG0H1qL3adYSTy6Y1HyclS6AEVWZVplwne64o+A+yEifjYkIUoPoFu9su6aCWFlqEsgf 83c9rHoWdtP333JyGfZk6l0Z7VF3ZNplpsQu+aFfRlxd3+JEypJh6+76EIoMJKhpZtPR syY5fDY+S5KkSPbSvJ9Xd16ge6v3h7JvCtwU/8uql60Wnzngcyy4X7z75i6V2xB/e26+ AcnA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DxjJWbKincMlvSXC/FY3Ala2ok6WlFlcTqLiBRO6M/w=; b=1BDIU1k9he+FKfhuE36uSb9gb92TdMaWou9IuTvyTPAlfUUmy+L25SWZ9BTbhfFioy 36OwyOOmXVTNWc8L6Ga5QTJLIyeOQ8S63IszisPdue379DRDAi8XQ/a897Tu/YMa4j2P xOOyeczzQZJvPWfE9wBdi7wFwz8bUYy8LO5RzJtW41s4Y+sRv7ncVuDjH4NAngeU4Aq0 BvkAqTtcJGrpaJoZnVCK8SCMCz7YapGC06PVD6HhePuVfwc1lCMQyx/GVtKFGRpqAkFc ASQIgwKpRtiTm2KMslhgZX3Wy4lt/nR9Q7hYHjF54k0ucG0vLEzreVt9ijfLvJa/p8JG VEnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TmOfNDnp; 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 g1si4790918pjl.47.2021.10.14.11.56.43; Thu, 14 Oct 2021 11:56:56 -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=@google.com header.s=20210112 header.b=TmOfNDnp; 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 S232721AbhJNQ4m (ORCPT + 99 others); Thu, 14 Oct 2021 12:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232641AbhJNQ4k (ORCPT ); Thu, 14 Oct 2021 12:56:40 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C340C061753 for ; Thu, 14 Oct 2021 09:54:35 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id x130so5977856pfd.6 for ; Thu, 14 Oct 2021 09:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DxjJWbKincMlvSXC/FY3Ala2ok6WlFlcTqLiBRO6M/w=; b=TmOfNDnpZ594weM/2UNFzn+MY2mLVQtNlWPXx1nvRjNLRuk3e4qJSZ+hf870+QB2jR agy34dupqT+XlQu0aOc5FFWJkU7NrAo35nTYXfcP1hVKEEJPOCK6m9qlcrztza4Rdx9V gTLuI0kzy0ZIf+ljd82tD/Qq0iMg4ZFRRqQzVCdh5zG/QjM/PkK/tP64E2fGXdFNVRk+ QPtSuqkBVFKKaUwSqa9cVDsu6SzCzg7Rg6SaCHVzSB+CPCVTtpPilbwGB4rBpGwdc3Ib qKHpgWBPd6ro+VOtbcgwcyhyeTWuKZV0bpMxJ0Q/ixHV2LGaM2/3erKqDn/DF70aoeoB EWmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DxjJWbKincMlvSXC/FY3Ala2ok6WlFlcTqLiBRO6M/w=; b=f2q1gIm/Q+qQHtHRgjJNwrwv9gw6fyrrR3YvjLh6Riu92Htnxd4ttwmsl7wauS/6+l TERPY2C9K/ULrxmx8xvmF28OeQmSyIOyUGjmLTGMfHeTRlgVSS5s1VsOYgLRBxB4VIgu zEph8FR+eDq/2m5zMr0/Glo15wiJU7P7lZi2UQLvhqd3qSRsJlp6o1Mi3ptCxoG42oma +O2KvypgrUzaoHuCOh0iz2ZHo/pURwLW1S+3JjdAt0HnEUW0XULwEQUImkgLdKORRVRu dMEvq45qN2c1s8rfsgFtPRQFQIFaC5S+MycOR3t4iZG12qVVMPD2rfNygK52sL2gdQsA 2bkg== X-Gm-Message-State: AOAM532N1iUFwYZTS6gTp9XjX6C48zdqLb9SXA6PraWrAhLUDLAtan3G UlFP2M6+Sbyjt1aGvnX7OYV2fA== X-Received: by 2002:a63:d205:: with SMTP id a5mr5010873pgg.30.1634230474404; Thu, 14 Oct 2021 09:54:34 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id m186sm3131409pfb.165.2021.10.14.09.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 09:54:33 -0700 (PDT) Date: Thu, 14 Oct 2021 16:54:30 +0000 From: Sean Christopherson To: Jim Mattson Cc: Vipin Sharma , pbonzini@redhat.com, dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: VMX: Add a wrapper for reading INVPCID/INVEPT/INVVPID type Message-ID: References: <20211011194615.2955791-1-vipinsh@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 11, 2021, Jim Mattson wrote: > On Mon, Oct 11, 2021 at 1:23 PM Sean Christopherson wrote: > > > > On Mon, Oct 11, 2021, Vipin Sharma wrote: > > > - if (type > 3) { > > > + if (type > INVPCID_TYPE_MAX) { > > > > Hrm, I don't love this because it's not auto-updating in the unlikely chance that > > a new type is added. I definitely don't like open coding '3' either. What about > > going with a verbose option of > > > > if (type != INVPCID_TYPE_INDIV_ADDR && > > type != INVPCID_TYPE_SINGLE_CTXT && > > type != INVPCID_TYPE_ALL_INCL_GLOBAL && > > type != INVPCID_TYPE_ALL_NON_GLOBAL) { > > kvm_inject_gp(vcpu, 0); > > return 1; > > } > > Better, perhaps, to introduce a new function, valid_invpcid_type(), > and squirrel away the ugliness there? Oh, yeah, definitely. I missed that SVM's invpcid_interception() has the same open-coded check. Alternatively, could we handle the invalid type in the main switch statement? I don't see anything in the SDM or APM that architecturally _requires_ the type be checked before reading the INVPCID descriptor. Hardware may operate that way, but that's uArch specific behavior unless there's explicit documentation. diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 89077160d463..c8aade2e2a20 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3119,11 +3119,6 @@ static int invpcid_interception(struct kvm_vcpu *vcpu) type = svm->vmcb->control.exit_info_2; gva = svm->vmcb->control.exit_info_1; - if (type > 3) { - kvm_inject_gp(vcpu, 0); - return 1; - } - return kvm_handle_invpcid(vcpu, type, gva); } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 1c8b2b6e7ed9..ad2e794d4cb2 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5504,11 +5504,6 @@ static int handle_invpcid(struct kvm_vcpu *vcpu) vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); - if (type > 3) { - kvm_inject_gp(vcpu, 0); - return 1; - } - /* According to the Intel instruction reference, the memory operand * is read even if it isn't needed (e.g., for type==all) */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d9273f536f9d..a3657db6daf9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12382,7 +12382,8 @@ int kvm_handle_invpcid(struct kvm_vcpu *vcpu, unsigned long type, gva_t gva) return kvm_skip_emulated_instruction(vcpu); default: - BUG(); /* We have already checked above that type <= 3 */ + kvm_inject_gp(vcpu, 0); + return 1; } } EXPORT_SYMBOL_GPL(kvm_handle_invpcid);