From patchwork Fri Jan 13 09:09:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 43102 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp167276wrt; Fri, 13 Jan 2023 01:16:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXsSEszlxJvZAKJWgJZ6rbW4QIqyDYVNURiQKHvFWEpz7DFKIe7xzVjZaGXivmd97QSurE0u X-Received: by 2002:a05:6402:414:b0:495:77a9:f108 with SMTP id q20-20020a056402041400b0049577a9f108mr29165580edv.39.1673601412193; Fri, 13 Jan 2023 01:16:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673601412; cv=none; d=google.com; s=arc-20160816; b=ZMZ4EHjdMAumKc51bCSavlLc7qcJ20MZ94raTojZVeWDOQDUKg+wecZU0AM1VDMPq3 5FbY/yYAf2+UNSbu8cO8dCi45QvEiLsUmc2jhyjUK/x5EoV2ZjZsJy3SMIsogg1CYLZw t4eB69i5ThxCCzI+lLc3jjN5u2pFSiLNXu+Tg2YNxzqJHyupNHJUSIQ+aIMaIjwj/V/g 7ugS3KXftgZ/8s3jZ8WPFTMSRrJCL/mQApp6PRlPUz4oHCalCd39vF1hsejsuVs2n3Ua xrUIkf2Ie/aftz7cRERU6ua0i2OXWYml2CHP7veUZV9Gdavtnk3X8hEoJ1NBRZBYDdiP Tr7A== 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=MReTfoZEtCBJ7/7PQF8RRjqn13uVX9nIzOsfgV2wfAI=; b=HtZV8TDde/+v9mIIRc4LPzQB0uS79H2DozVPcLJ3lKMOquCioseL8pveQxKyvoYoGv dNujEcwUfV0B98RdwRwYrU8+DY4NPtakM8CyMvsBge+D/1ukU8uld8sT2x1E9b72ejgJ VMT3NcUT/0/suVNhye4ntNj+Og/vvVOHG17Tlb5TSGGxk7l94M2xbgm1zzCyEowlvjuq xzWsTi448McsZN8TxJfXAA77bOtEF7zHLrj7Z3KFxmQ7Qf0Da7gV/+keBdXCHO/ysg3k +Aiy8s2viZstD0T5IOU5bM4n7fQxkAF9v2WQx9tpTZC9hbmLs2nPN+oDjm749Mn1Xu0d XOCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rh8DIK5p; 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 h42-20020a0564020eaa00b00499c322d3b9si10571891eda.377.2023.01.13.01.16.28; Fri, 13 Jan 2023 01:16:52 -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=Rh8DIK5p; 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 S240987AbjAMJMs (ORCPT + 99 others); Fri, 13 Jan 2023 04:12:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240995AbjAMJMJ (ORCPT ); Fri, 13 Jan 2023 04:12:09 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2B93B1D4 for ; Fri, 13 Jan 2023 01:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673600994; 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=MReTfoZEtCBJ7/7PQF8RRjqn13uVX9nIzOsfgV2wfAI=; b=Rh8DIK5pzJeNkL0339/NsSECmyxxLAYNJjGLSSD+jkSQsj0ZONPpJ6XiqlQqtOh5N5SUUf /r5ev2cBSIAZZJuBw8Dr9ok8BOWR4c+fkqUB/pJIEYNMO1rMPUVxjKNtPXd0ckX4Z4jlnN hWrQi5YQY1kiD8FoM/BySgbbhSeDelE= 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-641-d_eDA-nsMrqEu5o1F0dG5A-1; Fri, 13 Jan 2023 04:09:52 -0500 X-MC-Unique: d_eDA-nsMrqEu5o1F0dG5A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28E18802C1C; Fri, 13 Jan 2023 09:09:52 +0000 (UTC) Received: from plouf.redhat.com (ovpn-193-50.brq.redhat.com [10.40.193.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECEA11121315; Fri, 13 Jan 2023 09:09:49 +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 v2 5/9] selftests: hid: prepare tests for HID_BPF API change Date: Fri, 13 Jan 2023 10:09:31 +0100 Message-Id: <20230113090935.1763477-6-benjamin.tissoires@redhat.com> In-Reply-To: <20230113090935.1763477-1-benjamin.tissoires@redhat.com> References: <20230113090935.1763477-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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?1754898274794488087?= X-GMAIL-MSGID: =?utf-8?q?1754898274794488087?= We plan on changing the return value of hid_bpf_attach_prog(). Instead of returning an error code, it will return an fd to a bpf_link. This bpf_link is responsible for the binding between the bpf program and the hid device. Add a fallback mechanism to not break bisections by pinning the program when we run this test against the non changed kernel. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- tools/testing/selftests/hid/hid_bpf.c | 29 +++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c index 3b204a15e44b..9a262fe99b32 100644 --- a/tools/testing/selftests/hid/hid_bpf.c +++ b/tools/testing/selftests/hid/hid_bpf.c @@ -444,13 +444,21 @@ FIXTURE(hid_bpf) { int hid_id; pthread_t tid; struct hid *skel; + int hid_links[3]; /* max number of programs loaded in a single test */ }; static void detach_bpf(FIXTURE_DATA(hid_bpf) * self) { + int i; + if (self->hidraw_fd) close(self->hidraw_fd); self->hidraw_fd = 0; + for (i = 0; i < ARRAY_SIZE(self->hid_links); i++) { + if (self->hid_links[i]) + close(self->hid_links[i]); + } + hid__destroy(self->skel); self->skel = NULL; } @@ -512,6 +520,9 @@ static void load_programs(const struct test_program programs[], .ctx_size_in = sizeof(args), ); + ASSERT_LE(progs_count, ARRAY_SIZE(self->hid_links)) + TH_LOG("too many programs are to be loaded"); + /* open the bpf file */ self->skel = hid__open(); ASSERT_OK_PTR(self->skel) TEARDOWN_LOG("Error while calling hid__open"); @@ -543,7 +554,10 @@ static void load_programs(const struct test_program programs[], args.hid = self->hid_id; args.insert_head = programs[i].insert_head; err = bpf_prog_test_run_opts(attach_fd, &tattr); - ASSERT_OK(args.retval) TH_LOG("attach_hid(%s): %d", programs[i].name, args.retval); + ASSERT_GE(args.retval, 0) + TH_LOG("attach_hid(%s): %d", programs[i].name, args.retval); + + self->hid_links[i] = args.retval; } self->hidraw_fd = open_hidraw(self->dev_id); @@ -619,10 +633,17 @@ TEST_F(hid_bpf, test_attach_detach) { .name = "hid_second_event" }, }; __u8 buf[10] = {0}; - int err; + int err, link; LOAD_PROGRAMS(progs); + link = self->hid_links[0]; + /* we might not be using the new code path where hid_bpf_attach_prog() + * returns a link. + */ + if (!link) + link = bpf_program__fd(self->skel->progs.hid_first_event); + /* inject one event */ buf[0] = 1; buf[1] = 42; @@ -640,8 +661,8 @@ TEST_F(hid_bpf, test_attach_detach) /* pin the first program and immediately unpin it */ #define PIN_PATH "/sys/fs/bpf/hid_first_event" - err = bpf_program__pin(self->skel->progs.hid_first_event, PIN_PATH); - ASSERT_OK(err) TH_LOG("error while calling bpf_program__pin"); + err = bpf_obj_pin(link, PIN_PATH); + ASSERT_OK(err) TH_LOG("error while calling bpf_obj_pin"); remove(PIN_PATH); #undef PIN_PATH usleep(100000);