Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp322021rdf; Tue, 21 Nov 2023 03:57:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHL2rSpwD5YD05h4zWM9/l7XSdkcZAIScTHmH7QmymEud6+2xyKTrnQ2N1LLIf9XT5gRq1r X-Received: by 2002:a17:903:2350:b0:1cf:6ce6:5f22 with SMTP id c16-20020a170903235000b001cf6ce65f22mr2429719plh.60.1700567861651; Tue, 21 Nov 2023 03:57:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700567861; cv=none; d=google.com; s=arc-20160816; b=wMaD4RYQ5zGk582kfMuVN154LpTbzlzUjjkTnxCWM5ZRMhKL6szXnIPElybZJKi6Cs ysH6II+BWVUJJu43uAjjBty+g+Co4zULNDA51KVqqCYsbRy8YxCM/+63FfWI4xwBNN4A ayixLlcYmMuwDjlRbXtfYrnlztPMRykHMbwz6NA2PV5A3OIk+FCs/isjHY5HJODmhXX+ wCtzF7KooK3DWnSocuHBIHWgtPO/En5JQa5asJ76T0CulXnuyiJ4acr01JGwGhnUppW2 WkLwnRZWVUMrziGoDQgjm3F+DEn0aaDjZfKxUVsUuMU1ghyUZ+5Mr32Qo86I252a8ZQt wlrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZtftiOzjpf70P5oevOX6XZZCHaAm7J3EtiuJv1/+VvA=; fh=sIMbrHW6XchtO8J++xKMvfnuMh37piioh5cqciNSK/o=; b=cftJ+b1MXaKLgZzhcMsFQdlB7vcim15VhuD/Lhe5lHsUiyTQD/FdiqGqh7c54SZrLV b9Pr1ISIYYxNR+vWEjKaInW7R37otswvdLyAiGpm1Tz9N7nXO6lMZA6/eQc4KMcgnqM0 ATOja+RQxv8lmUWjh9El3JixlrFsTYKoJI72X2BzKniOokGZURiaUt7nWG/7Y0jt/yrk su1rYHszNBw01L9vNoukAVsGNWFAaffv0ki+fmFQ46zIAzNVIgcQE0cZXVQ6wq7Wecgj FX2Te4tWUjVQUZ/7Xsy2UM0doUTFRdv05dYZLXDc2xxUE/+Eo87xkFcjLJ/LBuqMfyiZ xGPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Qm1AT+aP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id c6-20020a170902aa4600b001c5ff477ebcsi7390652plr.265.2023.11.21.03.57.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 03:57:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Qm1AT+aP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 44BEE802CE60; Tue, 21 Nov 2023 03:56:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234592AbjKUL4H (ORCPT + 99 others); Tue, 21 Nov 2023 06:56:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234449AbjKULz5 (ORCPT ); Tue, 21 Nov 2023 06:55:57 -0500 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1838123; Tue, 21 Nov 2023 03:55:53 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-1cf5901b4c8so21522915ad.1; Tue, 21 Nov 2023 03:55:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700567753; x=1701172553; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZtftiOzjpf70P5oevOX6XZZCHaAm7J3EtiuJv1/+VvA=; b=Qm1AT+aPqLX7p1TgcTgzbWKQ/pOBlQTM0zaHKYZ7UxcdmVQia044wKWQFtAAd037y7 ZMch7ujaVV5dP4J6DG7R744rjMP/BHDDK3LYOVXc/uYIkQJxWtQb2HUfWTCcRL+2Er+v 4tXLApM5mv9EzRecwxBxymxGbXSJfP8mmP4M3vNQeTKsFlfgmpLBmcYxyiRpcmDlraWw HXzk4WLf2L7lIb+IC1o1ciVivUYMcIrLp9/1XlenXuqakN/zU4E6CPHYdV5HHNwdXbDV ec3427YMtgY79JuCf18o5xSRxJLFFPxJbY/KYQMkMX7LCBzvgIgwQQLgQj4Slk1iaMRL CKYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700567753; x=1701172553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZtftiOzjpf70P5oevOX6XZZCHaAm7J3EtiuJv1/+VvA=; b=qXiE5UpC8hcFw6iTsGUDaUbZNEsDTtMo6g7wxblFy3iUtf4aFFUtp/W3HhhN3o8pyq UeN3Sbh15giGyhuyPg6Fp249p5VJ0xsWwr8uI67BDofsHMkDwzd3HLw4XYp10GnKggMd h9wbc82AQI0TUnwjmVlu1qNUg4REkrahw+bU0OLSQiqh8pdVMhOMRj4wKEORDuGAg4WJ F5T03JyouJFw+4NB+Q6rUvxCfR/CdDBeT1Ul1UjSkP4mDqSv0LondGj2eDGWRtUU2AJR 7Q/ak6JpUtKpjU7Tl7axtHW+bSFGd1uCw8xEo58vBSG3cOHIB+XI+8uo4IKYORKb8l36 GHxg== X-Gm-Message-State: AOJu0YysVdUqSSiCBjlX8HM7k0kO5E8x7IHYOD+1Zr8/hGFfpkZSIYTm 9DWFWaeYlA4xePiiU/xfKCI= X-Received: by 2002:a17:903:2350:b0:1cf:6ce6:5f22 with SMTP id c16-20020a170903235000b001cf6ce65f22mr2426187plh.60.1700567753338; Tue, 21 Nov 2023 03:55:53 -0800 (PST) Received: from localhost.localdomain ([103.7.29.32]) by smtp.gmail.com with ESMTPSA id g10-20020a170902740a00b001cc1dff5b86sm7685431pll.244.2023.11.21.03.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 03:55:53 -0800 (PST) From: Jinrong Liang X-Google-Original-From: Jinrong Liang To: Sean Christopherson Cc: Paolo Bonzini , Like Xu , Jim Mattson , Aaron Lewis , Wanpeng Li , Jinrong Liang , Jinrong Liang , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/9] KVM: selftests: Test AMD Guest PerfCtrExtCore Date: Tue, 21 Nov 2023 19:54:56 +0800 Message-Id: <20231121115457.76269-9-cloudliang@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231121115457.76269-1-cloudliang@tencent.com> References: <20231121115457.76269-1-cloudliang@tencent.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 21 Nov 2023 03:56:32 -0800 (PST) From: Jinrong Liang Add test case for AMD Guest PerfCtrExtCore. Signed-off-by: Jinrong Liang --- .../selftests/kvm/x86_64/pmu_counters_test.c | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c index 07cb9694e225..ca5b352ea6ae 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c @@ -863,6 +863,36 @@ static void test_amd_pmu_version(void) } } +static void guest_test_perfctr_core(void) +{ + bool expect_gp = !this_cpu_has(X86_FEATURE_PERFCTR_CORE); + unsigned int i; + + for (i = 0; i < AMD64_NR_COUNTERS_CORE; i++) { + guest_wr_rd_amd_counters(MSR_F15H_PERF_CTR0 + i * 2, expect_gp, 0xffff); + guest_wr_rd_amd_counters(MSR_F15H_PERF_CTL0 + i * 2, expect_gp, 0); + } + + GUEST_DONE(); +} + +static void test_amd_perfctr_core(void) +{ + bool kvm_pmu_has_perfctr_core = kvm_cpu_has(X86_FEATURE_PERFCTR_CORE); + struct kvm_vcpu *vcpu; + struct kvm_vm *vm; + unsigned int i; + + for (i = 0; i <= kvm_pmu_has_perfctr_core; i++) { + vm = pmu_vm_create_with_one_vcpu(&vcpu, guest_test_perfctr_core); + + vcpu_set_or_clear_cpuid_feature(vcpu, X86_FEATURE_PERFCTR_CORE, i); + + run_vcpu(vcpu); + kvm_vm_free(vm); + } +} + int main(int argc, char *argv[]) { TEST_REQUIRE(kvm_is_pmu_enabled()); @@ -881,6 +911,7 @@ int main(int argc, char *argv[]) test_amd_zen_events(); test_amd_counters_num(); test_amd_pmu_version(); + test_amd_perfctr_core(); } else { TEST_FAIL("Unknown CPU vendor"); } -- 2.39.3