Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1210137lqp; Fri, 22 Mar 2024 08:25:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtHJuPEfhaUgfLb+D4xNCrzv+xMCfbQywKqX1AHB+xqzIoyLdQOSH+zS28c497VEtFpWGJ9nEFBgWdVOM9n7RN7WbX9WF0WatHUY+ZbA== X-Google-Smtp-Source: AGHT+IGzKetJmOMmgcnJm2EAGgAVx8/NjISCKJHqH8QsTqT+h7bYsoWR+yotABQPLPxWJO6X3ujb X-Received: by 2002:a05:6808:2395:b0:3c3:be67:922d with SMTP id bp21-20020a056808239500b003c3be67922dmr95010oib.3.1711121119439; Fri, 22 Mar 2024 08:25:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711121119; cv=pass; d=google.com; s=arc-20160816; b=u+6qqyz0OmpqciRcJYYxLWXqOFbR8BbpZryqEYajEYSmMpoNsTK57kle1BRKMsGeSd 51N7Xbop342wvhCrEXRNKY0qRvNU8hLHHYNzm29At0E019LY3Muzny2WLGap18eMZL6c MJo3/r47leJ5O6T1LJlhm/94KoG6XbdYem1lflJ2YCQgRTNpETdyDkrgk3uCiJ1rTdib USWt+ITIpvxBFDy/PMSXmOIQtkCUlBEKrDJquhUu1hhLPb3h8QohTYrj3u8QrYurrswF Y1g+nNczLKjsRXtJOWjZnR9b74RED5M+ELG58501IIxH5blGOZR5nYx5LLQ89Caug6ws kANA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=6Mwt+clMmeFlynCqWeYgsMgQsu2kallWPr96FGjiq3o=; fh=7ANf5w8gfosU0aJQGxo9jOCB//AalT+REXp1qydGE/Q=; b=cKHkwwFnDDynVGNpqlZShqA5OqXmcXOyivUgTjY6WRmbHc203qgWGAyR+FfQnZKe/T YzbtY5NWE9Fx9uVbrfqFhUVGI6+AXhvoTbcREaVGUn1ry9oCcaIN6p1GJCeRWxQok5mS NgioGw8Yr2h+KNrnY6Y1jjOg2VfARiYOwvJ8KcztD4xG6b6zWMZay4FRre0/RN3e8Kg4 R8oOD4rgPYrcbxJwIkEmR+XStDl0BPpKOFT+wwr+6NewFRDJNc9MzVwyeFKSOXHdrOIJ d9nZpgSdreGEvZ16y57/HrrzLriVGyiyM4L1aZ+M0FxMX0Z3ztdFPY9WrUXUYV6bGual On9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xtmDNovo; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-111699-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111699-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z18-20020ac87f92000000b0043103d57ef6si2124359qtj.703.2024.03.22.08.25.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 08:25:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111699-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xtmDNovo; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-111699-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111699-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 276CE1C2262B for ; Fri, 22 Mar 2024 15:25:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02DF7524C4; Fri, 22 Mar 2024 15:25:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xtmDNovo" Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D9D053E2E for ; Fri, 22 Mar 2024 15:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711121111; cv=none; b=r/ClbykDVybq2qJyn9xTum5UlF4ySnSWtwadvB9JhwjCKDhvYNiMQe3sbQtXB1oH/yr0OePuimEk29+H+Z/efvs1dWpoKi6zI5LVE53g9ZlgkMJMmSbMhxx0CFJuXU1SqKfU2yxdLfMbnPbMYeIuadBmJYU1zSIVsIwFev7RV1w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711121111; c=relaxed/simple; bh=2wLtvbfdZn3x4UVXEGhEhJpxbE8sclowteClLq1fG3c=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=dEYv/CQ5zWGKbwvrP9pCZm3aekEXEfpj3OiSXExgmhR0qepjlDK92xPCeQ6xg3e8j6aeUEmyPWy2GAUl/bg6+iGzcpJuW5pm4Mo1mNtyOIdrya3t7bottNcx9N7qu4By6mCe5crjIJUfRoQlEXyD+XNf9icl5XqHjp2tuoxXpV8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=xtmDNovo; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711121106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6Mwt+clMmeFlynCqWeYgsMgQsu2kallWPr96FGjiq3o=; b=xtmDNovo201g+m95MB0sDImmNbElEi6TQzc0YiBIQHQESsZtiGpoNmR0PzChrSRolbmahQ +19KrAQ6hPmRFRd7p7c/WHFbrKV+z5kkUNWdALtfQbxZRDjUn1RyqlEvFiBQmTnoKRy4av 0vHv1gP4ngStgN9OcENG/gj1UE7YV5M= Date: Fri, 22 Mar 2024 08:24:59 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 1/3] leds: trigger: legtrig-bpf: Add ledtrig-bpf module Content-Language: en-GB To: Daniel Hodges , ast@kernel.org, pavel@ucw.cz, lee@kernel.org, linux-leds@vger.kernel.org, daniel@iogearbox.net, bpf@vger.kernel.org, linux-kernel@vger.kernel.org References: X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yonghong Song In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 3/22/24 7:08 AM, Daniel Hodges wrote: > This patch adds a led trigger that interfaces with the bpf subsystem. It > allows for BPF programs to control LED activity through calling bpf > kfuncs. This functionality is useful in giving users a physical > indication that a BPF program has performed an operation such as > handling a packet or probe point. > > Signed-off-by: Daniel Hodges > --- > drivers/leds/trigger/Kconfig | 10 +++++ > drivers/leds/trigger/Makefile | 1 + > drivers/leds/trigger/ledtrig-bpf.c | 72 ++++++++++++++++++++++++++++++ > 3 files changed, 83 insertions(+) > create mode 100644 drivers/leds/trigger/ledtrig-bpf.c > > diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig > index d11d80176fc0..30b0fd3847be 100644 > --- a/drivers/leds/trigger/Kconfig > +++ b/drivers/leds/trigger/Kconfig > @@ -152,4 +152,14 @@ config LEDS_TRIGGER_TTY > > When build as a module this driver will be called ledtrig-tty. > > +config LEDS_TRIGGER_BPF > + tristate "LED BPF Trigger" > + depends on BPF > + depends on BPF_SYSCALL > + help > + This allows LEDs to be controlled by the BPF subsystem. This trigger > + must be used with a loaded BPF program in order to control LED state. > + BPF programs can control LED state with kfuncs. > + If unsure, say N. > + > endif # LEDS_TRIGGERS > diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile > index 25c4db97cdd4..ac47128d406c 100644 > --- a/drivers/leds/trigger/Makefile > +++ b/drivers/leds/trigger/Makefile > @@ -16,3 +16,4 @@ obj-$(CONFIG_LEDS_TRIGGER_NETDEV) += ledtrig-netdev.o > obj-$(CONFIG_LEDS_TRIGGER_PATTERN) += ledtrig-pattern.o > obj-$(CONFIG_LEDS_TRIGGER_AUDIO) += ledtrig-audio.o > obj-$(CONFIG_LEDS_TRIGGER_TTY) += ledtrig-tty.o > +obj-$(CONFIG_LEDS_TRIGGER_BPF) += ledtrig-bpf.o > diff --git a/drivers/leds/trigger/ledtrig-bpf.c b/drivers/leds/trigger/ledtrig-bpf.c > new file mode 100644 > index 000000000000..e3b0b8281b70 > --- /dev/null > +++ b/drivers/leds/trigger/ledtrig-bpf.c > @@ -0,0 +1,72 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * LED BPF Trigger > + * > + * Author: Daniel Hodges > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > + > +DEFINE_LED_TRIGGER(ledtrig_bpf); > + > +__bpf_hook_start() > + > +__bpf_kfunc void bpf_ledtrig_blink(unsigned long delay_on, unsigned long delay_off, int invert) > +{ > + led_trigger_blink_oneshot(ledtrig_bpf, delay_on, delay_off, invert); > +} > +__bpf_hook_end(); > + > +BTF_SET8_START(ledtrig_bpf_kfunc_ids) > +BTF_ID_FLAGS(func, bpf_ledtrig_blink) > +BTF_SET8_END(ledtrig_bpf_kfunc_ids) > + > +static const struct btf_kfunc_id_set ledtrig_bpf_kfunc_set = { > + .owner = THIS_MODULE, > + .set = &ledtrig_bpf_kfunc_ids, > +}; > + > +static int init_bpf(void) > +{ > + int ret; > + > + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_UNSPEC, > + &ledtrig_bpf_kfunc_set); If you add the kfunc to BPF_PROG_TYPE_UNSPEC, then you do not need to add to the following prog types since the kernel will search BPF_PROG_TYPE_UNSPEC for all prog types. But if the kfunc only intends to be used for the following program types, I suggest removing the above BPF_PROG_TYPE_UNSPEC registration. > + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, > + &ledtrig_bpf_kfunc_set); > + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, > + &ledtrig_bpf_kfunc_set); > + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SK_SKB, > + &ledtrig_bpf_kfunc_set); > + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, > + &ledtrig_bpf_kfunc_set); > + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_ACT, > + &ledtrig_bpf_kfunc_set); > + return ret; > +} > + > +static int ledtrig_bpf_init(void) > +{ > + led_trigger_register_simple("bpf", &ledtrig_bpf); > + > + return init_bpf(); > +} > + > +static void __exit ledtrig_bpf_exit(void) > +{ > + led_trigger_unregister_simple(ledtrig_bpf); > +} > + > +module_init(ledtrig_bpf_init); > +module_exit(ledtrig_bpf_exit); > + > +MODULE_AUTHOR("Daniel Hodges "); > +MODULE_DESCRIPTION("BPF LED trigger"); > +MODULE_LICENSE("GPL v2");