From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1761EC2BA15 for ; Tue, 18 Jun 2024 07:20:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=S+MZvD0c6jZAbOwtBsBdVea8BAt9Pk1x19oYnj2/Pfs=; b=Szx/NjOnpVdgr9Xpxf6utWJDyq tO2CTjegfQfXYJMSzjDMlZu6rftc96ltNUCnKQnSb0KZNxOEOdrrUZnWBQ8BiN+6SVt+EZDL8br5I ItyYpGBiBJPu8CzTtxRakoR/BSxipi+YWBtr4R+lR7/GFZZXzXJ2f6arLt0Rmdh6nceq97mFYym6+ 9C0Kh1I1R2X/wHBhv9uq5po+UFUk1sbOifHzO+bVnPN+o8cc88DnOMYgBrHS+1j2FSkZhxNsWGGMW lysv7W6kGKVM8CgnCWAtviaOQqUxOhy6775dnQVXNW2dQNGeYouQDCn5xp7qJ2besvgAt8VaAwbhV kMqBiOCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJT8x-0000000DwBP-3TWG; Tue, 18 Jun 2024 07:20:39 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJT8v-0000000DwAZ-0TPD for linux-arm-kernel@lists.infradead.org; Tue, 18 Jun 2024 07:20:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718695234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S+MZvD0c6jZAbOwtBsBdVea8BAt9Pk1x19oYnj2/Pfs=; b=S+J5XUH0rqu38cbNXIf8IwgBF1G3UvMlsQcV9wh36ioRaPeVdqyJ/DoQfTUXmco/jrgLyg AWBFwxlRBeZ0yNgrYKNDfdLaChkxBO0L8qJvh0VbmKATuuEMHdiVLs7y31vjDGyJF+pFNN cQGkPe0XuGi6owXW8rZrD6sRcAggcw0= Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-y4uKmBu6PS2hB5-laYpmkQ-1; Tue, 18 Jun 2024 03:20:33 -0400 X-MC-Unique: y4uKmBu6PS2hB5-laYpmkQ-1 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-254ba913a27so851948fac.3 for ; Tue, 18 Jun 2024 00:20:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718695232; x=1719300032; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S+MZvD0c6jZAbOwtBsBdVea8BAt9Pk1x19oYnj2/Pfs=; b=bnfCNDGb/iMIBemTJSEtINN2ltNbRTPSlGE2tNpisUxCeZBt+6K5oKNuLy30MLwHm6 FR3Opfyjf9KmeWSzUYdT4zBw+SVqGuCibtSaABw9rSaOjzAzkfFgoJq5j9ImdRrq8noj ym6lH1G/hrLgle/v4W5elZT0xV5BO9hEILeFOW9L5f4ezN5xkSGDjOcWqEk0QyXybnnF +7MFFV9cDA4uUfSuMNvZOyS2lpsjXLjxPTKg+9p4oav/r9vDG/2yBr4Wf+gGLPCOYHne f417oziXk87NrmxXtTQC8e2di3T7l14IFvAb0ntvULWJQfGrUKeNYAOH9EeLogT1suOl fmlg== X-Forwarded-Encrypted: i=1; AJvYcCUhN+t3PxV+m7PgT2zasDQ6DmDQXer5HlB0YnSIiNtXS0/IrPUr4yTBRZ+5Pib7oQKn75MtEzZVSGl+h+WhDuBH54w+mtIh9xLO0sa6XMmDtpwd898= X-Gm-Message-State: AOJu0Yw8svKzHwbJT5x4TG6LhI9g4eDxKH8rfRXGrOLzmYpThg7Cg6D9 /OmIywhqtrlFwpH6alG27v8TgE8zfBZ4GdYddvB0j6hSDpy2vPn94B+mZHJVyoeND248EPAc2rJ UYMdfY+azBFeNQThoh7BC0TimyBuW1cKaN0ir7hFAVhZI1DNLf3FK9s6sv4w0RDnFbsR3XZxh X-Received: by 2002:a05:6870:472c:b0:254:abd6:1a3d with SMTP id 586e51a60fabf-25842c4d336mr12855712fac.4.1718695232649; Tue, 18 Jun 2024 00:20:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOPqkcgbIKP9DQkszgI9BP4bpi27+YzHI5LkL7RDuPvbhH5VsAbpRdW0WQgV71WAmyOeyUHw== X-Received: by 2002:a05:6870:472c:b0:254:abd6:1a3d with SMTP id 586e51a60fabf-25842c4d336mr12855697fac.4.1718695232295; Tue, 18 Jun 2024 00:20:32 -0700 (PDT) Received: from [10.66.61.39] ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705cc91dd11sm8363871b3a.43.2024.06.18.00.20.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Jun 2024 00:20:31 -0700 (PDT) Message-ID: <7617ca12-6538-4638-a2ab-a90d06a3a7f0@redhat.com> Date: Tue, 18 Jun 2024 15:20:27 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 2/3] KVM: selftests: aarch64: Introduce pmu_event_filter_test To: Raghavendra Rao Ananta Cc: Oliver Upton , Marc Zyngier , kvmarm@lists.linux.dev, Paolo Bonzini , Shuah Khan , James Morse , Suzuki K Poulose , Zenghui Yu , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20240613082345.132336-1-shahuang@redhat.com> <20240613082345.132336-3-shahuang@redhat.com> From: Shaoqin Huang In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240618_002037_321695_9CF55AE6 X-CRM114-Status: GOOD ( 25.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Raghavendra, Thanks for helping review this series. On 6/18/24 08:01, Raghavendra Rao Ananta wrote: > Hi Shaoqin > > > On Thu, Jun 13, 2024 at 1:28 AM Shaoqin Huang wrote: > >> +static void prepare_expected_pmce(struct kvm_pmu_event_filter *filter) >> +{ >> + struct pmu_common_event_ids pmce_mask = { ~0, ~0 }; >> + bool first_filter = true; >> + int i; >> + >> + while (filter && filter->nevents != 0) { > Do you also want to add a check to ensure we aren't running over > FILTER_NR (I'd expect a compiler warning/error though)? The FILTER_NR is only used to assign the length of the filter array, if the defined filter array length is larger than the FILTER_NR, I believe there will be a compiling warning. > >> + if (first_filter) { >> + if (filter->action == KVM_PMU_EVENT_ALLOW) >> + memset(&pmce_mask, 0, sizeof(pmce_mask)); >> + first_filter = false; >> + } > nit: Probably we can make the 'first_filter' part a little cleaner by > checking this outside the loop. > > if (filter && filter->action == KVM_PMU_EVENT_ALLOW) > memset(&pmce_mask, 0, sizeof(pmce_mask)); > > while (filter && filter->nevents != 0) { > ... > } Thanks, this looks much better and I will change the code to it. > >> +static struct test_desc tests[] = { >> + { >> + .name = "without_filter", >> + .filter = { >> + { 0 } >> + }, >> + }, >> + { >> + .name = "member_allow_filter", >> + .filter = { >> + DEFINE_FILTER(ARMV8_PMUV3_PERFCTR_SW_INCR, 0), > In terms of readability, do you think it's better to use > KVM_PMU_EVENT_{ALLOW|DENY}, instead of 0 and 1? > > Or, if that's coming out to be too long, may be create another wrapper > over DEFINE_FILTER, and simply use that in the array: > > #define EVENT_ALLOW(event) DEFINE_FILTER(event, KVM_PMU_EVENT_ALLOW) > #define EVENT_DENY(event) DEFINE_FILTER(event, KVM_PMU_EVENT_DENY) > > .filter = { > EVENT_ALLOW(ARMV8_PMUV3_PERFCTR_SW_INCR), > Pretty good idea. I will take your code which looks much clean. >> + DEFINE_FILTER(ARMV8_PMUV3_PERFCTR_INST_RETIRED, 0), >> + DEFINE_FILTER(ARMV8_PMUV3_PERFCTR_BR_RETIRED, 0), >> + { 0 }, >> + }, >> + }, > >> + { >> + .name = "cancel_filter", >> + .filter = { >> + DEFINE_FILTER(ARMV8_PMUV3_PERFCTR_CPU_CYCLES, 0), >> + DEFINE_FILTER(ARMV8_PMUV3_PERFCTR_CPU_CYCLES, 1), >> + }, > Since the initial filter map depends on the event being allowed or > denied, do you think another "cancel_filter" case to first deny and > then allow would also be better? Yes. That would be better, I will add another test which first deny and then allow it. > >> + }, >> + { >> + .name = "multiple_filter", >> + .filter = { >> + __DEFINE_FILTER(0x0, 0x10, 0), >> + __DEFINE_FILTER(0x6, 0x3, 1), >> + }, >> + }, >> + { 0 } >> +}; >> + >> +static void run_tests(void) >> +{ >> + struct test_desc *t; >> + >> + for (t = &tests[0]; t->name; t++) >> + run_test(t); >> +} >> + >> +int used_pmu_events[] = { > nit: static int used_pmu_events[] = { > Got it. Thanks, Shaoqin > Thank you. > Raghavendra > > >> + ARMV8_PMUV3_PERFCTR_BR_RETIRED, >> + ARMV8_PMUV3_PERFCTR_INST_RETIRED, >> + ARMV8_PMUV3_PERFCTR_CHAIN, >> +}; >> + >> +static bool kvm_pmu_support_events(void) >> +{ >> + struct pmu_common_event_ids used_pmce = { 0, 0 }; >> + >> + create_vpmu_vm(guest_get_pmceid); >> + >> + memset(&max_pmce, 0, sizeof(max_pmce)); >> + sync_global_to_guest(vpmu_vm.vm, max_pmce); >> + run_vcpu(vpmu_vm.vcpu); >> + sync_global_from_guest(vpmu_vm.vm, max_pmce); >> + destroy_vpmu_vm(); >> + >> + for (int i = 0; i < ARRAY_SIZE(used_pmu_events); i++) >> + set_pmce(&used_pmce, KVM_PMU_EVENT_ALLOW, used_pmu_events[i]); >> + >> + return ((max_pmce.pmceid0 & used_pmce.pmceid0) == used_pmce.pmceid0) && >> + ((max_pmce.pmceid1 & used_pmce.pmceid1) == used_pmce.pmceid1); >> +} >> + >> +int main(void) >> +{ >> + TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_PMU_V3)); >> + TEST_REQUIRE(kvm_pmu_support_events()); >> + >> + run_tests(); >> +} >> -- >> 2.40.1 >> >> > -- Shaoqin