source
large_stringclasses
2 values
subject
large_stringclasses
112 values
code
large_stringclasses
112 values
critique
large_stringlengths
61
3.04M
metadata
dict
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/31 9:43, Chen Ridong wrote: I saw in patch 2/2 that isolated_cpus_updating is described as "protected by cpuset_top_mutex." This could be a bit ambiguous: the caller need to hold either cpus_read_lock or cpus_write_lock and cpuset_mutex to protect isolated_cpus_updating. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 09:49:04 +0800", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/31 9:45, Waiman Long wrote: This is somewhat confusing. cpuset_locked is only set to true when the "full lock" has been acquired. If cpuset_locked is false, that should mean we are outside of any critical region. Conversely, if we are inside a critical region, cpuset_locked should be true. The situation is a bit messy, it’s not clearly which lock protects which global variable. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 10:05:21 +0800", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/30 23:42, Waiman Long wrote: Introducing a new global lock warrants careful consideration. I wonder if we could make all updates to isolated_cpus asynchronous. If that is feasible, we could avoid adding a global lock altogether. If not, we need to clarify which updates must remain synchronous and which ones can be handled asynchronously. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 10:53:28 +0800", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 1/30/26 9:05 PM, Chen Ridong wrote: There is a comment above "cpuset_locked" which state which lock protect it. The locking situation is becoming more complicated. I think I will add a new patch to more clearly document what each global variable is being protected by. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Sat, 31 Jan 2026 18:00:02 -0500", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 1/30/26 9:53 PM, Chen Ridong wrote: Almost all the cpuset code are run with cpuset_mutex held with either cpus_read_lock or cpus_write_lock. So there is no concurrent access/update to any of the cpuset internal data. The new cpuset_top_mutex is aded to resolve the possible deadlock scenarios with the new housekeeping_update() call without breaking this model. Allow parallel concurrent access/update to cpuset data will greatly complicate the code and we will likely missed some corner cases that we have to fix in the future. We will only do that if cpuset is in a critical performance path, but it is not. It is not just isolated_cpus that we are protecting, all the other cpuset data may be at risk if we don't have another top level mutex to protect them. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Sat, 31 Jan 2026 18:13:09 -0500", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/2/1 7:00, Waiman Long wrote: Yes, We need that. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Mon, 2 Feb 2026 08:58:49 +0800", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/2/1 7:13, Waiman Long wrote: I agree with that point. However, we already have paths where isolated_cpus is updated asynchronously, meaning parallel concurrent access/update is already happening. Therefore, we cannot entirely avoid such scenarios, so why not keep the locking simple(make all updates to isolated_cpus asynchronous)? This is just a thought in my mind. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Mon, 2 Feb 2026 09:11:45 +0800", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On Fri, Jan 30, 2026 at 10:42:53AM -0500, Waiman Long wrote: I agree with Chen that this is bloody terrible. At the very least this should have: lockdep_assert_held(&cpuset_mutex); But ideally you'd do patches against this and tip/locking/core that add proper __guarded_by() annotations to this.
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 14:05:26 +0100", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2/2/26 8:05 AM, Peter Zijlstra wrote: Yes, I am going to remove cpuset_locked in the next version. As for __guarded_by() annotation, I need to set up a clang environment that I can use to test it before I will work on that. I usually just use gcc for my compilation need. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Mon, 2 Feb 2026 13:21:43 -0500", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2/1/26 8:11 PM, Chen Ridong wrote: isolated_cpus should only be updated in isolated_cpus_update() where both cpuset_mutex and callback_lock are held. It can be read asynchronously if either cpuset_mutex or callback_lock is held. Can you show me the  places where this rule isn't followed? Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Mon, 2 Feb 2026 13:29:36 -0500", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
linux-next: manual merge of the ftrace tree with the bpf-next tree
Hi all, Today's linux-next merge of the ftrace tree got a conflict in: kernel/trace/bpf_trace.c between commit: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf") from the bpf-next tree and commit: f2cc020d7876 ("tracing: Fix various typos in comments") from the ftrace tree. I fixed it up (the former removed the comment updated by the latter) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts. -- Cheers, Stephen Rothwell
Hi all, Today's linux-next merge of the ftrace tree got a conflict in: kernel/trace/Kconfig between commit: 25e4e3565d45 ("ftrace: Introduce FTRACE_OPS_FL_JMP") from the bpf-next tree and commit: f93a7d0caccd ("ftrace: Allow tracing of some of the tracing code") from the ftrace tree. I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts. -- Cheers, Stephen Rothwell diff --cc kernel/trace/Kconfig index 4661b9e606e0,e1214b9dc990..000000000000 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@@ -336,12 -330,20 +336,26 @@@ config DYNAMIC_FTRACE_WITH_ARG depends on DYNAMIC_FTRACE depends on HAVE_DYNAMIC_FTRACE_WITH_ARGS +config DYNAMIC_FTRACE_WITH_JMP + def_bool y + depends on DYNAMIC_FTRACE + depends on DYNAMIC_FTRACE_WITH_DIRECT_CALLS + depends on HAVE_DYNAMIC_FTRACE_WITH_JMP + + config FUNCTION_SELF_TRACING + bool "Function trace tracing code" + depends on FUNCTION_TRACER + help + Normally all the tracing code is set to notrace, where the function + tracer will ignore all the tracing functions. Sometimes it is useful + for debugging to trace some of the tracing infratructure itself. + Enable this to allow some of the tracing infrastructure to be traced + by the function tracer. Note, this will likely add noise to function + tracing if events and other tracing features are enabled along with + function tracing. + + If unsure, say N. + config FPROBE bool "Kernel Function Probe (fprobe)" depends on HAVE_FUNCTION_GRAPH_FREGS && HAVE_FTRACE_GRAPH_FUNC
{ "author": "Stephen Rothwell <sfr@canb.auug.org.au>", "date": "Mon, 1 Dec 2025 09:33:43 +1100", "thread_id": "20260202120430.760a448f@gandalf.local.home.mbox.gz" }
lkml
linux-next: manual merge of the ftrace tree with the bpf-next tree
Hi all, Today's linux-next merge of the ftrace tree got a conflict in: kernel/trace/bpf_trace.c between commit: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf") from the bpf-next tree and commit: f2cc020d7876 ("tracing: Fix various typos in comments") from the ftrace tree. I fixed it up (the former removed the comment updated by the latter) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts. -- Cheers, Stephen Rothwell
Hi all, Today's linux-next merge of the ftrace tree got a conflict in: kernel/trace/bpf_trace.c between commit: 93f0d09697613 ("bpf: move recursion detection logic to helpers") from the bpf-next tree and commit: f7d327654b886 ("bpf: Have __bpf_trace_run() use rcu_read_lock_dont_migrate()") from the ftrace tree. I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts. diff --cc kernel/trace/bpf_trace.c index f7baeb8278cac,abbf0177ad20b..0000000000000 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@@ -2076,8 -2062,8 +2076,8 @@@ void __bpf_trace_run(struct bpf_raw_tp_ struct bpf_run_ctx *old_run_ctx; struct bpf_trace_run_ctx run_ctx; - cant_sleep(); + rcu_read_lock_dont_migrate(); - if (unlikely(this_cpu_inc_return(*(prog->active)) != 1)) { + if (unlikely(!bpf_prog_get_recursion_context(prog))) { bpf_prog_inc_misses_counter(prog); goto out; } @@@ -2090,8 -2075,8 +2089,8 @@@ bpf_reset_run_ctx(old_run_ctx); out: - this_cpu_dec(*(prog->active)); + bpf_prog_put_recursion_context(prog); + rcu_read_unlock_migrate(); } #define UNPACK(...) __VA_ARGS__
{ "author": "Mark Brown <broonie@kernel.org>", "date": "Mon, 2 Feb 2026 14:30:14 +0000", "thread_id": "20260202120430.760a448f@gandalf.local.home.mbox.gz" }
lkml
linux-next: manual merge of the ftrace tree with the bpf-next tree
Hi all, Today's linux-next merge of the ftrace tree got a conflict in: kernel/trace/bpf_trace.c between commit: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf") from the bpf-next tree and commit: f2cc020d7876 ("tracing: Fix various typos in comments") from the ftrace tree. I fixed it up (the former removed the comment updated by the latter) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts. -- Cheers, Stephen Rothwell
On Mon, 2 Feb 2026 14:30:14 +0000 Mark Brown <broonie@kernel.org> wrote: Thanks Mark, the fix looks good to me. The conflict was caused by ftrace doing a small change that was recommended by Alexei so I hope this isn't a complex conflict ;-) -- Steve
{ "author": "Steven Rostedt <rostedt@goodmis.org>", "date": "Mon, 2 Feb 2026 11:20:10 -0500", "thread_id": "20260202120430.760a448f@gandalf.local.home.mbox.gz" }
lkml
linux-next: manual merge of the ftrace tree with the bpf-next tree
Hi all, Today's linux-next merge of the ftrace tree got a conflict in: kernel/trace/bpf_trace.c between commit: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf") from the bpf-next tree and commit: f2cc020d7876 ("tracing: Fix various typos in comments") from the ftrace tree. I fixed it up (the former removed the comment updated by the latter) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts. -- Cheers, Stephen Rothwell
On Mon, Feb 2, 2026 at 8:19 AM Steven Rostedt <rostedt@goodmis.org> wrote: yep. Conflict resolution is correct. I wonder whether we should take the whole srcu_fast in tracepoints patch set into bpf-next to avoid this conflict ? Probably not worth it in the last week before the merge window. Just a thought.
{ "author": "Alexei Starovoitov <alexei.starovoitov@gmail.com>", "date": "Mon, 2 Feb 2026 08:42:55 -0800", "thread_id": "20260202120430.760a448f@gandalf.local.home.mbox.gz" }
lkml
linux-next: manual merge of the ftrace tree with the bpf-next tree
Hi all, Today's linux-next merge of the ftrace tree got a conflict in: kernel/trace/bpf_trace.c between commit: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf") from the bpf-next tree and commit: f2cc020d7876 ("tracing: Fix various typos in comments") from the ftrace tree. I fixed it up (the former removed the comment updated by the latter) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts. -- Cheers, Stephen Rothwell
On Mon, 2 Feb 2026 08:42:55 -0800 Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: It's already in next where it would require a revert to get rid of. There's just one patch that touches the bpf code, so it still makes more sense to keep it in the tracing tree. -- Steve
{ "author": "Steven Rostedt <rostedt@goodmis.org>", "date": "Mon, 2 Feb 2026 12:04:30 -0500", "thread_id": "20260202120430.760a448f@gandalf.local.home.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
The update_isolation_cpumasks() function can be called either directly from regular cpuset control file write with cpuset_full_lock() called or via the CPU hotplug path with cpus_write_lock and cpuset_mutex held. As we are going to enable dynamic update to the nozh_full housekeeping cpumask (HK_TYPE_KERNEL_NOISE) soon with the help of CPU hotplug, allowing the CPU hotplug path to call into housekeeping_update() directly from update_isolation_cpumasks() will likely cause deadlock. So we have to defer any call to housekeeping_update() after the CPU hotplug operation has finished. This is now done via the workqueue where the actual housekeeping_update() call, if needed, will happen after cpus_write_lock is released. We can't use the synchronous task_work API as call from CPU hotplug path happen in the per-cpu kthread of the CPU that is being shut down or brought up. Because of the asynchronous nature of workqueue, the HK_TYPE_DOMAIN housekeeping cpumask will be updated a bit later than the "cpuset.cpus.isolated" control file in this case. Also add a check in test_cpuset_prs.sh and modify some existing test cases to confirm that "cpuset.cpus.isolated" and HK_TYPE_DOMAIN housekeeping cpumask will both be updated. Signed-off-by: Waiman Long <longman@redhat.com> --- kernel/cgroup/cpuset.c | 37 +++++++++++++++++-- .../selftests/cgroup/test_cpuset_prs.sh | 13 +++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 7b7d12ab1006..0b0eb1df09d5 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -84,6 +84,9 @@ static cpumask_var_t isolated_cpus; */ static bool isolated_cpus_updating; +/* Both cpuset_mutex and cpus_read_locked acquired */ +static bool cpuset_locked; + /* * A flag to force sched domain rebuild at the end of an operation. * It can be set in @@ -285,10 +288,12 @@ void cpuset_full_lock(void) { cpus_read_lock(); mutex_lock(&cpuset_mutex); + cpuset_locked = true; } void cpuset_full_unlock(void) { + cpuset_locked = false; mutex_unlock(&cpuset_mutex); cpus_read_unlock(); } @@ -1285,6 +1290,16 @@ static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus) return false; } +static void isolcpus_workfn(struct work_struct *work) +{ + cpuset_full_lock(); + if (isolated_cpus_updating) { + WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); + isolated_cpus_updating = false; + } + cpuset_full_unlock(); +} + /* * update_isolation_cpumasks - Update external isolation related CPU masks * @@ -1293,14 +1308,30 @@ static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus) */ static void update_isolation_cpumasks(void) { - int ret; + static DECLARE_WORK(isolcpus_work, isolcpus_workfn); if (!isolated_cpus_updating) return; - ret = housekeeping_update(isolated_cpus); - WARN_ON_ONCE(ret < 0); + /* + * This function can be reached either directly from regular cpuset + * control file write (cpuset_locked) or via hotplug (cpus_write_lock + * && cpuset_mutex held). In the later case, we defer the + * housekeeping_update() call to the system_unbound_wq to avoid the + * possibility of deadlock. This also means that there will be a short + * period of time where HK_TYPE_DOMAIN housekeeping cpumask will lag + * behind isolated_cpus. + */ + if (!cpuset_locked) { + /* + * We rely on WORK_STRUCT_PENDING_BIT to not requeue a work + * item that is still pending. + */ + queue_work(system_unbound_wq, &isolcpus_work); + return; + } + WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); isolated_cpus_updating = false; } diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh index 5dff3ad53867..0502b156582b 100755 --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh @@ -245,8 +245,9 @@ TEST_MATRIX=( "C2-3:P1:S+ C3:P2 . . O2=0 O2=1 . . 0 A1:2|A2:3 A1:P1|A2:P2" "C2-3:P1:S+ C3:P1 . . O2=0 . . . 0 A1:|A2:3 A1:P1|A2:P1" "C2-3:P1:S+ C3:P1 . . O3=0 . . . 0 A1:2|A2: A1:P1|A2:P1" - "C2-3:P1:S+ C3:P1 . . T:O2=0 . . . 0 A1:3|A2:3 A1:P1|A2:P-1" - "C2-3:P1:S+ C3:P1 . . . T:O3=0 . . 0 A1:2|A2:2 A1:P1|A2:P-1" + "C2-3:P1:S+ C3:P2 . . T:O2=0 . . . 0 A1:3|A2:3 A1:P1|A2:P-2" + "C1-3:P1:S+ C3:P2 . . . T:O3=0 . . 0 A1:1-2|A2:1-2 A1:P1|A2:P-2 3|" + "C1-3:P1:S+ C3:P2 . . . T:O3=0 O3=1 . 0 A1:1-2|A2:3 A1:P1|A2:P2 3" "$SETUP_A123_PARTITIONS . O1=0 . . . 0 A1:|A2:2|A3:3 A1:P1|A2:P1|A3:P1" "$SETUP_A123_PARTITIONS . O2=0 . . . 0 A1:1|A2:|A3:3 A1:P1|A2:P1|A3:P1" "$SETUP_A123_PARTITIONS . O3=0 . . . 0 A1:1|A2:2|A3: A1:P1|A2:P1|A3:P1" @@ -764,7 +765,7 @@ check_cgroup_states() # only CPUs in isolated partitions as well as those that are isolated at # boot time. # -# $1 - expected isolated cpu list(s) <isolcpus1>{,<isolcpus2>} +# $1 - expected isolated cpu list(s) <isolcpus1>{|<isolcpus2>} # <isolcpus1> - expected sched/domains value # <isolcpus2> - cpuset.cpus.isolated value = <isolcpus1> if not defined # @@ -773,6 +774,7 @@ check_isolcpus() EXPECTED_ISOLCPUS=$1 ISCPUS=${CGROUP2}/cpuset.cpus.isolated ISOLCPUS=$(cat $ISCPUS) + HKICPUS=$(cat /sys/devices/system/cpu/isolated) LASTISOLCPU= SCHED_DOMAINS=/sys/kernel/debug/sched/domains if [[ $EXPECTED_ISOLCPUS = . ]] @@ -810,6 +812,11 @@ check_isolcpus() ISOLCPUS= EXPECTED_ISOLCPUS=$EXPECTED_SDOMAIN + # + # The inverse of HK_TYPE_DOMAIN cpumask in $HKICPUS should match $ISOLCPUS + # + [[ "$ISOLCPUS" != "$HKICPUS" ]] && return 1 + # # Use the sched domain in debugfs to check isolated CPUs, if available # -- 2.52.0
{ "author": "Waiman Long <longman@redhat.com>", "date": "Fri, 30 Jan 2026 10:42:53 -0500", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
The current cpuset partition code is able to dynamically update the sched domains of a running system and the corresponding HK_TYPE_DOMAIN housekeeping cpumask to perform what is essentally the "isolcpus=domain,..." boot command line feature at run time. The housekeeping cpumask update requires flushing a number of different workqueues which may not be safe with cpus_read_lock() held as the workqueue flushing code may acquire cpus_read_lock() or acquiring locks which have locking dependency with cpus_read_lock() down the chain. Below is an example of such circular locking problem. ====================================================== WARNING: possible circular locking dependency detected 6.18.0-test+ #2 Tainted: G S ------------------------------------------------------ test_cpuset_prs/10971 is trying to acquire lock: ffff888112ba4958 ((wq_completion)sync_wq){+.+.}-{0:0}, at: touch_wq_lockdep_map+0x7a/0x180 but task is already holding lock: ffffffffae47f450 (cpuset_mutex){+.+.}-{4:4}, at: cpuset_partition_write+0x85/0x130 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #4 (cpuset_mutex){+.+.}-{4:4}: -> #3 (cpu_hotplug_lock){++++}-{0:0}: -> #2 (rtnl_mutex){+.+.}-{4:4}: -> #1 ((work_completion)(&arg.work)){+.+.}-{0:0}: -> #0 ((wq_completion)sync_wq){+.+.}-{0:0}: Chain exists of: (wq_completion)sync_wq --> cpu_hotplug_lock --> cpuset_mutex 5 locks held by test_cpuset_prs/10971: #0: ffff88816810e440 (sb_writers#7){.+.+}-{0:0}, at: ksys_write+0xf9/0x1d0 #1: ffff8891ab620890 (&of->mutex#2){+.+.}-{4:4}, at: kernfs_fop_write_iter+0x260/0x5f0 #2: ffff8890a78b83e8 (kn->active#187){.+.+}-{0:0}, at: kernfs_fop_write_iter+0x2b6/0x5f0 #3: ffffffffadf32900 (cpu_hotplug_lock){++++}-{0:0}, at: cpuset_partition_write+0x77/0x130 #4: ffffffffae47f450 (cpuset_mutex){+.+.}-{4:4}, at: cpuset_partition_write+0x85/0x130 Call Trace: <TASK> : touch_wq_lockdep_map+0x93/0x180 __flush_workqueue+0x111/0x10b0 housekeeping_update+0x12d/0x2d0 update_parent_effective_cpumask+0x595/0x2440 update_prstate+0x89d/0xce0 cpuset_partition_write+0xc5/0x130 cgroup_file_write+0x1a5/0x680 kernfs_fop_write_iter+0x3df/0x5f0 vfs_write+0x525/0xfd0 ksys_write+0xf9/0x1d0 do_syscall_64+0x95/0x520 entry_SYSCALL_64_after_hwframe+0x76/0x7e To avoid such a circular locking dependency problem, we have to call housekeeping_update() without holding the cpus_read_lock() and cpuset_mutex. The current set of wq's flushed by housekeeping_update() may not have work functions that call cpus_read_lock() directly, but we are likely to extend the list of wq's that are flushed in the future. Moreover, the current set of work functions may hold locks that may have cpu_hotplug_lock down the dependency chain. One way to do that is to introduce a new top level cpuset_top_mutex which will be acquired first. This new cpuset_top_mutex will provide the need mutual exclusion without the need to hold cpus_read_lock(). As cpus_read_lock() is now no longer held when tmigr_isolated_exclude_cpumask() is called, it needs to acquire it directly. The lockdep_is_cpuset_held() is also updated to check the new cpuset_top_mutex. Signed-off-by: Waiman Long <longman@redhat.com> --- kernel/cgroup/cpuset.c | 101 +++++++++++++++++++++++----------- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 0b0eb1df09d5..edccfa2df9da 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -78,13 +78,13 @@ static cpumask_var_t subpartitions_cpus; static cpumask_var_t isolated_cpus; /* - * isolated_cpus updating flag (protected by cpuset_mutex) + * isolated_cpus updating flag (protected by cpuset_top_mutex) * Set if isolated_cpus is going to be updated in the current * cpuset_mutex crtical section. */ static bool isolated_cpus_updating; -/* Both cpuset_mutex and cpus_read_locked acquired */ +/* cpuset_top_mutex acquired */ static bool cpuset_locked; /* @@ -222,29 +222,44 @@ struct cpuset top_cpuset = { }; /* - * There are two global locks guarding cpuset structures - cpuset_mutex and - * callback_lock. The cpuset code uses only cpuset_mutex. Other kernel - * subsystems can use cpuset_lock()/cpuset_unlock() to prevent change to cpuset - * structures. Note that cpuset_mutex needs to be a mutex as it is used in - * paths that rely on priority inheritance (e.g. scheduler - on RT) for - * correctness. + * CPUSET Locking Convention + * ------------------------- * - * A task must hold both locks to modify cpusets. If a task holds - * cpuset_mutex, it blocks others, ensuring that it is the only task able to - * also acquire callback_lock and be able to modify cpusets. It can perform - * various checks on the cpuset structure first, knowing nothing will change. - * It can also allocate memory while just holding cpuset_mutex. While it is - * performing these checks, various callback routines can briefly acquire - * callback_lock to query cpusets. Once it is ready to make the changes, it - * takes callback_lock, blocking everyone else. + * Below are the four global locks guarding cpuset structures in lock + * acquisition order: + * - cpuset_top_mutex + * - cpu_hotplug_lock (cpus_read_lock/cpus_write_lock) + * - cpuset_mutex + * - callback_lock (raw spinlock) * - * Calls to the kernel memory allocator can not be made while holding - * callback_lock, as that would risk double tripping on callback_lock - * from one of the callbacks into the cpuset code from within - * __alloc_pages(). + * The first cpuset_top_mutex will be held except when calling into + * cpuset_handle_hotplug() from the CPU hotplug code where cpus_write_lock + * and cpuset_mutex will be held instead. * - * If a task is only holding callback_lock, then it has read-only - * access to cpusets. + * As cpuset will now indirectly flush a number of different workqueues in + * housekeeping_update() when the set of isolated CPUs is going to be changed, + * it may not be safe from the circular locking perspective to hold the + * cpus_read_lock. So cpus_read_lock and cpuset_mutex will be released before + * calling housekeeping_update() and re-acquired afterward. + * + * A task must hold all the remaining three locks to modify externally visible + * or used fields of cpusets, though some of the internally used cpuset fields + * can be modified without holding callback_lock. If only reliable read access + * of the externally used fields are needed, a task can hold either + * cpuset_mutex or callback_lock which are exposed to other subsystems. + * + * If a task holds cpu_hotplug_lock and cpuset_mutex, it blocks others, + * ensuring that it is the only task able to also acquire callback_lock and + * be able to modify cpusets. It can perform various checks on the cpuset + * structure first, knowing nothing will change. It can also allocate memory + * without holding callback_lock. While it is performing these checks, various + * callback routines can briefly acquire callback_lock to query cpusets. Once + * it is ready to make the changes, it takes callback_lock, blocking everyone + * else. + * + * Calls to the kernel memory allocator cannot be made while holding + * callback_lock which is a spinlock, as the memory allocator may sleep or + * call back into cpuset code and acquire callback_lock. * * Now, the task_struct fields mems_allowed and mempolicy may be changed * by other task, we use alloc_lock in the task_struct fields to protect @@ -255,6 +270,7 @@ struct cpuset top_cpuset = { * cpumasks and nodemasks. */ +static DEFINE_MUTEX(cpuset_top_mutex); static DEFINE_MUTEX(cpuset_mutex); /** @@ -278,6 +294,18 @@ void lockdep_assert_cpuset_lock_held(void) lockdep_assert_held(&cpuset_mutex); } +static void cpuset_partial_lock(void) +{ + cpus_read_lock(); + mutex_lock(&cpuset_mutex); +} + +static void cpuset_partial_unlock(void) +{ + mutex_unlock(&cpuset_mutex); + cpus_read_unlock(); +} + /** * cpuset_full_lock - Acquire full protection for cpuset modification * @@ -286,22 +314,22 @@ void lockdep_assert_cpuset_lock_held(void) */ void cpuset_full_lock(void) { - cpus_read_lock(); - mutex_lock(&cpuset_mutex); + mutex_lock(&cpuset_top_mutex); + cpuset_partial_lock(); cpuset_locked = true; } void cpuset_full_unlock(void) { cpuset_locked = false; - mutex_unlock(&cpuset_mutex); - cpus_read_unlock(); + cpuset_partial_unlock(); + mutex_unlock(&cpuset_top_mutex); } #ifdef CONFIG_LOCKDEP bool lockdep_is_cpuset_held(void) { - return lockdep_is_held(&cpuset_mutex); + return lockdep_is_held(&cpuset_top_mutex); } #endif @@ -1292,12 +1320,12 @@ static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus) static void isolcpus_workfn(struct work_struct *work) { - cpuset_full_lock(); - if (isolated_cpus_updating) { - WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); - isolated_cpus_updating = false; - } - cpuset_full_unlock(); + guard(mutex)(&cpuset_top_mutex); + if (!isolated_cpus_updating) + return; + + WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); + isolated_cpus_updating = false; } /* @@ -1331,8 +1359,15 @@ static void update_isolation_cpumasks(void) return; } + lockdep_assert_held(&cpuset_top_mutex); + /* + * Release cpus_read_lock & cpuset_mutex before calling + * housekeeping_update() and re-acquiring them afterward. + */ + cpuset_partial_unlock(); WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); isolated_cpus_updating = false; + cpuset_partial_lock(); } /** diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 3b725d39c06e..ef152d401fe2 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -123,8 +123,6 @@ int housekeeping_update(struct cpumask *isol_mask) struct cpumask *trial, *old = NULL; int err; - lockdep_assert_cpus_held(); - trial = kmalloc(cpumask_size(), GFP_KERNEL); if (!trial) return -ENOMEM; @@ -136,7 +134,7 @@ int housekeeping_update(struct cpumask *isol_mask) } if (!housekeeping.flags) - static_branch_enable_cpuslocked(&housekeeping_overridden); + static_branch_enable(&housekeeping_overridden); if (housekeeping.flags & HK_FLAG_DOMAIN) old = housekeeping_cpumask_dereference(HK_TYPE_DOMAIN); diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c index 6da9cd562b20..244a8d025e78 100644 --- a/kernel/time/timer_migration.c +++ b/kernel/time/timer_migration.c @@ -1559,8 +1559,6 @@ int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask) cpumask_var_t cpumask __free(free_cpumask_var) = CPUMASK_VAR_NULL; int cpu; - lockdep_assert_cpus_held(); - if (!works) return -ENOMEM; if (!alloc_cpumask_var(&cpumask, GFP_KERNEL)) @@ -1570,6 +1568,7 @@ int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask) * First set previously isolated CPUs as available (unisolate). * This cpumask contains only CPUs that switched to available now. */ + guard(cpus_read_lock)(); cpumask_andnot(cpumask, cpu_online_mask, exclude_cpumask); cpumask_andnot(cpumask, cpumask, tmigr_available_cpumask); -- 2.52.0
{ "author": "Waiman Long <longman@redhat.com>", "date": "Fri, 30 Jan 2026 10:42:54 -0500", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/30 23:42, Waiman Long wrote: Can this happen? cpu0 cpu1 [...] isolated_cpus_updating = true; ... // 'full_lock' is not acquired update_isolation_cpumasks // exec worker concurrently isolcpus_workfn cpuset_full_lock isolated_cpus_updating = false; cpuset_full_unlock(); // This returns uncorrectly if (!isolated_cpus_updating) return; -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 08:47:37 +0800", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/30 23:42, Waiman Long wrote: Adding a global variable makes this difficult to handle, especially in concurrent scenarios, since we could read it outside of a critical region. I suggest removing cpuset_locked and adding async_update_isolation_cpumasks instead, which can indicate to the caller it should call without holding the full lock. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 08:58:40 +0800", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 1/30/26 7:47 PM, Chen Ridong wrote: Note this statement. That is not true. Either cpus_read_lock or cpus_write_lock and cpuset_mutex are held when update_isolation_cpumasks() is called. So there is mutual exclusion. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Fri, 30 Jan 2026 20:06:33 -0500", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/31 9:06, Waiman Long wrote: Thank you for reminder. Eh, we currently assume that it can only be called from existing scenarios, so it's okay for now. But I'm concerned that if we later use update_isolation_cpumasks without realizing that we need to hold either cpus_write_lock or (cpus_read_lock && cpuset_mutex) , we could run into concurrency issues. Maybe I'm worrying too much. And maybe we shuold add 'lockdep_assert_held' inside the update_isolation_cpumasks. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 09:43:07 +0800", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 1/30/26 7:58 PM, Chen Ridong wrote: No, cpuset_locked is always read from or written into inside a critical section. It is under cpuset_mutex up to this point and then with the cpuset_top_mutex with the next patch. The point of this global variable is to distinguish between calling from CPU hotplug and the other regular cpuset code paths. The only difference between these two are having cpus_read_lock or cpus_write_lock held. That is why I think adding a global variable in cpuset_full_lock() is the easy way. Otherwise, we will to add extra argument to some of the functions to distinguish these two cases. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Fri, 30 Jan 2026 20:45:52 -0500", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/31 9:43, Chen Ridong wrote: I saw in patch 2/2 that isolated_cpus_updating is described as "protected by cpuset_top_mutex." This could be a bit ambiguous: the caller need to hold either cpus_read_lock or cpus_write_lock and cpuset_mutex to protect isolated_cpus_updating. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 09:49:04 +0800", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/31 9:45, Waiman Long wrote: This is somewhat confusing. cpuset_locked is only set to true when the "full lock" has been acquired. If cpuset_locked is false, that should mean we are outside of any critical region. Conversely, if we are inside a critical region, cpuset_locked should be true. The situation is a bit messy, it’s not clearly which lock protects which global variable. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 10:05:21 +0800", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/30 23:42, Waiman Long wrote: Introducing a new global lock warrants careful consideration. I wonder if we could make all updates to isolated_cpus asynchronous. If that is feasible, we could avoid adding a global lock altogether. If not, we need to clarify which updates must remain synchronous and which ones can be handled asynchronously. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 10:53:28 +0800", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 1/30/26 9:05 PM, Chen Ridong wrote: There is a comment above "cpuset_locked" which state which lock protect it. The locking situation is becoming more complicated. I think I will add a new patch to more clearly document what each global variable is being protected by. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Sat, 31 Jan 2026 18:00:02 -0500", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 1/30/26 9:53 PM, Chen Ridong wrote: Almost all the cpuset code are run with cpuset_mutex held with either cpus_read_lock or cpus_write_lock. So there is no concurrent access/update to any of the cpuset internal data. The new cpuset_top_mutex is aded to resolve the possible deadlock scenarios with the new housekeeping_update() call without breaking this model. Allow parallel concurrent access/update to cpuset data will greatly complicate the code and we will likely missed some corner cases that we have to fix in the future. We will only do that if cpuset is in a critical performance path, but it is not. It is not just isolated_cpus that we are protecting, all the other cpuset data may be at risk if we don't have another top level mutex to protect them. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Sat, 31 Jan 2026 18:13:09 -0500", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/2/1 7:00, Waiman Long wrote: Yes, We need that. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Mon, 2 Feb 2026 08:58:49 +0800", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/2/1 7:13, Waiman Long wrote: I agree with that point. However, we already have paths where isolated_cpus is updated asynchronously, meaning parallel concurrent access/update is already happening. Therefore, we cannot entirely avoid such scenarios, so why not keep the locking simple(make all updates to isolated_cpus asynchronous)? This is just a thought in my mind. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Mon, 2 Feb 2026 09:11:45 +0800", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On Fri, Jan 30, 2026 at 10:42:53AM -0500, Waiman Long wrote: I agree with Chen that this is bloody terrible. At the very least this should have: lockdep_assert_held(&cpuset_mutex); But ideally you'd do patches against this and tip/locking/core that add proper __guarded_by() annotations to this.
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 14:05:26 +0100", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2/2/26 8:05 AM, Peter Zijlstra wrote: Yes, I am going to remove cpuset_locked in the next version. As for __guarded_by() annotation, I need to set up a clang environment that I can use to test it before I will work on that. I usually just use gcc for my compilation need. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Mon, 2 Feb 2026 13:21:43 -0500", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2/1/26 8:11 PM, Chen Ridong wrote: isolated_cpus should only be updated in isolated_cpus_update() where both cpuset_mutex and callback_lock are held. It can be read asynchronously if either cpuset_mutex or callback_lock is held. Can you show me the  places where this rule isn't followed? Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Mon, 2 Feb 2026 13:29:36 -0500", "thread_id": "c8a56031-023d-4bbe-b7af-53e91c6d1dfc@redhat.com.mbox.gz" }
lkml
[PATCH v2 0/2] ARM64 support for doorbell and intercept SINTs
From: "Anirudh Rayabharam (Microsoft)" <anirudh@anirudhrb.com> On x86, the HYPERVISOR_CALLBACK_VECTOR is used to receive synthetic interrupts (SINTs) from the hypervisor for doorbells and intercepts. There is no such vector reserved for arm64. On arm64, the INTID for SINTs should be in the SGI or PPI range. The hypervisor exposes a virtual device in the ACPI that reserves a PPI for this use. Introduce a platform_driver that binds to this ACPI device and obtains the interrupt vector that can be used for SINTs. Changes in v2: Addressed review comments: - Moved more stuff into mshv_synic.c - Code simplifications - Removed unnecessary debug prints v1: https://lore.kernel.org/linux-hyperv/20260128160437.3342167-1-anirudh@anirudhrb.com/ Anirudh Rayabharam (Microsoft) (2): mshv: refactor synic init and cleanup mshv: add arm64 support for doorbell & intercept SINTs drivers/hv/mshv_root.h | 5 +- drivers/hv/mshv_root_main.c | 59 ++------- drivers/hv/mshv_synic.c | 232 ++++++++++++++++++++++++++++++++++-- 3 files changed, 230 insertions(+), 66 deletions(-) -- 2.34.1
From: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> Rename mshv_synic_init() to mshv_synic_cpu_init() and mshv_synic_cleanup() to mshv_synic_cpu_exit() to better reflect that these functions handle per-cpu synic setup and teardown. Use mshv_synic_init/cleanup() to perform init/cleanup that is not per-cpu. Move all the synic related setup from mshv_parent_partition_init. Move the reboot notifier to mshv_synic.c because it currently only operates on the synic cpuhp state. Move out synic_pages from the global mshv_root since it's use is now completely local to mshv_synic.c. This is in preparation for the next patch which will add more stuff to mshv_synic_init(). No functional change. Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> --- drivers/hv/mshv_root.h | 5 ++- drivers/hv/mshv_root_main.c | 59 +++++------------------------- drivers/hv/mshv_synic.c | 71 +++++++++++++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 60 deletions(-) diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index 3c1d88b36741..26e0320c8097 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -183,7 +183,6 @@ struct hv_synic_pages { }; struct mshv_root { - struct hv_synic_pages __percpu *synic_pages; spinlock_t pt_ht_lock; DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS); struct hv_partition_property_vmm_capabilities vmm_caps; @@ -242,8 +241,8 @@ int mshv_register_doorbell(u64 partition_id, doorbell_cb_t doorbell_cb, void mshv_unregister_doorbell(u64 partition_id, int doorbell_portid); void mshv_isr(void); -int mshv_synic_init(unsigned int cpu); -int mshv_synic_cleanup(unsigned int cpu); +int mshv_synic_init(struct device *dev); +void mshv_synic_cleanup(void); static inline bool mshv_partition_encrypted(struct mshv_partition *partition) { diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 681b58154d5e..7c1666456e78 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -2035,7 +2035,6 @@ mshv_dev_release(struct inode *inode, struct file *filp) return 0; } -static int mshv_cpuhp_online; static int mshv_root_sched_online; static const char *scheduler_type_to_string(enum hv_scheduler_type type) @@ -2198,40 +2197,14 @@ root_scheduler_deinit(void) free_percpu(root_scheduler_output); } -static int mshv_reboot_notify(struct notifier_block *nb, - unsigned long code, void *unused) -{ - cpuhp_remove_state(mshv_cpuhp_online); - return 0; -} - -struct notifier_block mshv_reboot_nb = { - .notifier_call = mshv_reboot_notify, -}; - static void mshv_root_partition_exit(void) { - unregister_reboot_notifier(&mshv_reboot_nb); root_scheduler_deinit(); } static int __init mshv_root_partition_init(struct device *dev) { - int err; - - err = root_scheduler_init(dev); - if (err) - return err; - - err = register_reboot_notifier(&mshv_reboot_nb); - if (err) - goto root_sched_deinit; - - return 0; - -root_sched_deinit: - root_scheduler_deinit(); - return err; + return root_scheduler_init(dev); } static void mshv_init_vmm_caps(struct device *dev) @@ -2276,31 +2249,18 @@ static int __init mshv_parent_partition_init(void) MSHV_HV_MAX_VERSION); } - mshv_root.synic_pages = alloc_percpu(struct hv_synic_pages); - if (!mshv_root.synic_pages) { - dev_err(dev, "Failed to allocate percpu synic page\n"); - ret = -ENOMEM; + ret = mshv_synic_init(dev); + if (ret) goto device_deregister; - } - - ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", - mshv_synic_init, - mshv_synic_cleanup); - if (ret < 0) { - dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); - goto free_synic_pages; - } - - mshv_cpuhp_online = ret; ret = mshv_retrieve_scheduler_type(dev); if (ret) - goto remove_cpu_state; + goto synic_cleanup; if (hv_root_partition()) ret = mshv_root_partition_init(dev); if (ret) - goto remove_cpu_state; + goto synic_cleanup; mshv_init_vmm_caps(dev); @@ -2318,10 +2278,8 @@ static int __init mshv_parent_partition_init(void) exit_partition: if (hv_root_partition()) mshv_root_partition_exit(); -remove_cpu_state: - cpuhp_remove_state(mshv_cpuhp_online); -free_synic_pages: - free_percpu(mshv_root.synic_pages); +synic_cleanup: + mshv_synic_cleanup(); device_deregister: misc_deregister(&mshv_dev); return ret; @@ -2335,8 +2293,7 @@ static void __exit mshv_parent_partition_exit(void) mshv_irqfd_wq_cleanup(); if (hv_root_partition()) mshv_root_partition_exit(); - cpuhp_remove_state(mshv_cpuhp_online); - free_percpu(mshv_root.synic_pages); + mshv_synic_cleanup(); } module_init(mshv_parent_partition_init); diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index f8b0337cdc82..98c58755846d 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -12,11 +12,16 @@ #include <linux/mm.h> #include <linux/io.h> #include <linux/random.h> +#include <linux/cpuhotplug.h> +#include <linux/reboot.h> #include <asm/mshyperv.h> #include "mshv_eventfd.h" #include "mshv.h" +static int synic_cpuhp_online; +static struct hv_synic_pages __percpu *synic_pages; + static u32 synic_event_ring_get_queued_port(u32 sint_index) { struct hv_synic_event_ring_page **event_ring_page; @@ -26,7 +31,7 @@ static u32 synic_event_ring_get_queued_port(u32 sint_index) u32 message; u8 tail; - spages = this_cpu_ptr(mshv_root.synic_pages); + spages = this_cpu_ptr(synic_pages); event_ring_page = &spages->synic_event_ring_page; synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail); @@ -393,7 +398,7 @@ mshv_intercept_isr(struct hv_message *msg) void mshv_isr(void) { - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; struct hv_message *msg; bool handled; @@ -446,7 +451,7 @@ void mshv_isr(void) } } -int mshv_synic_init(unsigned int cpu) +static int mshv_synic_cpu_init(unsigned int cpu) { union hv_synic_simp simp; union hv_synic_siefp siefp; @@ -455,7 +460,7 @@ int mshv_synic_init(unsigned int cpu) union hv_synic_sint sint; #endif union hv_synic_scontrol sctrl; - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page = &spages->synic_event_flags_page; @@ -542,14 +547,14 @@ int mshv_synic_init(unsigned int cpu) return -EFAULT; } -int mshv_synic_cleanup(unsigned int cpu) +static int mshv_synic_cpu_exit(unsigned int cpu) { union hv_synic_sint sint; union hv_synic_simp simp; union hv_synic_siefp siefp; union hv_synic_sirbp sirbp; union hv_synic_scontrol sctrl; - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page = &spages->synic_event_flags_page; @@ -663,3 +668,57 @@ mshv_unregister_doorbell(u64 partition_id, int doorbell_portid) mshv_portid_free(doorbell_portid); } + +static int mshv_synic_reboot_notify(struct notifier_block *nb, + unsigned long code, void *unused) +{ + cpuhp_remove_state(synic_cpuhp_online); + return 0; +} + +static struct notifier_block mshv_synic_reboot_nb = { + .notifier_call = mshv_synic_reboot_notify, +}; + +int __init mshv_synic_init(struct device *dev) +{ + int ret = 0; + + synic_pages = alloc_percpu(struct hv_synic_pages); + if (!synic_pages) { + dev_err(dev, "Failed to allocate percpu synic page\n"); + return -ENOMEM; + } + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", + mshv_synic_cpu_init, + mshv_synic_cpu_exit); + if (ret < 0) { + dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); + goto free_synic_pages; + } + + synic_cpuhp_online = ret; + + if (hv_root_partition()) { + ret = register_reboot_notifier(&mshv_synic_reboot_nb); + if (ret) + goto remove_cpuhp_state; + } + + return 0; + +remove_cpuhp_state: + cpuhp_remove_state(synic_cpuhp_online); +free_synic_pages: + free_percpu(synic_pages); + return ret; +} + +void mshv_synic_cleanup(void) +{ + if (hv_root_partition()) + unregister_reboot_notifier(&mshv_synic_reboot_nb); + cpuhp_remove_state(synic_cpuhp_online); + free_percpu(synic_pages); +} -- 2.34.1
{ "author": "Anirudh Rayabharam <anirudh@anirudhrb.com>", "date": "Mon, 2 Feb 2026 18:27:05 +0000", "thread_id": "20260202182706.648192-2-anirudh@anirudhrb.com.mbox.gz" }
lkml
[PATCH v2 0/2] ARM64 support for doorbell and intercept SINTs
From: "Anirudh Rayabharam (Microsoft)" <anirudh@anirudhrb.com> On x86, the HYPERVISOR_CALLBACK_VECTOR is used to receive synthetic interrupts (SINTs) from the hypervisor for doorbells and intercepts. There is no such vector reserved for arm64. On arm64, the INTID for SINTs should be in the SGI or PPI range. The hypervisor exposes a virtual device in the ACPI that reserves a PPI for this use. Introduce a platform_driver that binds to this ACPI device and obtains the interrupt vector that can be used for SINTs. Changes in v2: Addressed review comments: - Moved more stuff into mshv_synic.c - Code simplifications - Removed unnecessary debug prints v1: https://lore.kernel.org/linux-hyperv/20260128160437.3342167-1-anirudh@anirudhrb.com/ Anirudh Rayabharam (Microsoft) (2): mshv: refactor synic init and cleanup mshv: add arm64 support for doorbell & intercept SINTs drivers/hv/mshv_root.h | 5 +- drivers/hv/mshv_root_main.c | 59 ++------- drivers/hv/mshv_synic.c | 232 ++++++++++++++++++++++++++++++++++-- 3 files changed, 230 insertions(+), 66 deletions(-) -- 2.34.1
From: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> On x86, the HYPERVISOR_CALLBACK_VECTOR is used to receive synthetic interrupts (SINTs) from the hypervisor for doorbells and intercepts. There is no such vector reserved for arm64. On arm64, the INTID for SINTs should be in the SGI or PPI range. The hypervisor exposes a virtual device in the ACPI that reserves a PPI for this use. Introduce a platform_driver that binds to this ACPI device and obtains the interrupt vector that can be used for SINTs. To better unify x86 and arm64 paths, introduce mshv_sint_vector_init() that either registers the platform_driver and obtains the INTID (arm64) or just uses HYPERVISOR_CALLBACK_VECTOR as the interrupt vector (x86). Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> --- drivers/hv/mshv_synic.c | 163 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 156 insertions(+), 7 deletions(-) diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index 98c58755846d..de5fee6e9f29 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -10,17 +10,24 @@ #include <linux/kernel.h> #include <linux/slab.h> #include <linux/mm.h> +#include <linux/interrupt.h> #include <linux/io.h> #include <linux/random.h> #include <linux/cpuhotplug.h> #include <linux/reboot.h> #include <asm/mshyperv.h> +#include <linux/platform_device.h> +#include <linux/acpi.h> #include "mshv_eventfd.h" #include "mshv.h" static int synic_cpuhp_online; static struct hv_synic_pages __percpu *synic_pages; +static int mshv_sint_vector = -1; /* hwirq for the SynIC SINTs */ +#ifndef HYPERVISOR_CALLBACK_VECTOR +static int mshv_sint_irq = -1; /* Linux IRQ for mshv_sint_vector */ +#endif static u32 synic_event_ring_get_queued_port(u32 sint_index) { @@ -456,9 +463,7 @@ static int mshv_synic_cpu_init(unsigned int cpu) union hv_synic_simp simp; union hv_synic_siefp siefp; union hv_synic_sirbp sirbp; -#ifdef HYPERVISOR_CALLBACK_VECTOR union hv_synic_sint sint; -#endif union hv_synic_scontrol sctrl; struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; @@ -501,10 +506,13 @@ static int mshv_synic_cpu_init(unsigned int cpu) hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); -#ifdef HYPERVISOR_CALLBACK_VECTOR +#ifndef HYPERVISOR_CALLBACK_VECTOR + enable_percpu_irq(mshv_sint_irq, 0); +#endif + /* Enable intercepts */ sint.as_uint64 = 0; - sint.vector = HYPERVISOR_CALLBACK_VECTOR; + sint.vector = mshv_sint_vector; sint.masked = false; sint.auto_eoi = hv_recommend_using_aeoi(); hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX, @@ -512,13 +520,12 @@ static int mshv_synic_cpu_init(unsigned int cpu) /* Doorbell SINT */ sint.as_uint64 = 0; - sint.vector = HYPERVISOR_CALLBACK_VECTOR; + sint.vector = mshv_sint_vector; sint.masked = false; sint.as_intercept = 1; sint.auto_eoi = hv_recommend_using_aeoi(); hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_DOORBELL_SINT_INDEX, sint.as_uint64); -#endif /* Enable global synic bit */ sctrl.as_uint64 = hv_get_non_nested_msr(HV_MSR_SCONTROL); @@ -573,6 +580,10 @@ static int mshv_synic_cpu_exit(unsigned int cpu) hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_DOORBELL_SINT_INDEX, sint.as_uint64); +#ifndef HYPERVISOR_CALLBACK_VECTOR + disable_percpu_irq(mshv_sint_irq); +#endif + /* Disable Synic's event ring page */ sirbp.as_uint64 = hv_get_non_nested_msr(HV_MSR_SIRBP); sirbp.sirbp_enabled = false; @@ -680,14 +691,149 @@ static struct notifier_block mshv_synic_reboot_nb = { .notifier_call = mshv_synic_reboot_notify, }; +#ifndef HYPERVISOR_CALLBACK_VECTOR +#ifdef CONFIG_ACPI +static long __percpu *mshv_evt; + +static acpi_status mshv_walk_resources(struct acpi_resource *res, void *ctx) +{ + struct resource r; + + if (res->type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ) { + if (!acpi_dev_resource_interrupt(res, 0, &r)) { + pr_err("Unable to parse MSHV ACPI interrupt\n"); + return AE_ERROR; + } + /* ARM64 INTID */ + mshv_sint_vector = res->data.extended_irq.interrupts[0]; + /* Linux IRQ number */ + mshv_sint_irq = r.start; + } + + return AE_OK; +} + +static irqreturn_t mshv_percpu_isr(int irq, void *dev_id) +{ + mshv_isr(); + return IRQ_HANDLED; +} + +static int mshv_sint_probe(struct platform_device *pdev) +{ + acpi_status result; + int ret; + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); + + result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, + mshv_walk_resources, NULL); + if (ACPI_FAILURE(result)) { + ret = -ENODEV; + goto out_fail; + } + + mshv_evt = alloc_percpu(long); + if (!mshv_evt) { + ret = -ENOMEM; + goto out_fail; + } + + ret = request_percpu_irq(mshv_sint_irq, mshv_percpu_isr, "MSHV", + mshv_evt); + if (ret) + goto free_evt; + + return 0; + +free_evt: + free_percpu(mshv_evt); +out_fail: + mshv_sint_vector = -1; + mshv_sint_irq = -1; + return ret; +} + +static void mshv_sint_remove(struct platform_device *pdev) +{ + free_percpu_irq(mshv_sint_irq, mshv_evt); + free_percpu(mshv_evt); +} +#else +static int mshv_sint_probe(struct platform_device *pdev) +{ + return -ENODEV; +} + +static void mshv_sint_remove(struct platform_device *pdev) +{ +} +#endif + +static const __maybe_unused struct acpi_device_id mshv_sint_device_ids[] = { + {"MSFT1003", 0}, + {"", 0}, +}; + +static struct platform_driver mshv_sint_drv = { + .probe = mshv_sint_probe, + .remove = mshv_sint_remove, + .driver = { + .name = "mshv_sint", + .acpi_match_table = ACPI_PTR(mshv_sint_device_ids), + .probe_type = PROBE_FORCE_SYNCHRONOUS, + }, +}; + +static int __init mshv_sint_vector_init(void) +{ + int ret; + + if (acpi_disabled) + return -ENODEV; + + ret = platform_driver_register(&mshv_sint_drv); + if (ret) + return ret; + + if (mshv_sint_vector == -1 || mshv_sint_irq == -1) { + platform_driver_unregister(&mshv_sint_drv); + return -ENODEV; + } + + return 0; +} + +static void mshv_sint_vector_cleanup(void) +{ + platform_driver_unregister(&mshv_sint_drv); +} +#else /* HYPERVISOR_CALLBACK_VECTOR */ +static int __init mshv_sint_vector_init(void) +{ + mshv_sint_vector = HYPERVISOR_CALLBACK_VECTOR; + return 0; +} + +static void mshv_sint_vector_cleanup(void) +{ +} +#endif /* HYPERVISOR_CALLBACK_VECTOR */ + int __init mshv_synic_init(struct device *dev) { int ret = 0; + ret = mshv_sint_vector_init(); + if (ret) { + dev_err(dev, "Failed to get MSHV SINT vector: %i\n", ret); + return ret; + } + synic_pages = alloc_percpu(struct hv_synic_pages); if (!synic_pages) { dev_err(dev, "Failed to allocate percpu synic page\n"); - return -ENOMEM; + ret = -ENOMEM; + goto sint_vector_cleanup; } ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", @@ -712,6 +858,8 @@ int __init mshv_synic_init(struct device *dev) cpuhp_remove_state(synic_cpuhp_online); free_synic_pages: free_percpu(synic_pages); +sint_vector_cleanup: + mshv_sint_vector_cleanup(); return ret; } @@ -721,4 +869,5 @@ void mshv_synic_cleanup(void) unregister_reboot_notifier(&mshv_synic_reboot_nb); cpuhp_remove_state(synic_cpuhp_online); free_percpu(synic_pages); + mshv_sint_vector_cleanup(); } -- 2.34.1
{ "author": "Anirudh Rayabharam <anirudh@anirudhrb.com>", "date": "Mon, 2 Feb 2026 18:27:06 +0000", "thread_id": "20260202182706.648192-2-anirudh@anirudhrb.com.mbox.gz" }
lkml
[PATCH net-next v4 0/9] dpll: Core improvements and ice E825-C SyncE support
This series introduces Synchronous Ethernet (SyncE) support for the Intel E825-C Ethernet controller. Unlike previous generations where DPLL connections were implicitly assumed, the E825-C architecture relies on the platform firmware (ACPI) to describe the physical connections between the Ethernet controller and external DPLLs (such as the ZL3073x). To accommodate this, the series extends the DPLL subsystem to support firmware node (fwnode) associations, asynchronous discovery via notifiers, and dynamic pin management. Additionally, a significant refactor of the DPLL reference counting logic is included to ensure robustness and debuggability. DPLL Core Extensions: * Firmware Node Association: Pins can now be associated with a struct fwnode_handle after allocation via dpll_pin_fwnode_set(). This allows drivers to link pin objects with their corresponding DT/ACPI nodes. * Asynchronous Notifiers: A raw notifier chain is added to the DPLL core. This allows the Ethernet driver to subscribe to events and react when the platform DPLL driver registers the parent pins, resolving probe ordering dependencies. * Dynamic Indexing: Drivers can now request DPLL_PIN_IDX_UNSPEC to have the core automatically allocate a unique pin index. Reference Counting & Debugging: * Refactor: The reference counting logic in the core is consolidated. Internal list management helpers now automatically handle hold/put operations, removing fragile open-coded logic in the registration paths. * Reference Tracking: A new Kconfig option DPLL_REFCNT_TRACKER is added. This allows developers to instrument and debug reference leaks by recording stack traces for every get/put operation. Driver Updates: * zl3073x: Updated to associate pins with fwnode handles using the new setter and support the 'mux' pin type. * ice: Implements the E825-C specific hardware configuration for SyncE (CGU registers). It utilizes the new notifier and fwnode APIs to dynamically discover and attach to the platform DPLLs. Patch Summary: Patch 1: DPLL Core (fwnode association). Patch 2: Driver zl3073x (Set fwnode). Patch 3-4: DPLL Core (Notifiers and dynamic IDs). Patch 5: Driver zl3073x (Mux type). Patch 6: DPLL Core (Refcount refactor). Patch 7-8: Refcount tracking infrastructure and driver updates. Patch 9: Driver ice (E825-C SyncE logic). Changes in v4: * Fixed documentation and function stub issues found by AI Arkadiusz Kubalewski (1): ice: dpll: Support E825-C SyncE and dynamic pin discovery Ivan Vecera (7): dpll: Allow associating dpll pin with a firmware node dpll: zl3073x: Associate pin with fwnode handle dpll: Support dynamic pin index allocation dpll: zl3073x: Add support for mux pin type dpll: Enhance and consolidate reference counting logic dpll: Add reference count tracking support drivers: Add support for DPLL reference count tracking Petr Oros (1): dpll: Add notifier chain for dpll events drivers/dpll/Kconfig | 15 + drivers/dpll/dpll_core.c | 288 ++++++- drivers/dpll/dpll_core.h | 11 + drivers/dpll/dpll_netlink.c | 6 + drivers/dpll/zl3073x/dpll.c | 15 +- drivers/dpll/zl3073x/dpll.h | 2 + drivers/dpll/zl3073x/prop.c | 2 + drivers/net/ethernet/intel/ice/ice_dpll.c | 755 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 30 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 +++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 16 +- drivers/ptp/ptp_ocp.c | 18 +- include/linux/dpll.h | 59 +- 18 files changed, 1347 insertions(+), 150 deletions(-) -- 2.52.0
Extend the DPLL core to support associating a DPLL pin with a firmware node. This association is required to allow other subsystems (such as network drivers) to locate and request specific DPLL pins defined in the Device Tree or ACPI. * Add a .fwnode field to the struct dpll_pin * Introduce dpll_pin_fwnode_set() helper to allow the provider driver to associate a pin with a fwnode after the pin has been allocated * Introduce fwnode_dpll_pin_find() helper to allow consumers to search for a registered DPLL pin using its associated fwnode handle * Ensure the fwnode reference is properly released in dpll_pin_put() Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> Signed-off-by: Ivan Vecera <ivecera@redhat.com> --- v4: * fixed fwnode_dpll_pin_find() return value description --- drivers/dpll/dpll_core.c | 49 ++++++++++++++++++++++++++++++++++++++++ drivers/dpll/dpll_core.h | 2 ++ include/linux/dpll.h | 11 +++++++++ 3 files changed, 62 insertions(+) diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index 8879a72351561..f04ed7195cadd 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -10,6 +10,7 @@ #include <linux/device.h> #include <linux/err.h> +#include <linux/property.h> #include <linux/slab.h> #include <linux/string.h> @@ -595,12 +596,60 @@ void dpll_pin_put(struct dpll_pin *pin) xa_destroy(&pin->parent_refs); xa_destroy(&pin->ref_sync_pins); dpll_pin_prop_free(&pin->prop); + fwnode_handle_put(pin->fwnode); kfree_rcu(pin, rcu); } mutex_unlock(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_pin_put); +/** + * dpll_pin_fwnode_set - set dpll pin firmware node reference + * @pin: pointer to a dpll pin + * @fwnode: firmware node handle + * + * Set firmware node handle for the given dpll pin. + */ +void dpll_pin_fwnode_set(struct dpll_pin *pin, struct fwnode_handle *fwnode) +{ + mutex_lock(&dpll_lock); + fwnode_handle_put(pin->fwnode); /* Drop fwnode previously set */ + pin->fwnode = fwnode_handle_get(fwnode); + mutex_unlock(&dpll_lock); +} +EXPORT_SYMBOL_GPL(dpll_pin_fwnode_set); + +/** + * fwnode_dpll_pin_find - find dpll pin by firmware node reference + * @fwnode: reference to firmware node + * + * Get existing object of a pin that is associated with given firmware node + * reference. + * + * Context: Acquires a lock (dpll_lock) + * Return: + * * valid dpll_pin pointer on success + * * NULL when no such pin exists + */ +struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode) +{ + struct dpll_pin *pin, *ret = NULL; + unsigned long index; + + mutex_lock(&dpll_lock); + xa_for_each(&dpll_pin_xa, index, pin) { + if (pin->fwnode == fwnode) { + ret = pin; + refcount_inc(&ret->refcount); + break; + } + } + mutex_unlock(&dpll_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(fwnode_dpll_pin_find); + static int __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv, void *cookie) diff --git a/drivers/dpll/dpll_core.h b/drivers/dpll/dpll_core.h index 8ce969bbeb64e..d3e17ff0ecef0 100644 --- a/drivers/dpll/dpll_core.h +++ b/drivers/dpll/dpll_core.h @@ -42,6 +42,7 @@ struct dpll_device { * @pin_idx: index of a pin given by dev driver * @clock_id: clock_id of creator * @module: module of creator + * @fwnode: optional reference to firmware node * @dpll_refs: hold referencees to dplls pin was registered with * @parent_refs: hold references to parent pins pin was registered with * @ref_sync_pins: hold references to pins for Reference SYNC feature @@ -54,6 +55,7 @@ struct dpll_pin { u32 pin_idx; u64 clock_id; struct module *module; + struct fwnode_handle *fwnode; struct xarray dpll_refs; struct xarray parent_refs; struct xarray ref_sync_pins; diff --git a/include/linux/dpll.h b/include/linux/dpll.h index c6d0248fa5273..f2e8660e90cdf 100644 --- a/include/linux/dpll.h +++ b/include/linux/dpll.h @@ -16,6 +16,7 @@ struct dpll_device; struct dpll_pin; struct dpll_pin_esync; +struct fwnode_handle; struct dpll_device_ops { int (*mode_get)(const struct dpll_device *dpll, void *dpll_priv, @@ -178,6 +179,8 @@ void dpll_netdev_pin_clear(struct net_device *dev); size_t dpll_netdev_pin_handle_size(const struct net_device *dev); int dpll_netdev_add_pin_handle(struct sk_buff *msg, const struct net_device *dev); + +struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode); #else static inline void dpll_netdev_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin) { } @@ -193,6 +196,12 @@ dpll_netdev_add_pin_handle(struct sk_buff *msg, const struct net_device *dev) { return 0; } + +static inline struct dpll_pin * +fwnode_dpll_pin_find(struct fwnode_handle *fwnode) +{ + return NULL; +} #endif struct dpll_device * @@ -218,6 +227,8 @@ void dpll_pin_unregister(struct dpll_device *dpll, struct dpll_pin *pin, void dpll_pin_put(struct dpll_pin *pin); +void dpll_pin_fwnode_set(struct dpll_pin *pin, struct fwnode_handle *fwnode); + int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv); -- 2.52.0
{ "author": "Ivan Vecera <ivecera@redhat.com>", "date": "Mon, 2 Feb 2026 18:16:30 +0100", "thread_id": "20260202171638.17427-1-ivecera@redhat.com.mbox.gz" }
lkml
[PATCH net-next v4 0/9] dpll: Core improvements and ice E825-C SyncE support
This series introduces Synchronous Ethernet (SyncE) support for the Intel E825-C Ethernet controller. Unlike previous generations where DPLL connections were implicitly assumed, the E825-C architecture relies on the platform firmware (ACPI) to describe the physical connections between the Ethernet controller and external DPLLs (such as the ZL3073x). To accommodate this, the series extends the DPLL subsystem to support firmware node (fwnode) associations, asynchronous discovery via notifiers, and dynamic pin management. Additionally, a significant refactor of the DPLL reference counting logic is included to ensure robustness and debuggability. DPLL Core Extensions: * Firmware Node Association: Pins can now be associated with a struct fwnode_handle after allocation via dpll_pin_fwnode_set(). This allows drivers to link pin objects with their corresponding DT/ACPI nodes. * Asynchronous Notifiers: A raw notifier chain is added to the DPLL core. This allows the Ethernet driver to subscribe to events and react when the platform DPLL driver registers the parent pins, resolving probe ordering dependencies. * Dynamic Indexing: Drivers can now request DPLL_PIN_IDX_UNSPEC to have the core automatically allocate a unique pin index. Reference Counting & Debugging: * Refactor: The reference counting logic in the core is consolidated. Internal list management helpers now automatically handle hold/put operations, removing fragile open-coded logic in the registration paths. * Reference Tracking: A new Kconfig option DPLL_REFCNT_TRACKER is added. This allows developers to instrument and debug reference leaks by recording stack traces for every get/put operation. Driver Updates: * zl3073x: Updated to associate pins with fwnode handles using the new setter and support the 'mux' pin type. * ice: Implements the E825-C specific hardware configuration for SyncE (CGU registers). It utilizes the new notifier and fwnode APIs to dynamically discover and attach to the platform DPLLs. Patch Summary: Patch 1: DPLL Core (fwnode association). Patch 2: Driver zl3073x (Set fwnode). Patch 3-4: DPLL Core (Notifiers and dynamic IDs). Patch 5: Driver zl3073x (Mux type). Patch 6: DPLL Core (Refcount refactor). Patch 7-8: Refcount tracking infrastructure and driver updates. Patch 9: Driver ice (E825-C SyncE logic). Changes in v4: * Fixed documentation and function stub issues found by AI Arkadiusz Kubalewski (1): ice: dpll: Support E825-C SyncE and dynamic pin discovery Ivan Vecera (7): dpll: Allow associating dpll pin with a firmware node dpll: zl3073x: Associate pin with fwnode handle dpll: Support dynamic pin index allocation dpll: zl3073x: Add support for mux pin type dpll: Enhance and consolidate reference counting logic dpll: Add reference count tracking support drivers: Add support for DPLL reference count tracking Petr Oros (1): dpll: Add notifier chain for dpll events drivers/dpll/Kconfig | 15 + drivers/dpll/dpll_core.c | 288 ++++++- drivers/dpll/dpll_core.h | 11 + drivers/dpll/dpll_netlink.c | 6 + drivers/dpll/zl3073x/dpll.c | 15 +- drivers/dpll/zl3073x/dpll.h | 2 + drivers/dpll/zl3073x/prop.c | 2 + drivers/net/ethernet/intel/ice/ice_dpll.c | 755 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 30 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 +++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 16 +- drivers/ptp/ptp_ocp.c | 18 +- include/linux/dpll.h | 59 +- 18 files changed, 1347 insertions(+), 150 deletions(-) -- 2.52.0
Associate the registered DPLL pin with its firmware node by calling dpll_pin_fwnode_set(). This links the created pin object to its corresponding DT/ACPI node in the DPLL core. Consequently, this enables consumer drivers (such as network drivers) to locate and request this specific pin using the fwnode_dpll_pin_find() helper. Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> --- drivers/dpll/zl3073x/dpll.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/dpll/zl3073x/dpll.c b/drivers/dpll/zl3073x/dpll.c index 7d8ed948b9706..9eed21088adac 100644 --- a/drivers/dpll/zl3073x/dpll.c +++ b/drivers/dpll/zl3073x/dpll.c @@ -1485,6 +1485,7 @@ zl3073x_dpll_pin_register(struct zl3073x_dpll_pin *pin, u32 index) rc = PTR_ERR(pin->dpll_pin); goto err_pin_get; } + dpll_pin_fwnode_set(pin->dpll_pin, props->fwnode); if (zl3073x_dpll_is_input_pin(pin)) ops = &zl3073x_dpll_input_pin_ops; -- 2.52.0
{ "author": "Ivan Vecera <ivecera@redhat.com>", "date": "Mon, 2 Feb 2026 18:16:31 +0100", "thread_id": "20260202171638.17427-1-ivecera@redhat.com.mbox.gz" }
lkml
[PATCH net-next v4 0/9] dpll: Core improvements and ice E825-C SyncE support
This series introduces Synchronous Ethernet (SyncE) support for the Intel E825-C Ethernet controller. Unlike previous generations where DPLL connections were implicitly assumed, the E825-C architecture relies on the platform firmware (ACPI) to describe the physical connections between the Ethernet controller and external DPLLs (such as the ZL3073x). To accommodate this, the series extends the DPLL subsystem to support firmware node (fwnode) associations, asynchronous discovery via notifiers, and dynamic pin management. Additionally, a significant refactor of the DPLL reference counting logic is included to ensure robustness and debuggability. DPLL Core Extensions: * Firmware Node Association: Pins can now be associated with a struct fwnode_handle after allocation via dpll_pin_fwnode_set(). This allows drivers to link pin objects with their corresponding DT/ACPI nodes. * Asynchronous Notifiers: A raw notifier chain is added to the DPLL core. This allows the Ethernet driver to subscribe to events and react when the platform DPLL driver registers the parent pins, resolving probe ordering dependencies. * Dynamic Indexing: Drivers can now request DPLL_PIN_IDX_UNSPEC to have the core automatically allocate a unique pin index. Reference Counting & Debugging: * Refactor: The reference counting logic in the core is consolidated. Internal list management helpers now automatically handle hold/put operations, removing fragile open-coded logic in the registration paths. * Reference Tracking: A new Kconfig option DPLL_REFCNT_TRACKER is added. This allows developers to instrument and debug reference leaks by recording stack traces for every get/put operation. Driver Updates: * zl3073x: Updated to associate pins with fwnode handles using the new setter and support the 'mux' pin type. * ice: Implements the E825-C specific hardware configuration for SyncE (CGU registers). It utilizes the new notifier and fwnode APIs to dynamically discover and attach to the platform DPLLs. Patch Summary: Patch 1: DPLL Core (fwnode association). Patch 2: Driver zl3073x (Set fwnode). Patch 3-4: DPLL Core (Notifiers and dynamic IDs). Patch 5: Driver zl3073x (Mux type). Patch 6: DPLL Core (Refcount refactor). Patch 7-8: Refcount tracking infrastructure and driver updates. Patch 9: Driver ice (E825-C SyncE logic). Changes in v4: * Fixed documentation and function stub issues found by AI Arkadiusz Kubalewski (1): ice: dpll: Support E825-C SyncE and dynamic pin discovery Ivan Vecera (7): dpll: Allow associating dpll pin with a firmware node dpll: zl3073x: Associate pin with fwnode handle dpll: Support dynamic pin index allocation dpll: zl3073x: Add support for mux pin type dpll: Enhance and consolidate reference counting logic dpll: Add reference count tracking support drivers: Add support for DPLL reference count tracking Petr Oros (1): dpll: Add notifier chain for dpll events drivers/dpll/Kconfig | 15 + drivers/dpll/dpll_core.c | 288 ++++++- drivers/dpll/dpll_core.h | 11 + drivers/dpll/dpll_netlink.c | 6 + drivers/dpll/zl3073x/dpll.c | 15 +- drivers/dpll/zl3073x/dpll.h | 2 + drivers/dpll/zl3073x/prop.c | 2 + drivers/net/ethernet/intel/ice/ice_dpll.c | 755 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 30 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 +++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 16 +- drivers/ptp/ptp_ocp.c | 18 +- include/linux/dpll.h | 59 +- 18 files changed, 1347 insertions(+), 150 deletions(-) -- 2.52.0
From: Petr Oros <poros@redhat.com> Currently, the DPLL subsystem reports events (creation, deletion, changes) to userspace via Netlink. However, there is no mechanism for other kernel components to be notified of these events directly. Add a raw notifier chain to the DPLL core protected by dpll_lock. This allows other kernel subsystems or drivers to register callbacks and receive notifications when DPLL devices or pins are created, deleted, or modified. Define the following: - Registration helpers: {,un}register_dpll_notifier() - Event types: DPLL_DEVICE_CREATED, DPLL_PIN_CREATED, etc. - Context structures: dpll_{device,pin}_notifier_info to pass relevant data to the listeners. The notification chain is invoked alongside the existing Netlink event generation to ensure in-kernel listeners are kept in sync with the subsystem state. Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> Co-developed-by: Ivan Vecera <ivecera@redhat.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> Signed-off-by: Petr Oros <poros@redhat.com> --- drivers/dpll/dpll_core.c | 57 +++++++++++++++++++++++++++++++++++++ drivers/dpll/dpll_core.h | 4 +++ drivers/dpll/dpll_netlink.c | 6 ++++ include/linux/dpll.h | 29 +++++++++++++++++++ 4 files changed, 96 insertions(+) diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index f04ed7195cadd..b05fe2ba46d91 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -23,6 +23,8 @@ DEFINE_MUTEX(dpll_lock); DEFINE_XARRAY_FLAGS(dpll_device_xa, XA_FLAGS_ALLOC); DEFINE_XARRAY_FLAGS(dpll_pin_xa, XA_FLAGS_ALLOC); +static RAW_NOTIFIER_HEAD(dpll_notifier_chain); + static u32 dpll_device_xa_id; static u32 dpll_pin_xa_id; @@ -46,6 +48,39 @@ struct dpll_pin_registration { void *cookie; }; +static int call_dpll_notifiers(unsigned long action, void *info) +{ + lockdep_assert_held(&dpll_lock); + return raw_notifier_call_chain(&dpll_notifier_chain, action, info); +} + +void dpll_device_notify(struct dpll_device *dpll, unsigned long action) +{ + struct dpll_device_notifier_info info = { + .dpll = dpll, + .id = dpll->id, + .idx = dpll->device_idx, + .clock_id = dpll->clock_id, + .type = dpll->type, + }; + + call_dpll_notifiers(action, &info); +} + +void dpll_pin_notify(struct dpll_pin *pin, unsigned long action) +{ + struct dpll_pin_notifier_info info = { + .pin = pin, + .id = pin->id, + .idx = pin->pin_idx, + .clock_id = pin->clock_id, + .fwnode = pin->fwnode, + .prop = &pin->prop, + }; + + call_dpll_notifiers(action, &info); +} + struct dpll_device *dpll_device_get_by_id(int id) { if (xa_get_mark(&dpll_device_xa, id, DPLL_REGISTERED)) @@ -539,6 +574,28 @@ void dpll_netdev_pin_clear(struct net_device *dev) } EXPORT_SYMBOL(dpll_netdev_pin_clear); +int register_dpll_notifier(struct notifier_block *nb) +{ + int ret; + + mutex_lock(&dpll_lock); + ret = raw_notifier_chain_register(&dpll_notifier_chain, nb); + mutex_unlock(&dpll_lock); + return ret; +} +EXPORT_SYMBOL_GPL(register_dpll_notifier); + +int unregister_dpll_notifier(struct notifier_block *nb) +{ + int ret; + + mutex_lock(&dpll_lock); + ret = raw_notifier_chain_unregister(&dpll_notifier_chain, nb); + mutex_unlock(&dpll_lock); + return ret; +} +EXPORT_SYMBOL_GPL(unregister_dpll_notifier); + /** * dpll_pin_get - find existing or create new dpll pin * @clock_id: clock_id of creator diff --git a/drivers/dpll/dpll_core.h b/drivers/dpll/dpll_core.h index d3e17ff0ecef0..b7b4bb251f739 100644 --- a/drivers/dpll/dpll_core.h +++ b/drivers/dpll/dpll_core.h @@ -91,4 +91,8 @@ struct dpll_pin_ref *dpll_xa_ref_dpll_first(struct xarray *xa_refs); extern struct xarray dpll_device_xa; extern struct xarray dpll_pin_xa; extern struct mutex dpll_lock; + +void dpll_device_notify(struct dpll_device *dpll, unsigned long action); +void dpll_pin_notify(struct dpll_pin *pin, unsigned long action); + #endif diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c index 904199ddd1781..83cbd64abf5a4 100644 --- a/drivers/dpll/dpll_netlink.c +++ b/drivers/dpll/dpll_netlink.c @@ -761,17 +761,20 @@ dpll_device_event_send(enum dpll_cmd event, struct dpll_device *dpll) int dpll_device_create_ntf(struct dpll_device *dpll) { + dpll_device_notify(dpll, DPLL_DEVICE_CREATED); return dpll_device_event_send(DPLL_CMD_DEVICE_CREATE_NTF, dpll); } int dpll_device_delete_ntf(struct dpll_device *dpll) { + dpll_device_notify(dpll, DPLL_DEVICE_DELETED); return dpll_device_event_send(DPLL_CMD_DEVICE_DELETE_NTF, dpll); } static int __dpll_device_change_ntf(struct dpll_device *dpll) { + dpll_device_notify(dpll, DPLL_DEVICE_CHANGED); return dpll_device_event_send(DPLL_CMD_DEVICE_CHANGE_NTF, dpll); } @@ -829,16 +832,19 @@ dpll_pin_event_send(enum dpll_cmd event, struct dpll_pin *pin) int dpll_pin_create_ntf(struct dpll_pin *pin) { + dpll_pin_notify(pin, DPLL_PIN_CREATED); return dpll_pin_event_send(DPLL_CMD_PIN_CREATE_NTF, pin); } int dpll_pin_delete_ntf(struct dpll_pin *pin) { + dpll_pin_notify(pin, DPLL_PIN_DELETED); return dpll_pin_event_send(DPLL_CMD_PIN_DELETE_NTF, pin); } int __dpll_pin_change_ntf(struct dpll_pin *pin) { + dpll_pin_notify(pin, DPLL_PIN_CHANGED); return dpll_pin_event_send(DPLL_CMD_PIN_CHANGE_NTF, pin); } diff --git a/include/linux/dpll.h b/include/linux/dpll.h index f2e8660e90cdf..8ed90dfc65f05 100644 --- a/include/linux/dpll.h +++ b/include/linux/dpll.h @@ -11,6 +11,7 @@ #include <linux/device.h> #include <linux/netlink.h> #include <linux/netdevice.h> +#include <linux/notifier.h> #include <linux/rtnetlink.h> struct dpll_device; @@ -172,6 +173,30 @@ struct dpll_pin_properties { u32 phase_gran; }; +#define DPLL_DEVICE_CREATED 1 +#define DPLL_DEVICE_DELETED 2 +#define DPLL_DEVICE_CHANGED 3 +#define DPLL_PIN_CREATED 4 +#define DPLL_PIN_DELETED 5 +#define DPLL_PIN_CHANGED 6 + +struct dpll_device_notifier_info { + struct dpll_device *dpll; + u32 id; + u32 idx; + u64 clock_id; + enum dpll_type type; +}; + +struct dpll_pin_notifier_info { + struct dpll_pin *pin; + u32 id; + u32 idx; + u64 clock_id; + const struct fwnode_handle *fwnode; + const struct dpll_pin_properties *prop; +}; + #if IS_ENABLED(CONFIG_DPLL) void dpll_netdev_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin); void dpll_netdev_pin_clear(struct net_device *dev); @@ -242,4 +267,8 @@ int dpll_device_change_ntf(struct dpll_device *dpll); int dpll_pin_change_ntf(struct dpll_pin *pin); +int register_dpll_notifier(struct notifier_block *nb); + +int unregister_dpll_notifier(struct notifier_block *nb); + #endif -- 2.52.0
{ "author": "Ivan Vecera <ivecera@redhat.com>", "date": "Mon, 2 Feb 2026 18:16:32 +0100", "thread_id": "20260202171638.17427-1-ivecera@redhat.com.mbox.gz" }
lkml
[PATCH net-next v4 0/9] dpll: Core improvements and ice E825-C SyncE support
This series introduces Synchronous Ethernet (SyncE) support for the Intel E825-C Ethernet controller. Unlike previous generations where DPLL connections were implicitly assumed, the E825-C architecture relies on the platform firmware (ACPI) to describe the physical connections between the Ethernet controller and external DPLLs (such as the ZL3073x). To accommodate this, the series extends the DPLL subsystem to support firmware node (fwnode) associations, asynchronous discovery via notifiers, and dynamic pin management. Additionally, a significant refactor of the DPLL reference counting logic is included to ensure robustness and debuggability. DPLL Core Extensions: * Firmware Node Association: Pins can now be associated with a struct fwnode_handle after allocation via dpll_pin_fwnode_set(). This allows drivers to link pin objects with their corresponding DT/ACPI nodes. * Asynchronous Notifiers: A raw notifier chain is added to the DPLL core. This allows the Ethernet driver to subscribe to events and react when the platform DPLL driver registers the parent pins, resolving probe ordering dependencies. * Dynamic Indexing: Drivers can now request DPLL_PIN_IDX_UNSPEC to have the core automatically allocate a unique pin index. Reference Counting & Debugging: * Refactor: The reference counting logic in the core is consolidated. Internal list management helpers now automatically handle hold/put operations, removing fragile open-coded logic in the registration paths. * Reference Tracking: A new Kconfig option DPLL_REFCNT_TRACKER is added. This allows developers to instrument and debug reference leaks by recording stack traces for every get/put operation. Driver Updates: * zl3073x: Updated to associate pins with fwnode handles using the new setter and support the 'mux' pin type. * ice: Implements the E825-C specific hardware configuration for SyncE (CGU registers). It utilizes the new notifier and fwnode APIs to dynamically discover and attach to the platform DPLLs. Patch Summary: Patch 1: DPLL Core (fwnode association). Patch 2: Driver zl3073x (Set fwnode). Patch 3-4: DPLL Core (Notifiers and dynamic IDs). Patch 5: Driver zl3073x (Mux type). Patch 6: DPLL Core (Refcount refactor). Patch 7-8: Refcount tracking infrastructure and driver updates. Patch 9: Driver ice (E825-C SyncE logic). Changes in v4: * Fixed documentation and function stub issues found by AI Arkadiusz Kubalewski (1): ice: dpll: Support E825-C SyncE and dynamic pin discovery Ivan Vecera (7): dpll: Allow associating dpll pin with a firmware node dpll: zl3073x: Associate pin with fwnode handle dpll: Support dynamic pin index allocation dpll: zl3073x: Add support for mux pin type dpll: Enhance and consolidate reference counting logic dpll: Add reference count tracking support drivers: Add support for DPLL reference count tracking Petr Oros (1): dpll: Add notifier chain for dpll events drivers/dpll/Kconfig | 15 + drivers/dpll/dpll_core.c | 288 ++++++- drivers/dpll/dpll_core.h | 11 + drivers/dpll/dpll_netlink.c | 6 + drivers/dpll/zl3073x/dpll.c | 15 +- drivers/dpll/zl3073x/dpll.h | 2 + drivers/dpll/zl3073x/prop.c | 2 + drivers/net/ethernet/intel/ice/ice_dpll.c | 755 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 30 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 +++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 16 +- drivers/ptp/ptp_ocp.c | 18 +- include/linux/dpll.h | 59 +- 18 files changed, 1347 insertions(+), 150 deletions(-) -- 2.52.0
Allow drivers to register DPLL pins without manually specifying a pin index. Currently, drivers must provide a unique pin index when calling dpll_pin_get(). This works well for hardware-mapped pins but creates friction for drivers handling virtual pins or those without a strict hardware indexing scheme. Introduce DPLL_PIN_IDX_UNSPEC (U32_MAX). When a driver passes this value as the pin index: 1. The core allocates a unique index using an IDA 2. The allocated index is mapped to a range starting above `INT_MAX` This separation ensures that dynamically allocated indices never collide with standard driver-provided hardware indices, which are assumed to be within the `0` to `INT_MAX` range. The index is automatically freed when the pin is released in dpll_pin_put(). Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> --- v2: * fixed integer overflow in dpll_pin_idx_free() --- drivers/dpll/dpll_core.c | 48 ++++++++++++++++++++++++++++++++++++++-- include/linux/dpll.h | 2 ++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index b05fe2ba46d91..59081cf2c73ae 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -10,6 +10,7 @@ #include <linux/device.h> #include <linux/err.h> +#include <linux/idr.h> #include <linux/property.h> #include <linux/slab.h> #include <linux/string.h> @@ -24,6 +25,7 @@ DEFINE_XARRAY_FLAGS(dpll_device_xa, XA_FLAGS_ALLOC); DEFINE_XARRAY_FLAGS(dpll_pin_xa, XA_FLAGS_ALLOC); static RAW_NOTIFIER_HEAD(dpll_notifier_chain); +static DEFINE_IDA(dpll_pin_idx_ida); static u32 dpll_device_xa_id; static u32 dpll_pin_xa_id; @@ -464,6 +466,36 @@ void dpll_device_unregister(struct dpll_device *dpll, } EXPORT_SYMBOL_GPL(dpll_device_unregister); +static int dpll_pin_idx_alloc(u32 *pin_idx) +{ + int ret; + + if (!pin_idx) + return -EINVAL; + + /* Alloc unique number from IDA. Number belongs to <0, INT_MAX> range */ + ret = ida_alloc(&dpll_pin_idx_ida, GFP_KERNEL); + if (ret < 0) + return ret; + + /* Map the value to dynamic pin index range <INT_MAX+1, U32_MAX> */ + *pin_idx = (u32)ret + INT_MAX + 1; + + return 0; +} + +static void dpll_pin_idx_free(u32 pin_idx) +{ + if (pin_idx <= INT_MAX) + return; /* Not a dynamic pin index */ + + /* Map the index value from dynamic pin index range to IDA range and + * free it. + */ + pin_idx -= (u32)INT_MAX + 1; + ida_free(&dpll_pin_idx_ida, pin_idx); +} + static void dpll_pin_prop_free(struct dpll_pin_properties *prop) { kfree(prop->package_label); @@ -521,9 +553,18 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module *module, struct dpll_pin *pin; int ret; + if (pin_idx == DPLL_PIN_IDX_UNSPEC) { + ret = dpll_pin_idx_alloc(&pin_idx); + if (ret) + return ERR_PTR(ret); + } else if (pin_idx > INT_MAX) { + return ERR_PTR(-EINVAL); + } pin = kzalloc(sizeof(*pin), GFP_KERNEL); - if (!pin) - return ERR_PTR(-ENOMEM); + if (!pin) { + ret = -ENOMEM; + goto err_pin_alloc; + } pin->pin_idx = pin_idx; pin->clock_id = clock_id; pin->module = module; @@ -551,6 +592,8 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module *module, dpll_pin_prop_free(&pin->prop); err_pin_prop: kfree(pin); +err_pin_alloc: + dpll_pin_idx_free(pin_idx); return ERR_PTR(ret); } @@ -654,6 +697,7 @@ void dpll_pin_put(struct dpll_pin *pin) xa_destroy(&pin->ref_sync_pins); dpll_pin_prop_free(&pin->prop); fwnode_handle_put(pin->fwnode); + dpll_pin_idx_free(pin->pin_idx); kfree_rcu(pin, rcu); } mutex_unlock(&dpll_lock); diff --git a/include/linux/dpll.h b/include/linux/dpll.h index 8ed90dfc65f05..8fff048131f1d 100644 --- a/include/linux/dpll.h +++ b/include/linux/dpll.h @@ -240,6 +240,8 @@ int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, void dpll_device_unregister(struct dpll_device *dpll, const struct dpll_device_ops *ops, void *priv); +#define DPLL_PIN_IDX_UNSPEC U32_MAX + struct dpll_pin * dpll_pin_get(u64 clock_id, u32 dev_driver_id, struct module *module, const struct dpll_pin_properties *prop); -- 2.52.0
{ "author": "Ivan Vecera <ivecera@redhat.com>", "date": "Mon, 2 Feb 2026 18:16:33 +0100", "thread_id": "20260202171638.17427-1-ivecera@redhat.com.mbox.gz" }
lkml
[PATCH net-next v4 0/9] dpll: Core improvements and ice E825-C SyncE support
This series introduces Synchronous Ethernet (SyncE) support for the Intel E825-C Ethernet controller. Unlike previous generations where DPLL connections were implicitly assumed, the E825-C architecture relies on the platform firmware (ACPI) to describe the physical connections between the Ethernet controller and external DPLLs (such as the ZL3073x). To accommodate this, the series extends the DPLL subsystem to support firmware node (fwnode) associations, asynchronous discovery via notifiers, and dynamic pin management. Additionally, a significant refactor of the DPLL reference counting logic is included to ensure robustness and debuggability. DPLL Core Extensions: * Firmware Node Association: Pins can now be associated with a struct fwnode_handle after allocation via dpll_pin_fwnode_set(). This allows drivers to link pin objects with their corresponding DT/ACPI nodes. * Asynchronous Notifiers: A raw notifier chain is added to the DPLL core. This allows the Ethernet driver to subscribe to events and react when the platform DPLL driver registers the parent pins, resolving probe ordering dependencies. * Dynamic Indexing: Drivers can now request DPLL_PIN_IDX_UNSPEC to have the core automatically allocate a unique pin index. Reference Counting & Debugging: * Refactor: The reference counting logic in the core is consolidated. Internal list management helpers now automatically handle hold/put operations, removing fragile open-coded logic in the registration paths. * Reference Tracking: A new Kconfig option DPLL_REFCNT_TRACKER is added. This allows developers to instrument and debug reference leaks by recording stack traces for every get/put operation. Driver Updates: * zl3073x: Updated to associate pins with fwnode handles using the new setter and support the 'mux' pin type. * ice: Implements the E825-C specific hardware configuration for SyncE (CGU registers). It utilizes the new notifier and fwnode APIs to dynamically discover and attach to the platform DPLLs. Patch Summary: Patch 1: DPLL Core (fwnode association). Patch 2: Driver zl3073x (Set fwnode). Patch 3-4: DPLL Core (Notifiers and dynamic IDs). Patch 5: Driver zl3073x (Mux type). Patch 6: DPLL Core (Refcount refactor). Patch 7-8: Refcount tracking infrastructure and driver updates. Patch 9: Driver ice (E825-C SyncE logic). Changes in v4: * Fixed documentation and function stub issues found by AI Arkadiusz Kubalewski (1): ice: dpll: Support E825-C SyncE and dynamic pin discovery Ivan Vecera (7): dpll: Allow associating dpll pin with a firmware node dpll: zl3073x: Associate pin with fwnode handle dpll: Support dynamic pin index allocation dpll: zl3073x: Add support for mux pin type dpll: Enhance and consolidate reference counting logic dpll: Add reference count tracking support drivers: Add support for DPLL reference count tracking Petr Oros (1): dpll: Add notifier chain for dpll events drivers/dpll/Kconfig | 15 + drivers/dpll/dpll_core.c | 288 ++++++- drivers/dpll/dpll_core.h | 11 + drivers/dpll/dpll_netlink.c | 6 + drivers/dpll/zl3073x/dpll.c | 15 +- drivers/dpll/zl3073x/dpll.h | 2 + drivers/dpll/zl3073x/prop.c | 2 + drivers/net/ethernet/intel/ice/ice_dpll.c | 755 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 30 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 +++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 16 +- drivers/ptp/ptp_ocp.c | 18 +- include/linux/dpll.h | 59 +- 18 files changed, 1347 insertions(+), 150 deletions(-) -- 2.52.0
Add parsing for the "mux" string in the 'connection-type' pin property mapping it to DPLL_PIN_TYPE_MUX. Recognizing this type in the driver allows these pins to be taken as parent pins for pin-on-pin pins coming from different modules (e.g. network drivers). Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> --- drivers/dpll/zl3073x/prop.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/dpll/zl3073x/prop.c b/drivers/dpll/zl3073x/prop.c index 4ed153087570b..ad1f099cbe2b5 100644 --- a/drivers/dpll/zl3073x/prop.c +++ b/drivers/dpll/zl3073x/prop.c @@ -249,6 +249,8 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev, props->dpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR; else if (!strcmp(type, "synce")) props->dpll_props.type = DPLL_PIN_TYPE_SYNCE_ETH_PORT; + else if (!strcmp(type, "mux")) + props->dpll_props.type = DPLL_PIN_TYPE_MUX; else dev_warn(zldev->dev, "Unknown or unsupported pin type '%s'\n", -- 2.52.0
{ "author": "Ivan Vecera <ivecera@redhat.com>", "date": "Mon, 2 Feb 2026 18:16:34 +0100", "thread_id": "20260202171638.17427-1-ivecera@redhat.com.mbox.gz" }
lkml
[PATCH net-next v4 0/9] dpll: Core improvements and ice E825-C SyncE support
This series introduces Synchronous Ethernet (SyncE) support for the Intel E825-C Ethernet controller. Unlike previous generations where DPLL connections were implicitly assumed, the E825-C architecture relies on the platform firmware (ACPI) to describe the physical connections between the Ethernet controller and external DPLLs (such as the ZL3073x). To accommodate this, the series extends the DPLL subsystem to support firmware node (fwnode) associations, asynchronous discovery via notifiers, and dynamic pin management. Additionally, a significant refactor of the DPLL reference counting logic is included to ensure robustness and debuggability. DPLL Core Extensions: * Firmware Node Association: Pins can now be associated with a struct fwnode_handle after allocation via dpll_pin_fwnode_set(). This allows drivers to link pin objects with their corresponding DT/ACPI nodes. * Asynchronous Notifiers: A raw notifier chain is added to the DPLL core. This allows the Ethernet driver to subscribe to events and react when the platform DPLL driver registers the parent pins, resolving probe ordering dependencies. * Dynamic Indexing: Drivers can now request DPLL_PIN_IDX_UNSPEC to have the core automatically allocate a unique pin index. Reference Counting & Debugging: * Refactor: The reference counting logic in the core is consolidated. Internal list management helpers now automatically handle hold/put operations, removing fragile open-coded logic in the registration paths. * Reference Tracking: A new Kconfig option DPLL_REFCNT_TRACKER is added. This allows developers to instrument and debug reference leaks by recording stack traces for every get/put operation. Driver Updates: * zl3073x: Updated to associate pins with fwnode handles using the new setter and support the 'mux' pin type. * ice: Implements the E825-C specific hardware configuration for SyncE (CGU registers). It utilizes the new notifier and fwnode APIs to dynamically discover and attach to the platform DPLLs. Patch Summary: Patch 1: DPLL Core (fwnode association). Patch 2: Driver zl3073x (Set fwnode). Patch 3-4: DPLL Core (Notifiers and dynamic IDs). Patch 5: Driver zl3073x (Mux type). Patch 6: DPLL Core (Refcount refactor). Patch 7-8: Refcount tracking infrastructure and driver updates. Patch 9: Driver ice (E825-C SyncE logic). Changes in v4: * Fixed documentation and function stub issues found by AI Arkadiusz Kubalewski (1): ice: dpll: Support E825-C SyncE and dynamic pin discovery Ivan Vecera (7): dpll: Allow associating dpll pin with a firmware node dpll: zl3073x: Associate pin with fwnode handle dpll: Support dynamic pin index allocation dpll: zl3073x: Add support for mux pin type dpll: Enhance and consolidate reference counting logic dpll: Add reference count tracking support drivers: Add support for DPLL reference count tracking Petr Oros (1): dpll: Add notifier chain for dpll events drivers/dpll/Kconfig | 15 + drivers/dpll/dpll_core.c | 288 ++++++- drivers/dpll/dpll_core.h | 11 + drivers/dpll/dpll_netlink.c | 6 + drivers/dpll/zl3073x/dpll.c | 15 +- drivers/dpll/zl3073x/dpll.h | 2 + drivers/dpll/zl3073x/prop.c | 2 + drivers/net/ethernet/intel/ice/ice_dpll.c | 755 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 30 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 +++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 16 +- drivers/ptp/ptp_ocp.c | 18 +- include/linux/dpll.h | 59 +- 18 files changed, 1347 insertions(+), 150 deletions(-) -- 2.52.0
Refactor the reference counting mechanism for DPLL devices and pins to improve consistency and prevent potential lifetime issues. Introduce internal helpers __dpll_{device,pin}_{hold,put}() to centralize reference management. Update the internal XArray reference helpers (dpll_xa_ref_*) to automatically grab a reference to the target object when it is added to a list, and release it when removed. This ensures that objects linked internally (e.g., pins referenced by parent pins) are properly kept alive without relying on the caller to manually manage the count. Consequently, remove the now redundant manual `refcount_inc/dec` calls in dpll_pin_on_pin_{,un}register()`, as ownership is now correctly handled by the dpll_xa_ref_* functions. Additionally, ensure that dpll_device_{,un}register()` takes/releases a reference to the device, ensuring the device object remains valid for the duration of its registration. Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> --- drivers/dpll/dpll_core.c | 74 +++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index 59081cf2c73ae..f6ab4f0cad84d 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -83,6 +83,45 @@ void dpll_pin_notify(struct dpll_pin *pin, unsigned long action) call_dpll_notifiers(action, &info); } +static void __dpll_device_hold(struct dpll_device *dpll) +{ + refcount_inc(&dpll->refcount); +} + +static void __dpll_device_put(struct dpll_device *dpll) +{ + if (refcount_dec_and_test(&dpll->refcount)) { + ASSERT_DPLL_NOT_REGISTERED(dpll); + WARN_ON_ONCE(!xa_empty(&dpll->pin_refs)); + xa_destroy(&dpll->pin_refs); + xa_erase(&dpll_device_xa, dpll->id); + WARN_ON(!list_empty(&dpll->registration_list)); + kfree(dpll); + } +} + +static void __dpll_pin_hold(struct dpll_pin *pin) +{ + refcount_inc(&pin->refcount); +} + +static void dpll_pin_idx_free(u32 pin_idx); +static void dpll_pin_prop_free(struct dpll_pin_properties *prop); + +static void __dpll_pin_put(struct dpll_pin *pin) +{ + if (refcount_dec_and_test(&pin->refcount)) { + xa_erase(&dpll_pin_xa, pin->id); + xa_destroy(&pin->dpll_refs); + xa_destroy(&pin->parent_refs); + xa_destroy(&pin->ref_sync_pins); + dpll_pin_prop_free(&pin->prop); + fwnode_handle_put(pin->fwnode); + dpll_pin_idx_free(pin->pin_idx); + kfree_rcu(pin, rcu); + } +} + struct dpll_device *dpll_device_get_by_id(int id) { if (xa_get_mark(&dpll_device_xa, id, DPLL_REGISTERED)) @@ -152,6 +191,7 @@ dpll_xa_ref_pin_add(struct xarray *xa_pins, struct dpll_pin *pin, reg->ops = ops; reg->priv = priv; reg->cookie = cookie; + __dpll_pin_hold(pin); if (ref_exists) refcount_inc(&ref->refcount); list_add_tail(&reg->list, &ref->registration_list); @@ -174,6 +214,7 @@ static int dpll_xa_ref_pin_del(struct xarray *xa_pins, struct dpll_pin *pin, if (WARN_ON(!reg)) return -EINVAL; list_del(&reg->list); + __dpll_pin_put(pin); kfree(reg); if (refcount_dec_and_test(&ref->refcount)) { xa_erase(xa_pins, i); @@ -231,6 +272,7 @@ dpll_xa_ref_dpll_add(struct xarray *xa_dplls, struct dpll_device *dpll, reg->ops = ops; reg->priv = priv; reg->cookie = cookie; + __dpll_device_hold(dpll); if (ref_exists) refcount_inc(&ref->refcount); list_add_tail(&reg->list, &ref->registration_list); @@ -253,6 +295,7 @@ dpll_xa_ref_dpll_del(struct xarray *xa_dplls, struct dpll_device *dpll, if (WARN_ON(!reg)) return; list_del(&reg->list); + __dpll_device_put(dpll); kfree(reg); if (refcount_dec_and_test(&ref->refcount)) { xa_erase(xa_dplls, i); @@ -323,8 +366,8 @@ dpll_device_get(u64 clock_id, u32 device_idx, struct module *module) if (dpll->clock_id == clock_id && dpll->device_idx == device_idx && dpll->module == module) { + __dpll_device_hold(dpll); ret = dpll; - refcount_inc(&ret->refcount); break; } } @@ -347,14 +390,7 @@ EXPORT_SYMBOL_GPL(dpll_device_get); void dpll_device_put(struct dpll_device *dpll) { mutex_lock(&dpll_lock); - if (refcount_dec_and_test(&dpll->refcount)) { - ASSERT_DPLL_NOT_REGISTERED(dpll); - WARN_ON_ONCE(!xa_empty(&dpll->pin_refs)); - xa_destroy(&dpll->pin_refs); - xa_erase(&dpll_device_xa, dpll->id); - WARN_ON(!list_empty(&dpll->registration_list)); - kfree(dpll); - } + __dpll_device_put(dpll); mutex_unlock(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_device_put); @@ -416,6 +452,7 @@ int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, reg->ops = ops; reg->priv = priv; dpll->type = type; + __dpll_device_hold(dpll); first_registration = list_empty(&dpll->registration_list); list_add_tail(&reg->list, &dpll->registration_list); if (!first_registration) { @@ -455,6 +492,7 @@ void dpll_device_unregister(struct dpll_device *dpll, return; } list_del(&reg->list); + __dpll_device_put(dpll); kfree(reg); if (!list_empty(&dpll->registration_list)) { @@ -666,8 +704,8 @@ dpll_pin_get(u64 clock_id, u32 pin_idx, struct module *module, if (pos->clock_id == clock_id && pos->pin_idx == pin_idx && pos->module == module) { + __dpll_pin_hold(pos); ret = pos; - refcount_inc(&ret->refcount); break; } } @@ -690,16 +728,7 @@ EXPORT_SYMBOL_GPL(dpll_pin_get); void dpll_pin_put(struct dpll_pin *pin) { mutex_lock(&dpll_lock); - if (refcount_dec_and_test(&pin->refcount)) { - xa_erase(&dpll_pin_xa, pin->id); - xa_destroy(&pin->dpll_refs); - xa_destroy(&pin->parent_refs); - xa_destroy(&pin->ref_sync_pins); - dpll_pin_prop_free(&pin->prop); - fwnode_handle_put(pin->fwnode); - dpll_pin_idx_free(pin->pin_idx); - kfree_rcu(pin, rcu); - } + __dpll_pin_put(pin); mutex_unlock(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_pin_put); @@ -740,8 +769,8 @@ struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode) mutex_lock(&dpll_lock); xa_for_each(&dpll_pin_xa, index, pin) { if (pin->fwnode == fwnode) { + __dpll_pin_hold(pin); ret = pin; - refcount_inc(&ret->refcount); break; } } @@ -893,7 +922,6 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, ret = dpll_xa_ref_pin_add(&pin->parent_refs, parent, ops, priv, pin); if (ret) goto unlock; - refcount_inc(&pin->refcount); xa_for_each(&parent->dpll_refs, i, ref) { ret = __dpll_pin_register(ref->dpll, pin, ops, priv, parent); if (ret) { @@ -913,7 +941,6 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, parent); dpll_pin_delete_ntf(pin); } - refcount_dec(&pin->refcount); dpll_xa_ref_pin_del(&pin->parent_refs, parent, ops, priv, pin); unlock: mutex_unlock(&dpll_lock); @@ -940,7 +967,6 @@ void dpll_pin_on_pin_unregister(struct dpll_pin *parent, struct dpll_pin *pin, mutex_lock(&dpll_lock); dpll_pin_delete_ntf(pin); dpll_xa_ref_pin_del(&pin->parent_refs, parent, ops, priv, pin); - refcount_dec(&pin->refcount); xa_for_each(&pin->dpll_refs, i, ref) __dpll_pin_unregister(ref->dpll, pin, ops, priv, parent); mutex_unlock(&dpll_lock); -- 2.52.0
{ "author": "Ivan Vecera <ivecera@redhat.com>", "date": "Mon, 2 Feb 2026 18:16:35 +0100", "thread_id": "20260202171638.17427-1-ivecera@redhat.com.mbox.gz" }
lkml
[PATCH net-next v4 0/9] dpll: Core improvements and ice E825-C SyncE support
This series introduces Synchronous Ethernet (SyncE) support for the Intel E825-C Ethernet controller. Unlike previous generations where DPLL connections were implicitly assumed, the E825-C architecture relies on the platform firmware (ACPI) to describe the physical connections between the Ethernet controller and external DPLLs (such as the ZL3073x). To accommodate this, the series extends the DPLL subsystem to support firmware node (fwnode) associations, asynchronous discovery via notifiers, and dynamic pin management. Additionally, a significant refactor of the DPLL reference counting logic is included to ensure robustness and debuggability. DPLL Core Extensions: * Firmware Node Association: Pins can now be associated with a struct fwnode_handle after allocation via dpll_pin_fwnode_set(). This allows drivers to link pin objects with their corresponding DT/ACPI nodes. * Asynchronous Notifiers: A raw notifier chain is added to the DPLL core. This allows the Ethernet driver to subscribe to events and react when the platform DPLL driver registers the parent pins, resolving probe ordering dependencies. * Dynamic Indexing: Drivers can now request DPLL_PIN_IDX_UNSPEC to have the core automatically allocate a unique pin index. Reference Counting & Debugging: * Refactor: The reference counting logic in the core is consolidated. Internal list management helpers now automatically handle hold/put operations, removing fragile open-coded logic in the registration paths. * Reference Tracking: A new Kconfig option DPLL_REFCNT_TRACKER is added. This allows developers to instrument and debug reference leaks by recording stack traces for every get/put operation. Driver Updates: * zl3073x: Updated to associate pins with fwnode handles using the new setter and support the 'mux' pin type. * ice: Implements the E825-C specific hardware configuration for SyncE (CGU registers). It utilizes the new notifier and fwnode APIs to dynamically discover and attach to the platform DPLLs. Patch Summary: Patch 1: DPLL Core (fwnode association). Patch 2: Driver zl3073x (Set fwnode). Patch 3-4: DPLL Core (Notifiers and dynamic IDs). Patch 5: Driver zl3073x (Mux type). Patch 6: DPLL Core (Refcount refactor). Patch 7-8: Refcount tracking infrastructure and driver updates. Patch 9: Driver ice (E825-C SyncE logic). Changes in v4: * Fixed documentation and function stub issues found by AI Arkadiusz Kubalewski (1): ice: dpll: Support E825-C SyncE and dynamic pin discovery Ivan Vecera (7): dpll: Allow associating dpll pin with a firmware node dpll: zl3073x: Associate pin with fwnode handle dpll: Support dynamic pin index allocation dpll: zl3073x: Add support for mux pin type dpll: Enhance and consolidate reference counting logic dpll: Add reference count tracking support drivers: Add support for DPLL reference count tracking Petr Oros (1): dpll: Add notifier chain for dpll events drivers/dpll/Kconfig | 15 + drivers/dpll/dpll_core.c | 288 ++++++- drivers/dpll/dpll_core.h | 11 + drivers/dpll/dpll_netlink.c | 6 + drivers/dpll/zl3073x/dpll.c | 15 +- drivers/dpll/zl3073x/dpll.h | 2 + drivers/dpll/zl3073x/prop.c | 2 + drivers/net/ethernet/intel/ice/ice_dpll.c | 755 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 30 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 +++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 16 +- drivers/ptp/ptp_ocp.c | 18 +- include/linux/dpll.h | 59 +- 18 files changed, 1347 insertions(+), 150 deletions(-) -- 2.52.0
Add support for the REF_TRACKER infrastructure to the DPLL subsystem. When enabled, this allows developers to track and debug reference counting leaks or imbalances for dpll_device and dpll_pin objects. It records stack traces for every get/put operation and exposes this information via debugfs at: /sys/kernel/debug/ref_tracker/dpll_device_* /sys/kernel/debug/ref_tracker/dpll_pin_* The following API changes are made to support this: 1. dpll_device_get() / dpll_device_put() now accept a 'dpll_tracker *' (which is a typedef to 'struct ref_tracker *' when enabled, or an empty struct otherwise). 2. dpll_pin_get() / dpll_pin_put() and fwnode_dpll_pin_find() similarly accept the tracker argument. 3. Internal registration structures now hold a tracker to associate the reference held by the registration with the specific owner. All existing in-tree drivers (ice, mlx5, ptp_ocp, zl3073x) are updated to pass NULL for the new tracker argument, maintaining current behavior while enabling future debugging capabilities. Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Co-developed-by: Petr Oros <poros@redhat.com> Signed-off-by: Petr Oros <poros@redhat.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> --- v4: * added missing tracker parameter to fwnode_dpll_pin_find() stub v3: * added Kconfig dependency on STACKTRACE_SUPPORT and DEBUG_KERNEL --- drivers/dpll/Kconfig | 15 +++ drivers/dpll/dpll_core.c | 98 ++++++++++++++----- drivers/dpll/dpll_core.h | 5 + drivers/dpll/zl3073x/dpll.c | 12 +-- drivers/net/ethernet/intel/ice/ice_dpll.c | 14 +-- .../net/ethernet/mellanox/mlx5/core/dpll.c | 13 +-- drivers/ptp/ptp_ocp.c | 15 +-- include/linux/dpll.h | 21 ++-- 8 files changed, 139 insertions(+), 54 deletions(-) diff --git a/drivers/dpll/Kconfig b/drivers/dpll/Kconfig index ade872c915ac6..be98969f040ab 100644 --- a/drivers/dpll/Kconfig +++ b/drivers/dpll/Kconfig @@ -8,6 +8,21 @@ menu "DPLL device support" config DPLL bool +config DPLL_REFCNT_TRACKER + bool "DPLL reference count tracking" + depends on DEBUG_KERNEL && STACKTRACE_SUPPORT && DPLL + select REF_TRACKER + help + Enable reference count tracking for DPLL devices and pins. + This helps debugging reference leaks and use-after-free bugs + by recording stack traces for each get/put operation. + + The tracking information is exposed via debugfs at: + /sys/kernel/debug/ref_tracker/dpll_device_* + /sys/kernel/debug/ref_tracker/dpll_pin_* + + If unsure, say N. + source "drivers/dpll/zl3073x/Kconfig" endmenu diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index f6ab4f0cad84d..627a5b39a0efd 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -41,6 +41,7 @@ struct dpll_device_registration { struct list_head list; const struct dpll_device_ops *ops; void *priv; + dpll_tracker tracker; }; struct dpll_pin_registration { @@ -48,6 +49,7 @@ struct dpll_pin_registration { const struct dpll_pin_ops *ops; void *priv; void *cookie; + dpll_tracker tracker; }; static int call_dpll_notifiers(unsigned long action, void *info) @@ -83,33 +85,68 @@ void dpll_pin_notify(struct dpll_pin *pin, unsigned long action) call_dpll_notifiers(action, &info); } -static void __dpll_device_hold(struct dpll_device *dpll) +static void dpll_device_tracker_alloc(struct dpll_device *dpll, + dpll_tracker *tracker) { +#ifdef CONFIG_DPLL_REFCNT_TRACKER + ref_tracker_alloc(&dpll->refcnt_tracker, tracker, GFP_KERNEL); +#endif +} + +static void dpll_device_tracker_free(struct dpll_device *dpll, + dpll_tracker *tracker) +{ +#ifdef CONFIG_DPLL_REFCNT_TRACKER + ref_tracker_free(&dpll->refcnt_tracker, tracker); +#endif +} + +static void __dpll_device_hold(struct dpll_device *dpll, dpll_tracker *tracker) +{ + dpll_device_tracker_alloc(dpll, tracker); refcount_inc(&dpll->refcount); } -static void __dpll_device_put(struct dpll_device *dpll) +static void __dpll_device_put(struct dpll_device *dpll, dpll_tracker *tracker) { + dpll_device_tracker_free(dpll, tracker); if (refcount_dec_and_test(&dpll->refcount)) { ASSERT_DPLL_NOT_REGISTERED(dpll); WARN_ON_ONCE(!xa_empty(&dpll->pin_refs)); xa_destroy(&dpll->pin_refs); xa_erase(&dpll_device_xa, dpll->id); WARN_ON(!list_empty(&dpll->registration_list)); + ref_tracker_dir_exit(&dpll->refcnt_tracker); kfree(dpll); } } -static void __dpll_pin_hold(struct dpll_pin *pin) +static void dpll_pin_tracker_alloc(struct dpll_pin *pin, dpll_tracker *tracker) { +#ifdef CONFIG_DPLL_REFCNT_TRACKER + ref_tracker_alloc(&pin->refcnt_tracker, tracker, GFP_KERNEL); +#endif +} + +static void dpll_pin_tracker_free(struct dpll_pin *pin, dpll_tracker *tracker) +{ +#ifdef CONFIG_DPLL_REFCNT_TRACKER + ref_tracker_free(&pin->refcnt_tracker, tracker); +#endif +} + +static void __dpll_pin_hold(struct dpll_pin *pin, dpll_tracker *tracker) +{ + dpll_pin_tracker_alloc(pin, tracker); refcount_inc(&pin->refcount); } static void dpll_pin_idx_free(u32 pin_idx); static void dpll_pin_prop_free(struct dpll_pin_properties *prop); -static void __dpll_pin_put(struct dpll_pin *pin) +static void __dpll_pin_put(struct dpll_pin *pin, dpll_tracker *tracker) { + dpll_pin_tracker_free(pin, tracker); if (refcount_dec_and_test(&pin->refcount)) { xa_erase(&dpll_pin_xa, pin->id); xa_destroy(&pin->dpll_refs); @@ -118,6 +155,7 @@ static void __dpll_pin_put(struct dpll_pin *pin) dpll_pin_prop_free(&pin->prop); fwnode_handle_put(pin->fwnode); dpll_pin_idx_free(pin->pin_idx); + ref_tracker_dir_exit(&pin->refcnt_tracker); kfree_rcu(pin, rcu); } } @@ -191,7 +229,7 @@ dpll_xa_ref_pin_add(struct xarray *xa_pins, struct dpll_pin *pin, reg->ops = ops; reg->priv = priv; reg->cookie = cookie; - __dpll_pin_hold(pin); + __dpll_pin_hold(pin, &reg->tracker); if (ref_exists) refcount_inc(&ref->refcount); list_add_tail(&reg->list, &ref->registration_list); @@ -214,7 +252,7 @@ static int dpll_xa_ref_pin_del(struct xarray *xa_pins, struct dpll_pin *pin, if (WARN_ON(!reg)) return -EINVAL; list_del(&reg->list); - __dpll_pin_put(pin); + __dpll_pin_put(pin, &reg->tracker); kfree(reg); if (refcount_dec_and_test(&ref->refcount)) { xa_erase(xa_pins, i); @@ -272,7 +310,7 @@ dpll_xa_ref_dpll_add(struct xarray *xa_dplls, struct dpll_device *dpll, reg->ops = ops; reg->priv = priv; reg->cookie = cookie; - __dpll_device_hold(dpll); + __dpll_device_hold(dpll, &reg->tracker); if (ref_exists) refcount_inc(&ref->refcount); list_add_tail(&reg->list, &ref->registration_list); @@ -295,7 +333,7 @@ dpll_xa_ref_dpll_del(struct xarray *xa_dplls, struct dpll_device *dpll, if (WARN_ON(!reg)) return; list_del(&reg->list); - __dpll_device_put(dpll); + __dpll_device_put(dpll, &reg->tracker); kfree(reg); if (refcount_dec_and_test(&ref->refcount)) { xa_erase(xa_dplls, i); @@ -337,6 +375,7 @@ dpll_device_alloc(const u64 clock_id, u32 device_idx, struct module *module) return ERR_PTR(ret); } xa_init_flags(&dpll->pin_refs, XA_FLAGS_ALLOC); + ref_tracker_dir_init(&dpll->refcnt_tracker, 128, "dpll_device"); return dpll; } @@ -346,6 +385,7 @@ dpll_device_alloc(const u64 clock_id, u32 device_idx, struct module *module) * @clock_id: clock_id of creator * @device_idx: idx given by device driver * @module: reference to registering module + * @tracker: tracking object for the acquired reference * * Get existing object of a dpll device, unique for given arguments. * Create new if doesn't exist yet. @@ -356,7 +396,8 @@ dpll_device_alloc(const u64 clock_id, u32 device_idx, struct module *module) * * ERR_PTR(X) - error */ struct dpll_device * -dpll_device_get(u64 clock_id, u32 device_idx, struct module *module) +dpll_device_get(u64 clock_id, u32 device_idx, struct module *module, + dpll_tracker *tracker) { struct dpll_device *dpll, *ret = NULL; unsigned long index; @@ -366,13 +407,17 @@ dpll_device_get(u64 clock_id, u32 device_idx, struct module *module) if (dpll->clock_id == clock_id && dpll->device_idx == device_idx && dpll->module == module) { - __dpll_device_hold(dpll); + __dpll_device_hold(dpll, tracker); ret = dpll; break; } } - if (!ret) + if (!ret) { ret = dpll_device_alloc(clock_id, device_idx, module); + if (!IS_ERR(ret)) + dpll_device_tracker_alloc(ret, tracker); + } + mutex_unlock(&dpll_lock); return ret; @@ -382,15 +427,16 @@ EXPORT_SYMBOL_GPL(dpll_device_get); /** * dpll_device_put - decrease the refcount and free memory if possible * @dpll: dpll_device struct pointer + * @tracker: tracking object for the acquired reference * * Context: Acquires a lock (dpll_lock) * Drop reference for a dpll device, if all references are gone, delete * dpll device object. */ -void dpll_device_put(struct dpll_device *dpll) +void dpll_device_put(struct dpll_device *dpll, dpll_tracker *tracker) { mutex_lock(&dpll_lock); - __dpll_device_put(dpll); + __dpll_device_put(dpll, tracker); mutex_unlock(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_device_put); @@ -452,7 +498,7 @@ int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, reg->ops = ops; reg->priv = priv; dpll->type = type; - __dpll_device_hold(dpll); + __dpll_device_hold(dpll, &reg->tracker); first_registration = list_empty(&dpll->registration_list); list_add_tail(&reg->list, &dpll->registration_list); if (!first_registration) { @@ -492,7 +538,7 @@ void dpll_device_unregister(struct dpll_device *dpll, return; } list_del(&reg->list); - __dpll_device_put(dpll); + __dpll_device_put(dpll, &reg->tracker); kfree(reg); if (!list_empty(&dpll->registration_list)) { @@ -622,6 +668,7 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module *module, &dpll_pin_xa_id, GFP_KERNEL); if (ret < 0) goto err_xa_alloc; + ref_tracker_dir_init(&pin->refcnt_tracker, 128, "dpll_pin"); return pin; err_xa_alloc: xa_destroy(&pin->dpll_refs); @@ -683,6 +730,7 @@ EXPORT_SYMBOL_GPL(unregister_dpll_notifier); * @pin_idx: idx given by dev driver * @module: reference to registering module * @prop: dpll pin properties + * @tracker: tracking object for the acquired reference * * Get existing object of a pin (unique for given arguments) or create new * if doesn't exist yet. @@ -694,7 +742,7 @@ EXPORT_SYMBOL_GPL(unregister_dpll_notifier); */ struct dpll_pin * dpll_pin_get(u64 clock_id, u32 pin_idx, struct module *module, - const struct dpll_pin_properties *prop) + const struct dpll_pin_properties *prop, dpll_tracker *tracker) { struct dpll_pin *pos, *ret = NULL; unsigned long i; @@ -704,13 +752,16 @@ dpll_pin_get(u64 clock_id, u32 pin_idx, struct module *module, if (pos->clock_id == clock_id && pos->pin_idx == pin_idx && pos->module == module) { - __dpll_pin_hold(pos); + __dpll_pin_hold(pos, tracker); ret = pos; break; } } - if (!ret) + if (!ret) { ret = dpll_pin_alloc(clock_id, pin_idx, module, prop); + if (!IS_ERR(ret)) + dpll_pin_tracker_alloc(ret, tracker); + } mutex_unlock(&dpll_lock); return ret; @@ -720,15 +771,16 @@ EXPORT_SYMBOL_GPL(dpll_pin_get); /** * dpll_pin_put - decrease the refcount and free memory if possible * @pin: pointer to a pin to be put + * @tracker: tracking object for the acquired reference * * Drop reference for a pin, if all references are gone, delete pin object. * * Context: Acquires a lock (dpll_lock) */ -void dpll_pin_put(struct dpll_pin *pin) +void dpll_pin_put(struct dpll_pin *pin, dpll_tracker *tracker) { mutex_lock(&dpll_lock); - __dpll_pin_put(pin); + __dpll_pin_put(pin, tracker); mutex_unlock(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_pin_put); @@ -752,6 +804,7 @@ EXPORT_SYMBOL_GPL(dpll_pin_fwnode_set); /** * fwnode_dpll_pin_find - find dpll pin by firmware node reference * @fwnode: reference to firmware node + * @tracker: tracking object for the acquired reference * * Get existing object of a pin that is associated with given firmware node * reference. @@ -761,7 +814,8 @@ EXPORT_SYMBOL_GPL(dpll_pin_fwnode_set); * * valid dpll_pin pointer on success * * NULL when no such pin exists */ -struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode) +struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode, + dpll_tracker *tracker) { struct dpll_pin *pin, *ret = NULL; unsigned long index; @@ -769,7 +823,7 @@ struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode) mutex_lock(&dpll_lock); xa_for_each(&dpll_pin_xa, index, pin) { if (pin->fwnode == fwnode) { - __dpll_pin_hold(pin); + __dpll_pin_hold(pin, tracker); ret = pin; break; } diff --git a/drivers/dpll/dpll_core.h b/drivers/dpll/dpll_core.h index b7b4bb251f739..71ac88ef20172 100644 --- a/drivers/dpll/dpll_core.h +++ b/drivers/dpll/dpll_core.h @@ -10,6 +10,7 @@ #include <linux/dpll.h> #include <linux/list.h> #include <linux/refcount.h> +#include <linux/ref_tracker.h> #include "dpll_nl.h" #define DPLL_REGISTERED XA_MARK_1 @@ -23,6 +24,7 @@ * @type: type of a dpll * @pin_refs: stores pins registered within a dpll * @refcount: refcount + * @refcnt_tracker: ref_tracker directory for debugging reference leaks * @registration_list: list of registered ops and priv data of dpll owners **/ struct dpll_device { @@ -33,6 +35,7 @@ struct dpll_device { enum dpll_type type; struct xarray pin_refs; refcount_t refcount; + struct ref_tracker_dir refcnt_tracker; struct list_head registration_list; }; @@ -48,6 +51,7 @@ struct dpll_device { * @ref_sync_pins: hold references to pins for Reference SYNC feature * @prop: pin properties copied from the registerer * @refcount: refcount + * @refcnt_tracker: ref_tracker directory for debugging reference leaks * @rcu: rcu_head for kfree_rcu() **/ struct dpll_pin { @@ -61,6 +65,7 @@ struct dpll_pin { struct xarray ref_sync_pins; struct dpll_pin_properties prop; refcount_t refcount; + struct ref_tracker_dir refcnt_tracker; struct rcu_head rcu; }; diff --git a/drivers/dpll/zl3073x/dpll.c b/drivers/dpll/zl3073x/dpll.c index 9eed21088adac..8788bcab7ec53 100644 --- a/drivers/dpll/zl3073x/dpll.c +++ b/drivers/dpll/zl3073x/dpll.c @@ -1480,7 +1480,7 @@ zl3073x_dpll_pin_register(struct zl3073x_dpll_pin *pin, u32 index) /* Create or get existing DPLL pin */ pin->dpll_pin = dpll_pin_get(zldpll->dev->clock_id, index, THIS_MODULE, - &props->dpll_props); + &props->dpll_props, NULL); if (IS_ERR(pin->dpll_pin)) { rc = PTR_ERR(pin->dpll_pin); goto err_pin_get; @@ -1503,7 +1503,7 @@ zl3073x_dpll_pin_register(struct zl3073x_dpll_pin *pin, u32 index) return 0; err_register: - dpll_pin_put(pin->dpll_pin); + dpll_pin_put(pin->dpll_pin, NULL); err_prio_get: pin->dpll_pin = NULL; err_pin_get: @@ -1534,7 +1534,7 @@ zl3073x_dpll_pin_unregister(struct zl3073x_dpll_pin *pin) /* Unregister the pin */ dpll_pin_unregister(zldpll->dpll_dev, pin->dpll_pin, ops, pin); - dpll_pin_put(pin->dpll_pin); + dpll_pin_put(pin->dpll_pin, NULL); pin->dpll_pin = NULL; } @@ -1708,7 +1708,7 @@ zl3073x_dpll_device_register(struct zl3073x_dpll *zldpll) dpll_mode_refsel); zldpll->dpll_dev = dpll_device_get(zldev->clock_id, zldpll->id, - THIS_MODULE); + THIS_MODULE, NULL); if (IS_ERR(zldpll->dpll_dev)) { rc = PTR_ERR(zldpll->dpll_dev); zldpll->dpll_dev = NULL; @@ -1720,7 +1720,7 @@ zl3073x_dpll_device_register(struct zl3073x_dpll *zldpll) zl3073x_prop_dpll_type_get(zldev, zldpll->id), &zl3073x_dpll_device_ops, zldpll); if (rc) { - dpll_device_put(zldpll->dpll_dev); + dpll_device_put(zldpll->dpll_dev, NULL); zldpll->dpll_dev = NULL; } @@ -1743,7 +1743,7 @@ zl3073x_dpll_device_unregister(struct zl3073x_dpll *zldpll) dpll_device_unregister(zldpll->dpll_dev, &zl3073x_dpll_device_ops, zldpll); - dpll_device_put(zldpll->dpll_dev); + dpll_device_put(zldpll->dpll_dev, NULL); zldpll->dpll_dev = NULL; } diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethernet/intel/ice/ice_dpll.c index 53b54e395a2ed..64b7b045ecd58 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -2814,7 +2814,7 @@ static void ice_dpll_release_pins(struct ice_dpll_pin *pins, int count) int i; for (i = 0; i < count; i++) - dpll_pin_put(pins[i].pin); + dpll_pin_put(pins[i].pin, NULL); } /** @@ -2840,7 +2840,7 @@ ice_dpll_get_pins(struct ice_pf *pf, struct ice_dpll_pin *pins, for (i = 0; i < count; i++) { pins[i].pin = dpll_pin_get(clock_id, i + start_idx, THIS_MODULE, - &pins[i].prop); + &pins[i].prop, NULL); if (IS_ERR(pins[i].pin)) { ret = PTR_ERR(pins[i].pin); goto release_pins; @@ -2851,7 +2851,7 @@ ice_dpll_get_pins(struct ice_pf *pf, struct ice_dpll_pin *pins, release_pins: while (--i >= 0) - dpll_pin_put(pins[i].pin); + dpll_pin_put(pins[i].pin, NULL); return ret; } @@ -3037,7 +3037,7 @@ static void ice_dpll_deinit_rclk_pin(struct ice_pf *pf) if (WARN_ON_ONCE(!vsi || !vsi->netdev)) return; dpll_netdev_pin_clear(vsi->netdev); - dpll_pin_put(rclk->pin); + dpll_pin_put(rclk->pin, NULL); } /** @@ -3247,7 +3247,7 @@ ice_dpll_deinit_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu) { if (cgu) dpll_device_unregister(d->dpll, d->ops, d); - dpll_device_put(d->dpll); + dpll_device_put(d->dpll, NULL); } /** @@ -3271,7 +3271,7 @@ ice_dpll_init_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu, u64 clock_id = pf->dplls.clock_id; int ret; - d->dpll = dpll_device_get(clock_id, d->dpll_idx, THIS_MODULE); + d->dpll = dpll_device_get(clock_id, d->dpll_idx, THIS_MODULE, NULL); if (IS_ERR(d->dpll)) { ret = PTR_ERR(d->dpll); dev_err(ice_pf_to_dev(pf), @@ -3287,7 +3287,7 @@ ice_dpll_init_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu, ice_dpll_update_state(pf, d, true); ret = dpll_device_register(d->dpll, type, ops, d); if (ret) { - dpll_device_put(d->dpll); + dpll_device_put(d->dpll, NULL); return ret; } d->ops = ops; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dpll.c b/drivers/net/ethernet/mellanox/mlx5/core/dpll.c index 3ea8a1766ae28..541d83e5d7183 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/dpll.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/dpll.c @@ -438,7 +438,7 @@ static int mlx5_dpll_probe(struct auxiliary_device *adev, auxiliary_set_drvdata(adev, mdpll); /* Multiple mdev instances might share one DPLL device. */ - mdpll->dpll = dpll_device_get(clock_id, 0, THIS_MODULE); + mdpll->dpll = dpll_device_get(clock_id, 0, THIS_MODULE, NULL); if (IS_ERR(mdpll->dpll)) { err = PTR_ERR(mdpll->dpll); goto err_free_mdpll; @@ -451,7 +451,8 @@ static int mlx5_dpll_probe(struct auxiliary_device *adev, /* Multiple mdev instances might share one DPLL pin. */ mdpll->dpll_pin = dpll_pin_get(clock_id, mlx5_get_dev_index(mdev), - THIS_MODULE, &mlx5_dpll_pin_properties); + THIS_MODULE, &mlx5_dpll_pin_properties, + NULL); if (IS_ERR(mdpll->dpll_pin)) { err = PTR_ERR(mdpll->dpll_pin); goto err_unregister_dpll_device; @@ -479,11 +480,11 @@ static int mlx5_dpll_probe(struct auxiliary_device *adev, dpll_pin_unregister(mdpll->dpll, mdpll->dpll_pin, &mlx5_dpll_pins_ops, mdpll); err_put_dpll_pin: - dpll_pin_put(mdpll->dpll_pin); + dpll_pin_put(mdpll->dpll_pin, NULL); err_unregister_dpll_device: dpll_device_unregister(mdpll->dpll, &mlx5_dpll_device_ops, mdpll); err_put_dpll_device: - dpll_device_put(mdpll->dpll); + dpll_device_put(mdpll->dpll, NULL); err_free_mdpll: kfree(mdpll); return err; @@ -499,9 +500,9 @@ static void mlx5_dpll_remove(struct auxiliary_device *adev) destroy_workqueue(mdpll->wq); dpll_pin_unregister(mdpll->dpll, mdpll->dpll_pin, &mlx5_dpll_pins_ops, mdpll); - dpll_pin_put(mdpll->dpll_pin); + dpll_pin_put(mdpll->dpll_pin, NULL); dpll_device_unregister(mdpll->dpll, &mlx5_dpll_device_ops, mdpll); - dpll_device_put(mdpll->dpll); + dpll_device_put(mdpll->dpll, NULL); kfree(mdpll); mlx5_dpll_synce_status_set(mdev, diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 65fe05cac8c42..f39b3966b3e8c 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -4788,7 +4788,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) devlink_register(devlink); clkid = pci_get_dsn(pdev); - bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE); + bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE, NULL); if (IS_ERR(bp->dpll)) { err = PTR_ERR(bp->dpll); dev_err(&pdev->dev, "dpll_device_alloc failed\n"); @@ -4800,7 +4800,8 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto out; for (i = 0; i < OCP_SMA_NUM; i++) { - bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, &bp->sma[i].dpll_prop); + bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, + &bp->sma[i].dpll_prop, NULL); if (IS_ERR(bp->sma[i].dpll_pin)) { err = PTR_ERR(bp->sma[i].dpll_pin); goto out_dpll; @@ -4809,7 +4810,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) err = dpll_pin_register(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); if (err) { - dpll_pin_put(bp->sma[i].dpll_pin); + dpll_pin_put(bp->sma[i].dpll_pin, NULL); goto out_dpll; } } @@ -4819,9 +4820,9 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) out_dpll: while (i--) { dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); - dpll_pin_put(bp->sma[i].dpll_pin); + dpll_pin_put(bp->sma[i].dpll_pin, NULL); } - dpll_device_put(bp->dpll); + dpll_device_put(bp->dpll, NULL); out: ptp_ocp_detach(bp); out_disable: @@ -4842,11 +4843,11 @@ ptp_ocp_remove(struct pci_dev *pdev) for (i = 0; i < OCP_SMA_NUM; i++) { if (bp->sma[i].dpll_pin) { dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); - dpll_pin_put(bp->sma[i].dpll_pin); + dpll_pin_put(bp->sma[i].dpll_pin, NULL); } } dpll_device_unregister(bp->dpll, &dpll_ops, bp); - dpll_device_put(bp->dpll); + dpll_device_put(bp->dpll, NULL); devlink_unregister(devlink); ptp_ocp_detach(bp); pci_disable_device(pdev); diff --git a/include/linux/dpll.h b/include/linux/dpll.h index 8fff048131f1d..5c80cdab0c180 100644 --- a/include/linux/dpll.h +++ b/include/linux/dpll.h @@ -18,6 +18,7 @@ struct dpll_device; struct dpll_pin; struct dpll_pin_esync; struct fwnode_handle; +struct ref_tracker; struct dpll_device_ops { int (*mode_get)(const struct dpll_device *dpll, void *dpll_priv, @@ -173,6 +174,12 @@ struct dpll_pin_properties { u32 phase_gran; }; +#ifdef CONFIG_DPLL_REFCNT_TRACKER +typedef struct ref_tracker *dpll_tracker; +#else +typedef struct {} dpll_tracker; +#endif + #define DPLL_DEVICE_CREATED 1 #define DPLL_DEVICE_DELETED 2 #define DPLL_DEVICE_CHANGED 3 @@ -205,7 +212,8 @@ size_t dpll_netdev_pin_handle_size(const struct net_device *dev); int dpll_netdev_add_pin_handle(struct sk_buff *msg, const struct net_device *dev); -struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode); +struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode, + dpll_tracker *tracker); #else static inline void dpll_netdev_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin) { } @@ -223,16 +231,17 @@ dpll_netdev_add_pin_handle(struct sk_buff *msg, const struct net_device *dev) } static inline struct dpll_pin * -fwnode_dpll_pin_find(struct fwnode_handle *fwnode) +fwnode_dpll_pin_find(struct fwnode_handle *fwnode, dpll_tracker *tracker); { return NULL; } #endif struct dpll_device * -dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module *module); +dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module *module, + dpll_tracker *tracker); -void dpll_device_put(struct dpll_device *dpll); +void dpll_device_put(struct dpll_device *dpll, dpll_tracker *tracker); int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, const struct dpll_device_ops *ops, void *priv); @@ -244,7 +253,7 @@ void dpll_device_unregister(struct dpll_device *dpll, struct dpll_pin * dpll_pin_get(u64 clock_id, u32 dev_driver_id, struct module *module, - const struct dpll_pin_properties *prop); + const struct dpll_pin_properties *prop, dpll_tracker *tracker); int dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv); @@ -252,7 +261,7 @@ int dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, void dpll_pin_unregister(struct dpll_device *dpll, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv); -void dpll_pin_put(struct dpll_pin *pin); +void dpll_pin_put(struct dpll_pin *pin, dpll_tracker *tracker); void dpll_pin_fwnode_set(struct dpll_pin *pin, struct fwnode_handle *fwnode); -- 2.52.0
{ "author": "Ivan Vecera <ivecera@redhat.com>", "date": "Mon, 2 Feb 2026 18:16:36 +0100", "thread_id": "20260202171638.17427-1-ivecera@redhat.com.mbox.gz" }
lkml
[PATCH net-next v4 0/9] dpll: Core improvements and ice E825-C SyncE support
This series introduces Synchronous Ethernet (SyncE) support for the Intel E825-C Ethernet controller. Unlike previous generations where DPLL connections were implicitly assumed, the E825-C architecture relies on the platform firmware (ACPI) to describe the physical connections between the Ethernet controller and external DPLLs (such as the ZL3073x). To accommodate this, the series extends the DPLL subsystem to support firmware node (fwnode) associations, asynchronous discovery via notifiers, and dynamic pin management. Additionally, a significant refactor of the DPLL reference counting logic is included to ensure robustness and debuggability. DPLL Core Extensions: * Firmware Node Association: Pins can now be associated with a struct fwnode_handle after allocation via dpll_pin_fwnode_set(). This allows drivers to link pin objects with their corresponding DT/ACPI nodes. * Asynchronous Notifiers: A raw notifier chain is added to the DPLL core. This allows the Ethernet driver to subscribe to events and react when the platform DPLL driver registers the parent pins, resolving probe ordering dependencies. * Dynamic Indexing: Drivers can now request DPLL_PIN_IDX_UNSPEC to have the core automatically allocate a unique pin index. Reference Counting & Debugging: * Refactor: The reference counting logic in the core is consolidated. Internal list management helpers now automatically handle hold/put operations, removing fragile open-coded logic in the registration paths. * Reference Tracking: A new Kconfig option DPLL_REFCNT_TRACKER is added. This allows developers to instrument and debug reference leaks by recording stack traces for every get/put operation. Driver Updates: * zl3073x: Updated to associate pins with fwnode handles using the new setter and support the 'mux' pin type. * ice: Implements the E825-C specific hardware configuration for SyncE (CGU registers). It utilizes the new notifier and fwnode APIs to dynamically discover and attach to the platform DPLLs. Patch Summary: Patch 1: DPLL Core (fwnode association). Patch 2: Driver zl3073x (Set fwnode). Patch 3-4: DPLL Core (Notifiers and dynamic IDs). Patch 5: Driver zl3073x (Mux type). Patch 6: DPLL Core (Refcount refactor). Patch 7-8: Refcount tracking infrastructure and driver updates. Patch 9: Driver ice (E825-C SyncE logic). Changes in v4: * Fixed documentation and function stub issues found by AI Arkadiusz Kubalewski (1): ice: dpll: Support E825-C SyncE and dynamic pin discovery Ivan Vecera (7): dpll: Allow associating dpll pin with a firmware node dpll: zl3073x: Associate pin with fwnode handle dpll: Support dynamic pin index allocation dpll: zl3073x: Add support for mux pin type dpll: Enhance and consolidate reference counting logic dpll: Add reference count tracking support drivers: Add support for DPLL reference count tracking Petr Oros (1): dpll: Add notifier chain for dpll events drivers/dpll/Kconfig | 15 + drivers/dpll/dpll_core.c | 288 ++++++- drivers/dpll/dpll_core.h | 11 + drivers/dpll/dpll_netlink.c | 6 + drivers/dpll/zl3073x/dpll.c | 15 +- drivers/dpll/zl3073x/dpll.h | 2 + drivers/dpll/zl3073x/prop.c | 2 + drivers/net/ethernet/intel/ice/ice_dpll.c | 755 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 30 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 +++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 16 +- drivers/ptp/ptp_ocp.c | 18 +- include/linux/dpll.h | 59 +- 18 files changed, 1347 insertions(+), 150 deletions(-) -- 2.52.0
Update existing DPLL drivers to utilize the DPLL reference count tracking infrastructure. Add dpll_tracker fields to the drivers' internal device and pin structures. Pass pointers to these trackers when calling dpll_device_get/put() and dpll_pin_get/put(). This allows developers to inspect the specific references held by this driver via debugfs when CONFIG_DPLL_REFCNT_TRACKER is enabled, aiding in the debugging of resource leaks. Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> --- drivers/dpll/zl3073x/dpll.c | 14 ++++++++------ drivers/dpll/zl3073x/dpll.h | 2 ++ drivers/net/ethernet/intel/ice/ice_dpll.c | 15 ++++++++------- drivers/net/ethernet/intel/ice/ice_dpll.h | 4 ++++ drivers/net/ethernet/mellanox/mlx5/core/dpll.c | 15 +++++++++------ drivers/ptp/ptp_ocp.c | 17 ++++++++++------- 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/drivers/dpll/zl3073x/dpll.c b/drivers/dpll/zl3073x/dpll.c index 8788bcab7ec53..a99d143a7acde 100644 --- a/drivers/dpll/zl3073x/dpll.c +++ b/drivers/dpll/zl3073x/dpll.c @@ -29,6 +29,7 @@ * @list: this DPLL pin list entry * @dpll: DPLL the pin is registered to * @dpll_pin: pointer to registered dpll_pin + * @tracker: tracking object for the acquired reference * @label: package label * @dir: pin direction * @id: pin id @@ -44,6 +45,7 @@ struct zl3073x_dpll_pin { struct list_head list; struct zl3073x_dpll *dpll; struct dpll_pin *dpll_pin; + dpll_tracker tracker; char label[8]; enum dpll_pin_direction dir; u8 id; @@ -1480,7 +1482,7 @@ zl3073x_dpll_pin_register(struct zl3073x_dpll_pin *pin, u32 index) /* Create or get existing DPLL pin */ pin->dpll_pin = dpll_pin_get(zldpll->dev->clock_id, index, THIS_MODULE, - &props->dpll_props, NULL); + &props->dpll_props, &pin->tracker); if (IS_ERR(pin->dpll_pin)) { rc = PTR_ERR(pin->dpll_pin); goto err_pin_get; @@ -1503,7 +1505,7 @@ zl3073x_dpll_pin_register(struct zl3073x_dpll_pin *pin, u32 index) return 0; err_register: - dpll_pin_put(pin->dpll_pin, NULL); + dpll_pin_put(pin->dpll_pin, &pin->tracker); err_prio_get: pin->dpll_pin = NULL; err_pin_get: @@ -1534,7 +1536,7 @@ zl3073x_dpll_pin_unregister(struct zl3073x_dpll_pin *pin) /* Unregister the pin */ dpll_pin_unregister(zldpll->dpll_dev, pin->dpll_pin, ops, pin); - dpll_pin_put(pin->dpll_pin, NULL); + dpll_pin_put(pin->dpll_pin, &pin->tracker); pin->dpll_pin = NULL; } @@ -1708,7 +1710,7 @@ zl3073x_dpll_device_register(struct zl3073x_dpll *zldpll) dpll_mode_refsel); zldpll->dpll_dev = dpll_device_get(zldev->clock_id, zldpll->id, - THIS_MODULE, NULL); + THIS_MODULE, &zldpll->tracker); if (IS_ERR(zldpll->dpll_dev)) { rc = PTR_ERR(zldpll->dpll_dev); zldpll->dpll_dev = NULL; @@ -1720,7 +1722,7 @@ zl3073x_dpll_device_register(struct zl3073x_dpll *zldpll) zl3073x_prop_dpll_type_get(zldev, zldpll->id), &zl3073x_dpll_device_ops, zldpll); if (rc) { - dpll_device_put(zldpll->dpll_dev, NULL); + dpll_device_put(zldpll->dpll_dev, &zldpll->tracker); zldpll->dpll_dev = NULL; } @@ -1743,7 +1745,7 @@ zl3073x_dpll_device_unregister(struct zl3073x_dpll *zldpll) dpll_device_unregister(zldpll->dpll_dev, &zl3073x_dpll_device_ops, zldpll); - dpll_device_put(zldpll->dpll_dev, NULL); + dpll_device_put(zldpll->dpll_dev, &zldpll->tracker); zldpll->dpll_dev = NULL; } diff --git a/drivers/dpll/zl3073x/dpll.h b/drivers/dpll/zl3073x/dpll.h index e8c39b44b356c..c65c798c37927 100644 --- a/drivers/dpll/zl3073x/dpll.h +++ b/drivers/dpll/zl3073x/dpll.h @@ -18,6 +18,7 @@ * @check_count: periodic check counter * @phase_monitor: is phase offset monitor enabled * @dpll_dev: pointer to registered DPLL device + * @tracker: tracking object for the acquired reference * @lock_status: last saved DPLL lock status * @pins: list of pins * @change_work: device change notification work @@ -31,6 +32,7 @@ struct zl3073x_dpll { u8 check_count; bool phase_monitor; struct dpll_device *dpll_dev; + dpll_tracker tracker; enum dpll_lock_status lock_status; struct list_head pins; struct work_struct change_work; diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethernet/intel/ice/ice_dpll.c index 64b7b045ecd58..4eca62688d834 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -2814,7 +2814,7 @@ static void ice_dpll_release_pins(struct ice_dpll_pin *pins, int count) int i; for (i = 0; i < count; i++) - dpll_pin_put(pins[i].pin, NULL); + dpll_pin_put(pins[i].pin, &pins[i].tracker); } /** @@ -2840,7 +2840,7 @@ ice_dpll_get_pins(struct ice_pf *pf, struct ice_dpll_pin *pins, for (i = 0; i < count; i++) { pins[i].pin = dpll_pin_get(clock_id, i + start_idx, THIS_MODULE, - &pins[i].prop, NULL); + &pins[i].prop, &pins[i].tracker); if (IS_ERR(pins[i].pin)) { ret = PTR_ERR(pins[i].pin); goto release_pins; @@ -2851,7 +2851,7 @@ ice_dpll_get_pins(struct ice_pf *pf, struct ice_dpll_pin *pins, release_pins: while (--i >= 0) - dpll_pin_put(pins[i].pin, NULL); + dpll_pin_put(pins[i].pin, &pins[i].tracker); return ret; } @@ -3037,7 +3037,7 @@ static void ice_dpll_deinit_rclk_pin(struct ice_pf *pf) if (WARN_ON_ONCE(!vsi || !vsi->netdev)) return; dpll_netdev_pin_clear(vsi->netdev); - dpll_pin_put(rclk->pin, NULL); + dpll_pin_put(rclk->pin, &rclk->tracker); } /** @@ -3247,7 +3247,7 @@ ice_dpll_deinit_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu) { if (cgu) dpll_device_unregister(d->dpll, d->ops, d); - dpll_device_put(d->dpll, NULL); + dpll_device_put(d->dpll, &d->tracker); } /** @@ -3271,7 +3271,8 @@ ice_dpll_init_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu, u64 clock_id = pf->dplls.clock_id; int ret; - d->dpll = dpll_device_get(clock_id, d->dpll_idx, THIS_MODULE, NULL); + d->dpll = dpll_device_get(clock_id, d->dpll_idx, THIS_MODULE, + &d->tracker); if (IS_ERR(d->dpll)) { ret = PTR_ERR(d->dpll); dev_err(ice_pf_to_dev(pf), @@ -3287,7 +3288,7 @@ ice_dpll_init_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu, ice_dpll_update_state(pf, d, true); ret = dpll_device_register(d->dpll, type, ops, d); if (ret) { - dpll_device_put(d->dpll, NULL); + dpll_device_put(d->dpll, &d->tracker); return ret; } d->ops = ops; diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.h b/drivers/net/ethernet/intel/ice/ice_dpll.h index c0da03384ce91..63fac6510df6e 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.h +++ b/drivers/net/ethernet/intel/ice/ice_dpll.h @@ -23,6 +23,7 @@ enum ice_dpll_pin_sw { /** ice_dpll_pin - store info about pins * @pin: dpll pin structure * @pf: pointer to pf, which has registered the dpll_pin + * @tracker: reference count tracker * @idx: ice pin private idx * @num_parents: hols number of parent pins * @parent_idx: hold indexes of parent pins @@ -37,6 +38,7 @@ enum ice_dpll_pin_sw { struct ice_dpll_pin { struct dpll_pin *pin; struct ice_pf *pf; + dpll_tracker tracker; u8 idx; u8 num_parents; u8 parent_idx[ICE_DPLL_RCLK_NUM_MAX]; @@ -58,6 +60,7 @@ struct ice_dpll_pin { /** ice_dpll - store info required for DPLL control * @dpll: pointer to dpll dev * @pf: pointer to pf, which has registered the dpll_device + * @tracker: reference count tracker * @dpll_idx: index of dpll on the NIC * @input_idx: currently selected input index * @prev_input_idx: previously selected input index @@ -76,6 +79,7 @@ struct ice_dpll_pin { struct ice_dpll { struct dpll_device *dpll; struct ice_pf *pf; + dpll_tracker tracker; u8 dpll_idx; u8 input_idx; u8 prev_input_idx; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dpll.c b/drivers/net/ethernet/mellanox/mlx5/core/dpll.c index 541d83e5d7183..3981dd81d4c17 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/dpll.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/dpll.c @@ -9,7 +9,9 @@ */ struct mlx5_dpll { struct dpll_device *dpll; + dpll_tracker dpll_tracker; struct dpll_pin *dpll_pin; + dpll_tracker pin_tracker; struct mlx5_core_dev *mdev; struct workqueue_struct *wq; struct delayed_work work; @@ -438,7 +440,8 @@ static int mlx5_dpll_probe(struct auxiliary_device *adev, auxiliary_set_drvdata(adev, mdpll); /* Multiple mdev instances might share one DPLL device. */ - mdpll->dpll = dpll_device_get(clock_id, 0, THIS_MODULE, NULL); + mdpll->dpll = dpll_device_get(clock_id, 0, THIS_MODULE, + &mdpll->dpll_tracker); if (IS_ERR(mdpll->dpll)) { err = PTR_ERR(mdpll->dpll); goto err_free_mdpll; @@ -452,7 +455,7 @@ static int mlx5_dpll_probe(struct auxiliary_device *adev, /* Multiple mdev instances might share one DPLL pin. */ mdpll->dpll_pin = dpll_pin_get(clock_id, mlx5_get_dev_index(mdev), THIS_MODULE, &mlx5_dpll_pin_properties, - NULL); + &mdpll->pin_tracker); if (IS_ERR(mdpll->dpll_pin)) { err = PTR_ERR(mdpll->dpll_pin); goto err_unregister_dpll_device; @@ -480,11 +483,11 @@ static int mlx5_dpll_probe(struct auxiliary_device *adev, dpll_pin_unregister(mdpll->dpll, mdpll->dpll_pin, &mlx5_dpll_pins_ops, mdpll); err_put_dpll_pin: - dpll_pin_put(mdpll->dpll_pin, NULL); + dpll_pin_put(mdpll->dpll_pin, &mdpll->pin_tracker); err_unregister_dpll_device: dpll_device_unregister(mdpll->dpll, &mlx5_dpll_device_ops, mdpll); err_put_dpll_device: - dpll_device_put(mdpll->dpll, NULL); + dpll_device_put(mdpll->dpll, &mdpll->dpll_tracker); err_free_mdpll: kfree(mdpll); return err; @@ -500,9 +503,9 @@ static void mlx5_dpll_remove(struct auxiliary_device *adev) destroy_workqueue(mdpll->wq); dpll_pin_unregister(mdpll->dpll, mdpll->dpll_pin, &mlx5_dpll_pins_ops, mdpll); - dpll_pin_put(mdpll->dpll_pin, NULL); + dpll_pin_put(mdpll->dpll_pin, &mdpll->pin_tracker); dpll_device_unregister(mdpll->dpll, &mlx5_dpll_device_ops, mdpll); - dpll_device_put(mdpll->dpll, NULL); + dpll_device_put(mdpll->dpll, &mdpll->dpll_tracker); kfree(mdpll); mlx5_dpll_synce_status_set(mdev, diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index f39b3966b3e8c..1b16a9c3d7fdc 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -285,6 +285,7 @@ struct ptp_ocp_sma_connector { u8 default_fcn; struct dpll_pin *dpll_pin; struct dpll_pin_properties dpll_prop; + dpll_tracker tracker; }; struct ocp_attr_group { @@ -383,6 +384,7 @@ struct ptp_ocp { struct ptp_ocp_sma_connector sma[OCP_SMA_NUM]; const struct ocp_sma_op *sma_op; struct dpll_device *dpll; + dpll_tracker tracker; int signals_nr; int freq_in_nr; }; @@ -4788,7 +4790,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) devlink_register(devlink); clkid = pci_get_dsn(pdev); - bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE, NULL); + bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE, &bp->tracker); if (IS_ERR(bp->dpll)) { err = PTR_ERR(bp->dpll); dev_err(&pdev->dev, "dpll_device_alloc failed\n"); @@ -4801,7 +4803,8 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) for (i = 0; i < OCP_SMA_NUM; i++) { bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, - &bp->sma[i].dpll_prop, NULL); + &bp->sma[i].dpll_prop, + &bp->sma[i].tracker); if (IS_ERR(bp->sma[i].dpll_pin)) { err = PTR_ERR(bp->sma[i].dpll_pin); goto out_dpll; @@ -4810,7 +4813,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) err = dpll_pin_register(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); if (err) { - dpll_pin_put(bp->sma[i].dpll_pin, NULL); + dpll_pin_put(bp->sma[i].dpll_pin, &bp->sma[i].tracker); goto out_dpll; } } @@ -4820,9 +4823,9 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) out_dpll: while (i--) { dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); - dpll_pin_put(bp->sma[i].dpll_pin, NULL); + dpll_pin_put(bp->sma[i].dpll_pin, &bp->sma[i].tracker); } - dpll_device_put(bp->dpll, NULL); + dpll_device_put(bp->dpll, &bp->tracker); out: ptp_ocp_detach(bp); out_disable: @@ -4843,11 +4846,11 @@ ptp_ocp_remove(struct pci_dev *pdev) for (i = 0; i < OCP_SMA_NUM; i++) { if (bp->sma[i].dpll_pin) { dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); - dpll_pin_put(bp->sma[i].dpll_pin, NULL); + dpll_pin_put(bp->sma[i].dpll_pin, &bp->sma[i].tracker); } } dpll_device_unregister(bp->dpll, &dpll_ops, bp); - dpll_device_put(bp->dpll, NULL); + dpll_device_put(bp->dpll, &bp->tracker); devlink_unregister(devlink); ptp_ocp_detach(bp); pci_disable_device(pdev); -- 2.52.0
{ "author": "Ivan Vecera <ivecera@redhat.com>", "date": "Mon, 2 Feb 2026 18:16:37 +0100", "thread_id": "20260202171638.17427-1-ivecera@redhat.com.mbox.gz" }
lkml
[PATCH net-next v4 0/9] dpll: Core improvements and ice E825-C SyncE support
This series introduces Synchronous Ethernet (SyncE) support for the Intel E825-C Ethernet controller. Unlike previous generations where DPLL connections were implicitly assumed, the E825-C architecture relies on the platform firmware (ACPI) to describe the physical connections between the Ethernet controller and external DPLLs (such as the ZL3073x). To accommodate this, the series extends the DPLL subsystem to support firmware node (fwnode) associations, asynchronous discovery via notifiers, and dynamic pin management. Additionally, a significant refactor of the DPLL reference counting logic is included to ensure robustness and debuggability. DPLL Core Extensions: * Firmware Node Association: Pins can now be associated with a struct fwnode_handle after allocation via dpll_pin_fwnode_set(). This allows drivers to link pin objects with their corresponding DT/ACPI nodes. * Asynchronous Notifiers: A raw notifier chain is added to the DPLL core. This allows the Ethernet driver to subscribe to events and react when the platform DPLL driver registers the parent pins, resolving probe ordering dependencies. * Dynamic Indexing: Drivers can now request DPLL_PIN_IDX_UNSPEC to have the core automatically allocate a unique pin index. Reference Counting & Debugging: * Refactor: The reference counting logic in the core is consolidated. Internal list management helpers now automatically handle hold/put operations, removing fragile open-coded logic in the registration paths. * Reference Tracking: A new Kconfig option DPLL_REFCNT_TRACKER is added. This allows developers to instrument and debug reference leaks by recording stack traces for every get/put operation. Driver Updates: * zl3073x: Updated to associate pins with fwnode handles using the new setter and support the 'mux' pin type. * ice: Implements the E825-C specific hardware configuration for SyncE (CGU registers). It utilizes the new notifier and fwnode APIs to dynamically discover and attach to the platform DPLLs. Patch Summary: Patch 1: DPLL Core (fwnode association). Patch 2: Driver zl3073x (Set fwnode). Patch 3-4: DPLL Core (Notifiers and dynamic IDs). Patch 5: Driver zl3073x (Mux type). Patch 6: DPLL Core (Refcount refactor). Patch 7-8: Refcount tracking infrastructure and driver updates. Patch 9: Driver ice (E825-C SyncE logic). Changes in v4: * Fixed documentation and function stub issues found by AI Arkadiusz Kubalewski (1): ice: dpll: Support E825-C SyncE and dynamic pin discovery Ivan Vecera (7): dpll: Allow associating dpll pin with a firmware node dpll: zl3073x: Associate pin with fwnode handle dpll: Support dynamic pin index allocation dpll: zl3073x: Add support for mux pin type dpll: Enhance and consolidate reference counting logic dpll: Add reference count tracking support drivers: Add support for DPLL reference count tracking Petr Oros (1): dpll: Add notifier chain for dpll events drivers/dpll/Kconfig | 15 + drivers/dpll/dpll_core.c | 288 ++++++- drivers/dpll/dpll_core.h | 11 + drivers/dpll/dpll_netlink.c | 6 + drivers/dpll/zl3073x/dpll.c | 15 +- drivers/dpll/zl3073x/dpll.h | 2 + drivers/dpll/zl3073x/prop.c | 2 + drivers/net/ethernet/intel/ice/ice_dpll.c | 755 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 30 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 +++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 16 +- drivers/ptp/ptp_ocp.c | 18 +- include/linux/dpll.h | 59 +- 18 files changed, 1347 insertions(+), 150 deletions(-) -- 2.52.0
From: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com> Implement SyncE support for the E825-C Ethernet controller using the DPLL subsystem. Unlike E810, the E825-C architecture relies on platform firmware (ACPI) to describe connections between the NIC's recovered clock outputs and external DPLL inputs. Implement the following mechanisms to support this architecture: 1. Discovery Mechanism: The driver parses the 'dpll-pins' and 'dpll-pin names' firmware properties to identify the external DPLL pins (parents) corresponding to its RCLK outputs ("rclk0", "rclk1"). It uses fwnode_dpll_pin_find() to locate these parent pins in the DPLL core. 2. Asynchronous Registration: Since the platform DPLL driver (e.g. zl3073x) may probe independently of the network driver, utilize the DPLL notifier chain The driver listens for DPLL_PIN_CREATED events to detect when the parent MUX pins become available, then registers its own Recovered Clock (RCLK) pins as children of those parents. 3. Hardware Configuration: Implement the specific register access logic for E825-C CGU (Clock Generation Unit) registers (R10, R11). This includes configuring the bypass MUXes and clock dividers required to drive SyncE signals. 4. Split Initialization: Refactor `ice_dpll_init()` to separate the static initialization path of E810 from the dynamic, firmware-driven path required for E825-C. Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Co-developed-by: Ivan Vecera <ivecera@redhat.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> Co-developed-by: Grzegorz Nitka <grzegorz.nitka@intel.com> Signed-off-by: Grzegorz Nitka <grzegorz.nitka@intel.com> Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com> --- v3: * DPLL init check in ice_ptp_link_change() * using completion for dpll initization to avoid races with DPLL notifier scheduled works * added parsing of dpll-pin-names and dpll-pins properties v2: * fixed error path in ice_dpll_init_pins_e825() * fixed misleading comment referring 'device tree' --- drivers/net/ethernet/intel/ice/ice_dpll.c | 742 +++++++++++++++++--- drivers/net/ethernet/intel/ice/ice_dpll.h | 26 + drivers/net/ethernet/intel/ice/ice_lib.c | 3 + drivers/net/ethernet/intel/ice/ice_ptp.c | 32 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 9 +- drivers/net/ethernet/intel/ice/ice_tspll.c | 217 ++++++ drivers/net/ethernet/intel/ice/ice_tspll.h | 13 +- drivers/net/ethernet/intel/ice/ice_type.h | 6 + 8 files changed, 956 insertions(+), 92 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethernet/intel/ice/ice_dpll.c index 4eca62688d834..a8c99e49bfae6 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -5,6 +5,7 @@ #include "ice_lib.h" #include "ice_trace.h" #include <linux/dpll.h> +#include <linux/property.h> #define ICE_CGU_STATE_ACQ_ERR_THRESHOLD 50 #define ICE_DPLL_PIN_IDX_INVALID 0xff @@ -528,6 +529,92 @@ ice_dpll_pin_disable(struct ice_hw *hw, struct ice_dpll_pin *pin, return ret; } +/** + * ice_dpll_pin_store_state - updates the state of pin in SW bookkeeping + * @pin: pointer to a pin + * @parent: parent pin index + * @state: pin state (connected or disconnected) + */ +static void +ice_dpll_pin_store_state(struct ice_dpll_pin *pin, int parent, bool state) +{ + pin->state[parent] = state ? DPLL_PIN_STATE_CONNECTED : + DPLL_PIN_STATE_DISCONNECTED; +} + +/** + * ice_dpll_rclk_update_e825c - updates the state of rclk pin on e825c device + * @pf: private board struct + * @pin: pointer to a pin + * + * Update struct holding pin states info, states are separate for each parent + * + * Context: Called under pf->dplls.lock + * Return: + * * 0 - OK + * * negative - error + */ +static int ice_dpll_rclk_update_e825c(struct ice_pf *pf, + struct ice_dpll_pin *pin) +{ + u8 rclk_bits; + int err; + u32 reg; + + if (pf->dplls.rclk.num_parents > ICE_SYNCE_CLK_NUM) + return -EINVAL; + + err = ice_read_cgu_reg(&pf->hw, ICE_CGU_R10, &reg); + if (err) + return err; + + rclk_bits = FIELD_GET(ICE_CGU_R10_SYNCE_S_REF_CLK, reg); + ice_dpll_pin_store_state(pin, ICE_SYNCE_CLK0, rclk_bits == + (pf->ptp.port.port_num + ICE_CGU_BYPASS_MUX_OFFSET_E825C)); + + err = ice_read_cgu_reg(&pf->hw, ICE_CGU_R11, &reg); + if (err) + return err; + + rclk_bits = FIELD_GET(ICE_CGU_R11_SYNCE_S_BYP_CLK, reg); + ice_dpll_pin_store_state(pin, ICE_SYNCE_CLK1, rclk_bits == + (pf->ptp.port.port_num + ICE_CGU_BYPASS_MUX_OFFSET_E825C)); + + return 0; +} + +/** + * ice_dpll_rclk_update - updates the state of rclk pin on a device + * @pf: private board struct + * @pin: pointer to a pin + * @port_num: port number + * + * Update struct holding pin states info, states are separate for each parent + * + * Context: Called under pf->dplls.lock + * Return: + * * 0 - OK + * * negative - error + */ +static int ice_dpll_rclk_update(struct ice_pf *pf, struct ice_dpll_pin *pin, + u8 port_num) +{ + int ret; + + for (u8 parent = 0; parent < pf->dplls.rclk.num_parents; parent++) { + ret = ice_aq_get_phy_rec_clk_out(&pf->hw, &parent, &port_num, + &pin->flags[parent], NULL); + if (ret) + return ret; + + ice_dpll_pin_store_state(pin, parent, + ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN & + pin->flags[parent]); + } + + return 0; +} + /** * ice_dpll_sw_pins_update - update status of all SW pins * @pf: private board struct @@ -668,22 +755,14 @@ ice_dpll_pin_state_update(struct ice_pf *pf, struct ice_dpll_pin *pin, } break; case ICE_DPLL_PIN_TYPE_RCLK_INPUT: - for (parent = 0; parent < pf->dplls.rclk.num_parents; - parent++) { - u8 p = parent; - - ret = ice_aq_get_phy_rec_clk_out(&pf->hw, &p, - &port_num, - &pin->flags[parent], - NULL); + if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) { + ret = ice_dpll_rclk_update_e825c(pf, pin); + if (ret) + goto err; + } else { + ret = ice_dpll_rclk_update(pf, pin, port_num); if (ret) goto err; - if (ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN & - pin->flags[parent]) - pin->state[parent] = DPLL_PIN_STATE_CONNECTED; - else - pin->state[parent] = - DPLL_PIN_STATE_DISCONNECTED; } break; case ICE_DPLL_PIN_TYPE_SOFTWARE: @@ -1842,6 +1921,40 @@ ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv, return 0; } +/** + * ice_dpll_synce_update_e825c - setting PHY recovered clock pins on e825c + * @hw: Pointer to the HW struct + * @ena: true if enable, false in disable + * @port_num: port number + * @output: output pin, we have two in E825C + * + * DPLL subsystem callback. Set proper signals to recover clock from port. + * + * Context: Called under pf->dplls.lock + * Return: + * * 0 - success + * * negative - error + */ +static int ice_dpll_synce_update_e825c(struct ice_hw *hw, bool ena, + u32 port_num, enum ice_synce_clk output) +{ + int err; + + /* configure the mux to deliver proper signal to DPLL from the MUX */ + err = ice_tspll_cfg_bypass_mux_e825c(hw, ena, port_num, output); + if (err) + return err; + + err = ice_tspll_cfg_synce_ethdiv_e825c(hw, output); + if (err) + return err; + + dev_dbg(ice_hw_to_dev(hw), "CLK_SYNCE%u recovered clock: pin %s\n", + output, str_enabled_disabled(ena)); + + return 0; +} + /** * ice_dpll_output_esync_set - callback for setting embedded sync * @pin: pointer to a pin @@ -2263,6 +2376,28 @@ ice_dpll_sw_input_ref_sync_get(const struct dpll_pin *pin, void *pin_priv, state, extack); } +static int +ice_dpll_pin_get_parent_num(struct ice_dpll_pin *pin, + const struct dpll_pin *parent) +{ + int i; + + for (i = 0; i < pin->num_parents; i++) + if (pin->pf->dplls.inputs[pin->parent_idx[i]].pin == parent) + return i; + + return -ENOENT; +} + +static int +ice_dpll_pin_get_parent_idx(struct ice_dpll_pin *pin, + const struct dpll_pin *parent) +{ + int num = ice_dpll_pin_get_parent_num(pin, parent); + + return num < 0 ? num : pin->parent_idx[num]; +} + /** * ice_dpll_rclk_state_on_pin_set - set a state on rclk pin * @pin: pointer to a pin @@ -2286,35 +2421,44 @@ ice_dpll_rclk_state_on_pin_set(const struct dpll_pin *pin, void *pin_priv, enum dpll_pin_state state, struct netlink_ext_ack *extack) { - struct ice_dpll_pin *p = pin_priv, *parent = parent_pin_priv; bool enable = state == DPLL_PIN_STATE_CONNECTED; + struct ice_dpll_pin *p = pin_priv; struct ice_pf *pf = p->pf; + struct ice_hw *hw; int ret = -EINVAL; - u32 hw_idx; + int hw_idx; + + hw = &pf->hw; if (ice_dpll_is_reset(pf, extack)) return -EBUSY; mutex_lock(&pf->dplls.lock); - hw_idx = parent->idx - pf->dplls.base_rclk_idx; - if (hw_idx >= pf->dplls.num_inputs) + hw_idx = ice_dpll_pin_get_parent_idx(p, parent_pin); + if (hw_idx < 0) goto unlock; if ((enable && p->state[hw_idx] == DPLL_PIN_STATE_CONNECTED) || (!enable && p->state[hw_idx] == DPLL_PIN_STATE_DISCONNECTED)) { NL_SET_ERR_MSG_FMT(extack, "pin:%u state:%u on parent:%u already set", - p->idx, state, parent->idx); + p->idx, state, + ice_dpll_pin_get_parent_num(p, parent_pin)); goto unlock; } - ret = ice_aq_set_phy_rec_clk_out(&pf->hw, hw_idx, enable, - &p->freq); + + ret = hw->mac_type == ICE_MAC_GENERIC_3K_E825 ? + ice_dpll_synce_update_e825c(hw, enable, + pf->ptp.port.port_num, + (enum ice_synce_clk)hw_idx) : + ice_aq_set_phy_rec_clk_out(hw, hw_idx, enable, &p->freq); if (ret) NL_SET_ERR_MSG_FMT(extack, "err:%d %s failed to set pin state:%u for pin:%u on parent:%u", ret, - libie_aq_str(pf->hw.adminq.sq_last_status), - state, p->idx, parent->idx); + libie_aq_str(hw->adminq.sq_last_status), + state, p->idx, + ice_dpll_pin_get_parent_num(p, parent_pin)); unlock: mutex_unlock(&pf->dplls.lock); @@ -2344,17 +2488,17 @@ ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin, void *pin_priv, enum dpll_pin_state *state, struct netlink_ext_ack *extack) { - struct ice_dpll_pin *p = pin_priv, *parent = parent_pin_priv; + struct ice_dpll_pin *p = pin_priv; struct ice_pf *pf = p->pf; int ret = -EINVAL; - u32 hw_idx; + int hw_idx; if (ice_dpll_is_reset(pf, extack)) return -EBUSY; mutex_lock(&pf->dplls.lock); - hw_idx = parent->idx - pf->dplls.base_rclk_idx; - if (hw_idx >= pf->dplls.num_inputs) + hw_idx = ice_dpll_pin_get_parent_idx(p, parent_pin); + if (hw_idx < 0) goto unlock; ret = ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_RCLK_INPUT, @@ -2814,7 +2958,8 @@ static void ice_dpll_release_pins(struct ice_dpll_pin *pins, int count) int i; for (i = 0; i < count; i++) - dpll_pin_put(pins[i].pin, &pins[i].tracker); + if (!IS_ERR_OR_NULL(pins[i].pin)) + dpll_pin_put(pins[i].pin, &pins[i].tracker); } /** @@ -2836,10 +2981,14 @@ static int ice_dpll_get_pins(struct ice_pf *pf, struct ice_dpll_pin *pins, int start_idx, int count, u64 clock_id) { + u32 pin_index; int i, ret; for (i = 0; i < count; i++) { - pins[i].pin = dpll_pin_get(clock_id, i + start_idx, THIS_MODULE, + pin_index = start_idx; + if (start_idx != DPLL_PIN_IDX_UNSPEC) + pin_index += i; + pins[i].pin = dpll_pin_get(clock_id, pin_index, THIS_MODULE, &pins[i].prop, &pins[i].tracker); if (IS_ERR(pins[i].pin)) { ret = PTR_ERR(pins[i].pin); @@ -2944,6 +3093,7 @@ ice_dpll_register_pins(struct dpll_device *dpll, struct ice_dpll_pin *pins, /** * ice_dpll_deinit_direct_pins - deinitialize direct pins + * @pf: board private structure * @cgu: if cgu is present and controlled by this NIC * @pins: pointer to pins array * @count: number of pins @@ -2955,7 +3105,8 @@ ice_dpll_register_pins(struct dpll_device *dpll, struct ice_dpll_pin *pins, * Release pins resources to the dpll subsystem. */ static void -ice_dpll_deinit_direct_pins(bool cgu, struct ice_dpll_pin *pins, int count, +ice_dpll_deinit_direct_pins(struct ice_pf *pf, bool cgu, + struct ice_dpll_pin *pins, int count, const struct dpll_pin_ops *ops, struct dpll_device *first, struct dpll_device *second) @@ -3024,14 +3175,14 @@ static void ice_dpll_deinit_rclk_pin(struct ice_pf *pf) { struct ice_dpll_pin *rclk = &pf->dplls.rclk; struct ice_vsi *vsi = ice_get_main_vsi(pf); - struct dpll_pin *parent; + struct ice_dpll_pin *parent; int i; for (i = 0; i < rclk->num_parents; i++) { - parent = pf->dplls.inputs[rclk->parent_idx[i]].pin; - if (!parent) + parent = &pf->dplls.inputs[rclk->parent_idx[i]]; + if (IS_ERR_OR_NULL(parent->pin)) continue; - dpll_pin_on_pin_unregister(parent, rclk->pin, + dpll_pin_on_pin_unregister(parent->pin, rclk->pin, &ice_dpll_rclk_ops, rclk); } if (WARN_ON_ONCE(!vsi || !vsi->netdev)) @@ -3040,60 +3191,213 @@ static void ice_dpll_deinit_rclk_pin(struct ice_pf *pf) dpll_pin_put(rclk->pin, &rclk->tracker); } +static bool ice_dpll_is_fwnode_pin(struct ice_dpll_pin *pin) +{ + return !IS_ERR_OR_NULL(pin->fwnode); +} + +static void ice_dpll_pin_notify_work(struct work_struct *work) +{ + struct ice_dpll_pin_work *w = container_of(work, + struct ice_dpll_pin_work, + work); + struct ice_dpll_pin *pin, *parent = w->pin; + struct ice_pf *pf = parent->pf; + int ret; + + wait_for_completion(&pf->dplls.dpll_init); + if (!test_bit(ICE_FLAG_DPLL, pf->flags)) + return; /* DPLL initialization failed */ + + switch (w->action) { + case DPLL_PIN_CREATED: + if (!IS_ERR_OR_NULL(parent->pin)) { + /* We have already our pin registered */ + goto out; + } + + /* Grab reference on fwnode pin */ + parent->pin = fwnode_dpll_pin_find(parent->fwnode, + &parent->tracker); + if (IS_ERR_OR_NULL(parent->pin)) { + dev_err(ice_pf_to_dev(pf), + "Cannot get fwnode pin reference\n"); + goto out; + } + + /* Register rclk pin */ + pin = &pf->dplls.rclk; + ret = dpll_pin_on_pin_register(parent->pin, pin->pin, + &ice_dpll_rclk_ops, pin); + if (ret) { + dev_err(ice_pf_to_dev(pf), + "Failed to register pin: %pe\n", ERR_PTR(ret)); + dpll_pin_put(parent->pin, &parent->tracker); + parent->pin = NULL; + goto out; + } + break; + case DPLL_PIN_DELETED: + if (IS_ERR_OR_NULL(parent->pin)) { + /* We have already our pin unregistered */ + goto out; + } + + /* Unregister rclk pin */ + pin = &pf->dplls.rclk; + dpll_pin_on_pin_unregister(parent->pin, pin->pin, + &ice_dpll_rclk_ops, pin); + + /* Drop fwnode pin reference */ + dpll_pin_put(parent->pin, &parent->tracker); + parent->pin = NULL; + break; + default: + break; + } +out: + kfree(w); +} + +static int ice_dpll_pin_notify(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct ice_dpll_pin *pin = container_of(nb, struct ice_dpll_pin, nb); + struct dpll_pin_notifier_info *info = data; + struct ice_dpll_pin_work *work; + + if (action != DPLL_PIN_CREATED && action != DPLL_PIN_DELETED) + return NOTIFY_DONE; + + /* Check if the reported pin is this one */ + if (pin->fwnode != info->fwnode) + return NOTIFY_DONE; /* Not this pin */ + + work = kzalloc(sizeof(*work), GFP_KERNEL); + if (!work) + return NOTIFY_DONE; + + INIT_WORK(&work->work, ice_dpll_pin_notify_work); + work->action = action; + work->pin = pin; + + queue_work(pin->pf->dplls.wq, &work->work); + + return NOTIFY_OK; +} + /** - * ice_dpll_init_rclk_pins - initialize recovered clock pin + * ice_dpll_init_pin_common - initialize pin * @pf: board private structure * @pin: pin to register * @start_idx: on which index shall allocation start in dpll subsystem * @ops: callback ops registered with the pins * - * Allocate resource for recovered clock pin in dpll subsystem. Register the - * pin with the parents it has in the info. Register pin with the pf's main vsi - * netdev. + * Allocate resource for given pin in dpll subsystem. Register the pin with + * the parents it has in the info. * * Return: * * 0 - success * * negative - registration failure reason */ static int -ice_dpll_init_rclk_pins(struct ice_pf *pf, struct ice_dpll_pin *pin, - int start_idx, const struct dpll_pin_ops *ops) +ice_dpll_init_pin_common(struct ice_pf *pf, struct ice_dpll_pin *pin, + int start_idx, const struct dpll_pin_ops *ops) { - struct ice_vsi *vsi = ice_get_main_vsi(pf); - struct dpll_pin *parent; + struct ice_dpll_pin *parent; int ret, i; - if (WARN_ON((!vsi || !vsi->netdev))) - return -EINVAL; - ret = ice_dpll_get_pins(pf, pin, start_idx, ICE_DPLL_RCLK_NUM_PER_PF, - pf->dplls.clock_id); + ret = ice_dpll_get_pins(pf, pin, start_idx, 1, pf->dplls.clock_id); if (ret) return ret; - for (i = 0; i < pf->dplls.rclk.num_parents; i++) { - parent = pf->dplls.inputs[pf->dplls.rclk.parent_idx[i]].pin; - if (!parent) { - ret = -ENODEV; - goto unregister_pins; + + for (i = 0; i < pin->num_parents; i++) { + parent = &pf->dplls.inputs[pin->parent_idx[i]]; + if (IS_ERR_OR_NULL(parent->pin)) { + if (!ice_dpll_is_fwnode_pin(parent)) { + ret = -ENODEV; + goto unregister_pins; + } + parent->pin = fwnode_dpll_pin_find(parent->fwnode, + &parent->tracker); + if (IS_ERR_OR_NULL(parent->pin)) { + dev_info(ice_pf_to_dev(pf), + "Mux pin not registered yet\n"); + continue; + } } - ret = dpll_pin_on_pin_register(parent, pf->dplls.rclk.pin, - ops, &pf->dplls.rclk); + ret = dpll_pin_on_pin_register(parent->pin, pin->pin, ops, pin); if (ret) goto unregister_pins; } - dpll_netdev_pin_set(vsi->netdev, pf->dplls.rclk.pin); return 0; unregister_pins: while (i) { - parent = pf->dplls.inputs[pf->dplls.rclk.parent_idx[--i]].pin; - dpll_pin_on_pin_unregister(parent, pf->dplls.rclk.pin, - &ice_dpll_rclk_ops, &pf->dplls.rclk); + parent = &pf->dplls.inputs[pin->parent_idx[--i]]; + if (IS_ERR_OR_NULL(parent->pin)) + continue; + dpll_pin_on_pin_unregister(parent->pin, pin->pin, ops, pin); } - ice_dpll_release_pins(pin, ICE_DPLL_RCLK_NUM_PER_PF); + ice_dpll_release_pins(pin, 1); + return ret; } +/** + * ice_dpll_init_rclk_pin - initialize recovered clock pin + * @pf: board private structure + * @start_idx: on which index shall allocation start in dpll subsystem + * @ops: callback ops registered with the pins + * + * Allocate resource for recovered clock pin in dpll subsystem. Register the + * pin with the parents it has in the info. + * + * Return: + * * 0 - success + * * negative - registration failure reason + */ +static int +ice_dpll_init_rclk_pin(struct ice_pf *pf, int start_idx, + const struct dpll_pin_ops *ops) +{ + struct ice_vsi *vsi = ice_get_main_vsi(pf); + int ret; + + ret = ice_dpll_init_pin_common(pf, &pf->dplls.rclk, start_idx, ops); + if (ret) + return ret; + + dpll_netdev_pin_set(vsi->netdev, pf->dplls.rclk.pin); + + return 0; +} + +static void +ice_dpll_deinit_fwnode_pin(struct ice_dpll_pin *pin) +{ + unregister_dpll_notifier(&pin->nb); + flush_workqueue(pin->pf->dplls.wq); + if (!IS_ERR_OR_NULL(pin->pin)) { + dpll_pin_put(pin->pin, &pin->tracker); + pin->pin = NULL; + } + fwnode_handle_put(pin->fwnode); + pin->fwnode = NULL; +} + +static void +ice_dpll_deinit_fwnode_pins(struct ice_pf *pf, struct ice_dpll_pin *pins, + int start_idx) +{ + int i; + + for (i = 0; i < pf->dplls.rclk.num_parents; i++) + ice_dpll_deinit_fwnode_pin(&pins[start_idx + i]); + destroy_workqueue(pf->dplls.wq); +} + /** * ice_dpll_deinit_pins - deinitialize direct pins * @pf: board private structure @@ -3113,6 +3417,8 @@ static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu) struct ice_dpll *dp = &d->pps; ice_dpll_deinit_rclk_pin(pf); + if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) + ice_dpll_deinit_fwnode_pins(pf, pf->dplls.inputs, 0); if (cgu) { ice_dpll_unregister_pins(dp->dpll, inputs, &ice_dpll_input_ops, num_inputs); @@ -3127,12 +3433,12 @@ static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu) &ice_dpll_output_ops, num_outputs); ice_dpll_release_pins(outputs, num_outputs); if (!pf->dplls.generic) { - ice_dpll_deinit_direct_pins(cgu, pf->dplls.ufl, + ice_dpll_deinit_direct_pins(pf, cgu, pf->dplls.ufl, ICE_DPLL_PIN_SW_NUM, &ice_dpll_pin_ufl_ops, pf->dplls.pps.dpll, pf->dplls.eec.dpll); - ice_dpll_deinit_direct_pins(cgu, pf->dplls.sma, + ice_dpll_deinit_direct_pins(pf, cgu, pf->dplls.sma, ICE_DPLL_PIN_SW_NUM, &ice_dpll_pin_sma_ops, pf->dplls.pps.dpll, @@ -3141,6 +3447,141 @@ static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu) } } +static struct fwnode_handle * +ice_dpll_pin_node_get(struct ice_pf *pf, const char *name) +{ + struct fwnode_handle *fwnode = dev_fwnode(ice_pf_to_dev(pf)); + int index; + + index = fwnode_property_match_string(fwnode, "dpll-pin-names", name); + if (index < 0) + return ERR_PTR(-ENOENT); + + return fwnode_find_reference(fwnode, "dpll-pins", index); +} + +static int +ice_dpll_init_fwnode_pin(struct ice_dpll_pin *pin, const char *name) +{ + struct ice_pf *pf = pin->pf; + int ret; + + pin->fwnode = ice_dpll_pin_node_get(pf, name); + if (IS_ERR(pin->fwnode)) { + dev_err(ice_pf_to_dev(pf), + "Failed to find %s firmware node: %pe\n", name, + pin->fwnode); + pin->fwnode = NULL; + return -ENODEV; + } + + dev_dbg(ice_pf_to_dev(pf), "Found fwnode node for %s\n", name); + + pin->pin = fwnode_dpll_pin_find(pin->fwnode, &pin->tracker); + if (IS_ERR_OR_NULL(pin->pin)) { + dev_info(ice_pf_to_dev(pf), + "DPLL pin for %pfwp not registered yet\n", + pin->fwnode); + pin->pin = NULL; + } + + pin->nb.notifier_call = ice_dpll_pin_notify; + ret = register_dpll_notifier(&pin->nb); + if (ret) { + dev_err(ice_pf_to_dev(pf), + "Failed to subscribe for DPLL notifications\n"); + + if (!IS_ERR_OR_NULL(pin->pin)) { + dpll_pin_put(pin->pin, &pin->tracker); + pin->pin = NULL; + } + fwnode_handle_put(pin->fwnode); + pin->fwnode = NULL; + + return ret; + } + + return ret; +} + +/** + * ice_dpll_init_fwnode_pins - initialize pins from device tree + * @pf: board private structure + * @pins: pointer to pins array + * @start_idx: starting index for pins + * @count: number of pins to initialize + * + * Initialize input pins for E825 RCLK support. The parent pins (rclk0, rclk1) + * are expected to be defined by the system firmware (ACPI). This function + * allocates them in the dpll subsystem and stores their indices for later + * registration with the rclk pin. + * + * Return: + * * 0 - success + * * negative - initialization failure reason + */ +static int +ice_dpll_init_fwnode_pins(struct ice_pf *pf, struct ice_dpll_pin *pins, + int start_idx) +{ + char pin_name[8]; + int i, ret; + + pf->dplls.wq = create_singlethread_workqueue("ice_dpll_wq"); + if (!pf->dplls.wq) + return -ENOMEM; + + for (i = 0; i < pf->dplls.rclk.num_parents; i++) { + pins[start_idx + i].pf = pf; + snprintf(pin_name, sizeof(pin_name), "rclk%u", i); + ret = ice_dpll_init_fwnode_pin(&pins[start_idx + i], pin_name); + if (ret) + goto error; + } + + return 0; +error: + while (i--) + ice_dpll_deinit_fwnode_pin(&pins[start_idx + i]); + + destroy_workqueue(pf->dplls.wq); + + return ret; +} + +/** + * ice_dpll_init_pins_e825 - init pins and register pins with a dplls + * @pf: board private structure + * @cgu: if cgu is present and controlled by this NIC + * + * Initialize directly connected pf's pins within pf's dplls in a Linux dpll + * subsystem. + * + * Return: + * * 0 - success + * * negative - initialization failure reason + */ +static int ice_dpll_init_pins_e825(struct ice_pf *pf) +{ + int ret; + + ret = ice_dpll_init_fwnode_pins(pf, pf->dplls.inputs, 0); + if (ret) + return ret; + + ret = ice_dpll_init_rclk_pin(pf, DPLL_PIN_IDX_UNSPEC, + &ice_dpll_rclk_ops); + if (ret) { + /* Inform DPLL notifier works that DPLL init was finished + * unsuccessfully (ICE_DPLL_FLAG not set). + */ + complete_all(&pf->dplls.dpll_init); + ice_dpll_deinit_fwnode_pins(pf, pf->dplls.inputs, 0); + } + + return ret; +} + /** * ice_dpll_init_pins - init pins and register pins with a dplls * @pf: board private structure @@ -3155,21 +3596,24 @@ static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu) */ static int ice_dpll_init_pins(struct ice_pf *pf, bool cgu) { + const struct dpll_pin_ops *output_ops; + const struct dpll_pin_ops *input_ops; int ret, count; + input_ops = &ice_dpll_input_ops; + output_ops = &ice_dpll_output_ops; + ret = ice_dpll_init_direct_pins(pf, cgu, pf->dplls.inputs, 0, - pf->dplls.num_inputs, - &ice_dpll_input_ops, - pf->dplls.eec.dpll, pf->dplls.pps.dpll); + pf->dplls.num_inputs, input_ops, + pf->dplls.eec.dpll, + pf->dplls.pps.dpll); if (ret) return ret; count = pf->dplls.num_inputs; if (cgu) { ret = ice_dpll_init_direct_pins(pf, cgu, pf->dplls.outputs, - count, - pf->dplls.num_outputs, - &ice_dpll_output_ops, - pf->dplls.eec.dpll, + count, pf->dplls.num_outputs, + output_ops, pf->dplls.eec.dpll, pf->dplls.pps.dpll); if (ret) goto deinit_inputs; @@ -3205,30 +3649,30 @@ static int ice_dpll_init_pins(struct ice_pf *pf, bool cgu) } else { count += pf->dplls.num_outputs + 2 * ICE_DPLL_PIN_SW_NUM; } - ret = ice_dpll_init_rclk_pins(pf, &pf->dplls.rclk, count + pf->hw.pf_id, - &ice_dpll_rclk_ops); + + ret = ice_dpll_init_rclk_pin(pf, count + pf->ptp.port.port_num, + &ice_dpll_rclk_ops); if (ret) goto deinit_ufl; return 0; deinit_ufl: - ice_dpll_deinit_direct_pins(cgu, pf->dplls.ufl, - ICE_DPLL_PIN_SW_NUM, - &ice_dpll_pin_ufl_ops, - pf->dplls.pps.dpll, pf->dplls.eec.dpll); + ice_dpll_deinit_direct_pins(pf, cgu, pf->dplls.ufl, ICE_DPLL_PIN_SW_NUM, + &ice_dpll_pin_ufl_ops, pf->dplls.pps.dpll, + pf->dplls.eec.dpll); deinit_sma: - ice_dpll_deinit_direct_pins(cgu, pf->dplls.sma, - ICE_DPLL_PIN_SW_NUM, - &ice_dpll_pin_sma_ops, - pf->dplls.pps.dpll, pf->dplls.eec.dpll); + ice_dpll_deinit_direct_pins(pf, cgu, pf->dplls.sma, ICE_DPLL_PIN_SW_NUM, + &ice_dpll_pin_sma_ops, pf->dplls.pps.dpll, + pf->dplls.eec.dpll); deinit_outputs: - ice_dpll_deinit_direct_pins(cgu, pf->dplls.outputs, + ice_dpll_deinit_direct_pins(pf, cgu, pf->dplls.outputs, pf->dplls.num_outputs, - &ice_dpll_output_ops, pf->dplls.pps.dpll, + output_ops, pf->dplls.pps.dpll, pf->dplls.eec.dpll); deinit_inputs: - ice_dpll_deinit_direct_pins(cgu, pf->dplls.inputs, pf->dplls.num_inputs, - &ice_dpll_input_ops, pf->dplls.pps.dpll, + ice_dpll_deinit_direct_pins(pf, cgu, pf->dplls.inputs, + pf->dplls.num_inputs, + input_ops, pf->dplls.pps.dpll, pf->dplls.eec.dpll); return ret; } @@ -3239,8 +3683,8 @@ static int ice_dpll_init_pins(struct ice_pf *pf, bool cgu) * @d: pointer to ice_dpll * @cgu: if cgu is present and controlled by this NIC * - * If cgu is owned unregister the dpll from dpll subsystem. - * Release resources of dpll device from dpll subsystem. + * If cgu is owned, unregister the DPL from DPLL subsystem. + * Release resources of DPLL device from DPLL subsystem. */ static void ice_dpll_deinit_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu) @@ -3257,8 +3701,8 @@ ice_dpll_deinit_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu) * @cgu: if cgu is present and controlled by this NIC * @type: type of dpll being initialized * - * Allocate dpll instance for this board in dpll subsystem, if cgu is controlled - * by this NIC, register dpll with the callback ops. + * Allocate DPLL instance for this board in dpll subsystem, if cgu is controlled + * by this NIC, register DPLL with the callback ops. * * Return: * * 0 - success @@ -3289,6 +3733,7 @@ ice_dpll_init_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu, ret = dpll_device_register(d->dpll, type, ops, d); if (ret) { dpll_device_put(d->dpll, &d->tracker); + d->dpll = NULL; return ret; } d->ops = ops; @@ -3506,6 +3951,26 @@ ice_dpll_init_info_direct_pins(struct ice_pf *pf, return ret; } +/** + * ice_dpll_init_info_pin_on_pin_e825c - initializes rclk pin information + * @pf: board private structure + * + * Init information for rclk pin, cache them in pf->dplls.rclk. + * + * Return: + * * 0 - success + */ +static int ice_dpll_init_info_pin_on_pin_e825c(struct ice_pf *pf) +{ + struct ice_dpll_pin *rclk_pin = &pf->dplls.rclk; + + rclk_pin->prop.type = DPLL_PIN_TYPE_SYNCE_ETH_PORT; + rclk_pin->prop.capabilities |= DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE; + rclk_pin->pf = pf; + + return 0; +} + /** * ice_dpll_init_info_rclk_pin - initializes rclk pin information * @pf: board private structure @@ -3632,7 +4097,10 @@ ice_dpll_init_pins_info(struct ice_pf *pf, enum ice_dpll_pin_type pin_type) case ICE_DPLL_PIN_TYPE_OUTPUT: return ice_dpll_init_info_direct_pins(pf, pin_type); case ICE_DPLL_PIN_TYPE_RCLK_INPUT: - return ice_dpll_init_info_rclk_pin(pf); + if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) + return ice_dpll_init_info_pin_on_pin_e825c(pf); + else + return ice_dpll_init_info_rclk_pin(pf); case ICE_DPLL_PIN_TYPE_SOFTWARE: return ice_dpll_init_info_sw_pins(pf); default: @@ -3654,6 +4122,50 @@ static void ice_dpll_deinit_info(struct ice_pf *pf) kfree(pf->dplls.pps.input_prio); } +/** + * ice_dpll_init_info_e825c - prepare pf's dpll information structure for e825c + * device + * @pf: board private structure + * + * Acquire (from HW) and set basic DPLL information (on pf->dplls struct). + * + * Return: + * * 0 - success + * * negative - init failure reason + */ +static int ice_dpll_init_info_e825c(struct ice_pf *pf) +{ + struct ice_dplls *d = &pf->dplls; + int ret = 0; + int i; + + d->clock_id = ice_generate_clock_id(pf); + d->num_inputs = ICE_SYNCE_CLK_NUM; + + d->inputs = kcalloc(d->num_inputs, sizeof(*d->inputs), GFP_KERNEL); + if (!d->inputs) + return -ENOMEM; + + ret = ice_get_cgu_rclk_pin_info(&pf->hw, &d->base_rclk_idx, + &pf->dplls.rclk.num_parents); + if (ret) + goto deinit_info; + + for (i = 0; i < pf->dplls.rclk.num_parents; i++) + pf->dplls.rclk.parent_idx[i] = d->base_rclk_idx + i; + + ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_RCLK_INPUT); + if (ret) + goto deinit_info; + dev_dbg(ice_pf_to_dev(pf), + "%s - success, inputs: %u, outputs: %u, rclk-parents: %u\n", + __func__, d->num_inputs, d->num_outputs, d->rclk.num_parents); + return 0; +deinit_info: + ice_dpll_deinit_info(pf); + return ret; +} + /** * ice_dpll_init_info - prepare pf's dpll information structure * @pf: board private structure @@ -3773,14 +4285,16 @@ void ice_dpll_deinit(struct ice_pf *pf) ice_dpll_deinit_worker(pf); ice_dpll_deinit_pins(pf, cgu); - ice_dpll_deinit_dpll(pf, &pf->dplls.pps, cgu); - ice_dpll_deinit_dpll(pf, &pf->dplls.eec, cgu); + if (!IS_ERR_OR_NULL(pf->dplls.pps.dpll)) + ice_dpll_deinit_dpll(pf, &pf->dplls.pps, cgu); + if (!IS_ERR_OR_NULL(pf->dplls.eec.dpll)) + ice_dpll_deinit_dpll(pf, &pf->dplls.eec, cgu); ice_dpll_deinit_info(pf); mutex_destroy(&pf->dplls.lock); } /** - * ice_dpll_init - initialize support for dpll subsystem + * ice_dpll_init_e825 - initialize support for dpll subsystem * @pf: board private structure * * Set up the device dplls, register them and pins connected within Linux dpll @@ -3789,7 +4303,43 @@ void ice_dpll_deinit(struct ice_pf *pf) * * Context: Initializes pf->dplls.lock mutex. */ -void ice_dpll_init(struct ice_pf *pf) +static void ice_dpll_init_e825(struct ice_pf *pf) +{ + struct ice_dplls *d = &pf->dplls; + int err; + + mutex_init(&d->lock); + init_completion(&d->dpll_init); + + err = ice_dpll_init_info_e825c(pf); + if (err) + goto err_exit; + err = ice_dpll_init_pins_e825(pf); + if (err) + goto deinit_info; + set_bit(ICE_FLAG_DPLL, pf->flags); + complete_all(&d->dpll_init); + + return; + +deinit_info: + ice_dpll_deinit_info(pf); +err_exit: + mutex_destroy(&d->lock); + dev_warn(ice_pf_to_dev(pf), "DPLLs init failure err:%d\n", err); +} + +/** + * ice_dpll_init_e810 - initialize support for dpll subsystem + * @pf: board private structure + * + * Set up the device dplls, register them and pins connected within Linux dpll + * subsystem. Allow userspace to obtain state of DPLL and handling of DPLL + * configuration requests. + * + * Context: Initializes pf->dplls.lock mutex. + */ +static void ice_dpll_init_e810(struct ice_pf *pf) { bool cgu = ice_is_feature_supported(pf, ICE_F_CGU); struct ice_dplls *d = &pf->dplls; @@ -3829,3 +4379,15 @@ void ice_dpll_init(struct ice_pf *pf) mutex_destroy(&d->lock); dev_warn(ice_pf_to_dev(pf), "DPLLs init failure err:%d\n", err); } + +void ice_dpll_init(struct ice_pf *pf) +{ + switch (pf->hw.mac_type) { + case ICE_MAC_GENERIC_3K_E825: + ice_dpll_init_e825(pf); + break; + default: + ice_dpll_init_e810(pf); + break; + } +} diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.h b/drivers/net/ethernet/intel/ice/ice_dpll.h index 63fac6510df6e..ae42cdea0ee14 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.h +++ b/drivers/net/ethernet/intel/ice/ice_dpll.h @@ -20,6 +20,12 @@ enum ice_dpll_pin_sw { ICE_DPLL_PIN_SW_NUM }; +struct ice_dpll_pin_work { + struct work_struct work; + unsigned long action; + struct ice_dpll_pin *pin; +}; + /** ice_dpll_pin - store info about pins * @pin: dpll pin structure * @pf: pointer to pf, which has registered the dpll_pin @@ -39,6 +45,8 @@ struct ice_dpll_pin { struct dpll_pin *pin; struct ice_pf *pf; dpll_tracker tracker; + struct fwnode_handle *fwnode; + struct notifier_block nb; u8 idx; u8 num_parents; u8 parent_idx[ICE_DPLL_RCLK_NUM_MAX]; @@ -118,7 +126,9 @@ struct ice_dpll { struct ice_dplls { struct kthread_worker *kworker; struct kthread_delayed_work work; + struct workqueue_struct *wq; struct mutex lock; + struct completion dpll_init; struct ice_dpll eec; struct ice_dpll pps; struct ice_dpll_pin *inputs; @@ -147,3 +157,19 @@ static inline void ice_dpll_deinit(struct ice_pf *pf) { } #endif #endif + +#define ICE_CGU_R10 0x28 +#define ICE_CGU_R10_SYNCE_CLKO_SEL GENMASK(8, 5) +#define ICE_CGU_R10_SYNCE_CLKODIV_M1 GENMASK(13, 9) +#define ICE_CGU_R10_SYNCE_CLKODIV_LOAD BIT(14) +#define ICE_CGU_R10_SYNCE_DCK_RST BIT(15) +#define ICE_CGU_R10_SYNCE_ETHCLKO_SEL GENMASK(18, 16) +#define ICE_CGU_R10_SYNCE_ETHDIV_M1 GENMASK(23, 19) +#define ICE_CGU_R10_SYNCE_ETHDIV_LOAD BIT(24) +#define ICE_CGU_R10_SYNCE_DCK2_RST BIT(25) +#define ICE_CGU_R10_SYNCE_S_REF_CLK GENMASK(31, 27) + +#define ICE_CGU_R11 0x2C +#define ICE_CGU_R11_SYNCE_S_BYP_CLK GENMASK(6, 1) + +#define ICE_CGU_BYPASS_MUX_OFFSET_E825C 3 diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 2522ebdea9139..d921269e1fe71 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -3989,6 +3989,9 @@ void ice_init_feature_support(struct ice_pf *pf) break; } + if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) + ice_set_feature_support(pf, ICE_F_PHY_RCLK); + if (pf->hw.mac_type == ICE_MAC_E830) { ice_set_feature_support(pf, ICE_F_MBX_LIMIT); ice_set_feature_support(pf, ICE_F_GCS); diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c index 4c8d20f2d2c0a..1d26be58e29a0 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c @@ -1341,6 +1341,38 @@ void ice_ptp_link_change(struct ice_pf *pf, bool linkup) if (pf->hw.reset_ongoing) return; + if (hw->mac_type == ICE_MAC_GENERIC_3K_E825) { + int pin, err; + + if (!test_bit(ICE_FLAG_DPLL, pf->flags)) + return; + + mutex_lock(&pf->dplls.lock); + for (pin = 0; pin < ICE_SYNCE_CLK_NUM; pin++) { + enum ice_synce_clk clk_pin; + bool active; + u8 port_num; + + port_num = ptp_port->port_num; + clk_pin = (enum ice_synce_clk)pin; + err = ice_tspll_bypass_mux_active_e825c(hw, + port_num, + &active, + clk_pin); + if (WARN_ON_ONCE(err)) { + mutex_unlock(&pf->dplls.lock); + return; + } + + err = ice_tspll_cfg_synce_ethdiv_e825c(hw, clk_pin); + if (active && WARN_ON_ONCE(err)) { + mutex_unlock(&pf->dplls.lock); + return; + } + } + mutex_unlock(&pf->dplls.lock); + } + switch (hw->mac_type) { case ICE_MAC_E810: case ICE_MAC_E830: diff --git a/drivers/net/ethernet/intel/ice/ice_ptp_hw.c b/drivers/net/ethernet/intel/ice/ice_ptp_hw.c index 35680dbe4a7f7..61c0a0d93ea89 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp_hw.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp_hw.c @@ -5903,7 +5903,14 @@ int ice_get_cgu_rclk_pin_info(struct ice_hw *hw, u8 *base_idx, u8 *pin_num) *base_idx = SI_REF1P; else ret = -ENODEV; - + break; + case ICE_DEV_ID_E825C_BACKPLANE: + case ICE_DEV_ID_E825C_QSFP: + case ICE_DEV_ID_E825C_SFP: + case ICE_DEV_ID_E825C_SGMII: + *pin_num = ICE_SYNCE_CLK_NUM; + *base_idx = 0; + ret = 0; break; default: ret = -ENODEV; diff --git a/drivers/net/ethernet/intel/ice/ice_tspll.c b/drivers/net/ethernet/intel/ice/ice_tspll.c index 66320a4ab86fd..fd4b58eb9bc00 100644 --- a/drivers/net/ethernet/intel/ice/ice_tspll.c +++ b/drivers/net/ethernet/intel/ice/ice_tspll.c @@ -624,3 +624,220 @@ int ice_tspll_init(struct ice_hw *hw) return err; } + +/** + * ice_tspll_bypass_mux_active_e825c - check if the given port is set active + * @hw: Pointer to the HW struct + * @port: Number of the port + * @active: Output flag showing if port is active + * @output: Output pin, we have two in E825C + * + * Check if given port is selected as recovered clock source for given output. + * + * Return: + * * 0 - success + * * negative - error + */ +int ice_tspll_bypass_mux_active_e825c(struct ice_hw *hw, u8 port, bool *active, + enum ice_synce_clk output) +{ + u8 active_clk; + u32 val; + int err; + + switch (output) { + case ICE_SYNCE_CLK0: + err = ice_read_cgu_reg(hw, ICE_CGU_R10, &val); + if (err) + return err; + active_clk = FIELD_GET(ICE_CGU_R10_SYNCE_S_REF_CLK, val); + break; + case ICE_SYNCE_CLK1: + err = ice_read_cgu_reg(hw, ICE_CGU_R11, &val); + if (err) + return err; + active_clk = FIELD_GET(ICE_CGU_R11_SYNCE_S_BYP_CLK, val); + break; + default: + return -EINVAL; + } + + if (active_clk == port % hw->ptp.ports_per_phy + + ICE_CGU_BYPASS_MUX_OFFSET_E825C) + *active = true; + else + *active = false; + + return 0; +} + +/** + * ice_tspll_cfg_bypass_mux_e825c - configure reference clock mux + * @hw: Pointer to the HW struct + * @ena: true to enable the reference, false if disable + * @port_num: Number of the port + * @output: Output pin, we have two in E825C + * + * Set reference clock source and output clock selection. + * + * Context: Called under pf->dplls.lock + * Return: + * * 0 - success + * * negative - error + */ +int ice_tspll_cfg_bypass_mux_e825c(struct ice_hw *hw, bool ena, u32 port_num, + enum ice_synce_clk output) +{ + u8 first_mux; + int err; + u32 r10; + + err = ice_read_cgu_reg(hw, ICE_CGU_R10, &r10); + if (err) + return err; + + if (!ena) + first_mux = ICE_CGU_NET_REF_CLK0; + else + first_mux = port_num + ICE_CGU_BYPASS_MUX_OFFSET_E825C; + + r10 &= ~(ICE_CGU_R10_SYNCE_DCK_RST | ICE_CGU_R10_SYNCE_DCK2_RST); + + switch (output) { + case ICE_SYNCE_CLK0: + r10 &= ~(ICE_CGU_R10_SYNCE_ETHCLKO_SEL | + ICE_CGU_R10_SYNCE_ETHDIV_LOAD | + ICE_CGU_R10_SYNCE_S_REF_CLK); + r10 |= FIELD_PREP(ICE_CGU_R10_SYNCE_S_REF_CLK, first_mux); + r10 |= FIELD_PREP(ICE_CGU_R10_SYNCE_ETHCLKO_SEL, + ICE_CGU_REF_CLK_BYP0_DIV); + break; + case ICE_SYNCE_CLK1: + { + u32 val; + + err = ice_read_cgu_reg(hw, ICE_CGU_R11, &val); + if (err) + return err; + val &= ~ICE_CGU_R11_SYNCE_S_BYP_CLK; + val |= FIELD_PREP(ICE_CGU_R11_SYNCE_S_BYP_CLK, first_mux); + err = ice_write_cgu_reg(hw, ICE_CGU_R11, val); + if (err) + return err; + r10 &= ~(ICE_CGU_R10_SYNCE_CLKODIV_LOAD | + ICE_CGU_R10_SYNCE_CLKO_SEL); + r10 |= FIELD_PREP(ICE_CGU_R10_SYNCE_CLKO_SEL, + ICE_CGU_REF_CLK_BYP1_DIV); + break; + } + default: + return -EINVAL; + } + + err = ice_write_cgu_reg(hw, ICE_CGU_R10, r10); + if (err) + return err; + + return 0; +} + +/** + * ice_tspll_get_div_e825c - get the divider for the given speed + * @link_speed: link speed of the port + * @divider: output value, calculated divider + * + * Get CGU divider value based on the link speed. + * + * Return: + * * 0 - success + * * negative - error + */ +static int ice_tspll_get_div_e825c(u16 link_speed, unsigned int *divider) +{ + switch (link_speed) { + case ICE_AQ_LINK_SPEED_100GB: + case ICE_AQ_LINK_SPEED_50GB: + case ICE_AQ_LINK_SPEED_25GB: + *divider = 10; + break; + case ICE_AQ_LINK_SPEED_40GB: + case ICE_AQ_LINK_SPEED_10GB: + *divider = 4; + break; + case ICE_AQ_LINK_SPEED_5GB: + case ICE_AQ_LINK_SPEED_2500MB: + case ICE_AQ_LINK_SPEED_1000MB: + *divider = 2; + break; + case ICE_AQ_LINK_SPEED_100MB: + *divider = 1; + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +/** + * ice_tspll_cfg_synce_ethdiv_e825c - set the divider on the mux + * @hw: Pointer to the HW struct + * @output: Output pin, we have two in E825C + * + * Set the correct CGU divider for RCLKA or RCLKB. + * + * Context: Called under pf->dplls.lock + * Return: + * * 0 - success + * * negative - error + */ +int ice_tspll_cfg_synce_ethdiv_e825c(struct ice_hw *hw, + enum ice_synce_clk output) +{ + unsigned int divider; + u16 link_speed; + u32 val; + int err; + + link_speed = hw->port_info->phy.link_info.link_speed; + if (!link_speed) + return 0; + + err = ice_tspll_get_div_e825c(link_speed, &divider); + if (err) + return err; + + err = ice_read_cgu_reg(hw, ICE_CGU_R10, &val); + if (err) + return err; + + /* programmable divider value (from 2 to 16) minus 1 for ETHCLKOUT */ + switch (output) { + case ICE_SYNCE_CLK0: + val &= ~(ICE_CGU_R10_SYNCE_ETHDIV_M1 | + ICE_CGU_R10_SYNCE_ETHDIV_LOAD); + val |= FIELD_PREP(ICE_CGU_R10_SYNCE_ETHDIV_M1, divider - 1); + err = ice_write_cgu_reg(hw, ICE_CGU_R10, val); + if (err) + return err; + val |= ICE_CGU_R10_SYNCE_ETHDIV_LOAD; + break; + case ICE_SYNCE_CLK1: + val &= ~(ICE_CGU_R10_SYNCE_CLKODIV_M1 | + ICE_CGU_R10_SYNCE_CLKODIV_LOAD); + val |= FIELD_PREP(ICE_CGU_R10_SYNCE_CLKODIV_M1, divider - 1); + err = ice_write_cgu_reg(hw, ICE_CGU_R10, val); + if (err) + return err; + val |= ICE_CGU_R10_SYNCE_CLKODIV_LOAD; + break; + default: + return -EINVAL; + } + + err = ice_write_cgu_reg(hw, ICE_CGU_R10, val); + if (err) + return err; + + return 0; +} diff --git a/drivers/net/ethernet/intel/ice/ice_tspll.h b/drivers/net/ethernet/intel/ice/ice_tspll.h index c0b1232cc07c3..d650867004d1f 100644 --- a/drivers/net/ethernet/intel/ice/ice_tspll.h +++ b/drivers/net/ethernet/intel/ice/ice_tspll.h @@ -21,11 +21,22 @@ struct ice_tspll_params_e82x { u32 frac_n_div; }; +#define ICE_CGU_NET_REF_CLK0 0x0 +#define ICE_CGU_REF_CLK_BYP0 0x5 +#define ICE_CGU_REF_CLK_BYP0_DIV 0x0 +#define ICE_CGU_REF_CLK_BYP1 0x4 +#define ICE_CGU_REF_CLK_BYP1_DIV 0x1 + #define ICE_TSPLL_CK_REFCLKFREQ_E825 0x1F #define ICE_TSPLL_NDIVRATIO_E825 5 #define ICE_TSPLL_FBDIV_INTGR_E825 256 int ice_tspll_cfg_pps_out_e825c(struct ice_hw *hw, bool enable); int ice_tspll_init(struct ice_hw *hw); - +int ice_tspll_bypass_mux_active_e825c(struct ice_hw *hw, u8 port, bool *active, + enum ice_synce_clk output); +int ice_tspll_cfg_bypass_mux_e825c(struct ice_hw *hw, bool ena, u32 port_num, + enum ice_synce_clk output); +int ice_tspll_cfg_synce_ethdiv_e825c(struct ice_hw *hw, + enum ice_synce_clk output); #endif /* _ICE_TSPLL_H_ */ diff --git a/drivers/net/ethernet/intel/ice/ice_type.h b/drivers/net/ethernet/intel/ice/ice_type.h index 6a2ec8389a8f3..1e82f4c40b326 100644 --- a/drivers/net/ethernet/intel/ice/ice_type.h +++ b/drivers/net/ethernet/intel/ice/ice_type.h @@ -349,6 +349,12 @@ enum ice_clk_src { NUM_ICE_CLK_SRC }; +enum ice_synce_clk { + ICE_SYNCE_CLK0, + ICE_SYNCE_CLK1, + ICE_SYNCE_CLK_NUM +}; + struct ice_ts_func_info { /* Function specific info */ enum ice_tspll_freq time_ref; -- 2.52.0
{ "author": "Ivan Vecera <ivecera@redhat.com>", "date": "Mon, 2 Feb 2026 18:16:38 +0100", "thread_id": "20260202171638.17427-1-ivecera@redhat.com.mbox.gz" }
lkml
[PATCH v1 0/4] usb: phy: tegra: HSIC adjustments
Followup to a recent HSIC bringup with a few small improvements. Svyatoslav Ryhel (4): usb: phy: tegra: cosmetic fixes usb: phy: tegra: return error value from utmi_wait_register usb: phy: tegra: parametrize HSIC PTS value usb: phy: tegra: parametrize PORTSC1 register offset drivers/usb/phy/phy-tegra-usb.c | 45 +++++++++++++++---------------- include/linux/usb/tegra_usb_phy.h | 8 ++++-- 2 files changed, 27 insertions(+), 26 deletions(-) -- 2.51.0
Change TEGRA_USB_HOSTPC1_DEVLC_PTS_HSIC to its literal value instead of using the BIT macro, as it is an enumeration. Correct the spelling in the comment and rename uhsic_registers_shift to uhsic_registers_offset. These changes are cosmetic and do not affect code behavior. Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> --- drivers/usb/phy/phy-tegra-usb.c | 12 ++++++------ include/linux/usb/tegra_usb_phy.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c index effa767ec019..3a7a74f01d1c 100644 --- a/drivers/usb/phy/phy-tegra-usb.c +++ b/drivers/usb/phy/phy-tegra-usb.c @@ -48,7 +48,7 @@ #define TEGRA_USB_HOSTPC1_DEVLC 0x1b4 #define TEGRA_USB_HOSTPC1_DEVLC_PTS(x) (((x) & 0x7) << 29) #define TEGRA_USB_HOSTPC1_DEVLC_PHCD BIT(22) -#define TEGRA_USB_HOSTPC1_DEVLC_PTS_HSIC BIT(2) +#define TEGRA_USB_HOSTPC1_DEVLC_PTS_HSIC 4 /* Bits of PORTSC1, which will get cleared by writing 1 into them */ #define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) @@ -169,7 +169,7 @@ /* * Tegra20 has no UTMIP registers on PHY2 and UHSIC registers start from 0x800 * just where UTMIP registers should have been. This is the case only with Tegra20 - * Tegra30+ have UTMIP registers at 0x800 and UHSIC registers shifter by 0x400 + * Tegra30+ have UTMIP registers at 0x800 and UHSIC registers are shifted by 0x400 * to 0xc00, but register layout is preserved. */ #define UHSIC_PLL_CFG1 0x804 @@ -873,7 +873,7 @@ static int ulpi_phy_power_off(struct tegra_usb_phy *phy) static u32 tegra_hsic_readl(struct tegra_usb_phy *phy, u32 reg) { void __iomem *base = phy->regs; - u32 shift = phy->soc_config->uhsic_registers_shift; + u32 shift = phy->soc_config->uhsic_registers_offset; return readl_relaxed(base + shift + reg); } @@ -881,7 +881,7 @@ static u32 tegra_hsic_readl(struct tegra_usb_phy *phy, u32 reg) static void tegra_hsic_writel(struct tegra_usb_phy *phy, u32 reg, u32 value) { void __iomem *base = phy->regs; - u32 shift = phy->soc_config->uhsic_registers_shift; + u32 shift = phy->soc_config->uhsic_registers_offset; writel_relaxed(value, base + shift + reg); } @@ -1469,7 +1469,7 @@ static const struct tegra_phy_soc_config tegra20_soc_config = { .requires_usbmode_setup = false, .requires_extra_tuning_parameters = false, .requires_pmc_ao_power_up = false, - .uhsic_registers_shift = 0, + .uhsic_registers_offset = 0, .uhsic_tx_rtune = 0, /* 40 ohm */ }; @@ -1479,7 +1479,7 @@ static const struct tegra_phy_soc_config tegra30_soc_config = { .requires_usbmode_setup = true, .requires_extra_tuning_parameters = true, .requires_pmc_ao_power_up = true, - .uhsic_registers_shift = 0x400, + .uhsic_registers_offset = 0x400, .uhsic_tx_rtune = 8, /* 50 ohm */ }; diff --git a/include/linux/usb/tegra_usb_phy.h b/include/linux/usb/tegra_usb_phy.h index 1a8843bd1e95..fbdd2dcb3a2b 100644 --- a/include/linux/usb/tegra_usb_phy.h +++ b/include/linux/usb/tegra_usb_phy.h @@ -24,7 +24,7 @@ struct gpio_desc; * requires_extra_tuning_parameters: true if xcvr_hsslew, hssquelch_level * and hsdiscon_level should be set for adequate signal quality * requires_pmc_ao_power_up: true if USB AO is powered down by default - * uhsic_registers_shift: for Tegra30+ where HSIC registers were shifted + * uhsic_registers_offset: for Tegra30+ where HSIC registers were offset * comparing to Tegra20 by 0x400, since Tegra20 has no UTMIP on PHY2 * uhsic_tx_rtune: fine tuned 50 Ohm termination resistor for NMOS/PMOS driver */ @@ -35,7 +35,7 @@ struct tegra_phy_soc_config { bool requires_usbmode_setup; bool requires_extra_tuning_parameters; bool requires_pmc_ao_power_up; - u32 uhsic_registers_shift; + u32 uhsic_registers_offset; u32 uhsic_tx_rtune; }; -- 2.51.0
{ "author": "Svyatoslav Ryhel <clamor95@gmail.com>", "date": "Mon, 2 Feb 2026 10:05:23 +0200", "thread_id": "20260202080526.23487-1-clamor95@gmail.com.mbox.gz" }
lkml
[PATCH v1 0/4] usb: phy: tegra: HSIC adjustments
Followup to a recent HSIC bringup with a few small improvements. Svyatoslav Ryhel (4): usb: phy: tegra: cosmetic fixes usb: phy: tegra: return error value from utmi_wait_register usb: phy: tegra: parametrize HSIC PTS value usb: phy: tegra: parametrize PORTSC1 register offset drivers/usb/phy/phy-tegra-usb.c | 45 +++++++++++++++---------------- include/linux/usb/tegra_usb_phy.h | 8 ++++-- 2 files changed, 27 insertions(+), 26 deletions(-) -- 2.51.0
Return exact error value from utmi_wait_register during HSIC power on. Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> --- drivers/usb/phy/phy-tegra-usb.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c index 3a7a74f01d1c..6173b240c3ea 100644 --- a/drivers/usb/phy/phy-tegra-usb.c +++ b/drivers/usb/phy/phy-tegra-usb.c @@ -891,6 +891,7 @@ static int uhsic_phy_power_on(struct tegra_usb_phy *phy) struct tegra_utmip_config *config = phy->config; void __iomem *base = phy->regs; u32 val; + int err = 0; val = tegra_hsic_readl(phy, UHSIC_PADS_CFG1); val &= ~(UHSIC_PD_BG | UHSIC_PD_TX | UHSIC_PD_TRK | UHSIC_PD_RX | @@ -984,12 +985,14 @@ static int uhsic_phy_power_on(struct tegra_usb_phy *phy) val |= UHSIC_TX_RTUNE(phy->soc_config->uhsic_tx_rtune); tegra_hsic_writel(phy, UHSIC_PADS_CFG0, val); - if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, - USB_PHY_CLK_VALID)) + err = utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, + USB_PHY_CLK_VALID); + + if (err) dev_err(phy->u_phy.dev, "Timeout waiting for PHY to stabilize on enable (HSIC)\n"); - return 0; + return err; } static int uhsic_phy_power_off(struct tegra_usb_phy *phy) -- 2.51.0
{ "author": "Svyatoslav Ryhel <clamor95@gmail.com>", "date": "Mon, 2 Feb 2026 10:05:24 +0200", "thread_id": "20260202080526.23487-1-clamor95@gmail.com.mbox.gz" }
lkml
[PATCH v1 0/4] usb: phy: tegra: HSIC adjustments
Followup to a recent HSIC bringup with a few small improvements. Svyatoslav Ryhel (4): usb: phy: tegra: cosmetic fixes usb: phy: tegra: return error value from utmi_wait_register usb: phy: tegra: parametrize HSIC PTS value usb: phy: tegra: parametrize PORTSC1 register offset drivers/usb/phy/phy-tegra-usb.c | 45 +++++++++++++++---------------- include/linux/usb/tegra_usb_phy.h | 8 ++++-- 2 files changed, 27 insertions(+), 26 deletions(-) -- 2.51.0
The parallel transceiver select used in HSIC mode differs on Tegra20, where it uses the UTMI value (0), whereas Tegra30+ uses a dedicated HSIC value. Reflect this in the SoC config. Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> --- drivers/usb/phy/phy-tegra-usb.c | 7 +++---- include/linux/usb/tegra_usb_phy.h | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c index 6173b240c3ea..812d99443180 100644 --- a/drivers/usb/phy/phy-tegra-usb.c +++ b/drivers/usb/phy/phy-tegra-usb.c @@ -957,10 +957,7 @@ static int uhsic_phy_power_on(struct tegra_usb_phy *phy) writel_relaxed(val, base + USB_USBMODE); } - if (phy->soc_config->has_hostpc) - set_pts(phy, TEGRA_USB_HOSTPC1_DEVLC_PTS_HSIC); - else - set_pts(phy, 0); + set_pts(phy, phy->soc_config->uhsic_pts_value); val = readl_relaxed(base + USB_TXFILLTUNING); if ((val & USB_FIFO_TXFILL_MASK) != USB_FIFO_TXFILL_THRES(0x10)) { @@ -1474,6 +1471,7 @@ static const struct tegra_phy_soc_config tegra20_soc_config = { .requires_pmc_ao_power_up = false, .uhsic_registers_offset = 0, .uhsic_tx_rtune = 0, /* 40 ohm */ + .uhsic_pts_value = 0, /* UTMI */ }; static const struct tegra_phy_soc_config tegra30_soc_config = { @@ -1484,6 +1482,7 @@ static const struct tegra_phy_soc_config tegra30_soc_config = { .requires_pmc_ao_power_up = true, .uhsic_registers_offset = 0x400, .uhsic_tx_rtune = 8, /* 50 ohm */ + .uhsic_pts_value = TEGRA_USB_HOSTPC1_DEVLC_PTS_HSIC, }; static const struct of_device_id tegra_usb_phy_id_table[] = { diff --git a/include/linux/usb/tegra_usb_phy.h b/include/linux/usb/tegra_usb_phy.h index fbdd2dcb3a2b..81d9f22e58b5 100644 --- a/include/linux/usb/tegra_usb_phy.h +++ b/include/linux/usb/tegra_usb_phy.h @@ -27,6 +27,7 @@ struct gpio_desc; * uhsic_registers_offset: for Tegra30+ where HSIC registers were offset * comparing to Tegra20 by 0x400, since Tegra20 has no UTMIP on PHY2 * uhsic_tx_rtune: fine tuned 50 Ohm termination resistor for NMOS/PMOS driver + * uhsic_pts_value: parallel transceiver select enumeration value */ struct tegra_phy_soc_config { @@ -37,6 +38,7 @@ struct tegra_phy_soc_config { bool requires_pmc_ao_power_up; u32 uhsic_registers_offset; u32 uhsic_tx_rtune; + u32 uhsic_pts_value; }; struct tegra_utmip_config { -- 2.51.0
{ "author": "Svyatoslav Ryhel <clamor95@gmail.com>", "date": "Mon, 2 Feb 2026 10:05:25 +0200", "thread_id": "20260202080526.23487-1-clamor95@gmail.com.mbox.gz" }
lkml
[PATCH v1 0/4] usb: phy: tegra: HSIC adjustments
Followup to a recent HSIC bringup with a few small improvements. Svyatoslav Ryhel (4): usb: phy: tegra: cosmetic fixes usb: phy: tegra: return error value from utmi_wait_register usb: phy: tegra: parametrize HSIC PTS value usb: phy: tegra: parametrize PORTSC1 register offset drivers/usb/phy/phy-tegra-usb.c | 45 +++++++++++++++---------------- include/linux/usb/tegra_usb_phy.h | 8 ++++-- 2 files changed, 27 insertions(+), 26 deletions(-) -- 2.51.0
The PORTSC1 register has a different offset in Tegra20 compared to Tegra30+, yet they share a crucial set of registers required for HSIC functionality. Reflect this register offset change in the SoC config. Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> --- drivers/usb/phy/phy-tegra-usb.c | 17 ++++++----------- include/linux/usb/tegra_usb_phy.h | 2 ++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c index 812d99443180..00443a7beaeb 100644 --- a/drivers/usb/phy/phy-tegra-usb.c +++ b/drivers/usb/phy/phy-tegra-usb.c @@ -965,17 +965,10 @@ static int uhsic_phy_power_on(struct tegra_usb_phy *phy) writel_relaxed(val, base + USB_TXFILLTUNING); } - if (phy->soc_config->has_hostpc) { - val = readl_relaxed(base + TEGRA30_USB_PORTSC1); - val &= ~(TEGRA_USB_PORTSC1_WKOC | TEGRA_USB_PORTSC1_WKDS | - TEGRA_USB_PORTSC1_WKCN); - writel_relaxed(val, base + TEGRA30_USB_PORTSC1); - } else { - val = readl_relaxed(base + TEGRA_USB_PORTSC1); - val &= ~(TEGRA_USB_PORTSC1_WKOC | TEGRA_USB_PORTSC1_WKDS | - TEGRA_USB_PORTSC1_WKCN); - writel_relaxed(val, base + TEGRA_USB_PORTSC1); - } + val = readl_relaxed(base + phy->soc_config->portsc1_offset); + val &= ~(TEGRA_USB_PORTSC1_WKOC | TEGRA_USB_PORTSC1_WKDS | + TEGRA_USB_PORTSC1_WKCN); + writel_relaxed(val, base + phy->soc_config->portsc1_offset); val = tegra_hsic_readl(phy, UHSIC_PADS_CFG0); val &= ~UHSIC_TX_RTUNEN; @@ -1472,6 +1465,7 @@ static const struct tegra_phy_soc_config tegra20_soc_config = { .uhsic_registers_offset = 0, .uhsic_tx_rtune = 0, /* 40 ohm */ .uhsic_pts_value = 0, /* UTMI */ + .portsc1_offset = TEGRA_USB_PORTSC1, }; static const struct tegra_phy_soc_config tegra30_soc_config = { @@ -1483,6 +1477,7 @@ static const struct tegra_phy_soc_config tegra30_soc_config = { .uhsic_registers_offset = 0x400, .uhsic_tx_rtune = 8, /* 50 ohm */ .uhsic_pts_value = TEGRA_USB_HOSTPC1_DEVLC_PTS_HSIC, + .portsc1_offset = TEGRA30_USB_PORTSC1, }; static const struct of_device_id tegra_usb_phy_id_table[] = { diff --git a/include/linux/usb/tegra_usb_phy.h b/include/linux/usb/tegra_usb_phy.h index 81d9f22e58b5..57e22aae6247 100644 --- a/include/linux/usb/tegra_usb_phy.h +++ b/include/linux/usb/tegra_usb_phy.h @@ -28,6 +28,7 @@ struct gpio_desc; * comparing to Tegra20 by 0x400, since Tegra20 has no UTMIP on PHY2 * uhsic_tx_rtune: fine tuned 50 Ohm termination resistor for NMOS/PMOS driver * uhsic_pts_value: parallel transceiver select enumeration value + * portsc1_offset: register offset of PORTSC1 */ struct tegra_phy_soc_config { @@ -39,6 +40,7 @@ struct tegra_phy_soc_config { u32 uhsic_registers_offset; u32 uhsic_tx_rtune; u32 uhsic_pts_value; + u32 portsc1_offset; }; struct tegra_utmip_config { -- 2.51.0
{ "author": "Svyatoslav Ryhel <clamor95@gmail.com>", "date": "Mon, 2 Feb 2026 10:05:26 +0200", "thread_id": "20260202080526.23487-1-clamor95@gmail.com.mbox.gz" }
lkml
[PATCH v1 0/4] usb: phy: tegra: HSIC adjustments
Followup to a recent HSIC bringup with a few small improvements. Svyatoslav Ryhel (4): usb: phy: tegra: cosmetic fixes usb: phy: tegra: return error value from utmi_wait_register usb: phy: tegra: parametrize HSIC PTS value usb: phy: tegra: parametrize PORTSC1 register offset drivers/usb/phy/phy-tegra-usb.c | 45 +++++++++++++++---------------- include/linux/usb/tegra_usb_phy.h | 8 ++++-- 2 files changed, 27 insertions(+), 26 deletions(-) -- 2.51.0
On Monday, February 2, 2026 5:05 PM Svyatoslav Ryhel wrote: Series Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com>
{ "author": "Mikko Perttunen <mperttunen@nvidia.com>", "date": "Mon, 02 Feb 2026 17:10:37 +0900", "thread_id": "20260202080526.23487-1-clamor95@gmail.com.mbox.gz" }
lkml
[PATCH v1 0/4] usb: phy: tegra: HSIC adjustments
Followup to a recent HSIC bringup with a few small improvements. Svyatoslav Ryhel (4): usb: phy: tegra: cosmetic fixes usb: phy: tegra: return error value from utmi_wait_register usb: phy: tegra: parametrize HSIC PTS value usb: phy: tegra: parametrize PORTSC1 register offset drivers/usb/phy/phy-tegra-usb.c | 45 +++++++++++++++---------------- include/linux/usb/tegra_usb_phy.h | 8 ++++-- 2 files changed, 27 insertions(+), 26 deletions(-) -- 2.51.0
On 2/2/26 11:05 AM, Svyatoslav Ryhel wrote: This initialization seems pointless -- the newly added variable gets overwritten by you later... [...] MBR, Sergey
{ "author": "Sergey Shtylyov <sergei.shtylyov@gmail.com>", "date": "Mon, 2 Feb 2026 15:05:03 +0300", "thread_id": "20260202080526.23487-1-clamor95@gmail.com.mbox.gz" }
lkml
[PATCH v1 0/4] usb: phy: tegra: HSIC adjustments
Followup to a recent HSIC bringup with a few small improvements. Svyatoslav Ryhel (4): usb: phy: tegra: cosmetic fixes usb: phy: tegra: return error value from utmi_wait_register usb: phy: tegra: parametrize HSIC PTS value usb: phy: tegra: parametrize PORTSC1 register offset drivers/usb/phy/phy-tegra-usb.c | 45 +++++++++++++++---------------- include/linux/usb/tegra_usb_phy.h | 8 ++++-- 2 files changed, 27 insertions(+), 26 deletions(-) -- 2.51.0
пн, 2 лют. 2026 р. о 14:05 Sergey Shtylyov <sergei.shtylyov@gmail.com> пише: So? let it better be initialized and rewritten then later on catch errors.
{ "author": "Svyatoslav Ryhel <clamor95@gmail.com>", "date": "Mon, 2 Feb 2026 14:14:13 +0200", "thread_id": "20260202080526.23487-1-clamor95@gmail.com.mbox.gz" }
lkml
[PATCH v1 0/4] usb: phy: tegra: HSIC adjustments
Followup to a recent HSIC bringup with a few small improvements. Svyatoslav Ryhel (4): usb: phy: tegra: cosmetic fixes usb: phy: tegra: return error value from utmi_wait_register usb: phy: tegra: parametrize HSIC PTS value usb: phy: tegra: parametrize PORTSC1 register offset drivers/usb/phy/phy-tegra-usb.c | 45 +++++++++++++++---------------- include/linux/usb/tegra_usb_phy.h | 8 ++++-- 2 files changed, 27 insertions(+), 26 deletions(-) -- 2.51.0
On 2/2/26 3:14 PM, Svyatoslav Ryhel wrote: I'm not sure what errors you mean here. To me, it (contrariwise) seems to mask the possible errors when you forget to set err to e.g. -ENOMEM before returning (when adding a call to kmalloc() or any other function that doesn't return an error code itself)... I'm pretty sure gcc will drop this initialization when generating the object code and (what's worse) the static analyzers will trip on this code telling you that the value 0 is unused... [...] MBR, Sergey
{ "author": "Sergey Shtylyov <sergei.shtylyov@gmail.com>", "date": "Mon, 2 Feb 2026 21:01:36 +0300", "thread_id": "20260202080526.23487-1-clamor95@gmail.com.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
When CONFIG_MODULE_SIG is disabled set_module_sig_enforced() is defined as an empty stub, so the check is unnecessary. The specific configuration option for set_module_sig_enforced() is about to change and removing the check avoids some later churn. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- arch/powerpc/kernel/ima_arch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/ima_arch.c b/arch/powerpc/kernel/ima_arch.c index b7029beed847..690263bf4265 100644 --- a/arch/powerpc/kernel/ima_arch.c +++ b/arch/powerpc/kernel/ima_arch.c @@ -63,8 +63,7 @@ static const char *const secure_and_trusted_rules[] = { const char *const *arch_get_ima_policy(void) { if (is_ppc_secureboot_enabled()) { - if (IS_ENABLED(CONFIG_MODULE_SIG)) - set_module_sig_enforced(); + set_module_sig_enforced(); if (is_ppc_trustedboot_enabled()) return secure_and_trusted_rules; -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:46 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
When configuration settings are disabled the guarded functions are defined as empty stubs, so the check is unnecessary. The specific configuration option for set_module_sig_enforced() is about to change and removing the checks avoids some later churn. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- security/integrity/ima/ima_efi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/security/integrity/ima/ima_efi.c b/security/integrity/ima/ima_efi.c index 138029bfcce1..a35dd166ad47 100644 --- a/security/integrity/ima/ima_efi.c +++ b/security/integrity/ima/ima_efi.c @@ -68,10 +68,8 @@ static const char * const sb_arch_rules[] = { const char * const *arch_get_ima_policy(void) { if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) { - if (IS_ENABLED(CONFIG_MODULE_SIG)) - set_module_sig_enforced(); - if (IS_ENABLED(CONFIG_KEXEC_SIG)) - set_kexec_sig_enforced(); + set_module_sig_enforced(); + set_kexec_sig_enforced(); return sb_arch_rules; } return NULL; -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:47 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
From: Coiby Xu <coxu@redhat.com> Currently if set_module_sig_enforced is called with CONFIG_MODULE_SIG=n e.g. [1], it can lead to a linking error, ld: security/integrity/ima/ima_appraise.o: in function `ima_appraise_measurement': security/integrity/ima/ima_appraise.c:587:(.text+0xbbb): undefined reference to `set_module_sig_enforced' This happens because the actual implementation of set_module_sig_enforced comes from CONFIG_MODULE_SIG but both the function declaration and the empty stub definition are tied to CONFIG_MODULES. So bind set_module_sig_enforced to CONFIG_MODULE_SIG instead. This allows (future) users to call set_module_sig_enforced directly without the "if IS_ENABLED(CONFIG_MODULE_SIG)" safeguard. Note this issue hasn't caused a real problem because all current callers of set_module_sig_enforced e.g. security/integrity/ima/ima_efi.c use "if IS_ENABLED(CONFIG_MODULE_SIG)" safeguard. [1] https://lore.kernel.org/lkml/20250928030358.3873311-1-coxu@redhat.com/ Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202510030029.VRKgik99-lkp@intel.com/ Reviewed-by: Aaron Tomlin <atomlin@atomlin.com> Reviewed-by: Daniel Gomez <da.gomez@samsung.com> Signed-off-by: Coiby Xu <coxu@redhat.com> Signed-off-by: Sami Tolvanen <samitolvanen@google.com> --- --- include/linux/module.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index d80c3ea57472..f288ca5cd95b 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -770,8 +770,6 @@ static inline bool is_livepatch_module(struct module *mod) #endif } -void set_module_sig_enforced(void); - void module_for_each_mod(int(*func)(struct module *mod, void *data), void *data); #else /* !CONFIG_MODULES... */ @@ -866,10 +864,6 @@ static inline bool module_requested_async_probing(struct module *module) } -static inline void set_module_sig_enforced(void) -{ -} - /* Dereference module function descriptor */ static inline void *dereference_module_function_descriptor(struct module *mod, void *ptr) @@ -925,6 +919,8 @@ static inline bool retpoline_module_ok(bool has_retpoline) #ifdef CONFIG_MODULE_SIG bool is_module_sig_enforced(void); +void set_module_sig_enforced(void); + static inline bool module_sig_ok(struct module *module) { return module->sig_ok; @@ -935,6 +931,10 @@ static inline bool is_module_sig_enforced(void) return false; } +static inline void set_module_sig_enforced(void) +{ +} + static inline bool module_sig_ok(struct module *module) { return true; -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:45 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
Switching the types will make some later changes cleaner. size_t is also the semantically correct type for this field. As both 'size_t' and 'unsigned int' are always the same size, this should be risk-free. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- kernel/module/internal.h | 2 +- kernel/module/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/module/internal.h b/kernel/module/internal.h index e68fbcd60c35..037fbb3b7168 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -66,7 +66,7 @@ struct load_info { /* pointer to module in temporary copy, freed at end of load_module() */ struct module *mod; Elf_Ehdr *hdr; - unsigned long len; + size_t len; Elf_Shdr *sechdrs; char *secstrings, *strtab; unsigned long symoffs, stroffs, init_typeoffs, core_typeoffs; diff --git a/kernel/module/main.c b/kernel/module/main.c index 710ee30b3bea..a88f95a13e06 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1838,7 +1838,7 @@ static int validate_section_offset(const struct load_info *info, Elf_Shdr *shdr) static int elf_validity_ehdr(const struct load_info *info) { if (info->len < sizeof(*(info->hdr))) { - pr_err("Invalid ELF header len %lu\n", info->len); + pr_err("Invalid ELF header len %zu\n", info->len); return -ENOEXEC; } if (memcmp(info->hdr->e_ident, ELFMAG, SELFMAG) != 0) { -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:49 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
The loading policy functionality will also be used by the hash-based module validation. Split it out from CONFIG_MODULE_SIG so it is usable by both. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- include/linux/module.h | 8 ++++---- kernel/module/Kconfig | 5 ++++- kernel/module/main.c | 26 +++++++++++++++++++++++++- kernel/module/signing.c | 21 --------------------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index f288ca5cd95b..f9601cba47cd 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -444,7 +444,7 @@ struct module { const u32 *gpl_crcs; bool using_gplonly_symbols; -#ifdef CONFIG_MODULE_SIG +#ifdef CONFIG_MODULE_SIG_POLICY /* Signature was verified. */ bool sig_ok; #endif @@ -916,7 +916,7 @@ static inline bool retpoline_module_ok(bool has_retpoline) } #endif -#ifdef CONFIG_MODULE_SIG +#ifdef CONFIG_MODULE_SIG_POLICY bool is_module_sig_enforced(void); void set_module_sig_enforced(void); @@ -925,7 +925,7 @@ static inline bool module_sig_ok(struct module *module) { return module->sig_ok; } -#else /* !CONFIG_MODULE_SIG */ +#else /* !CONFIG_MODULE_SIG_POLICY */ static inline bool is_module_sig_enforced(void) { return false; @@ -939,7 +939,7 @@ static inline bool module_sig_ok(struct module *module) { return true; } -#endif /* CONFIG_MODULE_SIG */ +#endif /* CONFIG_MODULE_SIG_POLICY */ #if defined(CONFIG_MODULES) && defined(CONFIG_KALLSYMS) int module_kallsyms_on_each_symbol(const char *modname, diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index e8bb2c9d917e..db3b61fb3e73 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -270,9 +270,12 @@ config MODULE_SIG debuginfo strip done by some packagers (such as rpmbuild) and inclusion into an initramfs that wants the module size reduced. +config MODULE_SIG_POLICY + def_bool MODULE_SIG + config MODULE_SIG_FORCE bool "Require modules to be validly signed" - depends on MODULE_SIG + depends on MODULE_SIG_POLICY help Reject unsigned modules or signed modules for which we don't have a key. Without this, such modules will simply taint the kernel. diff --git a/kernel/module/main.c b/kernel/module/main.c index a88f95a13e06..4442397a9f92 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2541,7 +2541,7 @@ static void module_augment_kernel_taints(struct module *mod, struct load_info *i mod->name); add_taint_module(mod, TAINT_TEST, LOCKDEP_STILL_OK); } -#ifdef CONFIG_MODULE_SIG +#ifdef CONFIG_MODULE_SIG_POLICY mod->sig_ok = info->sig_ok; if (!mod->sig_ok) { pr_notice_once("%s: module verification failed: signature " @@ -3921,3 +3921,27 @@ static int module_debugfs_init(void) } module_init(module_debugfs_init); #endif + +#ifdef CONFIG_MODULE_SIG_POLICY + +#undef MODULE_PARAM_PREFIX +#define MODULE_PARAM_PREFIX "module." + +static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE); +module_param(sig_enforce, bool_enable_only, 0644); + +/* + * Export sig_enforce kernel cmdline parameter to allow other subsystems rely + * on that instead of directly to CONFIG_MODULE_SIG_FORCE config. + */ +bool is_module_sig_enforced(void) +{ + return sig_enforce; +} +EXPORT_SYMBOL(is_module_sig_enforced); + +void set_module_sig_enforced(void) +{ + sig_enforce = true; +} +#endif diff --git a/kernel/module/signing.c b/kernel/module/signing.c index 6d64c0d18d0a..66d90784de89 100644 --- a/kernel/module/signing.c +++ b/kernel/module/signing.c @@ -16,27 +16,6 @@ #include <uapi/linux/module.h> #include "internal.h" -#undef MODULE_PARAM_PREFIX -#define MODULE_PARAM_PREFIX "module." - -static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE); -module_param(sig_enforce, bool_enable_only, 0644); - -/* - * Export sig_enforce kernel cmdline parameter to allow other subsystems rely - * on that instead of directly to CONFIG_MODULE_SIG_FORCE config. - */ -bool is_module_sig_enforced(void) -{ - return sig_enforce; -} -EXPORT_SYMBOL(is_module_sig_enforced); - -void set_module_sig_enforced(void) -{ - sig_enforce = true; -} - int module_sig_check(struct load_info *info, int flags) { int err; -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:53 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
With the addition of hash-based integrity checking, the configuration matrix is easier to represent in a dedicated function and with explicit usage of IS_ENABLED(). Drop the now unnecessary stub for module_sig_check(). Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- kernel/module/internal.h | 7 ------- kernel/module/main.c | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/kernel/module/internal.h b/kernel/module/internal.h index 037fbb3b7168..e053c29a5d08 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -337,14 +337,7 @@ int module_enforce_rwx_sections(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, void module_mark_ro_after_init(const Elf_Ehdr *hdr, Elf_Shdr *sechdrs, const char *secstrings); -#ifdef CONFIG_MODULE_SIG int module_sig_check(struct load_info *info, int flags); -#else /* !CONFIG_MODULE_SIG */ -static inline int module_sig_check(struct load_info *info, int flags) -{ - return 0; -} -#endif /* !CONFIG_MODULE_SIG */ #ifdef CONFIG_DEBUG_KMEMLEAK void kmemleak_load_module(const struct module *mod, const struct load_info *info); diff --git a/kernel/module/main.c b/kernel/module/main.c index 4442397a9f92..9c570078aa9c 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3344,6 +3344,16 @@ static int early_mod_check(struct load_info *info, int flags) return err; } +static int module_integrity_check(struct load_info *info, int flags) +{ + int err = 0; + + if (IS_ENABLED(CONFIG_MODULE_SIG)) + err = module_sig_check(info, flags); + + return err; +} + /* * Allocate and load the module: note that size of section 0 is always * zero, and we rely on this for optional sections. @@ -3357,18 +3367,18 @@ static int load_module(struct load_info *info, const char __user *uargs, char *after_dashes; /* - * Do the signature check (if any) first. All that - * the signature check needs is info->len, it does + * Do the integrity checks (if any) first. All that + * they need is info->len, it does * not need any of the section info. That can be * set up later. This will minimize the chances * of a corrupt module causing problems before - * we even get to the signature check. + * we even get to the integrity check. * * The check will also adjust info->len by stripping * off the sig length at the end of the module, making * checks against info->len more correct. */ - err = module_sig_check(info, flags); + err = module_integrity_check(info, flags); if (err) goto free_copy; -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:54 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
The upcoming module hashes functionality will build the modules in between the generation of the BTF data and the final link of vmlinux. At this point vmlinux is not yet built and therefore can't be used for module BTF generation. vmlinux.unstripped however is usable and sufficient for BTF generation. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- scripts/Makefile.modfinal | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index adfef1e002a9..930db0524a0a 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -40,11 +40,11 @@ quiet_cmd_ld_ko_o = LD [M] $@ quiet_cmd_btf_ko = BTF [M] $@ cmd_btf_ko = \ - if [ ! -f $(objtree)/vmlinux ]; then \ - printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \ + if [ ! -f $(objtree)/vmlinux.unstripped ]; then \ + printf "Skipping BTF generation for %s due to unavailability of vmlinux.unstripped\n" $@ 1>&2; \ else \ - LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base $(objtree)/vmlinux $@; \ - $(RESOLVE_BTFIDS) -b $(objtree)/vmlinux $@; \ + LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base $(objtree)/vmlinux.unstripped $@; \ + $(RESOLVE_BTFIDS) -b $(objtree)/vmlinux.unstripped $@; \ fi; # Same as newer-prereqs, but allows to exclude specified extra dependencies -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:51 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
The lockdown check buried in module_sig_check() will not compose well with the introduction of hash-based module validation. Move it into module_integrity_check() which will work better. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- kernel/module/main.c | 6 +++++- kernel/module/signing.c | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 9c570078aa9c..c09b25c0166a 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3351,7 +3351,11 @@ static int module_integrity_check(struct load_info *info, int flags) if (IS_ENABLED(CONFIG_MODULE_SIG)) err = module_sig_check(info, flags); - return err; + if (err) + return err; + if (info->sig_ok) + return 0; + return security_locked_down(LOCKDOWN_MODULE_SIGNATURE); } /* diff --git a/kernel/module/signing.c b/kernel/module/signing.c index 66d90784de89..8a5f66389116 100644 --- a/kernel/module/signing.c +++ b/kernel/module/signing.c @@ -11,7 +11,6 @@ #include <linux/module_signature.h> #include <linux/string.h> #include <linux/verification.h> -#include <linux/security.h> #include <crypto/public_key.h> #include <uapi/linux/module.h> #include "internal.h" @@ -68,5 +67,5 @@ int module_sig_check(struct load_info *info, int flags) return -EKEYREJECTED; } - return security_locked_down(LOCKDOWN_MODULE_SIGNATURE); + return 0; } -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:55 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
It is not used outside of signing.c. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- kernel/module/internal.h | 1 - kernel/module/signing.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/module/internal.h b/kernel/module/internal.h index 618202578b42..e68fbcd60c35 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -119,7 +119,6 @@ struct module_use { struct module *source, *target; }; -int mod_verify_sig(const void *mod, struct load_info *info); int try_to_force_load(struct module *mod, const char *reason); bool find_symbol(struct find_symbol_arg *fsa); struct module *find_module_all(const char *name, size_t len, bool even_unformed); diff --git a/kernel/module/signing.c b/kernel/module/signing.c index a2ff4242e623..fe3f51ac6199 100644 --- a/kernel/module/signing.c +++ b/kernel/module/signing.c @@ -40,7 +40,7 @@ void set_module_sig_enforced(void) /* * Verify the signature on a module. */ -int mod_verify_sig(const void *mod, struct load_info *info) +static int mod_verify_sig(const void *mod, struct load_info *info) { struct module_signature ms; size_t sig_len, modlen = info->len; -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:48 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
The new hash-based module integrity checking will also be able to satisfy the requirements of lockdown. Such an alternative is not representable with "select", so use "depends on" instead. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- security/lockdown/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/lockdown/Kconfig b/security/lockdown/Kconfig index e84ddf484010..155959205b8e 100644 --- a/security/lockdown/Kconfig +++ b/security/lockdown/Kconfig @@ -1,7 +1,7 @@ config SECURITY_LOCKDOWN_LSM bool "Basic module for enforcing kernel lockdown" depends on SECURITY - select MODULE_SIG if MODULES + depends on !MODULES || MODULE_SIG help Build support for an LSM that enforces a coarse kernel lockdown behaviour. -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:58 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
The upcoming CONFIG_MODULE_HASHES will introduce a signature type. This needs to be handled by callers differently than PKCS7 signatures. Report the signature type to the caller and let them verify it. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- include/linux/module_signature.h | 2 +- kernel/module/main.c | 9 +++++++-- kernel/module_signature.c | 14 ++++---------- security/integrity/ima/ima_modsig.c | 8 +++++++- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/include/linux/module_signature.h b/include/linux/module_signature.h index 186a55effa30..a45ce3b24403 100644 --- a/include/linux/module_signature.h +++ b/include/linux/module_signature.h @@ -41,6 +41,6 @@ struct module_signature { }; int mod_split_sig(const void *buf, size_t *buf_len, bool mangled, - size_t *sig_len, const u8 **sig, const char *name); + enum pkey_id_type *sig_type, size_t *sig_len, const u8 **sig, const char *name); #endif /* _LINUX_MODULE_SIGNATURE_H */ diff --git a/kernel/module/main.c b/kernel/module/main.c index d65bc300a78c..2a28a0ece809 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3348,19 +3348,24 @@ static int module_integrity_check(struct load_info *info, int flags) { bool mangled_module = flags & (MODULE_INIT_IGNORE_MODVERSIONS | MODULE_INIT_IGNORE_VERMAGIC); + enum pkey_id_type sig_type; size_t sig_len; const u8 *sig; int err = 0; if (IS_ENABLED(CONFIG_MODULE_SIG_POLICY)) { err = mod_split_sig(info->hdr, &info->len, mangled_module, - &sig_len, &sig, "module"); + &sig_type, &sig_len, &sig, "module"); if (err) return err; } - if (IS_ENABLED(CONFIG_MODULE_SIG)) + if (IS_ENABLED(CONFIG_MODULE_SIG) && sig_type == PKEY_ID_PKCS7) { err = module_sig_check(info, sig, sig_len); + } else { + pr_err("module: not signed with expected PKCS#7 message\n"); + err = -ENOPKG; + } if (err) return err; diff --git a/kernel/module_signature.c b/kernel/module_signature.c index b2384a73524c..8e0ac9906c9c 100644 --- a/kernel/module_signature.c +++ b/kernel/module_signature.c @@ -19,18 +19,11 @@ * @file_len: Size of the file to which @ms is appended. * @name: What is being checked. Used for error messages. */ -static int mod_check_sig(const struct module_signature *ms, size_t file_len, - const char *name) +static int mod_check_sig(const struct module_signature *ms, size_t file_len, const char *name) { if (be32_to_cpu(ms->sig_len) >= file_len - sizeof(*ms)) return -EBADMSG; - if (ms->id_type != PKEY_ID_PKCS7) { - pr_err("%s: not signed with expected PKCS#7 message\n", - name); - return -ENOPKG; - } - if (ms->algo != 0 || ms->hash != 0 || ms->signer_len != 0 || @@ -38,7 +31,7 @@ static int mod_check_sig(const struct module_signature *ms, size_t file_len, ms->__pad[0] != 0 || ms->__pad[1] != 0 || ms->__pad[2] != 0) { - pr_err("%s: PKCS#7 signature info has unexpected non-zero params\n", + pr_err("%s: signature info has unexpected non-zero params\n", name); return -EBADMSG; } @@ -47,7 +40,7 @@ static int mod_check_sig(const struct module_signature *ms, size_t file_len, } int mod_split_sig(const void *buf, size_t *buf_len, bool mangled, - size_t *sig_len, const u8 **sig, const char *name) + enum pkey_id_type *sig_type, size_t *sig_len, const u8 **sig, const char *name) { const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1; struct module_signature ms; @@ -74,6 +67,7 @@ int mod_split_sig(const void *buf, size_t *buf_len, bool mangled, if (ret) return ret; + *sig_type = ms.id_type; *sig_len = be32_to_cpu(ms.sig_len); modlen -= *sig_len + sizeof(ms); *buf_len = modlen; diff --git a/security/integrity/ima/ima_modsig.c b/security/integrity/ima/ima_modsig.c index a57342d39b07..a05008324a10 100644 --- a/security/integrity/ima/ima_modsig.c +++ b/security/integrity/ima/ima_modsig.c @@ -41,15 +41,21 @@ int ima_read_modsig(enum ima_hooks func, const void *buf, loff_t buf_len, struct modsig **modsig) { size_t buf_len_sz = buf_len; + enum pkey_id_type sig_type; struct modsig *hdr; size_t sig_len; const u8 *sig; int rc; - rc = mod_split_sig(buf, &buf_len_sz, true, &sig_len, &sig, func_tokens[func]); + rc = mod_split_sig(buf, &buf_len_sz, true, &sig_type, &sig_len, &sig, func_tokens[func]); if (rc) return rc; + if (sig_type != PKEY_ID_PKCS7) { + pr_err("%s: not signed with expected PKCS#7 message\n", func_tokens[func]); + return -ENOPKG; + } + /* Allocate sig_len additional bytes to hold the raw PKCS#7 data. */ hdr = kzalloc(struct_size(hdr, raw_pkcs7, sig_len), GFP_KERNEL); if (!hdr) -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:57 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
CONFIG_MODULE_HASHES needs to process the modules at build time in the exact form they will be loaded at runtime. If the modules are stripped afterwards they will not be loadable anymore. Also evaluate INSTALL_MOD_STRIP at build time and build the hashes based on modules stripped this way. If users specify inconsistent values of INSTALL_MOD_STRIP between build and installation time, an error is reported. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- .gitignore | 1 + kernel/module/Kconfig | 5 +++++ scripts/Makefile.modfinal | 9 +++++++-- scripts/Makefile.modinst | 4 ++-- scripts/Makefile.vmlinux | 1 + 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 299c54083672..900251c72ade 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ *.gz *.i *.ko +*.ko.stripped *.lex.c *.ll *.lst diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index c00ca830330c..9fd34765ce2c 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -425,6 +425,11 @@ config MODULE_HASHES Also see the warning in MODULE_SIG about stripping modules. +# To validate the consistency of INSTALL_MOD_STRIP for MODULE_HASHES +config MODULE_INSTALL_STRIP + string + default "$(INSTALL_MOD_STRIP)" + config MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS bool "Allow loading of modules with missing namespace imports" help diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 5b8e94170beb..890724edac69 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -63,10 +63,14 @@ ifdef CONFIG_DEBUG_INFO_BTF_MODULES endif +$(call cmd,check_tracepoint) +%.ko.stripped: %.ko $(wildcard include/config/MODULE_INSTALL_STRIP) + $(call cmd,install_mod) + $(call cmd,strip_mod) + quiet_cmd_merkle = MERKLE $@ - cmd_merkle = $(objtree)/scripts/modules-merkle-tree $@ .ko + cmd_merkle = $(objtree)/scripts/modules-merkle-tree $@ $(if $(CONFIG_MODULE_INSTALL_STRIP),.ko.stripped,.ko) -.tmp_module_hashes.c: $(modules:%.o=%.ko) $(objtree)/scripts/modules-merkle-tree FORCE +.tmp_module_hashes.c: $(if $(CONFIG_MODULE_INSTALL_STRIP),$(modules:%.o=%.ko.stripped),$(modules:%.o=%.ko)) $(objtree)/scripts/modules-merkle-tree $(wildcard include/config/MODULE_INSTALL_STRIP) FORCE $(call cmd,merkle) ifdef CONFIG_MODULE_HASHES @@ -75,6 +79,7 @@ endif targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) .module-common.o targets += $(modules:%.o=%.merkle) .tmp_module_hashes.c +targets += $(modules:%.o=%.ko.stripped) # Add FORCE to the prerequisites of a target to force it to be always rebuilt. # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 07380c7233a0..45606f994ad9 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -68,8 +68,8 @@ __modinst: $(install-y) ifdef CONFIG_MODULE_HASHES ifeq ($(KBUILD_EXTMOD),) -ifdef INSTALL_MOD_STRIP -$(error CONFIG_MODULE_HASHES and INSTALL_MOD_STRIP are mutually exclusive) +ifneq ($(INSTALL_MOD_STRIP),$(CONFIG_MODULE_INSTALL_STRIP)) +$(error Inconsistent values for INSTALL_MOD_STRIP between build and installation) endif endif endif diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index f4e38b953b01..4ce849f6253a 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -81,6 +81,7 @@ endif ifdef CONFIG_MODULE_HASHES vmlinux.unstripped: $(objtree)/scripts/modules-merkle-tree vmlinux.unstripped: modules.order +vmlinux.unstripped: $(wildcard include/config/MODULE_INSTALL_STRIP) endif # vmlinux -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:29:01 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
The logic to extract the signature bits from a module file are duplicated between the module core and IMA modsig appraisal. Unify the implementation. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- include/linux/module_signature.h | 4 +-- kernel/module/signing.c | 52 +++++++------------------------------ kernel/module_signature.c | 41 +++++++++++++++++++++++++++-- security/integrity/ima/ima_modsig.c | 24 ++++------------- 4 files changed, 56 insertions(+), 65 deletions(-) diff --git a/include/linux/module_signature.h b/include/linux/module_signature.h index 7eb4b00381ac..186a55effa30 100644 --- a/include/linux/module_signature.h +++ b/include/linux/module_signature.h @@ -40,7 +40,7 @@ struct module_signature { __be32 sig_len; /* Length of signature data */ }; -int mod_check_sig(const struct module_signature *ms, size_t file_len, - const char *name); +int mod_split_sig(const void *buf, size_t *buf_len, bool mangled, + size_t *sig_len, const u8 **sig, const char *name); #endif /* _LINUX_MODULE_SIGNATURE_H */ diff --git a/kernel/module/signing.c b/kernel/module/signing.c index fe3f51ac6199..6d64c0d18d0a 100644 --- a/kernel/module/signing.c +++ b/kernel/module/signing.c @@ -37,54 +37,22 @@ void set_module_sig_enforced(void) sig_enforce = true; } -/* - * Verify the signature on a module. - */ -static int mod_verify_sig(const void *mod, struct load_info *info) -{ - struct module_signature ms; - size_t sig_len, modlen = info->len; - int ret; - - pr_devel("==>%s(,%zu)\n", __func__, modlen); - - if (modlen <= sizeof(ms)) - return -EBADMSG; - - memcpy(&ms, mod + (modlen - sizeof(ms)), sizeof(ms)); - - ret = mod_check_sig(&ms, modlen, "module"); - if (ret) - return ret; - - sig_len = be32_to_cpu(ms.sig_len); - modlen -= sig_len + sizeof(ms); - info->len = modlen; - - return verify_pkcs7_signature(mod, modlen, mod + modlen, sig_len, - VERIFY_USE_SECONDARY_KEYRING, - VERIFYING_MODULE_SIGNATURE, - NULL, NULL); -} - int module_sig_check(struct load_info *info, int flags) { - int err = -ENODATA; - const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1; + int err; const char *reason; const void *mod = info->hdr; + size_t sig_len; + const u8 *sig; bool mangled_module = flags & (MODULE_INIT_IGNORE_MODVERSIONS | MODULE_INIT_IGNORE_VERMAGIC); - /* - * Do not allow mangled modules as a module with version information - * removed is no longer the module that was signed. - */ - if (!mangled_module && - info->len > markerlen && - memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) == 0) { - /* We truncate the module to discard the signature */ - info->len -= markerlen; - err = mod_verify_sig(mod, info); + + err = mod_split_sig(info->hdr, &info->len, mangled_module, &sig_len, &sig, "module"); + if (!err) { + err = verify_pkcs7_signature(mod, info->len, sig, sig_len, + VERIFY_USE_SECONDARY_KEYRING, + VERIFYING_MODULE_SIGNATURE, + NULL, NULL); if (!err) { info->sig_ok = true; return 0; diff --git a/kernel/module_signature.c b/kernel/module_signature.c index 00132d12487c..b2384a73524c 100644 --- a/kernel/module_signature.c +++ b/kernel/module_signature.c @@ -8,6 +8,7 @@ #include <linux/errno.h> #include <linux/printk.h> +#include <linux/string.h> #include <linux/module_signature.h> #include <asm/byteorder.h> @@ -18,8 +19,8 @@ * @file_len: Size of the file to which @ms is appended. * @name: What is being checked. Used for error messages. */ -int mod_check_sig(const struct module_signature *ms, size_t file_len, - const char *name) +static int mod_check_sig(const struct module_signature *ms, size_t file_len, + const char *name) { if (be32_to_cpu(ms->sig_len) >= file_len - sizeof(*ms)) return -EBADMSG; @@ -44,3 +45,39 @@ int mod_check_sig(const struct module_signature *ms, size_t file_len, return 0; } + +int mod_split_sig(const void *buf, size_t *buf_len, bool mangled, + size_t *sig_len, const u8 **sig, const char *name) +{ + const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1; + struct module_signature ms; + size_t modlen = *buf_len; + int ret; + + /* + * Do not allow mangled modules as a module with version information + * removed is no longer the module that was signed. + */ + if (!mangled && + *buf_len > markerlen && + memcmp(buf + modlen - markerlen, MODULE_SIG_STRING, markerlen) == 0) { + /* We truncate the module to discard the signature */ + modlen -= markerlen; + } + + if (modlen <= sizeof(ms)) + return -EBADMSG; + + memcpy(&ms, buf + (modlen - sizeof(ms)), sizeof(ms)); + + ret = mod_check_sig(&ms, modlen, name); + if (ret) + return ret; + + *sig_len = be32_to_cpu(ms.sig_len); + modlen -= *sig_len + sizeof(ms); + *buf_len = modlen; + *sig = buf + modlen; + + return 0; +} diff --git a/security/integrity/ima/ima_modsig.c b/security/integrity/ima/ima_modsig.c index 3265d744d5ce..a57342d39b07 100644 --- a/security/integrity/ima/ima_modsig.c +++ b/security/integrity/ima/ima_modsig.c @@ -40,44 +40,30 @@ struct modsig { int ima_read_modsig(enum ima_hooks func, const void *buf, loff_t buf_len, struct modsig **modsig) { - const size_t marker_len = strlen(MODULE_SIG_STRING); - const struct module_signature *sig; + size_t buf_len_sz = buf_len; struct modsig *hdr; size_t sig_len; - const void *p; + const u8 *sig; int rc; - if (buf_len <= marker_len + sizeof(*sig)) - return -ENOENT; - - p = buf + buf_len - marker_len; - if (memcmp(p, MODULE_SIG_STRING, marker_len)) - return -ENOENT; - - buf_len -= marker_len; - sig = (const struct module_signature *)(p - sizeof(*sig)); - - rc = mod_check_sig(sig, buf_len, func_tokens[func]); + rc = mod_split_sig(buf, &buf_len_sz, true, &sig_len, &sig, func_tokens[func]); if (rc) return rc; - sig_len = be32_to_cpu(sig->sig_len); - buf_len -= sig_len + sizeof(*sig); - /* Allocate sig_len additional bytes to hold the raw PKCS#7 data. */ hdr = kzalloc(struct_size(hdr, raw_pkcs7, sig_len), GFP_KERNEL); if (!hdr) return -ENOMEM; hdr->raw_pkcs7_len = sig_len; - hdr->pkcs7_msg = pkcs7_parse_message(buf + buf_len, sig_len); + hdr->pkcs7_msg = pkcs7_parse_message(sig, sig_len); if (IS_ERR(hdr->pkcs7_msg)) { rc = PTR_ERR(hdr->pkcs7_msg); kfree(hdr); return rc; } - memcpy(hdr->raw_pkcs7, buf + buf_len, sig_len); + memcpy(hdr->raw_pkcs7, sig, sig_len); /* We don't know the hash algorithm yet. */ hdr->hash_algo = HASH_ALGO__LAST; -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:52 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
To allow CONFIG_MODULE_HASHES in combination with INSTALL_MOD_STRIP, this logc will also be used by Makefile.modfinal. Move it to a shared location to enable reuse. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- scripts/Makefile.lib | 32 ++++++++++++++++++++++++++++++++ scripts/Makefile.modinst | 37 +++++-------------------------------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 28a1c08e3b22..7fcf3c43e408 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -474,6 +474,38 @@ define sed-offsets s:->::; p;}' endef +# +# Module Installation +# +quiet_cmd_install_mod = INSTALL $@ + cmd_install_mod = cp $< $@ + +# Module Strip +# --------------------------------------------------------------------------- +# +# INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they +# are installed. If INSTALL_MOD_STRIP is '1', then the default option +# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used +# as the options to the strip command. +ifeq ($(INSTALL_MOD_STRIP),1) +mod-strip-option := --strip-debug +else +mod-strip-option := $(INSTALL_MOD_STRIP) +endif + +# Strip +ifdef INSTALL_MOD_STRIP + +quiet_cmd_strip_mod = STRIP $@ + cmd_strip_mod = $(STRIP) $(mod-strip-option) $@ + +else + +quiet_cmd_strip_mod = + cmd_strip_mod = : + +endif + # Use filechk to avoid rebuilds when a header changes, but the resulting file # does not define filechk_offsets diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index ba4343b40497..07380c7233a0 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -8,6 +8,7 @@ __modinst: include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include +include $(srctree)/scripts/Makefile.lib install-y := @@ -36,7 +37,7 @@ install-y += $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo) install-$(CONFIG_BUILTIN_MODULE_RANGES) += $(MODLIB)/modules.builtin.ranges $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo modules.builtin.ranges): $(MODLIB)/%: % FORCE - $(call cmd,install) + $(call cmd,install_mod) endif @@ -65,40 +66,12 @@ install-$(CONFIG_MODULES) += $(modules) __modinst: $(install-y) @: -# -# Installation -# -quiet_cmd_install = INSTALL $@ - cmd_install = cp $< $@ - -# Strip -# -# INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they -# are installed. If INSTALL_MOD_STRIP is '1', then the default option -# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used -# as the options to the strip command. -ifdef INSTALL_MOD_STRIP - ifdef CONFIG_MODULE_HASHES ifeq ($(KBUILD_EXTMOD),) +ifdef INSTALL_MOD_STRIP $(error CONFIG_MODULE_HASHES and INSTALL_MOD_STRIP are mutually exclusive) endif endif - -ifeq ($(INSTALL_MOD_STRIP),1) -strip-option := --strip-debug -else -strip-option := $(INSTALL_MOD_STRIP) -endif - -quiet_cmd_strip = STRIP $@ - cmd_strip = $(STRIP) $(strip-option) $@ - -else - -quiet_cmd_strip = - cmd_strip = : - endif # @@ -133,8 +106,8 @@ endif $(foreach dir, $(sort $(dir $(install-y))), $(shell mkdir -p $(dir))) $(dst)/%.ko: %.ko FORCE - $(call cmd,install) - $(call cmd,strip) + $(call cmd,install_mod) + $(call cmd,strip_mod) $(call cmd,sign) ifdef CONFIG_MODULES -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:29:00 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
The signature splitting will also be used by CONFIG_MODULE_HASHES. Move it up the callchain, so the result can be reused. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- kernel/module/internal.h | 2 +- kernel/module/main.c | 13 ++++++++++++- kernel/module/signing.c | 21 +++++++-------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/kernel/module/internal.h b/kernel/module/internal.h index e053c29a5d08..e2d49122c2a1 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -337,7 +337,7 @@ int module_enforce_rwx_sections(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, void module_mark_ro_after_init(const Elf_Ehdr *hdr, Elf_Shdr *sechdrs, const char *secstrings); -int module_sig_check(struct load_info *info, int flags); +int module_sig_check(struct load_info *info, const u8 *sig, size_t sig_len); #ifdef CONFIG_DEBUG_KMEMLEAK void kmemleak_load_module(const struct module *mod, const struct load_info *info); diff --git a/kernel/module/main.c b/kernel/module/main.c index c09b25c0166a..d65bc300a78c 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3346,10 +3346,21 @@ static int early_mod_check(struct load_info *info, int flags) static int module_integrity_check(struct load_info *info, int flags) { + bool mangled_module = flags & (MODULE_INIT_IGNORE_MODVERSIONS | + MODULE_INIT_IGNORE_VERMAGIC); + size_t sig_len; + const u8 *sig; int err = 0; + if (IS_ENABLED(CONFIG_MODULE_SIG_POLICY)) { + err = mod_split_sig(info->hdr, &info->len, mangled_module, + &sig_len, &sig, "module"); + if (err) + return err; + } + if (IS_ENABLED(CONFIG_MODULE_SIG)) - err = module_sig_check(info, flags); + err = module_sig_check(info, sig, sig_len); if (err) return err; diff --git a/kernel/module/signing.c b/kernel/module/signing.c index 8a5f66389116..86164761cac7 100644 --- a/kernel/module/signing.c +++ b/kernel/module/signing.c @@ -15,26 +15,19 @@ #include <uapi/linux/module.h> #include "internal.h" -int module_sig_check(struct load_info *info, int flags) +int module_sig_check(struct load_info *info, const u8 *sig, size_t sig_len) { int err; const char *reason; const void *mod = info->hdr; - size_t sig_len; - const u8 *sig; - bool mangled_module = flags & (MODULE_INIT_IGNORE_MODVERSIONS | - MODULE_INIT_IGNORE_VERMAGIC); - err = mod_split_sig(info->hdr, &info->len, mangled_module, &sig_len, &sig, "module"); + err = verify_pkcs7_signature(mod, info->len, sig, sig_len, + VERIFY_USE_SECONDARY_KEYRING, + VERIFYING_MODULE_SIGNATURE, + NULL, NULL); if (!err) { - err = verify_pkcs7_signature(mod, info->len, sig, sig_len, - VERIFY_USE_SECONDARY_KEYRING, - VERIFYING_MODULE_SIGNATURE, - NULL, NULL); - if (!err) { - info->sig_ok = true; - return 0; - } + info->sig_ok = true; + return 0; } /* -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:56 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
The upcoming module hashes functionality will build the modules in between the generation of the BTF data and the final link of vmlinux. Having a dependency from the modules on vmlinux would make this impossible as it would mean having a cyclic dependency. Break this cyclic dependency by introducing a new target. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- scripts/Makefile.modfinal | 4 ++-- scripts/link-vmlinux.sh | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 149e12ff5700..adfef1e002a9 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -56,8 +56,8 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) # Re-generate module BTFs if either module's .ko or vmlinux changed -%.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE - +$(call if_changed_except,ld_ko_o,$(objtree)/vmlinux) +%.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/.tmp_vmlinux_btf.stamp) FORCE + +$(call if_changed_except,ld_ko_o,$(objtree)/.tmp_vmlinux_btf.stamp) ifdef CONFIG_DEBUG_INFO_BTF_MODULES +$(if $(newer-prereqs),$(call cmd,btf_ko)) endif diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 4ab44c73da4d..8c98f8645a5c 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -111,6 +111,7 @@ vmlinux_link() gen_btf() { local btf_data=${1}.btf.o + local btf_stamp=.tmp_vmlinux_btf.stamp info BTF "${btf_data}" LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1} @@ -131,6 +132,11 @@ gen_btf() fi printf "${et_rel}" | dd of="${btf_data}" conv=notrunc bs=1 seek=16 status=none + info STAMP $btf_stamp + if ! cmp --silent $btf_data $btf_stamp; then + cp $btf_data $btf_stamp + fi + btf_vmlinux_bin_o=${btf_data} } -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:50 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Non-builtin modules can be validated as before through signatures. Normally the .ko module files depend on a fully built vmlinux to be available for modpost validation and BTF generation. With CONFIG_MODULE_HASHES, vmlinux now depends on the modules to build a merkle tree. This introduces a dependency cycle which is impossible to satisfy. Work around this by building the modules during link-vmlinux.sh, after vmlinux is complete enough for modpost and BTF but before the final module hashes are The PKCS7 format which is used for regular module signatures can not represent Merkle proofs, so a new kind of module signature is introduced. As this signature type is only ever used for builtin modules, no compatibility issues can arise. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- .gitignore | 1 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 1 + kernel/module/Kconfig | 21 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 1 + kernel/module/main.c | 4 +- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.modfinal | 11 + scripts/Makefile.modinst | 13 + scripts/Makefile.vmlinux | 5 + scripts/link-vmlinux.sh | 14 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/lockdown/Kconfig | 2 +- 20 files changed, 685 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 3a7241c941f5..299c54083672 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ *.lz4 *.lzma *.lzo +*.merkle *.mod *.mod.c *.o diff --git a/Documentation/kbuild/reproducible-builds.rst b/Documentation/kbuild/reproducible-builds.rst index 96d208e578cd..bfde81e47b2d 100644 --- a/Documentation/kbuild/reproducible-builds.rst +++ b/Documentation/kbuild/reproducible-builds.rst @@ -82,7 +82,10 @@ generate a different temporary key for each build, resulting in the modules being unreproducible. However, including a signing key with your source would presumably defeat the purpose of signing modules. -One approach to this is to divide up the build process so that the +Instead ``CONFIG_MODULE_HASHES`` can be used to embed a static list +of valid modules to load. + +Another approach to this is to divide up the build process so that the unreproducible parts can be treated as sources: 1. Generate a persistent signing key. Add the certificate for the key diff --git a/Makefile b/Makefile index e404e4767944..841772a5a260 100644 --- a/Makefile +++ b/Makefile @@ -1588,8 +1588,10 @@ endif # is an exception. ifdef CONFIG_DEBUG_INFO_BTF_MODULES KBUILD_BUILTIN := y +ifndef CONFIG_MODULE_HASHES modules: vmlinux endif +endif modules: modules_prepare @@ -1981,7 +1983,11 @@ modules.order: $(build-dir) # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. # This is solely useful to speed up test compiles. modules: modpost -ifneq ($(KBUILD_MODPOST_NOFINAL),1) +ifdef CONFIG_MODULE_HASHES +ifeq ($(MODULE_HASHES_MODPOST_FINAL), 1) + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal +endif +else ifneq ($(KBUILD_MODPOST_NOFINAL),1) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal endif diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 8ca130af301f..d3846845e37b 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -508,6 +508,8 @@ \ PRINTK_INDEX \ \ + MODULE_HASHES \ + \ /* Kernel symbol table: Normal symbols */ \ __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \ __start___ksymtab = .; \ @@ -918,6 +920,15 @@ #define PRINTK_INDEX #endif +#ifdef CONFIG_MODULE_HASHES +#define MODULE_HASHES \ + .module_hashes : AT(ADDR(.module_hashes) - LOAD_OFFSET) { \ + KEEP(*(SORT(.module_hashes))) \ + } +#else +#define MODULE_HASHES +#endif + /* * Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler. * Otherwise, the type of .notes section would become PROGBITS instead of NOTES. diff --git a/include/linux/module_hashes.h b/include/linux/module_hashes.h new file mode 100644 index 000000000000..de61072627cc --- /dev/null +++ b/include/linux/module_hashes.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef _LINUX_MODULE_HASHES_H +#define _LINUX_MODULE_HASHES_H + +#include <linux/compiler_attributes.h> +#include <linux/types.h> +#include <crypto/sha2.h> + +#define __module_hashes_section __section(".module_hashes") +#define MODULE_HASHES_HASH_SIZE SHA256_DIGEST_SIZE + +struct module_hashes_proof { + __be32 pos; + u8 hash_sigs[][MODULE_HASHES_HASH_SIZE]; +} __packed; + +struct module_hashes_root { + u32 levels; + u8 hash[MODULE_HASHES_HASH_SIZE]; +}; + +extern const struct module_hashes_root module_hashes_root; + +#endif /* _LINUX_MODULE_HASHES_H */ diff --git a/include/linux/module_signature.h b/include/linux/module_signature.h index a45ce3b24403..3b510651830d 100644 --- a/include/linux/module_signature.h +++ b/include/linux/module_signature.h @@ -18,6 +18,7 @@ enum pkey_id_type { PKEY_ID_PGP, /* OpenPGP generated key ID */ PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */ PKEY_ID_PKCS7, /* Signature in PKCS#7 message */ + PKEY_ID_MERKLE, /* Merkle proof for modules */ }; /* diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index db3b61fb3e73..c00ca830330c 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -271,7 +271,7 @@ config MODULE_SIG inclusion into an initramfs that wants the module size reduced. config MODULE_SIG_POLICY - def_bool MODULE_SIG + def_bool MODULE_SIG || MODULE_HASHES config MODULE_SIG_FORCE bool "Require modules to be validly signed" @@ -289,7 +289,7 @@ config MODULE_SIG_ALL modules must be signed manually, using the scripts/sign-file tool. comment "Do not forget to sign required modules with scripts/sign-file" - depends on MODULE_SIG_FORCE && !MODULE_SIG_ALL + depends on MODULE_SIG_FORCE && !MODULE_SIG_ALL && !MODULE_HASHES choice prompt "Hash algorithm to sign modules" @@ -408,6 +408,23 @@ config MODULE_DECOMPRESS If unsure, say N. +config MODULE_HASHES + bool "Module hash validation" + depends on !MODULE_SIG_ALL + depends on !IMA_APPRAISE_MODSIG + select MODULE_SIG_FORMAT + select CRYPTO_LIB_SHA256 + help + Validate modules by their hashes. + Only modules built together with the main kernel image can be + validated that way. + + This is a reproducible-build compatible alternative to a build-time + generated module keyring, as enabled by + CONFIG_MODULE_SIG_KEY=certs/signing_key.pem. + + Also see the warning in MODULE_SIG about stripping modules. + config MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS bool "Allow loading of modules with missing namespace imports" help diff --git a/kernel/module/Makefile b/kernel/module/Makefile index d9e8759a7b05..dd37aaf4a61a 100644 --- a/kernel/module/Makefile +++ b/kernel/module/Makefile @@ -25,3 +25,4 @@ obj-$(CONFIG_KGDB_KDB) += kdb.o obj-$(CONFIG_MODVERSIONS) += version.o obj-$(CONFIG_MODULE_UNLOAD_TAINT_TRACKING) += tracking.o obj-$(CONFIG_MODULE_STATS) += stats.o +obj-$(CONFIG_MODULE_HASHES) += hashes.o hashes_root.o diff --git a/kernel/module/hashes.c b/kernel/module/hashes.c new file mode 100644 index 000000000000..23ca9f66652f --- /dev/null +++ b/kernel/module/hashes.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Module hash-based integrity checker + * + * Copyright (C) 2025 Thomas Weißschuh <linux@weissschuh.net> + * Copyright (C) 2025 Sebastian Andrzej Siewior <sebastian@breakpoint.cc> + */ + +#define pr_fmt(fmt) "module/hash: " fmt + +#include <linux/module_hashes.h> +#include <linux/module.h> +#include <linux/unaligned.h> + +#include <crypto/sha2.h> + +#include "internal.h" + +static __init __maybe_unused int module_hashes_init(void) +{ + pr_debug("root: levels=%u hash=%*phN\n", + module_hashes_root.levels, + (int)sizeof(module_hashes_root.hash), module_hashes_root.hash); + + return 0; +} + +#if IS_ENABLED(CONFIG_MODULE_DEBUG) +early_initcall(module_hashes_init); +#endif + +static void hash_entry(const void *left, const void *right, void *out) +{ + struct sha256_ctx ctx; + u8 magic = 0x02; + + sha256_init(&ctx); + sha256_update(&ctx, &magic, sizeof(magic)); + sha256_update(&ctx, left, MODULE_HASHES_HASH_SIZE); + sha256_update(&ctx, right, MODULE_HASHES_HASH_SIZE); + sha256_final(&ctx, out); +} + +static void hash_data(const void *d, size_t len, unsigned int pos, void *out) +{ + struct sha256_ctx ctx; + u8 magic = 0x01; + __be32 pos_be; + + pos_be = cpu_to_be32(pos); + + sha256_init(&ctx); + sha256_update(&ctx, &magic, sizeof(magic)); + sha256_update(&ctx, (const u8 *)&pos_be, sizeof(pos_be)); + sha256_update(&ctx, d, len); + sha256_final(&ctx, out); +} + +static bool module_hashes_verify_proof(u32 pos, const u8 hash_sigs[][MODULE_HASHES_HASH_SIZE], + u8 *cur) +{ + for (unsigned int i = 0; i < module_hashes_root.levels; i++, pos >>= 1) { + if ((pos & 1) == 0) + hash_entry(cur, hash_sigs[i], cur); + else + hash_entry(hash_sigs[i], cur, cur); + } + + return !memcmp(cur, module_hashes_root.hash, MODULE_HASHES_HASH_SIZE); +} + +int module_hash_check(struct load_info *info, const u8 *sig, size_t sig_len) +{ + u8 modhash[MODULE_HASHES_HASH_SIZE]; + const struct module_hashes_proof *proof; + size_t proof_size; + u32 pos; + + proof_size = struct_size(proof, hash_sigs, module_hashes_root.levels); + + if (sig_len != proof_size) + return -ENOPKG; + + proof = (const struct module_hashes_proof *)sig; + pos = get_unaligned_be32(&proof->pos); + + hash_data(info->hdr, info->len, pos, &modhash); + + if (module_hashes_verify_proof(pos, proof->hash_sigs, modhash)) + info->sig_ok = true; + + return 0; +} diff --git a/kernel/module/hashes_root.c b/kernel/module/hashes_root.c new file mode 100644 index 000000000000..1abfcd3aa679 --- /dev/null +++ b/kernel/module/hashes_root.c @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/module_hashes.h> + +/* Blank dummy data. Will be overridden by link-vmlinux.sh */ +const struct module_hashes_root module_hashes_root __module_hashes_section = {}; diff --git a/kernel/module/internal.h b/kernel/module/internal.h index e2d49122c2a1..e22837d3ac76 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -338,6 +338,7 @@ void module_mark_ro_after_init(const Elf_Ehdr *hdr, Elf_Shdr *sechdrs, const char *secstrings); int module_sig_check(struct load_info *info, const u8 *sig, size_t sig_len); +int module_hash_check(struct load_info *info, const u8 *sig, size_t sig_len); #ifdef CONFIG_DEBUG_KMEMLEAK void kmemleak_load_module(const struct module *mod, const struct load_info *info); diff --git a/kernel/module/main.c b/kernel/module/main.c index 2a28a0ece809..fa30b6387936 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3362,8 +3362,10 @@ static int module_integrity_check(struct load_info *info, int flags) if (IS_ENABLED(CONFIG_MODULE_SIG) && sig_type == PKEY_ID_PKCS7) { err = module_sig_check(info, sig, sig_len); + } else if (IS_ENABLED(CONFIG_MODULE_HASHES) && sig_type == PKEY_ID_MERKLE) { + err = module_hash_check(info, sig, sig_len); } else { - pr_err("module: not signed with expected PKCS#7 message\n"); + pr_err("module: not signed with signature mechanism\n"); err = -ENOPKG; } diff --git a/scripts/.gitignore b/scripts/.gitignore index 4215c2208f7e..8dad9b0d3b2d 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -5,6 +5,7 @@ /insert-sys-cert /kallsyms /module.lds +/modules-merkle-tree /recordmcount /rustdoc_test_builder /rustdoc_test_gen diff --git a/scripts/Makefile b/scripts/Makefile index 0941e5ce7b57..f539e4d93af7 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -11,6 +11,7 @@ hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += rustdoc_test_builder hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += rustdoc_test_gen +hostprogs-always-$(CONFIG_MODULE_HASHES) += modules-merkle-tree hostprogs-always-$(CONFIG_TRACEPOINTS) += tracepoint-update sorttable-objs := sorttable.o elf-parse.o @@ -36,6 +37,8 @@ HOSTLDLIBS_sorttable = -lpthread HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include HOSTCFLAGS_sign-file.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null) HOSTLDLIBS_sign-file = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto) +HOSTCFLAGS_modules-merkle-tree.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null) +HOSTLDLIBS_modules-merkle-tree = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto) ifdef CONFIG_UNWINDER_ORC ifeq ($(ARCH),x86_64) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 930db0524a0a..5b8e94170beb 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -63,7 +63,18 @@ ifdef CONFIG_DEBUG_INFO_BTF_MODULES endif +$(call cmd,check_tracepoint) +quiet_cmd_merkle = MERKLE $@ + cmd_merkle = $(objtree)/scripts/modules-merkle-tree $@ .ko + +.tmp_module_hashes.c: $(modules:%.o=%.ko) $(objtree)/scripts/modules-merkle-tree FORCE + $(call cmd,merkle) + +ifdef CONFIG_MODULE_HASHES +__modfinal: .tmp_module_hashes.c +endif + targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) .module-common.o +targets += $(modules:%.o=%.merkle) .tmp_module_hashes.c # Add FORCE to the prerequisites of a target to force it to be always rebuilt. # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 9ba45e5b32b1..ba4343b40497 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -79,6 +79,12 @@ quiet_cmd_install = INSTALL $@ # as the options to the strip command. ifdef INSTALL_MOD_STRIP +ifdef CONFIG_MODULE_HASHES +ifeq ($(KBUILD_EXTMOD),) +$(error CONFIG_MODULE_HASHES and INSTALL_MOD_STRIP are mutually exclusive) +endif +endif + ifeq ($(INSTALL_MOD_STRIP),1) strip-option := --strip-debug else @@ -116,6 +122,13 @@ quiet_cmd_sign := cmd_sign := : endif +ifeq ($(KBUILD_EXTMOD),) +ifdef CONFIG_MODULE_HASHES +quiet_cmd_sign = MERKLE [M] $@ + cmd_sign = cat $(objtree)/$*.merkle >> $@ +endif +endif + # Create necessary directories $(foreach dir, $(sort $(dir $(install-y))), $(shell mkdir -p $(dir))) diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index cd788cac9d91..f4e38b953b01 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -78,6 +78,11 @@ ifdef CONFIG_BUILDTIME_TABLE_SORT vmlinux.unstripped: scripts/sorttable endif +ifdef CONFIG_MODULE_HASHES +vmlinux.unstripped: $(objtree)/scripts/modules-merkle-tree +vmlinux.unstripped: modules.order +endif + # vmlinux # --------------------------------------------------------------------------- diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 8c98f8645a5c..bfeff1f5753d 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -103,7 +103,7 @@ vmlinux_link() ${ld} ${ldflags} -o ${output} \ ${wl}--whole-archive ${objs} ${wl}--no-whole-archive \ ${wl}--start-group ${libs} ${wl}--end-group \ - ${kallsymso} ${btf_vmlinux_bin_o} ${arch_vmlinux_o} ${ldlibs} + ${kallsymso} ${btf_vmlinux_bin_o} ${module_hashes_o} ${arch_vmlinux_o} ${ldlibs} } # generate .BTF typeinfo from DWARF debuginfo @@ -212,6 +212,7 @@ fi btf_vmlinux_bin_o= kallsymso= +module_hashes_o= strip_debug= generate_map= @@ -315,6 +316,17 @@ if is_enabled CONFIG_BUILDTIME_TABLE_SORT; then fi fi +if is_enabled CONFIG_MODULE_HASHES; then + info MAKE modules + ${MAKE} -f Makefile MODULE_HASHES_MODPOST_FINAL=1 modules + module_hashes_o=.tmp_module_hashes.o + info CC ${module_hashes_o} + ${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} ${KBUILD_CFLAGS} \ + ${KBUILD_CFLAGS_KERNEL} -fno-lto -c -o "${module_hashes_o}" ".tmp_module_hashes.c" + ${OBJCOPY} --dump-section .module_hashes=.tmp_module_hashes.bin ${module_hashes_o} + ${OBJCOPY} --update-section .module_hashes=.tmp_module_hashes.bin ${VMLINUX} +fi + # step a (see comment above) if is_enabled CONFIG_KALLSYMS; then if ! cmp -s System.map "${kallsyms_sysmap}"; then diff --git a/scripts/modules-merkle-tree.c b/scripts/modules-merkle-tree.c new file mode 100644 index 000000000000..a6ec0e21213b --- /dev/null +++ b/scripts/modules-merkle-tree.c @@ -0,0 +1,467 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Compute hashes for modules files and build a merkle tree. + * + * Copyright (C) 2025 Sebastian Andrzej Siewior <sebastian@breakpoint.cc> + * Copyright (C) 2025 Thomas Weißschuh <linux@weissschuh.net> + * + */ +#define _GNU_SOURCE 1 +#include <arpa/inet.h> +#include <err.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <stdbool.h> +#include <stdlib.h> + +#include <sys/stat.h> +#include <sys/mman.h> + +#include <openssl/evp.h> +#include <openssl/err.h> + +#include "ssl-common.h" + +static int hash_size; +static EVP_MD_CTX *ctx; + +struct module_signature { + uint8_t algo; /* Public-key crypto algorithm [0] */ + uint8_t hash; /* Digest algorithm [0] */ + uint8_t id_type; /* Key identifier type [PKEY_ID_PKCS7] */ + uint8_t signer_len; /* Length of signer's name [0] */ + uint8_t key_id_len; /* Length of key identifier [0] */ + uint8_t __pad[3]; + uint32_t sig_len; /* Length of signature data */ +}; + +#define PKEY_ID_MERKLE 3 + +static const char magic_number[] = "~Module signature appended~\n"; + +struct file_entry { + char *name; + unsigned int pos; + unsigned char hash[EVP_MAX_MD_SIZE]; +}; + +static struct file_entry *fh_list; +static size_t num_files; + +struct leaf_hash { + unsigned char hash[EVP_MAX_MD_SIZE]; +}; + +struct mtree { + struct leaf_hash **l; + unsigned int *entries; + unsigned int levels; +}; + +static inline void *xcalloc(size_t n, size_t size) +{ + void *p; + + p = calloc(n, size); + if (!p) + errx(1, "Memory allocation failed"); + + return p; +} + +static void *xmalloc(size_t size) +{ + void *p; + + p = malloc(size); + if (!p) + errx(1, "Memory allocation failed"); + + return p; +} + +static inline void *xreallocarray(void *oldp, size_t n, size_t size) +{ + void *p; + + p = reallocarray(oldp, n, size); + if (!p) + errx(1, "Memory allocation failed"); + + return p; +} + +static inline char *xasprintf(const char *fmt, ...) +{ + va_list ap; + char *strp; + int ret; + + va_start(ap, fmt); + ret = vasprintf(&strp, fmt, ap); + va_end(ap); + if (ret == -1) + err(1, "Memory allocation failed"); + + return strp; +} + +static unsigned int get_pow2(unsigned int val) +{ + return 31 - __builtin_clz(val); +} + +static unsigned int roundup_pow2(unsigned int val) +{ + return 1 << (get_pow2(val - 1) + 1); +} + +static unsigned int log2_roundup(unsigned int val) +{ + return get_pow2(roundup_pow2(val)); +} + +static void hash_data(void *p, unsigned int pos, size_t size, void *ret_hash) +{ + unsigned char magic = 0x01; + unsigned int pos_be; + + pos_be = htonl(pos); + + ERR(EVP_DigestInit_ex(ctx, NULL, NULL) != 1, "EVP_DigestInit_ex()"); + ERR(EVP_DigestUpdate(ctx, &magic, sizeof(magic)) != 1, "EVP_DigestUpdate(magic)"); + ERR(EVP_DigestUpdate(ctx, &pos_be, sizeof(pos_be)) != 1, "EVP_DigestUpdate(pos)"); + ERR(EVP_DigestUpdate(ctx, p, size) != 1, "EVP_DigestUpdate(data)"); + ERR(EVP_DigestFinal_ex(ctx, ret_hash, NULL) != 1, "EVP_DigestFinal_ex()"); +} + +static void hash_entry(void *left, void *right, void *ret_hash) +{ + int hash_size = EVP_MD_CTX_get_size_ex(ctx); + unsigned char magic = 0x02; + + ERR(EVP_DigestInit_ex(ctx, NULL, NULL) != 1, "EVP_DigestInit_ex()"); + ERR(EVP_DigestUpdate(ctx, &magic, sizeof(magic)) != 1, "EVP_DigestUpdate(magic)"); + ERR(EVP_DigestUpdate(ctx, left, hash_size) != 1, "EVP_DigestUpdate(left)"); + ERR(EVP_DigestUpdate(ctx, right, hash_size) != 1, "EVP_DigestUpdate(right)"); + ERR(EVP_DigestFinal_ex(ctx, ret_hash, NULL) != 1, "EVP_DigestFinal_ex()"); +} + +static void hash_file(struct file_entry *fe) +{ + struct stat sb; + int fd, ret; + void *mem; + + fd = open(fe->name, O_RDONLY); + if (fd < 0) + err(1, "Failed to open %s", fe->name); + + ret = fstat(fd, &sb); + if (ret) + err(1, "Failed to stat %s", fe->name); + + mem = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); + close(fd); + + if (mem == MAP_FAILED) + err(1, "Failed to mmap %s", fe->name); + + hash_data(mem, fe->pos, sb.st_size, fe->hash); + + munmap(mem, sb.st_size); +} + +static struct mtree *build_merkle(struct file_entry *fh, size_t num) +{ + struct mtree *mt; + unsigned int le; + + if (!num) + return NULL; + + mt = xmalloc(sizeof(*mt)); + mt->levels = log2_roundup(num); + + mt->l = xcalloc(sizeof(*mt->l), mt->levels); + + mt->entries = xcalloc(sizeof(*mt->entries), mt->levels); + le = num / 2; + if (num & 1) + le++; + mt->entries[0] = le; + mt->l[0] = xcalloc(sizeof(**mt->l), le); + + /* First level of pairs */ + for (unsigned int i = 0; i < num; i += 2) { + if (i == num - 1) { + /* Odd number of files, no pair. Hash with itself */ + hash_entry(fh[i].hash, fh[i].hash, mt->l[0][i / 2].hash); + } else { + hash_entry(fh[i].hash, fh[i + 1].hash, mt->l[0][i / 2].hash); + } + } + for (unsigned int i = 1; i < mt->levels; i++) { + int odd = 0; + + if (le & 1) { + le++; + odd++; + } + + mt->entries[i] = le / 2; + mt->l[i] = xcalloc(sizeof(**mt->l), le); + + for (unsigned int n = 0; n < le; n += 2) { + if (n == le - 2 && odd) { + /* Odd number of pairs, no pair. Hash with itself */ + hash_entry(mt->l[i - 1][n].hash, mt->l[i - 1][n].hash, + mt->l[i][n / 2].hash); + } else { + hash_entry(mt->l[i - 1][n].hash, mt->l[i - 1][n + 1].hash, + mt->l[i][n / 2].hash); + } + } + le = mt->entries[i]; + } + return mt; +} + +static void free_mtree(struct mtree *mt) +{ + if (!mt) + return; + + for (unsigned int i = 0; i < mt->levels; i++) + free(mt->l[i]); + + free(mt->l); + free(mt->entries); + free(mt); +} + +static void write_be_int(int fd, unsigned int v) +{ + unsigned int be_val = htonl(v); + + if (write(fd, &be_val, sizeof(be_val)) != sizeof(be_val)) + err(1, "Failed writing to file"); +} + +static void write_hash(int fd, const void *h) +{ + ssize_t wr; + + wr = write(fd, h, hash_size); + if (wr != hash_size) + err(1, "Failed writing to file"); +} + +static void build_proof(struct mtree *mt, unsigned int n, int fd) +{ + unsigned char cur[EVP_MAX_MD_SIZE]; + unsigned char tmp[EVP_MAX_MD_SIZE]; + struct file_entry *fe, *fe_sib; + + fe = &fh_list[n]; + + if ((n & 1) == 0) { + /* No pair, hash with itself */ + if (n + 1 == num_files) + fe_sib = fe; + else + fe_sib = &fh_list[n + 1]; + } else { + fe_sib = &fh_list[n - 1]; + } + /* First comes the node position into the file */ + write_be_int(fd, n); + + if ((n & 1) == 0) + hash_entry(fe->hash, fe_sib->hash, cur); + else + hash_entry(fe_sib->hash, fe->hash, cur); + + /* Next is the sibling hash, followed by hashes in the tree */ + write_hash(fd, fe_sib->hash); + + for (unsigned int i = 0; i < mt->levels - 1; i++) { + n >>= 1; + if ((n & 1) == 0) { + void *h; + + /* No pair, hash with itself */ + if (n + 1 == mt->entries[i]) + h = cur; + else + h = mt->l[i][n + 1].hash; + + hash_entry(cur, h, tmp); + write_hash(fd, h); + } else { + hash_entry(mt->l[i][n - 1].hash, cur, tmp); + write_hash(fd, mt->l[i][n - 1].hash); + } + memcpy(cur, tmp, hash_size); + } + + /* After all that, the end hash should match the root hash */ + if (memcmp(cur, mt->l[mt->levels - 1][0].hash, hash_size)) + errx(1, "hash mismatch"); +} + +static void append_module_signature_magic(int fd, unsigned int sig_len) +{ + struct module_signature sig_info = { + .id_type = PKEY_ID_MERKLE, + .sig_len = htonl(sig_len), + }; + + if (write(fd, &sig_info, sizeof(sig_info)) < 0) + err(1, "write(sig_info) failed"); + + if (write(fd, &magic_number, sizeof(magic_number) - 1) < 0) + err(1, "write(magic_number) failed"); +} + +static void write_merkle_root(struct mtree *mt, const char *fp) +{ + char buf[1024]; + unsigned int levels; + unsigned char *h; + FILE *f; + + if (mt) { + levels = mt->levels; + h = mt->l[mt->levels - 1][0].hash; + } else { + levels = 0; + h = xcalloc(1, hash_size); + } + + f = fopen(fp, "w"); + if (!f) + err(1, "Failed to create %s", buf); + + fprintf(f, "#include <linux/module_hashes.h>\n\n"); + fprintf(f, "const struct module_hashes_root module_hashes_root __module_hashes_section = {\n"); + + fprintf(f, "\t.levels = %u,\n", levels); + fprintf(f, "\t.hash = {"); + for (unsigned int i = 0; i < hash_size; i++) { + char *space = ""; + + if (!(i % 8)) + fprintf(f, "\n\t\t"); + + if ((i + 1) % 8) + space = " "; + + fprintf(f, "0x%02x,%s", h[i], space); + } + fprintf(f, "\n\t},"); + + fprintf(f, "\n};\n"); + fclose(f); + + if (!mt) + free(h); +} + +static char *xstrdup_replace_suffix(const char *str, const char *new_suffix) +{ + const char *current_suffix; + size_t base_len; + + current_suffix = strchr(str, '.'); + if (!current_suffix) + errx(1, "No existing suffix in '%s'", str); + + base_len = current_suffix - str; + + return xasprintf("%.*s%s", (int)base_len, str, new_suffix); +} + +static void read_modules_order(const char *fname, const char *suffix) +{ + char line[PATH_MAX]; + FILE *in; + + in = fopen(fname, "r"); + if (!in) + err(1, "fopen(%s)", fname); + + while (fgets(line, PATH_MAX, in)) { + struct file_entry *entry; + + fh_list = xreallocarray(fh_list, num_files + 1, sizeof(*fh_list)); + entry = &fh_list[num_files]; + + entry->pos = num_files; + entry->name = xstrdup_replace_suffix(line, suffix); + hash_file(entry); + + num_files++; + } + + fclose(in); +} + +static __attribute__((noreturn)) +void format(void) +{ + fprintf(stderr, + "Usage: scripts/modules-merkle-tree <root definition>\n"); + exit(2); +} + +int main(int argc, char *argv[]) +{ + const EVP_MD *hash_evp; + struct mtree *mt; + + if (argc != 3) + format(); + + hash_evp = EVP_get_digestbyname("sha256"); + ERR(!hash_evp, "EVP_get_digestbyname"); + + ctx = EVP_MD_CTX_new(); + ERR(!ctx, "EVP_MD_CTX_new()"); + + hash_size = EVP_MD_get_size(hash_evp); + ERR(hash_size <= 0, "EVP_get_digestbyname"); + + if (EVP_DigestInit_ex(ctx, hash_evp, NULL) != 1) + ERR(1, "EVP_DigestInit_ex()"); + + read_modules_order("modules.order", argv[2]); + + mt = build_merkle(fh_list, num_files); + write_merkle_root(mt, argv[1]); + for (unsigned int i = 0; i < num_files; i++) { + char *signame; + int fd; + + signame = xstrdup_replace_suffix(fh_list[i].name, ".merkle"); + + fd = open(signame, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd < 0) + err(1, "Can't create %s", signame); + + build_proof(mt, i, fd); + append_module_signature_magic(fd, lseek(fd, 0, SEEK_CUR)); + close(fd); + } + + free_mtree(mt); + for (unsigned int i = 0; i < num_files; i++) + free(fh_list[i].name); + free(fh_list); + + EVP_MD_CTX_free(ctx); + return 0; +} diff --git a/security/lockdown/Kconfig b/security/lockdown/Kconfig index 155959205b8e..60b240e3ef1f 100644 --- a/security/lockdown/Kconfig +++ b/security/lockdown/Kconfig @@ -1,7 +1,7 @@ config SECURITY_LOCKDOWN_LSM bool "Basic module for enforcing kernel lockdown" depends on SECURITY - depends on !MODULES || MODULE_SIG + depends on !MODULES || MODULE_SIG || MODULE_HASHES help Build support for an LSM that enforces a coarse kernel lockdown behaviour. -- 2.52.0
{ "author": "=?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Tue, 13 Jan 2026 13:28:59 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On 2026-01-13 13:28:59 [+0100], Thomas Weißschuh wrote: … This and a few other instances below could be optimized to avoid hashing. I probably forgot to let you know. -> https://git.kernel.org/pub/scm/linux/kernel/git/bigeasy/mtree-hashed-mods.git/commit/?id=10b565c123c731da37befe862de13678b7c54877 Sebastian
{ "author": "Sebastian Andrzej Siewior <bigeasy@linutronix.de>", "date": "Tue, 13 Jan 2026 15:56:35 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On 1/13/26 1:28 PM, Thomas Weißschuh wrote: The patch looks to modify the behavior when mangled_module is true. Previously, module_sig_check() didn't attempt to extract the signature in such a case and treated the module as unsigned. The err remained set to -ENODATA and the function subsequently consulted module_sig_check() and security_locked_down() to determine an appropriate result. Newly, module_sig_check() calls mod_split_sig(), which skips the extraction of the marker ("~Module signature appended~\n") from the end of the module and instead attempts to read it as an actual module_signature. The value is then passed to mod_check_sig() which should return -EBADMSG. The error is propagated to module_sig_check() and treated as fatal, without consulting module_sig_check() and security_locked_down(). I think the mangled_module flag should not be passed to mod_split_sig() and it should be handled solely by module_sig_check(). Passing mangled=true to mod_split_sig() seems incorrect here. It causes that the function doesn't properly extract the signature marker at the end of the module, no? -- Thanks, Petr
{ "author": "Petr Pavlu <petr.pavlu@suse.com>", "date": "Tue, 27 Jan 2026 16:20:15 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On 1/13/26 1:28 PM, Thomas Weißschuh wrote: I suggest moving the IS_ENABLED(CONFIG_MODULE_SIG) block under the new IS_ENABLED(CONFIG_MODULE_SIG_POLICY) section. I realize that CONFIG_MODULE_SIG implies CONFIG_MODULE_SIG_POLICY, but I believe this change makes it more apparent that this it the case. Otherwise, one might for example wonder if sig_len in the module_sig_check() call can be undefined. if (IS_ENABLED(CONFIG_MODULE_SIG_POLICY)) { err = mod_split_sig(info->hdr, &info->len, mangled_module, &sig_len, &sig, "module"); if (err) return err; if (IS_ENABLED(CONFIG_MODULE_SIG)) err = module_sig_check(info, sig, sig_len); } -- Thanks, Petr
{ "author": "Petr Pavlu <petr.pavlu@suse.com>", "date": "Thu, 29 Jan 2026 15:41:43 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On 1/13/26 1:28 PM, Thomas Weißschuh wrote: The new else branch means that if the user chooses not to configure any module integrity policy, they will no longer be able to load any modules. I think this entire if-else part should be moved under the IS_ENABLED(CONFIG_MODULE_SIG_POLICY) block above, as I'm mentioning on patch #12. -- Thanks, Petr
{ "author": "Petr Pavlu <petr.pavlu@suse.com>", "date": "Thu, 29 Jan 2026 15:44:31 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On 1/13/26 1:28 PM, Thomas Weißschuh wrote: I wonder if this dependency cycle could be resolved by utilizing the split into vmlinux.unstripped and vmlinux that occurred last year. The idea is to create the following ordering: vmlinux.unstripped -> modules -> vmlinux, and to patch in .module_hashes only when building the final vmlinux. This would require the following: * Split scripts/Makefile.vmlinux into two Makefiles, one that builds the current vmlinux.unstripped and the second one that builds the final vmlinux from it. * Modify the top Makefile to recognize vmlinux.unstripped and update the BTF generation rule 'modules: vmlinux' to 'modules: vmlinux.unstripped'. * Add the 'vmlinux: modules' ordering in the top Makefile for CONFIG_MODULE_HASHES=y. * Remove the patching of vmlinux.unstripped in scripts/link-vmlinux.sh and instead move it into scripts/Makefile.vmlinux when running objcopy to produce the final vmlinux. I think this approach has two main advantages: * CONFIG_MODULE_HASHES can be made orthogonal to CONFIG_DEBUG_INFO_BTF_MODULES. * All dependencies are expressed at the Makefile level instead of having scripts/link-vmlinux.sh invoke 'make -f Makefile modules'. Below is a rough prototype that applies on top of this series. It is a bit verbose due to the splitting of part of scripts/Makefile.vmlinux into scripts/Makefile.vmlinux_unstripped. -- Thanks, Petr diff --git a/Makefile b/Makefile index 841772a5a260..19a3beb82fa7 100644 --- a/Makefile +++ b/Makefile @@ -1259,7 +1259,7 @@ vmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS) vmlinux.o modules.builtin.modinfo modules.builtin: vmlinux_o @: -PHONY += vmlinux +PHONY += vmlinux.unstripped vmlinux # LDFLAGS_vmlinux in the top Makefile defines linker flags for the top vmlinux, # not for decompressors. LDFLAGS_vmlinux in arch/*/boot/compressed/Makefile is # unrelated; the decompressors just happen to have the same base name, @@ -1270,9 +1270,11 @@ PHONY += vmlinux # https://savannah.gnu.org/bugs/?61463 # For Make > 4.4, the following simple code will work: # vmlinux: private export LDFLAGS_vmlinux := $(LDFLAGS_vmlinux) -vmlinux: private _LDFLAGS_vmlinux := $(LDFLAGS_vmlinux) -vmlinux: export LDFLAGS_vmlinux = $(_LDFLAGS_vmlinux) -vmlinux: vmlinux.o $(KBUILD_LDS) modpost +vmlinux.unstripped: private _LDFLAGS_vmlinux := $(LDFLAGS_vmlinux) +vmlinux.unstripped: export LDFLAGS_vmlinux = $(_LDFLAGS_vmlinux) +vmlinux.unstripped: vmlinux.o $(KBUILD_LDS) modpost + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_unstripped +vmlinux: vmlinux.unstripped $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux # The actual objects are generated when descending, @@ -1541,7 +1543,7 @@ all: dtbs endif ifdef CONFIG_GENERIC_BUILTIN_DTB -vmlinux: dtbs +vmlinux.unstripped: dtbs endif endif @@ -1588,9 +1590,11 @@ endif # is an exception. ifdef CONFIG_DEBUG_INFO_BTF_MODULES KBUILD_BUILTIN := y -ifndef CONFIG_MODULE_HASHES -modules: vmlinux +modules: vmlinux.unstripped endif + +ifdef CONFIG_MODULE_HASHES +vmlinux: modules endif modules: modules_prepare @@ -1983,11 +1987,7 @@ modules.order: $(build-dir) # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. # This is solely useful to speed up test compiles. modules: modpost -ifdef CONFIG_MODULE_HASHES -ifeq ($(MODULE_HASHES_MODPOST_FINAL), 1) - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal -endif -else ifneq ($(KBUILD_MODPOST_NOFINAL),1) +ifneq ($(KBUILD_MODPOST_NOFINAL),1) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal endif diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 890724edac69..213e21ecfe0d 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -55,7 +55,7 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ $(cmd); \ printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) -# Re-generate module BTFs if either module's .ko or vmlinux changed +# Re-generate module BTFs if either module's .ko or vmlinux.unstripped changed %.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/.tmp_vmlinux_btf.stamp) FORCE +$(call if_changed_except,ld_ko_o,$(objtree)/.tmp_vmlinux_btf.stamp) ifdef CONFIG_DEBUG_INFO_BTF_MODULES diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index 4ce849f6253a..8c2a938c88ab 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -15,78 +15,24 @@ targets := %.o: %.S FORCE $(call if_changed_rule,as_o_S) -# Built-in dtb -# --------------------------------------------------------------------------- - -quiet_cmd_wrap_dtbs = WRAP $@ - cmd_wrap_dtbs = { \ - echo '\#include <asm-generic/vmlinux.lds.h>'; \ - echo '.section .dtb.init.rodata,"a"'; \ - while read dtb; do \ - symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _); \ - echo '.balign STRUCT_ALIGNMENT'; \ - echo ".global $${symbase}_begin"; \ - echo "$${symbase}_begin:"; \ - echo '.incbin "'$$dtb'" '; \ - echo ".global $${symbase}_end"; \ - echo "$${symbase}_end:"; \ - done < $<; \ - } > $@ - -.builtin-dtbs.S: .builtin-dtbs-list FORCE - $(call if_changed,wrap_dtbs) - -quiet_cmd_gen_dtbs_list = GEN $@ - cmd_gen_dtbs_list = \ - $(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@ - -.builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE - $(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list)) - -targets += .builtin-dtbs-list - -ifdef CONFIG_GENERIC_BUILTIN_DTB -targets += .builtin-dtbs.S .builtin-dtbs.o -vmlinux.unstripped: .builtin-dtbs.o -endif - -# vmlinux.unstripped +# vmlinux # --------------------------------------------------------------------------- -ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX -vmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o - -arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE - $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@ -endif - -ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) - -# Final link of vmlinux with optional arch pass after final link -cmd_link_vmlinux = \ - $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ - $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) +ifdef CONFIG_MODULE_HASHES +targets += .tmp_module_hashes.o +.tmp_module_hashes.o: .tmp_module_hashes.c FORCE -targets += vmlinux.unstripped .vmlinux.export.o -vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o .vmlinux.export.o $(KBUILD_LDS) FORCE - +$(call if_changed_dep,link_vmlinux) -ifdef CONFIG_DEBUG_INFO_BTF -vmlinux.unstripped: $(RESOLVE_BTFIDS) -endif +quiet_cmd_module_hashes = OBJCOPY $@ + cmd_module_hashes = $(OBJCOPY) --dump-section .module_hashes=$@ $< -ifdef CONFIG_BUILDTIME_TABLE_SORT -vmlinux.unstripped: scripts/sorttable -endif +targets += .tmp_module_hashes.bin +.tmp_module_hashes.bin: .tmp_module_hashes.o FORCE + $(call if_changed,module_hashes) -ifdef CONFIG_MODULE_HASHES -vmlinux.unstripped: $(objtree)/scripts/modules-merkle-tree -vmlinux.unstripped: modules.order -vmlinux.unstripped: $(wildcard include/config/MODULE_INSTALL_STRIP) +vmlinux: .tmp_module_hashes.bin +patch-module-hashes := --update-section .module_hashes=.tmp_module_hashes.bin endif -# vmlinux -# --------------------------------------------------------------------------- - remove-section-y := .modinfo remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*' '!.rel*.dyn' # for compatibility with binutils < 2.32 @@ -98,70 +44,15 @@ remove-symbols := -w --strip-unneeded-symbol='__mod_device_table__*' # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy, # it is necessary to remove the PT_LOAD flag from the segment. quiet_cmd_strip_relocs = OBJCOPY $@ - cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \ - $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $(remove-symbols) $@ + cmd_script_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \ + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \ + $(remove-symbols) \ + $(patch-module-hashes) $@ targets += vmlinux vmlinux: vmlinux.unstripped FORCE $(call if_changed,strip_relocs) -# modules.builtin.modinfo -# --------------------------------------------------------------------------- - -# .modinfo in vmlinux.unstripped is aligned to 8 bytes for compatibility with -# tools that expect vmlinux to have sufficiently aligned sections but the -# additional bytes used for padding .modinfo to satisfy this requirement break -# certain versions of kmod with -# -# depmod: ERROR: kmod_builtin_iter_next: unexpected string without modname prefix -# -# Strip the trailing padding bytes after extracting .modinfo to comply with -# what kmod expects to parse. -quiet_cmd_modules_builtin_modinfo = GEN $@ - cmd_modules_builtin_modinfo = $(cmd_objcopy); \ - sed -i 's/\x00\+$$/\x00/g' $@ - -OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary - -targets += modules.builtin.modinfo -modules.builtin.modinfo: vmlinux.unstripped FORCE - $(call if_changed,modules_builtin_modinfo) - -# modules.builtin -# --------------------------------------------------------------------------- - -__default: modules.builtin - -# The second line aids cases where multiple modules share the same object. - -quiet_cmd_modules_builtin = GEN $@ - cmd_modules_builtin = \ - tr '\0' '\n' < $< | \ - sed -n 's/^[[:alnum:]:_]*\.file=//p' | \ - tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@ - -targets += modules.builtin -modules.builtin: modules.builtin.modinfo FORCE - $(call if_changed,modules_builtin) - -# modules.builtin.ranges -# --------------------------------------------------------------------------- -ifdef CONFIG_BUILTIN_MODULE_RANGES -__default: modules.builtin.ranges - -quiet_cmd_modules_builtin_ranges = GEN $@ - cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@ - -targets += modules.builtin.ranges -modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ - modules.builtin vmlinux.map vmlinux.o.map FORCE - $(call if_changed,modules_builtin_ranges) - -vmlinux.map: vmlinux.unstripped - @: - -endif - # Add FORCE to the prerequisites of a target to force it to be always rebuilt. # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.vmlinux_unstripped b/scripts/Makefile.vmlinux_unstripped new file mode 100644 index 000000000000..914ee6f3b935 --- /dev/null +++ b/scripts/Makefile.vmlinux_unstripped @@ -0,0 +1,159 @@ +# SPDX-License-Identifier: GPL-2.0-only + +PHONY := __default +__default: vmlinux.unstripped + +include include/config/auto.conf +include $(srctree)/scripts/Kbuild.include +include $(srctree)/scripts/Makefile.lib + +targets := + +%.o: %.c FORCE + $(call if_changed_rule,cc_o_c) + +%.o: %.S FORCE + $(call if_changed_rule,as_o_S) + +# Built-in dtb +# --------------------------------------------------------------------------- + +quiet_cmd_wrap_dtbs = WRAP $@ + cmd_wrap_dtbs = { \ + echo '\#include <asm-generic/vmlinux.lds.h>'; \ + echo '.section .dtb.init.rodata,"a"'; \ + while read dtb; do \ + symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _); \ + echo '.balign STRUCT_ALIGNMENT'; \ + echo ".global $${symbase}_begin"; \ + echo "$${symbase}_begin:"; \ + echo '.incbin "'$$dtb'" '; \ + echo ".global $${symbase}_end"; \ + echo "$${symbase}_end:"; \ + done < $<; \ + } > $@ + +.builtin-dtbs.S: .builtin-dtbs-list FORCE + $(call if_changed,wrap_dtbs) + +quiet_cmd_gen_dtbs_list = GEN $@ + cmd_gen_dtbs_list = \ + $(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@ + +.builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE + $(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list)) + +targets += .builtin-dtbs-list + +ifdef CONFIG_GENERIC_BUILTIN_DTB +targets += .builtin-dtbs.S .builtin-dtbs.o +vmlinux.unstripped: .builtin-dtbs.o +endif + +# vmlinux.unstripped +# --------------------------------------------------------------------------- + +ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX +vmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o + +arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE + $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@ +endif + +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) + +# Final link of vmlinux with optional arch pass after final link +cmd_link_vmlinux = \ + $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ + $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) + +targets += vmlinux.unstripped .vmlinux.export.o +vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o .vmlinux.export.o $(KBUILD_LDS) FORCE + +$(call if_changed_dep,link_vmlinux) +ifdef CONFIG_DEBUG_INFO_BTF +vmlinux.unstripped: $(RESOLVE_BTFIDS) +endif + +ifdef CONFIG_BUILDTIME_TABLE_SORT +vmlinux.unstripped: scripts/sorttable +endif + +ifdef CONFIG_MODULE_HASHES +vmlinux.unstripped: $(objtree)/scripts/modules-merkle-tree +vmlinux.unstripped: modules.order +vmlinux.unstripped: $(wildcard include/config/MODULE_INSTALL_STRIP) +endif + +# modules.builtin.modinfo +# --------------------------------------------------------------------------- + +# .modinfo in vmlinux.unstripped is aligned to 8 bytes for compatibility with +# tools that expect vmlinux to have sufficiently aligned sections but the +# additional bytes used for padding .modinfo to satisfy this requirement break +# certain versions of kmod with +# +# depmod: ERROR: kmod_builtin_iter_next: unexpected string without modname prefix +# +# Strip the trailing padding bytes after extracting .modinfo to comply with +# what kmod expects to parse. +quiet_cmd_modules_builtin_modinfo = GEN $@ + cmd_modules_builtin_modinfo = $(cmd_objcopy); \ + sed -i 's/\x00\+$$/\x00/g' $@ + +OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary + +targets += modules.builtin.modinfo +modules.builtin.modinfo: vmlinux.unstripped FORCE + $(call if_changed,modules_builtin_modinfo) + +# modules.builtin +# --------------------------------------------------------------------------- + +__default: modules.builtin + +# The second line aids cases where multiple modules share the same object. + +quiet_cmd_modules_builtin = GEN $@ + cmd_modules_builtin = \ + tr '\0' '\n' < $< | \ + sed -n 's/^[[:alnum:]:_]*\.file=//p' | \ + tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@ + +targets += modules.builtin +modules.builtin: modules.builtin.modinfo FORCE + $(call if_changed,modules_builtin) + +# modules.builtin.ranges +# --------------------------------------------------------------------------- +ifdef CONFIG_BUILTIN_MODULE_RANGES +__default: modules.builtin.ranges + +quiet_cmd_modules_builtin_ranges = GEN $@ + cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@ + +targets += modules.builtin.ranges +modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ + modules.builtin vmlinux.map vmlinux.o.map FORCE + $(call if_changed,modules_builtin_ranges) + +vmlinux.map: vmlinux.unstripped + @: + +endif + +# Add FORCE to the prerequisites of a target to force it to be always rebuilt. +# --------------------------------------------------------------------------- + +PHONY += FORCE +FORCE: + +# Read all saved command lines and dependencies for the $(targets) we +# may be building above, using $(if_changed{,_dep}). As an +# optimization, we don't need to read them if the target does not +# exist, we will rebuild anyway in that case. + +existing-targets := $(wildcard $(sort $(targets))) + +-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) + +.PHONY: $(PHONY) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index bfeff1f5753d..80cb09707426 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -316,17 +316,6 @@ if is_enabled CONFIG_BUILDTIME_TABLE_SORT; then fi fi -if is_enabled CONFIG_MODULE_HASHES; then - info MAKE modules - ${MAKE} -f Makefile MODULE_HASHES_MODPOST_FINAL=1 modules - module_hashes_o=.tmp_module_hashes.o - info CC ${module_hashes_o} - ${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} ${KBUILD_CFLAGS} \ - ${KBUILD_CFLAGS_KERNEL} -fno-lto -c -o "${module_hashes_o}" ".tmp_module_hashes.c" - ${OBJCOPY} --dump-section .module_hashes=.tmp_module_hashes.bin ${module_hashes_o} - ${OBJCOPY} --update-section .module_hashes=.tmp_module_hashes.bin ${VMLINUX} -fi - # step a (see comment above) if is_enabled CONFIG_KALLSYMS; then if ! cmp -s System.map "${kallsyms_sysmap}"; then
{ "author": "Petr Pavlu <petr.pavlu@suse.com>", "date": "Fri, 30 Jan 2026 18:06:20 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On Tue, Jan 13, 2026 at 01:28:46PM +0100, Thomas Weißschuh wrote: Reviewed-by: Aaron Tomlin <atomlin@atomlin.com> -- Aaron Tomlin
{ "author": "Aaron Tomlin <atomlin@atomlin.com>", "date": "Fri, 30 Jan 2026 15:43:09 -0500", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On Tue, Jan 13, 2026 at 01:28:47PM +0100, Thomas Weißschuh wrote: Reviewed-by: Aaron Tomlin <atomlin@atomlin.com> -- Aaron Tomlin
{ "author": "Aaron Tomlin <atomlin@atomlin.com>", "date": "Fri, 30 Jan 2026 15:49:16 -0500", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On Tue, Jan 13, 2026 at 01:28:48PM +0100, Thomas Weißschuh wrote: Reviewed-by: Aaron Tomlin <atomlin@atomlin.com> -- Aaron Tomlin
{ "author": "Aaron Tomlin <atomlin@atomlin.com>", "date": "Fri, 30 Jan 2026 15:53:50 -0500", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. I think there is a middle ground where the module signing key is generated using a key derivation function that has as an input a deterministic value on the build host, such as /etc/machine-id . The problem with this approach is that only hosts knowing the value will be able to reproduce the build. Maybe this is a solution to NixOS secret management? Introduce minimal impurity as a cryptographic seed and derive the rest of the secrets using something like Argon2(seed, key_uuid). There might be another approach to code integrity rather than step-by-step reproducibility. One may exploit the very cryptographic primitives that make reproducibility hard to ensure that reproducibility is most likely valid. For example, the module signing issue, the build host publishes four artifacts: * The source-code * The compiled and signed binary * The build environment * Its public key Now, we don't need to sign with the private key to know that building the source code using the specific build environment and signing the result with the private key will result in the claimed binary. We can just compile and verify with the public key. So a traditional workflow would be: compiled_module + module_signature == module In this case we build the module, sign it with whatever key, distribute the builds and the private key to whoever wants to reproduce the build. Or we build locally and the key stays with the end-user. While the cryptographic approach would be: verify(compiled_code, module.signature) is True In this case we distribute the builds, source code and the public key. While everyone can ensure that the compiled code is the result of the build environment and source code. The signature is verified using cryptographic means. As long as no one cracks RSA or an algorithm of our choosing/has an absurd amount of luck, the cryptographic approach would be just as good as the traditional approach at ensuring that a program has stopped with a certain output.
{ "author": "=?UTF-8?q?Mihai-Drosi=20C=C3=A2ju?= <mcaju95@gmail.com>", "date": "Sat, 31 Jan 2026 09:36:36 +0200", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
Hi Mihai-Drosi, thanks for taking an interest into these patches! On 2026-01-31 09:36:36+0200, Mihai-Drosi Câju wrote: The goal is to make the distro kernel packages rebuildable by the general public. Any involvement of secret values will break this goal. I am not familiar with NixOS and its secret management. This patchset serves a wider audience. This could work if the goal is only to verify the reproducibility of a single, signed-en-bloc artifact. But we also need to handle vmlinux which contains the corresponding public key. It would need different handling. We can add some special logic to strip that public key before comparision. But then vmlinux might be compressed or wrapped in some other format. Another whole collection of special logic. (...) Thomas
{ "author": "Thomas =?utf-8?Q?Wei=C3=9Fschuh?= <linux@weissschuh.net>", "date": "Sun, 1 Feb 2026 17:22:12 +0100", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
Mihai-Drosi Câju <mcaju95@gmail.com> wrote: There is another issue too: If you have a static private key that you use to sign modules (and probably other things), someone will likely give you a GPL request to get it. One advantage of using a transient key every build and deleting it after is that no one has the key. One other thing to remember: security is *meant* to get in the way. That's the whole point of it. However, IANAL. David
{ "author": "David Howells <dhowells@redhat.com>", "date": "Sun, 01 Feb 2026 17:09:48 +0000", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On Sun, Feb 01, 2026 at 05:09:48PM +0000, David Howells wrote: It sounds like hash-based module authentication is just better, then. If the full set of authentic modules is known at kernel build time, then signatures are unnecessary to verify their authenticity: a list of hashes built into the kernel image is perfectly sufficient. (This patchset actually gets a little fancy and makes it a Merkle tree root. But it could be simplified to just a list of hashes.) With that being the case, why is there still effort being put into adding more features to module signing? I would think efforts should be focused on hash-based module authentication, i.e. this patchset. - Eric
{ "author": "Eric Biggers <ebiggers@kernel.org>", "date": "Sun, 1 Feb 2026 12:12:18 -0800", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
Eric Biggers <ebiggers@kernel.org> wrote: Because it's not just signing of modules and it's not just modules built with the kernel. Also a hash table just of module hashes built into the core kernel image will increase the size of the kernel by around a third of a meg (on Fedora 43 and assuming SHA512) with uncompressible data. David
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 02 Feb 2026 09:21:19 +0000", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
On Mon, Feb 02, 2026 at 09:21:19AM +0000, David Howells wrote: Module signing is indeed about the signing of modules. Could you give more details on this use case and why it needs signatures, as opposed to e.g. loading an additional Merkle tree root into the kernel to add to the set of allowed modules? This patchset already optimizes it to use Merkle tree proofs instead. While I'm a bit skeptical of the complexity myself (and distros shouldn't be shipping such an excessively large number of modules in the first place), if it's indeed needed it's already been solved. It's still much simpler than the PKCS#7 signature mess. - Eric
{ "author": "Eric Biggers <ebiggers@kernel.org>", "date": "Mon, 2 Feb 2026 10:30:55 -0800", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v4 00/17] module: Introduce hash-based integrity checking
The current signature-based module integrity checking has some drawbacks in combination with reproducible builds. Either the module signing key is generated at build time, which makes the build unreproducible, or a static signing key is used, which precludes rebuilds by third parties and makes the whole build and packaging process much more complicated. The goal is to reach bit-for-bit reproducibility. Excluding certain parts of the build output from the reproducibility analysis would be error-prone and force each downstream consumer to introduce new tooling. Introduce a new mechanism to ensure only well-known modules are loaded by embedding a merkle tree root of all modules built as part of the full kernel build into vmlinux. Interest has been proclaimed by NixOS, Arch Linux, Proxmox, SUSE and the general reproducible builds community. Compatibility with IMA modsig is not provided yet. It is still unclear to me if it should be hooked up transparently without any changes to the policy or it should require new policy options. Further improvements: * Use MODULE_SIG_HASH for configuration * UAPI for discovery? Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Use as Merkle tree over a linera list of hashes. - Provide compatibilith with INSTALL_MOD_STRIP - Rework commit messages. - Use vmlinux.unstripped over plain "vmlinux". - Link to v3: https://lore.kernel.org/r/20250429-module-hashes-v3-0-00e9258def9e@weissschuh.net Changes in v3: - Rebase on v6.15-rc1 - Use openssl to calculate hash - Avoid warning if no modules are built - Simplify module_integrity_check() a bit - Make incompatibility with INSTALL_MOD_STRIP explicit - Update docs - Add IMA cleanups - Link to v2: https://lore.kernel.org/r/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net Changes in v2: - Drop RFC state - Mention interested parties in cover letter - Expand Kconfig description - Add compatibility with CONFIG_MODULE_SIG - Parallelize module-hashes.sh - Update Documentation/kbuild/reproducible-builds.rst - Link to v1: https://lore.kernel.org/r/20241225-module-hashes-v1-0-d710ce7a3fd1@weissschuh.net --- Coiby Xu (1): module: Only declare set_module_sig_enforced when CONFIG_MODULE_SIG=y Thomas Weißschuh (16): powerpc/ima: Drop unnecessary check for CONFIG_MODULE_SIG ima: efi: Drop unnecessary check for CONFIG_MODULE_SIG/CONFIG_KEXEC_SIG module: Make mod_verify_sig() static module: Switch load_info::len to size_t kbuild: add stamp file for vmlinux BTF data kbuild: generate module BTF based on vmlinux.unstripped module: Deduplicate signature extraction module: Make module loading policy usable without MODULE_SIG module: Move integrity checks into dedicated function module: Move lockdown check into generic module loader module: Move signature splitting up module: Report signature type to users lockdown: Make the relationship to MODULE_SIG a dependency module: Introduce hash-based integrity checking kbuild: move handling of module stripping to Makefile.lib kbuild: make CONFIG_MODULE_HASHES compatible with module stripping .gitignore | 2 + Documentation/kbuild/reproducible-builds.rst | 5 +- Makefile | 8 +- arch/powerpc/kernel/ima_arch.c | 3 +- include/asm-generic/vmlinux.lds.h | 11 + include/linux/module.h | 20 +- include/linux/module_hashes.h | 25 ++ include/linux/module_signature.h | 5 +- kernel/module/Kconfig | 29 +- kernel/module/Makefile | 1 + kernel/module/hashes.c | 92 ++++++ kernel/module/hashes_root.c | 6 + kernel/module/internal.h | 13 +- kernel/module/main.c | 68 +++- kernel/module/signing.c | 83 +---- kernel/module_signature.c | 49 ++- scripts/.gitignore | 1 + scripts/Makefile | 3 + scripts/Makefile.lib | 32 ++ scripts/Makefile.modfinal | 28 +- scripts/Makefile.modinst | 46 +-- scripts/Makefile.vmlinux | 6 + scripts/link-vmlinux.sh | 20 +- scripts/modules-merkle-tree.c | 467 +++++++++++++++++++++++++++ security/integrity/ima/ima_efi.c | 6 +- security/integrity/ima/ima_modsig.c | 28 +- security/lockdown/Kconfig | 2 +- 27 files changed, 884 insertions(+), 175 deletions(-) --- base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 change-id: 20241225-module-hashes-7a50a7cc2a30 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>
Eric Biggers <ebiggers@kernel.org> wrote: The signature verification stuff in the kernel isn't just used for modules. kexec, for instance; wifi restriction database for another. Because we don't want to, for example, include all the nvidia drivers in our kernel SRPM. David
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 02 Feb 2026 18:38:51 +0000", "thread_id": "20260202183055.GB2036@quark.mbox.gz" }
lkml
[PATCH v2] hfsplus: fix s_fs_info leak on mount setup failure
Syzkaller reported a memory leak in hfsplus where s_fs_info (sbi) is allocated in hfsplus_init_fs_context() but never freed if the mount setup fails during setup_bdev_super(). In get_tree_bdev_flags(), if setup_bdev_super() fails, the superblock is torn down via deactivate_locked_super(). Since this failure occurs before fill_super() is called, the superblock's operations (sb->s_op) are not yet set. Consequently, the standard ->put_super() callback cannot be invoked, and the allocated s_fs_info remains leaked. Fix this by implementing a custom ->kill_sb() handler, hfsplus_kill_sb(), which explicitly frees s_fs_info using RCU synchronization. This ensures cleanup happens regardless of whether fill_super() succeeded or ->put_super() was called. To support this new lifecycle: 1. In hfsplus_put_super(), remove the call_rcu() call. The actual freeing of s_fs_info is deferred to hfsplus_kill_sb(). 2. In hfsplus_fill_super(), remove the explicit cleanup of sbi (both kfree and unload_nls) in the error path. The VFS will call ->kill_sb() on failure, so retaining these would result in double-frees or refcount underflows. 3. Implement hfsplus_kill_sb() to invoke kill_block_super() and then free s_fs_info via RCU. Reported-by: syzbot+99f6ed51479b86ac4c41@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=99f6ed51479b86ac4c41 Signed-off-by: Shardul Bankar <shardul.b@mpiricsoftware.com> --- v1: - tried to fix the leak in fs/super.c (VFS layer). - Link: https://lore.kernel.org/all/20260201082724.GC3183987@ZenIV/ v2: - abandons the VFS changes in favor of a driver-specific fix in hfsplus, implementing a custom ->kill_sb() to handle the cleanup lifecycle, as suggested by Al Viro. fs/hfsplus/super.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c index aaffa9e060a0..cc80cd545a3e 100644 --- a/fs/hfsplus/super.c +++ b/fs/hfsplus/super.c @@ -311,14 +311,6 @@ void hfsplus_mark_mdb_dirty(struct super_block *sb) spin_unlock(&sbi->work_lock); } -static void delayed_free(struct rcu_head *p) -{ - struct hfsplus_sb_info *sbi = container_of(p, struct hfsplus_sb_info, rcu); - - unload_nls(sbi->nls); - kfree(sbi); -} - static void hfsplus_put_super(struct super_block *sb) { struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb); @@ -344,7 +336,6 @@ static void hfsplus_put_super(struct super_block *sb) hfs_btree_close(sbi->ext_tree); kfree(sbi->s_vhdr_buf); kfree(sbi->s_backup_vhdr_buf); - call_rcu(&sbi->rcu, delayed_free); hfs_dbg("finished\n"); } @@ -648,9 +639,7 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc) kfree(sbi->s_vhdr_buf); kfree(sbi->s_backup_vhdr_buf); out_unload_nls: - unload_nls(sbi->nls); unload_nls(nls); - kfree(sbi); return err; } @@ -709,10 +698,27 @@ static int hfsplus_init_fs_context(struct fs_context *fc) return 0; } +static void delayed_free(struct rcu_head *p) +{ + struct hfsplus_sb_info *sbi = container_of(p, struct hfsplus_sb_info, rcu); + + unload_nls(sbi->nls); + kfree(sbi); +} + +static void hfsplus_kill_sb(struct super_block *sb) +{ + struct hfsplus_sb_info *sbi = sb->s_fs_info; + + kill_block_super(sb); + if (sbi) + call_rcu(&sbi->rcu, delayed_free); +} + static struct file_system_type hfsplus_fs_type = { .owner = THIS_MODULE, .name = "hfsplus", - .kill_sb = kill_block_super, + .kill_sb = hfsplus_kill_sb, .fs_flags = FS_REQUIRES_DEV, .init_fs_context = hfsplus_init_fs_context, }; -- 2.34.1
On Sun, 2026-02-01 at 18:42 +0530, Shardul Bankar wrote: The patch [1] fixes the issue and it in HFS/HFS+ tree already. Thanks, Slava. [1] https://lore.kernel.org/linux-fsdevel/20251201222843.82310-3-mehdi.benhadjkhelifa@gmail.com/
{ "author": "Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>", "date": "Mon, 2 Feb 2026 17:53:57 +0000", "thread_id": "cace4df975e1ae6e31af0103efcbca9cdb8b8350.camel@ibm.com.mbox.gz" }
lkml
[PATCH v2 0/2] ARM64 support for doorbell and intercept SINTs
From: "Anirudh Rayabharam (Microsoft)" <anirudh@anirudhrb.com> On x86, the HYPERVISOR_CALLBACK_VECTOR is used to receive synthetic interrupts (SINTs) from the hypervisor for doorbells and intercepts. There is no such vector reserved for arm64. On arm64, the INTID for SINTs should be in the SGI or PPI range. The hypervisor exposes a virtual device in the ACPI that reserves a PPI for this use. Introduce a platform_driver that binds to this ACPI device and obtains the interrupt vector that can be used for SINTs. Changes in v2: Addressed review comments: - Moved more stuff into mshv_synic.c - Code simplifications - Removed unnecessary debug prints v1: https://lore.kernel.org/linux-hyperv/20260128160437.3342167-1-anirudh@anirudhrb.com/ Anirudh Rayabharam (Microsoft) (2): mshv: refactor synic init and cleanup mshv: add arm64 support for doorbell & intercept SINTs drivers/hv/mshv_root.h | 5 +- drivers/hv/mshv_root_main.c | 59 ++------- drivers/hv/mshv_synic.c | 232 ++++++++++++++++++++++++++++++++++-- 3 files changed, 230 insertions(+), 66 deletions(-) -- 2.34.1
From: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> Rename mshv_synic_init() to mshv_synic_cpu_init() and mshv_synic_cleanup() to mshv_synic_cpu_exit() to better reflect that these functions handle per-cpu synic setup and teardown. Use mshv_synic_init/cleanup() to perform init/cleanup that is not per-cpu. Move all the synic related setup from mshv_parent_partition_init. Move the reboot notifier to mshv_synic.c because it currently only operates on the synic cpuhp state. Move out synic_pages from the global mshv_root since it's use is now completely local to mshv_synic.c. This is in preparation for the next patch which will add more stuff to mshv_synic_init(). No functional change. Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> --- drivers/hv/mshv_root.h | 5 ++- drivers/hv/mshv_root_main.c | 59 +++++------------------------- drivers/hv/mshv_synic.c | 71 +++++++++++++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 60 deletions(-) diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index 3c1d88b36741..26e0320c8097 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -183,7 +183,6 @@ struct hv_synic_pages { }; struct mshv_root { - struct hv_synic_pages __percpu *synic_pages; spinlock_t pt_ht_lock; DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS); struct hv_partition_property_vmm_capabilities vmm_caps; @@ -242,8 +241,8 @@ int mshv_register_doorbell(u64 partition_id, doorbell_cb_t doorbell_cb, void mshv_unregister_doorbell(u64 partition_id, int doorbell_portid); void mshv_isr(void); -int mshv_synic_init(unsigned int cpu); -int mshv_synic_cleanup(unsigned int cpu); +int mshv_synic_init(struct device *dev); +void mshv_synic_cleanup(void); static inline bool mshv_partition_encrypted(struct mshv_partition *partition) { diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 681b58154d5e..7c1666456e78 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -2035,7 +2035,6 @@ mshv_dev_release(struct inode *inode, struct file *filp) return 0; } -static int mshv_cpuhp_online; static int mshv_root_sched_online; static const char *scheduler_type_to_string(enum hv_scheduler_type type) @@ -2198,40 +2197,14 @@ root_scheduler_deinit(void) free_percpu(root_scheduler_output); } -static int mshv_reboot_notify(struct notifier_block *nb, - unsigned long code, void *unused) -{ - cpuhp_remove_state(mshv_cpuhp_online); - return 0; -} - -struct notifier_block mshv_reboot_nb = { - .notifier_call = mshv_reboot_notify, -}; - static void mshv_root_partition_exit(void) { - unregister_reboot_notifier(&mshv_reboot_nb); root_scheduler_deinit(); } static int __init mshv_root_partition_init(struct device *dev) { - int err; - - err = root_scheduler_init(dev); - if (err) - return err; - - err = register_reboot_notifier(&mshv_reboot_nb); - if (err) - goto root_sched_deinit; - - return 0; - -root_sched_deinit: - root_scheduler_deinit(); - return err; + return root_scheduler_init(dev); } static void mshv_init_vmm_caps(struct device *dev) @@ -2276,31 +2249,18 @@ static int __init mshv_parent_partition_init(void) MSHV_HV_MAX_VERSION); } - mshv_root.synic_pages = alloc_percpu(struct hv_synic_pages); - if (!mshv_root.synic_pages) { - dev_err(dev, "Failed to allocate percpu synic page\n"); - ret = -ENOMEM; + ret = mshv_synic_init(dev); + if (ret) goto device_deregister; - } - - ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", - mshv_synic_init, - mshv_synic_cleanup); - if (ret < 0) { - dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); - goto free_synic_pages; - } - - mshv_cpuhp_online = ret; ret = mshv_retrieve_scheduler_type(dev); if (ret) - goto remove_cpu_state; + goto synic_cleanup; if (hv_root_partition()) ret = mshv_root_partition_init(dev); if (ret) - goto remove_cpu_state; + goto synic_cleanup; mshv_init_vmm_caps(dev); @@ -2318,10 +2278,8 @@ static int __init mshv_parent_partition_init(void) exit_partition: if (hv_root_partition()) mshv_root_partition_exit(); -remove_cpu_state: - cpuhp_remove_state(mshv_cpuhp_online); -free_synic_pages: - free_percpu(mshv_root.synic_pages); +synic_cleanup: + mshv_synic_cleanup(); device_deregister: misc_deregister(&mshv_dev); return ret; @@ -2335,8 +2293,7 @@ static void __exit mshv_parent_partition_exit(void) mshv_irqfd_wq_cleanup(); if (hv_root_partition()) mshv_root_partition_exit(); - cpuhp_remove_state(mshv_cpuhp_online); - free_percpu(mshv_root.synic_pages); + mshv_synic_cleanup(); } module_init(mshv_parent_partition_init); diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index f8b0337cdc82..98c58755846d 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -12,11 +12,16 @@ #include <linux/mm.h> #include <linux/io.h> #include <linux/random.h> +#include <linux/cpuhotplug.h> +#include <linux/reboot.h> #include <asm/mshyperv.h> #include "mshv_eventfd.h" #include "mshv.h" +static int synic_cpuhp_online; +static struct hv_synic_pages __percpu *synic_pages; + static u32 synic_event_ring_get_queued_port(u32 sint_index) { struct hv_synic_event_ring_page **event_ring_page; @@ -26,7 +31,7 @@ static u32 synic_event_ring_get_queued_port(u32 sint_index) u32 message; u8 tail; - spages = this_cpu_ptr(mshv_root.synic_pages); + spages = this_cpu_ptr(synic_pages); event_ring_page = &spages->synic_event_ring_page; synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail); @@ -393,7 +398,7 @@ mshv_intercept_isr(struct hv_message *msg) void mshv_isr(void) { - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; struct hv_message *msg; bool handled; @@ -446,7 +451,7 @@ void mshv_isr(void) } } -int mshv_synic_init(unsigned int cpu) +static int mshv_synic_cpu_init(unsigned int cpu) { union hv_synic_simp simp; union hv_synic_siefp siefp; @@ -455,7 +460,7 @@ int mshv_synic_init(unsigned int cpu) union hv_synic_sint sint; #endif union hv_synic_scontrol sctrl; - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page = &spages->synic_event_flags_page; @@ -542,14 +547,14 @@ int mshv_synic_init(unsigned int cpu) return -EFAULT; } -int mshv_synic_cleanup(unsigned int cpu) +static int mshv_synic_cpu_exit(unsigned int cpu) { union hv_synic_sint sint; union hv_synic_simp simp; union hv_synic_siefp siefp; union hv_synic_sirbp sirbp; union hv_synic_scontrol sctrl; - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page = &spages->synic_event_flags_page; @@ -663,3 +668,57 @@ mshv_unregister_doorbell(u64 partition_id, int doorbell_portid) mshv_portid_free(doorbell_portid); } + +static int mshv_synic_reboot_notify(struct notifier_block *nb, + unsigned long code, void *unused) +{ + cpuhp_remove_state(synic_cpuhp_online); + return 0; +} + +static struct notifier_block mshv_synic_reboot_nb = { + .notifier_call = mshv_synic_reboot_notify, +}; + +int __init mshv_synic_init(struct device *dev) +{ + int ret = 0; + + synic_pages = alloc_percpu(struct hv_synic_pages); + if (!synic_pages) { + dev_err(dev, "Failed to allocate percpu synic page\n"); + return -ENOMEM; + } + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", + mshv_synic_cpu_init, + mshv_synic_cpu_exit); + if (ret < 0) { + dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); + goto free_synic_pages; + } + + synic_cpuhp_online = ret; + + if (hv_root_partition()) { + ret = register_reboot_notifier(&mshv_synic_reboot_nb); + if (ret) + goto remove_cpuhp_state; + } + + return 0; + +remove_cpuhp_state: + cpuhp_remove_state(synic_cpuhp_online); +free_synic_pages: + free_percpu(synic_pages); + return ret; +} + +void mshv_synic_cleanup(void) +{ + if (hv_root_partition()) + unregister_reboot_notifier(&mshv_synic_reboot_nb); + cpuhp_remove_state(synic_cpuhp_online); + free_percpu(synic_pages); +} -- 2.34.1
{ "author": "Anirudh Rayabharam <anirudh@anirudhrb.com>", "date": "Mon, 2 Feb 2026 18:27:05 +0000", "thread_id": "20260202182706.648192-1-anirudh@anirudhrb.com.mbox.gz" }
lkml
[PATCH v2 0/2] ARM64 support for doorbell and intercept SINTs
From: "Anirudh Rayabharam (Microsoft)" <anirudh@anirudhrb.com> On x86, the HYPERVISOR_CALLBACK_VECTOR is used to receive synthetic interrupts (SINTs) from the hypervisor for doorbells and intercepts. There is no such vector reserved for arm64. On arm64, the INTID for SINTs should be in the SGI or PPI range. The hypervisor exposes a virtual device in the ACPI that reserves a PPI for this use. Introduce a platform_driver that binds to this ACPI device and obtains the interrupt vector that can be used for SINTs. Changes in v2: Addressed review comments: - Moved more stuff into mshv_synic.c - Code simplifications - Removed unnecessary debug prints v1: https://lore.kernel.org/linux-hyperv/20260128160437.3342167-1-anirudh@anirudhrb.com/ Anirudh Rayabharam (Microsoft) (2): mshv: refactor synic init and cleanup mshv: add arm64 support for doorbell & intercept SINTs drivers/hv/mshv_root.h | 5 +- drivers/hv/mshv_root_main.c | 59 ++------- drivers/hv/mshv_synic.c | 232 ++++++++++++++++++++++++++++++++++-- 3 files changed, 230 insertions(+), 66 deletions(-) -- 2.34.1
From: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> On x86, the HYPERVISOR_CALLBACK_VECTOR is used to receive synthetic interrupts (SINTs) from the hypervisor for doorbells and intercepts. There is no such vector reserved for arm64. On arm64, the INTID for SINTs should be in the SGI or PPI range. The hypervisor exposes a virtual device in the ACPI that reserves a PPI for this use. Introduce a platform_driver that binds to this ACPI device and obtains the interrupt vector that can be used for SINTs. To better unify x86 and arm64 paths, introduce mshv_sint_vector_init() that either registers the platform_driver and obtains the INTID (arm64) or just uses HYPERVISOR_CALLBACK_VECTOR as the interrupt vector (x86). Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> --- drivers/hv/mshv_synic.c | 163 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 156 insertions(+), 7 deletions(-) diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index 98c58755846d..de5fee6e9f29 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -10,17 +10,24 @@ #include <linux/kernel.h> #include <linux/slab.h> #include <linux/mm.h> +#include <linux/interrupt.h> #include <linux/io.h> #include <linux/random.h> #include <linux/cpuhotplug.h> #include <linux/reboot.h> #include <asm/mshyperv.h> +#include <linux/platform_device.h> +#include <linux/acpi.h> #include "mshv_eventfd.h" #include "mshv.h" static int synic_cpuhp_online; static struct hv_synic_pages __percpu *synic_pages; +static int mshv_sint_vector = -1; /* hwirq for the SynIC SINTs */ +#ifndef HYPERVISOR_CALLBACK_VECTOR +static int mshv_sint_irq = -1; /* Linux IRQ for mshv_sint_vector */ +#endif static u32 synic_event_ring_get_queued_port(u32 sint_index) { @@ -456,9 +463,7 @@ static int mshv_synic_cpu_init(unsigned int cpu) union hv_synic_simp simp; union hv_synic_siefp siefp; union hv_synic_sirbp sirbp; -#ifdef HYPERVISOR_CALLBACK_VECTOR union hv_synic_sint sint; -#endif union hv_synic_scontrol sctrl; struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; @@ -501,10 +506,13 @@ static int mshv_synic_cpu_init(unsigned int cpu) hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); -#ifdef HYPERVISOR_CALLBACK_VECTOR +#ifndef HYPERVISOR_CALLBACK_VECTOR + enable_percpu_irq(mshv_sint_irq, 0); +#endif + /* Enable intercepts */ sint.as_uint64 = 0; - sint.vector = HYPERVISOR_CALLBACK_VECTOR; + sint.vector = mshv_sint_vector; sint.masked = false; sint.auto_eoi = hv_recommend_using_aeoi(); hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX, @@ -512,13 +520,12 @@ static int mshv_synic_cpu_init(unsigned int cpu) /* Doorbell SINT */ sint.as_uint64 = 0; - sint.vector = HYPERVISOR_CALLBACK_VECTOR; + sint.vector = mshv_sint_vector; sint.masked = false; sint.as_intercept = 1; sint.auto_eoi = hv_recommend_using_aeoi(); hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_DOORBELL_SINT_INDEX, sint.as_uint64); -#endif /* Enable global synic bit */ sctrl.as_uint64 = hv_get_non_nested_msr(HV_MSR_SCONTROL); @@ -573,6 +580,10 @@ static int mshv_synic_cpu_exit(unsigned int cpu) hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_DOORBELL_SINT_INDEX, sint.as_uint64); +#ifndef HYPERVISOR_CALLBACK_VECTOR + disable_percpu_irq(mshv_sint_irq); +#endif + /* Disable Synic's event ring page */ sirbp.as_uint64 = hv_get_non_nested_msr(HV_MSR_SIRBP); sirbp.sirbp_enabled = false; @@ -680,14 +691,149 @@ static struct notifier_block mshv_synic_reboot_nb = { .notifier_call = mshv_synic_reboot_notify, }; +#ifndef HYPERVISOR_CALLBACK_VECTOR +#ifdef CONFIG_ACPI +static long __percpu *mshv_evt; + +static acpi_status mshv_walk_resources(struct acpi_resource *res, void *ctx) +{ + struct resource r; + + if (res->type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ) { + if (!acpi_dev_resource_interrupt(res, 0, &r)) { + pr_err("Unable to parse MSHV ACPI interrupt\n"); + return AE_ERROR; + } + /* ARM64 INTID */ + mshv_sint_vector = res->data.extended_irq.interrupts[0]; + /* Linux IRQ number */ + mshv_sint_irq = r.start; + } + + return AE_OK; +} + +static irqreturn_t mshv_percpu_isr(int irq, void *dev_id) +{ + mshv_isr(); + return IRQ_HANDLED; +} + +static int mshv_sint_probe(struct platform_device *pdev) +{ + acpi_status result; + int ret; + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); + + result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, + mshv_walk_resources, NULL); + if (ACPI_FAILURE(result)) { + ret = -ENODEV; + goto out_fail; + } + + mshv_evt = alloc_percpu(long); + if (!mshv_evt) { + ret = -ENOMEM; + goto out_fail; + } + + ret = request_percpu_irq(mshv_sint_irq, mshv_percpu_isr, "MSHV", + mshv_evt); + if (ret) + goto free_evt; + + return 0; + +free_evt: + free_percpu(mshv_evt); +out_fail: + mshv_sint_vector = -1; + mshv_sint_irq = -1; + return ret; +} + +static void mshv_sint_remove(struct platform_device *pdev) +{ + free_percpu_irq(mshv_sint_irq, mshv_evt); + free_percpu(mshv_evt); +} +#else +static int mshv_sint_probe(struct platform_device *pdev) +{ + return -ENODEV; +} + +static void mshv_sint_remove(struct platform_device *pdev) +{ +} +#endif + +static const __maybe_unused struct acpi_device_id mshv_sint_device_ids[] = { + {"MSFT1003", 0}, + {"", 0}, +}; + +static struct platform_driver mshv_sint_drv = { + .probe = mshv_sint_probe, + .remove = mshv_sint_remove, + .driver = { + .name = "mshv_sint", + .acpi_match_table = ACPI_PTR(mshv_sint_device_ids), + .probe_type = PROBE_FORCE_SYNCHRONOUS, + }, +}; + +static int __init mshv_sint_vector_init(void) +{ + int ret; + + if (acpi_disabled) + return -ENODEV; + + ret = platform_driver_register(&mshv_sint_drv); + if (ret) + return ret; + + if (mshv_sint_vector == -1 || mshv_sint_irq == -1) { + platform_driver_unregister(&mshv_sint_drv); + return -ENODEV; + } + + return 0; +} + +static void mshv_sint_vector_cleanup(void) +{ + platform_driver_unregister(&mshv_sint_drv); +} +#else /* HYPERVISOR_CALLBACK_VECTOR */ +static int __init mshv_sint_vector_init(void) +{ + mshv_sint_vector = HYPERVISOR_CALLBACK_VECTOR; + return 0; +} + +static void mshv_sint_vector_cleanup(void) +{ +} +#endif /* HYPERVISOR_CALLBACK_VECTOR */ + int __init mshv_synic_init(struct device *dev) { int ret = 0; + ret = mshv_sint_vector_init(); + if (ret) { + dev_err(dev, "Failed to get MSHV SINT vector: %i\n", ret); + return ret; + } + synic_pages = alloc_percpu(struct hv_synic_pages); if (!synic_pages) { dev_err(dev, "Failed to allocate percpu synic page\n"); - return -ENOMEM; + ret = -ENOMEM; + goto sint_vector_cleanup; } ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", @@ -712,6 +858,8 @@ int __init mshv_synic_init(struct device *dev) cpuhp_remove_state(synic_cpuhp_online); free_synic_pages: free_percpu(synic_pages); +sint_vector_cleanup: + mshv_sint_vector_cleanup(); return ret; } @@ -721,4 +869,5 @@ void mshv_synic_cleanup(void) unregister_reboot_notifier(&mshv_synic_reboot_nb); cpuhp_remove_state(synic_cpuhp_online); free_percpu(synic_pages); + mshv_sint_vector_cleanup(); } -- 2.34.1
{ "author": "Anirudh Rayabharam <anirudh@anirudhrb.com>", "date": "Mon, 2 Feb 2026 18:27:06 +0000", "thread_id": "20260202182706.648192-1-anirudh@anirudhrb.com.mbox.gz" }
lkml
[PATCH] Cleanup ipu3 driver
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
On Mon, Feb 02, 2026 at 12:03:11PM +0200, Bogdan Sandu wrote: Was this an AI generated patch? Either way, it needs to be properly broken up into "one logical change per patch" like all others. thanks, greg k-h
{ "author": "Greg KH <gregkh@linuxfoundation.org>", "date": "Mon, 2 Feb 2026 11:14:26 +0100", "thread_id": "20260202175033.8640-1-bogdanelsandu2011@gmail.com.mbox.gz" }
lkml
[PATCH] Cleanup ipu3 driver
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
I can assure you, it is not AI-generated. per patch" like all others. Understood. I'll resend it afterwards. Thank you for your patience.
{ "author": "Bogdan Sandu <bogdanelsandu2011@gmail.com>", "date": "Mon, 2 Feb 2026 12:18:43 +0200", "thread_id": "20260202175033.8640-1-bogdanelsandu2011@gmail.com.mbox.gz" }
lkml
[PATCH] Cleanup ipu3 driver
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
{ "author": "Bogdan Sandu <bogdanelsandu2011@gmail.com>", "date": "Mon, 2 Feb 2026 12:18:44 +0200", "thread_id": "20260202175033.8640-1-bogdanelsandu2011@gmail.com.mbox.gz" }
lkml
[PATCH] Cleanup ipu3 driver
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
On Mon, Feb 02, 2026 at 12:18:44PM +0200, Bogdan Sandu wrote: You resent the same thing again? confused, greg k-h
{ "author": "Greg KH <gregkh@linuxfoundation.org>", "date": "Mon, 2 Feb 2026 11:32:15 +0100", "thread_id": "20260202175033.8640-1-bogdanelsandu2011@gmail.com.mbox.gz" }
lkml
[PATCH] Cleanup ipu3 driver
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
The previous patch has now been separated into four smaller ones, each one fixing a specific type of checkpatch.pl issue. Bogdan Sandu (4): media: ipu3: fix alignment media: ipu3: use tabs media: ipu3: avoid ending lines with paranthesis media: ipu3: use BIT() drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) -- 2.51.0
{ "author": "Bogdan Sandu <bogdanelsandu2011@gmail.com>", "date": "Mon, 2 Feb 2026 19:50:29 +0200", "thread_id": "20260202175033.8640-1-bogdanelsandu2011@gmail.com.mbox.gz" }
lkml
[PATCH] Cleanup ipu3 driver
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
Fix alignment with parentheses. Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 22 +++++++++++----------- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 +++++------ drivers/staging/media/ipu3/ipu3.c | 4 ++-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..145501e90 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1241,6 +1242,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1250,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1270,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2036,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2169,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..c33186208 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -774,7 +774,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
{ "author": "Bogdan Sandu <bogdanelsandu2011@gmail.com>", "date": "Mon, 2 Feb 2026 19:50:30 +0200", "thread_id": "20260202175033.8640-1-bogdanelsandu2011@gmail.com.mbox.gz" }
lkml
[PATCH] Cleanup ipu3 driver
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
Use tabs instead of spaces. Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 145501e90..e990eb5b3 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -1034,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) -- 2.51.0
{ "author": "Bogdan Sandu <bogdanelsandu2011@gmail.com>", "date": "Mon, 2 Feb 2026 19:50:31 +0200", "thread_id": "20260202175033.8640-1-bogdanelsandu2011@gmail.com.mbox.gz" }
lkml
[PATCH] Cleanup ipu3 driver
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
Don't end line with paranthesis. Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 13 +++++-------- drivers/staging/media/ipu3/ipu3.c | 3 +-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index e990eb5b3..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -1226,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index c33186208..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } -- 2.51.0
{ "author": "Bogdan Sandu <bogdanelsandu2011@gmail.com>", "date": "Mon, 2 Feb 2026 19:50:32 +0200", "thread_id": "20260202175033.8640-1-bogdanelsandu2011@gmail.com.mbox.gz" }
lkml
[PATCH] Cleanup ipu3 driver
Clean up warnings generated by ./scripts/checkpatch.pl regarding the ipu3 driver at /drivers/staging/media/ipu3 More specifically, the following files have been affected: ipu3-css.c, ipu3-mmu.c, ipu3-mmu.h, ipu3-v4l2.c, ipu3.c, ipu3.h Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-css.c | 39 ++++++++++++-------------- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 ++- drivers/staging/media/ipu3/ipu3-v4l2.c | 11 ++++---- drivers/staging/media/ipu3/ipu3.c | 7 ++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 777cac1c2..832581547 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -118,7 +118,8 @@ static const struct { /* Initialize queue based on given format, adjust format as needed */ static int imgu_css_queue_init(struct imgu_css_queue *queue, - struct v4l2_pix_format_mplane *fmt, u32 flags) + struct v4l2_pix_format_mplane *fmt, + u32 flags) { struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix; unsigned int i; @@ -1033,8 +1034,8 @@ static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe) 3 * cfg_dvs->num_horizontal_blocks / 2 * cfg_dvs->num_vertical_blocks) || imgu_css_pool_init(imgu, &css_pipe->pool.obgrid, - imgu_css_fw_obgrid_size( - &css->fwp->binary_header[css_pipe->bindex]))) + imgu_css_fw_obgrid_size + (&css->fwp->binary_header[css_pipe->bindex]))) goto out_of_memory; for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) @@ -1225,8 +1226,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++) for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) { - if (imgu_css_dma_buffer_resize( - imgu, + if (imgu_css_dma_buffer_resize(imgu, &css_pipe->binary_params_cs[j - 1][i], bi->info.isp.sp.mem_initializers.params[j][i].size)) goto out_of_memory; @@ -1241,6 +1241,7 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height, IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y; + h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height; w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width, 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X; @@ -1248,10 +1249,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w; size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2; for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i], + size)) goto out_of_memory; /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */ @@ -1269,10 +1269,9 @@ static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe) h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height; size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */ for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) - if (imgu_css_dma_buffer_resize( - imgu, - &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], - size)) + if (imgu_css_dma_buffer_resize(imgu, + &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i], + size)) goto out_of_memory; return 0; @@ -2036,7 +2035,7 @@ struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css) struct imgu_css_buffer, list); if (queue != b->queue || daddr != css_pipe->abi_buffers - [b->queue][b->queue_pos].daddr) { + [b->queue][b->queue_pos].daddr) { spin_unlock(&css_pipe->qlock); dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr); return ERR_PTR(-EIO); @@ -2169,7 +2168,7 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, map = imgu_css_pool_last(&css_pipe->pool.acc, 1); /* user acc */ r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr, - set_params ? &set_params->acc_param : NULL); + set_params ? &set_params->acc_param : NULL); if (r < 0) goto fail; } @@ -2298,13 +2297,11 @@ int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe, if (obgrid) imgu_css_pool_put(&css_pipe->pool.obgrid); if (vmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_VMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_VMEM0]); if (dmem0) - imgu_css_pool_put( - &css_pipe->pool.binary_params_p - [IMGU_ABI_MEM_ISP_DMEM0]); + imgu_css_pool_put(&css_pipe->pool.binary_params_p + [IMGU_ABI_MEM_ISP_DMEM0]); fail_no_put: return r; diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 2f6041d34..8ebfcddab 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -245,9 +245,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd, struct v4l2_rect *rect; dev_dbg(&imgu->pci_dev->dev, - "set subdev %u sel which %u target 0x%4x rect [%ux%u]", - imgu_sd->pipe, sel->which, sel->target, - sel->r.width, sel->r.height); + "set subdev %u sel which %u target 0x%4x rect [%ux%u]", + imgu_sd->pipe, sel->which, sel->target, + sel->r.width, sel->r.height); if (sel->pad != IMGU_NODE_IN) return -EINVAL; @@ -288,7 +288,7 @@ static int imgu_link_setup(struct media_entity *entity, WARN_ON(pad >= IMGU_NODE_NUM); dev_dbg(&imgu->pci_dev->dev, "pipe %u pad %u is %s", pipe, pad, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); imgu_pipe = &imgu->imgu_pipe[pipe]; imgu_pipe->nodes[pad].enabled = flags & MEDIA_LNK_FL_ENABLED; @@ -303,7 +303,7 @@ static int imgu_link_setup(struct media_entity *entity, __clear_bit(pipe, imgu->css.enabled_pipes); dev_dbg(&imgu->pci_dev->dev, "pipe %u is %s", pipe, - str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); + str_enabled_disabled(flags & MEDIA_LNK_FL_ENABLED)); return 0; } @@ -750,7 +750,6 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } - } if (!try) { diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index bdf5a4577..fe343d368 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -151,7 +151,7 @@ static int imgu_dummybufs_init(struct imgu_device *imgu, unsigned int pipe) /* May be called from atomic context */ static struct imgu_css_buffer *imgu_dummybufs_get(struct imgu_device *imgu, - int queue, unsigned int pipe) + int queue, unsigned int pipe) { unsigned int i; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; @@ -556,8 +556,7 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) buf->vid_buf.vbb.vb2_buf.timestamp = ns; buf->vid_buf.vbb.field = V4L2_FIELD_NONE; buf->vid_buf.vbb.sequence = - atomic_inc_return( - &imgu_pipe->nodes[node].sequence); + atomic_inc_return(&imgu_pipe->nodes[node].sequence); dev_dbg(&imgu->pci_dev->dev, "vb2 buffer sequence %d", buf->vid_buf.vbb.sequence); } @@ -774,7 +773,7 @@ static int __maybe_unused imgu_suspend(struct device *dev) synchronize_irq(pci_dev->irq); /* Wait until all buffers in CSS are done. */ if (!wait_event_timeout(imgu->buf_drain_wq, - imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) + imgu_css_queue_empty(&imgu->css), msecs_to_jiffies(1000))) dev_err(dev, "wait buffer drain timeout.\n"); imgu_css_stop_streaming(&imgu->css); -- 2.51.0
Prefer BIT() macro over manual bitshift. Signed-off-by: Bogdan Sandu <bogdanelsandu2011@gmail.com> --- drivers/staging/media/ipu3/ipu3-mmu.c | 2 +- drivers/staging/media/ipu3/ipu3-mmu.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c index cb9bf5fb2..95ce34ad8 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.c +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -21,7 +21,7 @@ #include "ipu3-mmu.h" #define IPU3_PT_BITS 10 -#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_PTES (BIT(IPU3_PT_BITS)) #define IPU3_PT_SIZE (IPU3_PT_PTES << 2) #define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) diff --git a/drivers/staging/media/ipu3/ipu3-mmu.h b/drivers/staging/media/ipu3/ipu3-mmu.h index a5f0bca7e..990482f10 100644 --- a/drivers/staging/media/ipu3/ipu3-mmu.h +++ b/drivers/staging/media/ipu3/ipu3-mmu.h @@ -5,8 +5,10 @@ #ifndef __IPU3_MMU_H #define __IPU3_MMU_H +#include <linux/bitops.h> + #define IPU3_PAGE_SHIFT 12 -#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) +#define IPU3_PAGE_SIZE (BIT(IPU3_PAGE_SHIFT)) /** * struct imgu_mmu_info - Describes mmu geometry -- 2.51.0
{ "author": "Bogdan Sandu <bogdanelsandu2011@gmail.com>", "date": "Mon, 2 Feb 2026 19:50:33 +0200", "thread_id": "20260202175033.8640-1-bogdanelsandu2011@gmail.com.mbox.gz" }
lkml
[PATCH] hwmon: gpio-fan: allow to stop FANs when CONFIG_PM is disabled
When CONFIG_PM is disabled, the GPIO controlled FANs can't be stopped by using the sysfs attributes since commit 0d01110e6356 ("hwmon: (gpio-fan) Add regulator support"). Using either the 'pwm1' or the 'fan1_target' attribute fails the same way: $ echo 0 > /sys/class/hwmon/hwmon1/pwm1 ash: write error: Function not implemented $ echo 0 > /sys/class/hwmon/hwmon1/fan1_target ash: write error: Function not implemented Both commands were working flawlessly before the mentioned commit. The issue happens because pm_runtime_put_sync() returns with -ENOSYS when CONFIG_PM is disabled, and the set_fan_speed() function handles this as an error. In order to restore the previous behaviour, change the error check in the set_fan_speed() function to ignore the -ENOSYS error code. Cc: stable@vger.kernel.org Fixes: 0d01110e6356 ("hwmon: (gpio-fan) Add regulator support") Signed-off-by: Gabor Juhos <j4g8y7@gmail.com> --- drivers/hwmon/gpio-fan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 516c34bb61c9cfa2927d31ee6459c8306be2fb5b..37645e9141dc7034fd440afed695af57829ec900 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -148,7 +148,7 @@ static int set_fan_speed(struct gpio_fan_data *fan_data, int speed_index) int ret; ret = pm_runtime_put_sync(fan_data->dev); - if (ret < 0) + if (ret < 0 && ret != -ENOSYS) return ret; } --- base-commit: 1117702454262fb361869451be5b006c022eb08a change-id: 20260202-gpio-fan-stop-fix-9ef4c26a9364 Best regards, -- Gabor Juhos <j4g8y7@gmail.com>
On Mon, Feb 02, 2026 at 04:58:57PM +0100, Gabor Juhos wrote: Applied. Thanks, Guenter
{ "author": "Guenter Roeck <linux@roeck-us.net>", "date": "Mon, 2 Feb 2026 08:58:33 -0800", "thread_id": "12798a6f-ab17-40aa-9b0c-eb44a2684ce3@roeck-us.net.mbox.gz" }
lkml
[iwl-net PATCH v3] idpf: change IRQ naming to match netdev and ethtool queue numbering
The code uses the vidx for the IRQ name but that doesn't match ethtool reporting nor netdev naming, this makes it hard to tune the device and associate queues with IRQs. Sequentially requesting irqs starting from '0' makes the output consistent. This commit changes the interrupt numbering but preserves the name format, maintaining ABI compatibility. Existing tools relying on the old numbering are already non-functional, as they lack a useful correlation to the interrupts. Before: ethtool -L eth1 tx 1 combined 3 grep . /proc/irq/*/*idpf*/../smp_affinity_list /proc/irq/67/idpf-Mailbox-0/../smp_affinity_list:0-55,112-167 /proc/irq/68/idpf-eth1-TxRx-1/../smp_affinity_list:0 /proc/irq/70/idpf-eth1-TxRx-3/../smp_affinity_list:1 /proc/irq/71/idpf-eth1-TxRx-4/../smp_affinity_list:2 /proc/irq/72/idpf-eth1-Tx-5/../smp_affinity_list:3 ethtool -S eth1 | grep -v ': 0' NIC statistics: tx_q-0_pkts: 1002 tx_q-1_pkts: 2679 tx_q-2_pkts: 1113 tx_q-3_pkts: 1192 <----- tx_q-3 vs idpf-eth1-Tx-5 rx_q-0_pkts: 1143 rx_q-1_pkts: 3172 rx_q-2_pkts: 1074 After: ethtool -L eth1 tx 1 combined 3 grep . /proc/irq/*/*idpf*/../smp_affinity_list /proc/irq/67/idpf-Mailbox-0/../smp_affinity_list:0-55,112-167 /proc/irq/68/idpf-eth1-TxRx-0/../smp_affinity_list:0 /proc/irq/70/idpf-eth1-TxRx-1/../smp_affinity_list:1 /proc/irq/71/idpf-eth1-TxRx-2/../smp_affinity_list:2 /proc/irq/72/idpf-eth1-Tx-3/../smp_affinity_list:3 ethtool -S eth1 | grep -v ': 0' NIC statistics: tx_q-0_pkts: 118 tx_q-1_pkts: 134 tx_q-2_pkts: 228 tx_q-3_pkts: 138 <--- tx_q-3 matches idpf-eth1-Tx-3 rx_q-0_pkts: 111 rx_q-1_pkts: 366 rx_q-2_pkts: 120 Fixes: d4d558718266 ("idpf: initialize interrupts and enable vport") Signed-off-by: Brian Vazquez <brianvv@google.com> Reviewed-by: Brett Creeley <brett.creeley@amd.com> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> --- V3: Add more context to the commit message V2: Add mising Fixes tag drivers/net/ethernet/intel/idpf/idpf_txrx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c index c2a1fe3c79ec..c1f8dfc570ce 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c @@ -4093,7 +4093,7 @@ static int idpf_vport_intr_req_irq(struct idpf_vport *vport, continue; name = kasprintf(GFP_KERNEL, "%s-%s-%s-%d", drv_name, if_name, - vec_name, vidx); + vec_name, vector); err = request_irq(irq_num, idpf_vport_intr_clean_queues, 0, name, q_vector); -- 2.52.0.457.g6b5491de43-goog
Dear Brian, Thank you for your patch. Am 26.01.26 um 22:55 schrieb Brian Vazquez via Intel-wired-lan: Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Kind regards, Paul
{ "author": "Paul Menzel <pmenzel@molgen.mpg.de>", "date": "Mon, 26 Jan 2026 23:33:18 +0100", "thread_id": "CANn89i+ioEJFnZF3B36xGXcCPgtiLevZOs9pncXhgLKb80sm_g@mail.gmail.com.mbox.gz" }
lkml
[iwl-net PATCH v3] idpf: change IRQ naming to match netdev and ethtool queue numbering
The code uses the vidx for the IRQ name but that doesn't match ethtool reporting nor netdev naming, this makes it hard to tune the device and associate queues with IRQs. Sequentially requesting irqs starting from '0' makes the output consistent. This commit changes the interrupt numbering but preserves the name format, maintaining ABI compatibility. Existing tools relying on the old numbering are already non-functional, as they lack a useful correlation to the interrupts. Before: ethtool -L eth1 tx 1 combined 3 grep . /proc/irq/*/*idpf*/../smp_affinity_list /proc/irq/67/idpf-Mailbox-0/../smp_affinity_list:0-55,112-167 /proc/irq/68/idpf-eth1-TxRx-1/../smp_affinity_list:0 /proc/irq/70/idpf-eth1-TxRx-3/../smp_affinity_list:1 /proc/irq/71/idpf-eth1-TxRx-4/../smp_affinity_list:2 /proc/irq/72/idpf-eth1-Tx-5/../smp_affinity_list:3 ethtool -S eth1 | grep -v ': 0' NIC statistics: tx_q-0_pkts: 1002 tx_q-1_pkts: 2679 tx_q-2_pkts: 1113 tx_q-3_pkts: 1192 <----- tx_q-3 vs idpf-eth1-Tx-5 rx_q-0_pkts: 1143 rx_q-1_pkts: 3172 rx_q-2_pkts: 1074 After: ethtool -L eth1 tx 1 combined 3 grep . /proc/irq/*/*idpf*/../smp_affinity_list /proc/irq/67/idpf-Mailbox-0/../smp_affinity_list:0-55,112-167 /proc/irq/68/idpf-eth1-TxRx-0/../smp_affinity_list:0 /proc/irq/70/idpf-eth1-TxRx-1/../smp_affinity_list:1 /proc/irq/71/idpf-eth1-TxRx-2/../smp_affinity_list:2 /proc/irq/72/idpf-eth1-Tx-3/../smp_affinity_list:3 ethtool -S eth1 | grep -v ': 0' NIC statistics: tx_q-0_pkts: 118 tx_q-1_pkts: 134 tx_q-2_pkts: 228 tx_q-3_pkts: 138 <--- tx_q-3 matches idpf-eth1-Tx-3 rx_q-0_pkts: 111 rx_q-1_pkts: 366 rx_q-2_pkts: 120 Fixes: d4d558718266 ("idpf: initialize interrupts and enable vport") Signed-off-by: Brian Vazquez <brianvv@google.com> Reviewed-by: Brett Creeley <brett.creeley@amd.com> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> --- V3: Add more context to the commit message V2: Add mising Fixes tag drivers/net/ethernet/intel/idpf/idpf_txrx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c index c2a1fe3c79ec..c1f8dfc570ce 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c @@ -4093,7 +4093,7 @@ static int idpf_vport_intr_req_irq(struct idpf_vport *vport, continue; name = kasprintf(GFP_KERNEL, "%s-%s-%s-%d", drv_name, if_name, - vec_name, vidx); + vec_name, vector); err = request_irq(irq_num, idpf_vport_intr_clean_queues, 0, name, q_vector); -- 2.52.0.457.g6b5491de43-goog
On Mon, Jan 26, 2026 at 10:56 PM Brian Vazquez <brianvv@google.com> wrote: Reviewed-by: Eric Dumazet <edumazet@google.com>
{ "author": "Eric Dumazet <edumazet@google.com>", "date": "Tue, 27 Jan 2026 17:38:16 +0100", "thread_id": "CANn89i+ioEJFnZF3B36xGXcCPgtiLevZOs9pncXhgLKb80sm_g@mail.gmail.com.mbox.gz" }
lkml
[PATCH] rtmutex: Introduce __cleanup() based infrastructure
Commit 54da6a092431 ("locking: Introduce __cleanup() based infrastructure") introduced lock guards for mutexes in include/linux/mutex.h, but, presumably as PREEMPT_RT wasn't merged at the time, the guard for rt_mutex was never created. Do this now so this infrastructure exists for rt_mutex as well. Signed-off-by: Thomas Böhler <witcher@wiredspace.de> --- include/linux/rtmutex.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index ede4c6bf6f22..3c766eba2c7d 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h @@ -17,6 +17,7 @@ #include <linux/linkage.h> #include <linux/rbtree_types.h> #include <linux/spinlock_types_raw.h> +#include <linux/cleanup.h> extern int max_lock_depth; @@ -129,4 +130,8 @@ extern int rt_mutex_trylock(struct rt_mutex *lock); extern void rt_mutex_unlock(struct rt_mutex *lock); +DEFINE_GUARD(rt_mutex, struct rt_mutex *, rt_mutex_lock(_T), rt_mutex_unlock(_T)) +DEFINE_GUARD_COND(rt_mutex, _try, rt_mutex_trylock(_T)) +DEFINE_GUARD_COND(rt_mutex, _intr, rt_mutex_lock_interruptible(_T), _RET == 0) + #endif --- base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62 change-id: 20260202-rt_mutex-guard-bfa1518b4f13 Best regards, -- Thomas Böhler <witcher@wiredspace.de>
On 2026-02-02 18:04:43 [+0100], Thomas Böhler wrote: Wait, what? rt_mutex can be used independently of PREEMPT_RT. I suggest you focus on what this patch does in its description and repost it with the locking maintainer in Cc. Do you plan to have any users of this? Sebastian
{ "author": "Sebastian Andrzej Siewior <bigeasy@linutronix.de>", "date": "Mon, 2 Feb 2026 18:58:40 +0100", "thread_id": "20260202175840.-IHSZ_Fn@linutronix.de.mbox.gz" }
lkml
[PATCH v7 0/6] i2c: xiic: use generic device property accessors
Switch to generic device property accessors. Switch to managed devm_ functions to simplify error handling. Skip clock setup on non-OF systems where clock cannot be provided. Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai> --- Changes in v7: - Drop the dt-bindings patch. - Skip clock setup on non-OF systems. - Minor commit body rewording. - Applied code-review trailers with `b4 trailers -u` - Link to v6: https://lore.kernel.org/r/20260127-i2c-xiic-v6-0-e82e2f6f657c@nexthop.ai Changes in v6: - Cosmetic changes to address the comments. - Added a patch to use resource format specifier in debug log. - Link to v5: https://lore.kernel.org/r/20260126-i2c-xiic-v5-0-88a16a28721c@nexthop.ai Changes in v5: - Reorder the cosmetic patch to be the last in the series. - Added a documentation patch to describe the optional clock. - Minor commit body rewording. - Link to v4: https://lore.kernel.org/r/20260123-i2c-xiic-v4-0-4a3eba3510ce@nexthop.ai Changes in v4: - Reorder the cosmetic patch to be the first in the series. - Amend the mutex_init patch to also switch to the managed pm_runtime_ variant. - Link to v3: https://lore.kernel.org/r/20260123-i2c-xiic-v3-0-eb7cd4254dfb@nexthop.ai Changes in v3: - Reorder the "optional clock" patch to be the first in the series. - Add a patch to switch to devm_mutex_init(). - Remove dup message in error path. - Cosmetic: use temporary dev variable. - Link to v2: https://lore.kernel.org/r/20260122-i2c-xiic-v2-0-134f5d743e8b@nexthop.ai Changes in v2: - Split the patch into two independent changes. - Added struct device *dev at the top of probe() and remove() to re-use. - Switched to device_set_node(...) --- Abdurrahman Hussain (6): i2c: xiic: skip input clock setup on non-OF systems i2c: xiic: switch to devres managed APIs i2c: xiic: remove duplicate error message i2c: xiic: switch to generic device property accessors i2c: xiic: cosmetic cleanup i2c xiic: cosmetic: use resource format specifier in debug log drivers/i2c/busses/i2c-xiic.c | 98 +++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 56 deletions(-) --- base-commit: 63804fed149a6750ffd28610c5c1c98cce6bd377 change-id: 20260122-i2c-xiic-3ba89ff5ea93 Best regards, -- Abdurrahman Hussain <abdurrahman@nexthop.ai>
From: Abdurrahman Hussain <abdurrahman@nexthop.ai> The devm_request_threaded_irq() already prints an error message. Remove the duplicate. Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai> --- drivers/i2c/busses/i2c-xiic.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index a480cbb86d93..ca5685660e45 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -1493,11 +1493,8 @@ static int xiic_i2c_probe(struct platform_device *pdev) ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, xiic_process, IRQF_ONESHOT, pdev->name, i2c); - - if (ret < 0) { - dev_err_probe(&pdev->dev, ret, "Cannot claim IRQ\n"); + if (ret) return ret; - } i2c->singlemaster = of_property_read_bool(pdev->dev.of_node, "single-master"); -- 2.52.0
{ "author": "Abdurrahman Hussain via B4 Relay <devnull+abdurrahman.nexthop.ai@kernel.org>", "date": "Thu, 29 Jan 2026 21:43:15 +0000", "thread_id": "7B60C48F-B2BA-4443-A4B7-F5086667A1F1@nexthop.ai.mbox.gz" }