From patchwork Wed Dec 28 19:24:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 37263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2050707wrt; Wed, 28 Dec 2022 11:25:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXvsSXGWbGRqaOPkULD8yalpcfl+Neuc9RN3yZvNEMDZb1Lmx+8CR/8aeFyfpbLU/ntlrQzW X-Received: by 2002:a17:90b:1296:b0:219:36c6:f06d with SMTP id fw22-20020a17090b129600b0021936c6f06dmr29573773pjb.20.1672255554187; Wed, 28 Dec 2022 11:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672255554; cv=none; d=google.com; s=arc-20160816; b=Dx/aFeD9nuTUyQ9DRQOnhYhTefsAF+6VtKNUJikyKtRmHPokfIb8I3DGzluLr2ZqJ4 XnYtSeSPGapRT+RTe2aWSc9r+6R6dTXBhejdcNQQNEKjGu3ikUN/4ASBhL35kUYrY38E FPC85QuXUiyxnlj4scFxFQFPH9KPECwvYC+OtIlUKJaDZxKD0IkCEVlctfdoGLSbVQW8 yiDN4kAhbxVk7O+XISC1kCz2K9lMKuMimkvNy6W6Eugj7qi2uQElQQ/bhIUCHzc0kY5E e8EMJFUSFQlt0vtRHPEiB9HAaoCSOugThpAO6gK2iVj3O1/eJM9aE60PyIWlSuqP5er7 v8SA== 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=Mo9WWk49bq3o6GgXHJZvpBlrKizEyknLEVuJxarZm6w=; b=VdzuBsM5xjL0O6kR80Zp+Fbj1hPV2ccVG65SkbSMXfAC/i1atdea8fqCHU/OIq3wPA iG39WiJNfZS6zPsUeFbt5w/B8WtU37CwWut1J3DDL84ZHbB4sVlnprXW0ZW0x9qKtt+P AMXPB7iIVXrA0pmv8y8pz8emkH3nwNaAXbH0BUxytiK6yGMrWNyzl6RK9GdrIMXRA9HE I0YFTQsPdQP7tKXyi/vpKA4q3OJW1/+Qe3ZHrgpaBUEJQ6Ce+kSqCj3ralMgizhE+o4P a3+0WfD5cCl78FdU/D2qAjAQ37ySS61w7YAuU63R/BIKsfBK+qwmiq6+DXL/Jr21KXX5 vT/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cpM7ihQB; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pc3-20020a17090b3b8300b0022601981ba2si7196120pjb.99.2022.12.28.11.25.42; Wed, 28 Dec 2022 11:25:54 -0800 (PST) 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=20210112 header.b=cpM7ihQB; 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 S231879AbiL1TY7 (ORCPT + 99 others); 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-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 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,USER_IN_DEF_DKIM_WL autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753487040162557515?= X-GMAIL-MSGID: =?utf-8?q?1753487040162557515?= 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()); } +static inline bool this_cpu_vendor_string_is(const char *vendor) +{ + const uint32_t *chunk = (const uint32_t *)vendor; + uint32_t eax, ebx, ecx, edx; + + cpuid(0, &eax, &ebx, &ecx, &edx); + return (ebx == chunk[0] && edx == chunk[1] && ecx == 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/testing/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 *state) free(state); } -static bool cpu_vendor_string_is(const char *vendor) -{ - const uint32_t *chunk = (const uint32_t *)vendor; - uint32_t eax, ebx, ecx, edx; - - cpuid(0, &eax, &ebx, &ecx, &edx); - return (ebx == chunk[0] && edx == chunk[1] && ecx == chunk[2]); -} - bool is_intel_cpu(void) { - return cpu_vendor_string_is("GenuineIntel"); + return this_cpu_is_intel(); } -/* - * 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(); } void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits) From patchwork Wed Dec 28 19:24:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 37264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2050780wrt; Wed, 28 Dec 2022 11:26:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXs8enb3mR9D7R4WWK3yibSN7t8FoOhwEwjjpe3c5H/w9npD2X2OHx/nZfpnzU+lKyhjHS97 X-Received: by 2002:a17:903:1358:b0:192:9c2e:b36b with SMTP id jl24-20020a170903135800b001929c2eb36bmr1140398plb.52.1672255562489; Wed, 28 Dec 2022 11:26:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672255562; cv=none; d=google.com; s=arc-20160816; b=JuT3aUhJX2axmHhj9U0WbGAe8n2bB4z7JKLMckltUvg3zfuwpolomxjJQTwJYo31cP 8aUlaJeiXIAjet6HND8toFR46gUoUcWxVHznZ3RuIBZyy/K18abw2CgAdL9r72jY5wh9 kZkoByzXTf+QS6amK2qPU0raLCiNLhz86MuJzmg2KM3C2FfFOEH1fCjG5oi94Rj84gjU EbApZO3j/2JTL+oBGMZixrtoQ+f2pGzxnCS8ArZz6y9JocjE4UruMX13zAeA7NzBBab5 8cgRFuxXSOuwLh/Q2ycaPOK41CaHyUFqMoCmZylGlK/75JAGBij8WWjHj+75uIeVEZVB D+uQ== 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=eezWDwyqk949sEAV6VBZXvmE65PTPfqNCFhhSoX++44=; b=zg8up3ETECFxDVgQmR4DEl0i5OuUgPrjIfyAEwC8KzgCcVmquLwf7xQVvGtlEMfQ5I NnXHuRFtMH0cJPOZkdQFAT9ZgOCOgRE0pwDvCr1FDba3RCE6SQglKw6KATCTc0r4Okjd wG+JBE8siq5OaEmsUTh8eUSBqY4mRyAS0LUTvU9/gyjPtINk5ssPAvCCt3hbkRUuPLtz TMkyA312V/jrAF69XZRQ1oaX+L7LJxEMBznpj6LnDNyBLSsxAPS5uvTr7RFZg7WvsPy3 Tp7pY97rw6w1KLy6U+rxFfEx07hXtv/DZfsyd38gqmmJKU74GRvly1XQ7mmsNuPpAO7E d1zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VQLWwAsn; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d3-20020a630e03000000b0047048d81089si16537371pgl.186.2022.12.28.11.25.50; Wed, 28 Dec 2022 11:26:02 -0800 (PST) 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=20210112 header.b=VQLWwAsn; 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 S233280AbiL1TZD (ORCPT + 99 others); Wed, 28 Dec 2022 14:25:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233285AbiL1TY6 (ORCPT ); Wed, 28 Dec 2022 14:24:58 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B05D1838A for ; Wed, 28 Dec 2022 11:24:52 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id e6-20020aa78c46000000b005772151d489so8656618pfd.15 for ; Wed, 28 Dec 2022 11:24:52 -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=eezWDwyqk949sEAV6VBZXvmE65PTPfqNCFhhSoX++44=; b=VQLWwAsnp8xEr114AAmlLuYwOEaQZ3kuhyeF6c365GeAlZ4EMzS8MiWB11jz/EMUgm khDN6r175XUEyW7m/oNk3OZkdkPyvwGwmsgCd4NMjRYpSLjTAYPrx72KQCfsNXcbQRLr 0EkXan3XgXT5CLnAlpsw0Vmj/h7JMY+8peywoXVo1O9CJLLG6GhpKfyUTh1zNLRd6zLY FEq1Y+kNPCkX43rdGocrQGj5MgGl4RnJaqHBexdt3XuZeOQtdNgiFzgO99+DYRM3JFBZ 20n74dHtErcViR3PW+5hpXz5jvnhsU/bhHiP4KqIRiiRfueHHRoeui8yVMj5sxFSEL5j 47jA== 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=eezWDwyqk949sEAV6VBZXvmE65PTPfqNCFhhSoX++44=; b=2SMcvlyi+qWifjT+KmkYnsPj3gj52RaZygWetdu0H/hKtQA/AC4OjajPD7HdrxZq6N sEzuvqS9OwuPqLUxmRoZ/meF3G+7xjUOHrho8E6VPDfPXOLqIXad8a357AJDyHRjxXPm 9jrR2Qr0MecDfYo8V/rp1FrbdExIpRuypPWt8ccsMzlqfmiTGOAvaLPhuM4p0LzBpGno ztl1Ku6TBYNxL8pi1OpLa6DML9/6u294KBskGq84+XIjyI3zvNM+ePP0esKhfZIZppA5 Z4WlIjwQZf+K9TcJ4evJ3Pk0nkYFbgk7d3w/JhzqoCSNEogeDOv8+5h5gW2V5sWpVrqq RjAQ== X-Gm-Message-State: AFqh2koD2iqPVrElVCO46SYusSG/EM/3G8H6j2tV/OqebuSi746gxe3z 10HRT4krdaW/jOBCQv3mBSyW3o7WAmDJ7eiH X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90a:5c86:b0:219:c1fb:5da8 with SMTP id r6-20020a17090a5c8600b00219c1fb5da8mr2330892pji.221.1672255492112; Wed, 28 Dec 2022 11:24:52 -0800 (PST) Date: Wed, 28 Dec 2022 19:24:36 +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-3-vannapurve@google.com> Subject: [V4 PATCH 2/4] KVM: selftests: x86: Add variables to store cpu type 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 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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753487048476704865?= X-GMAIL-MSGID: =?utf-8?q?1753487048476704865?= Add variables to hold the cpu vendor type that are initialized early during the selftest setup and later synced to guest vm post VM creation. These variables will be used in later patches to avoid querying CPU type multiple times. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- tools/testing/selftests/kvm/lib/x86_64/processor.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index a799af572f3f..b3d2a9ab5ced 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -19,6 +19,8 @@ #define MAX_NR_CPUID_ENTRIES 100 vm_vaddr_t exception_handlers; +static bool host_cpu_is_amd; +static bool host_cpu_is_intel; static void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent) { @@ -555,6 +557,8 @@ static void vcpu_setup(struct kvm_vm *vm, struct kvm_vcpu *vcpu) void kvm_arch_vm_post_create(struct kvm_vm *vm) { vm_create_irqchip(vm); + sync_global_to_guest(vm, host_cpu_is_intel); + sync_global_to_guest(vm, host_cpu_is_amd); } struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id, @@ -1264,3 +1268,9 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) return get_kvm_intel_param_bool("unrestricted_guest"); } + +void kvm_selftest_arch_init(void) +{ + host_cpu_is_intel = this_cpu_is_intel(); + host_cpu_is_amd = this_cpu_is_amd(); +} From patchwork Wed Dec 28 19:24:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 37266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2051152wrt; Wed, 28 Dec 2022 11:27:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXux0F/Q+uFrcT38EKUkpUd/RxJ9RWAA/MVou7Q8IDmSZ++be3cswE81BGn22zQSH0zYRvAr X-Received: by 2002:a62:5214:0:b0:581:b3b3:7714 with SMTP id g20-20020a625214000000b00581b3b37714mr1501856pfb.20.1672255623334; Wed, 28 Dec 2022 11:27:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672255623; cv=none; d=google.com; s=arc-20160816; b=uKCu/YE81p3960P7jTQ1CwYxaIUFw4IDc+fx1L1keibhq0c5G16FSwzN4Agugn/Wgn gFNjag0ozxmJ9elsBGDtZFh+X47UtY3/Y7LQKHZmRmSHsrwqVTjRl8xujbxZb457qDLo xT5lVU80hgXZl9XSfY2ENzhRh+hTmYcMSuVQkZO9pU4PEiDbdgECCxnoqHmUiy77I1iE RTt2wQMNd4mIjFPdXXDyid9gX6W2t5KQy47EywKXG0rvSXgZ4Qe8NMezQBOLyiy3QIoO ox5/r58vkewL9Bn76mmkqPtdrEbYVzSQMC+ppUC0RVy2ubd3OFdjsf1dB20CryxwfXH3 cprA== 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=LehCRL1Bkg7m894um912QRzB94JErMqn1lJvj9EXRDg=; b=BZpYqpmuNT2nmQz0aJ9d+1Z5HKCTnfK+O4Z5hFSrBF+Ms5guE+WZwxQ3Hhh4gbJ3fr kx1eDWEIb+DPTilkU7U0nfOXggFfvLrzVDQTOJVspNRc+ZM4dMaw33NddTnsHP8EyKMV ebk6uuRrEM1PwiktVIWna4MFStJxhQFGCMIgi3y90GWvum1MOnibfppQkfvuSItJd8ua Wh8xBZ0e7UDPu2eo5Qitvt/gkNbdNj4PHx1ceDZ+AqO/zBeUoWlMBphl77rvKnAqwNxz /1ciZ5F59UBS8selAZ2YGIxouP3TFE4MOQZQ3IELsvK//NLCXXI/n7JuLiN8zy8zNIkr t7BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cao+rbPp; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 73-20020a62144c000000b0058167c50a3asi4902808pfu.142.2022.12.28.11.26.51; Wed, 28 Dec 2022 11:27:03 -0800 (PST) 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=20210112 header.b=cao+rbPp; 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 S233513AbiL1TZP (ORCPT + 99 others); Wed, 28 Dec 2022 14:25:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233383AbiL1TZA (ORCPT ); Wed, 28 Dec 2022 14:25:00 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DCD3183A2 for ; Wed, 28 Dec 2022 11:24:55 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-410f1a84ed2so182739257b3.15 for ; Wed, 28 Dec 2022 11:24:54 -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=LehCRL1Bkg7m894um912QRzB94JErMqn1lJvj9EXRDg=; b=cao+rbPpEh0CM4eNRLM1YYxP2pEUWPF5BIRkUsfj4rNDx9tMa1UMwmLh/gsaxT2R9a TbQDPuzyWb+6AvKoXOoitB7sfl2tOX95dPoFEieF6+auG+rGxQ66VFr4zH6vQONur46I E9C6zsVWj3ij2PphdLOmMeH7rnbP+i5AUrfwl2QILD5/cgGK75dPOYvlRSzrbIvXlEwk jhMEhmlYZ5OxI3FTKKztXe0lmlyo26WoZ+dlHx80UviSfbIX7/1Op1MDK5HttSQH0PaX zNpWm8sAlZ/V98i3QgOxtGG42hcvfkqugKnzTNTSN9ahBF+13zPLYfz2E3W9eMDSycLT 2uAA== 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=LehCRL1Bkg7m894um912QRzB94JErMqn1lJvj9EXRDg=; b=mXkUMK3GXw42CP6B5WrRISgAcxLnqni5gYJZN70z8Xeay785d7pYauBLmNoUIKQlCc +k72b/kOr4uVoHogP+aeemnvI3Hf7393szK8ydpip0UHLfxIAt102HPqkiB6OxQU35uS dGfojLCl6WIX+YABQccwl4Jds+kx0Se24YB26cwscqj53w0tt6pZN5TpsVUq7bcYTgas YXxHYxOA4ewjk+lhqGFvrO+K3B/n1cMOnfhMELn6RoudF+srfwjte5mWWBGgHODj3aFW 1HYfe4mG/ifpZQIYHMx7NrIFvy6xoz0wjAgQAC432OZmWCAAwVERKu5PRB3FfpLXPFZl MdYA== X-Gm-Message-State: AFqh2kokOs2Mdmg48NiowuYu0QDUe5WRltLrTqtN0obR4ZpNAOLybcna bk52sIcgOugnjU+PYG/oHBeph4gk77ZuC/2m X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a25:bbd1:0:b0:70b:87c6:4fe with SMTP id c17-20020a25bbd1000000b0070b87c604femr2824610ybk.550.1672255494272; Wed, 28 Dec 2022 11:24:54 -0800 (PST) Date: Wed, 28 Dec 2022 19:24:37 +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-4-vannapurve@google.com> Subject: [V4 PATCH 3/4] KVM: sefltests: x86: Replace is_*cpu with is_host_*cpu 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 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,USER_IN_DEF_DKIM_WL autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753487112390019341?= X-GMAIL-MSGID: =?utf-8?q?1753487112390019341?= Replace APIs to query cpu type with APIs always checking the host cpu type. This way there are two set of APIs to query CPU type: 1) this_cpu_is_*() 2) is_host_*cpu() that can be invoked as per the usecase. All the current callers of is_*cpu actually care about host cpu type so they are updated to invoke is_host*cpu. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- .../testing/selftests/kvm/include/x86_64/processor.h | 4 ++-- tools/testing/selftests/kvm/lib/x86_64/processor.c | 12 ++++++------ .../selftests/kvm/x86_64/fix_hypercall_test.c | 4 ++-- .../testing/selftests/kvm/x86_64/mmio_warning_test.c | 2 +- .../selftests/kvm/x86_64/pmu_event_filter_test.c | 4 ++-- .../x86_64/vmx_exception_with_invalid_guest_state.c | 2 +- 6 files changed, 14 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 84edac133d8f..8f9e066c89d9 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -713,8 +713,8 @@ static inline void cpu_relax(void) "hlt\n" \ ) -bool is_intel_cpu(void); -bool is_amd_cpu(void); +bool is_host_cpu_intel(void); +bool is_host_cpu_amd(void); struct kvm_x86_state *vcpu_save_state(struct kvm_vcpu *vcpu); void vcpu_load_state(struct kvm_vcpu *vcpu, struct kvm_x86_state *state); diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index b3d2a9ab5ced..18f0608743d1 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -115,7 +115,7 @@ static void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent) bool kvm_is_tdp_enabled(void) { - if (is_intel_cpu()) + if (is_host_cpu_intel()) return get_kvm_intel_param_bool("ept"); else return get_kvm_amd_param_bool("npt"); @@ -1010,14 +1010,14 @@ void kvm_x86_state_cleanup(struct kvm_x86_state *state) free(state); } -bool is_intel_cpu(void) +bool is_host_cpu_intel(void) { - return this_cpu_is_intel(); + return host_cpu_is_intel; } -bool is_amd_cpu(void) +bool is_host_cpu_amd(void) { - return this_cpu_is_amd(); + return host_cpu_is_amd; } void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits) @@ -1228,7 +1228,7 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm) max_gfn = (1ULL << (vm->pa_bits - vm->page_shift)) - 1; /* Avoid reserved HyperTransport region on AMD processors. */ - if (!is_amd_cpu()) + if (!is_host_cpu_amd()) return max_gfn; /* On parts with <40 physical address bits, the area is fully hidden */ diff --git a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c index 32f7e09ef67c..e84c0c5a73b1 100644 --- a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c +++ b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c @@ -48,10 +48,10 @@ static void guest_main(void) const uint8_t *other_hypercall_insn; uint64_t ret; - if (is_intel_cpu()) { + if (is_host_cpu_intel()) { native_hypercall_insn = vmx_vmcall; other_hypercall_insn = svm_vmmcall; - } else if (is_amd_cpu()) { + } else if (is_host_cpu_amd()) { native_hypercall_insn = svm_vmmcall; other_hypercall_insn = vmx_vmcall; } else { diff --git a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c index fb02581953a3..d2d5dcae98e7 100644 --- a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c +++ b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c @@ -93,7 +93,7 @@ int main(void) { int warnings_before, warnings_after; - TEST_REQUIRE(is_intel_cpu()); + TEST_REQUIRE(is_host_cpu_intel()); TEST_REQUIRE(!vm_is_unrestricted_guest(NULL)); diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c index 2de98fce7edd..289226117513 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 @@ -363,7 +363,7 @@ static void test_pmu_config_disable(void (*guest_code)(void)) */ static bool use_intel_pmu(void) { - return is_intel_cpu() && + return is_host_cpu_intel() && kvm_cpu_property(X86_PROPERTY_PMU_VERSION) && kvm_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS) && kvm_pmu_has(X86_PMU_FEATURE_BRANCH_INSNS_RETIRED); @@ -397,7 +397,7 @@ static bool use_amd_pmu(void) uint32_t family = kvm_cpu_family(); uint32_t model = kvm_cpu_model(); - return is_amd_cpu() && + return is_host_cpu_amd() && (is_zen1(family, model) || is_zen2(family, model) || is_zen3(family, model)); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c b/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c index 2641b286b4ed..d74b0d22385a 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c @@ -111,7 +111,7 @@ int main(int argc, char *argv[]) struct kvm_vcpu *vcpu; struct kvm_vm *vm; - TEST_REQUIRE(is_intel_cpu()); + TEST_REQUIRE(is_host_cpu_intel()); TEST_REQUIRE(!vm_is_unrestricted_guest(NULL)); vm = vm_create_with_one_vcpu(&vcpu, guest_code); From patchwork Wed Dec 28 19:24:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 37265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2051074wrt; Wed, 28 Dec 2022 11:26:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXtYtr59URdhmiOwCSEMe8lO5bC6MEkzanJdAsFzORpQ0/H63EIUkvzJOKAoUB5vLEe/AurO X-Received: by 2002:a05:6a00:d1:b0:580:eb71:40f0 with SMTP id e17-20020a056a0000d100b00580eb7140f0mr17541627pfj.23.1672255609011; Wed, 28 Dec 2022 11:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672255608; cv=none; d=google.com; s=arc-20160816; b=ugYXs0j4Xqsa0LxCCBAzbu4VOclTYA+5Fo27Y4svz9JaDAMVncs/4UMEIW3XvnmrKA wxGN5v1WObKlod+k1h2VbuShw4JhXUJTiF36E5l5Yq7klo6uS7DDjZmowXaPJ3lD9BSK zkblkFp8CAbdJP2q3L0P4q/JXskD7UxwBsyRQF5nEF7godmHxtl7F8Oh/U/+qpMglA4d z8TRaJDp+Wn/EGtZyxYM4xjl7o7jeyafsK2XOs8cMJ1ZivM9GkCvTl3ITU7Fv7mUE60f 6Y8abYbCQGjY5p6GtKWryLQQ+qrKv9gUj9Pji5a9976HVmXwIMXjS5G97s6pKiWziJkx 3ATw== 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=sIyfuO6L8HnU8CmCldKrIpDi7aTZJyxJfn1wljTzIeI=; b=CNjqO9UfkUnY8IDaH7VC0cvd1V/YfLLt4gQf8lUehnvfds7tT7vu5B96G6DvIj6xK8 WQSpLjf6UGxbQK4W2mNMJ3DhA26AK7pViw2QiaKyx3oWTt8m1YNRf60MM/LHJ2di9GXU fmkFPhoCP9w+My3WSLshfhDdJ6RLJSF5+DK6DjDDGaYw7WTZmqDwt3nIFG9mrWleWjqn YaAciHGUMMiCDZVIKbboMImEv+qmXuMh9MwFXw3IcT+zj+PO1qWox8qDivFXh5digq6p i3tjZxHcGY7/wv4n8/aR2hLFYUY+GWsSSX+j1szLyCzIY9EyROnil8q6COUrF7ZakK2t 9z5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HbphtqtI; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h4-20020a056a00170400b00563960fdb21si17102948pfc.260.2022.12.28.11.26.37; Wed, 28 Dec 2022 11:26:48 -0800 (PST) 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=20210112 header.b=HbphtqtI; 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 S233191AbiL1TZZ (ORCPT + 99 others); Wed, 28 Dec 2022 14:25:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233350AbiL1TZF (ORCPT ); Wed, 28 Dec 2022 14:25:05 -0500 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 E32AB183AE for ; Wed, 28 Dec 2022 11:24:56 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id v16-20020a17090a899000b00219b1f0ddebso12926757pjn.5 for ; Wed, 28 Dec 2022 11:24:56 -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=sIyfuO6L8HnU8CmCldKrIpDi7aTZJyxJfn1wljTzIeI=; b=HbphtqtIjGcu1bCKK6wFWu4E/GlYZGDlsYger0IgbCeUkoHRrvjgvwYnY/vOQNJS3v FyjI7bdMglfCpRTTsNvK49p8IyLNoVRBVdcnldRVB+HUTo08LKiSrhC5Q/0Uc+QQdp+X IHJ89MTp65CrwucYaVMtjMiROhNdBnnGYlBREUmDHiQkTkehUA4DlpRUBvud1+SVqpMC 6jKDiAXw31yGNOiO07z1YlMzIXbFVC8qVLvnQMkUpOleAVc5L3CryHcplcqTmY4Pt+Gf tXjGKaI88IH6T+SOZw737PpHr745DcyWzXyYFxhUqfzzIygXPYuztcWMdNooU6ZBsvBQ U5Yg== 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=sIyfuO6L8HnU8CmCldKrIpDi7aTZJyxJfn1wljTzIeI=; b=ijMKKStsaTT14hNkFE01kEl5JP/h2MWruEIyM6BTf+AxRM+IVyORAZrsPha63LnCIX qiDB88VHs/xP/iUddCEECIHmr1CSvT/HHCd++2T7u/0DqIkixT+H4fCUOEAYddtg2FeK V609AF7q4hb4wSDsyEms1WSkocZ81isCUieE/OWcDCP8WRFyOvyux2zb3knmbHjhMhQ+ Pv7WZtutlRvyt9idQa9Ozejq+fAjCIphFRnpbipOmetoQSB6fBmTDcSIBxT26I90nJKA 8u0Xb4Ocbjf4buQWf3gakdsmcxY1bOqa29606hCZETfGeofo4HhTWelePS58DJxq2Jio c6/A== X-Gm-Message-State: AFqh2kqu03RUUl5/y986hBc84477lok6BB31BTse57cXrxaud8WaKId7 FjMdtLjJUheFka6W7UWM5d/y4CUhvJCXNDXu X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90a:7c48:b0:225:ff38:5494 with SMTP id e8-20020a17090a7c4800b00225ff385494mr796035pjl.151.1672255496443; Wed, 28 Dec 2022 11:24:56 -0800 (PST) Date: Wed, 28 Dec 2022 19:24:38 +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-5-vannapurve@google.com> Subject: [V4 PATCH 4/4] KVM: selftests: x86: Invoke kvm hypercall as per host cpu 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 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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753487097468070563?= X-GMAIL-MSGID: =?utf-8?q?1753487097468070563?= Invoke vmcall/vmmcall instructions from kvm_hypercall as per host CPU type. CVMs and current kvm_hyerpcall callers need to execute hypercall as per the cpu type to avoid KVM having to emulate the instruction anyways. CVMs need to avoid KVM emulation as the guest code is not updatable from KVM. Guest code region can be marked un-mondifiable from KVM without CVMs as well, so in general it's safer to avoid KVM emulation for vmcall/vmmcall instructions. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- tools/testing/selftests/kvm/lib/x86_64/processor.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 18f0608743d1..cc0b9c17fa91 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1154,9 +1154,15 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, { uint64_t r; - asm volatile("vmcall" + asm volatile("test %[use_vmmcall], %[use_vmmcall]\n\t" + "jnz 1f\n\t" + "vmcall\n\t" + "jmp 2f\n\t" + "1: vmmcall\n\t" + "2:" : "=a"(r) - : "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3)); + : "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3), + [use_vmmcall] "r" (is_host_cpu_amd())); return r; }