Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp584265rdb; Thu, 1 Feb 2024 18:59:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGR0O+Stkiu94JfwU3n11MTqqQULN7uL2QOGjgcT0VJSzKhUS52alLJP+tK5/3XScXVANsM X-Received: by 2002:a05:6830:100d:b0:6de:abe6:774d with SMTP id a13-20020a056830100d00b006deabe6774dmr6753208otp.32.1706842741731; Thu, 01 Feb 2024 18:59:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706842741; cv=pass; d=google.com; s=arc-20160816; b=Fdd3nxMRSP8wS0/3L4atD/6l0OJEkozFi7CrZdoRqPwP7kn+K9suq6GZHxQDaSXLSH RlE/Df/0V2F7OoFfikSUZIuzvQn39sRO3lIM/Q7PCbEWpfLXSTMIfojb6dKMYVGBheuP k+/ok1D6Tfql52puxEqtPLZv+jwdiIbp3mz84TYiND6BLcjjCwZ6x0pFs4iOekEQc/kw Yp5BWVPb6cDZOgpyzSGdRqlN40nFKfwJ0G0icJr1Bf7VF/wv52PDqTWrHWdpzMTT7W6i Rl9JuB+Ta6rQEY4dyYTtsZPuS7e6VKxXmT04WRQ1pXvs1e3wREodenSFw2Fu71lzcjtT s9BQ== ARC-Message-Signature: i=2; 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=xP6rwZtFvriCtOxRaIA8iRInzWUrkHKutxw6otg96m0=; b=apUjMRxL8g7pRDRU5W6nactdr+GoWhP9NUVenLGyOyW6l7MKlgxtoVMPmQ+GkD95cV Yf97/gYSG1W5vni3PYFOJXwNDnNOqg5dEjDyLZK+qAwGuXu+Dq+U9UQt0WFjxqURZrXP e1AwfXPWloeHaO1n8bI5nep5cHOMT90e+Qri3Q9qKMUSkLULf8GU59jhCzS0CC6+LX/+ 3nygjKt/sU3fpqco+ipRQcmItMO7cqXiGWsQ+FXXIrXo/Y4QRtDnmHmUvyqdvLvpA37O 7uRoPE40+NKgTFAL7w5/F4jhjiQj6yvtuZLkSEas14hiR4jC3louKxTwXSAt+7q/5EEi Y3Cw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F8tVfKiI; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-49126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWwF/7r1LenH/kRTFiUgqTQWTGEJBckkIfJwEvr7xrF8/TqvMPfGmUivK0s4UWr/Ft4OWrjNf2GW/ogq7PYUn4TP1lEan6i3ICCcumWWA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p8-20020a631e48000000b005d798062b8csi791162pgm.499.2024.02.01.18.59.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:59:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F8tVfKiI; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-49126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49126-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5E7B328F4AF for ; Fri, 2 Feb 2024 02:59:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E1C5168DF; Fri, 2 Feb 2024 02:57:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="F8tVfKiI" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 223EE12E5E for ; Fri, 2 Feb 2024 02:57:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706842638; cv=none; b=XNaKZzCYwustvhyvmfycwB4gKTkyCQYmlwlAsRBSTTCkqQ7YaZKG3bUUGzc3JuzW+KQGCcEyC3KadBpuDbTI5pLFQnuxf/JOuVwZeT5bXi/Z0eckWebL+6oof50sI9Wxi0Y5eMAPfjGdzLfl6xP+g1u1xLHe+P+DLGEUp8tfywA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706842638; c=relaxed/simple; bh=zte8xL5zY+PwyfTErBl+176GxQqh6zCUN2wZuJg8x1k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IRXDhINDv1vq7kQbvQ+y1e1kAal2SHh8xeFyJGRTA0I/rU7zQKcp7WHmyT8u6pGSXG0WLRB1iXxVcULYdPQN5ZumTQxOZhmobg1xt/SoEOFTNrHUJViWAoSu+WJ/7Lfxze2vQtCyMj8xtQiakFVf1YKWdreyQQc9eqbqihqhGNk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=F8tVfKiI; arc=none smtp.client-ip=170.10.129.124 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=1706842636; 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=F8tVfKiIPQpNs2b8oWIsjFgyma6sR3dItnUpXCnV65VyufhUTr1UAulj4brzQcMNYnK5qY cgHrs/8CZGlMoc5a5BbbG74cqqYiKWWNjQC0kPx0pM+gWO5VSVfOg8ySMPlX3SwrE1l7Vw xpWO38kie+5awmRR1iE/lH4pzY7aRJo= 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-253--tbSrAG7OjG93kxjDSKTrA-1; Thu, 01 Feb 2024 21:57:11 -0500 X-MC-Unique: -tbSrAG7OjG93kxjDSKTrA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 5C6BC3C0BE47; Fri, 2 Feb 2024 02:57:10 +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 48783C1ED76; Fri, 2 Feb 2024 02:57:10 +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 v4 5/5] KVM: selftests: aarch64: Add invalid filter test in pmu_event_filter_test Date: Thu, 1 Feb 2024 21:56:54 -0500 Message-Id: <20240202025659.5065-6-shahuang@redhat.com> In-Reply-To: <20240202025659.5065-1-shahuang@redhat.com> References: <20240202025659.5065-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.8 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