From nobody Tue Sep 16 21:49:15 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 4C2DFC3DA7A for ; Wed, 28 Dec 2022 19:25:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232366AbiL1TY7 (ORCPT ); Wed, 28 Dec 2022 14:24:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233144AbiL1TYv (ORCPT ); Wed, 28 Dec 2022 14:24:51 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 697E61741D for ; Wed, 28 Dec 2022 11:24:50 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id o18-20020a170902d4d200b00189d4c25568so12649695plg.13 for ; Wed, 28 Dec 2022 11:24:50 -0800 (PST) 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:from:to:cc:subject:date:message-id:reply-to; bh=Mo9WWk49bq3o6GgXHJZvpBlrKizEyknLEVuJxarZm6w=; b=cpM7ihQBd4FEp1qLIXzpJmruvJ3gQgEt9GzCCQuDYzGWE0/JQl180tij1IgB+3C1fI NI/CRB81Gq7Pn7zvsbktzzDsMrOjqyRGhefHNbr/27eV0KSb4bCymBjgValGjt5659P5 hnCuNueNq8N5g0T66+w9ELo5UBp8JnSXjCa9c3UVTjbtYAeJzkqJcs5a1fnnFFO1mAp1 LDzoMxKw2q/igdHUkIIUKWPRY4xdesLfXRisswaP4wC5MvSNJbOf3E1Y+S66a+hQj4lS 5oYExQ4FmaX+p9xdEUupA5dRNDU9nWqyptcGEq35t6lkLJu41sgez82NakYbR60frdT0 RgJg== 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:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Mo9WWk49bq3o6GgXHJZvpBlrKizEyknLEVuJxarZm6w=; b=qWd5t4M0dEV3w8+LQYRzIUw3EzBk9vk0NlC0PkrpZjzikZNKh4O8QHhuDP0gUyVQ8X rgh0xCOexEZNAtbtLUVoZSUfSNCknxlljmFoW4Ovu6ogahS3WTMGetzFhbS5++WdhPji B9BivnWAp3MAp9eHSINHPjdeb4IrQSgP96/0u4mndRJSd6ppScBFBIjJfzyOrtQMgsr8 GAsSedRwReQSX2m60ZJxUPqJy0d8siYeH1ILIWXDSS77as0SEcOuDRdTxsSJ6apKgF0V cQ4XzbvbRxBT83sKx7ZYQaSmAbkTrU4dIC4L9I//o8ZHk4y2B4hDdpMs17m/UCqpUgaj mIPg== X-Gm-Message-State: AFqh2kppVZgS/4oPMI31Bq/fM56GbpLm+G2I7vdFOydXdfuYPPQL/w6/ qa0TnQxliTwiei4saJ0P+JjOJJEogv9eFZjU X-Google-Smtp-Source: AMrXdXtkZ+HcHbVmFeuaUfv5lwMV1eVF0Rl5j7xYKonekBJINuj3BtwPXCLd3BflIhE0ONbuqzWkDl/Nee6iIaDK X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90b:4d83:b0:220:1f03:129b with SMTP id oj3-20020a17090b4d8300b002201f03129bmr106930pjb.0.1672255489536; Wed, 28 Dec 2022 11:24:49 -0800 (PST) Date: Wed, 28 Dec 2022 19:24:35 +0000 In-Reply-To: <20221228192438.2835203-1-vannapurve@google.com> Mime-Version: 1.0 References: <20221228192438.2835203-1-vannapurve@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221228192438.2835203-2-vannapurve@google.com> Subject: [V4 PATCH 1/4] KVM: selftests: x86: use this_cpu_* helpers From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use this_cpu_* helpers to query the cpu vendor. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- .../selftests/kvm/include/x86_64/processor.h | 22 +++++++++++++++++++ .../selftests/kvm/lib/x86_64/processor.c | 16 ++------------ 2 files changed, 24 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 2a5f47d51388..84edac133d8f 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -555,6 +555,28 @@ static inline uint32_t this_cpu_model(void) return x86_model(this_cpu_fms()); } =20 +static inline bool this_cpu_vendor_string_is(const char *vendor) +{ + const uint32_t *chunk =3D (const uint32_t *)vendor; + uint32_t eax, ebx, ecx, edx; + + cpuid(0, &eax, &ebx, &ecx, &edx); + return (ebx =3D=3D chunk[0] && edx =3D=3D chunk[1] && ecx =3D=3D chunk[2]= ); +} + +static inline bool this_cpu_is_intel(void) +{ + return this_cpu_vendor_string_is("GenuineIntel"); +} + +/* + * Exclude early K5 samples with a vendor string of "AMDisbetter!" + */ +static inline bool this_cpu_is_amd(void) +{ + return this_cpu_vendor_string_is("AuthenticAMD"); +} + static inline uint32_t __this_cpu_has(uint32_t function, uint32_t index, uint8_t reg, uint8_t lo, uint8_t hi) { diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index acfa1d01e7df..a799af572f3f 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1006,26 +1006,14 @@ void kvm_x86_state_cleanup(struct kvm_x86_state *st= ate) free(state); } =20 -static bool cpu_vendor_string_is(const char *vendor) -{ - const uint32_t *chunk =3D (const uint32_t *)vendor; - uint32_t eax, ebx, ecx, edx; - - cpuid(0, &eax, &ebx, &ecx, &edx); - return (ebx =3D=3D chunk[0] && edx =3D=3D chunk[1] && ecx =3D=3D chunk[2]= ); -} - bool is_intel_cpu(void) { - return cpu_vendor_string_is("GenuineIntel"); + return this_cpu_is_intel(); } =20 -/* - * Exclude early K5 samples with a vendor string of "AMDisbetter!" - */ bool is_amd_cpu(void) { - return cpu_vendor_string_is("AuthenticAMD"); + return this_cpu_is_amd(); } =20 void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bit= s) --=20 2.39.0.314.g84b9a713c41-goog