From patchwork Sat Nov 5 04:57:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 15885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp809788wru; Fri, 4 Nov 2022 22:02:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6jJiJtjrHI4923RNDHjm4RBoRAhk2+rhYOIT7MrrOlgoLj2QJyZcjcjqJEQAX2V+NjqY15 X-Received: by 2002:a63:2544:0:b0:46f:ed91:33ca with SMTP id l65-20020a632544000000b0046fed9133camr18449837pgl.383.1667624530977; Fri, 04 Nov 2022 22:02:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667624530; cv=none; d=google.com; s=arc-20160816; b=QUuKvaqwecQqYnu8elWtEwZ+k0XhC85JFTm7WsAOafVlyTKIVnrzFZSDIbjpH9KOF4 lwIkXH5lqfNYG0PZ5jfbmKizm1M5K/xrCeAZvt7KekXS9/BYavemln8q19qfyVzl8j53 BgZGXuKeCuEwOb9IrKqfKC6Qe9J2BoYvLauu9FJ/PZUEHETBEhQEzLbKoX7wydTKJ3fg lWzQ+DYl8uuh1dL9BUwvobATncobMPuLZNz8e+h+YV4wR0AVh3qH0Lv/Pe/QC6fBqCgZ SDw2jYAP6pSJ6yl697ohG6TU3l0cPrjFTxS0kkYIP0JLh+Jzpasji604kOYIHj7Yk5G/ PEYQ== 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=gZsOXIQ/ETlFCBETTe/elKVE4lpjamgAUlI2bZ+SvJc=; b=lK4qH28PfPdW2cT5ltwjO5FKK7KzL5XdQ4gA5Pm1beYl1Ivx1ZGeMCHu/SWWsf6Ez0 5cqxVgcdXHSQdJT28fl9q4squh2KOHjbsXdBQFYW3Vy72znIlRG1hC9t6H3IGcQlUaxI HO3VmZMx58L+IQTkvWKp64C5EQ/AmIyaw9pFABRzljdLELgehnLSKLX51JAMgSlzAfjn P49l7MQS2gQt4Ep4oEaeHjf/YiWsUtTMxeExTDi52x3qTPMzjBEwf4hRMZqBZSixkvSw uren/5+47FiZRfE9xIwf2PM3u/VeWVfBleflMfxbO32WQYulEPyEMkOuZLhsAqeE12Qb HCUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jB5l9Hay; 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 f7-20020a656287000000b0046ff26f21f0si1811882pgv.503.2022.11.04.22.01.57; Fri, 04 Nov 2022 22:02:10 -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=jB5l9Hay; 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 S229679AbiKEE5a (ORCPT + 99 others); Sat, 5 Nov 2022 00:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbiKEE5S (ORCPT ); Sat, 5 Nov 2022 00:57:18 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A26432BBD for ; Fri, 4 Nov 2022 21:57:17 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id f186-20020a636ac3000000b0044adaa7d347so3430935pgc.14 for ; Fri, 04 Nov 2022 21:57:17 -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=gZsOXIQ/ETlFCBETTe/elKVE4lpjamgAUlI2bZ+SvJc=; b=jB5l9Hayd7t9U2kjL83ltyjH3Fv+WtodRQcAlUj5Es6ZLiwVw+6vA0eIgG4QChDpWm qp97gIUIxTuhE8CWduUzsHWOHOaOc0cDlf58T7tROsRAsdnWkInlARWh8Q7AI3SF+UOf XIDyiMmkY9dKUGQuS0BWS6DlZ6s2LhcRrdf3AxedTUAp9uyDF8HyV7cPWu76Tc62OWgE +r333jvm8DKwfwdSxuekRtSS1+lkpnMhLgp9Re9QXOozWKUs8BUraLGvXaClX120fr+w iJm8sdJwJif+9C4KMMhykA94EhrQ4CEwxShXIwEqo6OQdiOR62eTPe43L1+UURPdKGE8 lhLw== 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=gZsOXIQ/ETlFCBETTe/elKVE4lpjamgAUlI2bZ+SvJc=; b=rNt96UsOHl2Gl0ojXiG178CfuGn3K2308uXQJcx7kW6X9+tXFjOylu4WycNrzd7vv7 pJWWnQn0oTXxbnvsggqLuEbl+nX9b8v8pabU7fN9PloJNyC5p8N0jYnE4irtHlLAtH/o TptwRryC/6vD3QnxxAZqRr8uAiMBHkUHcbRin14qjNPvk/DoZUH4s6c+RRBJpXhcRTJo nhYAIc8MZHNtsgz/x1ByjIUetcG4h/Q0y8GThcVmM/cI/N09RCRyzEoTwq9cA8ApTWEm +WZN+d6HYclJX+bwipngFKQJwwmuYA5mHv3la6GA4/5i02oNVFRXyhSivFNgEO6QgGCx VJnw== X-Gm-Message-State: ACrzQf1078+OLxQvoTZu25jiHVkOpNGL3FTxAUjCkY+gDYO+iFfP/3Q3 j0y9QXHO/BLwxdyUhJpHN7RJk5Mt94R8 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:218a:b0:56d:1bb6:af4f with SMTP id h10-20020a056a00218a00b0056d1bb6af4fmr36690480pfi.11.1667624236628; Fri, 04 Nov 2022 21:57:16 -0700 (PDT) Date: Fri, 4 Nov 2022 21:57:02 -0700 In-Reply-To: <20221105045704.2315186-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221105045704.2315186-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221105045704.2315186-5-vipinsh@google.com> Subject: [PATCH 4/6] KVM: selftests: Make Hyper-V guest OS ID common From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, vkuznets@redhat.com Cc: dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma 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?1748631060499294492?= X-GMAIL-MSGID: =?utf-8?q?1748631060499294492?= Make guest OS ID calculation common to all hyperv tests and similar to hv_generate_guest_id(). Signed-off-by: Vipin Sharma --- tools/testing/selftests/kvm/include/x86_64/hyperv.h | 10 ++++++++++ tools/testing/selftests/kvm/x86_64/hyperv_clock.c | 2 +- tools/testing/selftests/kvm/x86_64/hyperv_features.c | 6 ++---- tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/hyperv.h b/tools/testing/selftests/kvm/include/x86_64/hyperv.h index 075fd29071a6..9d8c325af1d9 100644 --- a/tools/testing/selftests/kvm/include/x86_64/hyperv.h +++ b/tools/testing/selftests/kvm/include/x86_64/hyperv.h @@ -9,6 +9,10 @@ #ifndef SELFTEST_KVM_HYPERV_H #define SELFTEST_KVM_HYPERV_H +#include + +#define HV_LINUX_VENDOR_ID 0x8100 + #define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000 #define HYPERV_CPUID_INTERFACE 0x40000001 #define HYPERV_CPUID_VERSION 0x40000002 @@ -189,4 +193,10 @@ /* hypercall options */ #define HV_HYPERCALL_FAST_BIT BIT(16) +static inline uint64_t hv_linux_guest_id(void) +{ + return ((uint64_t)HV_LINUX_VENDOR_ID << 48) | + ((uint64_t)LINUX_VERSION_CODE << 16); +} + #endif /* !SELFTEST_KVM_HYPERV_H */ diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_clock.c b/tools/testing/selftests/kvm/x86_64/hyperv_clock.c index d576bc8ce823..f9112c5dc3f7 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_clock.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_clock.c @@ -104,7 +104,7 @@ static void guest_main(struct ms_hyperv_tsc_page *tsc_page, vm_paddr_t tsc_page_ /* Set Guest OS id to enable Hyper-V emulation */ GUEST_SYNC(1); - wrmsr(HV_X64_MSR_GUEST_OS_ID, (u64)0x8100 << 48); + wrmsr(HV_X64_MSR_GUEST_OS_ID, hv_linux_guest_id()); GUEST_SYNC(2); check_tsc_msr_rdtsc(); diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c index 6b443ce456b6..b5a42cf1ad9d 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c @@ -13,8 +13,6 @@ #include "processor.h" #include "hyperv.h" -#define LINUX_OS_ID ((u64)0x8100 << 48) - static inline uint8_t hypercall(u64 control, vm_vaddr_t input_address, vm_vaddr_t output_address, uint64_t *hv_status) { @@ -71,7 +69,7 @@ static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall) GUEST_ASSERT(hcall->control); - wrmsr(HV_X64_MSR_GUEST_OS_ID, LINUX_OS_ID); + wrmsr(HV_X64_MSR_GUEST_OS_ID, hv_linux_guest_id()); wrmsr(HV_X64_MSR_HYPERCALL, pgs_gpa); if (!(hcall->control & HV_HYPERCALL_FAST_BIT)) { @@ -169,7 +167,7 @@ static void guest_test_msrs_access(void) */ msr->idx = HV_X64_MSR_GUEST_OS_ID; msr->write = 1; - msr->write_val = LINUX_OS_ID; + msr->write_val = hv_linux_guest_id(); msr->available = 1; break; case 3: diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c b/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c index a380ad7bb9b3..2c13a144b04c 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c @@ -69,7 +69,7 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm) GUEST_SYNC(1); - wrmsr(HV_X64_MSR_GUEST_OS_ID, (u64)0x8100 << 48); + wrmsr(HV_X64_MSR_GUEST_OS_ID, hv_linux_guest_id()); GUEST_ASSERT(svm->vmcb_gpa); /* Prepare for L2 execution. */