Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4533429pxb; Tue, 2 Nov 2021 11:15:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj7+v4H/VDDbwAKgLFltQxHuvcGX58qJVfcmvKLsAT1bRQNBh6VHbkwEkaGPXWqFhT9Kip X-Received: by 2002:a6b:f706:: with SMTP id k6mr6008092iog.155.1635876940878; Tue, 02 Nov 2021 11:15:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635876940; cv=none; d=google.com; s=arc-20160816; b=Fi9G8P3umPZ4bJ6u2TEEgFgb8KKJ4gE5EzUDQjLGAPU5Bw+BQRlcrk6BYg++Cb0mOv hlgtPWRqlCNy3ZPl3u30Il1sI85AYN9GSifCkmOiI+7vqrrcBd8sYEUgHCHVgHB7I96n nDwRXMZL87sk8hIZVqMNl/RAXrGvCmRq05570GOE9iVvKSGiMa3GALAyAfr9nM+M+wz3 ChySlBGEUbti7CCA30u5XY+cjGG6coTMqvFwdxIzsC2fz5CrgiIwpQ3Vxo93ykxePGo0 6bm2GNEq6Sv2kVoUs/UXhZ8kKUZgq1O4vh6aZ1NLVcodoxpl91lkrOdJxFkVjULW4Lc0 OTvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3aAa2g6F5cEPDJn1H2dtRZP1YIEtghO4gfoLlk3Pcbw=; b=OgPNHoIr8o9j9WSVeSjkmxFFiCq8xkTY3x9BwvHw0qa2rnpf9pTqOtfUtS6TIZCq6G VFQugFeTXp6VSTbLBUuhKcFY11hbbjzsEwIounUnafXyvnB2DdGXGlXCg8kJsRiszN9D nBZDuJSxJNCXfHWWH5AN6nQI4OomvkI6+5gsY+yFdNwcYNdYHMYRLi+qrI6Zf4RRiqoO TLnCpGWOd1zGLHH5umyiA9gCbIfmqwFMg8ISO2LZ6TNB+9TSU421m8SBmLrdQ0BHj3Ii 3LdpPWsNirGdbhZ8ug07rMdrXe6mdqh0+fvhxxPZB1FUxH7ji4HFwhYWLZFcXU6McADQ tjnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GfYlX9OX; 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 h16si27073499jav.87.2021.11.02.11.15.26; Tue, 02 Nov 2021 11:15:40 -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=GfYlX9OX; 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 S234834AbhKBSQI (ORCPT + 99 others); Tue, 2 Nov 2021 14:16:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbhKBSQI (ORCPT ); Tue, 2 Nov 2021 14:16:08 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA750C061714 for ; Tue, 2 Nov 2021 11:13:32 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id o18so245827lfu.13 for ; Tue, 02 Nov 2021 11:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3aAa2g6F5cEPDJn1H2dtRZP1YIEtghO4gfoLlk3Pcbw=; b=GfYlX9OX1sXNX3bqVCRC2BllZhiCQ8NlGee8f88VSWYP2ig7CAf2Utra5o2oD74c2m +LjbuarZU+QVe8722G9iG/Teg9V+KcqsX7jhPWSWsrMbt/+96RWuBKMlxbX1mZC6qwJL 8y5WE3+1DVmd5KG7eWHV5sNzPGKyrj+Xzf3WdLkvC/FYsEJtUniSvAYJm7MX6ewTxgOy FDC2VdZZVY1yQ2bbhwySRoE9HsQ2vLGfsXW80jdTrOFsJ6EKRLaPDzinyL9R8o9A2CJL nUvoPS7fgisBAp0eYwymB/TozwaXgxlAMK4KJ6zTIv36tvXmIoyBh1R/s72FpjxvNflN aa4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3aAa2g6F5cEPDJn1H2dtRZP1YIEtghO4gfoLlk3Pcbw=; b=cBQoaotdMNW4Js9pHMGDJxLKOoINV1rv/sRr0chqoioJpqXCIKn6ukHPZ2MzgOag0F VxBIU5CMqHLhB1w1WUHoxJX4oiFQB6l3PvYkqtXeqqSj35fd6zLh/wnQPvuMAa1IPksS RWZ14oIlopLv8lvfJWbz7Sc5q0sAa9OJ/pOvtuzMkOBrX0Uc3iW38Yjhq7OvSrUxI+jO Ztar50Y/1RqD8Pi/wNmeuWGJy87k4f6eu78mMv3hy5ITEblUOzFUTF0poa6VE9MOs0/B ZulnOcRxnfp/I4S+454IcmncSa+8T0RXeonB9t46m3/cb+Fe66Lxww35fVYxWwgFyHxg cpMQ== X-Gm-Message-State: AOAM531UuB5/tp/TIctKAhjatDr/mQ05YpLrLVLbxyseYC7NsorzIvjE v7Dzl5mMd78i/kYMtvQ4cmEIXhyIunc31QsZmOm3GA== X-Received: by 2002:a05:6512:3c9e:: with SMTP id h30mr5245802lfv.93.1635876810700; Tue, 02 Nov 2021 11:13:30 -0700 (PDT) MIME-Version: 1.0 References: <20211011194615.2955791-1-vipinsh@google.com> In-Reply-To: From: Vipin Sharma Date: Tue, 2 Nov 2021 11:12:53 -0700 Message-ID: Subject: Re: [PATCH] KVM: VMX: Add a wrapper for reading INVPCID/INVEPT/INVVPID type To: Jim Mattson , Sean Christopherson Cc: pbonzini@redhat.com, dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sorry for the late reply. On Thu, Oct 14, 2021 at 10:05 AM Jim Mattson wrote: > > On Thu, Oct 14, 2021 at 9:54 AM Sean Christopherson wrote: > > > > 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? > > I might not have understood your auto-updating concern correctly, can I change these macros to an enum like: enum INVPCID_TYPE { INVPCID_TYPE_INDIV_ADDR, INVPCID_TYPE_SINGLE_CTXT, INVPCID_TYPE_ALL_INCL_GLOBAL, INVPCID_TYPE_ALL_NON_GLOBAL, INVPCID_TYPE_MAX, }; My check in the condition will be then "if (type >= INVPCID_TYPE_MAX) {}" This way if there is a new type added, max will be auto updated. Will this answers your concern? > > 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. > > Right. INVVPID and INVEPT are explicitly documented to check the type > first, but INVPCID is not. It seems to me that I can move type > 3 check to kvm_handle_invpcid() switch statement. I can replace BUG() in that switch statement with kvm_inject_gp for the default case, I won't even need INVPCID_TYPE_MAX in this case. If you are fine with this approach then I will send out a patch where invalid type is handled in kvm_handle_invpcid() switch statement. Thanks Vipin