From patchwork Tue Oct 25 09:34:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 10659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp903937wru; Tue, 25 Oct 2022 02:40:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6lGnBak93spWOPv+/TOei05kXyL7HAjkm/LRtRjXTs4HUhmNhQJEg3sWe7ohJEddkyZDG7 X-Received: by 2002:a05:6402:1553:b0:461:539d:9b88 with SMTP id p19-20020a056402155300b00461539d9b88mr7174625edx.286.1666690822810; Tue, 25 Oct 2022 02:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666690822; cv=none; d=google.com; s=arc-20160816; b=kyUFkldDjnUODlDKNJGaq3zR8wr0U/5godSrahuwK49XGUSfAzvY+9rb5INHEknB+y 2dAjUMAmDbIcfsusWjdKu2ghX3M3egJN/leLiSSWyqA7LU5LicaP3G4knXi3zJrU9X6W gy+mG1YY30ca3hI+9wpNv9Ub52YKB8Xbn8EkBdA2nxKmbCHsyRB8ZFkaGQr+psBE4Wkj aEy7ylaT5jfp+IC29nP8ja00EtU+I2jikaoMYZdtlm/o8fo7RhvPBjRidhVeMH+lxEhz yajv0/k/1wg8RKj+secfLhap7C/x37uh99v+sGm1+caeXxv5YxBGwxfI144iIUS/Nb6K 1dDA== 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=0TpbgNcrLQg8txBsUUaYzs/Vlq7YdZrtaeFNot3mLLo=; b=bedDfL4SJOA4Hgc3LiraejeWG6XF38Loi2RulQDh50mREFsb8eU2Y/7OrB8ZZfpQkb WwL/kJcHyLd9OiDp6RGp7xfM3+ocR9vQJN/jKSy9t+E33l4c6cSWaWR9Gxussy/Cq4TW NR5KtdRWyv/DK0EEayHtA/NeN7YG9KzgszTM9IhJLYI6ga4DjC7BOR3MJSwsVpVgip6z PL5bf1yaz+MTqRp/QCkTkvX+LkijErA//xHoVL0A6Ayfrt/J/zYDivRdSg9ixkU8xYEj D4m6pVBDZKZzWItA81MD61j6r73hn4F5Q/bjfXlzoWf81xfY3YrC1F8cSiZq7VuR/3n2 CvNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jNzhUarY; 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 c3-20020a170906694300b0078a4aad3141si1961764ejs.211.2022.10.25.02.39.58; Tue, 25 Oct 2022 02:40:22 -0700 (PDT) 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=jNzhUarY; 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 S230410AbiJYJgR (ORCPT + 99 others); Tue, 25 Oct 2022 05:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231605AbiJYJfb (ORCPT ); Tue, 25 Oct 2022 05:35:31 -0400 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 89138F986B for ; Tue, 25 Oct 2022 02:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666690521; 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=0TpbgNcrLQg8txBsUUaYzs/Vlq7YdZrtaeFNot3mLLo=; b=jNzhUarYZOx8XjTz6PpymK59FKIfdUqOmjhG01tit5Kkf3xYijvodTcEWzH4bbZWfe5Ma9 G/SGrs+EWAYEMB2ZRc70Utrhd9gjC+ECdEfDs//aZAtEGZECIY1UvQONg9O9L+Kl3eA+Vd ut4Q5xQeL59wOOaKdBKDyJW+Jhp2s7Q= 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-377-bd5BeAJePe2jbnqRx0_ELQ-1; Tue, 25 Oct 2022 05:35:16 -0400 X-MC-Unique: bd5BeAJePe2jbnqRx0_ELQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB69C185A78F; Tue, 25 Oct 2022 09:35:15 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.195.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D9A4492CA2; Tue, 25 Oct 2022 09:35:14 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Jonathan Corbet , Shuah Khan Cc: Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Benjamin Tissoires Subject: [PATCH hid v11 06/14] selftests/hid: add test to change the report size Date: Tue, 25 Oct 2022 11:34:50 +0200 Message-Id: <20221025093458.457089-7-benjamin.tissoires@redhat.com> In-Reply-To: <20221025093458.457089-1-benjamin.tissoires@redhat.com> References: <20221025093458.457089-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.6 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=unavailable 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?1747651996241861769?= X-GMAIL-MSGID: =?utf-8?q?1747651996241861769?= Use a different report with a bigger size and ensures we are doing things properly. Signed-off-by: Benjamin Tissoires --- changes in v11: - use the new facility from selftests/hid no changes in v10 no changes in v9 no changes in v8 no changes in v7 no changes in v6 new in v5 --- tools/testing/selftests/hid/hid_bpf.c | 41 +++++++++++++++++++++++++ tools/testing/selftests/hid/progs/hid.c | 15 ++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c index 3012fb95e6fc..a6daaadccfb5 100644 --- a/tools/testing/selftests/hid/hid_bpf.c +++ b/tools/testing/selftests/hid/hid_bpf.c @@ -23,6 +23,17 @@ static unsigned char rdesc[] = { 0xa1, 0x01, /* COLLECTION (Application) */ 0x09, 0x01, /* Usage (Vendor Usage 0x01) */ 0xa1, 0x00, /* COLLECTION (Physical) */ + 0x85, 0x02, /* REPORT_ID (2) */ + 0x19, 0x01, /* USAGE_MINIMUM (1) */ + 0x29, 0x08, /* USAGE_MAXIMUM (3) */ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ + 0x25, 0xff, /* LOGICAL_MAXIMUM (255) */ + 0x95, 0x08, /* REPORT_COUNT (8) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ + 0xc0, /* END_COLLECTION */ + 0x09, 0x01, /* Usage (Vendor Usage 0x01) */ + 0xa1, 0x00, /* COLLECTION (Physical) */ 0x85, 0x01, /* REPORT_ID (1) */ 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */ 0x19, 0x01, /* USAGE_MINIMUM (1) */ @@ -646,6 +657,36 @@ TEST_F(hid_bpf, test_attach_detach) ASSERT_EQ(buf[2], 47); } +/* + * Attach hid_change_report_id to the given uhid device, + * retrieve and open the matching hidraw node, + * inject one event in the uhid device, + * check that the program sees it and can change the data + */ +TEST_F(hid_bpf, test_hid_change_report) +{ + const struct test_program progs[] = { + { .name = "hid_change_report_id" }, + }; + u8 buf[10] = {0}; + int err; + + LOAD_PROGRAMS(progs); + + /* inject one event */ + buf[0] = 1; + buf[1] = 42; + uhid_send_event(_metadata, self->uhid_fd, buf, 6); + + /* read the data from hidraw */ + memset(buf, 0, sizeof(buf)); + err = read(self->hidraw_fd, buf, sizeof(buf)); + ASSERT_EQ(err, 9) TH_LOG("read_hidraw"); + ASSERT_EQ(buf[0], 2); + ASSERT_EQ(buf[1], 42); + ASSERT_EQ(buf[2], 0) TH_LOG("leftovers_from_previous_test"); +} + static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args) { diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/selftests/hid/progs/hid.c index fc0a4241643a..ee7529c47ad8 100644 --- a/tools/testing/selftests/hid/progs/hid.c +++ b/tools/testing/selftests/hid/progs/hid.c @@ -32,7 +32,20 @@ int BPF_PROG(hid_first_event, struct hid_bpf_ctx *hid_ctx) rw_data[2] = rw_data[1] + 5; - return 0; + return hid_ctx->size; +} + +SEC("?fmod_ret/hid_bpf_device_event") +int BPF_PROG(hid_change_report_id, struct hid_bpf_ctx *hid_ctx) +{ + __u8 *rw_data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 3 /* size */); + + if (!rw_data) + return 0; /* EPERM check */ + + rw_data[0] = 2; + + return 9; } SEC("syscall")