Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2026043rwe; Fri, 2 Sep 2022 07:31:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR6pBkHPZxGcr5k7J3j91nw5u9o87W4eeJUD7eynOkDNVPDI1HUNU7cyCSV4z0OmhD0Vhjsk X-Received: by 2002:a17:907:3f1f:b0:73d:90ae:f800 with SMTP id hq31-20020a1709073f1f00b0073d90aef800mr27393173ejc.466.1662129088985; Fri, 02 Sep 2022 07:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662129088; cv=none; d=google.com; s=arc-20160816; b=cqWSfbINDrEUOLY0a70XuxFTGBNEE+l4zGHJqhFjAGeXUTZNbwiuaANLZju8SSDUra kkm6t/NUcFkvTk61mvtDy25NGmavG3Lme+UolPvqp/t6lhwC+DMEuCTlhoGkniaq6MYQ J4eaJZmXsBuivMZGlnvepu8LGb3jlLYEd+Bs4wzRvdv9qBrPPkfHdXQ2YB4TI5GAVMvA bpayaf/WulUHMolecLyPbi/xPeQe1DeJpkYa9mKaBhcyYNGIClqvMb4FszkhV/cDQxmE 6doDfjv2pWyc/szLupO2ghveeAommqDsOGAynGTZ7AMjxj6INZyxzXU2aP8GfkHUTz4b 2BqA== 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=pFPTkaV5QEOOCDZuDIgNNW4oe2wUZaGR5B39/sfYpGQ=; b=SPGKPXh9Q9YlHyJ6tSXRvGvFbnF753Nm5pUGQs64nwAAf2JqtO87obwmKFCikaInuR JnbXtht5crGt32wt+geJCF33WgY0RKVvvvYvA7f3wpoHKgpcQUuADgsaWb/FInIIEXIr wSxL0KPCdE8y6/lcY7yJB1dAVfK4LzWoZUlmog5d+/Q0OeGU/DubRU/N7hEoAGYkEW2f /BEvKKjSdPmosj8aDdBJEGO2b+P+OJXPmyhk74X9EC8aLsHOJOSSKxiKY5W/T7vKq4C6 oOPAKgRmZmpsnhnQWAmWyGEgCuqviViOOv/nP4nS7V4UtO7DU6YHpPZC+5TMsYOf8ga3 IjfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WPneFwXy; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y11-20020a50eb8b000000b0043d1c347df3si1718661edr.152.2022.09.02.07.31.02; Fri, 02 Sep 2022 07:31:28 -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=WPneFwXy; 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 S238108AbiIBN74 (ORCPT + 99 others); Fri, 2 Sep 2022 09:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237925AbiIBN60 (ORCPT ); Fri, 2 Sep 2022 09:58:26 -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 0CEC3167DF for ; Fri, 2 Sep 2022 06:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662125449; 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=pFPTkaV5QEOOCDZuDIgNNW4oe2wUZaGR5B39/sfYpGQ=; b=WPneFwXyYdOPgDromDqgOvs8pSS7azEt9c6VaY8T9jMScPlnGxafBTXiaiA4RX+7jf5F5O PrQstI+zxvZqKxaXzjnto1ZsGvaKu+vXZGwGBwY9VCIOz0oLQPMkHtHbDJ03oyQV9he6c3 hQNAdZXUt5+h2QeZEQ4OA9TaB3boH2A= 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-493-G33Z5gUoMvGFRP2AiihJGQ-1; Fri, 02 Sep 2022 09:30:46 -0400 X-MC-Unique: G33Z5gUoMvGFRP2AiihJGQ-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 1A4DA103942C; Fri, 2 Sep 2022 13:30:45 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.193.218]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02A79492CA7; Fri, 2 Sep 2022 13:30:40 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , Kumar Kartikeya Dwivedi , John Fastabend , KP Singh , Shuah Khan , Dave Marchevsky , Joe Stringer , Jonathan Corbet 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, linux-doc@vger.kernel.org, Benjamin Tissoires Subject: [PATCH bpf-next v10 15/23] selftests/bpf/hid: add test to change the report size Date: Fri, 2 Sep 2022 15:29:30 +0200 Message-Id: <20220902132938.2409206-16-benjamin.tissoires@redhat.com> In-Reply-To: <20220902132938.2409206-1-benjamin.tissoires@redhat.com> References: <20220902132938.2409206-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Use a different report with a bigger size and ensures we are doing things properly. Signed-off-by: Benjamin Tissoires --- 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/bpf/prog_tests/hid.c | 60 ++++++++++++++++++++ tools/testing/selftests/bpf/progs/hid.c | 15 ++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/hid.c b/tools/testing/selftests/bpf/prog_tests/hid.c index 719d220c8d86..47bc0a30c275 100644 --- a/tools/testing/selftests/bpf/prog_tests/hid.c +++ b/tools/testing/selftests/bpf/prog_tests/hid.c @@ -17,6 +17,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) */ @@ -635,6 +646,53 @@ static int test_attach_detach(int uhid_fd, int dev_id) return ret; } +/* + * 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 + */ +static int test_hid_change_report(int uhid_fd, int dev_id) +{ + struct test_params params; + int err, hidraw_fd = -1; + u8 buf[10] = {0}; + int ret = -1; + + err = prep_test(dev_id, "hid_change_report_id", ¶ms); + if (!ASSERT_EQ(err, 0, "prep_test(hid_change_report_id)")) + goto cleanup; + + hidraw_fd = params.hidraw_fd; + + /* inject one event */ + buf[0] = 1; + buf[1] = 42; + send_event(uhid_fd, buf, 6); + + /* read the data from hidraw */ + memset(buf, 0, sizeof(buf)); + err = read(hidraw_fd, buf, sizeof(buf)); + if (!ASSERT_EQ(err, 9, "read_hidraw")) + goto cleanup; + + if (!ASSERT_EQ(buf[0], 2, "hid_change_report_id")) + goto cleanup; + + if (!ASSERT_EQ(buf[1], 42, "hid_change_report_id")) + goto cleanup; + + if (!ASSERT_EQ(buf[2], 0, "leftovers_from_previous_test")) + goto cleanup; + + ret = 0; + +cleanup: + cleanup_test(¶ms); + + return ret; +} + void serial_test_hid_bpf(void) { int err, uhid_fd; @@ -660,6 +718,8 @@ void serial_test_hid_bpf(void) ASSERT_OK(err, "hid"); err = test_attach_detach(uhid_fd, dev_id); ASSERT_OK(err, "hid_attach_detach"); + err = test_hid_change_report(uhid_fd, dev_id); + ASSERT_OK(err, "hid_change_report"); destroy(uhid_fd); diff --git a/tools/testing/selftests/bpf/progs/hid.c b/tools/testing/selftests/bpf/progs/hid.c index fc0a4241643a..ee7529c47ad8 100644 --- a/tools/testing/selftests/bpf/progs/hid.c +++ b/tools/testing/selftests/bpf/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") -- 2.36.1