source
large_stringclasses
2 values
subject
large_stringclasses
112 values
code
large_stringclasses
112 values
critique
large_stringlengths
61
3.04M
metadata
dict
lkml
[PATCHSET v3 sched_ext/for-6.20] sched_ext: Fix ops.dequeue() semantics
The callback ops.dequeue() is provided to let BPF schedulers observe when a task leaves the scheduler, either because it is dispatched or due to a task property change. However, this callback is currently unreliable and not invoked systematically, which can result in missed ops.dequeue() events. In particular, once a task is removed from the scheduler (whether for dispatch or due to a property change) the BPF scheduler loses visibility of the task and the sched_ext core may not always trigger ops.dequeue(). This breaks accurate accounting (i.e., per-DSQ queued runtime sums) and prevents reliable tracking of task lifecycle transitions. This patch set fixes the semantics of ops.dequeue(), ensuring that every ops.enqueue() is balanced by a corresponding ops.dequeue() invocation. In addition, ops.dequeue() is now properly invoked when tasks are removed from the sched_ext class, such as on task property changes. To distinguish between a "regular" dequeue and a property change dequeue a new dequeue flag is introduced: %SCX_DEQ_SCHED_CHANGE. BPF schedulers can use this flag to distinguish between regular dispatch dequeues (%SCX_DEQ_SCHED_CHANGE unset) and property change dequeues (%SCX_DEQ_SCHED_CHANGE set). Together, these changes allow BPF schedulers to reliably track task ownership and maintain accurate accounting. Changes in v3: - Rename SCX_DEQ_ASYNC to SCX_DEQ_SCHED_CHANGE - Handle core-sched dequeues (Kuba) - Link to v2: https://lore.kernel.org/all/20260121123118.964704-1-arighi@nvidia.com/ Changes in v2: - Distinguish between "dispatch" dequeues and "property change" dequeues (flag SCX_DEQ_ASYNC) - Link to v1: https://lore.kernel.org/all/20251219224450.2537941-1-arighi@nvidia.com Andrea Righi (2): sched_ext: Fix ops.dequeue() semantics selftests/sched_ext: Add test to validate ops.dequeue() semantics Documentation/scheduler/sched-ext.rst | 33 ++++ include/linux/sched/ext.h | 11 ++ kernel/sched/ext.c | 89 +++++++++- kernel/sched/ext_internal.h | 7 + tools/sched_ext/include/scx/enum_defs.autogen.h | 2 + tools/sched_ext/include/scx/enums.autogen.bpf.h | 2 + tools/sched_ext/include/scx/enums.autogen.h | 1 + tools/testing/selftests/sched_ext/Makefile | 1 + tools/testing/selftests/sched_ext/dequeue.bpf.c | 209 ++++++++++++++++++++++++ tools/testing/selftests/sched_ext/dequeue.c | 182 +++++++++++++++++++++ 10 files changed, 534 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/sched_ext/dequeue.bpf.c create mode 100644 tools/testing/selftests/sched_ext/dequeue.c
On Mon, Feb 02, 2026 at 05:19:51AM -1000, Tejun Heo wrote: Alright, it seems that the general consensus, based on your feedback and Kuba's, is to treat SCX_DSQ_GLOBAL as a "terminal" DSQ for the purpose of triggering ops.dequeue(). I'll update the logic to do the following: - When a task is dispatched to SCX_DSQ_GLOBAL, the BPF scheduler is considered done with it (similar to local DSQ dispatches). - ops.dequeue() will not be called for SCX_DSQ_GLOBAL dispatches. - This aligns with the fallback behavior where tasks that fail local DSQ insertion end up in the global DSQ as a terminal destination. Thanks, -Andrea
{ "author": "Andrea Righi <arighi@nvidia.com>", "date": "Mon, 2 Feb 2026 16:30:28 +0100", "thread_id": "20260126084258.3798129-1-arighi@nvidia.com.mbox.gz" }
lkml
[PATCHSET v3 sched_ext/for-6.20] sched_ext: Fix ops.dequeue() semantics
The callback ops.dequeue() is provided to let BPF schedulers observe when a task leaves the scheduler, either because it is dispatched or due to a task property change. However, this callback is currently unreliable and not invoked systematically, which can result in missed ops.dequeue() events. In particular, once a task is removed from the scheduler (whether for dispatch or due to a property change) the BPF scheduler loses visibility of the task and the sched_ext core may not always trigger ops.dequeue(). This breaks accurate accounting (i.e., per-DSQ queued runtime sums) and prevents reliable tracking of task lifecycle transitions. This patch set fixes the semantics of ops.dequeue(), ensuring that every ops.enqueue() is balanced by a corresponding ops.dequeue() invocation. In addition, ops.dequeue() is now properly invoked when tasks are removed from the sched_ext class, such as on task property changes. To distinguish between a "regular" dequeue and a property change dequeue a new dequeue flag is introduced: %SCX_DEQ_SCHED_CHANGE. BPF schedulers can use this flag to distinguish between regular dispatch dequeues (%SCX_DEQ_SCHED_CHANGE unset) and property change dequeues (%SCX_DEQ_SCHED_CHANGE set). Together, these changes allow BPF schedulers to reliably track task ownership and maintain accurate accounting. Changes in v3: - Rename SCX_DEQ_ASYNC to SCX_DEQ_SCHED_CHANGE - Handle core-sched dequeues (Kuba) - Link to v2: https://lore.kernel.org/all/20260121123118.964704-1-arighi@nvidia.com/ Changes in v2: - Distinguish between "dispatch" dequeues and "property change" dequeues (flag SCX_DEQ_ASYNC) - Link to v1: https://lore.kernel.org/all/20251219224450.2537941-1-arighi@nvidia.com Andrea Righi (2): sched_ext: Fix ops.dequeue() semantics selftests/sched_ext: Add test to validate ops.dequeue() semantics Documentation/scheduler/sched-ext.rst | 33 ++++ include/linux/sched/ext.h | 11 ++ kernel/sched/ext.c | 89 +++++++++- kernel/sched/ext_internal.h | 7 + tools/sched_ext/include/scx/enum_defs.autogen.h | 2 + tools/sched_ext/include/scx/enums.autogen.bpf.h | 2 + tools/sched_ext/include/scx/enums.autogen.h | 1 + tools/testing/selftests/sched_ext/Makefile | 1 + tools/testing/selftests/sched_ext/dequeue.bpf.c | 209 ++++++++++++++++++++++++ tools/testing/selftests/sched_ext/dequeue.c | 182 +++++++++++++++++++++ 10 files changed, 534 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/sched_ext/dequeue.bpf.c create mode 100644 tools/testing/selftests/sched_ext/dequeue.c
On Sun, Feb 01, 2026 at 07:43:33AM -1000, Tejun Heo wrote: I like "terminal DSQ", if there's no objection I'll update the documentation using this terminology. Thanks, -Andrea
{ "author": "Andrea Righi <arighi@nvidia.com>", "date": "Mon, 2 Feb 2026 16:52:37 +0100", "thread_id": "20260126084258.3798129-1-arighi@nvidia.com.mbox.gz" }
lkml
[PATCHSET v3 sched_ext/for-6.20] sched_ext: Fix ops.dequeue() semantics
The callback ops.dequeue() is provided to let BPF schedulers observe when a task leaves the scheduler, either because it is dispatched or due to a task property change. However, this callback is currently unreliable and not invoked systematically, which can result in missed ops.dequeue() events. In particular, once a task is removed from the scheduler (whether for dispatch or due to a property change) the BPF scheduler loses visibility of the task and the sched_ext core may not always trigger ops.dequeue(). This breaks accurate accounting (i.e., per-DSQ queued runtime sums) and prevents reliable tracking of task lifecycle transitions. This patch set fixes the semantics of ops.dequeue(), ensuring that every ops.enqueue() is balanced by a corresponding ops.dequeue() invocation. In addition, ops.dequeue() is now properly invoked when tasks are removed from the sched_ext class, such as on task property changes. To distinguish between a "regular" dequeue and a property change dequeue a new dequeue flag is introduced: %SCX_DEQ_SCHED_CHANGE. BPF schedulers can use this flag to distinguish between regular dispatch dequeues (%SCX_DEQ_SCHED_CHANGE unset) and property change dequeues (%SCX_DEQ_SCHED_CHANGE set). Together, these changes allow BPF schedulers to reliably track task ownership and maintain accurate accounting. Changes in v3: - Rename SCX_DEQ_ASYNC to SCX_DEQ_SCHED_CHANGE - Handle core-sched dequeues (Kuba) - Link to v2: https://lore.kernel.org/all/20260121123118.964704-1-arighi@nvidia.com/ Changes in v2: - Distinguish between "dispatch" dequeues and "property change" dequeues (flag SCX_DEQ_ASYNC) - Link to v1: https://lore.kernel.org/all/20251219224450.2537941-1-arighi@nvidia.com Andrea Righi (2): sched_ext: Fix ops.dequeue() semantics selftests/sched_ext: Add test to validate ops.dequeue() semantics Documentation/scheduler/sched-ext.rst | 33 ++++ include/linux/sched/ext.h | 11 ++ kernel/sched/ext.c | 89 +++++++++- kernel/sched/ext_internal.h | 7 + tools/sched_ext/include/scx/enum_defs.autogen.h | 2 + tools/sched_ext/include/scx/enums.autogen.bpf.h | 2 + tools/sched_ext/include/scx/enums.autogen.h | 1 + tools/testing/selftests/sched_ext/Makefile | 1 + tools/testing/selftests/sched_ext/dequeue.bpf.c | 209 ++++++++++++++++++++++++ tools/testing/selftests/sched_ext/dequeue.c | 182 +++++++++++++++++++++ 10 files changed, 534 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/sched_ext/dequeue.bpf.c create mode 100644 tools/testing/selftests/sched_ext/dequeue.c
On Mon Feb 2, 2026 at 3:52 PM UTC, Andrea Righi wrote: "Built-in" would also work and avoids introducing new terminology, but it doesn't provide any insight into why these DSQs are special, whereas "terminal" suggests there's some finality to inserting a task there. I'm slightly leaning towards "terminal". Thanks, Kuba
{ "author": "Kuba Piecuch <jpiecuch@google.com>", "date": "Mon, 02 Feb 2026 16:23:19 +0000", "thread_id": "20260126084258.3798129-1-arighi@nvidia.com.mbox.gz" }
lkml
[PATCH 0/2] idpf: skip NULL pointers during deallocation.
In idpf txq and rxq error paths, some pointers are not allocated in the first place. In the corresponding deallocation logic, we should not deallocate them to prevent kernel panics. Li Li (2): idpf: skip deallocating bufq_sets from rx_qgrp if it is NULL. idpf: skip deallocating txq group's txqs if it is NULL. drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.52.0.457.g6b5491de43-goog
In idpf_rxq_group_alloc(), if rx_qgrp->splitq.bufq_sets failed to get allocated: rx_qgrp->splitq.bufq_sets = kcalloc(vport->num_bufqs_per_qgrp, sizeof(struct idpf_bufq_set), GFP_KERNEL); if (!rx_qgrp->splitq.bufq_sets) { err = -ENOMEM; goto err_alloc; } idpf_rxq_group_rel() would attempt to deallocate it in idpf_rxq_sw_queue_rel(), causing a kernel panic: ``` [ 7.967242] early-network-sshd-n-rexd[3148]: knetbase: Info: [ 8.127804] BUG: kernel NULL pointer dereference, address: 00000000000000c0 ... [ 8.129779] RIP: 0010:idpf_rxq_group_rel+0x101/0x170 ... [ 8.133854] Call Trace: [ 8.133980] <TASK> [ 8.134092] idpf_vport_queues_alloc+0x286/0x500 [ 8.134313] idpf_vport_open+0x4d/0x3f0 [ 8.134498] idpf_open+0x71/0xb0 [ 8.134668] __dev_open+0x142/0x260 [ 8.134840] netif_open+0x2f/0xe0 [ 8.135004] dev_open+0x3d/0x70 [ 8.135166] bond_enslave+0x5ed/0xf50 [ 8.135345] ? nla_put_ifalias+0x3d/0x90 [ 8.135533] ? kvfree_call_rcu+0xb5/0x3b0 [ 8.135725] ? kvfree_call_rcu+0xb5/0x3b0 [ 8.135916] do_set_master+0x114/0x160 [ 8.136098] do_setlink+0x412/0xfb0 [ 8.136269] ? security_sock_rcv_skb+0x2a/0x50 [ 8.136509] ? sk_filter_trim_cap+0x7c/0x320 [ 8.136714] ? skb_queue_tail+0x20/0x50 [ 8.136899] ? __nla_validate_parse+0x92/0xe50 [ 8.137112] ? security_capable+0x35/0x60 [ 8.137304] rtnl_newlink+0x95c/0xa00 [ 8.137483] ? __rtnl_unlock+0x37/0x70 [ 8.137664] ? netdev_run_todo+0x63/0x530 [ 8.137855] ? allocate_slab+0x280/0x870 [ 8.138044] ? security_capable+0x35/0x60 [ 8.138235] rtnetlink_rcv_msg+0x2e6/0x340 [ 8.138431] ? __pfx_rtnetlink_rcv_msg+0x10/0x10 [ 8.138650] netlink_rcv_skb+0x16a/0x1a0 [ 8.138840] netlink_unicast+0x20a/0x320 [ 8.139028] netlink_sendmsg+0x304/0x3b0 [ 8.139217] __sock_sendmsg+0x89/0xb0 [ 8.139399] ____sys_sendmsg+0x167/0x1c0 [ 8.139588] ? ____sys_recvmsg+0xed/0x150 [ 8.139780] ___sys_sendmsg+0xdd/0x120 [ 8.139960] ? ___sys_recvmsg+0x124/0x1e0 [ 8.140152] ? rcutree_enqueue+0x1f/0xb0 [ 8.140341] ? rcutree_enqueue+0x1f/0xb0 [ 8.140528] ? call_rcu+0xde/0x2a0 [ 8.140695] ? evict+0x286/0x2d0 [ 8.140856] ? rcutree_enqueue+0x1f/0xb0 [ 8.141043] ? kmem_cache_free+0x2c/0x350 [ 8.141236] __x64_sys_sendmsg+0x72/0xc0 [ 8.141424] do_syscall_64+0x6f/0x890 [ 8.141603] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 8.141841] RIP: 0033:0x7f2799d21bd0 ... [ 8.149905] Kernel panic - not syncing: Fatal exception [ 8.175940] Kernel Offset: 0xf800000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff) [ 8.176425] Rebooting in 10 seconds.. ``` Tested: With this patch, the kernel panic no longer appears. Fixes: 95af467d9a4e ("idpf: configure resources for RX queues") Signed-off-by: Li Li <boolli@google.com> --- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c index e7b131dba200c..b4dab4a8ee11b 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c @@ -1337,6 +1337,8 @@ static void idpf_txq_group_rel(struct idpf_vport *vport) static void idpf_rxq_sw_queue_rel(struct idpf_rxq_group *rx_qgrp) { int i, j; + if (!rx_qgrp->splitq.bufq_sets) + return; for (i = 0; i < rx_qgrp->vport->num_bufqs_per_qgrp; i++) { struct idpf_bufq_set *bufq_set = &rx_qgrp->splitq.bufq_sets[i]; -- 2.52.0.457.g6b5491de43-goog
{ "author": "Li Li <boolli@google.com>", "date": "Mon, 12 Jan 2026 23:09:43 +0000", "thread_id": "20260112230944.3085309-3-boolli@google.com.mbox.gz" }
lkml
[PATCH 0/2] idpf: skip NULL pointers during deallocation.
In idpf txq and rxq error paths, some pointers are not allocated in the first place. In the corresponding deallocation logic, we should not deallocate them to prevent kernel panics. Li Li (2): idpf: skip deallocating bufq_sets from rx_qgrp if it is NULL. idpf: skip deallocating txq group's txqs if it is NULL. drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.52.0.457.g6b5491de43-goog
In idpf_txq_group_alloc(), if any txq group's txqs failed to allocate memory: for (j = 0; j < tx_qgrp->num_txq; j++) { tx_qgrp->txqs[j] = kzalloc(sizeof(*tx_qgrp->txqs[j]), GFP_KERNEL); if (!tx_qgrp->txqs[j]) goto err_alloc; } It would cause a NULL ptr kernel panic in idpf_txq_group_rel(): for (j = 0; j < txq_grp->num_txq; j++) { if (flow_sch_en) { kfree(txq_grp->txqs[j]->refillq); txq_grp->txqs[j]->refillq = NULL; } kfree(txq_grp->txqs[j]); txq_grp->txqs[j] = NULL; } [ 6.532461] BUG: kernel NULL pointer dereference, address: 0000000000000058 ... [ 6.534433] RIP: 0010:idpf_txq_group_rel+0xc9/0x110 ... [ 6.538513] Call Trace: [ 6.538639] <TASK> [ 6.538760] idpf_vport_queues_alloc+0x75/0x550 [ 6.538978] idpf_vport_open+0x4d/0x3f0 [ 6.539164] idpf_open+0x71/0xb0 [ 6.539324] __dev_open+0x142/0x260 [ 6.539506] netif_open+0x2f/0xe0 [ 6.539670] dev_open+0x3d/0x70 [ 6.539827] bond_enslave+0x5ed/0xf50 [ 6.540005] ? rcutree_enqueue+0x1f/0xb0 [ 6.540193] ? call_rcu+0xde/0x2a0 [ 6.540375] ? barn_get_empty_sheaf+0x5c/0x80 [ 6.540594] ? __kfree_rcu_sheaf+0xb6/0x1a0 [ 6.540793] ? nla_put_ifalias+0x3d/0x90 [ 6.540981] ? kvfree_call_rcu+0xb5/0x3b0 [ 6.541173] ? kvfree_call_rcu+0xb5/0x3b0 [ 6.541365] do_set_master+0x114/0x160 [ 6.541547] do_setlink+0x412/0xfb0 [ 6.541717] ? security_sock_rcv_skb+0x2a/0x50 [ 6.541931] ? sk_filter_trim_cap+0x7c/0x320 [ 6.542136] ? skb_queue_tail+0x20/0x50 [ 6.542322] ? __nla_validate_parse+0x92/0xe50 ro[o t t o6 .d5e4f2a5u4l0t]- ? security_capable+0x35/0x60 [ 6.542792] rtnl_newlink+0x95c/0xa00 [ 6.542972] ? __rtnl_unlock+0x37/0x70 [ 6.543152] ? netdev_run_todo+0x63/0x530 [ 6.543343] ? allocate_slab+0x280/0x870 [ 6.543531] ? security_capable+0x35/0x60 [ 6.543722] rtnetlink_rcv_msg+0x2e6/0x340 [ 6.543918] ? __pfx_rtnetlink_rcv_msg+0x10/0x10 [ 6.544138] netlink_rcv_skb+0x16a/0x1a0 [ 6.544328] netlink_unicast+0x20a/0x320 [ 6.544516] netlink_sendmsg+0x304/0x3b0 [ 6.544748] __sock_sendmsg+0x89/0xb0 [ 6.544928] ____sys_sendmsg+0x167/0x1c0 [ 6.545116] ? ____sys_recvmsg+0xed/0x150 [ 6.545308] ___sys_sendmsg+0xdd/0x120 [ 6.545489] ? ___sys_recvmsg+0x124/0x1e0 [ 6.545680] ? rcutree_enqueue+0x1f/0xb0 [ 6.545867] ? rcutree_enqueue+0x1f/0xb0 [ 6.546055] ? call_rcu+0xde/0x2a0 [ 6.546222] ? evict+0x286/0x2d0 [ 6.546389] ? rcutree_enqueue+0x1f/0xb0 [ 6.546577] ? kmem_cache_free+0x2c/0x350 [ 6.546784] __x64_sys_sendmsg+0x72/0xc0 [ 6.546972] do_syscall_64+0x6f/0x890 [ 6.547150] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 6.547393] RIP: 0033:0x7fc1a3347bd0 ... [ 6.551375] RIP: 0010:idpf_txq_group_rel+0xc9/0x110 ... [ 6.578856] Rebooting in 10 seconds.. We should skip deallocating txqs[j] if it is NULL in the first place. Tested: with this patch, the kernel panic no longer appears. Fixes: 1c325aac10a8 ("idpf: configure resources for TX queues") Signed-off-by: Li Li <boolli@google.com> --- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c index b4dab4a8ee11b..25207da6c995d 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c @@ -1311,6 +1311,9 @@ static void idpf_txq_group_rel(struct idpf_vport *vport) struct idpf_txq_group *txq_grp = &vport->txq_grps[i]; for (j = 0; j < txq_grp->num_txq; j++) { + if (!txq_grp->txqs[j]) + continue; + if (flow_sch_en) { kfree(txq_grp->txqs[j]->refillq); txq_grp->txqs[j]->refillq = NULL; -- 2.52.0.457.g6b5491de43-goog
{ "author": "Li Li <boolli@google.com>", "date": "Mon, 12 Jan 2026 23:09:44 +0000", "thread_id": "20260112230944.3085309-3-boolli@google.com.mbox.gz" }
lkml
[PATCH 0/2] idpf: skip NULL pointers during deallocation.
In idpf txq and rxq error paths, some pointers are not allocated in the first place. In the corresponding deallocation logic, we should not deallocate them to prevent kernel panics. Li Li (2): idpf: skip deallocating bufq_sets from rx_qgrp if it is NULL. idpf: skip deallocating txq group's txqs if it is NULL. drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.52.0.457.g6b5491de43-goog
Dear Li, Thank you for your patch. Am 13.01.26 um 00:09 schrieb Li Li via Intel-wired-lan: Is it easy to reproduce? (Just for the future, a blank in the “tag section” is uncommon.) Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Kind regards, Paul
{ "author": "Paul Menzel <pmenzel@molgen.mpg.de>", "date": "Tue, 13 Jan 2026 07:31:26 +0100", "thread_id": "20260112230944.3085309-3-boolli@google.com.mbox.gz" }
lkml
[PATCH 0/2] idpf: skip NULL pointers during deallocation.
In idpf txq and rxq error paths, some pointers are not allocated in the first place. In the corresponding deallocation logic, we should not deallocate them to prevent kernel panics. Li Li (2): idpf: skip deallocating bufq_sets from rx_qgrp if it is NULL. idpf: skip deallocating txq group's txqs if it is NULL. drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.52.0.457.g6b5491de43-goog
Dear Li, Thank you for your patch. Am 13.01.26 um 00:09 schrieb Li Li: The reproduction steps would be nice to have documented. Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Kind regards, Paul
{ "author": "Paul Menzel <pmenzel@molgen.mpg.de>", "date": "Tue, 13 Jan 2026 07:43:07 +0100", "thread_id": "20260112230944.3085309-3-boolli@google.com.mbox.gz" }
lkml
[PATCH 0/2] idpf: skip NULL pointers during deallocation.
In idpf txq and rxq error paths, some pointers are not allocated in the first place. In the corresponding deallocation logic, we should not deallocate them to prevent kernel panics. Li Li (2): idpf: skip deallocating bufq_sets from rx_qgrp if it is NULL. idpf: skip deallocating txq group's txqs if it is NULL. drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.52.0.457.g6b5491de43-goog
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
{ "author": "\"Loktionov, Aleksandr\" <aleksandr.loktionov@intel.com>", "date": "Tue, 13 Jan 2026 07:34:09 +0000", "thread_id": "20260112230944.3085309-3-boolli@google.com.mbox.gz" }
lkml
[PATCH 0/2] idpf: skip NULL pointers during deallocation.
In idpf txq and rxq error paths, some pointers are not allocated in the first place. In the corresponding deallocation logic, we should not deallocate them to prevent kernel panics. Li Li (2): idpf: skip deallocating bufq_sets from rx_qgrp if it is NULL. idpf: skip deallocating txq group's txqs if it is NULL. drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.52.0.457.g6b5491de43-goog
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
{ "author": "\"Loktionov, Aleksandr\" <aleksandr.loktionov@intel.com>", "date": "Tue, 13 Jan 2026 07:34:57 +0000", "thread_id": "20260112230944.3085309-3-boolli@google.com.mbox.gz" }
lkml
[PATCH 0/2] idpf: skip NULL pointers during deallocation.
In idpf txq and rxq error paths, some pointers are not allocated in the first place. In the corresponding deallocation logic, we should not deallocate them to prevent kernel panics. Li Li (2): idpf: skip deallocating bufq_sets from rx_qgrp if it is NULL. idpf: skip deallocating txq group's txqs if it is NULL. drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.52.0.457.g6b5491de43-goog
On Mon, Jan 12, 2026 at 10:31 PM Paul Menzel <pmenzel@molgen.mpg.de> wrote: In our internal environments, we have the idpf driver running on machines with small RAM, and it's not uncommon for them to run out of memory and encounter kalloc issues, especially in kcallocs where we allocate higher order memory. To reliably reproduce the issue in my own testing, I simply set rx_qgrp->splitq.bufq_sets to NULL: rx_qgrp->splitq.bufq_sets = kcalloc(vport->num_bufqs_per_qgrp, sizeof(struct idpf_bufq_set), GFP_KERNEL); rx_qgrp->splitq.bufq_sets = NULL; If the error path works correctly, we should not see a kernel panic. Thank you for the info!
{ "author": "Li Li <boolli@google.com>", "date": "Thu, 15 Jan 2026 12:07:12 -0800", "thread_id": "20260112230944.3085309-3-boolli@google.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Add verify-only public key crypto support for ML-DSA so that the X.509/PKCS#7 signature verification code, as used by module signing, amongst other things, can make use of it through the common crypto_sig API. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> cc: Eric Biggers <ebiggers@kernel.org> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/Kconfig | 9 +++ crypto/Makefile | 2 + crypto/mldsa.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 crypto/mldsa.c diff --git a/crypto/Kconfig b/crypto/Kconfig index 12a87f7cf150..a210575fa5e0 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -344,6 +344,15 @@ config CRYPTO_ECRDSA One of the Russian cryptographic standard algorithms (called GOST algorithms). Only signature verification is implemented. +config CRYPTO_MLDSA + tristate "ML-DSA (Module-Lattice-Based Digital Signature Algorithm)" + select CRYPTO_SIG + select CRYPTO_LIB_MLDSA + help + ML-DSA (Module-Lattice-Based Digital Signature Algorithm) (FIPS-204). + + Only signature verification is implemented. + endmenu menu "Block ciphers" diff --git a/crypto/Makefile b/crypto/Makefile index 23d3db7be425..267d5403045b 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -60,6 +60,8 @@ ecdsa_generic-y += ecdsa-p1363.o ecdsa_generic-y += ecdsasignature.asn1.o obj-$(CONFIG_CRYPTO_ECDSA) += ecdsa_generic.o +obj-$(CONFIG_CRYPTO_MLDSA) += mldsa.o + crypto_acompress-y := acompress.o crypto_acompress-y += scompress.o obj-$(CONFIG_CRYPTO_ACOMP2) += crypto_acompress.o diff --git a/crypto/mldsa.c b/crypto/mldsa.c new file mode 100644 index 000000000000..d8de082cc67a --- /dev/null +++ b/crypto/mldsa.c @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * crypto_sig wrapper around ML-DSA library. + */ +#include <linux/init.h> +#include <linux/module.h> +#include <crypto/internal/sig.h> +#include <crypto/mldsa.h> + +struct crypto_mldsa_ctx { + u8 pk[MAX(MAX(MLDSA44_PUBLIC_KEY_SIZE, + MLDSA65_PUBLIC_KEY_SIZE), + MLDSA87_PUBLIC_KEY_SIZE)]; + unsigned int pk_len; + enum mldsa_alg strength; + bool key_set; +}; + +static int crypto_mldsa_sign(struct crypto_sig *tfm, + const void *msg, unsigned int msg_len, + void *sig, unsigned int sig_len) +{ + return -EOPNOTSUPP; +} + +static int crypto_mldsa_verify(struct crypto_sig *tfm, + const void *sig, unsigned int sig_len, + const void *msg, unsigned int msg_len) +{ + const struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + if (unlikely(!ctx->key_set)) + return -EINVAL; + + return mldsa_verify(ctx->strength, sig, sig_len, msg, msg_len, + ctx->pk, ctx->pk_len); +} + +static unsigned int crypto_mldsa_key_size(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + switch (ctx->strength) { + case MLDSA44: + return MLDSA44_PUBLIC_KEY_SIZE; + case MLDSA65: + return MLDSA65_PUBLIC_KEY_SIZE; + case MLDSA87: + return MLDSA87_PUBLIC_KEY_SIZE; + default: + WARN_ON_ONCE(1); + return 0; + } +} + +static int crypto_mldsa_set_pub_key(struct crypto_sig *tfm, + const void *key, unsigned int keylen) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + unsigned int expected_len = crypto_mldsa_key_size(tfm); + + if (keylen != expected_len) + return -EINVAL; + + ctx->pk_len = keylen; + memcpy(ctx->pk, key, keylen); + ctx->key_set = true; + return 0; +} + +static int crypto_mldsa_set_priv_key(struct crypto_sig *tfm, + const void *key, unsigned int keylen) +{ + return -EOPNOTSUPP; +} + +static unsigned int crypto_mldsa_max_size(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + switch (ctx->strength) { + case MLDSA44: + return MLDSA44_SIGNATURE_SIZE; + case MLDSA65: + return MLDSA65_SIGNATURE_SIZE; + case MLDSA87: + return MLDSA87_SIGNATURE_SIZE; + default: + WARN_ON_ONCE(1); + return 0; + } +} + +static int crypto_mldsa44_alg_init(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + ctx->strength = MLDSA44; + ctx->key_set = false; + return 0; +} + +static int crypto_mldsa65_alg_init(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + ctx->strength = MLDSA65; + ctx->key_set = false; + return 0; +} + +static int crypto_mldsa87_alg_init(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + ctx->strength = MLDSA87; + ctx->key_set = false; + return 0; +} + +static void crypto_mldsa_alg_exit(struct crypto_sig *tfm) +{ +} + +static struct sig_alg crypto_mldsa_algs[] = { + { + .sign = crypto_mldsa_sign, + .verify = crypto_mldsa_verify, + .set_pub_key = crypto_mldsa_set_pub_key, + .set_priv_key = crypto_mldsa_set_priv_key, + .key_size = crypto_mldsa_key_size, + .max_size = crypto_mldsa_max_size, + .init = crypto_mldsa44_alg_init, + .exit = crypto_mldsa_alg_exit, + .base.cra_name = "mldsa44", + .base.cra_driver_name = "mldsa44-lib", + .base.cra_ctxsize = sizeof(struct crypto_mldsa_ctx), + .base.cra_module = THIS_MODULE, + .base.cra_priority = 5000, + }, { + .sign = crypto_mldsa_sign, + .verify = crypto_mldsa_verify, + .set_pub_key = crypto_mldsa_set_pub_key, + .set_priv_key = crypto_mldsa_set_priv_key, + .key_size = crypto_mldsa_key_size, + .max_size = crypto_mldsa_max_size, + .init = crypto_mldsa65_alg_init, + .exit = crypto_mldsa_alg_exit, + .base.cra_name = "mldsa65", + .base.cra_driver_name = "mldsa65-lib", + .base.cra_ctxsize = sizeof(struct crypto_mldsa_ctx), + .base.cra_module = THIS_MODULE, + .base.cra_priority = 5000, + }, { + .sign = crypto_mldsa_sign, + .verify = crypto_mldsa_verify, + .set_pub_key = crypto_mldsa_set_pub_key, + .set_priv_key = crypto_mldsa_set_priv_key, + .key_size = crypto_mldsa_key_size, + .max_size = crypto_mldsa_max_size, + .init = crypto_mldsa87_alg_init, + .exit = crypto_mldsa_alg_exit, + .base.cra_name = "mldsa87", + .base.cra_driver_name = "mldsa87-lib", + .base.cra_ctxsize = sizeof(struct crypto_mldsa_ctx), + .base.cra_module = THIS_MODULE, + .base.cra_priority = 5000, + }, +}; + +static int __init mldsa_init(void) +{ + int ret, i; + + for (i = 0; i < ARRAY_SIZE(crypto_mldsa_algs); i++) { + ret = crypto_register_sig(&crypto_mldsa_algs[i]); + if (ret < 0) + goto error; + } + return 0; + +error: + pr_err("Failed to register (%d)\n", ret); + for (i--; i >= 0; i--) + crypto_unregister_sig(&crypto_mldsa_algs[i]); + return ret; +} +module_init(mldsa_init); + +static void mldsa_exit(void) +{ + for (int i = 0; i < ARRAY_SIZE(crypto_mldsa_algs); i++) + crypto_unregister_sig(&crypto_mldsa_algs[i]); +} +module_exit(mldsa_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Crypto API support for ML-DSA signature verification"); +MODULE_ALIAS_CRYPTO("mldsa44"); +MODULE_ALIAS_CRYPTO("mldsa65"); +MODULE_ALIAS_CRYPTO("mldsa87");
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:06 +0000", "thread_id": "20260202170216.2467036-3-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Calculate the SHA256 hash for blacklisting purposes independently of the signature hash (which may be something other than SHA256). This is necessary because when ML-DSA is used, no digest is calculated. Note that this represents a change of behaviour in that the hash used for the blacklist check would previously have been whatever digest was used for, say, RSA-based signatures. It may be that this is inadvisable. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/x509_parser.h | 2 ++ crypto/asymmetric_keys/x509_public_key.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crypto/asymmetric_keys/x509_parser.h b/crypto/asymmetric_keys/x509_parser.h index 0688c222806b..b7aeebdddb36 100644 --- a/crypto/asymmetric_keys/x509_parser.h +++ b/crypto/asymmetric_keys/x509_parser.h @@ -9,12 +9,14 @@ #include <linux/time.h> #include <crypto/public_key.h> #include <keys/asymmetric-type.h> +#include <crypto/sha2.h> struct x509_certificate { struct x509_certificate *next; struct x509_certificate *signer; /* Certificate that signed this one */ struct public_key *pub; /* Public key details */ struct public_key_signature *sig; /* Signature parameters */ + u8 sha256[SHA256_DIGEST_SIZE]; /* Hash for blacklist purposes */ char *issuer; /* Name of certificate issuer */ char *subject; /* Name of certificate subject */ struct asymmetric_key_id *id; /* Issuer + Serial number */ diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c index 12e3341e806b..79cc7b7a0630 100644 --- a/crypto/asymmetric_keys/x509_public_key.c +++ b/crypto/asymmetric_keys/x509_public_key.c @@ -31,6 +31,19 @@ int x509_get_sig_params(struct x509_certificate *cert) pr_devel("==>%s()\n", __func__); + /* Calculate a SHA256 hash of the TBS and check it against the + * blacklist. + */ + sha256(cert->tbs, cert->tbs_size, cert->sha256); + ret = is_hash_blacklisted(cert->sha256, sizeof(cert->sha256), + BLACKLIST_HASH_X509_TBS); + if (ret == -EKEYREJECTED) { + pr_err("Cert %*phN is blacklisted\n", + (int)sizeof(cert->sha256), cert->sha256); + cert->blacklisted = true; + ret = 0; + } + sig->s = kmemdup(cert->raw_sig, cert->raw_sig_size, GFP_KERNEL); if (!sig->s) return -ENOMEM; @@ -69,15 +82,6 @@ int x509_get_sig_params(struct x509_certificate *cert) if (ret < 0) goto error_2; - ret = is_hash_blacklisted(sig->digest, sig->digest_size, - BLACKLIST_HASH_X509_TBS); - if (ret == -EKEYREJECTED) { - pr_err("Cert %*phN is blacklisted\n", - sig->digest_size, sig->digest); - cert->blacklisted = true; - ret = 0; - } - error_2: kfree(desc); error:
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:07 +0000", "thread_id": "20260202170216.2467036-3-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Rename ->digest and ->digest_len to ->m and ->m_size to represent the input to the signature verification algorithm, reflecting that ->digest may no longer actually *be* a digest. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/asymmetric_type.c | 4 ++-- crypto/asymmetric_keys/pkcs7_verify.c | 28 ++++++++++++------------ crypto/asymmetric_keys/public_key.c | 3 +-- crypto/asymmetric_keys/signature.c | 2 +- crypto/asymmetric_keys/x509_public_key.c | 10 ++++----- include/crypto/public_key.h | 4 ++-- security/integrity/digsig_asymmetric.c | 4 ++-- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c index 348966ea2175..2326743310b1 100644 --- a/crypto/asymmetric_keys/asymmetric_type.c +++ b/crypto/asymmetric_keys/asymmetric_type.c @@ -593,10 +593,10 @@ static int asymmetric_key_verify_signature(struct kernel_pkey_params *params, { struct public_key_signature sig = { .s_size = params->in2_len, - .digest_size = params->in_len, + .m_size = params->in_len, .encoding = params->encoding, .hash_algo = params->hash_algo, - .digest = (void *)in, + .m = (void *)in, .s = (void *)in2, }; diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c index 6d6475e3a9bf..aa085ec6fb1c 100644 --- a/crypto/asymmetric_keys/pkcs7_verify.c +++ b/crypto/asymmetric_keys/pkcs7_verify.c @@ -31,7 +31,7 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, kenter(",%u,%s", sinfo->index, sinfo->sig->hash_algo); /* The digest was calculated already. */ - if (sig->digest) + if (sig->m) return 0; if (!sinfo->sig->hash_algo) @@ -45,11 +45,11 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, return (PTR_ERR(tfm) == -ENOENT) ? -ENOPKG : PTR_ERR(tfm); desc_size = crypto_shash_descsize(tfm) + sizeof(*desc); - sig->digest_size = crypto_shash_digestsize(tfm); + sig->m_size = crypto_shash_digestsize(tfm); ret = -ENOMEM; - sig->digest = kmalloc(sig->digest_size, GFP_KERNEL); - if (!sig->digest) + sig->m = kmalloc(sig->m_size, GFP_KERNEL); + if (!sig->m) goto error_no_desc; desc = kzalloc(desc_size, GFP_KERNEL); @@ -59,11 +59,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, desc->tfm = tfm; /* Digest the message [RFC2315 9.3] */ - ret = crypto_shash_digest(desc, pkcs7->data, pkcs7->data_len, - sig->digest); + ret = crypto_shash_digest(desc, pkcs7->data, pkcs7->data_len, sig->m); if (ret < 0) goto error; - pr_devel("MsgDigest = [%*ph]\n", 8, sig->digest); + pr_devel("MsgDigest = [%*ph]\n", 8, sig->m); /* However, if there are authenticated attributes, there must be a * message digest attribute amongst them which corresponds to the @@ -78,14 +77,14 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, goto error; } - if (sinfo->msgdigest_len != sig->digest_size) { + if (sinfo->msgdigest_len != sig->m_size) { pr_warn("Sig %u: Invalid digest size (%u)\n", sinfo->index, sinfo->msgdigest_len); ret = -EBADMSG; goto error; } - if (memcmp(sig->digest, sinfo->msgdigest, + if (memcmp(sig->m, sinfo->msgdigest, sinfo->msgdigest_len) != 0) { pr_warn("Sig %u: Message digest doesn't match\n", sinfo->index); @@ -98,7 +97,8 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, * convert the attributes from a CONT.0 into a SET before we * hash it. */ - memset(sig->digest, 0, sig->digest_size); + memset(sig->m, 0, sig->m_size); + ret = crypto_shash_init(desc); if (ret < 0) @@ -108,10 +108,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, if (ret < 0) goto error; ret = crypto_shash_finup(desc, sinfo->authattrs, - sinfo->authattrs_len, sig->digest); + sinfo->authattrs_len, sig->m); if (ret < 0) goto error; - pr_devel("AADigest = [%*ph]\n", 8, sig->digest); + pr_devel("AADigest = [%*ph]\n", 8, sig->m); } error: @@ -138,8 +138,8 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len, if (ret) return ret; - *buf = sinfo->sig->digest; - *len = sinfo->sig->digest_size; + *buf = sinfo->sig->m; + *len = sinfo->sig->m_size; i = match_string(hash_algo_name, HASH_ALGO__LAST, sinfo->sig->hash_algo); diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c index e5b177c8e842..a46356e0c08b 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c @@ -425,8 +425,7 @@ int public_key_verify_signature(const struct public_key *pkey, if (ret) goto error_free_key; - ret = crypto_sig_verify(tfm, sig->s, sig->s_size, - sig->digest, sig->digest_size); + ret = crypto_sig_verify(tfm, sig->s, sig->s_size, sig->m, sig->m_size); error_free_key: kfree_sensitive(key); diff --git a/crypto/asymmetric_keys/signature.c b/crypto/asymmetric_keys/signature.c index 041d04b5c953..f4ec126121b3 100644 --- a/crypto/asymmetric_keys/signature.c +++ b/crypto/asymmetric_keys/signature.c @@ -28,7 +28,7 @@ void public_key_signature_free(struct public_key_signature *sig) for (i = 0; i < ARRAY_SIZE(sig->auth_ids); i++) kfree(sig->auth_ids[i]); kfree(sig->s); - kfree(sig->digest); + kfree(sig->m); kfree(sig); } } diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c index 79cc7b7a0630..3854f7ae4ed0 100644 --- a/crypto/asymmetric_keys/x509_public_key.c +++ b/crypto/asymmetric_keys/x509_public_key.c @@ -63,11 +63,11 @@ int x509_get_sig_params(struct x509_certificate *cert) } desc_size = crypto_shash_descsize(tfm) + sizeof(*desc); - sig->digest_size = crypto_shash_digestsize(tfm); + sig->m_size = crypto_shash_digestsize(tfm); ret = -ENOMEM; - sig->digest = kmalloc(sig->digest_size, GFP_KERNEL); - if (!sig->digest) + sig->m = kmalloc(sig->m_size, GFP_KERNEL); + if (!sig->m) goto error; desc = kzalloc(desc_size, GFP_KERNEL); @@ -76,9 +76,7 @@ int x509_get_sig_params(struct x509_certificate *cert) desc->tfm = tfm; - ret = crypto_shash_digest(desc, cert->tbs, cert->tbs_size, - sig->digest); - + ret = crypto_shash_digest(desc, cert->tbs, cert->tbs_size, sig->m); if (ret < 0) goto error_2; diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h index 81098e00c08f..bd38ba4d217d 100644 --- a/include/crypto/public_key.h +++ b/include/crypto/public_key.h @@ -43,9 +43,9 @@ extern void public_key_free(struct public_key *key); struct public_key_signature { struct asymmetric_key_id *auth_ids[3]; u8 *s; /* Signature */ - u8 *digest; + u8 *m; /* Message data to pass to verifier */ u32 s_size; /* Number of bytes in signature */ - u32 digest_size; /* Number of bytes in digest */ + u32 m_size; /* Number of bytes in ->m */ const char *pkey_algo; const char *hash_algo; const char *encoding; diff --git a/security/integrity/digsig_asymmetric.c b/security/integrity/digsig_asymmetric.c index 457c0a396caf..87be85f477d1 100644 --- a/security/integrity/digsig_asymmetric.c +++ b/security/integrity/digsig_asymmetric.c @@ -121,8 +121,8 @@ int asymmetric_verify(struct key *keyring, const char *sig, goto out; } - pks.digest = (u8 *)data; - pks.digest_size = datalen; + pks.m = (u8 *)data; + pks.m_size = datalen; pks.s = hdr->sig; pks.s_size = siglen; ret = verify_signature(key, &pks);
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:08 +0000", "thread_id": "20260202170216.2467036-3-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Allow the data to be verified in a PKCS#7 or CMS message to be passed directly to an asymmetric cipher algorithm (e.g. ML-DSA) if it wants to do whatever passes for hashing/digestion itself. The normal digestion of the data is then skipped as that would be ignored unless another signed info in the message has some other algorithm that needs it. The 'data to be verified' may be the content of the PKCS#7 message or it will be the authenticatedAttributes (signedAttrs if CMS), modified, if those are present. This is done by: (1) Make ->m and ->m_size point to the data to be verified rather than making public_key_verify_signature() access the data directly. This is so that keyctl(KEYCTL_PKEY_VERIFY) will still work. (2) Add a flag, ->algo_takes_data, to indicate that the verification algorithm wants to access the data to be verified directly rather than having it digested first. (3) If the PKCS#7 message has authenticatedAttributes (or CMS signedAttrs), then the digest contained therein will be validated as now, and the modified attrs blob will either be digested or assigned to ->m as appropriate. (4) If present, always copy and modify the authenticatedAttributes (or signedAttrs) then digest that in one go rather than calling the shash update twice (once for the tag and once for the rest). (5) For ML-DSA, point ->m to the TBSCertificate instead of digesting it and using the digest. Note that whilst ML-DSA does allow for an "external mu", CMS doesn't yet have that standardised. Signed-off-by: David Howells <dhowells@redhat.com> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/pkcs7_parser.c | 4 +- crypto/asymmetric_keys/pkcs7_verify.c | 52 ++++++++++++++++-------- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_public_key.c | 10 +++++ include/crypto/public_key.h | 2 + 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c index 423d13c47545..3cdbab3b9f50 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.c +++ b/crypto/asymmetric_keys/pkcs7_parser.c @@ -599,8 +599,8 @@ int pkcs7_sig_note_set_of_authattrs(void *context, size_t hdrlen, } /* We need to switch the 'CONT 0' to a 'SET OF' when we digest */ - sinfo->authattrs = value - (hdrlen - 1); - sinfo->authattrs_len = vlen + (hdrlen - 1); + sinfo->authattrs = value - hdrlen; + sinfo->authattrs_len = vlen + hdrlen; return 0; } diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c index aa085ec6fb1c..06abb9838f95 100644 --- a/crypto/asymmetric_keys/pkcs7_verify.c +++ b/crypto/asymmetric_keys/pkcs7_verify.c @@ -30,6 +30,16 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, kenter(",%u,%s", sinfo->index, sinfo->sig->hash_algo); + if (!sinfo->authattrs && sig->algo_takes_data) { + /* There's no intermediate digest and the signature algo + * doesn't want the data prehashing. + */ + sig->m = (void *)pkcs7->data; + sig->m_size = pkcs7->data_len; + sig->m_free = false; + return 0; + } + /* The digest was calculated already. */ if (sig->m) return 0; @@ -48,9 +58,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, sig->m_size = crypto_shash_digestsize(tfm); ret = -ENOMEM; - sig->m = kmalloc(sig->m_size, GFP_KERNEL); + sig->m = kmalloc(umax(sinfo->authattrs_len, sig->m_size), GFP_KERNEL); if (!sig->m) goto error_no_desc; + sig->m_free = true; desc = kzalloc(desc_size, GFP_KERNEL); if (!desc) @@ -69,8 +80,6 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, * digest we just calculated. */ if (sinfo->authattrs) { - u8 tag; - if (!sinfo->msgdigest) { pr_warn("Sig %u: No messageDigest\n", sinfo->index); ret = -EKEYREJECTED; @@ -96,21 +105,25 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, * as the contents of the digest instead. Note that we need to * convert the attributes from a CONT.0 into a SET before we * hash it. + * + * However, for certain algorithms, such as ML-DSA, the digest + * is integrated into the signing algorithm. In such a case, + * we copy the authattrs, modifying the tag type, and set that + * as the digest. */ - memset(sig->m, 0, sig->m_size); - - - ret = crypto_shash_init(desc); - if (ret < 0) - goto error; - tag = ASN1_CONS_BIT | ASN1_SET; - ret = crypto_shash_update(desc, &tag, 1); - if (ret < 0) - goto error; - ret = crypto_shash_finup(desc, sinfo->authattrs, - sinfo->authattrs_len, sig->m); - if (ret < 0) - goto error; + memcpy(sig->m, sinfo->authattrs, sinfo->authattrs_len); + sig->m[0] = ASN1_CONS_BIT | ASN1_SET; + + if (sig->algo_takes_data) { + sig->m_size = sinfo->authattrs_len; + ret = 0; + } else { + ret = crypto_shash_digest(desc, sig->m, + sinfo->authattrs_len, + sig->m); + if (ret < 0) + goto error; + } pr_devel("AADigest = [%*ph]\n", 8, sig->m); } @@ -137,6 +150,11 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len, ret = pkcs7_digest(pkcs7, sinfo); if (ret) return ret; + if (!sinfo->sig->m_free) { + pr_notice_once("%s: No digest available\n", __func__); + return -EINVAL; /* TODO: MLDSA doesn't necessarily calculate an + * intermediate digest. */ + } *buf = sinfo->sig->m; *len = sinfo->sig->m_size; diff --git a/crypto/asymmetric_keys/signature.c b/crypto/asymmetric_keys/signature.c index f4ec126121b3..a5ac7a53b670 100644 --- a/crypto/asymmetric_keys/signature.c +++ b/crypto/asymmetric_keys/signature.c @@ -28,7 +28,8 @@ void public_key_signature_free(struct public_key_signature *sig) for (i = 0; i < ARRAY_SIZE(sig->auth_ids); i++) kfree(sig->auth_ids[i]); kfree(sig->s); - kfree(sig->m); + if (sig->m_free) + kfree(sig->m); kfree(sig); } } diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c index 3854f7ae4ed0..27b4fea37845 100644 --- a/crypto/asymmetric_keys/x509_public_key.c +++ b/crypto/asymmetric_keys/x509_public_key.c @@ -50,6 +50,14 @@ int x509_get_sig_params(struct x509_certificate *cert) sig->s_size = cert->raw_sig_size; + if (sig->algo_takes_data) { + /* The signature algorithm does whatever passes for hashing. */ + sig->m = (u8 *)cert->tbs; + sig->m_size = cert->tbs_size; + sig->m_free = false; + goto out; + } + /* Allocate the hashing algorithm we're going to need and find out how * big the hash operational data will be. */ @@ -69,6 +77,7 @@ int x509_get_sig_params(struct x509_certificate *cert) sig->m = kmalloc(sig->m_size, GFP_KERNEL); if (!sig->m) goto error; + sig->m_free = true; desc = kzalloc(desc_size, GFP_KERNEL); if (!desc) @@ -84,6 +93,7 @@ int x509_get_sig_params(struct x509_certificate *cert) kfree(desc); error: crypto_free_shash(tfm); +out: pr_devel("<==%s() = %d\n", __func__, ret); return ret; } diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h index bd38ba4d217d..4c5199b20338 100644 --- a/include/crypto/public_key.h +++ b/include/crypto/public_key.h @@ -46,6 +46,8 @@ struct public_key_signature { u8 *m; /* Message data to pass to verifier */ u32 s_size; /* Number of bytes in signature */ u32 m_size; /* Number of bytes in ->m */ + bool m_free; /* T if ->m needs freeing */ + bool algo_takes_data; /* T if public key algo operates on data, not a hash */ const char *pkey_algo; const char *hash_algo; const char *encoding;
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:09 +0000", "thread_id": "20260202170216.2467036-3-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Add support for ML-DSA keys and signatures to the CMS/PKCS#7 and X.509 implementations. ML-DSA-44, -65 and -87 are all supported. For X.509 certificates, the TBSCertificate is required to be signed directly; for CMS, direct signing of the data is preferred, though use of SHA512 (and only that) as an intermediate hash of the content is permitted with signedAttrs. Signed-off-by: David Howells <dhowells@redhat.com> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/pkcs7_parser.c | 24 +++++++++++++++++++- crypto/asymmetric_keys/public_key.c | 10 +++++++++ crypto/asymmetric_keys/x509_cert_parser.c | 27 ++++++++++++++++++++++- include/linux/oid_registry.h | 5 +++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c index 3cdbab3b9f50..594a8f1d9dfb 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.c +++ b/crypto/asymmetric_keys/pkcs7_parser.c @@ -95,11 +95,18 @@ static int pkcs7_check_authattrs(struct pkcs7_message *msg) if (sinfo->authattrs) { want = true; msg->have_authattrs = true; + } else if (sinfo->sig->algo_takes_data) { + sinfo->sig->hash_algo = "none"; } - for (sinfo = sinfo->next; sinfo; sinfo = sinfo->next) + for (sinfo = sinfo->next; sinfo; sinfo = sinfo->next) { if (!!sinfo->authattrs != want) goto inconsistent; + + if (!sinfo->authattrs && + sinfo->sig->algo_takes_data) + sinfo->sig->hash_algo = "none"; + } return 0; inconsistent: @@ -297,6 +304,21 @@ int pkcs7_sig_note_pkey_algo(void *context, size_t hdrlen, ctx->sinfo->sig->pkey_algo = "ecrdsa"; ctx->sinfo->sig->encoding = "raw"; break; + case OID_id_ml_dsa_44: + ctx->sinfo->sig->pkey_algo = "mldsa44"; + ctx->sinfo->sig->encoding = "raw"; + ctx->sinfo->sig->algo_takes_data = true; + break; + case OID_id_ml_dsa_65: + ctx->sinfo->sig->pkey_algo = "mldsa65"; + ctx->sinfo->sig->encoding = "raw"; + ctx->sinfo->sig->algo_takes_data = true; + break; + case OID_id_ml_dsa_87: + ctx->sinfo->sig->pkey_algo = "mldsa87"; + ctx->sinfo->sig->encoding = "raw"; + ctx->sinfo->sig->algo_takes_data = true; + break; default: printk("Unsupported pkey algo: %u\n", ctx->last_oid); return -ENOPKG; diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c index a46356e0c08b..09a0b83d5d77 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c @@ -142,6 +142,16 @@ software_key_determine_akcipher(const struct public_key *pkey, if (strcmp(hash_algo, "streebog256") != 0 && strcmp(hash_algo, "streebog512") != 0) return -EINVAL; + } else if (strcmp(pkey->pkey_algo, "mldsa44") == 0 || + strcmp(pkey->pkey_algo, "mldsa65") == 0 || + strcmp(pkey->pkey_algo, "mldsa87") == 0) { + if (strcmp(encoding, "raw") != 0) + return -EINVAL; + if (!hash_algo) + return -EINVAL; + if (strcmp(hash_algo, "none") != 0 && + strcmp(hash_algo, "sha512") != 0) + return -EINVAL; } else { /* Unknown public key algorithm */ return -ENOPKG; diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c index b37cae914987..2fe094f5caf3 100644 --- a/crypto/asymmetric_keys/x509_cert_parser.c +++ b/crypto/asymmetric_keys/x509_cert_parser.c @@ -257,6 +257,15 @@ int x509_note_sig_algo(void *context, size_t hdrlen, unsigned char tag, case OID_gost2012Signature512: ctx->cert->sig->hash_algo = "streebog512"; goto ecrdsa; + case OID_id_ml_dsa_44: + ctx->cert->sig->pkey_algo = "mldsa44"; + goto ml_dsa; + case OID_id_ml_dsa_65: + ctx->cert->sig->pkey_algo = "mldsa65"; + goto ml_dsa; + case OID_id_ml_dsa_87: + ctx->cert->sig->pkey_algo = "mldsa87"; + goto ml_dsa; } rsa_pkcs1: @@ -274,6 +283,12 @@ int x509_note_sig_algo(void *context, size_t hdrlen, unsigned char tag, ctx->cert->sig->encoding = "x962"; ctx->sig_algo = ctx->last_oid; return 0; +ml_dsa: + ctx->cert->sig->algo_takes_data = true; + ctx->cert->sig->hash_algo = "none"; + ctx->cert->sig->encoding = "raw"; + ctx->sig_algo = ctx->last_oid; + return 0; } /* @@ -300,7 +315,8 @@ int x509_note_signature(void *context, size_t hdrlen, if (strcmp(ctx->cert->sig->pkey_algo, "rsa") == 0 || strcmp(ctx->cert->sig->pkey_algo, "ecrdsa") == 0 || - strcmp(ctx->cert->sig->pkey_algo, "ecdsa") == 0) { + strcmp(ctx->cert->sig->pkey_algo, "ecdsa") == 0 || + strncmp(ctx->cert->sig->pkey_algo, "mldsa", 5) == 0) { /* Discard the BIT STRING metadata */ if (vlen < 1 || *(const u8 *)value != 0) return -EBADMSG; @@ -524,6 +540,15 @@ int x509_extract_key_data(void *context, size_t hdrlen, return -ENOPKG; } break; + case OID_id_ml_dsa_44: + ctx->cert->pub->pkey_algo = "mldsa44"; + break; + case OID_id_ml_dsa_65: + ctx->cert->pub->pkey_algo = "mldsa65"; + break; + case OID_id_ml_dsa_87: + ctx->cert->pub->pkey_algo = "mldsa87"; + break; default: return -ENOPKG; } diff --git a/include/linux/oid_registry.h b/include/linux/oid_registry.h index 6de479ebbe5d..ebce402854de 100644 --- a/include/linux/oid_registry.h +++ b/include/linux/oid_registry.h @@ -145,6 +145,11 @@ enum OID { OID_id_rsassa_pkcs1_v1_5_with_sha3_384, /* 2.16.840.1.101.3.4.3.15 */ OID_id_rsassa_pkcs1_v1_5_with_sha3_512, /* 2.16.840.1.101.3.4.3.16 */ + /* NIST FIPS-204 ML-DSA */ + OID_id_ml_dsa_44, /* 2.16.840.1.101.3.4.3.17 */ + OID_id_ml_dsa_65, /* 2.16.840.1.101.3.4.3.18 */ + OID_id_ml_dsa_87, /* 2.16.840.1.101.3.4.3.19 */ + OID__NR };
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:10 +0000", "thread_id": "20260202170216.2467036-3-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Allow ML-DSA module signing to be enabled. Note that OpenSSL's CMS_*() function suite does not, as of OpenSSL-3.6, support the use of CMS_NOATTR with ML-DSA, so the prohibition against using signedAttrs with module signing has to be removed. The selected digest then applies only to the algorithm used to calculate the digest stored in the messageDigest attribute. The OpenSSL development branch has patches applied that fix this[1], but it appears that that will only be available in OpenSSL-4. [1] https://github.com/openssl/openssl/pull/28923 sign-file won't set CMS_NOATTR if openssl is earlier than v4, resulting in the use of signed attributes. The ML-DSA algorithm takes the raw data to be signed without regard to what digest algorithm is specified in the CMS message. The CMS specified digest algorithm is ignored unless signedAttrs are used; in such a case, only SHA512 is permitted. Signed-off-by: David Howells <dhowells@redhat.com> cc: Jarkko Sakkinen <jarkko@kernel.org> cc: Eric Biggers <ebiggers@kernel.org> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- Documentation/admin-guide/module-signing.rst | 16 ++++---- certs/Kconfig | 40 ++++++++++++++++++++ certs/Makefile | 3 ++ scripts/sign-file.c | 39 ++++++++++++++----- 4 files changed, 82 insertions(+), 16 deletions(-) diff --git a/Documentation/admin-guide/module-signing.rst b/Documentation/admin-guide/module-signing.rst index a8667a777490..7f2f127dc76f 100644 --- a/Documentation/admin-guide/module-signing.rst +++ b/Documentation/admin-guide/module-signing.rst @@ -28,10 +28,12 @@ trusted userspace bits. This facility uses X.509 ITU-T standard certificates to encode the public keys involved. The signatures are not themselves encoded in any industrial standard -type. The built-in facility currently only supports the RSA & NIST P-384 ECDSA -public key signing standard (though it is pluggable and permits others to be -used). The possible hash algorithms that can be used are SHA-2 and SHA-3 of -sizes 256, 384, and 512 (the algorithm is selected by data in the signature). +type. The built-in facility currently only supports the RSA, NIST P-384 ECDSA +and NIST FIPS-204 ML-DSA public key signing standards (though it is pluggable +and permits others to be used). For RSA and ECDSA, the possible hash +algorithms that can be used are SHA-2 and SHA-3 of sizes 256, 384, and 512 (the +algorithm is selected by data in the signature); ML-DSA does its own hashing, +but is allowed to be used with a SHA512 hash for signed attributes. ========================== @@ -146,9 +148,9 @@ into vmlinux) using parameters in the:: file (which is also generated if it does not already exist). -One can select between RSA (``MODULE_SIG_KEY_TYPE_RSA``) and ECDSA -(``MODULE_SIG_KEY_TYPE_ECDSA``) to generate either RSA 4k or NIST -P-384 keypair. +One can select between RSA (``MODULE_SIG_KEY_TYPE_RSA``), ECDSA +(``MODULE_SIG_KEY_TYPE_ECDSA``) and ML-DSA (``MODULE_SIG_KEY_TYPE_MLDSA_*``) to +generate an RSA 4k, a NIST P-384 keypair or an ML-DSA 44, 65 or 87 keypair. It is strongly recommended that you provide your own x509.genkey file. diff --git a/certs/Kconfig b/certs/Kconfig index 78307dc25559..8e39a80c7abe 100644 --- a/certs/Kconfig +++ b/certs/Kconfig @@ -39,6 +39,39 @@ config MODULE_SIG_KEY_TYPE_ECDSA Note: Remove all ECDSA signing keys, e.g. certs/signing_key.pem, when falling back to building Linux 5.14 and older kernels. +config MODULE_SIG_KEY_TYPE_MLDSA_44 + bool "ML-DSA-44" + select CRYPTO_MLDSA + depends on OPENSSL_SUPPORTS_ML_DSA + help + Use an ML-DSA-44 key (NIST FIPS 204) for module signing. ML-DSA + support requires OpenSSL-3.5 minimum; preferably OpenSSL-4+. With + the latter, the entire module body will be signed; with the former, + signedAttrs will be used as it lacks support for CMS_NOATTR with + ML-DSA. + +config MODULE_SIG_KEY_TYPE_MLDSA_65 + bool "ML-DSA-65" + select CRYPTO_MLDSA + depends on OPENSSL_SUPPORTS_ML_DSA + help + Use an ML-DSA-65 key (NIST FIPS 204) for module signing. ML-DSA + support requires OpenSSL-3.5 minimum; preferably OpenSSL-4+. With + the latter, the entire module body will be signed; with the former, + signedAttrs will be used as it lacks support for CMS_NOATTR with + ML-DSA. + +config MODULE_SIG_KEY_TYPE_MLDSA_87 + bool "ML-DSA-87" + select CRYPTO_MLDSA + depends on OPENSSL_SUPPORTS_ML_DSA + help + Use an ML-DSA-87 key (NIST FIPS 204) for module signing. ML-DSA + support requires OpenSSL-3.5 minimum; preferably OpenSSL-4+. With + the latter, the entire module body will be signed; with the former, + signedAttrs will be used as it lacks support for CMS_NOATTR with + ML-DSA. + endchoice config SYSTEM_TRUSTED_KEYRING @@ -154,4 +187,11 @@ config SYSTEM_BLACKLIST_AUTH_UPDATE keyring. The PKCS#7 signature of the description is set in the key payload. Blacklist keys cannot be removed. +config OPENSSL_SUPPORTS_ML_DSA + def_bool $(success, openssl list -key-managers | grep -q ML-DSA-87) + help + Support for ML-DSA-44/65/87 was added in openssl-3.5, so as long + as older versions are supported, the key types may only be + set after testing the installed binary for support. + endmenu diff --git a/certs/Makefile b/certs/Makefile index f6fa4d8d75e0..3ee1960f9f4a 100644 --- a/certs/Makefile +++ b/certs/Makefile @@ -43,6 +43,9 @@ targets += x509_certificate_list ifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_key.pem) keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 +keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_MLDSA_44) := -newkey ml-dsa-44 +keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_MLDSA_65) := -newkey ml-dsa-65 +keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_MLDSA_87) := -newkey ml-dsa-87 quiet_cmd_gen_key = GENKEY $@ cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ diff --git a/scripts/sign-file.c b/scripts/sign-file.c index 7070245edfc1..78276b15ab23 100644 --- a/scripts/sign-file.c +++ b/scripts/sign-file.c @@ -27,7 +27,7 @@ #include <openssl/evp.h> #include <openssl/pem.h> #include <openssl/err.h> -#if OPENSSL_VERSION_MAJOR >= 3 +#if OPENSSL_VERSION_NUMBER >= 0x30000000L # define USE_PKCS11_PROVIDER # include <openssl/provider.h> # include <openssl/store.h> @@ -315,18 +315,39 @@ int main(int argc, char **argv) ERR(!digest_algo, "EVP_get_digestbyname"); #ifndef USE_PKCS7 + + unsigned int flags = + CMS_NOCERTS | + CMS_PARTIAL | + CMS_BINARY | + CMS_DETACHED | + CMS_STREAM | + CMS_NOSMIMECAP | +#ifdef CMS_NO_SIGNING_TIME + CMS_NO_SIGNING_TIME | +#endif + use_keyid; + +#if OPENSSL_VERSION_NUMBER >= 0x30000000L && OPENSSL_VERSION_NUMBER < 0x40000000L + if (EVP_PKEY_is_a(private_key, "ML-DSA-44") || + EVP_PKEY_is_a(private_key, "ML-DSA-65") || + EVP_PKEY_is_a(private_key, "ML-DSA-87")) { + /* ML-DSA + CMS_NOATTR is not supported in openssl-3.5 + * and before. + */ + use_signed_attrs = 0; + } +#endif + + flags |= use_signed_attrs; + /* Load the signature message from the digest buffer. */ - cms = CMS_sign(NULL, NULL, NULL, NULL, - CMS_NOCERTS | CMS_PARTIAL | CMS_BINARY | - CMS_DETACHED | CMS_STREAM); + cms = CMS_sign(NULL, NULL, NULL, NULL, flags); ERR(!cms, "CMS_sign"); - ERR(!CMS_add1_signer(cms, x509, private_key, digest_algo, - CMS_NOCERTS | CMS_BINARY | - CMS_NOSMIMECAP | use_keyid | - use_signed_attrs), + ERR(!CMS_add1_signer(cms, x509, private_key, digest_algo, flags), "CMS_add1_signer"); - ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) != 1, + ERR(CMS_final(cms, bm, NULL, flags) != 1, "CMS_final"); #else
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:11 +0000", "thread_id": "20260202170216.2467036-3-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Allow the rejection of authenticatedAttributes in PKCS#7 (signedAttrs in CMS) to be waived in the kernel config for ML-DSA when used for module signing. This reflects the issue that openssl < 4.0 cannot do this and openssl-4 has not yet been released. This does not permit RSA, ECDSA or ECRDSA to be so waived (behaviour unchanged). Signed-off-by: David Howells <dhowells@redhat.com> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Jarkko Sakkinen <jarkko@kernel.org> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/Kconfig | 11 +++++++++++ crypto/asymmetric_keys/pkcs7_parser.c | 8 ++++++++ crypto/asymmetric_keys/pkcs7_parser.h | 3 +++ crypto/asymmetric_keys/pkcs7_verify.c | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/crypto/asymmetric_keys/Kconfig b/crypto/asymmetric_keys/Kconfig index e1345b8f39f1..1dae2232fe9a 100644 --- a/crypto/asymmetric_keys/Kconfig +++ b/crypto/asymmetric_keys/Kconfig @@ -53,6 +53,17 @@ config PKCS7_MESSAGE_PARSER This option provides support for parsing PKCS#7 format messages for signature data and provides the ability to verify the signature. +config PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + bool "Waive rejection of authenticatedAttributes for ML-DSA" + depends on PKCS7_MESSAGE_PARSER + depends on CRYPTO_MLDSA + help + Due to use of CMS_NOATTR with ML-DSA not being supported in + OpenSSL < 4.0 (and thus any released version), enabling this + allows authenticatedAttributes to be used with ML-DSA for + module signing. Use of authenticatedAttributes in this + context is normally rejected. + config PKCS7_TEST_KEY tristate "PKCS#7 testing key type" depends on SYSTEM_DATA_VERIFICATION diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c index 594a8f1d9dfb..db1c90ca6fc1 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.c +++ b/crypto/asymmetric_keys/pkcs7_parser.c @@ -92,9 +92,17 @@ static int pkcs7_check_authattrs(struct pkcs7_message *msg) if (!sinfo) goto inconsistent; +#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + msg->authattrs_rej_waivable = true; +#endif + if (sinfo->authattrs) { want = true; msg->have_authattrs = true; +#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + if (strncmp(sinfo->sig->pkey_algo, "mldsa", 5) != 0) + msg->authattrs_rej_waivable = false; +#endif } else if (sinfo->sig->algo_takes_data) { sinfo->sig->hash_algo = "none"; } diff --git a/crypto/asymmetric_keys/pkcs7_parser.h b/crypto/asymmetric_keys/pkcs7_parser.h index e17f7ce4fb43..6ef9f335bb17 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.h +++ b/crypto/asymmetric_keys/pkcs7_parser.h @@ -55,6 +55,9 @@ struct pkcs7_message { struct pkcs7_signed_info *signed_infos; u8 version; /* Version of cert (1 -> PKCS#7 or CMS; 3 -> CMS) */ bool have_authattrs; /* T if have authattrs */ +#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + bool authattrs_rej_waivable; /* T if authatts rejection can be waived */ +#endif /* Content Data (or NULL) */ enum OID data_type; /* Type of Data */ diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c index 06abb9838f95..519eecfe6778 100644 --- a/crypto/asymmetric_keys/pkcs7_verify.c +++ b/crypto/asymmetric_keys/pkcs7_verify.c @@ -425,6 +425,12 @@ int pkcs7_verify(struct pkcs7_message *pkcs7, return -EKEYREJECTED; } if (pkcs7->have_authattrs) { +#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + if (pkcs7->authattrs_rej_waivable) { + pr_warn("Waived invalid module sig (has authattrs)\n"); + break; + } +#endif pr_warn("Invalid module sig (has authattrs)\n"); return -EKEYREJECTED; }
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:12 +0000", "thread_id": "20260202170216.2467036-3-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH 0/2] Add HPET NMI Watchdog support
The current NMI watchdog relies on performance counters and consistently occupies one on each CPU. When running virtual machines, we want to pass performance counters to virtual machines so they can make use of them. In addition the host system wants to use performance counters to check the system to identify when anything looks abnormal, such as split locks. That makes PMCs a precious resource. So any PMC we can free up is a PMC we can use for something useful. That made me look at the NMI watchdog. The PMC based NMI watchdog implementation does not actually need any performance counting. It just needs a per-CPU NMI timer source. X86 systems can make anything that emits an interrupt descriptor (IOAPIC, MSI(-X), etc) become an NMI source. So any time goes. Including the HPET. And while they can't really operate per-CPU, in almost all cases you only really want the NMI on *all* CPUs, rather than per-CPU. So I took a stab at building an HPET based NMI watchdog. In my (QEMU based) testing, it's fully functional and can successfully detect when CPUs get stuck. It even survives suspend/resume cycles. For now, its enablement is a config time option because the hardlockup framework does not support dynamic switching of multiple detectors. That's ok for our use case. But maybe something for the interested reader to tackle eventually :). You can enable the HPET watchdog by default by setting CONFIG_HARDLOCKUP_DETECTOR_HPET_DEFAULT=y or passing "hpet=watchdog" to the kernel command line. When active, it will emit a kernel log message to indicate it works: [ 0.179176] hpet: HPET watchdog initialized on timer 0, GSI 2 The HPET can only be in either watchdog or generic mode. I am a bit worried about IO-APIC pin allocation logic, so I opted to reuse the generic timer pin. And that means I'm effectively breaking the normal interrupt delivery path. so the easy way out was to say when watchdog is active, PIT and HPET are not available as timer sources. Which is ok on modern systems. There are way too many (unreliable) timer sources on x86 already. Trimming a few surely won't hurt. I'm open to inputs on how to make the HPET multi-purpose though, in case anyone feels strongly about it. Alex Alexander Graf (2): x86/ioapic: Add NMI delivery configuration helper hpet: Add HPET-based NMI watchdog support .../admin-guide/kernel-parameters.txt | 5 +- arch/x86/Kconfig | 19 ++ arch/x86/include/asm/io_apic.h | 2 + arch/x86/kernel/apic/io_apic.c | 32 ++++ arch/x86/kernel/hpet.c | 172 ++++++++++++++++++ arch/x86/kernel/i8253.c | 9 + drivers/char/hpet.c | 3 + include/linux/hpet.h | 14 ++ 8 files changed, 255 insertions(+), 1 deletion(-) -- 2.47.1 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
To implement an HPET based NMI watchdog, the HPET code will need to reconfigure an IOAPIC pin to NMI mode. Add a function that allows driver code to configure an IOAPIC pin for NMI delivery mode. The caller can choose whether to invoke NMIs on the BSP or broadcast on all CPUs in the system. (Disclaimer: Some of this code was written with the help of Kiro, an AI coding assistant) Signed-off-by: Alexander Graf <graf@amazon.com> --- arch/x86/include/asm/io_apic.h | 2 ++ arch/x86/kernel/apic/io_apic.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/arch/x86/include/asm/io_apic.h b/arch/x86/include/asm/io_apic.h index 0d806513c4b3..58cfb338bf39 100644 --- a/arch/x86/include/asm/io_apic.h +++ b/arch/x86/include/asm/io_apic.h @@ -158,6 +158,8 @@ extern void mp_save_irq(struct mpc_intsrc *m); extern void disable_ioapic_support(void); +extern int ioapic_set_nmi(u32 gsi, bool broadcast); + extern void __init io_apic_init_mappings(void); extern unsigned int native_io_apic_read(unsigned int apic, unsigned int reg); extern void native_restore_boot_irq_mode(void); diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index 28f934f05a85..5b303e5d2f3f 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -2951,6 +2951,38 @@ int mp_irqdomain_ioapic_idx(struct irq_domain *domain) return (int)(long)domain->host_data; } +/** + * ioapic_set_nmi - Configure an IOAPIC pin for NMI delivery + * @gsi: Global System Interrupt number + * @broadcast: true to broadcast to all CPUs, false to send to CPU 0 only + * + * Configures the specified GSI for NMI delivery mode. + * + * Returns 0 on success, negative error code on failure. + */ +int ioapic_set_nmi(u32 gsi, bool broadcast) +{ + struct IO_APIC_route_entry entry = { }; + int ioapic_idx, pin; + + ioapic_idx = mp_find_ioapic(gsi); + if (ioapic_idx < 0) + return -ENODEV; + + pin = mp_find_ioapic_pin(ioapic_idx, gsi); + if (pin < 0) + return -ENODEV; + + entry.delivery_mode = APIC_DELIVERY_MODE_NMI; + entry.destid_0_7 = broadcast ? 0xFF : boot_cpu_physical_apicid; + entry.dest_mode_logical = 0; + entry.masked = 0; + + ioapic_write_entry(ioapic_idx, pin, entry); + + return 0; +} + const struct irq_domain_ops mp_ioapic_irqdomain_ops = { .alloc = mp_irqdomain_alloc, .free = mp_irqdomain_free, -- 2.47.1 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
{ "author": "Alexander Graf <graf@amazon.com>", "date": "Mon, 2 Feb 2026 17:48:02 +0000", "thread_id": "20260202174803.66640-3-graf@amazon.com.mbox.gz" }
lkml
[PATCH 0/2] Add HPET NMI Watchdog support
The current NMI watchdog relies on performance counters and consistently occupies one on each CPU. When running virtual machines, we want to pass performance counters to virtual machines so they can make use of them. In addition the host system wants to use performance counters to check the system to identify when anything looks abnormal, such as split locks. That makes PMCs a precious resource. So any PMC we can free up is a PMC we can use for something useful. That made me look at the NMI watchdog. The PMC based NMI watchdog implementation does not actually need any performance counting. It just needs a per-CPU NMI timer source. X86 systems can make anything that emits an interrupt descriptor (IOAPIC, MSI(-X), etc) become an NMI source. So any time goes. Including the HPET. And while they can't really operate per-CPU, in almost all cases you only really want the NMI on *all* CPUs, rather than per-CPU. So I took a stab at building an HPET based NMI watchdog. In my (QEMU based) testing, it's fully functional and can successfully detect when CPUs get stuck. It even survives suspend/resume cycles. For now, its enablement is a config time option because the hardlockup framework does not support dynamic switching of multiple detectors. That's ok for our use case. But maybe something for the interested reader to tackle eventually :). You can enable the HPET watchdog by default by setting CONFIG_HARDLOCKUP_DETECTOR_HPET_DEFAULT=y or passing "hpet=watchdog" to the kernel command line. When active, it will emit a kernel log message to indicate it works: [ 0.179176] hpet: HPET watchdog initialized on timer 0, GSI 2 The HPET can only be in either watchdog or generic mode. I am a bit worried about IO-APIC pin allocation logic, so I opted to reuse the generic timer pin. And that means I'm effectively breaking the normal interrupt delivery path. so the easy way out was to say when watchdog is active, PIT and HPET are not available as timer sources. Which is ok on modern systems. There are way too many (unreliable) timer sources on x86 already. Trimming a few surely won't hurt. I'm open to inputs on how to make the HPET multi-purpose though, in case anyone feels strongly about it. Alex Alexander Graf (2): x86/ioapic: Add NMI delivery configuration helper hpet: Add HPET-based NMI watchdog support .../admin-guide/kernel-parameters.txt | 5 +- arch/x86/Kconfig | 19 ++ arch/x86/include/asm/io_apic.h | 2 + arch/x86/kernel/apic/io_apic.c | 32 ++++ arch/x86/kernel/hpet.c | 172 ++++++++++++++++++ arch/x86/kernel/i8253.c | 9 + drivers/char/hpet.c | 3 + include/linux/hpet.h | 14 ++ 8 files changed, 255 insertions(+), 1 deletion(-) -- 2.47.1 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
The traditional NMI watchdog timer uses performance counters to trigger periodic NMIs. But performance counters are a scarce resource that are best used for actual performance counting. However, the HPET is another timer source on most modern x86 systems that can inject NMI interrupts. Add support for using HPET timer as NMI watchdog source instead of performance counters. This frees up a PMC for profiling use. Unlike with the PMU based watchdog where we trigger a per-CPU NMI, APIC based interrupt descriptors can only target either a specific CPU or perform a broadcast on all CPUs. To not run into races and allow for CPU hotplug, the NMI watchdog switches between CPU 0 and broadcast modes based on whether all CPUs are up or not. The HPET watchdog always uses IO-APIC line 2. This line is architecturally defined as the PIT source on PCs and hence always available as long as we disable the PIT (which we do). We could in theory try to find a vacant GSI line, but in practice that would create a big dependency chain on ACPI which I would rather avoid for now. The implementation uses the standard HARDLOCKUP_DETECTOR_ARCH infrastructure, following the same pattern as powerpc's arch-specific hardlockup detector. With this watchdog present, I can successfully capture system lockups, verified by adding "local_irq_disable(); while(1) {}" into mount_root_generic(). (Disclaimer: Some of this code was written with the help of Kiro, an AI coding assistant) Signed-off-by: Alexander Graf <graf@amazon.com> --- .../admin-guide/kernel-parameters.txt | 5 +- arch/x86/Kconfig | 19 ++ arch/x86/kernel/hpet.c | 208 ++++++++++++++++++ arch/x86/kernel/i8253.c | 9 + drivers/char/hpet.c | 3 + include/linux/hpet.h | 14 ++ 6 files changed, 257 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 1058f2a6d6a8..c6a98812a896 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2045,11 +2045,14 @@ Kernel parameters hpet= [X86-32,HPET] option to control HPET usage Format: { enable (default) | disable | force | - verbose } + verbose | watchdog } disable: disable HPET and use PIT instead force: allow force enabled of undocumented chips (ICH4, VIA, nVidia) verbose: show contents of HPET registers during setup + watchdog: use HPET timer as NMI watchdog source instead + of performance counters. Use nmi_watchdog=1 to enable + or nmi_watchdog=panic to panic on hard lockup detection. hpet_mmap= [X86, HPET_MMAP] Allow userspace to mmap HPET registers. Default set by CONFIG_HPET_MMAP_DEFAULT. diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 80527299f859..e8873218a803 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -948,6 +948,25 @@ config HPET_EMULATE_RTC def_bool y depends on HPET_TIMER && (RTC_DRV_CMOS=m || RTC_DRV_CMOS=y) +config HARDLOCKUP_DETECTOR_HPET + bool "Use HPET for NMI watchdog" + depends on HPET_TIMER + select HAVE_HARDLOCKUP_DETECTOR_ARCH + select HARDLOCKUP_DETECTOR_COUNTS_HRTIMER + help + Use HPET timer as NMI source instead of performance counters. + This frees up a performance counter for profiling. + Enable with hpet=watchdog kernel parameter. + +config HARDLOCKUP_DETECTOR_HPET_DEFAULT + bool "Enable HPET watchdog by default" + depends on HARDLOCKUP_DETECTOR_HPET + help + Say Y here to enable HPET-based NMI watchdog by default without + requiring the hpet=watchdog kernel parameter. + + If unsure, say N. + # Mark as expert because too many people got it wrong. # The code disables itself when not needed. config DMI diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c index d6387dde3ff9..c9114997c383 100644 --- a/arch/x86/kernel/hpet.c +++ b/arch/x86/kernel/hpet.c @@ -6,9 +6,12 @@ #include <linux/hpet.h> #include <linux/cpu.h> #include <linux/irq.h> +#include <linux/nmi.h> +#include <linux/syscore_ops.h> #include <asm/cpuid/api.h> #include <asm/irq_remapping.h> +#include <asm/io_apic.h> #include <asm/hpet.h> #include <asm/time.h> #include <asm/mwait.h> @@ -100,6 +103,8 @@ static inline void hpet_clear_mapping(void) /* * HPET command line enable / disable */ +static bool hpet_watchdog_mode = IS_ENABLED(CONFIG_HARDLOCKUP_DETECTOR_HPET_DEFAULT); + static int __init hpet_setup(char *str) { while (str) { @@ -113,6 +118,8 @@ static int __init hpet_setup(char *str) hpet_force_user = true; if (!strncmp("verbose", str, 7)) hpet_verbose = true; + if (!strncmp("watchdog", str, 8)) + hpet_watchdog_mode = true; str = next; } return 1; @@ -985,6 +992,200 @@ static bool __init hpet_is_pc10_damaged(void) return true; } +#ifdef CONFIG_HARDLOCKUP_DETECTOR_HPET +/* + * HPET watchdog uses timer 0 routed to GSI 2 (legacy PIT IRQ line). + * When using HPET as watchdog, we repurpose this line for NMI delivery. + */ +#define HPET_WD_TIMER 0 +#define HPET_WD_GSI 2 + +bool hpet_watchdog_initialized; +static bool hpet_watchdog_ioapic_configured; +static DEFINE_PER_CPU(u32, hpet_watchdog_next_tick); + +static int hpet_nmi_handler(unsigned int cmd, struct pt_regs *regs) +{ + u32 now, next, delta; + + if (panic_in_progress()) + return NMI_HANDLED; + + /* Check if this NMI is from our HPET timer by comparing counter value */ + now = hpet_readl(HPET_COUNTER); + next = __this_cpu_read(hpet_watchdog_next_tick); + delta = hpet_freq * watchdog_thresh; + + /* + * If we have a next tick set and counter hasn't reached it yet, + * this NMI is not from our timer. Allow some tolerance for timing. + */ + if (next && (s32)(now - next) < -(s32)(delta / 4)) + return NMI_DONE; + + /* Update next expected tick */ + __this_cpu_write(hpet_watchdog_next_tick, now + delta); + + watchdog_hardlockup_check(smp_processor_id(), regs); + + return NMI_HANDLED; +} + +/* + * On suspend, clear the configured flag so that the first CPU to come + * online after resume will reconfigure the HPET timer and IO-APIC. + * + * We don't need to explicitly disable the watchdog here because: + * 1. The HPET registers are reset by the hibernation/suspend process anyway + * 2. The IO-APIC state is saved/restored by ioapic_syscore_ops, but we + * need to reconfigure it for NMI delivery after resume + * 3. Secondary CPUs are offlined before suspend, so we can't broadcast + * NMIs until they're back online - the enable callback handles this + */ +static int hpet_watchdog_suspend(void *data) +{ + hpet_watchdog_ioapic_configured = false; + return 0; +} + +static const struct syscore_ops hpet_watchdog_syscore_ops = { + .suspend = hpet_watchdog_suspend, +}; + +static struct syscore hpet_watchdog_syscore = { + .ops = &hpet_watchdog_syscore_ops, +}; + +static int __init hpet_watchdog_init(u32 channels) +{ + u32 cfg, i, route_cap; + + if (channels <= HPET_WD_TIMER) + return 0; + + /* Verify GSI 2 is available in the route capability bitmap */ + route_cap = hpet_readl(HPET_Tn_CFG(HPET_WD_TIMER) + 4); + if (!(route_cap & (1 << HPET_WD_GSI))) { + pr_info("HPET timer 0 cannot route to GSI %d\n", HPET_WD_GSI); + return 0; + } + + /* Deactivate all timers */ + for (i = 0; i < channels; i++) { + cfg = hpet_readl(HPET_Tn_CFG(i)); + cfg &= ~(HPET_TN_ENABLE | HPET_TN_LEVEL | HPET_TN_FSB); + hpet_writel(cfg, HPET_Tn_CFG(i)); + } + + /* Configure HPET timer for periodic mode */ + cfg = hpet_readl(HPET_Tn_CFG(HPET_WD_TIMER)); + cfg &= ~(HPET_TN_ENABLE | HPET_TN_FSB); + cfg |= HPET_TN_PERIODIC | HPET_TN_32BIT | HPET_TN_SETVAL | HPET_TN_LEVEL; + hpet_writel(cfg, HPET_Tn_CFG(HPET_WD_TIMER)); + + /* Route HPET timer to the GSI */ + cfg = hpet_readl(HPET_Tn_CFG(HPET_WD_TIMER)); + cfg &= ~(Tn_INT_ROUTE_CNF_MASK | HPET_CFG_ENABLE); + cfg |= (HPET_WD_GSI << Tn_INT_ROUTE_CNF_SHIFT) & Tn_INT_ROUTE_CNF_MASK; + hpet_writel(cfg, HPET_Tn_CFG(HPET_WD_TIMER)); + + if (register_nmi_handler(NMI_LOCAL, hpet_nmi_handler, 0, "hpet_watchdog")) { + pr_err("Failed to register NMI_LOCAL handler\n"); + return 0; + } + if (register_nmi_handler(NMI_UNKNOWN, hpet_nmi_handler, 0, "hpet_watchdog")) { + unregister_nmi_handler(NMI_LOCAL, "hpet_watchdog"); + pr_err("Failed to register NMI_UNKNOWN handler\n"); + return 0; + } + + hpet_start_counter(); + + hpet_watchdog_initialized = true; + + register_syscore(&hpet_watchdog_syscore); + + pr_info("HPET watchdog initialized on timer %d, GSI %d", HPET_WD_TIMER, HPET_WD_GSI); + + return 0; +} + +void watchdog_hardlockup_stop(void) +{ + u32 cfg; + + if (!hpet_watchdog_initialized) + return; + + cfg = hpet_readl(HPET_Tn_CFG(HPET_WD_TIMER)); + cfg &= ~HPET_TN_ENABLE; + hpet_writel(cfg, HPET_Tn_CFG(HPET_WD_TIMER)); +} + +void watchdog_hardlockup_start(void) +{ + u32 cfg, delta; + + if (!hpet_watchdog_initialized) + return; + + if (!hpet_watchdog_ioapic_configured) { + if (ioapic_set_nmi(HPET_WD_GSI, false)) { + pr_err("Unable to configure IO-APIC for NMI\n"); + return; + } + hpet_watchdog_ioapic_configured = true; + } + + delta = hpet_freq * watchdog_thresh; + + cfg = hpet_readl(HPET_Tn_CFG(HPET_WD_TIMER)); + cfg &= ~(HPET_TN_ENABLE | HPET_TN_FSB | HPET_TN_LEVEL); + cfg |= HPET_TN_PERIODIC | HPET_TN_32BIT | HPET_TN_SETVAL; + hpet_writel(cfg, HPET_Tn_CFG(HPET_WD_TIMER)); + + /* Write twice for AMD 81xx with buggy HPET */ + hpet_writel(delta, HPET_Tn_CMP(HPET_WD_TIMER)); + hpet_writel(delta, HPET_Tn_CMP(HPET_WD_TIMER)); + + cfg |= HPET_TN_ENABLE; + hpet_writel(cfg, HPET_Tn_CFG(HPET_WD_TIMER)); +} + +void watchdog_hardlockup_enable(unsigned int cpu) +{ + if (!hpet_watchdog_ioapic_configured) { + /* + * First CPU online after resume - reconfigure HPET timer. + * This also sets hpet_watchdog_ioapic_configured = true. + */ + watchdog_hardlockup_start(); + } + + if (num_online_cpus() == num_present_cpus()) { + ioapic_set_nmi(HPET_WD_GSI, true); + pr_info("switched to broadcast mode (all %d CPUs online)\n", + num_online_cpus()); + } +} + +void watchdog_hardlockup_disable(unsigned int cpu) +{ + if (num_online_cpus() < num_present_cpus()) { + ioapic_set_nmi(HPET_WD_GSI, false); + pr_info("switched to CPU 0 only (%d CPUs online)\n", + num_online_cpus() - 1); + } +} + +int __init watchdog_hardlockup_probe(void) +{ + return hpet_watchdog_mode ? 0 : -ENODEV; +} +#else +static inline int hpet_watchdog_init(u32 channels) { return 0; } +#endif /* CONFIG_HARDLOCKUP_DETECTOR_HPET */ + /** * hpet_enable - Try to setup the HPET timer. Returns 1 on success. */ @@ -1031,6 +1232,10 @@ int __init hpet_enable(void) /* This is the HPET channel number which is zero based */ channels = ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT) + 1; + /* If watchdog mode, hand off to watchdog driver */ + if (hpet_watchdog_mode) + return hpet_watchdog_init(channels); + /* * The legacy routing mode needs at least two channels, tick timer * and the rtc emulation channel. @@ -1122,6 +1327,9 @@ static __init int hpet_late_init(void) { int ret; + if (hpet_is_watchdog()) + return -ENODEV; + if (!hpet_address) { if (!force_hpet_address) return -ENODEV; diff --git a/arch/x86/kernel/i8253.c b/arch/x86/kernel/i8253.c index cb9852ad6098..36dd948371a4 100644 --- a/arch/x86/kernel/i8253.c +++ b/arch/x86/kernel/i8253.c @@ -7,6 +7,7 @@ #include <linux/init.h> #include <linux/timex.h> #include <linux/i8253.h> +#include <linux/hpet.h> #include <asm/hypervisor.h> #include <asm/apic.h> @@ -31,6 +32,14 @@ struct clock_event_device *global_clock_event; */ static bool __init use_pit(void) { + if (hpet_is_watchdog()) { + /* + * The PIT overlaps the HPET IRQ line which we configure to + * NMI in watchdog mode, rendering the PIT non functional. + */ + return false; + } + if (!IS_ENABLED(CONFIG_X86_TSC) || !boot_cpu_has(X86_FEATURE_TSC)) return true; diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c index 4f5ccd3a1f56..9d9e4d22ab7f 100644 --- a/drivers/char/hpet.c +++ b/drivers/char/hpet.c @@ -977,6 +977,9 @@ static int hpet_acpi_add(struct acpi_device *device) acpi_status result; struct hpet_data data; + if (hpet_is_watchdog()) + return -ENODEV; + memset(&data, 0, sizeof(data)); result = diff --git a/include/linux/hpet.h b/include/linux/hpet.h index 21e69eaf7a36..408b440163cc 100644 --- a/include/linux/hpet.h +++ b/include/linux/hpet.h @@ -108,4 +108,18 @@ static inline void hpet_reserve_timer(struct hpet_data *hd, int timer) int hpet_alloc(struct hpet_data *); +#ifdef CONFIG_HARDLOCKUP_DETECTOR_HPET +extern bool hpet_watchdog_initialized; + +static inline bool hpet_is_watchdog(void) +{ + return hpet_watchdog_initialized; +} +#else +static inline bool hpet_is_watchdog(void) +{ + return false; +} +#endif + #endif /* !__HPET__ */ -- 2.47.1 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
{ "author": "Alexander Graf <graf@amazon.com>", "date": "Mon, 2 Feb 2026 17:48:03 +0000", "thread_id": "20260202174803.66640-3-graf@amazon.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Add verify-only public key crypto support for ML-DSA so that the X.509/PKCS#7 signature verification code, as used by module signing, amongst other things, can make use of it through the common crypto_sig API. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> cc: Eric Biggers <ebiggers@kernel.org> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/Kconfig | 9 +++ crypto/Makefile | 2 + crypto/mldsa.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 crypto/mldsa.c diff --git a/crypto/Kconfig b/crypto/Kconfig index 12a87f7cf150..a210575fa5e0 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -344,6 +344,15 @@ config CRYPTO_ECRDSA One of the Russian cryptographic standard algorithms (called GOST algorithms). Only signature verification is implemented. +config CRYPTO_MLDSA + tristate "ML-DSA (Module-Lattice-Based Digital Signature Algorithm)" + select CRYPTO_SIG + select CRYPTO_LIB_MLDSA + help + ML-DSA (Module-Lattice-Based Digital Signature Algorithm) (FIPS-204). + + Only signature verification is implemented. + endmenu menu "Block ciphers" diff --git a/crypto/Makefile b/crypto/Makefile index 23d3db7be425..267d5403045b 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -60,6 +60,8 @@ ecdsa_generic-y += ecdsa-p1363.o ecdsa_generic-y += ecdsasignature.asn1.o obj-$(CONFIG_CRYPTO_ECDSA) += ecdsa_generic.o +obj-$(CONFIG_CRYPTO_MLDSA) += mldsa.o + crypto_acompress-y := acompress.o crypto_acompress-y += scompress.o obj-$(CONFIG_CRYPTO_ACOMP2) += crypto_acompress.o diff --git a/crypto/mldsa.c b/crypto/mldsa.c new file mode 100644 index 000000000000..d8de082cc67a --- /dev/null +++ b/crypto/mldsa.c @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * crypto_sig wrapper around ML-DSA library. + */ +#include <linux/init.h> +#include <linux/module.h> +#include <crypto/internal/sig.h> +#include <crypto/mldsa.h> + +struct crypto_mldsa_ctx { + u8 pk[MAX(MAX(MLDSA44_PUBLIC_KEY_SIZE, + MLDSA65_PUBLIC_KEY_SIZE), + MLDSA87_PUBLIC_KEY_SIZE)]; + unsigned int pk_len; + enum mldsa_alg strength; + bool key_set; +}; + +static int crypto_mldsa_sign(struct crypto_sig *tfm, + const void *msg, unsigned int msg_len, + void *sig, unsigned int sig_len) +{ + return -EOPNOTSUPP; +} + +static int crypto_mldsa_verify(struct crypto_sig *tfm, + const void *sig, unsigned int sig_len, + const void *msg, unsigned int msg_len) +{ + const struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + if (unlikely(!ctx->key_set)) + return -EINVAL; + + return mldsa_verify(ctx->strength, sig, sig_len, msg, msg_len, + ctx->pk, ctx->pk_len); +} + +static unsigned int crypto_mldsa_key_size(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + switch (ctx->strength) { + case MLDSA44: + return MLDSA44_PUBLIC_KEY_SIZE; + case MLDSA65: + return MLDSA65_PUBLIC_KEY_SIZE; + case MLDSA87: + return MLDSA87_PUBLIC_KEY_SIZE; + default: + WARN_ON_ONCE(1); + return 0; + } +} + +static int crypto_mldsa_set_pub_key(struct crypto_sig *tfm, + const void *key, unsigned int keylen) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + unsigned int expected_len = crypto_mldsa_key_size(tfm); + + if (keylen != expected_len) + return -EINVAL; + + ctx->pk_len = keylen; + memcpy(ctx->pk, key, keylen); + ctx->key_set = true; + return 0; +} + +static int crypto_mldsa_set_priv_key(struct crypto_sig *tfm, + const void *key, unsigned int keylen) +{ + return -EOPNOTSUPP; +} + +static unsigned int crypto_mldsa_max_size(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + switch (ctx->strength) { + case MLDSA44: + return MLDSA44_SIGNATURE_SIZE; + case MLDSA65: + return MLDSA65_SIGNATURE_SIZE; + case MLDSA87: + return MLDSA87_SIGNATURE_SIZE; + default: + WARN_ON_ONCE(1); + return 0; + } +} + +static int crypto_mldsa44_alg_init(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + ctx->strength = MLDSA44; + ctx->key_set = false; + return 0; +} + +static int crypto_mldsa65_alg_init(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + ctx->strength = MLDSA65; + ctx->key_set = false; + return 0; +} + +static int crypto_mldsa87_alg_init(struct crypto_sig *tfm) +{ + struct crypto_mldsa_ctx *ctx = crypto_sig_ctx(tfm); + + ctx->strength = MLDSA87; + ctx->key_set = false; + return 0; +} + +static void crypto_mldsa_alg_exit(struct crypto_sig *tfm) +{ +} + +static struct sig_alg crypto_mldsa_algs[] = { + { + .sign = crypto_mldsa_sign, + .verify = crypto_mldsa_verify, + .set_pub_key = crypto_mldsa_set_pub_key, + .set_priv_key = crypto_mldsa_set_priv_key, + .key_size = crypto_mldsa_key_size, + .max_size = crypto_mldsa_max_size, + .init = crypto_mldsa44_alg_init, + .exit = crypto_mldsa_alg_exit, + .base.cra_name = "mldsa44", + .base.cra_driver_name = "mldsa44-lib", + .base.cra_ctxsize = sizeof(struct crypto_mldsa_ctx), + .base.cra_module = THIS_MODULE, + .base.cra_priority = 5000, + }, { + .sign = crypto_mldsa_sign, + .verify = crypto_mldsa_verify, + .set_pub_key = crypto_mldsa_set_pub_key, + .set_priv_key = crypto_mldsa_set_priv_key, + .key_size = crypto_mldsa_key_size, + .max_size = crypto_mldsa_max_size, + .init = crypto_mldsa65_alg_init, + .exit = crypto_mldsa_alg_exit, + .base.cra_name = "mldsa65", + .base.cra_driver_name = "mldsa65-lib", + .base.cra_ctxsize = sizeof(struct crypto_mldsa_ctx), + .base.cra_module = THIS_MODULE, + .base.cra_priority = 5000, + }, { + .sign = crypto_mldsa_sign, + .verify = crypto_mldsa_verify, + .set_pub_key = crypto_mldsa_set_pub_key, + .set_priv_key = crypto_mldsa_set_priv_key, + .key_size = crypto_mldsa_key_size, + .max_size = crypto_mldsa_max_size, + .init = crypto_mldsa87_alg_init, + .exit = crypto_mldsa_alg_exit, + .base.cra_name = "mldsa87", + .base.cra_driver_name = "mldsa87-lib", + .base.cra_ctxsize = sizeof(struct crypto_mldsa_ctx), + .base.cra_module = THIS_MODULE, + .base.cra_priority = 5000, + }, +}; + +static int __init mldsa_init(void) +{ + int ret, i; + + for (i = 0; i < ARRAY_SIZE(crypto_mldsa_algs); i++) { + ret = crypto_register_sig(&crypto_mldsa_algs[i]); + if (ret < 0) + goto error; + } + return 0; + +error: + pr_err("Failed to register (%d)\n", ret); + for (i--; i >= 0; i--) + crypto_unregister_sig(&crypto_mldsa_algs[i]); + return ret; +} +module_init(mldsa_init); + +static void mldsa_exit(void) +{ + for (int i = 0; i < ARRAY_SIZE(crypto_mldsa_algs); i++) + crypto_unregister_sig(&crypto_mldsa_algs[i]); +} +module_exit(mldsa_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Crypto API support for ML-DSA signature verification"); +MODULE_ALIAS_CRYPTO("mldsa44"); +MODULE_ALIAS_CRYPTO("mldsa65"); +MODULE_ALIAS_CRYPTO("mldsa87");
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:06 +0000", "thread_id": "20260202170216.2467036-5-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Calculate the SHA256 hash for blacklisting purposes independently of the signature hash (which may be something other than SHA256). This is necessary because when ML-DSA is used, no digest is calculated. Note that this represents a change of behaviour in that the hash used for the blacklist check would previously have been whatever digest was used for, say, RSA-based signatures. It may be that this is inadvisable. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/x509_parser.h | 2 ++ crypto/asymmetric_keys/x509_public_key.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crypto/asymmetric_keys/x509_parser.h b/crypto/asymmetric_keys/x509_parser.h index 0688c222806b..b7aeebdddb36 100644 --- a/crypto/asymmetric_keys/x509_parser.h +++ b/crypto/asymmetric_keys/x509_parser.h @@ -9,12 +9,14 @@ #include <linux/time.h> #include <crypto/public_key.h> #include <keys/asymmetric-type.h> +#include <crypto/sha2.h> struct x509_certificate { struct x509_certificate *next; struct x509_certificate *signer; /* Certificate that signed this one */ struct public_key *pub; /* Public key details */ struct public_key_signature *sig; /* Signature parameters */ + u8 sha256[SHA256_DIGEST_SIZE]; /* Hash for blacklist purposes */ char *issuer; /* Name of certificate issuer */ char *subject; /* Name of certificate subject */ struct asymmetric_key_id *id; /* Issuer + Serial number */ diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c index 12e3341e806b..79cc7b7a0630 100644 --- a/crypto/asymmetric_keys/x509_public_key.c +++ b/crypto/asymmetric_keys/x509_public_key.c @@ -31,6 +31,19 @@ int x509_get_sig_params(struct x509_certificate *cert) pr_devel("==>%s()\n", __func__); + /* Calculate a SHA256 hash of the TBS and check it against the + * blacklist. + */ + sha256(cert->tbs, cert->tbs_size, cert->sha256); + ret = is_hash_blacklisted(cert->sha256, sizeof(cert->sha256), + BLACKLIST_HASH_X509_TBS); + if (ret == -EKEYREJECTED) { + pr_err("Cert %*phN is blacklisted\n", + (int)sizeof(cert->sha256), cert->sha256); + cert->blacklisted = true; + ret = 0; + } + sig->s = kmemdup(cert->raw_sig, cert->raw_sig_size, GFP_KERNEL); if (!sig->s) return -ENOMEM; @@ -69,15 +82,6 @@ int x509_get_sig_params(struct x509_certificate *cert) if (ret < 0) goto error_2; - ret = is_hash_blacklisted(sig->digest, sig->digest_size, - BLACKLIST_HASH_X509_TBS); - if (ret == -EKEYREJECTED) { - pr_err("Cert %*phN is blacklisted\n", - sig->digest_size, sig->digest); - cert->blacklisted = true; - ret = 0; - } - error_2: kfree(desc); error:
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:07 +0000", "thread_id": "20260202170216.2467036-5-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Rename ->digest and ->digest_len to ->m and ->m_size to represent the input to the signature verification algorithm, reflecting that ->digest may no longer actually *be* a digest. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/asymmetric_type.c | 4 ++-- crypto/asymmetric_keys/pkcs7_verify.c | 28 ++++++++++++------------ crypto/asymmetric_keys/public_key.c | 3 +-- crypto/asymmetric_keys/signature.c | 2 +- crypto/asymmetric_keys/x509_public_key.c | 10 ++++----- include/crypto/public_key.h | 4 ++-- security/integrity/digsig_asymmetric.c | 4 ++-- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c index 348966ea2175..2326743310b1 100644 --- a/crypto/asymmetric_keys/asymmetric_type.c +++ b/crypto/asymmetric_keys/asymmetric_type.c @@ -593,10 +593,10 @@ static int asymmetric_key_verify_signature(struct kernel_pkey_params *params, { struct public_key_signature sig = { .s_size = params->in2_len, - .digest_size = params->in_len, + .m_size = params->in_len, .encoding = params->encoding, .hash_algo = params->hash_algo, - .digest = (void *)in, + .m = (void *)in, .s = (void *)in2, }; diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c index 6d6475e3a9bf..aa085ec6fb1c 100644 --- a/crypto/asymmetric_keys/pkcs7_verify.c +++ b/crypto/asymmetric_keys/pkcs7_verify.c @@ -31,7 +31,7 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, kenter(",%u,%s", sinfo->index, sinfo->sig->hash_algo); /* The digest was calculated already. */ - if (sig->digest) + if (sig->m) return 0; if (!sinfo->sig->hash_algo) @@ -45,11 +45,11 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, return (PTR_ERR(tfm) == -ENOENT) ? -ENOPKG : PTR_ERR(tfm); desc_size = crypto_shash_descsize(tfm) + sizeof(*desc); - sig->digest_size = crypto_shash_digestsize(tfm); + sig->m_size = crypto_shash_digestsize(tfm); ret = -ENOMEM; - sig->digest = kmalloc(sig->digest_size, GFP_KERNEL); - if (!sig->digest) + sig->m = kmalloc(sig->m_size, GFP_KERNEL); + if (!sig->m) goto error_no_desc; desc = kzalloc(desc_size, GFP_KERNEL); @@ -59,11 +59,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, desc->tfm = tfm; /* Digest the message [RFC2315 9.3] */ - ret = crypto_shash_digest(desc, pkcs7->data, pkcs7->data_len, - sig->digest); + ret = crypto_shash_digest(desc, pkcs7->data, pkcs7->data_len, sig->m); if (ret < 0) goto error; - pr_devel("MsgDigest = [%*ph]\n", 8, sig->digest); + pr_devel("MsgDigest = [%*ph]\n", 8, sig->m); /* However, if there are authenticated attributes, there must be a * message digest attribute amongst them which corresponds to the @@ -78,14 +77,14 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, goto error; } - if (sinfo->msgdigest_len != sig->digest_size) { + if (sinfo->msgdigest_len != sig->m_size) { pr_warn("Sig %u: Invalid digest size (%u)\n", sinfo->index, sinfo->msgdigest_len); ret = -EBADMSG; goto error; } - if (memcmp(sig->digest, sinfo->msgdigest, + if (memcmp(sig->m, sinfo->msgdigest, sinfo->msgdigest_len) != 0) { pr_warn("Sig %u: Message digest doesn't match\n", sinfo->index); @@ -98,7 +97,8 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, * convert the attributes from a CONT.0 into a SET before we * hash it. */ - memset(sig->digest, 0, sig->digest_size); + memset(sig->m, 0, sig->m_size); + ret = crypto_shash_init(desc); if (ret < 0) @@ -108,10 +108,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, if (ret < 0) goto error; ret = crypto_shash_finup(desc, sinfo->authattrs, - sinfo->authattrs_len, sig->digest); + sinfo->authattrs_len, sig->m); if (ret < 0) goto error; - pr_devel("AADigest = [%*ph]\n", 8, sig->digest); + pr_devel("AADigest = [%*ph]\n", 8, sig->m); } error: @@ -138,8 +138,8 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len, if (ret) return ret; - *buf = sinfo->sig->digest; - *len = sinfo->sig->digest_size; + *buf = sinfo->sig->m; + *len = sinfo->sig->m_size; i = match_string(hash_algo_name, HASH_ALGO__LAST, sinfo->sig->hash_algo); diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c index e5b177c8e842..a46356e0c08b 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c @@ -425,8 +425,7 @@ int public_key_verify_signature(const struct public_key *pkey, if (ret) goto error_free_key; - ret = crypto_sig_verify(tfm, sig->s, sig->s_size, - sig->digest, sig->digest_size); + ret = crypto_sig_verify(tfm, sig->s, sig->s_size, sig->m, sig->m_size); error_free_key: kfree_sensitive(key); diff --git a/crypto/asymmetric_keys/signature.c b/crypto/asymmetric_keys/signature.c index 041d04b5c953..f4ec126121b3 100644 --- a/crypto/asymmetric_keys/signature.c +++ b/crypto/asymmetric_keys/signature.c @@ -28,7 +28,7 @@ void public_key_signature_free(struct public_key_signature *sig) for (i = 0; i < ARRAY_SIZE(sig->auth_ids); i++) kfree(sig->auth_ids[i]); kfree(sig->s); - kfree(sig->digest); + kfree(sig->m); kfree(sig); } } diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c index 79cc7b7a0630..3854f7ae4ed0 100644 --- a/crypto/asymmetric_keys/x509_public_key.c +++ b/crypto/asymmetric_keys/x509_public_key.c @@ -63,11 +63,11 @@ int x509_get_sig_params(struct x509_certificate *cert) } desc_size = crypto_shash_descsize(tfm) + sizeof(*desc); - sig->digest_size = crypto_shash_digestsize(tfm); + sig->m_size = crypto_shash_digestsize(tfm); ret = -ENOMEM; - sig->digest = kmalloc(sig->digest_size, GFP_KERNEL); - if (!sig->digest) + sig->m = kmalloc(sig->m_size, GFP_KERNEL); + if (!sig->m) goto error; desc = kzalloc(desc_size, GFP_KERNEL); @@ -76,9 +76,7 @@ int x509_get_sig_params(struct x509_certificate *cert) desc->tfm = tfm; - ret = crypto_shash_digest(desc, cert->tbs, cert->tbs_size, - sig->digest); - + ret = crypto_shash_digest(desc, cert->tbs, cert->tbs_size, sig->m); if (ret < 0) goto error_2; diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h index 81098e00c08f..bd38ba4d217d 100644 --- a/include/crypto/public_key.h +++ b/include/crypto/public_key.h @@ -43,9 +43,9 @@ extern void public_key_free(struct public_key *key); struct public_key_signature { struct asymmetric_key_id *auth_ids[3]; u8 *s; /* Signature */ - u8 *digest; + u8 *m; /* Message data to pass to verifier */ u32 s_size; /* Number of bytes in signature */ - u32 digest_size; /* Number of bytes in digest */ + u32 m_size; /* Number of bytes in ->m */ const char *pkey_algo; const char *hash_algo; const char *encoding; diff --git a/security/integrity/digsig_asymmetric.c b/security/integrity/digsig_asymmetric.c index 457c0a396caf..87be85f477d1 100644 --- a/security/integrity/digsig_asymmetric.c +++ b/security/integrity/digsig_asymmetric.c @@ -121,8 +121,8 @@ int asymmetric_verify(struct key *keyring, const char *sig, goto out; } - pks.digest = (u8 *)data; - pks.digest_size = datalen; + pks.m = (u8 *)data; + pks.m_size = datalen; pks.s = hdr->sig; pks.s_size = siglen; ret = verify_signature(key, &pks);
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:08 +0000", "thread_id": "20260202170216.2467036-5-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Allow the data to be verified in a PKCS#7 or CMS message to be passed directly to an asymmetric cipher algorithm (e.g. ML-DSA) if it wants to do whatever passes for hashing/digestion itself. The normal digestion of the data is then skipped as that would be ignored unless another signed info in the message has some other algorithm that needs it. The 'data to be verified' may be the content of the PKCS#7 message or it will be the authenticatedAttributes (signedAttrs if CMS), modified, if those are present. This is done by: (1) Make ->m and ->m_size point to the data to be verified rather than making public_key_verify_signature() access the data directly. This is so that keyctl(KEYCTL_PKEY_VERIFY) will still work. (2) Add a flag, ->algo_takes_data, to indicate that the verification algorithm wants to access the data to be verified directly rather than having it digested first. (3) If the PKCS#7 message has authenticatedAttributes (or CMS signedAttrs), then the digest contained therein will be validated as now, and the modified attrs blob will either be digested or assigned to ->m as appropriate. (4) If present, always copy and modify the authenticatedAttributes (or signedAttrs) then digest that in one go rather than calling the shash update twice (once for the tag and once for the rest). (5) For ML-DSA, point ->m to the TBSCertificate instead of digesting it and using the digest. Note that whilst ML-DSA does allow for an "external mu", CMS doesn't yet have that standardised. Signed-off-by: David Howells <dhowells@redhat.com> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/pkcs7_parser.c | 4 +- crypto/asymmetric_keys/pkcs7_verify.c | 52 ++++++++++++++++-------- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_public_key.c | 10 +++++ include/crypto/public_key.h | 2 + 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c index 423d13c47545..3cdbab3b9f50 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.c +++ b/crypto/asymmetric_keys/pkcs7_parser.c @@ -599,8 +599,8 @@ int pkcs7_sig_note_set_of_authattrs(void *context, size_t hdrlen, } /* We need to switch the 'CONT 0' to a 'SET OF' when we digest */ - sinfo->authattrs = value - (hdrlen - 1); - sinfo->authattrs_len = vlen + (hdrlen - 1); + sinfo->authattrs = value - hdrlen; + sinfo->authattrs_len = vlen + hdrlen; return 0; } diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c index aa085ec6fb1c..06abb9838f95 100644 --- a/crypto/asymmetric_keys/pkcs7_verify.c +++ b/crypto/asymmetric_keys/pkcs7_verify.c @@ -30,6 +30,16 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, kenter(",%u,%s", sinfo->index, sinfo->sig->hash_algo); + if (!sinfo->authattrs && sig->algo_takes_data) { + /* There's no intermediate digest and the signature algo + * doesn't want the data prehashing. + */ + sig->m = (void *)pkcs7->data; + sig->m_size = pkcs7->data_len; + sig->m_free = false; + return 0; + } + /* The digest was calculated already. */ if (sig->m) return 0; @@ -48,9 +58,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, sig->m_size = crypto_shash_digestsize(tfm); ret = -ENOMEM; - sig->m = kmalloc(sig->m_size, GFP_KERNEL); + sig->m = kmalloc(umax(sinfo->authattrs_len, sig->m_size), GFP_KERNEL); if (!sig->m) goto error_no_desc; + sig->m_free = true; desc = kzalloc(desc_size, GFP_KERNEL); if (!desc) @@ -69,8 +80,6 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, * digest we just calculated. */ if (sinfo->authattrs) { - u8 tag; - if (!sinfo->msgdigest) { pr_warn("Sig %u: No messageDigest\n", sinfo->index); ret = -EKEYREJECTED; @@ -96,21 +105,25 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, * as the contents of the digest instead. Note that we need to * convert the attributes from a CONT.0 into a SET before we * hash it. + * + * However, for certain algorithms, such as ML-DSA, the digest + * is integrated into the signing algorithm. In such a case, + * we copy the authattrs, modifying the tag type, and set that + * as the digest. */ - memset(sig->m, 0, sig->m_size); - - - ret = crypto_shash_init(desc); - if (ret < 0) - goto error; - tag = ASN1_CONS_BIT | ASN1_SET; - ret = crypto_shash_update(desc, &tag, 1); - if (ret < 0) - goto error; - ret = crypto_shash_finup(desc, sinfo->authattrs, - sinfo->authattrs_len, sig->m); - if (ret < 0) - goto error; + memcpy(sig->m, sinfo->authattrs, sinfo->authattrs_len); + sig->m[0] = ASN1_CONS_BIT | ASN1_SET; + + if (sig->algo_takes_data) { + sig->m_size = sinfo->authattrs_len; + ret = 0; + } else { + ret = crypto_shash_digest(desc, sig->m, + sinfo->authattrs_len, + sig->m); + if (ret < 0) + goto error; + } pr_devel("AADigest = [%*ph]\n", 8, sig->m); } @@ -137,6 +150,11 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len, ret = pkcs7_digest(pkcs7, sinfo); if (ret) return ret; + if (!sinfo->sig->m_free) { + pr_notice_once("%s: No digest available\n", __func__); + return -EINVAL; /* TODO: MLDSA doesn't necessarily calculate an + * intermediate digest. */ + } *buf = sinfo->sig->m; *len = sinfo->sig->m_size; diff --git a/crypto/asymmetric_keys/signature.c b/crypto/asymmetric_keys/signature.c index f4ec126121b3..a5ac7a53b670 100644 --- a/crypto/asymmetric_keys/signature.c +++ b/crypto/asymmetric_keys/signature.c @@ -28,7 +28,8 @@ void public_key_signature_free(struct public_key_signature *sig) for (i = 0; i < ARRAY_SIZE(sig->auth_ids); i++) kfree(sig->auth_ids[i]); kfree(sig->s); - kfree(sig->m); + if (sig->m_free) + kfree(sig->m); kfree(sig); } } diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c index 3854f7ae4ed0..27b4fea37845 100644 --- a/crypto/asymmetric_keys/x509_public_key.c +++ b/crypto/asymmetric_keys/x509_public_key.c @@ -50,6 +50,14 @@ int x509_get_sig_params(struct x509_certificate *cert) sig->s_size = cert->raw_sig_size; + if (sig->algo_takes_data) { + /* The signature algorithm does whatever passes for hashing. */ + sig->m = (u8 *)cert->tbs; + sig->m_size = cert->tbs_size; + sig->m_free = false; + goto out; + } + /* Allocate the hashing algorithm we're going to need and find out how * big the hash operational data will be. */ @@ -69,6 +77,7 @@ int x509_get_sig_params(struct x509_certificate *cert) sig->m = kmalloc(sig->m_size, GFP_KERNEL); if (!sig->m) goto error; + sig->m_free = true; desc = kzalloc(desc_size, GFP_KERNEL); if (!desc) @@ -84,6 +93,7 @@ int x509_get_sig_params(struct x509_certificate *cert) kfree(desc); error: crypto_free_shash(tfm); +out: pr_devel("<==%s() = %d\n", __func__, ret); return ret; } diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h index bd38ba4d217d..4c5199b20338 100644 --- a/include/crypto/public_key.h +++ b/include/crypto/public_key.h @@ -46,6 +46,8 @@ struct public_key_signature { u8 *m; /* Message data to pass to verifier */ u32 s_size; /* Number of bytes in signature */ u32 m_size; /* Number of bytes in ->m */ + bool m_free; /* T if ->m needs freeing */ + bool algo_takes_data; /* T if public key algo operates on data, not a hash */ const char *pkey_algo; const char *hash_algo; const char *encoding;
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:09 +0000", "thread_id": "20260202170216.2467036-5-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Add support for ML-DSA keys and signatures to the CMS/PKCS#7 and X.509 implementations. ML-DSA-44, -65 and -87 are all supported. For X.509 certificates, the TBSCertificate is required to be signed directly; for CMS, direct signing of the data is preferred, though use of SHA512 (and only that) as an intermediate hash of the content is permitted with signedAttrs. Signed-off-by: David Howells <dhowells@redhat.com> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/pkcs7_parser.c | 24 +++++++++++++++++++- crypto/asymmetric_keys/public_key.c | 10 +++++++++ crypto/asymmetric_keys/x509_cert_parser.c | 27 ++++++++++++++++++++++- include/linux/oid_registry.h | 5 +++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c index 3cdbab3b9f50..594a8f1d9dfb 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.c +++ b/crypto/asymmetric_keys/pkcs7_parser.c @@ -95,11 +95,18 @@ static int pkcs7_check_authattrs(struct pkcs7_message *msg) if (sinfo->authattrs) { want = true; msg->have_authattrs = true; + } else if (sinfo->sig->algo_takes_data) { + sinfo->sig->hash_algo = "none"; } - for (sinfo = sinfo->next; sinfo; sinfo = sinfo->next) + for (sinfo = sinfo->next; sinfo; sinfo = sinfo->next) { if (!!sinfo->authattrs != want) goto inconsistent; + + if (!sinfo->authattrs && + sinfo->sig->algo_takes_data) + sinfo->sig->hash_algo = "none"; + } return 0; inconsistent: @@ -297,6 +304,21 @@ int pkcs7_sig_note_pkey_algo(void *context, size_t hdrlen, ctx->sinfo->sig->pkey_algo = "ecrdsa"; ctx->sinfo->sig->encoding = "raw"; break; + case OID_id_ml_dsa_44: + ctx->sinfo->sig->pkey_algo = "mldsa44"; + ctx->sinfo->sig->encoding = "raw"; + ctx->sinfo->sig->algo_takes_data = true; + break; + case OID_id_ml_dsa_65: + ctx->sinfo->sig->pkey_algo = "mldsa65"; + ctx->sinfo->sig->encoding = "raw"; + ctx->sinfo->sig->algo_takes_data = true; + break; + case OID_id_ml_dsa_87: + ctx->sinfo->sig->pkey_algo = "mldsa87"; + ctx->sinfo->sig->encoding = "raw"; + ctx->sinfo->sig->algo_takes_data = true; + break; default: printk("Unsupported pkey algo: %u\n", ctx->last_oid); return -ENOPKG; diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c index a46356e0c08b..09a0b83d5d77 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c @@ -142,6 +142,16 @@ software_key_determine_akcipher(const struct public_key *pkey, if (strcmp(hash_algo, "streebog256") != 0 && strcmp(hash_algo, "streebog512") != 0) return -EINVAL; + } else if (strcmp(pkey->pkey_algo, "mldsa44") == 0 || + strcmp(pkey->pkey_algo, "mldsa65") == 0 || + strcmp(pkey->pkey_algo, "mldsa87") == 0) { + if (strcmp(encoding, "raw") != 0) + return -EINVAL; + if (!hash_algo) + return -EINVAL; + if (strcmp(hash_algo, "none") != 0 && + strcmp(hash_algo, "sha512") != 0) + return -EINVAL; } else { /* Unknown public key algorithm */ return -ENOPKG; diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c index b37cae914987..2fe094f5caf3 100644 --- a/crypto/asymmetric_keys/x509_cert_parser.c +++ b/crypto/asymmetric_keys/x509_cert_parser.c @@ -257,6 +257,15 @@ int x509_note_sig_algo(void *context, size_t hdrlen, unsigned char tag, case OID_gost2012Signature512: ctx->cert->sig->hash_algo = "streebog512"; goto ecrdsa; + case OID_id_ml_dsa_44: + ctx->cert->sig->pkey_algo = "mldsa44"; + goto ml_dsa; + case OID_id_ml_dsa_65: + ctx->cert->sig->pkey_algo = "mldsa65"; + goto ml_dsa; + case OID_id_ml_dsa_87: + ctx->cert->sig->pkey_algo = "mldsa87"; + goto ml_dsa; } rsa_pkcs1: @@ -274,6 +283,12 @@ int x509_note_sig_algo(void *context, size_t hdrlen, unsigned char tag, ctx->cert->sig->encoding = "x962"; ctx->sig_algo = ctx->last_oid; return 0; +ml_dsa: + ctx->cert->sig->algo_takes_data = true; + ctx->cert->sig->hash_algo = "none"; + ctx->cert->sig->encoding = "raw"; + ctx->sig_algo = ctx->last_oid; + return 0; } /* @@ -300,7 +315,8 @@ int x509_note_signature(void *context, size_t hdrlen, if (strcmp(ctx->cert->sig->pkey_algo, "rsa") == 0 || strcmp(ctx->cert->sig->pkey_algo, "ecrdsa") == 0 || - strcmp(ctx->cert->sig->pkey_algo, "ecdsa") == 0) { + strcmp(ctx->cert->sig->pkey_algo, "ecdsa") == 0 || + strncmp(ctx->cert->sig->pkey_algo, "mldsa", 5) == 0) { /* Discard the BIT STRING metadata */ if (vlen < 1 || *(const u8 *)value != 0) return -EBADMSG; @@ -524,6 +540,15 @@ int x509_extract_key_data(void *context, size_t hdrlen, return -ENOPKG; } break; + case OID_id_ml_dsa_44: + ctx->cert->pub->pkey_algo = "mldsa44"; + break; + case OID_id_ml_dsa_65: + ctx->cert->pub->pkey_algo = "mldsa65"; + break; + case OID_id_ml_dsa_87: + ctx->cert->pub->pkey_algo = "mldsa87"; + break; default: return -ENOPKG; } diff --git a/include/linux/oid_registry.h b/include/linux/oid_registry.h index 6de479ebbe5d..ebce402854de 100644 --- a/include/linux/oid_registry.h +++ b/include/linux/oid_registry.h @@ -145,6 +145,11 @@ enum OID { OID_id_rsassa_pkcs1_v1_5_with_sha3_384, /* 2.16.840.1.101.3.4.3.15 */ OID_id_rsassa_pkcs1_v1_5_with_sha3_512, /* 2.16.840.1.101.3.4.3.16 */ + /* NIST FIPS-204 ML-DSA */ + OID_id_ml_dsa_44, /* 2.16.840.1.101.3.4.3.17 */ + OID_id_ml_dsa_65, /* 2.16.840.1.101.3.4.3.18 */ + OID_id_ml_dsa_87, /* 2.16.840.1.101.3.4.3.19 */ + OID__NR };
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:10 +0000", "thread_id": "20260202170216.2467036-5-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Allow ML-DSA module signing to be enabled. Note that OpenSSL's CMS_*() function suite does not, as of OpenSSL-3.6, support the use of CMS_NOATTR with ML-DSA, so the prohibition against using signedAttrs with module signing has to be removed. The selected digest then applies only to the algorithm used to calculate the digest stored in the messageDigest attribute. The OpenSSL development branch has patches applied that fix this[1], but it appears that that will only be available in OpenSSL-4. [1] https://github.com/openssl/openssl/pull/28923 sign-file won't set CMS_NOATTR if openssl is earlier than v4, resulting in the use of signed attributes. The ML-DSA algorithm takes the raw data to be signed without regard to what digest algorithm is specified in the CMS message. The CMS specified digest algorithm is ignored unless signedAttrs are used; in such a case, only SHA512 is permitted. Signed-off-by: David Howells <dhowells@redhat.com> cc: Jarkko Sakkinen <jarkko@kernel.org> cc: Eric Biggers <ebiggers@kernel.org> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- Documentation/admin-guide/module-signing.rst | 16 ++++---- certs/Kconfig | 40 ++++++++++++++++++++ certs/Makefile | 3 ++ scripts/sign-file.c | 39 ++++++++++++++----- 4 files changed, 82 insertions(+), 16 deletions(-) diff --git a/Documentation/admin-guide/module-signing.rst b/Documentation/admin-guide/module-signing.rst index a8667a777490..7f2f127dc76f 100644 --- a/Documentation/admin-guide/module-signing.rst +++ b/Documentation/admin-guide/module-signing.rst @@ -28,10 +28,12 @@ trusted userspace bits. This facility uses X.509 ITU-T standard certificates to encode the public keys involved. The signatures are not themselves encoded in any industrial standard -type. The built-in facility currently only supports the RSA & NIST P-384 ECDSA -public key signing standard (though it is pluggable and permits others to be -used). The possible hash algorithms that can be used are SHA-2 and SHA-3 of -sizes 256, 384, and 512 (the algorithm is selected by data in the signature). +type. The built-in facility currently only supports the RSA, NIST P-384 ECDSA +and NIST FIPS-204 ML-DSA public key signing standards (though it is pluggable +and permits others to be used). For RSA and ECDSA, the possible hash +algorithms that can be used are SHA-2 and SHA-3 of sizes 256, 384, and 512 (the +algorithm is selected by data in the signature); ML-DSA does its own hashing, +but is allowed to be used with a SHA512 hash for signed attributes. ========================== @@ -146,9 +148,9 @@ into vmlinux) using parameters in the:: file (which is also generated if it does not already exist). -One can select between RSA (``MODULE_SIG_KEY_TYPE_RSA``) and ECDSA -(``MODULE_SIG_KEY_TYPE_ECDSA``) to generate either RSA 4k or NIST -P-384 keypair. +One can select between RSA (``MODULE_SIG_KEY_TYPE_RSA``), ECDSA +(``MODULE_SIG_KEY_TYPE_ECDSA``) and ML-DSA (``MODULE_SIG_KEY_TYPE_MLDSA_*``) to +generate an RSA 4k, a NIST P-384 keypair or an ML-DSA 44, 65 or 87 keypair. It is strongly recommended that you provide your own x509.genkey file. diff --git a/certs/Kconfig b/certs/Kconfig index 78307dc25559..8e39a80c7abe 100644 --- a/certs/Kconfig +++ b/certs/Kconfig @@ -39,6 +39,39 @@ config MODULE_SIG_KEY_TYPE_ECDSA Note: Remove all ECDSA signing keys, e.g. certs/signing_key.pem, when falling back to building Linux 5.14 and older kernels. +config MODULE_SIG_KEY_TYPE_MLDSA_44 + bool "ML-DSA-44" + select CRYPTO_MLDSA + depends on OPENSSL_SUPPORTS_ML_DSA + help + Use an ML-DSA-44 key (NIST FIPS 204) for module signing. ML-DSA + support requires OpenSSL-3.5 minimum; preferably OpenSSL-4+. With + the latter, the entire module body will be signed; with the former, + signedAttrs will be used as it lacks support for CMS_NOATTR with + ML-DSA. + +config MODULE_SIG_KEY_TYPE_MLDSA_65 + bool "ML-DSA-65" + select CRYPTO_MLDSA + depends on OPENSSL_SUPPORTS_ML_DSA + help + Use an ML-DSA-65 key (NIST FIPS 204) for module signing. ML-DSA + support requires OpenSSL-3.5 minimum; preferably OpenSSL-4+. With + the latter, the entire module body will be signed; with the former, + signedAttrs will be used as it lacks support for CMS_NOATTR with + ML-DSA. + +config MODULE_SIG_KEY_TYPE_MLDSA_87 + bool "ML-DSA-87" + select CRYPTO_MLDSA + depends on OPENSSL_SUPPORTS_ML_DSA + help + Use an ML-DSA-87 key (NIST FIPS 204) for module signing. ML-DSA + support requires OpenSSL-3.5 minimum; preferably OpenSSL-4+. With + the latter, the entire module body will be signed; with the former, + signedAttrs will be used as it lacks support for CMS_NOATTR with + ML-DSA. + endchoice config SYSTEM_TRUSTED_KEYRING @@ -154,4 +187,11 @@ config SYSTEM_BLACKLIST_AUTH_UPDATE keyring. The PKCS#7 signature of the description is set in the key payload. Blacklist keys cannot be removed. +config OPENSSL_SUPPORTS_ML_DSA + def_bool $(success, openssl list -key-managers | grep -q ML-DSA-87) + help + Support for ML-DSA-44/65/87 was added in openssl-3.5, so as long + as older versions are supported, the key types may only be + set after testing the installed binary for support. + endmenu diff --git a/certs/Makefile b/certs/Makefile index f6fa4d8d75e0..3ee1960f9f4a 100644 --- a/certs/Makefile +++ b/certs/Makefile @@ -43,6 +43,9 @@ targets += x509_certificate_list ifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_key.pem) keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 +keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_MLDSA_44) := -newkey ml-dsa-44 +keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_MLDSA_65) := -newkey ml-dsa-65 +keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_MLDSA_87) := -newkey ml-dsa-87 quiet_cmd_gen_key = GENKEY $@ cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ diff --git a/scripts/sign-file.c b/scripts/sign-file.c index 7070245edfc1..78276b15ab23 100644 --- a/scripts/sign-file.c +++ b/scripts/sign-file.c @@ -27,7 +27,7 @@ #include <openssl/evp.h> #include <openssl/pem.h> #include <openssl/err.h> -#if OPENSSL_VERSION_MAJOR >= 3 +#if OPENSSL_VERSION_NUMBER >= 0x30000000L # define USE_PKCS11_PROVIDER # include <openssl/provider.h> # include <openssl/store.h> @@ -315,18 +315,39 @@ int main(int argc, char **argv) ERR(!digest_algo, "EVP_get_digestbyname"); #ifndef USE_PKCS7 + + unsigned int flags = + CMS_NOCERTS | + CMS_PARTIAL | + CMS_BINARY | + CMS_DETACHED | + CMS_STREAM | + CMS_NOSMIMECAP | +#ifdef CMS_NO_SIGNING_TIME + CMS_NO_SIGNING_TIME | +#endif + use_keyid; + +#if OPENSSL_VERSION_NUMBER >= 0x30000000L && OPENSSL_VERSION_NUMBER < 0x40000000L + if (EVP_PKEY_is_a(private_key, "ML-DSA-44") || + EVP_PKEY_is_a(private_key, "ML-DSA-65") || + EVP_PKEY_is_a(private_key, "ML-DSA-87")) { + /* ML-DSA + CMS_NOATTR is not supported in openssl-3.5 + * and before. + */ + use_signed_attrs = 0; + } +#endif + + flags |= use_signed_attrs; + /* Load the signature message from the digest buffer. */ - cms = CMS_sign(NULL, NULL, NULL, NULL, - CMS_NOCERTS | CMS_PARTIAL | CMS_BINARY | - CMS_DETACHED | CMS_STREAM); + cms = CMS_sign(NULL, NULL, NULL, NULL, flags); ERR(!cms, "CMS_sign"); - ERR(!CMS_add1_signer(cms, x509, private_key, digest_algo, - CMS_NOCERTS | CMS_BINARY | - CMS_NOSMIMECAP | use_keyid | - use_signed_attrs), + ERR(!CMS_add1_signer(cms, x509, private_key, digest_algo, flags), "CMS_add1_signer"); - ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) != 1, + ERR(CMS_final(cms, bm, NULL, flags) != 1, "CMS_final"); #else
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:11 +0000", "thread_id": "20260202170216.2467036-5-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH v16 0/7] x509, pkcs7, crypto: Add ML-DSA signing
Hi Lukas, Ignat, [Note this is based on Eric Bigger's libcrypto-next branch]. These patches add ML-DSA module signing signing: (1) Add a crypto_sig interface for ML-DSA, verification only. (2) Generate a SHA256 hash of the X.509 TBSCertificate and check that in the blacklist. Direct-sign ML-DSA doesn't generate an easily accessible hash. Note that this changes behaviour as we no longer use whatever hash is specified in the certificate for this. (3) Rename the public_key_signature struct's "digest" and "digest_size" members to "m" and "m_size" to reflect that it's not necessarily a digest, but it is an input to the public key algorithm. (4) Modify PKCS#7 support to allow kernel module signatures to carry authenticatedAttributes as OpenSSL refuses to let them be opted out of for ML-DSA (CMS_NOATTR). This adds an extra digest calculation to the process. Modify PKCS#7 to pass the authenticatedAttributes directly to the ML-DSA algorithm rather than passing over a digest as is done with RSA as ML-DSA wants to do its own hashing and will add other stuff into the hash. We could use hashML-DSA or an external mu instead, but they aren't standardised for CMS yet. (5) Add support to the PKCS#7 and X.509 parsers for ML-DSA. (6) Modify sign-file to handle OpenSSL not permitting CMS_NOATTR with ML-DSA and add ML-DSA to the choice of algorithm with which to sign modules. Note that this might need some more 'select' lines in the Kconfig to select the lib stuff as well. (7) Add a config option to allow authenticatedAttributes to be used with ML-DSA for module signing. Ordinarily, authenticatedAttributes are not permitted for this purpose, however direct signing with ML-DSA will not be supported by OpenSSL until v4 is released. The patches can also be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-pqc David Changes ======= ver #16) - Make the selection of ML-DSA for module signing when configuring contingent on openssl saying it supports ML-DSA (fix from Arnd Bergmann). - Make ML-DSA-related bits of sign-file contingent on openssl >= 3.0.0. ver #15) - Undo a removed blank line to simplify the X.509 patch. - Split the rename of ->digest to ->m into its own patch. - In pkcs7_digest(), always copy the signedAttrs and modify rather than passing the replacement tag byte in a separate shash update call to the rest of the data. That way the ->m buffer is very likely to be optimally aligned for the crypto. - Only allow authenticatedAttributes with ML-DSA for module signing and only if permission is given in the kernel config. ver #14) - public_key: - Rename public_key::digest to public_key::m. - X.509: - Independently calculate the SHA256 hash for the blacklist check as an ML-DSA-signed X.509 cert doesn't generate a digest we can use. - Point public_key::m at the TBS data for ML-DSA. - PKCS#7: - Allocate a big enough digest buffer rather than reallocating in order to store the authattrs/signedattrs instead. - Merge the two patches that add direct signing support. - ML-DSA: - Use bool instead of u8. - Remove references to SHAKE in Kconfig and mention OpenSSL requirements there. - Limit ML-DSA with an intermediate hash (e.g. signedAttrs) to using SHA512 only. - Don't select CRYPTO_LIB_SHA3 for CRYPTO_MLDSA. - RSASSA-PSS: - Allow use with SHA256 and SHA384. - Fix calculation of emBits to be number of bits in the RSA modulus 'n'. - Use strncmp() not memcmp() to avoid reading beyond end of string. - Use correct destructor in rsassa_params_parse(). - Drop this algo for the moment. - Drop the pefile_context::digest_free for now - it's only set to true and is unrelated to public_key::digest_free. ver #13) - Allow a zero-length salt in RSASSA-PSS. - Don't reject ECDSA/ECRDSA with SHA256 and SHA384 otherwise the FIPS selftest panics when used. - Add a FIPS test for RSASSA-PSS (from NIST's SigVerPSS_186-3.rsp). - Add a FIPS test for ML-DSA (from NIST's FIPS204 JSON set). ver #12) - Rebased on Eric's libcrypto-next branch. - Delete references to Dilithium (ML-DSA derived from this). - Made sign-file supply CMS_NOATTR for ML-DSA if openssl >= v4. - Made it possible to do ML-DSA over the data without signedAttrs. - Made RSASSA-PSS info parser use strsep() and match_token(). - Cleaned the RSASSA-PSS param parsing. - Added limitation on what hashes can be used with what algos. - Moved __free()-marked variables to the point of setting. ver #11) - Rebased on Eric's libcrypto-next branch. - Added RSASSA-PSS support patches. ver #10) - Replaced the Leancrypto ML-DSA implementation with Eric's. - Fixed Eric's implementation to have MODULE_* info. - Added a patch to drive Eric's ML-DSA implementation from crypto_sig. - Removed SHAKE256 from the list of available module hash algorithms. - Changed a some more ML_DSA to MLDSA in config symbols. ver #9) - ML-DSA changes: - Separate output into four modules (1 common, 3 strength-specific). - Solves Kconfig issue with needing to select at least one strength. - Separate the strength-specific crypto-lib APIs. - This is now generated by preprocessor-templating. - Remove the multiplexor code. - Multiplex the crypto-lib APIs by C type. - Fix the PKCS#7/X.509 code to have the correct algo names. ver #8) - Moved the ML-DSA code to lib/crypto/mldsa/. - Renamed some bits from ml-dsa to mldsa. - Created a simplified API and placed that in include/crypto/mldsa.h. - Made the testing code use the simplified API. - Fixed a warning about implicitly casting between uint16_t and __le16. ver #7) - Rebased on Eric's tree as that now contains all the necessary SHA-3 infrastructure and drop the SHA-3 patches from here. - Added a minimal patch to provide shake256 support for crypto_sig. - Got rid of the memory allocation wrappers. - Removed the ML-DSA keypair generation code and the signing code, leaving only the signature verification code. - Removed the secret key handling code. - Removed the secret keys from the kunit tests and the signing testing. - Removed some unused bits from the ML-DSA code. - Downgraded the kdoc comments to ordinary comments, but keep the markup for easier comparison to Leancrypto. ver #6) - Added a patch to make the jitterentropy RNG use lib/sha3. - Added back the crypto/sha3_generic changes. - Added ML-DSA implementation (still needs more cleanup). - Added kunit test for ML-DSA. - Modified PKCS#7 to accommodate ML-DSA. - Modified PKCS#7 and X.509 to allow ML-DSA to be specified and used. - Modified sign-file to not use CMS_NOATTR with ML-DSA. - Allowed SHA3 and SHAKE* algorithms for module signing default. - Allowed ML-DSA-{44,65,87} to be selected as the module signing default. ver #5) - Fix gen-hash-testvecs.py to correctly handle algo names that contain a dash. - Fix gen-hash-testvecs.py to not generate HMAC for SHA3-* or SHAKE* as these don't currently have HMAC variants implemented. - Fix algo names to be correct. - Fix kunit module description as it now tests all SHA3 variants. ver #4) - Fix a couple of arm64 build problems. - Doc fixes: - Fix the description of the algorithm to be closer to the NIST spec's terminology. - Don't talk of finialising the context for XOFs. - Don't say "Return: None". - Declare the "Context" to be "Any context" and make no mention of the fact that it might use the FPU. - Change "initialise" to "initialize". - Don't warn that the context is relatively large for stack use. - Use size_t for size parameters/variables. - Make the module_exit unconditional. - Dropped the crypto/ dir-affecting patches for the moment. ver #3) - Renamed conflicting arm64 functions. - Made a separate wrapper API for each algorithm in the family. - Removed sha3_init(), sha3_reinit() and sha3_final(). - Removed sha3_ctx::digest_size. - Renamed sha3_ctx::partial to sha3_ctx::absorb_offset. - Refer to the output of SHAKE* as "output" not "digest". - Moved the Iota transform into the one-round function. - Made sha3_update() warn if called after sha3_squeeze(). - Simplified the module-load test to not do update after squeeze. - Added Return: and Context: kdoc statements and expanded the kdoc headers. - Added an API description document. - Overhauled the kunit tests. - Only have one kunit test. - Only call the general hash tester on one algo. - Add separate simple cursory checks for the other algos. - Add resqueezing tests. - Add some NIST example tests. - Changed crypto/sha3_generic to use this - Added SHAKE128/256 to crypto/sha3_generic and crypto/testmgr - Folded struct sha3_state into struct sha3_ctx. ver #2) - Simplify the endianness handling. - Rename sha3_final() to sha3_squeeze() and don't clear the context at the end as it's permitted to continue calling sha3_final() to extract continuations of the digest (needed by ML-DSA). - Don't reapply the end marker to the hash state in continuation sha3_squeeze() unless sha3_update() gets called again (needed by ML-DSA). - Give sha3_squeeze() the amount of digest to produce as a parameter rather than using ctx->digest_size and don't return the amount digested. - Reimplement sha3_final() as a wrapper around sha3_squeeze() that extracts ctx->digest_size amount of digest and then zeroes out the context. The latter is necessary to avoid upsetting hash-test-template.h. - Provide a sha3_reinit() function to clear the state, but to leave the parameters that indicate the hash properties unaffected, allowing for reuse. - Provide a sha3_set_digestsize() function to change the size of the digest to be extracted by sha3_final(). sha3_squeeze() takes a parameter for this instead. - Don't pass the digest size as a parameter to shake128/256_init() but rather default to 128/256 bits as per the function name. - Provide a sha3_clear() function to zero out the context. David Howells (7): crypto: Add ML-DSA crypto_sig support x509: Separately calculate sha256 for blacklist pkcs7, x509: Rename ->digest to ->m pkcs7: Allow the signing algo to do whatever digestion it wants itself pkcs7, x509: Add ML-DSA support modsign: Enable ML-DSA module signing pkcs7: Allow authenticatedAttributes for ML-DSA Documentation/admin-guide/module-signing.rst | 16 +- certs/Kconfig | 40 ++++ certs/Makefile | 3 + crypto/Kconfig | 9 + crypto/Makefile | 2 + crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/asymmetric_type.c | 4 +- crypto/asymmetric_keys/pkcs7_parser.c | 36 +++- crypto/asymmetric_keys/pkcs7_parser.h | 3 + crypto/asymmetric_keys/pkcs7_verify.c | 78 ++++--- crypto/asymmetric_keys/public_key.c | 13 +- crypto/asymmetric_keys/signature.c | 3 +- crypto/asymmetric_keys/x509_cert_parser.c | 27 ++- crypto/asymmetric_keys/x509_parser.h | 2 + crypto/asymmetric_keys/x509_public_key.c | 42 ++-- crypto/mldsa.c | 201 +++++++++++++++++++ include/crypto/public_key.h | 6 +- include/linux/oid_registry.h | 5 + scripts/sign-file.c | 39 +++- security/integrity/digsig_asymmetric.c | 4 +- 20 files changed, 473 insertions(+), 71 deletions(-) create mode 100644 crypto/mldsa.c
Allow the rejection of authenticatedAttributes in PKCS#7 (signedAttrs in CMS) to be waived in the kernel config for ML-DSA when used for module signing. This reflects the issue that openssl < 4.0 cannot do this and openssl-4 has not yet been released. This does not permit RSA, ECDSA or ECRDSA to be so waived (behaviour unchanged). Signed-off-by: David Howells <dhowells@redhat.com> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Jarkko Sakkinen <jarkko@kernel.org> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org --- crypto/asymmetric_keys/Kconfig | 11 +++++++++++ crypto/asymmetric_keys/pkcs7_parser.c | 8 ++++++++ crypto/asymmetric_keys/pkcs7_parser.h | 3 +++ crypto/asymmetric_keys/pkcs7_verify.c | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/crypto/asymmetric_keys/Kconfig b/crypto/asymmetric_keys/Kconfig index e1345b8f39f1..1dae2232fe9a 100644 --- a/crypto/asymmetric_keys/Kconfig +++ b/crypto/asymmetric_keys/Kconfig @@ -53,6 +53,17 @@ config PKCS7_MESSAGE_PARSER This option provides support for parsing PKCS#7 format messages for signature data and provides the ability to verify the signature. +config PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + bool "Waive rejection of authenticatedAttributes for ML-DSA" + depends on PKCS7_MESSAGE_PARSER + depends on CRYPTO_MLDSA + help + Due to use of CMS_NOATTR with ML-DSA not being supported in + OpenSSL < 4.0 (and thus any released version), enabling this + allows authenticatedAttributes to be used with ML-DSA for + module signing. Use of authenticatedAttributes in this + context is normally rejected. + config PKCS7_TEST_KEY tristate "PKCS#7 testing key type" depends on SYSTEM_DATA_VERIFICATION diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c index 594a8f1d9dfb..db1c90ca6fc1 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.c +++ b/crypto/asymmetric_keys/pkcs7_parser.c @@ -92,9 +92,17 @@ static int pkcs7_check_authattrs(struct pkcs7_message *msg) if (!sinfo) goto inconsistent; +#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + msg->authattrs_rej_waivable = true; +#endif + if (sinfo->authattrs) { want = true; msg->have_authattrs = true; +#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + if (strncmp(sinfo->sig->pkey_algo, "mldsa", 5) != 0) + msg->authattrs_rej_waivable = false; +#endif } else if (sinfo->sig->algo_takes_data) { sinfo->sig->hash_algo = "none"; } diff --git a/crypto/asymmetric_keys/pkcs7_parser.h b/crypto/asymmetric_keys/pkcs7_parser.h index e17f7ce4fb43..6ef9f335bb17 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.h +++ b/crypto/asymmetric_keys/pkcs7_parser.h @@ -55,6 +55,9 @@ struct pkcs7_message { struct pkcs7_signed_info *signed_infos; u8 version; /* Version of cert (1 -> PKCS#7 or CMS; 3 -> CMS) */ bool have_authattrs; /* T if have authattrs */ +#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + bool authattrs_rej_waivable; /* T if authatts rejection can be waived */ +#endif /* Content Data (or NULL) */ enum OID data_type; /* Type of Data */ diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c index 06abb9838f95..519eecfe6778 100644 --- a/crypto/asymmetric_keys/pkcs7_verify.c +++ b/crypto/asymmetric_keys/pkcs7_verify.c @@ -425,6 +425,12 @@ int pkcs7_verify(struct pkcs7_message *pkcs7, return -EKEYREJECTED; } if (pkcs7->have_authattrs) { +#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA + if (pkcs7->authattrs_rej_waivable) { + pr_warn("Waived invalid module sig (has authattrs)\n"); + break; + } +#endif pr_warn("Invalid module sig (has authattrs)\n"); return -EKEYREJECTED; }
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 2 Feb 2026 17:02:12 +0000", "thread_id": "20260202170216.2467036-5-dhowells@redhat.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in commit f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Commit 16ab7cb5825f ("crypto: pkcs7 - remove sha1 support") previously removed support for reading PKCS#7/CMS signed with SHA-1, along with the ability to use SHA-1 for module signing. This change broke iwd and was subsequently completely reverted in commit 203a6763ab69 ("Revert "crypto: pkcs7 - remove sha1 support""). However, dropping only the support for using SHA-1 for module signing is unrelated and can still be done separately. Note that this change only removes support for new modules to be SHA-1 signed, but already signed modules can still be loaded. Signed-off-by: Petr Pavlu <petr.pavlu@suse.com> --- kernel/module/Kconfig | 5 ----- 1 file changed, 5 deletions(-) diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index 2a1beebf1d37..be74917802ad 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -299,10 +299,6 @@ choice possible to load a signed module containing the algorithm to check the signature on that module. -config MODULE_SIG_SHA1 - bool "SHA-1" - select CRYPTO_SHA1 - config MODULE_SIG_SHA256 bool "SHA-256" select CRYPTO_SHA256 @@ -332,7 +328,6 @@ endchoice config MODULE_SIG_HASH string depends on MODULE_SIG || IMA_APPRAISE_MODSIG - default "sha1" if MODULE_SIG_SHA1 default "sha256" if MODULE_SIG_SHA256 default "sha384" if MODULE_SIG_SHA384 default "sha512" if MODULE_SIG_SHA512 -- 2.51.1
{ "author": "Petr Pavlu <petr.pavlu@suse.com>", "date": "Tue, 11 Nov 2025 16:48:31 +0100", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
The PKCS#7 code in sign-file allows for signing only with SHA-1. Since SHA-1 support for module signing has been removed, drop PKCS#7 support in favor of using only CMS. The use of the PKCS#7 code is selected by the following: #if defined(LIBRESSL_VERSION_NUMBER) || \ OPENSSL_VERSION_NUMBER < 0x10000000L || \ defined(OPENSSL_NO_CMS) #define USE_PKCS7 #endif Looking at the individual ifdefs: * LIBRESSL_VERSION_NUMBER: LibreSSL added the CMS implementation from OpenSSL in 3.1.0, making the ifdef no longer relevant. This version was released on April 8, 2020. * OPENSSL_VERSION_NUMBER < 0x10000000L: OpenSSL 1.0.0 was released on March 29, 2010. Supporting earlier versions should no longer be necessary. The file Documentation/process/changes.rst already states that at least version 1.0.0 is required to build the kernel. * OPENSSL_NO_CMS: OpenSSL can be configured with "no-cms" to disable the CMS support. In this case, sign-file will no longer be usable. The CMS support is now required. In practice, since distributions now typically sign modules with SHA-2, for which sign-file already required CMS support, removing PKCS#7 shouldn't cause any issues. Signed-off-by: Petr Pavlu <petr.pavlu@suse.com> --- scripts/sign-file.c | 66 +++------------------------------------------ 1 file changed, 3 insertions(+), 63 deletions(-) diff --git a/scripts/sign-file.c b/scripts/sign-file.c index 7070245edfc1..16f2bf2e1e3c 100644 --- a/scripts/sign-file.c +++ b/scripts/sign-file.c @@ -24,6 +24,7 @@ #include <arpa/inet.h> #include <openssl/opensslv.h> #include <openssl/bio.h> +#include <openssl/cms.h> #include <openssl/evp.h> #include <openssl/pem.h> #include <openssl/err.h> @@ -39,29 +40,6 @@ #endif #include "ssl-common.h" -/* - * Use CMS if we have openssl-1.0.0 or newer available - otherwise we have to - * assume that it's not available and its header file is missing and that we - * should use PKCS#7 instead. Switching to the older PKCS#7 format restricts - * the options we have on specifying the X.509 certificate we want. - * - * Further, older versions of OpenSSL don't support manually adding signers to - * the PKCS#7 message so have to accept that we get a certificate included in - * the signature message. Nor do such older versions of OpenSSL support - * signing with anything other than SHA1 - so we're stuck with that if such is - * the case. - */ -#if defined(LIBRESSL_VERSION_NUMBER) || \ - OPENSSL_VERSION_NUMBER < 0x10000000L || \ - defined(OPENSSL_NO_CMS) -#define USE_PKCS7 -#endif -#ifndef USE_PKCS7 -#include <openssl/cms.h> -#else -#include <openssl/pkcs7.h> -#endif - struct module_signature { uint8_t algo; /* Public-key crypto algorithm [0] */ uint8_t hash; /* Digest algorithm [0] */ @@ -228,15 +206,10 @@ int main(int argc, char **argv) bool raw_sig = false; unsigned char buf[4096]; unsigned long module_size, sig_size; - unsigned int use_signed_attrs; const EVP_MD *digest_algo; EVP_PKEY *private_key; -#ifndef USE_PKCS7 CMS_ContentInfo *cms = NULL; unsigned int use_keyid = 0; -#else - PKCS7 *pkcs7 = NULL; -#endif X509 *x509; BIO *bd, *bm; int opt, n; @@ -246,21 +219,13 @@ int main(int argc, char **argv) key_pass = getenv("KBUILD_SIGN_PIN"); -#ifndef USE_PKCS7 - use_signed_attrs = CMS_NOATTR; -#else - use_signed_attrs = PKCS7_NOATTR; -#endif - do { opt = getopt(argc, argv, "sdpk"); switch (opt) { case 's': raw_sig = true; break; case 'p': save_sig = true; break; case 'd': sign_only = true; save_sig = true; break; -#ifndef USE_PKCS7 case 'k': use_keyid = CMS_USE_KEYID; break; -#endif case -1: break; default: format(); } @@ -289,14 +254,6 @@ int main(int argc, char **argv) replace_orig = true; } -#ifdef USE_PKCS7 - if (strcmp(hash_algo, "sha1") != 0) { - fprintf(stderr, "sign-file: %s only supports SHA1 signing\n", - OPENSSL_VERSION_TEXT); - exit(3); - } -#endif - /* Open the module file */ bm = BIO_new_file(module_name, "rb"); ERR(!bm, "%s", module_name); @@ -314,7 +271,6 @@ int main(int argc, char **argv) digest_algo = EVP_get_digestbyname(hash_algo); ERR(!digest_algo, "EVP_get_digestbyname"); -#ifndef USE_PKCS7 /* Load the signature message from the digest buffer. */ cms = CMS_sign(NULL, NULL, NULL, NULL, CMS_NOCERTS | CMS_PARTIAL | CMS_BINARY | @@ -323,19 +279,12 @@ int main(int argc, char **argv) ERR(!CMS_add1_signer(cms, x509, private_key, digest_algo, CMS_NOCERTS | CMS_BINARY | - CMS_NOSMIMECAP | use_keyid | - use_signed_attrs), + CMS_NOSMIMECAP | CMS_NOATTR | + use_keyid), "CMS_add1_signer"); ERR(CMS_final(cms, bm, NULL, CMS_NOCERTS | CMS_BINARY) != 1, "CMS_final"); -#else - pkcs7 = PKCS7_sign(x509, private_key, NULL, bm, - PKCS7_NOCERTS | PKCS7_BINARY | - PKCS7_DETACHED | use_signed_attrs); - ERR(!pkcs7, "PKCS7_sign"); -#endif - if (save_sig) { char *sig_file_name; BIO *b; @@ -344,13 +293,8 @@ int main(int argc, char **argv) "asprintf"); b = BIO_new_file(sig_file_name, "wb"); ERR(!b, "%s", sig_file_name); -#ifndef USE_PKCS7 ERR(i2d_CMS_bio_stream(b, cms, NULL, 0) != 1, "%s", sig_file_name); -#else - ERR(i2d_PKCS7_bio(b, pkcs7) != 1, - "%s", sig_file_name); -#endif BIO_free(b); } @@ -377,11 +321,7 @@ int main(int argc, char **argv) module_size = BIO_number_written(bd); if (!raw_sig) { -#ifndef USE_PKCS7 ERR(i2d_CMS_bio_stream(bd, cms, NULL, 0) != 1, "%s", dest_name); -#else - ERR(i2d_PKCS7_bio(bd, pkcs7) != 1, "%s", dest_name); -#endif } else { BIO *b; -- 2.51.1
{ "author": "Petr Pavlu <petr.pavlu@suse.com>", "date": "Tue, 11 Nov 2025 16:48:32 +0100", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
Hi Petr, On Tue, Nov 11, 2025 at 7:49 AM Petr Pavlu <petr.pavlu@suse.com> wrote: It looks like GKI just uses the defaults here. Overall, Android doesn't rely on module signing for security, it's only used to differentiate between module types. Dropping SHA-1 support sounds like a good idea to me. For the series: Reviewed-by: Sami Tolvanen <samitolvanen@google.com> Sami
{ "author": "Sami Tolvanen <samitolvanen@google.com>", "date": "Tue, 11 Nov 2025 08:22:34 -0800", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
On Tue, 2025-11-11 at 16:48 +0100, Petr Pavlu wrote: The change log is a bit alarmist. CMS really *is* PKCS7 and most literature will refer to CMS as PKCS7. What you're really deprecating is the use of the PKCS7_sign() API which can only produce SHA-1 Signatures ... openssl is fully capable of producing any hash PKCS7 signatures using a different PKCS7_... API set but the CMS_... API is newer. The point being the module signature type is still set to PKEY_ID_PKCS7 so it doesn't square with the commit log saying "drop PKCS#7 support". What you really mean is only use the openssl CMS_... API for producing PKCS7 signatures. Regards, James
{ "author": "James Bottomley <James.Bottomley@HansenPartnership.com>", "date": "Tue, 11 Nov 2025 11:53:34 -0500", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
On Tue, Nov 11, 2025 at 04:48:31PM +0100, Petr Pavlu wrote: Agreed. Reviewed-by: Aaron Tomlin <atomlin@atomlin.com> -- Aaron Tomlin
{ "author": "Aaron Tomlin <atomlin@atomlin.com>", "date": "Tue, 11 Nov 2025 17:37:28 -0500", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
On 11/11/25 5:53 PM, James Bottomley wrote: Ok, I plan to update the description to the following in v2: sign-file: Use only the OpenSSL CMS API for signing The USE_PKCS7 code in sign-file utilizes PKCS7_sign(), which allows signing only with SHA-1. Since SHA-1 support for module signing has been removed, drop the use of the OpenSSL PKCS7 API by the tool in favor of using only the newer CMS API. The use of the PKCS7 API is selected by the following: #if defined(LIBRESSL_VERSION_NUMBER) || \ OPENSSL_VERSION_NUMBER < 0x10000000L || \ defined(OPENSSL_NO_CMS) #define USE_PKCS7 #endif Looking at the individual ifdefs: * LIBRESSL_VERSION_NUMBER: LibreSSL added the CMS API implementation from OpenSSL in 3.1.0, making the ifdef no longer relevant. This version was released on April 8, 2020. * OPENSSL_VERSION_NUMBER < 0x10000000L: OpenSSL 1.0.0 was released on March 29, 2010. Supporting earlier versions should no longer be necessary. The file Documentation/process/changes.rst already states that at least version 1.0.0 is required to build the kernel. * OPENSSL_NO_CMS: OpenSSL can be configured with "no-cms" to disable CMS support. In this case, sign-file will no longer be usable. The CMS API support is now required. In practice, since distributions now typically sign modules with SHA-2, for which sign-file already required CMS API support, removing the USE_PKCS7 code shouldn't cause any issues. -- Thanks, Petr
{ "author": "Petr Pavlu <petr.pavlu@suse.com>", "date": "Wed, 12 Nov 2025 14:51:24 +0100", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
On Wed, 2025-11-12 at 14:51 +0100, Petr Pavlu wrote: Much better, thanks! Regards, James
{ "author": "James Bottomley <James.Bottomley@HansenPartnership.com>", "date": "Wed, 12 Nov 2025 10:05:57 -0500", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
Petr Pavlu <petr.pavlu@suse.com> wrote: We're looking at moving to ML-DSA, and the CMS support there is slightly dodgy at the moment, so we need to hold off a bit on this change. Patch 1, removing the option to sign with SHA-1 from the kernel is fine, but doesn't stop things that are signed with SHA-1 from being verified. David
{ "author": "David Howells <dhowells@redhat.com>", "date": "Wed, 12 Nov 2025 15:36:57 +0000", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
On Wed, 2025-11-12 at 15:36 +0000, David Howells wrote: How will removing PKCS7_sign, which can only do sha1 signatures affect that? Is the dodginess that the PKCS7_... API is better than CMS_... for PQS at the moment? In which case we could pretty much do a rip and replace of the CMS_ API if necessary, but that would be a completely separate patch. Regards, James
{ "author": "James Bottomley <James.Bottomley@HansenPartnership.com>", "date": "Wed, 12 Nov 2025 10:47:23 -0500", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
James Bottomley <James.Bottomley@HansenPartnership.com> wrote: OpenSSL-3.5.1's ML-DSA support isn't completely right - in particular CMS_NOATTR is not currently supported. I believe there is a fix in the works there, but I doubt it has made it to all the distributions yet. I'm only asking that we hold off a cycle; that will probably suffice. David
{ "author": "David Howells <dhowells@redhat.com>", "date": "Wed, 12 Nov 2025 15:52:40 +0000", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
On Wed, 2025-11-12 at 15:52 +0000, David Howells wrote: I get that PQC in openssl-3.5 is highly experimental, but that merely means we tell people not to use it for a while. However, what I don't see is how this impacts PKCS7_sign removal. The CMS API can do a sha1 signature if that's what people want and keeping the PKCS7_sign API won't prevent anyone with openssl-3.5 installed from trying a PQ signature. Right but why? Is your thought that we'll have to change the CMS_ code slightly and this might conflict? Regards, James
{ "author": "James Bottomley <James.Bottomley@HansenPartnership.com>", "date": "Wed, 12 Nov 2025 10:58:31 -0500", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
On Tue, 11 Nov 2025 16:48:30 +0100, Petr Pavlu wrote: Applied to modules-next, thanks! [1/2] module: Remove SHA-1 support for module signing commit: 148519a06304af4e6fbb82f20e1a4480e2c1b126 [2/2] sign-file: Use only the OpenSSL CMS API for signing commit: d7afd65b4acc775df872af30948dd7c196587169 Best regards, Sami
{ "author": "Sami Tolvanen <samitolvanen@google.com>", "date": "Mon, 22 Dec 2025 20:24:17 +0000", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
Here's an alternative patch that will allow PKCS#7 with the hash specified on the command line, removing the SHA1 restriction. David --- sign-file, pkcs7: Honour the hash parameter to sign-file Currently, the sign-file program rejects anything other than "sha1" as the hash parameter if it is going to produce a PKCS#7 message-based signature rather than a CMS message-based signature (though it then ignores this argument and uses whatever is selected as the default which might not be SHA1 and may actually reflect whatever is used to sign the X.509 certificate). Fix sign-file to actually use the specified hash when producing a PKCS#7 message rather than just accepting the default. Fixes: 283e8ba2dfde ("MODSIGN: Change from CMS to PKCS#7 signing if the openssl is too old") Signed-off-by: David Howells <dhowells@redhat.com> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Jarkko Sakkinen <jarkko@kernel.org> cc: Stephan Mueller <smueller@chronox.de> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: Eric Biggers <ebiggers@kernel.org> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org diff --git a/scripts/sign-file.c b/scripts/sign-file.c index 547b97097230..f0b7e5616b9a 100644 --- a/scripts/sign-file.c +++ b/scripts/sign-file.c @@ -56,6 +56,7 @@ defined(OPENSSL_NO_CMS) #define USE_PKCS7 #endif +#define USE_PKCS7 #ifndef USE_PKCS7 #include <openssl/cms.h> #else @@ -289,14 +290,6 @@ int main(int argc, char **argv) replace_orig = true; } -#ifdef USE_PKCS7 - if (strcmp(hash_algo, "sha1") != 0) { - fprintf(stderr, "sign-file: %s only supports SHA1 signing\n", - OPENSSL_VERSION_TEXT); - exit(3); - } -#endif - /* Open the module file */ bm = BIO_new_file(module_name, "rb"); ERR(!bm, "%s", module_name); @@ -348,10 +341,17 @@ int main(int argc, char **argv) "CMS_final"); #else - pkcs7 = PKCS7_sign(x509, private_key, NULL, bm, - PKCS7_NOCERTS | PKCS7_BINARY | - PKCS7_DETACHED | use_signed_attrs); + unsigned int flags = + PKCS7_NOCERTS | + PKCS7_BINARY | + PKCS7_DETACHED | + use_signed_attrs; + pkcs7 = PKCS7_sign(NULL, NULL, NULL, bm, flags); ERR(!pkcs7, "PKCS7_sign"); + + ERR(!PKCS7_sign_add_signer(pkcs7, x509, private_key, digest_algo, flags), + "PKS7_sign_add_signer"); + ERR(PKCS7_final(pkcs7, bm, flags) != 1, "PKCS7_final"); #endif if (save_sig) {
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 02 Feb 2026 11:24:22 +0000", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
David Howells <dhowells@redhat.com> wrote: Apologies, that line was so I could debug it and should've been removed. David
{ "author": "David Howells <dhowells@redhat.com>", "date": "Mon, 02 Feb 2026 11:27:39 +0000", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
On 2/2/26 12:24 PM, David Howells wrote: Is it worth keeping this sign-file code that uses the OpenSSL PKCS7 API instead of having only one variant that uses the newer CMS API? -- Thanks, Petr
{ "author": "Petr Pavlu <petr.pavlu@suse.com>", "date": "Mon, 2 Feb 2026 13:25:06 +0100", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/2] module: Remove SHA-1 support for module signing
SHA-1 is considered deprecated and insecure due to vulnerabilities that can lead to hash collisions. Most distributions have already been using SHA-2 for module signing because of this. The default was also changed last year from SHA-1 to SHA-512 in f3b93547b91a ("module: sign with sha512 instead of sha1 by default"). This was not reported to cause any issues. Therefore, it now seems to be a good time to remove SHA-1 support for module signing. Looking at the configs of several distributions [1], it seems only Android still uses SHA-1 for module signing. @Sami, it this correct and is there a specific reason for using SHA-1? Note: The second patch has a minor conflict with the sign-file update in the series "lib/crypto: Add ML-DSA signing" [2]. [1] https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=MODULE_SIG_SHA1&version=be8f5f6abf0b0979be20ee8d9afa2a49a13500b8 [2] https://lore.kernel.org/linux-crypto/61637.1762509938@warthog.procyon.org.uk/ Petr Pavlu (2): module: Remove SHA-1 support for module signing sign-file: Remove support for signing with PKCS#7 kernel/module/Kconfig | 5 ---- scripts/sign-file.c | 66 ++----------------------------------------- 2 files changed, 3 insertions(+), 68 deletions(-) base-commit: 4427259cc7f7571a157fbc9b5011e1ef6fe0a4a8 -- 2.51.1
On Mon, Feb 2, 2026 at 4:25 AM Petr Pavlu <petr.pavlu@suse.com> wrote: I agree that keeping only the CMS variant makes more sense. However, David, please let me know if you'd prefer that I drop the patch removing PKCS7 support from sign-file for now. I assumed you had no further objections since the discussion in the other sub-thread tapered off, but perhaps I misread that. Sami
{ "author": "Sami Tolvanen <samitolvanen@google.com>", "date": "Mon, 2 Feb 2026 09:01:19 -0800", "thread_id": "20251111154923.978181-3-petr.pavlu@suse.com.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
jbd2_inode fields are updated under journal->j_list_lock, but some paths read them without holding the lock (e.g. fast commit helpers and the ordered truncate fast path). Use READ_ONCE() for these lockless reads to correct the concurrency assumptions. Suggested-by: Jan Kara <jack@suse.com> Signed-off-by: Li Chen <me@linux.beauty> --- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 7203d2d2624d..3347d75da2f8 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c @@ -180,7 +180,13 @@ static int journal_wait_on_commit_record(journal_t *journal, /* Send all the data buffers related to an inode */ int jbd2_submit_inode_data(journal_t *journal, struct jbd2_inode *jinode) { - if (!jinode || !(jinode->i_flags & JI_WRITE_DATA)) + unsigned long flags; + + if (!jinode) + return 0; + + flags = READ_ONCE(jinode->i_flags); + if (!(flags & JI_WRITE_DATA)) return 0; trace_jbd2_submit_inode_data(jinode->i_vfs_inode); @@ -191,12 +197,30 @@ EXPORT_SYMBOL(jbd2_submit_inode_data); int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode) { - if (!jinode || !(jinode->i_flags & JI_WAIT_DATA) || - !jinode->i_vfs_inode || !jinode->i_vfs_inode->i_mapping) + struct address_space *mapping; + struct inode *inode; + unsigned long flags; + loff_t start, end; + + if (!jinode) + return 0; + + flags = READ_ONCE(jinode->i_flags); + if (!(flags & JI_WAIT_DATA)) + return 0; + + inode = READ_ONCE(jinode->i_vfs_inode); + if (!inode) + return 0; + + mapping = inode->i_mapping; + start = READ_ONCE(jinode->i_dirty_start); + end = READ_ONCE(jinode->i_dirty_end); + + if (!mapping) return 0; return filemap_fdatawait_range_keep_errors( - jinode->i_vfs_inode->i_mapping, jinode->i_dirty_start, - jinode->i_dirty_end); + mapping, start, end); } EXPORT_SYMBOL(jbd2_wait_inode_data); @@ -240,10 +264,11 @@ static int journal_submit_data_buffers(journal_t *journal, int jbd2_journal_finish_inode_data_buffers(struct jbd2_inode *jinode) { struct address_space *mapping = jinode->i_vfs_inode->i_mapping; + loff_t start = READ_ONCE(jinode->i_dirty_start); + loff_t end = READ_ONCE(jinode->i_dirty_end); return filemap_fdatawait_range_keep_errors(mapping, - jinode->i_dirty_start, - jinode->i_dirty_end); + start, end); } /* diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index dca4b5d8aaaa..302b2090eea7 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -2739,7 +2739,7 @@ int jbd2_journal_begin_ordered_truncate(journal_t *journal, int ret = 0; /* This is a quick check to avoid locking if not necessary */ - if (!jinode->i_transaction) + if (!READ_ONCE(jinode->i_transaction)) goto out; /* Locks are here just to force reading of recent values, it is * enough that the transaction was not committing before we started -- 2.52.0
{ "author": "Li Chen <me@linux.beauty>", "date": "Fri, 30 Jan 2026 11:12:30 +0800", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
ext4 journal commit callbacks access jbd2_inode fields such as i_transaction and i_dirty_start/end without holding journal->j_list_lock. Use READ_ONCE() for these reads to correct the concurrency assumptions. Suggested-by: Jan Kara <jack@suse.com> Signed-off-by: Li Chen <me@linux.beauty> --- fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d99296d7315f..2d451388e080 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3033,11 +3033,13 @@ static int ext4_writepages(struct address_space *mapping, int ext4_normal_submit_inode_data_buffers(struct jbd2_inode *jinode) { + loff_t dirty_start = READ_ONCE(jinode->i_dirty_start); + loff_t dirty_end = READ_ONCE(jinode->i_dirty_end); struct writeback_control wbc = { .sync_mode = WB_SYNC_ALL, .nr_to_write = LONG_MAX, - .range_start = jinode->i_dirty_start, - .range_end = jinode->i_dirty_end, + .range_start = dirty_start, + .range_end = dirty_end, }; struct mpage_da_data mpd = { .inode = jinode->i_vfs_inode, diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 5cf6c2b54bbb..acb2bc016fd4 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -521,6 +521,7 @@ static bool ext4_journalled_writepage_needs_redirty(struct jbd2_inode *jinode, { struct buffer_head *bh, *head; struct journal_head *jh; + transaction_t *trans = READ_ONCE(jinode->i_transaction); bh = head = folio_buffers(folio); do { @@ -539,7 +540,7 @@ static bool ext4_journalled_writepage_needs_redirty(struct jbd2_inode *jinode, */ jh = bh2jh(bh); if (buffer_dirty(bh) || - (jh && (jh->b_transaction != jinode->i_transaction || + (jh && (jh->b_transaction != trans || jh->b_next_transaction))) return true; } while ((bh = bh->b_this_page) != head); @@ -550,12 +551,14 @@ static bool ext4_journalled_writepage_needs_redirty(struct jbd2_inode *jinode, static int ext4_journalled_submit_inode_data_buffers(struct jbd2_inode *jinode) { struct address_space *mapping = jinode->i_vfs_inode->i_mapping; + loff_t dirty_start = READ_ONCE(jinode->i_dirty_start); + loff_t dirty_end = READ_ONCE(jinode->i_dirty_end); struct writeback_control wbc = { - .sync_mode = WB_SYNC_ALL, + .sync_mode = WB_SYNC_ALL, .nr_to_write = LONG_MAX, - .range_start = jinode->i_dirty_start, - .range_end = jinode->i_dirty_end, - }; + .range_start = dirty_start, + .range_end = dirty_end, + }; struct folio *folio = NULL; int error; -- 2.52.0
{ "author": "Li Chen <me@linux.beauty>", "date": "Fri, 30 Jan 2026 11:12:31 +0800", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
ocfs2 journal commit callback reads jbd2_inode dirty range fields without holding journal->j_list_lock. Use READ_ONCE() for these reads to correct the concurrency assumptions. Suggested-by: Jan Kara <jack@suse.com> Signed-off-by: Li Chen <me@linux.beauty> --- fs/ocfs2/journal.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index 85239807dec7..7032284cdbd6 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -902,8 +902,11 @@ int ocfs2_journal_alloc(struct ocfs2_super *osb) static int ocfs2_journal_submit_inode_data_buffers(struct jbd2_inode *jinode) { - return filemap_fdatawrite_range(jinode->i_vfs_inode->i_mapping, - jinode->i_dirty_start, jinode->i_dirty_end); + struct address_space *mapping = jinode->i_vfs_inode->i_mapping; + loff_t dirty_start = READ_ONCE(jinode->i_dirty_start); + loff_t dirty_end = READ_ONCE(jinode->i_dirty_end); + + return filemap_fdatawrite_range(mapping, dirty_start, dirty_end); } int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty) -- 2.52.0
{ "author": "Li Chen <me@linux.beauty>", "date": "Fri, 30 Jan 2026 11:12:32 +0800", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
On Fri, Jan 30, 2026 at 11:12:32AM +0800, Li Chen wrote: I don't think this is the right solution to the problem. If it is, there needs to be much better argumentation in the commit message. As I understand it, jbd2_journal_file_inode() initialises jinode, then adds it to the t_inode_list, then drops the j_list_lock. So the actual problem we need to address is that there's no memory barrier between the store to i_dirty_start and the list_add(). Once that's added, there's no need for a READ_ONCE here. Or have I misunderstood the problem?
{ "author": "Matthew Wilcox <willy@infradead.org>", "date": "Fri, 30 Jan 2026 05:27:59 +0000", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
Hi Matthew, > On Fri, Jan 30, 2026 at 11:12:32AM +0800, Li Chen wrote: > > ocfs2 journal commit callback reads jbd2_inode dirty range fields without > > holding journal->j_list_lock. > > > > Use READ_ONCE() for these reads to correct the concurrency assumptions. > > I don't think this is the right solution to the problem. If it is, > there needs to be much better argumentation in the commit message. > > As I understand it, jbd2_journal_file_inode() initialises jinode, > then adds it to the t_inode_list, then drops the j_list_lock. So the > actual problem we need to address is that there's no memory barrier > between the store to i_dirty_start and the list_add(). Once that's > added, there's no need for a READ_ONCE here. > > Or have I misunderstood the problem? Thanks for the review. My understanding of your point is that you're worried about a missing "publish" ordering in jbd2_journal_file_inode(): we store jinode->i_dirty_start/end and then list_add() the jinode to t_inode_list, and a core which observes the list entry might miss the prior i_dirty_* stores. Is that the issue you had in mind? If so, for the normal commit path where the list is walked under journal->j_list_lock (e.g. journal_submit_data_buffers() in fs/jbd2/commit.c), spin_lock()/spin_unlock() should already provide the necessary ordering, since both the i_dirty_* updates and the list_add() happen inside the same critical section. The ocfs2 case I was aiming at is different: the filesystem callback is invoked after unlocking journal->j_list_lock and may sleep, so it can't hold j_list_lock but it still reads jinode->i_dirty_start/end while other threads update these fields under the lock. Adding a barrier between the stores and list_add() would not address that concurrent update window. So the itent of READ_ONCE() in ocfs2 is to take a single snapshot of the dirty range values from memory (avoid compiler to reuse a value kept in a register or fold multiple reads). I'm not trying to claim any additional memory ordering from this change. I'll respin and adjust the commit message accordingly. The updated part will say along the lines of: "ocfs2 reads jinode->i_dirty_start/end without journal->j_list_lock (callback may sleep); these fields are updated under j_list_lock in jbd2. Use READ_ONCE() so the callback takes a single snapshot via actual loads from the variable (i.e. don't let the compiler reuse a value kept in a register or fold multiple reads)." Does that match your understanding? Regards, Li​ > > Suggested-by: Jan Kara <jack@suse.com> > > Signed-off-by: Li Chen <me@linux.beauty> > > --- > > fs/ocfs2/journal.c | 7 +++++-- > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c > > index 85239807dec7..7032284cdbd6 100644 > > --- a/fs/ocfs2/journal.c > > +++ b/fs/ocfs2/journal.c > > @@ -902,8 +902,11 @@ int ocfs2_journal_alloc(struct ocfs2_super *osb) > > > > static int ocfs2_journal_submit_inode_data_buffers(struct jbd2_inode *jinode) > > { > > - return filemap_fdatawrite_range(jinode->i_vfs_inode->i_mapping, > > - jinode->i_dirty_start, jinode->i_dirty_end); > > + struct address_space *mapping = jinode->i_vfs_inode->i_mapping; > > + loff_t dirty_start = READ_ONCE(jinode->i_dirty_start); > > + loff_t dirty_end = READ_ONCE(jinode->i_dirty_end); > > + > > + return filemap_fdatawrite_range(mapping, dirty_start, dirty_end); > > } > > > > int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty) > > -- > > 2.52.0 > > >
{ "author": "Li Chen <me@linux.beauty>", "date": "Fri, 30 Jan 2026 20:26:40 +0800", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
On Fri, Jan 30, 2026 at 08:26:40PM +0800, Li Chen wrote: I think that's the only issue that exists ... I don't think that's true. I think what you're asserting is that: int *pi; int **ppi; spin_lock(&lock); *pi = 1; *ppi = pi; spin_unlock(&lock); that the store to *pi must be observed before the store to *ppi, and that's not true for a reader which doesn't read the value of lock. The store to *ppi needs a store barrier before it. I don't think that race exists. If it does exist, the READ_ONCE will not help (on 32 bit platforms) because it's a 64-bit quantity and 32-bit platforms do not, in general, have a way to do an atomic 64-bit load (look at the implementation of i_size_read() for the gyrations we go through to assure a non-torn read of that value). I think the prevention of this race occurs at a higher level than "it's updated under a lock". That is, jbd2_journal_file_inode() is never called for a jinode which is currently being operated on by j_submit_inode_data_buffers(). Now, I'm not an expert on the jbd code, so I may be wrong here.
{ "author": "Matthew Wilcox <willy@infradead.org>", "date": "Fri, 30 Jan 2026 16:36:28 +0000", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
Hi Matthew, Thank you very much for the detailed explanation and for your patience. On Sat, 31 Jan 2026 00:36:28 +0800, Matthew Wilcox wrote: Understood. Yes, agreed $B!=(B thank you. I was implicitly assuming the reader had taken the same lock at some point, which is not a valid assumption for a lockless reader. Thanks. I tried to sanity-check whether that $B!H(Bnever called$B!I(B invariant holds in practice. I added a small local-only tracepoint (not for upstream) which fires from jbd2_journal_file_inode() when it observes JI_COMMIT_RUNNING already set on the same jinode: /* fs/jbd2/transaction.c */ if (unlikely(jinode->i_flags & JI_COMMIT_RUNNING)) trace_jbd2_file_inode_commit_running(...); The trace event prints dev, ino, current tid, jinode flags, and the i_transaction / i_next_transaction tids. With an ext4 test (ordered mode) I do see repeated hits. Trace output: ... jbd2_submit_inode_data: dev 7,0 ino 20 ... jbd2_file_inode_commit_running: dev 7,0 ino 20 tid 3 op 0x6 i_flags 0x7 j_tid 2 j_next 3 ... comm python3 So it looks like jbd2_journal_file_inode() can run while JI_COMMIT_RUNNING is set for that inode, i.e. during the window where the commit thread drops j_list_lock around ->j_submit_inode_data_buffers() / ->j_finish_inode_data_buffers(). Given this, would you prefer the series to move towards something like: 1. taking a snapshot of i_dirty_start/end under j_list_lock in the commit path and passing the snapshot to the filesystem callback (so callbacks never read jinode->i_dirty_* locklessly), or 2. introducing a real synchronization mechanism for the dirty range itself (seqcount/atomic64/etc)? 3. something else. I$B!G(Bd be very grateful for guidance on what you consider the most appropriate direction or point out something I'm wrong. Thanks again. Regards, Li
{ "author": "Li Chen <me@linux.beauty>", "date": "Sun, 01 Feb 2026 12:37:36 +0800", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
On Fri 30-01-26 11:12:30, Li Chen wrote: Just one nit below. With that fixed feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> i_vfs_inode never changes so READ_ONCE is pointless here. Honza -- Jan Kara <jack@suse.com> SUSE Labs, CR
{ "author": "Jan Kara <jack@suse.cz>", "date": "Mon, 2 Feb 2026 17:40:45 +0100", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
On Fri 30-01-26 11:12:31, Li Chen wrote: Looks good. Feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> Honza -- Jan Kara <jack@suse.com> SUSE Labs, CR
{ "author": "Jan Kara <jack@suse.cz>", "date": "Mon, 2 Feb 2026 17:41:39 +0100", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
On Mon 02-02-26 17:40:45, Jan Kara wrote: One more note: I've realized that for this to work you also need to make jbd2_journal_file_inode() use WRITE_ONCE() when updating i_dirty_start, i_dirty_end and i_flags. Honza -- Jan Kara <jack@suse.com> SUSE Labs, CR
{ "author": "Jan Kara <jack@suse.cz>", "date": "Mon, 2 Feb 2026 17:52:30 +0100", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH 0/3] jbd2/ext4/ocfs2: READ_ONCE for lockless jinode reads
This series adds READ_ONCE() for existing lockless reads of jbd2_inode fields in jbd2 and filesystem callbacks used by ext4 and ocfs2. This is based on Jan's suggestion in the review of the ext4 jinode publication race fix. [1] [1]: https://lore.kernel.org/all/4jxwogttddiaoqbstlgou5ox6zs27ngjjz5ukrxafm2z5ijxod@so4eqnykiegj/ Thanks, Li Li Chen (3): jbd2: use READ_ONCE for lockless jinode reads ext4: use READ_ONCE for lockless jinode reads ocfs2: use READ_ONCE for lockless jinode reads fs/ext4/inode.c | 6 ++++-- fs/ext4/super.c | 13 ++++++++----- fs/jbd2/commit.c | 39 ++++++++++++++++++++++++++++++++------- fs/jbd2/transaction.c | 2 +- fs/ocfs2/journal.c | 7 +++++-- 5 files changed, 50 insertions(+), 17 deletions(-) -- 2.52.0
On Fri 30-01-26 16:36:28, Matthew Wilcox wrote: Well, the above reasonably accurately describes the code making jinode visible. The reader code is like: spin_lock(&lock); pi = *ppi; spin_unlock(&lock); work with pi so it is guaranteed to see pi properly initialized. The problem is that "work with pi" can race with other code updating the content of pi which is what this patch is trying to deal with. Sadly the race does exist - journal_submit_data_buffers() on the committing transaction can run in parallel with jbd2_journal_file_inode() in the running transaction. There's nothing preventing that. The problems arising out of that are mostly theoretical but they do exist. In particular you're correct that on 32-bit platforms this will be racy even with READ_ONCE / WRITE_ONCE which I didn't realize. Li, the best way to address this concern would be to modify jbd2_inode to switch i_dirty_start / i_dirty_end to account in PAGE_SIZE units instead of bytes and be of type pgoff_t. jbd2_journal_file_inode() just needs to round the passed ranges properly... Honza -- Jan Kara <jack@suse.com> SUSE Labs, CR
{ "author": "Jan Kara <jack@suse.cz>", "date": "Mon, 2 Feb 2026 18:17:49 +0100", "thread_id": "20260130031232.60780-1-me@linux.beauty.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Convert the device tree binding documentation for tilcdc from plain text to DT binding schema. Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v3: - Rename binding file to ti,am33xx-tilcdc.yaml. - Use generic node name and drop unused label. --- .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++++++++++++++++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ----------------- 2 files changed, 100 insertions(+), 82 deletions(-) diff --git a/Documentation/devicetree/bindings/display/tilcdc/ti,am33xx-tilcdc.yaml b/Documentation/devicetree/bindings/display/tilcdc/ti,am33xx-tilcdc.yaml new file mode 100644 index 0000000000000..eb0ebb678fa87 --- /dev/null +++ b/Documentation/devicetree/bindings/display/tilcdc/ti,am33xx-tilcdc.yaml @@ -0,0 +1,100 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2025 Bootlin +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/tilcdc/ti,am33xx-tilcdc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI LCD Controller, found on AM335x, DA850, AM18x and OMAP-L138 + +maintainers: + - Kory Maincent <kory.maincent@bootlin.com> + +properties: + compatible: + enum: + - ti,am33xx-tilcdc + - ti,da850-tilcdc + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + port: + $ref: /schemas/graph.yaml#/properties/port + + ti,hwmods: + $ref: /schemas/types.yaml#/definitions/string + description: + Name of the hwmod associated to the LCDC + + max-bandwidth: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The maximum pixels per second that the memory interface / lcd + controller combination can sustain + # maximum: 2048*2048*60 + maximum: 251658240 + + max-width: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The maximum horizontal pixel width supported by the lcd controller. + maximum: 2048 + + max-pixelclock: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The maximum pixel clock that can be supported by the lcd controller + in KHz. + + blue-and-red-wiring: + enum: [straight, crossed] + description: + This property deals with the LCDC revision 2 (found on AM335x) + color errata [1]. + - "straight" indicates normal wiring that supports RGB565, + BGR888, and XBGR8888 color formats. + - "crossed" indicates wiring that has blue and red wires + crossed. This setup supports BGR565, RGB888 and XRGB8888 + formats. + - If the property is not present or its value is not recognized + the legacy mode is assumed. This configuration supports RGB565, + RGB888 and XRGB8888 formats. However, depending on wiring, the red + and blue colors are swapped in either 16 or 24-bit color modes. + + [1] There is an errata about AM335x color wiring. For 16-bit color + mode the wires work as they should (LCD_DATA[0:4] is for Blue[3:7]), + but for 24 bit color modes the wiring of blue and red components is + crossed and LCD_DATA[0:4] is for Red[3:7] and LCD_DATA[11:15] is + for Blue[3-7]. For more details see section 3.1.1 in AM335x + Silicon Errata + https://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sprz360 + +required: + - compatible + - interrupts + - reg + - port + +additionalProperties: false + +examples: + - | + display-controller@4830e000 { + compatible = "ti,am33xx-tilcdc"; + reg = <0x4830e000 0x1000>; + interrupt-parent = <&intc>; + interrupts = <36>; + ti,hwmods = "lcdc"; + + blue-and-red-wiring = "crossed"; + + port { + endpoint { + remote-endpoint = <&hdmi_0>; + }; + }; + }; diff --git a/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt b/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt deleted file mode 100644 index 3b3d0bbfcfff4..0000000000000 --- a/Documentation/devicetree/bindings/display/tilcdc/tilcdc.txt +++ /dev/null @@ -1,82 +0,0 @@ -Device-Tree bindings for tilcdc DRM driver - -Required properties: - - compatible: value should be one of the following: - - "ti,am33xx-tilcdc" for AM335x based boards - - "ti,da850-tilcdc" for DA850/AM18x/OMAP-L138 based boards - - interrupts: the interrupt number - - reg: base address and size of the LCDC device - -Recommended properties: - - ti,hwmods: Name of the hwmod associated to the LCDC - -Optional properties: - - max-bandwidth: The maximum pixels per second that the memory - interface / lcd controller combination can sustain - - max-width: The maximum horizontal pixel width supported by - the lcd controller. - - max-pixelclock: The maximum pixel clock that can be supported - by the lcd controller in KHz. - - blue-and-red-wiring: Recognized values "straight" or "crossed". - This property deals with the LCDC revision 2 (found on AM335x) - color errata [1]. - - "straight" indicates normal wiring that supports RGB565, - BGR888, and XBGR8888 color formats. - - "crossed" indicates wiring that has blue and red wires - crossed. This setup supports BGR565, RGB888 and XRGB8888 - formats. - - If the property is not present or its value is not recognized - the legacy mode is assumed. This configuration supports RGB565, - RGB888 and XRGB8888 formats. However, depending on wiring, the red - and blue colors are swapped in either 16 or 24-bit color modes. - -Optional nodes: - - - port/ports: to describe a connection to an external encoder. The - binding follows Documentation/devicetree/bindings/graph.txt and - supports a single port with a single endpoint. - - - See also Documentation/devicetree/bindings/display/tilcdc/panel.txt and - Documentation/devicetree/bindings/display/bridge/ti,tfp410.yaml for connecting - tfp410 DVI encoder or lcd panel to lcdc - -[1] There is an errata about AM335x color wiring. For 16-bit color mode - the wires work as they should (LCD_DATA[0:4] is for Blue[3:7]), - but for 24 bit color modes the wiring of blue and red components is - crossed and LCD_DATA[0:4] is for Red[3:7] and LCD_DATA[11:15] is - for Blue[3-7]. For more details see section 3.1.1 in AM335x - Silicon Errata: - https://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sprz360 - -Example: - - fb: fb@4830e000 { - compatible = "ti,am33xx-tilcdc", "ti,da850-tilcdc"; - reg = <0x4830e000 0x1000>; - interrupt-parent = <&intc>; - interrupts = <36>; - ti,hwmods = "lcdc"; - - blue-and-red-wiring = "crossed"; - - port { - lcdc_0: endpoint { - remote-endpoint = <&hdmi_0>; - }; - }; - }; - - tda19988: tda19988 { - compatible = "nxp,tda998x"; - reg = <0x70>; - - pinctrl-names = "default", "off"; - pinctrl-0 = <&nxp_hdmi_bonelt_pins>; - pinctrl-1 = <&nxp_hdmi_bonelt_off_pins>; - - port { - hdmi_0: endpoint { - remote-endpoint = <&lcdc_0>; - }; - }; - }; -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:19 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
The tilcdc hardware does not generate VESA-compliant sync signals. It aligns the vertical sync (VS) on the second edge of the horizontal sync (HS) instead of the first edge. To compensate for this hardware behavior, the driver applies a timing adjustment in mode_fixup(). Previously, this adjustment was conditional based on the simulate_vesa_sync flag, which was only set when using external encoders. This appears problematic because: 1. The timing adjustment seems needed for the hardware behavior regardless of whether an external encoder is used 2. The external encoder infrastructure is driver-specific and being removed due to design issues 3. Boards using tilcdc without bridges (e.g., am335x-evm, am335x-evmsk) may not be getting the necessary timing adjustments Remove the simulate_vesa_sync flag and apply the VESA sync timing adjustment unconditionally, ensuring consistent behavior across all configurations. While it's unclear if the previous conditional behavior was causing actual issues, the unconditional adjustment better reflects the hardware's characteristics. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Only few board currently use tilcdc not associated to a bridge like the am335x_evm or the am335x-evmsk. --- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 16 ---------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 2 -- drivers/gpu/drm/tilcdc/tilcdc_external.c | 1 - 3 files changed, 19 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index 52c95131af5af..b06b1453db2dd 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c @@ -47,9 +47,6 @@ struct tilcdc_crtc { struct drm_framebuffer *next_fb; - /* Only set if an external encoder is connected */ - bool simulate_vesa_sync; - int sync_lost_count; bool frame_intact; struct work_struct recover_work; @@ -642,11 +639,6 @@ static bool tilcdc_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) { - struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); - - if (!tilcdc_crtc->simulate_vesa_sync) - return true; - /* * tilcdc does not generate VESA-compliant sync but aligns * VS on the second edge of HS instead of first edge. @@ -866,14 +858,6 @@ void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc, tilcdc_crtc->info = info; } -void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc, - bool simulate_vesa_sync) -{ - struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); - - tilcdc_crtc->simulate_vesa_sync = simulate_vesa_sync; -} - void tilcdc_crtc_update_clk(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index 58b276f82a669..3aba3a1155ba0 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -160,8 +160,6 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc); void tilcdc_crtc_update_clk(struct drm_crtc *crtc); void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc, const struct tilcdc_panel_info *info); -void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc, - bool simulate_vesa_sync); void tilcdc_crtc_shutdown(struct drm_crtc *crtc); void tilcdc_crtc_destroy(struct drm_crtc *crtc); int tilcdc_crtc_update_fb(struct drm_crtc *crtc, diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.c b/drivers/gpu/drm/tilcdc/tilcdc_external.c index 3b86d002ef62e..da755a411d9ff 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_external.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_external.c @@ -80,7 +80,6 @@ int tilcdc_add_component_encoder(struct drm_device *ddev) return -ENODEV; /* Only tda998x is supported at the moment. */ - tilcdc_crtc_set_simulate_vesa_sync(priv->crtc, true); tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_tda998x); return 0; -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:21 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
To maintain backward compatibility while removing the deprecated tilcdc_panel driver, add a tilcdc_panel_legacy subdriver that converts the legacy "ti,tilcdc,panel" devicetree binding to the standard panel-dpi binding at early boot. The conversion uses an embedded device tree overlay that is applied and modified during subsys_initcall. The process: - Apply embedded overlay to create a tilcdc-panel-dpi node with port/endpoint connections to the LCDC - Copy all properties from the legacy panel node to the new tilcdc-panel-dpi node - Copy display-timings from the legacy panel - Convert legacy panel-info properties (invert-pxl-clk, sync-edge) to standard display timing properties (pixelclk-active, syncclk-active) - Disable the legacy panel by removing its compatible property to prevent the deprecated driver from binding The result is a standard tilcdc-panel-dpi node with proper endpoints and timing properties, allowing the DRM panel infrastructure to work with legacy devicetrees without modification. Other legacy panel-info properties are not migrated as they consistently use default values across all mainline devicetrees and can be hardcoded in the tilcdc driver. This feature is optional via CONFIG_DRM_TILCDC_PANEL_LEGACY and should only be enabled for systems with legacy devicetrees containing "ti,tilcdc,panel" nodes. Suggested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Link: https://lore.kernel.org/all/1d9a9269-bfda-4d43-938b-2df6b82b9369@ideasonboard.com/ Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Reviewed-by: Herve Codina <herve.codina@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Using the approach of applying an overlay and then modifying the live device tree is the solution I found that requires no modification of the OF core. Dealing entirely with changesets would bring additional requirements such as phandle resolution management, which is internal to the OF framework. I intend to avoid OF core change to support this legacy binding. Change in v4: - Use tab instead of space. Change in v3: - Use __free() macro instead of manual house cleaning. - Enable CONFIG_DRM_TILCDC_PANEL_LEGACY config by default. - Improve config description. - Rename "panel-dpi" to "tilcdc-panel-dpi" to avoid any future conflict. - Use OF changeset instead of modifying the live devicetree step by step. - Add kfree to avoid memory leak. Change in v2: - New patch. --- drivers/gpu/drm/tilcdc/Kconfig | 16 ++ drivers/gpu/drm/tilcdc/Makefile | 2 + drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++++++++++++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++++ 4 files changed, 232 insertions(+) diff --git a/drivers/gpu/drm/tilcdc/Kconfig b/drivers/gpu/drm/tilcdc/Kconfig index 24f9a245ba593..a36e809f984cd 100644 --- a/drivers/gpu/drm/tilcdc/Kconfig +++ b/drivers/gpu/drm/tilcdc/Kconfig @@ -14,3 +14,19 @@ config DRM_TILCDC controller, for example AM33xx in beagle-bone, DA8xx, or OMAP-L1xx. This driver replaces the FB_DA8XX fbdev driver. +config DRM_TILCDC_PANEL_LEGACY + bool "Support device tree blobs using TI LCDC Panel binding" + default y + depends on DRM_TILCDC + depends on OF + depends on BACKLIGHT_CLASS_DEVICE + depends on PM + select OF_OVERLAY + select DRM_PANEL_SIMPLE + help + Modifies the live device tree at early boot to convert the legacy + "ti,tilcdc,panel" devicetree node to the standard panel-dpi node. + This allows to maintain backward compatibility for boards which + were using the deprecated tilcdc_panel driver. + If you find "ti,tilcdc,panel"-string from your DTB, you probably + need this. Otherwise you do not. diff --git a/drivers/gpu/drm/tilcdc/Makefile b/drivers/gpu/drm/tilcdc/Makefile index f5190477de721..6d6a08b5adf40 100644 --- a/drivers/gpu/drm/tilcdc/Makefile +++ b/drivers/gpu/drm/tilcdc/Makefile @@ -11,3 +11,5 @@ tilcdc-y := \ tilcdc_drv.o obj-$(CONFIG_DRM_TILCDC) += tilcdc.o +obj-$(CONFIG_DRM_TILCDC_PANEL_LEGACY) += tilcdc_panel_legacy.o \ + tilcdc_panel_legacy.dtbo.o diff --git a/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c b/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c new file mode 100644 index 0000000000000..37a69b3cf04b2 --- /dev/null +++ b/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c @@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2025 Bootlin + * Author: Kory Maincent <kory.maincent@bootlin.com> + * + * To support the legacy "ti,tilcdc,panel" binding, the devicetree has to + * be transformed to the new panel-dpi binding with the endpoint associated. + */ + +#include <linux/kernel.h> +#include <linux/of.h> +#include <linux/of_fdt.h> +#include <linux/slab.h> + +/* Embedded dtbo symbols created by cmd_wrap_S_dtb in scripts/Makefile.lib */ +extern char __dtbo_tilcdc_panel_legacy_begin[]; +extern char __dtbo_tilcdc_panel_legacy_end[]; + +static int __init +tilcdc_panel_update_prop(struct of_changeset *ocs, struct device_node *node, + char *name, void *val, int length) +{ + struct property *prop; + + prop = kzalloc(sizeof(*prop), GFP_KERNEL); + if (!prop) + return -ENOMEM; + + prop->name = kstrdup(name, GFP_KERNEL); + prop->length = length; + prop->value = kmemdup(val, length, GFP_KERNEL); + if (!prop->name || !prop->value) { + kfree(prop->name); + kfree(prop->value); + kfree(prop); + return -ENOMEM; + } + + return of_changeset_update_property(ocs, node, prop); +} + +static int __init tilcdc_panel_copy_props(struct device_node *old_panel, + struct device_node *new_panel) +{ + struct device_node *old_timing __free(device_node) = NULL; + struct device_node *new_timing __free(device_node) = NULL; + struct device_node *panel_info __free(device_node) = NULL; + struct device_node *child __free(device_node) = NULL; + u32 invert_pxl_clk = 0, sync_edge = 0; + struct of_changeset ocs; + struct property *prop; + int ret; + + child = of_get_child_by_name(old_panel, "display-timings"); + if (!child) + return -EINVAL; + + /* The default display timing is the one specified as native-mode. + * If no native-mode is specified then the first node is assumed + * to be the native mode. + */ + old_timing = of_parse_phandle(child, "native-mode", 0); + if (!old_timing) { + old_timing = of_get_next_child(child, NULL); + if (!old_timing) + return -EINVAL; + } + + panel_info = of_get_child_by_name(old_panel, "panel-info"); + if (!panel_info) + return -EINVAL; + + of_changeset_init(&ocs); + + /* Copy all panel properties to the new panel node */ + for_each_property_of_node(old_panel, prop) { + if (!strncmp(prop->name, "compatible", sizeof("compatible"))) + continue; + + ret = tilcdc_panel_update_prop(&ocs, new_panel, prop->name, + prop->value, prop->length); + if (ret) + goto destroy_ocs; + } + + new_timing = of_changeset_create_node(&ocs, new_panel, "panel-timing"); + if (!new_timing) { + ret = -ENODEV; + goto destroy_ocs; + } + + /* Copy all panel timing properties to the new panel node */ + for_each_property_of_node(old_timing, prop) { + ret = tilcdc_panel_update_prop(&ocs, new_timing, prop->name, + prop->value, prop->length); + if (ret) + goto destroy_ocs; + } + + /* Looked only for these two parameter as all the other are always + * set to default and not related to common DRM properties. + */ + of_property_read_u32(panel_info, "invert-pxl-clk", &invert_pxl_clk); + of_property_read_u32(panel_info, "sync-edge", &sync_edge); + + if (!invert_pxl_clk) { + ret = tilcdc_panel_update_prop(&ocs, new_timing, "pixelclk-active", + &(u32){cpu_to_be32(1)}, sizeof(u32)); + if (ret) + goto destroy_ocs; + } + + if (!sync_edge) { + ret = tilcdc_panel_update_prop(&ocs, new_timing, "syncclk-active", + &(u32){cpu_to_be32(1)}, sizeof(u32)); + if (ret) + goto destroy_ocs; + } + + /* Remove compatible property to avoid any driver compatible match */ + of_changeset_remove_property(&ocs, old_panel, + of_find_property(old_panel, "compatible", NULL)); + + of_changeset_apply(&ocs); + return 0; + +destroy_ocs: + of_changeset_destroy(&ocs); + return ret; +} + +static const struct of_device_id tilcdc_panel_of_match[] __initconst = { + { .compatible = "ti,tilcdc,panel", }, + {}, +}; + +static const struct of_device_id tilcdc_of_match[] __initconst = { + { .compatible = "ti,am33xx-tilcdc", }, + { .compatible = "ti,da850-tilcdc", }, + {}, +}; + +static int __init tilcdc_panel_legacy_init(void) +{ + struct device_node *new_panel __free(device_node) = NULL; + struct device_node *panel __free(device_node) = NULL; + struct device_node *lcdc __free(device_node) = NULL; + void *dtbo_start; + u32 dtbo_size; + int ovcs_id; + int ret; + + lcdc = of_find_matching_node(NULL, tilcdc_of_match); + panel = of_find_matching_node(NULL, tilcdc_panel_of_match); + + if (!of_device_is_available(panel) || + !of_device_is_available(lcdc)) + return 0; + + dtbo_start = __dtbo_tilcdc_panel_legacy_begin; + dtbo_size = __dtbo_tilcdc_panel_legacy_end - + __dtbo_tilcdc_panel_legacy_begin; + + ret = of_overlay_fdt_apply(dtbo_start, dtbo_size, &ovcs_id, NULL); + if (ret) + return ret; + + new_panel = of_find_node_by_name(NULL, "tilcdc-panel-dpi"); + if (!new_panel) { + ret = -ENODEV; + goto overlay_remove; + } + + ret = tilcdc_panel_copy_props(panel, new_panel); + if (ret) + goto overlay_remove; + + return 0; + +overlay_remove: + of_overlay_remove(&ovcs_id); + return ret; +} + +subsys_initcall(tilcdc_panel_legacy_init); diff --git a/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso b/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso new file mode 100644 index 0000000000000..ae71d10f5ec13 --- /dev/null +++ b/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * DTS overlay for converting ti,tilcdc,panel binding to new binding. + * + * Copyright (C) 2025 Bootlin + * Author: Kory Maincent <kory.maincent@bootlin.com> + */ + +/dts-v1/; +/plugin/; + +&{/} { + tilcdc-panel-dpi { + compatible = "panel-dpi"; + port { + panel_in: endpoint@0 { + remote-endpoint = <&lcd_0>; + }; + }; + }; +}; + +&lcdc { + port { + lcd_0: endpoint@0 { + remote-endpoint = <&panel_in>; + }; + }; +}; -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:23 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Mark the ti,tilcdc,panel binding as deprecated in the documentation. This legacy binding should no longer be used for new designs. Users should migrate to the standard DRM panel bindings instead. Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v2: - New patch --- Documentation/devicetree/bindings/display/tilcdc/panel.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/display/tilcdc/panel.txt b/Documentation/devicetree/bindings/display/tilcdc/panel.txt index 808216310ea27..b973174d704ed 100644 --- a/Documentation/devicetree/bindings/display/tilcdc/panel.txt +++ b/Documentation/devicetree/bindings/display/tilcdc/panel.txt @@ -1,4 +1,5 @@ Device-Tree bindings for tilcdc DRM generic panel output driver +This binding is deprecated and should not be used. Required properties: - compatible: value should be "ti,tilcdc,panel". -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:20 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Migrate CRTC mode configuration to use standard DRM bus flags in preparation for removing the tilcdc_panel driver and its custom tilcdc_panel_info structure. Add support for DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE and DRM_BUS_FLAG_SYNC_DRIVE_NEGEDGE flags to control pixel clock and sync signal edge polarity, while maintaining backward compatibility with the existing tilcdc panel info structure. Simplify several hardware parameters by setting them to fixed defaults based on common usage across existing device trees: - DMA burst size: 16 (previously configurable via switch statement) - AC bias frequency: 255 (previously panel-specific) - FIFO DMA request delay: 128 (previously panel-specific) These parameters show no variation in real-world usage, so hardcoding them simplifies the driver without losing functionality. Preserve FIFO threshold configurability by detecting the SoC type, as this parameter varies between AM33xx (8) and DA850 (16) platforms. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v4: - Use of_device_get_match_data() instead of of_match_node(). - Move back the tilcdc_of_match table down were it was before. Change in v2: - Use SoC type instead of devicetree parameter to set FIFO threshold value. --- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 47 +++++++++++++----------------------- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 17 +++++++++++-- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 2 ++ 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index b06b1453db2dd..2309a9a0c925d 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c @@ -285,27 +285,15 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) /* Configure the Burst Size and fifo threshold of DMA: */ reg = tilcdc_read(dev, LCDC_DMA_CTRL_REG) & ~0x00000770; - switch (info->dma_burst_sz) { - case 1: - reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_1); - break; - case 2: - reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_2); - break; - case 4: - reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_4); - break; - case 8: - reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_8); - break; - case 16: - reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_16); - break; - default: - dev_err(dev->dev, "invalid burst size\n"); - return; + /* Use 16 bit DMA burst size by default */ + reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_16); + if (priv->fifo_th) { + int fifo_th_val = ilog2(priv->fifo_th) - 3; + + reg |= (fifo_th_val << 8); + } else { + reg |= (info->fifo_th << 8); } - reg |= (info->fifo_th << 8); tilcdc_write(dev, LCDC_DMA_CTRL_REG, reg); /* Configure timings: */ @@ -321,8 +309,8 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) /* Set AC Bias Period and Number of Transitions per Interrupt: */ reg = tilcdc_read(dev, LCDC_RASTER_TIMING_2_REG) & ~0x000fff00; - reg |= LCDC_AC_BIAS_FREQUENCY(info->ac_bias) | - LCDC_AC_BIAS_TRANSITIONS_PER_INT(info->ac_bias_intrpt); + /* Use 255 AC Bias Pin Frequency by default */ + reg |= LCDC_AC_BIAS_FREQUENCY(255); /* * subtract one from hfp, hbp, hsw because the hardware uses @@ -392,20 +380,19 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) return; } } - reg |= info->fdd << 12; + /* Use 128 FIFO DMA Request Delay by default */ + reg |= 128 << 12; tilcdc_write(dev, LCDC_RASTER_CTRL_REG, reg); - if (info->invert_pxl_clk) + if (info->invert_pxl_clk || + mode->flags == DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE) tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); else tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); - if (info->sync_ctrl) - tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); - else - tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); - - if (info->sync_edge) + tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); + if (info->sync_edge || + mode->flags == DRM_BUS_FLAG_SYNC_DRIVE_NEGEDGE) tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); else tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 3dcbec312bacb..fe01f3fcaf3c2 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -31,6 +31,11 @@ #include "tilcdc_panel.h" #include "tilcdc_regs.h" +enum tilcdc_variant { + AM33XX_TILCDC, + DA850_TILCDC, +}; + static LIST_HEAD(module_list); static const u32 tilcdc_rev1_formats[] = { DRM_FORMAT_RGB565 }; @@ -198,6 +203,7 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct device_node *node = dev->of_node; struct tilcdc_drm_private *priv; + enum tilcdc_variant variant; u32 bpp = 0; int ret; @@ -209,6 +215,8 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) if (IS_ERR(ddev)) return PTR_ERR(ddev); + variant = (uintptr_t)of_device_get_match_data(dev); + ddev->dev_private = priv; platform_set_drvdata(pdev, ddev); drm_mode_config_init(ddev); @@ -309,6 +317,11 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) DBG("Maximum Pixel Clock Value %dKHz", priv->max_pixelclock); + if (variant == DA850_TILCDC) + priv->fifo_th = 16; + else + priv->fifo_th = 8; + ret = tilcdc_crtc_create(ddev); if (ret < 0) { dev_err(dev, "failed to create crtc\n"); @@ -598,8 +611,8 @@ static void tilcdc_pdev_shutdown(struct platform_device *pdev) } static const struct of_device_id tilcdc_of_match[] = { - { .compatible = "ti,am33xx-tilcdc", }, - { .compatible = "ti,da850-tilcdc", }, + { .compatible = "ti,am33xx-tilcdc", .data = (void *)AM33XX_TILCDC}, + { .compatible = "ti,da850-tilcdc", .data = (void *)DA850_TILCDC}, { }, }; MODULE_DEVICE_TABLE(of, tilcdc_of_match); diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index 3aba3a1155ba0..79078b4ae7393 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -61,6 +61,8 @@ struct tilcdc_drm_private { */ uint32_t max_width; + u32 fifo_th; + /* Supported pixel formats */ const uint32_t *pixelformats; uint32_t num_pixelformats; -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:22 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
The tilcdc panel subdriver is a legacy, non-standard driver that has been replaced by the standard panel-dpi driver and panel-simple infrastructure. With the device tree bindings removed and all in-tree users migrated to use panel-dpi, this driver no longer has any associated device tree bindings or users. The panel-dpi driver combined with DRM bus flags provides equivalent functionality in a standard way that is compatible with the broader DRM panel ecosystem. This removal eliminates 400+ lines of redundant code and completes the migration to standard panel handling. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/tilcdc/Makefile | 1 - drivers/gpu/drm/tilcdc/tilcdc_drv.c | 3 - drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ---------------------------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 -- 4 files changed, 427 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/Makefile b/drivers/gpu/drm/tilcdc/Makefile index 6d6a08b5adf40..b78204a65ce29 100644 --- a/drivers/gpu/drm/tilcdc/Makefile +++ b/drivers/gpu/drm/tilcdc/Makefile @@ -6,7 +6,6 @@ endif tilcdc-y := \ tilcdc_plane.o \ tilcdc_crtc.o \ - tilcdc_panel.o \ tilcdc_external.o \ tilcdc_drv.o diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index fe01f3fcaf3c2..f03861ed6349d 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -28,7 +28,6 @@ #include "tilcdc_drv.h" #include "tilcdc_external.h" -#include "tilcdc_panel.h" #include "tilcdc_regs.h" enum tilcdc_variant { @@ -634,7 +633,6 @@ static int __init tilcdc_drm_init(void) return -ENODEV; DBG("init"); - tilcdc_panel_init(); return platform_driver_register(&tilcdc_platform_driver); } @@ -642,7 +640,6 @@ static void __exit tilcdc_drm_fini(void) { DBG("fini"); platform_driver_unregister(&tilcdc_platform_driver); - tilcdc_panel_fini(); } module_init(tilcdc_drm_init); diff --git a/drivers/gpu/drm/tilcdc/tilcdc_panel.c b/drivers/gpu/drm/tilcdc/tilcdc_panel.c deleted file mode 100644 index 262f290d85d91..0000000000000 --- a/drivers/gpu/drm/tilcdc/tilcdc_panel.c +++ /dev/null @@ -1,408 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2012 Texas Instruments - * Author: Rob Clark <robdclark@gmail.com> - */ - -#include <linux/backlight.h> -#include <linux/gpio/consumer.h> -#include <linux/platform_device.h> - -#include <video/display_timing.h> -#include <video/of_display_timing.h> -#include <video/videomode.h> - -#include <drm/drm_atomic_state_helper.h> -#include <drm/drm_connector.h> -#include <drm/drm_modeset_helper_vtables.h> -#include <drm/drm_probe_helper.h> -#include <drm/drm_simple_kms_helper.h> - -#include "tilcdc_drv.h" -#include "tilcdc_panel.h" - -struct panel_module { - struct tilcdc_module base; - struct tilcdc_panel_info *info; - struct display_timings *timings; - struct backlight_device *backlight; - struct gpio_desc *enable_gpio; -}; -#define to_panel_module(x) container_of(x, struct panel_module, base) - - -/* - * Encoder: - */ - -struct panel_encoder { - struct drm_encoder base; - struct panel_module *mod; -}; -#define to_panel_encoder(x) container_of(x, struct panel_encoder, base) - -static void panel_encoder_dpms(struct drm_encoder *encoder, int mode) -{ - struct panel_encoder *panel_encoder = to_panel_encoder(encoder); - struct backlight_device *backlight = panel_encoder->mod->backlight; - struct gpio_desc *gpio = panel_encoder->mod->enable_gpio; - - if (backlight) { - backlight->props.power = mode == DRM_MODE_DPMS_ON ? - BACKLIGHT_POWER_ON : BACKLIGHT_POWER_OFF; - backlight_update_status(backlight); - } - - if (gpio) - gpiod_set_value_cansleep(gpio, - mode == DRM_MODE_DPMS_ON ? 1 : 0); -} - -static void panel_encoder_prepare(struct drm_encoder *encoder) -{ - panel_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); -} - -static void panel_encoder_commit(struct drm_encoder *encoder) -{ - panel_encoder_dpms(encoder, DRM_MODE_DPMS_ON); -} - -static void panel_encoder_mode_set(struct drm_encoder *encoder, - struct drm_display_mode *mode, - struct drm_display_mode *adjusted_mode) -{ - /* nothing needed */ -} - -static const struct drm_encoder_helper_funcs panel_encoder_helper_funcs = { - .dpms = panel_encoder_dpms, - .prepare = panel_encoder_prepare, - .commit = panel_encoder_commit, - .mode_set = panel_encoder_mode_set, -}; - -static struct drm_encoder *panel_encoder_create(struct drm_device *dev, - struct panel_module *mod) -{ - struct panel_encoder *panel_encoder; - struct drm_encoder *encoder; - int ret; - - panel_encoder = devm_kzalloc(dev->dev, sizeof(*panel_encoder), - GFP_KERNEL); - if (!panel_encoder) - return NULL; - - panel_encoder->mod = mod; - - encoder = &panel_encoder->base; - encoder->possible_crtcs = 1; - - ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_LVDS); - if (ret < 0) - goto fail; - - drm_encoder_helper_add(encoder, &panel_encoder_helper_funcs); - - return encoder; - -fail: - drm_encoder_cleanup(encoder); - return NULL; -} - -/* - * Connector: - */ - -struct panel_connector { - struct drm_connector base; - - struct drm_encoder *encoder; /* our connected encoder */ - struct panel_module *mod; -}; -#define to_panel_connector(x) container_of(x, struct panel_connector, base) - - -static void panel_connector_destroy(struct drm_connector *connector) -{ - drm_connector_unregister(connector); - drm_connector_cleanup(connector); -} - -static int panel_connector_get_modes(struct drm_connector *connector) -{ - struct drm_device *dev = connector->dev; - struct panel_connector *panel_connector = to_panel_connector(connector); - struct display_timings *timings = panel_connector->mod->timings; - int i; - - for (i = 0; i < timings->num_timings; i++) { - struct drm_display_mode *mode; - struct videomode vm; - - if (videomode_from_timings(timings, &vm, i)) - break; - - mode = drm_mode_create(dev); - if (!mode) - break; - - drm_display_mode_from_videomode(&vm, mode); - - mode->type = DRM_MODE_TYPE_DRIVER; - - if (timings->native_mode == i) - mode->type |= DRM_MODE_TYPE_PREFERRED; - - drm_mode_set_name(mode); - drm_mode_probed_add(connector, mode); - } - - return i; -} - -static struct drm_encoder *panel_connector_best_encoder( - struct drm_connector *connector) -{ - struct panel_connector *panel_connector = to_panel_connector(connector); - return panel_connector->encoder; -} - -static const struct drm_connector_funcs panel_connector_funcs = { - .destroy = panel_connector_destroy, - .fill_modes = drm_helper_probe_single_connector_modes, - .reset = drm_atomic_helper_connector_reset, - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, -}; - -static const struct drm_connector_helper_funcs panel_connector_helper_funcs = { - .get_modes = panel_connector_get_modes, - .best_encoder = panel_connector_best_encoder, -}; - -static struct drm_connector *panel_connector_create(struct drm_device *dev, - struct panel_module *mod, struct drm_encoder *encoder) -{ - struct panel_connector *panel_connector; - struct drm_connector *connector; - int ret; - - panel_connector = devm_kzalloc(dev->dev, sizeof(*panel_connector), - GFP_KERNEL); - if (!panel_connector) - return NULL; - - panel_connector->encoder = encoder; - panel_connector->mod = mod; - - connector = &panel_connector->base; - - drm_connector_init(dev, connector, &panel_connector_funcs, - DRM_MODE_CONNECTOR_LVDS); - drm_connector_helper_add(connector, &panel_connector_helper_funcs); - - connector->interlace_allowed = 0; - connector->doublescan_allowed = 0; - - ret = drm_connector_attach_encoder(connector, encoder); - if (ret) - goto fail; - - return connector; - -fail: - panel_connector_destroy(connector); - return NULL; -} - -/* - * Module: - */ - -static int panel_modeset_init(struct tilcdc_module *mod, struct drm_device *dev) -{ - struct panel_module *panel_mod = to_panel_module(mod); - struct tilcdc_drm_private *priv = dev->dev_private; - struct drm_encoder *encoder; - struct drm_connector *connector; - - encoder = panel_encoder_create(dev, panel_mod); - if (!encoder) - return -ENOMEM; - - connector = panel_connector_create(dev, panel_mod, encoder); - if (!connector) - return -ENOMEM; - - priv->encoders[priv->num_encoders++] = encoder; - priv->connectors[priv->num_connectors++] = connector; - - tilcdc_crtc_set_panel_info(priv->crtc, - to_panel_encoder(encoder)->mod->info); - - return 0; -} - -static const struct tilcdc_module_ops panel_module_ops = { - .modeset_init = panel_modeset_init, -}; - -/* - * Device: - */ - -/* maybe move this somewhere common if it is needed by other outputs? */ -static struct tilcdc_panel_info *of_get_panel_info(struct device_node *np) -{ - struct device_node *info_np; - struct tilcdc_panel_info *info; - int ret = 0; - - if (!np) { - pr_err("%s: no devicenode given\n", __func__); - return NULL; - } - - info_np = of_get_child_by_name(np, "panel-info"); - if (!info_np) { - pr_err("%s: could not find panel-info node\n", __func__); - return NULL; - } - - info = kzalloc(sizeof(*info), GFP_KERNEL); - if (!info) - goto put_node; - - ret |= of_property_read_u32(info_np, "ac-bias", &info->ac_bias); - ret |= of_property_read_u32(info_np, "ac-bias-intrpt", &info->ac_bias_intrpt); - ret |= of_property_read_u32(info_np, "dma-burst-sz", &info->dma_burst_sz); - ret |= of_property_read_u32(info_np, "bpp", &info->bpp); - ret |= of_property_read_u32(info_np, "fdd", &info->fdd); - ret |= of_property_read_u32(info_np, "sync-edge", &info->sync_edge); - ret |= of_property_read_u32(info_np, "sync-ctrl", &info->sync_ctrl); - ret |= of_property_read_u32(info_np, "raster-order", &info->raster_order); - ret |= of_property_read_u32(info_np, "fifo-th", &info->fifo_th); - - /* optional: */ - info->tft_alt_mode = of_property_read_bool(info_np, "tft-alt-mode"); - info->invert_pxl_clk = of_property_read_bool(info_np, "invert-pxl-clk"); - - if (ret) { - pr_err("%s: error reading panel-info properties\n", __func__); - kfree(info); - info = NULL; - } - -put_node: - of_node_put(info_np); - return info; -} - -static int panel_probe(struct platform_device *pdev) -{ - struct device_node *node = pdev->dev.of_node; - struct backlight_device *backlight; - struct panel_module *panel_mod; - struct tilcdc_module *mod; - int ret; - - /* bail out early if no DT data: */ - if (!node) { - dev_err(&pdev->dev, "device-tree data is missing\n"); - return -ENXIO; - } - - panel_mod = devm_kzalloc(&pdev->dev, sizeof(*panel_mod), GFP_KERNEL); - if (!panel_mod) - return -ENOMEM; - - backlight = devm_of_find_backlight(&pdev->dev); - if (IS_ERR(backlight)) - return PTR_ERR(backlight); - panel_mod->backlight = backlight; - - panel_mod->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable", - GPIOD_OUT_LOW); - if (IS_ERR(panel_mod->enable_gpio)) { - ret = PTR_ERR(panel_mod->enable_gpio); - dev_err(&pdev->dev, "failed to request enable GPIO\n"); - goto fail_backlight; - } - - if (panel_mod->enable_gpio) - dev_info(&pdev->dev, "found enable GPIO\n"); - - mod = &panel_mod->base; - pdev->dev.platform_data = mod; - - tilcdc_module_init(mod, "panel", &panel_module_ops); - - panel_mod->timings = of_get_display_timings(node); - if (!panel_mod->timings) { - dev_err(&pdev->dev, "could not get panel timings\n"); - ret = -EINVAL; - goto fail_free; - } - - panel_mod->info = of_get_panel_info(node); - if (!panel_mod->info) { - dev_err(&pdev->dev, "could not get panel info\n"); - ret = -EINVAL; - goto fail_timings; - } - - return 0; - -fail_timings: - display_timings_release(panel_mod->timings); - -fail_free: - tilcdc_module_cleanup(mod); - -fail_backlight: - if (panel_mod->backlight) - put_device(&panel_mod->backlight->dev); - return ret; -} - -static void panel_remove(struct platform_device *pdev) -{ - struct tilcdc_module *mod = dev_get_platdata(&pdev->dev); - struct panel_module *panel_mod = to_panel_module(mod); - struct backlight_device *backlight = panel_mod->backlight; - - if (backlight) - put_device(&backlight->dev); - - display_timings_release(panel_mod->timings); - - tilcdc_module_cleanup(mod); - kfree(panel_mod->info); -} - -static const struct of_device_id panel_of_match[] = { - { .compatible = "ti,tilcdc,panel", }, - { }, -}; - -static struct platform_driver panel_driver = { - .probe = panel_probe, - .remove = panel_remove, - .driver = { - .name = "tilcdc-panel", - .of_match_table = panel_of_match, - }, -}; - -int __init tilcdc_panel_init(void) -{ - return platform_driver_register(&panel_driver); -} - -void __exit tilcdc_panel_fini(void) -{ - platform_driver_unregister(&panel_driver); -} diff --git a/drivers/gpu/drm/tilcdc/tilcdc_panel.h b/drivers/gpu/drm/tilcdc/tilcdc_panel.h deleted file mode 100644 index 65d735d773a48..0000000000000 --- a/drivers/gpu/drm/tilcdc/tilcdc_panel.h +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2012 Texas Instruments - * Author: Rob Clark <robdclark@gmail.com> - */ - -#ifndef __TILCDC_PANEL_H__ -#define __TILCDC_PANEL_H__ - -/* sub-module for generic lcd panel output */ - -int tilcdc_panel_init(void); -void tilcdc_panel_fini(void); - -#endif /* __TILCDC_PANEL_H__ */ -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:24 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
The tilcdc driver previously used the component framework to bind external encoder subdrivers (specifically the TDA998x HDMI encoder). With the removal of these subdrivers in previous commits, the component framework is no longer needed. This commit removes all component framework infrastructure including: - Component master operations and bind/unbind callbacks - The is_componentized flag and conditional code paths - tilcdc_get_external_components() and tilcdc_add_component_encoder() - TDA998x-specific panel configuration The driver now uses a simplified initialization path that directly attaches external devices via the DRM bridge API, eliminating the complexity of dual code paths for componentized vs non-componentized configurations. This cleanup removes approximately 140 lines of code and makes the driver initialization flow more straightforward. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 10 ---- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 80 ++++---------------------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 1 - drivers/gpu/drm/tilcdc/tilcdc_external.c | 65 -------------------------- drivers/gpu/drm/tilcdc/tilcdc_external.h | 3 -- 5 files changed, 9 insertions(+), 150 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index 2309a9a0c925d..252e5adaeb6e2 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c @@ -1021,16 +1021,6 @@ int tilcdc_crtc_create(struct drm_device *dev) drm_crtc_helper_add(crtc, &tilcdc_crtc_helper_funcs); - if (priv->is_componentized) { - crtc->port = of_graph_get_port_by_id(dev->dev->of_node, 0); - if (!crtc->port) { /* This should never happen */ - dev_err(dev->dev, "Port node not found in %pOF\n", - dev->dev->of_node); - ret = -EINVAL; - goto fail; - } - } - priv->crtc = crtc; return 0; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index f03861ed6349d..f865c131dae66 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -6,7 +6,6 @@ /* LCDC DRM driver, based on da8xx-fb */ -#include <linux/component.h> #include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/pinctrl/consumer.h> @@ -220,9 +219,6 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) platform_set_drvdata(pdev, ddev); drm_mode_config_init(ddev); - priv->is_componentized = - tilcdc_get_external_components(dev, NULL) > 0; - priv->wq = alloc_ordered_workqueue("tilcdc", 0); if (!priv->wq) { ret = -ENOMEM; @@ -339,42 +335,32 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) } #endif - if (priv->is_componentized) { - ret = component_bind_all(dev, ddev); - if (ret < 0) - goto unregister_cpufreq_notif; - - ret = tilcdc_add_component_encoder(ddev); - if (ret < 0) - goto unbind_component; - } else { - ret = tilcdc_attach_external_device(ddev); - if (ret) - goto unregister_cpufreq_notif; - } + ret = tilcdc_attach_external_device(ddev); + if (ret) + goto unregister_cpufreq_notif; if (!priv->external_connector && ((priv->num_encoders == 0) || (priv->num_connectors == 0))) { dev_err(dev, "no encoders/connectors found\n"); ret = -EPROBE_DEFER; - goto unbind_component; + goto unregister_cpufreq_notif; } ret = drm_vblank_init(ddev, 1); if (ret < 0) { dev_err(dev, "failed to initialize vblank\n"); - goto unbind_component; + goto unregister_cpufreq_notif; } ret = platform_get_irq(pdev, 0); if (ret < 0) - goto unbind_component; + goto unregister_cpufreq_notif; priv->irq = ret; ret = tilcdc_irq_install(ddev, priv->irq); if (ret < 0) { dev_err(dev, "failed to install IRQ handler\n"); - goto unbind_component; + goto unregister_cpufreq_notif; } drm_mode_config_reset(ddev); @@ -392,9 +378,6 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) stop_poll: drm_kms_helper_poll_fini(ddev); tilcdc_irq_uninstall(ddev); -unbind_component: - if (priv->is_componentized) - component_unbind_all(dev, ddev); unregister_cpufreq_notif: #ifdef CONFIG_CPU_FREQ cpufreq_unregister_notifier(&priv->freq_transition, @@ -543,65 +526,20 @@ static int tilcdc_pm_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(tilcdc_pm_ops, tilcdc_pm_suspend, tilcdc_pm_resume); -/* - * Platform driver: - */ -static int tilcdc_bind(struct device *dev) -{ - return tilcdc_init(&tilcdc_driver, dev); -} - -static void tilcdc_unbind(struct device *dev) -{ - struct drm_device *ddev = dev_get_drvdata(dev); - - /* Check if a subcomponent has already triggered the unloading. */ - if (!ddev->dev_private) - return; - - tilcdc_fini(ddev); - dev_set_drvdata(dev, NULL); -} - -static const struct component_master_ops tilcdc_comp_ops = { - .bind = tilcdc_bind, - .unbind = tilcdc_unbind, -}; - static int tilcdc_pdev_probe(struct platform_device *pdev) { - struct component_match *match = NULL; - int ret; - /* bail out early if no DT data: */ if (!pdev->dev.of_node) { dev_err(&pdev->dev, "device-tree data is missing\n"); return -ENXIO; } - ret = tilcdc_get_external_components(&pdev->dev, &match); - if (ret < 0) - return ret; - else if (ret == 0) - return tilcdc_init(&tilcdc_driver, &pdev->dev); - else - return component_master_add_with_match(&pdev->dev, - &tilcdc_comp_ops, - match); + return tilcdc_init(&tilcdc_driver, &pdev->dev); } static void tilcdc_pdev_remove(struct platform_device *pdev) { - int ret; - - ret = tilcdc_get_external_components(&pdev->dev, NULL); - if (ret < 0) - dev_err(&pdev->dev, "tilcdc_get_external_components() failed (%pe)\n", - ERR_PTR(ret)); - else if (ret == 0) - tilcdc_fini(platform_get_drvdata(pdev)); - else - component_master_del(&pdev->dev, &tilcdc_comp_ops); + tilcdc_fini(platform_get_drvdata(pdev)); } static void tilcdc_pdev_shutdown(struct platform_device *pdev) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index 79078b4ae7393..c23b593dc61f6 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -84,7 +84,6 @@ struct tilcdc_drm_private { struct drm_encoder *external_encoder; struct drm_connector *external_connector; - bool is_componentized; bool irq_enabled; }; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.c b/drivers/gpu/drm/tilcdc/tilcdc_external.c index da755a411d9ff..2970c41d9c3eb 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_external.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_external.c @@ -4,7 +4,6 @@ * Author: Jyri Sarha <jsarha@ti.com> */ -#include <linux/component.h> #include <linux/of_graph.h> #include <drm/drm_atomic_helper.h> @@ -15,19 +14,6 @@ #include "tilcdc_drv.h" #include "tilcdc_external.h" -static const struct tilcdc_panel_info panel_info_tda998x = { - .ac_bias = 255, - .ac_bias_intrpt = 0, - .dma_burst_sz = 16, - .bpp = 16, - .fdd = 0x80, - .tft_alt_mode = 0, - .invert_pxl_clk = 1, - .sync_edge = 1, - .sync_ctrl = 1, - .raster_order = 0, -}; - static const struct tilcdc_panel_info panel_info_default = { .ac_bias = 255, .ac_bias_intrpt = 0, @@ -57,34 +43,6 @@ struct drm_connector *tilcdc_encoder_find_connector(struct drm_device *ddev, return NULL; } -int tilcdc_add_component_encoder(struct drm_device *ddev) -{ - struct tilcdc_drm_private *priv = ddev->dev_private; - struct drm_encoder *encoder = NULL, *iter; - - list_for_each_entry(iter, &ddev->mode_config.encoder_list, head) - if (iter->possible_crtcs & (1 << priv->crtc->index)) { - encoder = iter; - break; - } - - if (!encoder) { - dev_err(ddev->dev, "%s: No suitable encoder found\n", __func__); - return -ENODEV; - } - - priv->external_connector = - tilcdc_encoder_find_connector(ddev, encoder); - - if (!priv->external_connector) - return -ENODEV; - - /* Only tda998x is supported at the moment. */ - tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_tda998x); - - return 0; -} - static int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) { @@ -153,26 +111,3 @@ int tilcdc_attach_external_device(struct drm_device *ddev) drm_encoder_cleanup(priv->external_encoder); return ret; } - -static int dev_match_of(struct device *dev, void *data) -{ - return dev->of_node == data; -} - -int tilcdc_get_external_components(struct device *dev, - struct component_match **match) -{ - struct device_node *node; - - node = of_graph_get_remote_node(dev->of_node, 0, 0); - - if (!of_device_is_compatible(node, "nxp,tda998x")) { - of_node_put(node); - return 0; - } - - if (match) - drm_of_component_match_add(dev, match, dev_match_of, node); - of_node_put(node); - return 1; -} diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.h b/drivers/gpu/drm/tilcdc/tilcdc_external.h index fb4476694cd89..285a132f3035d 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_external.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_external.h @@ -7,8 +7,5 @@ #ifndef __TILCDC_EXTERNAL_H__ #define __TILCDC_EXTERNAL_H__ -int tilcdc_add_component_encoder(struct drm_device *dev); -int tilcdc_get_external_components(struct device *dev, - struct component_match **match); int tilcdc_attach_external_device(struct drm_device *ddev); #endif /* __TILCDC_SLAVE_H__ */ -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:25 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Remove the unnecessary #endif/#ifdef CONFIG_DEBUG_FS pair that splits the debugfs code section. This keeps all debugfs-related code within a single preprocessor conditional block, improving code readability. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index f865c131dae66..fd6764ce80afa 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -429,9 +429,6 @@ static const struct { #undef REG }; -#endif - -#ifdef CONFIG_DEBUG_FS static int tilcdc_regs_show(struct seq_file *m, void *arg) { struct drm_info_node *node = (struct drm_info_node *) m->private; -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:27 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Remove the tilcdc_panel_info structure and its associated helper function as the structure contains only redundant or unused parameters. Most panel configuration parameters in tilcdc_panel_info are either: - Already represented by existing DRM mode flags (invert_pxl_clk, sync_edge via DRM_BUS_FLAG_*), or - Set to identical values across all instances (panel_info_default), making them effectively constants The removed fifo_th field is already handled by priv->fifo_th when set. Other removed fields (tft_alt_mode, raster_order) were always set to 0 in the only instance (panel_info_default) and thus had no effect. This simplifies the code by eliminating unnecessary abstraction while preserving all functional behavior. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 28 +++------------------ drivers/gpu/drm/tilcdc/tilcdc_drv.h | 42 -------------------------------- drivers/gpu/drm/tilcdc/tilcdc_external.c | 14 ----------- 3 files changed, 3 insertions(+), 81 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index 252e5adaeb6e2..5b8aba0765f9b 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c @@ -31,7 +31,6 @@ struct tilcdc_crtc { struct drm_crtc base; struct drm_plane primary; - const struct tilcdc_panel_info *info; struct drm_pending_vblank_event *event; struct mutex enable_lock; bool enabled; @@ -272,14 +271,10 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); struct drm_device *dev = crtc->dev; struct tilcdc_drm_private *priv = dev->dev_private; - const struct tilcdc_panel_info *info = tilcdc_crtc->info; uint32_t reg, hbp, hfp, hsw, vbp, vfp, vsw; struct drm_display_mode *mode = &crtc->state->adjusted_mode; struct drm_framebuffer *fb = crtc->primary->state->fb; - if (WARN_ON(!info)) - return; - if (WARN_ON(!fb)) return; @@ -287,12 +282,11 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) reg = tilcdc_read(dev, LCDC_DMA_CTRL_REG) & ~0x00000770; /* Use 16 bit DMA burst size by default */ reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_16); + if (priv->fifo_th) { int fifo_th_val = ilog2(priv->fifo_th) - 3; reg |= (fifo_th_val << 8); - } else { - reg |= (info->fifo_th << 8); } tilcdc_write(dev, LCDC_DMA_CTRL_REG, reg); @@ -360,8 +354,6 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) LCDC_V2_TFT_24BPP_MODE | LCDC_V2_TFT_24BPP_UNPACK | 0x000ff000 /* Palette Loading Delay bits */); reg |= LCDC_TFT_MODE; /* no monochrome/passive support */ - if (info->tft_alt_mode) - reg |= LCDC_TFT_ALT_ENABLE; if (priv->rev == 2) { switch (fb->format->format) { case DRM_FORMAT_BGR565: @@ -384,15 +376,13 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) reg |= 128 << 12; tilcdc_write(dev, LCDC_RASTER_CTRL_REG, reg); - if (info->invert_pxl_clk || - mode->flags == DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE) + if (mode->flags == DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE) tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); else tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); - if (info->sync_edge || - mode->flags == DRM_BUS_FLAG_SYNC_DRIVE_NEGEDGE) + if (mode->flags == DRM_BUS_FLAG_SYNC_DRIVE_NEGEDGE) tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); else tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); @@ -407,11 +397,6 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) else tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_VSYNC); - if (info->raster_order) - tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER); - else - tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER); - tilcdc_crtc_set_clk(crtc); tilcdc_crtc_load_palette(crtc); @@ -838,13 +823,6 @@ static const struct drm_crtc_helper_funcs tilcdc_crtc_helper_funcs = { .atomic_flush = tilcdc_crtc_atomic_flush, }; -void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc, - const struct tilcdc_panel_info *info) -{ - struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); - tilcdc_crtc->info = info; -} - void tilcdc_crtc_update_clk(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index c23b593dc61f6..181b9d7a515b6 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -114,53 +114,11 @@ void tilcdc_module_init(struct tilcdc_module *mod, const char *name, const struct tilcdc_module_ops *funcs); void tilcdc_module_cleanup(struct tilcdc_module *mod); -/* Panel config that needs to be set in the crtc, but is not coming from - * the mode timings. The display module is expected to call - * tilcdc_crtc_set_panel_info() to set this during modeset. - */ -struct tilcdc_panel_info { - - /* AC Bias Pin Frequency */ - uint32_t ac_bias; - - /* AC Bias Pin Transitions per Interrupt */ - uint32_t ac_bias_intrpt; - - /* DMA burst size */ - uint32_t dma_burst_sz; - - /* Bits per pixel */ - uint32_t bpp; - - /* FIFO DMA Request Delay */ - uint32_t fdd; - - /* TFT Alternative Signal Mapping (Only for active) */ - bool tft_alt_mode; - - /* Invert pixel clock */ - bool invert_pxl_clk; - - /* Horizontal and Vertical Sync Edge: 0=rising 1=falling */ - uint32_t sync_edge; - - /* Horizontal and Vertical Sync: Control: 0=ignore */ - uint32_t sync_ctrl; - - /* Raster Data Order Select: 1=Most-to-least 0=Least-to-most */ - uint32_t raster_order; - - /* DMA FIFO threshold */ - uint32_t fifo_th; -}; - #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__) int tilcdc_crtc_create(struct drm_device *dev); irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc); void tilcdc_crtc_update_clk(struct drm_crtc *crtc); -void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc, - const struct tilcdc_panel_info *info); void tilcdc_crtc_shutdown(struct drm_crtc *crtc); void tilcdc_crtc_destroy(struct drm_crtc *crtc); int tilcdc_crtc_update_fb(struct drm_crtc *crtc, diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.c b/drivers/gpu/drm/tilcdc/tilcdc_external.c index 2970c41d9c3eb..81c90c2754c6c 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_external.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_external.c @@ -14,18 +14,6 @@ #include "tilcdc_drv.h" #include "tilcdc_external.h" -static const struct tilcdc_panel_info panel_info_default = { - .ac_bias = 255, - .ac_bias_intrpt = 0, - .dma_burst_sz = 16, - .bpp = 16, - .fdd = 0x80, - .tft_alt_mode = 0, - .sync_edge = 0, - .sync_ctrl = 1, - .raster_order = 0, -}; - static struct drm_connector *tilcdc_encoder_find_connector(struct drm_device *ddev, struct drm_encoder *encoder) @@ -55,8 +43,6 @@ int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) if (ret) return ret; - tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_default); - priv->external_connector = tilcdc_encoder_find_connector(ddev, priv->external_encoder); if (!priv->external_connector) -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:26 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
The num_encoders/encoders and num_connectors/connectors arrays in tilcdc_drm_private are never populated or used by the driver. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 3 +-- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index fd6764ce80afa..d911d413682ef 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -339,8 +339,7 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) if (ret) goto unregister_cpufreq_notif; - if (!priv->external_connector && - ((priv->num_encoders == 0) || (priv->num_connectors == 0))) { + if (!priv->external_connector) { dev_err(dev, "no encoders/connectors found\n"); ret = -EPROBE_DEFER; goto unregister_cpufreq_notif; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index 181b9d7a515b6..717529a331009 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -75,12 +75,6 @@ struct tilcdc_drm_private { struct drm_crtc *crtc; - unsigned int num_encoders; - struct drm_encoder *encoders[8]; - - unsigned int num_connectors; - struct drm_connector *connectors[8]; - struct drm_encoder *external_encoder; struct drm_connector *external_connector; -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:28 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Remove the "external_" prefix from encoder and connector members in the tilcdc driver. These are internal driver structures and the "external" naming is misleading. The simpler names better reflect that these are the primary encoder and connector managed by this driver. Also rename tilcdc_attach_external_device() to tilcdc_encoder_create() for consistency and to better describe the function's purpose. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 4 ++-- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 4 ++-- drivers/gpu/drm/tilcdc/tilcdc_external.c | 21 +++++++++------------ drivers/gpu/drm/tilcdc/tilcdc_external.h | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index d911d413682ef..4b9fa819358a2 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -335,11 +335,11 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) } #endif - ret = tilcdc_attach_external_device(ddev); + ret = tilcdc_encoder_create(ddev); if (ret) goto unregister_cpufreq_notif; - if (!priv->external_connector) { + if (!priv->connector) { dev_err(dev, "no encoders/connectors found\n"); ret = -EPROBE_DEFER; goto unregister_cpufreq_notif; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index 717529a331009..dafb00908d1d4 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -75,8 +75,8 @@ struct tilcdc_drm_private { struct drm_crtc *crtc; - struct drm_encoder *external_encoder; - struct drm_connector *external_connector; + struct drm_encoder *encoder; + struct drm_connector *connector; bool irq_enabled; }; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.c b/drivers/gpu/drm/tilcdc/tilcdc_external.c index 81c90c2754c6c..11ac9673ba98a 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_external.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_external.c @@ -37,21 +37,20 @@ int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) struct tilcdc_drm_private *priv = ddev->dev_private; int ret; - priv->external_encoder->possible_crtcs = BIT(0); + priv->encoder->possible_crtcs = BIT(0); - ret = drm_bridge_attach(priv->external_encoder, bridge, NULL, 0); + ret = drm_bridge_attach(priv->encoder, bridge, NULL, 0); if (ret) return ret; - priv->external_connector = - tilcdc_encoder_find_connector(ddev, priv->external_encoder); - if (!priv->external_connector) + priv->connector = tilcdc_encoder_find_connector(ddev, priv->encoder); + if (!priv->connector) return -ENODEV; return 0; } -int tilcdc_attach_external_device(struct drm_device *ddev) +int tilcdc_encoder_create(struct drm_device *ddev) { struct tilcdc_drm_private *priv = ddev->dev_private; struct drm_bridge *bridge; @@ -65,13 +64,11 @@ int tilcdc_attach_external_device(struct drm_device *ddev) else if (ret) return ret; - priv->external_encoder = devm_kzalloc(ddev->dev, - sizeof(*priv->external_encoder), - GFP_KERNEL); - if (!priv->external_encoder) + priv->encoder = devm_kzalloc(ddev->dev, sizeof(*priv->encoder), GFP_KERNEL); + if (!priv->encoder) return -ENOMEM; - ret = drm_simple_encoder_init(ddev, priv->external_encoder, + ret = drm_simple_encoder_init(ddev, priv->encoder, DRM_MODE_ENCODER_NONE); if (ret) { dev_err(ddev->dev, "drm_encoder_init() failed %d\n", ret); @@ -94,6 +91,6 @@ int tilcdc_attach_external_device(struct drm_device *ddev) return 0; err_encoder_cleanup: - drm_encoder_cleanup(priv->external_encoder); + drm_encoder_cleanup(priv->encoder); return ret; } diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.h b/drivers/gpu/drm/tilcdc/tilcdc_external.h index 285a132f3035d..c8f87f59024e6 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_external.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_external.h @@ -7,5 +7,5 @@ #ifndef __TILCDC_EXTERNAL_H__ #define __TILCDC_EXTERNAL_H__ -int tilcdc_attach_external_device(struct drm_device *ddev); +int tilcdc_encoder_create(struct drm_device *ddev); #endif /* __TILCDC_SLAVE_H__ */ -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:29 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
The tilcdc_external module describes the encoder part of the tilcdc driver. Rename it to tilcdc_encoder for better clarity and to make the naming more consistent with DRM subsystem conventions, where encoder-related files typically use "encoder" in their names. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/tilcdc/Makefile | 2 +- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 2 +- drivers/gpu/drm/tilcdc/{tilcdc_external.c => tilcdc_encoder.c} | 2 +- drivers/gpu/drm/tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 0 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/Makefile b/drivers/gpu/drm/tilcdc/Makefile index b78204a65ce29..c6b484dad711a 100644 --- a/drivers/gpu/drm/tilcdc/Makefile +++ b/drivers/gpu/drm/tilcdc/Makefile @@ -6,7 +6,7 @@ endif tilcdc-y := \ tilcdc_plane.o \ tilcdc_crtc.o \ - tilcdc_external.o \ + tilcdc_encoder.o \ tilcdc_drv.o obj-$(CONFIG_DRM_TILCDC) += tilcdc.o diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 4b9fa819358a2..d0503778b5f6f 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -26,7 +26,7 @@ #include "tilcdc_drv.h" -#include "tilcdc_external.h" +#include "tilcdc_encoder.h" #include "tilcdc_regs.h" enum tilcdc_variant { diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c similarity index 98% rename from drivers/gpu/drm/tilcdc/tilcdc_external.c rename to drivers/gpu/drm/tilcdc/tilcdc_encoder.c index 11ac9673ba98a..b1c7b2257df30 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_external.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c @@ -12,7 +12,7 @@ #include <drm/drm_simple_kms_helper.h> #include "tilcdc_drv.h" -#include "tilcdc_external.h" +#include "tilcdc_encoder.h" static struct drm_connector *tilcdc_encoder_find_connector(struct drm_device *ddev, diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.h b/drivers/gpu/drm/tilcdc/tilcdc_encoder.h similarity index 100% rename from drivers/gpu/drm/tilcdc/tilcdc_external.h rename to drivers/gpu/drm/tilcdc/tilcdc_encoder.h -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:30 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
The tilcdc driver previously supported a sub-module system where external display drivers (panels, encoders) could register themselves through tilcdc_module_init() and be automatically initialized through a module list. This infrastructure became unused after the component framework support and panel driver was removed. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v3: - Move the removal of module_init/exit in a following patch. --- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 29 ----------------------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 27 --------------------------- 2 files changed, 56 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index d0503778b5f6f..20f93240b335c 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -7,7 +7,6 @@ /* LCDC DRM driver, based on da8xx-fb */ #include <linux/mod_devicetable.h> -#include <linux/module.h> #include <linux/pinctrl/consumer.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> @@ -34,8 +33,6 @@ enum tilcdc_variant { DA850_TILCDC, }; -static LIST_HEAD(module_list); - static const u32 tilcdc_rev1_formats[] = { DRM_FORMAT_RGB565 }; static const u32 tilcdc_straight_formats[] = { DRM_FORMAT_RGB565, @@ -50,20 +47,6 @@ static const u32 tilcdc_legacy_formats[] = { DRM_FORMAT_RGB565, DRM_FORMAT_RGB888, DRM_FORMAT_XRGB8888 }; -void tilcdc_module_init(struct tilcdc_module *mod, const char *name, - const struct tilcdc_module_ops *funcs) -{ - mod->name = name; - mod->funcs = funcs; - INIT_LIST_HEAD(&mod->list); - list_add(&mod->list, &module_list); -} - -void tilcdc_module_cleanup(struct tilcdc_module *mod) -{ - list_del(&mod->list); -} - static int tilcdc_atomic_check(struct drm_device *dev, struct drm_atomic_state *state) { @@ -97,12 +80,6 @@ static const struct drm_mode_config_funcs mode_config_funcs = { static void modeset_init(struct drm_device *dev) { struct tilcdc_drm_private *priv = dev->dev_private; - struct tilcdc_module *mod; - - list_for_each_entry(mod, &module_list, list) { - DBG("loading module: %s", mod->name); - mod->funcs->modeset_init(mod, dev); - } dev->mode_config.min_width = 0; dev->mode_config.min_height = 0; @@ -465,15 +442,9 @@ static struct drm_info_list tilcdc_debugfs_list[] = { static void tilcdc_debugfs_init(struct drm_minor *minor) { - struct tilcdc_module *mod; - drm_debugfs_create_files(tilcdc_debugfs_list, ARRAY_SIZE(tilcdc_debugfs_list), minor->debugfs_root, minor); - - list_for_each_entry(mod, &module_list, list) - if (mod->funcs->debugfs_init) - mod->funcs->debugfs_init(mod, minor); } #endif diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index dafb00908d1d4..60e85e29b1063 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -81,33 +81,6 @@ struct tilcdc_drm_private { bool irq_enabled; }; -/* Sub-module for display. Since we don't know at compile time what panels - * or display adapter(s) might be present (for ex, off chip dvi/tfp410, - * hdmi encoder, various lcd panels), the connector/encoder(s) are split into - * separate drivers. If they are probed and found to be present, they - * register themselves with tilcdc_register_module(). - */ -struct tilcdc_module; - -struct tilcdc_module_ops { - /* create appropriate encoders/connectors: */ - int (*modeset_init)(struct tilcdc_module *mod, struct drm_device *dev); -#ifdef CONFIG_DEBUG_FS - /* create debugfs nodes (can be NULL): */ - int (*debugfs_init)(struct tilcdc_module *mod, struct drm_minor *minor); -#endif -}; - -struct tilcdc_module { - const char *name; - struct list_head list; - const struct tilcdc_module_ops *funcs; -}; - -void tilcdc_module_init(struct tilcdc_module *mod, const char *name, - const struct tilcdc_module_ops *funcs); -void tilcdc_module_cleanup(struct tilcdc_module *mod); - #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__) int tilcdc_crtc_create(struct drm_device *dev); -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:31 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Use the drm_module_platform_driver() helper macro to simplify driver registration. This macro handles both the platform driver registration and the drm_firmware_drivers_only() check, making the custom init/exit functions unnecessary. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v3: - New patch split from previous patch of the series. --- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 20f93240b335c..97380b623fca3 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -20,6 +20,7 @@ #include <drm/drm_gem_dma_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_mm.h> +#include <drm/drm_module.h> #include <drm/drm_probe_helper.h> #include <drm/drm_vblank.h> @@ -532,23 +533,7 @@ static struct platform_driver tilcdc_platform_driver = { }, }; -static int __init tilcdc_drm_init(void) -{ - if (drm_firmware_drivers_only()) - return -ENODEV; - - DBG("init"); - return platform_driver_register(&tilcdc_platform_driver); -} - -static void __exit tilcdc_drm_fini(void) -{ - DBG("fini"); - platform_driver_unregister(&tilcdc_platform_driver); -} - -module_init(tilcdc_drm_init); -module_exit(tilcdc_drm_fini); +drm_module_platform_driver(tilcdc_platform_driver); MODULE_AUTHOR("Rob Clark <robdclark@gmail.com"); MODULE_DESCRIPTION("TI LCD Controller DRM Driver"); -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:32 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Move tilcdc_init/fini functions adjacent to the probe and remove functions in preparation for cleanup and modernization. This improves readability for subsequent commits that will refactor these functions. No functional changes, only code reorganization. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v3: - New patch. --- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 238 ++++++++++++++++++------------------ 1 file changed, 119 insertions(+), 119 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 97380b623fca3..abe432b752dc0 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -140,6 +140,125 @@ static void tilcdc_irq_uninstall(struct drm_device *dev) * DRM operations: */ +#if defined(CONFIG_DEBUG_FS) +static const struct { + const char *name; + uint8_t rev; + uint8_t save; + uint32_t reg; +} registers[] = { +#define REG(rev, save, reg) { #reg, rev, save, reg } + /* exists in revision 1: */ + REG(1, false, LCDC_PID_REG), + REG(1, true, LCDC_CTRL_REG), + REG(1, false, LCDC_STAT_REG), + REG(1, true, LCDC_RASTER_CTRL_REG), + REG(1, true, LCDC_RASTER_TIMING_0_REG), + REG(1, true, LCDC_RASTER_TIMING_1_REG), + REG(1, true, LCDC_RASTER_TIMING_2_REG), + REG(1, true, LCDC_DMA_CTRL_REG), + REG(1, true, LCDC_DMA_FB_BASE_ADDR_0_REG), + REG(1, true, LCDC_DMA_FB_CEILING_ADDR_0_REG), + REG(1, true, LCDC_DMA_FB_BASE_ADDR_1_REG), + REG(1, true, LCDC_DMA_FB_CEILING_ADDR_1_REG), + /* new in revision 2: */ + REG(2, false, LCDC_RAW_STAT_REG), + REG(2, false, LCDC_MASKED_STAT_REG), + REG(2, true, LCDC_INT_ENABLE_SET_REG), + REG(2, false, LCDC_INT_ENABLE_CLR_REG), + REG(2, false, LCDC_END_OF_INT_IND_REG), + REG(2, true, LCDC_CLK_ENABLE_REG), +#undef REG +}; + +static int tilcdc_regs_show(struct seq_file *m, void *arg) +{ + struct drm_info_node *node = (struct drm_info_node *) m->private; + struct drm_device *dev = node->minor->dev; + struct tilcdc_drm_private *priv = dev->dev_private; + unsigned i; + + pm_runtime_get_sync(dev->dev); + + seq_printf(m, "revision: %d\n", priv->rev); + + for (i = 0; i < ARRAY_SIZE(registers); i++) + if (priv->rev >= registers[i].rev) + seq_printf(m, "%s:\t %08x\n", registers[i].name, + tilcdc_read(dev, registers[i].reg)); + + pm_runtime_put_sync(dev->dev); + + return 0; +} + +static int tilcdc_mm_show(struct seq_file *m, void *arg) +{ + struct drm_info_node *node = (struct drm_info_node *) m->private; + struct drm_device *dev = node->minor->dev; + struct drm_printer p = drm_seq_file_printer(m); + drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p); + return 0; +} + +static struct drm_info_list tilcdc_debugfs_list[] = { + { "regs", tilcdc_regs_show, 0, NULL }, + { "mm", tilcdc_mm_show, 0, NULL }, +}; + +static void tilcdc_debugfs_init(struct drm_minor *minor) +{ + drm_debugfs_create_files(tilcdc_debugfs_list, + ARRAY_SIZE(tilcdc_debugfs_list), + minor->debugfs_root, minor); +} +#endif + +DEFINE_DRM_GEM_DMA_FOPS(fops); + +static const struct drm_driver tilcdc_driver = { + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, + DRM_GEM_DMA_DRIVER_OPS, + DRM_FBDEV_DMA_DRIVER_OPS, +#ifdef CONFIG_DEBUG_FS + .debugfs_init = tilcdc_debugfs_init, +#endif + .fops = &fops, + .name = "tilcdc", + .desc = "TI LCD Controller DRM", + .major = 1, + .minor = 0, +}; + +/* + * Power management: + */ + +static int tilcdc_pm_suspend(struct device *dev) +{ + struct drm_device *ddev = dev_get_drvdata(dev); + int ret = 0; + + ret = drm_mode_config_helper_suspend(ddev); + + /* Select sleep pin state */ + pinctrl_pm_select_sleep_state(dev); + + return ret; +} + +static int tilcdc_pm_resume(struct device *dev) +{ + struct drm_device *ddev = dev_get_drvdata(dev); + + /* Select default pin state */ + pinctrl_pm_select_default_state(dev); + return drm_mode_config_helper_resume(ddev); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(tilcdc_pm_ops, + tilcdc_pm_suspend, tilcdc_pm_resume); + static void tilcdc_fini(struct drm_device *dev) { struct tilcdc_drm_private *priv = dev->dev_private; @@ -375,125 +494,6 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) return ret; } -#if defined(CONFIG_DEBUG_FS) -static const struct { - const char *name; - uint8_t rev; - uint8_t save; - uint32_t reg; -} registers[] = { -#define REG(rev, save, reg) { #reg, rev, save, reg } - /* exists in revision 1: */ - REG(1, false, LCDC_PID_REG), - REG(1, true, LCDC_CTRL_REG), - REG(1, false, LCDC_STAT_REG), - REG(1, true, LCDC_RASTER_CTRL_REG), - REG(1, true, LCDC_RASTER_TIMING_0_REG), - REG(1, true, LCDC_RASTER_TIMING_1_REG), - REG(1, true, LCDC_RASTER_TIMING_2_REG), - REG(1, true, LCDC_DMA_CTRL_REG), - REG(1, true, LCDC_DMA_FB_BASE_ADDR_0_REG), - REG(1, true, LCDC_DMA_FB_CEILING_ADDR_0_REG), - REG(1, true, LCDC_DMA_FB_BASE_ADDR_1_REG), - REG(1, true, LCDC_DMA_FB_CEILING_ADDR_1_REG), - /* new in revision 2: */ - REG(2, false, LCDC_RAW_STAT_REG), - REG(2, false, LCDC_MASKED_STAT_REG), - REG(2, true, LCDC_INT_ENABLE_SET_REG), - REG(2, false, LCDC_INT_ENABLE_CLR_REG), - REG(2, false, LCDC_END_OF_INT_IND_REG), - REG(2, true, LCDC_CLK_ENABLE_REG), -#undef REG -}; - -static int tilcdc_regs_show(struct seq_file *m, void *arg) -{ - struct drm_info_node *node = (struct drm_info_node *) m->private; - struct drm_device *dev = node->minor->dev; - struct tilcdc_drm_private *priv = dev->dev_private; - unsigned i; - - pm_runtime_get_sync(dev->dev); - - seq_printf(m, "revision: %d\n", priv->rev); - - for (i = 0; i < ARRAY_SIZE(registers); i++) - if (priv->rev >= registers[i].rev) - seq_printf(m, "%s:\t %08x\n", registers[i].name, - tilcdc_read(dev, registers[i].reg)); - - pm_runtime_put_sync(dev->dev); - - return 0; -} - -static int tilcdc_mm_show(struct seq_file *m, void *arg) -{ - struct drm_info_node *node = (struct drm_info_node *) m->private; - struct drm_device *dev = node->minor->dev; - struct drm_printer p = drm_seq_file_printer(m); - drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p); - return 0; -} - -static struct drm_info_list tilcdc_debugfs_list[] = { - { "regs", tilcdc_regs_show, 0, NULL }, - { "mm", tilcdc_mm_show, 0, NULL }, -}; - -static void tilcdc_debugfs_init(struct drm_minor *minor) -{ - drm_debugfs_create_files(tilcdc_debugfs_list, - ARRAY_SIZE(tilcdc_debugfs_list), - minor->debugfs_root, minor); -} -#endif - -DEFINE_DRM_GEM_DMA_FOPS(fops); - -static const struct drm_driver tilcdc_driver = { - .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, - DRM_GEM_DMA_DRIVER_OPS, - DRM_FBDEV_DMA_DRIVER_OPS, -#ifdef CONFIG_DEBUG_FS - .debugfs_init = tilcdc_debugfs_init, -#endif - .fops = &fops, - .name = "tilcdc", - .desc = "TI LCD Controller DRM", - .major = 1, - .minor = 0, -}; - -/* - * Power management: - */ - -static int tilcdc_pm_suspend(struct device *dev) -{ - struct drm_device *ddev = dev_get_drvdata(dev); - int ret = 0; - - ret = drm_mode_config_helper_suspend(ddev); - - /* Select sleep pin state */ - pinctrl_pm_select_sleep_state(dev); - - return ret; -} - -static int tilcdc_pm_resume(struct device *dev) -{ - struct drm_device *ddev = dev_get_drvdata(dev); - - /* Select default pin state */ - pinctrl_pm_select_default_state(dev); - return drm_mode_config_helper_resume(ddev); -} - -static DEFINE_SIMPLE_DEV_PM_OPS(tilcdc_pm_ops, - tilcdc_pm_suspend, tilcdc_pm_resume); - static int tilcdc_pdev_probe(struct platform_device *pdev) { /* bail out early if no DT data: */ -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:33 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Refactor the driver initialization to use modern DRM managed resource APIs, simplifying the code. The tilcdc_init and tilcdc_fini wrapper functions are removed since they served no purpose after the component framework was eliminated. Their logic is integrated directly into probe and remove. Key changes: - Use devm_drm_dev_alloc() instead of drm_dev_alloc(). - Use drmm_mode_config_init() instead of drm_mode_config_init(). - Align the remove path with the probe error path to ensure consistent cleanup ordering in both success and failure cases. - Adjust platform_set_drvdata() to store the private structure instead of the drm_device, matching the new allocation pattern. These changes reduce error-prone code while maintaining the same functional behavior. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v3: - Split the patch between code move and cleanup for better diff readibility. --- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 100 ++++++++++++------------------------ drivers/gpu/drm/tilcdc/tilcdc_drv.h | 2 + 2 files changed, 35 insertions(+), 67 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index abe432b752dc0..2f35075b663ff 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -259,68 +259,33 @@ static int tilcdc_pm_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(tilcdc_pm_ops, tilcdc_pm_suspend, tilcdc_pm_resume); -static void tilcdc_fini(struct drm_device *dev) -{ - struct tilcdc_drm_private *priv = dev->dev_private; - -#ifdef CONFIG_CPU_FREQ - if (priv->freq_transition.notifier_call) - cpufreq_unregister_notifier(&priv->freq_transition, - CPUFREQ_TRANSITION_NOTIFIER); -#endif - - if (priv->crtc) - tilcdc_crtc_shutdown(priv->crtc); - - drm_dev_unregister(dev); - - drm_kms_helper_poll_fini(dev); - drm_atomic_helper_shutdown(dev); - tilcdc_irq_uninstall(dev); - drm_mode_config_cleanup(dev); - - if (priv->clk) - clk_put(priv->clk); - - if (priv->wq) - destroy_workqueue(priv->wq); - - dev->dev_private = NULL; - - pm_runtime_disable(dev->dev); - - drm_dev_put(dev); -} - -static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) +static int tilcdc_pdev_probe(struct platform_device *pdev) { - struct drm_device *ddev; - struct platform_device *pdev = to_platform_device(dev); - struct device_node *node = dev->of_node; + struct device_node *node = pdev->dev.of_node; struct tilcdc_drm_private *priv; + struct device *dev = &pdev->dev; enum tilcdc_variant variant; + struct drm_device *ddev; u32 bpp = 0; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - - ddev = drm_dev_alloc(ddrv, dev); - if (IS_ERR(ddev)) - return PTR_ERR(ddev); + priv = devm_drm_dev_alloc(dev, &tilcdc_driver, + struct tilcdc_drm_private, ddev); + if (IS_ERR(priv)) + return PTR_ERR(priv); variant = (uintptr_t)of_device_get_match_data(dev); ddev->dev_private = priv; - platform_set_drvdata(pdev, ddev); - drm_mode_config_init(ddev); + platform_set_drvdata(pdev, priv); + ddev = &priv->ddev; + ret = drmm_mode_config_init(ddev); + if (ret) + return ret; priv->wq = alloc_ordered_workqueue("tilcdc", 0); - if (!priv->wq) { - ret = -ENOMEM; - goto put_drm; - } + if (!priv->wq) + return -ENOMEM; priv->mmio = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(priv->mmio)) { @@ -486,33 +451,34 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev) clk_put(priv->clk); free_wq: destroy_workqueue(priv->wq); -put_drm: - platform_set_drvdata(pdev, NULL); - ddev->dev_private = NULL; - drm_dev_put(ddev); return ret; } -static int tilcdc_pdev_probe(struct platform_device *pdev) -{ - /* bail out early if no DT data: */ - if (!pdev->dev.of_node) { - dev_err(&pdev->dev, "device-tree data is missing\n"); - return -ENXIO; - } - - return tilcdc_init(&tilcdc_driver, &pdev->dev); -} - static void tilcdc_pdev_remove(struct platform_device *pdev) { - tilcdc_fini(platform_get_drvdata(pdev)); + struct tilcdc_drm_private *priv = platform_get_drvdata(pdev); + struct drm_device *ddev = &priv->ddev; + + drm_dev_unregister(ddev); + drm_kms_helper_poll_fini(ddev); + tilcdc_irq_uninstall(ddev); +#ifdef CONFIG_CPU_FREQ + cpufreq_unregister_notifier(&priv->freq_transition, + CPUFREQ_TRANSITION_NOTIFIER); +#endif + tilcdc_crtc_destroy(priv->crtc); + pm_runtime_disable(&pdev->dev); + clk_put(priv->clk); + destroy_workqueue(priv->wq); } static void tilcdc_pdev_shutdown(struct platform_device *pdev) { - drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); + struct tilcdc_drm_private *priv = platform_get_drvdata(pdev); + struct drm_device *ddev = &priv->ddev; + + drm_atomic_helper_shutdown(ddev); } static const struct of_device_id tilcdc_of_match[] = { diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index 60e85e29b1063..e3d04a3eb25b4 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -48,6 +48,8 @@ struct tilcdc_drm_private { unsigned int irq; + struct drm_device ddev; + /* don't attempt resolutions w/ higher W * H * Hz: */ uint32_t max_bandwidth; /* -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:34 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
The DRM core documentation recommends against using dev_private: "Instead of using this pointer it is recommended that drivers use embed the struct &drm_device in their larger per-device structure." This patch refactors the tilcdc driver to follow this recommendation by embedding struct drm_device within struct tilcdc_drm_private and replacing all dev->dev_private accesses with the ddev_to_tilcdc_priv() helper macro that uses container_of(). This change aligns the driver with modern DRM best practices. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 28 ++++++++++++++-------------- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 11 +++++------ drivers/gpu/drm/tilcdc/tilcdc_drv.h | 2 ++ drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 4 ++-- drivers/gpu/drm/tilcdc/tilcdc_plane.c | 2 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 ++++---- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index 5b8aba0765f9b..0bd99a2efeeb4 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c @@ -59,7 +59,7 @@ struct tilcdc_crtc { static void set_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb) { struct drm_device *dev = crtc->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); struct drm_gem_dma_object *gem; dma_addr_t start, end; u64 dma_base_and_ceiling; @@ -94,7 +94,7 @@ static void tilcdc_crtc_load_palette(struct drm_crtc *crtc) { struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); struct drm_device *dev = crtc->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); int ret; reinit_completion(&tilcdc_crtc->palette_loaded); @@ -136,7 +136,7 @@ static void tilcdc_crtc_load_palette(struct drm_crtc *crtc) static void tilcdc_crtc_enable_irqs(struct drm_device *dev) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); tilcdc_clear_irqstatus(dev, 0xffffffff); @@ -153,7 +153,7 @@ static void tilcdc_crtc_enable_irqs(struct drm_device *dev) static void tilcdc_crtc_disable_irqs(struct drm_device *dev) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); /* disable irqs that we might have enabled: */ if (priv->rev == 1) { @@ -173,7 +173,7 @@ static void tilcdc_crtc_disable_irqs(struct drm_device *dev) static void reset(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); if (priv->rev != 2) return; @@ -198,7 +198,7 @@ static unsigned int tilcdc_pclk_diff(unsigned long rate, static void tilcdc_crtc_set_clk(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); unsigned long clk_rate, real_pclk_rate, pclk_rate; unsigned int clkdiv; @@ -270,7 +270,7 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) { struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); struct drm_device *dev = crtc->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); uint32_t reg, hbp, hfp, hsw, vbp, vfp, vsw; struct drm_display_mode *mode = &crtc->state->adjusted_mode; struct drm_framebuffer *fb = crtc->primary->state->fb; @@ -557,7 +557,7 @@ static void tilcdc_crtc_recover_work(struct work_struct *work) void tilcdc_crtc_destroy(struct drm_crtc *crtc) { - struct tilcdc_drm_private *priv = crtc->dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(crtc->dev); tilcdc_crtc_shutdown(crtc); @@ -647,7 +647,7 @@ static int tilcdc_crtc_enable_vblank(struct drm_crtc *crtc) { struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); struct drm_device *dev = crtc->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); unsigned long flags; spin_lock_irqsave(&tilcdc_crtc->irq_lock, flags); @@ -670,7 +670,7 @@ static void tilcdc_crtc_disable_vblank(struct drm_crtc *crtc) { struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); struct drm_device *dev = crtc->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); unsigned long flags; spin_lock_irqsave(&tilcdc_crtc->irq_lock, flags); @@ -728,7 +728,7 @@ static enum drm_mode_status tilcdc_crtc_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode) { - struct tilcdc_drm_private *priv = crtc->dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(crtc->dev); unsigned int bandwidth; uint32_t hbp, hfp, hsw, vbp, vfp, vsw; @@ -826,7 +826,7 @@ static const struct drm_crtc_helper_funcs tilcdc_crtc_helper_funcs = { void tilcdc_crtc_update_clk(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); drm_modeset_lock(&crtc->mutex, NULL); @@ -850,7 +850,7 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) { struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); struct drm_device *dev = crtc->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); uint32_t stat, reg; stat = tilcdc_read_irqstatus(dev); @@ -958,7 +958,7 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) int tilcdc_crtc_create(struct drm_device *dev) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); struct tilcdc_crtc *tilcdc_crtc; struct drm_crtc *crtc; int ret; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 2f35075b663ff..1a238a22309f4 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -80,7 +80,7 @@ static const struct drm_mode_config_funcs mode_config_funcs = { static void modeset_init(struct drm_device *dev) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); dev->mode_config.min_width = 0; dev->mode_config.min_height = 0; @@ -106,14 +106,14 @@ static int cpufreq_transition(struct notifier_block *nb, static irqreturn_t tilcdc_irq(int irq, void *arg) { struct drm_device *dev = arg; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); return tilcdc_crtc_irq(priv->crtc); } static int tilcdc_irq_install(struct drm_device *dev, unsigned int irq) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); int ret; ret = request_irq(irq, tilcdc_irq, 0, dev->driver->name, dev); @@ -127,7 +127,7 @@ static int tilcdc_irq_install(struct drm_device *dev, unsigned int irq) static void tilcdc_irq_uninstall(struct drm_device *dev) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); if (!priv->irq_enabled) return; @@ -175,7 +175,7 @@ static int tilcdc_regs_show(struct seq_file *m, void *arg) { struct drm_info_node *node = (struct drm_info_node *) m->private; struct drm_device *dev = node->minor->dev; - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); unsigned i; pm_runtime_get_sync(dev->dev); @@ -276,7 +276,6 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) variant = (uintptr_t)of_device_get_match_data(dev); - ddev->dev_private = priv; platform_set_drvdata(pdev, priv); ddev = &priv->ddev; ret = drmm_mode_config_init(ddev); diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index e3d04a3eb25b4..c69e279a2539d 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -85,6 +85,8 @@ struct tilcdc_drm_private { #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__) +#define ddev_to_tilcdc_priv(x) container_of(x, struct tilcdc_drm_private, ddev) + int tilcdc_crtc_create(struct drm_device *dev); irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc); void tilcdc_crtc_update_clk(struct drm_crtc *crtc); diff --git a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c index b1c7b2257df30..d42be3e16c536 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c @@ -34,7 +34,7 @@ struct drm_connector *tilcdc_encoder_find_connector(struct drm_device *ddev, static int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) { - struct tilcdc_drm_private *priv = ddev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(ddev); int ret; priv->encoder->possible_crtcs = BIT(0); @@ -52,7 +52,7 @@ int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) int tilcdc_encoder_create(struct drm_device *ddev) { - struct tilcdc_drm_private *priv = ddev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(ddev); struct drm_bridge *bridge; struct drm_panel *panel; int ret; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_plane.c b/drivers/gpu/drm/tilcdc/tilcdc_plane.c index aa72ca679598b..a77a5b22ebd96 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_plane.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_plane.c @@ -101,7 +101,7 @@ static const struct drm_plane_helper_funcs plane_helper_funcs = { int tilcdc_plane_init(struct drm_device *dev, struct drm_plane *plane) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); int ret; ret = drm_universal_plane_init(dev, plane, 1, &tilcdc_plane_funcs, diff --git a/drivers/gpu/drm/tilcdc/tilcdc_regs.h b/drivers/gpu/drm/tilcdc/tilcdc_regs.h index f90e2dc3457cd..26ebaf1e0f70f 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_regs.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_regs.h @@ -113,13 +113,13 @@ static inline void tilcdc_write(struct drm_device *dev, u32 reg, u32 data) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); iowrite32(data, priv->mmio + reg); } static inline void tilcdc_write64(struct drm_device *dev, u32 reg, u64 data) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); volatile void __iomem *addr = priv->mmio + reg; #if defined(iowrite64) && !defined(iowrite64_is_nonatomic) @@ -133,7 +133,7 @@ static inline void tilcdc_write64(struct drm_device *dev, u32 reg, u64 data) static inline u32 tilcdc_read(struct drm_device *dev, u32 reg) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); return ioread32(priv->mmio + reg); } @@ -156,7 +156,7 @@ static inline void tilcdc_clear(struct drm_device *dev, u32 reg, u32 mask) /* the register to read/clear irqstatus differs between v1 and v2 of the IP */ static inline u32 tilcdc_irqstatus_reg(struct drm_device *dev) { - struct tilcdc_drm_private *priv = dev->dev_private; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); return (priv->rev == 2) ? LCDC_MASKED_STAT_REG : LCDC_STAT_REG; } -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:35 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Convert the tilcdc driver to use DRM managed resources (drmm_* APIs) to eliminate resource lifetime issues, particularly in probe deferral scenarios. This conversion addresses potential use-after-free bugs by ensuring proper cleanup ordering through the DRM managed resource framework. The changes include: - Replace drm_crtc_init_with_planes() with drmm_crtc_alloc_with_planes() - Replace drm_universal_plane_init() with drmm_universal_plane_alloc() - Replace drm_simple_encoder_init() with drmm_simple_encoder_alloc() - Remove manual cleanup in tilcdc_crtc_destroy() and error paths - Remove drm_encoder_cleanup() from encoder error handling paths - Use drmm_add_action_or_reset() for remaining cleanup operations This approach is recommended by the DRM subsystem for improved resource lifetime management and is particularly important for drivers that may experience probe deferral. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v5: - Move drmm_add_action_or_reset() up to avoid missing cleanup in case of dmam_alloc_coherent() returning an error. Change in v4: - New patch. - Move on to DRM managed resources to fix null pointer dereference koops in case drm_of_find_panel_or_bridge() return EPROBE_DEFER. --- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 55 +++++++++++++++++---------------- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 5 +-- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 13 ++++++-- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 38 ++++++++--------------- drivers/gpu/drm/tilcdc/tilcdc_plane.c | 27 +++++++--------- 5 files changed, 64 insertions(+), 74 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index 0bd99a2efeeb4..2916de3dce91e 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c @@ -16,6 +16,7 @@ #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem_dma_helper.h> +#include <drm/drm_managed.h> #include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_print.h> #include <drm/drm_vblank.h> @@ -30,7 +31,7 @@ struct tilcdc_crtc { struct drm_crtc base; - struct drm_plane primary; + struct tilcdc_plane *primary; struct drm_pending_vblank_event *event; struct mutex enable_lock; bool enabled; @@ -555,16 +556,15 @@ static void tilcdc_crtc_recover_work(struct work_struct *work) drm_modeset_unlock(&crtc->mutex); } -void tilcdc_crtc_destroy(struct drm_crtc *crtc) +static void tilcdc_crtc_destroy(struct drm_device *dev, void *data) { - struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(crtc->dev); + struct tilcdc_drm_private *priv = (struct tilcdc_drm_private *)data; - tilcdc_crtc_shutdown(crtc); + tilcdc_crtc_shutdown(priv->crtc); flush_workqueue(priv->wq); - of_node_put(crtc->port); - drm_crtc_cleanup(crtc); + of_node_put(priv->crtc->port); } int tilcdc_crtc_update_fb(struct drm_crtc *crtc, @@ -714,7 +714,6 @@ static void tilcdc_crtc_reset(struct drm_crtc *crtc) } static const struct drm_crtc_funcs tilcdc_crtc_funcs = { - .destroy = tilcdc_crtc_destroy, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, .reset = tilcdc_crtc_reset, @@ -960,12 +959,31 @@ int tilcdc_crtc_create(struct drm_device *dev) { struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); struct tilcdc_crtc *tilcdc_crtc; + struct tilcdc_plane *primary; struct drm_crtc *crtc; int ret; - tilcdc_crtc = devm_kzalloc(dev->dev, sizeof(*tilcdc_crtc), GFP_KERNEL); - if (!tilcdc_crtc) - return -ENOMEM; + primary = tilcdc_plane_init(dev); + if (IS_ERR(primary)) { + dev_err(dev->dev, "Failed to initialize plane: %pe\n", primary); + return PTR_ERR(primary); + } + + tilcdc_crtc = drmm_crtc_alloc_with_planes(dev, struct tilcdc_crtc, base, + &primary->base, + NULL, + &tilcdc_crtc_funcs, + "tilcdc crtc"); + if (IS_ERR(tilcdc_crtc)) { + dev_err(dev->dev, "Failed to init CRTC: %pe\n", tilcdc_crtc); + return PTR_ERR(tilcdc_crtc); + } + + tilcdc_crtc->primary = primary; + priv->crtc = &tilcdc_crtc->base; + ret = drmm_add_action_or_reset(dev, tilcdc_crtc_destroy, priv); + if (ret) + return ret; init_completion(&tilcdc_crtc->palette_loaded); tilcdc_crtc->palette_base = dmam_alloc_coherent(dev->dev, @@ -978,10 +996,6 @@ int tilcdc_crtc_create(struct drm_device *dev) crtc = &tilcdc_crtc->base; - ret = tilcdc_plane_init(dev, &tilcdc_crtc->primary); - if (ret < 0) - goto fail; - mutex_init(&tilcdc_crtc->enable_lock); init_waitqueue_head(&tilcdc_crtc->frame_done_wq); @@ -989,20 +1003,7 @@ int tilcdc_crtc_create(struct drm_device *dev) spin_lock_init(&tilcdc_crtc->irq_lock); INIT_WORK(&tilcdc_crtc->recover_work, tilcdc_crtc_recover_work); - ret = drm_crtc_init_with_planes(dev, crtc, - &tilcdc_crtc->primary, - NULL, - &tilcdc_crtc_funcs, - "tilcdc crtc"); - if (ret < 0) - goto fail; - drm_crtc_helper_add(crtc, &tilcdc_crtc_helper_funcs); - priv->crtc = crtc; return 0; - -fail: - tilcdc_crtc_destroy(crtc); - return ret; } diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 1a238a22309f4..3b11d296a7e91 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -392,7 +392,7 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "failed to register cpufreq notifier\n"); priv->freq_transition.notifier_call = NULL; - goto destroy_crtc; + goto disable_pm; } #endif @@ -442,9 +442,7 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) #ifdef CONFIG_CPU_FREQ cpufreq_unregister_notifier(&priv->freq_transition, CPUFREQ_TRANSITION_NOTIFIER); -destroy_crtc: #endif - tilcdc_crtc_destroy(priv->crtc); disable_pm: pm_runtime_disable(dev); clk_put(priv->clk); @@ -466,7 +464,6 @@ static void tilcdc_pdev_remove(struct platform_device *pdev) cpufreq_unregister_notifier(&priv->freq_transition, CPUFREQ_TRANSITION_NOTIFIER); #endif - tilcdc_crtc_destroy(priv->crtc); pm_runtime_disable(&pdev->dev); clk_put(priv->clk); destroy_workqueue(priv->wq); diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index c69e279a2539d..17d152f9f0b69 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -77,7 +77,7 @@ struct tilcdc_drm_private { struct drm_crtc *crtc; - struct drm_encoder *encoder; + struct tilcdc_encoder *encoder; struct drm_connector *connector; bool irq_enabled; @@ -91,11 +91,18 @@ int tilcdc_crtc_create(struct drm_device *dev); irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc); void tilcdc_crtc_update_clk(struct drm_crtc *crtc); void tilcdc_crtc_shutdown(struct drm_crtc *crtc); -void tilcdc_crtc_destroy(struct drm_crtc *crtc); int tilcdc_crtc_update_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb, struct drm_pending_vblank_event *event); -int tilcdc_plane_init(struct drm_device *dev, struct drm_plane *plane); +struct tilcdc_plane { + struct drm_plane base; +}; + +struct tilcdc_encoder { + struct drm_encoder base; +}; + +struct tilcdc_plane *tilcdc_plane_init(struct drm_device *dev); #endif /* __TILCDC_DRV_H__ */ diff --git a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c index d42be3e16c536..1ee5761757a8c 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c @@ -37,13 +37,13 @@ int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(ddev); int ret; - priv->encoder->possible_crtcs = BIT(0); + priv->encoder->base.possible_crtcs = BIT(0); - ret = drm_bridge_attach(priv->encoder, bridge, NULL, 0); + ret = drm_bridge_attach(&priv->encoder->base, bridge, NULL, 0); if (ret) return ret; - priv->connector = tilcdc_encoder_find_connector(ddev, priv->encoder); + priv->connector = tilcdc_encoder_find_connector(ddev, &priv->encoder->base); if (!priv->connector) return -ENODEV; @@ -53,6 +53,7 @@ int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) int tilcdc_encoder_create(struct drm_device *ddev) { struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(ddev); + struct tilcdc_encoder *encoder; struct drm_bridge *bridge; struct drm_panel *panel; int ret; @@ -64,33 +65,20 @@ int tilcdc_encoder_create(struct drm_device *ddev) else if (ret) return ret; - priv->encoder = devm_kzalloc(ddev->dev, sizeof(*priv->encoder), GFP_KERNEL); - if (!priv->encoder) - return -ENOMEM; - - ret = drm_simple_encoder_init(ddev, priv->encoder, - DRM_MODE_ENCODER_NONE); - if (ret) { - dev_err(ddev->dev, "drm_encoder_init() failed %d\n", ret); - return ret; + encoder = drmm_simple_encoder_alloc(ddev, struct tilcdc_encoder, + base, DRM_MODE_ENCODER_NONE); + if (IS_ERR(encoder)) { + dev_err(ddev->dev, "drm_encoder_init() failed %pe\n", encoder); + return PTR_ERR(encoder); } + priv->encoder = encoder; if (panel) { bridge = devm_drm_panel_bridge_add_typed(ddev->dev, panel, DRM_MODE_CONNECTOR_DPI); - if (IS_ERR(bridge)) { - ret = PTR_ERR(bridge); - goto err_encoder_cleanup; - } + if (IS_ERR(bridge)) + return PTR_ERR(bridge); } - ret = tilcdc_attach_bridge(ddev, bridge); - if (ret) - goto err_encoder_cleanup; - - return 0; - -err_encoder_cleanup: - drm_encoder_cleanup(priv->encoder); - return ret; + return tilcdc_attach_bridge(ddev, bridge); } diff --git a/drivers/gpu/drm/tilcdc/tilcdc_plane.c b/drivers/gpu/drm/tilcdc/tilcdc_plane.c index a77a5b22ebd96..d98a1ae0e31f8 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_plane.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_plane.c @@ -14,7 +14,6 @@ static const struct drm_plane_funcs tilcdc_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, - .destroy = drm_plane_cleanup, .reset = drm_atomic_helper_plane_reset, .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, @@ -98,22 +97,20 @@ static const struct drm_plane_helper_funcs plane_helper_funcs = { .atomic_update = tilcdc_plane_atomic_update, }; -int tilcdc_plane_init(struct drm_device *dev, - struct drm_plane *plane) +struct tilcdc_plane *tilcdc_plane_init(struct drm_device *dev) { struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); - int ret; - - ret = drm_universal_plane_init(dev, plane, 1, &tilcdc_plane_funcs, - priv->pixelformats, - priv->num_pixelformats, - NULL, DRM_PLANE_TYPE_PRIMARY, NULL); - if (ret) { - dev_err(dev->dev, "Failed to initialize plane: %d\n", ret); - return ret; - } + struct tilcdc_plane *plane; - drm_plane_helper_add(plane, &plane_helper_funcs); + plane = drmm_universal_plane_alloc(dev, struct tilcdc_plane, base, + 1, &tilcdc_plane_funcs, + priv->pixelformats, + priv->num_pixelformats, + NULL, DRM_PLANE_TYPE_PRIMARY, NULL); + if (IS_ERR(plane)) + return plane; - return 0; + drm_plane_helper_add(&plane->base, &plane_helper_funcs); + + return plane; } -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:36 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper which simplifies the code by: - Automatically handling both panel and bridge cases internally - Managing the panel-to-bridge conversion when needed - Using devres for resource management, eliminating manual cleanup This removes the need for explicit panel-to-bridge conversion via devm_drm_panel_bridge_add_typed() and the associated error handling path. Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v4: - New patch --- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c index a34a10337f6a8..546fe7e6ee815 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c @@ -55,15 +55,12 @@ int tilcdc_encoder_create(struct drm_device *ddev) struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(ddev); struct tilcdc_encoder *encoder; struct drm_bridge *bridge; - struct drm_panel *panel; - int ret; - ret = drm_of_find_panel_or_bridge(ddev->dev->of_node, 0, 0, - &panel, &bridge); - if (ret == -ENODEV) + bridge = devm_drm_of_get_bridge(ddev->dev, ddev->dev->of_node, 0, 0); + if (PTR_ERR(bridge) == -ENODEV) return 0; - else if (ret) - return ret; + else if (IS_ERR(bridge)) + return PTR_ERR(bridge); encoder = drmm_simple_encoder_alloc(ddev, struct tilcdc_encoder, base, DRM_MODE_ENCODER_NONE); @@ -73,12 +70,5 @@ int tilcdc_encoder_create(struct drm_device *ddev) } priv->encoder = encoder; - if (panel) { - bridge = devm_drm_panel_bridge_add_typed(ddev->dev, panel, - DRM_MODE_CONNECTOR_DPI); - if (IS_ERR(bridge)) - return PTR_ERR(bridge); - } - return tilcdc_attach_bridge(ddev, bridge); } -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:38 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Replace dev_* logging calls with their DRM equivalents. This aligns with the DRM subsystem's logging infrastructure and provides better integration with DRM debugging mechanisms. The drm_* helpers automatically include device information and integrate with DRM's debug category filtering. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v4: - New patch. --- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 26 +++++++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 16 ++++++++-------- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 4 ++-- drivers/gpu/drm/tilcdc/tilcdc_plane.c | 8 ++++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index 2916de3dce91e..4d3b7059cd5b2 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c @@ -125,7 +125,7 @@ static void tilcdc_crtc_load_palette(struct drm_crtc *crtc) ret = wait_for_completion_timeout(&tilcdc_crtc->palette_loaded, msecs_to_jiffies(50)); if (ret == 0) - dev_err(dev->dev, "%s: Palette loading timeout", __func__); + drm_err(dev, "%s: Palette loading timeout", __func__); /* Disable LCDC DMA and DMA Palette Loaded Interrupt. */ tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE); @@ -223,7 +223,7 @@ static void tilcdc_crtc_set_clk(struct drm_crtc *crtc) */ if (!clk_rate) { /* Nothing more we can do. Just bail out. */ - dev_err(dev->dev, + drm_err(dev, "failed to set the pixel clock - unable to read current lcdc clock rate\n"); return; } @@ -240,7 +240,7 @@ static void tilcdc_crtc_set_clk(struct drm_crtc *crtc) real_pclk_rate = clk_rate / clkdiv; if (tilcdc_pclk_diff(pclk_rate, real_pclk_rate) > 5) { - dev_warn(dev->dev, + drm_warn(dev, "effective pixel clock rate (%luHz) differs from the requested rate (%luHz)\n", real_pclk_rate, pclk_rate); } @@ -369,7 +369,7 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) reg |= LCDC_V2_TFT_24BPP_MODE; break; default: - dev_err(dev->dev, "invalid pixel format\n"); + drm_err(dev, "invalid pixel format\n"); return; } } @@ -482,7 +482,7 @@ static void tilcdc_crtc_off(struct drm_crtc *crtc, bool shutdown) tilcdc_crtc->frame_done, msecs_to_jiffies(500)); if (ret == 0) - dev_err(dev->dev, "%s: timeout waiting for framedone\n", + drm_err(dev, "%s: timeout waiting for framedone\n", __func__); drm_crtc_vblank_off(crtc); @@ -543,7 +543,7 @@ static void tilcdc_crtc_recover_work(struct work_struct *work) container_of(work, struct tilcdc_crtc, recover_work); struct drm_crtc *crtc = &tilcdc_crtc->base; - dev_info(crtc->dev->dev, "%s: Reset CRTC", __func__); + drm_info(crtc->dev, "%s: Reset CRTC", __func__); drm_modeset_lock(&crtc->mutex, NULL); @@ -575,7 +575,7 @@ int tilcdc_crtc_update_fb(struct drm_crtc *crtc, struct drm_device *dev = crtc->dev; if (tilcdc_crtc->event) { - dev_err(dev->dev, "already pending page flip!\n"); + drm_err(dev, "already pending page flip!\n"); return -EBUSY; } @@ -707,7 +707,7 @@ static void tilcdc_crtc_reset(struct drm_crtc *crtc) tilcdc_crtc->frame_done, msecs_to_jiffies(500)); if (ret == 0) - dev_err(dev->dev, "%s: timeout waiting for framedone\n", + drm_err(dev, "%s: timeout waiting for framedone\n", __func__); } pm_runtime_put_sync(dev->dev); @@ -895,7 +895,7 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) } if (stat & LCDC_FIFO_UNDERFLOW) - dev_err_ratelimited(dev->dev, "%s(0x%08x): FIFO underflow", + drm_err_ratelimited(dev, "%s(0x%08x): FIFO underflow", __func__, stat); if (stat & LCDC_PL_LOAD_DONE) { @@ -909,7 +909,7 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) } if (stat & LCDC_SYNC_LOST) { - dev_err_ratelimited(dev->dev, "%s(0x%08x): Sync lost", + drm_err_ratelimited(dev, "%s(0x%08x): Sync lost", __func__, stat); tilcdc_crtc->frame_intact = false; if (priv->rev == 1) { @@ -923,7 +923,7 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) } else { if (tilcdc_crtc->sync_lost_count++ > SYNC_LOST_COUNT_LIMIT) { - dev_err(dev->dev, + drm_err(dev, "%s(0x%08x): Sync lost flood detected, recovering", __func__, stat); queue_work(system_wq, @@ -965,7 +965,7 @@ int tilcdc_crtc_create(struct drm_device *dev) primary = tilcdc_plane_init(dev); if (IS_ERR(primary)) { - dev_err(dev->dev, "Failed to initialize plane: %pe\n", primary); + drm_err(dev, "Failed to initialize plane: %pe\n", primary); return PTR_ERR(primary); } @@ -975,7 +975,7 @@ int tilcdc_crtc_create(struct drm_device *dev) &tilcdc_crtc_funcs, "tilcdc crtc"); if (IS_ERR(tilcdc_crtc)) { - dev_err(dev->dev, "Failed to init CRTC: %pe\n", tilcdc_crtc); + drm_err(dev, "Failed to init CRTC: %pe\n", tilcdc_crtc); return PTR_ERR(tilcdc_crtc); } diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 3b11d296a7e91..c877b2be9c2ec 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -288,14 +288,14 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) priv->mmio = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(priv->mmio)) { - dev_err(dev, "failed to request / ioremap\n"); + drm_err(ddev, "failed to request / ioremap\n"); ret = PTR_ERR(priv->mmio); goto free_wq; } priv->clk = clk_get(dev, "fck"); if (IS_ERR(priv->clk)) { - dev_err(dev, "failed to get functional clock\n"); + drm_err(ddev, "failed to get functional clock\n"); ret = -ENODEV; goto free_wq; } @@ -313,7 +313,7 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) priv->rev = 2; break; default: - dev_warn(dev, "Unknown PID Reg value 0x%08x, " + drm_warn(ddev, "Unknown PID Reg value 0x%08x, " "defaulting to LCD revision 1\n", tilcdc_read(ddev, LCDC_PID_REG)); priv->rev = 1; @@ -380,7 +380,7 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) ret = tilcdc_crtc_create(ddev); if (ret < 0) { - dev_err(dev, "failed to create crtc\n"); + drm_err(ddev, "failed to create crtc\n"); goto disable_pm; } modeset_init(ddev); @@ -390,7 +390,7 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) ret = cpufreq_register_notifier(&priv->freq_transition, CPUFREQ_TRANSITION_NOTIFIER); if (ret) { - dev_err(dev, "failed to register cpufreq notifier\n"); + drm_err(ddev, "failed to register cpufreq notifier\n"); priv->freq_transition.notifier_call = NULL; goto disable_pm; } @@ -401,14 +401,14 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) goto unregister_cpufreq_notif; if (!priv->connector) { - dev_err(dev, "no encoders/connectors found\n"); + drm_err(ddev, "no encoders/connectors found\n"); ret = -EPROBE_DEFER; goto unregister_cpufreq_notif; } ret = drm_vblank_init(ddev, 1); if (ret < 0) { - dev_err(dev, "failed to initialize vblank\n"); + drm_err(ddev, "failed to initialize vblank\n"); goto unregister_cpufreq_notif; } @@ -419,7 +419,7 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) ret = tilcdc_irq_install(ddev, priv->irq); if (ret < 0) { - dev_err(dev, "failed to install IRQ handler\n"); + drm_err(ddev, "failed to install IRQ handler\n"); goto unregister_cpufreq_notif; } diff --git a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c index 1ee5761757a8c..a34a10337f6a8 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c @@ -25,7 +25,7 @@ struct drm_connector *tilcdc_encoder_find_connector(struct drm_device *ddev, return connector; } - dev_err(ddev->dev, "No connector found for %s encoder (id %d)\n", + drm_err(ddev, "No connector found for %s encoder (id %d)\n", encoder->name, encoder->base.id); return NULL; @@ -68,7 +68,7 @@ int tilcdc_encoder_create(struct drm_device *ddev) encoder = drmm_simple_encoder_alloc(ddev, struct tilcdc_encoder, base, DRM_MODE_ENCODER_NONE); if (IS_ERR(encoder)) { - dev_err(ddev->dev, "drm_encoder_init() failed %pe\n", encoder); + drm_err(ddev, "drm_encoder_init() failed %pe\n", encoder); return PTR_ERR(encoder); } priv->encoder = encoder; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_plane.c b/drivers/gpu/drm/tilcdc/tilcdc_plane.c index d98a1ae0e31f8..a9982a9956903 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_plane.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_plane.c @@ -36,7 +36,7 @@ static int tilcdc_plane_atomic_check(struct drm_plane *plane, return -EINVAL; if (new_state->crtc_x || new_state->crtc_y) { - dev_err(plane->dev->dev, "%s: crtc position must be zero.", + drm_err(plane->dev, "%s: crtc position must be zero.", __func__); return -EINVAL; } @@ -48,7 +48,7 @@ static int tilcdc_plane_atomic_check(struct drm_plane *plane, if (crtc_state->mode.hdisplay != new_state->crtc_w || crtc_state->mode.vdisplay != new_state->crtc_h) { - dev_err(plane->dev->dev, + drm_err(plane->dev, "%s: Size must match mode (%dx%d == %dx%d)", __func__, crtc_state->mode.hdisplay, crtc_state->mode.vdisplay, new_state->crtc_w, new_state->crtc_h); @@ -58,13 +58,13 @@ static int tilcdc_plane_atomic_check(struct drm_plane *plane, pitch = crtc_state->mode.hdisplay * new_state->fb->format->cpp[0]; if (new_state->fb->pitches[0] != pitch) { - dev_err(plane->dev->dev, + drm_err(plane->dev, "Invalid pitch: fb and crtc widths must be the same"); return -EINVAL; } if (old_state->fb && new_state->fb->format != old_state->fb->format) { - dev_dbg(plane->dev->dev, + drm_dbg(plane->dev, "%s(): pixel format change requires mode_change\n", __func__); crtc_state->mode_changed = true; -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:37 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
The tilcdc driver no longer uses the component framework to bind the tda998x bridge driver. The component bind/unbind operations and the encoder initialization code are now dead code and can be safely removed. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/bridge/tda998x_drv.c | 69 +----------------------------------- 1 file changed, 1 insertion(+), 68 deletions(-) diff --git a/drivers/gpu/drm/bridge/tda998x_drv.c b/drivers/gpu/drm/bridge/tda998x_drv.c index e636459d91857..865285ba2bd8c 100644 --- a/drivers/gpu/drm/bridge/tda998x_drv.c +++ b/drivers/gpu/drm/bridge/tda998x_drv.c @@ -4,7 +4,6 @@ * Author: Rob Clark <robdclark@gmail.com> */ -#include <linux/component.h> #include <linux/gpio/consumer.h> #include <linux/hdmi.h> #include <linux/i2c.h> @@ -1963,85 +1962,19 @@ static int tda998x_create(struct device *dev) return ret; } -/* DRM encoder functions */ - -static int tda998x_encoder_init(struct device *dev, struct drm_device *drm) -{ - struct tda998x_priv *priv = dev_get_drvdata(dev); - u32 crtcs = 0; - int ret; - - if (dev->of_node) - crtcs = drm_of_find_possible_crtcs(drm, dev->of_node); - - /* If no CRTCs were found, fall back to our old behaviour */ - if (crtcs == 0) { - dev_warn(dev, "Falling back to first CRTC\n"); - crtcs = 1 << 0; - } - - priv->encoder.possible_crtcs = crtcs; - - ret = drm_simple_encoder_init(drm, &priv->encoder, - DRM_MODE_ENCODER_TMDS); - if (ret) - goto err_encoder; - - ret = drm_bridge_attach(&priv->encoder, &priv->bridge, NULL, 0); - if (ret) - goto err_bridge; - - return 0; - -err_bridge: - drm_encoder_cleanup(&priv->encoder); -err_encoder: - return ret; -} - -static int tda998x_bind(struct device *dev, struct device *master, void *data) -{ - struct drm_device *drm = data; - - return tda998x_encoder_init(dev, drm); -} - -static void tda998x_unbind(struct device *dev, struct device *master, - void *data) -{ - struct tda998x_priv *priv = dev_get_drvdata(dev); - - drm_encoder_cleanup(&priv->encoder); -} - -static const struct component_ops tda998x_ops = { - .bind = tda998x_bind, - .unbind = tda998x_unbind, -}; - static int tda998x_probe(struct i2c_client *client) { - int ret; - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_warn(&client->dev, "adapter does not support I2C\n"); return -EIO; } - ret = tda998x_create(&client->dev); - if (ret) - return ret; - - ret = component_add(&client->dev, &tda998x_ops); - if (ret) - tda998x_destroy(&client->dev); - return ret; + return tda998x_create(&client->dev); } static void tda998x_remove(struct i2c_client *client) { - component_del(&client->dev, &tda998x_ops); tda998x_destroy(&client->dev); } -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:39 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Now that tda998x_create and tda998x_destroy are called only in the probe function, there is no need for separate functions. Move the code into the tda998x_probe and tda998x_remove functions. Rewrite the cleanup path using goto calls in probe and reorder it in the remove function. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Change in v3: - Move free_irq() call at the right place in the probe error path. --- drivers/gpu/drm/bridge/tda998x_drv.c | 99 +++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/bridge/tda998x_drv.c b/drivers/gpu/drm/bridge/tda998x_drv.c index 865285ba2bd8c..e06d8d4c4b875 100644 --- a/drivers/gpu/drm/bridge/tda998x_drv.c +++ b/drivers/gpu/drm/bridge/tda998x_drv.c @@ -1748,38 +1748,20 @@ static int tda998x_get_audio_ports(struct tda998x_priv *priv, return 0; } -static void tda998x_destroy(struct device *dev) -{ - struct tda998x_priv *priv = dev_get_drvdata(dev); - - drm_bridge_remove(&priv->bridge); - - /* disable all IRQs and free the IRQ handler */ - cec_write(priv, REG_CEC_RXSHPDINTENA, 0); - reg_clear(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD); - - if (priv->audio_pdev) - platform_device_unregister(priv->audio_pdev); - - if (priv->hdmi->irq) - free_irq(priv->hdmi->irq, priv); - - timer_delete_sync(&priv->edid_delay_timer); - cancel_work_sync(&priv->detect_work); - - i2c_unregister_device(priv->cec); - - cec_notifier_conn_unregister(priv->cec_notify); -} - -static int tda998x_create(struct device *dev) +static int +tda998x_probe(struct i2c_client *client) { - struct i2c_client *client = to_i2c_client(dev); struct device_node *np = client->dev.of_node; + struct device *dev = &client->dev; struct i2c_board_info cec_info; struct tda998x_priv *priv; - u32 video; int rev_lo, rev_hi, ret; + u32 video; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_warn(&client->dev, "adapter does not support I2C\n"); + return -EIO; + } priv = devm_drm_bridge_alloc(dev, struct tda998x_priv, bridge, &tda998x_bridge_funcs); if (IS_ERR(priv)) @@ -1814,13 +1796,15 @@ static int tda998x_create(struct device *dev) rev_lo = reg_read(priv, REG_VERSION_LSB); if (rev_lo < 0) { dev_err(dev, "failed to read version: %d\n", rev_lo); - return rev_lo; + ret = rev_lo; + goto cancel_work; } rev_hi = reg_read(priv, REG_VERSION_MSB); if (rev_hi < 0) { dev_err(dev, "failed to read version: %d\n", rev_hi); - return rev_hi; + ret = rev_hi; + goto cancel_work; } priv->rev = rev_lo | rev_hi << 8; @@ -1843,7 +1827,8 @@ static int tda998x_create(struct device *dev) break; default: dev_err(dev, "found unsupported device: %04x\n", priv->rev); - return -ENXIO; + ret = -ENXIO; + goto cancel_work; } /* after reset, enable DDC: */ @@ -1887,7 +1872,7 @@ static int tda998x_create(struct device *dev) if (ret) { dev_err(dev, "failed to request IRQ#%u: %d\n", client->irq, ret); - goto err_irq; + goto cancel_work; } /* enable HPD irq */ @@ -1897,7 +1882,7 @@ static int tda998x_create(struct device *dev) priv->cec_notify = cec_notifier_conn_register(dev, NULL, NULL); if (!priv->cec_notify) { ret = -ENOMEM; - goto fail; + goto free_irq; } priv->cec_glue.parent = dev; @@ -1924,7 +1909,7 @@ static int tda998x_create(struct device *dev) priv->cec = i2c_new_client_device(client->adapter, &cec_info); if (IS_ERR(priv->cec)) { ret = PTR_ERR(priv->cec); - goto fail; + goto notifier_conn_unregister; } /* enable EDID read irq: */ @@ -1941,7 +1926,7 @@ static int tda998x_create(struct device *dev) ret = tda998x_get_audio_ports(priv, np); if (ret) - goto fail; + goto unregister_dev; if (priv->audio_port_enable[AUDIO_ROUTE_I2S] || priv->audio_port_enable[AUDIO_ROUTE_SPDIF]) @@ -1956,26 +1941,44 @@ static int tda998x_create(struct device *dev) return 0; -fail: - tda998x_destroy(dev); -err_irq: +unregister_dev: + i2c_unregister_device(priv->cec); +notifier_conn_unregister: + cec_notifier_conn_unregister(priv->cec_notify); +free_irq: + if (client->irq) { + cec_write(priv, REG_CEC_RXSHPDINTENA, 0); + reg_clear(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD); + free_irq(client->irq, priv); + } +cancel_work: + timer_delete_sync(&priv->edid_delay_timer); + cancel_work_sync(&priv->detect_work); return ret; } -static int -tda998x_probe(struct i2c_client *client) +static void tda998x_remove(struct i2c_client *client) { - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - dev_warn(&client->dev, "adapter does not support I2C\n"); - return -EIO; - } + struct tda998x_priv *priv = dev_get_drvdata(&client->dev); - return tda998x_create(&client->dev); -} + drm_bridge_remove(&priv->bridge); -static void tda998x_remove(struct i2c_client *client) -{ - tda998x_destroy(&client->dev); + if (priv->audio_pdev) + platform_device_unregister(priv->audio_pdev); + + i2c_unregister_device(priv->cec); + + cec_notifier_conn_unregister(priv->cec_notify); + + /* disable all IRQs and free the IRQ handler */ + if (client->irq) { + cec_write(priv, REG_CEC_RXSHPDINTENA, 0); + reg_clear(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD); + free_irq(priv->hdmi->irq, priv); + } + + timer_delete_sync(&priv->edid_delay_timer); + cancel_work_sync(&priv->detect_work); } #ifdef CONFIG_OF -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:40 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Use directly drm_connector_cleanup in the destroy ops instead of having a custom function that does nothing more. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/bridge/tda998x_drv.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/gpu/drm/bridge/tda998x_drv.c b/drivers/gpu/drm/bridge/tda998x_drv.c index e06d8d4c4b875..fad3c9bfda383 100644 --- a/drivers/gpu/drm/bridge/tda998x_drv.c +++ b/drivers/gpu/drm/bridge/tda998x_drv.c @@ -1203,16 +1203,11 @@ tda998x_connector_detect(struct drm_connector *connector, bool force) connector_status_disconnected; } -static void tda998x_connector_destroy(struct drm_connector *connector) -{ - drm_connector_cleanup(connector); -} - static const struct drm_connector_funcs tda998x_connector_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes, .detect = tda998x_connector_detect, - .destroy = tda998x_connector_destroy, + .destroy = drm_connector_cleanup, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:41 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Add support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag to allow display controller drivers to create their own connectors. This modernizes the driver to work with the current DRM bridge framework. The implementation includes: - Refactoring detection and EDID reading into bridge-usable helpers - Adding bridge operations: edid_read, detect, hpd_enable, hpd_disable - Setting appropriate bridge ops (DRM_BRIDGE_OP_EDID, DRM_BRIDGE_OP_DETECT, DRM_BRIDGE_OP_HPD) and connector type (HDMIA) - Skipping connector creation when DRM_BRIDGE_ATTACH_NO_CONNECTOR is set - Handling conditional connector cleanup in bridge_detach The driver maintains backward compatibility by continuing to create its own connector when the flag is not set. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- drivers/gpu/drm/bridge/tda998x_drv.c | 96 +++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/bridge/tda998x_drv.c b/drivers/gpu/drm/bridge/tda998x_drv.c index fad3c9bfda383..d9b388165de15 100644 --- a/drivers/gpu/drm/bridge/tda998x_drv.c +++ b/drivers/gpu/drm/bridge/tda998x_drv.c @@ -1193,16 +1193,22 @@ static int tda998x_audio_codec_init(struct tda998x_priv *priv, /* DRM connector functions */ -static enum drm_connector_status -tda998x_connector_detect(struct drm_connector *connector, bool force) +static enum drm_connector_status tda998x_conn_detect(struct tda998x_priv *priv) { - struct tda998x_priv *priv = conn_to_tda998x_priv(connector); u8 val = cec_read(priv, REG_CEC_RXSHPDLEV); return (val & CEC_RXSHPDLEV_HPD) ? connector_status_connected : connector_status_disconnected; } +static enum drm_connector_status +tda998x_connector_detect(struct drm_connector *connector, bool force) +{ + struct tda998x_priv *priv = conn_to_tda998x_priv(connector); + + return tda998x_conn_detect(priv); +} + static const struct drm_connector_funcs tda998x_connector_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes, @@ -1276,11 +1282,10 @@ static int read_edid_block(void *data, u8 *buf, unsigned int blk, size_t length) return ret; } -static int tda998x_connector_get_modes(struct drm_connector *connector) +static const struct drm_edid *tda998x_edid_read(struct tda998x_priv *priv, + struct drm_connector *connector) { - struct tda998x_priv *priv = conn_to_tda998x_priv(connector); const struct drm_edid *drm_edid; - int n; /* * If we get killed while waiting for the HPD timeout, return @@ -1298,6 +1303,16 @@ static int tda998x_connector_get_modes(struct drm_connector *connector) if (priv->rev == TDA19988) reg_set(priv, REG_TX4, TX4_PD_RAM); + return drm_edid; +} + +static int tda998x_connector_get_modes(struct drm_connector *connector) +{ + struct tda998x_priv *priv = conn_to_tda998x_priv(connector); + const struct drm_edid *drm_edid; + int n; + + drm_edid = tda998x_edid_read(priv, connector); drm_edid_connector_update(connector, drm_edid); cec_notifier_set_phys_addr(priv->cec_notify, connector->display_info.source_physical_address); @@ -1365,10 +1380,8 @@ static int tda998x_bridge_attach(struct drm_bridge *bridge, { struct tda998x_priv *priv = bridge_to_tda998x_priv(bridge); - if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) { - DRM_ERROR("Fix bridge driver to make connector optional!"); - return -EINVAL; - } + if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) + return 0; return tda998x_connector_init(priv, bridge->dev); } @@ -1377,7 +1390,8 @@ static void tda998x_bridge_detach(struct drm_bridge *bridge) { struct tda998x_priv *priv = bridge_to_tda998x_priv(bridge); - drm_connector_cleanup(&priv->connector); + if (priv->connector.dev) + drm_connector_cleanup(&priv->connector); } static enum drm_mode_status tda998x_bridge_mode_valid(struct drm_bridge *bridge, @@ -1677,6 +1691,59 @@ static void tda998x_bridge_mode_set(struct drm_bridge *bridge, mutex_unlock(&priv->audio_mutex); } +static const struct drm_edid * +tda998x_bridge_edid_read(struct drm_bridge *bridge, + struct drm_connector *connector) +{ + struct tda998x_priv *priv = bridge_to_tda998x_priv(bridge); + const struct drm_edid *drm_edid; + const struct edid *edid; + + drm_edid = tda998x_edid_read(priv, connector); + if (!drm_edid) { + dev_dbg(&priv->hdmi->dev, "failed to get edid\n"); + return NULL; + } + + /* + * FIXME: This should use connector->display_info.has_audio from + * a path that has read the EDID and called + * drm_edid_connector_update(). + */ + edid = drm_edid_raw(drm_edid); + + dev_dbg(&priv->hdmi->dev, "got edid: width[%d] x height[%d]\n", + edid->width_cm, edid->height_cm); + + priv->sink_has_audio = drm_detect_monitor_audio(edid); + cec_notifier_set_phys_addr_from_edid(priv->cec_notify, edid); + + return drm_edid; +} + +static enum drm_connector_status +tda998x_bridge_detect(struct drm_bridge *bridge, + struct drm_connector *connector) +{ + struct tda998x_priv *priv = bridge_to_tda998x_priv(bridge); + + return tda998x_conn_detect(priv); +} + +static void tda998x_bridge_hpd_enable(struct drm_bridge *bridge) +{ + struct tda998x_priv *priv = bridge_to_tda998x_priv(bridge); + + cec_write(priv, REG_CEC_RXSHPDINTENA, CEC_RXSHPDLEV_HPD); +} + +static void tda998x_bridge_hpd_disable(struct drm_bridge *bridge) +{ + struct tda998x_priv *priv = bridge_to_tda998x_priv(bridge); + + cec_write(priv, REG_CEC_RXSHPDINTENA, 0); +} + static const struct drm_bridge_funcs tda998x_bridge_funcs = { .attach = tda998x_bridge_attach, .detach = tda998x_bridge_detach, @@ -1684,6 +1751,10 @@ static const struct drm_bridge_funcs tda998x_bridge_funcs = { .disable = tda998x_bridge_disable, .mode_set = tda998x_bridge_mode_set, .enable = tda998x_bridge_enable, + .edid_read = tda998x_bridge_edid_read, + .detect = tda998x_bridge_detect, + .hpd_enable = tda998x_bridge_hpd_enable, + .hpd_disable = tda998x_bridge_hpd_disable, }; /* I2C driver functions */ @@ -1872,6 +1943,7 @@ tda998x_probe(struct i2c_client *client) /* enable HPD irq */ cec_write(priv, REG_CEC_RXSHPDINTENA, CEC_RXSHPDLEV_HPD); + priv->bridge.ops = DRM_BRIDGE_OP_HPD; } priv->cec_notify = cec_notifier_conn_register(dev, NULL, NULL); @@ -1932,6 +2004,8 @@ tda998x_probe(struct i2c_client *client) priv->bridge.of_node = dev->of_node; #endif + priv->bridge.ops |= DRM_BRIDGE_OP_EDID | DRM_BRIDGE_OP_DETECT; + priv->bridge.type = DRM_MODE_CONNECTOR_HDMIA; drm_bridge_add(&priv->bridge); return 0; -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:42 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Convert the driver to use the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag when attaching bridges. This modernizes the driver by delegating connector creation to the bridge subsystem through drm_bridge_connector_init() instead of manually searching for connectors created by the bridge. The custom tilcdc_encoder_find_connector() function is removed and replaced with the standard drm_bridge_connector infrastructure, which simplifies the code and aligns with current DRM bridge best practices. This change is safe as there are now no in-tree devicetrees that connect tilcdc to bridges which do not support the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Changes in v5: - Move DRM_DISPLAY_HELPER before DRM_BRIDGE_CONNECTOR for a more logical description. Changes in v4: - Select missing DRM_BRIDGE_CONNECTOR and DRM_DISPLAY_HELPER config dependency in Kconfig --- drivers/gpu/drm/tilcdc/Kconfig | 2 ++ drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 37 ++++++++++++++------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/Kconfig b/drivers/gpu/drm/tilcdc/Kconfig index a36e809f984cd..89df7528756c8 100644 --- a/drivers/gpu/drm/tilcdc/Kconfig +++ b/drivers/gpu/drm/tilcdc/Kconfig @@ -6,6 +6,8 @@ config DRM_TILCDC select DRM_KMS_HELPER select DRM_GEM_DMA_HELPER select DRM_BRIDGE + select DRM_DISPLAY_HELPER + select DRM_BRIDGE_CONNECTOR select DRM_PANEL_BRIDGE select VIDEOMODE_HELPERS select BACKLIGHT_CLASS_DEVICE diff --git a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c index 546fe7e6ee815..680a2ac6ab594 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c @@ -8,45 +8,40 @@ #include <drm/drm_atomic_helper.h> #include <drm/drm_bridge.h> +#include <drm/drm_bridge_connector.h> #include <drm/drm_of.h> #include <drm/drm_simple_kms_helper.h> #include "tilcdc_drv.h" #include "tilcdc_encoder.h" -static -struct drm_connector *tilcdc_encoder_find_connector(struct drm_device *ddev, - struct drm_encoder *encoder) -{ - struct drm_connector *connector; - - list_for_each_entry(connector, &ddev->mode_config.connector_list, head) { - if (drm_connector_has_possible_encoder(connector, encoder)) - return connector; - } - - drm_err(ddev, "No connector found for %s encoder (id %d)\n", - encoder->name, encoder->base.id); - - return NULL; -} - static int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) { struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(ddev); + struct drm_connector *connector; int ret; priv->encoder->base.possible_crtcs = BIT(0); - ret = drm_bridge_attach(&priv->encoder->base, bridge, NULL, 0); + ret = drm_bridge_attach(&priv->encoder->base, bridge, NULL, + DRM_BRIDGE_ATTACH_NO_CONNECTOR); if (ret) return ret; - priv->connector = tilcdc_encoder_find_connector(ddev, &priv->encoder->base); - if (!priv->connector) - return -ENODEV; + connector = drm_bridge_connector_init(ddev, &priv->encoder->base); + if (IS_ERR(connector)) { + drm_err(ddev, "bridge_connector create failed\n"); + return PTR_ERR(connector); + } + + ret = drm_connector_attach_encoder(connector, &priv->encoder->base); + if (ret) { + drm_err(ddev, "attaching encoder to connector failed\n"); + return ret; + } + priv->connector = connector; return 0; } -- 2.43.0
{ "author": "\"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>", "date": "Fri, 23 Jan 2026 17:12:43 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Hi Kory, On Fri Jan 23, 2026 at 5:12 PM CET, Kory Maincent (TI.com) wrote: I'm OK with this patch, based on the v4 discussion. I have a question however, see below. You are introducing a subtle difference here: while you pass the connector type to devm_drm_panel_bridge_add_typed(), devm_drm_of_get_bridge() does not take it and expects it to ahve been set previously and errors out if it hasn't. Can you ensure the connector type is alway set before this devm_drm_of_get_bridge() call? All the changes to the driver in the previous patches of this series make it hard to find that out from here. Luca -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
{ "author": "\"Luca Ceresoli\" <luca.ceresoli@bootlin.com>", "date": "Fri, 30 Jan 2026 20:31:11 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
On Fri, 30 Jan 2026 20:31:11 +0100 "Luca Ceresoli" <luca.ceresoli@bootlin.com> wrote: ... The connector type should be set by the bridge or the panel driver. https://elixir.bootlin.com/linux/v6.18.6/source/drivers/gpu/drm/bridge/panel.c#L397 * This function is deprecated and should not be used in new drivers. Use * devm_drm_panel_bridge_add() instead, and fix panel drivers as necessary if * they don't report a connector type. Regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
{ "author": "Kory Maincent <kory.maincent@bootlin.com>", "date": "Mon, 2 Feb 2026 10:57:17 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH v5 00/25] Clean and update tilcdc driver to support DRM_BRIDGE_ATTACH_NO_CONNECTOR
The starting point for this work was adding support for the HDMI cape: https://www.seeedstudio.com/Seeed-Studio-BeagleBone-Green-HDMI-Cape.html This will be sent in a later series. Initially, Miguel proposed modifying the ite-it66121 bridge to support the legacy behavior without the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag: https://lore.kernel.org/lkml/20250909-it66121-fix-v1-1-bc79ca83df17@bootlin.com/ This patch was NAK'd as we don't want to add more legacy code. Maxime requested that the tilcdc driver be updated to use DRM_BRIDGE_ATTACH_NO_CONNECTOR instead. While working on this update, I discovered that the tilcdc driver contained significant amounts of legacy code that needed cleaning. Since this driver was developed alongside the tda998x driver for several AM335x boards, the tda998x driver also required cleanup and support for the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag. A new tilcdc_panel_legacy driver replaces the old tilcdc_panel driver. It modifies the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. This series is based on the tilcdc fix sent to mainline: https://lore.kernel.org/lkml/20251125090546.137193-1-kory.maincent@bootlin.com/ This series has been tested on: - BeagleBone Black (tilcdc + tda998x bridge) - BeagleBone Black with LCD cape (tilcdc + ti,tilcdc,panel binding) - BeagleBone Green Eco with HDMI cape (tilcdc + it66121 bridge) The following mainline devicetrees still use ti,tilcdc,panel binding. I believe this series maintains compatibility, but I cannot test without hardware: - da850-evm.dts - am335x-guardian.dts - am335x-pdu001.dts - am335x-pepper.dts - am335x-sbc-t335.dts - am335x-sl50.dts Patches 1-2: Convert tilcdc binding to YAML and set the ti,tilcdc,panel sub-binding as legacy. Patches 3-6: Replace tilcdc_panel driver to the new tilcdc_panel_legacy driver which is tweaking the devicetree at boot time. Patches 7-20: Clean up tilcdc driver. Patches 21-23: Clean up tda998x driver. Patch 24: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tda998x driver. Patch 25: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support for tilcdc driver. Changes in v5: - Fix a missing cleanup path. - Link to v4: https://lore.kernel.org/r/20260116-feature_tilcdc-v4-0-2c1c22143087@bootlin.com Changes in v4: - Use device_get_match_data instead of of_match_node. - Convert the driver to use DRM managed resources to avoid lifetime resources issue. - Add a patch to convert to drm_device-based logging helpers. - Replace drm_of_find_panel_or_bridge() with the newer devm_drm_of_get_bridge() helper. - Link to v3: https://lore.kernel.org/r/20260106-feature_tilcdc-v3-0-9bad0f742164@bootlin.com Changes in v3: - Split patch 13 and patch 14 into two for better readability and git history clarity. - Update patch 5 to use OF changeset and __free() macro. Made also few small improvements as requested by Luca. - Rename binding file to ti,am33xx-tilcdc.yaml, use generic node name and drop unused label. - Link to v2: https://lore.kernel.org/r/20251211-feature_tilcdc-v2-0-f48bac3cd33e@bootlin.com Changes in v2: - Remove patch 2 that add fifo-threshold property. Use FIFO threshold value from SoC id instead. - Remove the part that breaks DTB compatibility. - Add tilcdc_panel_legacy to modify the devicetree at boot time to properly bind the tilcdc driver with the standard panel-simple driver. - Link to v1: https://lore.kernel.org/r/20251126-feature_tilcdc-v1-0-49b9ef2e3aa0@bootlin.com Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> --- Kory Maincent (TI.com) (25): dt-bindings: display: tilcdc: Convert to DT schema dt-bindings: display: tilcdc: Mark panel binding as deprecated drm/tilcdc: Remove simulate_vesa_sync flag drm/tilcdc: Add support for DRM bus flags and simplify panel config drm/tilcdc: Convert legacy panel binding via DT overlay at boot time drm/tilcdc: Remove tilcdc panel driver drm/tilcdc: Remove component framework support drm/tilcdc: Remove tilcdc_panel_info structure drm/tilcdc: Remove redundant #endif/#ifdef in debugfs code drm/tilcdc: Remove unused encoder and connector tracking arrays drm/tilcdc: Rename external_encoder and external_connector to encoder and connector drm/tilcdc: Rename tilcdc_external to tilcdc_encoder drm/tilcdc: Remove the useless module list support drm/tilcdc: Use drm_module_platform_driver() helper drm/tilcdc: Move tilcdc_init/fini closer to probe/remove drm/tilcdc: Modernize driver initialization and cleanup paths drm/tilcdc: Remove the use of drm_device private_data drm/tilcdc: Convert to DRM managed resources drm/tilcdc: Convert to drm_device-based logging helpers drm/tilcdc: Use devm_drm_of_get_bridge() helper drm/bridge: tda998x: Remove component support drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove drm/bridge: tda998x: Remove useless tda998x_connector_destroy wrapper drm/bridge: tda998x: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR drm/tilcdc: Add support for DRM_BRIDGE_ATTACH_NO_CONNECTOR .../devicetree/bindings/display/tilcdc/panel.txt | 1 + .../bindings/display/tilcdc/ti,am33xx-tilcdc.yaml | 100 +++++ .../devicetree/bindings/display/tilcdc/tilcdc.txt | 82 ---- drivers/gpu/drm/bridge/tda998x_drv.c | 251 +++++------ drivers/gpu/drm/tilcdc/Kconfig | 18 + drivers/gpu/drm/tilcdc/Makefile | 5 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 192 +++----- drivers/gpu/drm/tilcdc/tilcdc_drv.c | 486 ++++++++------------- drivers/gpu/drm/tilcdc/tilcdc_drv.h | 99 +---- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 69 +++ .../tilcdc/{tilcdc_external.h => tilcdc_encoder.h} | 5 +- drivers/gpu/drm/tilcdc/tilcdc_external.c | 179 -------- drivers/gpu/drm/tilcdc/tilcdc_panel.c | 408 ----------------- drivers/gpu/drm/tilcdc/tilcdc_panel.h | 15 - drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 185 ++++++++ drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.dtso | 29 ++ drivers/gpu/drm/tilcdc/tilcdc_plane.c | 37 +- drivers/gpu/drm/tilcdc/tilcdc_regs.h | 8 +- 18 files changed, 812 insertions(+), 1357 deletions(-) --- base-commit: a3158f3710111bbd4bfba3bc0883449efde10a0b change-id: 20251014-feature_tilcdc-79cd49e67bf9 Best regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
On Mon Feb 2, 2026 at 10:57 AM CET, Kory Maincent wrote: Ah, right, so it means this patch might cause some regressions due to panel drivers to be fixed. So it's fine as long as you are ready to handle such regression, should any happen. Also other patches did exactly the same, e.g.: commit 6e1853589ea6 ("drm/lcdif: switch to devm_drm_of_get_bridge") commit a43dd76bacd0 ("drm/vc4: dsi: Switch to devm_drm_of_get_bridge") And so: Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
{ "author": "\"Luca Ceresoli\" <luca.ceresoli@bootlin.com>", "date": "Mon, 02 Feb 2026 18:07:45 +0100", "thread_id": "DG4N39EA7RN5.NARFDHX3IXGE@bootlin.com.mbox.gz" }
lkml
[PATCH 1/1] mshv: Add comment about huge page mappings in guest physical address space
From: Michael Kelley <mhklinux@outlook.com> Huge page mappings in the guest physical address space depend on having matching alignment of the userspace address in the parent partition and of the guest physical address. Add a comment that captures this information. See the link to the mailing list thread. No code or functional change. Link: https://lore.kernel.org/linux-hyperv/aUrC94YvscoqBzh3@skinsburskii.localdomain/T/#m0871d2cae9b297fd397ddb8459e534981307c7dc Signed-off-by: Michael Kelley <mhklinux@outlook.com> --- drivers/hv/mshv_root_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 681b58154d5e..bc738ff4508e 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -1389,6 +1389,20 @@ mshv_partition_ioctl_set_memory(struct mshv_partition *partition, if (mem.flags & BIT(MSHV_SET_MEM_BIT_UNMAP)) return mshv_unmap_user_memory(partition, mem); + /* + * If the userspace_addr and the guest physical address (as derived + * from the guest_pfn) have the same alignment modulo PMD huge page + * size, the MSHV driver can map any PMD huge pages to the guest + * physical address space as PMD huge pages. If the alignments do + * not match, PMD huge pages must be mapped as single pages in the + * guest physical address space. The MSHV driver does not enforce + * that the alignments match, and it invokes the hypervisor to set + * up correct functional mappings either way. See mshv_chunk_stride(). + * The caller of the ioctl is responsible for providing userspace_addr + * and guest_pfn values with matching alignments if it wants the guest + * to get the performance benefits of PMD huge page mappings of its + * physical address space to real system memory. + */ return mshv_map_user_memory(partition, mem); } -- 2.25.1
On Mon, Feb 02, 2026 at 08:51:01AM -0800, mhkelley58@gmail.com wrote: Thanks. However, I'd suggest to reduce this commet a lot and put the details into the commit message instead. Also, why this place? Why not a part of the function description instead, for example? Thanks, Stanislav
{ "author": "Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>", "date": "Mon, 2 Feb 2026 09:17:33 -0800", "thread_id": "aYDcLRhxx9wXRXBG@skinsburskii.localdomain.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
From: Lance Yang <lance.yang@linux.dev> Now that we have tlb_remove_table_sync_mm(), convert callers from tlb_remove_table_sync_one() to enable targeted IPIs instead of broadcast. Three callers updated: 1) collapse_huge_page() - after flushing the old PMD, only IPIs CPUs walking this mm instead of all CPUs. 2) tlb_flush_unshared_tables() - when unsharing hugetlb page tables, use tlb->mm for targeted IPIs. 3) __tlb_remove_table_one() - updated to take mmu_gather parameter so it can use tlb->mm when batch allocation fails. Note that pmdp_get_lockless_sync() (PAE only) also calls tlb_remove_table_sync_one() under PTL to ensure all ongoing PMD split-reads complete between pmdp_get_lockless_{start,end}; the critical section is very short. I'm inclined not to convert it since PAE systems typically don't have many cores. Suggested-by: David Hildenbrand (Red Hat) <david@kernel.org> Signed-off-by: Lance Yang <lance.yang@linux.dev> --- include/asm-generic/tlb.h | 11 ++++++----- mm/khugepaged.c | 2 +- mm/mmu_gather.c | 12 ++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index b6b06e6b879f..40eb74b28f9d 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -831,17 +831,18 @@ static inline void tlb_flush_unshared_tables(struct mmu_gather *tlb) /* * Similarly, we must make sure that concurrent GUP-fast will not * walk previously-shared page tables that are getting modified+reused - * elsewhere. So broadcast an IPI to wait for any concurrent GUP-fast. + * elsewhere. So send an IPI to wait for any concurrent GUP-fast. * - * We only perform this when we are the last sharer of a page table, - * as the IPI will reach all CPUs: any GUP-fast. + * We only perform this when we are the last sharer of a page table. + * Use targeted IPI to CPUs actively walking this mm instead of + * broadcast. * - * Note that on configs where tlb_remove_table_sync_one() is a NOP, + * Note that on configs where tlb_remove_table_sync_mm() is a NOP, * the expectation is that the tlb_flush_mmu_tlbonly() would have issued * required IPIs already for us. */ if (tlb->fully_unshared_tables) { - tlb_remove_table_sync_one(); + tlb_remove_table_sync_mm(tlb->mm); tlb->fully_unshared_tables = false; } } diff --git a/mm/khugepaged.c b/mm/khugepaged.c index fa1e57fd2c46..7781d6628649 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1173,7 +1173,7 @@ static enum scan_result collapse_huge_page(struct mm_struct *mm, unsigned long a _pmd = pmdp_collapse_flush(vma, address, pmd); spin_unlock(pmd_ptl); mmu_notifier_invalidate_range_end(&range); - tlb_remove_table_sync_one(); + tlb_remove_table_sync_mm(mm); pte = pte_offset_map_lock(mm, &_pmd, address, &pte_ptl); if (pte) { diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index 35c89e4b6230..76573ec454e5 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -378,7 +378,7 @@ static inline void __tlb_remove_table_one_rcu(struct rcu_head *head) __tlb_remove_table(ptdesc); } -static inline void __tlb_remove_table_one(void *table) +static inline void __tlb_remove_table_one(struct mmu_gather *tlb, void *table) { struct ptdesc *ptdesc; @@ -386,16 +386,16 @@ static inline void __tlb_remove_table_one(void *table) call_rcu(&ptdesc->pt_rcu_head, __tlb_remove_table_one_rcu); } #else -static inline void __tlb_remove_table_one(void *table) +static inline void __tlb_remove_table_one(struct mmu_gather *tlb, void *table) { - tlb_remove_table_sync_one(); + tlb_remove_table_sync_mm(tlb->mm); __tlb_remove_table(table); } #endif /* CONFIG_PT_RECLAIM */ -static void tlb_remove_table_one(void *table) +static void tlb_remove_table_one(struct mmu_gather *tlb, void *table) { - __tlb_remove_table_one(table); + __tlb_remove_table_one(tlb, table); } static void tlb_table_flush(struct mmu_gather *tlb) @@ -417,7 +417,7 @@ void tlb_remove_table(struct mmu_gather *tlb, void *table) *batch = (struct mmu_table_batch *)__get_free_page(GFP_NOWAIT); if (*batch == NULL) { tlb_table_invalidate(tlb); - tlb_remove_table_one(table); + tlb_remove_table_one(tlb, table); return; } (*batch)->nr = 0; -- 2.49.0
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 15:45:56 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
From: Lance Yang <lance.yang@linux.dev> Currently, tlb_remove_table_sync_one() broadcasts IPIs to all CPUs to wait for any concurrent lockless page table walkers (e.g., GUP-fast). This is inefficient on systems with many CPUs, especially for RT workloads[1]. This patch introduces a per-CPU tracking mechanism to record which CPUs are actively performing lockless page table walks for a specific mm_struct. When freeing/unsharing page tables, we can now send IPIs only to the CPUs that are actually walking that mm, instead of broadcasting to all CPUs. In preparation for targeted IPIs; a follow-up will switch callers to tlb_remove_table_sync_mm(). Note that the tracking adds ~3% latency to GUP-fast, as measured on a 64-core system. [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ Suggested-by: David Hildenbrand (Red Hat) <david@kernel.org> Signed-off-by: Lance Yang <lance.yang@linux.dev> --- include/asm-generic/tlb.h | 2 ++ include/linux/mm.h | 34 ++++++++++++++++++++++++++ kernel/events/core.c | 2 ++ mm/gup.c | 2 ++ mm/mmu_gather.c | 50 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 4aeac0c3d3f0..b6b06e6b879f 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -250,6 +250,7 @@ static inline void tlb_remove_table(struct mmu_gather *tlb, void *table) #endif void tlb_remove_table_sync_one(void); +void tlb_remove_table_sync_mm(struct mm_struct *mm); #else @@ -258,6 +259,7 @@ void tlb_remove_table_sync_one(void); #endif static inline void tlb_remove_table_sync_one(void) { } +static inline void tlb_remove_table_sync_mm(struct mm_struct *mm) { } #endif /* CONFIG_MMU_GATHER_RCU_TABLE_FREE */ diff --git a/include/linux/mm.h b/include/linux/mm.h index f8a8fd47399c..d92df995fcd1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2995,6 +2995,40 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end, pgoff_t *offset); int folio_add_pins(struct folio *folio, unsigned int pins); +/* + * Track CPUs doing lockless page table walks to avoid broadcast IPIs + * during TLB flushes. + */ +DECLARE_PER_CPU(struct mm_struct *, active_lockless_pt_walk_mm); + +static inline void pt_walk_lockless_start(struct mm_struct *mm) +{ + lockdep_assert_irqs_disabled(); + + /* + * Tell other CPUs we're doing lockless page table walk. + * + * Full barrier needed to prevent page table reads from being + * reordered before this write. + * + * Pairs with smp_rmb() in tlb_remove_table_sync_mm(). + */ + this_cpu_write(active_lockless_pt_walk_mm, mm); + smp_mb(); +} + +static inline void pt_walk_lockless_end(void) +{ + lockdep_assert_irqs_disabled(); + + /* + * Clear the pointer so other CPUs no longer see this CPU as walking + * the mm. Use smp_store_release to ensure page table reads complete + * before the clear is visible to other CPUs. + */ + smp_store_release(this_cpu_ptr(&active_lockless_pt_walk_mm), NULL); +} + int get_user_pages_fast(unsigned long start, int nr_pages, unsigned int gup_flags, struct page **pages); int pin_user_pages_fast(unsigned long start, int nr_pages, diff --git a/kernel/events/core.c b/kernel/events/core.c index 5b5cb620499e..6539112c28ff 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8190,7 +8190,9 @@ static u64 perf_get_page_size(unsigned long addr) mm = &init_mm; } + pt_walk_lockless_start(mm); size = perf_get_pgtable_size(mm, addr); + pt_walk_lockless_end(); local_irq_restore(flags); diff --git a/mm/gup.c b/mm/gup.c index 8e7dc2c6ee73..6748e28b27f2 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3154,7 +3154,9 @@ static unsigned long gup_fast(unsigned long start, unsigned long end, * that come from callers of tlb_remove_table_sync_one(). */ local_irq_save(flags); + pt_walk_lockless_start(current->mm); gup_fast_pgd_range(start, end, gup_flags, pages, &nr_pinned); + pt_walk_lockless_end(); local_irq_restore(flags); /* diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index 2faa23d7f8d4..35c89e4b6230 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -285,6 +285,56 @@ void tlb_remove_table_sync_one(void) smp_call_function(tlb_remove_table_smp_sync, NULL, 1); } +DEFINE_PER_CPU(struct mm_struct *, active_lockless_pt_walk_mm); +EXPORT_PER_CPU_SYMBOL_GPL(active_lockless_pt_walk_mm); + +/** + * tlb_remove_table_sync_mm - send IPIs to CPUs doing lockless page table + * walk for @mm + * + * @mm: target mm; only CPUs walking this mm get an IPI. + * + * Like tlb_remove_table_sync_one() but only targets CPUs in + * active_lockless_pt_walk_mm. + */ +void tlb_remove_table_sync_mm(struct mm_struct *mm) +{ + cpumask_var_t target_cpus; + bool found_any = false; + int cpu; + + if (WARN_ONCE(!mm, "NULL mm in %s\n", __func__)) { + tlb_remove_table_sync_one(); + return; + } + + /* If we can't, fall back to broadcast. */ + if (!alloc_cpumask_var(&target_cpus, GFP_ATOMIC)) { + tlb_remove_table_sync_one(); + return; + } + + cpumask_clear(target_cpus); + + /* Pairs with smp_mb() in pt_walk_lockless_start(). */ + smp_rmb(); + + /* Find CPUs doing lockless page table walks for this mm */ + for_each_online_cpu(cpu) { + if (per_cpu(active_lockless_pt_walk_mm, cpu) == mm) { + cpumask_set_cpu(cpu, target_cpus); + found_any = true; + } + } + + /* Only send IPIs to CPUs actually doing lockless walks */ + if (found_any) + smp_call_function_many(target_cpus, tlb_remove_table_smp_sync, + NULL, 1); + + free_cpumask_var(target_cpus); +} + static void tlb_remove_table_rcu(struct rcu_head *head) { __tlb_remove_table_free(container_of(head, struct mmu_table_batch, rcu)); -- 2.49.0
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 15:45:55 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
From: Lance Yang <lance.yang@linux.dev> When the TLB flush path already sends IPIs (e.g. native without INVLPGB, or KVM), tlb_remove_table_sync_mm() does not need to send another round. Add a property on pv_mmu_ops so each paravirt backend can indicate whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. Native sets it in native_pv_tlb_init() when still using native_flush_tlb_multi() and INVLPGB is disabled. KVM sets it true; Xen and Hyper-V set it false because they use hypercalls. Also pass both freed_tables and unshared_tables from tlb_flush() into flush_tlb_mm_range() so lazy-TLB CPUs get IPIs during hugetlb unshare. Suggested-by: David Hildenbrand (Red Hat) <david@kernel.org> Signed-off-by: Lance Yang <lance.yang@linux.dev> --- arch/x86/hyperv/mmu.c | 5 +++++ arch/x86/include/asm/paravirt.h | 5 +++++ arch/x86/include/asm/paravirt_types.h | 6 ++++++ arch/x86/include/asm/tlb.h | 20 +++++++++++++++++++- arch/x86/kernel/kvm.c | 6 ++++++ arch/x86/kernel/paravirt.c | 18 ++++++++++++++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 ++ include/asm-generic/tlb.h | 15 +++++++++++++++ mm/mmu_gather.c | 7 +++++++ 10 files changed, 84 insertions(+), 1 deletion(-) diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c index cfcb60468b01..fc8fb275f295 100644 --- a/arch/x86/hyperv/mmu.c +++ b/arch/x86/hyperv/mmu.c @@ -243,4 +243,9 @@ void hyperv_setup_mmu_ops(void) pr_info("Using hypercall for remote TLB flush\n"); pv_ops.mmu.flush_tlb_multi = hyperv_flush_tlb_multi; + /* + * Hyper-V uses hypercalls for TLB flush, not real IPIs. + * Keep the property as false. + */ + pv_ops.mmu.flush_tlb_multi_implies_ipi_broadcast = false; } diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index 13f9cd31c8f8..1fdbe3736f41 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -698,6 +698,7 @@ static __always_inline unsigned long arch_local_irq_save(void) extern void default_banner(void); void native_pv_lock_init(void) __init; +void native_pv_tlb_init(void) __init; #else /* __ASSEMBLER__ */ @@ -727,6 +728,10 @@ void native_pv_lock_init(void) __init; static inline void native_pv_lock_init(void) { } + +static inline void native_pv_tlb_init(void) +{ +} #endif #endif /* !CONFIG_PARAVIRT */ diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index 3502939415ad..d8aa519ef5e3 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -133,6 +133,12 @@ struct pv_mmu_ops { void (*flush_tlb_multi)(const struct cpumask *cpus, const struct flush_tlb_info *info); + /* + * Indicates whether flush_tlb_multi IPIs provide sufficient + * synchronization during TLB flush when freeing or unsharing page tables. + */ + bool flush_tlb_multi_implies_ipi_broadcast; + /* Hook for intercepting the destruction of an mm_struct. */ void (*exit_mmap)(struct mm_struct *mm); void (*notify_page_enc_status_changed)(unsigned long pfn, int npages, bool enc); diff --git a/arch/x86/include/asm/tlb.h b/arch/x86/include/asm/tlb.h index 866ea78ba156..1e524d8e260a 100644 --- a/arch/x86/include/asm/tlb.h +++ b/arch/x86/include/asm/tlb.h @@ -5,10 +5,23 @@ #define tlb_flush tlb_flush static inline void tlb_flush(struct mmu_gather *tlb); +#define tlb_table_flush_implies_ipi_broadcast tlb_table_flush_implies_ipi_broadcast +static inline bool tlb_table_flush_implies_ipi_broadcast(void); + #include <asm-generic/tlb.h> #include <linux/kernel.h> #include <vdso/bits.h> #include <vdso/page.h> +#include <asm/paravirt.h> + +static inline bool tlb_table_flush_implies_ipi_broadcast(void) +{ +#ifdef CONFIG_PARAVIRT + return pv_ops.mmu.flush_tlb_multi_implies_ipi_broadcast; +#else + return !cpu_feature_enabled(X86_FEATURE_INVLPGB); +#endif +} static inline void tlb_flush(struct mmu_gather *tlb) { @@ -20,7 +33,12 @@ static inline void tlb_flush(struct mmu_gather *tlb) end = tlb->end; } - flush_tlb_mm_range(tlb->mm, start, end, stride_shift, tlb->freed_tables); + /* + * During TLB flushes, pass both freed_tables and unshared_tables + * so lazy-TLB CPUs receive IPIs. + */ + flush_tlb_mm_range(tlb->mm, start, end, stride_shift, + tlb->freed_tables || tlb->unshared_tables); } static inline void invlpg(unsigned long addr) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 37dc8465e0f5..6a5e47ee4eb6 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -856,6 +856,12 @@ static void __init kvm_guest_init(void) #ifdef CONFIG_SMP if (pv_tlb_flush_supported()) { pv_ops.mmu.flush_tlb_multi = kvm_flush_tlb_multi; + /* + * KVM's flush implementation calls native_flush_tlb_multi(), + * which sends real IPIs when INVLPGB is not available. + */ + if (!cpu_feature_enabled(X86_FEATURE_INVLPGB)) + pv_ops.mmu.flush_tlb_multi_implies_ipi_broadcast = true; pr_info("KVM setup pv remote TLB flush\n"); } diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index ab3e172dcc69..1af253c9f51d 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -60,6 +60,23 @@ void __init native_pv_lock_init(void) static_branch_enable(&virt_spin_lock_key); } +void __init native_pv_tlb_init(void) +{ + /* + * Check if we're still using native TLB flush (not overridden by + * a PV backend) and don't have INVLPGB support. + * + * In this case, native IPI-based TLB flush provides sufficient + * synchronization for GUP-fast. + * + * PV backends (KVM, Xen, HyperV) should set this property in their + * own initialization code if their flush implementation sends IPIs. + */ + if (pv_ops.mmu.flush_tlb_multi == native_flush_tlb_multi && + !cpu_feature_enabled(X86_FEATURE_INVLPGB)) + pv_ops.mmu.flush_tlb_multi_implies_ipi_broadcast = true; +} + struct static_key paravirt_steal_enabled; struct static_key paravirt_steal_rq_enabled; @@ -173,6 +190,7 @@ struct paravirt_patch_template pv_ops = { .mmu.flush_tlb_kernel = native_flush_tlb_global, .mmu.flush_tlb_one_user = native_flush_tlb_one_user, .mmu.flush_tlb_multi = native_flush_tlb_multi, + .mmu.flush_tlb_multi_implies_ipi_broadcast = false, .mmu.exit_mmap = paravirt_nop, .mmu.notify_page_enc_status_changed = paravirt_nop, diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 5cd6950ab672..3cdb04162843 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1167,6 +1167,7 @@ void __init native_smp_prepare_boot_cpu(void) switch_gdt_and_percpu_base(me); native_pv_lock_init(); + native_pv_tlb_init(); } void __init native_smp_cpus_done(unsigned int max_cpus) diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c index 7a35c3393df4..b6d86299cf10 100644 --- a/arch/x86/xen/mmu_pv.c +++ b/arch/x86/xen/mmu_pv.c @@ -2185,6 +2185,8 @@ static const typeof(pv_ops) xen_mmu_ops __initconst = { .flush_tlb_kernel = xen_flush_tlb, .flush_tlb_one_user = xen_flush_tlb_one_user, .flush_tlb_multi = xen_flush_tlb_multi, + /* Xen uses hypercalls for TLB flush, not real IPIs */ + .flush_tlb_multi_implies_ipi_broadcast = false, .pgd_alloc = xen_pgd_alloc, .pgd_free = xen_pgd_free, diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 40eb74b28f9d..fae97c8bcceb 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -240,6 +240,21 @@ static inline void tlb_remove_table(struct mmu_gather *tlb, void *table) } #endif /* CONFIG_MMU_GATHER_TABLE_FREE */ +/* + * Architectures can override this to indicate whether TLB flush operations + * send IPIs that are sufficient to synchronize with lockless page table + * walkers (e.g., GUP-fast). If true, tlb_remove_table_sync_mm() becomes + * a no-op as the TLB flush already provided the necessary IPI. + * + * Default is false, meaning we need explicit IPIs via tlb_remove_table_sync_mm(). + */ +#ifndef tlb_table_flush_implies_ipi_broadcast +static inline bool tlb_table_flush_implies_ipi_broadcast(void) +{ + return false; +} +#endif + #ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE /* * This allows an architecture that does not use the linux page-tables for diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index 76573ec454e5..9620480c11ce 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -303,6 +303,13 @@ void tlb_remove_table_sync_mm(struct mm_struct *mm) bool found_any = false; int cpu; + /* + * If the architecture's TLB flush already sent IPIs that are sufficient + * for synchronization, we don't need to send additional IPIs. + */ + if (tlb_table_flush_implies_ipi_broadcast()) + return; + if (WARN_ONCE(!mm, "NULL mm in %s\n", __func__)) { tlb_remove_table_sync_one(); return; -- 2.49.0
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 15:45:57 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On Mon, Feb 02, 2026 at 03:45:55PM +0800, Lance Yang wrote: What architecture, and that is acceptable? One thing to try is something like: xchg(this_cpu_ptr(&active_lockless_pt_walk_mm), mm); That *might* be a little better on x86_64, on anything else you really don't want to use this_cpu_() ops when you *know* IRQs are already disabled. Why the heck is this exported? Both users are firmly core code. Pairs how? The start thing does something like: [W] active_lockless_pt_walk_mm = mm MB [L] page-tables So this is: [L] page-tables RMB [L] active_lockless_pt_walk_mm ? You really don't need this to be atomic. Coding style wants { } here. Also, isn't this what we have smp_call_function_many_cond() for?
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 10:42:45 +0100", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On Mon, Feb 02, 2026 at 03:45:54PM +0800, Lance Yang wrote: I'm confused. This only happens when !PT_RECLAIM, because if PT_RECLAIM __tlb_remove_table_one() actually uses RCU. So why are you making things more expensive for no reason?
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 10:54:14 +0100", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On Mon, 2 Feb 2026 10:54:14 +0100, Peter Zijlstra wrote: You're right that when CONFIG_PT_RECLAIM is set, __tlb_remove_table_one() uses call_rcu() and we never call any sync there — this series doesn't touch that path. In the !PT_RECLAIM table-free path (same __tlb_remove_table_one() branch that calls tlb_remove_table_sync_mm(tlb->mm) before __tlb_remove_table), we're not adding any new sync; we're replacing the existing broadcast IPI (tlb_remove_table_sync_one()) with targeted IPIs (tlb_remove_table_sync_mm()). One thing I just realized: when CONFIG_MMU_GATHER_RCU_TABLE_FREE is not set, the sync path isn't used at all (tlb_remove_table_sync_one() and friends aren't even compiled), so we don't need the tracker in that config. Thanks for raising this! Lance
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 19:00:16 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
Hi Peter, Thanks for taking time to review! On 2026/2/2 17:42, Peter Zijlstra wrote: x86-64. I ran ./gup_bench which spawns 60 threads, each doing 500k GUP-fast operations (pinning 8 pages per call) via the gup_test ioctl. Results for pin pages: - Before: avg 1.489s (10 runs) - After: avg 1.533s (10 runs) Given we avoid broadcast IPIs on large systems, I think this is a reasonable trade-off :) Ah, good to know that. Thanks! IIUC, xchg() provides the full barrier we need ;) OK. Will drop this export. On the walker side (pt_walk_lockless_start): [W] active_lockless_pt_walk_mm = mm MB [L] page-tables (walker reads page tables) So the walker publishes "I'm walking this mm" before reading page tables. On the sync side we don't read page-tables. We do: RMB [L] active_lockless_pt_walk_mm (we read the per-CPU pointer below) We need to observe the walker's store of active_lockless_pt_walk_mm before we decide which CPUs to IPI. So on the sync side we do smp_rmb(), then read active_lockless_pt_walk_mm. That pairs with the full barrier in pt_walk_lockless_start(). Right! That would be better, something like: static bool tlb_remove_table_sync_mm_cond(int cpu, void *mm) { return per_cpu(active_lockless_pt_walk_mm, cpu) == (struct mm_struct *)mm; } on_each_cpu_cond_mask(tlb_remove_table_sync_mm_cond, tlb_remove_table_smp_sync, (void *)mm, true, cpu_online_mask); Thanks, Lance
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 20:14:32 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On Mon, Feb 02, 2026 at 07:00:16PM +0800, Lance Yang wrote: Right, but if we can use full RCU for PT_RECLAIM, why can't we do so unconditionally and not add overhead?
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 13:50:30 +0100", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On Mon, Feb 02, 2026 at 08:14:32PM +0800, Lance Yang wrote: No it doesn't; this is not how memory barriers work.
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 13:51:46 +0100", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On 2026/2/2 20:50, Peter Zijlstra wrote: The sync (IPI) is mainly needed for unshare (e.g. hugetlb) and collapse (khugepaged) paths, regardless of whether table free uses RCU, IIUC.
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 20:58:59 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On 2026/2/2 20:58, Lance Yang wrote: In addition: We need the sync when we modify page tables (e.g. unshare, collapse), not only when we free them. RCU can defer freeing but does not prevent lockless walkers from seeing concurrent in-place modifications, so we need the IPI to synchronize with those walkers first.
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 21:07:10 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On 2026/2/2 20:51, Peter Zijlstra wrote: Hmm... we need MB rather than RMB on the sync side. Is that correct? Walker: [W]active_lockless_pt_walk_mm = mm -> MB -> [L]page-tables Sync: [W]page-tables -> MB -> [L]active_lockless_pt_walk_mm Thanks, Lance
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 21:23:07 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On Mon, Feb 02, 2026 at 09:07:10PM +0800, Lance Yang wrote: Currently PT_RECLAIM=y has no IPI; are you saying that is broken? If not, then why do we need this at all?
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 14:37:13 +0100", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On Mon, Feb 02, 2026 at 09:23:07PM +0800, Lance Yang wrote: This can work -- but only if the walker and sync touch the same page-table address. Now, typically I would imagine they both share the p4d/pud address at the very least, right?
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 14:42:33 +0100", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On 2026/2/2 21:42, Peter Zijlstra wrote: Thanks. I think I see the confusion ... To be clear, the goal is not to make the walker see page-table writes through the MB pairing, but to wait for any concurrent lockless page table walkers to finish. The flow is: 1) Page tables are modified 2) TLB flush is done 3) Read active_lockless_pt_walk_mm (with MB to order page-table writes before this read) to find which CPUs are locklessly walking this mm 4) IPI those CPUs 5) The IPI forces them to sync, so after the IPI returns, any in-flight lockless page table walk has finished (or will restart and see the new page tables) The synchronization relies on the IPI to ensure walkers stop before continuing. I would assume the TLB flush (step 2) should imply some barrier. Does that clarify?
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 22:28:47 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On 2026/2/2 21:37, Peter Zijlstra wrote: PT_RECLAIM=y does have IPI for unshare/collapse — those paths call tlb_flush_unshared_tables() (for hugetlb unshare) and collapse_huge_page() (in khugepaged collapse), which already send IPIs today (broadcast to all CPUs via tlb_remove_table_sync_one()). What PT_RECLAIM=y doesn't need IPI for is table freeing ( __tlb_remove_table_one() uses call_rcu() instead). But table modification (unshare, collapse) still needs IPI to synchronize with lockless walkers, regardless of PT_RECLAIM. So PT_RECLAIM=y is not broken; it already has IPI where needed. This series just makes those IPIs targeted instead of broadcast. Does that clarify? Thanks, Lance
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 22:37:39 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On Mon, Feb 02, 2026 at 10:37:39PM +0800, Lance Yang wrote: Oh bah, reading is hard. I had missed they had more table_sync_one() calls, rather than remove_table_one(). So you *can* replace table_sync_one() with rcu_sync(), that will provide the same guarantees. Its just a 'little' bit slower on the update side, but does not incur the read side cost. I really think anything here needs to better explain the various requirements. Because now everybody gets to pay the price for hugetlb shared crud, while 'nobody' will actually use that.
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 16:09:57 +0100", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }
lkml
[PATCH v4 0/3] targeted TLB sync IPIs for lockless page table walkers
When freeing or unsharing page tables we send an IPI to synchronize with concurrent lockless page table walkers (e.g. GUP-fast). Today we broadcast that IPI to all CPUs, which is costly on large machines and hurts RT workloads[1]. This series makes those IPIs targeted. We track which CPUs are currently doing a lockless page table walk for a given mm (per-CPU active_lockless_pt_walk_mm). When we need to sync, we only IPI those CPUs. GUP-fast and perf_get_page_size() set/clear the tracker around their walk; tlb_remove_table_sync_mm() uses it and replaces the previous broadcast in the free/unshare paths. On x86, when the TLB flush path already sends IPIs (native without INVLPGB, or KVM), the extra sync IPI is redundant. We add a property on pv_mmu_ops so each backend can declare whether its flush_tlb_multi sends real IPIs; if so, tlb_remove_table_sync_mm() is a no-op. We also have tlb_flush() pass both freed_tables and unshared_tables so lazy-TLB CPUs get IPIs during hugetlb unshare. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! [1] https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ v3 -> v4: - Rework based on David's two-step direction and per-CPU idea: 1) Targeted IPIs: per-CPU variable when entering/leaving lockless page table walk; tlb_remove_table_sync_mm() IPIs only those CPUs. 2) On x86, pv_mmu_ops property set at init to skip the extra sync when flush_tlb_multi() already sends IPIs. https://lore.kernel.org/linux-mm/bbfdf226-4660-4949-b17b-0d209ee4ef8c@kernel.org/ - https://lore.kernel.org/linux-mm/20260106120303.38124-1-lance.yang@linux.dev/ v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (3): mm: use targeted IPIs for TLB sync with lockless page table walkers mm: switch callers to tlb_remove_table_sync_mm() x86/tlb: add architecture-specific TLB IPI optimization support arch/x86/hyperv/mmu.c | 5 ++ arch/x86/include/asm/paravirt.h | 5 ++ arch/x86/include/asm/paravirt_types.h | 6 +++ arch/x86/include/asm/tlb.h | 20 +++++++- arch/x86/kernel/kvm.c | 6 +++ arch/x86/kernel/paravirt.c | 18 +++++++ arch/x86/kernel/smpboot.c | 1 + arch/x86/xen/mmu_pv.c | 2 + include/asm-generic/tlb.h | 28 +++++++++-- include/linux/mm.h | 34 +++++++++++++ kernel/events/core.c | 2 + mm/gup.c | 2 + mm/khugepaged.c | 2 +- mm/mmu_gather.c | 69 ++++++++++++++++++++++++--- 14 files changed, 187 insertions(+), 13 deletions(-) -- 2.49.0
On 2026/2/2 23:09, Peter Zijlstra wrote: Yep, we could replace the IPI with synchronize_rcu() on the sync side: - Currently: TLB flush → send IPI → wait for walkers to finish - With synchronize_rcu(): TLB flush → synchronize_rcu() -> waits for grace period Lockless walkers (e.g. GUP-fast) use local_irq_disable(); synchronize_rcu() also waits for regions with preemption/interrupts disabled, so it should work, IIUC. And then, the trade-off would be: - Read side: zero cost (no per-CPU tracking) - Write side: wait for RCU grace period (potentially slower) For collapse/unshare, that write-side latency might be acceptable :) @David, what do you think? Right. If we go with synchronize_rcu(), the read-side cost goes away ... Thanks, Lance
{ "author": "Lance Yang <lance.yang@linux.dev>", "date": "Mon, 2 Feb 2026 23:52:31 +0800", "thread_id": "be38af98-e344-4552-a77b-b5345135e382@intel.com.mbox.gz" }