From patchwork Tue Dec 6 14:59:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 30363 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2875712wrr; Tue, 6 Dec 2022 07:09:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf4URKEjxxnswjAUeJ+Pg4lVuMKkP7NWjL6UuhQujvuPUOJco8Mky644CQipLP49rs7Yi3Zj X-Received: by 2002:a17:906:1182:b0:78d:99f2:a94e with SMTP id n2-20020a170906118200b0078d99f2a94emr71045889eja.232.1670339362278; Tue, 06 Dec 2022 07:09:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670339362; cv=none; d=google.com; s=arc-20160816; b=FA6abUsFQ3QBqUh2jZ6y28jfQcqYKLvrz2JQSPgTgGzzEAD8hgYHG9CPgduKIQHiAA NLPXfda2/XEZpMBJ+NZCLmavfGBx+JVJzVexQQ6oD4f9tA/rr84gawMxdBTbzOkh0ctN gOsw7Y8wF1D7UPeZHU9JikStgVfPdtyWZMb2auAElSAKhqt6FdTY6bfA/DHtah3klTv5 G6vK3MYmzJ0ySI1GARwkXA60qKdo4wEhDunboVxl+hux10dQaoIsuzLh10bF7IUBtqA+ DpUdeeIgzd/ITFWhKeySdMrovzVYyjLby9wNfLIFdWOm4CY/qU0RS3MKvR17IM6+uhHF x+3w== 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=HSdZJQSYji1CS/LRhNVKICa1dzFhmYVtK87Hjv0Ja0w=; b=i91cBLMwmRCmKWpo3HFhfkx8rw8j5GkKW5hZGw3r/5FInyXTz2uRaPJbxF5JgXCI5i gs6q2bXvr7cyz38KKkRviTy80E+Y1ZjzbyBw6hSDnbY+mjoPKzpi2lQYSt5obaibDmYa H44KF37sP8G/5JOhl53PFs7TU5wzYSGDN6ln/b4D6k0gsfeT+hBFBw1wwZaHqL4qPS9g nJO1uy3gKAR75/f4Y30TuseJIHRDrA/MaIGTddyqfZfDXI4rijXJ+Ew4dSKCr8YL4wNv ZOcwU+s9y0952JIoGoiMZDjnsGRSPUOUAqaCjzTokzfCo/VUZILLQHxxq1sLinl4wBuY WZrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZJfqpcp2; 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 r5-20020aa7c145000000b00468468cd389si1904742edp.205.2022.12.06.07.08.48; Tue, 06 Dec 2022 07:09:22 -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=ZJfqpcp2; 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 S234414AbiLFPHG (ORCPT + 99 others); Tue, 6 Dec 2022 10:07:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235129AbiLFPG2 (ORCPT ); Tue, 6 Dec 2022 10:06:28 -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 00CF036C43 for ; Tue, 6 Dec 2022 06:59:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670338790; 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=HSdZJQSYji1CS/LRhNVKICa1dzFhmYVtK87Hjv0Ja0w=; b=ZJfqpcp2rGMrKhXDxq0eBXp8o9NFn1s1/OT16k7giV9h19Vobp5Qzc/nVPVDpKZDIZrcpu +FXDgpwDJme+sfEvsz4r2MggswGHhcS9jVF1lMG/t9JCcQopa5ZCGvzj1w/4NhKM4mASrz j/L62Vluq7R0S+iIND6RkOp0KMFoik8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-617-R7RqIA-_P6q66p73UY98ng-1; Tue, 06 Dec 2022 09:59:45 -0500 X-MC-Unique: R7RqIA-_P6q66p73UY98ng-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 74B2C3C0F42A; Tue, 6 Dec 2022 14:59:44 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.193.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id C77AB4A9254; Tue, 6 Dec 2022 14:59:42 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Florent Revest , Jon Hunter , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH HID for-next v3 1/5] bpf: do not rely on ALLOW_ERROR_INJECTION for fmod_ret Date: Tue, 6 Dec 2022 15:59:32 +0100 Message-Id: <20221206145936.922196-2-benjamin.tissoires@redhat.com> In-Reply-To: <20221206145936.922196-1-benjamin.tissoires@redhat.com> References: <20221206145936.922196-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.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=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?1751477766824609843?= X-GMAIL-MSGID: =?utf-8?q?1751477766824609843?= The current way of expressing that a non-bpf kernel component is willing to accept that bpf programs can be attached to it and that they can change the return value is to abuse ALLOW_ERROR_INJECTION. This is debated in the link below, and the result is that it is not a reasonable thing to do. Reuse the kfunc declaration structure to also tag the kernel functions we want to be fmodret. This way we can control from any subsystem which functions are being modified by bpf without touching the verifier. Link: https://lore.kernel.org/all/20221121104403.1545f9b5@gandalf.local.home/ Suggested-by: Alexei Starovoitov Signed-off-by: Benjamin Tissoires Acked-by: Alexei Starovoitov --- changes in v3: - renamed btf_kern_func_is_modify_return() into btf_kfunc_is_modify_return() - removed copy/paste in register_btf_fmodret_id_set() changes in v2: - compared to https://lore.kernel.org/all/c9912b24-f611-29b8-28e1-5e8be0d5ad41@redhat.com/ - make use of register_btf_kfunc_id_set() so we don't have to include hid-bpf.h in bpf core. --- include/linux/btf.h | 2 ++ kernel/bpf/btf.c | 30 +++++++++++++++++++++++++----- kernel/bpf/verifier.c | 17 +++++++++++++++-- net/bpf/test_run.c | 14 +++++++++++--- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/include/linux/btf.h b/include/linux/btf.h index f9aababc5d78..6a0808e7845c 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -412,8 +412,10 @@ struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog); u32 *btf_kfunc_id_set_contains(const struct btf *btf, enum bpf_prog_type prog_type, u32 kfunc_btf_id); +u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id); int register_btf_kfunc_id_set(enum bpf_prog_type prog_type, const struct btf_kfunc_id_set *s); +int register_btf_fmodret_id_set(const struct btf_kfunc_id_set *kset); s32 btf_find_dtor_kfunc(struct btf *btf, u32 btf_id); int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_cnt, struct module *owner); diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 35c07afac924..c1df506293e4 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -204,6 +204,7 @@ enum btf_kfunc_hook { BTF_KFUNC_HOOK_STRUCT_OPS, BTF_KFUNC_HOOK_TRACING, BTF_KFUNC_HOOK_SYSCALL, + BTF_KFUNC_HOOK_FMODRET, BTF_KFUNC_HOOK_MAX, }; @@ -7448,11 +7449,14 @@ u32 *btf_kfunc_id_set_contains(const struct btf *btf, return __btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id); } -/* This function must be invoked only from initcalls/module init functions */ -int register_btf_kfunc_id_set(enum bpf_prog_type prog_type, - const struct btf_kfunc_id_set *kset) +u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id) +{ + return __btf_kfunc_id_set_contains(btf, BTF_KFUNC_HOOK_FMODRET, kfunc_btf_id); +} + +static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook, + const struct btf_kfunc_id_set *kset) { - enum btf_kfunc_hook hook; struct btf *btf; int ret; @@ -7471,13 +7475,29 @@ int register_btf_kfunc_id_set(enum bpf_prog_type prog_type, if (IS_ERR(btf)) return PTR_ERR(btf); - hook = bpf_prog_type_to_kfunc_hook(prog_type); ret = btf_populate_kfunc_set(btf, hook, kset->set); btf_put(btf); return ret; } + +/* This function must be invoked only from initcalls/module init functions */ +int register_btf_kfunc_id_set(enum bpf_prog_type prog_type, + const struct btf_kfunc_id_set *kset) +{ + enum btf_kfunc_hook hook; + + hook = bpf_prog_type_to_kfunc_hook(prog_type); + return __register_btf_kfunc_id_set(hook, kset); +} EXPORT_SYMBOL_GPL(register_btf_kfunc_id_set); +/* This function must be invoked only from initcalls/module init functions */ +int register_btf_fmodret_id_set(const struct btf_kfunc_id_set *kset) +{ + return __register_btf_kfunc_id_set(BTF_KFUNC_HOOK_FMODRET, kset); +} +EXPORT_SYMBOL_GPL(register_btf_fmodret_id_set); + s32 btf_find_dtor_kfunc(struct btf *btf, u32 btf_id) { struct btf_id_dtor_kfunc_tab *tab = btf->dtor_kfunc_tab; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 225666307bba..ec2e6ec7309e 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -15021,12 +15021,22 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, ret = -EINVAL; switch (prog->type) { case BPF_PROG_TYPE_TRACING: - /* fentry/fexit/fmod_ret progs can be sleepable only if they are + + /* fentry/fexit/fmod_ret progs can be sleepable if they are * attached to ALLOW_ERROR_INJECTION and are not in denylist. */ if (!check_non_sleepable_error_inject(btf_id) && within_error_injection_list(addr)) ret = 0; + /* fentry/fexit/fmod_ret progs can also be sleepable if they are + * in the fmodret id set with the KF_SLEEPABLE flag. + */ + else { + u32 *flags = btf_kfunc_is_modify_return(btf, btf_id); + + if (flags && (*flags & KF_SLEEPABLE)) + ret = 0; + } break; case BPF_PROG_TYPE_LSM: /* LSM progs check that they are attached to bpf_lsm_*() funcs. @@ -15047,7 +15057,10 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, bpf_log(log, "can't modify return codes of BPF programs\n"); return -EINVAL; } - ret = check_attach_modify_return(addr, tname); + ret = -EINVAL; + if (btf_kfunc_is_modify_return(btf, btf_id) || + !check_attach_modify_return(addr, tname)) + ret = 0; if (ret) { bpf_log(log, "%s() is not modifiable\n", tname); return ret; diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 13d578ce2a09..5079fb089b5f 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -489,7 +489,6 @@ int noinline bpf_fentry_test1(int a) return a + 1; } EXPORT_SYMBOL_GPL(bpf_fentry_test1); -ALLOW_ERROR_INJECTION(bpf_fentry_test1, ERRNO); int noinline bpf_fentry_test2(int a, u64 b) { @@ -733,7 +732,15 @@ noinline void bpf_kfunc_call_test_destructive(void) __diag_pop(); -ALLOW_ERROR_INJECTION(bpf_modify_return_test, ERRNO); +BTF_SET8_START(bpf_test_modify_return_ids) +BTF_ID_FLAGS(func, bpf_modify_return_test) +BTF_ID_FLAGS(func, bpf_fentry_test1, KF_SLEEPABLE) +BTF_SET8_END(bpf_test_modify_return_ids) + +static const struct btf_kfunc_id_set bpf_test_modify_return_set = { + .owner = THIS_MODULE, + .set = &bpf_test_modify_return_ids, +}; BTF_SET8_START(test_sk_check_kfunc_ids) BTF_ID_FLAGS(func, bpf_kfunc_call_test1) @@ -1668,7 +1675,8 @@ static int __init bpf_prog_test_run_init(void) }; int ret; - ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, &bpf_prog_test_kfunc_set); + ret = register_btf_fmodret_id_set(&bpf_test_modify_return_set); + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, &bpf_prog_test_kfunc_set); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &bpf_prog_test_kfunc_set); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &bpf_prog_test_kfunc_set); return ret ?: register_btf_id_dtor_kfuncs(bpf_prog_test_dtor_kfunc, From patchwork Tue Dec 6 14:59:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 30362 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2875599wrr; Tue, 6 Dec 2022 07:09:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf6fLHNwYsBk9Z3F3DFnFeQVPfg2/1tRlzJ8DK0oZqTxF5P5Vwcg4+EbCO0somM2Egni/2aG X-Received: by 2002:a05:6402:1a:b0:467:30ad:c4ca with SMTP id d26-20020a056402001a00b0046730adc4camr78107777edu.285.1670339352704; Tue, 06 Dec 2022 07:09:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670339352; cv=none; d=google.com; s=arc-20160816; b=YR0MQBMEMnwubNE2WE/siAd9Wss7F967dLLj+nfMidIOdEdJueEdP2Pb/lN8FwCNO2 DfZYfFJ3RwyIik53aE+8UVYQfTsg5XD/nSwARrv12QdccBvQrSALQmhHzIzWQkc6L9mK TBM+W/gLffTLD85mUTwRlDkoeiH92V0Q5lMyFsWF1jhMk18ZGPAk/YyroUd9ogsJIJGb Xh7XGo+eARixKzFBC2yNIw+ITRncOU6msVWqqof3y8hSjqRrdxZ9VGYvjttFdu+k+vPV cTKIYExORm8RbG1b6JqTt98btZmI9zHRy1xrFt4XdiOL2s+WqNrUT89hkpePoln1Bc3L Ytsg== 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=7HAe1+QIbLkOhg0A9ITflkE14lK9YXc6vwi8hBrPFjg=; b=fCkaWMUh3RwX4YujPMElRoXmWLsabAdiHk7JJ52fBxB0J6HBsyH04iJq3N1IH7TukD FSjAQ6+NFR/FPG325UnxvEbspKhfOpphbRXW/hdqWtZZFXBkQEH6g1GArhwa2uRG40Rp N0pTi1g7K16uFJTIszXh9R06/5BuWG6bQsmcSiZn3V7W+LiTqEcaJ8ODB6V7pAMpty4H msdGyI2+qR9FIjnRpJtEZh0LEW/w0igWvLjyUuFh7wBm+t/kh5/IV6PH5CpCbz/lT7cP wO+IjXtS47MJE7es5ENfzlkV4iOGo3tgnUWNKaK447WUEbo7IPGwc2AHbJLsa2VV/pS8 uGkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MQbpK189; 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 hq19-20020a1709073f1300b007c086018a40si14230373ejc.996.2022.12.06.07.08.38; Tue, 06 Dec 2022 07:09:12 -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=MQbpK189; 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 S234167AbiLFPGz (ORCPT + 99 others); Tue, 6 Dec 2022 10:06:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232037AbiLFPG0 (ORCPT ); Tue, 6 Dec 2022 10:06:26 -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 EF54532BBF for ; Tue, 6 Dec 2022 06:59:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670338788; 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=7HAe1+QIbLkOhg0A9ITflkE14lK9YXc6vwi8hBrPFjg=; b=MQbpK189sySSIQYQilGPdJAeHS9UtD0UfqBe+AaIBsVzmO8EgMJGhHA6EX2BsKuYz79H6l AO+d3dG/gUrLdxkCMVVWidGQTmEhzYul3agmr6WhD1BSU3w6+7nGMfH2wZqJypVta27u9f /MgGU8/BPlMNoOz+RCbTgKAHPpDk3bk= 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-518-TbdcHy17MgCxmm4yC13WkA-1; Tue, 06 Dec 2022 09:59:47 -0500 X-MC-Unique: TbdcHy17MgCxmm4yC13WkA-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 5882B101A528; Tue, 6 Dec 2022 14:59:46 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.193.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id B14F14A9254; Tue, 6 Dec 2022 14:59:44 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Florent Revest , Jon Hunter , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH HID for-next v3 2/5] HID: bpf: do not rely on ALLOW_ERROR_INJECTION Date: Tue, 6 Dec 2022 15:59:33 +0100 Message-Id: <20221206145936.922196-3-benjamin.tissoires@redhat.com> In-Reply-To: <20221206145936.922196-1-benjamin.tissoires@redhat.com> References: <20221206145936.922196-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.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?1751477757456347596?= X-GMAIL-MSGID: =?utf-8?q?1751477757456347596?= Now that we have aproper non debug API to declare which function is fmodret, we can rely on it. Link: https://lore.kernel.org/all/20221121104403.1545f9b5@gandalf.local.home/ Suggested-by: Alexei Starovoitov Signed-off-by: Benjamin Tissoires --- no changes in v3 changes in v2: - new, split from https://lore.kernel.org/all/c9912b24-f611-29b8-28e1-5e8be0d5ad41@redhat.com/ and use the new API --- drivers/hid/bpf/hid_bpf_dispatch.c | 20 ++++++++++++++++++-- drivers/hid/bpf/hid_bpf_jmp_table.c | 1 - 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c index c3920c7964dc..58e608ebf0fa 100644 --- a/drivers/hid/bpf/hid_bpf_dispatch.c +++ b/drivers/hid/bpf/hid_bpf_dispatch.c @@ -44,7 +44,6 @@ __weak noinline int hid_bpf_device_event(struct hid_bpf_ctx *ctx) { return 0; } -ALLOW_ERROR_INJECTION(hid_bpf_device_event, ERRNO); u8 * dispatch_hid_bpf_device_event(struct hid_device *hdev, enum hid_report_type type, u8 *data, @@ -105,7 +104,6 @@ __weak noinline int hid_bpf_rdesc_fixup(struct hid_bpf_ctx *ctx) { return 0; } -ALLOW_ERROR_INJECTION(hid_bpf_rdesc_fixup, ERRNO); u8 *call_hid_bpf_rdesc_fixup(struct hid_device *hdev, u8 *rdesc, unsigned int *size) { @@ -429,6 +427,18 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz, return ret; } +/* our HID-BPF entrypoints */ +BTF_SET8_START(hid_bpf_fmodret_ids) +BTF_ID_FLAGS(func, hid_bpf_device_event) +BTF_ID_FLAGS(func, hid_bpf_rdesc_fixup) +BTF_ID_FLAGS(func, __hid_bpf_tail_call) +BTF_SET8_END(hid_bpf_fmodret_ids) + +static const struct btf_kfunc_id_set hid_bpf_fmodret_set = { + .owner = THIS_MODULE, + .set = &hid_bpf_fmodret_ids, +}; + /* for syscall HID-BPF */ BTF_SET8_START(hid_bpf_syscall_kfunc_ids) BTF_ID_FLAGS(func, hid_bpf_attach_prog) @@ -495,6 +505,12 @@ static int __init hid_bpf_init(void) * will not be available, so nobody will be able to use the functionality. */ + err = register_btf_fmodret_id_set(&hid_bpf_fmodret_set); + if (err) { + pr_warn("error while registering fmodret entrypoints: %d", err); + return 0; + } + err = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &hid_bpf_kfunc_set); if (err) { pr_warn("error while setting HID BPF tracing kfuncs: %d", err); diff --git a/drivers/hid/bpf/hid_bpf_jmp_table.c b/drivers/hid/bpf/hid_bpf_jmp_table.c index 579a6c06906e..207972b028d9 100644 --- a/drivers/hid/bpf/hid_bpf_jmp_table.c +++ b/drivers/hid/bpf/hid_bpf_jmp_table.c @@ -103,7 +103,6 @@ __weak noinline int __hid_bpf_tail_call(struct hid_bpf_ctx *ctx) { return 0; } -ALLOW_ERROR_INJECTION(__hid_bpf_tail_call, ERRNO); int hid_bpf_prog_run(struct hid_device *hdev, enum hid_bpf_prog_type type, struct hid_bpf_ctx_kern *ctx_kern) From patchwork Tue Dec 6 14:59:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 30364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2876352wrr; Tue, 6 Dec 2022 07:10:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf4hJDWnU71rny1xxyxJkpo16TmsVLXiAHRG0MtmBKbXm0pNUHsIeOAMICkKGqzF4BkzyKDw X-Received: by 2002:aa7:c988:0:b0:46b:aedf:f330 with SMTP id c8-20020aa7c988000000b0046baedff330mr24979143edt.76.1670339410394; Tue, 06 Dec 2022 07:10:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670339410; cv=none; d=google.com; s=arc-20160816; b=fSjmWHcBd+qmvWsrGVnsM4I35VF5WPeAH4Vq3Y3AQ0c8e5/e6Mt5KaQNgeV56ACVbw 2wJLknXMZ/3OwNE+iMegjXdp3Lep7Ksehpnfvdrld095XfTXWNKn0xTfvZ2GH9U/uNSS +gZmGCFH85fDqA2VbHeikPHlRnR6WKE03Wv4bWJbeLuUMX7ZM29A77r+c4j2V3mc5qMN qZOfhc1sOK2DEELbB/R454aMnPcuKFB5iK+jD/g11G5qGv2dwB8pqKH8vbb0zvOswmaU URlZhQQKLdLSC/U/7svSaTHb7inrsoGTRqL54Suxf1CX/PdzF24R0JQp/g1pPy7ZR2aD jcVg== 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=oqtAUCO0SEZJgsVoKCePLBtYNI2eYf5kC10HYrGr3GM=; b=0oiFnihjH7WpwHwdxYYqYD7i9vProoQbpF84/FFp9Tl0N1cVGAvTIkXzybcEzq3qtE O/LdWBw/tb6ddYGZy02kTOQInDOu29fDLFRRbE/D5JR5eaDhSv2herVA3t3nNBjxpwSd 4dppHFp3GZm/rTZ0karPwWGxJRyS/PzvtMJl5+wEgQmVbc/XWKYlJQELpChEkocbMxPN VLrCBQ39TruJydocv87wk5COKkcL6fnq6aqjK4NEXjgTvhi4ty7NQwWLrnnY3gL1JXb9 B65lXJHYKITUHhi7/sS2nBUJo0jRquPCm4OdaIeLPN2iBUrllf+JyoSlgw0H/PjeKG05 ek4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bss7Qsjf; 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 he30-20020a1709073d9e00b007a1e33462c1si4527564ejc.268.2022.12.06.07.09.46; Tue, 06 Dec 2022 07:10:10 -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=bss7Qsjf; 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 S234765AbiLFPHs (ORCPT + 99 others); Tue, 6 Dec 2022 10:07:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234965AbiLFPGd (ORCPT ); Tue, 6 Dec 2022 10:06:33 -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 8257E2EF3F for ; Tue, 6 Dec 2022 06:59:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670338791; 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=oqtAUCO0SEZJgsVoKCePLBtYNI2eYf5kC10HYrGr3GM=; b=bss7Qsjfj5RkHNZpk468Su77VGlq7Qx+hH8nhAwzbIp6Hsiu/X3I7e3B6qckKw4Nh8XHfz QeF6XANJ7SDxC2n6WWUnffkD5LHf49kJwtr+wGGEIP727E7UI34jN7/6Wch7xlbDYQL5+N brcZsYnUfgoZes0H6wrFscbkm8GCsPw= 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-620-Q6O4LbPCNOWLfG69VKMC1g-1; Tue, 06 Dec 2022 09:59:48 -0500 X-MC-Unique: Q6O4LbPCNOWLfG69VKMC1g-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 340DB811E75; Tue, 6 Dec 2022 14:59:48 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.193.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9327F4A9254; Tue, 6 Dec 2022 14:59:46 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Florent Revest , Jon Hunter , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH HID for-next v3 3/5] HID: bpf: enforce HID_BPF dependencies Date: Tue, 6 Dec 2022 15:59:34 +0100 Message-Id: <20221206145936.922196-4-benjamin.tissoires@redhat.com> In-Reply-To: <20221206145936.922196-1-benjamin.tissoires@redhat.com> References: <20221206145936.922196-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.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=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?1751477817267629373?= X-GMAIL-MSGID: =?utf-8?q?1751477817267629373?= As mentioned in the link below, having JIT and BPF is not enough to have fentry/fexit/fmod_ret APIs. This resolves the error that happens on a system without tracing enabled when hid-bpf tries to load itself. Link: https://lore.kernel.org/r/CABRcYmKyRchQhabi1Vd9RcMQFCcb=EtWyEbFDFRTc-L-U8WhgA@mail.gmail.com Fixes: f5c27da4e3c8 ("HID: initial BPF implementation") Signed-off-by: Benjamin Tissoires Reviewed-by: Florent Revest --- no changes in v3 changes in v2: - dropped ALLOW_ERROR_INJECTION requirement --- drivers/hid/bpf/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hid/bpf/Kconfig b/drivers/hid/bpf/Kconfig index 298634fc3335..03f52145b83b 100644 --- a/drivers/hid/bpf/Kconfig +++ b/drivers/hid/bpf/Kconfig @@ -4,7 +4,8 @@ menu "HID-BPF support" config HID_BPF bool "HID-BPF support" default HID_SUPPORT - depends on BPF && BPF_SYSCALL + depends on BPF && BPF_SYSCALL && \ + DYNAMIC_FTRACE_WITH_DIRECT_CALLS help This option allows to support eBPF programs on the HID subsystem. eBPF programs can fix HID devices in a lighter way than a full From patchwork Tue Dec 6 14:59:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 30366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2876488wrr; Tue, 6 Dec 2022 07:10:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Ao8gcQj9nxNTAy3woTev1oquf8IbuJ3eCuEtRCYTfhc1QwLdV2YUwQ1n4rccVLY0xab9G X-Received: by 2002:a17:906:eb17:b0:7c0:fe68:1c5 with SMTP id mb23-20020a170906eb1700b007c0fe6801c5mr5640106ejb.410.1670339422210; Tue, 06 Dec 2022 07:10:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670339422; cv=none; d=google.com; s=arc-20160816; b=cInvs04HM6ISj9od8/tk+YL79ICWYeHzjuBK+Dv3WNaeA17vCEXaDhXaRYgPdgo6dk sR6geKz+xIcsf7bnucTniPIgKdmT4fJ0PjTKQG0HSIdVh03G3GmaBKm0s8cdm/z4ElTw XN89uVA8gyh2DG3GQmzDCQ1bH5NfXSaBdPDPcZjJFY209QxmX5eRRtEhufxzplmSzFPy XODHQFVpzZUvdVvY+fLNem4Ba6edP8ltrkhVNY7rqw6ski/NaEq6j3oW4Uc2h7iHwb+A HAGwCATDb50x5r5BkAfdq+ZqILzJKqM1cI+mPBAqEBMachGajY0m0CXQQNAinNDrb4TG NWUQ== 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=Dw9LzDdkg+wvG7saGSy8g5Pbbu5VhCTac8ookPf3stw=; b=TP+MwwVOkF/gPBcEgOiZ7vh+aizqoWvzTL5kHPetNkZFFgvlDo0nah6DX0z0ogXC8/ IPg6blcsk4li0T3xTtAMo7o4jUX6W7/HmBTZ30rZODJRRabbcDmGNNw8Xs9Cz6F1nINb 3cKLZj8h+IBvYZEj7QjEi+Brg7tM+wLVRQg0Tm7u5vrlgSIE5BNp5h8kTufYJbx+TyKd sKviCVe3wqFFUMIpYOLwl1NEuOOsACjdKKPtW82MjREhdJdeN0ws1ljn4aUlNmVdmrM4 quILJi0XLw2Ba7upVa4GKraazL164iVzVFz/GS5oZYVxlZtbcOFznU4tXK2w6FEEVFUb pGRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S5WxW6Bz; 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 gn25-20020a1709070d1900b007c10d4cc297si1470776ejc.85.2022.12.06.07.09.29; Tue, 06 Dec 2022 07:10:22 -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=S5WxW6Bz; 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 S233826AbiLFPHe (ORCPT + 99 others); Tue, 6 Dec 2022 10:07:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235228AbiLFPGd (ORCPT ); Tue, 6 Dec 2022 10:06:33 -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 688072E9C8 for ; Tue, 6 Dec 2022 06:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670338793; 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=Dw9LzDdkg+wvG7saGSy8g5Pbbu5VhCTac8ookPf3stw=; b=S5WxW6BzOX8YwgrGZMyoPtneb4IOD9LeliuXg35kTq/h8ZD+yMO9dYaRdDMhXwgAyxVjvY 1EZiUrxCJMkYpKoG11LcG47K8OoP54GgrbopaUgROVp9WcJOwG7TpiOHk+ZLj0Ozc4YLae sJC0AZkPNXM/E/AZbwRLbIVzPrZz4DQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-uE6U-oznPByWDiyaxG4gog-1; Tue, 06 Dec 2022 09:59:50 -0500 X-MC-Unique: uE6U-oznPByWDiyaxG4gog-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 1433A1C0A581; Tue, 6 Dec 2022 14:59:50 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.193.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F43C4A9254; Tue, 6 Dec 2022 14:59:48 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Florent Revest , Jon Hunter , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH HID for-next v3 4/5] selftests: hid: ensures we have the proper requirements in config Date: Tue, 6 Dec 2022 15:59:35 +0100 Message-Id: <20221206145936.922196-5-benjamin.tissoires@redhat.com> In-Reply-To: <20221206145936.922196-1-benjamin.tissoires@redhat.com> References: <20221206145936.922196-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.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=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?1751477829962603270?= X-GMAIL-MSGID: =?utf-8?q?1751477829962603270?= DYNAMIC_FTRACE_WITH_DIRECT_CALLS is implicit on x86_64 but is still a WIP on aarm64. Ensure we get it selected to not have any surprises. Signed-off-by: Benjamin Tissoires --- no changes in v3 changes in v2: - dropped ALLOW_ERROR_INJECTION requirement --- tools/testing/selftests/hid/config | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/hid/config b/tools/testing/selftests/hid/config index d4130489c1b1..9c5a55abca6b 100644 --- a/tools/testing/selftests/hid/config +++ b/tools/testing/selftests/hid/config @@ -11,6 +11,7 @@ CONFIG_BPF_SYSCALL=y CONFIG_BPF=y CONFIG_CGROUP_BPF=y CONFIG_DEBUG_INFO_BTF=y +CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS=y CONFIG_FPROBE=y CONFIG_FTRACE_SYSCALLS=y CONFIG_FUNCTION_TRACER=y From patchwork Tue Dec 6 14:59:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 30367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2876543wrr; Tue, 6 Dec 2022 07:10:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf6YSGw94ekqzR37SpuyCb5czLf+ISylCjwUS/k3ImFicnWIPFN2U9zJrG1FV2d/E8O6Date X-Received: by 2002:a17:906:2d49:b0:7ae:16a9:e4d7 with SMTP id e9-20020a1709062d4900b007ae16a9e4d7mr72116386eji.574.1670339427211; Tue, 06 Dec 2022 07:10:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670339427; cv=none; d=google.com; s=arc-20160816; b=sxYi6gJzThw1H3b8dcrShQwkGbXl6fOFSx1Z5wjNBUtxlpD2obAHyn/YEyzCcGvGdA wwXPY0cv/yWKjmuQFb/z6jnopamX+i7fnW/survsH+LYvEly2ZBzY76Z3UmEs4Yr1aRF uX3suWx3w7dyhcfFTC9i/WVzgoxoK71xiedCnIh5aKWOjltWnCX9pZSDqVeZPnNWLVMO py1nMHVcQmJ/viigud1HggLAIJHD8zTSgwzbCH/2OjWadalR90lZgtHrY5oL+nXL+26y fnioH5JwBeDssla/VJT8hM//xjwQsrWTdMxhKMAiwIVKrQepVp/ByA/KIDQWYln4XXVl Yu4w== 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=j0Cs3s9/XrNdXYu1iTbXoXBPyJJ8fDscz+47ISINcok=; b=kZBd4ZL4KS5hnzK90iY3MxTIo5OwBhD9ybQ0Z1U0Yvx2gnCaZ7jsckZie2vFuYM2aT hF38jbJCA4wNdllAeD+imZH4Mq944p1tz4zqOH+9ziKND4bm+m7qYApXpg8so+4Bg8HS ybfvB4EMZy1MySVv1aOk8Dp/XBhBvRADRr+GMyHVHBzKMgD1b+mJZ41dzWs0XUyijRBl u1NYTJ/eXpZPtTr2+K1iqCSJCgiTxl0D0wiEaBXrWI9AIjL/L7sKlAY+q78dMK1VSNj0 yCigdFFuKdVKzdVVmBAcewk17KJkT6hhtg6ui2xWWtEaVC4wwgfAv+YYgvnnehtPRs4p u9NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GGJhlrh5; 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 l12-20020aa7c3cc000000b0046107f951f9si1914452edr.237.2022.12.06.07.09.47; Tue, 06 Dec 2022 07:10:27 -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=GGJhlrh5; 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 S234995AbiLFPHz (ORCPT + 99 others); Tue, 6 Dec 2022 10:07:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235257AbiLFPGh (ORCPT ); Tue, 6 Dec 2022 10:06:37 -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 69E362E9DC for ; Tue, 6 Dec 2022 06:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670338796; 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=j0Cs3s9/XrNdXYu1iTbXoXBPyJJ8fDscz+47ISINcok=; b=GGJhlrh5byor3DLfFJMNA8EDaVxu16EGP56caK5eV+68a4qdrVQXgcfew6Oe2n2segqHYX 7HeSW4nyLWmTJ1sHxnm0ZftgWs3F4Z59JFfFyUzUBjoGxl/Lx8DLEW5giNcHy9iivNmOEF HC7UCYG3vjCS+O8WxUUYeb1YVWBa80g= 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-119-LwnsOCfJMjy305Ga6-HEwg-1; Tue, 06 Dec 2022 09:59:52 -0500 X-MC-Unique: LwnsOCfJMjy305Ga6-HEwg-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 29AFA86C15F; Tue, 6 Dec 2022 14:59:52 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.193.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EF304A9254; Tue, 6 Dec 2022 14:59:50 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Florent Revest , Jon Hunter , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires , kernel test robot Subject: [PATCH HID for-next v3 5/5] kselftests: hid: fix missing headers_install step Date: Tue, 6 Dec 2022 15:59:36 +0100 Message-Id: <20221206145936.922196-6-benjamin.tissoires@redhat.com> In-Reply-To: <20221206145936.922196-1-benjamin.tissoires@redhat.com> References: <20221206145936.922196-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.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?1751477835062035850?= X-GMAIL-MSGID: =?utf-8?q?1751477835062035850?= The Makefile was assuming that headers_install was already done in the top source directory, and was searching for installed uapi headers there. Unfortunately this is not the case and we need to manually call that step. To do so, reorder the declaration of the variables, and reuses top_srcdir provided by lib.mk Reported-by: kernel test robot Link: https://lore.kernel.org/all/202212060216.a6X8Py5H-lkp@intel.com/#t Signed-off-by: Benjamin Tissoires --- new in v3 --- tools/testing/selftests/hid/Makefile | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile index 693f1cb6e47a..f6fc5cfff770 100644 --- a/tools/testing/selftests/hid/Makefile +++ b/tools/testing/selftests/hid/Makefile @@ -7,17 +7,9 @@ include ../../../scripts/Makefile.include CXX ?= $(CROSS_COMPILE)g++ -CURDIR := $(abspath .) -TOOLSDIR := $(abspath ../../..) -TOP_SRCDIR = $(CURDIR)/../../../.. -KHDR_INCLUDES := $(TOP_SRCDIR)/usr/include -LIBDIR := $(TOOLSDIR)/lib -BPFDIR := $(LIBDIR)/bpf -TOOLSINCDIR := $(TOOLSDIR)/include -BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool HOSTPKG_CONFIG := pkg-config -CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(KHDR_INCLUDES) +CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(KHDR_INCLUDES) -I$(OUTPUT) LDLIBS += -lelf -lz -lrt -lpthread # Silence some warnings when compiled with clang @@ -53,9 +45,15 @@ endef include ../lib.mk +TOOLSDIR := $(top_srcdir)/tools +LIBDIR := $(TOOLSDIR)/lib +BPFDIR := $(LIBDIR)/bpf +TOOLSINCDIR := $(TOOLSDIR)/include +BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool SCRATCH_DIR := $(OUTPUT)/tools BUILD_DIR := $(SCRATCH_DIR)/build INCLUDE_DIR := $(SCRATCH_DIR)/include +KHDR_INCLUDES := $(SCRATCH_DIR)/uapi/include BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a ifneq ($(CROSS_COMPILE),) HOST_BUILD_DIR := $(BUILD_DIR)/host @@ -122,7 +120,6 @@ $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \ prefix= DESTDIR=$(HOST_SCRATCH_DIR)/ install-bin $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ - $(KHDR_INCLUDES)/linux/bpf.h \ | $(BUILD_DIR)/libbpf $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \ EXTRA_CFLAGS='-g -O0' \ @@ -130,7 +127,6 @@ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ ifneq ($(BPFOBJ),$(HOST_BPFOBJ)) $(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ - $(KHDR_INCLUDES)/linux/bpf.h \ | $(HOST_BUILD_DIR)/libbpf $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) \ EXTRA_CFLAGS='-g -O0' ARCH= CROSS_COMPILE= \ @@ -147,6 +143,9 @@ else $(Q)cp "$(VMLINUX_H)" $@ endif +$(KHDR_INCLUDES)/linux/hid.h: $(top_srcdir)/include/uapi/linux/hid.h + $(MAKE) -C $(top_srcdir) INSTALL_HDR_PATH=$(SCRATCH_DIR)/uapi headers_install + $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ $(TOOLSDIR)/bpf/resolve_btfids/main.c \ $(TOOLSDIR)/lib/rbtree.c \ @@ -178,8 +177,7 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) BPF_CFLAGS = -g -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ - -I$(INCLUDE_DIR) -I$(CURDIR) -I$(KHDR_INCLUDES) \ - -I$(abspath $(OUTPUT)/../usr/include) + -I$(INCLUDE_DIR) CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ -Wno-compare-distinct-pointer-types @@ -225,7 +223,7 @@ $(BPF_SKELS): %.skel.h: %.bpf.o $(BPFTOOL) | $(OUTPUT) $(Q)$(BPFTOOL) gen object $(<:.o=.linked1.o) $< $(Q)$(BPFTOOL) gen skeleton $(<:.o=.linked1.o) name $(notdir $(<:.bpf.o=)) > $@ -$(OUTPUT)/%:%.c $(BPF_SKELS) +$(OUTPUT)/%:%.c $(BPF_SKELS) $(KHDR_INCLUDES)/linux/hid.h $(call msg,BINARY,,$@) $(Q)$(LINK.c) $^ $(LDLIBS) -o $@