RDMA/siw: Fix potential NULL pointer dereference in header processing
Subsystems (235)
PATCH 1/385 RDMA/siw: Fix potential NULL pointer dereference in header processing
From: YunJe Shin <[email protected]>
commit 14ab3da122bd18920ad57428f6cf4fade8385142 upstream.
If siw_get_hdr() returns -EINVAL before set_rx_fpdu_context(), qp->rx_fpdu can be NULL. The error path in siw_tcp_rx_data() dereferences qp->rx_fpdu->more_ddp_segs without checking, which may lead to a NULL pointer deref. Only check more_ddp_segs when rx_fpdu is present.
KASAN splat:
[ 101.384271] KASAN: null-ptr-deref in range [0x00000000000000c0-0x00000000000000c7] [ 101.385869] RIP: 0010:siw_tcp_rx_data+0x13ad/0x1e50
--- drivers/infiniband/sw/siw/siw_qp_rx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/sw/siw/siw_qp_rx.c +2 -1
@@ -1436,7 +1436,8 @@ int siw_tcp_rx_data(read_descriptor_t *rd_desc, struct sk_buff *skb, }if (unlikely (rv !=0 && rv != -EAGAIN )) {if ((srx->state >SIW_GET_HDR || - qp->rx_fpdu->more_ddp_segs) && run_completion) + (qp->rx_fpdu && qp->rx_fpdu->more_ddp_segs)) && + run_completion)siw_rdmap_complete (qp, rv); siw_dbg_qp(qp, "rx error %d, rx state %d\n", rv,
Signature · 1 line
2.51.0
PATCH 2/385 RDMA/umad: Reject negative data_len in ib_umad_write
From: YunJe Shin <[email protected]>
commit 5551b02fdbfd85a325bb857f3a8f9c9f33397ed2 upstream.
ib_umad_write computes data_len from user-controlled count and the MAD header sizes. With a mismatched user MAD header size and RMPP header length, data_len can become negative and reach ib_create_send_mad(). This can make the padding calculation exceed the segment size and trigger an out-of-bounds memset in alloc_send_rmpp_list().
Add an explicit check to reject negative data_len before creating the send buffer.
KASAN splat:
[ 211.363464] BUG: KASAN: slab-out-of-bounds in ib_create_send_mad+0xa01/0x11b0 [ 211.364077] Write of size 220 at addr ffff88800c3fa1f8 by task spray_thread/102 [ 211.365867] ib_create_send_mad+0xa01/0x11b0 [ 211.365887] ib_umad_write+0x853/0x1c80
--- drivers/infiniband/core/user_mad.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/core/user_mad.c +6 -2
@@ -514,7 +514,8 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,struct rdma_ah_attr ah_attr;struct ib_ah *ah;__be64 *tid; -int ret, data_len, hdr_len, copy_offset, rmpp_active; +int ret, hdr_len, copy_offset, rmpp_active; +size_t data_len;u8 base_version;if (count <hdr_size (file) +IB_MGMT_RMPP_HDR )
@@ -588,7 +589,10 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf, } base_version = ((struct ib_mad_hdr *)&packet->mad.data)->base_version; - data_len = count -hdr_size (file) - hdr_len; +if (check_sub_overflow (count,hdr_size (file) + hdr_len, &data_len)) { + ret = -EINVAL ; + goto err_ah; + } packet->msg = ib_create_send_mad(agent, be32_to_cpu(packet->mad.hdr.qpn), packet->mad.hdr.pkey_index, rmpp_active,
Signature · 1 line
2.51.0
PATCH 3/385 auxdisplay: arm-charlcd: fix release_mem_region() size
In reply to Sasha LevinFrom: Thomas Fourier <[email protected]>
[ Upstream commit b5c23a4d291d2ac1dfdd574a68a3a68c8da3069e ]
It seems like, after the request_mem_region(), the corresponding release_mem_region() must take the same size. This was done in (now removed due to previous refactoring) charlcd_remove() but not in the error path in charlcd_probe().
--- drivers/auxdisplay/arm-charlcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/arm-charlcd.c +1 -1
@@ -323,7 +323,7 @@ static int __init charlcd_probe(struct platform_device *pdev) out_no_irq:iounmap (lcd->virtbase); out_no_memregion: -release_mem_region (lcd->phybase,SZ_4K ); +release_mem_region (lcd->phybase, lcd->physize); out_no_resource:kfree (lcd);return ret;
Signature · 1 line
2.51.0
PATCH 4/385 hfsplus: return error when node already exists in hfs_bnode_create
In reply to Sasha LevinFrom: Shardul Bankar <[email protected]>
[ Upstream commit d8a73cc46c8462a969a7516131feb3096f4c49d3 ]
When hfs_bnode_create() finds that a node is already hashed (which should not happen in normal operation), it currently returns the existing node without incrementing its reference count. This causes a reference count inconsistency that leads to a kernel panic when the node is later freed in hfs_bnode_put():
kernel BUG at fs/hfsplus/bnode.c:676!
BUG_ON(!atomic_read(&node->refcnt))
This scenario can occur when hfs_bmap_alloc() attempts to allocate a node that is already in use (e.g., when node 0's bitmap bit is incorrectly unset), or due to filesystem corruption.
Returning an existing node from a create path is not normal operation.
Fix this by returning ERR_PTR(-EEXIST) instead of the node when it's already hashed. This properly signals the error condition to callers, which already check for IS_ERR() return values.
--- fs/hfsplus/bnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hfsplus/bnode.c +1 -1
@@ -629,7 +629,7 @@ struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num)if (node) {pr_crit ("new node %u already hashed?\n" , num);WARN_ON (1 ); -return node; +return ERR_PTR (-EEXIST ); } node =__hfs_bnode_create (tree, num);if (!node)
Signature · 1 line
2.51.0
PATCH 5/385 rcu: Refactor expedited handling check in rcu_read_unlock_special()
In reply to Sasha LevinFrom: Joel Fernandes <[email protected]>
[ Upstream commit 908a97eba8c8b510996bf5d77d1e3070d59caa6d ]
Extract the complex expedited handling condition in rcu_read_unlock_special() into a separate function rcu_unlock_needs_exp_handling() with detailed comments explaining each condition.
This improves code readability. No functional change intended.
Stable-dep-of: d41e37f26b31 ("rcu: Fix rcu_read_unlock() deadloop due to softirq")
--- kernel/rcu/tree_plugin.h | 83 +++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 9 deletions(-)
kernel/rcu/tree_plugin.h +74 -9
@@ -651,6 +651,75 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)local_irq_restore (flags); } +/* +* Check if expedited grace period processing during unlock is needed. +* +* This function determines whether expedited handling is required based on: +* 1. Task blocking an expedited grace period (based on a heuristic, could be +* false-positive, see below.) +* 2. CPU participating in an expedited grace period +* 3. Strict grace period mode requiring expedited handling +* 4. RCU priority deboosting needs when interrupts were disabled +* +* @t: The task being checked +* @rdp: The per-CPU RCU data +* @rnp: The RCU node for this CPU +* @irqs_were_disabled: Whether interrupts were disabled before rcu_read_unlock() +* +* Returns true if expedited processing of the rcu_read_unlock() is needed. +*/ +static bool rcu_unlock_needs_exp_handling (struct task_struct *t, +struct rcu_data *rdp, +struct rcu_node *rnp, +bool irqs_were_disabled) +{ +/* +* Check if this task is blocking an expedited grace period. If the +* task was preempted within an RCU read-side critical section and is +* on the expedited grace period blockers list (exp_tasks), we need +* expedited handling to unblock the expedited GP. This is not an exact +* check because 't' might not be on the exp_tasks list at all - its +* just a fast heuristic that can be false-positive sometimes. +*/ +if (t->rcu_blocked_node &&READ_ONCE (t->rcu_blocked_node->exp_tasks)) +return true; + +/* +* Check if this CPU is participating in an expedited grace period. +* The expmask bitmap tracks which CPUs need to check in for the +* current expedited GP. If our CPU's bit is set, we need expedited +* handling to help complete the expedited GP. +*/ +if (rdp->grpmask &READ_ONCE (rnp->expmask)) +return true; + +/* +* In CONFIG_RCU_STRICT_GRACE_PERIOD=y kernels, all grace periods +* are treated as short for testing purposes even if that means +* disturbing the system more. Check if either: +* - This CPU has not yet reported a quiescent state, or +* - This task was preempted within an RCU critical section +* In either case, require expedited handling for strict GP mode. +*/ +if (IS_ENABLED (CONFIG_RCU_STRICT_GRACE_PERIOD ) && + ((rdp->grpmask &READ_ONCE (rnp->qsmask)) || t->rcu_blocked_node)) +return true; + +/* +* RCU priority boosting case: If a task is subject to RCU priority +* boosting and exits an RCU read-side critical section with interrupts +* disabled, we need expedited handling to ensure timely deboosting. +* Without this, a low-priority task could incorrectly run at high +* real-time priority for an extended period degrading real-time +* responsiveness. This applies to all CONFIG_RCU_BOOST=y kernels, +* not just to PREEMPT_RT. +*/ +if (IS_ENABLED (CONFIG_RCU_BOOST ) && irqs_were_disabled && t->rcu_blocked_node) +return true; + +return false; +} +/* * Handle special cases during rcu_read_unlock(), such as needing to * notify RCU core processing or task having blocked during the RCU
@@ -670,18 +739,14 @@ static void rcu_read_unlock_special(struct task_struct *t)local_irq_save (flags); irqs_were_disabled =irqs_disabled_flags (flags);if (preempt_bh_were_disabled || irqs_were_disabled) { -bool expboost;// Expedited GP in flight or possible boosting. +bool needs_exp;// Expedited handling needed. struct rcu_data *rdp =this_cpu_ptr (&rcu_data);struct rcu_node *rnp = rdp->mynode; - expboost = (t->rcu_blocked_node &&READ_ONCE (t->rcu_blocked_node->exp_tasks)) || - (rdp->grpmask &READ_ONCE (rnp->expmask)) || - (IS_ENABLED (CONFIG_RCU_STRICT_GRACE_PERIOD ) && - ((rdp->grpmask &READ_ONCE (rnp->qsmask)) || t->rcu_blocked_node)) || - (IS_ENABLED (CONFIG_RCU_BOOST ) && irqs_were_disabled && - t->rcu_blocked_node); + needs_exp =rcu_unlock_needs_exp_handling (t, rdp, rnp, irqs_were_disabled); +// Need to defer quiescent state until everything is enabled. -if (use_softirq && (in_hardirq () || (expboost && !irqs_were_disabled))) { +if (use_softirq && (in_hardirq () || (needs_exp && !irqs_were_disabled))) {// Using softirq, safe to awaken, and either the // wakeup is free or there is either an expedited // GP in flight or a potential need to deboost.
@@ -694,7 +759,7 @@ static void rcu_read_unlock_special(struct task_struct *t)set_tsk_need_resched (current);set_preempt_need_resched ();if (IS_ENABLED (CONFIG_IRQ_WORK ) && irqs_were_disabled && - expboost && rdp->defer_qs_iw_pending !=DEFER_QS_PENDING && + needs_exp && rdp->defer_qs_iw_pending !=DEFER_QS_PENDING &&cpu_online (rdp->cpu)) {// Get scheduler to re-evaluate and call hooks. // If !IRQ_WORK, FQS scan will eventually IPI.
Signature · 1 line
2.51.0
PATCH 6/385 rcu: Remove local_irq_save/restore() in rcu_preempt_deferred_qs_handler()
In reply to Sasha LevinFrom: Zqiang <[email protected]>
[ Upstream commit 42d590d100f2e47e47d974a902b9ed610e464824 ]
The per-CPU rcu_data structure's ->defer_qs_iw field is initialized by IRQ_WORK_INIT_HARD(), which means that the subsequent invocation of rcu_preempt_deferred_qs_handler() will always be executed with interrupts disabled. This commit therefore removes the local_irq_save/restore() operations from rcu_preempt_deferred_qs_handler() and adds a call to lockdep_assert_irqs_disabled() in order to enable lockdep to diagnose mistaken invocations of this function from interrupts-enabled code.
Stable-dep-of: d41e37f26b31 ("rcu: Fix rcu_read_unlock() deadloop due to softirq")
--- kernel/rcu/tree_plugin.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
kernel/rcu/tree_plugin.h +1 -4
@@ -626,11 +626,10 @@ notrace void rcu_preempt_deferred_qs(struct task_struct *t)*/ static void rcu_preempt_deferred_qs_handler (struct irq_work *iwp) { -unsigned long flags;struct rcu_data *rdp; +lockdep_assert_irqs_disabled (); rdp = container_of(iwp, struct rcu_data, defer_qs_iw); -local_irq_save (flags);/* * If the IRQ work handler happens to run in the middle of RCU read-side
@@ -647,8 +646,6 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)*/ if (rcu_preempt_depth () >0 )WRITE_ONCE (rdp->defer_qs_iw_pending,DEFER_QS_IDLE ); - -local_irq_restore (flags); }/*
Signature · 1 line
2.51.0
PATCH 7/385 rcu: Fix rcu_read_unlock() deadloop due to softirq
In reply to Sasha LevinFrom: Yao Kai <[email protected]>
[ Upstream commit d41e37f26b3157b3f1d10223863519a943aa239b ]
Commit 5f5fa7ea89dc ("rcu: Don't use negative nesting depth in __rcu_read_unlock()") removes the recursion-protection code from __rcu_read_unlock(). Therefore, we could invoke the deadloop in raise_softirq_irqoff() with ftrace enabled as follows:
WARNING: CPU: 0 PID: 0 at kernel/trace/trace.c:3021 __ftrace_trace_stack.constprop.0+0x172/0x180 Modules linked in: my_irq_work(O) CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Tainted: G O 6.18.0-rc7-dirty #23 PREEMPT(full) Tainted: [O]=OOT_MODULE Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 RIP: 0010:__ftrace_trace_stack.constprop.0+0x172/0x180 RSP: 0018:ffffc900000034a8 EFLAGS: 00010002 RAX: 0000000000000000 RBX: 0000000000000004 RCX: 0000000000000000 RDX: 0000000000000003 RSI: ffffffff826d7b87 RDI: ffffffff826e9329 RBP: 0000000000090009 R08: 0000000000000005 R09: ffffffff82afbc4c R10: 0000000000000008 R11: 0000000000011d7a R12: 0000000000000000 R13: ffff888003874100 R14: 0000000000000003 R15: ffff8880038c1054 FS: 0000000000000000(0000) GS:ffff8880fa8ea000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055b31fa7f540 CR3: 00000000078f4005 CR4: 0000000000770ef0 PKRU: 55555554 Call Trace: <IRQ> trace_buffer_unlock_commit_regs+0x6d/0x220 trace_event_buffer_commit+0x5c/0x260 trace_event_raw_event_softirq+0x47/0x80 raise_softirq_irqoff+0x6e/0xa0 rcu_read_unlock_special+0xb1/0x160 unwind_next_frame+0x203/0x9b0 __unwind_start+0x15d/0x1c0 arch_stack_walk+0x62/0xf0 stack_trace_save+0x48/0x70 __ftrace_trace_stack.constprop.0+0x144/0x180 trace_buffer_unlock_commit_regs+0x6d/0x220 trace_event_buffer_commit+0x5c/0x260 trace_event_raw_event_softirq+0x47/0x80 raise_softirq_irqoff+0x6e/0xa0 rcu_read_unlock_special+0xb1/0x160 unwind_next_frame+0x203/0x9b0 __unwind_start+0x15d/0x1c0 arch_stack_walk+0x62/0xf0 stack_trace_save+0x48/0x70 __ftrace_trace_stack.constprop.0+0x144/0x180 trace_buffer_unlock_commit_regs+0x6d/0x220 trace_event_buffer_commit+0x5c/0x260 trace_event_raw_event_softirq+0x47/0x80 raise_softirq_irqoff+0x6e/0xa0 rcu_read_unlock_special+0xb1/0x160 unwind_next_frame+0x203/0x9b0 __unwind_start+0x15d/0x1c0 arch_stack_walk+0x62/0xf0 stack_trace_save+0x48/0x70 __ftrace_trace_stack.constprop.0+0x144/0x180 trace_buffer_unlock_commit_regs+0x6d/0x220 trace_event_buffer_commit+0x5c/0x260 trace_event_raw_event_softirq+0x47/0x80 raise_softirq_irqoff+0x6e/0xa0 rcu_read_unlock_special+0xb1/0x160 __is_insn_slot_addr+0x54/0x70 kernel_text_address+0x48/0xc0 __kernel_text_address+0xd/0x40 unwind_get_return_address+0x1e/0x40 arch_stack_walk+0x9c/0xf0 stack_trace_save+0x48/0x70 __ftrace_trace_stack.constprop.0+0x144/0x180 trace_buffer_unlock_commit_regs+0x6d/0x220 trace_event_buffer_commit+0x5c/0x260 trace_event_raw_event_softirq+0x47/0x80 __raise_softirq_irqoff+0x61/0x80 __flush_smp_call_function_queue+0x115/0x420 __sysvec_call_function_single+0x17/0xb0 sysvec_call_function_single+0x8c/0xc0 </IRQ>
Commit b41642c87716 ("rcu: Fix rcu_read_unlock() deadloop due to IRQ work") fixed the infinite loop in rcu_read_unlock_special() for IRQ work by setting a flag before calling irq_work_queue_on(). We fix this issue by setting the same flag before calling raise_softirq_irqoff() and rename the flag to defer_qs_pending for more common.
--- kernel/rcu/tree.h | 2 +- kernel/rcu/tree_plugin.h | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-)
kernel/rcu/tree.h +1 -1
@@ -202,7 +202,7 @@ struct rcu_data {/* during and after the last grace */ /* period it is aware of. */ struct irq_work defer_qs_iw;/* Obtain later scheduler attention. */ -int defer_qs_iw_pending;/* Scheduler attention pending? */ +int defer_qs_pending;/* irqwork or softirq pending? */ struct work_struct strict_work;/* Schedule readers for strict GPs. */ /* 2) batch handling */
kernel/rcu/tree_plugin.h +9 -6
@@ -486,8 +486,8 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags)union rcu_special special; rdp =this_cpu_ptr (&rcu_data); -if (rdp->defer_qs_iw_pending ==DEFER_QS_PENDING ) - rdp->defer_qs_iw_pending =DEFER_QS_IDLE ; +if (rdp->defer_qs_pending ==DEFER_QS_PENDING ) + rdp->defer_qs_pending =DEFER_QS_IDLE ;/* * If RCU core is waiting for this CPU to exit its critical section,
@@ -645,7 +645,7 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)* 5. Deferred QS reporting does not happen. */ if (rcu_preempt_depth () >0 ) -WRITE_ONCE (rdp->defer_qs_iw_pending,DEFER_QS_IDLE ); +WRITE_ONCE (rdp->defer_qs_pending,DEFER_QS_IDLE ); }/*
@@ -747,7 +747,10 @@ static void rcu_read_unlock_special(struct task_struct *t)// Using softirq, safe to awaken, and either the // wakeup is free or there is either an expedited // GP in flight or a potential need to deboost. -raise_softirq_irqoff (RCU_SOFTIRQ ); +if (rdp->defer_qs_pending !=DEFER_QS_PENDING ) { + rdp->defer_qs_pending =DEFER_QS_PENDING ; +raise_softirq_irqoff (RCU_SOFTIRQ ); + } }else {// Enabling BH or preempt does reschedule, so... // Also if no expediting and no possible deboosting,
@@ -756,11 +759,11 @@ static void rcu_read_unlock_special(struct task_struct *t)set_tsk_need_resched (current);set_preempt_need_resched ();if (IS_ENABLED (CONFIG_IRQ_WORK ) && irqs_were_disabled && - needs_exp && rdp->defer_qs_iw_pending !=DEFER_QS_PENDING && + needs_exp && rdp->defer_qs_pending !=DEFER_QS_PENDING &&cpu_online (rdp->cpu)) {// Get scheduler to re-evaluate and call hooks. // If !IRQ_WORK, FQS scan will eventually IPI. - rdp->defer_qs_iw_pending =DEFER_QS_PENDING ; + rdp->defer_qs_pending =DEFER_QS_PENDING ;irq_work_queue_on (&rdp->defer_qs_iw, rdp->cpu); } }
Signature · 1 line
2.51.0
PATCH 8/385 audit: move the compat_xxx_class[] extern declarations to audit_arch.h
In reply to Sasha LevinFrom: Ben Dooks <[email protected]>
[ Upstream commit 76489955c6d4a065ca69dc88faf7a50a59b66f35 ]
The comapt_xxx_class symbols aren't declared in anything that lib/comapt_audit.c is including (arm64 build) which is causing the following sparse warnings:
lib/compat_audit.c:7:10: warning: symbol 'compat_dir_class'
was not declared. Should it be static?lib/compat_audit.c:12:10: warning: symbol 'compat_read_class'
was not declared. Should it be static?lib/compat_audit.c:17:10: warning: symbol 'compat_write_class'
was not declared. Should it be static?lib/compat_audit.c:22:10: warning: symbol 'compat_chattr_class'
was not declared. Should it be static?lib/compat_audit.c:27:10: warning: symbol 'compat_signal_class'
was not declared. Should it be static?
Trying to fix this by chaning compat_audit.c to inclde <linux/audit.h> does not work on arm64 due to compile errors with the extra includes that changing this header makes. The simpler thing would be just to move the definitons of these symbols out of <linux/audit.h> into <linux/audit_arch.h> which is included.
--- include/linux/audit.h | 6 ------ include/linux/audit_arch.h | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/audit.h +0 -6
@@ -126,12 +126,6 @@ enum audit_nfcfgop {extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); -/* only for compat system calls */ -extern unsigned compat_write_class[]; -extern unsigned compat_read_class[]; -extern unsigned compat_dir_class[]; -extern unsigned compat_chattr_class[]; -extern unsigned compat_signal_class[];/* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */
include/linux/audit_arch.h +7 -0
@@ -23,4 +23,11 @@ enum auditsc_class_t {extern int audit_classify_compat_syscall (int abi,unsigned syscall); +/* only for compat system calls */ +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; +#endif
Signature · 1 line
2.51.0
PATCH 9/385 i3c: Move device name assignment after i3c_bus_init
In reply to Sasha LevinFrom: Billy Tsai <[email protected]>
[ Upstream commit 3502cea99c7ceb331458cbd34ef6792c83144687 ]
Move device name initialization to occur after i3c_bus_init() so that i3cbus->id is guaranteed to be assigned before it is used.
--- drivers/i3c/master.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/i3c/master.c +2 -1
@@ -2810,7 +2810,6 @@ int i3c_master_register(struct i3c_master_controller *master,INIT_LIST_HEAD (&master->boardinfo.i3c);device_initialize (&master->dev); -dev_set_name (&master->dev,"i3c-%d" , i3cbus->id); master->dev.dma_mask = parent->dma_mask; master->dev.coherent_dma_mask = parent->coherent_dma_mask;
@@ -2820,6 +2819,8 @@ int i3c_master_register(struct i3c_master_controller *master,if (ret) goto err_put_dev; +dev_set_name (&master->dev,"i3c-%d" , i3cbus->id); + ret =of_populate_i3c_bus (master);if (ret) goto err_put_dev;
Signature · 1 line
2.51.0
PATCH 10/385 fs: add <linux/init_task.h> for 'init_fs'
In reply to Sasha LevinFrom: Ben Dooks <[email protected]>
[ Upstream commit 589cff4975afe1a4eaaa1d961652f50b1628d78d ]
The init_fs symbol is defined in <linux/init_task.h> but was not included in fs/fs_struct.c so fix by adding the include.
Fixes the following sparse warning:fs/fs_struct.c:150:18: warning: symbol 'init_fs' was not declared. Should it be static?
--- fs/fs_struct.c | 1 + 1 file changed, 1 insertion(+)
fs/fs_struct.c +1 -0
@@ -6,6 +6,7 @@#include <linux/path.h> #include <linux/slab.h> #include <linux/fs_struct.h> +#include <linux/init_task.h> #include "internal.h" /*
Signature · 1 line
2.51.0
PATCH 11/385 i3c: master: Update hot-join flag only on success
In reply to Sasha LevinFrom: Adrian Hunter <[email protected]>
[ Upstream commit f0775157b9f9a28ae3eabc8d05b0bc52e8056c80 ]
To prevent inconsistent state when an error occurs, ensure the hot-join flag is updated only when enabling or disabling hot-join succeeds.
--- drivers/i3c/master.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/i3c/master.c +2 -1
@@ -619,7 +619,8 @@ static int i3c_set_hotjoin(struct i3c_master_controller *master, bool enable)else ret = master->ops->disable_hotjoin (master); - master->hotjoin = enable; +if (!ret) + master->hotjoin = enable;i3c_bus_normaluse_unlock (&master->bus);
Signature · 1 line
2.51.0
PATCH 12/385 gfs2: Retries missing in gfs2_{rename,exchange}
In reply to Sasha LevinFrom: Andreas Gruenbacher <[email protected]>
[ Upstream commit 11d763f0b0afc2cf5f92f4adae5dbbbbef712f8f ]
Fix a bug in gfs2's asynchronous glock handling for rename and exchange operations. The original async implementation from commit ad26967b9afa ("gfs2: Use async glocks for rename") mentioned that retries were needed but never implemented them, causing operations to fail with -ESTALE instead of retrying on timeout.
Also makes the waiting interruptible.
In addition, the timeouts used were too high for situations in which timing out is a rare but expected scenario. Switch to shorter timeouts with randomization and exponentional backoff.
--- fs/gfs2/glock.c | 36 +++++++++++++++++++++++++++--------- fs/gfs2/glock.h | 3 ++- fs/gfs2/inode.c | 18 ++++++++++++++---- 3 files changed, 43 insertions(+), 14 deletions(-)
fs/gfs2/glock.c +27 -9
@@ -1393,31 +1393,45 @@ static int glocks_pending(unsigned int num_gh, struct gfs2_holder *ghs)* gfs2_glock_async_wait - wait on multiple asynchronous glock acquisitions * @num_gh: the number of holders in the array * @ghs: the glock holder array +* @retries: number of retries attempted so far * * Returns: 0 on success, meaning all glocks have been granted and are held. * -ESTALE if the request timed out, meaning all glocks were released, * and the caller should retry the operation. */ -int gfs2_glock_async_wait (unsigned int num_gh,struct gfs2_holder *ghs) +int gfs2_glock_async_wait (unsigned int num_gh,struct gfs2_holder *ghs, +unsigned int retries) {struct gfs2_sbd *sdp = ghs[0 ].gh_gl->gl_name.ln_sbd; -int i, ret =0 , timeout =0 ;unsigned long start_time = jiffies; +int i, ret =0 ; +long timeout;might_sleep (); -/* -* Total up the (minimum hold time * 2) of all glocks and use that to -* determine the max amount of time we should wait. -*/ -for (i =0 ; i < num_gh; i++) - timeout += ghs[i].gh_gl->gl_hold_time <<1 ; -if (!wait_event_timeout (sdp->sd_async_glock_wait, + timeout =GL_GLOCK_MIN_HOLD ; +if (retries) { +unsigned int max_shift; +long incr; + +/* Add a random delay and increase the timeout exponentially. */ + max_shift =BITS_PER_LONG -2 -__fls (GL_GLOCK_HOLD_INCR ); + incr =min (GL_GLOCK_HOLD_INCR <<min (retries -1 , max_shift), +10 *HZ -GL_GLOCK_MIN_HOLD ); +schedule_timeout_interruptible (get_random_long () % (incr /3 )); +if (signal_pending (current)) + goto interrupted; + timeout += (incr /3 ) +get_random_long () % (incr /3 ); + } + +if (!wait_event_interruptible_timeout (sdp->sd_async_glock_wait, !glocks_pending (num_gh, ghs), timeout)) { ret = -ESTALE ;/* request timed out. */ goto out; } +if (signal_pending (current)) + goto interrupted;for (i =0 ; i < num_gh; i++) {struct gfs2_holder *gh = &ghs[i];
@@ -1441,6 +1455,10 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs) } }return ret; + +interrupted: + ret = -EINTR ; + goto out; }/**
fs/gfs2/glock.h +2 -1
@@ -190,7 +190,8 @@ int gfs2_glock_poll(struct gfs2_holder *gh);int gfs2_instantiate (struct gfs2_holder *gh);int gfs2_glock_holder_ready (struct gfs2_holder *gh);int gfs2_glock_wait (struct gfs2_holder *gh); -int gfs2_glock_async_wait (unsigned int num_gh,struct gfs2_holder *ghs); +int gfs2_glock_async_wait (unsigned int num_gh,struct gfs2_holder *ghs, +unsigned int retries);void gfs2_glock_dq (struct gfs2_holder *gh);void gfs2_glock_dq_wait (struct gfs2_holder *gh);void gfs2_glock_dq_uninit (struct gfs2_holder *gh);
fs/gfs2/inode.c +14 -4
@@ -1504,7 +1504,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,unsigned int num_gh;int dir_rename =0 ;struct gfs2_diradd da = { .nr_blocks =0 , .save_loc =0 , }; -unsigned int x; +unsigned int retries =0 , x;int error;gfs2_holder_mark_uninitialized (&r_gh);
@@ -1554,12 +1554,17 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, num_gh++; } +again:for (x =0 ; x < num_gh; x++) { error =gfs2_glock_nq (ghs + x);if (error) goto out_gunlock; } - error =gfs2_glock_async_wait (num_gh, ghs); + error =gfs2_glock_async_wait (num_gh, ghs, retries); +if (error == -ESTALE ) { + retries++; + goto again; + }if (error) goto out_gunlock;
@@ -1748,7 +1753,7 @@ static int gfs2_exchange(struct inode *odir, struct dentry *odentry,struct gfs2_sbd *sdp =GFS2_SB (odir);struct gfs2_holder ghs[4 ], r_gh;unsigned int num_gh; -unsigned int x; +unsigned int retries =0 , x;umode_t old_mode = oip->i_inode.i_mode;umode_t new_mode = nip->i_inode.i_mode;int error;
@@ -1792,13 +1797,18 @@ static int gfs2_exchange(struct inode *odir, struct dentry *odentry,gfs2_holder_init (nip->i_gl,LM_ST_EXCLUSIVE ,GL_ASYNC , ghs + num_gh); num_gh++; +again:for (x =0 ; x < num_gh; x++) { error =gfs2_glock_nq (ghs + x);if (error) goto out_gunlock; } - error =gfs2_glock_async_wait (num_gh, ghs); + error =gfs2_glock_async_wait (num_gh, ghs, retries); +if (error == -ESTALE ) { + retries++; + goto again; + }if (error) goto out_gunlock;
Signature · 1 line
2.51.0
PATCH 13/385 gfs2: Fix slab-use-after-free in qd_put
In reply to Sasha LevinFrom: Andreas Gruenbacher <[email protected]>
[ Upstream commit 22150a7d401d9e9169b9b68e05bed95f7f49bf69 ]
Commit a475c5dd16e5 ("gfs2: Free quota data objects synchronously") started freeing quota data objects during filesystem shutdown instead of putting them back onto the LRU list, but it failed to remove these objects from the LRU list, causing LRU list corruption. This caused use-after-free when the shrinker (gfs2_qd_shrink_scan) tried to access already-freed objects on the LRU list.
Fix this by removing qd objects from the LRU list before freeing them in qd_put().
Initial fix from Deepanshu Kartikey <[email protected]>.
--- fs/gfs2/quota.c | 1 + 1 file changed, 1 insertion(+)
fs/gfs2/quota.c +1 -0
@@ -336,6 +336,7 @@ static void qd_put(struct gfs2_quota_data *qd)lockref_mark_dead (&qd->qd_lockref);spin_unlock (&qd->qd_lockref.lock); +list_lru_del_obj (&gfs2_qd_lru, &qd->qd_lru);gfs2_qd_dispose (qd);return ; }
Signature · 1 line
2.51.0
PATCH 14/385 gfs2: Fix use-after-free in iomap inline data write path
In reply to Sasha LevinFrom: Deepanshu Kartikey <[email protected]>
[ Upstream commit faddeb848305e79db89ee0479bb0e33380656321 ]
The inline data buffer head (dibh) is being released prematurely in gfs2_iomap_begin() via release_metapath() while iomap->inline_data still points to dibh->b_data. This causes a use-after-free when iomap_write_end_inline() later attempts to write to the inline data area.
The bug sequence:
1. gfs2_iomap_begin() calls gfs2_meta_inode_buffer() to read inode metadata into dibh
2. Sets iomap->inline_data = dibh->b_data + sizeof(struct gfs2_dinode)
3. Calls release_metapath() which calls brelse(dibh), dropping refcount to 0
4. kswapd reclaims the page (~39ms later in the syzbot report)
5. iomap_write_end_inline() tries to memcpy() to iomap->inline_data
6. KASAN detects use-after-free write to freed memory
Fix by storing dibh in iomap->private and incrementing its refcount with get_bh() in gfs2_iomap_begin(). The buffer is then properly released in gfs2_iomap_end() after the inline write completes, ensuring the page stays alive for the entire iomap operation.
Note: A C reproducer is not available for this issue. The fix is based on analysis of the KASAN report and code review showing the buffer head is freed before use.
[agruenba: Take buffer head reference in gfs2_iomap_begin() to avoid leaks in gfs2_iomap_get() and gfs2_iomap_alloc().]
--- fs/gfs2/bmap.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
fs/gfs2/bmap.c +12 -1
@@ -1124,10 +1124,18 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, goto out_unlock;break ;default : - goto out_unlock; + goto out; } ret =gfs2_iomap_begin_write (inode, pos, length, flags, iomap, &mp); +if (ret) + goto out_unlock; + +out: +if (iomap->type ==IOMAP_INLINE ) { + iomap->private =metapath_dibh (&mp); +get_bh (iomap->private); + } out_unlock:release_metapath (&mp);
@@ -1141,6 +1149,9 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_sbd *sdp =GFS2_SB (inode); +if (iomap->private) +brelse (iomap->private); +switch (flags & (IOMAP_WRITE |IOMAP_ZERO )) {case IOMAP_WRITE :if (flags &IOMAP_DIRECT )
Signature · 1 line
2.51.0
PATCH 15/385 i3c: dw: Initialize spinlock to avoid upsetting lockdep
In reply to Sasha LevinFrom: Fredrik Markstrom <[email protected]>
[ Upstream commit b58eaa4761ab02fc38c39d674a6bcdd55e00f388 ]
The devs_lock spinlock introduced when adding support for ibi:s was never initialized.
--- drivers/i3c/master/dw-i3c-master.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/i3c/master/dw-i3c-master.c +2 -0
@@ -1575,6 +1575,8 @@ int dw_i3c_common_probe(struct dw_i3c_master *master,spin_lock_init (&master->xferqueue.lock);INIT_LIST_HEAD (&master->xferqueue.list); +spin_lock_init (&master->devs_lock); +writel (INTR_ALL , master->regs +INTR_STATUS ); irq =platform_get_irq (pdev,0 ); ret = devm_request_irq(&pdev->dev, irq,
Signature · 1 line
2.51.0
PATCH 16/385 i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers()
In reply to Sasha LevinFrom: Zilin Guan <[email protected]>
[ Upstream commit 2537089413514caaa9a5fdeeac3a34d45100f747 ]
The dw_i3c_master_i2c_xfers() function allocates memory for the xfer structure using dw_i3c_master_alloc_xfer(). If pm_runtime_resume_and_get() fails, the function returns without freeing the allocated xfer, resulting in a memory leak.
Add a dw_i3c_master_free_xfer() call to the error path to ensure the allocated memory is properly freed.
Compile tested only. Issue found using a prototype static analysis tool and code review.
--- drivers/i3c/master/dw-i3c-master.c | 1 + 1 file changed, 1 insertion(+)
drivers/i3c/master/dw-i3c-master.c +1 -0
@@ -1102,6 +1102,7 @@ static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,dev_err (master->dev,"<%s> cannot resume i3c bus master, err: %d\n" , __func__, ret); +dw_i3c_master_free_xfer (xfer);return ret; }
Signature · 1 line
2.51.0
PATCH 17/385 tpm: tpm_i2c_infineon: Fix locality leak on get_burstcount() failure
In reply to Sasha LevinFrom: Alper Ak <[email protected]>
[ Upstream commit bbd6e97c836cbeb9606d7b7e5dcf8a1d89525713 ]
get_burstcount() can return -EBUSY on timeout. When this happens, the function returns directly without releasing the locality that was acquired at the beginning of tpm_tis_i2c_send().
Use goto out_err to ensure proper cleanup when get_burstcount() fails.
--- drivers/char/tpm/tpm_i2c_infineon.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_i2c_infineon.c +4 -2
@@ -543,8 +543,10 @@ static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len) burstcnt =get_burstcount (chip);/* burstcnt < 0 = TPM is busy */ -if (burstcnt <0 ) -return burstcnt; +if (burstcnt <0 ) { + rc = burstcnt; + goto out_err; + }if (burstcnt > (len -1 - count)) burstcnt = len -1 - count;
Signature · 1 line
2.51.0
PATCH 18/385 tpm: st33zp24: Fix missing cleanup on get_burstcount() error
In reply to Sasha LevinFrom: Alper Ak <[email protected]>
[ Upstream commit 3e91b44c93ad2871f89fc2a98c5e4fe6ca5db3d9 ]
get_burstcount() can return -EBUSY on timeout. When this happens, st33zp24_send() returns directly without releasing the locality acquired earlier.
Use goto out_err to ensure proper cleanup when get_burstcount() fails.
--- drivers/char/tpm/st33zp24/st33zp24.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/char/tpm/st33zp24/st33zp24.c +4 -2
@@ -328,8 +328,10 @@ static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf,for (i =0 ; i < len -1 ;) { burstcnt =get_burstcount (chip); -if (burstcnt <0 ) -return burstcnt; +if (burstcnt <0 ) { + ret = burstcnt; + goto out_err; + } size =min_t (int, len - i -1 , burstcnt); ret = tpm_dev->ops->send (tpm_dev->phy_id,TPM_DATA_FIFO , buf + i, size);
Signature · 1 line
2.51.0
PATCH 19/385 erofs: get rid of raw bi_end_io() usage
In reply to Sasha LevinFrom: Gao Xiang <[email protected]>
[ Upstream commit 80d0c27a0a4af8e0678d7412781482e6f73c22c7 ]
These BIOs are actually harmless in practice, as they are all pseudo BIOs and do not use advanced features like chaining. Using the BIO interface is a more friendly and unified approach for both bdev and and file-backed I/Os (compared to awkward bvec interfaces).
Let's use bio_endio() instead.
Stable-dep-of: bc804a8d7e86 ("erofs: handle end of filesystem properly for file-backed mounts")
--- fs/erofs/fileio.c | 2 +- fs/erofs/fscache.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/erofs/fileio.c +1 -1
@@ -35,13 +35,13 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret)if (rq->bio.bi_end_io) {if (ret <0 && !rq->bio.bi_status) rq->bio.bi_status =errno_to_blk_status (ret); - rq->bio.bi_end_io (&rq->bio); }else {bio_for_each_folio_all (fi, &rq->bio) {DBG_BUGON (folio_test_uptodate (fi.folio));erofs_onlinefolio_end (fi.folio, ret, false); } } +bio_endio (&rq->bio);bio_uninit (&rq->bio);if (refcount_dec_and_test (&rq->ref))kfree (rq);
fs/erofs/fscache.c +2 -2
@@ -187,7 +187,7 @@ static void erofs_fscache_bio_endio(void *priv,if (IS_ERR_VALUE (transferred_or_error)) io->bio.bi_status =errno_to_blk_status (transferred_or_error); - io->bio.bi_end_io (&io->bio); +bio_endio (&io->bio);BUILD_BUG_ON (offsetof(struct erofs_fscache_bio , io) !=0 );erofs_fscache_io_put (&io->io); }
@@ -218,7 +218,7 @@ void erofs_fscache_submit_bio(struct bio *bio)if (!ret)return ; bio->bi_status =errno_to_blk_status (ret); - bio->bi_end_io (bio); +bio_endio (bio); }static int erofs_fscache_meta_read_folio (struct file *data,struct folio *folio)
Signature · 1 line
2.51.0
PATCH 20/385 erofs: handle end of filesystem properly for file-backed mounts
In reply to Sasha LevinFrom: Gao Xiang <[email protected]>
[ Upstream commit bc804a8d7e865ef47fb7edcaf5e77d18bf444ebc ]
I/O requests beyond the end of the filesystem should be zeroed out, similar to loopback devices and that is what we expect.
--- fs/erofs/fileio.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
fs/erofs/fileio.c +8 -12
@@ -25,21 +25,17 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret) container_of(iocb, struct erofs_fileio_rq, iocb);struct folio_iter fi; -if (ret >0 ) { -if (ret != rq->bio.bi_iter.bi_size) { -bio_advance (&rq->bio, ret); -zero_fill_bio (&rq->bio); - } - ret =0 ; +if (ret >=0 && ret != rq->bio.bi_iter.bi_size) { +bio_advance (&rq->bio, ret); +zero_fill_bio (&rq->bio); } -if (rq->bio.bi_end_io) { -if (ret <0 && !rq->bio.bi_status) - rq->bio.bi_status =errno_to_blk_status (ret); - }else { +if (!rq->bio.bi_end_io) {bio_for_each_folio_all (fi, &rq->bio) {DBG_BUGON (folio_test_uptodate (fi.folio)); -erofs_onlinefolio_end (fi.folio, ret, false); +erofs_onlinefolio_end (fi.folio, ret <0 , false); } + }else if (ret <0 && !rq->bio.bi_status) { + rq->bio.bi_status =errno_to_blk_status (ret); }bio_endio (&rq->bio);bio_uninit (&rq->bio);
@@ -50,7 +46,7 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret)static void erofs_fileio_rq_submit (struct erofs_fileio_rq *rq) {struct iov_iter iter; -int ret; +ssize_t ret;if (!rq)return ;
Signature · 1 line
2.51.0
PATCH 21/385 btrfs: qgroup: return correct error when deleting qgroup relation item
In reply to Sasha LevinFrom: Filipe Manana <[email protected]>
[ Upstream commit 51b1fcf71c88c3c89e7dcf07869c5de837b1f428 ]
If we fail to delete the second qgroup relation item, we end up returning success or -ENOENT in case the first item does not exist, instead of returning the error from the second item deletion.
--- fs/btrfs/qgroup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/qgroup.c +3 -1
@@ -1673,8 +1673,10 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src,if (ret <0 && ret != -ENOENT ) goto out; ret2 =del_qgroup_relation_item (trans, dst, src); -if (ret2 <0 && ret2 != -ENOENT ) +if (ret2 <0 && ret2 != -ENOENT ) { + ret = ret2; goto out; + }/* At least one deletion succeeded, return 0 */ if (!ret || !ret2)
Signature · 1 line
2.51.0
PATCH 22/385 btrfs: fix block_group_tree dirty_list corruption
In reply to Sasha LevinFrom: Boris Burkov <[email protected]>
[ Upstream commit 3a1f4264daed4b419c325a7fe35e756cada3cf82 ]
When the incompat flag EXTENT_TREE_V2 is set, we unconditionally add the block group tree to the switch_commits list before calling switch_commit_roots, as we do for the tree root and the chunk root. However, the block group tree uses normal root dirty tracking and in any transaction that does an allocation and dirties a block group, the block group root will already be linked to a list by the dirty_list field and this use of list_add_tail() is invalid and corrupts the prev/next members of block_group_root->dirty_list.
This is apparent on a subsequent list_del on the prev if we enable CONFIG_DEBUG_LIST:
[32.1571] ------------[ cut here ]------------ [32.1572] list_del corruption. next->prev should beffff958890202538, but was ffff9588992bd538. (next=ffff958890201538) [32.1575] WARNING: lib/list_debug.c:65 at 0x0, CPU#3: sync/607 [32.1583] CPU: 3 UID: 0 PID: 607 Comm: sync Not tainted 6.18.0 #24PREEMPT(none) [32.1585] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS1.17.0-4.fc41 04/01/2014 [32.1587] RIP: 0010:__list_del_entry_valid_or_report+0x108/0x120 [32.1593] RSP: 0018:ffffaa288287fdd0 EFLAGS: 00010202 [32.1594] RAX: 0000000000000001 RBX: ffff95889326e800 RCX:ffff958890201538 [32.1596] RDX: ffff9588992bd538 RSI: ffff958890202538 RDI:ffffffff82a41e00 [32.1597] RBP: ffff958890202538 R08: ffffffff828fc1e8 R09:00000000ffffefff [32.1599] R10: ffffffff8288c200 R11: ffffffff828e4200 R12:ffff958890201538 [32.1601] R13: ffff95889326e958 R14: ffff958895c24000 R15:ffff958890202538 [32.1603] FS: 00007f0c28eb5740(0000) GS:ffff958af2bd2000(0000)knlGS:0000000000000000 [32.1605] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [32.1607] CR2: 00007f0c28e8a3cc CR3: 0000000109942005 CR4:0000000000370ef0 [32.1609] Call Trace: [32.1610] <TASK> [32.1611] switch_commit_roots+0x82/0x1d0 [btrfs] [32.1615] btrfs_commit_transaction+0x968/0x1550 [btrfs] [32.1618] ? btrfs_attach_transaction_barrier+0x23/0x60 [btrfs] [32.1621] __iterate_supers+0xe8/0x190 [32.1622] ? __pfx_sync_fs_one_sb+0x10/0x10 [32.1623] ksys_sync+0x63/0xb0 [32.1624] __do_sys_sync+0xe/0x20 [32.1625] do_syscall_64+0x73/0x450 [32.1626] entry_SYSCALL_64_after_hwframe+0x76/0x7e [32.1627] RIP: 0033:0x7f0c28d05d2b [32.1632] RSP: 002b:00007ffc9d988048 EFLAGS: 00000246 ORIG_RAX:00000000000000a2 [32.1634] RAX: ffffffffffffffda RBX: 00007ffc9d988228 RCX:00007f0c28d05d2b [32.1636] RDX: 00007f0c28e02301 RSI: 00007ffc9d989b21 RDI:00007f0c28dba90d [32.1637] RBP: 0000000000000001 R08: 0000000000000001 R09:0000000000000000 [32.1639] R10: 0000000000000000 R11: 0000000000000246 R12:000055b96572cb80 [32.1641] R13: 000055b96572b19f R14: 00007f0c28dfa434 R15:000055b96572b034 [32.1643] </TASK> [32.1644] irq event stamp: 0 [32.1644] hardirqs last enabled at (0): [<0000000000000000>] 0x0 [32.1646] hardirqs last disabled at (0): [<ffffffff81298817>]copy_process+0xb37/0x2260 [32.1648] softirqs last enabled at (0): [<ffffffff81298817>]copy_process+0xb37/0x2260 [32.1650] softirqs last disabled at (0): [<0000000000000000>] 0x0 [32.1652] ---[ end trace 0000000000000000 ]---
Furthermore, this list corruption eventually (when we happen to add a new block group) results in getting the switch_commits and dirty_cowonly_roots lists mixed up and attempting to call update_root on the tree root which can't be found in the tree root, resulting in a transaction abort:
[87.8269] BTRFS critical (device nvme1n1): unable to find root key (1 0 0) in tree 1 [87.8272] ------------[ cut here ]------------ [87.8274] BTRFS: Transaction aborted (error -117) [87.8275] WARNING: fs/btrfs/root-tree.c:153 at 0x0, CPU#4: sync/703 [87.8285] CPU: 4 UID: 0 PID: 703 Comm: sync Not tainted 6.18.0 #25 PREEMPT(none) [87.8287] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.17.0-4.fc41 04/01/2014 [87.8289] RIP: 0010:btrfs_update_root+0x296/0x790 [btrfs] [87.8295] RSP: 0018:ffffa58d035dfd60 EFLAGS: 00010282 [87.8297] RAX: ffff9a59126ddb68 RBX: ffff9a59126dc000 RCX: 0000000000000000 [87.8299] RDX: 0000000000000000 RSI: 00000000ffffff8b RDI: ffffffffc0b28270 [87.8301] RBP: ffff9a5904aec000 R08: 0000000000000000 R09: 00000000ffffefff [87.8303] R10: ffffffff9ac8c200 R11: ffffffff9ace4200 R12: 0000000000000001 [87.8305] R13: ffff9a59041740e8 R14: ffff9a5904aec1f7 R15: ffff9a590fdefaf0 [87.8307] FS: 00007f54cde6b740(0000) GS:ffff9a5b5a81c000(0000) knlGS:0000000000000000 [87.8309] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [87.8310] CR2: 00007f54cde403cc CR3: 0000000112902004 CR4: 0000000000370ef0 [87.8312] Call Trace: [87.8313] <TASK> [87.8314] ? _raw_spin_unlock+0x23/0x40 [87.8315] commit_cowonly_roots+0x1ad/0x250 [btrfs] [87.8317] ? btrfs_commit_transaction+0x79b/0x1560 [btrfs] [87.8320] btrfs_commit_transaction+0x8aa/0x1560 [btrfs] [87.8322] ? btrfs_attach_transaction_barrier+0x23/0x60 [btrfs] [87.8325] __iterate_supers+0xf1/0x170 [87.8326] ? __pfx_sync_fs_one_sb+0x10/0x10 [87.8327] ksys_sync+0x63/0xb0 [87.8328] __do_sys_sync+0xe/0x20 [87.8329] do_syscall_64+0x73/0x450 [87.8330] entry_SYSCALL_64_after_hwframe+0x76/0x7e [87.8331] RIP: 0033:0x7f54cdd05d2b [87.8336] RSP: 002b:00007fff1b58ff78 EFLAGS: 00000246 ORIG_RAX: 00000000000000a2 [87.8338] RAX: ffffffffffffffda RBX: 00007fff1b590158 RCX: 00007f54cdd05d2b [87.8340] RDX: 00007f54cde02301 RSI: 00007fff1b592b66 RDI: 00007f54cddba90d [87.8342] RBP: 0000000000000001 R08: 0000000000000001 R09: 0000000000000000 [87.8344] R10: 0000000000000000 R11: 0000000000000246 R12: 000055e07ca96b80 [87.8346] R13: 000055e07ca9519f R14: 00007f54cddfa434 R15: 000055e07ca95034 [87.8348] </TASK> [87.8348] irq event stamp: 0 [87.8349] hardirqs last enabled at (0): [<0000000000000000>] 0x0 [87.8351] hardirqs last disabled at (0): [<ffffffff99698797>] copy_process+0xb37/0x21e0 [87.8353] softirqs last enabled at (0): [<ffffffff99698797>] copy_process+0xb37/0x21e0 [87.8355] softirqs last disabled at (0): [<0000000000000000>] 0x0 [87.8357] ---[ end trace 0000000000000000 ]--- [87.8358] BTRFS: error (device nvme1n1 state A) in btrfs_update_root:153: errno=-117 Filesystem corrupted [87.8360] BTRFS info (device nvme1n1 state EA): forced readonly [87.8362] BTRFS warning (device nvme1n1 state EA): Skipping commit of aborted transaction. [87.8364] BTRFS: error (device nvme1n1 state EA) in cleanup_transaction:2037: errno=-117 Filesystem corrupted
Since the block group tree was pulled out of the extent tree and uses normal root dirty tracking, remove the offending extra list_add. This fixes the list corruption and the resulting fs corruption.
--- fs/btrfs/transaction.c | 7 ------- 1 file changed, 7 deletions(-)
fs/btrfs/transaction.c +0 -7
@@ -2487,13 +2487,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)list_add_tail (&fs_info->chunk_root->dirty_list, &cur_trans->switch_commits); -if (btrfs_fs_incompat (fs_info,EXTENT_TREE_V2 )) { -btrfs_set_root_node (&fs_info->block_group_root->root_item, - fs_info->block_group_root->node); -list_add_tail (&fs_info->block_group_root->dirty_list, - &cur_trans->switch_commits); - } -switch_commit_roots (trans);ASSERT (list_empty (&cur_trans->dirty_bgs));
Signature · 1 line
2.51.0
PATCH 23/385 smb: client: fix potential UAF and double free in smb2_open_file()
In reply to Sasha LevinFrom: Paulo Alcantara <[email protected]>
[ Upstream commit ebbbc4bfad4cb355d17c671223d0814ee3ef4eda ]
Zero out @err_iov and @err_buftype before retrying SMB2_open() to prevent an UAF bug if @data != NULL, otherwise a double free.
--- fs/smb/client/smb2file.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/smb2file.c +2 -0
@@ -123,6 +123,8 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32 &err_buftype);if (rc == -EACCES && retry_without_read_attributes) {free_rsp_buf (err_buftype, err_iov.iov_base); +memset (&err_iov,0 ,sizeof (err_iov)); + err_buftype =CIFS_NO_BUFFER ; oparms->desired_access &= ~FILE_READ_ATTRIBUTES ; rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype);
Signature · 1 line
2.51.0
PATCH 24/385 block: add a bio_add_virt_nofail helper
In reply to Sasha LevinFrom: Christoph Hellwig <[email protected]>
[ Upstream commit 850e210d5ad21b94b55b97d4d82b4cdeb0bb05df ]
Add a helper to add a directly mapped kernel virtual address to a bio so that callers don't have to convert to pages or folios.
For now only the _nofail variant is provided as that is what all the obvious callers want.
Stable-dep-of: 4ac9690d4b94 ("rnbd-srv: Fix server side setting of bi_size for special IOs")
--- block/bio.c | 16 ++++++++++++++++ include/linux/bio.h | 2 ++ 2 files changed, 18 insertions(+)
block/bio.c +16 -0
@@ -1119,6 +1119,22 @@ void __bio_add_page(struct bio *bio, struct page *page, }EXPORT_SYMBOL_GPL (__bio_add_page); +/** +* bio_add_virt_nofail - add data in the direct kernel mapping to a bio +* @bio: destination bio +* @vaddr: data to add +* @len: length of the data to add, may cross pages +* +* Add the data at @vaddr to @bio. The caller must have ensure a segment +* is available for the added data. No merging into an existing segment +* will be performed. +*/ +void bio_add_virt_nofail (struct bio *bio,void *vaddr,unsigned len) +{ +__bio_add_page (bio,virt_to_page (vaddr), len,offset_in_page (vaddr)); +} +EXPORT_SYMBOL_GPL (bio_add_virt_nofail); +/** * bio_add_page - attempt to add page(s) to bio * @bio: destination bio
include/linux/bio.h +2 -0
@@ -425,6 +425,8 @@ void __bio_add_page(struct bio *bio, struct page *page, unsigned int len, unsigned int off);void bio_add_folio_nofail (struct bio *bio,struct folio *folio,size_t len,size_t off); +void bio_add_virt_nofail (struct bio *bio,void *vaddr,unsigned len); +int bio_iov_iter_get_pages (struct bio *bio,struct iov_iter *iter);void bio_iov_bvec_set (struct bio *bio,struct iov_iter *iter);void __bio_release_pages (struct bio *bio,bool mark_dirty);
Signature · 1 line
2.51.0
PATCH 25/385 rnbd-srv: use bio_add_virt_nofail
In reply to Sasha LevinFrom: Christoph Hellwig <[email protected]>
[ Upstream commit a216081323a1391991c9073fed2459265bfc7f5c ]
Use the bio_add_virt_nofail to add a single kernel virtual address to a bio as that can't fail.
Stable-dep-of: 4ac9690d4b94 ("rnbd-srv: Fix server side setting of bi_size for special IOs")
--- drivers/block/rnbd/rnbd-srv.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/block/rnbd/rnbd-srv.c +1 -6
@@ -147,12 +147,7 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, bio =bio_alloc (file_bdev (sess_dev->bdev_file),1 ,rnbd_to_bio_flags (le32_to_cpu (msg->rw)),GFP_KERNEL ); -if (bio_add_page (bio,virt_to_page (data), datalen, -offset_in_page (data)) != datalen) { -rnbd_srv_err_rl (sess_dev,"Failed to map data to bio\n" ); - err = -EINVAL ; - goto bio_put; - } +bio_add_virt_nofail (bio, data, datalen); bio->bi_opf =rnbd_to_bio_flags (le32_to_cpu (msg->rw)); if (bio_has_data(bio) &&
Signature · 1 line
2.51.0
PATCH 26/385 rnbd-srv: Fix server side setting of bi_size for special IOs
In reply to Sasha LevinFrom: Florian-Ewald Mueller <[email protected]>
[ Upstream commit 4ac9690d4b9456ca1d5276d86547fa2e7cd47684 ]
On rnbd-srv, the bi_size of the bio is set during the bio_add_page function, to which datalen is passed. But for special IOs like DISCARD and WRITE_ZEROES, datalen is 0, since there is no data to write. For these special IOs, use the bi_size of the rnbd_msg_io.
--- drivers/block/rnbd/rnbd-srv.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
drivers/block/rnbd/rnbd-srv.c +23 -10
@@ -145,18 +145,30 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, priv->sess_dev = sess_dev; priv->id = id; - bio =bio_alloc (file_bdev (sess_dev->bdev_file),1 , + bio =bio_alloc (file_bdev (sess_dev->bdev_file), !!datalen,rnbd_to_bio_flags (le32_to_cpu (msg->rw)),GFP_KERNEL ); -bio_add_virt_nofail (bio, data, datalen); - - bio->bi_opf =rnbd_to_bio_flags (le32_to_cpu (msg->rw)); -if (bio_has_data (bio) && - bio->bi_iter.bi_size !=le32_to_cpu (msg->bi_size)) { -rnbd_srv_err_rl (sess_dev,"Datalen mismatch: bio bi_size (%u), bi_size (%u)\n" , - bio->bi_iter.bi_size, msg->bi_size); - err = -EINVAL ; - goto bio_put; +if (unlikely (!bio)) { + err = -ENOMEM ; + goto put_sess_dev; } + +if (!datalen) { +/* +* For special requests like DISCARD and WRITE_ZEROES, the datalen is zero. +*/ + bio->bi_iter.bi_size =le32_to_cpu (msg->bi_size); + }else { +bio_add_virt_nofail (bio, data, datalen); + bio->bi_opf =rnbd_to_bio_flags (le32_to_cpu (msg->rw)); +if (bio->bi_iter.bi_size !=le32_to_cpu (msg->bi_size)) { +rnbd_srv_err_rl (sess_dev, +"Datalen mismatch: bio bi_size (%u), bi_size (%u)\n" , + bio->bi_iter.bi_size, msg->bi_size); + err = -EINVAL ; + goto bio_put; + } + } + bio->bi_end_io = rnbd_dev_bi_end_io; bio->bi_private = priv; bio->bi_iter.bi_sector =le64_to_cpu (msg->sector);
@@ -170,6 +182,7 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, bio_put:bio_put (bio); +put_sess_dev:rnbd_put_sess_dev (sess_dev); err:kfree (priv);
Signature · 1 line
2.51.0
PATCH 27/385 xen/virtio: Don't use grant-dma-ops when running as Dom0
In reply to Sasha LevinFrom: Teddy Astie <[email protected]>
[ Upstream commit dc8ea8714311e549ee93a2b0bdd5487d20bfadbf ]
Dom0 inherit devices from the machine and is usually in PV mode. If we are running in a virtual that has virtio devices, these devices would be considered as using grants with Dom0 as backend, while being the said Dom0 itself, while we want to use these devices like regular PCI devices.
Fix this by preventing grant-dma-ops from being used when running as Dom0 (initial domain). We still keep the device-tree logic as-is.
Message-ID: <6698564dd2270a9f7377b78ebfb20cb425cabbe8.1767720955.git.teddy.astie@vates.tech>
--- drivers/xen/grant-dma-ops.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/xen/grant-dma-ops.c +2 -1
@@ -362,7 +362,8 @@ static int xen_grant_init_backend_domid(struct device *dev,if (np) { ret =xen_dt_grant_init_backend_domid (dev, np, backend_domid);of_node_put (np); - }else if (IS_ENABLED (CONFIG_XEN_VIRTIO_FORCE_GRANT ) ||xen_pv_domain ()) { + }else if (!xen_initial_domain () && + (IS_ENABLED (CONFIG_XEN_VIRTIO_FORCE_GRANT ) ||xen_pv_domain ())) {dev_info (dev,"Using dom0 as backend\n" ); *backend_domid =0 ; ret =0 ;
Signature · 1 line
2.51.0
PATCH 28/385 io_uring: use release-acquire ordering for IORING_SETUP_R_DISABLED
In reply to Sasha LevinFrom: Caleb Sander Mateos <[email protected]>
[ Upstream commit 7a8737e1132ff07ca225aa7a4008f87319b5b1ca ]
io_uring_enter(), __io_msg_ring_data(), and io_msg_send_fd() read ctx->flags and ctx->submitter_task without holding the ctx's uring_lock. This means they may race with the assignment to ctx->submitter_task and the clearing of IORING_SETUP_R_DISABLED from ctx->flags in io_register_enable_rings(). Ensure the correct ordering of the ctx->flags and ctx->submitter_task memory accesses by storing to ctx->flags using release ordering and loading it using acquire ordering.
--- io_uring/io_uring.c | 6 +++++- io_uring/msg_ring.c | 12 ++++++++++-- io_uring/register.c | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-)
io_uring/io_uring.c +5 -1
@@ -3312,7 +3312,11 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ctx = file->private_data; ret = -EBADFD ; -if (unlikely (ctx->flags &IORING_SETUP_R_DISABLED )) +/* +* Keep IORING_SETUP_R_DISABLED check before submitter_task load +* in io_uring_add_tctx_node() -> __io_uring_add_tctx_node_from_submit() +*/ +if (unlikely (smp_load_acquire (&ctx->flags) &IORING_SETUP_R_DISABLED )) goto out;/*
io_uring/msg_ring.c +10 -2
@@ -126,7 +126,11 @@ static int io_msg_ring_data(struct io_kiocb *req, unsigned int issue_flags)return -EINVAL ;if (!(msg->flags &IORING_MSG_RING_FLAGS_PASS ) && msg->dst_fd)return -EINVAL ; -if (target_ctx->flags &IORING_SETUP_R_DISABLED ) +/* +* Keep IORING_SETUP_R_DISABLED check before submitter_task load +* in io_msg_data_remote() -> io_msg_remote_post() +*/ +if (smp_load_acquire (&target_ctx->flags) &IORING_SETUP_R_DISABLED )return -EBADFD ;if (io_msg_need_remote (target_ctx))
@@ -237,7 +241,11 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)return -EINVAL ;if (target_ctx == ctx)return -EINVAL ; -if (target_ctx->flags &IORING_SETUP_R_DISABLED ) +/* +* Keep IORING_SETUP_R_DISABLED check before submitter_task load +* in io_msg_fd_remote() +*/ +if (smp_load_acquire (&target_ctx->flags) &IORING_SETUP_R_DISABLED )return -EBADFD ;if (!src_file) { src_file =io_msg_grab_file (req, issue_flags);
io_uring/register.c +2 -1
@@ -190,7 +190,8 @@ static int io_register_enable_rings(struct io_ring_ctx *ctx)if (ctx->restrictions.registered) ctx->restricted =1 ; - ctx->flags &= ~IORING_SETUP_R_DISABLED ; +/* Keep submitter_task store before clearing IORING_SETUP_R_DISABLED */ +smp_store_release (&ctx->flags, ctx->flags & ~IORING_SETUP_R_DISABLED );if (ctx->sq_data &&wq_has_sleeper (&ctx->sq_data->wait))wake_up (&ctx->sq_data->wait);return 0 ;
Signature · 1 line
2.51.0
PATCH 29/385 ACPICA: Fix NULL pointer dereference in acpi_ev_address_space_dispatch()
In reply to Sasha LevinFrom: Alexey Simakov <[email protected]>
[ Upstream commit f851e03bce968ff9b3faad1b616062e1244fd38d ]
Cover a missed execution path with a new check.
--- drivers/acpi/acpica/evregion.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/acpica/evregion.c +3 -1
@@ -163,7 +163,9 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,return_ACPI_STATUS (AE_NOT_EXIST ); } -if (region_obj->region.space_id ==ACPI_ADR_SPACE_PLATFORM_COMM ) { +if (field_obj + && region_obj->region.space_id == +ACPI_ADR_SPACE_PLATFORM_COMM ) {struct acpi_pcc_info *ctx = handler_desc->address_space.context;
Signature · 1 line
2.51.0
PATCH 30/385 io_uring/sync: validate passed in offset
In reply to Sasha LevinFrom: Jens Axboe <[email protected]>
[ Upstream commit 649dd18f559891bdafc5532d737c7dfb56060a6d ]
Check if the passed in offset is negative once cast to sync->off. This ensures that -EINVAL is returned for that case, like it would be for sync_file_range(2).
--- io_uring/sync.c | 2 ++ 1 file changed, 2 insertions(+)
io_uring/sync.c +2 -0
@@ -62,6 +62,8 @@ int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)return -EINVAL ; sync->off =READ_ONCE (sqe->off); +if (sync->off <0 ) +return -EINVAL ; sync->len =READ_ONCE (sqe->len); req->flags |=REQ_F_FORCE_ASYNC ;return 0 ;
Signature · 1 line
2.51.0
PATCH 31/385 cpuidle: governors: menu: Always check timers with tick stopped
In reply to Sasha LevinFrom: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit 80606f4eb8d7484ab7f7d6f0fd30d71e6fbcf328 ]
After commit 5484e31bbbff ("cpuidle: menu: Skip tick_nohz_get_sleep_length() call in some cases"), if the return value of get_typical_interval() multiplied by NSEC_PER_USEC is not greater than RESIDENCY_THRESHOLD_NS, the menu governor will skip computing the time till the closest timer. If that happens when the tick has been stopped already, the selected idle state may be too deep due to the subsequent check comparing predicted_ns with TICK_NSEC and causing its value to be replaced with the expected time till the closest timer, which is KTIME_MAX in that case. That will cause the deepest enabled idle state to be selected, but the time till the closest timer very well may be shorter than the target residency of that state, in which case a shallower state should be used.
Address this by making menu_select() always compute the time till the closest timer when the tick has been stopped.
Also move the predicted_ns check mentioned above into the branch in which the time till the closest timer is determined because it only needs to be done in that case.
--- drivers/cpuidle/governors/menu.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/cpuidle/governors/menu.c +11 -11
@@ -245,7 +245,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,/* Find the shortest expected idle interval. */ predicted_ns =get_typical_interval (data) *NSEC_PER_USEC ; -if (predicted_ns >RESIDENCY_THRESHOLD_NS ) { +if (predicted_ns >RESIDENCY_THRESHOLD_NS ||tick_nohz_tick_stopped ()) {unsigned int timer_us;/* Determine the time till the closest timer. */
@@ -265,6 +265,16 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, RESOLUTION * DECAY * NSEC_PER_USEC);/* Use the lowest expected idle interval to pick the idle state. */ predicted_ns =min ((u64 )timer_us *NSEC_PER_USEC , predicted_ns); +/* +* If the tick is already stopped, the cost of possible short +* idle duration misprediction is much higher, because the CPU +* may be stuck in a shallow idle state for a long time as a +* result of it. In that case, say we might mispredict and use +* the known time till the closest timer event for the idle +* state selection. +*/ +if (tick_nohz_tick_stopped () && predicted_ns <TICK_NSEC ) + predicted_ns = data->next_timer_ns; }else {/* * Because the next timer event is not going to be determined
@@ -290,16 +300,6 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,return 0 ; } -/* -* If the tick is already stopped, the cost of possible short idle -* duration misprediction is much higher, because the CPU may be stuck -* in a shallow idle state for a long time as a result of it. In that -* case, say we might mispredict and use the known time till the closest -* timer event for the idle state selection. -*/ -if (tick_nohz_tick_stopped () && predicted_ns <TICK_NSEC ) - predicted_ns = data->next_timer_ns; -/* * Find the idle state with the lowest power while satisfying * our constraints.
Signature · 1 line
2.51.0
PATCH 32/385 thermal: intel: x86_pkg_temp_thermal: Handle invalid temperature
In reply to Sasha LevinFrom: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit 9635c586a559ba0e45b2bfbff79c937ddbaf1a62 ]
After commit be0a3600aa1e ("thermal: sysfs: Rework the handling of trip point updates"), THERMAL_TEMP_INVALID can be passed to sys_set_trip_temp() and it is treated as a regular temperature value there, so the sysfs write fails even though it is expected to succeed and disable the given trip point.
Address this by making sys_set_trip_temp() clear its temp variable when it is equal to THERMAL_TEMP_INVALID.
--- drivers/thermal/intel/x86_pkg_temp_thermal.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/thermal/intel/x86_pkg_temp_thermal.c +3 -0
@@ -127,6 +127,9 @@ sys_set_trip_temp(struct thermal_zone_device *tzd,u32 l, h, mask, shift, intr;int tj_max, val, ret; +if (temp ==THERMAL_TEMP_INVALID ) + temp =0 ; + tj_max =intel_tcc_get_tjmax (zonedev->cpu);if (tj_max <0 )return tj_max;
Signature · 1 line
2.51.0
PATCH 33/385 md/raid5: fix raid5_run() to return error when log_init() fails
In reply to Sasha LevinFrom: Yu Kuai <[email protected]>
[ Upstream commit 2d9f7150ac197ce79c9c917a004d4cf0b26ad7e0 ]
Since commit f63f17350e53 ("md/raid5: use the atomic queue limit update APIs"), the abort path in raid5_run() returns 'ret' instead of -EIO. However, if log_init() fails, 'ret' is still 0 from the previous successful call, causing raid5_run() to return success despite the failure.
Fix this by capturing the return value from log_init().
--- drivers/md/raid5.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/raid5.c +2 -1
@@ -8049,7 +8049,8 @@ static int raid5_run(struct mddev *mddev) goto abort; } -if (log_init (conf, journal_dev,raid5_has_ppl (conf))) + ret =log_init (conf, journal_dev,raid5_has_ppl (conf)); +if (ret) goto abort;return 0 ;
Signature · 1 line
2.51.0
PATCH 34/385 md/raid10: fix any_working flag handling in raid10_sync_request
In reply to Sasha LevinFrom: Li Nan <[email protected]>
[ Upstream commit 99582edb3f62e8ee6c34512021368f53f9b091f2 ]
In raid10_sync_request(), 'any_working' indicates if any IO will be submitted. When there's only one In_sync disk with badblocks, 'any_working' might be set to 1 but no IO is submitted. Fix it by setting 'any_working' after badblock checks.
--- drivers/md/raid10.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid10.c +1 -1
@@ -3417,7 +3417,6 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr, !test_bit(In_sync, &rdev->flags))continue ;/* This is where we read from */ - any_working =1 ; sector = r10_bio->devs[j].addr; if (is_badblock(rdev, sector, max_sync,
@@ -3432,6 +3431,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,continue ; } } + any_working =1 ; bio = r10_bio->devs[0 ].bio; bio->bi_next = biolist; biolist = bio;
Signature · 1 line
2.51.0
PATCH 35/385 OPP: Return correct value in dev_pm_opp_get_level
In reply to Sasha LevinFrom: Aleks Todorov <[email protected]>
[ Upstream commit 0b7277e02dabba2a9921a7f4761ae6e627e7297a ]
Commit 073d3d2ca7d4 ("OPP: Level zero is valid") modified the documentation for this function to indicate that errors should return a non-zero value to avoid colliding with the OPP level zero, however forgot to actually update the return.
No in-tree kernel code depends on the error value being 0.
--- drivers/opp/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/opp/core.c +1 -1
@@ -226,7 +226,7 @@ unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp) {if (IS_ERR_OR_NULL (opp) || !opp->available) {pr_err ("%s: Invalid parameters\n" , __func__); -return 0 ; +return U32_MAX ; }return opp->level;
Signature · 1 line
2.51.0
PATCH 36/385 cpufreq: scmi: Fix device_node reference leak in scmi_cpu_domain_id()
In reply to Sasha LevinFrom: Felix Gu <[email protected]>
[ Upstream commit 0b7fbf9333fa4699a53145bad8ce74ea986caa13 ]
When calling of_parse_phandle_with_args(), the caller is responsible to call of_node_put() to release the reference of device node. In scmi_cpu_domain_id(), it does not release the reference.
--- drivers/cpufreq/scmi-cpufreq.c | 1 + 1 file changed, 1 insertion(+)
drivers/cpufreq/scmi-cpufreq.c +1 -0
@@ -98,6 +98,7 @@ static int scmi_cpu_domain_id(struct device *cpu_dev)return -EINVAL ; } +of_node_put (domain_id.np);return domain_id.args[0 ]; }
Signature · 1 line
2.51.0
PATCH 37/385 iomap: fix submission side handling of completion side errors
In reply to Sasha LevinFrom: Christoph Hellwig <[email protected]>
[ Upstream commit 4ad357e39b2ecd5da7bcc7e840ee24d179593cd5 ]
The "if (dio->error)" in iomap_dio_bio_iter exists to stop submitting more bios when a completion already return an error. Commit cfe057f7db1f ("iomap_dio_actor(): fix iov_iter bugs") made it revert the iov by "copied", which is very wrong given that we've already consumed that range and submitted a bio for it.
--- fs/iomap/direct-io.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fs/iomap/direct-io.c +7 -3
@@ -398,9 +398,13 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, nr_pages =bio_iov_vecs_to_alloc (dio->submit.iter,BIO_MAX_VECS ); do { size_t n; - if (dio->error) { - iov_iter_revert(dio->submit.iter, copied); - copied = ret = 0; + + /* + * If completions already occurred and reported errors, give up now and + * don't bother submitting more bios. + */ + if (unlikely(data_race(dio->error))) { + ret = 0; goto out; }
Signature · 1 line
2.51.0
PATCH 38/385 thermal/of: Fix reference leak in thermal_of_cm_lookup()
In reply to Sasha LevinFrom: Felix Gu <[email protected]>
[ Upstream commit a1fe789a96fe47733c133134fd264cb7ca832395 ]
In thermal_of_cm_lookup(), tr_np is obtained via of_parse_phandle(), but never released.
Use the __free(device_node) cleanup attribute to automatically release the node and fix the leak.
--- drivers/thermal/thermal_of.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/thermal_of.c +2 -2
@@ -299,10 +299,10 @@ static bool thermal_of_cm_lookup(struct device_node *cm_np, struct cooling_spec *c) {for_each_child_of_node_scoped (cm_np, child) { -struct device_node *tr_np;int count, i; - tr_np =of_parse_phandle (child,"trip" ,0 ); + struct device_node *tr_np __free(device_node) = +of_parse_phandle (child,"trip" ,0 );if (tr_np != trip->priv)continue ;
Signature · 1 line
2.51.0
PATCH 39/385 ublk: Validate SQE128 flag before accessing the cmd
In reply to Sasha LevinFrom: Govindarajulu Varadarajan <[email protected]>
[ Upstream commit da7e4b75e50c087d2031a92f6646eb90f7045a67 ]
ublk_ctrl_cmd_dump() accesses (header *)sqe->cmd before IO_URING_F_SQE128 flag check. This could cause out of boundary memory access.
Move the SQE128 flag check earlier in ublk_ctrl_uring_cmd() to return -EINVAL immediately if the flag is not set.
--- drivers/block/ublk_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/ublk_drv.c +3 -3
@@ -3026,10 +3026,10 @@ static int ublk_ctrl_uring_cmd(struct io_uring_cmd *cmd,if (issue_flags &IO_URING_F_NONBLOCK )return -EAGAIN ; -ublk_ctrl_cmd_dump (cmd); -if (!(issue_flags &IO_URING_F_SQE128 )) - goto out; +return -EINVAL ; + +ublk_ctrl_cmd_dump (cmd); ret =ublk_check_cmd_op (cmd_op);if (ret)
Signature · 1 line
2.51.0
PATCH 40/385 Partial revert "x86/xen: fix balloon target initialization for PVH dom0"
In reply to Sasha LevinFrom: Roger Pau Monne <[email protected]>
[ Upstream commit 0949c646d64697428ff6257d52efa5093566868d ]
This partially reverts commit 87af633689ce16ddb166c80f32b120e50b1295de so the current memory target for PV guests is still fetched from start_info->nr_pages, which matches exactly what the toolstack sets the initial memory target to.
Using get_num_physpages() is possible on PV also, but needs adjusting to take into account the ISA hole and the PFN at 0 not considered usable memory despite being populated, and hence would need extra adjustments. Instead of carrying those extra adjustments switch back to the previous code. That leaves Linux with a difference in how current memory target is obtained for HVM vs PV, but that's better than adding extra logic just for PV.
However if switching to start_info->nr_pages for PV domains we need to differentiate between released pages (freed back to the hypervisor) as opposed to pages in the physmap which are not populated to start with. Introduce a new xen_unpopulated_pages to account for papges that have never been populated, and hence in the PV case don't need subtracting.
Message-ID: <[email protected]>
--- arch/x86/xen/enlighten.c | 2 +- drivers/xen/balloon.c | 19 +++++++++++++++---- drivers/xen/unpopulated-alloc.c | 3 +++ include/xen/xen.h | 2 ++ 4 files changed, 21 insertions(+), 5 deletions(-)
arch/x86/xen/enlighten.c +1 -1
@@ -474,7 +474,7 @@ int __init arch_xen_unpopulated_init(struct resource **res)* driver to know how much of the physmap is unpopulated and * set an accurate initial memory target. */ - xen_released_pages += xen_extra_mem[i].n_pfns; + xen_unpopulated_pages += xen_extra_mem[i].n_pfns;/* Zero so region is not also added to the balloon driver. */ xen_extra_mem[i].n_pfns =0 ; }
drivers/xen/balloon.c +15 -4
@@ -720,6 +720,7 @@ static int __init balloon_add_regions(void)static int __init balloon_init (void ) {struct task_struct *task; +unsigned long current_pages;int rc;if (!xen_domain ())
@@ -727,12 +728,18 @@ static int __init balloon_init(void)pr_info ("Initialising balloon driver\n" ); -if (xen_released_pages >=get_num_physpages ()) { -WARN (1 ,"Released pages underflow current target" ); -return -ERANGE ; +if (xen_pv_domain ()) { +if (xen_released_pages >= xen_start_info->nr_pages) + goto underflow; + current_pages =min (xen_start_info->nr_pages - + xen_released_pages, max_pfn); + }else { +if (xen_unpopulated_pages >=get_num_physpages ()) + goto underflow; + current_pages =get_num_physpages () - xen_unpopulated_pages; } - balloon_stats.current_pages =get_num_physpages () - xen_released_pages; + balloon_stats.current_pages = current_pages; balloon_stats.target_pages = balloon_stats.current_pages; balloon_stats.balloon_low =0 ; balloon_stats.balloon_high =0 ;
@@ -763,6 +770,10 @@ static int __init balloon_init(void)xen_balloon_init ();return 0 ; + + underflow: +WARN (1 ,"Released pages underflow current target" ); +return -ERANGE ; }subsys_initcall (balloon_init);
drivers/xen/unpopulated-alloc.c +3 -0
@@ -18,6 +18,9 @@ static unsigned int list_count;static struct resource *target_resource; +/* Pages to subtract from the memory count when setting balloon target. */ +unsigned long xen_unpopulated_pages__initdata ; +/* * If arch is not happy with system "iomem_resource" being used for * the region allocation it can provide it's own view by creating specific
include/xen/xen.h +2 -0
@@ -62,11 +62,13 @@ extern u64 xen_saved_max_mem_size;#endif #ifdef CONFIG_XEN_UNPOPULATED_ALLOC +extern unsigned long xen_unpopulated_pages;int xen_alloc_unpopulated_pages (unsigned int nr_pages,struct page **pages);void xen_free_unpopulated_pages (unsigned int nr_pages,struct page **pages);#include <linux/ioport.h> int arch_xen_unpopulated_init (struct resource **res);#else +#define xen_unpopulated_pages 0UL#include <xen/balloon.h> static inline int xen_alloc_unpopulated_pages (unsigned int nr_pages,struct page **pages)
Signature · 1 line
2.51.0
PATCH 41/385 md/raid1: fix memory leak in raid1_run() if no active rdev
In reply to Sasha LevinFrom: Zheng Qixing <[email protected]>
[ Upstream commit 5fbcf76e0dfe68578ffa2a8a691cc44cf586ae35 ]
When raid1_set_limits() fails or when the array has no active rdev, the allocated memory for conf is not properly freed.
Add raid1_free() call to properly free the conf in error path.
Stable-dep-of: 6abc7d5dcf0e ("md/raid1: fix memory leak in raid1_run()")
--- drivers/md/raid1.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/md/raid1.c +7 -1
@@ -45,6 +45,7 @@static void allow_barrier (struct r1conf *conf,sector_t sector_nr);static void lower_barrier (struct r1conf *conf,sector_t sector_nr); +static void raid1_free (struct mddev *mddev,void *priv);#define RAID_1_10_NAME "raid1"#include "raid1-10.c"
@@ -3245,8 +3246,11 @@ static int raid1_run(struct mddev *mddev)if (!mddev_is_dm (mddev)) { ret =raid1_set_limits (mddev); -if (ret) +if (ret) { +if (!mddev->private) +raid1_free (mddev, conf);return ret; + } } mddev->degraded =0 ;
@@ -3260,6 +3264,8 @@ static int raid1_run(struct mddev *mddev)*/ if (conf->raid_disks - mddev->degraded <1 ) {md_unregister_thread (mddev, &conf->thread); +if (!mddev->private) +raid1_free (mddev, conf);return -EINVAL ; }
Signature · 1 line
2.51.0
PATCH 42/385 md/raid1: fix memory leak in raid1_run()
In reply to Sasha LevinFrom: Zilin Guan <[email protected]>
[ Upstream commit 6abc7d5dcf0ee0f85e16e41c87fbd06231f28753 ]
raid1_run() calls setup_conf() which registers a thread via md_register_thread(). If raid1_set_limits() fails, the previously registered thread is not unregistered, resulting in a memory leak of the md_thread structure and the thread resource itself.
Add md_unregister_thread() to the error path to properly cleanup the thread, which aligns with the error handling logic of other paths in this function.
Compile tested only. Issue found using a prototype static analysis tool and code review.
--- drivers/md/raid1.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/raid1.c +1 -0
@@ -3247,6 +3247,7 @@ static int raid1_run(struct mddev *mddev)if (!mddev_is_dm (mddev)) { ret =raid1_set_limits (mddev);if (ret) { +md_unregister_thread (mddev, &conf->thread);if (!mddev->private)raid1_free (mddev, conf);return ret;
Signature · 1 line
2.51.0
PATCH 43/385 PM: wakeup: Handle empty list in wakeup_sources_walk_start()
In reply to Sasha LevinFrom: Samuel Wu <[email protected]>
[ Upstream commit 75ce02f4bc9a8b8350b6b1b01872467b0cc960cc ]
In the case of an empty wakeup_sources list, wakeup_sources_walk_start() will return an invalid but non-NULL address. This also affects wrappers of the aforementioned function, like for_each_wakeup_source().
Update wakeup_sources_walk_start() to return NULL in case of an empty list.
--- drivers/base/power/wakeup.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/base/power/wakeup.c +1 -3
@@ -280,9 +280,7 @@ EXPORT_SYMBOL_GPL(wakeup_sources_read_unlock);*/ struct wakeup_source *wakeup_sources_walk_start (void ) { -struct list_head *ws_head = &wakeup_sources; - - return list_entry_rcu(ws_head->next, struct wakeup_source, entry); + return list_first_or_null_rcu(&wakeup_sources, struct wakeup_source, entry); }EXPORT_SYMBOL_GPL (wakeup_sources_walk_start);
Signature · 1 line
2.51.0
PATCH 44/385 perf: arm_spe: Properly set hw.state on failures
In reply to Sasha LevinFrom: Leo Yan <[email protected]>
[ Upstream commit 283182c1c239f6873d1a50e9e710c1a699f2256b ]
When arm_spe_pmu_next_off() fails to calculate a valid limit, it returns zero to indicate that tracing should not start. However, the caller arm_spe_perf_aux_output_begin() does not propagate this failure by updating hwc->state, cause the error to be silently ignored by upper layers.
Because hwc->state remains zero after a failure, arm_spe_pmu_start() continues to programs filter registers unnecessarily. The driver still reports success to the perf core, so the core assumes the SPE event was enabled and proceeds to enable other events. This breaks event group semantics: SPE is already stopped while other events in the same group are enabled.
Fix this by updating arm_spe_perf_aux_output_begin() to return a status code indicating success (0) or failure (-EIO). Both the interrupt handler and arm_spe_pmu_start() check the return value and call arm_spe_pmu_stop() to set PERF_HES_STOPPED in hwc->state.
In the interrupt handler, the period (e.g., period_left) needs to be updated, so PERF_EF_UPDATE is passed to arm_spe_pmu_stop(). When the error occurs during event start, the trace unit is not yet enabled, so a flag '0' is used to drain buffer and update state only.
--- drivers/perf/arm_spe_pmu.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/perf/arm_spe_pmu.c +12 -6
@@ -102,6 +102,8 @@ struct arm_spe_pmu {/* Keep track of our dynamic hotplug state */ static enum cpuhp_state arm_spe_pmu_online; +static void arm_spe_pmu_stop (struct perf_event *event,int flags); +enum arm_spe_pmu_buf_fault_action {SPE_PMU_BUF_FAULT_ACT_SPURIOUS ,SPE_PMU_BUF_FAULT_ACT_FATAL ,
@@ -497,8 +499,8 @@ static u64 arm_spe_pmu_next_off(struct perf_output_handle *handle)return limit; } -static void arm_spe_perf_aux_output_begin (struct perf_output_handle *handle, -struct perf_event *event) +static int arm_spe_perf_aux_output_begin (struct perf_output_handle *handle, +struct perf_event *event) {u64 base, limit;struct arm_spe_pmu_buf *buf;
@@ -506,7 +508,6 @@ static void arm_spe_perf_aux_output_begin(struct perf_output_handle *handle,/* Start a new aux session */ buf =perf_aux_output_begin (handle, event);if (!buf) { - event->hw.state |=PERF_HES_STOPPED ;/* * We still need to clear the limit pointer, since the * profiler might only be disabled by virtue of a fault.
@@ -526,6 +527,7 @@ static void arm_spe_perf_aux_output_begin(struct perf_output_handle *handle, out_write_limit:write_sysreg_s (limit,SYS_PMBLIMITR_EL1 ); +return (limit &PMBLIMITR_EL1_E ) ?0 : -EIO ; }static void arm_spe_perf_aux_output_end (struct perf_output_handle *handle)
@@ -665,7 +667,10 @@ static irqreturn_t arm_spe_pmu_irq_handler(int irq, void *dev)* when we get to it. */ if (!(handle->aux_flags &PERF_AUX_FLAG_TRUNCATED )) { -arm_spe_perf_aux_output_begin (handle, event); +if (arm_spe_perf_aux_output_begin (handle, event)) { +arm_spe_pmu_stop (event,PERF_EF_UPDATE ); +break ; + }isb (); }break ;
@@ -760,9 +765,10 @@ static void arm_spe_pmu_start(struct perf_event *event, int flags)struct perf_output_handle *handle =this_cpu_ptr (spe_pmu->handle); hwc->state =0 ; -arm_spe_perf_aux_output_begin (handle, event); -if (hwc->state) +if (arm_spe_perf_aux_output_begin (handle, event)) { +arm_spe_pmu_stop (event,0 );return ; + } reg =arm_spe_event_to_pmsfcr (event);write_sysreg_s (reg,SYS_PMSFCR_EL1 );
Signature · 1 line
2.51.0
PATCH 45/385 cpufreq: intel_pstate: Enable asym capacity only when CPU SMT is not possible
In reply to Sasha LevinFrom: Yaxiong Tian <[email protected]>
[ Upstream commit 1fedbb589448bee9f20bb2ed9c850d1d2cf9963c ]
According to the description in the intel_pstate.rst documentation, Capacity-Aware Scheduling and Energy-Aware Scheduling are only supported on a hybrid processor without SMT. Previously, the system used sched_smt_active() for judgment, which is not a strict condition because users can switch it on or off via /sys at any time.
This could lead to incorrect driver settings in certain scenarios. For example, on a CPU that supports SMT, a user can disable SMT via the nosmt parameter to enable asym capacity, and then re-enable SMT via /sys. In such cases, some settings in the driver would no longer be correct.
To address this issue, replace sched_smt_active() with cpu_smt_possible(), and only enable asym capacity when CPU SMT is not possible.
--- drivers/cpufreq/intel_pstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/intel_pstate.c +1 -1
@@ -1058,7 +1058,7 @@ static void hybrid_init_cpu_capacity_scaling(bool refresh)* the capacity of SMT threads is not deterministic even approximately, * do not do that when SMT is in use. */ -if (hwp_is_hybrid && !sched_smt_active () &&arch_enable_hybrid_capacity_scale ()) { +if (hwp_is_hybrid && !cpu_smt_possible () &&arch_enable_hybrid_capacity_scale ()) {hybrid_refresh_cpu_capacity_scaling ();/* * Disabling ITMT causes sched domains to be rebuilt to disable asym
Signature · 1 line
2.51.0
PATCH 46/385 PM: sleep: wakeirq: harden dev_pm_clear_wake_irq() against races
In reply to Sasha LevinFrom: Gui-Dong Han <[email protected]>
[ Upstream commit 5c9ecd8e6437cd55a38ea4f1e1d19cee8e226cb8 ]
dev_pm_clear_wake_irq() currently uses a dangerous pattern where dev->power.wakeirq is read and checked for NULL outside the lock. If two callers invoke this function concurrently, both might see a valid pointer and proceed. This could result in a double-free when the second caller acquires the lock and tries to release the same object.
Address this by removing the lockless check of dev->power.wakeirq. Instead, acquire dev->power.lock immediately to ensure the check and the subsequent operations are atomic. If dev->power.wakeirq is NULL under the lock, simply unlock and return. This guarantees that concurrent calls cannot race to free the same object.
Based on a quick scan of current users, I did not find an actual bug as drivers seem to rely on their own synchronization. However, since asynchronous usage patterns exist (e.g., in drivers/net/wireless/ti/wlcore), I believe a race is theoretically possible if the API is used less carefully in the future. This change hardens the API to be robust against such cases.
--- drivers/base/power/wakeirq.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/base/power/wakeirq.c +6 -3
@@ -83,13 +83,16 @@ EXPORT_SYMBOL_GPL(dev_pm_set_wake_irq);*/ void dev_pm_clear_wake_irq (struct device *dev) { -struct wake_irq *wirq = dev->power.wakeirq; +struct wake_irq *wirq;unsigned long flags; -if (!wirq) +spin_lock_irqsave (&dev->power.lock, flags); + wirq = dev->power.wakeirq; +if (!wirq) { +spin_unlock_irqrestore (&dev->power.lock, flags);return ; + } -spin_lock_irqsave (&dev->power.lock, flags);device_wakeup_detach_irq (dev); dev->power.wakeirq =NULL ;spin_unlock_irqrestore (&dev->power.lock, flags);
Signature · 1 line
2.51.0
PATCH 47/385 s390/cio: Fix device lifecycle handling in css_alloc_subchannel()
In reply to Sasha LevinFrom: Salah Triki <[email protected]>
[ Upstream commit f65c75b0b9b5a390bc3beadcde0a6fbc3ad118f7 ]
css_alloc_subchannel() calls device_initialize() before setting up the DMA masks. If dma_set_coherent_mask() or dma_set_mask() fails, the error path frees the subchannel structure directly, bypassing the device model reference counting.
Once device_initialize() has been called, the embedded struct device must be released via put_device(), allowing the release callback to free the container structure.
Fix the error path by dropping the initial device reference with put_device() instead of calling kfree() directly.
This ensures correct device lifetime handling and avoids potential use-after-free or double-free issues.
--- drivers/s390/cio/css.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/cio/css.c +1 -1
@@ -236,7 +236,7 @@ struct subchannel *css_alloc_subchannel(struct subchannel_id schid,return sch; err: -kfree (sch); +put_device (&sch->dev);return ERR_PTR (ret); }
Signature · 1 line
2.51.0
PATCH 48/385 perf/x86/core: Do not set bit width for unavailable counters
In reply to Sasha LevinFrom: Sandipan Das <[email protected]>
[ Upstream commit b456a6ba5756b6fb7e651775343e713bd08418e7 ]
Not all x86 processors have fixed counters. It may also be the case that a processor has only fixed counters and no general-purpose counters. Set the bit widths corresponding to each counter type only if such counters are available.
--- arch/x86/events/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/events/core.c +2 -2
@@ -3051,8 +3051,8 @@ void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap) cap->version = x86_pmu.version; cap->num_counters_gp =x86_pmu_num_counters (NULL ); cap->num_counters_fixed =x86_pmu_num_counters_fixed (NULL ); - cap->bit_width_gp = x86_pmu.cntval_bits; - cap->bit_width_fixed = x86_pmu.cntval_bits; + cap->bit_width_gp = cap->num_counters_gp ? x86_pmu.cntval_bits :0 ; + cap->bit_width_fixed = cap->num_counters_fixed ? x86_pmu.cntval_bits :0 ; cap->events_mask = (unsigned int )x86_pmu.events_maskl; cap->events_mask_len = x86_pmu.events_mask_len; cap->pebs_ept = x86_pmu.pebs_ept;
Signature · 1 line
2.51.0
PATCH 49/385 crypto: qat - fix warning on adf_pfvf_pf_proto.c
In reply to Sasha LevinFrom: Giovanni Cabiddu <[email protected]>
[ Upstream commit 994689b8f91b02fdb5f64cba2412cde5ef3084b5 ]
Building the QAT driver with -Wmaybe-uninitialized triggers warnings in qat_common/adf_pfvf_pf_proto.c. Specifically, the variables blk_type, blk_byte, and byte_max may be used uninitialized in handle_blkmsg_req():
make M=drivers/crypto/intel/qat W=1 C=2 "KCFLAGS=-Werror" \
KBUILD_CFLAGS_KERNEL=-Wmaybe-uninitialized \
CFLAGS_MODULE=-Wmaybe-uninitialized ...
warning: ‘byte_max’ may be used uninitialized [-Wmaybe-uninitialized]
warning: ‘blk_type’ may be used uninitialized [-Wmaybe-uninitialized]
warning: ‘blk_byte’ may be used uninitialized [-Wmaybe-uninitialized]
Although the caller of handle_blkmsg_req() always provides a req.type that is handled by the switch, the compiler cannot guarantee this.
Add a default case to the switch statement to handle an invalid req.type.
--- .../crypto/intel/qat/qat_common/adf_pfvf_pf_proto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/crypto/intel/qat/qat_common/adf_pfvf_pf_proto.c +10 -0
@@ -148,6 +148,16 @@ static struct pfvf_message handle_blkmsg_req(struct adf_accel_vf_info *vf_info, blk_byte =FIELD_GET (ADF_VF2PF_SMALL_BLOCK_BYTE_MASK , req.data); byte_max =ADF_VF2PF_SMALL_BLOCK_BYTE_MAX ;break ; +default : +dev_err (&GET_DEV (vf_info->accel_dev), +"Invalid BlockMsg type 0x%.4x received from VF%u\n" , + req.type, vf_info->vf_nr); + resp.type =ADF_PF2VF_MSGTYPE_BLKMSG_RESP ; + resp.data =FIELD_PREP (ADF_PF2VF_BLKMSG_RESP_TYPE_MASK , +ADF_PF2VF_BLKMSG_RESP_TYPE_ERROR ) | +FIELD_PREP (ADF_PF2VF_BLKMSG_RESP_DATA_MASK , +ADF_PF2VF_UNSPECIFIED_ERROR ); +return resp; }/* Is this a request for CRC or data? */
Signature · 1 line
2.51.0
PATCH 50/385 selftests/bpf: veristat: fix printing order in output_stats()
In reply to Sasha LevinFrom: Puranjay Mohan <[email protected]>
[ Upstream commit c286e7e9d1f1f3d90ad11c37e896f582b02d19c4 ]
The order of the variables in the printf() doesn't match the text and therefore veristat prints something like this:
Done. Processed 24 files, 0 programs. Skipped 62 files, 0 programs.
When it should print:
Done. Processed 24 files, 62 programs. Skipped 0 files, 0 programs.
Fix the order of variables in the printf() call.
--- tools/testing/selftests/bpf/veristat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/veristat.c +1 -1
@@ -1424,7 +1424,7 @@ static void output_stats(const struct verif_stats *s, enum resfmt fmt, bool lastif (last && fmt ==RESFMT_TABLE ) {output_header_underlines ();printf ("Done. Processed %d files, %d programs. Skipped %d files, %d programs.\n" , - env.files_processed, env.files_skipped, env.progs_processed, env.progs_skipped); + env.files_processed, env.progs_processed, env.files_skipped, env.progs_skipped); } }
Signature · 1 line
2.51.0
PATCH 51/385 libbpf: Fix OOB read in btf_dump_get_bitfield_value
In reply to Sasha LevinFrom: Varun R Mallya <[email protected]>
[ Upstream commit 5714ca8cba5ed736f3733663c446cbee63a10a64 ]
When dumping bitfield data, btf_dump_get_bitfield_value() reads data based on the underlying type's size (t->size). However, it does not verify that the provided data buffer (data_sz) is large enough to contain these bytes.
If btf_dump__dump_type_data() is called with a buffer smaller than the type's size, this leads to an out-of-bounds read. This was confirmed by AddressSanitizer in the linked issue.
Fix this by ensuring we do not read past the provided data_sz limit.
--- tools/lib/bpf/btf_dump.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/lib/bpf/btf_dump.c +9 -0
@@ -1758,9 +1758,18 @@ static int btf_dump_get_bitfield_value(struct btf_dump *d,__u16 left_shift_bits, right_shift_bits;const __u8 *bytes = data;__u8 nr_copy_bits; +__u8 start_bit, nr_bytes;__u64 num =0 ;int i; +/* Calculate how many bytes cover the bitfield */ + start_bit = bits_offset %8 ; + nr_bytes = (start_bit + bit_sz +7 ) /8 ; + +/* Bound check */ +if (data + nr_bytes > d->typed_dump->data_end) +return -E2BIG ; +/* Maximum supported bitfield size is 64 bits */ if (t->size >8 ) {pr_warn ("unexpected bitfield size %d\n" , t->size);
Signature · 1 line
2.51.0
PATCH 52/385 ARM: VDSO: Patch out __vdso_clock_getres() if unavailable
In reply to Sasha LevinFrom: Thomas Weißschuh <[email protected]>
[ Upstream commit b9fecf0dddfc55cd7d02b0011494da3c613f7cde ]
The vDSO code hides symbols which are non-functional. __vdso_clock_getres() was not added to this list when it got introduced.
--- arch/arm/kernel/vdso.c | 1 + 1 file changed, 1 insertion(+)
arch/arm/kernel/vdso.c +1 -0
@@ -172,6 +172,7 @@ static void __init patch_vdso(void *ehdr)vdso_nullpatch_one (&einfo,"__vdso_gettimeofday" );vdso_nullpatch_one (&einfo,"__vdso_clock_gettime" );vdso_nullpatch_one (&einfo,"__vdso_clock_gettime64" ); +vdso_nullpatch_one (&einfo,"__vdso_clock_getres" ); } }
Signature · 1 line
2.51.0
PATCH 53/385 crypto: cavium - fix dma_free_coherent() size
In reply to Sasha LevinFrom: Thomas Fourier <[email protected]>
[ Upstream commit 941676c30ba5b40a01bed92448f457ce62fd1f07 ]
The size of the buffer in alloc_command_queues() is curr->size + CPT_NEXT_CHUNK_PTR_SIZE, so used that length for dma_free_coherent().
--- drivers/crypto/cavium/cpt/cptvf_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/cavium/cpt/cptvf_main.c +2 -1
@@ -180,7 +180,8 @@ static void free_command_queues(struct cpt_vf *cptvf,hlist_for_each_entry_safe (chunk, node, &cqinfo->queue[i].chead, nextchunk) { -dma_free_coherent (&pdev->dev, chunk->size, +dma_free_coherent (&pdev->dev, + chunk->size +CPT_NEXT_CHUNK_PTR_SIZE , chunk->head, chunk->dma_addr); chunk->head =NULL ;
Signature · 1 line
2.51.0
PATCH 54/385 crypto: octeontx - fix dma_free_coherent() size
In reply to Sasha LevinFrom: Thomas Fourier <[email protected]>
[ Upstream commit 624a6760bf8464965c17c8df10b40b557eaa3002 ]
The size of the buffer in alloc_command_queues() is curr->size + OTX_CPT_NEXT_CHUNK_PTR_SIZE, so used that length for dma_free_coherent().
--- drivers/crypto/marvell/octeontx/otx_cptvf_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/marvell/octeontx/otx_cptvf_main.c +2 -1
@@ -168,7 +168,8 @@ static void free_command_queues(struct otx_cptvf *cptvf, chunk =list_first_entry (&cqinfo->queue[i].chead, struct otx_cpt_cmd_chunk, nextchunk); -dma_free_coherent (&pdev->dev, chunk->size, +dma_free_coherent (&pdev->dev, + chunk->size +OTX_CPT_NEXT_CHUNK_PTR_SIZE , chunk->head, chunk->dma_addr); chunk->head =NULL ;
Signature · 1 line
2.51.0
PATCH 55/385 crypto: hisilicon/zip - adjust the way to obtain the req in the callback function
In reply to Sasha LevinFrom: Chenghai Huang <[email protected]>
[ Upstream commit 19c2475ce1984cf675ebfbbeaa5509b2fb1887d6 ]
In the shared queue design, multiple tfms use same qp, and one qp need to corresponds to multiple qp_ctx. So use tag to obtain the req virtual address. Build a one-to-one relationship between tfm and qp_ctx. finaly remove the old get_tag operation.
--- drivers/crypto/hisilicon/zip/zip_crypto.c | 24 +++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/crypto/hisilicon/zip/zip_crypto.c +9 -15
@@ -39,6 +39,7 @@ enum { HZIP_CTX_Q_NUM }; +#define GET_REQ_FROM_SQE (sqe) ((u64)(sqe)->dw26 | (u64)(sqe)->dw27 << 32)#define COMP_NAME_TO_TYPE (alg_name) \ (!strcmp((alg_name), "deflate") ? HZIP_ALG_TYPE_DEFLATE : 0)
@@ -48,6 +49,7 @@ struct hisi_zip_req {struct hisi_acc_hw_sgl *hw_dst;dma_addr_t dma_src;dma_addr_t dma_dst; +struct hisi_zip_qp_ctx *qp_ctx;u16 req_id; };
@@ -74,7 +76,6 @@ struct hisi_zip_sqe_ops {void (*fill_req_type)(struct hisi_zip_sqe *sqe,u8 req_type);void (*fill_tag)(struct hisi_zip_sqe *sqe,struct hisi_zip_req *req);void (*fill_sqe_type)(struct hisi_zip_sqe *sqe,u8 sqe_type); -u32 (*get_tag)(struct hisi_zip_sqe *sqe);u32 (*get_status)(struct hisi_zip_sqe *sqe);u32 (*get_dstlen)(struct hisi_zip_sqe *sqe); };
@@ -131,6 +132,7 @@ static struct hisi_zip_req *hisi_zip_create_req(struct hisi_zip_qp_ctx *qp_ctx, req_cache = q + req_id; req_cache->req_id = req_id; req_cache->req = req; + req_cache->qp_ctx = qp_ctx;return req_cache; }
@@ -181,7 +183,8 @@ static void hisi_zip_fill_req_type(struct hisi_zip_sqe *sqe, u8 req_type)static void hisi_zip_fill_tag (struct hisi_zip_sqe *sqe,struct hisi_zip_req *req) { - sqe->dw26 = req->req_id; + sqe->dw26 =lower_32_bits ((u64 )req); + sqe->dw27 =upper_32_bits ((u64 )req); }static void hisi_zip_fill_sqe_type (struct hisi_zip_sqe *sqe,u8 sqe_type)
@@ -236,7 +239,7 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx, &req->dma_dst);if (IS_ERR (req->hw_dst)) { ret =PTR_ERR (req->hw_dst); -dev_err (dev,"failed to map the dst buffer to hw slg (%d)!\n" , +dev_err (dev,"failed to map the dst buffer to hw sgl (%d)!\n" , ret); goto err_unmap_input; }
@@ -264,11 +267,6 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,return ret; } -static u32 hisi_zip_get_tag (struct hisi_zip_sqe *sqe) -{ -return sqe->dw26; -} -static u32 hisi_zip_get_status (struct hisi_zip_sqe *sqe) {return sqe->dw3 &HZIP_BD_STATUS_M ;
@@ -281,14 +279,12 @@ static u32 hisi_zip_get_dstlen(struct hisi_zip_sqe *sqe)static void hisi_zip_acomp_cb (struct hisi_qp *qp,void *data) { -struct hisi_zip_qp_ctx *qp_ctx = qp->qp_ctx; +struct hisi_zip_sqe *sqe = data; +struct hisi_zip_req *req = (struct hisi_zip_req *)GET_REQ_FROM_SQE (sqe); +struct hisi_zip_qp_ctx *qp_ctx = req->qp_ctx;const struct hisi_zip_sqe_ops *ops = qp_ctx->ctx->ops;struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx; -struct hisi_zip_req_q *req_q = &qp_ctx->req_q;struct device *dev = &qp->qm->pdev->dev; -struct hisi_zip_sqe *sqe = data; -u32 tag = ops->get_tag (sqe); -struct hisi_zip_req *req = req_q->q + tag;struct acomp_req *acomp_req = req->req;int err =0 ;u32 status;
@@ -392,7 +388,6 @@ static const struct hisi_zip_sqe_ops hisi_zip_ops = { .fill_req_type = hisi_zip_fill_req_type, .fill_tag = hisi_zip_fill_tag, .fill_sqe_type = hisi_zip_fill_sqe_type, - .get_tag = hisi_zip_get_tag, .get_status = hisi_zip_get_status, .get_dstlen = hisi_zip_get_dstlen, };
@@ -580,7 +575,6 @@ static void hisi_zip_acomp_exit(struct crypto_acomp *tfm) {struct hisi_zip_ctx *ctx =crypto_tfm_ctx (&tfm->base); -hisi_zip_set_acomp_cb (ctx,NULL );hisi_zip_release_sgl_pool (ctx);hisi_zip_release_req_q (ctx);hisi_zip_ctx_exit (ctx);
Signature · 1 line
2.51.0
PATCH 56/385 crypto: hisilicon/sec2 - support skcipher/aead fallback for hardware queue unavailable
In reply to Sasha LevinFrom: Qi Tao <[email protected]>
[ Upstream commit e7507439628052363500d717caffb5c2241854dc ]
When all hardware queues are busy and no shareable queue, new processes fail to apply for queues. To avoid affecting tasks, support fallback mechanism when hardware queues are unavailable.
--- drivers/crypto/hisilicon/sec2/sec_crypto.c | 62 ++++++++++++++++------ 1 file changed, 47 insertions(+), 15 deletions(-)
drivers/crypto/hisilicon/sec2/sec_crypto.c +47 -15
@@ -591,10 +591,8 @@ static int sec_ctx_base_init(struct sec_ctx *ctx)int i, ret; ctx->qps =sec_create_qps (); -if (!ctx->qps) { -pr_err ("Can not create sec qps!\n" ); +if (!ctx->qps)return -ENODEV ; - } sec = container_of(ctx->qps[0]->qm, struct sec_dev, qm); ctx->sec = sec;
@@ -633,6 +631,9 @@ static void sec_ctx_base_uninit(struct sec_ctx *ctx) {int i; +if (!ctx->qps) +return ; +for (i =0 ; i < ctx->sec->ctx_q_num; i++)sec_release_qp_ctx (ctx, &ctx->qp_ctx[i]);
@@ -644,6 +645,9 @@ static int sec_cipher_init(struct sec_ctx *ctx) {struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; +if (!ctx->qps) +return 0 ; + c_ctx->c_key =dma_alloc_coherent (ctx->dev,SEC_MAX_KEY_SIZE , &c_ctx->c_key_dma,GFP_KERNEL );if (!c_ctx->c_key)
@@ -656,6 +660,9 @@ static void sec_cipher_uninit(struct sec_ctx *ctx) {struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; +if (!ctx->qps) +return ; +memzero_explicit (c_ctx->c_key,SEC_MAX_KEY_SIZE );dma_free_coherent (ctx->dev,SEC_MAX_KEY_SIZE , c_ctx->c_key, c_ctx->c_key_dma);
@@ -677,6 +684,9 @@ static void sec_auth_uninit(struct sec_ctx *ctx) {struct sec_auth_ctx *a_ctx = &ctx->a_ctx; +if (!ctx->qps) +return ; +memzero_explicit (a_ctx->a_key,SEC_MAX_AKEY_SIZE );dma_free_coherent (ctx->dev,SEC_MAX_AKEY_SIZE , a_ctx->a_key, a_ctx->a_key_dma);
@@ -714,7 +724,7 @@ static int sec_skcipher_init(struct crypto_skcipher *tfm) } ret =sec_ctx_base_init (ctx); -if (ret) +if (ret && ret != -ENODEV )return ret; ret =sec_cipher_init (ctx);
@@ -823,6 +833,9 @@ static int sec_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,struct device *dev = ctx->dev;int ret; +if (!ctx->qps) + goto set_soft_key; +if (c_mode ==SEC_CMODE_XTS ) { ret =xts_verify_key (tfm, key, keylen);if (ret) {
@@ -853,13 +866,14 @@ static int sec_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key, }memcpy (c_ctx->c_key, key, keylen); -if (c_ctx->fbtfm) { - ret =crypto_sync_skcipher_setkey (c_ctx->fbtfm, key, keylen); -if (ret) { -dev_err (dev,"failed to set fallback skcipher key!\n" ); -return ret; - } + +set_soft_key: + ret =crypto_sync_skcipher_setkey (c_ctx->fbtfm, key, keylen); +if (ret) { +dev_err (dev,"failed to set fallback skcipher key!\n" ); +return ret; } +return 0 ; }
@@ -1135,6 +1149,9 @@ static int sec_aead_setkey(struct crypto_aead *tfm, const u8 *key,struct crypto_authenc_keys keys;int ret; +if (!ctx->qps) +return sec_aead_fallback_setkey (a_ctx, tfm, key, keylen); + ctx->a_ctx.a_alg = a_alg; ctx->c_ctx.c_alg = c_alg; c_ctx->c_mode = c_mode;
@@ -1829,6 +1846,9 @@ static int sec_skcipher_ctx_init(struct crypto_skcipher *tfm)if (ret)return ret; +if (!ctx->qps) +return 0 ; +if (ctx->sec->qm.ver <QM_HW_V3 ) { ctx->type_supported =SEC_BD_TYPE2 ; ctx->req_op = &sec_skcipher_req_ops;
@@ -1837,7 +1857,7 @@ static int sec_skcipher_ctx_init(struct crypto_skcipher *tfm) ctx->req_op = &sec_skcipher_req_ops_v3; } -return ret; +return 0 ; }static void sec_skcipher_ctx_exit (struct crypto_skcipher *tfm)
@@ -1905,7 +1925,7 @@ static int sec_aead_ctx_init(struct crypto_aead *tfm, const char *hash_name)int ret; ret =sec_aead_init (tfm); -if (ret) { +if (ret && ret != -ENODEV ) {pr_err ("hisi_sec2: aead init error!\n" );return ret; }
@@ -1947,7 +1967,7 @@ static int sec_aead_xcm_ctx_init(struct crypto_aead *tfm)int ret; ret =sec_aead_init (tfm); -if (ret) { +if (ret && ret != -ENODEV ) {dev_err (ctx->dev,"hisi_sec2: aead xcm init error!\n" );return ret; }
@@ -2092,6 +2112,9 @@ static int sec_skcipher_crypto(struct skcipher_request *sk_req, bool encrypt)bool need_fallback = false;int ret; +if (!ctx->qps) + goto soft_crypto; +if (!sk_req->cryptlen) {if (ctx->c_ctx.c_mode ==SEC_CMODE_XTS )return -EINVAL ;
@@ -2108,9 +2131,12 @@ static int sec_skcipher_crypto(struct skcipher_request *sk_req, bool encrypt)return -EINVAL ;if (unlikely (ctx->c_ctx.fallback || need_fallback)) -return sec_skcipher_soft_crypto (ctx, sk_req, encrypt); + goto soft_crypto;return ctx->req_op->process (ctx, req); + +soft_crypto: +return sec_skcipher_soft_crypto (ctx, sk_req, encrypt); }static int sec_skcipher_encrypt (struct skcipher_request *sk_req)
@@ -2315,6 +2341,9 @@ static int sec_aead_crypto(struct aead_request *a_req, bool encrypt)bool need_fallback = false;int ret; +if (!ctx->qps) + goto soft_crypto; + req->flag = a_req->base.flags; req->aead_req.aead_req = a_req; req->c_req.encrypt = encrypt;
@@ -2324,11 +2353,14 @@ static int sec_aead_crypto(struct aead_request *a_req, bool encrypt) ret =sec_aead_param_check (ctx, req, &need_fallback);if (unlikely (ret)) {if (need_fallback) -return sec_aead_soft_crypto (ctx, a_req, encrypt); + goto soft_crypto;return -EINVAL ; }return ctx->req_op->process (ctx, req); + +soft_crypto: +return sec_aead_soft_crypto (ctx, a_req, encrypt); }static int sec_aead_encrypt (struct aead_request *a_req)
Signature · 1 line
2.51.0
PATCH 57/385 bpf: Preserve id of register in sync_linked_regs()
In reply to Sasha LevinFrom: Puranjay Mohan <[email protected]>
[ Upstream commit af9e89d8dd39530c8bd14c33ddf6b502df1071b6 ]
sync_linked_regs() copies the id of known_reg to reg when propagating bounds of known_reg to reg using the off of known_reg, but when known_reg was linked to reg like:
known_reg = reg ; both known_reg and reg get same idknown_reg += 4 ; known_reg gets off = 4, and its id gets BPF_ADD_CONST
now when a call to sync_linked_regs() happens, let's say with the following:
if known_reg >= 10 goto pc+2
known_reg's new bounds are propagated to reg but now reg gets BPF_ADD_CONST from the copy.
This means if another link to reg is created like:
another_reg = reg ; another_reg should get the id of reg but
assign_scalar_id_before_mov() sees BPF_ADD_CONST on reg and assigns a new id to it.
As reg has a new id now, known_reg's link to reg is broken. If we find new bounds for known_reg, they will not be propagated to reg.
This can be seen in the selftest added in the next commit:
0: (85) call bpf_get_prandom_u32#7 ; R0=scalar() 1: (57) r0 &= 255 ; R0=scalar(smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff)) 2: (bf) r1 = r0 ; R0=scalar(id=1,smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff)) R1=scalar(id=1,smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff)) 3: (07) r1 += 4 ; R1=scalar(id=1+4,smin=umin=smin32=umin32=4,smax=umax=smax32=umax32=259,var_off=(0x0; 0x1ff)) 4: (a5) if r1 < 0xa goto pc+4 ; R1=scalar(id=1+4,smin=umin=smin32=umin32=10,smax=umax=smax32=umax32=259,var_off=(0x0; 0x1ff)) 5: (bf) r2 = r0 ; R0=scalar(id=2,smin=umin=smin32=umin32=6,smax=umax=smax32=umax32=255) R2=scalar(id=2,smin=umin=smin32=umin32=6,smax=umax=smax32=umax32=255) 6: (a5) if r1 < 0xe goto pc+2 ; R1=scalar(id=1+4,smin=umin=smin32=umin32=14,smax=umax=smax32=umax32=259,var_off=(0x0; 0x1ff)) 7: (35) if r0 >= 0xa goto pc+1 ; R0=scalar(id=2,smin=umin=smin32=umin32=6,smax=umax=smax32=umax32=9,var_off=(0x0; 0xf))
8: (37) r0 /= 0
div by zero
When 4 is verified, r1's bounds are propagated to r0 but r0 also gets BPF_ADD_CONST (bug).
When 5 is verified, r0 gets a new id (2) and its link with r1 is broken.
After 6 we know r1 has bounds [14, 259] and therefore r0 should have bounds [10, 255], therefore the branch at 7 is always taken. But because r0's id was changed to 2, r1's new bounds are not propagated to r0. The verifier still thinks r0 has bounds [6, 255] before 7 and execution can reach div by zero.
Fix this by preserving id in sync_linked_regs() like off and subreg_def.
--- kernel/bpf/verifier.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +3 -1
@@ -15478,6 +15478,7 @@ static void sync_linked_regs(struct bpf_verifier_state *vstate, struct bpf_reg_s }else {s32 saved_subreg_def = reg->subreg_def;s32 saved_off = reg->off; +u32 saved_id = reg->id; fake_reg.type =SCALAR_VALUE ;__mark_reg_known (&fake_reg, (s32 )reg->off - (s32 )known_reg->off);
@@ -15485,10 +15486,11 @@ static void sync_linked_regs(struct bpf_verifier_state *vstate, struct bpf_reg_s/* reg = known_reg; reg += delta */ copy_register_state (reg, known_reg);/* -* Must preserve off, id and add_const flag, +* Must preserve off, id and subreg_def flag, * otherwise another sync_linked_regs() will be incorrect. */ reg->off = saved_off; + reg->id = saved_id; reg->subreg_def = saved_subreg_def;scalar32_min_max_add (reg, &fake_reg);
Signature · 1 line
2.51.0
PATCH 58/385 selftests/bpf: Fix resource leak in serial_test_wq on attach failure
In reply to Sasha LevinFrom: Kery Qi <[email protected]>
[ Upstream commit a32ae2658471dd87a2f7a438388ed7d9a5767212 ]
When wq__attach() fails, serial_test_wq() returns early without calling wq__destroy(), leaking the skeleton resources allocated by wq__open_and_load(). This causes ASAN leak reports in selftests runs.
Fix this by jumping to a common clean_up label that calls wq__destroy() on all exit paths after successful open_and_load.
Note that the early return after wq__open_and_load() failure is correct and doesn't need fixing, since that function returns NULL on failure (after internally cleaning up any partial allocations).
--- tools/testing/selftests/bpf/prog_tests/wq.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/wq.c +3 -2
@@ -16,12 +16,12 @@ void serial_test_wq(void)/* re-run the success test to check if the timer was actually executed */ wq_skel =wq__open_and_load (); -if (!ASSERT_OK_PTR (wq_skel,"wq_skel_load" )) +if (!ASSERT_OK_PTR (wq_skel,"wq__open_and_load" ))return ; err =wq__attach (wq_skel);if (!ASSERT_OK (err,"wq_attach" )) -return ; + goto clean_up; prog_fd =bpf_program__fd (wq_skel->progs.test_syscall_array_sleepable); err =bpf_prog_test_run_opts (prog_fd, &topts);
@@ -31,6 +31,7 @@ void serial_test_wq(void)usleep (50 );/* 10 usecs should be enough, but give it extra */ ASSERT_EQ (wq_skel->bss->ok_sleepable, (1 <<1 ),"ok_sleepable" ); +clean_up:wq__destroy (wq_skel); }
Signature · 1 line
2.51.0
PATCH 59/385 hrtimer: Fix trace oddity
In reply to Sasha LevinFrom: Thomas Gleixner <[email protected]>
[ Upstream commit 5d6446f409da00e5a389125ddb5ce09f5bc404c9 ]
It turns out that __run_hrtimer() will trace like:
<idle>-0 [032] d.h2. 20705.474563: hrtimer_cancel: hrtimer=0xff2db8f77f8226e8
<idle>-0 [032] d.h1. 20705.474563: hrtimer_expire_entry: hrtimer=0xff2db8f77f8226e8 now=20699452001850 function=tick_nohz_handler/0x0Which is a bit nonsensical, the timer doesn't get canceled on expiration. The cause is the use of the incorrect debug helper.
--- kernel/time/hrtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/hrtimer.c +1 -1
@@ -1714,7 +1714,7 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base,lockdep_assert_held (&cpu_base->lock); -debug_deactivate (timer); +debug_hrtimer_deactivate (timer); base->running = timer;/*
Signature · 1 line
2.51.0
PATCH 60/385 crypto: ccp - Ensure implicit SEV/SNP init and shutdown in ioctls
In reply to Sasha LevinFrom: Ashish Kalra <[email protected]>
[ Upstream commit ceac7fb89e8da465aec3ac3c20477f912f5c3a6c ]
Modify the behavior of implicit SEV initialization in some of the SEV ioctls to do both SEV initialization and shutdown and add implicit SNP initialization and shutdown to some of the SNP ioctls so that the change of SEV/SNP platform initialization not being done during PSP driver probe time does not break userspace tools such as sevtool, etc.
Prior to this patch, SEV has always been initialized before these ioctls as SEV initialization is done as part of PSP module probe, but now with SEV initialization being moved to KVM module load instead of PSP driver probe, the implied SEV INIT actually makes sense and gets used and additionally to maintain SEV platform state consistency before and after the ioctl SEV shutdown needs to be done after the firmware call.
It is important to do SEV Shutdown here with the SEV/SNP initialization moving to KVM, an implicit SEV INIT here as part of the SEV ioctls not followed with SEV Shutdown will cause SEV to remain in INIT state and then a future SNP INIT in KVM module load will fail.
Also ensure that for these SEV ioctls both implicit SNP and SEV INIT is done followed by both SEV and SNP shutdown as RMP table must be initialized before calling SEV INIT if SNP host support is enabled.
Similarly, prior to this patch, SNP has always been initialized before these ioctls as SNP initialization is done as part of PSP module probe, therefore, to keep a consistent behavior, SNP init needs to be done here implicitly as part of these ioctls followed with SNP shutdown before returning from the ioctl to maintain the consistent platform state before and after the ioctl.
Stable-dep-of: dc8ccab15081 ("crypto: ccp - narrow scope of snp_range_list")
--- drivers/crypto/ccp/sev-dev.c | 142 +++++++++++++++++++++++++++++------ 1 file changed, 119 insertions(+), 23 deletions(-)
drivers/crypto/ccp/sev-dev.c +119 -23
@@ -110,6 +110,8 @@ static void *sev_init_ex_buffer;*/ static struct sev_data_range_list *snp_range_list; +static void __sev_firmware_shutdown (struct sev_device *sev,bool panic); +static inline bool sev_version_greater_or_equal (u8 maj,u8 min) {struct sev_device *sev = psp_master->sev_data;
@@ -1399,6 +1401,37 @@ static int sev_get_platform_state(int *state, int *error)return rc; } +static int sev_move_to_init_state (struct sev_issue_cmd *argp,bool *shutdown_required) +{ +struct sev_platform_init_args init_args = {0 }; +int rc; + + rc =_sev_platform_init_locked (&init_args); +if (rc) { + argp->error =SEV_RET_INVALID_PLATFORM_STATE ; +return rc; + } + + *shutdown_required = true; + +return 0 ; +} + +static int snp_move_to_init_state (struct sev_issue_cmd *argp,bool *shutdown_required) +{ +int error, rc; + + rc =__sev_snp_init_locked (&error); +if (rc) { + argp->error =SEV_RET_INVALID_PLATFORM_STATE ; +return rc; + } + + *shutdown_required = true; + +return 0 ; +} +static int sev_ioctl_do_reset (struct sev_issue_cmd *argp,bool writable) {int state, rc;
@@ -1451,24 +1484,31 @@ static int sev_ioctl_do_platform_status(struct sev_issue_cmd *argp)static int sev_ioctl_do_pek_pdh_gen (int cmd,struct sev_issue_cmd *argp,bool writable) {struct sev_device *sev = psp_master->sev_data; +bool shutdown_required = false;int rc;if (!writable)return -EPERM ;if (sev->state ==SEV_STATE_UNINIT ) { - rc =__sev_platform_init_locked (&argp->error); + rc =sev_move_to_init_state (argp, &shutdown_required);if (rc)return rc; } -return __sev_do_cmd_locked (cmd,NULL , &argp->error); + rc =__sev_do_cmd_locked (cmd,NULL , &argp->error); + +if (shutdown_required) +__sev_firmware_shutdown (sev, false); + +return rc; }static int sev_ioctl_do_pek_csr (struct sev_issue_cmd *argp,bool writable) {struct sev_device *sev = psp_master->sev_data;struct sev_user_data_pek_csr input; +bool shutdown_required = false;struct sev_data_pek_csr data;void __user *input_address;void *blob =NULL ;
@@ -1500,7 +1540,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) cmd:if (sev->state ==SEV_STATE_UNINIT ) { - ret =__sev_platform_init_locked (&argp->error); + ret =sev_move_to_init_state (argp, &shutdown_required);if (ret) goto e_free_blob; }
@@ -1521,6 +1561,9 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) } e_free_blob: +if (shutdown_required) +__sev_firmware_shutdown (sev, false); +kfree (blob);return ret; }
@@ -1736,6 +1779,7 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable)struct sev_device *sev = psp_master->sev_data;struct sev_user_data_pek_cert_import input;struct sev_data_pek_cert_import data; +bool shutdown_required = false;void *pek_blob, *oca_blob;int ret;
@@ -1766,7 +1810,7 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable)/* If platform is not in INIT state then transition it to INIT */ if (sev->state !=SEV_STATE_INIT ) { - ret =__sev_platform_init_locked (&argp->error); + ret =sev_move_to_init_state (argp, &shutdown_required);if (ret) goto e_free_oca; }
@@ -1774,6 +1818,9 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable) ret =__sev_do_cmd_locked (SEV_CMD_PEK_CERT_IMPORT , &data, &argp->error); e_free_oca: +if (shutdown_required) +__sev_firmware_shutdown (sev, false); +kfree (oca_blob); e_free_pek:kfree (pek_blob);
@@ -1890,18 +1937,9 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)struct sev_data_pdh_cert_export data;void __user *input_cert_chain_address;void __user *input_pdh_cert_address; +bool shutdown_required = false;int ret; -/* If platform is not in INIT state then transition it to INIT. */ -if (sev->state !=SEV_STATE_INIT ) { -if (!writable) -return -EPERM ; - - ret =__sev_platform_init_locked (&argp->error); -if (ret) -return ret; - } -if (copy_from_user (&input, (void __user *)argp->data,sizeof (input)))return -EFAULT ;
@@ -1941,6 +1979,17 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) data.cert_chain_len = input.cert_chain_len; cmd: +/* If platform is not in INIT state then transition it to INIT. */ +if (sev->state !=SEV_STATE_INIT ) { +if (!writable) { + ret = -EPERM ; + goto e_free_cert; + } + ret =sev_move_to_init_state (argp, &shutdown_required); +if (ret) + goto e_free_cert; + } + ret =__sev_do_cmd_locked (SEV_CMD_PDH_CERT_EXPORT , &data, &argp->error);/* If we query the length, FW responded with expected data. */
@@ -1967,6 +2016,9 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) } e_free_cert: +if (shutdown_required) +__sev_firmware_shutdown (sev, false); +kfree (cert_blob); e_free_pdh:kfree (pdh_blob);
@@ -1976,12 +2028,13 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)static int sev_ioctl_do_snp_platform_status (struct sev_issue_cmd *argp) {struct sev_device *sev = psp_master->sev_data; +bool shutdown_required = false;struct sev_data_snp_addr buf;struct page *status_page; +int ret, error;void *data; -int ret; -if (!sev->snp_initialized || !argp->data) +if (!argp->data)return -EINVAL ; status_page =alloc_page (GFP_KERNEL_ACCOUNT );
@@ -1990,6 +2043,12 @@ static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp) data =page_address (status_page); +if (!sev->snp_initialized) { + ret =snp_move_to_init_state (argp, &shutdown_required); +if (ret) + goto cleanup; + } +/* * Firmware expects status page to be in firmware-owned state, otherwise * it will report firmware error code INVALID_PAGE_STATE (0x1A).
@@ -2018,6 +2077,9 @@ static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp) ret = -EFAULT ; cleanup: +if (shutdown_required) +__sev_snp_shutdown_locked (&error, false); +__free_pages (status_page,0 );return ret; }
@@ -2026,21 +2088,33 @@ static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp) {struct sev_device *sev = psp_master->sev_data;struct sev_data_snp_commit buf; +bool shutdown_required = false; +int ret, error; -if (!sev->snp_initialized) -return -EINVAL ; +if (!sev->snp_initialized) { + ret =snp_move_to_init_state (argp, &shutdown_required); +if (ret) +return ret; + } buf.len =sizeof (buf); -return __sev_do_cmd_locked (SEV_CMD_SNP_COMMIT , &buf, &argp->error); + ret =__sev_do_cmd_locked (SEV_CMD_SNP_COMMIT , &buf, &argp->error); + +if (shutdown_required) +__sev_snp_shutdown_locked (&error, false); + +return ret; }static int sev_ioctl_do_snp_set_config (struct sev_issue_cmd *argp,bool writable) {struct sev_device *sev = psp_master->sev_data;struct sev_user_data_snp_config config; +bool shutdown_required = false; +int ret, error; -if (!sev->snp_initialized || !argp->data) +if (!argp->data)return -EINVAL ;if (!writable)
@@ -2049,17 +2123,29 @@ static int sev_ioctl_do_snp_set_config(struct sev_issue_cmd *argp, bool writableif (copy_from_user (&config, (void __user *)argp->data,sizeof (config)))return -EFAULT ; -return __sev_do_cmd_locked (SEV_CMD_SNP_CONFIG , &config, &argp->error); +if (!sev->snp_initialized) { + ret =snp_move_to_init_state (argp, &shutdown_required); +if (ret) +return ret; + } + + ret =__sev_do_cmd_locked (SEV_CMD_SNP_CONFIG , &config, &argp->error); + +if (shutdown_required) +__sev_snp_shutdown_locked (&error, false); + +return ret; }static int sev_ioctl_do_snp_vlek_load (struct sev_issue_cmd *argp,bool writable) {struct sev_device *sev = psp_master->sev_data;struct sev_user_data_snp_vlek_load input; +bool shutdown_required = false; +int ret, error;void *blob; -int ret; -if (!sev->snp_initialized || !argp->data) +if (!argp->data)return -EINVAL ;if (!writable)
@@ -2078,8 +2164,18 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable) input.vlek_wrapped_address =__psp_pa (blob); +if (!sev->snp_initialized) { + ret =snp_move_to_init_state (argp, &shutdown_required); +if (ret) + goto cleanup; + } + ret =__sev_do_cmd_locked (SEV_CMD_SNP_VLEK_LOAD , &input, &argp->error); +if (shutdown_required) +__sev_snp_shutdown_locked (&error, false); + +cleanup:kfree (blob);return ret;
Signature · 1 line
2.51.0
PATCH 61/385 crypto: ccp - narrow scope of snp_range_list
In reply to Sasha LevinFrom: "Tycho Andersen (AMD)" <[email protected]>
[ Upstream commit dc8ccab15081efc4f2c5a9fc7b209cd641d29177 ]
snp_range_list is only used in __sev_snp_init_locked() in the SNP_INIT_EX case, move the declaration there and add a __free() cleanup helper for it instead of waiting until shutdown.
--- drivers/crypto/ccp/sev-dev.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/crypto/ccp/sev-dev.c +1 -12
@@ -103,13 +103,6 @@ static size_t sev_es_tmr_size = SEV_TMR_SIZE;#define NV_LENGTH (32 * 1024)static void *sev_init_ex_buffer; -/* -* SEV_DATA_RANGE_LIST: -* Array containing range of pages that firmware transitions to HV-fixed -* page state. -*/ -static struct sev_data_range_list *snp_range_list; -static void __sev_firmware_shutdown (struct sev_device *sev,bool panic);static inline bool sev_version_greater_or_equal (u8 maj,u8 min)
@@ -1098,6 +1091,7 @@ static int snp_filter_reserved_mem_regions(struct resource *rs, void *arg)static int __sev_snp_init_locked (int *error) { + struct sev_data_range_list *snp_range_list __free(kfree) = NULL;struct psp_device *psp = psp_master;struct sev_data_snp_init_ex data;struct sev_device *sev;
@@ -2430,11 +2424,6 @@ static void __sev_firmware_shutdown(struct sev_device *sev, bool panic) sev_init_ex_buffer =NULL ; } -if (snp_range_list) { -kfree (snp_range_list); - snp_range_list =NULL ; - } -__sev_snp_shutdown_locked (&error, panic); }
Signature · 1 line
2.51.0
PATCH 62/385 bpf, sockmap: Fix incorrect copied_seq calculation
In reply to Sasha LevinFrom: Jiayuan Chen <[email protected]>
[ Upstream commit b40cc5adaa80e1471095a62d78233b611d7a558c ]
A socket using sockmap has its own independent receive queue: ingress_msg. This queue may contain data from its own protocol stack or from other sockets.
The issue is that when reading from ingress_msg, we update tp->copied_seq by default. However, if the data is not from its own protocol stack, tcp->rcv_nxt is not increased. Later, if we convert this socket to a native socket, reading from this socket may fail because copied_seq might be significantly larger than rcv_nxt.
This fix also addresses the syzkaller-reported bug referenced in the Closes tag.
This patch marks the skmsg objects in ingress_msg. When reading, we update copied_seq only if the data is from its own protocol stack.
FD1:read()
-- FD1->copied_seq++
| [read data]
|
[enqueue data] v
[sockmap] -> ingress to self -> ingress_msg queue
FD1 native stack ------> ^
-- FD1->rcv_nxt++ -> redirect to other | [enqueue data]
| | | ingress to FD1
v ^
... | [sockmap]
FD2 native stack
--- include/linux/skmsg.h | 2 ++ net/core/skmsg.c | 27 ++++++++++++++++++++++++--- net/ipv4/tcp_bpf.c | 5 +++-- 3 files changed, 29 insertions(+), 5 deletions(-)
include/linux/skmsg.h +2 -0
@@ -141,6 +141,8 @@ int sk_msg_memcopy_from_iter(struct sock *sk, struct iov_iter *from, struct sk_msg *msg, u32 bytes);int sk_msg_recvmsg (struct sock *sk,struct sk_psock *psock,struct msghdr *msg,int len,int flags); +int __sk_msg_recvmsg (struct sock *sk,struct sk_psock *psock,struct msghdr *msg, +int len,int flags,int *copied_from_self);bool sk_msg_is_readable (struct sock *sk);static inline void sk_msg_check_to_free (struct sk_msg *msg,u32 i,u32 bytes)
net/core/skmsg.c +24 -3
@@ -408,22 +408,26 @@ int sk_msg_memcopy_from_iter(struct sock *sk, struct iov_iter *from, }EXPORT_SYMBOL_GPL (sk_msg_memcopy_from_iter); -/* Receive sk_msg from psock->ingress_msg to @msg. */ -int sk_msg_recvmsg (struct sock *sk,struct sk_psock *psock,struct msghdr *msg, -int len,int flags) +int __sk_msg_recvmsg (struct sock *sk,struct sk_psock *psock,struct msghdr *msg, +int len,int flags,int *copied_from_self) {struct iov_iter *iter = &msg->msg_iter;int peek = flags &MSG_PEEK ;struct sk_msg *msg_rx;int i, copied =0 ; +bool from_self; msg_rx =sk_psock_peek_msg (psock); +if (copied_from_self) + *copied_from_self =0 ; +while (copied != len) {struct scatterlist *sge;if (unlikely (!msg_rx))break ; + from_self = msg_rx->sk == sk; i = msg_rx->sg.start; do { struct page *page;
@@ -442,6 +446,9 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, } copied += copy; +if (from_self && copied_from_self) + *copied_from_self += copy; +if (likely (!peek)) { sge->offset += copy; sge->length -= copy;
@@ -486,6 +493,13 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, out:return copied; } + +/* Receive sk_msg from psock->ingress_msg to @msg. */ +int sk_msg_recvmsg (struct sock *sk,struct sk_psock *psock,struct msghdr *msg, +int len,int flags) +{ +return __sk_msg_recvmsg (sk, psock, msg, len, flags,NULL ); +}EXPORT_SYMBOL_GPL (sk_msg_recvmsg);bool sk_msg_is_readable (struct sock *sk)
@@ -615,6 +629,12 @@ static int sk_psock_skb_ingress_self(struct sk_psock *psock, struct sk_buff *skbif (unlikely (!msg))return -EAGAIN ;skb_set_owner_r (skb, sk); + +/* This is used in tcp_bpf_recvmsg_parser() to determine whether the +* data originates from the socket's own protocol stack. No need to +* refcount sk because msg's lifetime is bound to sk via the ingress_msg. +*/ + msg->sk = sk; err =sk_psock_skb_ingress_enqueue (skb, off, len, psock, sk, msg, take_ref);if (err <0 )kfree (msg);
@@ -908,6 +928,7 @@ int sk_psock_msg_verdict(struct sock *sk, struct sk_psock *psock,sk_msg_compute_data_pointers (msg); msg->sk = sk; ret =bpf_prog_run_pin_on_cpu (prog, msg); + msg->sk =NULL ; ret =sk_psock_map_verd (ret, msg->sk_redir); psock->apply_bytes = msg->apply_bytes;if (ret == __SK_REDIRECT) {
net/ipv4/tcp_bpf.c +3 -2
@@ -226,6 +226,7 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,int peek = flags &MSG_PEEK ;struct sk_psock *psock;struct tcp_sock *tcp; +int copied_from_self =0 ;int copied =0 ;u32 seq;
@@ -262,7 +263,7 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk, } msg_bytes_ready: - copied =sk_msg_recvmsg (sk, psock, msg, len, flags); + copied =__sk_msg_recvmsg (sk, psock, msg, len, flags, &copied_from_self);/* The typical case for EFAULT is the socket was gracefully * shutdown with a FIN pkt. So check here the other case is * some error on copy_page_to_iter which would be unexpected.
@@ -277,7 +278,7 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk, goto out; } } - seq += copied; + seq += copied_from_self;if (!copied) {long timeo;int data;
Signature · 1 line
2.51.0
PATCH 63/385 bpf, sockmap: Fix FIONREAD for sockmap
In reply to Sasha LevinFrom: Jiayuan Chen <[email protected]>
[ Upstream commit 929e30f9312514902133c45e51c79088421ab084 ]
A socket using sockmap has its own independent receive queue: ingress_msg. This queue may contain data from its own protocol stack or from other sockets.
Therefore, for sockmap, relying solely on copied_seq and rcv_nxt to calculate FIONREAD is not enough.
This patch adds a new msg_tot_len field in the psock structure to record the data length in ingress_msg. Additionally, we implement new ioctl interfaces for TCP and UDP to intercept FIONREAD operations.
Note that we intentionally do not include sk_receive_queue data in the FIONREAD result. Data in sk_receive_queue has not yet been processed by the BPF verdict program, and may be redirected to other sockets or dropped. Including it would create semantic ambiguity since this data may never be readable by the user.
Unix and VSOCK sockets have similar issues, but fixing them is outside the scope of this patch as it would require more intrusive changes.
Previous work by John Fastabend made some efforts towards FIONREAD support:
commit e5c6de5fa025 ("bpf, sockmap: Incorrectly handling copied_seq") Although the current patch is based on the previous work by John Fastabend, it is acceptable for our Fixes tag to point to the same commit.
FD1:read()
-- FD1->copied_seq++
| [read data]
|
[enqueue data] v
[sockmap] -> ingress to self -> ingress_msg queue
FD1 native stack ------> ^
-- FD1->rcv_nxt++ -> redirect to other | [enqueue data]
| | | ingress to FD1
v ^
... | [sockmap]
FD2 native stack
--- include/linux/skmsg.h | 68 +++++++++++++++++++++++++++++++++++++++++-- net/core/skmsg.c | 3 ++ net/ipv4/tcp_bpf.c | 20 +++++++++++++ net/ipv4/udp_bpf.c | 23 ++++++++++++--- 4 files changed, 108 insertions(+), 6 deletions(-)
include/linux/skmsg.h +66 -2
@@ -97,6 +97,8 @@ struct sk_psock {struct sk_buff_head ingress_skb;struct list_head ingress_msg;spinlock_t ingress_lock; +/** @msg_tot_len: Total bytes queued in ingress_msg list. */ +u32 msg_tot_len;unsigned long state;struct list_head link;spinlock_t link_lock;
@@ -321,6 +323,27 @@ static inline void sock_drop(struct sock *sk, struct sk_buff *skb)kfree_skb (skb); } +static inline u32 sk_psock_get_msg_len_nolock (struct sk_psock *psock) +{ +/* Used by ioctl to read msg_tot_len only; lock-free for performance */ +return READ_ONCE (psock->msg_tot_len); +} + +static inline void sk_psock_msg_len_add_locked (struct sk_psock *psock,int diff) +{ +/* Use WRITE_ONCE to ensure correct read in sk_psock_get_msg_len_nolock(). +* ingress_lock should be held to prevent concurrent updates to msg_tot_len +*/ +WRITE_ONCE (psock->msg_tot_len, psock->msg_tot_len + diff); +} + +static inline void sk_psock_msg_len_add (struct sk_psock *psock,int diff) +{ +spin_lock_bh (&psock->ingress_lock); +sk_psock_msg_len_add_locked (psock, diff); +spin_unlock_bh (&psock->ingress_lock); +} +static inline bool sk_psock_queue_msg (struct sk_psock *psock,struct sk_msg *msg) {
@@ -329,6 +352,7 @@ static inline bool sk_psock_queue_msg(struct sk_psock *psock,spin_lock_bh (&psock->ingress_lock);if (sk_psock_test_state (psock,SK_PSOCK_TX_ENABLED )) {list_add_tail (&msg->list, &psock->ingress_msg); +sk_psock_msg_len_add_locked (psock, msg->sg.size); ret = true; }else {sk_msg_free (psock->sk, msg);
@@ -345,18 +369,25 @@ static inline struct sk_msg *sk_psock_dequeue_msg(struct sk_psock *psock)spin_lock_bh (&psock->ingress_lock); msg = list_first_entry_or_null(&psock->ingress_msg, struct sk_msg, list); -if (msg) +if (msg) {list_del (&msg->list); +sk_psock_msg_len_add_locked (psock, -msg->sg.size); + }spin_unlock_bh (&psock->ingress_lock);return msg; } +static inline struct sk_msg *sk_psock_peek_msg_locked (struct sk_psock *psock) +{ + return list_first_entry_or_null(&psock->ingress_msg, struct sk_msg, list); +} +static inline struct sk_msg *sk_psock_peek_msg (struct sk_psock *psock) {struct sk_msg *msg;spin_lock_bh (&psock->ingress_lock); - msg = list_first_entry_or_null(&psock->ingress_msg, struct sk_msg, list); + msg =sk_psock_peek_msg_locked (psock);spin_unlock_bh (&psock->ingress_lock);return msg; }
@@ -523,6 +554,39 @@ static inline bool sk_psock_strp_enabled(struct sk_psock *psock)return !!psock->saved_data_ready; } +/* for tcp only, sk is locked */ +static inline ssize_t sk_psock_msg_inq (struct sock *sk) +{ +struct sk_psock *psock; +ssize_t inq =0 ; + + psock =sk_psock_get (sk); +if (likely (psock)) { + inq =sk_psock_get_msg_len_nolock (psock); +sk_psock_put (sk, psock); + } +return inq; +} + +/* for udp only, sk is not locked */ +static inline ssize_t sk_msg_first_len (struct sock *sk) +{ +struct sk_psock *psock; +struct sk_msg *msg; +ssize_t inq =0 ; + + psock =sk_psock_get (sk); +if (likely (psock)) { +spin_lock_bh (&psock->ingress_lock); + msg =sk_psock_peek_msg_locked (psock); +if (msg) + inq = msg->sg.size; +spin_unlock_bh (&psock->ingress_lock); +sk_psock_put (sk, psock); + } +return inq; +} +#if IS_ENABLED (CONFIG_NET_SOCK_MSG )#define BPF_F_STRPARSER (1UL << 1)
net/core/skmsg.c +3 -0
@@ -457,6 +457,7 @@ int __sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msgatomic_sub (copy, &sk->sk_rmem_alloc); } msg_rx->sg.size -= copy; +sk_psock_msg_len_add (psock, -copy);if (!sge->length) {sk_msg_iter_var_next (i);
@@ -820,9 +821,11 @@ static void __sk_psock_purge_ingress_msg(struct sk_psock *psock)list_del (&msg->list);if (!msg->skb)atomic_sub (msg->sg.size, &psock->sk->sk_rmem_alloc); +sk_psock_msg_len_add (psock, -msg->sg.size);sk_msg_free (psock->sk, msg);kfree (msg); } +WARN_ON_ONCE (psock->msg_tot_len); }static void __sk_psock_zap_ingress (struct sk_psock *psock)
net/ipv4/tcp_bpf.c +20 -0
@@ -10,6 +10,7 @@#include <net/inet_common.h> #include <net/tls.h> +#include <asm/ioctls.h> void tcp_eat_skb (struct sock *sk,struct sk_buff *skb) {
@@ -332,6 +333,24 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,return copied; } +static int tcp_bpf_ioctl (struct sock *sk,int cmd,int *karg) +{ +bool slow; + +if (cmd !=SIOCINQ ) +return tcp_ioctl (sk, cmd, karg); + +/* works similar as tcp_ioctl */ +if (sk->sk_state ==TCP_LISTEN ) +return -EINVAL ; + + slow =lock_sock_fast (sk); + *karg =sk_psock_msg_inq (sk); +unlock_sock_fast (sk, slow); + +return 0 ; +} +static int tcp_bpf_recvmsg (struct sock *sk,struct msghdr *msg,size_t len,int flags,int *addr_len) {
@@ -610,6 +629,7 @@ static void tcp_bpf_rebuild_protos(struct proto prot[TCP_BPF_NUM_CFGS], prot[TCP_BPF_BASE ].close = sock_map_close; prot[TCP_BPF_BASE ].recvmsg = tcp_bpf_recvmsg; prot[TCP_BPF_BASE ].sock_is_readable = sk_msg_is_readable; + prot[TCP_BPF_BASE ].ioctl = tcp_bpf_ioctl; prot[TCP_BPF_TX ] = prot[TCP_BPF_BASE ]; prot[TCP_BPF_TX ].sendmsg = tcp_bpf_sendmsg;
net/ipv4/udp_bpf.c +19 -4
@@ -5,6 +5,7 @@#include <net/sock.h> #include <net/udp.h> #include <net/inet_common.h> +#include <asm/ioctls.h> #include "udp_impl.h"
@@ -111,12 +112,26 @@ enum {static DEFINE_SPINLOCK (udpv6_prot_lock);static struct proto udp_bpf_prots[UDP_BPF_NUM_PROTS ]; +static int udp_bpf_ioctl (struct sock *sk,int cmd,int *karg) +{ +if (cmd !=SIOCINQ ) +return udp_ioctl (sk, cmd, karg); + +/* Since we don't hold a lock, sk_receive_queue may contain data. +* BPF might only be processing this data at the moment. We only +* care about the data in the ingress_msg here. +*/ + *karg =sk_msg_first_len (sk); +return 0 ; +} +static void udp_bpf_rebuild_protos (struct proto *prot,const struct proto *base) { - *prot = *base; - prot->close = sock_map_close; - prot->recvmsg = udp_bpf_recvmsg; - prot->sock_is_readable = sk_msg_is_readable; + *prot = *base; + prot->close = sock_map_close; + prot->recvmsg = udp_bpf_recvmsg; + prot->sock_is_readable = sk_msg_is_readable; + prot->ioctl = udp_bpf_ioctl; }static void udp_bpf_check_v6_needs_rebuild (struct proto *ops)
Signature · 1 line
2.51.0
PATCH 64/385 tracing: Add a comment about ftrace_regs definition
In reply to Sasha LevinFrom: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit a370b72ec7165ebe1230d0225cbe66f6526e68ef ]
To clarify what will be expected on ftrace_regs, add a comment to the architecture independent definition of the ftrace_regs.
Stable-dep-of: aea251799998 ("x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path")
--- include/linux/ftrace.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
include/linux/ftrace.h +26 -0
@@ -117,6 +117,32 @@ extern int ftrace_enabled;#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS +/** +* ftrace_regs - ftrace partial/optimal register set +* +* ftrace_regs represents a group of registers which is used at the +* function entry and exit. There are three types of registers. +* +* - Registers for passing the parameters to callee, including the stack +* pointer. (e.g. rcx, rdx, rdi, rsi, r8, r9 and rsp on x86_64) +* - Registers for passing the return values to caller. +* (e.g. rax and rdx on x86_64) +* - Registers for hooking the function call and return including the +* frame pointer (the frame pointer is architecture/config dependent) +* (e.g. rip, rbp and rsp for x86_64) +* +* Also, architecture dependent fields can be used for internal process. +* (e.g. orig_ax on x86_64) +* +* On the function entry, those registers will be restored except for +* the stack pointer, so that user can change the function parameters +* and instruction pointer (e.g. live patching.) +* On the function exit, only registers which is used for return values +* are restored. +* +* NOTE: user *must not* access regs directly, only do it via APIs, because +* the member can be changed according to the architecture. +*/ struct ftrace_regs {struct pt_regs regs; };
Signature · 1 line
2.51.0
PATCH 65/385 ftrace: Make ftrace_regs abstract from direct use
In reply to Sasha LevinFrom: Steven Rostedt <[email protected]>
[ Upstream commit 7888af4166d4ab07ba51234be6ba332b7807e901 ]
ftrace_regs was created to hold registers that store information to save function parameters, return value and stack. Since it is a subset of pt_regs, it should only be used by its accessor functions. But because pt_regs can easily be taken from ftrace_regs (on most archs), it is tempting to use it directly. But when running on other architectures, it may fail to build or worse, build but crash the kernel!
Instead, make struct ftrace_regs an empty structure and have the architectures define __arch_ftrace_regs and all the accessor functions will typecast to it to get to the actual fields. This will help avoid usage of ftrace_regs directly.
Stable-dep-of: aea251799998 ("x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path")
--- arch/arm64/include/asm/ftrace.h | 20 +++++++++-------- arch/arm64/kernel/asm-offsets.c | 22 +++++++++---------- arch/arm64/kernel/ftrace.c | 10 ++++----- arch/loongarch/include/asm/ftrace.h | 22 ++++++++++--------- arch/loongarch/kernel/ftrace_dyn.c | 2 +- arch/powerpc/include/asm/ftrace.h | 21 ++++++++++-------- arch/powerpc/kernel/trace/ftrace.c | 4 ++-- arch/powerpc/kernel/trace/ftrace_64_pg.c | 2 +- arch/riscv/include/asm/ftrace.h | 21 ++++++++++-------- arch/riscv/kernel/asm-offsets.c | 28 ++++++++++++------------ arch/riscv/kernel/ftrace.c | 2 +- arch/s390/include/asm/ftrace.h | 23 ++++++++++--------- arch/s390/kernel/asm-offsets.c | 4 ++-- arch/s390/kernel/ftrace.c | 2 +- arch/s390/lib/test_unwind.c | 4 ++-- arch/x86/include/asm/ftrace.h | 25 +++++++++++---------- arch/x86/kernel/ftrace.c | 2 +- include/linux/ftrace.h | 21 +++++++++++++++--- kernel/trace/ftrace.c | 2 +- 19 files changed, 134 insertions(+), 103 deletions(-)
arch/arm64/include/asm/ftrace.h +11 -9
@@ -56,6 +56,8 @@ unsigned long ftrace_call_adjust(unsigned long addr);#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS struct dyn_ftrace ;struct ftrace_ops ; +struct ftrace_regs ; +#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs))#define arch_ftrace_get_regs (regs) NULL
@@ -63,7 +65,7 @@ struct ftrace_ops;* Note: sizeof(struct ftrace_regs) must be a multiple of 16 to ensure correct * stack alignment */ -struct ftrace_regs { +struct __arch_ftrace_regs {/* x0 - x8 */ unsigned long regs[9 ];
@@ -83,47 +85,47 @@ struct ftrace_regs {static __always_inline unsigned long ftrace_regs_get_instruction_pointer (const struct ftrace_regs *fregs) { -return fregs->pc; +return arch_ftrace_regs (fregs)->pc; } static __always_inline voidftrace_regs_set_instruction_pointer (struct ftrace_regs *fregs,unsigned long pc) { - fregs->pc = pc; +arch_ftrace_regs (fregs)->pc = pc; }static __always_inline unsigned long ftrace_regs_get_stack_pointer (const struct ftrace_regs *fregs) { -return fregs->sp; +return arch_ftrace_regs (fregs)->sp; }static __always_inline unsigned long ftrace_regs_get_argument (struct ftrace_regs *fregs,unsigned int n) {if (n <8 ) -return fregs->regs[n]; +return arch_ftrace_regs (fregs)->regs[n];return 0 ; }static __always_inline unsigned long ftrace_regs_get_return_value (const struct ftrace_regs *fregs) { -return fregs->regs[0 ]; +return arch_ftrace_regs (fregs)->regs[0 ]; } static __always_inline voidftrace_regs_set_return_value (struct ftrace_regs *fregs,unsigned long ret) { - fregs->regs[0 ] = ret; +arch_ftrace_regs (fregs)->regs[0 ] = ret; } static __always_inline voidftrace_override_function_with_return (struct ftrace_regs *fregs) { - fregs->pc = fregs->lr; +arch_ftrace_regs (fregs)->pc =arch_ftrace_regs (fregs)->lr; }int ftrace_regs_query_register_offset (const char *name);
@@ -143,7 +145,7 @@ static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs,* The ftrace trampoline will return to this address instead of the * instrumented function. */ - fregs->direct_tramp = addr; + arch_ftrace_regs(fregs)->direct_tramp = addr; }#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
arch/arm64/kernel/asm-offsets.c +11 -11
@@ -85,19 +85,19 @@ int main(void)DEFINE (PT_REGS_SIZE ,sizeof (struct pt_regs ));BLANK ();#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS - DEFINE(FREGS_X0, offsetof(struct ftrace_regs, regs[0])); - DEFINE(FREGS_X2, offsetof(struct ftrace_regs, regs[2])); - DEFINE(FREGS_X4, offsetof(struct ftrace_regs, regs[4])); - DEFINE(FREGS_X6, offsetof(struct ftrace_regs, regs[6])); - DEFINE(FREGS_X8, offsetof(struct ftrace_regs, regs[8])); -DEFINE (FREGS_FP , offsetof(struct ftrace_regs , fp)); -DEFINE (FREGS_LR , offsetof(struct ftrace_regs , lr)); -DEFINE (FREGS_SP , offsetof(struct ftrace_regs , sp)); -DEFINE (FREGS_PC , offsetof(struct ftrace_regs , pc)); + DEFINE(FREGS_X0, offsetof(struct __arch_ftrace_regs, regs[0])); + DEFINE(FREGS_X2, offsetof(struct __arch_ftrace_regs, regs[2])); + DEFINE(FREGS_X4, offsetof(struct __arch_ftrace_regs, regs[4])); + DEFINE(FREGS_X6, offsetof(struct __arch_ftrace_regs, regs[6])); + DEFINE(FREGS_X8, offsetof(struct __arch_ftrace_regs, regs[8])); +DEFINE (FREGS_FP , offsetof(struct __arch_ftrace_regs , fp)); +DEFINE (FREGS_LR , offsetof(struct __arch_ftrace_regs , lr)); +DEFINE (FREGS_SP , offsetof(struct __arch_ftrace_regs , sp)); +DEFINE (FREGS_PC , offsetof(struct __arch_ftrace_regs , pc));#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS -DEFINE (FREGS_DIRECT_TRAMP , offsetof(struct ftrace_regs , direct_tramp)); +DEFINE (FREGS_DIRECT_TRAMP , offsetof(struct __arch_ftrace_regs , direct_tramp));#endif -DEFINE (FREGS_SIZE ,sizeof (struct ftrace_regs )); +DEFINE (FREGS_SIZE ,sizeof (struct __arch_ftrace_regs ));BLANK ();#endif #ifdef CONFIG_COMPAT
arch/arm64/kernel/ftrace.c +5 -5
@@ -23,10 +23,10 @@ struct fregs_offset {int offset; }; -#define FREGS_OFFSET (n, field) \ -{ \ - .name = n, \ - .offset = offsetof(struct ftrace_regs, field), \ +#define FREGS_OFFSET (n, field) \ +{ \ + .name = n, \ + .offset = offsetof(struct __arch_ftrace_regs, field), \ }static const struct fregs_offset fregs_offsets[] = {
@@ -488,7 +488,7 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent,void ftrace_graph_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs) { -prepare_ftrace_return (ip, &fregs->lr, fregs->fp); +prepare_ftrace_return (ip, &arch_ftrace_regs (fregs)->lr,arch_ftrace_regs (fregs)->fp); }#else /*
arch/loongarch/include/asm/ftrace.h +12 -10
@@ -43,38 +43,40 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent);#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS struct ftrace_ops ; +struct ftrace_regs ; +#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) -struct ftrace_regs { +struct __arch_ftrace_regs {struct pt_regs regs; }; static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) { -return &fregs->regs; +return &arch_ftrace_regs (fregs)->regs; }static __always_inline unsigned long ftrace_regs_get_instruction_pointer (struct ftrace_regs *fregs) { -return instruction_pointer (&fregs->regs); +return instruction_pointer (&arch_ftrace_regs (fregs)->regs); } static __always_inline voidftrace_regs_set_instruction_pointer (struct ftrace_regs *fregs,unsigned long ip) { -instruction_pointer_set (&fregs->regs, ip); +instruction_pointer_set (&arch_ftrace_regs (fregs)->regs, ip); }#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(&(fregs)->regs, n) + regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n)#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(&(fregs)->regs) + kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_return_value (fregs) \ - regs_return_value(&(fregs)->regs) + regs_return_value(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(&(fregs)->regs, ret) + regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret)#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(&(fregs)->regs) + override_function_with_return(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_query_register_offset (name) \ regs_query_register_offset(name)
@@ -90,7 +92,7 @@ __arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr) }#define arch_ftrace_set_direct_caller (fregs, addr) \ - __arch_ftrace_set_direct_caller(&(fregs)->regs, addr) + __arch_ftrace_set_direct_caller(&arch_ftrace_regs(fregs)->regs, addr)#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ #endif
arch/loongarch/kernel/ftrace_dyn.c +1 -1
@@ -241,7 +241,7 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent)void ftrace_graph_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs) { -struct pt_regs *regs = &fregs->regs; +struct pt_regs *regs = &arch_ftrace_regs (fregs)->regs;unsigned long *parent = (unsigned long *)®s->regs[1 ];prepare_ftrace_return (ip, (unsigned long *)parent);
arch/powerpc/include/asm/ftrace.h +12 -9
@@ -32,39 +32,42 @@ struct dyn_arch_ftrace {int ftrace_init_nop (struct module *mod,struct dyn_ftrace *rec);#define ftrace_init_nop ftrace_init_nop -struct ftrace_regs { +struct ftrace_regs ; +#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) + +struct __arch_ftrace_regs {struct pt_regs regs; }; static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) {/* We clear regs.msr in ftrace_call */ -return fregs->regs.msr ? &fregs->regs :NULL ; +return arch_ftrace_regs (fregs)->regs.msr ? &arch_ftrace_regs (fregs)->regs :NULL ; } static __always_inline voidftrace_regs_set_instruction_pointer (struct ftrace_regs *fregs,unsigned long ip) { -regs_set_return_ip (&fregs->regs, ip); +regs_set_return_ip (&arch_ftrace_regs (fregs)->regs, ip); }static __always_inline unsigned long ftrace_regs_get_instruction_pointer (struct ftrace_regs *fregs) { -return instruction_pointer (&fregs->regs); +return instruction_pointer (&arch_ftrace_regs (fregs)->regs); }#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(&(fregs)->regs, n) + regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n)#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(&(fregs)->regs) + kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_return_value (fregs) \ - regs_return_value(&(fregs)->regs) + regs_return_value(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(&(fregs)->regs, ret) + regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret)#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(&(fregs)->regs) + override_function_with_return(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_query_register_offset (name) \ regs_query_register_offset(name)
arch/powerpc/kernel/trace/ftrace.c +2 -2
@@ -421,7 +421,7 @@ int __init ftrace_dyn_arch_init(void)void ftrace_graph_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs) { -unsigned long sp = fregs->regs.gpr[1 ]; +unsigned long sp =arch_ftrace_regs (fregs)->regs.gpr[1 ];int bit;if (unlikely (ftrace_graph_is_dead ()))
@@ -439,6 +439,6 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,ftrace_test_recursion_unlock (bit); out: - fregs->regs.link = parent_ip; + arch_ftrace_regs(fregs)->regs.link = parent_ip; }#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
arch/powerpc/kernel/trace/ftrace_64_pg.c +1 -1
@@ -829,7 +829,7 @@ __prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned long spvoid ftrace_graph_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs) { - fregs->regs.link =__prepare_ftrace_return (parent_ip, ip, fregs->regs.gpr[1 ]); +arch_ftrace_regs (fregs)->regs.link =__prepare_ftrace_return (parent_ip, ip,arch_ftrace_regs (fregs)->regs.gpr[1 ]); }#else unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip,
arch/riscv/include/asm/ftrace.h +12 -9
@@ -126,7 +126,10 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS #define arch_ftrace_get_regs(regs) NULL struct ftrace_ops; -struct ftrace_regs { +struct ftrace_regs; +#define arch_ftrace_regs(fregs) ((struct __arch_ftrace_regs *)(fregs)) + +struct __arch_ftrace_regs { unsigned long epc; unsigned long ra; unsigned long sp;
@@ -150,42 +153,42 @@ struct ftrace_regs {static __always_inline unsigned long ftrace_regs_get_instruction_pointer (const struct ftrace_regs *fregs) { -return fregs->epc; +return arch_ftrace_regs (fregs)->epc; } static __always_inline void ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,unsigned long pc) { - fregs->epc = pc; +arch_ftrace_regs (fregs)->epc = pc; }static __always_inline unsigned long ftrace_regs_get_stack_pointer (const struct ftrace_regs *fregs) { -return fregs->sp; +return arch_ftrace_regs (fregs)->sp; }static __always_inline unsigned long ftrace_regs_get_argument (struct ftrace_regs *fregs,unsigned int n) {if (n <8 ) -return fregs->args[n]; +return arch_ftrace_regs (fregs)->args[n];return 0 ; }static __always_inline unsigned long ftrace_regs_get_return_value (const struct ftrace_regs *fregs) { -return fregs->a0; +return arch_ftrace_regs (fregs)->a0; } static __always_inline void ftrace_regs_set_return_value(struct ftrace_regs *fregs,unsigned long ret) { - fregs->a0 = ret; +arch_ftrace_regs (fregs)->a0 = ret; } static __always_inline void ftrace_override_function_with_return(struct ftrace_regs *fregs) { - fregs->epc = fregs->ra; +arch_ftrace_regs (fregs)->epc =arch_ftrace_regs (fregs)->ra; }int ftrace_regs_query_register_offset (const char *name);
@@ -196,7 +199,7 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,static inline void arch_ftrace_set_direct_caller (struct ftrace_regs *fregs,unsigned long addr) { - fregs->t1 = addr; +arch_ftrace_regs (fregs)->t1 = addr; }#endif /* CONFIG_DYNAMIC_FTRACE_WITH_ARGS */
arch/riscv/kernel/asm-offsets.c +14 -14
@@ -497,19 +497,19 @@ void asm_offsets(void)OFFSET (STACKFRAME_RA , stackframe, ra);#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS -DEFINE (FREGS_SIZE_ON_STACK ,ALIGN (sizeof (struct ftrace_regs ),STACK_ALIGN )); -DEFINE (FREGS_EPC , offsetof(struct ftrace_regs , epc)); -DEFINE (FREGS_RA , offsetof(struct ftrace_regs , ra)); -DEFINE (FREGS_SP , offsetof(struct ftrace_regs , sp)); -DEFINE (FREGS_S0 , offsetof(struct ftrace_regs , s0)); -DEFINE (FREGS_T1 , offsetof(struct ftrace_regs , t1)); -DEFINE (FREGS_A0 , offsetof(struct ftrace_regs , a0)); -DEFINE (FREGS_A1 , offsetof(struct ftrace_regs , a1)); -DEFINE (FREGS_A2 , offsetof(struct ftrace_regs , a2)); -DEFINE (FREGS_A3 , offsetof(struct ftrace_regs , a3)); -DEFINE (FREGS_A4 , offsetof(struct ftrace_regs , a4)); -DEFINE (FREGS_A5 , offsetof(struct ftrace_regs , a5)); -DEFINE (FREGS_A6 , offsetof(struct ftrace_regs , a6)); -DEFINE (FREGS_A7 , offsetof(struct ftrace_regs , a7)); +DEFINE (FREGS_SIZE_ON_STACK ,ALIGN (sizeof (struct __arch_ftrace_regs ),STACK_ALIGN )); +DEFINE (FREGS_EPC , offsetof(struct __arch_ftrace_regs , epc)); +DEFINE (FREGS_RA , offsetof(struct __arch_ftrace_regs , ra)); +DEFINE (FREGS_SP , offsetof(struct __arch_ftrace_regs , sp)); +DEFINE (FREGS_S0 , offsetof(struct __arch_ftrace_regs , s0)); +DEFINE (FREGS_T1 , offsetof(struct __arch_ftrace_regs , t1)); +DEFINE (FREGS_A0 , offsetof(struct __arch_ftrace_regs , a0)); +DEFINE (FREGS_A1 , offsetof(struct __arch_ftrace_regs , a1)); +DEFINE (FREGS_A2 , offsetof(struct __arch_ftrace_regs , a2)); +DEFINE (FREGS_A3 , offsetof(struct __arch_ftrace_regs , a3)); +DEFINE (FREGS_A4 , offsetof(struct __arch_ftrace_regs , a4)); +DEFINE (FREGS_A5 , offsetof(struct __arch_ftrace_regs , a5)); +DEFINE (FREGS_A6 , offsetof(struct __arch_ftrace_regs , a6)); +DEFINE (FREGS_A7 , offsetof(struct __arch_ftrace_regs , a7));#endif }
arch/riscv/kernel/ftrace.c +1 -1
@@ -214,7 +214,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,void ftrace_graph_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs) { -prepare_ftrace_return (&fregs->ra, ip, fregs->s0); +prepare_ftrace_return (&arch_ftrace_regs (fregs)->ra, ip,arch_ftrace_regs (fregs)->s0); }#else /* CONFIG_DYNAMIC_FTRACE_WITH_ARGS */ extern void ftrace_graph_call (void );
arch/s390/include/asm/ftrace.h +13 -10
@@ -51,13 +51,16 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr)return addr; } -struct ftrace_regs { +struct ftrace_regs ; +#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) + +struct __arch_ftrace_regs {struct pt_regs regs; }; static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) { -struct pt_regs *regs = &fregs->regs; +struct pt_regs *regs = &arch_ftrace_regs (fregs)->regs;if (test_pt_regs_flag (regs,PIF_FTRACE_FULL_REGS ))return regs;
@@ -84,26 +87,26 @@ static __always_inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraphstatic __always_inline unsigned long ftrace_regs_get_instruction_pointer (const struct ftrace_regs *fregs) { -return fregs->regs.psw.addr; +return arch_ftrace_regs (fregs)->regs.psw.addr; } static __always_inline voidftrace_regs_set_instruction_pointer (struct ftrace_regs *fregs,unsigned long ip) { - fregs->regs.psw.addr = ip; +arch_ftrace_regs (fregs)->regs.psw.addr = ip; }#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(&(fregs)->regs, n) + regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n)#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(&(fregs)->regs) + kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_return_value (fregs) \ - regs_return_value(&(fregs)->regs) + regs_return_value(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(&(fregs)->regs, ret) + regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret)#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(&(fregs)->regs) + override_function_with_return(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_query_register_offset (name) \ regs_query_register_offset(name)
@@ -117,7 +120,7 @@ ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,*/ static inline void arch_ftrace_set_direct_caller (struct ftrace_regs *fregs,unsigned long addr) { -struct pt_regs *regs = &fregs->regs; +struct pt_regs *regs = &arch_ftrace_regs (fregs)->regs; regs->orig_gpr2 = addr; }#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
arch/s390/kernel/asm-offsets.c +2 -2
@@ -185,8 +185,8 @@ int main(void)OFFSET (__FGRAPH_RET_FP, fgraph_ret_regs, fp);DEFINE (__FGRAPH_RET_SIZE,sizeof (struct fgraph_ret_regs ));#endif -OFFSET (__FTRACE_REGS_PT_REGS, ftrace_regs, regs); -DEFINE (__FTRACE_REGS_SIZE,sizeof (struct ftrace_regs )); +OFFSET (__FTRACE_REGS_PT_REGS, __arch_ftrace_regs, regs); +DEFINE (__FTRACE_REGS_SIZE,sizeof (struct __arch_ftrace_regs ));OFFSET (__PCPU_FLAGS, pcpu, flags);return 0 ;
arch/s390/kernel/ftrace.c +1 -1
@@ -318,7 +318,7 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,if (bit <0 )return ; -kmsan_unpoison_memory (fregs,sizeof (*fregs)); +kmsan_unpoison_memory (fregs,ftrace_regs_size ()); regs =ftrace_get_regs (fregs); p =get_kprobe ((kprobe_opcode_t *)ip);if (!regs ||unlikely (!p) ||kprobe_disabled (p))
arch/s390/lib/test_unwind.c +2 -2
@@ -270,9 +270,9 @@ static void notrace __used test_unwind_ftrace_handler(unsigned long ip,struct ftrace_ops *fops, struct ftrace_regs *fregs) { - struct unwindme *u = (struct unwindme *)fregs->regs.gprs[2]; + struct unwindme *u = (struct unwindme *)arch_ftrace_regs(fregs)->regs.gprs[2]; - u->ret =test_unwind (NULL , (u->flags &UWM_REGS ) ? &fregs->regs :NULL , + u->ret =test_unwind (NULL , (u->flags &UWM_REGS ) ? &arch_ftrace_regs (fregs)->regs :NULL , (u->flags &UWM_SP ) ? u->sp :0 ); }
arch/x86/include/asm/ftrace.h +14 -11
@@ -35,7 +35,10 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr) }#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS -struct ftrace_regs { +struct ftrace_regs ; +#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) + +struct __arch_ftrace_regs {struct pt_regs regs; };
@@ -43,27 +46,27 @@ static __always_inline struct pt_regs * arch_ftrace_get_regs(struct ftrace_regs *fregs) {/* Only when FL_SAVE_REGS is set, cs will be non zero */ -if (!fregs->regs.cs) +if (!arch_ftrace_regs (fregs)->regs.cs)return NULL ; -return &fregs->regs; +return &arch_ftrace_regs (fregs)->regs; }#define ftrace_regs_set_instruction_pointer (fregs, _ip) \ - do { (fregs)->regs.ip = (_ip); } while (0) + do { arch_ftrace_regs(fregs)->regs.ip = (_ip); } while (0)#define ftrace_regs_get_instruction_pointer (fregs) \ - ((fregs)->regs.ip) + arch_ftrace_regs(fregs)->regs.ip)#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(&(fregs)->regs, n) + regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n)#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(&(fregs)->regs) + kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_return_value (fregs) \ - regs_return_value(&(fregs)->regs) + regs_return_value(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(&(fregs)->regs, ret) + regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret)#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(&(fregs)->regs) + override_function_with_return(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_query_register_offset (name) \ regs_query_register_offset(name)
@@ -90,7 +93,7 @@ __arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr) regs->orig_ax = addr; }#define arch_ftrace_set_direct_caller (fregs, addr) \ - __arch_ftrace_set_direct_caller(&(fregs)->regs, addr) + __arch_ftrace_set_direct_caller(&arch_ftrace_regs(fregs)->regs, addr)#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ #ifdef CONFIG_DYNAMIC_FTRACE
arch/x86/kernel/ftrace.c +1 -1
@@ -647,7 +647,7 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent,void ftrace_graph_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs) { -struct pt_regs *regs = &fregs->regs; +struct pt_regs *regs = &arch_ftrace_regs (fregs)->regs;unsigned long *stack = (unsigned long *)kernel_stack_pointer (regs);prepare_ftrace_return (ip, (unsigned long *)stack,0 );
include/linux/ftrace.h +18 -3
@@ -115,8 +115,6 @@ static inline int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *valextern int ftrace_enabled; -#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS -/** * ftrace_regs - ftrace partial/optimal register set *
@@ -142,11 +140,28 @@ extern int ftrace_enabled;* * NOTE: user *must not* access regs directly, only do it via APIs, because * the member can be changed according to the architecture. +* This is why the structure is empty here, so that nothing accesses +* the ftrace_regs directly. */ struct ftrace_regs { +/* Nothing to see here, use the accessor functions! */ +}; + +#define ftrace_regs_size () sizeof(struct __arch_ftrace_regs) + +#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS + +struct __arch_ftrace_regs {struct pt_regs regs; }; -#define arch_ftrace_get_regs (fregs) (&(fregs)->regs) + +struct ftrace_regs ; +#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) + +static inline struct pt_regs *arch_ftrace_get_regs (struct ftrace_regs *fregs) +{ +return &arch_ftrace_regs (fregs)->regs; +}/* * ftrace_regs_set_instruction_pointer() is to be defined by the architecture
kernel/trace/ftrace.c +1 -1
@@ -7973,7 +7973,7 @@ __ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,void arch_ftrace_ops_list_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs) { -kmsan_unpoison_memory (fregs,sizeof (*fregs)); +kmsan_unpoison_memory (fregs,ftrace_regs_size ());__ftrace_ops_list_func (ip, parent_ip,NULL , fregs); }#else
Signature · 1 line
2.51.0
PATCH 66/385 ftrace: Consolidate ftrace_regs accessor functions for archs using pt_regs
In reply to Sasha LevinFrom: Steven Rostedt <[email protected]>
[ Upstream commit e4cf33ca48128d580e25ebe779b7ba7b4b4cf733 ]
Most architectures use pt_regs within ftrace_regs making a lot of the accessor functions just calls to the pt_regs internally. Instead of duplication this effort, use a HAVE_ARCH_FTRACE_REGS for architectures that have their own ftrace_regs that is not based on pt_regs and will define all the accessor functions, and for the architectures that just use pt_regs, it will leave it undefined, and the default accessor functions will be used.
Note, this will also make it easier to add new accessor functions to ftrace_regs as it will mean having to touch less architectures.
Stable-dep-of: aea251799998 ("x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path")
--- arch/arm64/include/asm/ftrace.h | 1 + arch/loongarch/include/asm/ftrace.h | 25 +------------------- arch/powerpc/include/asm/ftrace.h | 26 +-------------------- arch/riscv/include/asm/ftrace.h | 1 + arch/s390/include/asm/ftrace.h | 26 +-------------------- arch/x86/include/asm/ftrace.h | 21 +---------------- include/linux/ftrace.h | 32 ++++++------------------- include/linux/ftrace_regs.h | 36 +++++++++++++++++++++++++++++ 8 files changed, 49 insertions(+), 119 deletions(-) create mode 100644 include/linux/ftrace_regs.h
arch/arm64/include/asm/ftrace.h +1 -0
@@ -54,6 +54,7 @@ extern void return_to_handler(void);unsigned long ftrace_call_adjust (unsigned long addr);#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS +#define HAVE_ARCH_FTRACE_REGS struct dyn_ftrace ;struct ftrace_ops ;struct ftrace_regs ;
arch/loongarch/include/asm/ftrace.h +1 -24
@@ -43,43 +43,20 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent);#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS struct ftrace_ops ; -struct ftrace_regs ; -#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) -struct __arch_ftrace_regs { -struct pt_regs regs; -}; +#include <linux/ftrace_regs.h> static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) {return &arch_ftrace_regs (fregs)->regs; } -static __always_inline unsigned long -ftrace_regs_get_instruction_pointer (struct ftrace_regs *fregs) -{ -return instruction_pointer (&arch_ftrace_regs (fregs)->regs); -} - static __always_inline voidftrace_regs_set_instruction_pointer (struct ftrace_regs *fregs,unsigned long ip) {instruction_pointer_set (&arch_ftrace_regs (fregs)->regs, ip); } -#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n) -#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_return_value (fregs) \ - regs_return_value(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret) -#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_query_register_offset (name) \ - regs_query_register_offset(name) -#define ftrace_graph_func ftrace_graph_funcvoid ftrace_graph_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs);
arch/powerpc/include/asm/ftrace.h +1 -25
@@ -32,12 +32,7 @@ struct dyn_arch_ftrace {int ftrace_init_nop (struct module *mod,struct dyn_ftrace *rec);#define ftrace_init_nop ftrace_init_nop -struct ftrace_regs ; -#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) - -struct __arch_ftrace_regs { -struct pt_regs regs; -}; +#include <linux/ftrace_regs.h> static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) {
@@ -52,25 +47,6 @@ ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,regs_set_return_ip (&arch_ftrace_regs (fregs)->regs, ip); } -static __always_inline unsigned long -ftrace_regs_get_instruction_pointer (struct ftrace_regs *fregs) -{ -return instruction_pointer (&arch_ftrace_regs (fregs)->regs); -} - -#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n) -#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_return_value (fregs) \ - regs_return_value(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret) -#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_query_register_offset (name) \ - regs_query_register_offset(name) -struct ftrace_ops ;#define ftrace_graph_func ftrace_graph_func
arch/riscv/include/asm/ftrace.h +1 -0
@@ -125,6 +125,7 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS #define arch_ftrace_get_regs (regs) NULL +#define HAVE_ARCH_FTRACE_REGS struct ftrace_ops ;struct ftrace_regs ;#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs))
arch/s390/include/asm/ftrace.h +1 -25
@@ -51,12 +51,7 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr)return addr; } -struct ftrace_regs ; -#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) - -struct __arch_ftrace_regs { -struct pt_regs regs; -}; +#include <linux/ftrace_regs.h> static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) {
@@ -84,12 +79,6 @@ static __always_inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph }#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ -static __always_inline unsigned long -ftrace_regs_get_instruction_pointer (const struct ftrace_regs *fregs) -{ -return arch_ftrace_regs (fregs)->regs.psw.addr; -} - static __always_inline voidftrace_regs_set_instruction_pointer (struct ftrace_regs *fregs,unsigned long ip)
@@ -97,19 +86,6 @@ ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,arch_ftrace_regs (fregs)->regs.psw.addr = ip; } -#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n) -#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_return_value (fregs) \ - regs_return_value(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret) -#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_query_register_offset (name) \ - regs_query_register_offset(name) -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS /* * When an ftrace registered caller is tracing a function that is
arch/x86/include/asm/ftrace.h +1 -20
@@ -35,12 +35,8 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr) }#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS -struct ftrace_regs ; -#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) -struct __arch_ftrace_regs { -struct pt_regs regs; -}; +#include <linux/ftrace_regs.h> static __always_inline struct pt_regs *arch_ftrace_get_regs (struct ftrace_regs *fregs)
@@ -54,21 +50,6 @@ arch_ftrace_get_regs(struct ftrace_regs *fregs)#define ftrace_regs_set_instruction_pointer (fregs, _ip) \ do { arch_ftrace_regs(fregs)->regs.ip = (_ip); } while (0) -#define ftrace_regs_get_instruction_pointer (fregs) \ - arch_ftrace_regs(fregs)->regs.ip) - -#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n) -#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_return_value (fregs) \ - regs_return_value(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret) -#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_query_register_offset (name) \ - regs_query_register_offset(name)struct ftrace_ops ;#define ftrace_graph_func ftrace_graph_func
include/linux/ftrace.h +7 -25
@@ -113,6 +113,8 @@ static inline int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *val#ifdef CONFIG_FUNCTION_TRACER +#include <linux/ftrace_regs.h> +extern int ftrace_enabled;/**
@@ -150,14 +152,11 @@ struct ftrace_regs {#define ftrace_regs_size () sizeof(struct __arch_ftrace_regs)#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS - -struct __arch_ftrace_regs { -struct pt_regs regs; -}; - -struct ftrace_regs ; -#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) - +/* +* Architectures that define HAVE_DYNAMIC_FTRACE_WITH_ARGS must define their own +* arch_ftrace_get_regs() where it only returns pt_regs *if* it is fully +* populated. It should return NULL otherwise. +*/ static inline struct pt_regs *arch_ftrace_get_regs (struct ftrace_regs *fregs) {return &arch_ftrace_regs (fregs)->regs;
@@ -191,23 +190,6 @@ static __always_inline bool ftrace_regs_has_args(struct ftrace_regs *fregs)return ftrace_get_regs (fregs) !=NULL ; } -#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS -#define ftrace_regs_get_instruction_pointer (fregs) \ - instruction_pointer(ftrace_get_regs(fregs)) -#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(ftrace_get_regs(fregs), n) -#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(ftrace_get_regs(fregs)) -#define ftrace_regs_return_value (fregs) \ - regs_return_value(ftrace_get_regs(fregs)) -#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(ftrace_get_regs(fregs), ret) -#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(ftrace_get_regs(fregs)) -#define ftrace_regs_query_register_offset (name) \ - regs_query_register_offset(name) -#endif -typedef void (*ftrace_func_t )(unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs);
include/linux/ftrace_regs.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_FTRACE_REGS_H +#define _LINUX_FTRACE_REGS_H + +/* +* For archs that just copy pt_regs in ftrace regs, it can use this default. +* If an architecture does not use pt_regs, it must define all the below +* accessor functions. +*/ +#ifndef HAVE_ARCH_FTRACE_REGS +struct __arch_ftrace_regs { +struct pt_regs regs; +}; + +#define arch_ftrace_regs (fregs) ((struct __arch_ftrace_regs *)(fregs)) + +struct ftrace_regs ; + +#define ftrace_regs_get_instruction_pointer (fregs) \ + instruction_pointer(arch_ftrace_get_regs(fregs)) +#define ftrace_regs_get_argument (fregs, n) \ + regs_get_kernel_argument(arch_ftrace_get_regs(fregs), n) +#define ftrace_regs_get_stack_pointer (fregs) \ + kernel_stack_pointer(arch_ftrace_get_regs(fregs)) +#define ftrace_regs_return_value (fregs) \ + regs_return_value(arch_ftrace_get_regs(fregs)) +#define ftrace_regs_set_return_value (fregs, ret) \ + regs_set_return_value(arch_ftrace_get_regs(fregs), ret) +#define ftrace_override_function_with_return (fregs) \ + override_function_with_return(arch_ftrace_get_regs(fregs)) +#define ftrace_regs_query_register_offset (name) \ + regs_query_register_offset(name) + +#endif /* HAVE_ARCH_FTRACE_REGS */ + +#endif /* _LINUX_FTRACE_REGS_H */
Signature · 1 line
2.51.0
PATCH 67/385 ftrace: Use arch_ftrace_regs() for ftrace_regs_*() macros
In reply to Sasha LevinFrom: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit 0b582611a8f4270fa357a22a546909b2dd5fc5fe ]
Since the arch_ftrace_get_regs(fregs) is only valid when the FL_SAVE_REGS is set, we need to use &arch_ftrace_regs()->regs for ftrace_regs_*() APIs because those APIs are for ftrace_regs, not complete pt_regs.
Stable-dep-of: aea251799998 ("x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path")
--- include/linux/ftrace_regs.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
include/linux/ftrace_regs.h +6 -6
@@ -17,17 +17,17 @@ struct __arch_ftrace_regs {struct ftrace_regs ;#define ftrace_regs_get_instruction_pointer (fregs) \ - instruction_pointer(arch_ftrace_get_regs(fregs)) + instruction_pointer(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_get_argument (fregs, n) \ - regs_get_kernel_argument(arch_ftrace_get_regs(fregs), n) + regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n)#define ftrace_regs_get_stack_pointer (fregs) \ - kernel_stack_pointer(arch_ftrace_get_regs(fregs)) + kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_return_value (fregs) \ - regs_return_value(arch_ftrace_get_regs(fregs)) + regs_return_value(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_set_return_value (fregs, ret) \ - regs_set_return_value(arch_ftrace_get_regs(fregs), ret) + regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret)#define ftrace_override_function_with_return (fregs) \ - override_function_with_return(arch_ftrace_get_regs(fregs)) + override_function_with_return(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_query_register_offset (name) \ regs_query_register_offset(name)
Signature · 1 line
2.51.0
PATCH 68/385 ftrace: Rename ftrace_regs_return_value to ftrace_regs_get_return_value
In reply to Sasha LevinFrom: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit 2d17932da44fdc1ba835ad05110ab996d2912dbf ]
Rename ftrace_regs_return_value to ftrace_regs_get_return_value as same as other ftrace_regs_get/set_* APIs. arm64 and riscv are already using this new name.
Stable-dep-of: aea251799998 ("x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path")
--- include/linux/ftrace_regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/ftrace_regs.h +1 -1
@@ -22,7 +22,7 @@ struct ftrace_regs; regs_get_kernel_argument(&arch_ftrace_regs(fregs)->regs, n)#define ftrace_regs_get_stack_pointer (fregs) \ kernel_stack_pointer(&arch_ftrace_regs(fregs)->regs) -#define ftrace_regs_return_value (fregs) \ +#define ftrace_regs_get_return_value (fregs) \ regs_return_value(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_set_return_value (fregs, ret) \ regs_set_return_value(&arch_ftrace_regs(fregs)->regs, ret)
Signature · 1 line
2.51.0
PATCH 69/385 fgraph: Replace fgraph_ret_regs with ftrace_regs
In reply to Sasha LevinFrom: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit a3ed4157b7d89800a0008de0c9e46a438a5c3745 ]
Use ftrace_regs instead of fgraph_ret_regs for tracing return value on function_graph tracer because of simplifying the callback interface.
The CONFIG_HAVE_FUNCTION_GRAPH_RETVAL is also replaced by CONFIG_HAVE_FUNCTION_GRAPH_FREGS.
Stable-dep-of: aea251799998 ("x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path")
--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/ftrace.h | 23 ++++++--------------- arch/arm64/kernel/asm-offsets.c | 12 ----------- arch/arm64/kernel/entry-ftrace.S | 32 ++++++++++++++++------------- arch/loongarch/Kconfig | 2 +- arch/loongarch/include/asm/ftrace.h | 26 ++++------------------- arch/loongarch/kernel/asm-offsets.c | 12 ----------- arch/loongarch/kernel/mcount.S | 17 ++++++++------- arch/loongarch/kernel/mcount_dyn.S | 14 ++++++------- arch/riscv/Kconfig | 2 +- arch/riscv/include/asm/ftrace.h | 26 +++++------------------ arch/riscv/kernel/mcount.S | 24 ++++++++++++---------- arch/s390/Kconfig | 2 +- arch/s390/include/asm/ftrace.h | 24 +++++++--------------- arch/s390/kernel/asm-offsets.c | 6 ------ arch/s390/kernel/mcount.S | 12 +++++------ arch/x86/Kconfig | 2 +- arch/x86/include/asm/ftrace.h | 20 ------------------ arch/x86/kernel/ftrace_32.S | 13 ++++++------ arch/x86/kernel/ftrace_64.S | 17 +++++++-------- include/linux/ftrace.h | 12 ++++++++--- include/linux/ftrace_regs.h | 2 ++ kernel/trace/Kconfig | 4 ++-- kernel/trace/fgraph.c | 21 ++++++++----------- 24 files changed, 119 insertions(+), 207 deletions(-)
arch/arm64/Kconfig +1 -0
@@ -216,6 +216,7 @@ config ARM64 select HAVE_FTRACE_MCOUNT_RECORD select HAVE_FUNCTION_TRACER select HAVE_FUNCTION_ERROR_INJECTION + select HAVE_FUNCTION_GRAPH_FREGS select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_GRAPH_RETVAL select HAVE_GCC_PLUGINS
arch/arm64/include/asm/ftrace.h +6 -17
@@ -129,6 +129,12 @@ ftrace_override_function_with_return(struct ftrace_regs *fregs)arch_ftrace_regs (fregs)->pc =arch_ftrace_regs (fregs)->lr; } +static __always_inline unsigned long +ftrace_regs_get_frame_pointer (const struct ftrace_regs *fregs) +{ +return arch_ftrace_regs (fregs)->fp; +} +int ftrace_regs_query_register_offset (const char *name);int ftrace_init_nop (struct module *mod,struct dyn_ftrace *rec);
@@ -186,23 +192,6 @@ static inline bool arch_syscall_match_sym_name(const char *sym,#ifndef __ASSEMBLY__#ifdef CONFIG_FUNCTION_GRAPH_TRACER -struct fgraph_ret_regs { -/* x0 - x7 */ -unsigned long regs[8 ]; - -unsigned long fp; -unsigned long __unused; -}; - -static inline unsigned long fgraph_ret_regs_return_value (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->regs[0 ]; -} - -static inline unsigned long fgraph_ret_regs_frame_pointer (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->fp; -}void prepare_ftrace_return (unsigned long self_addr,unsigned long *parent,unsigned long frame_pointer);
arch/arm64/kernel/asm-offsets.c +0 -12
@@ -203,18 +203,6 @@ int main(void)DEFINE (FTRACE_OPS_FUNC , offsetof(struct ftrace_ops , func));#endif BLANK (); -#ifdef CONFIG_FUNCTION_GRAPH_TRACER - DEFINE(FGRET_REGS_X0, offsetof(struct fgraph_ret_regs, regs[0])); - DEFINE(FGRET_REGS_X1, offsetof(struct fgraph_ret_regs, regs[1])); - DEFINE(FGRET_REGS_X2, offsetof(struct fgraph_ret_regs, regs[2])); - DEFINE(FGRET_REGS_X3, offsetof(struct fgraph_ret_regs, regs[3])); - DEFINE(FGRET_REGS_X4, offsetof(struct fgraph_ret_regs, regs[4])); - DEFINE(FGRET_REGS_X5, offsetof(struct fgraph_ret_regs, regs[5])); - DEFINE(FGRET_REGS_X6, offsetof(struct fgraph_ret_regs, regs[6])); - DEFINE(FGRET_REGS_X7, offsetof(struct fgraph_ret_regs, regs[7])); -DEFINE (FGRET_REGS_FP , offsetof(struct fgraph_ret_regs , fp)); -DEFINE (FGRET_REGS_SIZE ,sizeof (struct fgraph_ret_regs )); -#endif #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS DEFINE (FTRACE_OPS_DIRECT_CALL , offsetof(struct ftrace_ops , direct_call));#endif
arch/arm64/kernel/entry-ftrace.S +18 -14
@@ -329,24 +329,28 @@ SYM_FUNC_END(ftrace_stub_graph) * @fp is checked against the value passed by ftrace_graph_caller(). */ SYM_CODE_START(return_to_handler) - /* save return value regs */ - sub sp, sp, #FGRET_REGS_SIZE - stp x0, x1, [sp, #FGRET_REGS_X0] - stp x2, x3, [sp, #FGRET_REGS_X2] - stp x4, x5, [sp, #FGRET_REGS_X4] - stp x6, x7, [sp, #FGRET_REGS_X6] - str x29, [sp, #FGRET_REGS_FP] // parent's fp + /* Make room for ftrace_regs */ + sub sp, sp, #FREGS_SIZE + + /* Save return value regs */ + stp x0, x1, [sp, #FREGS_X0] + stp x2, x3, [sp, #FREGS_X2] + stp x4, x5, [sp, #FREGS_X4] + stp x6, x7, [sp, #FREGS_X6] + + /* Save the callsite's FP */ + str x29, [sp, #FREGS_FP] mov x0, sp - bl ftrace_return_to_handler // addr = ftrace_return_to_hander(regs); + bl ftrace_return_to_handler // addr = ftrace_return_to_hander(fregs); mov x30, x0 // restore the original return address - /* restore return value regs */ - ldp x0, x1, [sp, #FGRET_REGS_X0] - ldp x2, x3, [sp, #FGRET_REGS_X2] - ldp x4, x5, [sp, #FGRET_REGS_X4] - ldp x6, x7, [sp, #FGRET_REGS_X6] - add sp, sp, #FGRET_REGS_SIZE + /* Restore return value regs */ + ldp x0, x1, [sp, #FREGS_X0] + ldp x2, x3, [sp, #FREGS_X2] + ldp x4, x5, [sp, #FREGS_X4] + ldp x6, x7, [sp, #FREGS_X6] + add sp, sp, #FREGS_SIZE ret SYM_CODE_END(return_to_handler)
arch/loongarch/Kconfig +1 -1
@@ -136,7 +136,7 @@ config LOONGARCH select HAVE_FTRACE_MCOUNT_RECORD select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_FUNCTION_ERROR_INJECTION - select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER + select HAVE_FUNCTION_GRAPH_FREGS select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS
arch/loongarch/include/asm/ftrace.h +4 -22
@@ -57,6 +57,10 @@ ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, unsigned long ip)instruction_pointer_set (&arch_ftrace_regs (fregs)->regs, ip); } +#undef ftrace_regs_get_frame_pointer +#define ftrace_regs_get_frame_pointer (fregs) \ + (arch_ftrace_regs(fregs)->regs.regs[22]) +#define ftrace_graph_func ftrace_graph_funcvoid ftrace_graph_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct ftrace_regs *fregs);
@@ -78,26 +82,4 @@ __arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)#endif /* CONFIG_FUNCTION_TRACER */ -#ifndef __ASSEMBLY__ -#ifdef CONFIG_FUNCTION_GRAPH_TRACER -struct fgraph_ret_regs { -/* a0 - a1 */ -unsigned long regs[2 ]; - -unsigned long fp; -unsigned long __unused; -}; - -static inline unsigned long fgraph_ret_regs_return_value (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->regs[0 ]; -} - -static inline unsigned long fgraph_ret_regs_frame_pointer (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->fp; -} -#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */ -#endif -#endif /* _ASM_LOONGARCH_FTRACE_H */
arch/loongarch/kernel/asm-offsets.c +0 -12
@@ -281,18 +281,6 @@ static void __used output_pbe_defines(void) }#endif -#ifdef CONFIG_FUNCTION_GRAPH_TRACER -static void __used output_fgraph_ret_regs_defines (void ) -{ -COMMENT ("LoongArch fgraph_ret_regs offsets." ); -OFFSET (FGRET_REGS_A0 , fgraph_ret_regs, regs[0 ]); -OFFSET (FGRET_REGS_A1 , fgraph_ret_regs, regs[1 ]); -OFFSET (FGRET_REGS_FP , fgraph_ret_regs, fp); -DEFINE (FGRET_REGS_SIZE ,sizeof (struct fgraph_ret_regs )); -BLANK (); -} -#endif -static void __used output_kvm_defines (void ) {COMMENT ("KVM/LoongArch Specific offsets." );
arch/loongarch/kernel/mcount.S +10 -7
@@ -79,10 +79,11 @@ SYM_FUNC_START(ftrace_graph_caller) SYM_FUNC_END(ftrace_graph_caller) SYM_FUNC_START(return_to_handler) - PTR_ADDI sp, sp, -FGRET_REGS_SIZE - PTR_S a0, sp, FGRET_REGS_A0 - PTR_S a1, sp, FGRET_REGS_A1 - PTR_S zero, sp, FGRET_REGS_FP + /* Save return value regs */ + PTR_ADDI sp, sp, -PT_SIZE + PTR_S a0, sp, PT_R4 + PTR_S a1, sp, PT_R5 + PTR_S zero, sp, PT_R22 move a0, sp bl ftrace_return_to_handler
@@ -90,9 +91,11 @@ SYM_FUNC_START(return_to_handler) /* Restore the real parent address: a0 -> ra */ move ra, a0 - PTR_L a0, sp, FGRET_REGS_A0 - PTR_L a1, sp, FGRET_REGS_A1 - PTR_ADDI sp, sp, FGRET_REGS_SIZE + /* Restore return value regs */ + PTR_L a0, sp, PT_R4 + PTR_L a1, sp, PT_R5 + PTR_ADDI sp, sp, PT_SIZE + jr ra SYM_FUNC_END(return_to_handler) #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
arch/loongarch/kernel/mcount_dyn.S +7 -7
@@ -144,19 +144,19 @@ SYM_CODE_END(ftrace_graph_caller) SYM_CODE_START(return_to_handler) UNWIND_HINT_UNDEFINED /* Save return value regs */ - PTR_ADDI sp, sp, -FGRET_REGS_SIZE - PTR_S a0, sp, FGRET_REGS_A0 - PTR_S a1, sp, FGRET_REGS_A1 - PTR_S zero, sp, FGRET_REGS_FP + PTR_ADDI sp, sp, -PT_SIZE + PTR_S a0, sp, PT_R4 + PTR_S a1, sp, PT_R5 + PTR_S zero, sp, PT_R22 move a0, sp bl ftrace_return_to_handler move ra, a0 /* Restore return value regs */ - PTR_L a0, sp, FGRET_REGS_A0 - PTR_L a1, sp, FGRET_REGS_A1 - PTR_ADDI sp, sp, FGRET_REGS_SIZE + PTR_L a0, sp, PT_R4 + PTR_L a1, sp, PT_R5 + PTR_ADDI sp, sp, PT_SIZE jr ra SYM_CODE_END(return_to_handler)
arch/riscv/Kconfig +1 -1
@@ -144,7 +144,7 @@ config RISCV select HAVE_DYNAMIC_FTRACE_WITH_ARGS if HAVE_DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_GRAPH_TRACER - select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER + select HAVE_FUNCTION_GRAPH_FREGS select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION select HAVE_EBPF_JIT if MMU select HAVE_GUP_FAST if MMU
arch/riscv/include/asm/ftrace.h +5 -21
@@ -168,6 +168,11 @@ static __always_inline unsigned long ftrace_regs_get_stack_pointer(const structreturn arch_ftrace_regs (fregs)->sp; } +static __always_inline unsigned long ftrace_regs_get_frame_pointer (const struct ftrace_regs *fregs) +{ +return arch_ftrace_regs (fregs)->s0; +} +static __always_inline unsigned long ftrace_regs_get_argument (struct ftrace_regs *fregs,unsigned int n) {
@@ -208,25 +213,4 @@ static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsi#endif /* CONFIG_DYNAMIC_FTRACE */ -#ifndef __ASSEMBLY__ -#ifdef CONFIG_FUNCTION_GRAPH_TRACER -struct fgraph_ret_regs { -unsigned long a1; -unsigned long a0; -unsigned long s0; -unsigned long ra; -}; - -static inline unsigned long fgraph_ret_regs_return_value (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->a0; -} - -static inline unsigned long fgraph_ret_regs_frame_pointer (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->s0; -} -#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */ -#endif -#endif /* _ASM_RISCV_FTRACE_H */
arch/riscv/kernel/mcount.S +13 -11
@@ -12,6 +12,8 @@ #include <asm/asm-offsets.h> #include <asm/ftrace.h> +#define ABI_SIZE_ON_STACK 80 + .text .macro SAVE_ABI_STATE
@@ -26,12 +28,12 @@ * register if a0 was not saved. */ .macro SAVE_RET_ABI_STATE - addi sp, sp, -4*SZREG - REG_S s0, 2*SZREG(sp) - REG_S ra, 3*SZREG(sp) - REG_S a0, 1*SZREG(sp) - REG_S a1, 0*SZREG(sp) - addi s0, sp, 4*SZREG + addi sp, sp, -ABI_SIZE_ON_STACK + REG_S ra, 1*SZREG(sp) + REG_S s0, 8*SZREG(sp) + REG_S a0, 10*SZREG(sp) + REG_S a1, 11*SZREG(sp) + addi s0, sp, ABI_SIZE_ON_STACK .endm .macro RESTORE_ABI_STATE
@@ -41,11 +43,11 @@ .endm .macro RESTORE_RET_ABI_STATE - REG_L ra, 3*SZREG(sp) - REG_L s0, 2*SZREG(sp) - REG_L a0, 1*SZREG(sp) - REG_L a1, 0*SZREG(sp) - addi sp, sp, 4*SZREG + REG_L ra, 1*SZREG(sp) + REG_L s0, 8*SZREG(sp) + REG_L a0, 10*SZREG(sp) + REG_L a1, 11*SZREG(sp) + addi sp, sp, ABI_SIZE_ON_STACK .endm SYM_TYPED_FUNC_START(ftrace_stub)
arch/s390/Kconfig +1 -1
@@ -184,7 +184,7 @@ config S390 select HAVE_FTRACE_MCOUNT_RECORD select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_FUNCTION_ERROR_INJECTION - select HAVE_FUNCTION_GRAPH_RETVAL + select HAVE_FUNCTION_GRAPH_FREGS select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS
arch/s390/include/asm/ftrace.h +7 -17
@@ -62,23 +62,6 @@ static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *return NULL ; } -#ifdef CONFIG_FUNCTION_GRAPH_TRACER -struct fgraph_ret_regs { -unsigned long gpr2; -unsigned long fp; -}; - -static __always_inline unsigned long fgraph_ret_regs_return_value (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->gpr2; -} - -static __always_inline unsigned long fgraph_ret_regs_frame_pointer (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->fp; -} -#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ - static __always_inline voidftrace_regs_set_instruction_pointer (struct ftrace_regs *fregs,unsigned long ip)
@@ -86,6 +69,13 @@ ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,arch_ftrace_regs (fregs)->regs.psw.addr = ip; } +#undef ftrace_regs_get_frame_pointer +static __always_inline unsigned long +ftrace_regs_get_frame_pointer (struct ftrace_regs *fregs) +{ +return ftrace_regs_get_stack_pointer (fregs); +} +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS /* * When an ftrace registered caller is tracing a function that is
arch/s390/kernel/asm-offsets.c +0 -6
@@ -179,12 +179,6 @@ int main(void)DEFINE (OLDMEM_SIZE ,PARMAREA + offsetof(struct parmarea , oldmem_size));DEFINE (COMMAND_LINE ,PARMAREA + offsetof(struct parmarea , command_line));DEFINE (MAX_COMMAND_LINE_SIZE ,PARMAREA + offsetof(struct parmarea , max_command_line_size)); -#ifdef CONFIG_FUNCTION_GRAPH_TRACER -/* function graph return value tracing */ -OFFSET (__FGRAPH_RET_GPR2, fgraph_ret_regs, gpr2); -OFFSET (__FGRAPH_RET_FP, fgraph_ret_regs, fp); -DEFINE (__FGRAPH_RET_SIZE,sizeof (struct fgraph_ret_regs )); -#endif OFFSET (__FTRACE_REGS_PT_REGS, __arch_ftrace_regs, regs);DEFINE (__FTRACE_REGS_SIZE,sizeof (struct __arch_ftrace_regs ));
arch/s390/kernel/mcount.S +6 -6
@@ -134,14 +134,14 @@ SYM_CODE_END(ftrace_common) SYM_FUNC_START(return_to_handler) stmg %r2,%r5,32(%r15) lgr %r1,%r15 - aghi %r15,-(STACK_FRAME_OVERHEAD+__FGRAPH_RET_SIZE) + # allocate ftrace_regs and stack frame for ftrace_return_to_handler + aghi %r15,-STACK_FRAME_SIZE_FREGS stg %r1,__SF_BACKCHAIN(%r15) - la %r3,STACK_FRAME_OVERHEAD(%r15) - stg %r1,__FGRAPH_RET_FP(%r3) - stg %r2,__FGRAPH_RET_GPR2(%r3) - lgr %r2,%r3 + stg %r2,(STACK_FREGS_PTREGS_GPRS+2*8)(%r15) + stg %r1,(STACK_FREGS_PTREGS_GPRS+15*8)(%r15) + la %r2,STACK_FRAME_OVERHEAD(%r15) brasl %r14,ftrace_return_to_handler - aghi %r15,STACK_FRAME_OVERHEAD+__FGRAPH_RET_SIZE + aghi %r15,STACK_FRAME_SIZE_FREGS lgr %r14,%r2 lmg %r2,%r5,32(%r15) BR_EX %r14
arch/x86/Kconfig +1 -1
@@ -231,7 +231,7 @@ config X86 select HAVE_GUP_FAST select HAVE_FENTRY if X86_64 || DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD - select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER + select HAVE_FUNCTION_GRAPH_FREGS if HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_GRAPH_TRACER if X86_32 || (X86_64 && DYNAMIC_FTRACE) select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS
arch/x86/include/asm/ftrace.h +0 -20
@@ -134,24 +134,4 @@ static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)#endif /* !COMPILE_OFFSETS */ #endif /* !__ASSEMBLY__ */ -#ifndef __ASSEMBLY__ -#ifdef CONFIG_FUNCTION_GRAPH_TRACER -struct fgraph_ret_regs { -unsigned long ax; -unsigned long dx; -unsigned long bp; -}; - -static inline unsigned long fgraph_ret_regs_return_value (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->ax; -} - -static inline unsigned long fgraph_ret_regs_frame_pointer (struct fgraph_ret_regs *ret_regs) -{ -return ret_regs->bp; -} -#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */ -#endif -#endif /* _ASM_X86_FTRACE_H */
arch/x86/kernel/ftrace_32.S +7 -6
@@ -187,14 +187,15 @@ SYM_CODE_END(ftrace_graph_caller) .globl return_to_handler return_to_handler: - pushl $0 - pushl %edx - pushl %eax + subl $(PTREGS_SIZE), %esp + movl $0, PT_EBP(%esp) + movl %edx, PT_EDX(%esp) + movl %eax, PT_EAX(%esp) movl %esp, %eax call ftrace_return_to_handler movl %eax, %ecx - popl %eax - popl %edx - addl $4, %esp # skip ebp + movl PT_EAX(%esp), %eax + movl PT_EDX(%esp), %edx + addl $(PTREGS_SIZE), %esp JMP_NOSPEC ecx #endif
arch/x86/kernel/ftrace_64.S +9 -8
@@ -348,21 +348,22 @@ STACK_FRAME_NON_STANDARD_FP(__fentry__) SYM_CODE_START(return_to_handler) UNWIND_HINT_UNDEFINED ANNOTATE_NOENDBR - subq $24, %rsp - /* Save the return values */ - movq %rax, (%rsp) - movq %rdx, 8(%rsp) - movq %rbp, 16(%rsp) + /* Save ftrace_regs for function exit context */ + subq $(FRAME_SIZE), %rsp + + movq %rax, RAX(%rsp) + movq %rdx, RDX(%rsp) + movq %rbp, RBP(%rsp) movq %rsp, %rdi call ftrace_return_to_handler movq %rax, %rdi - movq 8(%rsp), %rdx - movq (%rsp), %rax + movq RDX(%rsp), %rdx + movq RAX(%rsp), %rax - addq $24, %rsp + addq $(FRAME_SIZE), %rsp /* * Jump back to the old return address. This cannot be JMP_NOSPEC rdi * since IBT would demand that contain ENDBR, which simply isn't so for
include/linux/ftrace.h +9 -3
@@ -43,9 +43,8 @@ struct dyn_ftrace;char *arch_ftrace_match_adjust (char *str,const char *search); -#ifdef CONFIG_HAVE_FUNCTION_GRAPH_RETVAL -struct fgraph_ret_regs ; -unsigned long ftrace_return_to_handler (struct fgraph_ret_regs *ret_regs); +#ifdef CONFIG_HAVE_FUNCTION_GRAPH_FREGS +unsigned long ftrace_return_to_handler (struct ftrace_regs *fregs);#else unsigned long ftrace_return_to_handler (unsigned long frame_pointer);#endif
@@ -134,6 +133,13 @@ extern int ftrace_enabled;* Also, architecture dependent fields can be used for internal process. * (e.g. orig_ax on x86_64) * +* Basically, ftrace_regs stores the registers related to the context. +* On function entry, registers for function parameters and hooking the +* function call are stored, and on function exit, registers for function +* return value and frame pointers are stored. +* +* And also, it dpends on the context that which registers are restored +* from the ftrace_regs. * On the function entry, those registers will be restored except for * the stack pointer, so that user can change the function parameters * and instruction pointer (e.g. live patching.)
include/linux/ftrace_regs.h +2 -0
@@ -30,6 +30,8 @@ struct ftrace_regs; override_function_with_return(&arch_ftrace_regs(fregs)->regs)#define ftrace_regs_query_register_offset (name) \ regs_query_register_offset(name) +#define ftrace_regs_get_frame_pointer (fregs) \ + frame_pointer(&arch_ftrace_regs(fregs)->regs)#endif /* HAVE_ARCH_FTRACE_REGS */
kernel/trace/Kconfig +2 -2
@@ -31,7 +31,7 @@ config HAVE_FUNCTION_GRAPH_TRACER help See Documentation/trace/ftrace-design.rst -config HAVE_FUNCTION_GRAPH_RETVAL +config HAVE_FUNCTION_GRAPH_FREGS bool config HAVE_DYNAMIC_FTRACE
@@ -232,7 +232,7 @@ config FUNCTION_GRAPH_TRACER config FUNCTION_GRAPH_RETVAL bool "Kernel Function Graph Return Value" - depends on HAVE_FUNCTION_GRAPH_RETVAL + depends on HAVE_FUNCTION_GRAPH_FREGS depends on FUNCTION_GRAPH_TRACER default n help
kernel/trace/fgraph.c +9 -12
@@ -761,15 +761,12 @@ static struct notifier_block ftrace_suspend_notifier = { .notifier_call = ftrace_suspend_notifier_call, }; -/* fgraph_ret_regs is not defined without CONFIG_FUNCTION_GRAPH_RETVAL */ -struct fgraph_ret_regs ; -/* * Send the trace to the ring-buffer. * @return the original return address. */ -static unsigned long __ftrace_return_to_handler (struct fgraph_ret_regs *ret_regs, -unsigned long frame_pointer) +static inline unsigned long +__ftrace_return_to_handler (struct ftrace_regs *fregs,unsigned long frame_pointer) {struct ftrace_ret_stack *ret_stack;struct ftrace_graph_ret trace;
@@ -789,7 +786,7 @@ static unsigned long __ftrace_return_to_handler(struct fgraph_ret_regs *ret_regs trace.rettime =trace_clock_local ();#ifdef CONFIG_FUNCTION_GRAPH_RETVAL - trace.retval =fgraph_ret_regs_return_value (ret_regs); + trace.retval =ftrace_regs_get_return_value (fregs);#endif bitmap =get_bitmap_bits (current, offset);
@@ -824,14 +821,14 @@ static unsigned long __ftrace_return_to_handler(struct fgraph_ret_regs *ret_regs }/* -* After all architecures have selected HAVE_FUNCTION_GRAPH_RETVAL, we can -* leave only ftrace_return_to_handler(ret_regs). +* After all architecures have selected HAVE_FUNCTION_GRAPH_FREGS, we can +* leave only ftrace_return_to_handler(fregs). */ -#ifdef CONFIG_HAVE_FUNCTION_GRAPH_RETVAL -unsigned long ftrace_return_to_handler (struct fgraph_ret_regs *ret_regs) +#ifdef CONFIG_HAVE_FUNCTION_GRAPH_FREGS +unsigned long ftrace_return_to_handler (struct ftrace_regs *fregs) { -return __ftrace_return_to_handler (ret_regs, -fgraph_ret_regs_frame_pointer (ret_regs)); +return __ftrace_return_to_handler (fregs, +ftrace_regs_get_frame_pointer (fregs)); }#else unsigned long ftrace_return_to_handler (unsigned long frame_pointer)
Signature · 1 line
2.51.0
PATCH 70/385 tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs
In reply to Sasha LevinFrom: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit b9b55c8912ce1e5555715d126486bdd63ddfeaec ]
Add ftrace_partial_regs() which converts the ftrace_regs to pt_regs. This is for the eBPF which needs this to keep the same pt_regs interface to access registers.
Thus when replacing the pt_regs with ftrace_regs in fprobes (which is used by kprobe_multi eBPF event), this will be used.
If the architecture defines its own ftrace_regs, this copies partial registers to pt_regs and returns it. If not, ftrace_regs is the same as pt_regs and ftrace_partial_regs() will return ftrace_regs::regs.
Stable-dep-of: aea251799998 ("x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path")
--- arch/arm64/include/asm/ftrace.h | 13 +++++++++++++ arch/riscv/include/asm/ftrace.h | 14 ++++++++++++++ include/linux/ftrace.h | 17 +++++++++++++++++ 3 files changed, 44 insertions(+)
arch/arm64/include/asm/ftrace.h +13 -0
@@ -135,6 +135,19 @@ ftrace_regs_get_frame_pointer(const struct ftrace_regs *fregs)return arch_ftrace_regs (fregs)->fp; } +static __always_inline struct pt_regs * +ftrace_partial_regs (const struct ftrace_regs *fregs,struct pt_regs *regs) +{ +struct __arch_ftrace_regs *afregs =arch_ftrace_regs (fregs); + +memcpy (regs->regs, afregs->regs,sizeof (afregs->regs)); + regs->sp = afregs->sp; + regs->pc = afregs->pc; + regs->regs[29 ] = afregs->fp; + regs->regs[30 ] = afregs->lr; +return regs; +} +int ftrace_regs_query_register_offset (const char *name);int ftrace_init_nop (struct module *mod,struct dyn_ftrace *rec);
arch/riscv/include/asm/ftrace.h +14 -0
@@ -197,6 +197,20 @@ static __always_inline void ftrace_override_function_with_return(struct ftrace_rarch_ftrace_regs (fregs)->epc =arch_ftrace_regs (fregs)->ra; } +static __always_inline struct pt_regs * +ftrace_partial_regs (const struct ftrace_regs *fregs,struct pt_regs *regs) +{ +struct __arch_ftrace_regs *afregs =arch_ftrace_regs (fregs); + +memcpy (®s->a0, afregs->args,sizeof (afregs->args)); + regs->epc = afregs->epc; + regs->ra = afregs->ra; + regs->sp = afregs->sp; + regs->s0 = afregs->s0; + regs->t1 = afregs->t1; +return regs; +} +int ftrace_regs_query_register_offset (const char *name); void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
include/linux/ftrace.h +17 -0
@@ -184,6 +184,23 @@ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregsreturn arch_ftrace_get_regs (fregs); } +#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS ) || \ + defined(CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS ) + +static __always_inline struct pt_regs * +ftrace_partial_regs (struct ftrace_regs *fregs,struct pt_regs *regs) +{ +/* +* If CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS=y, ftrace_regs memory +* layout is including pt_regs. So always returns that address. +* Since arch_ftrace_get_regs() will check some members and may return +* NULL, we can not use it. +*/ +return &arch_ftrace_regs (fregs)->regs; +} + +#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS */ +/* * When true, the ftrace_regs_{get,set}_*() functions may be used on fregs. * Note: this can be true even when ftrace_get_regs() cannot provide a pt_regs.
Signature · 1 line
2.51.0
PATCH 71/385 tracing: Add ftrace_fill_perf_regs() for perf event
In reply to Sasha LevinFrom: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit d5d01b71996ec03af51b3c0736c92d0fc89703b5 ]
Add ftrace_fill_perf_regs() which should be compatible with the perf_fetch_caller_regs(). In other words, the pt_regs returned from the ftrace_fill_perf_regs() must satisfy 'user_mode(regs) == false' and can be used for stack tracing.
Stable-dep-of: aea251799998 ("x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path")
--- arch/arm64/include/asm/ftrace.h | 7 +++++++ arch/powerpc/include/asm/ftrace.h | 7 +++++++ arch/s390/include/asm/ftrace.h | 6 ++++++ arch/x86/include/asm/ftrace.h | 7 +++++++ include/linux/ftrace.h | 31 +++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+)
arch/arm64/include/asm/ftrace.h +7 -0
@@ -148,6 +148,13 @@ ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs)return regs; } +#define arch_ftrace_fill_perf_regs (fregs, _regs) do { \ + (_regs)->pc = arch_ftrace_regs(fregs)->pc; \ + (_regs)->regs[29] = arch_ftrace_regs(fregs)->fp; \ + (_regs)->sp = arch_ftrace_regs(fregs)->sp; \ + (_regs)->pstate = PSR_MODE_EL1h; \ + } while (0) +int ftrace_regs_query_register_offset (const char *name);int ftrace_init_nop (struct module *mod,struct dyn_ftrace *rec);
arch/powerpc/include/asm/ftrace.h +7 -0
@@ -40,6 +40,13 @@ static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *return arch_ftrace_regs (fregs)->regs.msr ? &arch_ftrace_regs (fregs)->regs :NULL ; } +#define arch_ftrace_fill_perf_regs (fregs, _regs) do { \ + (_regs)->result = 0; \ + (_regs)->nip = arch_ftrace_regs(fregs)->regs.nip; \ + (_regs)->gpr[1] = arch_ftrace_regs(fregs)->regs.gpr[1]; \ + asm volatile("mfmsr %0" : "=r" ((_regs)->msr)); \ + } while (0) + static __always_inline voidftrace_regs_set_instruction_pointer (struct ftrace_regs *fregs,unsigned long ip)
arch/s390/include/asm/ftrace.h +6 -0
@@ -76,6 +76,12 @@ ftrace_regs_get_frame_pointer(struct ftrace_regs *fregs)return ftrace_regs_get_stack_pointer (fregs); } +#define arch_ftrace_fill_perf_regs (fregs, _regs) do { \ + (_regs)->psw.mask = 0; \ + (_regs)->psw.addr = arch_ftrace_regs(fregs)->regs.psw.addr; \ + (_regs)->gprs[15] = arch_ftrace_regs(fregs)->regs.gprs[15]; \ + } while (0) +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS /* * When an ftrace registered caller is tracing a function that is
arch/x86/include/asm/ftrace.h +7 -0
@@ -47,6 +47,13 @@ arch_ftrace_get_regs(struct ftrace_regs *fregs)return &arch_ftrace_regs (fregs)->regs; } +#define arch_ftrace_fill_perf_regs (fregs, _regs) do { \ + (_regs)->ip = arch_ftrace_regs(fregs)->regs.ip; \ + (_regs)->sp = arch_ftrace_regs(fregs)->regs.sp; \ + (_regs)->cs = __KERNEL_CS; \ + (_regs)->flags = 0; \ + } while (0) +#define ftrace_regs_set_instruction_pointer (fregs, _ip) \ do { arch_ftrace_regs(fregs)->regs.ip = (_ip); } while (0)
include/linux/ftrace.h +31 -0
@@ -201,6 +201,37 @@ ftrace_partial_regs(struct ftrace_regs *fregs, struct pt_regs *regs)#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS */ +#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS + +/* +* Please define arch dependent pt_regs which compatible to the +* perf_arch_fetch_caller_regs() but based on ftrace_regs. +* This requires +* - user_mode(_regs) returns false (always kernel mode). +* - able to use the _regs for stack trace. +*/ +#ifndef arch_ftrace_fill_perf_regs +/* As same as perf_arch_fetch_caller_regs(), do nothing by default */ +#define arch_ftrace_fill_perf_regs (fregs, _regs) do {} while (0) +#endif + +static __always_inline struct pt_regs * +ftrace_fill_perf_regs (struct ftrace_regs *fregs,struct pt_regs *regs) +{ +arch_ftrace_fill_perf_regs (fregs, regs); +return regs; +} + +#else /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */ + +static __always_inline struct pt_regs * +ftrace_fill_perf_regs (struct ftrace_regs *fregs,struct pt_regs *regs) +{ +return &arch_ftrace_regs (fregs)->regs; +} + +#endif +/* * When true, the ftrace_regs_{get,set}_*() functions may be used on fregs. * Note: this can be true even when ftrace_get_regs() cannot provide a pt_regs.
Signature · 1 line
2.51.0
PATCH 72/385 x86/fgraph,bpf: Fix stack ORC unwind from kprobe_multi return probe
In reply to Sasha LevinFrom: Jiri Olsa <[email protected]>
[ Upstream commit 20a0bc10272fa17a44fc857c31574a8306f60d20 ]
Currently we don't get stack trace via ORC unwinder on top of fgraph exit handler. We can see that when generating stacktrace from kretprobe_multi bpf program which is based on fprobe/fgraph.
The reason is that the ORC unwind code won't get pass the return_to_handler callback installed by fgraph return probe machinery.
Solving this by creating stack frame in return_to_handler expected by ftrace_graph_ret_addr function to recover original return address and continue with the unwind.
Also updating the pt_regs data with cs/flags/rsp which are needed for successful stack retrieval from ebpf bpf_get_stackid helper.
- in get_perf_callchain we check user_mode(regs) so CS has to be set
- in perf_callchain_kernel we call perf_hw_regs(regs), so EFLAGS/FIXED has to be unset
Stable-dep-of: aea251799998 ("x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path")
--- arch/x86/include/asm/ftrace.h | 5 +++++ arch/x86/kernel/ftrace_64.S | 8 +++++++- include/linux/ftrace.h | 10 +++++++++- 3 files changed, 21 insertions(+), 2 deletions(-)
arch/x86/include/asm/ftrace.h +5 -0
@@ -47,6 +47,11 @@ arch_ftrace_get_regs(struct ftrace_regs *fregs)return &arch_ftrace_regs (fregs)->regs; } +#define arch_ftrace_partial_regs (regs) do { \ + regs->flags &= ~X86_EFLAGS_FIXED; \ + regs->cs = __KERNEL_CS; \ +} while (0) +#define arch_ftrace_fill_perf_regs (fregs, _regs) do { \ (_regs)->ip = arch_ftrace_regs(fregs)->regs.ip; \ (_regs)->sp = arch_ftrace_regs(fregs)->regs.sp; \
arch/x86/kernel/ftrace_64.S +7 -1
@@ -349,12 +349,17 @@ SYM_CODE_START(return_to_handler) UNWIND_HINT_UNDEFINED ANNOTATE_NOENDBR + /* Restore return_to_handler value that got eaten by previous ret instruction. */ + subq $8, %rsp + UNWIND_HINT_FUNC + /* Save ftrace_regs for function exit context */ subq $(FRAME_SIZE), %rsp movq %rax, RAX(%rsp) movq %rdx, RDX(%rsp) movq %rbp, RBP(%rsp) + movq %rsp, RSP(%rsp) movq %rsp, %rdi call ftrace_return_to_handler
@@ -363,7 +368,8 @@ SYM_CODE_START(return_to_handler) movq RDX(%rsp), %rdx movq RAX(%rsp), %rax - addq $(FRAME_SIZE), %rsp + addq $(FRAME_SIZE) + 8, %rsp + /* * Jump back to the old return address. This cannot be JMP_NOSPEC rdi * since IBT would demand that contain ENDBR, which simply isn't so for
include/linux/ftrace.h +9 -1
@@ -187,6 +187,10 @@ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS ) || \ defined(CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS ) +#ifndef arch_ftrace_partial_regs +#define arch_ftrace_partial_regs (regs) do {} while (0) +#endif + static __always_inline struct pt_regs *ftrace_partial_regs (struct ftrace_regs *fregs,struct pt_regs *regs) {
@@ -196,7 +200,11 @@ ftrace_partial_regs(struct ftrace_regs *fregs, struct pt_regs *regs)* Since arch_ftrace_get_regs() will check some members and may return * NULL, we can not use it. */ - return &arch_ftrace_regs(fregs)->regs; + regs = &arch_ftrace_regs (fregs)->regs; + +/* Allow arch specific updates to regs. */ +arch_ftrace_partial_regs (regs); + return regs; }#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS */
Signature · 1 line
2.51.0
PATCH 73/385 x86/fgraph,bpf: Switch kprobe_multi program stack unwind to hw_regs path
In reply to Sasha LevinFrom: Jiri Olsa <[email protected]>
[ Upstream commit aea251799998aa1b78eacdfb308f18ea114ea5b3 ]
Mahe reported missing function from stack trace on top of kprobe multi program. The missing function is the very first one in the stacktrace, the one that the bpf program is attached to.
# bpftrace -e 'kprobe:__x64_sys_newuname* { print(kstack)}'
Attaching 1 probe... do_syscall_64+134
entry_SYSCALL_64_after_hwframe+118 ('*' is used for kprobe_multi attachment)
The reason is that the previous change (the Fixes commit) fixed stack unwind for tracepoint, but removed attached function address from the stack trace on top of kprobe multi programs, which I also overlooked in the related test (check following patch).
The tracepoint and kprobe_multi have different stack setup, but use same unwind path. I think it's better to keep the previous change, which fixed tracepoint unwind and instead change the kprobe multi unwind as explained below.
The bpf program stack unwind calls perf_callchain_kernel for kernel portion and it follows two unwind paths based on X86_EFLAGS_FIXED bit in pt_regs.flags.
When the bit set we unwind from stack represented by pt_regs argument, otherwise we unwind currently executed stack up to 'first_frame' boundary.
The 'first_frame' value is taken from regs.rsp value, but ftrace_caller and ftrace_regs_caller (ftrace trampoline) functions set the regs.rsp to the previous stack frame, so we skip the attached function entry.
If we switch kprobe_multi unwind to use the X86_EFLAGS_FIXED bit, we set the start of the unwind to the attached function address. As another benefit we also cut extra unwind cycles needed to reach the 'first_frame' boundary.
The speedup can be measured with trigger bench for kprobe_multi program and stacktrace support.
- trigger bench with stacktrace on current code:
kprobe-multi : 0.810 ± 0.001M/s
kretprobe-multi: 0.808 ± 0.001M/s- and with the fix:
kprobe-multi : 1.264 ± 0.001M/s
kretprobe-multi: 1.401 ± 0.002M/sWith the fix, the entry probe stacktrace:
# bpftrace -e 'kprobe:__x64_sys_newuname* { print(kstack)}'
Attaching 1 probe... __x64_sys_newuname+9
do_syscall_64+134
entry_SYSCALL_64_after_hwframe+118The return probe skips the attached function, because it's no longer on the stack at the point of the unwind and this way is the same how standard kretprobe works.
# bpftrace -e 'kretprobe:__x64_sys_newuname* { print(kstack)}'
Attaching 1 probe... do_syscall_64+134
entry_SYSCALL_64_after_hwframe+118--- arch/x86/include/asm/ftrace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/ftrace.h +1 -1
@@ -48,7 +48,7 @@ arch_ftrace_get_regs(struct ftrace_regs *fregs) }#define arch_ftrace_partial_regs (regs) do { \ - regs->flags &= ~X86_EFLAGS_FIXED; \ + regs->flags |= X86_EFLAGS_FIXED; \ regs->cs = __KERNEL_CS; \ } while (0)
Signature · 1 line
2.51.0
PATCH 74/385 crypto: hisilicon/trng - support tfms sharing the device
In reply to Sasha LevinFrom: Weili Qian <[email protected]>
[ Upstream commit 3d3135057ff567d5c09fff4c9ef6391a684e8042 ]
Since the number of devices is limited, and the number of tfms may exceed the number of devices, to ensure that tfms can be successfully allocated, support tfms sharing the same device.
--- drivers/crypto/hisilicon/trng/trng.c | 121 +++++++++++++++++++-------- 1 file changed, 86 insertions(+), 35 deletions(-)
drivers/crypto/hisilicon/trng/trng.c +86 -35
@@ -40,6 +40,7 @@#define SEED_SHIFT_24 24#define SEED_SHIFT_16 16#define SEED_SHIFT_8 8 +#define SW_MAX_RANDOM_BYTES 65520struct hisi_trng_list {struct mutex lock;
@@ -53,8 +54,10 @@ struct hisi_trng {struct list_head list;struct hwrng rng;u32 ver; -bool is_used; -struct mutex mutex; +u32 ctx_num; +/* The bytes of the random number generated since the last seeding. */ +u32 random_bytes; +struct mutex lock; };struct hisi_trng_ctx {
@@ -63,10 +66,14 @@ struct hisi_trng_ctx {static atomic_t trng_active_devs;static struct hisi_trng_list trng_devices; +static int hisi_trng_read (struct hwrng *rng,void *buf,size_t max,bool wait); -static void hisi_trng_set_seed (struct hisi_trng *trng,const u8 *seed) +static int hisi_trng_set_seed (struct hisi_trng *trng,const u8 *seed) {u32 val, seed_reg, i; +int ret; + +writel (0x0 , trng->base +SW_DRBG_BLOCKS );for (i =0 ; i <SW_DRBG_SEED_SIZE ; i +=SW_DRBG_SEED_SIZE /SW_DRBG_SEED_REGS_NUM ) {
@@ -78,6 +85,20 @@ static void hisi_trng_set_seed(struct hisi_trng *trng, const u8 *seed) seed_reg = (i >>SW_DRBG_NUM_SHIFT ) %SW_DRBG_SEED_REGS_NUM ;writel (val, trng->base +SW_DRBG_SEED (seed_reg)); } + +writel (SW_DRBG_BLOCKS_NUM | (0x1 <<SW_DRBG_ENABLE_SHIFT ), + trng->base +SW_DRBG_BLOCKS ); +writel (0x1 , trng->base +SW_DRBG_INIT ); + ret =readl_relaxed_poll_timeout (trng->base +SW_DRBG_STATUS , + val, val &BIT (0 ),SLEEP_US ,TIMEOUT_US ); +if (ret) { +pr_err ("failed to init trng(%d)\n" , ret); +return -EIO ; + } + + trng->random_bytes =0 ; + +return 0 ; } static int hisi_trng_seed(struct crypto_rng *tfm, const u8 *seed,
@@ -85,8 +106,7 @@ static int hisi_trng_seed(struct crypto_rng *tfm, const u8 *seed, {struct hisi_trng_ctx *ctx =crypto_rng_ctx (tfm);struct hisi_trng *trng = ctx->trng; -u32 val =0 ; -int ret =0 ; +int ret;if (slen <SW_DRBG_SEED_SIZE ) { pr_err("slen(%u) is not matched with trng(%d)\n", slen,
@@ -94,43 +114,45 @@ static int hisi_trng_seed(struct crypto_rng *tfm, const u8 *seed,return -EINVAL ; } -writel (0x0 , trng->base +SW_DRBG_BLOCKS ); -hisi_trng_set_seed (trng, seed); +mutex_lock (&trng->lock); + ret =hisi_trng_set_seed (trng, seed); +mutex_unlock (&trng->lock); -writel (SW_DRBG_BLOCKS_NUM | (0x1 <<SW_DRBG_ENABLE_SHIFT ), - trng->base +SW_DRBG_BLOCKS ); -writel (0x1 , trng->base +SW_DRBG_INIT ); +return ret; +} - ret =readl_relaxed_poll_timeout (trng->base +SW_DRBG_STATUS , - val, val &BIT (0 ),SLEEP_US ,TIMEOUT_US ); -if (ret) -pr_err ("fail to init trng(%d)\n" , ret); +static int hisi_trng_reseed (struct hisi_trng *trng) +{ +u8 seed[SW_DRBG_SEED_SIZE ]; +int size; -return ret; +if (!trng->random_bytes) +return 0 ; + + size =hisi_trng_read (&trng->rng, seed,SW_DRBG_SEED_SIZE , false); +if (size !=SW_DRBG_SEED_SIZE ) +return -EIO ; + +return hisi_trng_set_seed (trng, seed); } -static int hisi_trng_generate (struct crypto_rng *tfm,const u8 *src, -unsigned int slen,u8 *dstn,unsigned int dlen) +static int hisi_trng_get_bytes (struct hisi_trng *trng,u8 *dstn,unsigned int dlen) { -struct hisi_trng_ctx *ctx =crypto_rng_ctx (tfm); -struct hisi_trng *trng = ctx->trng;u32 data[SW_DRBG_DATA_NUM ];u32 currsize =0 ;u32 val =0 ;int ret;u32 i; -if (dlen >SW_DRBG_BLOCKS_NUM *SW_DRBG_BYTES || dlen ==0 ) { -pr_err ("dlen(%u) exceeds limit(%d)!\n" , dlen, -SW_DRBG_BLOCKS_NUM *SW_DRBG_BYTES ); -return -EINVAL ; - } + ret =hisi_trng_reseed (trng); +if (ret) +return ret; do { ret = readl_relaxed_poll_timeout(trng->base + SW_DRBG_STATUS, - val, val & BIT(1), SLEEP_US, TIMEOUT_US); + val, val & BIT(1), SLEEP_US, TIMEOUT_US); if (ret) { - pr_err("fail to generate random number(%d)!\n", ret); + pr_err("failed to generate random number(%d)!\n", ret); break; }
@@ -145,30 +167,57 @@ static int hisi_trng_generate(struct crypto_rng *tfm, const u8 *src, currsize = dlen; } + trng->random_bytes +=SW_DRBG_BYTES ;writel (0x1 , trng->base +SW_DRBG_GEN ); }while (currsize < dlen);return ret; } +static int hisi_trng_generate (struct crypto_rng *tfm,const u8 *src, +unsigned int slen,u8 *dstn,unsigned int dlen) +{ +struct hisi_trng_ctx *ctx =crypto_rng_ctx (tfm); +struct hisi_trng *trng = ctx->trng; +unsigned int currsize =0 ; +unsigned int block_size; +int ret; + +if (!dstn || !dlen) { +pr_err ("output is error, dlen %u!\n" , dlen); +return -EINVAL ; + } + +do { + block_size = min_t(unsigned int, dlen - currsize, SW_MAX_RANDOM_BYTES); +mutex_lock (&trng->lock); + ret =hisi_trng_get_bytes (trng, dstn + currsize, block_size); +mutex_unlock (&trng->lock); +if (ret) +return ret; + currsize += block_size; + }while (currsize < dlen); + +return 0 ; +} +static int hisi_trng_init (struct crypto_tfm *tfm) {struct hisi_trng_ctx *ctx =crypto_tfm_ctx (tfm);struct hisi_trng *trng; -int ret = -EBUSY ; +u32 ctx_num = ~0 ;mutex_lock (&trng_devices.lock);list_for_each_entry (trng, &trng_devices.list, list) { -if (!trng->is_used) { - trng->is_used = true; +if (trng->ctx_num < ctx_num) { + ctx_num = trng->ctx_num; ctx->trng = trng; - ret =0 ; -break ; } } + ctx->trng->ctx_num++;mutex_unlock (&trng_devices.lock); -return ret; +return 0 ; }static void hisi_trng_exit (struct crypto_tfm *tfm)
@@ -176,7 +225,7 @@ static void hisi_trng_exit(struct crypto_tfm *tfm)struct hisi_trng_ctx *ctx =crypto_tfm_ctx (tfm);mutex_lock (&trng_devices.lock); - ctx->trng->is_used = false; + ctx->trng->ctx_num--;mutex_unlock (&trng_devices.lock); }
@@ -238,7 +287,7 @@ static int hisi_trng_del_from_list(struct hisi_trng *trng)int ret = -EBUSY ;mutex_lock (&trng_devices.lock); -if (!trng->is_used) { +if (!trng->ctx_num) {list_del (&trng->list); ret =0 ; }
@@ -262,7 +311,9 @@ static int hisi_trng_probe(struct platform_device *pdev)if (IS_ERR (trng->base))return PTR_ERR (trng->base); - trng->is_used = false; + trng->ctx_num =0 ; + trng->random_bytes =SW_MAX_RANDOM_BYTES ; +mutex_init (&trng->lock); trng->ver =readl (trng->base +HISI_TRNG_VERSION );if (!trng_devices.is_init) {INIT_LIST_HEAD (&trng_devices.list);
Signature · 1 line
2.51.0
PATCH 75/385 crypto: caam - fix netdev memory leak in dpaa2_caam_probe
In reply to Sasha LevinFrom: Jianpeng Chang <[email protected]>
[ Upstream commit 7d43252b3060b0ba4a192dce5dba85a3f39ffe39 ]
When commit 0e1a4d427f58 ("crypto: caam: Unembed net_dev structure in dpaa2") converted embedded net_device to dynamically allocated pointers, it added cleanup in dpaa2_dpseci_disable() but missed adding cleanup in dpaa2_dpseci_free() for error paths.
This causes memory leaks when dpaa2_dpseci_dpio_setup() fails during probe due to DPIO devices not being ready yet. The kernel's deferred probe mechanism handles the retry successfully, but the netdevs allocated during the failed probe attempt are never freed, resulting in kmemleak reports showing multiple leaked netdev-related allocations all traced back to dpaa2_caam_probe().
Fix this by preserving the CPU mask of allocated netdevs during setup and using it for cleanup in dpaa2_dpseci_free(). This approach ensures that only the CPUs that actually had netdevs allocated will be cleaned up, avoiding potential issues with CPU hotplug scenarios.
--- drivers/crypto/caam/caamalg_qi2.c | 27 +++++++++++++++------------ drivers/crypto/caam/caamalg_qi2.h | 2 ++ 2 files changed, 17 insertions(+), 12 deletions(-)
drivers/crypto/caam/caamalg_qi2.c +15 -12
@@ -4813,7 +4813,8 @@ static void dpaa2_dpseci_free(struct dpaa2_caam_priv *priv) {struct device *dev = priv->dev;struct fsl_mc_device *ls_dev =to_fsl_mc_device (dev); -int err; +struct dpaa2_caam_priv_per_cpu *ppriv; +int i, err;if (DPSECI_VER (priv->major_ver, priv->minor_ver) >DPSECI_VER (5 ,3 )) { err =dpseci_reset (priv->mc_io,0 , ls_dev->mc_handle);
@@ -4821,6 +4822,12 @@ static void dpaa2_dpseci_free(struct dpaa2_caam_priv *priv)dev_err (dev,"dpseci_reset() failed\n" ); } +for_each_cpu (i, priv->clean_mask) { + ppriv =per_cpu_ptr (priv->ppriv, i); +free_netdev (ppriv->net_dev); + } +free_cpumask_var (priv->clean_mask); +dpaa2_dpseci_congestion_free (priv);dpseci_close (priv->mc_io,0 , ls_dev->mc_handle); }
@@ -5006,16 +5013,15 @@ static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)struct device *dev = &ls_dev->dev;struct dpaa2_caam_priv *priv;struct dpaa2_caam_priv_per_cpu *ppriv; -cpumask_var_t clean_mask;int err, cpu;u8 i; err = -ENOMEM ; -if (!zalloc_cpumask_var (&clean_mask,GFP_KERNEL )) - goto err_cpumask; - priv =dev_get_drvdata (dev); +if (!zalloc_cpumask_var (&priv->clean_mask,GFP_KERNEL )) + goto err_cpumask; + priv->dev = dev; priv->dpsec_id = ls_dev->obj_desc.id;
@@ -5117,7 +5123,7 @@ static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev) err = -ENOMEM ; goto err_alloc_netdev; } -cpumask_set_cpu (cpu, clean_mask); +cpumask_set_cpu (cpu, priv->clean_mask); ppriv->net_dev->dev = *dev; netif_napi_add_tx_weight(ppriv->net_dev, &ppriv->napi,
@@ -5125,18 +5131,16 @@ static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev) DPAA2_CAAM_NAPI_WEIGHT); } - err =0 ; - goto free_cpumask; +return 0 ; err_alloc_netdev: -free_dpaa2_pcpu_netdev (priv, clean_mask); +free_dpaa2_pcpu_netdev (priv, priv->clean_mask); err_get_rx_queue:dpaa2_dpseci_congestion_free (priv); err_get_vers:dpseci_close (priv->mc_io,0 , ls_dev->mc_handle); err_open: -free_cpumask: -free_cpumask_var (clean_mask); +free_cpumask_var (priv->clean_mask); err_cpumask:return err; }
@@ -5181,7 +5185,6 @@ static int __cold dpaa2_dpseci_disable(struct dpaa2_caam_priv *priv) ppriv =per_cpu_ptr (priv->ppriv, i);napi_disable (&ppriv->napi);netif_napi_del (&ppriv->napi); -free_netdev (ppriv->net_dev); }return 0 ;
drivers/crypto/caam/caamalg_qi2.h +2 -0
@@ -42,6 +42,7 @@* @mc_io: pointer to MC portal's I/O object * @domain: IOMMU domain * @ppriv: per CPU pointers to privata data +* @clean_mask: CPU mask of CPUs that have allocated netdevs */ struct dpaa2_caam_priv {int dpsec_id;
@@ -65,6 +66,7 @@ struct dpaa2_caam_priv {struct dpaa2_caam_priv_per_cpu __percpu *ppriv;struct dentry *dfs_root; +cpumask_var_t clean_mask; };/**
Signature · 1 line
2.51.0
PATCH 76/385 bpf: Fix bpf_xdp_store_bytes proto for read-only arg
In reply to Sasha LevinFrom: Paul Chaignon <[email protected]>
[ Upstream commit 6557f1565d779851c4db9c488c49c05a47a6e72f ]
While making some maps in Cilium read-only from the BPF side, we noticed that the bpf_xdp_store_bytes proto is incorrect. In particular, the verifier was throwing the following error:
; ret = ctx_store_bytes(ctx, l3_off + offsetof(struct iphdr, saddr),
&nat->address, 4, 0); 635: (79) r1 = *(u64 *)(r10 -144) ; R1=ctx() R10=fp0 fp-144=ctx() 636: (b4) w2 = 26 ; R2=26 637: (b4) w4 = 4 ; R4=4 638: (b4) w5 = 0 ; R5=0
639: (85) call bpf_xdp_store_bytes#190 write into map forbidden, value_size=6 off=0 size=4
nat comes from a BPF_F_RDONLY_PROG map, so R3 is a PTR_TO_MAP_VALUE. The verifier checks the helper's memory access to R3 in check_mem_size_reg, as it reaches ARG_CONST_SIZE argument. The third argument has expected type ARG_PTR_TO_UNINIT_MEM, which includes the MEM_WRITE flag. The verifier thus checks for a BPF_WRITE access on R3. Given R3 points to a read-only map, the check fails.
Conversely, ARG_PTR_TO_UNINIT_MEM can also lead to the helper reading from uninitialized memory.
This patch simply fixes the expected argument type to match that of bpf_skb_store_bytes.
--- net/core/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/filter.c +1 -1
@@ -4140,7 +4140,7 @@ static const struct bpf_func_proto bpf_xdp_store_bytes_proto = { .ret_type = RET_INTEGER, .arg1_type = ARG_PTR_TO_CTX, .arg2_type = ARG_ANYTHING, - .arg3_type = ARG_PTR_TO_UNINIT_MEM, + .arg3_type = ARG_PTR_TO_MEM | MEM_RDONLY, .arg4_type = ARG_CONST_SIZE, };
Signature · 1 line
2.51.0
PATCH 77/385 genirq: Set IRQF_COND_ONESHOT in devm_request_irq().
In reply to Sasha LevinFrom: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit 943b052ded21feb84f293d40b06af3181cd0d0d7 ]
The flag IRQF_COND_ONESHOT was already force-added to request_irq() because the ACPI SCI interrupt handler is using the IRQF_ONESHOT flag which breaks all shared handlers.
devm_request_irq() needs the same change since some users, such as int0002_vgpio, are using this function instead.
Add IRQF_COND_ONESHOT to the flags passed to devm_request_irq().
--- include/linux/interrupt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/interrupt.h +1 -1
@@ -215,7 +215,7 @@ static inline int __must_check devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler, unsigned long irqflags, const char *devname, void *dev_id) { - return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags, + return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags | IRQF_COND_ONESHOT, devname, dev_id); }
Signature · 1 line
2.51.0
PATCH 78/385 platform/x86: int0002: Remove IRQF_ONESHOT from request_irq()
In reply to Sasha LevinFrom: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit f6bc712877f24dc89bdfd7bdbf1a32f3b9960b34 ]
Passing IRQF_ONESHOT ensures that the interrupt source is masked until the secondary (threaded) handler is done. If only a primary handler is used then the flag makes no sense because the interrupt cannot fire (again) while its handler is running.
The flag also prevents force-threading of the primary handler and the irq-core will warn about this.
The flag was added to match the flag on the shared handler which uses a threaded handler and therefore IRQF_ONESHOT. This is no longer needed because devm_request_irq() now passes IRQF_COND_ONESHOT for this case.
Revert adding IRQF_ONESHOT to irqflags.
--- drivers/platform/x86/intel/int0002_vgpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/int0002_vgpio.c +2 -2
@@ -195,8 +195,8 @@ static int int0002_probe(struct platform_device *pdev)* FIXME: augment this if we managed to pull handling of shared * IRQs into gpiolib. */ - ret =devm_request_irq (dev, irq, int0002_irq, -IRQF_ONESHOT |IRQF_SHARED ,"INT0002" , chip); + ret =devm_request_irq (dev, irq, int0002_irq,IRQF_SHARED ,"INT0002" , + chip);if (ret) {dev_err (dev,"Error requesting IRQ %d: %d\n" , irq, ret);return ret;
Signature · 1 line
2.51.0
PATCH 79/385 Bluetooth: btintel_pcie: Use IRQF_ONESHOT and default primary handler
In reply to Sasha LevinFrom: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit 28abed6569c87eab9071ab56c64433c2f0d9ce51 ]
There is no added value in btintel_pcie_msix_isr() compared to irq_default_primary_handler().
Using a threaded interrupt without a dedicated primary handler mandates the IRQF_ONESHOT flag to mask the interrupt source while the threaded handler is active. Otherwise the interrupt can fire again before the threaded handler had a chance to run.
Use the default primary interrupt handler by specifying NULL and set IRQF_ONESHOT so the interrupt source is masked until the secondary handler is done.
--- drivers/bluetooth/btintel_pcie.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/bluetooth/btintel_pcie.c +2 -7
@@ -798,11 +798,6 @@ static void btintel_pcie_msix_rx_handle(struct btintel_pcie_data *data) } } -static irqreturn_t btintel_pcie_msix_isr (int irq,void *data) -{ -return IRQ_WAKE_THREAD ; -} -static inline bool btintel_pcie_is_rxq_empty (struct btintel_pcie_data *data) {return data->ia.cr_hia[BTINTEL_PCIE_RXQ_NUM ] == data->ia.cr_tia[BTINTEL_PCIE_RXQ_NUM ];
@@ -896,9 +891,9 @@ static int btintel_pcie_setup_irq(struct btintel_pcie_data *data) err =devm_request_threaded_irq (&data->pdev->dev, msix_entry->vector, - btintel_pcie_msix_isr, +NULL , btintel_pcie_irq_msix_handler, -IRQF_SHARED , +IRQF_ONESHOT |IRQF_SHARED ,KBUILD_MODNAME , msix_entry);if (err) {
Signature · 1 line
2.51.0
PATCH 80/385 scsi: efct: Use IRQF_ONESHOT and default primary handler
In reply to Sasha LevinFrom: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit bd81f07e9a27c341cd7e72be95eb0b7cf3910926 ]
There is no added value in efct_intr_msix() compared to irq_default_primary_handler().
Using a threaded interrupt without a dedicated primary handler mandates the IRQF_ONESHOT flag to mask the interrupt source while the threaded handler is active. Otherwise the interrupt can fire again before the threaded handler had a chance to run.
Use the default primary interrupt handler by specifying NULL and set IRQF_ONESHOT so the interrupt source is masked until the secondary handler is done.
--- drivers/scsi/elx/efct/efct_driver.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/scsi/elx/efct/efct_driver.c +1 -7
@@ -415,12 +415,6 @@ efct_intr_thread(int irq, void *handle)return IRQ_HANDLED ; } -static irqreturn_t -efct_intr_msix (int irq,void *handle) -{ -return IRQ_WAKE_THREAD ; -} -static int efct_setup_msix (struct efct *efct,u32 num_intrs) {
@@ -450,7 +444,7 @@ efct_setup_msix(struct efct *efct, u32 num_intrs) intr_ctx->index = i; rc =request_threaded_irq (pci_irq_vector (efct->pci, i), - efct_intr_msix, efct_intr_thread,0 , +NULL , efct_intr_thread,IRQF_ONESHOT ,EFCT_DRIVER_NAME , intr_ctx);if (rc) { dev_err(&efct->pci->dev,
Signature · 1 line
2.51.0
PATCH 81/385 EDAC/altera: Remove IRQF_ONESHOT
In reply to Sasha LevinFrom: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit 5c858d6c66304b4c7579582ec5235f02d43578ea ]
Passing IRQF_ONESHOT ensures that the interrupt source is masked until the secondary (threaded) handler is done. If only a primary handler is used then the flag makes no sense because the interrupt can not fire (again) while its handler is running.
The flag also prevents force-threading of the primary handler and the irq-core will warn about this.
Remove IRQF_ONESHOT from irqflags.
--- drivers/edac/altera_edac.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/edac/altera_edac.c +4 -7
@@ -1563,8 +1563,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) goto err_release_group_1; } rc =devm_request_irq (&altdev->ddev, altdev->sb_irq, - prv->ecc_irq_handler, -IRQF_ONESHOT |IRQF_TRIGGER_HIGH , + prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB SBERR IRQ error\n" );
@@ -1587,8 +1586,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) goto err_release_group_1; } rc =devm_request_irq (&altdev->ddev, altdev->db_irq, - prv->ecc_irq_handler, -IRQF_ONESHOT |IRQF_TRIGGER_HIGH , + prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB DBERR IRQ error\n" );
@@ -1970,8 +1968,7 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac, goto err_release_group1; } rc =devm_request_irq (edac->dev, altdev->sb_irq, prv->ecc_irq_handler, -IRQF_ONESHOT |IRQF_TRIGGER_HIGH , - ecc_name, altdev); +IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {edac_printk (KERN_ERR ,EDAC_DEVICE ,"No SBERR IRQ resource\n" ); goto err_release_group1;
@@ -1993,7 +1990,7 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac, goto err_release_group1; } rc =devm_request_irq (edac->dev, altdev->db_irq, prv->ecc_irq_handler, -IRQF_ONESHOT |IRQF_TRIGGER_HIGH , +IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {edac_printk (KERN_ERR ,EDAC_DEVICE ,"No DBERR IRQ resource\n" );
Signature · 1 line
2.51.0
PATCH 82/385 mfd: wm8350-core: Use IRQF_ONESHOT
In reply to Sasha LevinFrom: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit 553b4999cbe231b5011cb8db05a3092dec168aca ]
Using a threaded interrupt without a dedicated primary handler mandates the IRQF_ONESHOT flag to mask the interrupt source while the threaded handler is active. Otherwise the interrupt can fire again before the threaded handler had a chance to run.
Mark explained that this should not happen with this hardware since it is a slow irqchip which is behind an I2C/ SPI bus but the IRQ-core will refuse to accept such a handler.
Set IRQF_ONESHOT so the interrupt source is masked until the secondary handler is done.
--- include/linux/mfd/wm8350/core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/mfd/wm8350/core.h +1 -1
@@ -663,7 +663,7 @@ static inline int wm8350_register_irq(struct wm8350 *wm8350, int irq,return -ENODEV ;return request_threaded_irq (irq + wm8350->irq_base,NULL , - handler, flags, name, data); + handler, flags |IRQF_ONESHOT , name, data); }static inline void wm8350_free_irq (struct wm8350 *wm8350,int irq,void *data)
Signature · 1 line
2.51.0
PATCH 83/385 media: pci: mg4b: Use IRQF_NO_THREAD
In reply to Sasha LevinFrom: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit ef92b98f5f6758a049898b53aa30476010db04fa ]
The interrupt handler iio_trigger_generic_data_rdy_poll() will invoke other interrupt handlers and this supposed to happen from hard interrupt context.
Use IRQF_NO_THREAD to forbid forced-threading.
--- drivers/media/pci/mgb4/mgb4_trigger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/mgb4/mgb4_trigger.c +1 -1
@@ -114,7 +114,7 @@ static int probe_trigger(struct iio_dev *indio_dev, int irq)if (!st->trig)return -ENOMEM ; - ret =request_irq (irq, &iio_trigger_generic_data_rdy_poll,0 , + ret =request_irq (irq, &iio_trigger_generic_data_rdy_poll,IRQF_NO_THREAD ,"mgb4-trigger" , st->trig);if (ret) goto error_free_trig;
Signature · 1 line
2.51.0
PATCH 84/385 sched/deadline: Clear the defer params
In reply to Sasha LevinFrom: Joel Fernandes <[email protected]>
[ Upstream commit 3cb3b27693bf30defb16aa096158a3b24583b8d2 ]
The defer params were not cleared in __dl_clear_params. Clear them.
Without this is some of my test cases are flaking and the DL timer is not starting correctly AFAICS.
--- kernel/sched/deadline.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/sched/deadline.c +3 -0
@@ -3649,6 +3649,9 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se) dl_se->dl_non_contending =0 ; dl_se->dl_overrun =0 ; dl_se->dl_server =0 ; + dl_se->dl_defer =0 ; + dl_se->dl_defer_running =0 ; + dl_se->dl_defer_armed =0 ;#ifdef CONFIG_RT_MUTEXES dl_se->pi_se = dl_se;
Signature · 1 line
2.51.0
PATCH 85/385 sched/rt: Skip currently executing CPU in rto_next_cpu()
In reply to Sasha LevinFrom: Chen Jinghuang <[email protected]>
[ Upstream commit 94894c9c477e53bcea052e075c53f89df3d2a33e ]
CPU0 becomes overloaded when hosting a CPU-bound RT task, a non-CPU-bound RT task, and a CFS task stuck in kernel space. When other CPUs switch from RT to non-RT tasks, RT load balancing (LB) is triggered; with HAVE_RT_PUSH_IPI enabled, they send IPIs to CPU0 to drive the execution of rto_push_irq_work_func. During push_rt_task on CPU0,
if next_task->prio < rq->donor->prio, resched_curr() sets NEED_RESCHED and after the push operation completes, CPU0 calls rto_next_cpu(). Since only CPU0 is overloaded in this scenario, rto_next_cpu() should ideally return -1 (no further IPI needed).
However, multiple CPUs invoking tell_cpu_to_push() during LB increments rd->rto_loop_next. Even when rd->rto_cpu is set to -1, the mismatch between rd->rto_loop and rd->rto_loop_next forces rto_next_cpu() to restart its search from -1. With CPU0 remaining overloaded (satisfying rt_nr_migratory && rt_nr_total > 1), it gets reselected, causing CPU0 to queue irq_work to itself and send self-IPIs repeatedly. As long as CPU0 stays overloaded and other CPUs run pull_rt_tasks(), it falls into an infinite self-IPI loop, which triggers a CPU hardlockup due to continuous self-interrupts.
The trigging scenario is as follows:
cpu0 cpu1 cpu2
pull_rt_task
tell_cpu_to_push
<------------irq_work_queue_onrto_push_irq_work_func
push_rt_task
resched_curr(rq) pull_rt_task
rto_next_cpu tell_cpu_to_push
<-------------------------- atomic_inc(rto_loop_next)rd->rto_loop != next
rto_next_cpu
irq_work_queue_onrto_push_irq_work_func
Fix redundant self-IPI by filtering the initiating CPU in rto_next_cpu(). This solution has been verified to effectively eliminate spurious self-IPIs and prevent CPU hardlockup scenarios.
--- kernel/sched/rt.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/sched/rt.c +5 -0
@@ -2151,6 +2151,7 @@ static void push_rt_tasks(struct rq *rq)*/ static int rto_next_cpu (struct root_domain *rd) { +int this_cpu =smp_processor_id ();int next;int cpu;
@@ -2174,6 +2175,10 @@ static int rto_next_cpu(struct root_domain *rd) rd->rto_cpu = cpu; +/* Do not send IPI to self */ +if (cpu == this_cpu) +continue ; +if (cpu < nr_cpu_ids)return cpu;
Signature · 1 line
2.51.0
PATCH 86/385 fs/tests: exec: drop duplicate bprm_stack_limits test vectors
In reply to Sasha LevinFrom: Titouan Ameline de Cadeville <[email protected]>
[ Upstream commit 46a03ea50b5f380bdb99178b8f90b39c6ba1f528 ]
Remove duplicate entries from the bprm_stack_limits KUnit test vector table. The duplicates do not add coverage and only increase test size.
--- fs/tests/exec_kunit.c | 6 ------ 1 file changed, 6 deletions(-)
fs/tests/exec_kunit.c +0 -6
@@ -87,9 +87,6 @@ static const struct bprm_stack_limits_result bprm_stack_limits_results[] = { .argc = 0, .envc = ARG_MAX / sizeof(void *) - 1 }, .expected_argmin = ULONG_MAX - sizeof(void *) },/* Raising rlim_stack / 4 to _STK_LIM / 4 * 3 will see more space. */ - { { .p = ULONG_MAX, .rlim_stack.rlim_cur = 4 * (_STK_LIM / 4 * 3), - .argc = 0, .envc = 0 }, - .expected_argmin = ULONG_MAX - (_STK_LIM / 4 * 3) + sizeof(void *) }, { { .p = ULONG_MAX, .rlim_stack.rlim_cur = 4 * (_STK_LIM / 4 * 3), .argc = 0, .envc = 0 }, .expected_argmin = ULONG_MAX - (_STK_LIM / 4 * 3) + sizeof(void *) },
@@ -103,9 +100,6 @@ static const struct bprm_stack_limits_result bprm_stack_limits_results[] = { { { .p = ULONG_MAX, .rlim_stack.rlim_cur = 4 * _STK_LIM, .argc = 0, .envc = 0 }, .expected_argmin = ULONG_MAX - (_STK_LIM / 4 * 3) + sizeof(void *) }, - { { .p = ULONG_MAX, .rlim_stack.rlim_cur = 4 * _STK_LIM, - .argc = 0, .envc = 0 }, - .expected_argmin = ULONG_MAX - (_STK_LIM / 4 * 3) + sizeof(void *) }, }; static void exec_test_bprm_stack_limits(struct kunit *test)
Signature · 1 line
2.51.0
PATCH 87/385 crypto: starfive - Fix memory leak in starfive_aes_aead_do_one_req()
In reply to Sasha LevinFrom: Zilin Guan <[email protected]>
[ Upstream commit ccb679fdae2e62ed92fd9acb25ed809c0226fcc6 ]
The starfive_aes_aead_do_one_req() function allocates rctx->adata with kzalloc() but fails to free it if sg_copy_to_buffer() or starfive_aes_hw_init() fails, which lead to memory leaks.
Since rctx->adata is unconditionally freed after the write_adata operations, ensure consistent cleanup by freeing the allocation in these earlier error paths as well.
Compile tested only. Issue found using a prototype static analysis tool and code review.
--- drivers/crypto/starfive/jh7110-aes.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/crypto/starfive/jh7110-aes.c +7 -2
@@ -673,8 +673,10 @@ static int starfive_aes_aead_do_one_req(struct crypto_engine *engine, void *areq "Failed to alloc memory for adata");if (sg_copy_to_buffer (req->src,sg_nents_for_len (req->src, cryp->assoclen), - rctx->adata, cryp->assoclen) != cryp->assoclen) + rctx->adata, cryp->assoclen) != cryp->assoclen) { +kfree (rctx->adata);return -EINVAL ; + } }if (cryp->total_in)
@@ -685,8 +687,11 @@ static int starfive_aes_aead_do_one_req(struct crypto_engine *engine, void *areq ctx->rctx = rctx; ret =starfive_aes_hw_init (ctx); -if (ret) +if (ret) { +if (cryp->assoclen) +kfree (rctx->adata);return ret; + }if (!cryp->assoclen) goto write_text;
Signature · 1 line
2.51.0
PATCH 88/385 hwrng: core - Allow runtime disabling of the HW RNG
In reply to Sasha LevinFrom: Jonathan McDowell <[email protected]>
[ Upstream commit e74b96d77da9eb5ee1b603c937c2adab5134a04b ]
The HW RNG core allows for manual selection of which RNG device to use, but does not allow for no device to be enabled. It may be desirable to do this on systems with only a single suitable hardware RNG, where we need exclusive access to other functionality on this device. In particular when performing TPM firmware upgrades this lets us ensure the kernel does not try to access the device.
Before:
root@debian-qemu-efi:~# grep "" /sys/devices/virtual/misc/hw_random/rng_* /sys/devices/virtual/misc/hw_random/rng_available:tpm-rng-0 /sys/devices/virtual/misc/hw_random/rng_current:tpm-rng-0 /sys/devices/virtual/misc/hw_random/rng_quality:1024 /sys/devices/virtual/misc/hw_random/rng_selected:0
After:
root@debian-qemu-efi:~# grep "" /sys/devices/virtual/misc/hw_random/rng_* /sys/devices/virtual/misc/hw_random/rng_available:tpm-rng-0 none /sys/devices/virtual/misc/hw_random/rng_current:tpm-rng-0 /sys/devices/virtual/misc/hw_random/rng_quality:1024 /sys/devices/virtual/misc/hw_random/rng_selected:0
root@debian-qemu-efi:~# echo none > /sys/devices/virtual/misc/hw_random/rng_current root@debian-qemu-efi:~# grep "" /sys/devices/virtual/misc/hw_random/rng_* /sys/devices/virtual/misc/hw_random/rng_available:tpm-rng-0 none /sys/devices/virtual/misc/hw_random/rng_current:none grep: /sys/devices/virtual/misc/hw_random/rng_quality: No such device /sys/devices/virtual/misc/hw_random/rng_selected:1
(Observe using bpftrace no calls to TPM being made)
root@debian-qemu-efi:~# echo "" > /sys/devices/virtual/misc/hw_random/rng_current root@debian-qemu-efi:~# grep "" /sys/devices/virtual/misc/hw_random/rng_* /sys/devices/virtual/misc/hw_random/rng_available:tpm-rng-0 none /sys/devices/virtual/misc/hw_random/rng_current:tpm-rng-0 /sys/devices/virtual/misc/hw_random/rng_quality:1024 /sys/devices/virtual/misc/hw_random/rng_selected:0
(Observe using bpftrace that calls to the TPM resume)
Stable-dep-of: cc2f39d6ac48 ("hwrng: core - use RCU and work_struct to fix race condition")
--- drivers/char/hw_random/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/char/hw_random/core.c +6 -3
@@ -334,6 +334,9 @@ static ssize_t rng_current_store(struct device *dev,if (sysfs_streq (buf,"" )) { err =enable_best_rng (); + }else if (sysfs_streq (buf,"none" )) { + cur_rng_set_by_user =1 ; +drop_current_rng (); }else {list_for_each_entry (rng, &rng_list, list) {if (sysfs_streq (rng->name, buf)) {
@@ -385,7 +388,7 @@ static ssize_t rng_available_show(struct device *dev,strlcat (buf, rng->name,PAGE_SIZE );strlcat (buf," " ,PAGE_SIZE ); } -strlcat (buf,"\n" ,PAGE_SIZE ); +strlcat (buf,"none\n" ,PAGE_SIZE );mutex_unlock (&rng_mutex);return strlen (buf);
@@ -537,8 +540,8 @@ int hwrng_register(struct hwrng *rng)/* Adjust quality field to always have a proper value */ rng->quality =min_t (u16,min_t (u16, default_quality,1024 ), rng->quality ?:1024 ); -if (!current_rng || - (!cur_rng_set_by_user && rng->quality > current_rng->quality)) { +if (!cur_rng_set_by_user && + (!current_rng || rng->quality > current_rng->quality)) {/* * Set new rng as current as the new rng source * provides better entropy quality and was not
Signature · 1 line
2.51.0
PATCH 89/385 hwrng: core - use RCU and work_struct to fix race condition
In reply to Sasha LevinFrom: Lianjie Wang <[email protected]>
[ Upstream commit cc2f39d6ac48e6e3cb2d6240bc0d6df839dd0828 ]
Currently, hwrng_fill is not cleared until the hwrng_fillfn() thread exits. Since hwrng_unregister() reads hwrng_fill outside the rng_mutex lock, a concurrent hwrng_unregister() may call kthread_stop() again on the same task.
Additionally, if hwrng_unregister() is called immediately after hwrng_register(), the stopped thread may have never been executed. Thus, hwrng_fill remains dirty even after hwrng_unregister() returns. In this case, subsequent calls to hwrng_register() will fail to start new threads, and hwrng_unregister() will call kthread_stop() on the same freed task. In both cases, a use-after-free occurs:
refcount_t: addition on 0; use-after-free.
WARNING: ... at lib/refcount.c:25 refcount_warn_saturate+0xec/0x1c0
Call Trace: kthread_stop+0x181/0x360 hwrng_unregister+0x288/0x380 virtrng_remove+0xe3/0x200
This patch fixes the race by protecting the global hwrng_fill pointer inside the rng_mutex lock, so that hwrng_fillfn() thread is stopped only once, and calls to kthread_run() and kthread_stop() are serialized with the lock held.
To avoid deadlock in hwrng_fillfn() while being stopped with the lock held, we convert current_rng to RCU, so that get_current_rng() can read current_rng without holding the lock. To remove the lock from put_rng(), we also delay the actual cleanup into a work_struct.
Since get_current_rng() no longer returns ERR_PTR values, the IS_ERR() checks are removed from its callers.
With hwrng_fill protected by the rng_mutex lock, hwrng_fillfn() can no longer clear hwrng_fill itself. Therefore, if hwrng_fillfn() returns directly after current_rng is dropped, kthread_stop() would be called on a freed task_struct later. To fix this, hwrng_fillfn() calls schedule() now to keep the task alive until being stopped. The kthread_stop() call is also moved from hwrng_unregister() to drop_current_rng(), ensuring kthread_stop() is called on all possible paths where current_rng becomes NULL, so that the thread would not wait forever.
--- drivers/char/hw_random/core.c | 168 +++++++++++++++++++++------------- include/linux/hw_random.h | 2 + 2 files changed, 107 insertions(+), 63 deletions(-)
drivers/char/hw_random/core.c +105 -63
@@ -20,23 +20,25 @@#include <linux/miscdevice.h> #include <linux/module.h> #include <linux/random.h> +#include <linux/rcupdate.h> #include <linux/sched.h> #include <linux/sched/signal.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/uaccess.h> +#include <linux/workqueue.h> #define RNG_MODULE_NAME "hw_random"#define RNG_BUFFER_SIZE (SMP_CACHE_BYTES < 32 ? 32 : SMP_CACHE_BYTES) -static struct hwrng *current_rng; +static struct hwrng __rcu *current_rng;/* the current rng has been explicitly chosen by user via sysfs */ static int cur_rng_set_by_user;static struct task_struct *hwrng_fill;/* list of registered rngs */ static LIST_HEAD (rng_list); -/* Protects rng_list and current_rng */ +/* Protects rng_list, hwrng_fill and updating on current_rng */ static DEFINE_MUTEX (rng_mutex);/* Protects rng read functions, data_avail, rng_buffer and rng_fillbuf */ static DEFINE_MUTEX (reading_mutex);
@@ -64,18 +66,39 @@ static size_t rng_buffer_size(void)return RNG_BUFFER_SIZE ; } -static inline void cleanup_rng (struct kref *kref) +static void cleanup_rng_work (struct work_struct *work) { - struct hwrng *rng = container_of(kref, struct hwrng, ref); + struct hwrng *rng = container_of(work, struct hwrng, cleanup_work); + +/* +* Hold rng_mutex here so we serialize in case they set_current_rng +* on rng again immediately. +*/ +mutex_lock (&rng_mutex); + +/* Skip if rng has been reinitialized. */ +if (kref_read (&rng->ref)) { +mutex_unlock (&rng_mutex); +return ; + }if (rng->cleanup) rng->cleanup (rng);complete (&rng->cleanup_done); +mutex_unlock (&rng_mutex); +} + +static inline void cleanup_rng (struct kref *kref) +{ + struct hwrng *rng = container_of(kref, struct hwrng, ref); + +schedule_work (&rng->cleanup_work); }static int set_current_rng (struct hwrng *rng) { +struct hwrng *old_rng;int err;BUG_ON (!mutex_is_locked (&rng_mutex));
@@ -84,8 +107,14 @@ static int set_current_rng(struct hwrng *rng)if (err)return err; -drop_current_rng (); - current_rng = rng; + old_rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); +rcu_assign_pointer (current_rng, rng); + +if (old_rng) { +synchronize_rcu (); +kref_put (&old_rng->ref, cleanup_rng); + }/* if necessary, start hwrng thread */ if (!hwrng_fill) {
@@ -101,47 +130,56 @@ static int set_current_rng(struct hwrng *rng)static void drop_current_rng (void ) { -BUG_ON (!mutex_is_locked (&rng_mutex)); -if (!current_rng) +struct hwrng *rng; + + rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); +if (!rng)return ; +RCU_INIT_POINTER (current_rng,NULL ); +synchronize_rcu (); + +if (hwrng_fill) { +kthread_stop (hwrng_fill); + hwrng_fill =NULL ; + } +/* decrease last reference for triggering the cleanup */ -kref_put (¤t_rng->ref, cleanup_rng); - current_rng =NULL ; +kref_put (&rng->ref, cleanup_rng); } -/* Returns ERR_PTR(), NULL or refcounted hwrng */ +/* Returns NULL or refcounted hwrng */ static struct hwrng *get_current_rng_nolock (void ) { -if (current_rng) -kref_get (¤t_rng->ref); +struct hwrng *rng; + + rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); +if (rng) +kref_get (&rng->ref); -return current_rng; +return rng; }static struct hwrng *get_current_rng (void ) {struct hwrng *rng; -if (mutex_lock_interruptible (&rng_mutex)) -return ERR_PTR (-ERESTARTSYS ); +rcu_read_lock (); + rng =rcu_dereference (current_rng); +if (rng) +kref_get (&rng->ref); - rng =get_current_rng_nolock (); +rcu_read_unlock (); -mutex_unlock (&rng_mutex);return rng; }static void put_rng (struct hwrng *rng) { -/* -* Hold rng_mutex here so we serialize in case they set_current_rng -* on rng again immediately. -*/ -mutex_lock (&rng_mutex);if (rng)kref_put (&rng->ref, cleanup_rng); -mutex_unlock (&rng_mutex); }static int hwrng_init (struct hwrng *rng)
@@ -206,10 +244,6 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,while (size) { rng =get_current_rng (); -if (IS_ERR (rng)) { - err =PTR_ERR (rng); - goto out; - }if (!rng) { err = -ENODEV ; goto out;
@@ -296,7 +330,7 @@ static struct miscdevice rng_miscdev = {static int enable_best_rng (void ) { -struct hwrng *rng, *new_rng =NULL ; +struct hwrng *rng, *cur_rng, *new_rng =NULL ;int ret = -ENODEV ;BUG_ON (!mutex_is_locked (&rng_mutex));
@@ -314,7 +348,9 @@ static int enable_best_rng(void) new_rng = rng; } - ret = ((new_rng == current_rng) ?0 :set_current_rng (new_rng)); + cur_rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); + ret = ((new_rng == cur_rng) ?0 :set_current_rng (new_rng));if (!ret) cur_rng_set_by_user =0 ;
@@ -364,8 +400,6 @@ static ssize_t rng_current_show(struct device *dev,struct hwrng *rng; rng =get_current_rng (); -if (IS_ERR (rng)) -return PTR_ERR (rng); ret =sysfs_emit (buf,"%s\n" , rng ? rng->name :"none" );put_rng (rng);
@@ -409,8 +443,6 @@ static ssize_t rng_quality_show(struct device *dev,struct hwrng *rng; rng =get_current_rng (); -if (IS_ERR (rng)) -return PTR_ERR (rng);if (!rng)/* no need to put_rng */ return -ENODEV ;
@@ -425,6 +457,7 @@ static ssize_t rng_quality_store(struct device *dev,struct device_attribute *attr, const char *buf, size_t len) { + struct hwrng *rng;u16 quality;int ret = -EINVAL ;
@@ -441,12 +474,13 @@ static ssize_t rng_quality_store(struct device *dev, goto out; } -if (!current_rng) { + rng =rcu_dereference_protected (current_rng,lockdep_is_held (&rng_mutex)); +if (!rng) { ret = -ENODEV ; goto out; } - current_rng->quality = quality; + rng->quality = quality; current_quality = quality;/* obsolete */ /* the best available RNG may have changed */
@@ -482,8 +516,20 @@ static int hwrng_fillfn(void *unused)struct hwrng *rng; rng =get_current_rng (); -if (IS_ERR (rng) || !rng) +if (!rng) { +/* +* Keep the task_struct alive until kthread_stop() +* is called to avoid UAF in drop_current_rng(). +*/ +while (!kthread_should_stop ()) { +set_current_state (TASK_INTERRUPTIBLE ); +if (!kthread_should_stop ()) +schedule (); + } +set_current_state (TASK_RUNNING );break ; + } +mutex_lock (&reading_mutex); rc =rng_get_data (rng, rng_fillbuf,rng_buffer_size (),1 );
@@ -511,14 +557,13 @@ static int hwrng_fillfn(void *unused)add_hwgenerator_randomness ((void *)rng_fillbuf, rc, entropy >>10 , true); } - hwrng_fill =NULL ;return 0 ; }int hwrng_register (struct hwrng *rng) {int err = -EINVAL ; -struct hwrng *tmp; +struct hwrng *cur_rng, *tmp;if (!rng->name || (!rng->data_read && !rng->read)) goto out;
@@ -533,6 +578,7 @@ int hwrng_register(struct hwrng *rng) }list_add_tail (&rng->list, &rng_list); +INIT_WORK (&rng->cleanup_work, cleanup_rng_work);init_completion (&rng->cleanup_done);complete (&rng->cleanup_done);init_completion (&rng->dying);
@@ -540,16 +586,19 @@ int hwrng_register(struct hwrng *rng)/* Adjust quality field to always have a proper value */ rng->quality =min_t (u16,min_t (u16, default_quality,1024 ), rng->quality ?:1024 ); -if (!cur_rng_set_by_user && - (!current_rng || rng->quality > current_rng->quality)) { -/* -* Set new rng as current as the new rng source -* provides better entropy quality and was not -* chosen by userspace. -*/ - err =set_current_rng (rng); -if (err) - goto out_unlock; +if (!cur_rng_set_by_user) { + cur_rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); +if (!cur_rng || rng->quality > cur_rng->quality) { +/* +* Set new rng as current as the new rng source +* provides better entropy quality and was not +* chosen by userspace. +*/ + err =set_current_rng (rng); +if (err) + goto out_unlock; + } }mutex_unlock (&rng_mutex);return 0 ;
@@ -562,14 +611,17 @@ EXPORT_SYMBOL_GPL(hwrng_register);void hwrng_unregister (struct hwrng *rng) { -struct hwrng *new_rng; +struct hwrng *cur_rng;int err;mutex_lock (&rng_mutex);list_del (&rng->list);complete_all (&rng->dying); -if (current_rng == rng) { + + cur_rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); +if (cur_rng == rng) { err =enable_best_rng ();if (err) {drop_current_rng ();
@@ -577,17 +629,7 @@ void hwrng_unregister(struct hwrng *rng) } } - new_rng =get_current_rng_nolock (); -if (list_empty (&rng_list)) { -mutex_unlock (&rng_mutex); -if (hwrng_fill) -kthread_stop (hwrng_fill); - }else -mutex_unlock (&rng_mutex); - -if (new_rng) -put_rng (new_rng); - +mutex_unlock (&rng_mutex);wait_for_completion (&rng->cleanup_done); }EXPORT_SYMBOL_GPL (hwrng_unregister);
@@ -675,7 +717,7 @@ static int __init hwrng_modinit(void) static void __exit hwrng_modexit(void) {mutex_lock (&rng_mutex); -BUG_ON (current_rng); +WARN_ON (rcu_access_pointer (current_rng));kfree (rng_buffer);kfree (rng_fillbuf);mutex_unlock (&rng_mutex);
include/linux/hw_random.h +2 -0
@@ -15,6 +15,7 @@#include <linux/completion.h> #include <linux/kref.h> #include <linux/types.h> +#include <linux/workqueue_types.h> /** * struct hwrng - Hardware Random Number Generator driver
@@ -48,6 +49,7 @@ struct hwrng {/* internal. */ struct list_head list;struct kref ref; +struct work_struct cleanup_work;struct completion cleanup_done;struct completion dying; };
Signature · 1 line
2.51.0
PATCH 90/385 pstore/ram: fix buffer overflow in persistent_ram_save_old()
In reply to Sasha LevinFrom: Sai Ritvik Tanksalkar <[email protected]>
[ Upstream commit 5669645c052f235726a85f443769b6fc02f66762 ]
persistent_ram_save_old() can be called multiple times for the same persistent_ram_zone (e.g., via ramoops_pstore_read -> ramoops_get_next_prz for PSTORE_TYPE_DMESG records).
Currently, the function only allocates prz->old_log when it is NULL, but it unconditionally updates prz->old_log_size to the current buffer size and then performs memcpy_fromio() using this new size. If the buffer size has grown since the first allocation (which can happen across different kernel boot cycles), this leads to:
1. A heap buffer overflow (OOB write) in the memcpy_fromio() calls
2. A subsequent OOB read when ramoops_pstore_read() accesses the buffer using the incorrect (larger) old_log_size
The KASAN splat would look similar to:
BUG: KASAN: slab-out-of-bounds in ramoops_pstore_read+0x... Read of size N at addr ... by task ...
The conditions are likely extremely hard to hit:
0. Crash with a ramoops write of less-than-record-max-size bytes.
1. Reboot: ramoops registers, pstore_get_records(0) reads old crash, allocates old_log with size X
2. Crash handler registered, timer started (if pstore_update_ms >= 0)
3. Oops happens (non-fatal, system continues)
4. pstore_dump() writes oops via ramoops_pstore_write() size Y (>X)
5. pstore_new_entry = 1, pstore_timer_kick() called
6. System continues running (not a panic oops)
7. Timer fires after pstore_update_ms milliseconds
8. pstore_timefunc() → schedule_work() → pstore_dowork() → pstore_get_records(1)
9. ramoops_get_next_prz() → persistent_ram_save_old()
10. buffer_size() returns Y, but old_log is X bytes
11. Y > X: memcpy_fromio() overflows heap
Requirements:
- a prior crash record exists that did not fill the record size (almost impossible since the crash handler writes as much as it can possibly fit into the record, capped by max record size and the kmsg buffer almost always exceeds the max record size)
- pstore_update_ms >= 0 (disabled by default)
- Non-fatal oops (system survives)
Free and reallocate the buffer when the new size differs from the previously allocated size. This ensures old_log always has sufficient space for the data being copied.
--- fs/pstore/ram_core.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/pstore/ram_core.c +11 -0
@@ -298,6 +298,17 @@ void persistent_ram_save_old(struct persistent_ram_zone *prz)if (!size)return ; +/* +* If the existing buffer is differently sized, free it so a new +* one is allocated. This can happen when persistent_ram_save_old() +* is called early in boot and later for a timer-triggered +* survivable crash when the crash dumps don't match in size +* (which would be extremely unlikely given kmsg buffers usually +* exceed prz buffer sizes). +*/ +if (prz->old_log && prz->old_log_size != size) +persistent_ram_free_old (prz); +if (!prz->old_log) {persistent_ram_ecc_old (prz); prz->old_log =kvzalloc (size,GFP_KERNEL );
Signature · 1 line
2.51.0
PATCH 91/385 soc: qcom: smem: handle ENOMEM error during probe
In reply to Sasha LevinFrom: Jorge Ramirez-Ortiz <[email protected]>
[ Upstream commit 0fe01a7955f4fef97e7cc6d14bfc5931c660402b ]
Fail the driver probe if the region can't be mapped
--- drivers/soc/qcom/smem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/soc/qcom/smem.c +3 -1
@@ -1211,7 +1211,9 @@ static int qcom_smem_probe(struct platform_device *pdev) smem->item_count =qcom_smem_get_item_count (smem);break ;case SMEM_GLOBAL_HEAP_VERSION : -qcom_smem_map_global (smem, size); + ret =qcom_smem_map_global (smem, size); +if (ret <0 ) +return ret; smem->item_count =SMEM_ITEM_COUNT ;break ;default :
Signature · 1 line
2.51.0
PATCH 92/385 EDAC/i5000: Fix snprintf() size calculation in calculate_dimm_size()
In reply to Sasha LevinFrom: Dan Carpenter <[email protected]>
[ Upstream commit 7b5c7e83ac405ff9ecbdd92b37a477f4288f8814 ]
The snprintf() can't really overflow because we're writing a max of 42 bytes to a PAGE_SIZE buffer. But the limit calculation doesn't take the first 11 bytes that we wrote into consideration so the limit is not correct. Just fix it for correctness even though it doesn't affect runtime.
--- drivers/edac/i5000_edac.c | 1 + 1 file changed, 1 insertion(+)
drivers/edac/i5000_edac.c +1 -0
@@ -1111,6 +1111,7 @@ static void calculate_dimm_size(struct i5000_pvt *pvt) n =snprintf (p, space," " ); p += n; + space -= n;for (branch =0 ; branch <MAX_BRANCHES ; branch++) { n =snprintf (p, space," branch %d | " , branch); p += n;
Signature · 1 line
2.51.0
PATCH 93/385 EDAC/i5400: Fix snprintf() limit calculation in calculate_dimm_size()
In reply to Sasha LevinFrom: Dan Carpenter <[email protected]>
[ Upstream commit 72f12683611344853ab030fe7d19b23970ed2bd8 ]
The snprintf() can't really overflow because we're writing a max of 42 bytes to a PAGE_SIZE buffer. But my static checker complains because the limit calculation doesn't take the first 11 space characters that we wrote into the buffer into consideration. Fix this for the sake of correctness even though it doesn't affect runtime.
Also delete an earlier "space -= n;" which was not used.
--- drivers/edac/i5400_edac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/edac/i5400_edac.c +1 -1
@@ -1025,13 +1025,13 @@ static void calculate_dimm_size(struct i5400_pvt *pvt) space -= n; } - space -= n;edac_dbg (2 ,"%s\n" , mem_buffer); p = mem_buffer; space =PAGE_SIZE ; n =snprintf (p, space," " ); p += n; + space -= n;for (branch =0 ; branch <MAX_BRANCHES ; branch++) { n =snprintf (p, space," branch %d | " , branch); p += n;
Signature · 1 line
2.51.0
PATCH 94/385 firmware: arm_ffa: Correct 32-bit response handling in NOTIFICATION_INFO_GET
In reply to Sasha LevinFrom: Sudeep Holla <[email protected]>
[ Upstream commit be4d4543f78074fbebd530ba5109d39a2a34e668 ]
The FF-A specification allows NOTIFICATION_INFO_GET to return either a 64-bit (FFA_FN64_SUCCESS) or a 32-bit (FFA_SUCCESS) response, depending on whether the firmware chooses the SMC64 or SMC32 calling convention.
The driver previously detected the response format by checking ret.a0, but still interpreted the returned ID lists (x3..x17 or w3..w7) as if they always followed the 64-bit SMC64 layout. In the SMC32 case, the upper 32 bits of each argument register are undefined by the calling convention, meaning the driver could read stale or garbage values when parsing notification IDs.
This resulted in incorrectly decoded partition/VCPU IDs whenever the FF-A firmware used an SMC32 return path.
Fix the issue by:
- Introducing logic to map list indices to the correct u16 offsets, depending on whether the response width matches the kernel word size or is a 32-bit response on a 64-bit kernel.
- Ensuring that the packed ID list is parsed using the proper layout, avoiding reads from undefined upper halves in the SMC32 case.
With this change, NOTIFICATION_INFO_GET now correctly interprets ID list entries regardless of the response width, aligning the driver with the FF-A specification.
Message-Id: <[email protected]>
--- drivers/firmware/arm_ffa/driver.c | 33 +++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/firmware/arm_ffa/driver.c +29 -4
@@ -895,10 +895,27 @@ static void __do_sched_recv_cb(u16 part_id, u16 vcpu, bool is_per_vcpu)callback (vcpu, is_per_vcpu, cb_data); } +/* +* Map logical ID index to the u16 index within the packed ID list. +* +* For native responses (FF-A width == kernel word size), IDs are +* tightly packed: idx -> idx. +* +* For 32-bit responses on a 64-bit kernel, each 64-bit register +* contributes 4 x u16 values but only the lower 2 are defined; the +* upper 2 are garbage. This mapping skips those upper halves: +* 0,1,2,3,4,5,... -> 0,1,4,5,8,9,... +*/ +static int list_idx_to_u16_idx (int idx,bool is_native_resp) +{ +return is_native_resp ? idx : idx +2 * (idx >>1 ); +} +static void ffa_notification_info_get (void ) { -int idx, list, max_ids, lists_cnt, ids_processed, ids_count[MAX_IDS_64 ]; -bool is_64b_resp; +int ids_processed, ids_count[MAX_IDS_64 ]; +int idx, list, max_ids, lists_cnt; +bool is_64b_resp, is_native_resp;ffa_value_t ret;u64 id_list;
@@ -915,6 +932,7 @@ static void ffa_notification_info_get(void) } is_64b_resp = (ret.a0 ==FFA_FN64_SUCCESS ); + is_native_resp = (ret.a0 ==FFA_FN_NATIVE (SUCCESS )); ids_processed =0 ; lists_cnt =FIELD_GET (NOTIFICATION_INFO_GET_ID_COUNT , ret.a2);
@@ -931,12 +949,16 @@ static void ffa_notification_info_get(void)/* Process IDs */ for (list =0 ; list < lists_cnt; list++) { +int u16_idx;u16 vcpu_id, part_id, *packed_id_list = (u16 *)&ret.a3;if (ids_processed >= max_ids -1 )break ; - part_id = packed_id_list[ids_processed++]; + u16_idx =list_idx_to_u16_idx (ids_processed, + is_native_resp); + part_id = packed_id_list[u16_idx]; + ids_processed++;if (ids_count[list] ==1 ) {/* Global Notification */ __do_sched_recv_cb (part_id,0 , false);
@@ -948,7 +970,10 @@ static void ffa_notification_info_get(void)if (ids_processed >= max_ids -1 )break ; - vcpu_id = packed_id_list[ids_processed++]; + u16_idx =list_idx_to_u16_idx (ids_processed, + is_native_resp); + vcpu_id = packed_id_list[u16_idx]; + ids_processed++;__do_sched_recv_cb (part_id, vcpu_id, true); }
Signature · 1 line
2.51.0
PATCH 95/385 arm64: dts: tqma8mpql-mba8mpxl: Fix HDMI CEC pad control settings
In reply to Sasha LevinFrom: Alexander Stein <[email protected]>
[ Upstream commit 8401527abb5e3a00c867b6597b8e1b29c80c9824 ]
As per datasheet of the HDMI protection IC the CEC_IC pin has been configured as open-drain.
--- arch/arm64/boot/dts/freescale/imx8mp-tqma8mpql-mba8mpxl.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/freescale/imx8mp-tqma8mpql-mba8mpxl.dts +1 -1
@@ -859,7 +859,7 @@ pinctrl_hdmi: hdmigrp { fsl,pins = <MX8MP_IOMUXC_HDMI_DDC_SCL__HDMIMIX_HDMI_SCL 0x400001c2>, <MX8MP_IOMUXC_HDMI_DDC_SDA__HDMIMIX_HDMI_SDA 0x400001c2>, <MX8MP_IOMUXC_HDMI_HPD__HDMIMIX_HDMI_HPD 0x40000010>, - <MX8MP_IOMUXC_HDMI_CEC__HDMIMIX_HDMI_CEC 0x40000010>; + <MX8MP_IOMUXC_HDMI_CEC__HDMIMIX_HDMI_CEC 0x40000030>; }; pinctrl_hoggpio2: hoggpio2grp {
Signature · 1 line
2.51.0
PATCH 96/385 arm64: dts: tqma8mpql-mba8mp-ras314: Fix HDMI CEC pad control settings
In reply to Sasha LevinFrom: Alexander Stein <[email protected]>
[ Upstream commit 53a5c1d98d1155ece4c9446c0fea55e17d08774a ]
As per datasheet of the HDMI protection IC the CEC_IC pin has been configured as open-drain.
--- .../arm64/boot/dts/freescale/imx8mp-tqma8mpql-mba8mp-ras314.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/freescale/imx8mp-tqma8mpql-mba8mp-ras314.dts +1 -1
@@ -704,7 +704,7 @@ pinctrl_hdmi: hdmigrp { fsl,pins = <MX8MP_IOMUXC_HDMI_DDC_SCL__HDMIMIX_HDMI_SCL 0x400001c2>, <MX8MP_IOMUXC_HDMI_DDC_SDA__HDMIMIX_HDMI_SDA 0x400001c2>, <MX8MP_IOMUXC_HDMI_HPD__HDMIMIX_HDMI_HPD 0x40000010>, - <MX8MP_IOMUXC_HDMI_CEC__HDMIMIX_HDMI_CEC 0x40000154>; + <MX8MP_IOMUXC_HDMI_CEC__HDMIMIX_HDMI_CEC 0x40000030>; }; pinctrl_gpt1: gpt1grp {
Signature · 1 line
2.51.0
PATCH 97/385 clk: qcom: Return correct error code in qcom_cc_probe_by_index()
In reply to Sasha LevinFrom: Haotian Zhang <[email protected]>
[ Upstream commit 1e07ebe744fb522983bd52a4a6148601675330c7 ]
When devm_platform_ioremap_resource() fails, it returns various error codes. Returning a hardcoded -ENOMEM masks the actual failure reason.
Use PTR_ERR() to propagate the actual error code returned by devm_platform_ioremap_resource() instead of -ENOMEM.
--- drivers/clk/qcom/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/qcom/common.c +1 -1
@@ -375,7 +375,7 @@ int qcom_cc_probe_by_index(struct platform_device *pdev, int index, base =devm_platform_ioremap_resource (pdev, index);if (IS_ERR (base)) -return -ENOMEM ; +return PTR_ERR (base); regmap =devm_regmap_init_mmio (&pdev->dev, base, desc->config);if (IS_ERR (regmap))
Signature · 1 line
2.51.0
PATCH 98/385 arm64: dts: qcom: sdm630: fix gpu_speed_bin size
In reply to Sasha LevinFrom: Dmitry Baryshkov <[email protected]>
[ Upstream commit e814796dfcae8905682ac3ac2dd57f512a9f6726 ]
Historically sdm630.dtsi has used 1 byte length for the gpu_speed_bin cell, although it spans two bytes (offset 5, size 7 bits). It was being accepted by the kernel because before the commit 7a06ef751077 ("nvmem:
core: fix bit offsets of more than one byte") the kernel didn't have length check. After this commit nvmem core rejects QFPROM on sdm630 / sdm660, making GPU and USB unusable on those platforms.
Set the size of the gpu_speed_bin cell to 2 bytes, fixing the parsing error. While we are at it, update the length to 8 bits as pointed out by Alexey Minnekhanov.
--- arch/arm64/boot/dts/qcom/sdm630.dtsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sdm630.dtsi +2 -2
@@ -591,8 +591,8 @@ qusb2_hstx_trim: hstx-trim@240 { }; gpu_speed_bin: gpu-speed-bin@41a0 { - reg = <0x41a2 0x1>; - bits = <5 7>; + reg = <0x41a2 0x2>; + bits = <5 8>; }; };
Signature · 1 line
2.51.0
PATCH 99/385 arm64: dts: qcom: sdm845-oneplus: Don't mark ts supply boot-on
In reply to Sasha LevinFrom: Casey Connolly <[email protected]>
[ Upstream commit c9b98b9dad9749bf2eb7336a6fca31a6af1039d7 ]
The touchscreen isn't enabled by bootloader and doesn't need to be enabled at boot, only when the driver probes, thus remove the regulator-boot-on property.
--- arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi | 1 - 1 file changed, 1 deletion(-)
arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi +0 -1
@@ -156,7 +156,6 @@ ts_1p8_supply: ts-1p8-regulator { gpio = <&tlmm 88 0>; enable-active-high; - regulator-boot-on; }; };
Signature · 1 line
2.51.0
PATCH 100/385 arm64: dts: qcom: sdm845-oneplus: Don't keep panel regulator always on
In reply to Sasha LevinFrom: Casey Connolly <[email protected]>
[ Upstream commit 45d1f42d3e84b5880cf9fab1eb24a7818320eeb7 ]
The panel regulator doesn't need to be always on, so remove this property.
--- arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi | 1 - 1 file changed, 1 deletion(-)
arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi +0 -1
@@ -252,7 +252,6 @@ vreg_l14a_1p88: ldo14 { regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>; - regulator-always-on; }; vreg_l17a_1p3: ldo17 {
Signature · 1 line
2.51.0
David Heidelberg
maintainerRe: [PATCH 6.12 100/385] arm64: dts: qcom: sdm845-oneplus: Don't keep panel regulator always on
I believe this patch SHOULDN'T be backported. The 6.12 trees for sdm845 following stable releases may have drivers and setup, which may not be able to work with regulators properly. This got fixed later with fixes to sofef00 and introduction of s6e3fc2x01 driver with proper regulator handling.
The clean (without additional patches) 6.12 stable won't work anyway here, so it would be meaningless add this patch.
Thanks
David
Quoted 30 lines · Sasha Levin
From: Casey Connolly <[email protected]>
[ Upstream commit
45d1f42d3e84b5880cf9fab1eb24a7818320eeb7]The panel regulator doesn't need to be always on, so remove this property.
Fixes 288ef8a42612 ("arm64: dts: sdm845: add oneplus6/6t devices")Signed-off-by Casey Connolly <[email protected]>Signed-off-by David Heidelberg <[email protected]>Reviewed-by Konrad Dybcio <[email protected]>Signed-off-by Bjorn Andersson <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi | 1 - 1 file changed, 1 deletion(-)arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi +0
-1@@ -252,7 +252,6 @@ vreg_l14a_1p88: ldo14 { regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>; - regulator-always-on; }; vreg_l17a_1p3: ldo17 {
Signature · 1 line
David Heidelberg
Re: [PATCH 6.12 100/385] arm64: dts: qcom: sdm845-oneplus: Don't keep panel regulator always on
Quoted 3 lines · David Heidelberg
I believe this patch SHOULDN'T be backported. The 6.12 trees for sdm845 following stable releases may have drivers and setup, which may not be able to work with regulators properly. This got fixed later with fixes to sofef00 and introduction of s6e3fc2x01 driver with proper regulator handling.
The clean (without additional patches) 6.12 stable won't work anyway here, so it would be meaningless add this patch.
Dropped, thanks!
Signature · 2 lines
Thanks, Sasha
PATCH 101/385 arm64: dts: qcom: sdm845-oneplus: Mark l14a regulator as boot-on
In reply to Sasha LevinFrom: Casey Connolly <[email protected]>
[ Upstream commit ad33ee060be46794a03d033894c9db3a9d6c1a0f ]
This regulator is used only for the display, which is enabled by the bootloader and left on for continuous splash. Mark it as such.
--- arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/qcom/sdm845-oneplus-common.dtsi +1 -0
@@ -252,6 +252,7 @@ vreg_l14a_1p88: ldo14 { regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>; + regulator-boot-on; }; vreg_l17a_1p3: ldo17 {
Signature · 1 line
2.51.0
PATCH 102/385 arm64: dts: qcom: x1e80100: Fix USB combo PHYs SS1 and SS2 ref clocks
In reply to Sasha LevinFrom: Abel Vesa <[email protected]>
[ Upstream commit 3af51501e2b8c87564b5cda43b0e5c316cf54717 ]
It seems the USB combo SS1 and SS2 ref clocks have another gate, unlike the SS0. These gates are part of the TCSR clock controller.
At least on Dell XPS 13 (9345), if the ref clock provided by the TCSR clock controller for SS1 PHY is disabled on the clk_disable_unused late initcall, the PHY fails to initialize. It doesn't happen on the SS0 PHY and the SS2 is not used on this device.
This doesn't seem to be a problem on CRD though. It might be that the RPMh has a vote for it from some other consumer and does not actually disable it when ther kernel drops its vote.
Either way, these TCSR provided clocks seem to be the correct ones for the SS1 and SS2, so use them instead.
--- arch/arm64/boot/dts/qcom/x1e80100.dtsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/x1e80100.dtsi +2 -2
@@ -2679,7 +2679,7 @@ usb_1_ss1_qmpphy: phy@fda000 { reg = <0 0x00fda000 0 0x4000>; clocks = <&gcc GCC_USB3_SEC_PHY_AUX_CLK>, - <&rpmhcc RPMH_CXO_CLK>, + <&tcsr TCSR_USB4_1_CLKREF_EN>, <&gcc GCC_USB3_SEC_PHY_COM_AUX_CLK>, <&gcc GCC_USB3_SEC_PHY_PIPE_CLK>; clock-names = "aux",
@@ -2749,7 +2749,7 @@ usb_1_ss2_qmpphy: phy@fdf000 { reg = <0 0x00fdf000 0 0x4000>; clocks = <&gcc GCC_USB3_TERT_PHY_AUX_CLK>, - <&rpmhcc RPMH_CXO_CLK>, + <&tcsr TCSR_USB4_2_CLKREF_EN>, <&gcc GCC_USB3_TERT_PHY_COM_AUX_CLK>, <&gcc GCC_USB3_TERT_PHY_PIPE_CLK>; clock-names = "aux",
Signature · 1 line
2.51.0
PATCH 103/385 arm64: dts: qcom: msm8994-octagon: Fix Analog Devices vendor prefix of AD7147
In reply to Sasha LevinFrom: Vladimir Zapolskiy <[email protected]>
[ Upstream commit 7db5fbe508deedec6c183d5056cf3c504c027f40 ]
Trivial change, Analog Devices vendor prefix is "adi", but there is a valid "ad" vendor prefix of another company, this may explain why the issue hasn't been discovered by the automatic tests.
A problem of not described compatible value is out of this change scope.
--- arch/arm64/boot/dts/qcom/msm8994-msft-lumia-octagon.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/msm8994-msft-lumia-octagon.dtsi +1 -1
@@ -378,7 +378,7 @@ &blsp2_i2c1 { status = "okay"; sideinteraction: touch@2c { - compatible = "ad,ad7147_captouch"; + compatible = "adi,ad7147_captouch"; reg = <0x2c>; pinctrl-names = "default", "sleep";
Signature · 1 line
2.51.0
PATCH 104/385 ARM: dts: allwinner: sun5i-a13-utoo-p66: delete "power-gpios" property
In reply to Sasha LevinFrom: Chen-Yu Tsai <[email protected]>
[ Upstream commit 0b2761eb1287bd9f62367cccf6626eb3107cef6f ]
The P66's device tree includes the reference design dtsi files, which defines a node and properties for the touchpanel in the common design. The P66 dts file then overrides all the properties to match its own design, but as the touchpanel model is different, a different schema is matched. This other schema uses a different name for the GPIO.
The original submission added the correct GPIO property, but did not delete the one inherited from the reference design, causing validation errors.
Explicitly delete the incorrect GPIO property.
--- arch/arm/boot/dts/allwinner/sun5i-a13-utoo-p66.dts | 1 + 1 file changed, 1 insertion(+)
arch/arm/boot/dts/allwinner/sun5i-a13-utoo-p66.dts +1 -0
@@ -102,6 +102,7 @@ &touchscreen { /* The P66 uses a different EINT then the reference design */ interrupts = <6 9 IRQ_TYPE_EDGE_FALLING>; /* EINT9 (PG9) */ /* The icn8318 binding expects wake-gpios instead of power-gpios */ + /delete-property/ power-gpios; wake-gpios = <&pio 1 3 GPIO_ACTIVE_HIGH>; /* PB3 */ touchscreen-size-x = <800>; touchscreen-size-y = <480>;
Signature · 1 line
2.51.0
PATCH 105/385 powerpc/uaccess: Move barrier_nospec() out of allow_read_{from/write}_user()
In reply to Sasha LevinFrom: Christophe Leroy <[email protected]>
[ Upstream commit 5fbc09eb0b4f4b1a4b33abebacbeee0d29f195e9 ]
Commit 74e19ef0ff80 ("uaccess: Add speculation barrier to copy_from_user()") added a redundant barrier_nospec() in copy_from_user(), because powerpc is already calling barrier_nospec() in allow_read_from_user() and allow_read_write_user(). But on other architectures that call to barrier_nospec() was missing. So change powerpc instead of reverting the above commit and having to fix other architectures one by one. This is now possible because barrier_nospec() has also been added in copy_from_user_iter().
Move barrier_nospec() out of allow_read_from_user() and allow_read_write_user(). This will also allow reuse of those functions when implementing masked user access which doesn't require barrier_nospec().
Don't add it back in raw_copy_from_user() as it is already called by copy_from_user() and copy_from_user_iter().
--- arch/powerpc/include/asm/kup.h | 2 -- arch/powerpc/include/asm/uaccess.h | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/kup.h +0 -2
@@ -134,7 +134,6 @@ static __always_inline void kuap_assert_locked(void) static __always_inline void allow_read_from_user(const void __user *from, unsigned long size) { -barrier_nospec ();allow_user_access (NULL , from, size,KUAP_READ ); }
@@ -146,7 +145,6 @@ static __always_inline void allow_write_to_user(void __user *to, unsigned long s static __always_inline void allow_read_write_user(void __user *to, const void __user *from,unsigned long size) { -barrier_nospec ();allow_user_access (to, from, size,KUAP_READ_WRITE ); }
arch/powerpc/include/asm/uaccess.h +4 -0
@@ -301,6 +301,7 @@ do { \__typeof__ (sizeof(*(ptr ))) __gu_size =sizeof (*(ptr)); \ \might_fault (); \ +barrier_nospec (); \allow_read_from_user (__gu_addr, __gu_size); \__get_user_size_allowed (__gu_val, __gu_addr, __gu_size, __gu_err); \prevent_read_from_user (__gu_addr, __gu_size); \
@@ -329,6 +330,7 @@ raw_copy_in_user(void __user *to, const void __user *from, unsigned long n) {unsigned long ret; +barrier_nospec ();allow_read_write_user (to, from, n); ret =__copy_tofrom_user (to, from, n);prevent_read_write_user (to, from, n);
@@ -415,6 +417,7 @@ static __must_check __always_inline bool user_access_begin(const void __user *ptmight_fault (); +barrier_nospec ();allow_read_write_user ((void __user *)ptr, ptr, len);return true; }
@@ -431,6 +434,7 @@ user_read_access_begin(const void __user *ptr, size_t len)might_fault (); +barrier_nospec ();allow_read_from_user (ptr, len);return true; }
Signature · 1 line
2.51.0
PATCH 106/385 soc: qcom: cmd-db: Use devm_memremap() to fix memory leak in cmd_db_dev_probe
In reply to Sasha LevinFrom: Haotian Zhang <[email protected]>
[ Upstream commit 0da7824734d8d83e6a844dd0207f071cb0c50cf4 ]
If cmd_db_magic_matches() fails after memremap() succeeds, the function returns -EINVAL without unmapping the memory region, causing a potential resource leak.
Switch to devm_memremap to automatically manage the map resource.
--- drivers/soc/qcom/cmd-db.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/soc/qcom/cmd-db.c +4 -3
@@ -349,15 +349,16 @@ static int cmd_db_dev_probe(struct platform_device *pdev)return -EINVAL ; } - cmd_db_header =memremap (rmem->base, rmem->size,MEMREMAP_WC ); -if (!cmd_db_header) { - ret = -ENOMEM ; + cmd_db_header =devm_memremap (&pdev->dev, rmem->base, rmem->size,MEMREMAP_WC ); +if (IS_ERR (cmd_db_header)) { + ret =PTR_ERR (cmd_db_header); cmd_db_header =NULL ;return ret; }if (!cmd_db_magic_matches (cmd_db_header)) {dev_err (&pdev->dev,"Invalid Command DB Magic\n" ); + cmd_db_header =NULL ;return -EINVAL ; }
Signature · 1 line
2.51.0
PATCH 107/385 soc: mediatek: svs: Fix memory leak in svs_enable_debug_write()
In reply to Sasha LevinFrom: Zilin Guan <[email protected]>
[ Upstream commit 6259094ee806fb813ca95894c65fb80e2ec98bf1 ]
In svs_enable_debug_write(), the buf allocated by memdup_user_nul() is leaked if kstrtoint() fails.
Fix this by using __free(kfree) to automatically free buf, eliminating the need for explicit kfree() calls and preventing leaks.
--- drivers/soc/mediatek/mtk-svs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/soc/mediatek/mtk-svs.c +2 -3
@@ -9,6 +9,7 @@#include <linux/bits.h> #include <linux/clk.h> #include <linux/completion.h> +#include <linux/cleanup.h> #include <linux/cpu.h> #include <linux/cpuidle.h> #include <linux/debugfs.h>
@@ -789,7 +790,7 @@ static ssize_t svs_enable_debug_write(struct file *filp,struct svs_bank *svsb =file_inode (filp)->i_private;struct svs_platform *svsp =dev_get_drvdata (svsb->dev);int enabled, ret; -char *buf =NULL ; + char *buf __free(kfree) = NULL;if (count >=PAGE_SIZE )return -EINVAL ;
@@ -807,8 +808,6 @@ static ssize_t svs_enable_debug_write(struct file *filp, svsb->mode_support =SVSB_MODE_ALL_DISABLE ; } -kfree (buf); -return count; }
Signature · 1 line
2.51.0
PATCH 108/385 powerpc/eeh: fix recursive pci_lock_rescan_remove locking in EEH event handling
In reply to Sasha LevinFrom: Narayana Murty N <[email protected]>
[ Upstream commit 815a8d2feb5615ae7f0b5befd206af0b0160614c ]
The recent commit 1010b4c012b0 ("powerpc/eeh: Make EEH driver device hotplug safe") restructured the EEH driver to improve synchronization with the PCI hotplug layer.
However, it inadvertently moved pci_lock_rescan_remove() outside its intended scope in eeh_handle_normal_event(), leading to broken PCI error reporting and improper EEH event triggering. Specifically, eeh_handle_normal_event() acquired pci_lock_rescan_remove() before calling eeh_pe_bus_get(), but eeh_pe_bus_get() itself attempts to acquire the same lock internally, causing nested locking and disrupting normal EEH event handling paths.
This patch adds a boolean parameter do_lock to _eeh_pe_bus_get(), with two public wrappers:
eeh_pe_bus_get() with locking enabled. eeh_pe_bus_get_nolock() that skips locking.
Callers that already hold pci_lock_rescan_remove() now use eeh_pe_bus_get_nolock() to avoid recursive lock acquisition.
Additionally, pci_lock_rescan_remove() calls are restored to the correct position—after eeh_pe_bus_get() and immediately before iterating affected PEs and devices. This ensures EEH-triggered PCI removes occur under proper bus rescan locking without recursive lock contention.
The eeh_pe_loc_get() function has been split into two functions:
eeh_pe_loc_get(struct eeh_pe *pe) which retrieves the loc for given PE. eeh_pe_loc_get_bus(struct pci_bus *bus) which retrieves the location code for given bus.
This resolves lockdep warnings such as:
<snip>
[ 84.964298] [ T928] ============================================
[ 84.964304] [ T928] WARNING: possible recursive locking detected
[ 84.964311] [ T928] 6.18.0-rc3 #51 Not tainted
[ 84.964315] [ T928] --------------------------------------------
[ 84.964320] [ T928] eehd/928 is trying to acquire lock:
[ 84.964324] [ T928] c000000003b29d58 (pci_rescan_remove_lock){+.+.}-{3:3}, at: pci_lock_rescan_remove+0x28/0x40
[ 84.964342] [ T928]
but task is already holding lock:
[ 84.964347] [ T928] c000000003b29d58 (pci_rescan_remove_lock){+.+.}-{3:3}, at: pci_lock_rescan_remove+0x28/0x40
[ 84.964357] [ T928]
other info that might help us debug this:
[ 84.964363] [ T928] Possible unsafe locking scenario:[ 84.964367] [ T928] CPU0
[ 84.964370] [ T928] ----
[ 84.964373] [ T928] lock(pci_rescan_remove_lock);
[ 84.964378] [ T928] lock(pci_rescan_remove_lock);
[ 84.964383] [ T928]
*** DEADLOCK ***[ 84.964388] [ T928] May be due to missing lock nesting notation
[ 84.964393] [ T928] 1 lock held by eehd/928:
[ 84.964397] [ T928] #0: c000000003b29d58 (pci_rescan_remove_lock){+.+.}-{3:3}, at: pci_lock_rescan_remove+0x28/0x40
[ 84.964408] [ T928]
stack backtrace:
[ 84.964414] [ T928] CPU: 2 UID: 0 PID: 928 Comm: eehd Not tainted 6.18.0-rc3 #51 VOLUNTARY
[ 84.964417] [ T928] Hardware name: IBM,9080-HEX POWER10 (architected) 0x800200 0xf000006 of:IBM,FW1060.00 (NH1060_022) hv:phyp pSeries
[ 84.964419] [ T928] Call Trace:
[ 84.964420] [ T928] [c0000011a7157990] [c000000001705de4] dump_stack_lvl+0xc8/0x130 (unreliable)
[ 84.964424] [ T928] [c0000011a71579d0] [c0000000002f66e0] print_deadlock_bug+0x430/0x440
[ 84.964428] [ T928] [c0000011a7157a70] [c0000000002fd0c0] __lock_acquire+0x1530/0x2d80
[ 84.964431] [ T928] [c0000011a7157ba0] [c0000000002fea54] lock_acquire+0x144/0x410
[ 84.964433] [ T928] [c0000011a7157cb0] [c0000011a7157cb0] __mutex_lock+0xf4/0x1050
[ 84.964436] [ T928] [c0000011a7157e00] [c000000000de21d8] pci_lock_rescan_remove+0x28/0x40
[ 84.964439] [ T928] [c0000011a7157e20] [c00000000004ed98] eeh_pe_bus_get+0x48/0xc0
[ 84.964442] [ T928] [c0000011a7157e50] [c000000000050434] eeh_handle_normal_event+0x64/0xa60
[ 84.964446] [ T928] [c0000011a7157f30] [c000000000051de8] eeh_event_handler+0xf8/0x190
[ 84.964450] [ T928] [c0000011a7157f90] [c0000000002747ac] kthread+0x16c/0x180
[ 84.964453] [ T928] [c0000011a7157fe0] [c00000000000ded8] start_kernel_thread+0x14/0x18</snip>
--- arch/powerpc/include/asm/eeh.h | 2 + arch/powerpc/kernel/eeh_driver.c | 11 ++--- arch/powerpc/kernel/eeh_pe.c | 74 ++++++++++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/eeh.h +2 -0
@@ -289,6 +289,8 @@ void eeh_pe_dev_traverse(struct eeh_pe *root,void eeh_pe_restore_bars (struct eeh_pe *pe);const char *eeh_pe_loc_get (struct eeh_pe *pe);struct pci_bus *eeh_pe_bus_get (struct eeh_pe *pe); +const char *eeh_pe_loc_get_bus (struct pci_bus *bus); +struct pci_bus *eeh_pe_bus_get_nolock (struct eeh_pe *pe);void eeh_show_enabled (void );int __init eeh_init (struct eeh_ops *ops);
arch/powerpc/kernel/eeh_driver.c +6 -5
@@ -846,7 +846,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)pci_lock_rescan_remove (); - bus =eeh_pe_bus_get (pe); + bus =eeh_pe_bus_get_nolock (pe);if (!bus) {pr_err ("%s: Cannot find PCI bus for PHB#%x-PE#%x\n" , __func__, pe->phb->global_number, pe->addr);
@@ -886,14 +886,15 @@ void eeh_handle_normal_event(struct eeh_pe *pe)/* Log the event */ if (pe->type &EEH_PE_PHB ) {pr_err ("EEH: Recovering PHB#%x, location: %s\n" , - pe->phb->global_number,eeh_pe_loc_get (pe)); + pe->phb->global_number,eeh_pe_loc_get_bus (bus)); }else {struct eeh_pe *phb_pe =eeh_phb_pe_get (pe->phb);pr_err ("EEH: Recovering PHB#%x-PE#%x\n" , pe->phb->global_number, pe->addr);pr_err ("EEH: PE location: %s, PHB location: %s\n" , -eeh_pe_loc_get (pe),eeh_pe_loc_get (phb_pe)); +eeh_pe_loc_get_bus (bus), +eeh_pe_loc_get_bus (eeh_pe_bus_get_nolock (phb_pe))); }#ifdef CONFIG_STACKTRACE
@@ -1098,7 +1099,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)eeh_pe_state_clear (pe,EEH_PE_PRI_BUS , true);eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); - bus =eeh_pe_bus_get (pe); + bus =eeh_pe_bus_get_nolock (pe);if (bus)pci_hp_remove_devices (bus);else
@@ -1222,7 +1223,7 @@ void eeh_handle_special_event(void) (phb_pe->state & EEH_PE_RECOVERING))continue ; - bus =eeh_pe_bus_get (phb_pe); + bus =eeh_pe_bus_get_nolock (phb_pe);if (!bus) { pr_err("%s: Cannot find PCI bus for " "PHB#%x-PE#%x\n",
arch/powerpc/kernel/eeh_pe.c +70 -4
102 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH 109/385 ARM: dts: lpc32xx: Set motor PWM #pwm-cells property value to 3 cells
In reply to Sasha LevinFrom: Vladimir Zapolskiy <[email protected]>
[ Upstream commit 65ae9ea77e1f2a20ad2866f99596df7ccdbd3b95 ]
Since commit 4cd2f417a0ac ("dt-bindings: pwm: Convert lpc32xx-pwm.txt to yaml format") both types of PWM controlles on NXP LPC32xx SoC fairly gained 3 cells, reflect it in the platform dtsi file.
The change removes a dt binding checker warning:
mpwm@400e8000: #pwm-cells:0:0: 3 was expected
Stable-dep-of: 71630e581a0e ("arm: dts: lpc32xx: add clocks property to Motor Control PWM device tree node")
--- arch/arm/boot/dts/nxp/lpc/lpc32xx.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/nxp/lpc/lpc32xx.dtsi +1 -1
@@ -301,8 +301,8 @@ i2c2: i2c@400a8000 { mpwm: mpwm@400e8000 { compatible = "nxp,lpc3220-motor-pwm"; reg = <0x400e8000 0x78>; + #pwm-cells = <3>; status = "disabled"; - #pwm-cells = <2>; }; };
Signature · 1 line
2.51.0
PATCH 110/385 arm: dts: lpc32xx: add clocks property to Motor Control PWM device tree node
In reply to Sasha LevinFrom: Vladimir Zapolskiy <[email protected]>
[ Upstream commit 71630e581a0e34c03757f5c1706f57c853b92555 ]
Motor Control PWM depends on its own supply clock, the clock gate control is present in TIMCLK_CTRL1 register.
--- arch/arm/boot/dts/nxp/lpc/lpc32xx.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm/boot/dts/nxp/lpc/lpc32xx.dtsi +1 -0
@@ -301,6 +301,7 @@ i2c2: i2c@400a8000 { mpwm: mpwm@400e8000 { compatible = "nxp,lpc3220-motor-pwm"; reg = <0x400e8000 0x78>; + clocks = <&clk LPC32XX_CLK_MCPWM>; #pwm-cells = <3>; status = "disabled"; };
Signature · 1 line
2.51.0
PATCH 111/385 arm64: dts: mediatek: mt8183-jacuzzi-pico6: Fix typo in pinmux node
In reply to Sasha LevinFrom: AngeloGioacchino Del Regno <[email protected]>
[ Upstream commit b1fc81a986c9b8089db31e21a372cc8b6514e900 ]
Rename "piins-bt-wakeup" to "pins-bt-wakeup" to fix a dtbs_check warning happening due to this typo.
--- arch/arm64/boot/dts/mediatek/mt8183-kukui-jacuzzi-pico6.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/mediatek/mt8183-kukui-jacuzzi-pico6.dts +1 -1
@@ -91,7 +91,7 @@ bluetooth@2 { &pio { bt_pins_wakeup: bt-pins-wakeup { - piins-bt-wakeup { + pins-bt-wakeup { pinmux = <PINMUX_GPIO42__FUNC_GPIO42>; input-enable; };
Signature · 1 line
2.51.0
PATCH 112/385 arm64: dts: amlogic: s4: assign mmc b clock to 24MHz
In reply to Sasha LevinFrom: Jerome Brunet <[email protected]>
[ Upstream commit 86124a8becb43eed3103f2459399daee8af2c99d ]
The amlogic MMC driver operate with the assumption that MMC clock is configured to provide 24MHz. It uses this path for low rates such as 400kHz.
This assumption did hold true until but it now, but it is apparently not the case with s4. The clock has been reported to provide 1GHz instead. This is most likely due to how the bootloader is using the MMC clock on this platform.
Regardless of why the MMC clock rate is 1GHz, if the MMC driver expects 24MHz, the clock should be properly assigned, so assign it.
--- arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/boot/dts/amlogic/meson-s4.dtsi +3 -0
@@ -833,6 +833,9 @@ sd: mmc@fe08a000 { clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_B>; status = "disabled"; + + assigned-clocks = <&clkc_periphs CLKID_SD_EMMC_B>; + assigned-clock-rates = <24000000>; }; emmc: mmc@fe08c000 {
Signature · 1 line
2.51.0
PATCH 113/385 arm64: dts: amlogic: s4: fix mmc clock assignment
In reply to Sasha LevinFrom: Jerome Brunet <[email protected]>
[ Upstream commit 3a115d42922cffc91b303992eadf220111d66c31 ]
MMC A and C are mis-represented as having their "clkin0" input connected to xtal while it is actually connected to the MMC clock, probably in an attempt to provide 24MHz to the device on this input.
Fix this and assign the clock to 24MHz to actually provide the required rate.
--- arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/amlogic/meson-s4.dtsi +8 -2
@@ -814,13 +814,16 @@ sdio: mmc@fe088000 { reg = <0x0 0xfe088000 0x0 0x800>; interrupts = <GIC_SPI 176 IRQ_TYPE_LEVEL_HIGH>; clocks = <&clkc_periphs CLKID_SDEMMC_A>, - <&xtal>, + <&clkc_periphs CLKID_SD_EMMC_A>, <&clkc_pll CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_A>; cap-sdio-irq; keep-power-in-suspend; status = "disabled"; + + assigned-clocks = <&clkc_periphs CLKID_SD_EMMC_A>; + assigned-clock-rates = <24000000>; }; sd: mmc@fe08a000 {
@@ -843,13 +846,16 @@ emmc: mmc@fe08c000 { reg = <0x0 0xfe08c000 0x0 0x800>; interrupts = <GIC_SPI 178 IRQ_TYPE_EDGE_RISING>; clocks = <&clkc_periphs CLKID_NAND>, - <&xtal>, + <&clkc_periphs CLKID_SD_EMMC_C>, <&clkc_pll CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_NAND_EMMC>; no-sdio; no-sd; status = "disabled"; + + assigned-clocks = <&clkc_periphs CLKID_SD_EMMC_C>; + assigned-clock-rates = <24000000>; }; }; };
Signature · 1 line
2.51.0
PATCH 114/385 arm64: dts: ti: k3-j784s4-main.dtsi: Move c71_3 node to appropriate order
In reply to Sasha LevinFrom: Abhash Kumar Jha <[email protected]>
[ Upstream commit 24c9d5fb8bbf5e8c9e6fc2beffeb80ac2da83de4 ]
The device tree nodes should be ordered by unit addresses in ascending order.
Correct the order by moving the c71_3 DSP node at the end as it has a higher unit address.
Stable-dep-of: 61acc4428a7f ("arm64: dts: ti: k3-j784s4-j742s2-main-common.dtsi: Refactor watchdog instances for j784s4")
--- arch/arm64/boot/dts/ti/k3-j784s4-main.dtsi | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-)
arch/arm64/boot/dts/ti/k3-j784s4-main.dtsi +13 -13
@@ -6,19 +6,6 @@ */ &cbass_main { - c71_3: dsp@67800000 { - compatible = "ti,j721s2-c71-dsp"; - reg = <0x00 0x67800000 0x00 0x00080000>, - <0x00 0x67e00000 0x00 0x0000c000>; - reg-names = "l2sram", "l1dram"; - resets = <&k3_reset 40 1>; - firmware-name = "j784s4-c71_3-fw"; - ti,sci = <&sms>; - ti,sci-dev-id = <40>; - ti,sci-proc-ids = <0x33 0xff>; - status = "disabled"; - }; - pcie2_rc: pcie@2920000 { compatible = "ti,j784s4-pcie-host"; reg = <0x00 0x02920000 0x00 0x1000>,
@@ -113,6 +100,19 @@ serdes2: serdes@5020000 { status = "disabled"; }; }; + + c71_3: dsp@67800000 { + compatible = "ti,j721s2-c71-dsp"; + reg = <0x00 0x67800000 0x00 0x00080000>, + <0x00 0x67e00000 0x00 0x0000c000>; + reg-names = "l2sram", "l1dram"; + resets = <&k3_reset 40 1>; + firmware-name = "j784s4-c71_3-fw"; + ti,sci = <&sms>; + ti,sci-dev-id = <40>; + ti,sci-proc-ids = <0x33 0xff>; + status = "disabled"; + }; }; &scm_conf {
Signature · 1 line
2.51.0
PATCH 115/385 arm64: dts: ti: k3-j784s4-j742s2-main-common.dtsi: Refactor watchdog instances for j784s4
In reply to Sasha LevinFrom: Abhash Kumar Jha <[email protected]>
[ Upstream commit 61acc4428a7f52e0a13e226ba76f2ce2ca66c065 ]
Each A72 core has one watchdog instance associated with it. Since j742s2 has 4 A72 cores, the common file should not define 8 watchdog instances.
Refactor the last 4 extra watchdogs from the common file to j784s4 specific file, as j784s4 has 8 A72 cores and thus hardware description requires 8 watchdog instances.
--- .../dts/ti/k3-j784s4-j742s2-main-common.dtsi | 36 ------------------- arch/arm64/boot/dts/ti/k3-j784s4-main.dtsi | 36 +++++++++++++++++++ 2 files changed, 36 insertions(+), 36 deletions(-)
arch/arm64/boot/dts/ti/k3-j784s4-j742s2-main-common.dtsi +0 -36
@@ -2350,42 +2350,6 @@ watchdog3: watchdog@2230000 { assigned-clock-parents = <&k3_clks 351 4>; }; - watchdog4: watchdog@2240000 { - compatible = "ti,j7-rti-wdt"; - reg = <0x00 0x2240000 0x00 0x100>; - clocks = <&k3_clks 352 0>; - power-domains = <&k3_pds 352 TI_SCI_PD_EXCLUSIVE>; - assigned-clocks = <&k3_clks 352 0>; - assigned-clock-parents = <&k3_clks 352 4>; - }; - - watchdog5: watchdog@2250000 { - compatible = "ti,j7-rti-wdt"; - reg = <0x00 0x2250000 0x00 0x100>; - clocks = <&k3_clks 353 0>; - power-domains = <&k3_pds 353 TI_SCI_PD_EXCLUSIVE>; - assigned-clocks = <&k3_clks 353 0>; - assigned-clock-parents = <&k3_clks 353 4>; - }; - - watchdog6: watchdog@2260000 { - compatible = "ti,j7-rti-wdt"; - reg = <0x00 0x2260000 0x00 0x100>; - clocks = <&k3_clks 354 0>; - power-domains = <&k3_pds 354 TI_SCI_PD_EXCLUSIVE>; - assigned-clocks = <&k3_clks 354 0>; - assigned-clock-parents = <&k3_clks 354 4>; - }; - - watchdog7: watchdog@2270000 { - compatible = "ti,j7-rti-wdt"; - reg = <0x00 0x2270000 0x00 0x100>; - clocks = <&k3_clks 355 0>; - power-domains = <&k3_pds 355 TI_SCI_PD_EXCLUSIVE>; - assigned-clocks = <&k3_clks 355 0>; - assigned-clock-parents = <&k3_clks 355 4>; - }; - /* * The following RTI instances are coupled with MCU R5Fs, c7x and * GPU so keeping them reserved as these will be used by their
arch/arm64/boot/dts/ti/k3-j784s4-main.dtsi +36 -0
@@ -6,6 +6,42 @@ */ &cbass_main { + watchdog4: watchdog@2240000 { + compatible = "ti,j7-rti-wdt"; + reg = <0x00 0x2240000 0x00 0x100>; + clocks = <&k3_clks 352 0>; + power-domains = <&k3_pds 352 TI_SCI_PD_EXCLUSIVE>; + assigned-clocks = <&k3_clks 352 0>; + assigned-clock-parents = <&k3_clks 352 4>; + }; + + watchdog5: watchdog@2250000 { + compatible = "ti,j7-rti-wdt"; + reg = <0x00 0x2250000 0x00 0x100>; + clocks = <&k3_clks 353 0>; + power-domains = <&k3_pds 353 TI_SCI_PD_EXCLUSIVE>; + assigned-clocks = <&k3_clks 353 0>; + assigned-clock-parents = <&k3_clks 353 4>; + }; + + watchdog6: watchdog@2260000 { + compatible = "ti,j7-rti-wdt"; + reg = <0x00 0x2260000 0x00 0x100>; + clocks = <&k3_clks 354 0>; + power-domains = <&k3_pds 354 TI_SCI_PD_EXCLUSIVE>; + assigned-clocks = <&k3_clks 354 0>; + assigned-clock-parents = <&k3_clks 354 4>; + }; + + watchdog7: watchdog@2270000 { + compatible = "ti,j7-rti-wdt"; + reg = <0x00 0x2270000 0x00 0x100>; + clocks = <&k3_clks 355 0>; + power-domains = <&k3_pds 355 TI_SCI_PD_EXCLUSIVE>; + assigned-clocks = <&k3_clks 355 0>; + assigned-clock-parents = <&k3_clks 355 4>; + }; + pcie2_rc: pcie@2920000 { compatible = "ti,j784s4-pcie-host"; reg = <0x00 0x02920000 0x00 0x1000>,
Signature · 1 line
2.51.0
PATCH 116/385 hwspinlock: omap: Handle devm_pm_runtime_enable() errors
In reply to Sasha LevinFrom: Haotian Zhang <[email protected]>
[ Upstream commit 3bd4edd67b034f8e1f61c86e0eb098de6179e3f2 ]
Although unlikely, devm_pm_runtime_enable() can fail due to memory allocations. Without proper error handling, the subsequent pm_runtime_resume_and_get() call may operate on incorrectly initialized runtime PM state.
Add error handling to check the return value ofdevm_pm_runtime_enable() and return on failure.
--- drivers/hwspinlock/omap_hwspinlock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwspinlock/omap_hwspinlock.c +3 -1
@@ -88,7 +88,9 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)* make sure the module is enabled and clocked before reading * the module SYSSTATUS register */ -devm_pm_runtime_enable (&pdev->dev); + ret =devm_pm_runtime_enable (&pdev->dev); +if (ret) +return ret; ret =pm_runtime_resume_and_get (&pdev->dev);if (ret <0 )return ret;
Signature · 1 line
2.51.0
PATCH 117/385 arm64: dts: amlogic: c3: assign the MMC signal clocks
In reply to Sasha LevinFrom: Jerome Brunet <[email protected]>
[ Upstream commit 69330fd2368371c4eb47d60ace6bca09763d24a0 ]
The amlogic MMC driver operate with the assumption that MMC clock is configured to provide 24MHz. It uses this path for low rates such as 400kHz.
Assign the clocks to make sure they are properly configured
--- arch/arm64/boot/dts/amlogic/amlogic-c3.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-c3.dtsi +7 -0
@@ -570,6 +570,10 @@ sdio: mmc@88000 { no-sd; resets = <&reset RESET_SD_EMMC_A>; status = "disabled"; + + assigned-clocks = <&clkc_periphs CLKID_SD_EMMC_A>; + assigned-clock-rates = <24000000>; + }; sd: mmc@8a000 {
@@ -585,6 +589,9 @@ sd: mmc@8a000 { no-sdio; resets = <&reset RESET_SD_EMMC_B>; status = "disabled"; + + assigned-clocks = <&clkc_periphs CLKID_SD_EMMC_B>; + assigned-clock-rates = <24000000>; }; nand: nand-controller@8d000 {
Signature · 1 line
2.51.0
PATCH 118/385 arm64: dts: amlogic: axg: assign the MMC signal clocks
In reply to Sasha LevinFrom: Jerome Brunet <[email protected]>
[ Upstream commit 13d3fe2318ef6e46d6fcfe13bc373827fdf2aeac ]
The amlogic MMC driver operate with the assumption that MMC clock is configured to provide 24MHz. It uses this path for low rates such as 400kHz.
Assign the clocks to make sure they are properly configured
--- arch/arm64/boot/dts/amlogic/meson-axg.dtsi | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm64/boot/dts/amlogic/meson-axg.dtsi +6 -0
@@ -1923,6 +1923,9 @@ sd_emmc_b: mmc@5000 { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_B>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_B_CLK0>; + assigned-clock-rates = <24000000>; }; sd_emmc_c: mmc@7000 {
@@ -1935,6 +1938,9 @@ sd_emmc_c: mmc@7000 { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_C>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_C_CLK0>; + assigned-clock-rates = <24000000>; }; nfc: nand-controller@7800 {
Signature · 1 line
2.51.0
PATCH 119/385 arm64: dts: amlogic: gx: assign the MMC signal clocks
In reply to Sasha LevinFrom: Jerome Brunet <[email protected]>
[ Upstream commit 406706559046eebc09a31e8ae5e78620bfd746fe ]
The amlogic MMC driver operate with the assumption that MMC clock is configured to provide 24MHz. It uses this path for low rates such as 400kHz.
Assign the clocks to make sure they are properly configured
--- arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 9 +++++++++ arch/arm64/boot/dts/amlogic/meson-gxl.dtsi | 9 +++++++++ 2 files changed, 18 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +9 -0
@@ -799,6 +799,9 @@ &sd_emmc_a { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_A>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_A_CLK0>; + assigned-clock-rates = <24000000>; }; &sd_emmc_b {
@@ -807,6 +810,9 @@ &sd_emmc_b { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_B>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_B_CLK0>; + assigned-clock-rates = <24000000>; }; &sd_emmc_c {
@@ -815,6 +821,9 @@ &sd_emmc_c { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_C>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_C_CLK0>; + assigned-clock-rates = <24000000>; }; &simplefb_hdmi {
arch/arm64/boot/dts/amlogic/meson-gxl.dtsi +9 -0
@@ -869,6 +869,9 @@ &sd_emmc_a { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_A>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_A_CLK0>; + assigned-clock-rates = <24000000>; }; &sd_emmc_b {
@@ -877,6 +880,9 @@ &sd_emmc_b { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_B>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_B_CLK0>; + assigned-clock-rates = <24000000>; }; &sd_emmc_c {
@@ -885,6 +891,9 @@ &sd_emmc_c { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_C>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_C_CLK0>; + assigned-clock-rates = <24000000>; }; &simplefb_hdmi {
Signature · 1 line
2.51.0
PATCH 120/385 arm64: dts: amlogic: g12: assign the MMC B and C signal clocks
In reply to Sasha LevinFrom: Jerome Brunet <[email protected]>
[ Upstream commit be2ff5fdb0e83e32d4ec4e68a69875cec0d14621 ]
The amlogic MMC driver operate with the assumption that MMC clock is configured to provide 24MHz. It uses this path for low rates such as 400kHz.
Assign the clocks to make sure they are properly configured
--- arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi +6 -0
@@ -2420,6 +2420,9 @@ sd_emmc_b: mmc@ffe05000 { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_B>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_B_CLK0>; + assigned-clock-rates = <24000000>; }; sd_emmc_c: mmc@ffe07000 {
@@ -2432,6 +2435,9 @@ sd_emmc_c: mmc@ffe07000 { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_C>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_C_CLK0>; + assigned-clock-rates = <24000000>; }; usb: usb@ffe09000 {
Signature · 1 line
2.51.0
PATCH 121/385 arm64: dts: amlogic: g12: assign the MMC A signal clock
In reply to Sasha LevinFrom: Jerome Brunet <[email protected]>
[ Upstream commit 3c941feaa363f1573a501452391ddf513394c84b ]
The amlogic MMC driver operate with the assumption that MMC clock is configured to provide 24MHz. It uses this path for low rates such as 400kHz.
Assign the clock to make sure it is properly configured
--- arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi +3 -0
@@ -2408,6 +2408,9 @@ sd_emmc_a: mmc@ffe03000 { <&clkc CLKID_FCLK_DIV2>; clock-names = "core", "clkin0", "clkin1"; resets = <&reset RESET_SD_EMMC_A>; + + assigned-clocks = <&clkc CLKID_SD_EMMC_A_CLK0>; + assigned-clock-rates = <24000000>; }; sd_emmc_b: mmc@ffe05000 {
Signature · 1 line
2.51.0
PATCH 122/385 arm64: dts: qcom: qrb4210-rb2: Fix UART3 wakeup IRQ storm
In reply to Sasha LevinFrom: Dmitry Baryshkov <[email protected]>
[ Upstream commit c5dc4812f6bf397b82290c540085e9ec98b47b30 ]
Follow commit 9c92d36b0b1e ("arm64: dts: qcom: qrb2210-rb1: Fix UART3 wakeup IRQ storm") and apply the similar fix to the RB2 platform.
Having RX / TX pins as pull up and wakup interrupt as high-level triggered generates an interrupt storm when trying to suspend the device. Avoid the storm by using the falling edge trigger (as all other platforms do).
--- arch/arm64/boot/dts/qcom/qrb4210-rb2.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/qrb4210-rb2.dts +1 -1
@@ -636,7 +636,7 @@ sdc2_card_det_n: sd-card-det-n-state { &uart3 { interrupts-extended = <&intc GIC_SPI 330 IRQ_TYPE_LEVEL_HIGH>, - <&tlmm 11 IRQ_TYPE_LEVEL_HIGH>; + <&tlmm 11 IRQ_TYPE_EDGE_FALLING>; pinctrl-0 = <&uart3_default>; pinctrl-1 = <&uart3_sleep>; pinctrl-names = "default", "sleep";
Signature · 1 line
2.51.0
PATCH 123/385 arm64: dts: qcom: sdm845-db845c: drop CS from SPIO0
In reply to Sasha LevinFrom: Dmitry Baryshkov <[email protected]>
[ Upstream commit 8bfb696ccdc5bcfad7a45b84c2c8a36757070e19 ]
On SDM845 SPI uses hardware-provided chip select, while specifying cs-gpio makes the driver request GPIO pin, which on DB845c conflicts with the normal host controllers pinctrl entry.
Drop the cs-gpios property to restore SPI functionality.
--- arch/arm64/boot/dts/qcom/sdm845-db845c.dts | 1 - 1 file changed, 1 deletion(-)
arch/arm64/boot/dts/qcom/sdm845-db845c.dts +0 -1
@@ -858,7 +858,6 @@ &spi0 { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&qup_spi0_default>; - cs-gpios = <&tlmm 3 GPIO_ACTIVE_LOW>; can@0 { compatible = "microchip,mcp2517fd";
Signature · 1 line
2.51.0
PATCH 124/385 arm64: dts: qcom: sdm845-db845c: specify power for WiFi CH1
In reply to Sasha LevinFrom: Dmitry Baryshkov <[email protected]>
[ Upstream commit c303e89f7f17c29981d09f8beaaf60937ae8b1f2 ]
Specify power supply for the second chain / antenna output of the onboard WiFi chip.
--- arch/arm64/boot/dts/qcom/sdm845-db845c.dts | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/boot/dts/qcom/sdm845-db845c.dts +7 -0
@@ -378,6 +378,12 @@ vreg_l21a_2p95: ldo21 { regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>; }; + vreg_l23a_3p3: ldo23 { + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3312000>; + regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>; + }; + vreg_l24a_3p075: ldo24 { regulator-min-microvolt = <3088000>; regulator-max-microvolt = <3088000>;
@@ -1163,6 +1169,7 @@ &wifi { vdd-1.8-xo-supply = <&vreg_l7a_1p8>; vdd-1.3-rfa-supply = <&vreg_l17a_1p3>; vdd-3.3-ch0-supply = <&vreg_l25a_3p3>; + vdd-3.3-ch1-supply = <&vreg_l23a_3p3>; qcom,snoc-host-cap-8bit-quirk; qcom,ath10k-calibration-variant = "Thundercomm_DB845C";
Signature · 1 line
2.51.0
PATCH 125/385 arm64: dts: qcom: x1e: bus is 40-bits (fix 64GB models)
In reply to Sasha LevinFrom: Jonathan Marek <[email protected]>
[ Upstream commit b38dd256e11a4c8bd5a893e11fc42d493939c907 ]
Unlike the phone SoCs this was copied from, x1e has a 40-bit physical bus. The upper address space is used to support more than 32GB of memory.
This fixes issues when DMA buffers are allocated outside the 36-bit range.
--- arch/arm64/boot/dts/qcom/x1e80100.dtsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/x1e80100.dtsi +2 -2
@@ -736,8 +736,8 @@ soc: soc@0 { #address-cells = <2>; #size-cells = <2>; - dma-ranges = <0 0 0 0 0x10 0>; - ranges = <0 0 0 0 0x10 0>; + dma-ranges = <0 0 0 0 0x100 0>; + ranges = <0 0 0 0 0x100 0>; gcc: clock-controller@100000 { compatible = "qcom,x1e80100-gcc";
Signature · 1 line
2.51.0
PATCH 126/385 arm64: dts: qcom: agatti: Add CX_MEM/DBGC GPU regions
In reply to Sasha LevinFrom: Konrad Dybcio <[email protected]>
[ Upstream commit 0fdcc948929a6d673bd0f90631dd6e42090c3dbd ]
Describe the GPU register regions, with the former existing but not being used much if at all on this silicon, and the latter containing various debugging levers generally related to dumping the state of the IP upon a crash.
--- arch/arm64/boot/dts/qcom/qcm2290.dtsi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/qcm2290.dtsi +6 -2
@@ -1434,8 +1434,12 @@ usb_dwc3_ss: endpoint { gpu: gpu@5900000 { compatible = "qcom,adreno-07000200", "qcom,adreno"; - reg = <0x0 0x05900000 0x0 0x40000>; - reg-names = "kgsl_3d0_reg_memory"; + reg = <0x0 0x05900000 0x0 0x40000>, + <0x0 0x0599e000 0x0 0x1000>, + <0x0 0x05961000 0x0 0x800>; + reg-names = "kgsl_3d0_reg_memory", + "cx_mem", + "cx_dbgc"; interrupts = <GIC_SPI 177 IRQ_TYPE_LEVEL_HIGH>;
Signature · 1 line
2.51.0
PATCH 127/385 arm64: dts: qcom: sm6115: Add CX_MEM/DBGC GPU regions
In reply to Sasha LevinFrom: Konrad Dybcio <[email protected]>
[ Upstream commit 78c13dac18cf0e6f6cbc6ea85d4f967e6cca9562 ]
Describe the GPU register regions, with the former existing but not being used much if at all on this silicon, and the latter containing various debugging levers generally related to dumping the state of the IP upon a crash.
--- arch/arm64/boot/dts/qcom/sm6115.dtsi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sm6115.dtsi +6 -2
@@ -1688,8 +1688,12 @@ usb_dwc3_ss: endpoint { gpu: gpu@5900000 { compatible = "qcom,adreno-610.0", "qcom,adreno"; - reg = <0x0 0x05900000 0x0 0x40000>; - reg-names = "kgsl_3d0_reg_memory"; + reg = <0x0 0x05900000 0x0 0x40000>, + <0x0 0x0599e000 0x0 0x1000>, + <0x0 0x05961000 0x0 0x800>; + reg-names = "kgsl_3d0_reg_memory", + "cx_mem", + "cx_dbgc"; /* There's no (real) GMU, so we have to handle quite a bunch of clocks! */ clocks = <&gpucc GPU_CC_GX_GFX3D_CLK>,
Signature · 1 line
2.51.0
PATCH 128/385 drm/panthor: Recover from panthor_gpu_flush_caches() failures
In reply to Sasha LevinFrom: Boris Brezillon <[email protected]>
[ Upstream commit 3c0a60195b37af83bbbaf223cd3a78945bace49e ]
We have seen a few cases where the whole memory subsystem is blocked and flush operations never complete. When that happens, we want to:
- schedule a reset, so we can recover from this situation
- in the reset path, we need to reset the pending_reqs so we can send new commands after the reset
- if more panthor_gpu_flush_caches() operations are queued after the timeout, we skip them and return -EIO directly to avoid needless waits (the memory block won't miraculously work again)
Note that we drop the WARN_ON()s because these hangs can be triggered with buggy GPU jobs created by the UMD, and there's no way we can prevent it. We do keep the error messages though.
v2:
- New patch
v3:
- Collect R-b
- Explicitly mention the fact we dropped the WARN_ON()s in the commit message
v4:
- No changes
--- drivers/gpu/drm/panthor/panthor_gpu.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/gpu/drm/panthor/panthor_gpu.c +12 -7
@@ -384,38 +384,42 @@ int panthor_gpu_l2_power_on(struct panthor_device *ptdev)int panthor_gpu_flush_caches (struct panthor_device *ptdev,u32 l2,u32 lsc,u32 other) { -bool timedout = false;unsigned long flags; +int ret =0 ;/* Serialize cache flush operations. */ guard (mutex)(&ptdev->gpu->cache_flush_lock);spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags); -if (!drm_WARN_ON (&ptdev->base, - ptdev->gpu->pending_reqs &GPU_IRQ_CLEAN_CACHES_COMPLETED )) { +if (!(ptdev->gpu->pending_reqs &GPU_IRQ_CLEAN_CACHES_COMPLETED )) { ptdev->gpu->pending_reqs |=GPU_IRQ_CLEAN_CACHES_COMPLETED ;gpu_write (ptdev,GPU_CMD ,GPU_FLUSH_CACHES (l2, lsc, other)); + }else { + ret = -EIO ; }spin_unlock_irqrestore (&ptdev->gpu->reqs_lock, flags); +if (ret) +return ret; +if (!wait_event_timeout (ptdev->gpu->reqs_acked, !(ptdev->gpu->pending_reqs &GPU_IRQ_CLEAN_CACHES_COMPLETED ),msecs_to_jiffies (100 ))) {spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags);if ((ptdev->gpu->pending_reqs &GPU_IRQ_CLEAN_CACHES_COMPLETED ) !=0 && !(gpu_read (ptdev,GPU_INT_RAWSTAT ) &GPU_IRQ_CLEAN_CACHES_COMPLETED )) - timedout = true; + ret = -ETIMEDOUT ;else ptdev->gpu->pending_reqs &= ~GPU_IRQ_CLEAN_CACHES_COMPLETED ;spin_unlock_irqrestore (&ptdev->gpu->reqs_lock, flags); } -if (timedout) { +if (ret) { +panthor_device_schedule_reset (ptdev);drm_err (&ptdev->base,"Flush caches timeout" ); -return -ETIMEDOUT ; } -return 0 ; +return ret; }/**
@@ -455,6 +459,7 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev)return -ETIMEDOUT ; } + ptdev->gpu->pending_reqs =0 ;return 0 ; }
Signature · 1 line
2.51.0
PATCH 129/385 drm/panthor: Fix the full_tick check
In reply to Sasha LevinFrom: Boris Brezillon <[email protected]>
[ Upstream commit a3c2d0b40b108bd45d44f6c1dfa33c39d577adcd ]
We have a full tick when the remaining time to the next tick is zero, not the other way around. Declare a full_tick variable so we don't get that test wrong in other places.
v2:
- Add R-b
v3:
- Collect R-b
--- drivers/gpu/drm/panthor/panthor_sched.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/panthor/panthor_sched.c +5 -2
@@ -2338,6 +2338,7 @@ static void tick_work(struct work_struct *work)u64 remaining_jiffies =0 , resched_delay;u64 now =get_jiffies_64 ();int prio, ret, cookie; +bool full_tick;if (!drm_dev_enter (&ptdev->base, &cookie))return ;
@@ -2349,15 +2350,17 @@ static void tick_work(struct work_struct *work)if (time_before64 (now, sched->resched_target)) remaining_jiffies = sched->resched_target - now; + full_tick = remaining_jiffies ==0 ; +mutex_lock (&sched->lock);if (panthor_device_reset_is_pending (sched->ptdev)) goto out_unlock; -tick_ctx_init (sched, &ctx, remaining_jiffies !=0 ); +tick_ctx_init (sched, &ctx, full_tick);if (ctx.csg_upd_failed_mask) goto out_cleanup_ctx; -if (remaining_jiffies) { +if (!full_tick) {/* Scheduling forced in the middle of a tick. Only RT groups * can preempt non-RT ones. Currently running RT groups can't be * preempted.
Signature · 1 line
2.51.0
PATCH 130/385 drm/panthor: Fix the group priority rotation logic
In reply to Sasha LevinFrom: Boris Brezillon <[email protected]>
[ Upstream commit 55429c51d5db3db24c2ad561944c6a0ca922d476 ]
When rotating group priorities, we want the group with the highest priority to go back to the end of the queue, and all other active groups to get their priority bumped, otherwise some groups will never get a chance to run with the highest priority. This implies moving the rotation itself to tick_work(), and only dealing with old group ordering in tick_ctx_insert_old_group().
v2:
- Add R-b
- Fix the commit message
v3:
- Drop the full_tick argument in tick_ctx_init()
- Collect R-b
--- drivers/gpu/drm/panthor/panthor_sched.c | 52 +++++++++++++++---------- 1 file changed, 31 insertions(+), 21 deletions(-)
drivers/gpu/drm/panthor/panthor_sched.c +31 -21
@@ -1940,31 +1940,22 @@ tick_ctx_pick_groups_from_list(const struct panthor_scheduler *sched,static void tick_ctx_insert_old_group (struct panthor_scheduler *sched,struct panthor_sched_tick_ctx *ctx, -struct panthor_group *group, -bool full_tick) +struct panthor_group *group) {struct panthor_csg_slot *csg_slot = &sched->csg_slots[group->csg_id];struct panthor_group *other_group; -if (!full_tick) { -list_add_tail (&group->run_node, &ctx->old_groups[group->priority]); -return ; - } - -/* Rotate to make sure groups with lower CSG slot -* priorities have a chance to get a higher CSG slot -* priority next time they get picked. This priority -* has an impact on resource request ordering, so it's -* important to make sure we don't let one group starve -* all other groups with the same group priority. -*/ +/* Class groups in descending priority order so we can easily rotate. */ list_for_each_entry (other_group, &ctx->old_groups[csg_slot->group->priority], run_node) {struct panthor_csg_slot *other_csg_slot = &sched->csg_slots[other_group->csg_id]; -if (other_csg_slot->priority > csg_slot->priority) { -list_add_tail (&csg_slot->group->run_node, &other_group->run_node); +/* Our group has a higher prio than the one we're testing against, +* place it just before. +*/ +if (csg_slot->priority > other_csg_slot->priority) { +list_add_tail (&group->run_node, &other_group->run_node);return ; } }
@@ -1974,8 +1965,7 @@ tick_ctx_insert_old_group(struct panthor_scheduler *sched,static void tick_ctx_init (struct panthor_scheduler *sched, -struct panthor_sched_tick_ctx *ctx, -bool full_tick) +struct panthor_sched_tick_ctx *ctx) {struct panthor_device *ptdev = sched->ptdev;struct panthor_csg_slots_upd_ctx upd_ctx;
@@ -2013,7 +2003,7 @@ tick_ctx_init(struct panthor_scheduler *sched, group->fatal_queues |=GENMASK (group->queue_count -1 ,0 ); } -tick_ctx_insert_old_group (sched, ctx, group, full_tick); +tick_ctx_insert_old_group (sched, ctx, group);csgs_upd_ctx_queue_reqs (ptdev, &upd_ctx, i, csg_iface->output->ack ^CSG_STATUS_UPDATE ,CSG_STATUS_UPDATE );
@@ -2356,7 +2346,7 @@ static void tick_work(struct work_struct *work)if (panthor_device_reset_is_pending (sched->ptdev)) goto out_unlock; -tick_ctx_init (sched, &ctx, full_tick); +tick_ctx_init (sched, &ctx);if (ctx.csg_upd_failed_mask) goto out_cleanup_ctx;
@@ -2382,9 +2372,29 @@ static void tick_work(struct work_struct *work)for (prio =PANTHOR_CSG_PRIORITY_COUNT -1 ; prio >=0 && !tick_ctx_is_full (sched, &ctx); prio--) { +struct panthor_group *old_highest_prio_group = +list_first_entry_or_null (&ctx.old_groups[prio], + struct panthor_group, run_node); + +/* Pull out the group with the highest prio for rotation. */ +if (old_highest_prio_group) +list_del (&old_highest_prio_group->run_node); + +/* Re-insert old active groups so they get a chance to run with higher prio. */ +tick_ctx_pick_groups_from_list (sched, &ctx, &ctx.old_groups[prio], true, true); + +/* Fill the remaining slots with runnable groups. */ tick_ctx_pick_groups_from_list (sched, &ctx, &sched->groups.runnable[prio], true, false); -tick_ctx_pick_groups_from_list (sched, &ctx, &ctx.old_groups[prio], true, true); + +/* Re-insert the old group with the highest prio, and give it a chance to be +* scheduled again (but with a lower prio) if there's room left. +*/ +if (old_highest_prio_group) { +list_add_tail (&old_highest_prio_group->run_node, &ctx.old_groups[prio]); +tick_ctx_pick_groups_from_list (sched, &ctx, &ctx.old_groups[prio], + true, true); + } }/* If we have free CSG slots left, pick idle groups */
Signature · 1 line
2.51.0
PATCH 131/385 drm/panthor: Fix immediate ticking on a disabled tick
In reply to Sasha LevinFrom: Boris Brezillon <[email protected]>
[ Upstream commit 4356d21994f4ff5c87305b874939b359f16f6677 ]
We have a few paths where we schedule the tick work immediately without changing the resched_target. If the tick was stopped, this would lead to a remaining_jiffies that's always > 0, and it wouldn't force a full tick in that case. Add extra checks to cover that case properly.
v2:
- Fix typo
- Simplify the code as suggested by Steve
v3:
- Collect R-b
--- drivers/gpu/drm/panthor/panthor_sched.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/panthor/panthor_sched.c +7 -2
@@ -2325,6 +2325,7 @@ static void tick_work(struct work_struct *work) tick_work.work);struct panthor_device *ptdev = sched->ptdev;struct panthor_sched_tick_ctx ctx; +u64 resched_target = sched->resched_target;u64 remaining_jiffies =0 , resched_delay;u64 now =get_jiffies_64 ();int prio, ret, cookie;
@@ -2337,8 +2338,12 @@ static void tick_work(struct work_struct *work)if (drm_WARN_ON (&ptdev->base, ret)) goto out_dev_exit; -if (time_before64 (now, sched->resched_target)) - remaining_jiffies = sched->resched_target - now; +/* If the tick is stopped, calculate when the next tick would be */ +if (resched_target ==U64_MAX ) + resched_target = sched->last_tick + sched->tick_period; + +if (time_before64 (now, resched_target)) + remaining_jiffies = resched_target - now; full_tick = remaining_jiffies ==0 ;
Signature · 1 line
2.51.0
PATCH 132/385 drm/panthor: Fix the logic that decides when to stop ticking
In reply to Sasha LevinFrom: Boris Brezillon <[email protected]>
[ Upstream commit 61d9a43d70dc3e1709ecd14a34f6d5f01e21dfc9 ]
When we have multiple active groups with the same priority, we need to keep ticking for the priority rotation to take place. If we don't do that, we might starve slots with lower priorities.
It's annoying to deal with that in tick_ctx_update_resched_target(), so let's add a ::stop_tick field to the tick context which is initialized to true, and downgraded to false as soon as we detect something that requires to tick to happen. This way we can complement the current logic with extra conditions if needed.
v2:
- Add R-b
v3:
- Drop panthor_sched_tick_ctx::min_priority (no longer relevant)
- Collect R-b
--- drivers/gpu/drm/panthor/panthor_sched.c | 44 ++++++++++--------------- 1 file changed, 17 insertions(+), 27 deletions(-)
drivers/gpu/drm/panthor/panthor_sched.c +17 -27
@@ -1853,10 +1853,10 @@ struct panthor_sched_tick_ctx {struct list_head groups[PANTHOR_CSG_PRIORITY_COUNT ];u32 idle_group_count;u32 group_count; -enum panthor_csg_priority min_priority;struct panthor_vm *vms[MAX_CS_PER_CSG ];u32 as_count;bool immediate_tick; +bool stop_tick;u32 csg_upd_failed_mask; };
@@ -1921,17 +1921,21 @@ tick_ctx_pick_groups_from_list(const struct panthor_scheduler *sched,if (!owned_by_tick_ctx)group_get (group); -list_move_tail (&group->run_node, &ctx->groups[group->priority]); ctx->group_count++; + +/* If we have more than one active group with the same priority, +* we need to keep ticking to rotate the CSG priority. +*/ if (group_is_idle (group)) ctx->idle_group_count++; +else if (!list_empty (&ctx->groups[group->priority])) + ctx->stop_tick = false; + +list_move_tail (&group->run_node, &ctx->groups[group->priority]);if (i == ctx->as_count) ctx->vms[ctx->as_count++] = group->vm; -if (ctx->min_priority > group->priority) - ctx->min_priority = group->priority; -if (tick_ctx_is_full (sched, ctx))return ; }
@@ -1975,7 +1979,7 @@ tick_ctx_init(struct panthor_scheduler *sched,memset (ctx,0 ,sizeof (*ctx));csgs_upd_ctx_init (&upd_ctx); - ctx->min_priority =PANTHOR_CSG_PRIORITY_COUNT ; + ctx->stop_tick = true;for (i =0 ; i <ARRAY_SIZE (ctx->groups); i++) {INIT_LIST_HEAD (&ctx->groups[i]);INIT_LIST_HEAD (&ctx->old_groups[i]);
@@ -2287,32 +2291,18 @@ static u64 tick_ctx_update_resched_target(struct panthor_scheduler *sched, const struct panthor_sched_tick_ctx *ctx) { -/* We had space left, no need to reschedule until some external event happens. */ -if (!tick_ctx_is_full (sched, ctx)) - goto no_tick; - -/* If idle groups were scheduled, no need to wake up until some external -* event happens (group unblocked, new job submitted, ...). -*/ -if (ctx->idle_group_count) - goto no_tick; + u64 resched_target; -if (drm_WARN_ON (&sched->ptdev->base, ctx->min_priority >=PANTHOR_CSG_PRIORITY_COUNT )) +if (ctx->stop_tick) goto no_tick; -/* If there are groups of the same priority waiting, we need to -* keep the scheduler ticking, otherwise, we'll just wait for -* new groups with higher priority to be queued. -*/ -if (!list_empty (&sched->groups.runnable[ctx->min_priority])) { -u64 resched_target = sched->last_tick + sched->tick_period; + resched_target = sched->last_tick + sched->tick_period; -if (time_before64 (sched->resched_target, sched->last_tick) || -time_before64 (resched_target, sched->resched_target)) - sched->resched_target = resched_target; +if (time_before64 (sched->resched_target, sched->last_tick) || +time_before64 (resched_target, sched->resched_target)) + sched->resched_target = resched_target; -return sched->resched_target - sched->last_tick; - } +return sched->resched_target - sched->last_tick; no_tick: sched->resched_target =U64_MAX ;
Signature · 1 line
2.51.0
PATCH 133/385 drm/panthor: Make sure we resume the tick when new jobs are submitted
In reply to Sasha LevinFrom: Boris Brezillon <[email protected]>
[ Upstream commit 99820b4b7e50d9651f01d2d55b6b9ba92dcc5b99 ]
If the group is already assigned a slot but was idle before this job submission, we need to make sure the priority rotation happens in the future. Extract the existing logic living in group_schedule_locked() and call this new sched_resume_tick() helper from the "group is assigned a slot" path.
v2:
- Add R-b
v3:
- Re-use queue_mask to clear the bit
- Collect R-b
--- drivers/gpu/drm/panthor/panthor_sched.c | 43 +++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-)
drivers/gpu/drm/panthor/panthor_sched.c +34 -9
@@ -2514,14 +2514,33 @@ static void sync_upd_work(struct work_struct *work)sched_queue_delayed_work (sched, tick,0 ); } +static void sched_resume_tick (struct panthor_device *ptdev) +{ +struct panthor_scheduler *sched = ptdev->scheduler; +u64 delay_jiffies, now; + +drm_WARN_ON (&ptdev->base, sched->resched_target !=U64_MAX ); + +/* Scheduler tick was off, recalculate the resched_target based on the +* last tick event, and queue the scheduler work. +*/ + now =get_jiffies_64 (); + sched->resched_target = sched->last_tick + sched->tick_period; +if (sched->used_csg_slot_count == sched->csg_slot_count && +time_before64 (now, sched->resched_target)) + delay_jiffies = min_t(unsigned long, sched->resched_target - now, ULONG_MAX); +else + delay_jiffies =0 ; + +sched_queue_delayed_work (sched, tick, delay_jiffies); +} +static void group_schedule_locked (struct panthor_group *group,u32 queue_mask) {struct panthor_device *ptdev = group->ptdev;struct panthor_scheduler *sched = ptdev->scheduler;struct list_head *queue = &sched->groups.runnable[group->priority]; -u64 delay_jiffies =0 ;bool was_idle; -u64 now;if (!group_can_run (group))return ;
@@ -2566,13 +2585,7 @@ static void group_schedule_locked(struct panthor_group *group, u32 queue_mask)/* Scheduler tick was off, recalculate the resched_target based on the * last tick event, and queue the scheduler work. */ - now =get_jiffies_64 (); - sched->resched_target = sched->last_tick + sched->tick_period; -if (sched->used_csg_slot_count == sched->csg_slot_count && -time_before64 (now, sched->resched_target)) - delay_jiffies = min_t(unsigned long, sched->resched_target - now, ULONG_MAX); - -sched_queue_delayed_work (sched, tick, delay_jiffies); +sched_resume_tick (ptdev); } static void queue_stop(struct panthor_queue *queue,
@@ -3129,6 +3142,18 @@ queue_run_job(struct drm_sched_job *sched_job)group_schedule_locked (group,BIT (job->queue_idx)); }else { +u32 queue_mask =BIT (job->queue_idx); +bool resume_tick =group_is_idle (group) && + (group->idle_queues & queue_mask) && + !(group->blocked_queues & queue_mask) && + sched->resched_target ==U64_MAX ; + +/* We just added something to the queue, so it's no longer idle. */ + group->idle_queues &= ~queue_mask; + +if (resume_tick) +sched_resume_tick (ptdev); +gpu_write (ptdev,CSF_DOORBELL (queue->doorbell_id),1 );if (!sched->pm.has_ref && !(group->blocked_queues &BIT (job->queue_idx))) {
Signature · 1 line
2.51.0