* [PATCH] kprobes: use DEFINE_DEBUGFS_ATTRIBUTE for the enabled knob
@ 2026-08-18 1:49 Bradley Morgan
2026-08-18 22:52 ` Masami Hiramatsu
0 siblings, 1 reply; 3+ messages in thread
From: Bradley Morgan @ 2026-08-18 1:49 UTC (permalink / raw)
To: Naveen N Rao, David S . Miller, Masami Hiramatsu
Cc: linux-kernel, linux-trace-kernel
This enabled knob is a disgusting terrible hack. It has rolled its
own read/write pair since 2007, writing '1' or '0' into a three byte
buffer by hand just to print a single character, with an XXX comment
begging debugfs for write callbacks on bool files.
DEFINE_DEBUGFS_ATTRIBUTE showed up in 2016 and does exactly that, so
the disgusting terrible hack has outlived its excuse for nine years.
Kill it, and the stale comment with it.
The behavior does not change, except the write only accepts 0/1 now
instead of y/n/on/off, and nothing uses anything else.
---
kernel/kprobes.c | 43 +++++++++----------------------------------
1 file changed, 9 insertions(+), 34 deletions(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index bfc89083daa9..044c6b5fd2aa 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -3013,47 +3013,22 @@ static int disarm_all_kprobes(void)
return ret;
}
-/*
- * XXX: The debugfs bool file interface doesn't allow for callbacks
- * when the bool state is switched. We can reuse that facility when
- * available
- */
-static ssize_t read_enabled_file_bool(struct file *file,
- char __user *user_buf, size_t count, loff_t *ppos)
+static int kprobes_enabled_set(void *data, u64 val)
{
- char buf[3];
+ if (val)
+ return arm_all_kprobes();
- if (!kprobes_all_disarmed)
- buf[0] = '1';
- else
- buf[0] = '0';
- buf[1] = '\n';
- buf[2] = 0x00;
- return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+ return disarm_all_kprobes();
}
-static ssize_t write_enabled_file_bool(struct file *file,
- const char __user *user_buf, size_t count, loff_t *ppos)
+static int kprobes_enabled_get(void *data, u64 *val)
{
- bool enable;
- int ret;
-
- ret = kstrtobool_from_user(user_buf, count, &enable);
- if (ret)
- return ret;
-
- ret = enable ? arm_all_kprobes() : disarm_all_kprobes();
- if (ret)
- return ret;
-
- return count;
+ *val = !kprobes_all_disarmed;
+ return 0;
}
-static const struct file_operations fops_kp = {
- .read = read_enabled_file_bool,
- .write = write_enabled_file_bool,
- .llseek = default_llseek,
-};
+DEFINE_DEBUGFS_ATTRIBUTE(fops_kp, kprobes_enabled_get,
+ kprobes_enabled_set, "%llu\n");
static int __init debugfs_kprobe_init(void)
{
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kprobes: use DEFINE_DEBUGFS_ATTRIBUTE for the enabled knob
2026-08-18 1:49 [PATCH] kprobes: use DEFINE_DEBUGFS_ATTRIBUTE for the enabled knob Bradley Morgan
@ 2026-08-18 22:52 ` Masami Hiramatsu
2026-08-18 22:56 ` Bradley Morgan
0 siblings, 1 reply; 3+ messages in thread
From: Masami Hiramatsu @ 2026-08-18 22:52 UTC (permalink / raw)
To: Bradley Morgan
Cc: Naveen N Rao, David S . Miller, linux-kernel, linux-trace-kernel
On Tue, 18 Aug 2026 01:49:20 +0000
Bradley Morgan <include@grrlz.net> wrote:
> This enabled knob is a disgusting terrible hack. It has rolled its
> own read/write pair since 2007, writing '1' or '0' into a three byte
> buffer by hand just to print a single character, with an XXX comment
> begging debugfs for write callbacks on bool files.
> DEFINE_DEBUGFS_ATTRIBUTE showed up in 2016 and does exactly that, so
> the disgusting terrible hack has outlived its excuse for nine years.
> Kill it, and the stale comment with it.
Hm, OK, but please calm down. Just describe the technical reason here.
>
> The behavior does not change, except the write only accepts 0/1 now
> instead of y/n/on/off, and nothing uses anything else.
I think this comment is needed.
Please add Signed-off-by.
The code looks good to me.
Thanks,
> ---
> kernel/kprobes.c | 43 +++++++++----------------------------------
> 1 file changed, 9 insertions(+), 34 deletions(-)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index bfc89083daa9..044c6b5fd2aa 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -3013,47 +3013,22 @@ static int disarm_all_kprobes(void)
> return ret;
> }
>
> -/*
> - * XXX: The debugfs bool file interface doesn't allow for callbacks
> - * when the bool state is switched. We can reuse that facility when
> - * available
> - */
> -static ssize_t read_enabled_file_bool(struct file *file,
> - char __user *user_buf, size_t count, loff_t *ppos)
> +static int kprobes_enabled_set(void *data, u64 val)
> {
> - char buf[3];
> + if (val)
> + return arm_all_kprobes();
>
> - if (!kprobes_all_disarmed)
> - buf[0] = '1';
> - else
> - buf[0] = '0';
> - buf[1] = '\n';
> - buf[2] = 0x00;
> - return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
> + return disarm_all_kprobes();
> }
>
> -static ssize_t write_enabled_file_bool(struct file *file,
> - const char __user *user_buf, size_t count, loff_t *ppos)
> +static int kprobes_enabled_get(void *data, u64 *val)
> {
> - bool enable;
> - int ret;
> -
> - ret = kstrtobool_from_user(user_buf, count, &enable);
> - if (ret)
> - return ret;
> -
> - ret = enable ? arm_all_kprobes() : disarm_all_kprobes();
> - if (ret)
> - return ret;
> -
> - return count;
> + *val = !kprobes_all_disarmed;
> + return 0;
> }
>
> -static const struct file_operations fops_kp = {
> - .read = read_enabled_file_bool,
> - .write = write_enabled_file_bool,
> - .llseek = default_llseek,
> -};
> +DEFINE_DEBUGFS_ATTRIBUTE(fops_kp, kprobes_enabled_get,
> + kprobes_enabled_set, "%llu\n");
>
> static int __init debugfs_kprobe_init(void)
> {
> --
> 2.47.3
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kprobes: use DEFINE_DEBUGFS_ATTRIBUTE for the enabled knob
2026-08-18 22:52 ` Masami Hiramatsu
@ 2026-08-18 22:56 ` Bradley Morgan
0 siblings, 0 replies; 3+ messages in thread
From: Bradley Morgan @ 2026-08-18 22:56 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Naveen N Rao, David S . Miller, linux-kernel, linux-trace-kernel
On 18 August 2026 23:52:21 BST, Masami Hiramatsu <mhiramat@kernel.org>
wrote:
>On Tue, 18 Aug 2026 01:49:20 +0000
>Bradley Morgan <include@grrlz.net> wrote:
>
>> This enabled knob is a disgusting terrible hack. It has rolled its
>> own read/write pair since 2007, writing '1' or '0' into a three byte
>> buffer by hand just to print a single character, with an XXX comment
>> begging debugfs for write callbacks on bool files.
>> DEFINE_DEBUGFS_ATTRIBUTE showed up in 2016 and does exactly that, so
>> the disgusting terrible hack has outlived its excuse for nine years.
>> Kill it, and the stale comment with it.
>
>Hm, OK, but please calm down. Just describe the technical reason here.
>
>>
>> The behavior does not change, except the write only accepts 0/1 now
>> instead of y/n/on/off, and nothing uses anything else.
>
>I think this comment is needed.
>
What do you suggest?
I'm saying
/* Let's kill this hack */
(I love using the word hack!)
>Please add Signed-off-by.
>
V2 acks it
>The code looks good to me.
>
>Thanks,
>
>> ---
>> kernel/kprobes.c | 43 +++++++++----------------------------------
>> 1 file changed, 9 insertions(+), 34 deletions(-)
>>
>> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
>> index bfc89083daa9..044c6b5fd2aa 100644
>> --- a/kernel/kprobes.c
>> +++ b/kernel/kprobes.c
>> @@ -3013,47 +3013,22 @@ static int disarm_all_kprobes(void)
>> return ret;
>> }
>>
>> -/*
>> - * XXX: The debugfs bool file interface doesn't allow for callbacks
>> - * when the bool state is switched. We can reuse that facility when
>> - * available
>> - */
>> -static ssize_t read_enabled_file_bool(struct file *file,
>> - char __user *user_buf, size_t count, loff_t *ppos)
>> +static int kprobes_enabled_set(void *data, u64 val)
>> {
>> - char buf[3];
>> + if (val)
>> + return arm_all_kprobes();
>>
>> - if (!kprobes_all_disarmed)
>> - buf[0] = '1';
>> - else
>> - buf[0] = '0';
>> - buf[1] = '\n';
>> - buf[2] = 0x00;
>> - return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
>> + return disarm_all_kprobes();
>> }
>>
>> -static ssize_t write_enabled_file_bool(struct file *file,
>> - const char __user *user_buf, size_t count, loff_t *ppos)
>> +static int kprobes_enabled_get(void *data, u64 *val)
>> {
>> - bool enable;
>> - int ret;
>> -
>> - ret = kstrtobool_from_user(user_buf, count, &enable);
>> - if (ret)
>> - return ret;
>> -
>> - ret = enable ? arm_all_kprobes() : disarm_all_kprobes();
>> - if (ret)
>> - return ret;
>> -
>> - return count;
>> + *val = !kprobes_all_disarmed;
>> + return 0;
>> }
>>
>> -static const struct file_operations fops_kp = {
>> - .read = read_enabled_file_bool,
>> - .write = write_enabled_file_bool,
>> - .llseek = default_llseek,
>> -};
>> +DEFINE_DEBUGFS_ATTRIBUTE(fops_kp, kprobes_enabled_get,
>> + kprobes_enabled_set, "%llu\n");
>>
>> static int __init debugfs_kprobe_init(void)
>> {
>> --
>> 2.47.3
>>
>
>
>
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-18 22:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 1:49 [PATCH] kprobes: use DEFINE_DEBUGFS_ATTRIBUTE for the enabled knob Bradley Morgan
2026-08-18 22:52 ` Masami Hiramatsu
2026-08-18 22:56 ` Bradley Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox