From nobody Fri Dec 19 20:42:16 2025 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 288F8C433F5 for ; Thu, 6 Oct 2022 00:52:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbiJFAwr (ORCPT ); Wed, 5 Oct 2022 20:52:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbiJFAwB (ORCPT ); Wed, 5 Oct 2022 20:52:01 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2A03422C8 for ; Wed, 5 Oct 2022 17:51:47 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id my9-20020a17090b4c8900b002027721b2b0so1855990pjb.6 for ; Wed, 05 Oct 2022 17:51:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; 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=4+CWUStYTQoTh0BU8RtshI04zg9Zxynj28PspoRPHoc=; b=rOtPmzwq4YRmk3PIS3+JztMvwdz7Z1mI20nu2l4Ha69F1mkOv+MBWjoZetB8JMjsu4 N/RDXxVQJPvLuvI46EXDdA3azXP/Pb8ixNP49936Y4Q5Svauz9vq2TukSzldjjRAGlyQ nBUYWm3dObDKO6FSekxcnDdQ7w5uSUhxPla1CxFtZlqIqPVpOeD+MciqQkkIFtMmuxnX MgHimDfUbK9Zt5F9Qd1PKcTEHWApumNoHC5NgmDB1RBGYjXEcIBc9IDBsPom4aBVwX4i Bg2L6Zz9zweQtyQUywTeJom7Y9y5DM2++kVw7qpoI8kwukNsKhCsjYjbcRedR+Li7E4E av4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=4+CWUStYTQoTh0BU8RtshI04zg9Zxynj28PspoRPHoc=; b=Ow8VbzjhRu0gaoIHzNK1t046AAXRNOJ9W0g6ugJcPrz3I/kIsSACPxdnRMvTfbEx98 NRkOvQWAEEjf8QOtB7Fj9+ttHFQXtszMWRozTEMdTV8kXrbzhJYEJmSU5vBsv4UshlXX HTFzOML1XMXO9BE36aP5dGpZuqzljiv9H0W4+JcbobqzpoeRC4cGcjbUcsQivFPVQ3F9 lfxhvvXxP6saKex3ICZGzumUP6cJvZRSgZliWp7lUj3GKf/y7n2YYtJD14vppftSIbya AaC96CxRrjxktKVph268hs6n1A70qaj8RBg+j6AYzFs3Uue5eI+21GCpXzBnu68NMbCt /nbA== X-Gm-Message-State: ACrzQf0509e3GiiHi+wg+cJ+1Bnpx+JWJc0kNlnIC/fD8EG6JqPNroiR AqJzoKC+B8FMmM4I1qKkRMZ16dmVXv8= X-Google-Smtp-Source: AMsMyM6Zc7TATcUVy3byTQCMQVUVqVcMugAkoChUZ7xp+S/H/0fCKciymhrfxnjKqjdOYFpK2DUChO1+oIs= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:41c6:b0:178:348e:f760 with SMTP id u6-20020a17090341c600b00178348ef760mr1932110ple.123.1665017506765; Wed, 05 Oct 2022 17:51:46 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 6 Oct 2022 00:51:24 +0000 In-Reply-To: <20221006005125.680782-1-seanjc@google.com> Mime-Version: 1.0 References: <20221006005125.680782-1-seanjc@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221006005125.680782-12-seanjc@google.com> Subject: [PATCH 11/12] KVM: selftests: Add and use KVM helpers for x86 Family and Model From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add KVM variants of the x86 Family and Model helpers, and use them in the PMU event filter test. Open code the retrieval of KVM's supported CPUID entry 0x1.0 in anticipation of dropping kvm_get_supported_cpuid_entry(). No functional change intended. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 19 +++++++++++++-- .../kvm/x86_64/pmu_event_filter_test.c | 23 +++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index a1dafd4e8f43..021c5f375158 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -748,10 +748,27 @@ static inline void vcpu_xcrs_set(struct kvm_vcpu *vcp= u, struct kvm_xcrs *xcrs) vcpu_ioctl(vcpu, KVM_SET_XCRS, xcrs); } =20 +const struct kvm_cpuid_entry2 *get_cpuid_entry(const struct kvm_cpuid2 *cp= uid, + uint32_t function, uint32_t index); const struct kvm_cpuid2 *kvm_get_supported_cpuid(void); const struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void); const struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vcpu *vcpu= ); =20 +static inline uint32_t kvm_cpu_fms(void) +{ + return get_cpuid_entry(kvm_get_supported_cpuid(), 0x1, 0)->eax; +} + +static inline uint32_t kvm_cpu_family(void) +{ + return x86_family(kvm_cpu_fms()); +} + +static inline uint32_t kvm_cpu_model(void) +{ + return x86_model(kvm_cpu_fms()); +} + bool kvm_cpuid_has(const struct kvm_cpuid2 *cpuid, struct kvm_x86_cpu_feature feature); =20 @@ -819,8 +836,6 @@ static inline struct kvm_cpuid2 *allocate_kvm_cpuid2(in= t nr_entries) return cpuid; } =20 -const struct kvm_cpuid_entry2 *get_cpuid_entry(const struct kvm_cpuid2 *cp= uid, - uint32_t function, uint32_t index); void vcpu_init_cpuid(struct kvm_vcpu *vcpu, const struct kvm_cpuid2 *cpuid= ); void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu); =20 diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/t= ools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c index 5cc88ac31c45..540b122ea588 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c @@ -369,20 +369,19 @@ static bool use_intel_pmu(void) kvm_pmu_has(X86_PMU_FEATURE_BRANCH_INSNS_RETIRED); } =20 -static bool is_zen1(uint32_t eax) +static bool is_zen1(uint32_t family, uint32_t model) { - return x86_family(eax) =3D=3D 0x17 && x86_model(eax) <=3D 0x0f; + return family =3D=3D 0x17 && model <=3D 0x0f; } =20 -static bool is_zen2(uint32_t eax) +static bool is_zen2(uint32_t family, uint32_t model) { - return x86_family(eax) =3D=3D 0x17 && - x86_model(eax) >=3D 0x30 && x86_model(eax) <=3D 0x3f; + return family =3D=3D 0x17 && model >=3D 0x30 && model <=3D 0x3f; } =20 -static bool is_zen3(uint32_t eax) +static bool is_zen3(uint32_t family, uint32_t model) { - return x86_family(eax) =3D=3D 0x19 && x86_model(eax) <=3D 0x0f; + return family =3D=3D 0x19 && model <=3D 0x0f; } =20 /* @@ -395,13 +394,13 @@ static bool is_zen3(uint32_t eax) */ static bool use_amd_pmu(void) { - const struct kvm_cpuid_entry2 *entry; + uint32_t family =3D kvm_cpu_family(); + uint32_t model =3D kvm_cpu_model(); =20 - entry =3D kvm_get_supported_cpuid_entry(1); return is_amd_cpu() && - (is_zen1(entry->eax) || - is_zen2(entry->eax) || - is_zen3(entry->eax)); + (is_zen1(family, model) || + is_zen2(family, model) || + is_zen3(family, model)); } =20 int main(int argc, char *argv[]) --=20 2.38.0.rc1.362.ged0d419d3c-goog