Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp263050rdb; Mon, 15 Jan 2024 22:03:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGsRIG3l0EvS2S+XXanKJGPYFXW4BG1ATfvkhCiE/fRGyqUy/dLr55uZij290CE/AoX4kV X-Received: by 2002:a05:6a00:2d15:b0:6d9:955a:d3bb with SMTP id fa21-20020a056a002d1500b006d9955ad3bbmr8097660pfb.10.1705385009309; Mon, 15 Jan 2024 22:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705385009; cv=none; d=google.com; s=arc-20160816; b=XGjD3iep5ucHH2J14rNZSB0qur7SA0UCKH7hmnOneWsNjKj35/dG7RGjdol5mW0s8S h7EyHDULicjrwv6rQXdaM4wIyyLz/8brAiyIPtwcnfB4M/nPbhmGXguJiRJBrKNbVwK3 6njNV2Qidgfot1AdXtJXtLfovbvhot0mVJInuV+Q3Y8xl+KOeZwx8woUhxffk33I2kN4 5c7/cwpeLqcNqrq9jgp20CdqlVef4cWjdRaHrauwh1SXtKoUushcPWYwsznIJ2FJEsdw cNTktOLcdWB28wZMqKSk/w13rxOARXRi5p0DtQa8mMk1dNgUYITcCJeqMRnF+w+SZ+2G Vr3A== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27030-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b190-20020a6334c7000000b005ce008218b6si10371609pga.841.2024.01.15.22.03.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 22:03:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27030-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27030-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6BC75B2280A for ; Tue, 16 Jan 2024 06:03:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB30E12B82; Tue, 16 Jan 2024 06:01:45 +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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 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(); } -- 2.40.1