* [PATCH v2] alloc_tag: fix rw permission issue when handling boot parameter
@ 2026-01-15 3:15 ranxiaokai627
2026-01-15 3:23 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: ranxiaokai627 @ 2026-01-15 3:15 UTC (permalink / raw)
To: surenb, kent.overstreet, akpm
Cc: linux-mm, linux-kernel, ran.xiaokai, ranxiaokai627
From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Boot parameters prefixed with "sysctl." are processed
during the final stage of system initialization via kernel_init()->
do_sysctl_args(). When CONFIG_MEM_ALLOC_PROFILING_DEBUG is enabled,
the sysctl.vm.mem_profiling entry is not writable and will cause
a warning.
Before run_init_process(), system initialization executes in kernel
thread context. Use current->mm to distinguish sysctl writes during
do_sysctl_args() from user-space triggered ones.
And when the proc_handler is from do_sysctl_args(), always return success
because the same value was already set by setup_early_mem_profiling()
and this eliminates a permission denied warning.
Suggested-by: Suren Baghdasaryan <surenb@google.com>
Acked-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
lib/alloc_tag.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
index 846a5b5b44a4..00ae4673a271 100644
--- a/lib/alloc_tag.c
+++ b/lib/alloc_tag.c
@@ -776,8 +776,22 @@ EXPORT_SYMBOL(page_alloc_tagging_ops);
static int proc_mem_profiling_handler(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
- if (!mem_profiling_support && write)
- return -EINVAL;
+ if (write) {
+ /*
+ * Call from do_sysctl_args() which is a no-op since the same
+ * value was already set by setup_early_mem_profiling.
+ * Return success to avoid warnings from do_sysctl_args().
+ */
+ if (!current->mm)
+ return 0;
+
+#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG
+ /* User can't toggle profiling while debugging */
+ return -EACCES;
+#endif
+ if (!mem_profiling_support)
+ return -EINVAL;
+ }
return proc_do_static_key(table, write, buffer, lenp, ppos);
}
@@ -787,11 +801,7 @@ static const struct ctl_table memory_allocation_profiling_sysctls[] = {
{
.procname = "mem_profiling",
.data = &mem_alloc_profiling_key,
-#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG
- .mode = 0444,
-#else
.mode = 0644,
-#endif
.proc_handler = proc_mem_profiling_handler,
},
};
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] alloc_tag: fix rw permission issue when handling boot parameter
2026-01-15 3:15 [PATCH v2] alloc_tag: fix rw permission issue when handling boot parameter ranxiaokai627
@ 2026-01-15 3:23 ` Andrew Morton
2026-01-15 4:58 ` Suren Baghdasaryan
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2026-01-15 3:23 UTC (permalink / raw)
To: ranxiaokai627
Cc: surenb, kent.overstreet, linux-mm, linux-kernel, ran.xiaokai
On Thu, 15 Jan 2026 03:15:36 +0000 ranxiaokai627@163.com wrote:
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
>
> Boot parameters prefixed with "sysctl." are processed
> during the final stage of system initialization via kernel_init()->
> do_sysctl_args(). When CONFIG_MEM_ALLOC_PROFILING_DEBUG is enabled,
> the sysctl.vm.mem_profiling entry is not writable and will cause
> a warning.
This sounds strange. Why would setting a Kconfig debug thing disable
alteration of a runtime control?
Documentation/mm/allocation-profiling.rst provided no hint.
> Before run_init_process(), system initialization executes in kernel
> thread context. Use current->mm to distinguish sysctl writes during
> do_sysctl_args() from user-space triggered ones.
>
> And when the proc_handler is from do_sysctl_args(), always return success
> because the same value was already set by setup_early_mem_profiling()
> and this eliminates a permission denied warning.
>
> Suggested-by: Suren Baghdasaryan <surenb@google.com>
> Acked-by: Suren Baghdasaryan <surenb@google.com>
> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Should we backport it?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] alloc_tag: fix rw permission issue when handling boot parameter
2026-01-15 3:23 ` Andrew Morton
@ 2026-01-15 4:58 ` Suren Baghdasaryan
2026-01-15 5:47 ` Suren Baghdasaryan
0 siblings, 1 reply; 4+ messages in thread
From: Suren Baghdasaryan @ 2026-01-15 4:58 UTC (permalink / raw)
To: Andrew Morton
Cc: ranxiaokai627, kent.overstreet, linux-mm, linux-kernel, ran.xiaokai
On Wed, Jan 14, 2026 at 7:23 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Thu, 15 Jan 2026 03:15:36 +0000 ranxiaokai627@163.com wrote:
>
> > From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> >
> > Boot parameters prefixed with "sysctl." are processed
> > during the final stage of system initialization via kernel_init()->
> > do_sysctl_args(). When CONFIG_MEM_ALLOC_PROFILING_DEBUG is enabled,
> > the sysctl.vm.mem_profiling entry is not writable and will cause
> > a warning.
>
> This sounds strange. Why would setting a Kconfig debug thing disable
> alteration of a runtime control?
If debug is enabled we don't want the users toggling profiling on and
off because all allocations made while profiling is off will have no
tags. If used later enables profiling and these allocations get freed,
each one will prodice a warning about missing tag. We want to avoid
that by disallowing to toggle this control at runtime when debugging
is enabled.
> Documentation/mm/allocation-profiling.rst provided no hint.
True. I'll post a patch to add that limitation there with description why.
>
> > Before run_init_process(), system initialization executes in kernel
> > thread context. Use current->mm to distinguish sysctl writes during
> > do_sysctl_args() from user-space triggered ones.
> >
> > And when the proc_handler is from do_sysctl_args(), always return success
> > because the same value was already set by setup_early_mem_profiling()
> > and this eliminates a permission denied warning.
> >
> > Suggested-by: Suren Baghdasaryan <surenb@google.com>
> > Acked-by: Suren Baghdasaryan <surenb@google.com>
> > Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
>
> Should we backport it?
I'm not sure a single boot time warning produced only in debug mode
warrants backporting. Do you think we should do it anyway?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] alloc_tag: fix rw permission issue when handling boot parameter
2026-01-15 4:58 ` Suren Baghdasaryan
@ 2026-01-15 5:47 ` Suren Baghdasaryan
0 siblings, 0 replies; 4+ messages in thread
From: Suren Baghdasaryan @ 2026-01-15 5:47 UTC (permalink / raw)
To: Andrew Morton
Cc: ranxiaokai627, kent.overstreet, linux-mm, linux-kernel, ran.xiaokai
On Wed, Jan 14, 2026 at 8:58 PM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Wed, Jan 14, 2026 at 7:23 PM Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > On Thu, 15 Jan 2026 03:15:36 +0000 ranxiaokai627@163.com wrote:
> >
> > > From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> > >
> > > Boot parameters prefixed with "sysctl." are processed
> > > during the final stage of system initialization via kernel_init()->
> > > do_sysctl_args(). When CONFIG_MEM_ALLOC_PROFILING_DEBUG is enabled,
> > > the sysctl.vm.mem_profiling entry is not writable and will cause
> > > a warning.
> >
> > This sounds strange. Why would setting a Kconfig debug thing disable
> > alteration of a runtime control?
>
> If debug is enabled we don't want the users toggling profiling on and
> off because all allocations made while profiling is off will have no
> tags. If used later enables profiling and these allocations get freed,
> each one will prodice a warning about missing tag. We want to avoid
> that by disallowing to toggle this control at runtime when debugging
> is enabled.
>
> > Documentation/mm/allocation-profiling.rst provided no hint.
>
> True. I'll post a patch to add that limitation there with description why.
Documentation update is posted at
https://lore.kernel.org/all/20260115054557.2127777-1-surenb@google.com/
>
> >
> > > Before run_init_process(), system initialization executes in kernel
> > > thread context. Use current->mm to distinguish sysctl writes during
> > > do_sysctl_args() from user-space triggered ones.
> > >
> > > And when the proc_handler is from do_sysctl_args(), always return success
> > > because the same value was already set by setup_early_mem_profiling()
> > > and this eliminates a permission denied warning.
> > >
> > > Suggested-by: Suren Baghdasaryan <surenb@google.com>
> > > Acked-by: Suren Baghdasaryan <surenb@google.com>
> > > Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> >
> > Should we backport it?
>
> I'm not sure a single boot time warning produced only in debug mode
> warrants backporting. Do you think we should do it anyway?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-15 5:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-15 3:15 [PATCH v2] alloc_tag: fix rw permission issue when handling boot parameter ranxiaokai627
2026-01-15 3:23 ` Andrew Morton
2026-01-15 4:58 ` Suren Baghdasaryan
2026-01-15 5:47 ` Suren Baghdasaryan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox