Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1566259rda; Mon, 23 Oct 2023 17:27:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4F/9Ocpe5HYAavy/90WBCowlLgnSqpziqyunQSxYJAs2YmKulkxLZGKSk3VvThatHk6M1 X-Received: by 2002:a17:902:da91:b0:1c6:de7:add9 with SMTP id j17-20020a170902da9100b001c60de7add9mr13875519plx.19.1698107236656; Mon, 23 Oct 2023 17:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698107236; cv=none; d=google.com; s=arc-20160816; b=NQJSjZf2VOJq7cNCfb9DtSrvTStvYDvAYnIh1dPul75xtqG4EJt9Djr24NApGOi5xs nURoOqrpqcs8EelEqgazq4V31yx2XjDCc9rb+9zUMQDkR++MsBz3SDMTrsvqTpzDToba QCQhzPuXj2UFORNaSDdU0a/pIfnZ84A03reFmo6Vi/Ng1se6I2z4zxuLH6sF+dp3rC+n O5T1bwsJ/rw6NGR/x4z0TOuD5tvnLG+aG1zpDF6M/qx0KrCYdbzOqb9FU++gv5QlTpGc ET906wsZjsRh6QV718mkldsuf+OHCH62D2Ng9mRPx012sKhOT2r+RcvDbqenWNXK87wL Uluw== 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=eiyrZUCrtXg6DUYczSD0Onn4lO3H8IBkZ8lYsggwbsM=; fh=D//PLXZS63mgWSQM2kcZZyW+2k64a7rh3i2k12EZPR4=; b=uX42WDDAWUpdJT0WSJiiWUunIpo/2EDDOTujfWESTVsNbe6BmLZ6TestZgwHFZ05Ew gWsUyVdWdiIqwwHpx7USVRxOWTa527s6elSjD7WpVBTGuQU2N/ZrenqG16lfBxEvmQTv pBQ2ow5kr+8C+Vy8QLHMzFoQuglLm6JC1gRsJvBFrpnefpyDJAxZnwIakYQ7JBPfJBcD 9DRcCz2nOY1g105sbi5a0TqPdkieUMxsknamL0LTQQMc3JXhC4y8ZjTtfU3SgeDbC9FM VY9PKcEy+l8Nvbf+qkrGAxhQkCcv/URbW5IZFgPSIUA17zwxKrSaYndbtXXt/effwtDi VnyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=prC4RNRG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id ij6-20020a170902ab4600b001c7245a1e73si7234224plb.32.2023.10.23.17.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 17:27:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=prC4RNRG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 387B4806823A; Mon, 23 Oct 2023 17:27:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231657AbjJXA0o (ORCPT + 99 others); Mon, 23 Oct 2023 20:26:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbjJXA0l (ORCPT ); Mon, 23 Oct 2023 20:26:41 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6887110E for ; Mon, 23 Oct 2023 17:26:39 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1c9d140fcddso28146765ad.1 for ; Mon, 23 Oct 2023 17:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698107199; x=1698711999; 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=eiyrZUCrtXg6DUYczSD0Onn4lO3H8IBkZ8lYsggwbsM=; b=prC4RNRG9KDEzUdaKcOxD4bCKkR79gHNgBrWobLc3nJT/IUYiPAZVeEC8/FT1WrAPP Ium5Uz5RtJLP39gGZRvTsEm6UxjqbhwYb2NDL8xv646BQ+UpqLRvhJaByh0/FTC/lEY2 WUv9YX29SF2x1Rpk3nyU08d2NLNkvgKlbCQdG8akyeD7bntsrKCCaU67vt6IAcaB+y8C Uks4skqGFCHek1Vgtx4KEBHG83kCe6llbz9PBN/27d//yC975/Uk7G9tNG9o+K4k/ZcE uenz3U2F4Y3Yo/sEXn3HQaaluWgRfjki0VBsrCYLVNe23mGjkHpU5xIpr53L8RuAfO2U zFHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698107199; x=1698711999; 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=eiyrZUCrtXg6DUYczSD0Onn4lO3H8IBkZ8lYsggwbsM=; b=VZ9aC9uOgRbFR8noQsiVCDP0C3vshIn7etd9ZbUoe0XI/5lvNGVr2UJHv+8RdWFyCl QnOEe2+0w4foy4MvlNh87dwpcM23MN83inSZXecNv6hhqvthOSkpy/W501fgeQ4QYVIi bDysjmmJeLmbB9yUneGE9cfCiajyTuRfDrHiLRNRXg2pdLJzAUYQ1Z+tNwxGlaVjLB7d tKGxGNa5n9SdyRnAPsN3gJK47afSMM5kyER3SqUGLtgleGK4f4XE7d67m7XqxU7qKnjq eR20oYKsw61XK/41fjdMqqKEWM5tJi7Wc471QD4Iz+gmxrN9Mk2GsLCFOcKNyg1F3MmD gnlQ== X-Gm-Message-State: AOJu0YxXA0iTteV3qmJCyuwoRXbe7tX59gABIGBDr380Fzb4MVaJ3t+k 7DDD9sigkvhQqOwmitmRB6INt2E4wqo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:4346:b0:1ca:85ab:1638 with SMTP id lo6-20020a170903434600b001ca85ab1638mr189311plb.12.1698107198877; Mon, 23 Oct 2023 17:26:38 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 23 Oct 2023 17:26:21 -0700 In-Reply-To: <20231024002633.2540714-1-seanjc@google.com> Mime-Version: 1.0 References: <20231024002633.2540714-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231024002633.2540714-2-seanjc@google.com> Subject: [PATCH v5 01/13] KVM: x86/pmu: Don't allow exposing unsupported architectural events From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jinrong Liang , Like Xu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 17:27:05 -0700 (PDT) Hide architectural events that are 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 --- 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.758.gaed0368e0e-goog