From patchwork Tue Jan 16 06:01:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoqin Huang X-Patchwork-Id: 188424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp74950dye; Mon, 15 Jan 2024 22:11:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNud7CBFXGmg/kh9iakz/eKAGyLr6it8j/VuwsaHi6XZRQt8EG4xCeKI/6EtJvbzeYKODu X-Received: by 2002:a17:906:3597:b0:a2a:769e:bfa2 with SMTP id o23-20020a170906359700b00a2a769ebfa2mr3031605ejb.100.1705385488725; Mon, 15 Jan 2024 22:11:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705385488; cv=none; d=google.com; s=arc-20160816; b=DTdMxYP675giGjwlqbTWrhLkZNopjfkBO+csK/BV7GwIFviZPhcB3Rs9IuhBOghQID I1ybCq5SxDCM0ylj5l+8w6t5bH1c+efZP19bYUyTxptSJ7PR1UkoSZ1J5ZJDU2BYPfET FQjhX/0XjPNix4DPHBQghfvmwNzx5xy0ZPFBXFm994uYFgr1rKgAo1SlSJNoDMEafK3C EypRVYDZI8JQ/pnjwvyyjTg9pXyl/qbYXY47dYRCWRIT5DMitLnptOcL730i3cYRZsWb yEhib93CQ5SFlAXAic3EUkuHyNGuX+E+4d+5jpdH79WEx3ckSHzYdsoXz/5/BgYG5xn5 l6Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JdhKz6AkD7EoSnhTdlrYl+SSLH69MnV7i+2uXd+vqdc=; fh=U3XTG3/wmm+g74EZBmJF/aM+/HTKNpU7QIMmvSNz7bI=; b=HNdsp9M79VBQinEnH36hvGoyig9eELbOLEvEQ7eNEO1du39YroC5bKS76IYWa227nH mPc5hQpPQ3JasMrYif9LsjSznvBwqcGy4UOpvD5PNNAiYo88zj7hW2eqXDikD6NQ6dKi hNy4yJWLazS24RdNk6vCFrdrOEmWT7o7TUCOhXrMv3Fgaz6b1aq2Mw617pSA4Sbf2LMx mlhAfZAi0O01CK5J0QwnQ5NiTpvyTQBcExXMo7ObppYV3Gk4UCzBxg5q7WzfIRFNJiv+ mvtXjQAyirquiwUbsgOtuOJv78j2xxLynzgKaAejAizCTOWDu7j0Nq0hqQ8IpLd9UeF2 Iu6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JHQUgDnN; spf=pass (google.com: domain of linux-kernel+bounces-27030-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27030-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s22-20020a170906285600b00a2d0b1beb8esi3009266ejc.65.2024.01.15.22.11.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 22:11:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27030-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JHQUgDnN; spf=pass (google.com: domain of linux-kernel+bounces-27030-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27030-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 205EF1F2572E for ; Tue, 16 Jan 2024 06:03:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 986D812E51; Tue, 16 Jan 2024 06:01:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JHQUgDnN" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E0D8125B2 for ; Tue, 16 Jan 2024 06:01:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705384902; 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=JdhKz6AkD7EoSnhTdlrYl+SSLH69MnV7i+2uXd+vqdc=; b=JHQUgDnNnbxwhoBwceXuarIajU4CV79F6AmZWrMgVlw55bE5GNa2kbo1kZNH/ZvhHE7yxZ 3u8CH2B+Dnar26s7w9oqsHucFqcm5FDFFsL/c0QJQYjHOymWgKF+SLwc11WHwNETRI5zoX hAuE9l1GLsueNAdiQmm27MpR+pu0Q44= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-42-RxYvaupvNKaKQFCfEbImgA-1; Tue, 16 Jan 2024 01:01:38 -0500 X-MC-Unique: RxYvaupvNKaKQFCfEbImgA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 7588C85A589; Tue, 16 Jan 2024 06:01:37 +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 6B99E2026D6F; Tue, 16 Jan 2024 06:01:37 +0000 (UTC) From: Shaoqin Huang To: Oliver Upton , Marc Zyngier , 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 v3 5/5] KVM: selftests: aarch64: Add invalid filter test in pmu_event_filter_test Date: Tue, 16 Jan 2024 01:01:23 -0500 Message-Id: <20240116060129.55473-6-shahuang@redhat.com> In-Reply-To: <20240116060129.55473-1-shahuang@redhat.com> References: <20240116060129.55473-1-shahuang@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788226294303815584 X-GMAIL-MSGID: 1788226294303815584 Add the invalid filter test includes sets the filter beyond the event space and sets the invalid action 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 d280382f362f..68e1f2003312 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. */ @@ -183,6 +184,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 largeer 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; @@ -216,4 +250,6 @@ int main(void) TEST_REQUIRE(host_pmu_supports_events()); for_each_test(); + + test_invalid_filter(); }