From patchwork Wed May 18 13:25:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Like Xu X-Patchwork-Id: 12853674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE982C43217 for ; Wed, 18 May 2022 13:26:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237870AbiERN0k (ORCPT ); Wed, 18 May 2022 09:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237800AbiERNZs (ORCPT ); Wed, 18 May 2022 09:25:48 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33B011AF; Wed, 18 May 2022 06:25:47 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 31so2122890pgp.8; Wed, 18 May 2022 06:25:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fWq2dft195z67E3HmJbQS7CQHaiqAGijLUxUajn85g8=; b=SAmoBGLWGdD9VZvDpKQEOA25kznLhwkX3Asno5SON222ZqJ9OTUZOmLCwDXVCbqJpm AIHkHTKIH78SItD9TV/qOxSkrghPH7RMSjApSt57Rbl8XW1wEH0SK/8+nfGrPVnoqqkX 17HnINiFrua8UMbdX0QUj0NCDbQgPvQ9qAjOsHBWPNaHXof7UMyTSaotuk6jsWxT95hm e/2L+og0C73hUEQuh82ExL6ud3w1m910srRYWkjLd6teA1OQ5zOAt9+yeEfFnhhKXjwK a4F1lXvsW6132LJrnhJ8U5nNSCkqKvcrWZQ+yLMSYZOrdoGJFi8BMriSKrqodjH3gvNW S6hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fWq2dft195z67E3HmJbQS7CQHaiqAGijLUxUajn85g8=; b=0b4MVa4q7NHGGEiBUScVbpn3hOpEJQQd+yw51Liej1TMYlJCAtXqNWMe5KOuswxr/8 D4sVKukh8YX51WgoPuNCpyqLk1dKoznmnvELjoJbBnTS6JuCf+78SixTRu4jCaKZ2EWY X4rQuKxud+NK+2ICXdLxeo3meCkxbb3Un9k4NnP4QEZ0ahrLgf7FK/DUvT/sHnS1pe8f oTkUGLqOxsVN+wbhI2k6psvcx+XG214WQC3YK1HxMT66j2u/1R68g+mzdWGbjyu+RNoh JgkZA6OeASSzEwidW6QorarCDmc9ViXTV1+dUpQGUxxyiVojxNEpJGhQiz3kr5TAvp/W 6XLg== X-Gm-Message-State: AOAM533ZcpaG1kOVCGrE6aBRLwCCDoZxGH070ho7tK4WuHxTUWG9sL3m QKLDJyaU+HxTbohZuV+xx28= X-Google-Smtp-Source: ABdhPJxCiW4vNidQr8d3khFMkKX2tm2oQM/WD8vaW3HKyU18UDKF1u8TMcdp4aq/dq6zQW78s0K6nQ== X-Received: by 2002:a62:c545:0:b0:50d:2d0f:2e8a with SMTP id j66-20020a62c545000000b0050d2d0f2e8amr28009615pfg.12.1652880346560; Wed, 18 May 2022 06:25:46 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.117]) by smtp.gmail.com with ESMTPSA id s13-20020a17090302cd00b0015e8d4eb244sm1625549plk.142.2022.05.18.06.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 06:25:46 -0700 (PDT) From: Like Xu X-Google-Original-From: Like Xu To: Paolo Bonzini Cc: Sean Christopherson , Jim Mattson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH RESEND v3 10/11] KVM: x86/pmu: Replace pmc_perf_hw_id() with perf_get_hw_event_config() Date: Wed, 18 May 2022 21:25:11 +0800 Message-Id: <20220518132512.37864-11-likexu@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518132512.37864-1-likexu@tencent.com> References: <20220518132512.37864-1-likexu@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Like Xu With the help of perf_get_hw_event_config(), KVM could query the correct EVENTSEL_{EVENT, UMASK} pair of a kernel-generic hw event directly from the different *_perfmon_event_map[] by the kernel's pre-defined perf_hw_id. Also extend the bit range of the comparison field to AMD64_RAW_EVENT_MASK_NB to prevent AMD from defining EventSelect[11:8] into perfmon_event_map[] one day. Signed-off-by: Like Xu --- arch/x86/kvm/pmu.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index 33bf08fc0282..7dc949f6a92c 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -517,13 +517,8 @@ static void kvm_pmu_incr_counter(struct kvm_pmc *pmc) static inline bool eventsel_match_perf_hw_id(struct kvm_pmc *pmc, unsigned int perf_hw_id) { - u64 old_eventsel = pmc->eventsel; - unsigned int config; - - pmc->eventsel &= (ARCH_PERFMON_EVENTSEL_EVENT | ARCH_PERFMON_EVENTSEL_UMASK); - config = static_call(kvm_x86_pmu_pmc_perf_hw_id)(pmc); - pmc->eventsel = old_eventsel; - return config == perf_hw_id; + return !((pmc->eventsel ^ perf_get_hw_event_config(perf_hw_id)) & + AMD64_RAW_EVENT_MASK_NB); } static inline bool cpl_is_matched(struct kvm_pmc *pmc)