RDMA/siw: Fix potential NULL pointer dereference in header processing
Subsystems (188)
PATCH 1/283 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
@@ -1456,7 +1456,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/283 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/283 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/283 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/283 rcu: s/boost_kthread_mutex/kthread_mutex
In reply to Sasha LevinFrom: Frederic Weisbecker <[email protected]>
[ Upstream commit 7836b270607676ed1c0c6a4a840a2ede9437a6a1 ]
This mutex is currently protecting per node boost kthreads creation and affinity setting across CPU hotplug operations.
Since the expedited kworkers will soon be split per node as well, they will be subject to the same concurrency constraints against hotplug.
Therefore their creation and affinity tuning operations will be grouped with those of boost kthreads and then rely on the same mutex.
To prepare for that, generalize its name.
Stable-dep-of: d41e37f26b31 ("rcu: Fix rcu_read_unlock() deadloop due to softirq")
--- kernel/rcu/tree.c | 2 +- kernel/rcu/tree.h | 2 +- kernel/rcu/tree_plugin.h | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-)
kernel/rcu/tree.c +1 -1
@@ -4874,7 +4874,7 @@ static void __init rcu_init_one(void)init_waitqueue_head (&rnp->exp_wq[2 ]);init_waitqueue_head (&rnp->exp_wq[3 ]);spin_lock_init (&rnp->exp_lock); -mutex_init (&rnp->boost_kthread_mutex); +mutex_init (&rnp->kthread_mutex);raw_spin_lock_init (&rnp->exp_poll_lock); rnp->exp_seq_poll_rq =RCU_GET_STATE_COMPLETED ;INIT_WORK (&rnp->exp_poll_wq, sync_rcu_do_polled_gp);
kernel/rcu/tree.h +1 -1
@@ -113,7 +113,7 @@ struct rcu_node {/* side effect, not as a lock. */ unsigned long boost_time;/* When to start boosting (jiffies). */ -struct mutex boost_kthread_mutex; +struct mutex kthread_mutex;/* Exclusion for thread spawning and affinity */ /* manipulation. */ struct task_struct *boost_kthread_task;
kernel/rcu/tree_plugin.h +5 -5
@@ -1229,7 +1229,7 @@ static void rcu_spawn_one_boost_kthread(struct rcu_node *rnp)struct sched_param sp;struct task_struct *t; -mutex_lock (&rnp->boost_kthread_mutex); +mutex_lock (&rnp->kthread_mutex);if (rnp->boost_kthread_task || !rcu_scheduler_fully_active) goto out;
@@ -1246,7 +1246,7 @@ static void rcu_spawn_one_boost_kthread(struct rcu_node *rnp)wake_up_process (t);/* get to TASK_INTERRUPTIBLE quickly. */ out: -mutex_unlock (&rnp->boost_kthread_mutex); +mutex_unlock (&rnp->kthread_mutex); }/*
@@ -1258,7 +1258,7 @@ static void rcu_spawn_one_boost_kthread(struct rcu_node *rnp)* no outgoing CPU. If there are no CPUs left in the affinity set, * this function allows the kthread to execute on any CPU. * -* Any future concurrent calls are serialized via ->boost_kthread_mutex. +* Any future concurrent calls are serialized via ->kthread_mutex. */ static void rcu_boost_kthread_setaffinity (struct rcu_node *rnp,int outgoingcpu) {
@@ -1271,7 +1271,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)return ;if (!zalloc_cpumask_var (&cm,GFP_KERNEL ))return ; -mutex_lock (&rnp->boost_kthread_mutex); +mutex_lock (&rnp->kthread_mutex); mask =rcu_rnp_online_cpus (rnp);for_each_leaf_node_possible_cpu (rnp, cpu) if ((mask & leaf_node_cpu_bit(rnp, cpu)) &&
@@ -1284,7 +1284,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)cpumask_clear_cpu (outgoingcpu, cm); }set_cpus_allowed_ptr (t, cm); -mutex_unlock (&rnp->boost_kthread_mutex); +mutex_unlock (&rnp->kthread_mutex);free_cpumask_var (cm); }
Signature · 1 line
2.51.0
PATCH 6/283 rcu/exp: Move expedited kthread worker creation functions above rcutree_prepare_cpu()
In reply to Sasha LevinFrom: Frederic Weisbecker <[email protected]>
[ Upstream commit c19e5d3b497a3036f800edf751dc7814e3e887e1 ]
The expedited kthread worker performing the per node initialization is going to be split into per node kthreads. As such, the future per node kthread creation will need to be called from CPU hotplug callbacks instead of an initcall, right beside the per node boost kthread creation.
To prepare for that, move the kthread worker creation above rcutree_prepare_cpu() as a first step to make the review smoother for the upcoming modifications.
No intended functional change.
Stable-dep-of: d41e37f26b31 ("rcu: Fix rcu_read_unlock() deadloop due to softirq")
--- kernel/rcu/tree.c | 96 +++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 48 deletions(-)
kernel/rcu/tree.c +48 -48
@@ -4379,6 +4379,54 @@ rcu_boot_init_percpu_data(int cpu)rcu_boot_init_nocb_percpu_data (rdp); } +#ifdef CONFIG_RCU_EXP_KTHREAD +struct kthread_worker *rcu_exp_gp_kworker; +struct kthread_worker *rcu_exp_par_gp_kworker; + +static void __init rcu_start_exp_gp_kworkers (void ) +{ +const char *par_gp_kworker_name ="rcu_exp_par_gp_kthread_worker" ; +const char *gp_kworker_name ="rcu_exp_gp_kthread_worker" ; +struct sched_param param = { .sched_priority = kthread_prio }; + + rcu_exp_gp_kworker =kthread_create_worker (0 , gp_kworker_name); +if (IS_ERR_OR_NULL (rcu_exp_gp_kworker)) { +pr_err ("Failed to create %s!\n" , gp_kworker_name); + rcu_exp_gp_kworker =NULL ; +return ; + } + + rcu_exp_par_gp_kworker =kthread_create_worker (0 , par_gp_kworker_name); +if (IS_ERR_OR_NULL (rcu_exp_par_gp_kworker)) { +pr_err ("Failed to create %s!\n" , par_gp_kworker_name); + rcu_exp_par_gp_kworker =NULL ; +kthread_destroy_worker (rcu_exp_gp_kworker); + rcu_exp_gp_kworker =NULL ; +return ; + } + +sched_setscheduler_nocheck (rcu_exp_gp_kworker->task,SCHED_FIFO , ¶m); +sched_setscheduler_nocheck (rcu_exp_par_gp_kworker->task,SCHED_FIFO , + ¶m); +} + +static inline void rcu_alloc_par_gp_wq (void ) +{ +} +#else /* !CONFIG_RCU_EXP_KTHREAD */ +struct workqueue_struct *rcu_par_gp_wq; + +static void __init rcu_start_exp_gp_kworkers (void ) +{ +} + +static inline void rcu_alloc_par_gp_wq (void ) +{ + rcu_par_gp_wq =alloc_workqueue ("rcu_par_gp" ,WQ_MEM_RECLAIM ,0 ); +WARN_ON (!rcu_par_gp_wq); +} +#endif /* CONFIG_RCU_EXP_KTHREAD */ +/* * Invoked early in the CPU-online process, when pretty much all services * are available. The incoming CPU is not present.
@@ -4686,54 +4734,6 @@ static int rcu_pm_notify(struct notifier_block *self,return NOTIFY_OK ; } -#ifdef CONFIG_RCU_EXP_KTHREAD -struct kthread_worker *rcu_exp_gp_kworker; -struct kthread_worker *rcu_exp_par_gp_kworker; - -static void __init rcu_start_exp_gp_kworkers (void ) -{ -const char *par_gp_kworker_name ="rcu_exp_par_gp_kthread_worker" ; -const char *gp_kworker_name ="rcu_exp_gp_kthread_worker" ; -struct sched_param param = { .sched_priority = kthread_prio }; - - rcu_exp_gp_kworker =kthread_create_worker (0 , gp_kworker_name); -if (IS_ERR_OR_NULL (rcu_exp_gp_kworker)) { -pr_err ("Failed to create %s!\n" , gp_kworker_name); - rcu_exp_gp_kworker =NULL ; -return ; - } - - rcu_exp_par_gp_kworker =kthread_create_worker (0 , par_gp_kworker_name); -if (IS_ERR_OR_NULL (rcu_exp_par_gp_kworker)) { -pr_err ("Failed to create %s!\n" , par_gp_kworker_name); - rcu_exp_par_gp_kworker =NULL ; -kthread_destroy_worker (rcu_exp_gp_kworker); - rcu_exp_gp_kworker =NULL ; -return ; - } - -sched_setscheduler_nocheck (rcu_exp_gp_kworker->task,SCHED_FIFO , ¶m); -sched_setscheduler_nocheck (rcu_exp_par_gp_kworker->task,SCHED_FIFO , - ¶m); -} - -static inline void rcu_alloc_par_gp_wq (void ) -{ -} -#else /* !CONFIG_RCU_EXP_KTHREAD */ -struct workqueue_struct *rcu_par_gp_wq; - -static void __init rcu_start_exp_gp_kworkers (void ) -{ -} - -static inline void rcu_alloc_par_gp_wq (void ) -{ - rcu_par_gp_wq =alloc_workqueue ("rcu_par_gp" ,WQ_MEM_RECLAIM ,0 ); -WARN_ON (!rcu_par_gp_wq); -} -#endif /* CONFIG_RCU_EXP_KTHREAD */ -/* * Spawn the kthreads that handle RCU's grace periods. */
Signature · 1 line
2.51.0
PATCH 7/283 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
@@ -640,6 +640,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
@@ -659,18 +728,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.
@@ -683,7 +748,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 8/283 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
@@ -615,11 +615,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
@@ -636,8 +635,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 9/283 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
@@ -203,7 +203,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
@@ -475,8 +475,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,
@@ -634,7 +634,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 ); }/*
@@ -736,7 +736,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,
@@ -745,11 +748,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 10/283 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
@@ -125,12 +125,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 11/283 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
@@ -2769,7 +2769,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;
@@ -2779,6 +2778,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 12/283 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 13/283 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
@@ -586,7 +586,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 14/283 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
@@ -1396,31 +1396,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];
@@ -1444,6 +1458,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
@@ -204,7 +204,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
@@ -1408,7 +1408,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);
@@ -1458,12 +1458,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;
@@ -1652,7 +1657,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;
@@ -1696,13 +1701,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 15/283 gfs2: Add metapath_dibh helper
In reply to Sasha LevinFrom: Andreas Gruenbacher <[email protected]>
[ Upstream commit 92099f0c92270c8c7a79e6bc6e0312ad248ea331 ]
Add a metapath_dibh() helper for extracting the inode's buffer head from a metapath.
Stable-dep-of: faddeb848305 ("gfs2: Fix use-after-free in iomap inline data write path")
--- fs/gfs2/bmap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/gfs2/bmap.c +7 -1
@@ -317,6 +317,12 @@ static void gfs2_metapath_ra(struct gfs2_glock *gl, __be64 *start, __be64 *end) } } +static inline struct buffer_head * +metapath_dibh (struct metapath *mp) +{ +return mp->mp_bh[0 ]; +} +static int __fillup_metapath (struct gfs2_inode *ip,struct metapath *mp,unsigned int x,unsigned int h) {
@@ -660,7 +666,7 @@ static int __gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap, {struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_sbd *sdp =GFS2_SB (inode); -struct buffer_head *dibh = mp->mp_bh[0 ]; +struct buffer_head *dibh =metapath_dibh (mp);u64 bn;unsigned n, i, blks, alloced =0 , iblks =0 , branch_start =0 ;size_t dblks = iomap->length >> inode->i_blkbits;
Signature · 1 line
2.51.0
PATCH 16/283 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
@@ -1126,10 +1126,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);
@@ -1143,6 +1151,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 17/283 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
@@ -1483,6 +1483,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 18/283 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 19/283 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 20/283 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
@@ -1601,8 +1601,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 21/283 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
@@ -2457,13 +2457,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 22/283 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 23/283 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 24/283 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 25/283 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 26/283 cpuidle: menu: Cleanup after loadavg removal
In reply to Sasha LevinFrom: Christian Loehle <[email protected]>
[ Upstream commit bf183113842b0fcf4b6f977a97fa9cf8e2b21625 ]
The performance impact of loadavg was removed with commit a7fe5190c03f ("cpuidle: menu: Remove get_loadavg() from the performance multiplier") With only iowait remaining the description can be simplified, remove also the no longer needed includes.
Stable-dep-of: 80606f4eb8d7 ("cpuidle: governors: menu: Always check timers with tick stopped")
--- drivers/cpuidle/governors/menu.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/cpuidle/governors/menu.c +5 -12
@@ -14,8 +14,6 @@#include <linux/ktime.h> #include <linux/hrtimer.h> #include <linux/tick.h> -#include <linux/sched.h> -#include <linux/sched/loadavg.h> #include <linux/sched/stat.h> #include <linux/math64.h>
@@ -94,16 +92,11 @@* state, and thus the less likely a busy CPU will hit such a deep * C state. * -* Two factors are used in determing this multiplier: -* a value of 10 is added for each point of "per cpu load average" we have. -* a value of 5 points is added for each process that is waiting for -* IO on this CPU. -* (these values are experimentally determined) -* -* The load average factor gives a longer term (few seconds) input to the -* decision, while the iowait value gives a cpu local instantanious input. -* The iowait factor may look low, but realize that this is also already -* represented in the system load average. +* Currently there is only one value determining the factor: +* 10 points are added for each process that is waiting for IO on this CPU. +* (This value was experimentally determined.) +* Utilization is no longer a factor as it was shown that it never contributed +* significantly to the performance multiplier in the first place. * */
Signature · 1 line
2.51.0
PATCH 27/283 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
@@ -269,7 +269,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. */
@@ -289,6 +289,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
@@ -314,16 +324,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 28/283 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
@@ -3533,7 +3533,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,
@@ -3548,6 +3547,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 29/283 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
@@ -381,9 +381,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 30/283 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
@@ -2908,10 +2908,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 31/283 x86/xen: make some functions static
In reply to Sasha LevinFrom: Juergen Gross <[email protected]>
[ Upstream commit 337c628ab74d1bbfe5377bbd8d31c858baf5fbc6 ]
Some functions and variables in arch/x86/xen are used locally only, make them static.
Message-ID: <[email protected]>
Stable-dep-of: 0949c646d646 ("Partial revert "x86/xen: fix balloon target initialization for PVH dom0"")
--- arch/x86/xen/mmu.h | 4 ---- arch/x86/xen/mmu_pv.c | 11 ++++++----- arch/x86/xen/xen-ops.h | 1 - 3 files changed, 6 insertions(+), 10 deletions(-)
arch/x86/xen/mmu.h +0 -4
@@ -17,10 +17,6 @@ bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);void set_pte_mfn (unsigned long vaddr,unsigned long pfn,pgprot_t flags); -pte_t xen_ptep_modify_prot_start (struct vm_area_struct *vma,unsigned long addr,pte_t *ptep); -void xen_ptep_modify_prot_commit (struct vm_area_struct *vma,unsigned long addr, -pte_t *ptep,pte_t pte); -unsigned long xen_read_cr2_direct (void );extern void xen_init_mmu_ops (void );
arch/x86/xen/mmu_pv.c +6 -5
@@ -173,7 +173,7 @@ static int alloc_discontig_frames(unsigned int order)* looking at another vcpu's cr3 value, it should use this variable. */ DEFINE_PER_CPU(unsigned long, xen_cr3); /* cr3 stored as physaddr */ -DEFINE_PER_CPU(unsigned long, xen_current_cr3); /* actual vcpu cr3 */ +static DEFINE_PER_CPU(unsigned long, xen_current_cr3); /* actual vcpu cr3 */static phys_addr_t xen_pt_base, xen_pt_size__initdata ;
@@ -350,16 +350,17 @@ static void xen_set_pte(pte_t *ptep, pte_t pteval)__xen_set_pte (ptep, pteval); } -pte_t xen_ptep_modify_prot_start (struct vm_area_struct *vma, -unsigned long addr,pte_t *ptep) +static pte_t xen_ptep_modify_prot_start (struct vm_area_struct *vma, +unsigned long addr,pte_t *ptep) {/* Just return the pte as-is. We preserve the bits on commit */ trace_xen_mmu_ptep_modify_prot_start (vma->vm_mm, addr, ptep, *ptep);return *ptep; } -void xen_ptep_modify_prot_commit (struct vm_area_struct *vma,unsigned long addr, -pte_t *ptep,pte_t pte) +static void xen_ptep_modify_prot_commit (struct vm_area_struct *vma, +unsigned long addr, +pte_t *ptep,pte_t pte) {struct mmu_update u;
arch/x86/xen/xen-ops.h +0 -1
@@ -23,7 +23,6 @@ void xen_copy_trap_info(struct trap_info *traps); DECLARE_PER_CPU_ALIGNED(struct vcpu_info, xen_vcpu_info); DECLARE_PER_CPU(unsigned long, xen_cr3); -DECLARE_PER_CPU(unsigned long, xen_current_cr3);extern struct start_info *xen_start_info;extern struct shared_info xen_dummy_shared_info;
Signature · 1 line
2.51.0
PATCH 32/283 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
@@ -480,7 +480,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
@@ -716,6 +716,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 ())
@@ -723,12 +724,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 ;
@@ -759,6 +766,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 33/283 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 34/283 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 ,
@@ -519,8 +521,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;
@@ -528,7 +530,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.
@@ -548,6 +549,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)
@@ -687,7 +689,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 ;
@@ -782,9 +787,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 35/283 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 36/283 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
@@ -247,7 +247,7 @@ struct subchannel *css_alloc_subchannel(struct subchannel_id schid, err_lock:kfree (sch->lock); err: -kfree (sch); +put_device (&sch->dev);return ERR_PTR (ret); }
Signature · 1 line
2.51.0
PATCH 37/283 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 38/283 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
@@ -1372,7 +1372,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 39/283 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 40/283 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
@@ -176,6 +176,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 41/283 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 42/283 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 43/283 crypto: hisilicon/zip - support deflate algorithm
In reply to Sasha LevinFrom: Yang Shen <[email protected]>
[ Upstream commit aa3f80500382ca864b7cfcff4e5ca2fa6a0e977d ]
Add the deflate algorithm support for hisilicon zip hardware.
Stable-dep-of: 19c2475ce198 ("crypto: hisilicon/zip - adjust the way to obtain the req in the callback function")
--- drivers/crypto/hisilicon/zip/zip_crypto.c | 86 ++++++++++++++++++----- drivers/crypto/hisilicon/zip/zip_main.c | 4 +- 2 files changed, 72 insertions(+), 18 deletions(-)
drivers/crypto/hisilicon/zip/zip_crypto.c +70 -16
@@ -16,6 +16,7 @@#define HZIP_OUT_SGE_DATA_OFFSET_M GENMASK(23, 0)/* hisi_zip_sqe dw9 */ #define HZIP_REQ_TYPE_M GENMASK(7, 0) +#define HZIP_ALG_TYPE_DEFLATE 0x01#define HZIP_ALG_TYPE_ZLIB 0x02#define HZIP_ALG_TYPE_GZIP 0x03#define HZIP_BUF_TYPE_M GENMASK(11, 8)
@@ -41,6 +42,7 @@#define HZIP_ALG_ZLIB GENMASK(1, 0)#define HZIP_ALG_GZIP GENMASK(3, 2) +#define HZIP_ALG_DEFLATE GENMASK(5, 4)static const u8 zlib_head[HZIP_ZLIB_HEAD_SIZE ] = {0x78 ,0x9c };static const u8 gzip_head[HZIP_GZIP_HEAD_SIZE ] = {
@@ -59,8 +61,9 @@ enum { };#define COMP_NAME_TO_TYPE (alg_name) \ + (!strcmp((alg_name), "deflate") ? HZIP_ALG_TYPE_DEFLATE : \ (!strcmp((alg_name), "zlib-deflate") ? HZIP_ALG_TYPE_ZLIB : \ - !strcmp((alg_name), "gzip") ? HZIP_ALG_TYPE_GZIP : 0) \ + !strcmp((alg_name), "gzip") ? HZIP_ALG_TYPE_GZIP : 0)) \#define TO_HEAD_SIZE (req_type) \ (((req_type) == HZIP_ALG_TYPE_ZLIB) ? sizeof(zlib_head) : \
@@ -447,15 +450,17 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP ];struct device *dev = &qp_ctx->qp->qm->pdev->dev;struct hisi_zip_req *req; -int head_size; +int head_size =0 ;int ret;/* let's output compression head now */ - head_size =add_comp_head (acomp_req->dst, qp_ctx->qp->req_type); -if (unlikely (head_size <0 )) { -dev_err_ratelimited (dev,"failed to add comp head (%d)!\n" , - head_size); -return head_size; +if (qp_ctx->qp->req_type !=HZIP_ALG_TYPE_DEFLATE ) { + head_size =add_comp_head (acomp_req->dst, qp_ctx->qp->req_type); +if (unlikely (head_size <0 )) { +dev_err_ratelimited (dev,"failed to add comp head (%d)!\n" , + head_size); +return head_size; + } } req =hisi_zip_create_req (acomp_req, qp_ctx, head_size, true);
@@ -477,13 +482,15 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req)struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP ];struct device *dev = &qp_ctx->qp->qm->pdev->dev;struct hisi_zip_req *req; -int head_size, ret; - - head_size =get_comp_head_size (acomp_req, qp_ctx->qp->req_type); -if (unlikely (head_size <0 )) { -dev_err_ratelimited (dev,"failed to get comp head size (%d)!\n" , - head_size); -return head_size; +int head_size =0 , ret; + +if (qp_ctx->qp->req_type !=HZIP_ALG_TYPE_DEFLATE ) { + head_size =get_comp_head_size (acomp_req, qp_ctx->qp->req_type); +if (unlikely (head_size <0 )) { +dev_err_ratelimited (dev,"failed to get comp head size (%d)!\n" , + head_size); +return head_size; + } } req =hisi_zip_create_req (acomp_req, qp_ctx, head_size, false);
@@ -745,6 +752,42 @@ static void hisi_zip_acomp_exit(struct crypto_acomp *tfm)hisi_zip_ctx_exit (ctx); } +static struct acomp_alg hisi_zip_acomp_deflate = { + .init = hisi_zip_acomp_init, + .exit = hisi_zip_acomp_exit, + .compress = hisi_zip_acompress, + .decompress = hisi_zip_adecompress, + .base = { + .cra_name ="deflate" , + .cra_driver_name ="hisi-deflate-acomp" , + .cra_module =THIS_MODULE , + .cra_priority =HZIP_ALG_PRIORITY , + .cra_ctxsize =sizeof (struct hisi_zip_ctx ), + } +}; + +static int hisi_zip_register_deflate (struct hisi_qm *qm) +{ +int ret; + +if (!hisi_zip_alg_support (qm,HZIP_ALG_DEFLATE )) +return 0 ; + + ret =crypto_register_acomp (&hisi_zip_acomp_deflate); +if (ret) +dev_err (&qm->pdev->dev,"failed to register to deflate (%d)!\n" , ret); + +return ret; +} + +static void hisi_zip_unregister_deflate (struct hisi_qm *qm) +{ +if (!hisi_zip_alg_support (qm,HZIP_ALG_DEFLATE )) +return ; + +crypto_unregister_acomp (&hisi_zip_acomp_deflate); +} +static struct acomp_alg hisi_zip_acomp_zlib = { .init = hisi_zip_acomp_init, .exit = hisi_zip_acomp_exit,
@@ -821,19 +864,30 @@ int hisi_zip_register_to_crypto(struct hisi_qm *qm) {int ret =0 ; - ret =hisi_zip_register_zlib (qm); + ret =hisi_zip_register_deflate (qm);if (ret)return ret; + ret =hisi_zip_register_zlib (qm); +if (ret) + goto err_unreg_deflate; + ret =hisi_zip_register_gzip (qm);if (ret) -hisi_zip_unregister_zlib (qm); + goto err_unreg_zlib; + +return 0 ; +err_unreg_zlib: +hisi_zip_unregister_zlib (qm); +err_unreg_deflate: +hisi_zip_unregister_deflate (qm);return ret; }void hisi_zip_unregister_from_crypto (struct hisi_qm *qm) { +hisi_zip_unregister_deflate (qm);hisi_zip_unregister_zlib (qm);hisi_zip_unregister_gzip (qm); }
drivers/crypto/hisilicon/zip/zip_main.c +2 -2
@@ -238,8 +238,8 @@ static struct hisi_qm_cap_info zip_basic_cap_info[] = { {ZIP_CLUSTER_DECOMP_NUM_CAP, 0x313C, 0, GENMASK(7, 0), 0x6, 0x6, 0x3}, {ZIP_DECOMP_ENABLE_BITMAP, 0x3140, 16, GENMASK(15, 0), 0xFC, 0xFC, 0x1C}, {ZIP_COMP_ENABLE_BITMAP, 0x3140, 0, GENMASK(15, 0), 0x3, 0x3, 0x3}, - {ZIP_DRV_ALG_BITMAP, 0x3144, 0, GENMASK(31, 0), 0xF, 0xF, 0xF}, - {ZIP_DEV_ALG_BITMAP, 0x3148, 0, GENMASK(31, 0), 0xF, 0xF, 0xFF}, + {ZIP_DRV_ALG_BITMAP, 0x3144, 0, GENMASK(31, 0), 0xF, 0xF, 0x3F}, + {ZIP_DEV_ALG_BITMAP, 0x3148, 0, GENMASK(31, 0), 0xF, 0xF, 0x3F}, {ZIP_CORE1_ALG_BITMAP, 0x314C, 0, GENMASK(31, 0), 0x5, 0x5, 0xD5}, {ZIP_CORE2_ALG_BITMAP, 0x3150, 0, GENMASK(31, 0), 0x5, 0x5, 0xD5}, {ZIP_CORE3_ALG_BITMAP, 0x3154, 0, GENMASK(31, 0), 0xA, 0xA, 0x2A},
Signature · 1 line
2.51.0
PATCH 44/283 crypto: hisilicon/zip - remove zlib and gzip
In reply to Sasha LevinFrom: Yang Shen <[email protected]>
[ Upstream commit 1a9e6f59caeea35d157f91b452ae75f251d8255b ]
Remove the support of zlib-deflate and gzip.
Stable-dep-of: 19c2475ce198 ("crypto: hisilicon/zip - adjust the way to obtain the req in the callback function")
--- drivers/crypto/hisilicon/zip/zip_crypto.c | 308 ++-------------------- drivers/crypto/hisilicon/zip/zip_main.c | 2 +- 2 files changed, 22 insertions(+), 288 deletions(-)
drivers/crypto/hisilicon/zip/zip_crypto.c +21 -287
@@ -17,38 +17,14 @@/* hisi_zip_sqe dw9 */ #define HZIP_REQ_TYPE_M GENMASK(7, 0)#define HZIP_ALG_TYPE_DEFLATE 0x01 -#define HZIP_ALG_TYPE_ZLIB 0x02 -#define HZIP_ALG_TYPE_GZIP 0x03#define HZIP_BUF_TYPE_M GENMASK(11, 8) -#define HZIP_PBUFFER 0x0#define HZIP_SGL 0x1 -#define HZIP_ZLIB_HEAD_SIZE 2 -#define HZIP_GZIP_HEAD_SIZE 10 - -#define GZIP_HEAD_FHCRC_BIT BIT(1) -#define GZIP_HEAD_FEXTRA_BIT BIT(2) -#define GZIP_HEAD_FNAME_BIT BIT(3) -#define GZIP_HEAD_FCOMMENT_BIT BIT(4) - -#define GZIP_HEAD_FLG_SHIFT 3 -#define GZIP_HEAD_FEXTRA_SHIFT 10 -#define GZIP_HEAD_FEXTRA_XLEN 2UL -#define GZIP_HEAD_FHCRC_SIZE 2 - -#define HZIP_GZIP_HEAD_BUF 256#define HZIP_ALG_PRIORITY 300#define HZIP_SGL_SGE_NR 10 -#define HZIP_ALG_ZLIB GENMASK(1, 0) -#define HZIP_ALG_GZIP GENMASK(3, 2)#define HZIP_ALG_DEFLATE GENMASK(5, 4) -static const u8 zlib_head[HZIP_ZLIB_HEAD_SIZE ] = {0x78 ,0x9c }; -static const u8 gzip_head[HZIP_GZIP_HEAD_SIZE ] = { -0x1f ,0x8b ,0x08 ,0x0 ,0x0 ,0x0 ,0x0 ,0x0 ,0x0 ,0x03 -}; -enum hisi_zip_alg_type {HZIP_ALG_TYPE_COMP =0 ,HZIP_ALG_TYPE_DECOMP =1 ,
@@ -61,22 +37,10 @@ enum { };#define COMP_NAME_TO_TYPE (alg_name) \ - (!strcmp((alg_name), "deflate") ? HZIP_ALG_TYPE_DEFLATE : \ - (!strcmp((alg_name), "zlib-deflate") ? HZIP_ALG_TYPE_ZLIB : \ - !strcmp((alg_name), "gzip") ? HZIP_ALG_TYPE_GZIP : 0)) \ - -#define TO_HEAD_SIZE (req_type) \ - (((req_type) == HZIP_ALG_TYPE_ZLIB) ? sizeof(zlib_head) : \ - ((req_type) == HZIP_ALG_TYPE_GZIP) ? sizeof(gzip_head) : 0) \ - -#define TO_HEAD (req_type) \ - (((req_type) == HZIP_ALG_TYPE_ZLIB) ? zlib_head : \ - ((req_type) == HZIP_ALG_TYPE_GZIP) ? gzip_head : NULL) \ + (!strcmp((alg_name), "deflate") ? HZIP_ALG_TYPE_DEFLATE : 0)struct hisi_zip_req {struct acomp_req *req; -u32 sskip; -u32 dskip;struct hisi_acc_hw_sgl *hw_src;struct hisi_acc_hw_sgl *hw_dst;dma_addr_t dma_src;
@@ -141,85 +105,8 @@ static u16 sgl_sge_nr = HZIP_SGL_SGE_NR;module_param_cb (sgl_sge_nr, &sgl_sge_nr_ops, &sgl_sge_nr,0444 );MODULE_PARM_DESC (sgl_sge_nr,"Number of sge in sgl(1-255)" ); -static u32 get_extra_field_size (const u8 *start) -{ -return *((u16 *)start) +GZIP_HEAD_FEXTRA_XLEN ; -} - -static u32 get_name_field_size (const u8 *start) -{ -return strlen (start) +1 ; -} - -static u32 get_comment_field_size (const u8 *start) -{ -return strlen (start) +1 ; -} - -static u32 __get_gzip_head_size (const u8 *src) -{ -u8 head_flg = *(src +GZIP_HEAD_FLG_SHIFT ); -u32 size =GZIP_HEAD_FEXTRA_SHIFT ; - -if (head_flg &GZIP_HEAD_FEXTRA_BIT ) - size +=get_extra_field_size (src + size); -if (head_flg &GZIP_HEAD_FNAME_BIT ) - size +=get_name_field_size (src + size); -if (head_flg &GZIP_HEAD_FCOMMENT_BIT ) - size +=get_comment_field_size (src + size); -if (head_flg &GZIP_HEAD_FHCRC_BIT ) - size +=GZIP_HEAD_FHCRC_SIZE ; - -return size; -} - -static u32 __maybe_unused get_gzip_head_size (struct scatterlist *sgl) -{ -char buf[HZIP_GZIP_HEAD_BUF ]; - -sg_copy_to_buffer (sgl,sg_nents (sgl), buf,sizeof (buf)); - -return __get_gzip_head_size (buf); -} - -static int add_comp_head (struct scatterlist *dst,u8 req_type) -{ -int head_size =TO_HEAD_SIZE (req_type); -const u8 *head =TO_HEAD (req_type); -int ret; - - ret =sg_copy_from_buffer (dst,sg_nents (dst), head, head_size); -if (unlikely (ret != head_size)) { -pr_err ("the head size of buffer is wrong (%d)!\n" , ret); -return -ENOMEM ; - } - -return head_size; -} - -static int get_comp_head_size (struct acomp_req *acomp_req,u8 req_type) -{ -if (unlikely (!acomp_req->src || !acomp_req->slen)) -return -EINVAL ; - -if (unlikely (req_type ==HZIP_ALG_TYPE_GZIP && - acomp_req->slen <GZIP_HEAD_FEXTRA_SHIFT )) -return -EINVAL ; - -switch (req_type) { -case HZIP_ALG_TYPE_ZLIB : -return TO_HEAD_SIZE (HZIP_ALG_TYPE_ZLIB ); -case HZIP_ALG_TYPE_GZIP : -return TO_HEAD_SIZE (HZIP_ALG_TYPE_GZIP ); -default : -pr_err ("request type does not support!\n" ); -return -EINVAL ; - } -} - -static struct hisi_zip_req *hisi_zip_create_req (struct acomp_req *req, -struct hisi_zip_qp_ctx *qp_ctx, -size_t head_size,bool is_comp) +static struct hisi_zip_req *hisi_zip_create_req (struct hisi_zip_qp_ctx *qp_ctx, +struct acomp_req *req) {struct hisi_zip_req_q *req_q = &qp_ctx->req_q;struct hisi_zip_req *q = req_q->q;
@@ -242,14 +129,6 @@ static struct hisi_zip_req *hisi_zip_create_req(struct acomp_req *req, req_cache->req_id = req_id; req_cache->req = req; -if (is_comp) { - req_cache->sskip =0 ; - req_cache->dskip = head_size; - }else { - req_cache->sskip = head_size; - req_cache->dskip =0 ; - } -return req_cache; }
@@ -275,10 +154,8 @@ static void hisi_zip_fill_buf_size(struct hisi_zip_sqe *sqe, struct hisi_zip_req {struct acomp_req *a_req = req->req; - sqe->input_data_length = a_req->slen - req->sskip; - sqe->dest_avail_out = a_req->dlen - req->dskip; - sqe->dw7 =FIELD_PREP (HZIP_IN_SGE_DATA_OFFSET_M , req->sskip); - sqe->dw8 =FIELD_PREP (HZIP_OUT_SGE_DATA_OFFSET_M , req->dskip); + sqe->input_data_length = a_req->slen; + sqe->dest_avail_out = a_req->dlen; }static void hisi_zip_fill_buf_type (struct hisi_zip_sqe *sqe,u8 buf_type)
@@ -299,12 +176,7 @@ static void hisi_zip_fill_req_type(struct hisi_zip_sqe *sqe, u8 req_type) sqe->dw9 = val; } -static void hisi_zip_fill_tag_v1 (struct hisi_zip_sqe *sqe,struct hisi_zip_req *req) -{ - sqe->dw13 = req->req_id; -} - -static void hisi_zip_fill_tag_v2 (struct hisi_zip_sqe *sqe,struct hisi_zip_req *req) +static void hisi_zip_fill_tag (struct hisi_zip_sqe *sqe,struct hisi_zip_req *req) { sqe->dw26 = req->req_id; }
@@ -333,8 +205,8 @@ static void hisi_zip_fill_sqe(struct hisi_zip_ctx *ctx, struct hisi_zip_sqe *sqe ops->fill_sqe_type (sqe, ops->sqe_type); } -static int hisi_zip_do_work (struct hisi_zip_req *req, -struct hisi_zip_qp_ctx *qp_ctx) +static int hisi_zip_do_work (struct hisi_zip_qp_ctx *qp_ctx, +struct hisi_zip_req *req) {struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool;struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx;
@@ -386,12 +258,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,return ret; } -static u32 hisi_zip_get_tag_v1 (struct hisi_zip_sqe *sqe) -{ -return sqe->dw13; -} - -static u32 hisi_zip_get_tag_v2 (struct hisi_zip_sqe *sqe) +static u32 hisi_zip_get_tag (struct hisi_zip_sqe *sqe) {return sqe->dw26; }
@@ -417,8 +284,8 @@ static void hisi_zip_acomp_cb(struct hisi_qp *qp, void *data)u32 tag = ops->get_tag (sqe);struct hisi_zip_req *req = req_q->q + tag;struct acomp_req *acomp_req = req->req; -u32 status, dlen, head_size;int err =0 ; +u32 status;atomic64_inc (&dfx->recv_cnt); status = ops->get_status (sqe);
@@ -430,13 +297,10 @@ static void hisi_zip_acomp_cb(struct hisi_qp *qp, void *data) err = -EIO ; } - dlen = ops->get_dstlen (sqe); -hisi_acc_sg_buf_unmap (dev, acomp_req->src, req->hw_src);hisi_acc_sg_buf_unmap (dev, acomp_req->dst, req->hw_dst); - head_size = (qp->alg_type ==0 ) ?TO_HEAD_SIZE (qp->req_type) :0 ; - acomp_req->dlen = dlen + head_size; + acomp_req->dlen = ops->get_dstlen (sqe);if (acomp_req->base.complete)acomp_request_complete (acomp_req, err);
@@ -450,24 +314,13 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP ];struct device *dev = &qp_ctx->qp->qm->pdev->dev;struct hisi_zip_req *req; -int head_size =0 ;int ret; -/* let's output compression head now */ -if (qp_ctx->qp->req_type !=HZIP_ALG_TYPE_DEFLATE ) { - head_size =add_comp_head (acomp_req->dst, qp_ctx->qp->req_type); -if (unlikely (head_size <0 )) { -dev_err_ratelimited (dev,"failed to add comp head (%d)!\n" , - head_size); -return head_size; - } - } - - req =hisi_zip_create_req (acomp_req, qp_ctx, head_size, true); + req =hisi_zip_create_req (qp_ctx, acomp_req);if (IS_ERR (req))return PTR_ERR (req); - ret =hisi_zip_do_work (req, qp_ctx); + ret =hisi_zip_do_work (qp_ctx, req);if (unlikely (ret != -EINPROGRESS )) {dev_info_ratelimited (dev,"failed to do compress (%d)!\n" , ret);hisi_zip_remove_req (qp_ctx, req);
@@ -482,22 +335,13 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req)struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP ];struct device *dev = &qp_ctx->qp->qm->pdev->dev;struct hisi_zip_req *req; -int head_size =0 , ret; - -if (qp_ctx->qp->req_type !=HZIP_ALG_TYPE_DEFLATE ) { - head_size =get_comp_head_size (acomp_req, qp_ctx->qp->req_type); -if (unlikely (head_size <0 )) { -dev_err_ratelimited (dev,"failed to get comp head size (%d)!\n" , - head_size); -return head_size; - } - } +int ret; - req =hisi_zip_create_req (acomp_req, qp_ctx, head_size, false); + req =hisi_zip_create_req (qp_ctx, acomp_req);if (IS_ERR (req))return PTR_ERR (req); - ret =hisi_zip_do_work (req, qp_ctx); + ret =hisi_zip_do_work (qp_ctx, req);if (unlikely (ret != -EINPROGRESS )) {dev_info_ratelimited (dev,"failed to do decompress (%d)!\n" , ret);
@@ -534,28 +378,15 @@ static void hisi_zip_release_qp(struct hisi_zip_qp_ctx *qp_ctx)hisi_qm_free_qps (&qp_ctx->qp,1 ); } -static const struct hisi_zip_sqe_ops hisi_zip_ops_v1 = { - .sqe_type =0 , - .fill_addr = hisi_zip_fill_addr, - .fill_buf_size = hisi_zip_fill_buf_size, - .fill_buf_type = hisi_zip_fill_buf_type, - .fill_req_type = hisi_zip_fill_req_type, - .fill_tag = hisi_zip_fill_tag_v1, - .fill_sqe_type = hisi_zip_fill_sqe_type, - .get_tag = hisi_zip_get_tag_v1, - .get_status = hisi_zip_get_status, - .get_dstlen = hisi_zip_get_dstlen, -}; - -static const struct hisi_zip_sqe_ops hisi_zip_ops_v2 = { +static const struct hisi_zip_sqe_ops hisi_zip_ops = { .sqe_type =0x3 , .fill_addr = hisi_zip_fill_addr, .fill_buf_size = hisi_zip_fill_buf_size, .fill_buf_type = hisi_zip_fill_buf_type, .fill_req_type = hisi_zip_fill_req_type, - .fill_tag = hisi_zip_fill_tag_v2, + .fill_tag = hisi_zip_fill_tag, .fill_sqe_type = hisi_zip_fill_sqe_type, - .get_tag = hisi_zip_get_tag_v2, + .get_tag = hisi_zip_get_tag, .get_status = hisi_zip_get_status, .get_dstlen = hisi_zip_get_dstlen, };
@@ -591,10 +422,7 @@ static int hisi_zip_ctx_init(struct hisi_zip_ctx *hisi_zip_ctx, u8 req_type, int qp_ctx->zip_dev = hisi_zip; } -if (hisi_zip->qm.ver <QM_HW_V3 ) - hisi_zip_ctx->ops = &hisi_zip_ops_v1; -else - hisi_zip_ctx->ops = &hisi_zip_ops_v2; + hisi_zip_ctx->ops = &hisi_zip_ops;return 0 ; }
@@ -788,106 +616,12 @@ static void hisi_zip_unregister_deflate(struct hisi_qm *qm)crypto_unregister_acomp (&hisi_zip_acomp_deflate); } -static struct acomp_alg hisi_zip_acomp_zlib = { - .init = hisi_zip_acomp_init, - .exit = hisi_zip_acomp_exit, - .compress = hisi_zip_acompress, - .decompress = hisi_zip_adecompress, - .base = { - .cra_name ="zlib-deflate" , - .cra_driver_name ="hisi-zlib-acomp" , - .cra_module =THIS_MODULE , - .cra_priority =HZIP_ALG_PRIORITY , - .cra_ctxsize =sizeof (struct hisi_zip_ctx ), - } -}; - -static int hisi_zip_register_zlib (struct hisi_qm *qm) -{ -int ret; - -if (!hisi_zip_alg_support (qm,HZIP_ALG_ZLIB )) -return 0 ; - - ret =crypto_register_acomp (&hisi_zip_acomp_zlib); -if (ret) -dev_err (&qm->pdev->dev,"failed to register to zlib (%d)!\n" , ret); - -return ret; -} - -static void hisi_zip_unregister_zlib (struct hisi_qm *qm) -{ -if (!hisi_zip_alg_support (qm,HZIP_ALG_ZLIB )) -return ; - -crypto_unregister_acomp (&hisi_zip_acomp_zlib); -} - -static struct acomp_alg hisi_zip_acomp_gzip = { - .init = hisi_zip_acomp_init, - .exit = hisi_zip_acomp_exit, - .compress = hisi_zip_acompress, - .decompress = hisi_zip_adecompress, - .base = { - .cra_name ="gzip" , - .cra_driver_name ="hisi-gzip-acomp" , - .cra_module =THIS_MODULE , - .cra_priority =HZIP_ALG_PRIORITY , - .cra_ctxsize =sizeof (struct hisi_zip_ctx ), - } -}; - -static int hisi_zip_register_gzip (struct hisi_qm *qm) -{ -int ret; - -if (!hisi_zip_alg_support (qm,HZIP_ALG_GZIP )) -return 0 ; - - ret =crypto_register_acomp (&hisi_zip_acomp_gzip); -if (ret) -dev_err (&qm->pdev->dev,"failed to register to gzip (%d)!\n" , ret); - -return ret; -} - -static void hisi_zip_unregister_gzip (struct hisi_qm *qm) -{ -if (!hisi_zip_alg_support (qm,HZIP_ALG_GZIP )) -return ; - -crypto_unregister_acomp (&hisi_zip_acomp_gzip); -} -int hisi_zip_register_to_crypto (struct hisi_qm *qm) { -int ret =0 ; - - ret =hisi_zip_register_deflate (qm); -if (ret) -return ret; - - ret =hisi_zip_register_zlib (qm); -if (ret) - goto err_unreg_deflate; - - ret =hisi_zip_register_gzip (qm); -if (ret) - goto err_unreg_zlib; - -return 0 ; - -err_unreg_zlib: -hisi_zip_unregister_zlib (qm); -err_unreg_deflate: -hisi_zip_unregister_deflate (qm); -return ret; +return hisi_zip_register_deflate (qm); }void hisi_zip_unregister_from_crypto (struct hisi_qm *qm) {hisi_zip_unregister_deflate (qm); -hisi_zip_unregister_zlib (qm); -hisi_zip_unregister_gzip (qm); }
drivers/crypto/hisilicon/zip/zip_main.c +1 -1
@@ -238,7 +238,7 @@ static struct hisi_qm_cap_info zip_basic_cap_info[] = { {ZIP_CLUSTER_DECOMP_NUM_CAP, 0x313C, 0, GENMASK(7, 0), 0x6, 0x6, 0x3}, {ZIP_DECOMP_ENABLE_BITMAP, 0x3140, 16, GENMASK(15, 0), 0xFC, 0xFC, 0x1C}, {ZIP_COMP_ENABLE_BITMAP, 0x3140, 0, GENMASK(15, 0), 0x3, 0x3, 0x3}, - {ZIP_DRV_ALG_BITMAP, 0x3144, 0, GENMASK(31, 0), 0xF, 0xF, 0x3F}, + {ZIP_DRV_ALG_BITMAP, 0x3144, 0, GENMASK(31, 0), 0x0, 0x0, 0x30}, {ZIP_DEV_ALG_BITMAP, 0x3148, 0, GENMASK(31, 0), 0xF, 0xF, 0x3F}, {ZIP_CORE1_ALG_BITMAP, 0x314C, 0, GENMASK(31, 0), 0x5, 0x5, 0xD5}, {ZIP_CORE2_ALG_BITMAP, 0x3150, 0, GENMASK(31, 0), 0x5, 0x5, 0xD5},
Signature · 1 line
2.51.0
PATCH 45/283 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
@@ -36,6 +36,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)
@@ -45,6 +46,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; };
@@ -71,7 +73,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); };
@@ -128,6 +129,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; }
@@ -178,7 +180,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)
@@ -232,7 +235,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; }
@@ -258,11 +261,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 ;
@@ -275,14 +273,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;
@@ -386,7 +382,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, };
@@ -574,7 +569,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 46/283 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
@@ -590,10 +590,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;
@@ -632,6 +630,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]);
@@ -643,6 +644,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)
@@ -655,6 +659,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);
@@ -676,6 +683,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);
@@ -713,7 +723,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);
@@ -824,6 +834,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) {
@@ -854,13 +867,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 ; }
@@ -1139,6 +1153,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;
@@ -1833,6 +1850,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;
@@ -1841,7 +1861,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)
@@ -1909,7 +1929,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; }
@@ -1951,7 +1971,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; }
@@ -2098,6 +2118,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 ;
@@ -2114,9 +2137,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)
@@ -2346,6 +2372,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;
@@ -2355,11 +2384,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 47/283 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
@@ -1715,7 +1715,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 48/283 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
@@ -132,6 +132,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 49/283 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
@@ -93,6 +93,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;
@@ -312,6 +314,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) {
@@ -320,6 +343,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);
@@ -336,18 +360,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; }
@@ -511,6 +542,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 50/283 crypto: hisilicon/trng - modifying the order of header files
In reply to Sasha LevinFrom: Chenghai Huang <[email protected]>
[ Upstream commit f5dd7c43022799ac5c4e3a0d445f9c293a198413 ]
Header files is included Order-ref: standard library headers, OS library headers, and project-specific headers. This patch modifies the order of header files according to suggestions.
In addition, use %u to print unsigned int variables to prevent overflow.
Stable-dep-of: 3d3135057ff5 ("crypto: hisilicon/trng - support tfms sharing the device")
--- drivers/crypto/hisilicon/trng/trng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/hisilicon/trng/trng.c +2 -2
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2019 HiSilicon Limited. */ +#include <crypto/internal/rng.h> #include <linux/acpi.h> #include <linux/crypto.h> #include <linux/err.h>
@@ -13,7 +14,6 @@#include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/random.h> -#include <crypto/internal/rng.h> #define HISI_TRNG_REG 0x00F0#define HISI_TRNG_BYTES 4
@@ -121,7 +121,7 @@ static int hisi_trng_generate(struct crypto_rng *tfm, const u8 *src,u32 i;if (dlen >SW_DRBG_BLOCKS_NUM *SW_DRBG_BYTES || dlen ==0 ) { -pr_err ("dlen(%d) exceeds limit(%d)!\n" , dlen, +pr_err ("dlen(%u) exceeds limit(%d)!\n" , dlen,SW_DRBG_BLOCKS_NUM *SW_DRBG_BYTES );return -EINVAL ; }
Signature · 1 line
2.51.0
PATCH 51/283 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 52/283 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
@@ -4118,7 +4118,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 53/283 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 54/283 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
@@ -1573,8 +1573,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" );
@@ -1597,8 +1596,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" );
@@ -1981,8 +1979,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;
@@ -2004,7 +2001,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 55/283 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 56/283 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
@@ -2219,6 +2219,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;
@@ -2242,6 +2243,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 57/283 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 58/283 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
@@ -1189,7 +1189,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 59/283 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 60/283 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 61/283 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
@@ -810,7 +810,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 62/283 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
@@ -325,7 +325,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 63/283 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
@@ -589,8 +589,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 64/283 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
@@ -155,7 +155,6 @@ ts_1p8_supply: ts-1p8-regulator { gpio = <&tlmm 88 0>; enable-active-high; - regulator-boot-on; }; };
Signature · 1 line
2.51.0
PATCH 65/283 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
@@ -251,7 +251,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.6 065/283] arm64: dts: qcom: sdm845-oneplus: Don't keep panel regulator always on
Just as addition to the 6.12 explanation, currently 6.6 or any older isn't supported by any distribution supporting this phone, so it's slightly irrelevant here, but same rules as for 6.12 should apply here, thus please do not apply this patch. See message bellow
=== 6.12 mail
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@@ -251,7 +251,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
PATCH 66/283 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
@@ -251,6 +251,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 67/283 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 68/283 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
@@ -290,6 +290,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); \
@@ -318,6 +319,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);
@@ -404,6 +406,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; }
@@ -420,6 +423,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 69/283 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
@@ -354,15 +354,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 70/283 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
@@ -7,6 +7,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>
@@ -717,7 +718,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 ;
@@ -735,8 +736,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 71/283 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);
@@ -877,14 +877,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
@@ -1089,7 +1090,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
@@ -1213,7 +1214,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 72/283 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 73/283 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 74/283 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
@@ -1894,6 +1894,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 {
@@ -1906,6 +1909,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>; }; usb2_phy1: phy@9020 {
Signature · 1 line
2.51.0
PATCH 75/283 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 76/283 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
@@ -2353,6 +2353,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 {
@@ -2365,6 +2368,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 77/283 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
@@ -2341,6 +2341,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 78/283 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
@@ -852,7 +852,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 79/283 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
@@ -372,6 +372,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>;
@@ -1157,6 +1163,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 80/283 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
@@ -1336,8 +1336,12 @@ usb_dwc3: usb@4e00000 { 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 81/283 workqueue: Factor out assign_rescuer_work()
In reply to Sasha LevinFrom: Lai Jiangshan <[email protected]>
[ Upstream commit 99ed6f62a46e91dc796b785618d646eeded1b230 ]
Move the code to assign work to rescuer and assign_rescuer_work().
Stable-dep-of: e5a30c303b07 ("workqueue: Process rescuer work items one-by-one using a cursor")
--- kernel/workqueue.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
kernel/workqueue.c +18 -11
@@ -2808,6 +2808,23 @@ static int worker_thread(void *__worker) goto woke_up; } +static bool assign_rescuer_work (struct pool_workqueue *pwq,struct worker *rescuer) +{ +struct worker_pool *pool = pwq->pool; +struct work_struct *work, *n; + +/* +* Slurp in all works issued via this workqueue and +* process'em. +*/ +list_for_each_entry_safe (work, n, &pool->worklist, entry) { +if (get_work_pwq (work) == pwq &&assign_work (work, rescuer, &n)) + pwq->stats[PWQ_STAT_RESCUED ]++; + } + +return !list_empty (&rescuer->scheduled); +} +/** * rescuer_thread - the rescuer thread function * @__rescuer: self
@@ -2862,7 +2879,6 @@ static int rescuer_thread(void *__rescuer)struct pool_workqueue *pwq =list_first_entry (&wq->maydays, struct pool_workqueue, mayday_node);struct worker_pool *pool = pwq->pool; -struct work_struct *work, *n;__set_current_state (TASK_RUNNING );list_del_init (&pwq->mayday_node);
@@ -2873,18 +2889,9 @@ static int rescuer_thread(void *__rescuer)raw_spin_lock_irq (&pool->lock); -/* -* Slurp in all works issued via this workqueue and -* process'em. -*/ WARN_ON_ONCE (!list_empty (&rescuer->scheduled)); -list_for_each_entry_safe (work, n, &pool->worklist, entry) { -if (get_work_pwq (work) == pwq && -assign_work (work, rescuer, &n)) - pwq->stats[PWQ_STAT_RESCUED ]++; - } -if (!list_empty (&rescuer->scheduled)) { +if (assign_rescuer_work (pwq, rescuer)) {process_scheduled_works (rescuer);/*
Signature · 1 line
2.51.0
PATCH 82/283 workqueue: Only assign rescuer work when really needed
In reply to Sasha LevinFrom: Lai Jiangshan <[email protected]>
[ Upstream commit 7b05c90b3302cf3d830dfa6f8961376bcaf43b94 ]
If the pwq does not need rescue (normal workers have been created or become available), the rescuer can immediately move on to other stalled pwqs.
Stable-dep-of: e5a30c303b07 ("workqueue: Process rescuer work items one-by-one using a cursor")
--- kernel/workqueue.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/workqueue.c +4 -0
@@ -2813,6 +2813,10 @@ static bool assign_rescuer_work(struct pool_workqueue *pwq, struct worker *rescustruct worker_pool *pool = pwq->pool;struct work_struct *work, *n; +/* need rescue? */ +if (!pwq->nr_active || !need_to_create_worker (pool)) +return false; +/* * Slurp in all works issued via this workqueue and * process'em.
Signature · 1 line
2.51.0
PATCH 83/283 workqueue: Process rescuer work items one-by-one using a cursor
In reply to Sasha LevinFrom: Lai Jiangshan <[email protected]>
[ Upstream commit e5a30c303b07a4d6083e0f7f051b53add6d93c5d ]
Previously, the rescuer scanned for all matching work items at once and processed them within a single rescuer thread, which could cause one blocking work item to stall all others.
Make the rescuer process work items one-by-one instead of slurping all matches in a single pass.
Break the rescuer loop after finding and processing the first matching work item, then restart the search to pick up the next. This gives normal worker threads a chance to process other items which gives them the opportunity to be processed instead of waiting on the rescuer's queue and prevents a blocking work item from stalling the rest once memory pressure is relieved.
Introduce a dummy cursor work item to avoid potentially O(N^2) rescans of the work list. The marker records the resume position for the next scan, eliminating redundant traversals.
Also introduce RESCUER_BATCH to control the maximum number of work items the rescuer processes in each turn, and move on to other PWQs when the limit is reached.
--- kernel/workqueue.c | 75 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 16 deletions(-)
kernel/workqueue.c +59 -16
@@ -101,6 +101,8 @@ enum {MAYDAY_INTERVAL =HZ /10 ,/* and then every 100ms */ CREATE_COOLDOWN =HZ ,/* time to breath after fail */ +RESCUER_BATCH =16 ,/* process items per turn */ +/* * Rescue workers are used only on emergencies and shared by * all cpus. Give MIN_NICE.
@@ -254,6 +256,7 @@ struct pool_workqueue {struct list_head inactive_works;/* L: inactive works */ struct list_head pwqs_node;/* WR: node on wq->pwqs */ struct list_head mayday_node;/* MD: node on wq->maydays */ +struct work_struct mayday_cursor;/* L: cursor on pool->worklist */ u64 stats[PWQ_NR_STATS ];
@@ -1015,6 +1018,12 @@ static struct worker *find_worker_executing_work(struct worker_pool *pool,return NULL ; } +static void mayday_cursor_func (struct work_struct *work) +{ +/* should not be processed, only for marking position */ +BUG (); +} +/** * move_linked_works - move linked works to a list * @work: start of series of works to be scheduled
@@ -1077,6 +1086,16 @@ static bool assign_work(struct work_struct *work, struct worker *worker,lockdep_assert_held (&pool->lock); +/* The cursor work should not be processed */ +if (unlikely (work->func == mayday_cursor_func)) { +/* only worker_thread() can possibly take this branch */ +WARN_ON_ONCE (worker->rescue_wq); +if (nextp) + *nextp =list_next_entry (work, entry); +list_del_init (&work->entry); +return false; + } +/* * A single work shouldn't be executed concurrently by multiple workers. * __queue_work() ensures that @work doesn't jump to a different pool
@@ -2811,22 +2830,30 @@ static int worker_thread(void *__worker)static bool assign_rescuer_work (struct pool_workqueue *pwq,struct worker *rescuer) {struct worker_pool *pool = pwq->pool; +struct work_struct *cursor = &pwq->mayday_cursor;struct work_struct *work, *n;/* need rescue? */ if (!pwq->nr_active || !need_to_create_worker (pool))return false; -/* -* Slurp in all works issued via this workqueue and -* process'em. -*/ -list_for_each_entry_safe (work, n, &pool->worklist, entry) { -if (get_work_pwq (work) == pwq &&assign_work (work, rescuer, &n)) +/* search from the start or cursor if available */ +if (list_empty (&cursor->entry)) + work = list_first_entry(&pool->worklist, struct work_struct, entry); +else + work =list_next_entry (cursor, entry); + +/* find the next work item to rescue */ +list_for_each_entry_safe_from (work, n, &pool->worklist, entry) { +if (get_work_pwq (work) == pwq &&assign_work (work, rescuer, &n)) { pwq->stats[PWQ_STAT_RESCUED ]++; +/* put the cursor for next search */ +list_move_tail (&cursor->entry, &n->entry); +return true; + } } -return !list_empty (&rescuer->scheduled); +return false; }/**
@@ -2883,6 +2910,7 @@ static int rescuer_thread(void *__rescuer)struct pool_workqueue *pwq =list_first_entry (&wq->maydays, struct pool_workqueue, mayday_node);struct worker_pool *pool = pwq->pool; +unsigned int count =0 ;__set_current_state (TASK_RUNNING );list_del_init (&pwq->mayday_node);
@@ -2895,19 +2923,16 @@ static int rescuer_thread(void *__rescuer)WARN_ON_ONCE (!list_empty (&rescuer->scheduled)); -if (assign_rescuer_work (pwq, rescuer)) { +while (assign_rescuer_work (pwq, rescuer)) {process_scheduled_works (rescuer);/* -* The above execution of rescued work items could -* have created more to rescue through -* pwq_activate_first_inactive() or chained -* queueing. Let's put @pwq back on mayday list so -* that such back-to-back work items, which may be -* being used to relieve memory pressure, don't -* incur MAYDAY_INTERVAL delay inbetween. +* If the per-turn work item limit is reached and other +* PWQs are in mayday, requeue mayday for this PWQ and +* let the rescuer handle the other PWQs first. */ -if (pwq->nr_active &&need_to_create_worker (pool)) { +if (++count >RESCUER_BATCH && !list_empty (&pwq->wq->maydays) && + pwq->nr_active &&need_to_create_worker (pool)) {raw_spin_lock (&wq_mayday_lock);/* * Queue iff we aren't racing destruction
@@ -2918,9 +2943,14 @@ static int rescuer_thread(void *__rescuer)list_add_tail (&pwq->mayday_node, &wq->maydays); }raw_spin_unlock (&wq_mayday_lock); +break ; } } +/* The cursor can not be left behind without the rescuer watching it. */ +if (!list_empty (&pwq->mayday_cursor.entry) &&list_empty (&pwq->mayday_node)) +list_del_init (&pwq->mayday_cursor.entry); +/* * Put the reference grabbed by send_mayday(). @pool won't * go away while we're still attached to it.
@@ -4233,6 +4263,19 @@ static void init_pwq(struct pool_workqueue *pwq, struct workqueue_struct *wq,INIT_LIST_HEAD (&pwq->pwqs_node);INIT_LIST_HEAD (&pwq->mayday_node);kthread_init_work (&pwq->release_work, pwq_release_workfn); + +/* +* Set the dummy cursor work with valid function and get_work_pwq(). +* +* The cursor work should only be in the pwq->pool->worklist, and +* should not be treated as a processable work item. +* +* WORK_STRUCT_PENDING and WORK_STRUCT_INACTIVE just make it less +* surprise for kernel debugging tools and reviewers. +*/ +INIT_WORK (&pwq->mayday_cursor, mayday_cursor_func); +atomic_long_set (&pwq->mayday_cursor.data, (unsigned long )pwq | +WORK_STRUCT_PENDING |WORK_STRUCT_PWQ |WORK_STRUCT_INACTIVE ); }/* sync @pwq with the current state of its associated wq and link it */
Signature · 1 line
2.51.0
PATCH 84/283 smack: /smack/doi must be > 0
In reply to Sasha LevinFrom: Konstantin Andreev <[email protected]>
[ Upstream commit 19c013e1551bf51e1493da1270841d60e4fd3f15 ]
/smack/doi allows writing and keeping negative doi values. Correct values are 0 < doi <= (max 32-bit positive integer)
(2008-02-04, Casey Schaufler)
--- security/smack/smackfs.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
security/smack/smackfs.c +7 -5
@@ -139,7 +139,7 @@ struct smack_parsed_rule {int smk_access2; }; -static int smk_cipso_doi_value =SMACK_CIPSO_DOI_DEFAULT ; +static u32 smk_cipso_doi_value =SMACK_CIPSO_DOI_DEFAULT ;/* * Values for parsing cipso rules
@@ -1580,7 +1580,7 @@ static ssize_t smk_read_doi(struct file *filp, char __user *buf,if (*ppos !=0 )return 0 ; -sprintf (temp,"%d" , smk_cipso_doi_value); +sprintf (temp,"%lu" , (unsigned long )smk_cipso_doi_value); rc =simple_read_from_buffer (buf, count, ppos, temp,strlen (temp));return rc;
@@ -1599,7 +1599,7 @@ static ssize_t smk_write_doi(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { char temp[80]; -int i; +unsigned long u;if (!smack_privileged (CAP_MAC_ADMIN ))return -EPERM ;
@@ -1612,10 +1612,12 @@ static ssize_t smk_write_doi(struct file *file, const char __user *buf, temp[count] ='\0' ; -if (sscanf (temp,"%d" , &i) !=1 ) +if (kstrtoul (temp,10 , &u))return -EINVAL ; - smk_cipso_doi_value = i; +if (u ==CIPSO_V4_DOI_UNKNOWN || u >U32_MAX ) +return -EINVAL ; + smk_cipso_doi_value = u;smk_cipso_doi ();
Signature · 1 line
2.51.0
PATCH 85/283 smack: /smack/doi: accept previously used values
In reply to Sasha LevinFrom: Konstantin Andreev <[email protected]>
[ Upstream commit 33d589ed60ae433b483761987b85e0d24e54584e ]
Writing to /smack/doi a value that has ever been written there in the past disables networking for non-ambient labels.
E.g.
# cat /smack/doi
3
# netlabelctl -p cipso list
Configured CIPSO mappings (1)
DOI value : 3
mapping type : PASS_THROUGH
# netlabelctl -p map list
Configured NetLabel domain mappings (3)
domain: "_" (IPv4)
protocol: UNLABELED
domain: DEFAULT (IPv4)
protocol: CIPSO, DOI = 3
domain: DEFAULT (IPv6)
protocol: UNLABELED # cat /smack/ambient
_
# cat /proc/$$/attr/smack/current
_
# ping -c1 10.1.95.12
64 bytes from 10.1.95.12: icmp_seq=1 ttl=64 time=0.964 ms
# echo foo >/proc/$$/attr/smack/current
# ping -c1 10.1.95.12
64 bytes from 10.1.95.12: icmp_seq=1 ttl=64 time=0.956 ms
unknown option 86 # echo 4 >/smack/doi
# echo 3 >/smack/doi
!> [ 214.050395] smk_cipso_doi:691 cipso add rc = -17
# echo 3 >/smack/doi
!> [ 249.402261] smk_cipso_doi:678 remove rc = -2
!> [ 249.402261] smk_cipso_doi:691 cipso add rc = -17# ping -c1 10.1.95.12 !!> ping: 10.1.95.12: Address family for hostname not supported
# echo _ >/proc/$$/attr/smack/current
# ping -c1 10.1.95.12
64 bytes from 10.1.95.12: icmp_seq=1 ttl=64 time=0.617 msThis happens because Smack keeps decommissioned DOIs, fails to re-add them, and consequently refuses to add the “default” domain map:
# netlabelctl -p cipso list
Configured CIPSO mappings (2)
DOI value : 3
mapping type : PASS_THROUGH
DOI value : 4
mapping type : PASS_THROUGH
# netlabelctl -p map list
Configured NetLabel domain mappings (2)
domain: "_" (IPv4)
protocol: UNLABELED
!> (no ipv4 map for default domain here)
domain: DEFAULT (IPv6)
protocol: UNLABELEDFix by clearing decommissioned DOI definitions and serializing concurrent DOI updates with a new lock.
Also:
- allow /smack/doi to live unconfigured, since adding a map (netlbl_cfg_cipsov4_map_add) may fail. CIPSO_V4_DOI_UNKNOWN(0) indicates the unconfigured DOI
- add new DOI before removing the old default map, so the old map remains if the add fails
(2008-02-04, Casey Schaufler)
--- security/smack/smackfs.c | 71 +++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 26 deletions(-)
security/smack/smackfs.c +45 -26
@@ -68,6 +68,7 @@ enum smk_inos {static DEFINE_MUTEX (smack_cipso_lock);static DEFINE_MUTEX (smack_ambient_lock);static DEFINE_MUTEX (smk_net4addr_lock); +static DEFINE_MUTEX (smk_cipso_doi_lock);#if IS_ENABLED (CONFIG_IPV6 )static DEFINE_MUTEX (smk_net6addr_lock);#endif /* CONFIG_IPV6 */
@@ -139,7 +140,7 @@ struct smack_parsed_rule {int smk_access2; }; -static u32 smk_cipso_doi_value =SMACK_CIPSO_DOI_DEFAULT ; +static u32 smk_cipso_doi_value =CIPSO_V4_DOI_UNKNOWN ;/* * Values for parsing cipso rules
@@ -679,43 +680,60 @@ static const struct file_operations smk_load_ops = { };/** -* smk_cipso_doi - initialize the CIPSO domain +* smk_cipso_doi - set netlabel maps +* @ndoi: new value for our CIPSO DOI +* @gfp_flags: kmalloc allocation context */ -static void smk_cipso_doi (void ) +static int +smk_cipso_doi (u32 ndoi,gfp_t gfp_flags) { -int rc; +int rc =0 ;struct cipso_v4_doi *doip;struct netlbl_audit nai; -smk_netlabel_audit_set (&nai); +mutex_lock (&smk_cipso_doi_lock); - rc =netlbl_cfg_map_del (NULL ,PF_INET ,NULL ,NULL , &nai); -if (rc !=0 ) -printk (KERN_WARNING "%s:%d remove rc = %d\n" , - __func__, __LINE__, rc); +if (smk_cipso_doi_value == ndoi) + goto clr_doi_lock; + +smk_netlabel_audit_set (&nai); - doip =kmalloc (sizeof (struct cipso_v4_doi ),GFP_KERNEL | __GFP_NOFAIL); + doip =kmalloc (sizeof (struct cipso_v4_doi ), gfp_flags); +if (!doip) { + rc = -ENOMEM ; + goto clr_doi_lock; + } doip->map.std =NULL ; - doip->doi = smk_cipso_doi_value; + doip->doi = ndoi; doip->type =CIPSO_V4_MAP_PASS ; doip->tags[0 ] =CIPSO_V4_TAG_RBITMAP ;for (rc =1 ; rc <CIPSO_V4_TAG_MAXCNT ; rc++) doip->tags[rc] =CIPSO_V4_TAG_INVALID ; rc =netlbl_cfg_cipsov4_add (doip, &nai); -if (rc !=0 ) { -printk (KERN_WARNING "%s:%d cipso add rc = %d\n" , - __func__, __LINE__, rc); +if (rc) {kfree (doip); -return ; + goto clr_doi_lock; } - rc =netlbl_cfg_cipsov4_map_add (doip->doi,NULL ,NULL ,NULL , &nai); -if (rc !=0 ) { -printk (KERN_WARNING "%s:%d map add rc = %d\n" , - __func__, __LINE__, rc); -netlbl_cfg_cipsov4_del (doip->doi, &nai); -return ; + +if (smk_cipso_doi_value !=CIPSO_V4_DOI_UNKNOWN ) { + rc =netlbl_cfg_map_del (NULL ,PF_INET ,NULL ,NULL , &nai); +if (rc && rc != -ENOENT ) + goto clr_ndoi_def; + +netlbl_cfg_cipsov4_del (smk_cipso_doi_value, &nai); } + + rc =netlbl_cfg_cipsov4_map_add (ndoi,NULL ,NULL ,NULL , &nai); +if (rc) { + smk_cipso_doi_value =CIPSO_V4_DOI_UNKNOWN ;// no default map +clr_ndoi_def:netlbl_cfg_cipsov4_del (ndoi, &nai); + }else + smk_cipso_doi_value = ndoi; + +clr_doi_lock: +mutex_unlock (&smk_cipso_doi_lock); +return rc; }/**
@@ -1617,11 +1635,8 @@ static ssize_t smk_write_doi(struct file *file, const char __user *buf,if (u ==CIPSO_V4_DOI_UNKNOWN || u >U32_MAX )return -EINVAL ; - smk_cipso_doi_value = u; - -smk_cipso_doi (); -return count; +return smk_cipso_doi (u,GFP_KERNEL ) ? : count; }static const struct file_operations smk_doi_ops = {
@@ -2998,6 +3013,7 @@ static int __init init_smk_fs(void) {int err;int rc; +struct netlbl_audit nai;if (smack_enabled ==0 )return 0 ;
@@ -3016,7 +3032,10 @@ static int __init init_smk_fs(void) } } -smk_cipso_doi (); +smk_netlabel_audit_set (&nai); + (void )netlbl_cfg_map_del (NULL ,PF_INET ,NULL ,NULL , &nai); + (void )smk_cipso_doi (SMACK_CIPSO_DOI_DEFAULT , +GFP_KERNEL | __GFP_NOFAIL);smk_unlbl_ambient (NULL ); rc =smack_populate_secattr (&smack_known_floor);
Signature · 1 line
2.51.0
PATCH 86/283 ASoC: nau8821: Consistently clear interrupts before unmasking
In reply to Sasha LevinFrom: Cristian Ciocaltea <[email protected]>
[ Upstream commit a698679fe8b0fec41d1fb9547a53127a85c1be92 ]
The interrupt handler attempts to perform some IRQ status clear operations *after* rather than *before* unmasking and enabling interrupts. This is a rather fragile approach since it may generally lead to missing IRQ requests or causing spurious interrupts.
Make use of the nau8821_irq_status_clear() helper instead of manipulating the related register directly and ensure any interrupt clearing is performed *after* the target interrupts are disabled/masked and *before* proceeding with additional interrupt unmasking/enablement operations.
This also implicitly drops the redundant clear operation of the ejection IRQ in the interrupt handler, since nau8821_eject_jack() has been already responsible for clearing all active interrupts.
Stable-dep-of: 70237853edf0 ("ASoC: nau8821: Fixup nau8821_enable_jack_detect()")
--- sound/soc/codecs/nau8821.c | 58 ++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 28 deletions(-)
sound/soc/codecs/nau8821.c +30 -28
@@ -1067,20 +1067,24 @@ static void nau8821_eject_jack(struct nau8821 *nau8821)snd_soc_component_disable_pin (component,"MICBIAS" );snd_soc_dapm_sync (dapm); +/* Disable & mask both insertion & ejection IRQs */ +regmap_update_bits (regmap,NAU8821_R12_INTERRUPT_DIS_CTRL , +NAU8821_IRQ_INSERT_DIS |NAU8821_IRQ_EJECT_DIS , +NAU8821_IRQ_INSERT_DIS |NAU8821_IRQ_EJECT_DIS ); +regmap_update_bits (regmap,NAU8821_R0F_INTERRUPT_MASK , +NAU8821_IRQ_INSERT_EN |NAU8821_IRQ_EJECT_EN , +NAU8821_IRQ_INSERT_EN |NAU8821_IRQ_EJECT_EN ); +/* Clear all interruption status */ nau8821_irq_status_clear (regmap,0 ); -/* Enable the insertion interruption, disable the ejection inter- -* ruption, and then bypass de-bounce circuit. -*/ +/* Enable & unmask the insertion IRQ */ regmap_update_bits (regmap,NAU8821_R12_INTERRUPT_DIS_CTRL , -NAU8821_IRQ_EJECT_DIS |NAU8821_IRQ_INSERT_DIS , -NAU8821_IRQ_EJECT_DIS ); -/* Mask unneeded IRQs: 1 - disable, 0 - enable */ +NAU8821_IRQ_INSERT_DIS ,0 );regmap_update_bits (regmap,NAU8821_R0F_INTERRUPT_MASK , -NAU8821_IRQ_EJECT_EN |NAU8821_IRQ_INSERT_EN , -NAU8821_IRQ_EJECT_EN ); +NAU8821_IRQ_INSERT_EN ,0 ); +/* Bypass de-bounce circuit */ regmap_update_bits (regmap,NAU8821_R0D_JACK_DET_CTRL ,NAU8821_JACK_DET_DB_BYPASS ,NAU8821_JACK_DET_DB_BYPASS );
@@ -1104,7 +1108,6 @@ static void nau8821_eject_jack(struct nau8821 *nau8821)NAU8821_IRQ_KEY_RELEASE_DIS | NAU8821_IRQ_KEY_PRESS_DIS); } - }static void nau8821_jdet_work (struct work_struct *work)
@@ -1158,6 +1161,15 @@ static void nau8821_setup_inserted_irq(struct nau8821 *nau8821) {struct regmap *regmap = nau8821->regmap; +/* Disable & mask insertion IRQ */ +regmap_update_bits (regmap,NAU8821_R12_INTERRUPT_DIS_CTRL , +NAU8821_IRQ_INSERT_DIS ,NAU8821_IRQ_INSERT_DIS ); +regmap_update_bits (regmap,NAU8821_R0F_INTERRUPT_MASK , +NAU8821_IRQ_INSERT_EN ,NAU8821_IRQ_INSERT_EN ); + +/* Clear insert IRQ status */ +nau8821_irq_status_clear (regmap,NAU8821_JACK_INSERT_DETECTED ); +/* Enable internal VCO needed for interruptions */ if (nau8821->dapm->bias_level <SND_SOC_BIAS_PREPARE )nau8821_configure_sysclk (nau8821,NAU8821_CLK_INTERNAL ,0 );
@@ -1177,17 +1189,18 @@ static void nau8821_setup_inserted_irq(struct nau8821 *nau8821)regmap_update_bits (regmap,NAU8821_R0D_JACK_DET_CTRL ,NAU8821_JACK_DET_DB_BYPASS ,0 ); +/* Unmask & enable the ejection IRQs */ regmap_update_bits (regmap,NAU8821_R0F_INTERRUPT_MASK , -NAU8821_IRQ_EJECT_EN ,0 ); +NAU8821_IRQ_EJECT_EN ,0 );regmap_update_bits (regmap,NAU8821_R12_INTERRUPT_DIS_CTRL , -NAU8821_IRQ_EJECT_DIS ,0 ); +NAU8821_IRQ_EJECT_DIS ,0 ); }static irqreturn_t nau8821_interrupt (int irq,void *data) {struct nau8821 *nau8821 = (struct nau8821 *)data;struct regmap *regmap = nau8821->regmap; -int active_irq, clear_irq =0 , event =0 , event_mask =0 ; +int active_irq, event =0 , event_mask =0 ;if (regmap_read (regmap,NAU8821_R10_IRQ_STATUS , &active_irq)) {dev_err (nau8821->dev,"failed to read irq status\n" );
@@ -1203,14 +1216,13 @@ static irqreturn_t nau8821_interrupt(int irq, void *data) NAU8821_MICDET_MASK, NAU8821_MICDET_DIS);nau8821_eject_jack (nau8821); event_mask |=SND_JACK_HEADSET ; - clear_irq =NAU8821_JACK_EJECT_IRQ_MASK ; }else if (active_irq &NAU8821_KEY_SHORT_PRESS_IRQ ) { event |=NAU8821_BUTTON ; event_mask |=NAU8821_BUTTON ; - clear_irq =NAU8821_KEY_SHORT_PRESS_IRQ ; +nau8821_irq_status_clear (regmap,NAU8821_KEY_SHORT_PRESS_IRQ ); }else if (active_irq &NAU8821_KEY_RELEASE_IRQ ) { event_mask =NAU8821_BUTTON ; - clear_irq =NAU8821_KEY_RELEASE_IRQ ; +nau8821_irq_status_clear (regmap,NAU8821_KEY_RELEASE_IRQ ); }else if ((active_irq &NAU8821_JACK_INSERT_IRQ_MASK ) ==NAU8821_JACK_INSERT_DETECTED ) {cancel_work_sync (&nau8821->jdet_work);
@@ -1220,27 +1232,17 @@ static irqreturn_t nau8821_interrupt(int irq, void *data)/* detect microphone and jack type */ schedule_work (&nau8821->jdet_work);/* Turn off insertion interruption at manual mode */ -regmap_update_bits (regmap, -NAU8821_R12_INTERRUPT_DIS_CTRL , -NAU8821_IRQ_INSERT_DIS , -NAU8821_IRQ_INSERT_DIS ); -regmap_update_bits (regmap, -NAU8821_R0F_INTERRUPT_MASK , -NAU8821_IRQ_INSERT_EN , -NAU8821_IRQ_INSERT_EN );nau8821_setup_inserted_irq (nau8821); }else {dev_warn (nau8821->dev,"Inserted IRQ fired but not connected\n" );nau8821_eject_jack (nau8821); } + }else { +/* Clear the rightmost interrupt */ +nau8821_irq_status_clear (regmap, active_irq); } -if (!clear_irq) - clear_irq = active_irq; -/* clears the rightmost interruption */ -regmap_write (regmap,NAU8821_R11_INT_CLR_KEY_STATUS , clear_irq); -if (event_mask)snd_soc_jack_report (nau8821->jack, event, event_mask);
Signature · 1 line
2.51.0
PATCH 87/283 ASoC: nau8821: Avoid unnecessary blocking in IRQ handler
In reply to Sasha LevinFrom: Cristian Ciocaltea <[email protected]>
[ Upstream commit ee70bacef1c6050e4836409927294d744dbcfa72 ]
The interrupt handler offloads the microphone detection logic to nau8821_jdet_work(), which implies a sleep operation. However, before being able to process any subsequent hotplug event, the interrupt handler needs to wait for any prior scheduled work to complete.
Move the sleep out of jdet_work by converting it to a delayed work. This eliminates the undesired blocking in the interrupt handler when attempting to cancel a recently scheduled work item and should help reducing transient input reports that might confuse user-space.
Stable-dep-of: 70237853edf0 ("ASoC: nau8821: Fixup nau8821_enable_jack_detect()")
--- sound/soc/codecs/nau8821.c | 22 ++++++++++++---------- sound/soc/codecs/nau8821.h | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-)
sound/soc/codecs/nau8821.c +12 -10
@@ -1113,16 +1113,12 @@ static void nau8821_eject_jack(struct nau8821 *nau8821)static void nau8821_jdet_work (struct work_struct *work) {struct nau8821 *nau8821 = - container_of(work, struct nau8821, jdet_work); + container_of(work, struct nau8821, jdet_work.work);struct snd_soc_dapm_context *dapm = nau8821->dapm;struct snd_soc_component *component =snd_soc_dapm_to_component (dapm);struct regmap *regmap = nau8821->regmap;int jack_status_reg, mic_detected, event =0 , event_mask =0 ; -snd_soc_component_force_enable_pin (component,"MICBIAS" ); -snd_soc_dapm_sync (dapm); -msleep (20 ); -regmap_read (regmap,NAU8821_R58_I2C_DEVICE_ID , &jack_status_reg); mic_detected = !(jack_status_reg &NAU8821_KEYDET );if (mic_detected) {
@@ -1152,6 +1148,7 @@ static void nau8821_jdet_work(struct work_struct *work)snd_soc_component_disable_pin (component,"MICBIAS" );snd_soc_dapm_sync (dapm); } + event_mask |=SND_JACK_HEADSET ;snd_soc_jack_report (nau8821->jack, event, event_mask); }
@@ -1200,6 +1197,7 @@ static irqreturn_t nau8821_interrupt(int irq, void *data) {struct nau8821 *nau8821 = (struct nau8821 *)data;struct regmap *regmap = nau8821->regmap; +struct snd_soc_component *component;int active_irq, event =0 , event_mask =0 ;if (regmap_read (regmap,NAU8821_R10_IRQ_STATUS , &active_irq)) {
@@ -1211,7 +1209,7 @@ static irqreturn_t nau8821_interrupt(int irq, void *data)if ((active_irq &NAU8821_JACK_EJECT_IRQ_MASK ) ==NAU8821_JACK_EJECT_DETECTED ) { -cancel_work_sync (&nau8821->jdet_work); +cancel_delayed_work_sync (&nau8821->jdet_work);regmap_update_bits (regmap,NAU8821_R71_ANALOG_ADC_1 ,NAU8821_MICDET_MASK ,NAU8821_MICDET_DIS );nau8821_eject_jack (nau8821);
@@ -1225,12 +1223,15 @@ static irqreturn_t nau8821_interrupt(int irq, void *data)nau8821_irq_status_clear (regmap,NAU8821_KEY_RELEASE_IRQ ); }else if ((active_irq &NAU8821_JACK_INSERT_IRQ_MASK ) ==NAU8821_JACK_INSERT_DETECTED ) { -cancel_work_sync (&nau8821->jdet_work); +cancel_delayed_work_sync (&nau8821->jdet_work);regmap_update_bits (regmap,NAU8821_R71_ANALOG_ADC_1 ,NAU8821_MICDET_MASK ,NAU8821_MICDET_EN );if (nau8821_is_jack_inserted (regmap)) { -/* detect microphone and jack type */ -schedule_work (&nau8821->jdet_work); +/* Detect microphone and jack type */ + component =snd_soc_dapm_to_component (nau8821->dapm); +snd_soc_component_force_enable_pin (component,"MICBIAS" ); +snd_soc_dapm_sync (nau8821->dapm); +schedule_delayed_work (&nau8821->jdet_work,msecs_to_jiffies (20 ));/* Turn off insertion interruption at manual mode */ nau8821_setup_inserted_irq (nau8821); }else {
@@ -1667,7 +1668,8 @@ int nau8821_enable_jack_detect(struct snd_soc_component *component, nau8821->jack = jack;/* Initiate jack detection work queue */ -INIT_WORK (&nau8821->jdet_work, nau8821_jdet_work); +INIT_DELAYED_WORK (&nau8821->jdet_work, nau8821_jdet_work); + ret =devm_request_threaded_irq (nau8821->dev, nau8821->irq,NULL , nau8821_interrupt,IRQF_TRIGGER_LOW |IRQF_ONESHOT ,"nau8821" , nau8821);
sound/soc/codecs/nau8821.h +1 -1
@@ -559,7 +559,7 @@ struct nau8821 {struct regmap *regmap;struct snd_soc_dapm_context *dapm;struct snd_soc_jack *jack; -struct work_struct jdet_work; +struct delayed_work jdet_work;int irq;int clk_id;int micbias_voltage;
Signature · 1 line
2.51.0
PATCH 88/283 ASoC: nau8821: Fixup nau8821_enable_jack_detect()
In reply to Sasha LevinFrom: Cristian Ciocaltea <[email protected]>
[ Upstream commit 70237853edf0a69773a7370eb74ea2a44dfe3050 ]
The nau8821_enable_jack_detect() function was supposed to allow enabling or disabling jack events reporting. However, once enabled, any subsequent invocation would fail and the following splat is shown:
[ 3136.996771] Hardware name: Valve Jupiter/Jupiter, BIOS F7A0131 01/30/2024 [ 3136.996773] Workqueue: events_unbound deferred_probe_work_func [ 3136.996780] Call Trace: [ 3136.996782] <TASK> [ 3136.996787] dump_stack_lvl+0x6e/0xa0 [ 3136.996796] __setup_irq.cold+0x9c/0xce [ 3136.996803] ? __pfx_irq_default_primary_handler+0x10/0x10 [ 3136.996812] ? __pfx_nau8821_interrupt+0x10/0x10 [snd_soc_nau8821] [ 3136.996825] request_threaded_irq+0xd9/0x160 [ 3136.996853] devm_request_threaded_irq+0x71/0xd0 [ 3136.996859] ? __pfx_nau8821_interrupt+0x10/0x10 [snd_soc_nau8821] [ 3136.996882] nau8821_enable_jack_detect+0xa5/0xc0 [snd_soc_nau8821] [ 3136.996901] acp5x_8821_init+0x8d/0xa0 [snd_soc_acp5x_mach] [ 3136.996917] snd_soc_link_init+0x25/0x50 [snd_soc_core] [ 3136.996958] snd_soc_bind_card+0x615/0xd00 [snd_soc_core] [ 3136.997026] snd_soc_register_card+0x1b2/0x1c0 [snd_soc_core] [ 3136.997064] devm_snd_soc_register_card+0x47/0x90 [snd_soc_core] [ 3136.997108] acp5x_probe+0x72/0xb0 [snd_soc_acp5x_mach] [...] [ 3136.997508] nau8821 i2c-NVTN2020:00: Cannot request irq 58 (-16)
Introduce jdet_active flag to driver data structure and use it to provide one-time initialization of the jack detection work queue and related interrupt line.
Note this is also a prerequisite for additional fixes around module unloading and suspend handling.
--- sound/soc/codecs/nau8821.c | 5 +++++ sound/soc/codecs/nau8821.h | 1 + 2 files changed, 6 insertions(+)
sound/soc/codecs/nau8821.c +5 -0
@@ -1667,8 +1667,13 @@ int nau8821_enable_jack_detect(struct snd_soc_component *component,int ret; nau8821->jack = jack; + +if (nau8821->jdet_active) +return 0 ; +/* Initiate jack detection work queue */ INIT_DELAYED_WORK (&nau8821->jdet_work, nau8821_jdet_work); + nau8821->jdet_active = true; ret = devm_request_threaded_irq(nau8821->dev, nau8821->irq, NULL, nau8821_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT,
sound/soc/codecs/nau8821.h +1 -0
@@ -560,6 +560,7 @@ struct nau8821 {struct snd_soc_dapm_context *dapm;struct snd_soc_jack *jack;struct delayed_work jdet_work; +bool jdet_active;int irq;int clk_id;int micbias_voltage;
Signature · 1 line
2.51.0
PATCH 89/283 drm/amdgpu: Use explicit VCN instance 0 in SR-IOV init
In reply to Sasha LevinFrom: Srinivasan Shanmugam <[email protected]>
[ Upstream commit af26fa751c2eef66916acbf0d3c3e9159da56186 ]
vcn_v2_0_start_sriov() declares a local variable "i" initialized to zero and uses it only as the instance index in SOC15_REG_OFFSET(UVD, i, ...). The value is never changed and all other fields are taken from adev->vcn.inst[0], so this path only ever programs VCN instance 0.
This triggered a Smatch:
warn: iterator 'i' not incremented
Replace the dummy iterator with an explicit instance index of 0 in SOC15_REG_OFFSET() calls.
Reported by: Dan Carpenter <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 45 ++++++++++++++------------- 1 file changed, 23 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +23 -22
@@ -1862,7 +1862,8 @@ static int vcn_v2_0_start_sriov(struct amdgpu_device *adev)struct mmsch_v2_0_cmd_end end = { {0 } };struct mmsch_v2_0_init_header *header;uint32_t *init_table = adev->virt.mm_table.cpu_addr; -uint8_t i =0 ; + +/* This path only programs VCN instance 0. */ header = (struct mmsch_v2_0_init_header *)init_table; direct_wt.cmd_header.command_type =MMSCH_COMMAND__DIRECT_REG_WRITE ;
@@ -1881,93 +1882,93 @@ static int vcn_v2_0_start_sriov(struct amdgpu_device *adev) size =AMDGPU_GPU_PAGE_ALIGN (adev->vcn.fw->size +4 );MMSCH_V2_0_INSERT_DIRECT_RD_MOD_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_STATUS), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_STATUS),0xFFFFFFFF ,0x00000004 );/* mc resume*/ if (adev->firmware.load_type ==AMDGPU_FW_LOAD_PSP ) {MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW), adev->firmware.ucode[AMDGPU_UCODE_ID_VCN ].tmr_mc_addr_lo);MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH), adev->firmware.ucode[AMDGPU_UCODE_ID_VCN ].tmr_mc_addr_hi); offset =0 ; }else {MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW),lower_32_bits (adev->vcn.inst->gpu_addr));MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH),upper_32_bits (adev->vcn.inst->gpu_addr)); offset = size; }MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_VCPU_CACHE_OFFSET0), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_VCPU_CACHE_OFFSET0),0 );MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_VCPU_CACHE_SIZE0), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_VCPU_CACHE_SIZE0), size);MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW),lower_32_bits (adev->vcn.inst->gpu_addr + offset));MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH),upper_32_bits (adev->vcn.inst->gpu_addr + offset));MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_VCPU_CACHE_OFFSET1), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_VCPU_CACHE_OFFSET1),0 );MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_VCPU_CACHE_SIZE1), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_VCPU_CACHE_SIZE1),AMDGPU_VCN_STACK_SIZE );MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_VCPU_CACHE2_64BIT_BAR_LOW),lower_32_bits (adev->vcn.inst->gpu_addr + offset +AMDGPU_VCN_STACK_SIZE ));MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_VCPU_CACHE2_64BIT_BAR_HIGH),upper_32_bits (adev->vcn.inst->gpu_addr + offset +AMDGPU_VCN_STACK_SIZE ));MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_VCPU_CACHE_OFFSET2), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_VCPU_CACHE_OFFSET2),0 );MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_VCPU_CACHE_SIZE2), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_VCPU_CACHE_SIZE2),AMDGPU_VCN_CONTEXT_SIZE );for (r =0 ; r < adev->vcn.num_enc_rings; ++r) { ring = &adev->vcn.inst->ring_enc[r]; ring->wptr =0 ;MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_RB_BASE_LO), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_RB_BASE_LO),lower_32_bits (ring->gpu_addr));MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_RB_BASE_HI), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_RB_BASE_HI),upper_32_bits (ring->gpu_addr));MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_RB_SIZE), +SOC15_REG_OFFSET (UVD ,0 , mmUVD_RB_SIZE), ring->ring_size /4 ); } ring = &adev->vcn.inst->ring_dec; ring->wptr =0 ;MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_RBC_RB_64BIT_BAR_LOW),lower_32_bits (ring->gpu_addr));MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, +SOC15_REG_OFFSET (UVD ,0 , mmUVD_LMI_RBC_RB_64BIT_BAR_HIGH),upper_32_bits (ring->gpu_addr));/* force RBC into idle state */
@@ -1978,7 +1979,7 @@ static int vcn_v2_0_start_sriov(struct amdgpu_device *adev) tmp =REG_SET_FIELD (tmp,UVD_RBC_RB_CNTL ,RB_NO_UPDATE ,1 ); tmp =REG_SET_FIELD (tmp,UVD_RBC_RB_CNTL ,RB_RPTR_WR_EN ,1 );MMSCH_V2_0_INSERT_DIRECT_WT ( -SOC15_REG_OFFSET (UVD , i, mmUVD_RBC_RB_CNTL), tmp); +SOC15_REG_OFFSET (UVD ,0 , mmUVD_RBC_RB_CNTL), tmp);/* add end packet */ tmp =sizeof (struct mmsch_v2_0_cmd_end );
Signature · 1 line
2.51.0
PATCH 90/283 drm/msm/disp/dpu: add merge3d support for sc7280
In reply to Sasha LevinFrom: Mahadevan P <[email protected]>
[ Upstream commit 2892de3f4f985fa779c330468e2f341fdb762ccd ]
On SC7280 targets, display modes with a width greater than the max_mixer_width (2400) are rejected during mode validation when merge3d is disabled. This limitation exists because, without a 3D merge block, two layer mixers cannot be combined(non-DSC interface), preventing large layers from being split across mixers. As a result, higher resolution modes cannot be supported.
Enable merge3d support on SC7280 to allow combining streams from two layer mixers into a single non-DSC interface. This capability removes the width restriction and enables buffer sizes beyond the 2400-pixel limit.
Patchwork: https://patchwork.freedesktop.org/patch/696713/
--- .../gpu/drm/msm/disp/dpu1/catalog/dpu_7_2_sc7280.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/catalog/dpu_7_2_sc7280.h +12 -2
@@ -14,6 +14,7 @@ static const struct dpu_caps sc7280_dpu_caps = { .has_dim_layer = true, .has_idle_pc = true, .max_linewidth = 2400, + .has_3d_merge = true, .pixel_ram_size = DEFAULT_PIXEL_RAM_SIZE, };
@@ -145,7 +146,7 @@ static const struct dpu_pingpong_cfg sc7280_pp[] = { .base = 0x6b000, .len = 0, .features = BIT(DPU_PINGPONG_DITHER), .sblk = &sc7280_pp_sblk, - .merge_3d = 0, + .merge_3d = MERGE_3D_1, .intr_done = DPU_IRQ_IDX(MDP_SSPP_TOP0_INTR, 10), .intr_rdptr = -1, }, {
@@ -153,12 +154,19 @@ static const struct dpu_pingpong_cfg sc7280_pp[] = { .base = 0x6c000, .len = 0, .features = BIT(DPU_PINGPONG_DITHER), .sblk = &sc7280_pp_sblk, - .merge_3d = 0, + .merge_3d = MERGE_3D_1, .intr_done = DPU_IRQ_IDX(MDP_SSPP_TOP0_INTR, 11), .intr_rdptr = -1, }, }; +static const struct dpu_merge_3d_cfg sc7280_merge_3d[] = { + { + .name ="merge_3d_1" , .id =MERGE_3D_1 , + .base =0x4f000 , .len =0x8 , + }, +}; +/* NOTE: sc7280 only has one DSC hard slice encoder */ static const struct dpu_dsc_cfg sc7280_dsc[] = { {
@@ -265,6 +273,8 @@ const struct dpu_mdss_cfg dpu_sc7280_cfg = { .mixer = sc7280_lm, .pingpong_count = ARRAY_SIZE(sc7280_pp), .pingpong = sc7280_pp, + .merge_3d_count = ARRAY_SIZE(sc7280_merge_3d), + .merge_3d = sc7280_merge_3d, .dsc_count = ARRAY_SIZE(sc7280_dsc), .dsc = sc7280_dsc, .wb_count = ARRAY_SIZE(sc7280_wb),
Signature · 1 line
2.51.0
PATCH 91/283 regulator: core: move supply check earlier in set_machine_constraints()
In reply to Sasha LevinFrom: André Draszik <[email protected]>
[ Upstream commit 86a8eeb0e913f4b6a55dabba5122098d4e805e55 ]
Since commit 98e48cd9283d ("regulator: core: resolve supply for boot-on/always-on regulators"), set_machine_constraints() can return -EPROBE_DEFER very late, after it has done a lot of work and configuration of the regulator.
This means that configuration will happen multiple times for no benefit in that case. Furthermore, this can lead to timing-dependent voltage glitches as mentioned e.g. in commit 8a866d527ac0 ("regulator:
core: Resolve supply name earlier to prevent double-init").
We can know that it's going to fail very early, in particular before going through the complete regulator configuration by moving some code around a little.
Do so to avoid re-configuring the regulator multiple times, also avoiding the voltage glitches if we can.
--- drivers/regulator/core.c | 55 ++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-)
drivers/regulator/core.c +30 -25
@@ -1466,6 +1466,33 @@ static int set_machine_constraints(struct regulator_dev *rdev)int ret =0 ;const struct regulator_ops *ops = rdev->desc->ops; +/* +* If there is no mechanism for controlling the regulator then +* flag it as always_on so we don't end up duplicating checks +* for this so much. Note that we could control the state of +* a supply to control the output on a regulator that has no +* direct control. +*/ +if (!rdev->ena_pin && !ops->enable) { +if (rdev->supply_name && !rdev->supply) +return -EPROBE_DEFER ; + +if (rdev->supply) + rdev->constraints->always_on = + rdev->supply->rdev->constraints->always_on; +else + rdev->constraints->always_on = true; + } + +/* +* If we want to enable this regulator, make sure that we know the +* supplying regulator. +*/ +if (rdev->constraints->always_on || rdev->constraints->boot_on) { +if (rdev->supply_name && !rdev->supply) +return -EPROBE_DEFER ; + } + ret =machine_constraints_voltage (rdev, rdev->constraints);if (ret !=0 )return ret;
@@ -1631,37 +1658,15 @@ static int set_machine_constraints(struct regulator_dev *rdev) } } -/* -* If there is no mechanism for controlling the regulator then -* flag it as always_on so we don't end up duplicating checks -* for this so much. Note that we could control the state of -* a supply to control the output on a regulator that has no -* direct control. -*/ -if (!rdev->ena_pin && !ops->enable) { -if (rdev->supply_name && !rdev->supply) -return -EPROBE_DEFER ; - -if (rdev->supply) - rdev->constraints->always_on = - rdev->supply->rdev->constraints->always_on; -else - rdev->constraints->always_on = true; - } -/* If the constraints say the regulator should be on at this point * and we have control then make sure it is enabled. */ if (rdev->constraints->always_on || rdev->constraints->boot_on) {bool supply_enabled = false; -/* If we want to enable this regulator, make sure that we know -* the supplying regulator. -*/ -if (rdev->supply_name && !rdev->supply) -return -EPROBE_DEFER ; - -/* If supplying regulator has already been enabled, +/* We have ensured a potential supply has been resolved above. +* +* If supplying regulator has already been enabled, * it's not intended to have use_count increment * when rdev is only boot-on. */
Signature · 1 line
2.51.0
PATCH 92/283 HID: playstation: Add missing check for input_ff_create_memless
In reply to Sasha LevinFrom: Haotian Zhang <[email protected]>
[ Upstream commit e6807641ac94e832988655a1c0e60ccc806b76dc ]
The ps_gamepad_create() function calls input_ff_create_memless() without verifying its return value, which can lead to incorrect behavior or potential crashes when FF effects are triggered.
Add a check for the return value of input_ff_create_memless().
--- drivers/hid/hid-playstation.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hid/hid-playstation.c +3 -1
@@ -732,7 +732,9 @@ static struct input_dev *ps_gamepad_create(struct hid_device *hdev,#if IS_ENABLED (CONFIG_PLAYSTATION_FF )if (play_effect) {input_set_capability (gamepad,EV_FF ,FF_RUMBLE ); -input_ff_create_memless (gamepad,NULL , play_effect); + ret =input_ff_create_memless (gamepad,NULL , play_effect); +if (ret) +return ERR_PTR (ret); }#endif
Signature · 1 line
2.51.0
PATCH 93/283 drm/msm/dpu: fix CMD panels on DPU 1.x - 3.x
In reply to Sasha LevinFrom: Dmitry Baryshkov <[email protected]>
[ Upstream commit 59ca3d11f5311d9167015fe4f431701614ae0048 ]
DPU units before 4.x don't have a separate CTL_START IRQ to mark the begin of the data transfer. In such a case, wait for the frame transfer to complete rather than trying to wait for the CTL_START interrupt (and obviously hitting the timeout).
Patchwork: https://patchwork.freedesktop.org/patch/696490/
--- drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_cmd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_cmd.c +4 -3
@@ -675,10 +675,11 @@ static int dpu_encoder_phys_cmd_wait_for_commit_done(if (!dpu_encoder_phys_cmd_is_master (phys_enc))return 0 ; -if (phys_enc->hw_ctl->ops.is_started (phys_enc->hw_ctl)) -return dpu_encoder_phys_cmd_wait_for_tx_complete (phys_enc); +if (phys_enc->irq[INTR_IDX_CTL_START ] && + !phys_enc->hw_ctl->ops.is_started (phys_enc->hw_ctl)) +return _dpu_encoder_phys_cmd_wait_for_ctl_start (phys_enc); -return _dpu_encoder_phys_cmd_wait_for_ctl_start (phys_enc); +return dpu_encoder_phys_cmd_wait_for_tx_complete (phys_enc); } static void dpu_encoder_phys_cmd_handle_post_kickoff(
Signature · 1 line
2.51.0
PATCH 94/283 media: ccs: Accommodate C-PHY into the calculation
In reply to Sasha LevinFrom: David Heidelberg <[email protected]>
[ Upstream commit 3085977e734dab74adebb1dda195befce25addff ]
We need to set correct mode for PLL to calculate correct frequency. Signalling mode is known at this point, so use it for that.
--- drivers/media/i2c/ccs/ccs-core.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/media/i2c/ccs/ccs-core.c +15 -1
@@ -3530,7 +3530,21 @@ static int ccs_probe(struct i2c_client *client) sensor->scale_m =CCS_LIM (sensor,SCALER_N_MIN );/* prepare PLL configuration input values */ - sensor->pll.bus_type =CCS_PLL_BUS_TYPE_CSI2_DPHY ; +switch (sensor->hwcfg.csi_signalling_mode) { +case CCS_CSI_SIGNALING_MODE_CSI_2_CPHY : + sensor->pll.bus_type =CCS_PLL_BUS_TYPE_CSI2_CPHY ; +break ; +case CCS_CSI_SIGNALING_MODE_CSI_2_DPHY : +case SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK : +case SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_STROBE : + sensor->pll.bus_type =CCS_PLL_BUS_TYPE_CSI2_DPHY ; +break ; +default : +dev_err (&client->dev,"unsupported signalling mode %u\n" , + sensor->hwcfg.csi_signalling_mode); + rval = -EINVAL ; + goto out_cleanup; + } sensor->pll.csi2.lanes = sensor->hwcfg.lanes;if (CCS_LIM (sensor,CLOCK_CALCULATION ) &CCS_CLOCK_CALCULATION_LANE_SPEED ) {
Signature · 1 line
2.51.0
PATCH 95/283 drm/msm/a2xx: fix pixel shader start on A225
In reply to Sasha LevinFrom: Dmitry Baryshkov <[email protected]>
[ Upstream commit 6a7b0a670ba4d283285d76d45233cbecc5af5e40 ]
A225 has a different PixelShader start address, write correct address while initializing GPU.
Patchwork: https://patchwork.freedesktop.org/patch/689906/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/adreno/a2xx_gpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/adreno/a2xx_gpu.c +4 -1
@@ -77,7 +77,10 @@ static bool a2xx_me_init(struct msm_gpu *gpu)/* Vertex and Pixel Shader Start Addresses in instructions * (3 DWORDS per instruction) */ -OUT_RING (ring,0x80000180 ); +if (adreno_is_a225 (adreno_gpu)) +OUT_RING (ring,0x80000300 ); +else +OUT_RING (ring,0x80000180 );/* Maximum Contexts */ OUT_RING (ring,0x00000001 );/* Write Confirm Interval and The CP will wait the
Signature · 1 line
2.51.0
PATCH 96/283 platform/chrome: cros_typec_switch: Don't touch struct fwnode_handle::dev
In reply to Sasha LevinFrom: Andy Shevchenko <[email protected]>
[ Upstream commit e1adf48853bc715f4deea074932aa1c44eb7abea ]
The 'dev' field in struct fwnode is special and related to device links, There no driver should use it for printing messages. Fix incorrect use of private field.
--- drivers/platform/chrome/cros_typec_switch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/chrome/cros_typec_switch.c +3 -3
@@ -230,20 +230,20 @@ static int cros_typec_register_switches(struct cros_typec_switch_data *sdata) adev =to_acpi_device_node (fwnode);if (!adev) { -dev_err (fwnode->dev,"Couldn't get ACPI device handle\n" ); +dev_err (dev,"Couldn't get ACPI device handle for %pfwP\n" , fwnode); ret = -ENODEV ; goto err_switch; } ret =acpi_evaluate_integer (adev->handle,"_ADR" ,NULL , &index);if (ACPI_FAILURE (ret)) { -dev_err (fwnode->dev,"_ADR wasn't evaluated\n" ); +dev_err (dev,"_ADR wasn't evaluated for %pfwP\n" , fwnode); ret = -ENODATA ; goto err_switch; }if (index >=EC_USB_PD_MAX_PORTS ) { -dev_err (fwnode->dev,"Invalid port index number: %llu\n" , index); +dev_err (dev,"%pfwP: Invalid port index number: %llu\n" , fwnode, index); ret = -EINVAL ; goto err_switch; }
Signature · 1 line
2.51.0
PATCH 97/283 media: uvcvideo: Fix allocation for small frame sizes
In reply to Sasha LevinFrom: Ricardo Ribalda <[email protected]>
[ Upstream commit 40d3ac25c11310bfaa50ed7614846ef75cb69a1e ]
If a frame has size of less or equal than one packet size uvc_alloc_urb_buffers() is unable to allocate memory for it due to a off-by-one error.
Fix the off-by-one-error and now that we are at it, make sure that stream->urb_size has always a valid value when we return from the function, even when an error happens.
--- drivers/media/usb/uvc/uvc_video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_video.c +2 -1
@@ -1819,7 +1819,7 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, npackets =UVC_MAX_PACKETS ;/* Retry allocations until one succeed. */ -for (; npackets >1 ; npackets /=2 ) { +for (; npackets >0 ; npackets /=2 ) { stream->urb_size = psize * npackets;for (i =0 ; i <UVC_URBS ; ++i) {
@@ -1844,6 +1844,7 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,uvc_dbg (stream->dev,VIDEO ,"Failed to allocate URB buffers (%u bytes per packet)\n" , psize); + stream->urb_size =0 ;return 0 ; }
Signature · 1 line
2.51.0
PATCH 98/283 platform/chrome: cros_ec_lightbar: Fix response size initialization
In reply to Sasha LevinFrom: Tzung-Bi Shih <[email protected]>
[ Upstream commit ec0dd36dbf8b0b209e63d0cd795451fa2203c736 ]
Commit 1e7913ff5f9f ("platform/chrome: cros_ec_lightbar: Reduce ligthbar get version command") meant to set smaller values for both request and response sizes.
However, it incorrectly assigned the response size to the result field instead of insize. Fix it.
--- drivers/platform/chrome/cros_ec_lightbar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_lightbar.c +1 -1
@@ -118,7 +118,7 @@ static int get_lightbar_version(struct cros_ec_dev *ec, param = (struct ec_params_lightbar *)msg->data; param->cmd =LIGHTBAR_CMD_VERSION ; msg->outsize =sizeof (param->cmd); - msg->result =sizeof (resp->version); + msg->insize =sizeof (resp->version); ret =cros_ec_cmd_xfer_status (ec->ec_dev, msg);if (ret <0 && ret != -EINVAL ) { ret =0 ;
Signature · 1 line
2.51.0
PATCH 99/283 spi: tools: Add include folder to .gitignore
In reply to Sasha LevinFrom: Francesco Lavra <[email protected]>
[ Upstream commit 5af56f30c4fcbade4a92f94dadfea517d1db9703 ]
The Makefile for the SPI tools creates an include/linux/spi folder and some symlinks inside it. After running make -C spi/tools, this folder shows up as untracked in the git status.
Add the above folder to the .gitignore file.
--- tools/spi/.gitignore | 1 + 1 file changed, 1 insertion(+)
tools/spi/.gitignore +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only spidev_fdx spidev_test +include/
Signature · 1 line
2.51.0
PATCH 100/283 Revert "hwmon: (ibmpex) fix use-after-free in high/low store"
In reply to Sasha LevinFrom: Guenter Roeck <[email protected]>
[ Upstream commit 8bde3e395a85017f12af2b0ba5c3684f5af9c006 ]
This reverts commit 6946c726c3f4c36f0f049e6f97e88c510b15f65d.
Jean Delvare points out that the patch does not completely fix the reported problem, that it in fact introduces a (new) race condition, and that it may actually not be needed in the first place.
Various AI reviews agree. Specific and relevant AI feedback:
"
This reordering sets the driver data to NULL before removing the sensor attributes in the loop below.
ibmpex_show_sensor() retrieves this driver data via dev_get_drvdata() but does not check if it is NULL before dereferencing it to access data->sensors[].
If a userspace process reads a sensor file (like temp1_input) while this delete function is running, could it race with the dev_set_drvdata(..., NULL) call here and crash in ibmpex_show_sensor()?
Would it be safer to keep the original order where device_remove_file() is called before clearing the driver data? device_remove_file() should wait for any active sysfs callbacks to complete, which might already prevent the use-after-free this patch intends to fix.
"
Revert the offending patch. If it can be shown that the originally reported alleged race condition does indeed exist, it can always be re-introduced with a complete fix.
--- drivers/hwmon/ibmpex.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/hwmon/ibmpex.c +2 -7
@@ -282,9 +282,6 @@ static ssize_t ibmpex_high_low_store(struct device *dev, {struct ibmpex_bmc_data *data =dev_get_drvdata (dev); -if (!data) -return -ENODEV ; -ibmpex_reset_high_low_data (data);return count;
@@ -517,9 +514,6 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data) {int i, j; -hwmon_device_unregister (data->hwmon_dev); -dev_set_drvdata (data->bmc_device,NULL ); -device_remove_file (data->bmc_device, &sensor_dev_attr_reset_high_low.dev_attr);device_remove_file (data->bmc_device, &sensor_dev_attr_name.dev_attr);
@@ -533,7 +527,8 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data) }list_del (&data->list); - +dev_set_drvdata (data->bmc_device,NULL ); +hwmon_device_unregister (data->hwmon_dev);ipmi_destroy_user (data->user);kfree (data->sensors);kfree (data);
Signature · 1 line
2.51.0
PATCH 101/283 PCI: mediatek: Fix IRQ domain leak when MSI allocation fails
In reply to Sasha LevinFrom: Haotian Zhang <[email protected]>
[ Upstream commit 7f0cdcddf8bef1c8c18f9be6708073fd3790a20f ]
In mtk_pcie_init_irq_domain(), if mtk_pcie_allocate_msi_domains() fails after port->irq_domain has been successfully created via irq_domain_create_linear(), the function returns directly without cleaning up the allocated IRQ domain, resulting in a resource leak.
Add irq_domain_remove() call in the error path to properly release the INTx IRQ domain before returning the error.
--- drivers/pci/controller/pcie-mediatek.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-mediatek.c +3 -1
@@ -587,8 +587,10 @@ static int mtk_pcie_init_irq_domain(struct mtk_pcie_port *port,if (IS_ENABLED (CONFIG_PCI_MSI )) { ret =mtk_pcie_allocate_msi_domains (port); -if (ret) +if (ret) { +irq_domain_remove (port->irq_domain);return ret; + } }return 0 ;
Signature · 1 line
2.51.0
PATCH 102/283 Documentation: PCI: endpoint: Fix ntb/vntb copy & paste errors
In reply to Sasha LevinFrom: Baruch Siach <[email protected]>
[ Upstream commit ad0c6da5be901f5c181490f683d22b416059bccb ]
Fix copy & paste errors by changing the references from 'ntb' to 'vntb'.
--- Documentation/PCI/endpoint/pci-vntb-howto.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
Documentation/PCI/endpoint/pci-vntb-howto.rst +7 -7
@@ -52,14 +52,14 @@ pci-epf-vntb device, the following commands can be used:: # cd /sys/kernel/config/pci_ep/ # mkdir functions/pci_epf_vntb/func1 -The "mkdir func1" above creates the pci-epf-ntb function device that will +The "mkdir func1" above creates the pci-epf-vntb function device that will be probed by pci_epf_vntb driver. The PCI endpoint framework populates the directory with the following configurable fields:: - # ls functions/pci_epf_ntb/func1 - baseclass_code deviceid msi_interrupts pci-epf-ntb.0 + # ls functions/pci_epf_vntb/func1 + baseclass_code deviceid msi_interrupts pci-epf-vntb.0 progif_code secondary subsys_id vendorid cache_line_size interrupt_pin msix_interrupts primary revid subclass_code subsys_vendor_id
@@ -106,13 +106,13 @@ A sample configuration for virtual NTB driver for virtual PCI bus:: # echo 0x080A > functions/pci_epf_vntb/func1/pci_epf_vntb.0/vntb_pid # echo 0x10 > functions/pci_epf_vntb/func1/pci_epf_vntb.0/vbus_number -Binding pci-epf-ntb Device to EP Controller +Binding pci-epf-vntb Device to EP Controller -------------------------------------------- NTB function device should be attached to PCI endpoint controllers connected to the host. - # ln -s controllers/5f010000.pcie_ep functions/pci-epf-ntb/func1/primary + # ln -s controllers/5f010000.pcie_ep functions/pci_epf_vntb/func1/primary Once the above step is completed, the PCI endpoint controllers are ready to establish a link with the host.
@@ -134,7 +134,7 @@ lspci Output at Host side ------------------------- Note that the devices listed here correspond to the values populated in -"Creating pci-epf-ntb Device" section above:: +"Creating pci-epf-vntb Device" section above:: # lspci 00:00.0 PCI bridge: Freescale Semiconductor Inc Device 0000 (rev 01)
@@ -147,7 +147,7 @@ lspci Output at EP Side / Virtual PCI bus ----------------------------------------- Note that the devices listed here correspond to the values populated in -"Creating pci-epf-ntb Device" section above:: +"Creating pci-epf-vntb Device" section above:: # lspci 10:00.0 Unassigned class [ffff]: Dawicontrol Computersysteme GmbH Device 1234 (rev ff)
Signature · 1 line
2.51.0
PATCH 103/283 PCI/PM: Avoid redundant delays on D3hot->D3cold
In reply to Sasha LevinFrom: Brian Norris <[email protected]>
[ Upstream commit 4d982084507d663df160546c4c48066a8887ed89 ]
When transitioning to D3cold, __pci_set_power_state() first transitions to D3hot. If the device was already in D3hot, this adds excess work:
(a) read/modify/write PMCSR; and
(b) excess delay (pci_dev_d3_sleep()).
For (b), we already performed the necessary delay on the previous D3hot entry; this was extra noticeable when evaluating runtime PM transition latency.
Check whether we're already in the target state before continuing.
Note that __pci_set_power_state() already does this same check for other state transitions, but D3cold is special because __pci_set_power_state() converts it to D3hot for the purposes of PMCSR.
This seems to be an oversight in commit 0aacdc957401 ("PCI/PM: Clean up pci_set_low_power_state()").
--- drivers/pci/pci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pci/pci.c +3 -0
@@ -1427,6 +1427,9 @@ static int pci_set_low_power_state(struct pci_dev *dev, pci_power_t state, bool || (state == PCI_D2 && !dev->d2_support))return -EIO ; +if (dev->current_state == state) +return 0 ; +pci_read_config_word (dev, dev->pm_cap +PCI_PM_CTRL , &pmcsr);if (PCI_POSSIBLE_ERROR (pmcsr)) { pci_err(dev, "Unable to change power state from %s to %s, device inaccessible\n",
Signature · 1 line
2.51.0
PATCH 104/283 PCI/P2PDMA: Release per-CPU pgmap ref when vm_insert_page() fails
In reply to Sasha LevinFrom: Hou Tao <[email protected]>
[ Upstream commit 6220694c52a5a04102b48109e4f24e958b559bd3 ]
When vm_insert_page() fails in p2pmem_alloc_mmap(), p2pmem_alloc_mmap() doesn't invoke percpu_ref_put() to free the per-CPU ref of pgmap acquired after gen_pool_alloc_owner(), and memunmap_pages() will hang forever when trying to remove the PCI device.
Fix it by adding the missed percpu_ref_put().
--- drivers/pci/p2pdma.c | 1 + 1 file changed, 1 insertion(+)
drivers/pci/p2pdma.c +1 -0
@@ -143,6 +143,7 @@ static int p2pmem_alloc_mmap(struct file *filp, struct kobject *kobj, ret =vm_insert_page (vma, vaddr,virt_to_page (kaddr));if (ret) {gen_pool_free (p2pdma->pool, (uintptr_t )kaddr, len); +percpu_ref_put (ref);return ret; }percpu_ref_get (ref);
Signature · 1 line
2.51.0
PATCH 105/283 Documentation: tracing: Add ring-buffer mapping
In reply to Sasha LevinFrom: Vincent Donnefort <[email protected]>
[ Upstream commit a1e0dd7ce38af3fb1a3bc54a222a7c5e4eaa4202 ]
It is now possible to mmap() a ring-buffer to stream its content. Add some documentation and a code example.
Stable-dep-of: 8236fc613d44 ("Documentation: tracing: Add PCI tracepoint documentation")
--- Documentation/trace/index.rst | 1 + Documentation/trace/ring-buffer-map.rst | 106 ++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 Documentation/trace/ring-buffer-map.rst
Documentation/trace/index.rst +1 -0
@@ -29,6 +29,7 @@ Linux Tracing Technologies timerlat-tracer intel_th ring-buffer-design + ring-buffer-map stm sys-t coresight/index
Documentation/trace/ring-buffer-map.rst new file +106 -0
106 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH 106/283 docs: fix WARNING document not included in any toctree
In reply to Sasha LevinFrom: SurajSonawane2415 <[email protected]>
[ Upstream commit 998bece1d22bf2cbc819cb3a492148932d4e12a8 ]
Add debugging.rst to the relevant toctree to fix warning about missing documentation inclusion in toctree.
Stable-dep-of: 8236fc613d44 ("Documentation: tracing: Add PCI tracepoint documentation")
--- Documentation/trace/index.rst | 1 + 1 file changed, 1 insertion(+)
Documentation/trace/index.rst +1 -0
@@ -24,6 +24,7 @@ Linux Tracing Technologies histogram histogram-design boottime-trace + debugging hwlat_detector osnoise-tracer timerlat-tracer
Signature · 1 line
2.51.0
PATCH 107/283 Documentation: trace: Refactor toctree
In reply to Sasha LevinFrom: Purva Yeshi <[email protected]>
[ Upstream commit f0ba72e65516d1d86f40c79a49c4ba01c9555592 ]
Refactor table of contents of kernel tracing subsystem docs to improve clarity, structure, and organization:
- Reformat sections and add appropriate headings
- Improve section grouping and refine descriptions for each group
- Add docs intro paragraph
Stable-dep-of: 8236fc613d44 ("Documentation: tracing: Add PCI tracepoint documentation")
--- Documentation/trace/index.rst | 96 +++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 16 deletions(-)
Documentation/trace/index.rst +80 -16
@@ -1,39 +1,103 @@ -========================== -Linux Tracing Technologies -========================== +================================ +Linux Tracing Technologies Guide +================================ + +Tracing in the Linux kernel is a powerful mechanism that allows +developers and system administrators to analyze and debug system +behavior. This guide provides documentation on various tracing +frameworks and tools available in the Linux kernel. + +Introduction to Tracing +----------------------- + +This section provides an overview of Linux tracing mechanisms +and debugging approaches. .. toctree:: :maxdepth: 2 - ftrace-design + debugging + tracepoints tracepoint-analysis + ring-buffer-map + +Core Tracing Frameworks +----------------------- + +The following are the primary tracing frameworks integrated into +the Linux kernel. + +.. toctree:: + :maxdepth: 1 + ftrace + ftrace-design ftrace-uses - fprobe kprobes kprobetrace - uprobetracer fprobetrace - tracepoints + fprobe + ring-buffer-design + +Event Tracing and Analysis +-------------------------- + +A detailed explanation of event tracing mechanisms and their +applications. + +.. toctree:: + :maxdepth: 1 + events events-kmem events-power events-nmi events-msr - mmiotrace + boottime-trace histogram histogram-design - boottime-trace - debugging - hwlat_detector - osnoise-tracer - timerlat-tracer + +Hardware and Performance Tracing +-------------------------------- + +This section covers tracing features that monitor hardware +interactions and system performance. + +.. toctree:: + :maxdepth: 1 + intel_th - ring-buffer-design - ring-buffer-map stm sys-t coresight/index - user_events rv/index hisi-ptt + mmiotrace + hwlat_detector + osnoise-tracer + timerlat-tracer + +User-Space Tracing +------------------ + +These tools allow tracing user-space applications and +interactions. + +.. toctree:: + :maxdepth: 1 + + user_events + uprobetracer + +Additional Resources +-------------------- + +For more details, refer to the respective documentation of each +tracing tool and framework. + +.. only:: subproject and html + + Indices + ======= + + * :ref:`genindex`
Signature · 1 line
2.51.0
PATCH 108/283 Documentation: tracing: Add PCI tracepoint documentation
In reply to Sasha LevinFrom: Shuai Xue <[email protected]>
[ Upstream commit 8236fc613d44e59f6736d6c3e9efffaf26ab7f00 ]
The PCI tracing system provides tracepoints to monitor critical hardware events that can impact system performance and reliability. Add documentation about it.
[bhelgaas: squash fixes:
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]]
--- Documentation/trace/events-pci.rst | 74 ++++++++++++++++++++++++++++++ Documentation/trace/index.rst | 1 + 2 files changed, 75 insertions(+) create mode 100644 Documentation/trace/events-pci.rst
Documentation/trace/events-pci.rst new file +74 -0
@@ -0,0 +1,74 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========================== +Subsystem Trace Points: PCI +=========================== + +Overview +======== +The PCI tracing system provides tracepoints to monitor critical hardware events +that can impact system performance and reliability. These events normally show +up here: + + /sys/kernel/tracing/events/pci + +Cf. include/trace/events/pci.h for the events definitions. + +Available Tracepoints +===================== + +pci_hp_event +------------ + +Monitors PCI hotplug events including card insertion/removal and link +state changes. +:: + + pci_hp_event "%s slot:%s, event:%s\n" + +**Event Types**: + +* ``LINK_UP`` - PCIe link established +* ``LINK_DOWN`` - PCIe link lost +* ``CARD_PRESENT`` - Card detected in slot +* ``CARD_NOT_PRESENT`` - Card removed from slot + +**Example Usage**:: + + # Enable the tracepoint + echo 1 > /sys/kernel/debug/tracing/events/pci/pci_hp_event/enable + + # Monitor events (the following output is generated when a device is hotplugged) + cat /sys/kernel/debug/tracing/trace_pipe + irq/51-pciehp-88 [001] ..... 1311.177459: pci_hp_event: 0000:00:02.0 slot:10, event:CARD_PRESENT + + irq/51-pciehp-88 [001] ..... 1311.177566: pci_hp_event: 0000:00:02.0 slot:10, event:LINK_UP + +pcie_link_event +--------------- + +Monitors PCIe link speed changes and provides detailed link status information. +:: + + pcie_link_event "%s type:%d, reason:%d, cur_bus_speed:%d, max_bus_speed:%d, width:%u, flit_mode:%u, status:%s\n" + +**Parameters**: + +* ``type`` - PCIe device type (4=Root Port, etc.) +* ``reason`` - Reason for link change: + + - ``0`` - Link retrain + - ``1`` - Bus enumeration + - ``2`` - Bandwidth notification enable + - ``3`` - Bandwidth notification IRQ + - ``4`` - Hotplug event + + +**Example Usage**:: + + # Enable the tracepoint + echo 1 > /sys/kernel/debug/tracing/events/pci/pcie_link_event/enable + + # Monitor events (the following output is generated when a device is hotplugged) + cat /sys/kernel/debug/tracing/trace_pipe + irq/51-pciehp-88 [001] ..... 381.545386: pcie_link_event: 0000:00:02.0 type:4, reason:4, cur_bus_speed:20, max_bus_speed:23, width:1, flit_mode:0, status:DLLLA
Documentation/trace/index.rst +1 -0
@@ -53,6 +53,7 @@ applications. events-power events-nmi events-msr + events-pci boottime-trace histogram histogram-design
Signature · 1 line
2.51.0
PATCH 109/283 PCI: Do not attempt to set ExtTag for VFs
In reply to Sasha LevinFrom: Håkon Bugge <[email protected]>
[ Upstream commit 73711730a1128d91ebca1a6994ceeb18f36cb0cd ]
The bit for enabling extended tags is Reserved and Preserved (RsvdP) for VFs, according to PCIe r7.0 section 7.5.3.4 table 7.21. Hence, bail out early from pci_configure_extended_tags() if the device is a VF.
Otherwise, we may see incorrect log messages such as:
kernel: pci 0000:af:00.2: enabling Extended Tags
(af:00.2 is a VF)
--- drivers/pci/probe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/probe.c +2 -1
@@ -2101,7 +2101,8 @@ int pci_configure_extended_tags(struct pci_dev *dev, void *ign)u16 ctl;int ret; -if (!pci_is_pcie (dev)) +/* PCI_EXP_DEVCTL_EXT_TAG is RsvdP in VFs */ +if (!pci_is_pcie (dev) || dev->is_virtfn)return 0 ; ret =pcie_capability_read_dword (dev,PCI_EXP_DEVCAP , &cap);
Signature · 1 line
2.51.0
PATCH 110/283 PCI/portdrv: Fix potential resource leak
In reply to Sasha LevinFrom: Uwe Kleine-König <[email protected]>
[ Upstream commit 01464a3fdf91c041a381d93a1b6fefbdb819a46f ]
pcie_port_probe_service() unconditionally calls get_device() (unless it fails). So drop that reference also unconditionally as it's fine for a PCIe driver to not have a remove callback.
--- drivers/pci/pcie/portdrv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/pcie/portdrv.c +3 -3
@@ -554,10 +554,10 @@ static int pcie_port_remove_service(struct device *dev) pciedev =to_pcie_device (dev); driver =to_service_driver (dev->driver); -if (driver && driver->remove) { +if (driver && driver->remove) driver->remove (pciedev); -put_device (dev); - } + +put_device (dev);return 0 ; }
Signature · 1 line
2.51.0
PATCH 111/283 quota: fix livelock between quotactl and freeze_super
In reply to Sasha LevinFrom: Abhishek Bapat <[email protected]>
[ Upstream commit 77449e453dfc006ad738dec55374c4cbc056fd39 ]
When a filesystem is frozen, quotactl_block() enters a retry loop waiting for the filesystem to thaw. It acquires s_umount, checks the freeze state, drops s_umount and uses sb_start_write() - sb_end_write() pair to wait for the unfreeze.
However, this retry loop can trigger a livelock issue, specifically on kernels with preemption disabled.
The mechanism is as follows:
1. freeze_super() sets SB_FREEZE_WRITE and calls sb_wait_write().
2. sb_wait_write() calls percpu_down_write(), which initiates synchronize_rcu().
3. Simultaneously, quotactl_block() spins in its retry loop, immediately executing the sb_start_write() - sb_end_write() pair.
4. Because the kernel is non-preemptible and the loop contains no scheduling points, quotactl_block() never yields the CPU. This prevents that CPU from reaching an RCU quiescent state.
5. synchronize_rcu() in the freezer thread waits indefinitely for the quotactl_block() CPU to report a quiescent state.
6. quotactl_block() spins indefinitely waiting for the freezer to advance, which it cannot do as it is blocked on the RCU sync.
This results in a hang of the freezer process and 100% CPU usage by the quota process.
While this can occur intermittently on multi-core systems, it is reliably reproducing on a node with the following script, running both the freezer and the quota toggle on the same CPU:
# mkfs.ext4 -O quota /dev/sda 2g && mkdir a_mount
# mount /dev/sda -o quota,usrquota,grpquota a_mount
# taskset -c 3 bash -c "while true; do xfs_freeze -f a_mount; \
xfs_freeze -u a_mount; done" &
# taskset -c 3 bash -c "while true; do quotaon a_mount; \
quotaoff a_mount; done" &Adding cond_resched() to the retry loop fixes the issue. It acts as an RCU quiescent state, allowing synchronize_rcu() in percpu_down_write() to complete.
--- fs/quota/quota.c | 1 + 1 file changed, 1 insertion(+)
fs/quota/quota.c +1 -0
@@ -899,6 +899,7 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)sb_start_write (sb);sb_end_write (sb);put_super (sb); +cond_resched (); goto retry; }return sb;
Signature · 1 line
2.51.0
PATCH 112/283 net: mctp-i2c: fix duplicate reception of old data
In reply to Sasha LevinFrom: Jian Zhang <[email protected]>
[ Upstream commit ae4744e173fadd092c43eda4ca92dcb74645225a ]
The MCTP I2C slave callback did not handle I2C_SLAVE_READ_REQUESTED events. As a result, i2c read event will trigger repeated reception of old data, reset rx_pos when a read request is received.
Stable-dep-of: 2a14e91b6d76 ("mctp i2c: initialise event handler read bytes")
--- drivers/net/mctp/mctp-i2c.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/mctp/mctp-i2c.c +6 -0
@@ -243,6 +243,9 @@ static int mctp_i2c_slave_cb(struct i2c_client *client,return 0 ;switch (event) { +case I2C_SLAVE_READ_REQUESTED : + midev->rx_pos =0 ; +break ;case I2C_SLAVE_WRITE_RECEIVED :if (midev->rx_pos <MCTP_I2C_BUFSZ ) { midev->rx_buffer[midev->rx_pos] = *val;
@@ -280,6 +283,9 @@ static int mctp_i2c_recv(struct mctp_i2c_dev *midev)size_t recvlen;int status; +if (midev->rx_pos ==0 ) +return 0 ; +/* + 1 for the PEC */ if (midev->rx_pos <MCTP_I2C_MINLEN +1 ) { ndev->stats.rx_length_errors++;
Signature · 1 line
2.51.0
PATCH 113/283 mctp i2c: initialise event handler read bytes
In reply to Sasha LevinFrom: Matt Johnston <[email protected]>
[ Upstream commit 2a14e91b6d76639dac70ea170f4384c1ee3cb48d ]
Set a 0xff value for i2c reads of an mctp-i2c device. Otherwise reads will return "val" from the i2c bus driver. For i2c-aspeed and i2c-npcm7xx that is a stack uninitialised u8.
Tested with "i2ctransfer -y 1 r10@0x34" where 0x34 is a mctp-i2c instance, now it returns all 0xff.
--- drivers/net/mctp/mctp-i2c.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/mctp/mctp-i2c.c +3 -0
@@ -244,7 +244,10 @@ static int mctp_i2c_slave_cb(struct i2c_client *client,switch (event) {case I2C_SLAVE_READ_REQUESTED : +case I2C_SLAVE_READ_PROCESSED : +/* MCTP I2C transport only uses writes */ midev->rx_pos =0 ; + *val =0xff ;break ;case I2C_SLAVE_WRITE_RECEIVED :if (midev->rx_pos <MCTP_I2C_BUFSZ ) {
Signature · 1 line
2.51.0
PATCH 114/283 wifi: cfg80211: stop NAN and P2P in cfg80211_leave
In reply to Sasha LevinFrom: Miri Korenblit <[email protected]>
[ Upstream commit e1696c8bd0056bc1a5f7766f58ac333adc203e8a ]
Seems that there is an assumption that this function should be called only for netdev interfaces, but it can also be called in suspend, or from nl80211_netlink_notify (indirectly).
Note that the documentation of NL80211_ATTR_SOCKET_OWNER explicitly says that NAN interfaces would be destroyed as well in the nl80211_netlink_notify case.
Fix this by also stopping P2P and NAN.
--- net/wireless/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/wireless/core.c +3 -1
@@ -1331,8 +1331,10 @@ void __cfg80211_leave(struct cfg80211_registered_device *rdev,__cfg80211_leave_ocb (rdev, dev);break ;case NL80211_IFTYPE_P2P_DEVICE : +cfg80211_stop_p2p_device (rdev, wdev); +break ;case NL80211_IFTYPE_NAN : -/* cannot happen, has no netdev */ +cfg80211_stop_nan (rdev, wdev);break ;case NL80211_IFTYPE_AP_VLAN :case NL80211_IFTYPE_MONITOR :
Signature · 1 line
2.51.0
PATCH 115/283 netfilter: nf_tables: reset table validation state on abort
In reply to Sasha LevinFrom: Florian Westphal <[email protected]>
[ Upstream commit 6f93616a7323d646d18db9c09f147e453b40fdd7 ]
If a transaction fails the final validation in the commit hook, the table validation state is changed to NFT_VALIDATE_DO and a replay of the batch is performed. Every rule insert will then do a graph validation.
This is much slower, but provides better error reporting to the user because we can point at the rule that introduces the validation issue.
Without this reset the affected table(s) remain in full validation mode, i.e. on next transaction we start with slow-mode.
This makes the next transaction after a failed incremental update very slow:
# time iptables-restore < /tmp/ruleset real 0m0.496s [..] # time iptables -A CALLEE -j CALLER iptables v1.8.11 (nf_tables): RULE_APPEND failed (Too many links): rule in chain CALLEE real 0m0.022s [..] # time iptables-restore < /tmp/ruleset real 1m22.355s [..]
After this patch, 2nd iptables-restore is back to ~0.5s.
--- net/netfilter/nf_tables_api.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/netfilter/nf_tables_api.c +7 -0
@@ -10824,6 +10824,13 @@ static int nf_tables_abort(struct net *net, struct sk_buff *skb, ret =__nf_tables_abort (net, action);nft_gc_seq_end (nft_net, gc_seq); +if (action ==NFNL_ABORT_NONE ) { +struct nft_table *table; + +list_for_each_entry (table, &nft_net->tables, list) + table->validate_state =NFT_VALIDATE_SKIP ; + } +WARN_ON_ONCE (!list_empty (&nft_net->commit_list));/* module autoload needs to happen after GC sequence update because it
Signature · 1 line
2.51.0
PATCH 116/283 netfilter: nf_conncount: make nf_conncount_gc_list() to disable BH
In reply to Sasha LevinFrom: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit c0362b5748282e22fa1592a8d3474f726ad964c2 ]
For convenience when performing GC over the connection list, make nf_conncount_gc_list() to disable BH. This unifies the behavior with nf_conncount_add() and nf_conncount_count().
Stable-dep-of: 21d033e47273 ("netfilter: nf_conncount: increase the connection clean up limit to 64")
--- net/netfilter/nf_conncount.c | 24 +++++++++++++++++------- net/netfilter/nft_connlimit.c | 7 +------ 2 files changed, 18 insertions(+), 13 deletions(-)
net/netfilter/nf_conncount.c +17 -7
@@ -282,8 +282,8 @@ void nf_conncount_list_init(struct nf_conncount_list *list)EXPORT_SYMBOL_GPL (nf_conncount_list_init);/* Return true if the list is empty. Must be called with BH disabled. */ -bool nf_conncount_gc_list (struct net *net, -struct nf_conncount_list *list) +static bool __nf_conncount_gc_list (struct net *net, +struct nf_conncount_list *list) {const struct nf_conntrack_tuple_hash *found;struct nf_conncount_tuple *conn, *conn_n;
@@ -295,10 +295,6 @@ bool nf_conncount_gc_list(struct net *net,if ((u32 )jiffies ==READ_ONCE (list->last_gc))return false; -/* don't bother if other cpu is already doing GC */ -if (!spin_trylock (&list->list_lock)) -return false; -list_for_each_entry_safe (conn, conn_n, &list->head, node) { found =find_or_evict (net, list, conn);if (IS_ERR (found)) {
@@ -327,7 +323,21 @@ bool nf_conncount_gc_list(struct net *net,if (!list->count) ret = true; list->last_gc = (u32 )jiffies; -spin_unlock (&list->list_lock); + +return ret; +} + +bool nf_conncount_gc_list (struct net *net, +struct nf_conncount_list *list) +{ +bool ret; + +/* don't bother if other cpu is already doing GC */ +if (!spin_trylock_bh (&list->list_lock)) +return false; + + ret =__nf_conncount_gc_list (net, list); +spin_unlock_bh (&list->list_lock);return ret; }
net/netfilter/nft_connlimit.c +1 -6
@@ -232,13 +232,8 @@ static void nft_connlimit_destroy_clone(const struct nft_ctx *ctx,static bool nft_connlimit_gc (struct net *net,const struct nft_expr *expr) {struct nft_connlimit *priv =nft_expr_priv (expr); -bool ret; -local_bh_disable (); - ret =nf_conncount_gc_list (net, priv->list); -local_bh_enable (); - -return ret; +return nf_conncount_gc_list (net, priv->list); }static struct nft_expr_type nft_connlimit_type;
Signature · 1 line
2.51.0
PATCH 117/283 netfilter: nf_conncount: increase the connection clean up limit to 64
In reply to Sasha LevinFrom: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 21d033e472735ecec677f1ae46d6740b5e47a4f3 ]
After the optimization to only perform one GC per jiffy, a new problem was introduced. If more than 8 new connections are tracked per jiffy the list won't be cleaned up fast enough possibly reaching the limit wrongly.
In order to prevent this issue, only skip the GC if it was already triggered during the same jiffy and the increment is lower than the clean up limit. In addition, increase the clean up limit to 64 connections to avoid triggering GC too often and do more effective GCs.
This has been tested using a HTTP server and several performance tools while having nft_connlimit/xt_connlimit or OVS limit configured.
Output of slowhttptest + OVS limit at 52000 connections:
slow HTTP test status on 340th second:
initializing: 0 pending: 432 connected: 51998 error: 0 closed: 0 service available: YES
--- include/net/netfilter/nf_conntrack_count.h | 1 + net/netfilter/nf_conncount.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-)
include/net/netfilter/nf_conntrack_count.h +1 -0
@@ -13,6 +13,7 @@ struct nf_conncount_list {u32 last_gc;/* jiffies at most recent gc */ struct list_head head;/* connections with the same filtering key */ unsigned int count;/* length of list */ +unsigned int last_gc_count;/* length of list at most recent gc */ }; struct nf_conncount_data *nf_conncount_init(struct net *net, unsigned int family,
net/netfilter/nf_conncount.c +10 -5
@@ -34,8 +34,9 @@#define CONNCOUNT_SLOTS 256U -#define CONNCOUNT_GC_MAX_NODES 8 -#define MAX_KEYLEN 5 +#define CONNCOUNT_GC_MAX_NODES 8 +#define CONNCOUNT_GC_MAX_COLLECT 64 +#define MAX_KEYLEN 5/* we will save the tuples of all connections we care about */ struct nf_conncount_tuple {
@@ -182,12 +183,13 @@ static int __nf_conncount_add(struct net *net, goto out_put; } -if ((u32 )jiffies == list->last_gc) +if ((u32 )jiffies == list->last_gc && + (list->count - list->last_gc_count) <CONNCOUNT_GC_MAX_COLLECT ) goto add_new_node;/* check the saved connections */ list_for_each_entry_safe (conn, conn_n, &list->head, node) { -if (collect >CONNCOUNT_GC_MAX_NODES ) +if (collect >CONNCOUNT_GC_MAX_COLLECT )break ; found =find_or_evict (net, list, conn);
@@ -230,6 +232,7 @@ static int __nf_conncount_add(struct net *net,nf_ct_put (found_ct); } list->last_gc = (u32 )jiffies; + list->last_gc_count = list->count; add_new_node:if (WARN_ON_ONCE (list->count >INT_MAX )) {
@@ -277,6 +280,7 @@ void nf_conncount_list_init(struct nf_conncount_list *list)spin_lock_init (&list->list_lock);INIT_LIST_HEAD (&list->head); list->count =0 ; + list->last_gc_count =0 ; list->last_gc = (u32 )jiffies; }EXPORT_SYMBOL_GPL (nf_conncount_list_init);
@@ -316,13 +320,14 @@ static bool __nf_conncount_gc_list(struct net *net, }nf_ct_put (found_ct); -if (collected >CONNCOUNT_GC_MAX_NODES ) +if (collected >CONNCOUNT_GC_MAX_COLLECT )break ; }if (!list->count) ret = true; list->last_gc = (u32 )jiffies; + list->last_gc_count = list->count;return ret; }
Signature · 1 line
2.51.0
PATCH 118/283 netfilter: nft_compat: add more restrictions on netlink attributes
In reply to Sasha LevinFrom: Florian Westphal <[email protected]>
[ Upstream commit cda26c645946b08f070f20c166d4736767e4a805 ]
As far as I can see nothing bad can happen when NFTA_TARGET/MATCH_NAME are too large because this calls x_tables helpers which check for the length, but it seems better to already reject it during netlink parsing.
Rest of the changes avoid silent u8/u16 truncations.
For _TYPE, its expected to be only 1 or 0. In x_tables world, this variable is set by kernel, for IPT_SO_GET_REVISION_TARGET its 1, for all others its set to 0.
As older versions of nf_tables permitted any value except 1 to mean 'match', keep this as-is but sanitize the value for consistency.
--- net/netfilter/nft_compat.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
net/netfilter/nft_compat.c +10 -3
@@ -134,7 +134,8 @@ static void nft_target_eval_bridge(const struct nft_expr *expr, }static const struct nla_policy nft_target_policy[NFTA_TARGET_MAX +1 ] = { - [NFTA_TARGET_NAME ] = { .type =NLA_NUL_STRING }, + [NFTA_TARGET_NAME ] = { .type =NLA_NUL_STRING , + .len =XT_EXTENSION_MAXNAMELEN , }, [NFTA_TARGET_REV ] =NLA_POLICY_MAX (NLA_BE32 ,255 ), [NFTA_TARGET_INFO ] = { .type =NLA_BINARY }, };
@@ -434,7 +435,8 @@ static void nft_match_eval(const struct nft_expr *expr, }static const struct nla_policy nft_match_policy[NFTA_MATCH_MAX +1 ] = { - [NFTA_MATCH_NAME ] = { .type =NLA_NUL_STRING }, + [NFTA_MATCH_NAME ] = { .type =NLA_NUL_STRING , + .len =XT_EXTENSION_MAXNAMELEN }, [NFTA_MATCH_REV ] =NLA_POLICY_MAX (NLA_BE32 ,255 ), [NFTA_MATCH_INFO ] = { .type =NLA_BINARY }, };
@@ -693,7 +695,12 @@ static int nfnl_compat_get_rcu(struct sk_buff *skb, name =nla_data (tb[NFTA_COMPAT_NAME ]); rev =ntohl (nla_get_be32 (tb[NFTA_COMPAT_REV ])); - target =ntohl (nla_get_be32 (tb[NFTA_COMPAT_TYPE ])); +/* x_tables api checks for 'target == 1' to mean target, +* everything else means 'match'. +* In x_tables world, the number is set by kernel, not +* userspace. +*/ + target =nla_get_be32 (tb[NFTA_COMPAT_TYPE ]) ==htonl (1 );switch (family) {case AF_INET :
Signature · 1 line
2.51.0
PATCH 119/283 netfilter: nf_conncount: fix tracking of connections from localhost
In reply to Sasha LevinFrom: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit de8a70cefcb26cdceaafdc5ac144712681419c29 ]
Since commit be102eb6a0e7 ("netfilter: nf_conncount: rework API to use sk_buff directly"), we skip the adding and trigger a GC when the ct is confirmed. For connections originated from local to local it doesn't work because the connection is confirmed on POSTROUTING, therefore tracking on the INPUT hook is always skipped.
In order to fix this, we check whether skb input ifindex is set to loopback ifindex. If it is then we fallback on a GC plus track operation skipping the optimization. This fallback is necessary to avoid duplicated tracking of a packet train e.g 10 UDP datagrams sent on a burst when initiating the connection.
Tested with xt_connlimit/nft_connlimit and OVS limit and with a HTTP server and iperf3 on UDP mode.
--- net/netfilter/nf_conncount.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
net/netfilter/nf_conncount.c +13 -2
@@ -179,14 +179,25 @@ static int __nf_conncount_add(struct net *net,return -ENOENT ;if (ct &&nf_ct_is_confirmed (ct)) { - err = -EEXIST ; - goto out_put; +/* local connections are confirmed in postrouting so confirmation +* might have happened before hitting connlimit +*/ +if (skb->skb_iif !=LOOPBACK_IFINDEX ) { + err = -EEXIST ; + goto out_put; + } + +/* this is likely a local connection, skip optimization to avoid +* adding duplicates from a 'packet train' +*/ + goto check_connections; }if ((u32 )jiffies == list->last_gc && (list->count - list->last_gc_count) <CONNCOUNT_GC_MAX_COLLECT ) goto add_new_node; +check_connections:/* check the saved connections */ list_for_each_entry_safe (conn, conn_n, &list->head, node) {if (collect >CONNCOUNT_GC_MAX_COLLECT )
Signature · 1 line
2.51.0
PATCH 120/283 module: add helper function for reading module_buildid()
In reply to Sasha LevinFrom: Petr Mladek <[email protected]>
[ Upstream commit acfdbb4ab2910ff6f03becb569c23ac7b2223913 ]
Add a helper function for reading the optional "build_id" member of struct module. It is going to be used also in ftrace_mod_address_lookup().
Use "#ifdef" instead of "#if IS_ENABLED()" to match the declaration of the optional field in struct module.
Stable-dep-of: e8a1e7eaa19d ("kallsyms/ftrace: set module buildid in ftrace_mod_address_lookup()")
--- include/linux/module.h | 9 +++++++++ kernel/module/kallsyms.c | 9 ++------- 2 files changed, 11 insertions(+), 7 deletions(-)
include/linux/module.h +9 -0
@@ -735,6 +735,15 @@ static inline void __module_get(struct module *module) __mod ? __mod->name :"kernel" ; \ }) +static inline const unsigned char *module_buildid (struct module *mod) +{ +#ifdef CONFIG_STACKTRACE_BUILD_ID +return mod->build_id; +#else +return NULL ; +#endif +} +/* Dereference module function descriptor */ void *dereference_module_function_descriptor (struct module *mod,void *ptr);
kernel/module/kallsyms.c +2 -7
@@ -336,13 +336,8 @@ const char *module_address_lookup(unsigned long addr,if (mod) {if (modname) *modname = mod->name; -if (modbuildid) { -#if IS_ENABLED (CONFIG_STACKTRACE_BUILD_ID ) - *modbuildid = mod->build_id; -#else - *modbuildid =NULL ; -#endif - } +if (modbuildid) + *modbuildid =module_buildid (mod); ret =find_kallsyms_symbol (mod, addr, size, offset); }
Signature · 1 line
2.51.0
PATCH 121/283 kallsyms/ftrace: set module buildid in ftrace_mod_address_lookup()
In reply to Sasha LevinFrom: Petr Mladek <[email protected]>
[ Upstream commit e8a1e7eaa19d0b757b06a2f913e3eeb4b1c002c6 ]
__sprint_symbol() might access an invalid pointer when kallsyms_lookup_buildid() returns a symbol found by ftrace_mod_address_lookup().
The ftrace lookup function must set both @modname and @modbuildid the same way as module_address_lookup().
--- include/linux/ftrace.h | 6 ++++-- kernel/kallsyms.c | 4 ++-- kernel/trace/ftrace.c | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-)
include/linux/ftrace.h +4 -2
@@ -89,11 +89,13 @@ struct ftrace_direct_func;defined (CONFIG_DYNAMIC_FTRACE) const char *ftrace_mod_address_lookup (unsigned long addr,unsigned long *size, -unsigned long *off,char **modname,char *sym); +unsigned long *off,char **modname, +const unsigned char **modbuildid,char *sym);#else static inline const char *ftrace_mod_address_lookup (unsigned long addr,unsigned long *size, -unsigned long *off,char **modname,char *sym) +unsigned long *off,char **modname, +const unsigned char **modbuildid,char *sym) {return NULL ; }
kernel/kallsyms.c +2 -2
@@ -431,8 +431,8 @@ static const char *kallsyms_lookup_buildid(unsigned long addr, offset, modname, namebuf);if (!ret) - ret =ftrace_mod_address_lookup (addr, symbolsize, - offset, modname, namebuf); + ret =ftrace_mod_address_lookup (addr, symbolsize, offset, + modname, modbuildid, namebuf); found:cleanup_symbol_name (namebuf);
kernel/trace/ftrace.c +4 -1
@@ -7046,7 +7046,8 @@ ftrace_func_address_lookup(struct ftrace_mod_map *mod_map,const char *ftrace_mod_address_lookup (unsigned long addr,unsigned long *size, -unsigned long *off,char **modname,char *sym) +unsigned long *off,char **modname, +const unsigned char **modbuildid,char *sym) {struct ftrace_mod_map *mod_map;const char *ret =NULL ;
@@ -7058,6 +7059,8 @@ ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,if (ret) {if (modname) *modname = mod_map->mod->name; +if (modbuildid) + *modbuildid =module_buildid (mod_map->mod);break ; } }
Signature · 1 line
2.51.0
PATCH 122/283 PCI: Mark 3ware-9650SA Root Port Extended Tags as broken
In reply to Sasha LevinFrom: Jörg Wedekind <[email protected]>
[ Upstream commit 959ac08a2c2811305be8c2779779e8b0932e5a99 ]
Per PCIe r7.0, sec 2.2.6.2.1 and 7.5.3.4, a Requester may not use 8-bit Tags unless its Extended Tag Field Enable is set, but all Receivers/Completers must handle 8-bit Tags correctly regardless of their Extended Tag Field Enable.
Some devices do not handle 8-bit Tags as Completers, so add a quirk for them. If we find such a device, we disable Extended Tags for the entire hierarchy to make peer-to-peer DMA possible.
The 3ware 9650SA seems to have issues with handling 8-bit tags. Mark it as broken.
This fixes PCI Parity Errors like :
3w-9xxx: scsi0: ERROR: (0x06:0x000C): PCI Parity Error: clearing. 3w-9xxx: scsi0: ERROR: (0x06:0x000D): PCI Abort: clearing. 3w-9xxx: scsi0: ERROR: (0x06:0x000E): Controller Queue Error: clearing. 3w-9xxx: scsi0: ERROR: (0x06:0x0010): Microcontroller Error: clearing.
--- drivers/pci/quirks.c | 1 + 1 file changed, 1 insertion(+)
drivers/pci/quirks.c +1 -0
@@ -5573,6 +5573,7 @@ static void quirk_no_ext_tags(struct pci_dev *pdev)pci_walk_bus (bridge->bus, pci_configure_extended_tags,NULL ); }DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_3WARE ,0x1004 , quirk_no_ext_tags); +DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_3WARE ,0x1005 , quirk_no_ext_tags);DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_SERVERWORKS ,0x0132 , quirk_no_ext_tags);DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_SERVERWORKS ,0x0140 , quirk_no_ext_tags);DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_SERVERWORKS ,0x0141 , quirk_no_ext_tags);
Signature · 1 line
2.51.0
PATCH 123/283 iommu/vt-d: Flush cache for PASID table before using it
In reply to Sasha LevinFrom: Dmytro Maluka <[email protected]>
[ Upstream commit 22d169bdd2849fe6bd18c2643742e1c02be6451c ]
When writing the address of a freshly allocated zero-initialized PASID table to a PASID directory entry, do that after the CPU cache flush for this PASID table, not before it, to avoid the time window when this PASID table may be already used by non-coherent IOMMU hardware while its contents in RAM is still some random old data, not zero-initialized.
--- drivers/iommu/intel/pasid.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iommu/intel/pasid.c +4 -3
@@ -207,6 +207,9 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)if (!entries)return NULL ; +if (!ecap_coherent (info->iommu->ecap)) +clflush_cache_range (entries,VTD_PAGE_SIZE ); +/* * The pasid directory table entry won't be freed after * allocation. No worry about the race with free and
@@ -218,10 +221,8 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)free_pgtable_page (entries); goto retry; } -if (!ecap_coherent (info->iommu->ecap)) { -clflush_cache_range (entries,VTD_PAGE_SIZE ); +if (!ecap_coherent (info->iommu->ecap))clflush_cache_range (&dir[dir_index].val,sizeof (*dir)); - } }return &entries[index];
Signature · 1 line
2.51.0
PATCH 124/283 dm: use bio_clone_blkg_association
In reply to Sasha LevinFrom: Mikulas Patocka <[email protected]>
[ Upstream commit 2df8b310bcfe76827fd71092f58a2493ee6590b0 ]
The origin bio carries blk-cgroup information which could be set from foreground(task_css(css) - wbc->wb->blkcg_css), so the blkcg won't control buffer io since commit ca522482e3eaf ("dm: pass NULL bdev to bio_alloc_clone"). The synchronous io is still under control by blkcg, because 'bio->bi_blkg' is set by io submitting task which has been added into 'cgroup.procs'.
Fix it by using bio_clone_blkg_association when submitting a cloned bio.
--- drivers/md/dm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/dm.c +2 -0
@@ -1363,6 +1363,8 @@ void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone)if (!tgt_clone) tgt_clone = clone; +bio_clone_blkg_association (tgt_clone, io->orig_bio); +/* * Account io->origin_bio to DM dev on behalf of target * that took ownership of IO with DM_MAPIO_SUBMITTED.
Signature · 1 line
2.51.0
PATCH 125/283 nfsd: never defer requests during idmap lookup
In reply to Sasha LevinFrom: Anthony Iliopoulos <[email protected]>
[ Upstream commit f9c206cdc4266caad6a9a7f46341420a10f03ccb ]
During v4 request compound arg decoding, some ops (e.g. SETATTR) can trigger idmap lookup upcalls. When those upcall responses get delayed beyond the allowed time limit, cache_check() will mark the request for deferral and cause it to be dropped.
This prevents nfs4svc_encode_compoundres from being executed, and thus the session slot flag NFSD4_SLOT_INUSE never gets cleared. Subsequent client requests will fail with NFSERR_JUKEBOX, given that the slot will be marked as in-use, making the SEQUENCE op fail.
Fix this by making sure that the RQ_USEDEFERRAL flag is always clear during nfs4svc_decode_compoundargs(), since no v4 request should ever be deferred.
--- fs/nfsd/nfs4idmap.c | 48 +++++++++++++++++++++++++++++++++++++++------ fs/nfsd/nfs4proc.c | 2 -- fs/nfsd/nfs4xdr.c | 16 +++++++++++++++ 3 files changed, 58 insertions(+), 8 deletions(-)
fs/nfsd/nfs4idmap.c +42 -6
@@ -643,13 +643,31 @@ static __be32 encode_name_from_id(struct xdr_stream *xdr,return idmap_id_to_name (xdr, rqstp, type, id); } -__be32 -nfsd_map_name_to_uid (struct svc_rqst *rqstp,const char *name,size_t namelen, -kuid_t *uid) +/** +* nfsd_map_name_to_uid - Map user@domain to local UID +* @rqstp: RPC execution context +* @name: user@domain name to be mapped +* @namelen: length of name, in bytes +* @uid: OUT: mapped local UID value +* +* Returns nfs_ok on success or an NFSv4 status code on failure. +*/ +__be32 nfsd_map_name_to_uid (struct svc_rqst *rqstp,const char *name, +size_t namelen,kuid_t *uid) {__be32 status;u32 id =-1 ; +/* +* The idmap lookup below triggers an upcall that invokes +* cache_check(). RQ_USEDEFERRAL must be clear to prevent +* cache_check() from setting RQ_DROPME via svc_defer(). +* NFSv4 servers are not permitted to drop requests. Also +* RQ_DROPME will force NFSv4.1 session slot processing to +* be skipped. +*/ +WARN_ON_ONCE (test_bit (RQ_USEDEFERRAL , &rqstp->rq_flags)); +if (name ==NULL || namelen ==0 )return nfserr_inval;
@@ -660,13 +678,31 @@ nfsd_map_name_to_uid(struct svc_rqst *rqstp, const char *name, size_t namelen,return status; } -__be32 -nfsd_map_name_to_gid (struct svc_rqst *rqstp,const char *name,size_t namelen, -kgid_t *gid) +/** +* nfsd_map_name_to_gid - Map user@domain to local GID +* @rqstp: RPC execution context +* @name: user@domain name to be mapped +* @namelen: length of name, in bytes +* @gid: OUT: mapped local GID value +* +* Returns nfs_ok on success or an NFSv4 status code on failure. +*/ +__be32 nfsd_map_name_to_gid (struct svc_rqst *rqstp,const char *name, +size_t namelen,kgid_t *gid) {__be32 status;u32 id =-1 ; +/* +* The idmap lookup below triggers an upcall that invokes +* cache_check(). RQ_USEDEFERRAL must be clear to prevent +* cache_check() from setting RQ_DROPME via svc_defer(). +* NFSv4 servers are not permitted to drop requests. Also +* RQ_DROPME will force NFSv4.1 session slot processing to +* be skipped. +*/ +WARN_ON_ONCE (test_bit (RQ_USEDEFERRAL , &rqstp->rq_flags)); +if (name ==NULL || namelen ==0 )return nfserr_inval;
fs/nfsd/nfs4proc.c +0 -2
@@ -2763,8 +2763,6 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)BUG_ON (cstate->replay_owner); out: cstate->status = status; -/* Reset deferral mechanism for RPC deferrals */ -set_bit (RQ_USEDEFERRAL , &rqstp->rq_flags);return rpc_success; }
fs/nfsd/nfs4xdr.c +16 -0
@@ -5492,6 +5492,22 @@ nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) args->ops = args->iops; args->rqstp = rqstp; +/* +* NFSv4 operation decoders can invoke svc cache lookups +* that trigger svc_defer() when RQ_USEDEFERRAL is set, +* setting RQ_DROPME. This creates two problems: +* +* 1. Non-idempotency: Compounds make it too hard to avoid +* problems if a request is deferred and replayed. +* +* 2. Session slot leakage (NFSv4.1+): If RQ_DROPME is set +* during decode but SEQUENCE executes successfully, the +* session slot will be marked INUSE. The request is then +* dropped before encoding, so the slot is never released, +* rendering it permanently unusable by the client. +*/ +clear_bit (RQ_USEDEFERRAL , &rqstp->rq_flags); +return nfsd4_decode_compound (args); }
Signature · 1 line
2.51.0
PATCH 126/283 fat: avoid parent link count underflow in rmdir
In reply to Sasha LevinFrom: Zhiyu Zhang <[email protected]>
[ Upstream commit 8cafcb881364af5ef3a8b9fed4db254054033d8a ]
Corrupted FAT images can leave a directory inode with an incorrect i_nlink (e.g. 2 even though subdirectories exist). rmdir then unconditionally calls drop_nlink(dir) and can drive i_nlink to 0, triggering the WARN_ON in drop_nlink().
Add a sanity check in vfat_rmdir() and msdos_rmdir(): only drop the parent link count when it is at least 3, otherwise report a filesystem error.
--- fs/fat/namei_msdos.c | 7 ++++++- fs/fat/namei_vfat.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-)
fs/fat/namei_msdos.c +6 -1
@@ -325,7 +325,12 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry) err =fat_remove_entries (dir, &sinfo);/* and releases bh */ if (err) goto out; -drop_nlink (dir); +if (dir->i_nlink >=3 ) +drop_nlink (dir); +else { +fat_fs_error (sb,"parent dir link count too low (%u)" , + dir->i_nlink); + }clear_nlink (inode);fat_truncate_time (inode,NULL ,S_CTIME );
fs/fat/namei_vfat.c +6 -1
@@ -806,7 +806,12 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry) err =fat_remove_entries (dir, &sinfo);/* and releases bh */ if (err) goto out; -drop_nlink (dir); +if (dir->i_nlink >=3 ) +drop_nlink (dir); +else { +fat_fs_error (sb,"parent dir link count too low (%u)" , + dir->i_nlink); + }clear_nlink (inode);fat_truncate_time (inode,NULL ,S_ATIME |S_MTIME );
Signature · 1 line
2.51.0
PATCH 127/283 tcp: tcp_tx_timestamp() must look at the rtx queue
In reply to Sasha LevinFrom: Eric Dumazet <[email protected]>
[ Upstream commit 838eb9687691d29915797a885b861fd09353386e ]
tcp_tx_timestamp() is only called at the end of tcp_sendmsg_locked() before the final tcp_push().
By the time it is called, it is possible all the copied data has been sent already (transmit queue is empty).
If this is the case, use the last skb in the rtx queue.
--- net/ipv4/tcp.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv4/tcp.c +3 -0
@@ -468,6 +468,9 @@ static void tcp_tx_timestamp(struct sock *sk, u16 tsflags) {struct sk_buff *skb =tcp_write_queue_tail (sk); +if (unlikely (!skb)) + skb =skb_rb_last (&sk->tcp_rtx_queue); +if (tsflags && skb) {struct skb_shared_info *shinfo =skb_shinfo (skb);struct tcp_skb_cb *tcb =TCP_SKB_CB (skb);
Signature · 1 line
2.51.0
PATCH 128/283 wifi: ath10k: sdio: add missing lock protection in ath10k_sdio_fw_crashed_dump()
In reply to Sasha LevinFrom: Ziyi Guo <[email protected]>
[ Upstream commit e55ac348089e579fc224569c7bd90340bf2439f9 ]
ath10k_sdio_fw_crashed_dump() calls ath10k_coredump_new() which requires ar->dump_mutex to be held, as indicated by lockdep_assert_held() in that function. However, the SDIO implementation does not acquire this lock, unlike the PCI and SNOC implementations which properly hold the mutex.
Additionally, ar->stats.fw_crash_counter is documented as protected by ar->data_lock in core.h, but the SDIO implementation modifies it without holding this spinlock.
Add the missing mutex_lock()/mutex_unlock() around the coredump operations, and add spin_lock_bh()/spin_unlock_bh() around the fw_crash_counter increment, following the pattern used in ath10k_pci_fw_dump_work() and ath10k_snoc_fw_crashed_dump().
--- drivers/net/wireless/ath/ath10k/sdio.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/ath/ath10k/sdio.c +6 -0
@@ -2486,7 +2486,11 @@ void ath10k_sdio_fw_crashed_dump(struct ath10k *ar)if (fast_dump)ath10k_bmi_start (ar); +mutex_lock (&ar->dump_mutex); + +spin_lock_bh (&ar->data_lock); ar->stats.fw_crash_counter++; +spin_unlock_bh (&ar->data_lock);ath10k_sdio_disable_intrs (ar);
@@ -2504,6 +2508,8 @@ void ath10k_sdio_fw_crashed_dump(struct ath10k *ar)ath10k_sdio_enable_intrs (ar); +mutex_unlock (&ar->dump_mutex); +ath10k_core_start_recovery (ar); }
Signature · 1 line
2.51.0
PATCH 129/283 PCI: Initialize RCB from pci_configure_device()
In reply to Sasha LevinFrom: Håkon Bugge <[email protected]>
[ Upstream commit 1a6845aaa6de81f95959b380b45de8f10d6a8502 ]
Commit e42010d8207f ("PCI: Set Read Completion Boundary to 128 iff Root Port supports it (_HPX)") worked around a bogus _HPX type 2 record, which caused program_hpx_type2() to set the RCB in an endpoint even though the Root Port did not have the RCB bit set.
e42010d8207f fixed that by setting the RCB in the endpoint only when it was set in the Root Port.
In retrospect, program_hpx_type2() is intended for AER-related settings, and the RCB should be configured elsewhere so it doesn't depend on the presence or contents of an _HPX record.
Explicitly program the RCB from pci_configure_device() so it matches the Root Port's RCB. The Root Port may not be visible to virtualized guests; in that case, leave RCB alone.
--- drivers/pci/probe.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/pci/probe.c +32 -0
@@ -2288,6 +2288,37 @@ static void pci_configure_serr(struct pci_dev *dev) } } +static void pci_configure_rcb (struct pci_dev *dev) +{ +struct pci_dev *rp; +u16 rp_lnkctl; + +/* +* Per PCIe r7.0, sec 7.5.3.7, RCB is only meaningful in Root Ports +* (where it is read-only), Endpoints, and Bridges. It may only be +* set for Endpoints and Bridges if it is set in the Root Port. For +* Endpoints, it is 'RsvdP' for Virtual Functions. +*/ +if (!pci_is_pcie (dev) || +pci_pcie_type (dev) ==PCI_EXP_TYPE_ROOT_PORT || +pci_pcie_type (dev) ==PCI_EXP_TYPE_UPSTREAM || +pci_pcie_type (dev) ==PCI_EXP_TYPE_DOWNSTREAM || +pci_pcie_type (dev) ==PCI_EXP_TYPE_RC_EC || + dev->is_virtfn) +return ; + +/* Root Port often not visible to virtualized guests */ + rp =pcie_find_root_port (dev); +if (!rp) +return ; + +pcie_capability_read_word (rp,PCI_EXP_LNKCTL , &rp_lnkctl); +pcie_capability_clear_and_set_word (dev,PCI_EXP_LNKCTL , +PCI_EXP_LNKCTL_RCB , + (rp_lnkctl &PCI_EXP_LNKCTL_RCB ) ? +PCI_EXP_LNKCTL_RCB :0 ); +} +static void pci_configure_device (struct pci_dev *dev) {pci_configure_mps (dev);
@@ -2296,6 +2327,7 @@ static void pci_configure_device(struct pci_dev *dev)pci_configure_ltr (dev);pci_configure_eetlp_prefix (dev);pci_configure_serr (dev); +pci_configure_rcb (dev);pci_acpi_program_hp_params (dev); }
Signature · 1 line
2.51.0
PATCH 130/283 PCI: Move pci_read_bridge_windows() below individual window accessors
In reply to Sasha LevinFrom: Bjorn Helgaas <[email protected]>
[ Upstream commit 6f32099a91720b6d91da961858d48173f01a729d ]
Move pci_read_bridge_windows() below the functions that read the I/O, memory, and prefetchable memory windows, so pci_read_bridge_windows() can use them in the future. No functional change intended.
Stable-dep-of: 9abf79c8d7b4 ("PCI/ACPI: Restrict program_hpx_type2() to AER bits")
--- drivers/pci/probe.c | 102 ++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 51 deletions(-)
drivers/pci/probe.c +51 -51
@@ -344,57 +344,6 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) } } -static void pci_read_bridge_windows (struct pci_dev *bridge) -{ -u16 io; -u32 pmem, tmp; - -pci_read_config_word (bridge,PCI_IO_BASE , &io); -if (!io) { -pci_write_config_word (bridge,PCI_IO_BASE ,0xe0f0 ); -pci_read_config_word (bridge,PCI_IO_BASE , &io); -pci_write_config_word (bridge,PCI_IO_BASE ,0x0 ); - } -if (io) - bridge->io_window =1 ; - -/* -* DECchip 21050 pass 2 errata: the bridge may miss an address -* disconnect boundary by one PCI data phase. Workaround: do not -* use prefetching on this device. -*/ -if (bridge->vendor ==PCI_VENDOR_ID_DEC && bridge->device ==0x0001 ) -return ; - -pci_read_config_dword (bridge,PCI_PREF_MEMORY_BASE , &pmem); -if (!pmem) { -pci_write_config_dword (bridge,PCI_PREF_MEMORY_BASE , -0xffe0fff0 ); -pci_read_config_dword (bridge,PCI_PREF_MEMORY_BASE , &pmem); -pci_write_config_dword (bridge,PCI_PREF_MEMORY_BASE ,0x0 ); - } -if (!pmem) -return ; - - bridge->pref_window =1 ; - -if ((pmem &PCI_PREF_RANGE_TYPE_MASK ) ==PCI_PREF_RANGE_TYPE_64 ) { - -/* -* Bridge claims to have a 64-bit prefetchable memory -* window; verify that the upper bits are actually -* writable. -*/ -pci_read_config_dword (bridge,PCI_PREF_BASE_UPPER32 , &pmem); -pci_write_config_dword (bridge,PCI_PREF_BASE_UPPER32 , -0xffffffff ); -pci_read_config_dword (bridge,PCI_PREF_BASE_UPPER32 , &tmp); -pci_write_config_dword (bridge,PCI_PREF_BASE_UPPER32 , pmem); -if (tmp) - bridge->pref_64_window =1 ; - } -} -static void pci_read_bridge_io (struct pci_bus *child) {struct pci_dev *dev = child->self;
@@ -510,6 +459,57 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child) } } +static void pci_read_bridge_windows (struct pci_dev *bridge) +{ +u16 io; +u32 pmem, tmp; + +pci_read_config_word (bridge,PCI_IO_BASE , &io); +if (!io) { +pci_write_config_word (bridge,PCI_IO_BASE ,0xe0f0 ); +pci_read_config_word (bridge,PCI_IO_BASE , &io); +pci_write_config_word (bridge,PCI_IO_BASE ,0x0 ); + } +if (io) + bridge->io_window =1 ; + +/* +* DECchip 21050 pass 2 errata: the bridge may miss an address +* disconnect boundary by one PCI data phase. Workaround: do not +* use prefetching on this device. +*/ +if (bridge->vendor ==PCI_VENDOR_ID_DEC && bridge->device ==0x0001 ) +return ; + +pci_read_config_dword (bridge,PCI_PREF_MEMORY_BASE , &pmem); +if (!pmem) { +pci_write_config_dword (bridge,PCI_PREF_MEMORY_BASE , +0xffe0fff0 ); +pci_read_config_dword (bridge,PCI_PREF_MEMORY_BASE , &pmem); +pci_write_config_dword (bridge,PCI_PREF_MEMORY_BASE ,0x0 ); + } +if (!pmem) +return ; + + bridge->pref_window =1 ; + +if ((pmem &PCI_PREF_RANGE_TYPE_MASK ) ==PCI_PREF_RANGE_TYPE_64 ) { + +/* +* Bridge claims to have a 64-bit prefetchable memory +* window; verify that the upper bits are actually +* writable. +*/ +pci_read_config_dword (bridge,PCI_PREF_BASE_UPPER32 , &pmem); +pci_write_config_dword (bridge,PCI_PREF_BASE_UPPER32 , +0xffffffff ); +pci_read_config_dword (bridge,PCI_PREF_BASE_UPPER32 , &tmp); +pci_write_config_dword (bridge,PCI_PREF_BASE_UPPER32 , pmem); +if (tmp) + bridge->pref_64_window =1 ; + } +} +void pci_read_bridge_bases (struct pci_bus *child) {struct pci_dev *dev = child->self;
Signature · 1 line
2.51.0
PATCH 131/283 PCI: Supply bridge device, not secondary bus, to read window details
In reply to Sasha LevinFrom: Bjorn Helgaas <[email protected]>
[ Upstream commit 281e1f137a97dae4fe47a7d30635c5b83def790b ]
Previously we logged information about devices *below* the bridge before logging information about the bridge itself, e.g.,
pci 0000:00:01.0: [8086:1901] type 01 class 0x060400 pci 0000:01:00.0: [10de:13b6] type 00 class 0x030200 pci 0000:01:00.0: reg 0x10: [mem 0xec000000-0xecffffff] pci 0000:00:01.0: PCI bridge to [bus 01]
pci 0000:00:01.0: bridge window [io 0xe000-0xefff]
This is partly because the bridge windows are read in this path:
pci_scan_child_bus_extend
for (devfn = 0; devfn < 256; devfn += 8)
pci_scan_slot(bus, devfn) # scan below bridge
pcibios_fixup_bus(bus)
pci_read_bridge_bases(bus) # read bridge windows
pci_read_bridge_io(bus)
Remove the assumption that the secondary (child) pci_bus already exists by passing in the bridge device (instead of the pci_bus) and a resource pointer when reading bridge windows. A future change can use this to log the bridge details before we enumerate the devices below the bridge.
No functional change intended.
Stable-dep-of: 9abf79c8d7b4 ("PCI/ACPI: Restrict program_hpx_type2() to AER bits")
--- drivers/pci/probe.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/pci/probe.c +6 -15
@@ -344,13 +344,11 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) } } -static void pci_read_bridge_io (struct pci_bus *child) +static void pci_read_bridge_io (struct pci_dev *dev,struct resource *res) { -struct pci_dev *dev = child->self;u8 io_base_lo, io_limit_lo;unsigned long io_mask, io_granularity, base, limit;struct pci_bus_region region; -struct resource *res; io_mask =PCI_IO_RANGE_MASK ; io_granularity =0x1000 ;
@@ -360,7 +358,6 @@ static void pci_read_bridge_io(struct pci_bus *child) io_granularity =0x400 ; } - res = child->resource[0 ];pci_read_config_byte (dev,PCI_IO_BASE , &io_base_lo);pci_read_config_byte (dev,PCI_IO_LIMIT , &io_limit_lo); base = (io_base_lo & io_mask) <<8 ;
@@ -384,15 +381,12 @@ static void pci_read_bridge_io(struct pci_bus *child) } } -static void pci_read_bridge_mmio (struct pci_bus *child) +static void pci_read_bridge_mmio (struct pci_dev *dev,struct resource *res) { -struct pci_dev *dev = child->self;u16 mem_base_lo, mem_limit_lo;unsigned long base, limit;struct pci_bus_region region; -struct resource *res; - res = child->resource[1 ];pci_read_config_word (dev,PCI_MEMORY_BASE , &mem_base_lo);pci_read_config_word (dev,PCI_MEMORY_LIMIT , &mem_limit_lo); base = ((unsigned long ) mem_base_lo &PCI_MEMORY_RANGE_MASK ) <<16 ;
@@ -406,16 +400,13 @@ static void pci_read_bridge_mmio(struct pci_bus *child) } } -static void pci_read_bridge_mmio_pref (struct pci_bus *child) +static void pci_read_bridge_mmio_pref (struct pci_dev *dev,struct resource *res) { -struct pci_dev *dev = child->self;u16 mem_base_lo, mem_limit_lo;u64 base64, limit64;pci_bus_addr_t base, limit;struct pci_bus_region region; -struct resource *res; - res = child->resource[2 ];pci_read_config_word (dev,PCI_PREF_MEMORY_BASE , &mem_base_lo);pci_read_config_word (dev,PCI_PREF_MEMORY_LIMIT , &mem_limit_lo); base64 = (mem_base_lo &PCI_PREF_RANGE_MASK ) <<16 ;
@@ -527,9 +518,9 @@ void pci_read_bridge_bases(struct pci_bus *child)for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) child->resource[i] = &dev->resource[PCI_BRIDGE_RESOURCES +i]; -pci_read_bridge_io (child); -pci_read_bridge_mmio (child); -pci_read_bridge_mmio_pref (child); +pci_read_bridge_io (child->self, child->resource[0 ]); +pci_read_bridge_mmio (child->self, child->resource[1 ]); +pci_read_bridge_mmio_pref (child->self, child->resource[2 ]);if (dev->transparent) {pci_bus_for_each_resource (child->parent, res) {
Signature · 1 line
2.51.0
PATCH 132/283 PCI: Log bridge windows conditionally
In reply to Sasha LevinFrom: Bjorn Helgaas <[email protected]>
[ Upstream commit 63c6ebb294b7c708cc987d621e59499686650683 ]
Previously pci_read_bridge_io(), pci_read_bridge_mmio(), and pci_read_bridge_mmio_pref() unconditionally logged the bridge window resource. A future change will call these functions earlier and more often. Add a "log" parameter so callers can control whether to generate the log message. No functional change intended.
Stable-dep-of: 9abf79c8d7b4 ("PCI/ACPI: Restrict program_hpx_type2() to AER bits")
--- drivers/pci/probe.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/pci/probe.c +15 -9
@@ -344,7 +344,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) } } -static void pci_read_bridge_io (struct pci_dev *dev,struct resource *res) +static void pci_read_bridge_io (struct pci_dev *dev,struct resource *res, +bool log) {u8 io_base_lo, io_limit_lo;unsigned long io_mask, io_granularity, base, limit;
@@ -377,11 +378,13 @@ static void pci_read_bridge_io(struct pci_dev *dev, struct resource *res) region.start = base; region.end = limit + io_granularity -1 ;pcibios_bus_to_resource (dev->bus, res, ®ion); -pci_info (dev," bridge window %pR\n" , res); +if (log) +pci_info (dev," bridge window %pR\n" , res); } } -static void pci_read_bridge_mmio (struct pci_dev *dev,struct resource *res) +static void pci_read_bridge_mmio (struct pci_dev *dev,struct resource *res, +bool log) {u16 mem_base_lo, mem_limit_lo;unsigned long base, limit;
@@ -396,11 +399,13 @@ static void pci_read_bridge_mmio(struct pci_dev *dev, struct resource *res) region.start = base; region.end = limit +0xfffff ;pcibios_bus_to_resource (dev->bus, res, ®ion); -pci_info (dev," bridge window %pR\n" , res); +if (log) +pci_info (dev," bridge window %pR\n" , res); } } -static void pci_read_bridge_mmio_pref (struct pci_dev *dev,struct resource *res) +static void pci_read_bridge_mmio_pref (struct pci_dev *dev,struct resource *res, +bool log) {u16 mem_base_lo, mem_limit_lo;u64 base64, limit64;
@@ -446,7 +451,8 @@ static void pci_read_bridge_mmio_pref(struct pci_dev *dev, struct resource *res) region.start = base; region.end = limit +0xfffff ;pcibios_bus_to_resource (dev->bus, res, ®ion); -pci_info (dev," bridge window %pR\n" , res); +if (log) +pci_info (dev," bridge window %pR\n" , res); } }
@@ -518,9 +524,9 @@ void pci_read_bridge_bases(struct pci_bus *child)for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) child->resource[i] = &dev->resource[PCI_BRIDGE_RESOURCES +i]; -pci_read_bridge_io (child->self, child->resource[0 ]); -pci_read_bridge_mmio (child->self, child->resource[1 ]); -pci_read_bridge_mmio_pref (child->self, child->resource[2 ]); +pci_read_bridge_io (child->self, child->resource[0 ], true); +pci_read_bridge_mmio (child->self, child->resource[1 ], true); +pci_read_bridge_mmio_pref (child->self, child->resource[2 ], true);if (dev->transparent) {pci_bus_for_each_resource (child->parent, res) {
Signature · 1 line
2.51.0
PATCH 133/283 PCI: Log bridge info when first enumerating bridge
In reply to Sasha LevinFrom: Bjorn Helgaas <[email protected]>
[ Upstream commit 95140c2fbfdf3b6ca98578e5bdbc82d9922f08b9 ]
Log bridge secondary/subordinate bus and window information at the same time we log the bridge BARs, just after discovering the bridge and before scanning the bridge's secondary bus. This logs the bridge and downstream devices in a more logical order:
- pci 0000:00:01.0: [8086:1901] type 01 class 0x060400
- pci 0000:01:00.0: [10de:13b6] type 00 class 0x030200
- pci 0000:01:00.0: reg 0x10: [mem 0xec000000-0xecffffff]
- pci 0000:00:01.0: PCI bridge to [bus 01]
- pci 0000:00:01.0: bridge window [io 0xe000-0xefff]
+ pci 0000:00:01.0: [8086:1901] type 01 class 0x060400
+ pci 0000:00:01.0: PCI bridge to [bus 01]
+ pci 0000:00:01.0: bridge window [io 0xe000-0xefff]
+ pci 0000:01:00.0: [10de:13b6] type 00 class 0x030200
+ pci 0000:01:00.0: reg 0x10: [mem 0xec000000-0xecffffff]
Note that we read the windows into a temporary struct resource that is thrown away, not into the resources in the struct pci_bus.
The windows may be adjusted after we know what downstream devices require, and those adjustments are logged as they are made.
Stable-dep-of: 9abf79c8d7b4 ("PCI/ACPI: Restrict program_hpx_type2() to AER bits")
--- drivers/pci/probe.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/pci/probe.c +19 -4
@@ -458,8 +458,17 @@ static void pci_read_bridge_mmio_pref(struct pci_dev *dev, struct resource *res,static void pci_read_bridge_windows (struct pci_dev *bridge) { +u32 buses;u16 io;u32 pmem, tmp; +struct resource res; + +pci_read_config_dword (bridge,PCI_PRIMARY_BUS , &buses); + res.flags =IORESOURCE_BUS ; + res.start = (buses >>8 ) &0xff ; + res.end = (buses >>16 ) &0xff ; +pci_info (bridge,"PCI bridge to %pR%s\n" , &res, + bridge->transparent ?" (subtractive decode)" :"" );pci_read_config_word (bridge,PCI_IO_BASE , &io);if (!io) {
@@ -467,8 +476,12 @@ static void pci_read_bridge_windows(struct pci_dev *bridge)pci_read_config_word (bridge,PCI_IO_BASE , &io);pci_write_config_word (bridge,PCI_IO_BASE ,0x0 ); } -if (io) +if (io) { bridge->io_window =1 ; +pci_read_bridge_io (bridge, &res, true); + } + +pci_read_bridge_mmio (bridge, &res, true);/* * DECchip 21050 pass 2 errata: the bridge may miss an address
@@ -505,6 +518,8 @@ static void pci_read_bridge_windows(struct pci_dev *bridge)if (tmp) bridge->pref_64_window =1 ; } + +pci_read_bridge_mmio_pref (bridge, &res, true); }void pci_read_bridge_bases (struct pci_bus *child)
@@ -524,9 +539,9 @@ void pci_read_bridge_bases(struct pci_bus *child)for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) child->resource[i] = &dev->resource[PCI_BRIDGE_RESOURCES +i]; -pci_read_bridge_io (child->self, child->resource[0 ], true); -pci_read_bridge_mmio (child->self, child->resource[1 ], true); -pci_read_bridge_mmio_pref (child->self, child->resource[2 ], true); +pci_read_bridge_io (child->self, child->resource[0 ], false); +pci_read_bridge_mmio (child->self, child->resource[1 ], false); +pci_read_bridge_mmio_pref (child->self, child->resource[2 ], false);if (dev->transparent) {pci_bus_for_each_resource (child->parent, res) {
Signature · 1 line
2.51.0
PATCH 134/283 PCI: Add PCIE_MSG_CODE_ASSERT_INTx message macros
In reply to Sasha LevinFrom: Yoshihiro Shimoda <[email protected]>
[ Upstream commit 95cb8ff68851ed0d249fb8a1d9657987cd844e08 ]
Add "Message Routing" and "INTx Mechanism Messages" macros to enable a PCIe driver to send messages for INTx Interrupt Signaling.
Values from PCIe r6.1, sec 2.2.8 and 2.2.8.1.
Stable-dep-of: 9abf79c8d7b4 ("PCI/ACPI: Restrict program_hpx_type2() to AER bits")
--- drivers/pci/pci.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/pci/pci.h +18 -0
@@ -22,6 +22,24 @@*/ #define PCIE_PME_TO_L2_TIMEOUT_US 10000 +/* Message Routing (r[2:0]); PCIe r6.0, sec 2.2.8 */ +#define PCIE_MSG_TYPE_R_RC 0 +#define PCIE_MSG_TYPE_R_ADDR 1 +#define PCIE_MSG_TYPE_R_ID 2 +#define PCIE_MSG_TYPE_R_BC 3 +#define PCIE_MSG_TYPE_R_LOCAL 4 +#define PCIE_MSG_TYPE_R_GATHER 5 + +/* INTx Mechanism Messages; PCIe r6.0, sec 2.2.8.1 */ +#define PCIE_MSG_CODE_ASSERT_INTA 0x20 +#define PCIE_MSG_CODE_ASSERT_INTB 0x21 +#define PCIE_MSG_CODE_ASSERT_INTC 0x22 +#define PCIE_MSG_CODE_ASSERT_INTD 0x23 +#define PCIE_MSG_CODE_DEASSERT_INTA 0x24 +#define PCIE_MSG_CODE_DEASSERT_INTB 0x25 +#define PCIE_MSG_CODE_DEASSERT_INTC 0x26 +#define PCIE_MSG_CODE_DEASSERT_INTD 0x27 +extern const unsigned char pcie_link_speed[];extern bool pci_early_dump;
Signature · 1 line
2.51.0
PATCH 135/283 PCI: Add defines for bridge window indexing
In reply to Sasha LevinFrom: Ilpo Järvinen <[email protected]>
[ Upstream commit e4934832c588f72bcc139d3ca0acc490c63a821c ]
include/linux/pci.h provides PCI_BRIDGE_{IO,MEM,PREF_MEM}_WINDOW defines, however, they're based on the resource array indexing in the pci_dev struct. The struct pci_bus also has pointers to those same resources but they start from zeroth index.
Add PCI_BUS_BRIDGE_{IO,MEM,PREF_MEM}_WINDOW defines to get rid of literal indexing.
Stable-dep-of: 9abf79c8d7b4 ("PCI/ACPI: Restrict program_hpx_type2() to AER bits")
--- drivers/pci/pci.h | 4 ++++ drivers/pci/probe.c | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/pci/pci.h +4 -0
@@ -40,6 +40,10 @@#define PCIE_MSG_CODE_DEASSERT_INTC 0x26#define PCIE_MSG_CODE_DEASSERT_INTD 0x27 +#define PCI_BUS_BRIDGE_IO_WINDOW 0 +#define PCI_BUS_BRIDGE_MEM_WINDOW 1 +#define PCI_BUS_BRIDGE_PREF_MEM_WINDOW 2 +extern const unsigned char pcie_link_speed[];extern bool pci_early_dump;
drivers/pci/probe.c +7 -3
@@ -539,9 +539,13 @@ void pci_read_bridge_bases(struct pci_bus *child)for (i =0 ; i <PCI_BRIDGE_RESOURCE_NUM ; i++) child->resource[i] = &dev->resource[PCI_BRIDGE_RESOURCES +i]; -pci_read_bridge_io (child->self, child->resource[0 ], false); -pci_read_bridge_mmio (child->self, child->resource[1 ], false); -pci_read_bridge_mmio_pref (child->self, child->resource[2 ], false); +pci_read_bridge_io (child->self, + child->resource[PCI_BUS_BRIDGE_IO_WINDOW ], false); +pci_read_bridge_mmio (child->self, + child->resource[PCI_BUS_BRIDGE_MEM_WINDOW ], false); +pci_read_bridge_mmio_pref (child->self, + child->resource[PCI_BUS_BRIDGE_PREF_MEM_WINDOW ], + false);if (dev->transparent) {pci_bus_for_each_resource (child->parent, res) {
Signature · 1 line
2.51.0
PATCH 136/283 PCI/ACPI: Restrict program_hpx_type2() to AER bits
In reply to Sasha LevinFrom: Håkon Bugge <[email protected]>
[ Upstream commit 9abf79c8d7b40db0e5a34aa8c744ea60ff9a3fcf ]
Previously program_hpx_type2() applied PCIe settings unconditionally, which could incorrectly change bits like Extended Tag Field Enable and Enable Relaxed Ordering.
When _HPX was added to ACPI r3.0, the intent of the PCIe Setting Record (Type 2) in sec 6.2.7.3 was to configure AER registers when the OS does not own the AER Capability:
The PCI Express setting record contains ... [the AER] Uncorrectable Error Mask, Uncorrectable Error Severity, Correctable Error Mask ... to be used when configuring registers in the Advanced Error Reporting Extended Capability Structure ...
OSPM [1] will only evaluate _HPX with Setting Record – Type 2 if OSPM is not controlling the PCI Express Advanced Error Reporting capability.
ACPI r3.0b, sec 6.2.7.3, added more AER registers, including registers in the PCIe Capability with AER-related bits, and the restriction that the OS use this only when it owns PCIe native hotplug:
... when configuring PCI Express registers in the Advanced Error Reporting Extended Capability Structure *or PCI Express Capability Structure* ...
An OS that has assumed ownership of native hot plug but does not ... have ownership of the AER register set must use ... the Type 2 record to program the AER registers ...
However, since the Type 2 record also includes register bits that have functions other than AER, the OS must ignore values ... that are not applicable.
Restrict program_hpx_type2() to only the intended purpose:
- Apply settings only when OS owns PCIe native hotplug but not AER,
- Only touch the AER-related bits (Error Reporting Enables) in Device Control
- Don't touch Link Control at all, since nothing there seems AER-related, but log _HPX settings for debugging purposes
Note that Read Completion Boundary is now configured elsewhere, since it is unrelated to _HPX.
[1] Operating System-directed configuration and Power Management
--- drivers/pci/pci-acpi.c | 59 +++++++++++++++++------------------------- drivers/pci/pci.h | 3 +++ drivers/pci/pcie/aer.c | 3 --- 3 files changed, 27 insertions(+), 38 deletions(-)
drivers/pci/pci-acpi.c +24 -35
@@ -246,21 +246,6 @@ static acpi_status decode_type1_hpx_record(union acpi_object *record,return AE_OK ; } -static bool pcie_root_rcb_set (struct pci_dev *dev) -{ -struct pci_dev *rp =pcie_find_root_port (dev); -u16 lnkctl; - -if (!rp) -return false; - -pcie_capability_read_word (rp,PCI_EXP_LNKCTL , &lnkctl); -if (lnkctl &PCI_EXP_LNKCTL_RCB ) -return true; - -return false; -} -/* _HPX PCI Express Setting Record (Type 2) */ struct hpx_type2 {u32 revision;
@@ -286,6 +271,7 @@ static void program_hpx_type2(struct pci_dev *dev, struct hpx_type2 *hpx) {int pos;u32 reg32; +const struct pci_host_bridge *host;if (!hpx)return ;
@@ -293,6 +279,15 @@ static void program_hpx_type2(struct pci_dev *dev, struct hpx_type2 *hpx)if (!pci_is_pcie (dev))return ; + host =pci_find_host_bridge (dev->bus); + +/* +* Only do the _HPX Type 2 programming if OS owns PCIe native +* hotplug but not AER. +*/ +if (!host->native_pcie_hotplug || host->native_aer) +return ; +if (hpx->revision >1 ) {pci_warn (dev,"PCIe settings rev %d not supported\n" , hpx->revision);
@@ -300,33 +295,27 @@ static void program_hpx_type2(struct pci_dev *dev, struct hpx_type2 *hpx) }/* -* Don't allow _HPX to change MPS or MRRS settings. We manage -* those to make sure they're consistent with the rest of the -* platform. +* We only allow _HPX to program DEVCTL bits related to AER, namely +* PCI_EXP_DEVCTL_CERE, PCI_EXP_DEVCTL_NFERE, PCI_EXP_DEVCTL_FERE, +* and PCI_EXP_DEVCTL_URRE. +* +* The rest of DEVCTL is managed by the OS to make sure it's +* consistent with the rest of the platform. */ - hpx->pci_exp_devctl_and |=PCI_EXP_DEVCTL_PAYLOAD | -PCI_EXP_DEVCTL_READRQ ; - hpx->pci_exp_devctl_or &= ~(PCI_EXP_DEVCTL_PAYLOAD | -PCI_EXP_DEVCTL_READRQ ); + hpx->pci_exp_devctl_and |= ~PCI_EXP_AER_FLAGS ; + hpx->pci_exp_devctl_or &=PCI_EXP_AER_FLAGS ;/* Initialize Device Control Register */ pcie_capability_clear_and_set_word (dev,PCI_EXP_DEVCTL , ~hpx->pci_exp_devctl_and, hpx->pci_exp_devctl_or); -/* Initialize Link Control Register */ +/* Log if _HPX attempts to modify Link Control Register */ if (pcie_cap_has_lnkctl (dev)) { - -/* -* If the Root Port supports Read Completion Boundary of -* 128, set RCB to 128. Otherwise, clear it. -*/ - hpx->pci_exp_lnkctl_and |=PCI_EXP_LNKCTL_RCB ; - hpx->pci_exp_lnkctl_or &= ~PCI_EXP_LNKCTL_RCB ; -if (pcie_root_rcb_set (dev)) - hpx->pci_exp_lnkctl_or |=PCI_EXP_LNKCTL_RCB ; - -pcie_capability_clear_and_set_word (dev,PCI_EXP_LNKCTL , - ~hpx->pci_exp_lnkctl_and, hpx->pci_exp_lnkctl_or); +if (hpx->pci_exp_lnkctl_and !=0xffff || + hpx->pci_exp_lnkctl_or !=0 ) +pci_info (dev,"_HPX attempts Link Control setting (AND %#06x OR %#06x)\n" , + hpx->pci_exp_lnkctl_and, + hpx->pci_exp_lnkctl_or); }/* Find Advanced Error Reporting Enhanced Capability */
drivers/pci/pci.h +3 -0
@@ -44,6 +44,9 @@#define PCI_BUS_BRIDGE_MEM_WINDOW 1#define PCI_BUS_BRIDGE_PREF_MEM_WINDOW 2 +#define PCI_EXP_AER_FLAGS (PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | \ + PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE) +extern const unsigned char pcie_link_speed[];extern bool pci_early_dump;
drivers/pci/pcie/aer.c +0 -3
@@ -218,9 +218,6 @@ void pcie_ecrc_get_policy(char *str) }#endif /* CONFIG_PCIE_ECRC */ -#define PCI_EXP_AER_FLAGS (PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | \ - PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE) -int pcie_aer_is_native (struct pci_dev *dev) {struct pci_host_bridge *host =pci_find_host_bridge (dev->bus);
Signature · 1 line
2.51.0
PATCH 137/283 ipc: don't audit capability check in ipc_permissions()
In reply to Sasha LevinFrom: Ondrej Mosnacek <[email protected]>
[ Upstream commit 071588136007482d70fd2667b827036bc60b1f8f ]
The IPC sysctls implement the ctl_table_root::permissions hook and they override the file access mode based on the CAP_CHECKPOINT_RESTORE capability, which is being checked regardless of whether any access is actually denied or not, so if an LSM denies the capability, an audit record may be logged even when access is in fact granted.
It wouldn't be viable to restructure the sysctl permission logic to only check the capability when the access would be actually denied if it's not granted. Thus, do the same as in net_ctl_permissions() (net/sysctl_net.c) - switch from ns_capable() to ns_capable_noaudit(), so that the check never emits an audit record.
Stable-dep-of: 8924336531e2 ("ipc: don't audit capability check in ipc_permissions()")
--- include/linux/capability.h | 6 ++++++ ipc/ipc_sysctl.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/capability.h +6 -0
@@ -208,6 +208,12 @@ static inline bool checkpoint_restore_ns_capable(struct user_namespace *ns)ns_capable (ns,CAP_SYS_ADMIN ); } +static inline bool checkpoint_restore_ns_capable_noaudit (struct user_namespace *ns) +{ +return ns_capable_noaudit (ns,CAP_CHECKPOINT_RESTORE ) || +ns_capable_noaudit (ns,CAP_SYS_ADMIN ); +} +/* audit system wants to get cap info from files as well */ int get_vfs_caps_from_disk(struct mnt_idmap *idmap, const struct dentry *dentry,
ipc/ipc_sysctl.c +1 -1
@@ -215,7 +215,7 @@ static int ipc_permissions(struct ctl_table_header *head, struct ctl_table *tablif (((table->data == &ns->ids[IPC_SEM_IDS ].next_id) || (table->data == &ns->ids[IPC_MSG_IDS ].next_id) || (table->data == &ns->ids[IPC_SHM_IDS ].next_id)) && -checkpoint_restore_ns_capable (ns->user_ns)) +checkpoint_restore_ns_capable_noaudit (ns->user_ns)) mode =0666 ; else#endif
Signature · 1 line
2.51.0
PATCH 138/283 ucount: check for CAP_SYS_RESOURCE using ns_capable_noaudit()
In reply to Sasha LevinFrom: Ondrej Mosnacek <[email protected]>
[ Upstream commit 0895a000e4fff9e950a7894210db45973e485c35 ]
The user.* sysctls implement the ctl_table_root::permissions hook and they override the file access mode based on the CAP_SYS_RESOURCE capability (at most rwx if capable, at most r-- if not). The capability is being checked unconditionally, so if an LSM denies the capability, an audit record may be logged even when access is in fact granted.
Given the logic in the set_permissions() function in kernel/ucount.c and the unfortunate way the permission checking is implemented, it doesn't seem viable to avoid false positive denials by deferring the capability check. Thus, do the same as in net_ctl_permissions() (net/sysctl_net.c) - switch from ns_capable() to ns_capable_noaudit(), so that the check never logs an audit record.
--- kernel/ucount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/ucount.c +1 -1
@@ -45,7 +45,7 @@ static int set_permissions(struct ctl_table_header *head,int mode;/* Allow users with CAP_SYS_RESOURCE unrestrained access */ -if (ns_capable (user_ns,CAP_SYS_RESOURCE )) +if (ns_capable_noaudit (user_ns,CAP_SYS_RESOURCE )) mode = (table->mode &S_IRWXU ) >>6 ;else /* Allow all others at most read-only access */
Signature · 1 line
2.51.0
PATCH 139/283 of: unittest: fix possible null-pointer dereferences in of_unittest_property_copy()
In reply to Sasha LevinFrom: Tuo Li <[email protected]>
[ Upstream commit d289cb7fcefe41a54d8f9c6d0e0947f5f82b15c6 ]
This function first duplicates p1 and p2 into new, and then checks whether the duplication succeeds. However, if the duplication fails (e.g., kzalloc() returns NULL in __of_prop_dup()), new will be NULL but is still dereferenced in __of_prop_free(). To ensure that the unit test continues to run even when duplication fails, add a NULL check before calling __of_prop_free().
--- drivers/of/unittest.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/of/unittest.c +4 -2
@@ -800,11 +800,13 @@ static void __init of_unittest_property_copy(void) new =__of_prop_dup (&p1,GFP_KERNEL );unittest (new &&propcmp (&p1, new),"empty property didn't copy correctly\n" ); -__of_prop_free (new); +if (new) +__of_prop_free (new); new =__of_prop_dup (&p2,GFP_KERNEL );unittest (new &&propcmp (&p2, new),"non-empty property didn't copy correctly\n" ); -__of_prop_free (new); +if (new) +__of_prop_free (new);#endif }
Signature · 1 line
2.51.0
PATCH 140/283 mptcp: fix receive space timestamp initialization
In reply to Sasha LevinFrom: Paolo Abeni <[email protected]>
[ Upstream commit 70274765fef555af92a1532d5bd5450c691fca9d ]
MPTCP initialize the receive buffer stamp in mptcp_rcv_space_init(), using the provided subflow stamp. Such helper is invoked in several places; for passive sockets, space init happened at clone time.
In such scenario, MPTCP ends-up accesses the subflow stamp before its initialization, leading to quite randomic timing for the first receive buffer auto-tune event, as the timestamp for newly created subflow is not refreshed there.
Fix the issue moving the stamp initialization out of the mentioned helper, at the data transfer start, and always using a fresh timestamp.
--- net/mptcp/protocol.c | 8 ++++---- net/mptcp/protocol.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +4 -4
@@ -2048,8 +2048,8 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied) msk->rcvq_space.copied += copied; - mstamp =div_u64 (tcp_clock_ns (),NSEC_PER_USEC ); - time =tcp_stamp_us_delta (mstamp, msk->rcvq_space.time); + mstamp =mptcp_stamp (); + time =tcp_stamp_us_delta (mstamp,READ_ONCE (msk->rcvq_space.time)); rtt_us = msk->rcvq_space.rtt_us;if (rtt_us && time < (rtt_us >>3 ))
@@ -3451,6 +3451,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,__mptcp_propagate_sndbuf (nsk, ssk);mptcp_rcv_space_init (msk, ssk); + msk->rcvq_space.time =mptcp_stamp ();if (mp_opt->suboptions &OPTION_MPTCP_MPC_ACK )__mptcp_subflow_fully_established (msk, subflow, mp_opt);
@@ -3468,8 +3469,6 @@ void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk) msk->rcvq_space.copied =0 ; msk->rcvq_space.rtt_us =0 ; - msk->rcvq_space.time = tp->tcp_mstamp; -/* initial rcv_space offering made to peer */ msk->rcvq_space.space =min_t (u32, tp->rcv_wnd,TCP_INIT_CWND * tp->advmss);
@@ -3688,6 +3687,7 @@ void mptcp_finish_connect(struct sock *ssk)* accessing the field below */ WRITE_ONCE (msk->local_key, subflow->local_key); +WRITE_ONCE (msk->rcvq_space.time,mptcp_stamp ());mptcp_pm_new_connection (msk, ssk,0 ); }
net/mptcp/protocol.h +5 -0
@@ -786,6 +786,11 @@ static inline bool mptcp_is_fully_established(struct sock *sk)READ_ONCE (mptcp_sk (sk)->fully_established); } +static inline u64 mptcp_stamp (void ) +{ +return div_u64 (tcp_clock_ns (),NSEC_PER_USEC ); +} +void mptcp_rcv_space_init (struct mptcp_sock *msk,const struct sock *ssk);void mptcp_data_ready (struct sock *sk,struct sock *ssk);bool mptcp_finish_join (struct sock *sk);
Signature · 1 line
2.51.0
PATCH 141/283 octeontx2-af: Fix PF driver crash with kexec kernel booting
In reply to Sasha LevinFrom: Anshumali Gaur <[email protected]>
[ Upstream commit 2d2d574309e3ae84ee794869a5da8b4c38753a94 ]
During a kexec reboot the hardware is not power-cycled, so AF state from the old kernel can persist into the new kernel. When AF and PF drivers are built as modules, the PF driver may probe before AF reinitializes the hardware.
The PF driver treats the RVUM block revision as an indication that AF initialization is complete. If this value is left uncleared at shutdown, PF may incorrectly assume AF is ready and access stale hardware state, leading to a crash.
Clear the RVUM block revision during AF shutdown to avoid PF mis-detecting AF readiness after kexec.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +11 -0
@@ -3444,11 +3444,22 @@ static void rvu_remove(struct pci_dev *pdev)devm_kfree (&pdev->dev, rvu); } +static void rvu_shutdown (struct pci_dev *pdev) +{ +struct rvu *rvu =pci_get_drvdata (pdev); + +if (!rvu) +return ; + +rvu_clear_rvum_blk_revid (rvu); +} +static struct pci_driver rvu_driver = { .name =DRV_NAME , .id_table = rvu_id_table, .probe = rvu_probe, .remove = rvu_remove, + .shutdown = rvu_shutdown, };static int __init rvu_init_module (void )
Signature · 1 line
2.51.0
PATCH 142/283 bonding: only set speed/duplex to unknown, if getting speed failed
In reply to Sasha LevinFrom: Thomas Bogendoerfer <[email protected]>
[ Upstream commit 48dec8d88af96039a4a17b8c2f148f2a4066e195 ]
bond_update_speed_duplex() first set speed/duplex to unknown and then asks slave driver for current speed/duplex. Since getting speed/duplex might take longer there is a race, where this false state is visible by /proc/net/bonding. With commit 691b2bf14946 ("bonding:
update port speed when getting bond speed") this race gets more visible,
if user space is calling ethtool on a regular base.
Fix this by only setting speed/duplex to unknown, if link speed is really unknown/unusable.
--- drivers/net/bonding/bond_main.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/net/bonding/bond_main.c +9 -6
@@ -727,26 +727,29 @@ static int bond_update_speed_duplex(struct slave *slave)struct ethtool_link_ksettings ecmd;int res; - slave->speed =SPEED_UNKNOWN ; - slave->duplex =DUPLEX_UNKNOWN ; - res =__ethtool_get_link_ksettings (slave_dev, &ecmd);if (res <0 ) -return 1 ; + goto speed_duplex_unknown;if (ecmd.base.speed ==0 || ecmd.base.speed == ((__u32)-1 )) -return 1 ; + goto speed_duplex_unknown;switch (ecmd.base.duplex) {case DUPLEX_FULL :case DUPLEX_HALF :break ;default : -return 1 ; + goto speed_duplex_unknown; } slave->speed = ecmd.base.speed; slave->duplex = ecmd.base.duplex;return 0 ; + +speed_duplex_unknown: + slave->speed =SPEED_UNKNOWN ; + slave->duplex =DUPLEX_UNKNOWN ; + +return 1 ; }const char *bond_slave_link_status (s8 link)
Signature · 1 line
2.51.0
PATCH 143/283 inet: RAW sockets using IPPROTO_RAW MUST drop incoming ICMP
In reply to Sasha LevinFrom: Eric Dumazet <[email protected]>
[ Upstream commit c89477ad79446867394360b29bb801010fc3ff22 ]
Yizhou Zhao reported that simply having one RAW socket on protocol IPPROTO_RAW (255) was dangerous.
socket(AF_INET, SOCK_RAW, 255);
A malicious incoming ICMP packet can set the protocol field to 255 and match this socket, leading to FNHE cache changes.
inner = IP(src="192.168.2.1", dst="8.8.8.8", proto=255)/Raw("TEST")
pkt = IP(src="192.168.1.1", dst="192.168.2.1")/ICMP(type=3, code=4, nexthopmtu=576)/inner
"man 7 raw" states:
A protocol of IPPROTO_RAW implies enabled IP_HDRINCL and is able to send any IP protocol that is specified in the passed header. Receiving of all IP protocols via IPPROTO_RAW is not possible using raw sockets.
Make sure we drop these malicious packets.
--- net/ipv4/icmp.c | 14 ++++++++++---- net/ipv6/icmp.c | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-)
net/ipv4/icmp.c +10 -4
@@ -840,16 +840,22 @@ static void icmp_socket_deliver(struct sk_buff *skb, u32 info)/* Checkin full IP header plus 8 bytes of protocol to * avoid additional coding at protocol handlers. */ -if (!pskb_may_pull (skb, iph->ihl *4 +8 )) { -__ICMP_INC_STATS (dev_net_rcu (skb->dev),ICMP_MIB_INERRORS ); -return ; - } +if (!pskb_may_pull (skb, iph->ihl *4 +8 )) + goto out; + +/* IPPROTO_RAW sockets are not supposed to receive anything. */ +if (protocol ==IPPROTO_RAW ) + goto out;raw_icmp_error (skb, protocol, info); ipprot =rcu_dereference (inet_protos[protocol]);if (ipprot && ipprot->err_handler) ipprot->err_handler (skb, info); +return ; + +out: +__ICMP_INC_STATS (dev_net_rcu (skb->dev),ICMP_MIB_INERRORS ); }static bool icmp_tag_validation (int proto)
net/ipv6/icmp.c +6 -0
@@ -869,6 +869,12 @@ enum skb_drop_reason icmpv6_notify(struct sk_buff *skb, u8 type,if (reason !=SKB_NOT_DROPPED_YET ) goto out; +if (nexthdr ==IPPROTO_RAW ) { +/* Add a more specific reason later ? */ + reason =SKB_DROP_REASON_NOT_SPECIFIED ; + goto out; + } +/* BUGGG_FUTURE: we should try to parse exthdrs in this packet. Without this we will not able f.e. to make source routed pmtu discovery.
Signature · 1 line
2.51.0
PATCH 144/283 nfc: hci: shdlc: Stop timers and work before freeing context
In reply to Sasha LevinFrom: Votokina Victoria <[email protected]>
[ Upstream commit c9efde1e537baed7648a94022b43836a348a074f ]
llc_shdlc_deinit() purges SHDLC skb queues and frees the llc_shdlc structure while its timers and state machine work may still be active.
Timer callbacks can schedule sm_work, and sm_work accesses SHDLC state and the skb queues. If teardown happens in parallel with a queued/running work item, it can lead to UAF and other shutdown races.
Stop all SHDLC timers and cancel sm_work synchronously before purging the queues and freeing the context.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- net/nfc/hci/llc_shdlc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/nfc/hci/llc_shdlc.c +8 -0
@@ -762,6 +762,14 @@ static void llc_shdlc_deinit(struct nfc_llc *llc) {struct llc_shdlc *shdlc =nfc_llc_get_data (llc); +timer_shutdown_sync (&shdlc->connect_timer); +timer_shutdown_sync (&shdlc->t1_timer); +timer_shutdown_sync (&shdlc->t2_timer); + shdlc->t1_active = false; + shdlc->t2_active = false; + +cancel_work_sync (&shdlc->sm_work); +skb_queue_purge (&shdlc->rcv_q);skb_queue_purge (&shdlc->send_q);skb_queue_purge (&shdlc->ack_pending_q);
Signature · 1 line
2.51.0
PATCH 145/283 netfilter: nft_set_hash: fix get operation on big endian
In reply to Sasha LevinFrom: Florian Westphal <[email protected]>
[ Upstream commit 2f635adbe2642d398a0be3ab245accd2987be0c3 ]
tests/shell/testcases/packetpath/set_match_nomatch_hash_fast fails on big endian with:
Error: Could not process rule: No such file or directory reset element ip test s { 244.147.90.126 } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Fatal: Cannot fetch element "244.147.90.126"
... because the wrong bucket is searched, jhash() and jhash1_word are not interchangeable on big endian.
--- net/netfilter/nft_set_hash.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/netfilter/nft_set_hash.c +7 -2
@@ -525,15 +525,20 @@ bool nft_hash_lookup(const struct net *net, const struct nft_set *set,static void *nft_hash_get (const struct net *net,const struct nft_set *set,const struct nft_set_elem *elem,unsigned int flags) { +const u32 *key = (const u32 *)&elem->key.val;struct nft_hash *priv =nft_set_priv (set);u8 genmask =nft_genmask_cur (net);struct nft_hash_elem *he;u32 hash; - hash =jhash (elem->key.val.data, set->klen, priv->seed); +if (set->klen ==4 ) + hash =jhash_1word (*key, priv->seed); +else + hash =jhash (key, set->klen, priv->seed); + hash =reciprocal_scale (hash, priv->buckets);hlist_for_each_entry_rcu (he, &priv->table[hash], node) { -if (!memcmp (nft_set_ext_key (&he->ext), elem->key.val.data, set->klen) && +if (!memcmp (nft_set_ext_key (&he->ext), key, set->klen) &&nft_set_elem_active (&he->ext, genmask))return he; }
Signature · 1 line
2.51.0
PATCH 146/283 netfilter: nft_counter: fix reset of counters on 32bit archs
In reply to Sasha LevinFrom: Anders Grahn <[email protected]>
[ Upstream commit 1e13f27e0675552161ab1778be9a23a636dde8a7 ]
nft_counter_reset() calls u64_stats_add() with a negative value to reset the counter. This will work on 64bit archs, hence the negative value added will wrap as a 64bit value which then can wrap the stat counter as well.
On 32bit archs, the added negative value will wrap as a 32bit value and _not_ wrapping the stat counter properly. In most cases, this would just lead to a very large 32bit value being added to the stat counter.
Fix by introducing u64_stats_sub().
--- include/linux/u64_stats_sync.h | 10 ++++++++++ net/netfilter/nft_counter.c | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-)
include/linux/u64_stats_sync.h +10 -0
@@ -89,6 +89,11 @@ static inline void u64_stats_add(u64_stats_t *p, unsigned long val)local64_add (val, &p->v); } +static inline void u64_stats_sub (u64_stats_t *p,s64 val) +{ +local64_sub (val, &p->v); +} +static inline void u64_stats_inc (u64_stats_t *p) {local64_inc (&p->v);
@@ -130,6 +135,11 @@ static inline void u64_stats_add(u64_stats_t *p, unsigned long val) p->v += val; } +static inline void u64_stats_sub (u64_stats_t *p,s64 val) +{ + p->v -= val; +} +static inline void u64_stats_inc (u64_stats_t *p) { p->v++;
net/netfilter/nft_counter.c +2 -2
@@ -117,8 +117,8 @@ static void nft_counter_reset(struct nft_counter_percpu_priv *priv, nft_sync =this_cpu_ptr (&nft_counter_sync);u64_stats_update_begin (nft_sync); -u64_stats_add (&this_cpu->packets, -total->packets); -u64_stats_add (&this_cpu->bytes, -total->bytes); +u64_stats_sub (&this_cpu->packets, total->packets); +u64_stats_sub (&this_cpu->bytes, total->bytes);u64_stats_update_end (nft_sync);local_bh_enable ();
Signature · 1 line
2.51.0
PATCH 147/283 netfilter: nft_set_rbtree: check for partial overlaps in anonymous sets
In reply to Sasha LevinFrom: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 4780ec142cbb24b794129d3080eee5cac2943ffc ]
Userspace provides an optimized representation in case intervals are adjacent, where the end element is omitted.
The existing partial overlap detection logic skips anonymous set checks on start elements for this reason.
However, it is possible to add intervals that overlap to this anonymous where two start elements with the same, eg. A-B, A-C where C < B.
start end
A B
start end
A C
Restore the check on overlapping start elements to report an overlap.
--- net/netfilter/nft_set_rbtree.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
net/netfilter/nft_set_rbtree.c +25 -5
@@ -305,11 +305,23 @@ static bool nft_rbtree_update_first(const struct nft_set *set,return false; } +/* Only for anonymous sets which do not allow updates, all element are active. */ +static struct nft_rbtree_elem *nft_rbtree_prev_active (struct nft_rbtree_elem *rbe) +{ +struct rb_node *node; + + node =rb_prev (&rbe->node); +if (!node) +return NULL ; + + return rb_entry(node, struct nft_rbtree_elem, node); +} +static int __nft_rbtree_insert (const struct net *net,const struct nft_set *set,struct nft_rbtree_elem *new,struct nft_set_ext **ext) { -struct nft_rbtree_elem *rbe, *rbe_le =NULL , *rbe_ge =NULL ; +struct nft_rbtree_elem *rbe, *rbe_le =NULL , *rbe_ge =NULL , *rbe_prev;struct rb_node *node, *next, *parent, **p, *first =NULL ;struct nft_rbtree *priv =nft_set_priv (set);u8 cur_genmask =nft_genmask_cur (net);
@@ -441,11 +453,19 @@ static int __nft_rbtree_insert(const struct net *net, const struct nft_set *set,/* - new start element with existing closest, less or equal key value * being a start element: partial overlap, reported as -ENOTEMPTY. * Anonymous sets allow for two consecutive start element since they -* are constant, skip them to avoid bogus overlap reports. +* are constant, but validate that this new start element does not +* sit in between an existing start and end elements: partial overlap, +* reported as -ENOTEMPTY. */ -if (!nft_set_is_anonymous (set) && rbe_le && -nft_rbtree_interval_start (rbe_le) &&nft_rbtree_interval_start (new)) -return -ENOTEMPTY ; +if (rbe_le && +nft_rbtree_interval_start (rbe_le) &&nft_rbtree_interval_start (new)) { +if (!nft_set_is_anonymous (set)) +return -ENOTEMPTY ; + + rbe_prev =nft_rbtree_prev_active (rbe_le); +if (rbe_prev &&nft_rbtree_interval_end (rbe_prev)) +return -ENOTEMPTY ; + }/* - new end element with existing closest, less or equal key value * being a end element: partial overlap, reported as -ENOTEMPTY.
Signature · 1 line
2.51.0
PATCH 148/283 PCI: Add ACS quirk for Pericom PI7C9X2G404 switches [12d8:b404]
In reply to Sasha LevinFrom: Nicolas Cavallari <[email protected]>
[ Upstream commit 5907a90551e9f7968781f3a6ab8684458959beb3 ]
12d8:b404 is apparently another PCI ID for Pericom PI7C9X2G404 (as identified by the chip silkscreen and lspci).
It is also affected by the PI7C9X2G errata (e.g. a network card attached to it fails under load when P2P Redirect Request is enabled), so apply the same quirk to this PCI ID too.
PCI bridge [0604]: Pericom Semiconductor PI7C9X2G404 EV/SV PCIe2 4-Port/4-Lane Packet Switch [12d8:b404] (rev 01)
--- drivers/pci/quirks.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/pci/quirks.c +4 -0
@@ -6181,6 +6181,10 @@ DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_PERICOM, 0x2303, pci_fixup_pericom_acs_store_forward);DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_PERICOM ,0x2303 , pci_fixup_pericom_acs_store_forward); +DECLARE_PCI_FIXUP_ENABLE (PCI_VENDOR_ID_PERICOM ,0xb404 , + pci_fixup_pericom_acs_store_forward); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_PERICOM ,0xb404 , + pci_fixup_pericom_acs_store_forward);static void nvidia_ion_ahci_fixup (struct pci_dev *pdev) {
Signature · 1 line
2.51.0
PATCH 149/283 net: hns3: fix double free issue for tx spare buffer
In reply to Sasha LevinFrom: Jian Shen <[email protected]>
[ Upstream commit 6d2f142b1e4b203387a92519d9d2e34752a79dbb ]
In hns3_set_ringparam(), a temporary copy (tmp_rings) of the ring structure is created for rollback. However, the tx_spare pointer in the original ring handle is incorrectly left pointing to the old backup memory.
Later, if memory allocation fails in hns3_init_all_ring() during the setup, the error path attempts to free all newly allocated rings. Since tx_spare contains a stale (non-NULL) pointer from the backup, it is mistaken for a newly allocated buffer and is erroneously freed, leading to a double-free of the backup memory.
The root cause is that the tx_spare field was not cleared after its value was saved in tmp_rings, leaving a dangling pointer.
Fix this by setting tx_spare to NULL in the original ring structure when the creation of the new tx_spare fails. This ensures the error cleanup path only frees genuinely newly allocated buffers.
--- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +9 -2
@@ -1048,13 +1048,13 @@ static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring)int order;if (!alloc_size) -return ; + goto not_init; order =get_order (alloc_size);if (order >MAX_ORDER ) {if (net_ratelimit ())dev_warn (ring_to_dev (ring),"failed to allocate tx spare buffer, exceed to max order\n" ); -return ; + goto not_init; } tx_spare = devm_kzalloc(ring_to_dev(ring), sizeof(*tx_spare),
@@ -1092,6 +1092,13 @@ static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring)devm_kfree (ring_to_dev (ring), tx_spare); devm_kzalloc_error: ring->tqp->handle->kinfo.tx_spare_buf_size =0 ; +not_init: +/* When driver init or reset_init, the ring->tx_spare is always NULL; +* but when called from hns3_set_ringparam, it's usually not NULL, and +* will be restored if hns3_init_all_ring() failed. So it's safe to set +* ring->tx_spare to NULL here. +*/ + ring->tx_spare =NULL ; }/* Use hns3_tx_spare_space() to make sure there is enough buffer
Signature · 1 line
2.51.0
PATCH 150/283 procfs: fix missing RCU protection when reading real_parent in do_task_stat()
In reply to Sasha LevinFrom: Jinliang Zheng <[email protected]>
[ Upstream commit 76149d53502cf17ef3ae454ff384551236fba867 ]
When reading /proc/[pid]/stat, do_task_stat() accesses task->real_parent without proper RCU protection, which leads to:
cpu 0 cpu 1
----- -----
do_task_stat
var = task->real_parent
release_task
call_rcu(delayed_put_task_struct)
task_tgid_nr_ns(var)
rcu_read_lock <--- Too late to protect task->real_parent!
task_pid_ptr <--- UAF!
rcu_read_unlockThis patch uses task_ppid_nr_ns() instead of task_tgid_nr_ns() to add proper RCU protection for accessing task->real_parent.
--- fs/proc/array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/proc/array.c +1 -1
@@ -531,7 +531,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, } sid =task_session_nr_ns (task, ns); - ppid =task_tgid_nr_ns (task->real_parent, ns); + ppid =task_ppid_nr_ns (task, ns); pgid =task_pgrp_nr_ns (task, ns);unlock_task_sighand (task, &flags);
Signature · 1 line
2.51.0
PATCH 151/283 smb: client: correct value for smbd_max_fragmented_recv_size
In reply to Sasha LevinFrom: Stefan Metzmacher <[email protected]>
[ Upstream commit 4a93d1ee2d0206970b6eb13fbffe07938cd95948 ]
When we download a file without rdma offload or get
a large directly enumeration from the server,
the server might want to send up to smbd_max_fragmented_recv_size bytes, but if it is too large all our recv buffers might already be moved to the recv_io.reassembly.list and we're no longer able to grant recv credits.
The maximum fragmented upper-layer payload receive size supported
Assume max_payload_per_credit issmbd_max_receive_size - 24 = 1340
The maximum number would besmbd_receive_credit_max * max_payload_per_credit
1340 * 255 = 341700 (0x536C4)
The minimum value from the spec is 131072 (0x20000)
For now we use the logic we used in ksmbd before:
(1364 * 255) / 2 = 173910 (0x2A756)
--- fs/smb/client/smbdirect.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
fs/smb/client/smbdirect.c +17 -2
@@ -91,8 +91,23 @@ int smbd_send_credit_target = 255;/* The maximum single message size can be sent to remote peer */ int smbd_max_send_size =1364 ; -/* The maximum fragmented upper-layer payload receive size supported */ -int smbd_max_fragmented_recv_size =1024 *1024 ; +/* +* The maximum fragmented upper-layer payload receive size supported +* +* Assume max_payload_per_credit is +* smbd_max_receive_size - 24 = 1340 +* +* The maximum number would be +* smbd_receive_credit_max * max_payload_per_credit +* +* 1340 * 255 = 341700 (0x536C4) +* +* The minimum value from the spec is 131072 (0x20000) +* +* For now we use the logic we used in ksmbd before: +* (1364 * 255) / 2 = 173910 (0x2A756) +*/ +int smbd_max_fragmented_recv_size = (1364 *255 ) /2 ;/* The maximum single-message size which can be received */ int smbd_max_receive_size =1364 ;
Signature · 1 line
2.51.0