Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4572286imw; Tue, 12 Jul 2022 10:12:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tBzGvOsBmg05M6lzpqe4McC8IRpsYOC/ocYZuIAmKqzMXpe6s2/26S/Qw1AJLhYB9qWAbe X-Received: by 2002:a17:906:7304:b0:6ff:a76:5b09 with SMTP id di4-20020a170906730400b006ff0a765b09mr24162489ejc.193.1657645964247; Tue, 12 Jul 2022 10:12:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657645964; cv=none; d=google.com; s=arc-20160816; b=PDt8gqbve//8yFa/p7tqMN6ACXDatP3pV1+i6M5LmQhDH/jizGTKOOdtLjaRXHbayV nc8qGoIgG1v8U37qkmeZmYKuk9UH5Wc8t9fIRpym8CTXuPMyFBXJC1hKsjRPUD7YqOyF bORyx/7Vd9F+1NUY1WWtGuxFWaIVW1ov9eRxoIoJU+Gwru8VfilGUmF13Jwi4xS1XuCA RTu4wtL8NPR/H69S5NQV/K2qD9EQULy25c2Nv0B516Gbal0I571siCvS7sJli80aVEBh De7elEWXSxVWw+WgPz/TGvTk3trLqTtjFLbXRjVm6E/LGLRaTGg5nIS2FBm3uoo9MhgO jzrA== 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=2A19SFZc712Zr90/HxHXBLZXts62Gst8gLFaGLjAnSo=; b=BIHU01P+XrSQT4huA1Amkhv/cW0SHpqgh9jF1Ym91hYRLyzgOo4R2n02Y4fyYpKje7 uqaBho/NadxFkOY1Dk4UobjG2DxMHWiUvQkTqR2XtYUN+rwCrKRSvqWSCr4rcjkNzzGl WCvoGqr/Tfk8nC2bXNYRKt37MXMxh5W+iqzNDFlQotVGyoF/pF6seL2YjNG7nD7+CKqC 2XmZFVTToOgDOwusKFC/STPuJPXke8vQupdbz0u2lViP6g/WovAAc4XMcdSqzmu1m0up GAXpRKBS/bRB9VyYbyI3Puzdx5k0EfQzcM6FK2hv2dsjRd7TmXlN0NlUuybeqmHauTXG MC7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VYS1kepN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020a170906490d00b0072a9a683407si13151855ejq.118.2022.07.12.10.12.18; Tue, 12 Jul 2022 10:12:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VYS1kepN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233044AbiGLRJ2 (ORCPT + 99 others); Tue, 12 Jul 2022 13:09:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232488AbiGLRJ0 (ORCPT ); Tue, 12 Jul 2022 13:09:26 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C03622525 for ; Tue, 12 Jul 2022 10:09:26 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id 72so8198813pge.0 for ; Tue, 12 Jul 2022 10:09:26 -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:content-transfer-encoding:in-reply-to; bh=2A19SFZc712Zr90/HxHXBLZXts62Gst8gLFaGLjAnSo=; b=VYS1kepNgU6dnPULTf1c3ax9LyR/C7eQbkjFEvadxbv9o9m6kfbFvC1BoeZS1b0LAV mbcpKkIgA2JX4BuPkUV/0ROYsqBHa8doX4iC3k2YuHrsA+o/DrJSDdlwBAYhQ8CYbLvf LftumPHX/MpRJsVLKHdPZhJchYT4iAmy3tC6e8vwK1eHycnlA01r2IloCJdoZSz3+taY Ek6jSpMuENPgYFC8OJpUsFH5a2HDPxxtP7qTXIVQEocYAbEPyVEP+TNsiP+lyBUdwWmk U44ZhQCRlc1LP8T6ZY6zPmIfp3BxaGEU6S449HEib+qJwAP57Cq9gtS4GcyWZlQLdjT+ ZcCQ== 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:content-transfer-encoding :in-reply-to; bh=2A19SFZc712Zr90/HxHXBLZXts62Gst8gLFaGLjAnSo=; b=r+7c+u0stOirwZFAJBKV7tav6PL5qGSBLPHYDd7tCWhG+r4lRrLIBPjxr3B5wKTUQt /jmRVIATrG8PUbS90Xj4T5Ws98vQlDES9RPEVobNv8P99TIcX9cx9Reci/7fFz01o7fl bun3zWU3nFVMJH/SV6bei03egHdHCr9o3g3aswDB2Ly9SG0fIkYs1gaxx26Rm52C1lB9 qJhb/60ogH9zTrki3D9b0TC4nFnrP1r+srcVvKeIObOOMSd028+3DbtsmwyiFrddryLu Y5Vc6agoWfi0FQbplLNlSXXbtDm+oKhVTGs0bMVImnI/Ib8XiC5IRrLIwYIxfh4nDdJ8 dcxQ== X-Gm-Message-State: AJIora+n2OGUU+7z7AD8SgceeHLk6/9eHMoCwnpt5vwEZPRs2ff3nn+N 5qVvN6ygsMJB113UkYPgNqcsHg== X-Received: by 2002:a05:6a00:f85:b0:52a:c718:ff9 with SMTP id ct5-20020a056a000f8500b0052ac7180ff9mr14298591pfb.85.1657645765469; Tue, 12 Jul 2022 10:09:25 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id b13-20020a170903228d00b0016c35b21901sm6745429plh.195.2022.07.12.10.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 10:09:24 -0700 (PDT) Date: Tue, 12 Jul 2022 17:09:21 +0000 From: Sean Christopherson To: Maxim Levitsky Cc: Paolo Bonzini , Vitaly Kuznetsov , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] KVM: x86: Add dedicated helper to get CPUID entry with significant index Message-ID: References: <20220712000645.1144186-1-seanjc@google.com> <8a1ff7338f1252d75ff96c3518f16742919f92d7.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 12, 2022, Sean Christopherson wrote: > On Tue, Jul 12, 2022, Maxim Levitsky wrote: > > On Tue, 2022-07-12 at 00:06 +0000, Sean Christopherson wrote: > > > +???????????????/* > > > +??????????????? * Function matches and index is significant; not specifying an > > > +??????????????? * exact index in this case is a KVM bug. > > > +??????????????? */ > > Nitpick: Why KVM bug? Bad userspace can also provide a index-significant entry for cpuid > > leaf for which index is not significant in the x86 spec. > > Ugh, you're right. > > > We could arrange a table of all known leaves and for each leaf if it has an index > > in the x86 spec, and warn/reject the userspace CPUID info if it doesn't match. > > We have such a table, cpuid_function_is_indexed(). The alternative would be to > do: > > WARN_ON_ONCE(index == KVM_CPUID_INDEX_NOT_SIGNIFICANT && > cpuid_function_is_indexed(function)); > > The problem with rejecting userspace CPUID on mismatch is that it could break > userspace :-/ Of course, this entire patch would also break userspace to some > extent, e.g. if userspace is relying on an exact match on index==0. The only > difference being the guest lookups with an exact index would still work. > > I think the restriction we could put in place would be that userspace can make > a leaf more relaxed, e.g. to play nice if userspace forgets to set the SIGNFICANT > flag, but rejects attempts to make guest CPUID more restrictive, i.e. disallow > setting the SIGNFICANT flag on leafs that KVM doesn't enumerate as significant. > > > > +???????????????WARN_ON_ONCE(index == KVM_CPUID_INDEX_NOT_SIGNIFICANT); Actually, better idea. Let userspace do whatever, and have direct KVM lookups for functions that architecturally don't have a significant index use the first entry even if userspace set the SIGNIFICANT flag. That will mostly maintain backwards compatibility, the only thing that would break is if userspace set the SIGNIFICANT flag _and_ provided a non-zero index _and_ relied on KVM to not match the entry. We could still enforce matching in the future, but it wouldn't be a prerequisite for this cleanup. /* * Similarly, use the first matching entry if KVM is doing a * lookup (as opposed to emulating CPUID) for a function that's * architecturally defined as not having a significant index. */ if (index == KVM_CPUID_INDEX_NOT_SIGNIFICANT) { /* * Direct lookups from KVM should not diverge from what * KVM defines internally (the architectural behavior). */ WARN_ON_ONCE(cpuid_function_is_indexed(function)); return e; }