From patchwork Sat Mar 11 00:46:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 67910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp52424wrd; Fri, 10 Mar 2023 16:53:40 -0800 (PST) X-Google-Smtp-Source: AK7set/5FOlT0G+oNTLUBmUg+fFU2PUCPCqWUl/88vxG7CSEhahh+IwcXBqC4fWbCK4ps8kZKQ8h X-Received: by 2002:a17:903:283:b0:19c:d309:4612 with SMTP id j3-20020a170903028300b0019cd3094612mr32811512plr.6.1678496020090; Fri, 10 Mar 2023 16:53:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678496020; cv=none; d=google.com; s=arc-20160816; b=NndLXMtCU16MKVb5LA5nQbCmfH67Vprc2wmyYR5we5RdxmcMrPS50RwtnHq5Dze299 8s/CNLY3UB33Oh/axUmlADnCga1ylqhPbq/HodWZB9x5w1O86nwnsMvT2EjDV9WQpTC4 ZpJ9ndAiX8CrgLzHQDiINzXbD9pq3qPdCajiBccoMPVL4NGYVYfndy29zjrq8ZzJekvu JTP9IFachMNrSGoBHBcn7TQafpLIoQepDo+F/SJ86PpljERg5uMM8SITlJNdAnDysuvS 6Y67mdxCxlQgh2rv5J+kGDb7oChOh8XxDGOEC7TCWV+aXQgfGzH+jcShgD94FYRwaT0A En3A== 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:reply-to:dkim-signature; bh=UwMxWX9lXc3VYeDgFb3qxT6J0GWhUZ4fTBpHKmaPUo4=; b=HVY8qYpIrCHRNyVLctWn99btuFXPUQPPG25RgloVvVmUPjv9UkkxN2PNS0wl5dcnNr IHCDTsdbjmjV/huJxck6qKCryLltjsZR8M6V6y7+zwmw7e6e3X7YNB4RzNtyC+pMnOI7 x2/5lrwhvCvTijJUmr3qEAUh4vopXNgCbtOCTLpAlWj/a8rF0kMum0NfroqZRID96KdT ZX2SoHNqgh3A4g+fBVHLtU1Bjp8Nti25iILATXozuEPST49yUdrDwDWl3QxNydM82pjW GrdKok+9+IUn3LctG7IhG9UXiNF+mMWbXAEwzC6UPRXP6DQw2MzA2vepGQh9as4gtIc/ XBRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="hLQNM/3C"; 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 s9-20020a635249000000b00503151d6493si1025152pgl.198.2023.03.10.16.53.25; Fri, 10 Mar 2023 16:53:40 -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="hLQNM/3C"; 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 S230142AbjCKArk (ORCPT + 99 others); Fri, 10 Mar 2023 19:47:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230268AbjCKAq7 (ORCPT ); Fri, 10 Mar 2023 19:46:59 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FC7B13F68F for ; Fri, 10 Mar 2023 16:46:39 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id iw4-20020a170903044400b0019ccafc1fbeso3625784plb.3 for ; Fri, 10 Mar 2023 16:46:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678495599; 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=UwMxWX9lXc3VYeDgFb3qxT6J0GWhUZ4fTBpHKmaPUo4=; b=hLQNM/3Ck9a+9imtZyP3GGuRTeJaPSfHJ3XwUnAuDM6l7vf+ikPghSZhCLyFewxoTt 718eWMvalMU42w8rWkdJJUZkYM2/S2CxvLq3CW8IHb/ZZTrMYsJys6tQHDuLVfegXA6M 3e3RDgLF8L7LDGWlIiLgvGG/7GYRPQYdnqTqWJVtR/Hhwk4IhRQiIKAyv/7J42kNq6g6 XzfJZIzEDu7cNBDO8+zQAibWaYjGYP2MDPxuYR2rpR/7KWp4X7/GmqvpstJp4cB6eTiD Gc2tU8JPK9q3ttX1zc+p525ikfyD+dpPWif0Dtg7kB2APcnlLrPxDZHEa/BRVNYR8j1x Yaiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678495599; 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=UwMxWX9lXc3VYeDgFb3qxT6J0GWhUZ4fTBpHKmaPUo4=; b=gJBEZwGvo0bk3n7OK76IJgo9hM5DJhf9ni3Rh+pEtgqQz5A+tLHcjWJMiUbswm14oc 0x3OO8jFthudtJso00Ksjenjmpn0830i1J6R4U6yZCcHela6OUoUH5Pj21QqyT/SVZa4 nIe0i4NG8UjPYK1W2iNWTR64QWotyIa1/GZGMKFNXzucqUEZb8GKr+wIsB1zsn357c9q D7Prwt2lBAawbvrrwZ3X1PBHwrSm9ZwhcELCxc8oAgiUu4K3Tdg4p5btDkPUffJJ2V4W BvKIRWmrlMnLZzZsbrRmvHjCkwLTgCk/FxihFajqbY8Acc2PHnLmcJxHV1hGUFcpXC/5 t39A== X-Gm-Message-State: AO0yUKV1jxZMnWU2lTN/Z17CpSUVJz5mMYRAkIWKkV7jbuRLTMzHR+5r /oXUMEGPzICeUHgNbQkMseAzzONGWLg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:894:b0:23b:318d:dda7 with SMTP id bj20-20020a17090b089400b0023b318ddda7mr224259pjb.4.1678495599064; Fri, 10 Mar 2023 16:46:39 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 10 Mar 2023 16:46:06 -0800 In-Reply-To: <20230311004618.920745-1-seanjc@google.com> Mime-Version: 1.0 References: <20230311004618.920745-1-seanjc@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230311004618.920745-10-seanjc@google.com> Subject: [PATCH v3 09/21] KVM: selftests: Move 0/initial value PERF_CAPS checks to dedicated sub-test From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Like Xu , Yu Zhang 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?1760030642829843230?= X-GMAIL-MSGID: =?utf-8?q?1760030642829843230?= Use a separate sub-test to verify userspace can clear PERF_CAPABILITIES and restore it to the KVM-supported value, as the testcase isn't unique to the LBR format. Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86_64/vmx_pmu_caps_test.c | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c index ac08c0fdd84d..c3b0738e361b 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c @@ -41,6 +41,24 @@ static void guest_code(void) wrmsr(MSR_IA32_PERF_CAPABILITIES, PMU_CAP_LBR_FMT); } +/* + * Verify KVM allows writing PERF_CAPABILITIES with all KVM-supported features + * enabled, as well as '0' (to disable all features). + */ +static void test_basic_perf_capabilities(union perf_capabilities host_cap) +{ + struct kvm_vcpu *vcpu; + struct kvm_vm *vm = vm_create_with_one_vcpu(&vcpu, NULL); + + vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, 0); + ASSERT_EQ(vcpu_get_msr(vcpu, MSR_IA32_PERF_CAPABILITIES), 0); + + vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities); + ASSERT_EQ(vcpu_get_msr(vcpu, MSR_IA32_PERF_CAPABILITIES), host_cap.capabilities); + + kvm_vm_free(vm); +} + static void test_fungible_perf_capabilities(union perf_capabilities host_cap) { struct kvm_vcpu *vcpu; @@ -66,12 +84,6 @@ static void test_immutable_perf_capabilities(union perf_capabilities host_cap) uint64_t val; int ret; - vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, 0); - ASSERT_EQ(vcpu_get_msr(vcpu, MSR_IA32_PERF_CAPABILITIES), 0); - - vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.lbr_format); - ASSERT_EQ(vcpu_get_msr(vcpu, MSR_IA32_PERF_CAPABILITIES), (u64)host_cap.lbr_format); - /* * KVM only supports the host's native LBR format, as well as '0' (to * disable LBR support). Verify KVM rejects all other LBR formats. @@ -98,6 +110,7 @@ int main(int argc, char *argv[]) host_cap.capabilities = kvm_get_feature_msr(MSR_IA32_PERF_CAPABILITIES); host_cap.capabilities &= (PMU_CAP_FW_WRITES | PMU_CAP_LBR_FMT); + test_basic_perf_capabilities(host_cap); test_fungible_perf_capabilities(host_cap); test_immutable_perf_capabilities(host_cap);