From patchwork Thu Oct 13 12:13:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 2038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp241582wrs; Thu, 13 Oct 2022 05:19:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6C6PrJqxJhn3/jzxavxFnfgr0+G5vufJ2wLlEIJY8gE+TqiUOgLzdo8GUjwHXshu24BelQ X-Received: by 2002:a17:906:9c83:b0:779:c14c:55e4 with SMTP id fj3-20020a1709069c8300b00779c14c55e4mr25755133ejc.619.1665663552884; Thu, 13 Oct 2022 05:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665663552; cv=none; d=google.com; s=arc-20160816; b=e2FSElOE23H1rBLaB803z14gO3h6IQJWMiZehOaqsL5x5XPO/BTA20JNqcmTKE+c3j GmOMN9DrHpADkhsSP/odhdLnG8i4WeUrFDTbT3wAOWAIsMqpbNguanurtLgCi5gmiCVb TcPPUcUDUZuAiLJJ3Vq1nO/vNwH4DpsQBS+NtsJvJfWjeR822j6HxuMEKLtcsY4meEc+ t+TWw+v47Vxa05J3Y5/wSlU5VAW7oKjgsyQnlQN4d2n/9y3T+1GV/SJDsYT+OKbzpk1W mgFFfrB0lPJq6fM+43EhhfL28WuX7IOQKwT3EyREdCBR2U/lFyMq/ELVkAup7dH36Ku1 88Qg== 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=H9SaswMeDVA0PXtGn+/RgF2ttyuiFbIBcmIgImTCEOc=; b=BBmCWWVsfDszOLrl6FTujJi9v+keaDMIKKZSe6pczgtfCkG2dyG8F87ITNknjby02T A8LDiZCQIxgq9NQKWby3RfXhW+BbY2XFLfy7L+NJwE0mVCwlG3HhF+VOkvKmUmqszs/0 iwIyBELJ0SPGW0lMifZZOk+DqHJGeN9TEUx9kbOBigBr52uWtFVd00N3gMgsAZEPJemK Q9jWqYtRtG5t3GheNY5oI77M9reXJBcL0lug/x3yowbsiBwpAXdGaBVem605wPjQVhRP E0tdDCqEDmdmuBMC3W3kNtKWMgm4irCISPXMnbwg8O7Lgx8n4ySqUfZSWk23VWLA/Bdr ZKdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ii25z3y8; 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 fg4-20020a056402548400b0045cb9cf913csi2904234edb.424.2022.10.13.05.18.47; Thu, 13 Oct 2022 05:19:12 -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=20210112 header.b=Ii25z3y8; 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 S229733AbiJMMOJ (ORCPT + 99 others); Thu, 13 Oct 2022 08:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbiJMMOC (ORCPT ); Thu, 13 Oct 2022 08:14:02 -0400 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 C7244FDB62 for ; Thu, 13 Oct 2022 05:13:54 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id c12-20020a170903234c00b0017f695bf8f0so1213633plh.6 for ; Thu, 13 Oct 2022 05:13:54 -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:from:to:cc:subject:date:message-id:reply-to; bh=H9SaswMeDVA0PXtGn+/RgF2ttyuiFbIBcmIgImTCEOc=; b=Ii25z3y8bR8LKI7fL+IKrahfLIIcV3i2dTRT7mx45kXaZTqxy+AlAEJavNtwpa3Anw FzlrCvqcIVsgqY5N/4i6RpGtHtnXrv/KT6iO8pgRcqZeKk0f08HQPZeixvrS75+Ucw5L VV0Kp9LASJiH661+y+0zqS+0bi4Ge2wi5JIRdmc3Simtu4fnznbSA2LJuCQfxGGBNgOd km5BGclc4f2DTtfQwUTKXBVv+e3Mc14iEnNDliLXhGJtJJ+t/Xt3wBj9OliaFx99xuMS sLj0INBleT8YXIcOCau1ft0h9gLiAptL/Q5xHngJ5C8CySJVqOXuEHFcRnQWu/xLRthx +jsw== 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=H9SaswMeDVA0PXtGn+/RgF2ttyuiFbIBcmIgImTCEOc=; b=kx5bs8SMo/JlRSkshW1ibiJ6Oo9XWpmGWCA/iPY863u18NoiNOzp0LqlyUX1evxTxw EYIJ6jhB05p75UMB0ZfMkkuuOMeG2NilwzaYLgYqFUIQMTnz3UwNxRyJpn0/cPIoiMZ/ wbUn+6edUtYBKVQ5Bk6pK/77nVzmNiQ03LXTAK7SOYI0zaGynOimtNINGR1IZOq5lL03 5KkX2G7d9/Kfv7n5qNRKk2Hc7NhibwgXTbljRUAkRT1EFI/5MvDFGUy0HxrvF1Mr1Bqd jzzgzFyUZlTa8iE8EGe7/ni1kdT/3NdRbNEb/SrllRpGii2mp7zn+3Fh4lANQA4TI0YS IGZw== X-Gm-Message-State: ACrzQf2YGcQW/44Bf9GGgAEwo2s1e4GJMl8warSHOg3XX6upweBKfy2A 90y7+5bMOKG/AEVPpTACN3Kq+Xan9RDRMw7Y X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90a:8c8e:b0:202:883b:2644 with SMTP id b14-20020a17090a8c8e00b00202883b2644mr10744181pjo.89.1665663233436; Thu, 13 Oct 2022 05:13:53 -0700 (PDT) Date: Thu, 13 Oct 2022 12:13:19 +0000 In-Reply-To: <20221013121319.994170-1-vannapurve@google.com> Mime-Version: 1.0 References: <20221013121319.994170-1-vannapurve@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221013121319.994170-5-vannapurve@google.com> Subject: [V3 PATCH 4/4] KVM: selftests: x86: Precompute the 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?1746574825356452079?= X-GMAIL-MSGID: =?utf-8?q?1746574825356452079?= Cache the vendor CPU type in a global variable so that multiple calls to is_amd/intel_cpu() do not need to re-execute CPUID. Sync the global variable is_cpu_amd into the guest so the guest can also avoid executing CPUID instruction. 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 fa65e8142c16..f508e58346e9 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -19,6 +19,7 @@ #define MAX_NR_CPUID_ENTRIES 100 vm_vaddr_t exception_handlers; +static bool is_cpu_amd; static void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent) { @@ -1046,7 +1047,7 @@ static bool cpu_vendor_string_is(const char *vendor) bool is_intel_cpu(void) { - return cpu_vendor_string_is("GenuineIntel"); + return !is_cpu_amd; } /* @@ -1054,7 +1055,7 @@ bool is_intel_cpu(void) */ bool is_amd_cpu(void) { - return cpu_vendor_string_is("AuthenticAMD"); + return is_cpu_amd; } void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits) @@ -1328,8 +1329,13 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) return get_kvm_intel_param_bool("unrestricted_guest"); } +void kvm_selftest_arch_init(void) +{ + is_cpu_amd = cpu_vendor_string_is("AuthenticAMD"); +} void kvm_arch_vm_post_create(struct kvm_vm *vm) { vm_create_irqchip(vm); + sync_global_to_guest(vm, is_cpu_amd); }