Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp349816rdf; Tue, 21 Nov 2023 04:43:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEeL6//sHRfObW7iEhYr+3JWicVzy5WYP08oGmKBeWDWujcRJnbF36D6gkPl5ubtcSXtjX1 X-Received: by 2002:a05:6a00:189b:b0:68e:2f6e:b4c0 with SMTP id x27-20020a056a00189b00b0068e2f6eb4c0mr9334509pfh.28.1700570610090; Tue, 21 Nov 2023 04:43:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700570610; cv=none; d=google.com; s=arc-20160816; b=uKGqdKPQwIvsqnTCLKFXnP8tkSzpmZUQarVLN4Ylb8gkM/uU3C3zsKLwINcJ4aOrol OXYx7R7OLqI7iRQmLngXzliZLfTanT8+kCd/Tkf5ga1fy4NeybI8QaJkm8PjbjIs3YYi cl3pj7/aRuT7gGW/sTBA8fivzeFmAdFISZzCgBR6vQycDUsU7tkOjR474qyv2E8xseuR +camzFeLS1bfAF9TOdM0PE685risNvYegrY73y/+GlVzSnKyIEmZpNjVYYndICeFTeIO h0/ibZfxnQBNCVxxpotHEGOCfJsHSaBF1Q/rsgGao1diX6Et1cfA2pLeCcB+ixNJ6fYA JR/g== 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=maJ6auOp8L0b9qivkNZj20bUmfFTqIu0eFCNZfSuBj0=; fh=sIMbrHW6XchtO8J++xKMvfnuMh37piioh5cqciNSK/o=; b=noUIT4gG4T1ry0nOCpDXhR4259aCasZxBc00y8C4oe+jj+q4kw25m7/WI2Jf5koqpj ZzxAk1YYVVlpI9vnQtOQxRbVNDAfitx4nFM47zFZwSJ5Z9fzujryxtD+dRf/n8Hbhqil poPCKecyZ+99VybQlIWYyYs9CyRAMUgor0PDe7Wd8jvm5gQKMNBqVKnSGbfR+8uvSpGG wsPMM+SqjBdo0WsotLTBTc3PR7zWE1J+Xfl+0/4rHkiH+abBiT2DpDphjlPPKdI1mDTD 4AfXEBVFBT1On0KQw0nmmHx9ubPmN01rUG4tTFnkVVBjNbKJNdMNf4SQFVJQy8M/Fbqd 8OTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JcyGLbpb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q14-20020a056a00084e00b006cb68d849afsi6498045pfk.280.2023.11.21.04.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 04:43:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JcyGLbpb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id D42108116E46; Tue, 21 Nov 2023 04:43:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233504AbjKUMmu (ORCPT + 99 others); Tue, 21 Nov 2023 07:42:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234554AbjKULzo (ORCPT ); Tue, 21 Nov 2023 06:55:44 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B74B1112; Tue, 21 Nov 2023 03:55:40 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id d2e1a72fcca58-6bee11456baso4596584b3a.1; Tue, 21 Nov 2023 03:55:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700567740; x=1701172540; 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=maJ6auOp8L0b9qivkNZj20bUmfFTqIu0eFCNZfSuBj0=; b=JcyGLbpbjM9C1isQ2bo06+B8NEJd4AUr8du5v4ybN68pv7GpjUXNCbEqTCX9lhjzop BoEnfKZ6yzMMcmNEEN0QCjsf37kTGFAndfEqNE58OLej+sSJAEgEJBrrgoMsdLn8eLT3 Qill8FncNrhOH5Pj3AtzBiS/WJyyKUEkU14CZvqU7w+EKPfTGdRYQtJOyp5gRiOkOV+C jB5qMJRpFH1qVffuAl9H0dJ8lTtoOfC+NQ5Z6d0nS5pD2+IH7UGkVm1IxaM1JdUdAtet M/Ff/ml0FoUxbxENuQBs0wKhZA/lJLYtn8tEAzunSsiSaNLiFdEFBj14YdqQKjPtsHHa TypQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700567740; x=1701172540; 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=maJ6auOp8L0b9qivkNZj20bUmfFTqIu0eFCNZfSuBj0=; b=phXB2g1Khu9+4xvxZ82WVRWLFzSQ4UtQPzgItWwnckjS3lqwGE4g4YbXBZDkeGidxX TRkzhwqj8b8RMH3/i6Go2s4Z/sjJ70Lo5UdXAnH9YqTPd92lstW3XHU/cu9sBeb1z7eZ HLc+MX9u8rTWYwb4niAryDi1pYo75M8dt6e3dhDEiBCBC1XmAZJBGnCHsqLOWf77MKcm 05xUUETSzwkcH63WY7SG4zvjEGr5qrgXtY01xmj8oPUvyEY0h9qnPnYAnEWisWYWAKP4 iWo+xP0k8EsPMqYaJbhd1zPHeWaufUpyUFOI9umH5g/EijDK5Ji8YRppetQts/dbkPE1 CI9A== X-Gm-Message-State: AOJu0YxM/DqQPnhV6tq7+H7WOougxLydziyfIA3hQevsE8DqrpCNPWBa +ntHQJbu0KXi5dPfHQaQbDghdhuzjU+b0Q9GfSw= X-Received: by 2002:a05:6a20:7f8d:b0:187:f2f7:2383 with SMTP id d13-20020a056a207f8d00b00187f2f72383mr8957676pzj.45.1700567740082; Tue, 21 Nov 2023 03:55:40 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 03:55:39 -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 3/9] KVM: selftests: Test fixed counters overflow interrupt handling Date: Tue, 21 Nov 2023 19:54:51 +0800 Message-Id: <20231121115457.76269-4-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 04:43:10 -0800 (PST) From: Jinrong Liang Add tests to verify that fixed counters overflow interrupt handling works as expected. Signed-off-by: Jinrong Liang --- .../selftests/kvm/x86_64/pmu_counters_test.c | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) 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 1b108e6718fc..efd8c61e1c16 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c @@ -551,9 +551,8 @@ static void test_pmi_init_x2apic(void) pmi_irq_called = false; } -static void guest_test_gp_counter_pmi(void) +static void guest_test_gp_counter_pmi(uint8_t guest_pmu_version) { - uint8_t guest_pmu_version = guest_get_pmu_version(); uint32_t base_msr = get_pmc_msr(); test_pmi_init_x2apic(); @@ -569,6 +568,33 @@ static void guest_test_gp_counter_pmi(void) guest_test_counters_pmi_workload(); GUEST_ASSERT(pmi_irq_called); +} + +static void guest_test_fixed_counter_pmi(uint8_t guest_pmu_version) +{ + if (guest_pmu_version < 2) + return; + + test_pmi_init_x2apic(); + + wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, 0); + wrmsr(MSR_CORE_PERF_FIXED_CTR0, + (1ULL << this_cpu_property(X86_PROPERTY_PMU_FIXED_COUNTERS_BIT_WIDTH)) - 2); + wrmsr(MSR_CORE_PERF_FIXED_CTR_CTRL, FIXED_PMC_CTRL(0, FIXED_PMC_ENABLE_PMI)); + + wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, FIXED_PMC_GLOBAL_CTRL_ENABLE(0)); + guest_test_counters_pmi_workload(); + + GUEST_ASSERT(pmi_irq_called); +} + +static void guest_test_counters_pmi(void) +{ + uint8_t guest_pmu_version = guest_get_pmu_version(); + + guest_test_gp_counter_pmi(guest_pmu_version); + guest_test_fixed_counter_pmi(guest_pmu_version); + GUEST_DONE(); } @@ -580,7 +606,7 @@ static void test_intel_ovf_pmi(uint8_t pmu_version, uint64_t perf_capabilities) if (!pmu_version) return; - vm = intel_pmu_vm_create(&vcpu, guest_test_gp_counter_pmi, pmu_version, + vm = intel_pmu_vm_create(&vcpu, guest_test_counters_pmi, pmu_version, perf_capabilities); vm_install_exception_handler(vm, PMI_VECTOR, pmi_irq_handler); -- 2.39.3