Message ID | 20231104000239.367005-2-seanjc@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1379223vqu; Fri, 3 Nov 2023 17:02:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwe83XnASQzBdmg8WazXxdiYdAmp9bWp6Pp8EE8WD3yIveoq61N6Lw2bPpH0vgNgApD6kF X-Received: by 2002:a05:6e02:3387:b0:359:50c2:62b6 with SMTP id bn7-20020a056e02338700b0035950c262b6mr9272416ilb.12.1699056177645; Fri, 03 Nov 2023 17:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699056177; cv=none; d=google.com; s=arc-20160816; b=IEZ4ZkBvDLyyn41n5maAZuRe010Z5YB2bskMvzin071sgnBaogP849lPH4JCzRKzFT BYTj/b43Ny+3fGxTk5kADUkIPJWE9AiGjXMx+0mePNGO6BCz33dsg+EoZ3n5q3PZ4HrE aKtYqufv13ffRRealTRfCDQ5GfbhdD3gvYPCTtqE0ZTIyPPYb+zf96/fIGAZKHBHqDqY j0umFn19O/08oupxKOAXtgT3+j3zckY4SvkWkY46VLl8N8IPSmria8xfOkD9FCIJqmcJ +RfjYXs9OPEtt2H+UDBrQc8p/oIeIHk/bzFPtjfmHY9ueEPAHkF8Zr9ftp2gDNQYTmkr jv9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=nOzsUN1YNjo4mM3u1hilIKuxhzw1b/cPpyuR5vqvOEM=; fh=z/UQYx9FUD9Bz9JyYrmi2ijAScp29gktKr8lejSUuXU=; b=kXiq5vhWEa9FAS3LksXfAfHMX5JlSLevPde870iLNaKVgLZCkkmxP3PlDmf1GnUGWr JEG/+B9SFd+XuqVI4ioS81HMwvvDlul/V7nW7w5N8qsWgowvQEpvbv9uW5oMObM+dXHy zFGJnzUWd98LuExVtrSDtKK5SFPsmYFXL5QUt5thBVCHoUA3Q6TgTn5HYGc1hvLCwzlz rR+gJPfHmBXKHn4XNA6qTLdpZywa1qAhXahrY57ri7j/WbTH30sAXTMQpF932he3Eldl WCgwSSqp3HT+R3i+og5LkNe3Vcc62/dLmWLQr1dosVzPEvCoLIk229PG3CJJOcXsbgVV Ioog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="CFMT/kaO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id q24-20020a63cc58000000b00578b6e2f462si2378979pgi.351.2023.11.03.17.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 17:02:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="CFMT/kaO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A9B1E802C58D; Fri, 3 Nov 2023 17:02:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230512AbjKDACr (ORCPT <rfc822;heyuhang3455@gmail.com> + 35 others); Fri, 3 Nov 2023 20:02:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230453AbjKDACq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 3 Nov 2023 20:02:46 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3A1FD52 for <linux-kernel@vger.kernel.org>; Fri, 3 Nov 2023 17:02:43 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a839b31a0dso53877677b3.0 for <linux-kernel@vger.kernel.org>; Fri, 03 Nov 2023 17:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699056162; x=1699660962; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=nOzsUN1YNjo4mM3u1hilIKuxhzw1b/cPpyuR5vqvOEM=; b=CFMT/kaORlS2yU0gvAAAxQ1jOYqJYKqa+q1KZd9Zwuc+usFP6yHgxaoOBKETtlFsHv jHBAR8F7UnDz5/UBgKXgSZE84V7ckfz8L9jy+oCz+lPi+I36q8t/TEPLd4DfM78CMBED p8cd016sLD1tRfZhMOPhlHcPA3NAIY53MEk1kpzXdHjCkDHUdw/p6zociJAplcCG0JL6 5St3VZgwKFNnCnP9LEg523MvY0ckM1/Df3ELVoBjagBf33fjUSNOIyRfiNBMCHK/UlhA zqtzlxYHY6MY7US7zMVNGPip7G1VSzuMG90d9AqUq7d7kz1FF+fs1qTu9iFX6a3R49WZ ZmYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699056162; x=1699660962; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nOzsUN1YNjo4mM3u1hilIKuxhzw1b/cPpyuR5vqvOEM=; b=EWUM0NTOFz2hWFtr4XFuy1F0X7uR7tH1ubnWbHfW/J+Oz9M6NYly+WkPOSwARVJYIT YR+qhnPYLExOFXgIQhb9H5QH4TLut5izAFNdU0QXMgqvUO6Suk2aJ7P3T38D2ZGRU13t F5L8ub5hzExGo7phDt6/VRIonP/UzI7rP1LopGkKQcWzwQ7sITBTf9IqhlB4+gxMat5t ySr4+RybF88NsClZsNYnuah0hGXGvOon8m17ZQGtWP23yS8sf/SyIhubXMdEOzSDIb4a ni50M3fVrNTLiAuInu3tmD5DrFP8pV1wriZvllmsXbqpOJIbm8wtkXwyOmOx3U7viMOz bN/A== X-Gm-Message-State: AOJu0Yx3hlrl8wiWJmnRnTYTo9hFizAuC6sDVKpk3Ejxx52weQKf2Sm1 ZOY2cMW8xXTf4IfaMOnUGlZI5qTDPmg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:df52:0:b0:5a7:b9b0:d23f with SMTP id i79-20020a0ddf52000000b005a7b9b0d23fmr83931ywe.6.1699056162701; Fri, 03 Nov 2023 17:02:42 -0700 (PDT) Reply-To: Sean Christopherson <seanjc@google.com> Date: Fri, 3 Nov 2023 17:02:19 -0700 In-Reply-To: <20231104000239.367005-1-seanjc@google.com> Mime-Version: 1.0 References: <20231104000239.367005-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231104000239.367005-2-seanjc@google.com> Subject: [PATCH v6 01/20] KVM: x86/pmu: Don't allow exposing unsupported architectural events From: Sean Christopherson <seanjc@google.com> To: Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com> Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kan Liang <kan.liang@linux.intel.com>, Dapeng Mi <dapeng1.mi@linux.intel.com>, Jinrong Liang <cloudliang@tencent.com>, Like Xu <likexu@tencent.com>, Jim Mattson <jmattson@google.com>, Aaron Lewis <aaronlewis@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 03 Nov 2023 17:02:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781589530388904871 X-GMAIL-MSGID: 1781589530388904871 |
Series |
KVM: x86/pmu: selftests: Fixes and new tests
|
|
Commit Message
Sean Christopherson
Nov. 4, 2023, 12:02 a.m. UTC
Hide architectural events that unsupported according to guest CPUID *or*
hardware, i.e. don't let userspace advertise and potentially program
unsupported architectural events.
Note, KVM already limits the length of the reverse polarity field, only
the mask itself is missing.
Fixes: f5132b01386b ("KVM: Expose a version 2 architectural PMU to a guests")
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/vmx/pmu_intel.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Nov 3, 2023 at 5:02 PM Sean Christopherson <seanjc@google.com> wrote: > > Hide architectural events that unsupported according to guest CPUID *or* > hardware, i.e. don't let userspace advertise and potentially program > unsupported architectural events. The bitmask, pmu->available_event_types, is only used in intel_hw_event_available(). As discussed (https://lore.kernel.org/kvm/ZUU12-TUR_1cj47u@google.com/), intel_hw_event_available() should go away. > Note, KVM already limits the length of the reverse polarity field, only > the mask itself is missing. > > Fixes: f5132b01386b ("KVM: Expose a version 2 architectural PMU to a guests") > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson <seanjc@google.com> > --- > arch/x86/kvm/vmx/pmu_intel.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c > index 820d3e1f6b4f..1b13a472e3f2 100644 > --- a/arch/x86/kvm/vmx/pmu_intel.c > +++ b/arch/x86/kvm/vmx/pmu_intel.c > @@ -533,7 +533,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) > pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1; > eax.split.mask_length = min_t(int, eax.split.mask_length, > kvm_pmu_cap.events_mask_len); > - pmu->available_event_types = ~entry->ebx & > + pmu->available_event_types = ~(entry->ebx | kvm_pmu_cap.events_mask) & > ((1ull << eax.split.mask_length) - 1); > > if (pmu->version == 1) { > -- > 2.42.0.869.gea05f2083d-goog >
On Sat, Nov 04, 2023, Jim Mattson wrote: > On Fri, Nov 3, 2023 at 5:02 PM Sean Christopherson <seanjc@google.com> wrote: > > > > Hide architectural events that unsupported according to guest CPUID *or* > > hardware, i.e. don't let userspace advertise and potentially program > > unsupported architectural events. > > The bitmask, pmu->available_event_types, is only used in > intel_hw_event_available(). As discussed > (https://lore.kernel.org/kvm/ZUU12-TUR_1cj47u@google.com/), > intel_hw_event_available() should go away. Ah drat, I completely forgot about this patch when I added the patch to remove intel_hw_event_available().
diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 820d3e1f6b4f..1b13a472e3f2 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -533,7 +533,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1; eax.split.mask_length = min_t(int, eax.split.mask_length, kvm_pmu_cap.events_mask_len); - pmu->available_event_types = ~entry->ebx & + pmu->available_event_types = ~(entry->ebx | kvm_pmu_cap.events_mask) & ((1ull << eax.split.mask_length) - 1); if (pmu->version == 1) {