From patchwork Fri Jan 6 10:23:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 40071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp748993wrt; Fri, 6 Jan 2023 02:26:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXtT0flpjxS1w7UYFL4okV4MF2AMYZwtd7S/+2ir8CxW0Xrl6GJmYCheSsfjw70i3wCjRFll X-Received: by 2002:a17:907:6d0b:b0:83f:1f64:c1e with SMTP id sa11-20020a1709076d0b00b0083f1f640c1emr53099026ejc.47.1673000792621; Fri, 06 Jan 2023 02:26:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673000792; cv=none; d=google.com; s=arc-20160816; b=fdSdfZoz3aJi2yaKn40Ie2j6TT41tirc2+gRWLL7qxl/cGb8fhzaEfITUtHK4Y89kR m7MbiXzVfMSAtlyK/gj+IltgRizqGZkXdVt4HxAn2hanjufkdeDizA90T5+huVk5PHvc od+J116ZS32kzT5inXxwyKk1Dp3eh2EsIb47PS6CT24EgM3N/E5coDWGWrvVYq5kKOke +nXXGh3lgeszMwH0PbGApR42OxDWx2BaG98ys4c7yaXujva75eOIsiuFcg4PhyBxP7tN nQaprt50UWgDLS7gbScsYfIK1GMmEzhB/OZq8m5ZdUE30JaSc17CQeXjsnoDNngemzfm 9R4g== 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=Wf1YklaqcAiXjW3N2/GPx9e6Ol6MPpmodCEeSsCG99s=; b=qGHiUu/gs0oAWQ12AJGdTuMagFUMXaOJYBPNVm05Kq4G1Ejza6Bxv3R2jzfd/n2zdZ ZBkEJLy3PVn9O1ZAAIQN5gS0Zmm9lRU+DWkJJfZL2NbIEZTHQp3ARqoo0Ccl4jInB+qY 5Zjjg1GQngwPMqJJKWaGd/NQdT1vcaIRumaSq7kgaKSLqubY9/8Ef23C9pgVuTfYFY+b QbAGzCVBZcnSmEyJOEOvIv28xBTJBSVsqsMPNjSdL8tQuAqnlTYA93yTelvv+U8YC6Aq 0Z8luup9cii//b1h/tbbMuLI1dVJCTHEQE1jAKzhq1FcqDNn8OHkVjZWV955XtqfQyWj ZilQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E3SodfV8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h20-20020a170906111400b007c0ef00a05csi650305eja.922.2023.01.06.02.26.08; Fri, 06 Jan 2023 02:26:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E3SodfV8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233770AbjAFKZO (ORCPT + 99 others); Fri, 6 Jan 2023 05:25:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232538AbjAFKYg (ORCPT ); Fri, 6 Jan 2023 05:24:36 -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 4BA3A6ADA6 for ; Fri, 6 Jan 2023 02:23:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673000630; 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=Wf1YklaqcAiXjW3N2/GPx9e6Ol6MPpmodCEeSsCG99s=; b=E3SodfV8I7k0tZWKX1KDqHjGkxECoOrrrGtt92UrO+C+Vo/2yyA3wQQp0XJK5/0LQMGqlB vLhh/fg2ZB/d0DyC0i304TZzwSgoHAMiJczt/wAS/Jf5YB46ZiJEYUZPsalsZ5O/YHxEdJ 3vyOS7z1VWjl3q/zQVt5Y8wtRo6ZQLs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-398-GwZWDMXMPGeajLp47YMaZQ-1; Fri, 06 Jan 2023 05:23:47 -0500 X-MC-Unique: GwZWDMXMPGeajLp47YMaZQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 721378533DA; Fri, 6 Jan 2023 10:23:46 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.192.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80C49C15BAD; Fri, 6 Jan 2023 10:23:44 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Dmitry Torokhov Cc: Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires Subject: [PATCH HID for-next v1 3/9] selftests: hid: attach/detach 2 bpf programs, not just one Date: Fri, 6 Jan 2023 11:23:26 +0100 Message-Id: <20230106102332.1019632-4-benjamin.tissoires@redhat.com> In-Reply-To: <20230106102332.1019632-1-benjamin.tissoires@redhat.com> References: <20230106102332.1019632-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754268479209882204?= X-GMAIL-MSGID: =?utf-8?q?1754268479209882204?= Add a second BPF program to attach to the device, as the development of this feature showed that we also need to ensure we can detach multiple programs to a device (hid_bpf_link->index was actually not set initially, and this lead to any BPF program not being released except for the first one). Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 8 +++++++- tools/testing/selftests/hid/progs/hid.c | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c index 6615c26fb5dd..d215bb492eb4 100644 --- a/tools/testing/selftests/hid/hid_bpf.c +++ b/tools/testing/selftests/hid/hid_bpf.c @@ -616,6 +616,7 @@ TEST_F(hid_bpf, test_attach_detach) { const struct test_program progs[] = { { .name = "hid_first_event" }, + { .name = "hid_second_event" }, }; __u8 buf[10] = {0}; int err; @@ -634,7 +635,10 @@ TEST_F(hid_bpf, test_attach_detach) ASSERT_EQ(buf[0], 1); ASSERT_EQ(buf[2], 47); - /* pin the program and immediately unpin it */ + /* make sure both programs are run */ + ASSERT_EQ(buf[3], 52); + + /* pin the first program and immediately unpin it */ #define PIN_PATH "/sys/fs/bpf/hid_first_event" bpf_program__pin(self->skel->progs.hid_first_event, PIN_PATH); remove(PIN_PATH); @@ -660,6 +664,7 @@ TEST_F(hid_bpf, test_attach_detach) ASSERT_EQ(buf[0], 1); ASSERT_EQ(buf[1], 47); ASSERT_EQ(buf[2], 0); + ASSERT_EQ(buf[3], 0); /* re-attach our program */ @@ -677,6 +682,7 @@ TEST_F(hid_bpf, test_attach_detach) ASSERT_EQ(err, 6) TH_LOG("read_hidraw"); ASSERT_EQ(buf[0], 1); ASSERT_EQ(buf[2], 47); + ASSERT_EQ(buf[3], 52); } /* diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/selftests/hid/progs/hid.c index 6a86af0aa545..88c593f753b5 100644 --- a/tools/testing/selftests/hid/progs/hid.c +++ b/tools/testing/selftests/hid/progs/hid.c @@ -32,6 +32,19 @@ int BPF_PROG(hid_first_event, struct hid_bpf_ctx *hid_ctx) return hid_ctx->size; } +SEC("?fmod_ret/hid_bpf_device_event") +int BPF_PROG(hid_second_event, struct hid_bpf_ctx *hid_ctx) +{ + __u8 *rw_data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 4 /* size */); + + if (!rw_data) + return 0; /* EPERM check */ + + rw_data[3] = rw_data[2] + 5; + + return hid_ctx->size; +} + SEC("?fmod_ret/hid_bpf_device_event") int BPF_PROG(hid_change_report_id, struct hid_bpf_ctx *hid_ctx) {