Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp49095rwp; Wed, 12 Jul 2023 09:30:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlFthorGmJ3V1ufWwgelqDyLQuGY2750rdcl5CUukf2OcShCHF6x6VrFuJEUJ+kgU5cXPnmp X-Received: by 2002:a17:90b:1c12:b0:263:a5b5:c538 with SMTP id oc18-20020a17090b1c1200b00263a5b5c538mr12244pjb.4.1689179400229; Wed, 12 Jul 2023 09:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689179400; cv=none; d=google.com; s=arc-20160816; b=KBtgNBlkjphK7nFTF/KXors/s0+ihzrjBM4rLixwH3LvYVFaHS0x5lgGI0yR84//ZW dHwbUDA133NVWlFg/E5NYW1z/C0svo6xn7KzehhxKqP9dy8xrmFqJ3RZzTXDA8zabb1e /U2QylejSt1/AZ027WCP4cQ6eq67AKvQ9kABGENelFzNMPCxPyvArsno9Zh6QCBRSOdz 5PTLqtFS2UJKp0BpeODlYY2669t9y9AU9izoZz8GjbLXvBMmxgSfFAxhoENyn7KVpXe6 UAhUax0A2tVHxAa/cce0LtksCV0Ug17hT6abxaT9IIo0Q6ZcrdWavyhV2a4LAdcBRG9/ BsWg== 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:dkim-signature; bh=jUTKveXRPyLPHLkVKvmFTziE4B+NDus/75xf0DkHGe0=; fh=Q/eBo5g2skav/AeKAZNI6YOBxbzVIhLZqKXXnF64B64=; b=j9M7eZU+AryCjKYfA5/+7P1ePVEQ0QiJHuxxjcGTGh38j7cWxMMk8n2v7hdtcyn4/V bK0DgyM8lqGBMD/70PsNJ+qGNPVZzapiahVJM6D0CCi5OA2i1HGUUBoeeCsmr+19RM/r aXyGNWheDDALvecG7gkHgp8eWb+yoTAdCZA70lxeK51D509yvz6NE0AEPuMPbYEln3ii U3sjDgZyMcDOM2Ednez+EecGDKQ59MXOYoBVIQWOKM7Tv6xFt6ktP/jigjKALzepYXo5 0L6PpdV/zZ9hGTArAdEYu3CRjLQZRgiBT/phScOIeG8+jiIdiQzSzXBj48Q+LB2dO5+1 tb9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=LXQXMaFM; 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 x8-20020a17090a164800b0024e47fae466si3656191pje.180.2023.07.12.09.29.48; Wed, 12 Jul 2023 09:30:00 -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=20221208 header.b=LXQXMaFM; 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 S232144AbjGLQM1 (ORCPT + 99 others); Wed, 12 Jul 2023 12:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231773AbjGLQM0 (ORCPT ); Wed, 12 Jul 2023 12:12:26 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F37881BF6 for ; Wed, 12 Jul 2023 09:11:55 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-c64521ac8d6so7069441276.1 for ; Wed, 12 Jul 2023 09:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689178302; x=1691770302; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jUTKveXRPyLPHLkVKvmFTziE4B+NDus/75xf0DkHGe0=; b=LXQXMaFMV7pPyOMePG4Vf89vY4jUnQXjuSq2D27W5tED/0cZpSK/S5xod8YmliJe8i 4YihG5B1pEKqxQeQfyWLBovG1Ov71fagz0sok8Ng+h7DXqVEexClbCd+HVrFHsiCwEyJ ApWw3btGejBn8ymD4TUY1sXer4CRs1jp936OfV82x/jXM9NexwTarEZ4TEJv7ngMbRyP i6rS3K2mVGrv0Ge6c+Z3UztxgJ+7t64OmQ+2aFsif76IO9T7MsCnQSQvqRZqzyo4ffbK 5F7NMTu22lQPV+eqB1O5IXO7XGGIhMFcXd9IPdfqiRxmNbdVG4KwrZcqQbicRlmU1RL+ InpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689178302; x=1691770302; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jUTKveXRPyLPHLkVKvmFTziE4B+NDus/75xf0DkHGe0=; b=JUMc6oc0xDzS9hRwU913ztcuRgLqvEm0G4ydPAjJ8LLwvq0eXpDRrx76kJ43ZXFu94 DLGEcOYW4KTrRVdF/dUSqbzAUbjHgCGgMv6j+U9OsgPtb7NFgsRk5ie3VK4E7gU/iwxB MGEB+Y3Fzd01XEBl//t465dKiFAoQtyEFNbPYLgnlIYpFN9bTGZj45aVf1kQrRtQ15pG jXP1xfj5atsxr97Cn5cB+J4GWQubhXKU7boyOBv9trSUoGUqCZUxCWT6tunjZs25JNAL mtG459zgHuOHjyrG7fhqH5I/5iWzwqfW0kmWcvtVDyyMd+KNVjy3OjJbRpBvunNodbaq oA+Q== X-Gm-Message-State: ABy/qLazj+x4/FMU4JxtxRONiS0nhIPxKVsL5FXP/mS6Sh7iLCe7ecDu fLIMur+N7usqr/Mhp5/sRuIn8kAoad4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:ccc2:0:b0:c41:4696:e879 with SMTP id l185-20020a25ccc2000000b00c414696e879mr165043ybf.7.1689178302438; Wed, 12 Jul 2023 09:11:42 -0700 (PDT) Date: Wed, 12 Jul 2023 09:11:40 -0700 In-Reply-To: <81c32ae2-ff21-131f-e498-f87b1e7fe3b5@gmail.com> Mime-Version: 1.0 References: <20230607010206.1425277-1-seanjc@google.com> <20230607010206.1425277-5-seanjc@google.com> <81c32ae2-ff21-131f-e498-f87b1e7fe3b5@gmail.com> Message-ID: Subject: Re: [PATCH 4/4] KVM: x86/pmu: Move .hw_event_available() check out of PMC filter helper From: Sean Christopherson To: Like Xu Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Aaron Lewis , Paolo Bonzini Content-Type: text/plain; charset="us-ascii" 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_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 12, 2023, Like Xu wrote: > On 2023/6/7 09:02, Sean Christopherson wrote: > > Move the call to kvm_x86_pmu.hw_event_available(), which has nothing to > > with the userspace PMU filter, out of check_pmu_event_filter() and into > > its sole caller pmc_event_is_allowed(). pmc_event_is_allowed() didn't > > exist when commit 7aadaa988c5e ("KVM: x86/pmu: Drop amd_event_mapping[] > > in the KVM context"), so presumably the motivation for invoking > > .hw_event_available() from check_pmu_event_filter() was to avoid having > > to add multiple call sites. > > The event unavailability check based on intel cpuid is, in my opinion, > part of our pmu_event_filter mechanism. Unavailable events can be > defined either by KVM userspace or by architectural cpuid (if any). > > The bigger issue here is what happens when the two rules conflict, and > the answer can be found more easily by putting the two parts in one > function (the architectural cpuid rule takes precedence). I want to clearly differentiate between what KVM allows and what userspace allows, and specifically I want to use "filter" only to describe userspace intervention as much as possible. Outside of kvm_get_filtered_xcr0(), which I would classify as userspace-defined behavior (albeit rather indirectly), and a few architecturally defined "filter" terms from Intel and AMD, we don't use "filter" in KVM to describe KVM behavior. IMO, there's a lot of value in being able to associate "filter" with userspace desires, e.g. just mentioning "filtering" immediately frames a conversation as dealing with userspace's wants, not internal KVM behavior.