Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4396351rdh; Tue, 28 Nov 2023 23:28:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxxyWSfULWmBj1G/t1EUemmxj65iOpRyuyghc80rlJl5mvu3FO4T84UCNNX5hZVCWMY3kV X-Received: by 2002:a05:6808:2222:b0:3b8:979b:b6c7 with SMTP id bd34-20020a056808222200b003b8979bb6c7mr1004810oib.3.1701242884475; Tue, 28 Nov 2023 23:28:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701242884; cv=none; d=google.com; s=arc-20160816; b=rQSnYG8xMLeePM3Mh7tO12CuuxZtN2n0dRgfSQSaaHd9ssQ++0GS1sFU+MDyiKyIC3 KSKetpk09lLFUDZtB4oUMXDasqIcdNgIJQimo9/SxAHlOfcugGkFHJ85QtYfebuJfEBC wD4O8yAZb7VcFnLKe+3z3MKvTkO98EWflAv4snLefRrvvMUA1IdkB40mbKxvf1gCsTwE BSaZj7cERqGee2dSDaUwukFnTHx2h+nI0kCE8lSJEKLZteFLOeb7webHBsjokeglac+I uftos9DRV5uXxfZL3hYRt/f2weyCIU33SQ1UbsVUaVDnA5baV2fSWgPlHPoUEGDjXdb1 MGIg== 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=kImp972QN3FgRVvMXHDG7RWMY5d+pXRZAAAzWuPuZ8w=; fh=iDxqS2ylYbPnsqv8HSvHCqUt+745msxjAtp8mswlLTk=; b=MTI5HNGR7/hCrahcrzXr7mkzaESFPL/krYk0pIs2EWwuh1ruOZ7WI6LCJd4YwWi9hG VsCstXcdyOocQY9cOLbmW9Y7SHgsCvaKnI/a9DeRJDyOoX5IoP4bjOSGDZFRdQDTkuzr 6aAXANli8H0dhdS9x9X3wPkOVZgu5AZq8j5mrGCTRIs7lAhpNda+3gqaHsX+b3AS9ICe SKcLhDi1p0wIHNAZmlHcsjWQXqSwcdc/0YHOfPFGP45JXj1VPxgOOLdiW2O0JDEFpUVk ++v40ppG/CuxaEZkgpPVE6yqlQtQbAPbgmMCfUHMwzMPADsHww0o0JhIpuu/aK5w0fvz 80YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jQbXN764; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id v64-20020a632f43000000b00557531eafb0si13434112pgv.559.2023.11.28.23.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 23:28:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jQbXN764; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B30CB8043ED3; Tue, 28 Nov 2023 23:28:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230293AbjK2H1k (ORCPT + 99 others); Wed, 29 Nov 2023 02:27:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbjK2H13 (ORCPT ); Wed, 29 Nov 2023 02:27:29 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 487BB19BB for ; Tue, 28 Nov 2023 23:27:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701242855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kImp972QN3FgRVvMXHDG7RWMY5d+pXRZAAAzWuPuZ8w=; b=jQbXN764KQHkk5IGOXF5SvJglyvIBVgPrll/5kUfdHJDwb0FL62HdaFT5cO1xxp2MqUc7o JFrkLtxW12F1LBkQDorThbJwL4I1DRQDGv7g0tsT5cgazGgLF/mxsP+cKAKDaXqJCjUXhm LVmW0lNZxxCGoRAprETiQZ+uncxFt7w= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-OI1xr56gNkmh64mcydxjVA-1; Wed, 29 Nov 2023 02:27:30 -0500 X-MC-Unique: OI1xr56gNkmh64mcydxjVA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CAF9B285F99B; Wed, 29 Nov 2023 07:27:29 +0000 (UTC) Received: from virt-mtcollins-01.lab.eng.rdu2.redhat.com (virt-mtcollins-01.lab.eng.rdu2.redhat.com [10.8.1.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDD561C060AE; Wed, 29 Nov 2023 07:27:29 +0000 (UTC) From: Shaoqin Huang To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev Cc: Eric Auger , Shaoqin Huang , James Morse , Suzuki K Poulose , Zenghui Yu , Paolo Bonzini , Shuah Khan , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] KVM: selftests: aarch64: Add invalid filter test in pmu_event_filter_test Date: Wed, 29 Nov 2023 02:27:07 -0500 Message-Id: <20231129072712.2667337-6-shahuang@redhat.com> In-Reply-To: <20231129072712.2667337-1-shahuang@redhat.com> References: <20231129072712.2667337-1-shahuang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 28 Nov 2023 23:28:00 -0800 (PST) Add the invalid filter test to double check if the KVM_ARM_VCPU_PMU_V3_FILTER will return the expected error. Signed-off-by: Shaoqin Huang --- .../kvm/aarch64/pmu_event_filter_test.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tools/testing/selftests/kvm/aarch64/pmu_event_filter_test.c b/tools/testing/selftests/kvm/aarch64/pmu_event_filter_test.c index 0e652fbdb37a..4c375417b194 100644 --- a/tools/testing/selftests/kvm/aarch64/pmu_event_filter_test.c +++ b/tools/testing/selftests/kvm/aarch64/pmu_event_filter_test.c @@ -7,6 +7,7 @@ * This test checks if the guest only see the limited pmu event that userspace * sets, if the guest can use those events which user allow, and if the guest * can't use those events which user deny. + * It also checks that setting invalid filter ranges return the expected error. * This test runs only when KVM_CAP_ARM_PMU_V3, KVM_ARM_VCPU_PMU_V3_FILTER * is supported on the host. */ @@ -197,6 +198,39 @@ static void for_each_test(void) run_test(t); } +static void set_invalid_filter(struct vpmu_vm *vm, void *arg) +{ + struct kvm_pmu_event_filter invalid; + struct kvm_device_attr attr = { + .group = KVM_ARM_VCPU_PMU_V3_CTRL, + .attr = KVM_ARM_VCPU_PMU_V3_FILTER, + .addr = (uint64_t)&invalid, + }; + int ret = 0; + + /* The max event number is (1 << 16), set a range large than it. */ + invalid = __DEFINE_FILTER(BIT(15), BIT(15)+1, 0); + ret = __vcpu_ioctl(vm->vcpu, KVM_SET_DEVICE_ATTR, &attr); + TEST_ASSERT(ret && errno == EINVAL, "Set Invalid filter range " + "ret = %d, errno = %d (expected ret = -1, errno = EINVAL)", + ret, errno); + + ret = 0; + + /* Set the Invalid action. */ + invalid = __DEFINE_FILTER(0, 1, 3); + ret = __vcpu_ioctl(vm->vcpu, KVM_SET_DEVICE_ATTR, &attr); + TEST_ASSERT(ret && errno == EINVAL, "Set Invalid filter action " + "ret = %d, errno = %d (expected ret = -1, errno = EINVAL)", + ret, errno); +} + +static void test_invalid_filter(void) +{ + vpmu_vm = __create_vpmu_vm(guest_code, set_invalid_filter, NULL); + destroy_vpmu_vm(vpmu_vm); +} + static bool kvm_supports_pmu_event_filter(void) { int r; @@ -228,4 +262,6 @@ int main(void) TEST_REQUIRE(host_pmu_supports_events()); for_each_test(); + + test_invalid_filter(); } -- 2.40.1