7.3.7-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 340/1005 perf: Move and enhance has_extended_regs() for arch-specific use
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kan Liang <[email protected]>
[ Upstream commit 05fe8825796e6b5557656c6c984486f0e66154fe ]
Move has_extended_regs() to include/linux/perf_event.h so it can be used by arch-specific code.
While moving it, enhance the check logic and rename it to event_has_extended_regs() to match existing perf event helper naming.
Stable-dep-of: b61c12527223 ("perf/amd/ibs: Fix kernel address leak via REGS_USER and REGS_INTR")
--- include/linux/perf_event.h | 10 ++++++++++ kernel/events/core.c | 8 +------- 2 files changed, 11 insertions(+), 7 deletions(-)
include/linux/perf_event.h +10 -0
@@ -1518,6 +1518,16 @@ perf_event__output_id_sample(struct perf_event *event,extern void perf_log_lost_samples (struct perf_event *event,u64 lost); +static inline bool event_has_extended_regs (struct perf_event *event) +{ +struct perf_event_attr *attr = &event->attr; + +return ((attr->sample_type &PERF_SAMPLE_REGS_USER ) && + (attr->sample_regs_user &PERF_REG_EXTENDED_MASK )) || + ((attr->sample_type &PERF_SAMPLE_REGS_INTR ) && + (attr->sample_regs_intr &PERF_REG_EXTENDED_MASK )); +} +static inline bool event_has_any_exclude_flag (struct perf_event *event) {struct perf_event_attr *attr = &event->attr;
kernel/events/core.c +1 -7
@@ -13110,12 +13110,6 @@ int perf_pmu_unregister(struct pmu *pmu) }EXPORT_SYMBOL_GPL (perf_pmu_unregister); -static inline bool has_extended_regs (struct perf_event *event) -{ -return (event->attr.sample_regs_user &PERF_REG_EXTENDED_MASK ) || - (event->attr.sample_regs_intr &PERF_REG_EXTENDED_MASK ); -} -static int perf_try_init_event (struct pmu *pmu,struct perf_event *event) {struct perf_event_context *ctx =NULL ;
@@ -13150,7 +13144,7 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event) goto err_pmu;if (!(pmu->capabilities &PERF_PMU_CAP_EXTENDED_REGS ) && -has_extended_regs (event)) { +event_has_extended_regs (event)) { ret = -EOPNOTSUPP ; goto err_destroy; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 341/1005 perf: Add sampling support for SIMD registers
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kan Liang <[email protected]>
[ Upstream commit 918b7d6d1729952d51da4fa81db7b366a207de8f ]
Users may be interested in sampling SIMD registers during profiling. The current sample_regs_* structure does not have sufficient space for all SIMD registers.
To address this, new attribute fields sample_simd_{pred,vec}_reg_* are added to struct perf_event_attr to represent the SIMD registers that are expected to be sampled.
Currently, the perf/x86 code supports XMM registers in sample_regs_*. To unify the configuration of SIMD registers and ensure a consistent method for configuring XMM and other SIMD registers, a new event attribute field, sample_simd_regs_enabled, is introduced. When sample_simd_regs_enabled is set, it indicates that all SIMD registers, including XMM, will be represented by the newly introduced sample_simd_{pred|vec}_reg_* fields. The original XMM space in sample_regs_* is reserved for future uses.
Since SIMD registers are wider than 64 bits, a new output format is introduced. The number and width of SIMD registers are dumped first, followed by the register values. The number and width are based on the user's configuration.
A new ABI, PERF_SAMPLE_REGS_ABI_SIMD, is added to indicate the new format. The enum perf_sample_regs_abi is now a bitmap. This change should not impact existing tools, as the version and bitmap remain the same for values 1 and 2.
Additionally, two new __weak functions are introduced:
- perf_simd_reg_value(): Retrieves the value of the requested SIMD register.
- perf_simd_reg_validate(): Validates the configuration of the SIMD registers.
A new flag, PERF_PMU_CAP_SIMD_REGS, is added to indicate that the PMU supports SIMD register dumping. An error is generated if sample_simd_{pred|vec}_reg_* is mistakenly set for a PMU that does not support this capability.
Stable-dep-of: b61c12527223 ("perf/amd/ibs: Fix kernel address leak via REGS_USER and REGS_INTR")
--- include/linux/perf_event.h | 12 +++ include/linux/perf_regs.h | 4 + include/uapi/linux/perf_event.h | 49 ++++++++++- kernel/events/core.c | 141 +++++++++++++++++++++++++++++--- 4 files changed, 192 insertions(+), 14 deletions(-)
include/linux/perf_event.h +12 -0
@@ -306,6 +306,7 @@ struct perf_event_pmu_context;#define PERF_PMU_CAP_AUX_PAUSE 0x0200#define PERF_PMU_CAP_AUX_PREFER_LARGE 0x0400#define PERF_PMU_CAP_MEDIATED_VPMU 0x0800 +#define PERF_PMU_CAP_SIMD_REGS 0x1000/** * pmu::scope
@@ -1518,6 +1519,17 @@ perf_event__output_id_sample(struct perf_event *event,extern void perf_log_lost_samples (struct perf_event *event,u64 lost); +static inline bool event_has_simd_regs (struct perf_event *event) +{ +struct perf_event_attr *attr = &event->attr; + +if (!(event->attr.sample_type & + (PERF_SAMPLE_REGS_INTR |PERF_SAMPLE_REGS_USER ))) +return false; + +return attr->sample_simd_regs_enabled !=0 ; +} +static inline bool event_has_extended_regs (struct perf_event *event) {struct perf_event_attr *attr = &event->attr;
include/linux/perf_regs.h +4 -0
@@ -14,6 +14,10 @@ int perf_reg_validate(u64 mask);u64 perf_reg_abi (struct task_struct *task);void perf_get_regs_user (struct perf_regs *regs_user,struct pt_regs *regs); +int perf_simd_reg_validate (u16 vec_qwords,u64 vec_mask, +u16 pred_qwords,u32 pred_mask); +u64 perf_simd_reg_value (struct pt_regs *regs,int idx, +u16 qwords_idx,bool pred);#ifdef CONFIG_HAVE_PERF_REGS #include <asm/perf_regs.h>
include/uapi/linux/perf_event.h +45 -4
79 lines not on this page · raw message
kernel/events/core.c +131 -10
226 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 342/1005 perf/amd/ibs: Fix kernel address leak via REGS_USER and REGS_INTR
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ravi Bangoria <[email protected]>
[ Upstream commit b61c12527223423ab66891b2e8131da0d66537c4 ]
IBS hardware captures a sample and raises an NMI. Since the NMI can be delivered with a delay, a privilege change may occur between sample capture and NMI delivery. Because IBS only provides the sample RIP, the kernel records GPRs from the NMI pt_regs, which may reflect kernel mode if a privilege switch occurred in the interim. This can leak kernel addresses to unprivileged users through PERF_SAMPLE_REGS_USER and/or PERF_SAMPLE_REGS_INTR.
Fix this by using interrupt regs while preparing PERF_SAMPLE_REGS_USER and PERF_SAMPLE_REGS_INTR. With the change, when IBS samples a user mode instruction but the NMI is delivered in kernel mode, PERF_SAMPLE_REGS_USER will source its register state from task_pt_regs(current) and PERF_SAMPLE_REGS_INTR will be omitted from the data sent to userspace.
In addition to fixing the kernel address leak, this change also ensures GPR snapshot consistency, which resolves the DWARF unwinding issue with IBS.
--- arch/x86/events/amd/ibs.c | 50 ++++++++++++++++++++++++++++++++++++++ include/linux/perf_event.h | 6 +++++ kernel/events/core.c | 10 ++++---- 3 files changed, 61 insertions(+), 5 deletions(-)
arch/x86/events/amd/ibs.c +50 -0
@@ -1533,6 +1533,56 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs) throttle =perf_event_account_interrupt (event); goto out; } + +/* +* IBS captured RIP is out of sync with NMI pt_regs due to NMI +* delivery latency. Use NMI pt_regs for PERF_SAMPLE_REGS_USER. +* +* Note: Valid user regs are required for PERF_SAMPLE_STACK_USER. +*/ +if (event->attr.sample_type & (PERF_SAMPLE_REGS_USER | +PERF_SAMPLE_STACK_USER )) { +perf_sample_regs_user (&data.regs_user, iregs); + +/* +* Don't update dyn_size if user has not requested for +* PERF_SAMPLE_REGS_USER. +*/ +if (event->attr.sample_type &PERF_SAMPLE_REGS_USER ) { +/* regs dump ABI info */ +int size =sizeof (u64); + +if (data.regs_user.regs) { +u64 mask = event->attr.sample_regs_user; + size +=hweight64 (mask) *sizeof (u64); + } + + data.dyn_size += size; + } + + data.sample_flags |=PERF_SAMPLE_REGS_USER ; + } + +/* +* IBS captured RIP is out of sync with NMI pt_regs due to NMI +* delivery latency. Use NMI pt_regs for PERF_SAMPLE_REGS_INTR. +*/ +if (event->attr.sample_type &PERF_SAMPLE_REGS_INTR ) { +/* regs dump ABI info */ +int size =sizeof (u64); + +perf_sample_regs_intr (&data.regs_intr, iregs, + event->attr.exclude_kernel); + +if (data.regs_intr.regs) { +u64 mask = event->attr.sample_regs_intr; + size +=hweight64 (mask) *sizeof (u64); + } + + data.dyn_size += size; + data.sample_flags |=PERF_SAMPLE_REGS_INTR ; + } +/* * Prevent leaking physical addresses to unprivileged users. Skip * PERF_SAMPLE_PHYS_ADDR check since generic code prevents it for
include/linux/perf_event.h +6 -0
@@ -1813,6 +1813,12 @@ extern unsigned long perf_misc_flags(struct perf_event *event, struct pt_regs *rextern unsigned long perf_instruction_pointer (struct perf_event *event,struct pt_regs *regs); +extern void perf_sample_regs_user (struct perf_regs *regs_user, +struct pt_regs *regs); +extern void perf_sample_regs_intr (struct perf_regs *regs_intr, +struct pt_regs *regs, +bool exclude_kernel); +#ifndef perf_arch_misc_flags# define perf_arch_misc_flags (regs) \ (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
kernel/events/core.c +5 -5
@@ -7919,8 +7919,8 @@ perf_output_sample_simd_regs(struct perf_output_handle *handle, } } -static void perf_sample_regs_user (struct perf_regs *regs_user, -struct pt_regs *regs) +void perf_sample_regs_user (struct perf_regs *regs_user, +struct pt_regs *regs) {if (user_mode (regs)) { regs_user->abi =perf_reg_abi (current);
@@ -7933,9 +7933,9 @@ static void perf_sample_regs_user(struct perf_regs *regs_user, } } -static void perf_sample_regs_intr (struct perf_regs *regs_intr, -struct pt_regs *regs, -bool exclude_kernel) +void perf_sample_regs_intr (struct perf_regs *regs_intr, +struct pt_regs *regs, +bool exclude_kernel) {/* * Hardware skid can lead to a scenario where a PMI is
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 343/1005 perf/amd/ibs: Simplify event state handling with IBS_CAPS_DIS
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ravi Bangoria <[email protected]>
[ Upstream commit 927f9c5cdadbc4ac6973bcd1690107fcb392612c ]
The IBS_{FETCH|OP}_CTL2[Dis] bit allows IBS sampling to be stopped without a RMW of IBS_{FETCH,OP}_CTL. Systems providing this bit therefore do not require the IBS_STARTED and IBS_STOPPED states used to coordinate control MSR updates with late NMIs.
Add a separate stop path for these systems. Preserve the Val bit while disabling the event so that a delayed NMI can be identified and consumed, and wait briefly for such an NMI before restarting the event.
Leave the existing handling unchanged on systems without IBS_CAPS_DIS.
--- arch/x86/events/amd/ibs.c | 145 ++++++++++++++++++++++++++++++++------ 1 file changed, 122 insertions(+), 23 deletions(-)
arch/x86/events/amd/ibs.c +122 -23
@@ -28,6 +28,7 @@ static u32 ibs_caps;#include <linux/hardirq.h> #include <asm/nmi.h> +#include <asm/delay.h> #include <asm/amd/ibs.h> /* attr.config2 */
@@ -73,7 +74,12 @@ static u32 ibs_caps;* * XXX: we could probably be using !atomic bitops for all this. */ - +/* +* NOTE: IBS_CAPS_DIS eliminates the RMW race on the IBS_{FETCH|OP}_CTL, making +* IBS_STARTED and IBS_STOPPED states unnecessary. We use only IBS_ENABLED and +* IBS_STOPPING states when IBS_CAPS_DIS is present. Semantics of IBS_STOPPING +* changes a bit as well. +*/ enum ibs_states {IBS_ENABLED =0 ,IBS_STARTED =1 ,
@@ -557,7 +563,9 @@ static void perf_ibs_start(struct perf_event *event, int flags)struct hw_perf_event *hwc = &event->hw; struct perf_ibs *perf_ibs = container_of(event->pmu, struct perf_ibs, pmu);struct cpu_perf_ibs *pcpu =this_cpu_ptr (perf_ibs->pcpu); +unsigned int delay =50 ;u64 period, config =0 ; +u64 ctl;if (WARN_ON_ONCE (!(hwc->state &PERF_HES_STOPPED )))return ;
@@ -575,23 +583,87 @@ static void perf_ibs_start(struct perf_event *event, int flags) } config |= period >>4 ; -/* -* Reset the IBS_{FETCH|OP}_CTL MSR before updating pcpu->state. -* Doing so prevents a race condition in which an NMI due to other -* source might accidentally activate the event before we enable -* it ourselves. -*/ -perf_ibs_disable_event (perf_ibs, hwc,0 ); +if (ibs_caps &IBS_CAPS_DIS ) { +/* +* IBS HW SW +* +* o Capture sample o ->stop() +* o Set VAL bit CTL2[Dis] = 1 +* o Raise NMI --. o ... +* \ o ->start() +* \ wrmsr(IBS_{FETCH|OP}_CTL, new value); +* \ (wrmsr clears the VAL bit) +* `--> o Receives delayed NMI +* (Unknown NMI since VAL bit is cleared) +* +* Handle this with induced delay. +*/ +rdmsrq (hwc->config_base, ctl); +while ((ctl & perf_ibs->valid_mask) && delay--) { +udelay (1 ); +rdmsrq (hwc->config_base, ctl); + } + }else { +/* +* Reset the IBS_{FETCH|OP}_CTL MSR before updating pcpu->state. +* Doing so prevents a race condition in which an NMI due to +* other source might accidentally activate the event before we +* enable it ourselves. +*/ +perf_ibs_disable_event (perf_ibs, hwc,0 ); +/* +* Set STARTED before enabling the hardware, such that a +* subsequent NMI must observe it. +*/ +set_bit (IBS_STARTED , pcpu->state); +clear_bit (IBS_STOPPING , pcpu->state); + } +perf_ibs_enable_event (perf_ibs, hwc, config); + +perf_event_update_userpage (event); +} + +/* ->stop() for platforms with additional CTL2[Dis] bit. */ +static void perf_ibs_stop_dis (struct perf_event *event,int flags) +{ +struct hw_perf_event *hwc = &event->hw; + struct perf_ibs *perf_ibs = container_of(event->pmu, struct perf_ibs, pmu); +struct cpu_perf_ibs *pcpu =this_cpu_ptr (perf_ibs->pcpu); +u64 config; +u64 ctl2; + +WARN_ON_ONCE (test_bit (IBS_STOPPING , pcpu->state)); + +set_bit (IBS_STOPPING , pcpu->state); + +rdmsrq (hwc->extra_reg.reg, ctl2); +if (ctl2 & perf_ibs->disable_mask) + goto reset_state; + +wrmsrq (hwc->extra_reg.reg, perf_ibs->disable_mask); + +WARN_ON_ONCE (hwc->state &PERF_HES_STOPPED ); + hwc->state |=PERF_HES_STOPPED ; + +if (hwc->state &PERF_HES_UPTODATE ) + goto reset_state; + +rdmsrq (hwc->config_base, config); + + config &= ~perf_ibs->valid_mask;/* -* Set STARTED before enabling the hardware, such that a subsequent NMI -* must observe it. +* Clear the Val bit otherwise ->start() will unnecessarily +* wait for 50us. */ -set_bit (IBS_STARTED , pcpu->state); -clear_bit (IBS_STOPPING , pcpu->state); -perf_ibs_enable_event (perf_ibs, hwc, config); +if (in_nmi ()) +wrmsrq (hwc->config_base, config); -perf_event_update_userpage (event); +perf_ibs_event_update (perf_ibs, event, &config); + hwc->state |=PERF_HES_UPTODATE ; + +reset_state: +clear_bit (IBS_STOPPING , pcpu->state); }static void perf_ibs_stop (struct perf_event *event,int flags)
@@ -602,6 +674,9 @@ static void perf_ibs_stop(struct perf_event *event, int flags)u64 config;int stopping; +if (ibs_caps &IBS_CAPS_DIS ) +return perf_ibs_stop_dis (event, flags); +if (test_and_set_bit (IBS_STOPPING , pcpu->state))return ;
@@ -1416,19 +1491,43 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)unsigned int msr;u64 *buf, *config, period, new_config =0 ;int br_target_idx =-1 ; +u64 ctl2, ctl; -if (!test_bit (IBS_STARTED , pcpu->state)) { -fail: +if (ibs_caps &IBS_CAPS_DIS ) {/* -* Catch spurious interrupts after stopping IBS: After -* disabling IBS there could be still incoming NMIs -* with samples that even have the valid bit cleared. -* Mark all this NMIs as handled. +* ->stop() { +* set_bit(IBS_STOPPING); +* <-- NMI (race 1) +* CTL2[Dis]=1; +* ... <-- NMI (race 2) +* } */ -if (test_and_clear_bit (IBS_STOPPED , pcpu->state)) -return 1 ; +rdmsrq (perf_ibs->msr2, ctl2); +if (test_bit (IBS_STOPPING , pcpu->state)/* race 1 */ || + (ctl2 & perf_ibs->disable_mask)/* race 2 */ ) { +rdmsrq (perf_ibs->msr, ctl); +if (ctl & perf_ibs->valid_mask) { + ctl &= ~(perf_ibs->enable_mask | + perf_ibs->valid_mask); +wrmsrq (perf_ibs->msr, ctl); +return 1 ; + } +return 0 ; + } + }else { +if (!test_bit (IBS_STARTED , pcpu->state)) { +fail: +/* +* Catch spurious interrupts after stopping IBS: After +* disabling IBS there could be still incoming NMIs +* with samples that even have the valid bit cleared. +* Mark all this NMIs as handled. +*/ +if (test_and_clear_bit (IBS_STOPPED , pcpu->state)) +return 1 ; -return 0 ; +return 0 ; + } }if (WARN_ON_ONCE (!event))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 344/1005 sched/deadline: Fix this_bw on class change of a dying task
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nickolai Zeldovich <[email protected]>
[ Upstream commit 0c93e25ef11a9dee43f6076bd1f09771dc2b167e ]
Moving a SCHED_DEADLINE task out of the class with sched_setscheduler(2) after it stored TASK_DEAD in do_task_dead(), but before __schedule() dequeued it, subtracts its bandwidth from the runqueue's this_bw twice. this_bw then stays short until reboot: __sub_rq_bw() warns about the underflow or about running_bw > this_bw, and GRUB reclaim for SCHED_FLAG_RECLAIM tasks on that CPU is miscomputed.
The class change dequeues the still queued task with DEQUEUE_SAVE, which removes its bandwidth from running_bw and this_bw. switched_from_dl() then calls task_non_contending(), which, if the 0-lag time has passed, removes it from this_bw again because the task is TASK_DEAD. That removal is meant for the dying task's own DEQUEUE_SLEEP dequeue, which has removed nothing before it.
Do the TASK_DEAD removal only on that dequeue path.
Reproduced under QEMU on x86_64 and riscv64 by moving exiting deadline tasks to SCHED_OTHER in a loop; with this patch there is no warning.
--- kernel/sched/deadline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/deadline.c +1 -1
@@ -444,7 +444,7 @@ static void task_non_contending(struct sched_dl_entity *dl_se, bool dl_task)if (!dl_task ||READ_ONCE (p->__state) ==TASK_DEAD ) {struct dl_bw *dl_b =dl_bw_of (task_cpu (p)); -if (READ_ONCE (p->__state) ==TASK_DEAD ) +if (dl_task &&READ_ONCE (p->__state) ==TASK_DEAD )sub_rq_bw (dl_se, &rq->dl);raw_spin_lock (&dl_b->lock);__dl_sub (dl_b, dl_se->dl_bw,dl_bw_cpus (task_cpu (p)));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 345/1005 sched/core: Account I/O waits independently of delayed dequeue
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Loehle <[email protected]>
[ Upstream commit 0965587d00b84f0a3b0fc94930d4a5f8ff011eda ]
Starting blkio delay accounting and incrementing rq->nr_iowait in __block_task() ties both to removal from the runqueue. With EEVDF delayed dequeue, this misses the initial part of an I/O sleep, or the entire sleep if the task wakes before it is dequeued. Such tasks are also missing from procs_blocked while their dequeue is delayed. Final dequeue can run in another task's context, causing delayacct_blkio_start() to timestamp the wrong task.
Start both forms of accounting in try_to_block_task(), when the current task commits to blocking, before delayed dequeue or proxy execution can retain it on the runqueue. End both when clearing is_blocked, including queued wakeups and the proxy execution paths that let the current task continue. Checking is_blocked excludes wakeups that precede blocking.
Save the CPU charged at the start of the wait. Delayed tasks can migrate while still queued, and proxy execution can also move blocked tasks. Decrement the saved CPU's counter on unblock, regardless of the task's current placement, and remove the old dequeue-based accounting.
CPU iowait continues to classify idle time using the counter on the charged CPU; it does not accumulate the full per-task blocked duration.
--- include/linux/sched.h | 2 ++ kernel/sched/core.c | 33 ++++++++++++++++++++------------- kernel/sched/sched.h | 5 ----- 3 files changed, 22 insertions(+), 18 deletions(-)
include/linux/sched.h +2 -0
@@ -880,6 +880,8 @@ struct task_struct {*/ int recent_used_cpu;int wake_cpu; +/* CPU charged while is_blocked && in_iowait. */ +int iowait_cpu;int prio;int static_prio;
kernel/sched/core.c +20 -13
@@ -636,7 +636,7 @@ int task_llc(const struct task_struct *p)* * p->is_blocked <- { 0, 1 }: * -* is set by try_to_block_task() and cleared by ttwu_do_wakeup() and tracks +* is set by try_to_block_task() and cleared by unblock_task() and tracks * if the task is blocked. Traditionally this would mirror p->on_rq, however * due things like DELAY_DEQUEUE and PROXY_EXEC, this can diverge. *
@@ -3740,12 +3740,22 @@ ttwu_stat(struct task_struct *p, int cpu, int wake_flags)__schedstat_inc (p->stats.nr_wakeups_sync); } +static inline void unblock_task (struct task_struct *p) +{ +if (p->is_blocked && p->in_iowait) { +delayacct_blkio_end (p); +atomic_dec (&cpu_rq (p->iowait_cpu)->nr_iowait); + } + + p->is_blocked =0 ; +} +/* * Mark the task runnable. */ static inline void ttwu_do_wakeup (struct task_struct *p) { - p->is_blocked =0 ; +unblock_task (p);WRITE_ONCE (p->__state,TASK_RUNNING );trace_sched_wakeup (p); }
@@ -3843,10 +3853,6 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, en_flags |=ENQUEUE_RQ_SELECTED ;if (wake_flags &WF_MIGRATED ) en_flags |=ENQUEUE_MIGRATED ; -else if (p->in_iowait) { -delayacct_blkio_end (p); -atomic_dec (&task_rq (p)->nr_iowait); - }activate_task (rq, p, en_flags);wakeup_preempt (rq, p, wake_flags);
@@ -4419,11 +4425,6 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) cpu =select_task_rq (p, p->wake_cpu, &wake_flags);if (task_cpu (p) != cpu) { -if (p->in_iowait) { -delayacct_blkio_end (p); -atomic_dec (&task_rq (p)->nr_iowait); - } - wake_flags |=WF_MIGRATED ;psi_ttwu_dequeue (p);set_task_cpu (p, cpu);
@@ -6766,6 +6767,12 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p, p->is_blocked =1 ; +if (p->in_iowait) { + p->iowait_cpu =cpu_of (rq); +atomic_inc (&rq->nr_iowait); +delayacct_blkio_start (); + } +/* * We check should_block after signal_pending because we * will want to wake the task in that case. But if
@@ -6938,7 +6945,7 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)if (!mutex) {clear_task_blocked_on (p, mutex);if (task_current (rq, p)) { - p->is_blocked =0 ; +unblock_task (p);return p; } goto deactivate;
@@ -6974,7 +6981,7 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf)*/ __clear_task_blocked_on (p,NULL );if (task_current (rq, p)) { - p->is_blocked =0 ; +unblock_task (p);return p; } goto deactivate;
kernel/sched/sched.h +0 -5
@@ -3082,11 +3082,6 @@ static inline void __block_task(struct rq *rq, struct task_struct *p)if (p->sched_contributes_to_load) rq->nr_uninterruptible++; -if (p->in_iowait) { -atomic_inc (&rq->nr_iowait); -delayacct_blkio_start (); - } -ASSERT_EXCLUSIVE_WRITER (p->on_rq);/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 346/1005 sched/pelt: Fix u32 truncation of the PELT period count
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Su <[email protected]>
[ Upstream commit a0c755e574e37fddb59edf175f27dc3877e7fe23 ]
accumulate_sum() computes the number of elapsed PELT periods in a u64 but returns u32. When the count is a multiple of 2^32, it is truncated to zero even though the PELT sums have been updated.
The caller interprets zero as no period boundary crossed and skips recomputing the averages, leaving *_avg stale relative to *_sum.
Return the period count as u64 so the caller can test it without truncation.
--- kernel/sched/pelt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/pelt.c +1 -1
@@ -99,7 +99,7 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)* d1 y^p + 1024 \Sum y^n + d3 y^0 (Step 2) * n=1 */ -static __always_inline u32 +static __always_inline u64accumulate_sum (u64 delta,struct sched_avg *sa,unsigned long load,unsigned long runnable,int running) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 347/1005 sched/topology: Balance cluster static-key updates
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Su <[email protected]>
[ Upstream commit 5ebdfe12ab96368d0339593129d4ce0bc2bd06f5 ]
build_sched_domains() increments sched_cluster_active once per newly built partition that contains an SD_CLUSTER domain. detach_destroy_domains() instead tested the global static key before decrementing it, so destroying a cluster-less partition could drop a reference owned by another partition and disable cluster-aware scheduling while SD_CLUSTER domains remained installed.
Check the installed domains before detaching them, only while the key is enabled, and decrement only when the removed partition contains an SD_CLUSTER domain.
With two cluster-bearing partitions installed, removing a singleton partition left the baseline count at 1 where 2 partitions still carried SD_CLUSTER; the fixed kernel correctly reports 2. On an asymmetric cluster topology where the parent partition gains no cluster domain, the baseline count drops to 0 while a cluster partition remains installed; the fixed kernel keeps it at 1.
--- kernel/sched/topology.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
kernel/sched/topology.c +14 -2
@@ -3314,13 +3314,25 @@ int __init sched_init_domains(const struct cpumask *cpu_map)static void detach_destroy_domains (const struct cpumask *cpu_map) {unsigned int cpu =cpumask_any (cpu_map); +bool has_cluster = false;int i;if (rcu_access_pointer (per_cpu (sd_asym_cpucapacity, cpu)))static_branch_dec_cpuslocked (&sched_asym_cpucapacity); -if (static_branch_unlikely (&sched_cluster_active)) -static_branch_dec_cpuslocked (&sched_cluster_active); +if (static_branch_unlikely (&sched_cluster_active)) { +rcu_read_lock (); +for_each_cpu (i, cpu_map) { +if (lowest_flag_domain (i,SD_CLUSTER )) { + has_cluster = true; +break ; + } + } +rcu_read_unlock (); + +if (has_cluster) +static_branch_dec_cpuslocked (&sched_cluster_active); + }rcu_read_lock ();for_each_cpu (i, cpu_map)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 348/1005 sched/cache: Ignore non-fair current in alb_break_llc()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kayra Cizmeci <[email protected]>
[ Upstream commit 006991aa89974378ee579416dba87adc22cd60fd ]
Commit d6b9afab44e23 ("sched/cache: Fix
checking active load balance by only considering the CFS task") stopped using task_util() for non-fair cur.
__active_load_balance_cpu_stop() calls detach_one_task(), that only looks to cfs_tasks list. So if the rq->curr is not fair, doing a decision according to it is wrong, since we only migrate tasks that is fair.
Commit f0d243a96f26 ("sched/fair: Avoid creating misfits during cache-aware balancing") passes cur to task_misfits_asym_cpu() without checking if the cur is in fair class or not. Fix this.
--- kernel/sched/fair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/sched/fair.c +8 -1
@@ -11035,7 +11035,14 @@ alb_break_llc(struct lb_env *env)return true; cur =rcu_dereference_all (env->src_rq->curr); -if (cur && cur->sched_class == &fair_sched_class) +/* +* Active balance only detaches CFS tasks, so a non-fair +* curr is never migrated. Ignore it and avoid using its +* state util in the misfit and LLC checks. +*/ +if (cur && cur->sched_class != &fair_sched_class) + cur =NULL ; +if (cur) util =task_util (cur); if (task_misfits_asym_cpu(env, cur) ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 349/1005 tcp: bound snd_cwnd_clamp to TCP_MAX_SND_CWND
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 475ff14ba558bb8857bca878f1d593784ccc4f0f ]
snd_cwnd has no practical upper bound: snd_cwnd_clamp defaults to ~0, and RTAX_INITCWND, a locked RTAX_CWND metric, TCP_BPF_IW and TCP_BPF_SNDCWND_CLAMP accept any positive value.
Congestion control modules do u32 arithmetic on cwnd that assumes much smaller values. For instance, ssthresh() handlers compute:
CUBIC, BIC, ROCCET: cwnd * (BICTCP_BETA_SCALE + beta), up to 2047
DCTCP: cwnd * dctcp_alpha, up to 1024
CDG, NV, CUBIC, ...: cwnd * beta, below 1024
With a large initcwnd route or TCP_BPF_IW, cwnd is set directly to such values, and the next RTO or recovery calls ->ssthresh() with it. The product then wraps: DCTCP with cwnd = 2^24 and alpha = 1024 gets ssthresh == cwnd, and CUBIC computes a wrong ssthresh and Wmax. CUBIC bictcp_update() also expects cwnd below about one million packets.
The paths that can grow cwnd by large amounts (tcp_slow_start(), tcp_cong_avoid_ai(), bbr_set_cwnd() and tcp_init_cwnd()) already bound it by snd_cwnd_clamp, so give snd_cwnd_clamp a finite default of 2^20 packets, and cap the metric and BPF paths that set it or set cwnd directly.
2^20 packets do not limit real flows: with the maximum window scale of 14, a peer can not advertise more than 65535 << 14 bytes (~1GB), which is less than 2^20 packets for any MSS of 1024 bytes or more.
--- include/net/tcp.h | 9 +++++++++ net/core/filter.c | 3 ++- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_metrics.c | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-)
include/net/tcp.h +9 -0
@@ -1514,6 +1514,15 @@ static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp)#define TCP_INFINITE_SSTHRESH 0x7fffffff +/* Default and maximum snd_cwnd_clamp, in packets. +* A peer can not advertise more than 65535 << 14 bytes, so a larger +* cwnd is useless with any MSS of 1024 bytes or more. +* Congestion control modules multiply cwnd by u32 factors up to 2047 +* (cwnd * (BICTCP_BETA_SCALE + beta) in CUBIC), and CUBIC's +* bictcp_update() expects cwnd to stay below about one million packets. +*/ +#define TCP_MAX_SND_CWND (1U << 20) +static inline u32 tcp_snd_cwnd (const struct tcp_sock *tp) {return tp->snd_cwnd;
net/core/filter.c +2 -1
@@ -5652,11 +5652,12 @@ static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname,case TCP_BPF_IW :if (val <=0 || tp->data_segs_out > tp->syn_data)return -EINVAL ; -tcp_snd_cwnd_set (tp, val); +tcp_snd_cwnd_set (tp,min_t (u32, val, tp->snd_cwnd_clamp));break ;case TCP_BPF_SNDCWND_CLAMP :if (val <=0 )return -EINVAL ; + val =min_t (u32, val,TCP_MAX_SND_CWND ); tp->snd_cwnd_clamp = val;WRITE_ONCE (tp->snd_ssthresh, val);break ;
net/ipv4/tcp.c +1 -1
@@ -455,7 +455,7 @@ void tcp_init_sock(struct sock *sk)* initialization of these values. */ tp->snd_ssthresh =TCP_INFINITE_SSTHRESH ; - tp->snd_cwnd_clamp = ~0 ; + tp->snd_cwnd_clamp =TCP_MAX_SND_CWND ; tp->mss_cache =TCP_MSS_DEFAULT ; tp->reordering =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_reordering);
net/ipv4/tcp_metrics.c +2 -1
@@ -495,7 +495,8 @@ void tcp_init_metrics(struct sock *sk) }if (tcp_metric_locked (tm,TCP_METRIC_CWND )) - tp->snd_cwnd_clamp =tcp_metric_get (tm,TCP_METRIC_CWND ); + tp->snd_cwnd_clamp =min (tcp_metric_get (tm,TCP_METRIC_CWND ), +TCP_MAX_SND_CWND ); val =READ_ONCE (net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) ?0 :tcp_metric_get (tm,TCP_METRIC_SSTHRESH );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 350/1005 gpio: mpfs: reject unsupported interrupt types
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Isaac Adjei <[email protected]>
[ Upstream commit cfbd01eddaf5bfdd4f53560013fe830571a186e9 ]
The switch statement in mpfs_gpio_irq_set_type() does not handle unsupported interrupt types. For example, IRQ_TYPE_NONE is not listed.
When an unsupported type is passed, interrupt_type remains uninitialised. Its undefined value is then written to the GPIO control register. The function still returns 0, making the caller believe the operation succeeded.
Add a default case to return -EINVAL for unsupported interrupt types.
Smatch reported the following warning:
drivers/gpio/gpio-mpfs.c:144 mpfs_gpio_irq_set_type() error: uninitialized symbol 'interrupt_type'.
I built the driver with W=1 and got no warnings. I also reran Smatch and confirmed that the warning was resolved.
This is compile-tested only. I do not have access to PolarFire SoC hardware for runtime testing.
--- drivers/gpio/gpio-mpfs.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpio-mpfs.c +2 -0
@@ -138,6 +138,8 @@ static int mpfs_gpio_irq_set_type(struct irq_data *data, unsigned int type)case IRQ_TYPE_LEVEL_LOW : interrupt_type =MPFS_GPIO_TYPE_INT_LEVEL_LOW ;break ; +default : +return -EINVAL ; } regmap_update_bits(mpfs_gpio->regs, MPFS_GPIO_CTRL(gpio_index),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 351/1005 x86/kcfi: Dont emit KCFI_REFERENCE() in modules
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ridge Lomont <[email protected]>
[ Upstream commit fb685de78e6bf79e49854e7d149f69b125583de5 ]
KCFI_REFERENCE() takes the address of a symbol so that the compiler emits its __kcfi_typeid_ symbol, which the SYM_TYPED_FUNC_START() assembly implementing it needs. It is used from arch/x86 headers for __clear_pages_unrolled(), copy_page(), __memset() and __memmove(), and all of that assembly is built into vmlinux.
Modules include the same headers, so with CONFIG_CFI=y every module also gets an __ADDRESSABLE() reference to each of these symbols in .discard.addressable. This serves no purpose there, and since __clear_pages_unrolled() is EXPORT_SYMBOL_GPL, modpost now rejects any GPL-incompatible module that includes <linux/mm.h>:
ERROR: modpost: GPL-incompatible module repro.ko uses GPL-only symbol '__clear_pages_unrolled'
even though the module never uses the symbol. This makes OpenZFS impossible to build against CFI kernels; its configure checks fail in the same way and are misreported as CONFIG_DEBUG_LOCK_ALLOC.
scripts/module.lds.S does not help here: modpost checks <module>.o before the final link, and even after it the discarded section only loses its relocations, the undefined symbols stay in .symtab, where the module loader resolves them with the same license check.
Only emit the reference when building vmlinux.
Tested on x86_64 with clang 23.1.3 and CONFIG_CFI=y, with both CONFIG_LTO_CLANG_FULL=y (the configuration from the Fixes: commit) and CONFIG_LTO_CLANG_THIN=y: vmlinux links without warnings and still contains __kcfi_typeid___clear_pages_unrolled, __kcfi_typeid_copy_page, __kcfi_typeid___memset and __kcfi_typeid___memmove. It boots in QEMU with no CFI failures. A minimal module with MODULE_LICENSE("Proprietary") including <linux/mm.h> fails modpost before this change and builds and loads after it. OpenZFS builds against a CFI kernel with this change, and its pool, encryption, checksum and send/recv operations run without CFI failures, in QEMU and on a desktop with CFI enforcing.
--- include/linux/compiler.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/linux/compiler.h +5 -2
@@ -241,10 +241,13 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,#endif /* __KERNEL__ */ -#if defined(CONFIG_CFI ) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO ) +#if defined(CONFIG_CFI ) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO ) && \ + !defined(MODULE )/* * Force a reference to the external symbol so the compiler generates -* __kcfi_typid. +* __kcfi_typid. Only vmlinux needs it, as that is where the assembly +* using the typeid lives; in a module it would only add a reference to +* the symbol, which fails modpost if the symbol is GPL-only. */ #define KCFI_REFERENCE (sym) __ADDRESSABLE(sym)#else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 352/1005 net/mlx5e: TC, Fix double free of branch in failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Fourier <[email protected]>
[ Upstream commit 31f9b43a3bb3d2201eadd147440252d0912dab21 ]
When allocating the false branch fails in parse_branch_ctrl(), the already allocated true branch is freed but attr->branch_true is left pointing to it. The caller parse_tc_actions() fails the flow, and free_flow_post_acts(), mlx5_free_flow_attr_actions() which calls again free_branch_attr() on attr->branch_true.
Clear the pointer after freeing it.
This bug is theoretical and was compile tested only.
--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +1 -0
@@ -4005,6 +4005,7 @@ parse_branch_ctrl(struct flow_action_entry *act, struct mlx5e_tc_act *tc_act, err_branch_false:free_branch_attr (flow, attr->branch_true); + attr->branch_true =NULL ; out_err:return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 353/1005 locking/lockdep: Fix inverted "on"/"last" CPU label in lockdep_print_held_locks()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhuangzhuang Wang <[email protected]>
[ Upstream commit aa63c0df79920f6abe1b66e1f8b6443ad2d62d0e ]
Commit 051f5d223dfc ("lockdep: Enable the printing of held locks of remote running tasks and print task CPU") added the task's CPU to the "locks held by" line. As the comment above the printk() describes, a running task should be reported as "on CPU#N" and a task that is not running as "last CPU#N". The ternary has the two strings swapped, so the labels are inverted.
Swap the strings so the output matches the comment.
--- kernel/locking/lockdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/lockdep.c +1 -1
@@ -811,7 +811,7 @@ static void lockdep_print_held_locks(struct task_struct *p)*/ printk ("locks held by %s/%d: %d, %s CPU#%d%s\n" , p->comm,task_pid_nr (p), depth, -task_is_running (p) ?"last" :"on" ,task_cpu (p), +task_is_running (p) ?"on" :"last" ,task_cpu (p), depth >0 ?":" :"" );for (i =0 ; i < depth; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 354/1005 locking/osq: Switch osq_wait_next()/atomic_cmpxchg() ordering
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
[ Upstream commit 1b9e01fcc47aff00d2fd64693c5dcd620eff5865 ]
The atomic_cmpxchg() in osq_wait_next() removes the current CPU's node from the tail of the queue and puts @old_cpu back.
This is very much like an 'unlock', which is RELEASE, rather than ACQUIRE.
Additionally, on success (the only case where the ordering is effective), this returns NULL which means both callsites will do nothing more, there are no subsequent operations to order against.
Furthermore, the osq_lock() caller will then return false, indicating failure to acquire -- the mutex must go block. Again, not making a case for ACQUIRE. Neither atomics nor locks provide ordering on failure.
Since ACQUIRE makes no sense, while RELEASE makes it more symmetric with osq_unlock(), switch the ordering. This then makes osq_unlock() consistently RELEASE.
--- kernel/locking/osq_lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/osq_lock.c +1 -1
@@ -59,7 +59,7 @@ osq_wait_next(struct optimistic_spin_queue *lock,for (;;) {if (atomic_read (&lock->tail) == curr && -atomic_cmpxchg_acquire (&lock->tail, curr, old_cpu) == curr) { +atomic_cmpxchg_release (&lock->tail, curr, old_cpu) == curr) {/* * We were the last queued, we moved @lock back. @prev * will now observe @lock and will complete its
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 355/1005 locking/osq: Fix unlink queue corruption
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
[ Upstream commit 408b129aac48b574c0c9d11137a89eefba825d5d ]
Very similar to commit 50972fe78f24 ("locking/osq_lock: Fix osq_lock queue corruption"), make sure to order the prev->next store against the next->prev store.
--- kernel/locking/osq_lock.c | 60 +++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-)
kernel/locking/osq_lock.c +45 -15
@@ -90,6 +90,49 @@ osq_wait_next(struct optimistic_spin_queue *lock, } } +/* +* Set prev->next; this is the counterpart of osq_wait_next() in that +* by setting ->next the wait is terminated and progress is resumed. +*/ +static inline void osq_link_next (struct optimistic_spin_node *prev, +struct optimistic_spin_node *next) +{ +/* +* Suppose: +* +* tail +* | +* V +* CPU1 -> CPU2 -> CPU3: +* n: 2 n: 3 n: nil +* p: nil p: 1 p: 2 +* +* And this is CPU2 doing the self-unqueue concurrent against CPU1s +* unlock()/unqueue(). Since 'prev->next == NULL' and CPU1 will be +* stuck in osq_wait_next() until the below store of 'prev->next'. +* +* CPU2 CPU1 +* +* next->prev = prev; osq_wait_next() +* WMB MB +* prev->next = next; next->prev = prev +* +* Without the WMB it would be possible to have conflicting stores +* like: +* +* CPU2 CPU1 +* +* prev->next = next // CPU1.n = 3 +* next = osq_wait_next() // = 3 +* next->prev = prev // CPU3.p = nil +* next->prev = prev // CPU3.p = 1 +* +* Which would result in list corruption. +*/ +smp_wmb (); +WRITE_ONCE (prev->next, next); +} +bool osq_lock (struct optimistic_spin_queue *lock) {struct optimistic_spin_node *node =this_cpu_ptr (&osq_node);
@@ -113,20 +156,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) prev =decode_cpu (old); node->prev = prev; - -/* -* osq_lock() unqueue -* -* node->prev = prev osq_wait_next() -* WMB MB -* prev->next = node next->prev = prev // unqueue-C -* -* Here 'node->prev' and 'next->prev' are the same variable and we need -* to ensure these stores happen in-order to avoid corrupting the list. -*/ -smp_wmb (); - -WRITE_ONCE (prev->next, node); +osq_link_next (prev, node);/* * Normally @prev is untouchable after the above store; because at that
@@ -202,7 +232,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)*/ WRITE_ONCE (next->prev, prev); -WRITE_ONCE (prev->next, next); +osq_link_next (prev, next);return false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 356/1005 perf/x86/amd/uncore: Avoid context migration from non-owners
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sandipan Das <[email protected]>
[ Upstream commit 0ae655bce1934857fa3e316ddcb4be38c30dbd38 ]
Each uncore context is owned by a single CPU that hosts all events for the corresponding uncore domain and is advertised through the sysfs cpumask attribute. When a CPU goes offline, the context is migrated to an online sibling if the departing CPU is the owner.
Before commit d6389d3ccc13 ("perf/x86/amd/uncore: Refactor uncore management"), uncore_down_prepare() checked whether the CPU going offline owned the context. The check was lost when the function was replaced by amd_uncore_ctx_move(). Hence, when a CPU that is not the owner goes offline, ownership is always handed over to the first online sibling in the uncore domain irrespective of whether another sibling already owns it. This goes unnoticed as long as the owner is the lowest-numbered online CPU in the domain, since the first online sibling is then the owner itself. Once ownership has moved, that no longer holds.
For example, consider an L3 domain spanning CPUs 8-15,136-143 and owned by CPU 8.
$ cat /sys/bus/event_source/devices/amd_l3/cpumask 0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120
$ echo 0 | sudo tee /sys/devices/system/cpu/cpu8/online $ cat /sys/bus/event_source/devices/amd_l3/cpumask 0,9,16,24,32,40,48,56,64,72,80,88,96,104,112,120
$ echo 1 | sudo tee /sys/devices/system/cpu/cpu8/online $ cat /sys/bus/event_source/devices/amd_l3/cpumask 0,9,16,24,32,40,48,56,64,72,80,88,96,104,112,120
$ echo 0 | sudo tee /sys/devices/system/cpu/cpu10/online $ cat /sys/bus/event_source/devices/amd_l3/cpumask 0,8-9,16,24,32,40,48,56,64,72,80,88,96,104,112,120
Offlining CPU 8 correctly moves ownership to CPU 9 and onlining it again leaves CPU 9 as the owner. However, offlining CPU 10 then makes CPU 8 the owner while existing events remain on CPU 9. Both CPUs are now advertised for the same domain, so tools that open an event on every CPU in the cpumask count the domain twice, and the context gets modified from two CPUs without any synchronization.
Restore the ownership check that was lost during the refactor.
--- arch/x86/events/amd/uncore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/amd/uncore.c +1 -1
@@ -610,7 +610,7 @@ static void amd_uncore_ctx_move(struct amd_uncore *uncore, unsigned int cpu)for (i =0 ; i < uncore->num_pmus; i++) { pmu = &uncore->pmus[i]; curr = *per_cpu_ptr (pmu->ctx, cpu); -if (!curr) +if (!curr || curr->cpu != cpu)continue ;/* Migrate to a shared sibling if possible */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 357/1005 perf: Fix racy update of cpc->hrtimer_interval
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Segall <[email protected]>
[ Upstream commit 3bbd85b2f67aff58f2cbec9a7fb705677b94473b ]
Updates to cpc->hrtimer_interval can race with reads either in the hrtimer itself, or other calls to perf_mux_hrtimer_restart. This is not exactly expected to be a common config change, but it's easy enough to fix.
Since there's already an IPI to each cpu to restart the timer, and all reads are with irqs disabled, just move the update onto the target cpu.
--- kernel/events/core.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
kernel/events/core.c +11 -11
@@ -1332,14 +1332,19 @@ static int perf_mux_hrtimer_restart(struct perf_cpu_pmu_context *cpc)return 0 ; } -static int perf_mux_hrtimer_restart_ipi (void *arg) +static __always_inline struct perf_cpu_pmu_context *this_cpc(struct pmu *pmu) { -return perf_mux_hrtimer_restart (arg); +return *this_cpu_ptr (pmu->cpu_pmu_context); } -static __always_inline struct perf_cpu_pmu_context *this_cpc(struct pmu *pmu) +static int perf_mux_hrtimer_interval_ipi (void *arg) { -return *this_cpu_ptr (pmu->cpu_pmu_context); +struct pmu *pmu = arg; +struct perf_cpu_pmu_context *cpc =this_cpc (pmu); +int ms = pmu->hrtimer_interval_ms; + + cpc->hrtimer_interval =ns_to_ktime (NSEC_PER_MSEC * ms); +return perf_mux_hrtimer_restart (cpc); }void perf_pmu_disable (struct pmu *pmu)
@@ -12770,13 +12775,8 @@ perf_event_mux_interval_ms_store(struct device *dev,/* update all cpuctx for this PMU */ cpus_read_lock (); -for_each_online_cpu (cpu) { -struct perf_cpu_pmu_context *cpc; - cpc = *per_cpu_ptr (pmu->cpu_pmu_context, cpu); - cpc->hrtimer_interval =ns_to_ktime (NSEC_PER_MSEC * timer); - -cpu_function_call (cpu, perf_mux_hrtimer_restart_ipi, cpc); - } +for_each_online_cpu (cpu) +cpu_function_call (cpu, perf_mux_hrtimer_interval_ipi, pmu);cpus_read_unlock ();mutex_unlock (&mux_interval_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 358/1005 iommu/amd: Clear amd_iommu_snp_en if snp_rmptable_init() fails
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dheeraj Kumar Srivastava <[email protected]>
[ Upstream commit ec91bb159dc24eefe144ef8867937f4a055dd0e2 ]
iommu_snp_enable() checks that the IOMMU can support SNP and sets amd_iommu_snp_en, then calls snp_rmptable_init() to map the RMP table. If that call fails, CC_ATTR_HOST_SEV_SNP is cleared but amd_iommu_snp_en is left set. Later IOMMU initialization uses amd_iommu_snp_en to configure the IOMMU for SNP, on the assumption that RMP setup succeeded.
Clear amd_iommu_snp_en along with CC_ATTR_HOST_SEV_SNP.
--- drivers/iommu/amd/init.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/amd/init.c +1 -0
@@ -3493,6 +3493,7 @@ static __init void iommu_snp_enable(void)return ; disable_snp: + amd_iommu_snp_en = false;cc_platform_clear (CC_ATTR_HOST_SEV_SNP );#endif }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 359/1005 cpufreq: Preserve global boost state on failed updates
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Loehle <[email protected]>
[ Upstream commit a0cde2b601bc32b76d61e50141c619790e5e2e41 ]
cpufreq_boost_trigger_state() restores the opposite of the requested state when updating policy boost state fails. For example, a failed write of 0 when global boost is already disabled enables the global flag without enabling any policies.
Save the original global boost state and restore it on failure.
--- drivers/cpufreq/cpufreq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +3 -1
@@ -2818,6 +2818,7 @@ static int cpufreq_boost_trigger_state(int state) {struct cpufreq_policy *policy;unsigned long flags; +bool boost_enabled;int ret = -EOPNOTSUPP ;/*
@@ -2826,6 +2827,7 @@ static int cpufreq_boost_trigger_state(int state)*/ write_lock_irqsave (&cpufreq_driver_lock, flags); + boost_enabled = cpufreq_driver->boost_enabled; cpufreq_driver->boost_enabled = state;write_unlock_irqrestore (&cpufreq_driver_lock, flags);
@@ -2847,7 +2849,7 @@ static int cpufreq_boost_trigger_state(int state)return 0 ;write_lock_irqsave (&cpufreq_driver_lock, flags); - cpufreq_driver->boost_enabled = !state; + cpufreq_driver->boost_enabled = boost_enabled;write_unlock_irqrestore (&cpufreq_driver_lock, flags); pr_err("%s: Cannot %s BOOST\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 360/1005 cpufreq: Serialize global boost updates
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Loehle <[email protected]>
[ Upstream commit 3d5720dff09f3b90d9ab2a6707e4bb8d69542f4a ]
Concurrent global boost sysfs writes can interleave their global flag and per-policy updates. An enabling write can set the global flag, then a disabling write can clear it and finish before the enabling write updates the policies. Both writes succeed, leaving boost enabled on the policies while the global flag is disabled.
Serialize the complete global boost update, including rollback on failure, with a mutex.
--- drivers/cpufreq/cpufreq.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/cpufreq/cpufreq.c +4 -0
@@ -2814,6 +2814,8 @@ int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state) }EXPORT_SYMBOL_GPL (cpufreq_boost_set_sw); +static DEFINE_MUTEX (cpufreq_boost_mutex); +static int cpufreq_boost_trigger_state (int state) {struct cpufreq_policy *policy;
@@ -2821,6 +2823,8 @@ static int cpufreq_boost_trigger_state(int state)bool boost_enabled;int ret = -EOPNOTSUPP ; +guard (mutex)(&cpufreq_boost_mutex); +/* * Don't compare 'cpufreq_driver->boost_enabled' with 'state' here to * make sure all policies are in sync with global boost flag.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 361/1005 sched_ext: Reset task fields on exit of an SCX_TASK_READY task
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rahad Bhuiya <[email protected]>
[ Upstream commit 564405c424f49d70b13debe7fe5b550234ad6b84 ]
Tasks in SCX_TASK_READY are attached to a scheduler but outside the ext class, such as RT/DL tasks, or non-SCHED_EXT tasks under a partial switch. The scheduler's BPF code can still update their dsq_vtime and slice (for instance, via ops.cgroup_move() as done by scx_flatcg).
Because __scx_disable_and_exit_task() currently breaks out of the state switch for SCX_TASK_READY without calling scx_reset_task_fields(), these fields are not cleared when the task leaves the scheduler. If the task is subsequently moved to another cgroup/sub-scheduler and later switches to SCHED_NORMAL, the new scheduler's ops.enable() sees stale dsq_vtime from the previous scheduler's clock.
Call scx_reset_task_fields() in the SCX_TASK_READY case of __scx_disable_and_exit_task() to ensure SCX-managed fields are properly reset when leaving the scheduler.
--- kernel/sched/ext/ext.c | 1 + 1 file changed, 1 insertion(+)
kernel/sched/ext/ext.c +1 -0
@@ -4198,6 +4198,7 @@ void __scx_disable_and_exit_task(struct scx_sched *sch, struct task_struct *p) args.cancelled = true;break ;case SCX_TASK_READY : +scx_reset_task_fields (task_rq (p), p);break ;case SCX_TASK_ENABLED :scx_disable_task (sch, p);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 362/1005 Bluetooth: reject invalid LE supervision timeout relationships
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Pepper <[email protected]>
[ Upstream commit c1d50a71cdee90a0c68b7a67221d8aae96d14a0c ]
The LE parameter validator calculates an unsigned maximum latency by subtracting one from a truncated quotient. If the quotient is zero, this wraps and accepts invalid parameters. Exact quotient boundaries also accept equality where the supervision timeout must be greater.
Compare the products directly after checking the field bounds. The validated interval and latency limits keep the products within int. This enforces the strict timeout relationship without division or unsigned subtraction.
Sashiko identified the underflow while reviewing the soft interval preference RFC. The bug is already present in its unpatched base; keep this common-validator fix independent of that preference policy.
--- include/net/bluetooth/hci_core.h | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
include/net/bluetooth/hci_core.h +3 -10
@@ -2320,8 +2320,6 @@ static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,static inline int hci_check_conn_params (u16 min,u16 max,u16 latency,u16 to_multiplier) { -u16 max_latency; -if (min > max) {BT_WARN ("min %d > max %d" , min, max);return -EINVAL ;
@@ -2347,19 +2345,14 @@ static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,return -EINVAL ; } -if (max >= to_multiplier *8 ) { -BT_WARN ("max %d >= to_multiplier %d * 8" , max, to_multiplier); -return -EINVAL ; - } - - max_latency = (to_multiplier *4 / max) -1 ;if (latency >499 ) {BT_WARN ("latency %d > 499" , latency);return -EINVAL ; } -if (latency > max_latency) { -BT_WARN ("latency %d > max_latency %d" , latency, max_latency); +if ((latency +1 ) * max >= to_multiplier *4 ) { +BT_WARN ("latency %d, max %d and timeout %d are incompatible" , + latency, max, to_multiplier);return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 363/1005 net/mlx5e: IPoIB, Fix QPN lookup race
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prathamesh Deshpande <[email protected]>
[ Upstream commit 29066b0fc046a2965129a74325b98d9abb4647a9 ]
The parent RX completion path can load a QPN hash entry before mlx5i_pkey_del_qpn() unlinks and frees it, then dereference freed memory.
Use RCU hlist operations and defer freeing with kfree_rcu(). The existing RCU read-side section in mlx5e_napi_poll() covers the lookup. Keep ht_lock for writers and acquire it before looking up the entry to delete.
--- .../ethernet/mellanox/mlx5/core/ipoib/ipoib.h | 2 +- .../mellanox/mlx5/core/ipoib/ipoib_vlan.c | 26 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.h +1 -1
@@ -82,7 +82,7 @@ void mlx5i_pkey_qpn_ht_cleanup(struct net_device *netdev);int mlx5i_pkey_add_qpn (struct net_device *netdev,u32 qpn);int mlx5i_pkey_del_qpn (struct net_device *netdev,u32 qpn); -/* Get the net-device corresponding to the given underlay QPN */ +/* Get the net-device for a QPN. Caller must hold rcu_read_lock(). */ struct net_device *mlx5i_pkey_get_netdev (struct net_device *netdev,u32 qpn);/* Shared ndo functions */
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c +15 -11
@@ -31,6 +31,7 @@*/ #include <linux/hash.h> +#include <linux/rculist.h> #include "ipoib.h" #define MLX5I_MAX_LOG_PKEY_SUP 7
@@ -39,11 +40,12 @@ struct qpn_to_netdev {struct net_device *netdev;struct hlist_node hlist;u32 underlay_qpn; +struct rcu_head rcu; };struct mlx5i_pkey_qpn_ht {struct hlist_head buckets[1 <<MLX5I_MAX_LOG_PKEY_SUP ]; -spinlock_t ht_lock;/* Synchronise with NAPI */ +spinlock_t ht_lock;/* Serialize hash table updates */ };int mlx5i_pkey_qpn_ht_init (struct net_device *netdev)
@@ -68,13 +70,14 @@ void mlx5i_pkey_qpn_ht_cleanup(struct net_device *netdev)kfree (ipriv->qpn_htbl); } -static struct qpn_to_netdev *mlx5i_find_qpn_to_netdev_node (struct hlist_head *buckets, -u32 qpn) +static struct qpn_to_netdev * +mlx5i_find_qpn_to_netdev_node (struct mlx5i_pkey_qpn_ht *ht,u32 qpn) { -struct hlist_head *h = &buckets[hash_32 (qpn,MLX5I_MAX_LOG_PKEY_SUP )]; +struct hlist_head *h = &ht->buckets[hash_32 (qpn,MLX5I_MAX_LOG_PKEY_SUP )];struct qpn_to_netdev *node; -hlist_for_each_entry (node, h, hlist) { +hlist_for_each_entry_rcu (node, h, hlist, +lockdep_is_held (&ht->ht_lock)) {if (node->underlay_qpn == qpn)return node; }
@@ -96,7 +99,7 @@ int mlx5i_pkey_add_qpn(struct net_device *netdev, u32 qpn) new_node->netdev = netdev; new_node->underlay_qpn = qpn;spin_lock_bh (&ht->ht_lock); -hlist_add_head (&new_node->hlist, &ht->buckets[key]); +hlist_add_head_rcu (&new_node->hlist, &ht->buckets[key]);spin_unlock_bh (&ht->ht_lock);return 0 ;
@@ -109,16 +112,17 @@ int mlx5i_pkey_del_qpn(struct net_device *netdev, u32 qpn)struct mlx5i_pkey_qpn_ht *ht = ipriv->qpn_htbl;struct qpn_to_netdev *node; - node =mlx5i_find_qpn_to_netdev_node (ht->buckets, qpn); +spin_lock_bh (&ht->ht_lock); + node =mlx5i_find_qpn_to_netdev_node (ht, qpn);if (!node) { +spin_unlock_bh (&ht->ht_lock);mlx5_core_warn (epriv->mdev,"QPN to netdev delete from HT failed\n" );return -EINVAL ; } -spin_lock_bh (&ht->ht_lock); -hlist_del_init (&node->hlist); +hlist_del_rcu (&node->hlist);spin_unlock_bh (&ht->ht_lock); -kfree (node); +kfree_rcu (node, rcu);return 0 ; }
@@ -128,7 +132,7 @@ struct net_device *mlx5i_pkey_get_netdev(struct net_device *netdev, u32 qpn)struct mlx5i_priv *ipriv =netdev_priv (netdev);struct qpn_to_netdev *node; - node =mlx5i_find_qpn_to_netdev_node (ipriv->qpn_htbl->buckets, qpn); + node =mlx5i_find_qpn_to_netdev_node (ipriv->qpn_htbl, qpn);if (!node)return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 364/1005 netlink: Do not call the unbind callback with the table locked
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anil Kaushik <[email protected]>
[ Upstream commit a36b9e205cb3c452ab96cc783e63465d466fe615 ]
When netlink_bind() fails to insert the socket, it calls netlink_undo_bind() with the table locked. genl_unbind() then takes cb_lock, while genl_unregister_family() and genl_register_family() take cb_lock for writing and then wait in netlink_table_grab() for the table users to go away:
netlink_bind() genl_unregister_family()
netlink_lock_table() down_write(&cb_lock)
netlink_insert() fails
netlink_undo_bind() netlink_table_grab()
genl_unbind() waits for nl_table_users == 0
down_read(&cb_lock)An unprivileged user can get here by binding to a port ID that is in use, with nl_groups set. Lockdep does not see it, as nl_table_users is a plain counter.
Unlock the table first, as the comment in netlink_release() asks for.
--- net/netlink/af_netlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netlink/af_netlink.c +2 -1
@@ -1050,8 +1050,9 @@ static int netlink_bind(struct socket *sock, struct sockaddr_unsized *addr, netlink_insert(sk, nladdr->nl_pid) :netlink_autobind (sock);if (err) { +netlink_unlock_table ();netlink_undo_bind (BITS_PER_TYPE (u32), groups, sk); - goto unlock; +return err; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 365/1005 net: ethernet: ti: am65-cpts: keep port and direction when matching PTPv1 TX timestamps
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesper L. Nielsen <[email protected]>
[ Upstream commit c4b75e64aa5b1adc75b4f1f251b5e3baa5b75b09 ]
The CPTS reports the message type of a timestamp event using the PTPv2 header layout, i.e. the low nibble of the first header byte. In a PTPv1 header that byte is the upper byte of versionPTP and always 0, so every PTPv1 event is reported as message type 0, while am65_skb_get_mtype_seqid() reads the PTPv1 message type from the control field. To make PTPv1 match at all, commit 1b9e743e923b ("net: ethernet:
ti: am65-cpts: Fix PTPv1 message type on TX packets") overwrites the whole value compared against the skb with the skb's own value once the sequence ids are equal. That throws away the event type and the port number of the event as well, so a PTPv1 skb matches any TX event with the same sequence id on either port. For PTPv1 this defeats commit a23c657e332f ("net: ethernet: ti: am65-cpsw: Use also port number to identify timestamps"). The overwritten value also sticks for the rest of the TX queue walk.
Since every PTPv1 frame reads as message type 0, the hardware timestamps all PTPv1 frames to UDP ports 319 and 320, including Follow_Up and Delay_Resp, for which no skb waits. With a PTPv1 master on both ports whose sequence ids run in step (e.g. a Dante device with primary and secondary network started at the same time), the unclaimed TX event of Follow_Up N on one port is still on the event list when the other port queues Sync N, and am65_cpts_find_tx_ts() tries to match before it checks for expiry. Sync N then gets the transmit time of the other port's Follow_Up N, and the master announces a preciseOriginTimestamp up to one Sync interval early to every slave on that network.
For PTPv1 replace only the message type of the event with the skb's and keep its event type, port number and sequence id, and compute the value per skb.
Tested on AM62x with ti-linux-6.12.y and the port number commit backported:
without this patch every boot in which both ports started PTP together (10 of 10) sent wrong Sync timestamps, with it none did (0 of 29).
The bug was tracked down, and this fix and changelog drafted, with the help of an AI coding assistant (Claude). I reviewed and tested it on hardware as described above.
--- drivers/net/ethernet/ti/am65-cpts.c | 31 +++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/net/ethernet/ti/am65-cpts.c +25 -6
@@ -811,6 +811,28 @@ static struct ptp_clock_info am65_ptp_info = { .do_aux_work = am65_cpts_ts_work, }; +/* The CPTS decodes the message type of an event using the PTPv2 header +* layout. For PTPv1 that nibble is part of versionPTP and always reads 0, +* while am65_skb_get_mtype_seqid() takes the message type from the PTPv1 +* control field. For PTPv1 take the message type from the skb, but keep +* the event type, port number and sequence id of the event so that an +* event only matches a packet of the same direction on the same port. +*/ +static u32 am65_cpts_event_mtype_seqid (struct am65_cpts_event *event, +u32 skb_mtype_seqid, +unsigned int ptp_class) +{ +u32 mtype_seqid = event->event1; + +if (ptp_class &PTP_CLASS_V1 ) { + mtype_seqid &= ~AM65_CPTS_EVENT_1_MESSAGE_TYPE_MASK ; + mtype_seqid |= skb_mtype_seqid & +AM65_CPTS_EVENT_1_MESSAGE_TYPE_MASK ; + } + +return mtype_seqid; +} +static bool am65_cpts_match_tx_ts (struct am65_cpts *cpts,struct am65_cpts_event *event) {
@@ -820,7 +842,6 @@ static bool am65_cpts_match_tx_ts(struct am65_cpts *cpts,bool found = false;u32 mtype_seqid; - mtype_seqid = event->event1;__skb_queue_head_init (&txq_list);spin_lock_irqsave (&cpts->txq.lock, flags);
@@ -833,11 +854,9 @@ static bool am65_cpts_match_tx_ts(struct am65_cpts *cpts,struct am65_cpts_skb_cb_data *skb_cb = (struct am65_cpts_skb_cb_data *)skb->cb; -if ((ptp_classify_raw (skb) &PTP_CLASS_V1 ) && - ((mtype_seqid &AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK ) == - (skb_cb->skb_mtype_seqid &AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK ))) - mtype_seqid = skb_cb->skb_mtype_seqid; - + mtype_seqid =am65_cpts_event_mtype_seqid (event, + skb_cb->skb_mtype_seqid, +ptp_classify_raw (skb));if (mtype_seqid == skb_cb->skb_mtype_seqid) {u64 ns = event->timestamp;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 366/1005 net/mlx5e: Add missing Ethernet multicast octets to vport_rx_bytes sum
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Or Har-Toov <[email protected]>
[ Upstream commit 9c1adbe7fa6cbc02c25db2039532918acf846400 ]
mlx5e_rep_update_hw_counters() adds transmitted_eth_multicast.packets to vport_rx_packets but does not add transmitted_eth_multicast.octets to vport_rx_bytes. As a result, Ethernet multicast sent by a VF/SF is counted in its representor's rx_packets but not in rx_bytes.
Fix by adding transmitted_eth_multicast.octets to the vport_rx_bytes sum.
--- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +1 -0
@@ -238,6 +238,7 @@ static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(vport_rep)MLX5_GET_CTR (out, transmitted_ib_unicast.octets) +MLX5_GET_CTR (out, transmitted_eth_unicast.octets) +MLX5_GET_CTR (out, transmitted_ib_multicast.octets) + +MLX5_GET_CTR (out, transmitted_eth_multicast.octets) +MLX5_GET_CTR (out, transmitted_eth_broadcast.octets); rep_stats->vport_tx_bytes =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 367/1005 calipso: do not charge request socket options to the listener
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit b4a2cc6d748d3056a25812dcf5f5377a59afd02f ]
calipso_req_setattr() and calipso_req_delattr() allocate ireq->ipv6_opt with ipv6_renew_options(), which charges the listener sk_omem_alloc through sock_kmalloc().
tcp_v6_reqsk_destructor() frees ireq->ipv6_opt without uncharging it, so each request socket leaks its options size from the listener budget. Once sysctl_optmem_max is reached, sock_kmalloc() fails, calipso_req_setattr() returns -ENOBUFS, and tcp_v6_route_req() drops all subsequent SYN packets. __sk_destruct() also reports an optmem leakage when the listener is destroyed.
Uncharging in tcp_v6_reqsk_destructor() would not be correct: after a migration, req->rsk_listener is no longer the socket that was charged.
These options belong to the request socket, there is no reason to charge them to the listener. Change ipv6_renew_options() to use kmalloc() when its sk argument is NULL, and use this from calipso_req_setattr() and calipso_req_delattr(),
like cipso_v4_req_setattr() which uses kzalloc().
Note:
After this patch, calipso_req_setattr() and calipso_req_delattr() no longer need the listener. Commit 10876da918fa ("calipso: Fix null-ptr-deref in calipso_req_{set,del}attr().") could be reverted in net-next (also removing the then unused sk variables), so that CALIPSO works with SYN cookies.
--- net/ipv6/calipso.c | 12 ++++-------- net/ipv6/exthdrs.c | 5 +++-- 2 files changed, 7 insertions(+), 10 deletions(-)
net/ipv6/calipso.c +4 -8
@@ -1219,7 +1219,7 @@ static int calipso_req_setattr(struct request_sock *req,if (IS_ERR (new))return PTR_ERR (new); - txopts =ipv6_renew_options (sk, req_inet->ipv6_opt,IPV6_HOPOPTS , new); + txopts =ipv6_renew_options (NULL , req_inet->ipv6_opt,IPV6_HOPOPTS , new);kfree (new);
@@ -1227,10 +1227,8 @@ static int calipso_req_setattr(struct request_sock *req,return PTR_ERR (txopts); txopts =xchg (&req_inet->ipv6_opt, txopts); -if (txopts) { -atomic_sub (txopts->tot_len, &sk->sk_omem_alloc); +if (txopts)txopt_put (txopts); - }return 0 ; }
@@ -1260,14 +1258,12 @@ static void calipso_req_delattr(struct request_sock *req)if (calipso_opt_del (req_inet->ipv6_opt->hopopt, &new))return ;/* Nothing to do */ - txopts =ipv6_renew_options (sk, req_inet->ipv6_opt,IPV6_HOPOPTS , new); + txopts =ipv6_renew_options (NULL , req_inet->ipv6_opt,IPV6_HOPOPTS , new);if (!IS_ERR (txopts)) { txopts =xchg (&req_inet->ipv6_opt, txopts); -if (txopts) { -atomic_sub (txopts->tot_len, &sk->sk_omem_alloc); +if (txopts)txopt_put (txopts); - } }kfree (new); }
net/ipv6/exthdrs.c +3 -2
@@ -1281,7 +1281,7 @@ static void ipv6_renew_option(int renewtype,* not copied into the new set of options. * * The new set of options is allocated from the socket option memory -* buffer of @sk. +* buffer of @sk, or with kmalloc() if @sk is NULL. */ struct ipv6_txoptions * ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,
@@ -1309,7 +1309,8 @@ ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,return NULL ; tot_len +=sizeof (*opt2); - opt2 =sock_kmalloc (sk, tot_len,GFP_ATOMIC ); + opt2 = sk ?sock_kmalloc (sk, tot_len,GFP_ATOMIC ) : +kmalloc (tot_len,GFP_ATOMIC );if (!opt2)return ERR_PTR (-ENOBUFS );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 368/1005 ipv6: Check the Home Address option again before its address is used
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 30c71476d842b094651bd7712f6c8ee8716147d0 ]
ipv6_dest_hao() checks the Home Address option and sets IP6CB(skb)->dsthao to the offset of the destination options header. Later mip6_addr_swap() and mip6_destopt_reject() call ipv6_find_tlv() with that offset and use the 16 address bytes. They assume that the same header is still there.
But the seg6 and ioam6 lwtunnels, the End.B6 actions, ipv6_rpl_srh_rcv() and BPF lwt progs move or rewrite the IPv6 headers and keep IP6CB(skb). Then ipv6_find_tlv() parses other bytes. It returns when the type matches, before it checks that the option is inside the header. Nobody checks the length of the option again. Thus mip6_addr_swap() can write after the data of the skb. mip6_destopt_reject() can copy that memory to an xfrm report.
In ipv6_find_tlv(), check the length of an option before its type. The returned option is then inside the header, and the header is inside the linear data. In both callers, ignore an option with a length other than 16, as if ipv6_find_tlv() found none. Then the ICMPv6 error goes to the source address of the IPv6 header, and the xfrm report has no XFRMA_COADDR attribute. Nothing changes for a header that ip6_parse_tlv() accepted and that is still in its place. For the other callers an incomplete option is now absent:
- ip6_find_1stfragopt() and mip6_rthdr_offset() can return another offset for the fragment header or the xfrm header, also in a forwarded packet.
- calipso_skbuff_optptr() returns NULL. netlbl_skbuff_getattr() and netlbl_cache_add() then see no option. calipso_skbuff_delattr() returns 0 and the packet continues unchanged. Today it returns -EINVAL and SELinux drops the packet. It already returns 0 when an earlier option is incomplete. The receiver drops such a header in ip6_parse_tlv().
The code that moves the headers still does not reset the offset or the other fields of IP6CB(skb). If the bytes there look like a header with a Home Address option of length 16, both callers still use its address.
The first tag also covers ipv6_find_tlv(), because its early return did no harm before mip6_addr_swap(). The second tag is for mip6_destopt_reject().
--- net/ipv6/exthdrs_core.c | 7 ++++--- net/ipv6/icmp.c | 7 ++++++- net/ipv6/mip6.c | 9 ++++++++- 3 files changed, 18 insertions(+), 5 deletions(-)
net/ipv6/exthdrs_core.c +4 -3
@@ -138,9 +138,6 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type)int opttype = nh[offset];int optlen; -if (opttype == type) -return offset; -switch (opttype) {case IPV6_TLV_PAD1 : optlen =1 ;
@@ -153,6 +150,10 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type) goto bad;break ; } +/* Some callers read the option, so it must be in the header. */ +if (opttype == type) +return offset; + offset += optlen; len -= optlen; }
net/ipv6/icmp.c +6 -1
@@ -343,7 +343,12 @@ static void mip6_addr_swap(struct sk_buff *skb, const struct inet6_skb_parm *optif (likely (off >=0 )) { hao = (struct ipv6_destopt_hao *) (skb_network_header (skb) + off); -swap (iph->saddr, hao->addr); +/* +* The header can have moved or changed after +* ipv6_dest_hao() checked the length. +*/ +if (hao->length ==16 ) +swap (iph->saddr, hao->addr); } } }
net/ipv6/mip6.c +8 -1
@@ -211,9 +211,16 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb,if (likely (opt->dsthao)) { offset =ipv6_find_tlv (skb, opt->dsthao,IPV6_TLV_HAO ); -if (likely (offset >=0 )) +if (likely (offset >=0 )) { hao = (struct ipv6_destopt_hao *) (skb_network_header (skb) + offset); +/* +* The header can have moved or changed after +* ipv6_dest_hao() checked the length. +*/ +if (hao->length !=16 ) + hao =NULL ; + } } stamp =skb_get_ktime (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 369/1005 ata: libata-scsi: fix MODE SELECT handling of data after the mode page
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 6fde0444d07ec954f3d885375e0402ff2f2e5064 ]
ata_scsi_mode_select_xlat() only supports one mode page per MODE SELECT command, and rejects a parameter list with data after the mode page with INVALID FIELD IN PARAMETER LIST. However:
- It does not set the field pointer, so the sense data reports 0xffff as the FIELD POINTER.
- It only checks for data after the mode page after the mode page handler has been called. ata_mselect_control_ata_feature() has then already updated the CDL enabled flag of the device, even though the command is rejected and the CDL setting of the device is not changed.
- For the control mode page, ata_mselect_control_spg0() does not need an ATA command, so the check is skipped, and the data after the mode page is silently ignored.
Check for data after the mode page before calling the mode page handlers, and set the FIELD POINTER to the first byte after the mode page, i.e. to the first byte of the next mode page.
The reason why only one mode page per command is supported is that a MODE SELECT command is translated into at most one ATA command, so update the comment accordingly.
--- drivers/ata/libata-scsi.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/ata/libata-scsi.c +11 -7
@@ -4629,6 +4629,17 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)if (pg_len > len) goto invalid_param_len; +/* +* A MODE SELECT command is translated into at most one ATA command, so +* only one mode page per command is supported. Reject any data after +* the mode page before calling the mode page handlers, which may +* already update the device flags. +*/ +if (len > pg_len) { + fp = p - buffer + pg_len; + goto invalid_param; + } +switch (pg) {case CACHE_MPAGE :if (ata_mselect_caching (qc, p, pg_len, &fp) <0 ) {
@@ -4651,13 +4662,6 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param; } -/* -* Only one page has changeable data, so we only support setting one -* page at a time. -*/ -if (len > pg_len) - goto invalid_param; -return 0 ; invalid_fld:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 370/1005 ata: libata-scsi: do not accept subpage code FFh in MODE SELECT
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit b29c40dc150b0b4218c4d6844770892eb6b2f6b5 ]
When the SUBPAGE CODE of the mode page in a MODE SELECT parameter list is FFh, ata_scsi_mode_select_xlat() rejects it for the control mode page, but accepts it for all other mode pages, i.e. for the caching mode page, the only other mode page that it supports.
However, FFh is not the subpage code of an actual mode page: SPC-7 (7.5.2) only defines it as the MODE SENSE request code for all subpages. SUBPAGE CODE FFh only means "all subpages" in requests, i.e. in the MODE SENSE CDB for mode pages and in the LOG SELECT CDB for log pages (see SPC-5, 6.8), while the SUBPAGE CODE of a mode page in a MODE SELECT parameter list identifies a specific mode page. Also, SAT-2 and later versions of SAT define the Caching mode page with the SPF bit set to zero (see SAT-6, 10.4.9), i.e. without a SUBPAGE CODE field.
Remove the ALL_SUB_MPAGES case, so that SUBPAGE CODE FFh is rejected like any other unsupported subpage.
--- drivers/ata/libata-scsi.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/ata/libata-scsi.c +2 -10
@@ -4602,19 +4602,11 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) }/* -* Supported subpages: all subpages and ATA feature sub-page f2h of -* the control page. +* The only supported subpage is the ATA feature sub-page f2h of the +* control page. */ if (spg) {switch (spg) { -case ALL_SUB_MPAGES : -/* All subpages is not supported for the control page */ -if (pg ==CONTROL_MPAGE ) { - fp = (p[0 ] &0x40 ) ?1 :0 ; - fp += hdr_len + bd_len; - goto invalid_param; - } -break ;case ATA_FEATURE_SUB_MPAGE :if (qc->dev->flags &ATA_DFLAG_CDL && pg ==CONTROL_MPAGE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 371/1005 ata: libata-scsi: reject MODE SELECT mode pages with a wrong SPF bit
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit a1eb72c477ec1320c540f27ce1e2f717d4518e62 ]
ata_scsi_mode_select_xlat() accepts the caching and control mode pages both in page_0 format and in sub_page format with SUBPAGE CODE 00h.
However, SAT-2 and later versions of SAT define the SPF bit of the Caching mode page and of the Control mode page as not changeable and set to zero (see SAT-6, 10.4.9 and 10.4.6), and SPC-7 (6.12, MODE SELECT(10) command) requires the device server to terminate a MODE SELECT command with INVALID FIELD IN PARAMETER LIST if the application client sets any field that is reported as not changeable to a value other than its current value.
Reject a mode page with the SPF bit set to one and SUBPAGE CODE 00h, with the FIELD POINTER set to the byte containing the SPF bit. The only mode page with the SPF bit set to one that remains accepted is the ATA Feature Control mode page (control mode page, sub-page f2h), for which SAT-6 (12.3.4) requires the SPF bit to be set to one. The opposite case does not need a check: a mode page in page_0 format always has subpage code 00h, so it can never be the ATA Feature Control mode page.
This also allows the mode page handlers to rely on the format of their mode page, which a later patch will make use of.
--- drivers/ata/libata-scsi.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/ata/libata-scsi.c +10 -0
@@ -4587,7 +4587,17 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)if (len <4 ) goto invalid_param_len; +/* +* Mode pages with subpage code 00h use the page_0 format: SAT +* defines the SPF bit of the Caching and Control mode pages, +* for subpage code 00h, as not changeable and set to zero. +*/ spg = p[1 ]; +if (!spg) { + fp = hdr_len + bd_len; + goto invalid_param; + } + pg_len =get_unaligned_be16 (&p[2 ]); p +=4 ; len -=4 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 372/1005 ata: libata-scsi: fix MODE SELECT field pointer for unsupported subpages
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 2a4c61cf94d48ec8560473d4fd5383583ce8809c ]
When the mode page of a MODE SELECT parameter list has an unsupported SUBPAGE CODE, ata_scsi_mode_select_xlat() sets the FIELD POINTER of the INVALID FIELD IN PARAMETER LIST sense data to the SUBPAGE CODE byte of the mode page header (byte 1 of the page) if the SPF bit is set, and to the PAGE CODE byte (byte 0 of the page) otherwise.
However, the SPF bit is tested on p[0] after p has already been advanced past the mode page header, so the test reads bit 6 of the first byte of the mode page data instead. If the parameter list ends with the mode page header, it even reads the byte that follows the parameter list in buffer, which is not initialized when no data beyond the parameter list was transferred.
The test is not needed anyway: spg can only be non-zero for a mode page in sub_page format, i.e. with the SPF bit set, and the field in error is the SUBPAGE CODE. Always set the FIELD POINTER to the SUBPAGE CODE byte, which follows the mode parameter header, the block descriptors and the PAGE CODE byte.
--- drivers/ata/libata-scsi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/ata/libata-scsi.c +1 -2
@@ -4623,8 +4623,7 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)break ; fallthrough;default : - fp = (p[0 ] &0x40 ) ?1 :0 ; - fp += hdr_len + bd_len; + fp = hdr_len + bd_len +1 ; goto invalid_param; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 373/1005 ata: libata-scsi: fix MODE SELECT field pointer for block descriptor length
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit a3e52dcf0fbaa1a103accef3e8861cdc250ee5d6 ]
ata_scsi_mode_select_xlat() only accepts MODE SELECT parameter lists without block descriptors or with a single 8 byte block descriptor. For any other BLOCK DESCRIPTOR LENGTH, it terminates the command with INVALID FIELD IN PARAMETER LIST, and the FIELD POINTER should point at the BLOCK DESCRIPTOR LENGTH field, i.e. at byte 3 of the mode parameter header(6) or at byte 6 of the mode parameter header(10), as SPC requires the FIELD POINTER of a multiple-byte field to point at its first byte.
However, the mode parameter header length and the BLOCK DESCRIPTOR LENGTH are added to the offset of the field, so the FIELD POINTER points 3 or 6 bytes after the end of the block descriptors instead. For example, a MODE SELECT(10) with a BLOCK DESCRIPTOR LENGTH of 16 reports byte 30 instead of byte 6.
Do not add the mode parameter header length and the BLOCK DESCRIPTOR LENGTH to the offset of the BLOCK DESCRIPTOR LENGTH field.
--- drivers/ata/libata-scsi.c | 1 - 1 file changed, 1 deletion(-)
drivers/ata/libata-scsi.c +0 -1
@@ -4572,7 +4572,6 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param_len;if (bd_len !=0 && bd_len !=8 ) { fp = (six_byte) ?3 :6 ; - fp += bd_len + hdr_len; goto invalid_param; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 374/1005 ata: libata-scsi: pass the whole mode page to the MODE SELECT handlers
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 0fdb8eef88a886751e33600d446a66c529384f11 ]
ata_scsi_mode_select_xlat() strips the mode page header before calling the mode page handlers, which report the position of an invalid field as an offset relative to the mode page data. It then converts this offset into an offset in the parameter list by adding the length of the mode parameter header and of the block descriptors, but not the length of the mode page header. As a result, the FIELD POINTER of the INVALID FIELD IN PARAMETER LIST sense data points 2 bytes (page_0 format) or 4 bytes (sub_page format) before the byte that is actually invalid. For example, changing byte 3 of the caching mode page in a MODE SELECT(10) parameter list without block descriptors reports byte 9 instead of byte 11.
Pass the whole mode page, starting with its mode page header, to the handlers instead, like the ata_msense_*() functions, which generate the whole mode page. Offsets in buf are then the byte numbers of the mode page, as used in the mode page definitions of SPC, SBC and SAT, the handlers can compare buf with the mode page generated by the matching ata_msense_*() function without adjusting offsets, and the conversion done by ata_scsi_mode_select_xlat() becomes correct. This also allows reporting an invalid PAGE LENGTH at the PAGE LENGTH field, which was not part of buf before. As ata_scsi_mode_select_xlat() rejects SUBPAGE CODE FFh and mode pages with a wrong SPF bit, each handler only gets its mode page in a single format, so the mode page header length is known.
Document what buf, len and fp are, and the return values, in kernel-doc comments for all the handlers.
--- drivers/ata/libata-scsi.c | 133 +++++++++++++++++++++++--------------- 1 file changed, 82 insertions(+), 51 deletions(-)
drivers/ata/libata-scsi.c +82 -51
@@ -4325,14 +4325,22 @@ static unsigned int ata_scsi_zbc_out_xlat(struct ata_queued_cmd *qc)/** * ata_mselect_caching - Simulate MODE SELECT for caching info page * @qc: Storage for translated ATA taskfile -* @buf: input buffer -* @len: number of valid bytes in the input buffer -* @fp: out parameter for the failed field on error +* @buf: Mode page, starting with the mode page header +* @len: Length of the mode page, including the mode page header +* @fp: Out parameter, offset in @buf of the first invalid byte on error * * Prepare a taskfile to modify caching information for the device. * +* The caller has stripped the mode parameter header and the block +* descriptors, so @buf points at the mode page header, like the buffer +* filled by the ata_msense_*() functions, and offsets in @buf, including +* the one returned in @fp, are the byte numbers of the mode page. +* * LOCKING: * None. +* +* RETURNS: +* 0 if a taskfile was prepared, -EINVAL if the mode page is invalid. */ static int ata_mselect_caching (struct ata_queued_cmd *qc,const u8 *buf,int len,u16 *fp)
@@ -4343,26 +4351,19 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,u8 wce;int i; -/* -* The first two bytes of def_cache_mpage are a header, so offsets -* in mpage are off by 2 compared to buf. Same for len. -*/ - -if (len !=CACHE_MPAGE_LEN -2 ) { - *fp =min (len,CACHE_MPAGE_LEN -2 ); +if (len !=CACHE_MPAGE_LEN ) { + *fp =1 ;return -EINVAL ; } - wce = buf[0 ] & (1 <<2 ); + wce = buf[2 ] & (1 <<2 );/* * Check that read-only bits are not modified. */ ata_msense_caching (dev->id, mpage, false); -for (i =0 ; i <CACHE_MPAGE_LEN -2 ; i++) { -if (i ==0 ) -continue ; -if (mpage[i +2 ] != buf[i]) { +for (i =3 ; i <CACHE_MPAGE_LEN ; i++) { +if (mpage[i] != buf[i]) { *fp = i;return -EINVAL ; }
@@ -4376,8 +4377,26 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc,return 0 ; } -/* -* Simulate MODE SELECT control mode page, sub-page 0. +/** +* ata_mselect_control_spg0 - Simulate MODE SELECT for control sub-page 0 +* @qc: Storage for translated ATA taskfile +* @buf: Mode page, starting with the mode page header +* @len: Length of the mode page, including the mode page header +* @fp: Out parameter, offset in @buf of the first invalid byte on error +* +* Simulate MODE SELECT control mode page, sub-page 0. +* +* The caller has stripped the mode parameter header and the block +* descriptors, so @buf points at the mode page header, like the buffer +* filled by the ata_msense_*() functions, and offsets in @buf, including +* the one returned in @fp, are the byte numbers of the mode page. +* +* LOCKING: +* None. +* +* RETURNS: +* 0, as no ATA command needs to be sent, or -EINVAL if the mode page is +* invalid. */ static int ata_mselect_control_spg0 (struct ata_queued_cmd *qc,const u8 *buf,int len,u16 *fp)
@@ -4387,26 +4406,19 @@ static int ata_mselect_control_spg0(struct ata_queued_cmd *qc,u8 d_sense;int i; -/* -* The first two bytes of def_control_mpage are a header, so offsets -* in mpage are off by 2 compared to buf. Same for len. -*/ - -if (len !=CONTROL_MPAGE_LEN -2 ) { - *fp =min (len,CONTROL_MPAGE_LEN -2 ); +if (len !=CONTROL_MPAGE_LEN ) { + *fp =1 ;return -EINVAL ; } - d_sense = buf[0 ] & (1 <<2 ); + d_sense = buf[2 ] & (1 <<2 );/* * Check that read-only bits are not modified. */ ata_msense_control_spg0 (dev, mpage, false); -for (i =0 ; i <CONTROL_MPAGE_LEN -2 ; i++) { -if (i ==0 ) -continue ; -if (mpage[2 + i] != buf[i]) { +for (i =3 ; i <CONTROL_MPAGE_LEN ; i++) { +if (mpage[i] != buf[i]) { *fp = i;return -EINVAL ; }
@@ -4418,9 +4430,27 @@ static int ata_mselect_control_spg0(struct ata_queued_cmd *qc,return 0 ; } -/* -* Translate MODE SELECT control mode page, sub-page f2h (ATA feature mode -* page) into a SET FEATURES command. +/** +* ata_mselect_control_ata_feature - Translate ATA Feature Control page +* @qc: Storage for translated ATA taskfile +* @buf: Mode page, starting with the mode page header +* @len: Length of the mode page, including the mode page header +* @fp: Out parameter, offset in @buf of the first invalid byte on error +* +* Translate MODE SELECT control mode page, sub-page f2h (ATA feature mode +* page) into a SET FEATURES command. +* +* The caller has stripped the mode parameter header and the block +* descriptors, so @buf points at the mode page header, like the buffer +* filled by the ata_msense_*() functions, and offsets in @buf, including +* the one returned in @fp, are the byte numbers of the mode page. +* +* LOCKING: +* None. +* +* RETURNS: +* 1 if a taskfile was prepared, -EINVAL if the mode page is invalid or if +* CDL cannot be enabled. */ static int ata_mselect_control_ata_feature (struct ata_queued_cmd *qc,const u8 *buf,int len,u16 *fp)
@@ -4429,17 +4459,13 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc,struct ata_taskfile *tf = &qc->tf;u8 cdl_action; -/* -* The first four bytes of ATA Feature Control mode page are a header, -* so offsets in mpage are off by 4 compared to buf. Same for len. -*/ -if (len !=ATA_FEATURE_SUB_MPAGE_LEN -4 ) { - *fp =min (len,ATA_FEATURE_SUB_MPAGE_LEN -4 ); +if (len !=ATA_FEATURE_SUB_MPAGE_LEN ) { + *fp =2 ;return -EINVAL ; }/* Check cdl_ctrl */ -switch (buf[0 ] &0x03 ) { +switch (buf[4 ] &0x03 ) {case 0 :/* Disable CDL */ ata_dev_dbg (dev,"Disabling CDL\n" );
@@ -4461,7 +4487,7 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc, dev->flags |=ATA_DFLAG_CDL_ENABLED ;break ;default : - *fp =0 ; + *fp =4 ;return -EINVAL ; }
@@ -4477,15 +4503,24 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc,/** * ata_mselect_control - Simulate MODE SELECT for control page * @qc: Storage for translated ATA taskfile -* @spg: target sub-page of the control page -* @buf: input buffer -* @len: number of valid bytes in the input buffer -* @fp: out parameter for the failed field on error +* @spg: Sub-page of the control page, 0 or ATA_FEATURE_SUB_MPAGE +* @buf: Mode page, starting with the mode page header +* @len: Length of the mode page, including the mode page header +* @fp: Out parameter, offset in @buf of the first invalid byte on error * -* Prepare a taskfile to modify caching information for the device. +* Call the handler of sub-page @spg of the control mode page. +* +* The caller has stripped the mode parameter header and the block +* descriptors, so @buf points at the mode page header, like the buffer +* filled by the ata_msense_*() functions, and offsets in @buf, including +* the one returned in @fp, are the byte numbers of the mode page. * * LOCKING: * None. +* +* RETURNS: +* 0 if no ATA command needs to be sent, 1 if a taskfile was prepared, +* -EINVAL if the mode page is invalid. */ static int ata_mselect_control (struct ata_queued_cmd *qc,u8 spg,const u8 *buf,int len,u16 *fp)
@@ -4597,17 +4632,13 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param; } - pg_len =get_unaligned_be16 (&p[2 ]); - p +=4 ; - len -=4 ; + pg_len =get_unaligned_be16 (&p[2 ]) +4 ; }else {if (len <2 ) goto invalid_param_len; spg =0 ; - pg_len = p[1 ]; - p +=2 ; - len -=2 ; + pg_len = p[1 ] +2 ; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 375/1005 ata: libata-scsi: set the field pointer when rejecting CDL
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shao Mingyin <[email protected]>
[ Upstream commit 7c972e73641cbe5f77f63c336de15c7a30268d49 ]
ata_mselect_control_ata_feature() rejects enabling CDL while NCQ priority is enabled, but unlike its other error branches it returns without setting *fp.
ata_scsi_mode_select_xlat() initializes fp to 0xffff and, when the handler fails, adds the offset of the mode page in the parameter list to it, i.e. the length of the mode parameter header and of the block descriptors. As fp is a u16, this wraps around, so the resulting sense data reports the byte before the mode page, i.e. the last byte of the mode parameter header or of the block descriptors, as the FIELD POINTER, instead of the byte containing the CDL_CTRL field that requests enabling CDL.
Set *fp to 4, i.e. to the byte containing the CDL_CTRL field, like the branch rejecting an invalid CDL_CTRL value does.
--- drivers/ata/libata-scsi.c | 1 + 1 file changed, 1 insertion(+)
drivers/ata/libata-scsi.c +1 -0
@@ -4480,6 +4480,7 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc,if (dev->flags &ATA_DFLAG_NCQ_PRIO_ENABLED ) {ata_dev_err (dev,"NCQ priority must be disabled to enable CDL\n" ); + *fp =4 ;return -EINVAL ; }ata_dev_dbg (dev,"Enabling CDL\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 376/1005 tracing/probes: bound symstr stores to reserved length
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifan Zhang <[email protected]>
[ Upstream commit 2fc0b3070d6d5dcecfed43cd0e62aa0fd4b4315c ]
Traceprobe calculates dynamic string sizes before storing the values. A probed pointer can change between those passes, so fetch_store_symstrlen() can reserve space for a short symbol while fetch_store_symstring() observes a longer one. The store path then overwrites the trace record.
Format the symbol into a temporary KSYM_SYMBOL_LEN buffer and copy only the bytes that fit in the reserved field, including a trailing NUL. Update __data_loc with the length actually stored so consumers do not read beyond the truncated value.
--- kernel/trace/trace_probe_tmpl.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/trace/trace_probe_tmpl.h +13 -1
@@ -87,15 +87,27 @@ fetch_store_symstrlen(unsigned long addr) static nokprobe_inline intfetch_store_symstring (unsigned long addr,void *dest,void *base) { +char namebuf[KSYM_SYMBOL_LEN ];int maxlen =get_loc_len (*(u32 *)dest);void *__dest; +int len;if (unlikely (!maxlen))return -ENOMEM ; __dest =get_loc_data (dest, base); + len =sprint_symbol (namebuf, addr); +if (len <0 ) { + *(u32 *)dest =make_data_loc (0 , __dest - base); +return 0 ; + } + + len =min (len, maxlen -1 ); +memcpy (__dest, namebuf, len); + ((char *)__dest)[len] ='\0' ; + *(u32 *)dest =make_data_loc (len +1 , __dest - base); -return sprint_symbol (__dest, addr); +return len +1 ; }/* common part of process_fetch_insn*/
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 377/1005 kho: check fdt_phys in is_kho_boot()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Thelen <[email protected]>
[ Upstream commit 58c5852ca96c58cdfdb9646870b217fc54d06a97 ]
is_kho_boot() is called early in boot before the linear memory map is initialized, so calling phys_to_virt() via kho_get_fdt() there is invalid.
On arm64 (and similarly in upcoming riscv64 support), this triggers BUG_ONs in debug builds, such as:
kernel BUG at ./arch/arm64/include/asm/memory.h:377!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP Call trace: is_kho_boot+0x2c/0x38 (P) efi_init+0x94/0xf8 setup_arch+0xf0/0x240 start_kernel+0x84/0x490 __primary_switched+0x88/0x98
Use kho_in.fdt_phys in is_kho_boot() directly instead of translating it to a virtual address.
--- kernel/liveupdate/kexec_handover.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/liveupdate/kexec_handover.c +1 -1
@@ -1631,7 +1631,7 @@ EXPORT_SYMBOL_GPL(kho_restore_free);*/ bool is_kho_boot (void ) { -return !!kho_get_fdt (); +return !!kho_in.fdt_phys; }EXPORT_SYMBOL_GPL (is_kho_boot);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 378/1005 drm/xe/cri: Expose device UID through sysfs
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Badal Nilawar <[email protected]>
[ Upstream commit 0acb5de8d7a9aec9419f316ef06b937dde285685 ]
Expose a read-only sysfs attribute, device_uid, that reports the GPU SoC's unique identifier.
Bspec: 53048, 53049
Stable-dep-of: 7539edbca32d ("drm/xe/pat: Return error from xe_pat_init_early() on unknown platform")
--- .../ABI/testing/sysfs-driver-intel-xe-gpu | 10 ++++++ drivers/gpu/drm/xe/regs/xe_regs.h | 2 ++ drivers/gpu/drm/xe/xe_device.c | 9 +++++ drivers/gpu/drm/xe/xe_device_sysfs.c | 36 +++++++++++++++++++ drivers/gpu/drm/xe/xe_device_types.h | 5 +++ drivers/gpu/drm/xe/xe_pci.c | 2 ++ drivers/gpu/drm/xe/xe_pci_types.h | 1 + 7 files changed, 65 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-intel-xe-gpu
Documentation/ABI/testing/sysfs-driver-intel-xe-gpu new file +10 -0
@@ -0,0 +1,10 @@ +What: /sys/bus/pci/drivers/xe/.../device_uid +Date: October 2026 +KernelVersion: 7.4 +Contact: [email protected] +Description: + RO. Unique 64-bit identifier of the GPU SoC device, exposed as + hexadecimal value. + + This sysfs file is present only on supported Intel Xe platforms. + Accessible only to users with administrative privileges.
drivers/gpu/drm/xe/regs/xe_regs.h +2 -0
@@ -30,6 +30,8 @@#define XEHP_MTCFG_ADDR XE_REG(0x101800)#define TILE_COUNT REG_GENMASK(15, 8) +#define CRI_DEVICE_UID XE_REG(0x102008) +#define GGC XE_REG(0x108040)#define GMS_MASK REG_GENMASK(15, 8)#define GGMS_MASK REG_GENMASK(7, 6)
drivers/gpu/drm/xe/xe_device.c +9 -0
@@ -742,6 +742,7 @@ static void vf_update_device_info(struct xe_device *xe) xe->info.skip_guc_pc =1 ; xe->info.skip_pcode =1 ; xe->info.has_drm_ras = false; + xe->info.has_device_uid = false; }static int xe_device_vram_alloc (struct xe_device *xe)
@@ -942,6 +943,12 @@ static int xe_debug_page_size_alloc_ctrl_init(struct xe_device *xe) }#endif +static void xe_uid_probe (struct xe_device *xe) +{ +if (xe->info.has_device_uid) + xe->device_uid =xe_mmio_read64_2x32 (xe_root_tile_mmio (xe),CRI_DEVICE_UID ); +} +int xe_device_probe (struct xe_device *xe) {struct xe_tile *tile;
@@ -949,6 +956,8 @@ int xe_device_probe(struct xe_device *xe)int err;u8 id; +xe_uid_probe (xe); +xe_pat_init_early (xe); err =xe_sriov_init (xe);
drivers/gpu/drm/xe/xe_device_sysfs.c +36 -0
@@ -8,6 +8,7 @@#include <linux/pci.h> #include <linux/sysfs.h> +#include "regs/xe_regs.h" #include "xe_device.h" #include "xe_device_sysfs.h" #include "xe_mmio.h"
@@ -264,6 +265,35 @@ static const struct attribute_group auto_link_downgrade_attr_group = { .attrs = auto_link_downgrade_attrs, }; +/** +* DOC: Device Unique ID +* +* On supported platforms, Xe driver exposes a unique 64-bit GPU SOC +* device identifier through the 'device_uid' sysfs entry. +* +* See Documentation/ABI/testing/sysfs-driver-intel-xe-gpu for the ABI +* specification. +*/ + +static ssize_t +device_uid_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct xe_device *xe =pdev_to_xe_device (pdev); + +return sysfs_emit (buf,"0x%016llx\n" , xe->device_uid); +} +static DEVICE_ATTR_ADMIN_RO (device_uid); + +static struct attribute *device_uid_attrs[] = { + &dev_attr_device_uid.attr, +NULL +}; + +static const struct attribute_group device_uid_attr_group = { + .attrs = device_uid_attrs, +}; +int xe_device_sysfs_init (struct xe_device *xe) {struct device *dev = xe->drm.dev;
@@ -285,5 +315,11 @@ int xe_device_sysfs_init(struct xe_device *xe)return ret; } +if (xe->info.has_device_uid) { + ret =devm_device_add_group (dev, &device_uid_attr_group); +if (ret) +return ret; + } +return 0 ; }
drivers/gpu/drm/xe/xe_device_types.h +5 -0
@@ -171,6 +171,8 @@ struct xe_device { u8 has_cached_pt:1;/** @info.has_device_atomics_on_smem: Supports device atomics on SMEM */ u8 has_device_atomics_on_smem:1; +/** @info.has_device_uid: Device supports unique 64-bit GPU SOC ID */ + u8 has_device_uid:1;/** @info.has_drm_ras: Device supports drm_ras (Reliability, Availability, Serviceability) */ u8 has_drm_ras:1;/** @info.has_fan_control: Device supports fan control */
@@ -255,6 +257,9 @@ struct xe_device {bool oob_initialized; } wa_active; +/** @device_uid: unique 64-bit GPU SOC identifier */ +u64 device_uid; +/** @survivability: survivability information for device */ struct xe_survivability survivability;
drivers/gpu/drm/xe/xe_pci.c +2 -0
@@ -470,6 +470,7 @@ static const struct xe_device_desc cri_desc = {PLATFORM (CRESCENTISLAND ), .dma_mask_size = 52, .has_display = false, + .has_device_uid = true, .has_drm_ras = true, .has_flat_ccs = false, .has_gsc_nvm = 1,
@@ -791,6 +792,7 @@ static int xe_info_init_early(struct xe_device *xe, xe->info.is_dgfx = desc->is_dgfx; xe->info.has_cached_pt = desc->has_cached_pt; + xe->info.has_device_uid = desc->has_device_uid; xe->info.has_drm_ras = desc->has_drm_ras; xe->info.has_fan_control = desc->has_fan_control;/* runtime fusing may force flat_ccs to disabled later */
drivers/gpu/drm/xe/xe_pci_types.h +1 -0
@@ -40,6 +40,7 @@ struct xe_device_desc { u8 has_cached_pt:1; u8 has_display:1; + u8 has_device_uid:1; u8 has_drm_ras:1; u8 has_fan_control:1; u8 has_flat_ccs:1;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 379/1005 drm/xe/gsc: Define GSC for NVL-S
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Previn <[email protected]>
[ Upstream commit 8a90f0d1098f9a9019f1a076bd1ee4b6c7da7dbd ]
NVL-S is identified by GSC major version 108.
The compatibility version is 0.0.
Stable-dep-of: 7539edbca32d ("drm/xe/pat: Return error from xe_pat_init_early() on unknown platform")
--- drivers/gpu/drm/xe/xe_uc_fw.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/xe/xe_uc_fw.c +1 -0
@@ -141,6 +141,7 @@ struct fw_blobs_by_type {/* for the GSC FW we match the compatibility version and not the release one */ #define XE_GSC_FIRMWARE_DEFS (fw_def, major_ver) \ + fw_def(NOVALAKE_S, GT_TYPE_ANY, major_ver(xe, gsc, nvl, 108, 0, 0)) \ fw_def(PANTHERLAKE, GT_TYPE_ANY, major_ver(xe, gsc, ptl, 105, 1, 0)) \ fw_def(LUNARLAKE, GT_TYPE_ANY, major_ver(xe, gsc, lnl, 104, 1, 0)) \ fw_def(METEORLAKE, GT_TYPE_ANY, major_ver(i915, gsc, mtl, 102, 1, 0))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 380/1005 drm/xe/pat: Return error from xe_pat_init_early() on unknown platform
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dnyaneshwar Bhadane <[email protected]>
[ Upstream commit 7539edbca32d63ce309f5e29cb9d595b0959466a ]
xe_pat_init_early() currently only logs an error when the platform's graphics version doesn't match any known PAT table, but continues probing with an uninitialized pat.ops. This can lead to a NULL pointer dereference later when pat.ops is used.
Change xe_pat_init_early() to return an int and propagate -ENODATA to xe_device_probe() so the driver fails to load cleanly instead of continuing in a broken state.
--- drivers/gpu/drm/xe/xe_device.c | 4 +++- drivers/gpu/drm/xe/xe_pat.c | 11 ++++++++++- drivers/gpu/drm/xe/xe_pat.h | 4 +++- 3 files changed, 16 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_device.c +3 -1
@@ -958,7 +958,9 @@ int xe_device_probe(struct xe_device *xe)xe_uid_probe (xe); -xe_pat_init_early (xe); + err =xe_pat_init_early (xe); +if (err) +return err; err =xe_sriov_init (xe);if (err)
drivers/gpu/drm/xe/xe_pat.c +10 -1
@@ -590,7 +590,13 @@ static const struct xe_pat_ops xe3p_xpc_pat_ops = { .entry_dump = xe3p_xpc_pat_entry_dump, }; -void xe_pat_init_early (struct xe_device *xe) +/** +* xe_pat_init_early() - Init early pat table operation. +* @xe: the &xe_device +* +* Return: 0 on success or a negative error code on failure. +*/ +int xe_pat_init_early (struct xe_device *xe) { xe->pat.idx[XE_CACHE_WB_COMPRESSION ] =XE_PAT_INVALID_IDX ; xe->pat.idx[XE_CACHE_NONE_COMPRESSION ] =XE_PAT_INVALID_IDX ;
@@ -688,12 +694,15 @@ void xe_pat_init_early(struct xe_device *xe)*/ drm_err (&xe->drm,"Missing PAT table for platform with graphics version %d.%02d!\n" ,GRAPHICS_VER (xe),GRAPHICS_VERx100 (xe) %100 ); +return -ENODATA ; } +xe_assert (xe, xe->pat.ops);xe_assert (xe, xe->pat.ops->dump);xe_assert (xe, xe->pat.ops->program_graphics);xe_assert (xe,MEDIA_VER (xe) <13 || xe->pat.ops->program_media);xe_assert (xe,GRAPHICS_VER (xe) <20 || xe->pat.ops->entry_dump); +return 0 ; }void xe_pat_init (struct xe_gt *gt)
drivers/gpu/drm/xe/xe_pat.h +3 -1
@@ -42,8 +42,10 @@ struct xe_pat_table_entry {/** * xe_pat_init_early - SW initialization, setting up data based on device * @xe: xe device +* +* Return: 0 on success or a negative error code on failure. */ -void xe_pat_init_early (struct xe_device *xe); +int xe_pat_init_early (struct xe_device *xe);/** * xe_pat_init - Program HW PAT table
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 381/1005 drm/xe: Prevent VF memory IRQ from accessing a torn-down engine
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Satyanarayana K V P <[email protected]>
[ Upstream commit db58638d5d0531beafafa498cffa516779876ee5 ]
The VF memory IRQ handler iterates over HW engines whose names are set. Engine teardown clears hwe->gt but leaves hwe->name set, so the handler can select an engine whose GT has already been invalidated. This can cause a NULL pointer dereference in xe_hw_engine_handle_irq().
Invalidate the engine name during teardown so subsequent engine scans skip it.
--- drivers/gpu/drm/xe/xe_hw_engine.c | 17 ++++++++++++++--- drivers/gpu/drm/xe/xe_irq.c | 3 +++ drivers/gpu/drm/xe/xe_memirq.c | 3 +++ 3 files changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_hw_engine.c +14 -3
@@ -275,11 +275,22 @@ static const struct engine_info engine_infos[] = {static void hw_engine_fini (void *arg) {struct xe_hw_engine *hwe = arg; +struct xe_gt *gt = hwe->gt; + +if (gt) { +struct xe_device *xe =gt_to_xe (gt); +unsigned long flags; -if (hwe->exl_port) -xe_execlist_port_destroy (hwe->exl_port); +if (hwe->exl_port) +xe_execlist_port_destroy (hwe->exl_port); - hwe->gt =NULL ; +spin_lock_irqsave (&xe->irq.lock, flags); + hwe->name =NULL ; + hwe->gt =NULL ; +spin_unlock_irqrestore (&xe->irq.lock, flags); + }else { + hwe->name =NULL ; + } }/**
drivers/gpu/drm/xe/xe_irq.c +3 -0
@@ -908,6 +908,7 @@ static irqreturn_t xe_irq_msix_default_hwe_handler(int irq, void *arg)struct xe_hw_engine *hwe;enum xe_hw_engine_id id;struct xe_tile *tile; +unsigned long flags;struct xe_gt *gt;if (!atomic_read (&xe->irq.enabled))
@@ -922,8 +923,10 @@ static irqreturn_t xe_irq_msix_default_hwe_handler(int irq, void *arg)if (gt->tile != tile)continue ; +spin_lock_irqsave (&xe->irq.lock, flags);for_each_hw_engine (hwe, gt, id)xe_memirq_hwe_handler (memirq, hwe); +spin_unlock_irqrestore (&xe->irq.lock, flags); } }
drivers/gpu/drm/xe/xe_memirq.c +3 -0
@@ -555,6 +555,7 @@ void xe_memirq_handler(struct xe_memirq *memirq)struct xe_hw_engine *hwe;enum xe_hw_engine_id id;struct iosys_map map; +unsigned long flags;unsigned int gtid;struct xe_gt *gt;
@@ -568,8 +569,10 @@ void xe_memirq_handler(struct xe_memirq *memirq)if (gt->tile != tile)continue ; +spin_lock_irqsave (&xe->irq.lock, flags);for_each_hw_engine (hwe, gt, id)xe_memirq_hwe_handler (memirq, hwe); +spin_unlock_irqrestore (&xe->irq.lock, flags); }/* GuC and media GuC (if present) must be checked separately */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 382/1005 drm/xe/guc: Protect timeout handling from device unplug
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Satyanarayana K V P <[email protected]>
[ Upstream commit 78945c8c44bb2cfd6e5d2f762535efce0cefb086 ]
The GuC scheduler timeout callback accesses device and GT state while handling a timed-out job. Guard the callback with drm_dev_enter() and drm_dev_exit() so device unplug waits for in-flight timeout handling. If unplug has already started, mark the job with -ENODEV and return it to the scheduler for cleanup.
--- drivers/gpu/drm/xe/xe_guc_submit.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/xe/xe_guc_submit.c +8 -0
@@ -1505,6 +1505,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)int err = -ETIME ;pid_t pid =-1 ;bool wedged = false, wedge_device = false, skip_timeout_check; +int idx;xe_gt_assert (guc_to_gt (guc), !exec_queue_destroyed (q));
@@ -1520,6 +1521,11 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job) vf_recovery(guc))return DRM_GPU_SCHED_STAT_NO_HANG ; +if (!drm_dev_enter (&xe->drm, &idx)) { +xe_sched_job_set_error (job, -ENODEV ); +return DRM_GPU_SCHED_STAT_NO_HANG ; + } +/* Kill the run_job entry point */ if (xe_exec_queue_is_multi_queue (q))xe_guc_exec_queue_group_stop (q);
@@ -1683,6 +1689,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)* We want the job added back to the pending list so it gets freed; this * is what DRM_GPU_SCHED_STAT_NO_HANG does. */ +drm_dev_exit (idx);return DRM_GPU_SCHED_STAT_NO_HANG ; rearm:
@@ -1696,6 +1703,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)else xe_sched_submission_start (sched); handle_vf_resume: +drm_dev_exit (idx);return DRM_GPU_SCHED_STAT_NO_HANG ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 383/1005 drm/xe/gt: Disable GT reset worker before engine teardown
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Satyanarayana K V P <[email protected]>
[ Upstream commit 31ac48502b2d2d953249c1cd1bf3d38667049a00 ]
During tear-down process, a reset queued from Guc timeout handler can still access hwe after hwe is freed. Register a separate devm action that disables and drains the reset worker, so it runs before any engine is torn down.
--- drivers/gpu/drm/xe/xe_gt.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_gt.c +22 -7
@@ -621,8 +621,21 @@ static int gt_init_with_gt_forcewake(struct xe_gt *gt)return 0 ; } +static void gt_reset_worker_disable (void *arg) +{ +struct xe_gt *gt = arg; + +if (disable_work_sync (>->reset.worker)) +/* +* If gt_reset_worker was halted from executing, take care of +* releasing the rpm reference here. +*/ +xe_pm_runtime_put (gt_to_xe (gt)); +} +static int gt_init_with_all_forcewake (struct xe_gt *gt) { +struct xe_device *xe =gt_to_xe (gt);int err;CLASS (xe_force_wake, fw_ref)(gt_to_fw (gt),XE_FORCEWAKE_ALL );
@@ -689,6 +702,11 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt)if (IS_SRIOV_PF (gt_to_xe (gt)))xe_gt_sriov_pf_init_hw (gt); +/* Last action registered here so devres drains resets before teardown */ + err =devm_add_action_or_reset (xe->drm.dev, gt_reset_worker_disable, gt); +if (err) +return err; +return 0 ; }
@@ -697,12 +715,7 @@ static void xe_gt_fini(void *arg)struct xe_gt *gt = arg;int i; -if (disable_work_sync (>->reset.worker)) -/* -* If gt_reset_worker was halted from executing, take care of -* releasing the rpm reference here. -*/ -xe_pm_runtime_put (gt_to_xe (gt)); +gt_reset_worker_disable (gt);for (i =0 ; i <XE_ENGINE_CLASS_MAX ; ++i)xe_hw_fence_irq_finish (>->fence_irq[i]);
@@ -745,8 +758,10 @@ int xe_gt_init(struct xe_gt *gt)xe_force_wake_init_engines (gt,gt_to_fw (gt)); err =gt_init_with_all_forcewake (gt); -if (err) +if (err) { +gt_reset_worker_disable (gt);return err; + }xe_gt_record_user_engines (gt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 384/1005 drm/xe/pcode: match argument naming with PCODE_DATAx
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michał Grzelak <[email protected]>
[ Upstream commit 68b966310260924a9dc6a5a96fd91cd190edbe2a ]
Variable naming of val and val1 should match register macro naming.
For xe, register macro naming of PCODE_DATA0 and PCODE_DATA1 is already synced with register name. Nevertheless there are still functions declaring val and val1. Rename val into val0 in functions declaring val1 in xe.
v4->v5
- clean changelog's versioning
v3->v4
- split i915 changes from xe (Jani)
v2->v3
- resolve conflict from rebase
v1->v2
- rebase onto drm-tip (Jani)
Bspec: 19978, 19979
Stable-dep-of: 94099304b80e ("drm/xe/hwmon: Fix pcode power limit handling")
--- drivers/gpu/drm/xe/display/xe_display_pcode.c | 4 ++-- drivers/gpu/drm/xe/xe_pcode.c | 4 ++-- drivers/gpu/drm/xe/xe_pcode.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/display/xe_display_pcode.c +2 -2
@@ -6,12 +6,12 @@#include "xe_device.h" #include "xe_pcode.h" -static int xe_display_pcode_read (struct drm_device *drm,u32 mbox,u32 *val,u32 *val1) +static int xe_display_pcode_read (struct drm_device *drm,u32 mbox,u32 *val0,u32 *val1) {struct xe_device *xe =to_xe_device (drm);struct xe_tile *tile =xe_device_get_root_tile (xe); -return xe_pcode_read (tile, mbox, val, val1); +return xe_pcode_read (tile, mbox, val0, val1); }static int xe_display_pcode_write_timeout (struct drm_device *drm,u32 mbox,u32 val,int timeout_ms)
drivers/gpu/drm/xe/xe_pcode.c +2 -2
@@ -136,12 +136,12 @@ int xe_pcode_write64_timeout(struct xe_tile *tile, u32 mbox, u32 data0, u32 datareturn err; } -int xe_pcode_read (struct xe_tile *tile,u32 mbox,u32 *val,u32 *val1) +int xe_pcode_read (struct xe_tile *tile,u32 mbox,u32 *val0,u32 *val1) {int err;mutex_lock (&tile->pcode.lock); - err =pcode_mailbox_rw (tile, mbox, val, val1,1 , true, false); + err =pcode_mailbox_rw (tile, mbox, val0, val1,1 , true, false);mutex_unlock (&tile->pcode.lock);return err;
drivers/gpu/drm/xe/xe_pcode.h +1 -1
@@ -23,7 +23,7 @@ int xe_pcode_probe_early(struct xe_device *xe);int xe_pcode_ready (struct xe_device *xe,bool locked);int xe_pcode_init_min_freq_table (struct xe_tile *tile,u32 min_gt_freq,u32 max_gt_freq); -int xe_pcode_read (struct xe_tile *tile,u32 mbox,u32 *val,u32 *val1); +int xe_pcode_read (struct xe_tile *tile,u32 mbox,u32 *val0,u32 *val1);int xe_pcode_write_timeout (struct xe_tile *tile,u32 mbox,u32 val,int timeout_ms); int xe_pcode_write64_timeout(struct xe_tile *tile, u32 mbox, u32 data0,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 385/1005 drm/xe/pcode: Increase default pcode mailbox timeout to 10ms
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karthik Poosa <[email protected]>
[ Upstream commit 8721a51d44733b8b5cb41fa1bfe7fac2cf55107b ]
The previous 1ms timeout may be insufficient for some mailbox commands, leading to spurious -ETIMEDOUT failures under load. Increase the default timeout to 10ms and introduce PCODE_DEFAULT_TIMEOUT_MS for a shared timeout definition, in line with pcode mailbox specification guidance.
Stable-dep-of: 94099304b80e ("drm/xe/hwmon: Fix pcode power limit handling")
--- drivers/gpu/drm/xe/xe_pcode.c | 2 +- drivers/gpu/drm/xe/xe_pcode.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_pcode.c +1 -1
@@ -141,7 +141,7 @@ int xe_pcode_read(struct xe_tile *tile, u32 mbox, u32 *val0, u32 *val1)int err;mutex_lock (&tile->pcode.lock); - err =pcode_mailbox_rw (tile, mbox, val0, val1,1 , true, false); + err =pcode_mailbox_rw (tile, mbox, val0, val1,PCODE_DEFAULT_TIMEOUT_MS , true, false);mutex_unlock (&tile->pcode.lock);return err;
drivers/gpu/drm/xe/xe_pcode.h +3 -1
@@ -18,6 +18,8 @@ struct xe_pcode_version {u32 engg; }; +#define PCODE_DEFAULT_TIMEOUT_MS 10 +int xe_pcode_init_early (struct xe_tile *tile);int xe_pcode_probe_early (struct xe_device *xe);int xe_pcode_ready (struct xe_device *xe,bool locked);
@@ -31,7 +33,7 @@ int xe_pcode_write64_timeout(struct xe_tile *tile, u32 mbox, u32 data0,int xe_get_pcode_version (struct xe_device *xe,struct xe_pcode_version *version);#define xe_pcode_write (tile, mbox, val) \ - xe_pcode_write_timeout(tile, mbox, val, 1) + xe_pcode_write_timeout(tile, mbox, val, PCODE_DEFAULT_TIMEOUT_MS)int xe_pcode_request (struct xe_tile *tile,u32 mbox,u32 request,u32 reply_mask,u32 reply,int timeout_ms);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 386/1005 drm/xe/hwmon: Use shared pcode default timeout for power limit write
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karthik Poosa <[email protected]>
[ Upstream commit 1a925ad51847db376fc0acd21fc5b76fb9c36cde ]
Drop the local PL_WRITE_MBX_TIMEOUT_MS macro and use the common PCODE_DEFAULT_TIMEOUT_MS for the power limit write mailbox command. This removes a duplicate timeout definition and keeps hwmon in sync with the pcode default (now 10ms).
Stable-dep-of: 94099304b80e ("drm/xe/hwmon: Fix pcode power limit handling")
--- drivers/gpu/drm/xe/xe_hwmon.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpu/drm/xe/xe_hwmon.c +1 -6
@@ -101,11 +101,6 @@ enum sensor_attr_power {#define PWR_ATTR_TO_STR (attr) (((attr) == hwmon_power_max) ? "PL1" : "PL2") -/* -* Timeout for power limit write mailbox command. -*/ -#define PL_WRITE_MBX_TIMEOUT_MS (1) -/* Index of memory controller in READ_THERMAL_DATA output */ #define TEMP_INDEX_MCTRL 2
@@ -252,7 +247,7 @@ static int xe_hwmon_pcode_rmw_power_limit(const struct xe_hwmon *hwmon, u32 attr (channel ==CHANNEL_CARD ) ?WRITE_PSYSGPU_POWER_LIMIT : WRITE_PACKAGE_POWER_LIMIT, 0), - val0, val1, PL_WRITE_MBX_TIMEOUT_MS); + val0, val1, PCODE_DEFAULT_TIMEOUT_MS);if (ret)drm_dbg (&hwmon->xe->drm,"write failed ch %d val0 0x%08x, val1 0x%08x, ret %d\n" , channel, val0, val1, ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 387/1005 drm/xe/hwmon: Fix pcode power limit handling
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karthik Poosa <[email protected]>
[ Upstream commit 94099304b80e8c6e842c2626f603930577938f3a ]
Return early on pcode read failure in xe_hwmon_pcode_rmw_power_limit() and propagate errors to callers.
Replace boot_power_limit_read with per-channel read_power_limit_from_pcode[], set on the first successful pcode write, so reads and writes stay consistent even if the default limit write at boot fails.
Also return PWR_LIM_EN for power label so card label visibility works.
v2: Move default power limit writes to helper
xe_hwmon_pcode_set_default_power_limits().
--- drivers/gpu/drm/xe/xe_hwmon.c | 84 +++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 29 deletions(-)
drivers/gpu/drm/xe/xe_hwmon.c +55 -29
@@ -165,8 +165,8 @@ struct xe_hwmon {struct xe_hwmon_energy_info ei[CHANNEL_MAX ];/** @fi: Fan info for fanN_input */ struct xe_hwmon_fan_info fi[FAN_MAX ]; -/** @boot_power_limit_read: is boot power limits read */ -bool boot_power_limit_read; +/** @read_power_limit_from_pcode: pcode accepted power limits write for the channel */ +bool read_power_limit_from_pcode[CHANNEL_MAX ];/** @pl1_on_boot: power limit PL1 on boot */ u32 pl1_on_boot[CHANNEL_MAX ];/** @pl2_on_boot: power limit PL2 on boot */
@@ -175,9 +175,9 @@ struct xe_hwmon {struct xe_hwmon_thermal_info temp; }; -static inline int prepare_power_limit_param2 (const struct xe_hwmon *hwmon) +static inline int prepare_power_limit_param2 (const struct xe_hwmon *hwmon,int channel) { -if (hwmon->boot_power_limit_read) { +if (hwmon->read_power_limit_from_pcode[channel]) {if (hwmon->xe->info.platform >=XE_CRESCENTISLAND )return READ_PL_ACCEPTED ;else
@@ -198,7 +198,8 @@ static int xe_hwmon_pcode_read_power_limit(const struct xe_hwmon *hwmon, u32 att (channel == CHANNEL_CARD) ? READ_PSYSGPU_POWER_LIMIT : READ_PACKAGE_POWER_LIMIT, - prepare_power_limit_param2(hwmon)), &val0, &val1); + prepare_power_limit_param2(hwmon, channel)), + &val0, &val1);if (ret) { drm_dbg(&hwmon->xe->drm, "read failed ch %d val0 0x%08x, val1 0x%08x, ret %d\n",
@@ -213,14 +214,14 @@ static int xe_hwmon_pcode_read_power_limit(const struct xe_hwmon *hwmon, u32 attelse if (attr ==PL2_HWMON_ATTR ) *uval = (val1 &PWR_LIM_EN ) ? val1 :0 ;else if (attr == hwmon_power_label) - *uval = (val0 &PWR_LIM_EN ) ?1 : (val1 &PWR_LIM_EN ) ?1 :0 ; + *uval = (val0 | val1) &PWR_LIM_EN ;else *uval =0 ;return ret; } -static int xe_hwmon_pcode_rmw_power_limit (const struct xe_hwmon *hwmon,u32 attr,u8 channel, +static int xe_hwmon_pcode_rmw_power_limit (struct xe_hwmon *hwmon,u32 attr,u8 channel,u32 clr,u32 set) {struct xe_tile *root_tile =xe_device_get_root_tile (hwmon->xe);
@@ -231,10 +232,13 @@ static int xe_hwmon_pcode_rmw_power_limit(const struct xe_hwmon *hwmon, u32 attr (channel == CHANNEL_CARD) ? READ_PSYSGPU_POWER_LIMIT : READ_PACKAGE_POWER_LIMIT, - prepare_power_limit_param2(hwmon)), &val0, &val1); -if (ret) -drm_dbg (&hwmon->xe->drm,"read failed ch %d val0 0x%08x, val1 0x%08x, ret %d\n" , + prepare_power_limit_param2(hwmon, channel)), + &val0, &val1); +if (ret) { +drm_err (&hwmon->xe->drm,"read failed ch %d val0 0x%08x, val1 0x%08x, ret %d\n" , channel, val0, val1, ret); +return ret; + }if (attr ==PL1_HWMON_ATTR ) val0 = (val0 & ~clr) | set;
@@ -248,9 +252,36 @@ static int xe_hwmon_pcode_rmw_power_limit(const struct xe_hwmon *hwmon, u32 attr WRITE_PSYSGPU_POWER_LIMIT : WRITE_PACKAGE_POWER_LIMIT, 0), val0, val1, PCODE_DEFAULT_TIMEOUT_MS); -if (ret) +if (ret) {drm_dbg (&hwmon->xe->drm,"write failed ch %d val0 0x%08x, val1 0x%08x, ret %d\n" , channel, val0, val1, ret); +return ret; + } + +/* Read from pcode once it holds a driver-written limit */ +if (!hwmon->read_power_limit_from_pcode[channel]) + hwmon->read_power_limit_from_pcode[channel] = true; + +return 0 ; +} + +static int xe_hwmon_pcode_set_default_power_limits (struct xe_hwmon *hwmon) +{ +int ret =0 ; + + ret |=xe_hwmon_pcode_rmw_power_limit (hwmon,PL1_HWMON_ATTR ,CHANNEL_CARD , +PWR_LIM |PWR_LIM_TIME , + hwmon->pl1_on_boot[CHANNEL_CARD ]); + ret |=xe_hwmon_pcode_rmw_power_limit (hwmon,PL1_HWMON_ATTR ,CHANNEL_PKG , +PWR_LIM |PWR_LIM_TIME , + hwmon->pl1_on_boot[CHANNEL_PKG ]); + ret |=xe_hwmon_pcode_rmw_power_limit (hwmon,PL2_HWMON_ATTR ,CHANNEL_CARD , +PWR_LIM |PWR_LIM_TIME , + hwmon->pl2_on_boot[CHANNEL_CARD ]); + ret |=xe_hwmon_pcode_rmw_power_limit (hwmon,PL2_HWMON_ATTR ,CHANNEL_PKG , +PWR_LIM |PWR_LIM_TIME , + hwmon->pl2_on_boot[CHANNEL_PKG ]); +return ret; }
@@ -394,7 +425,9 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, u32 attr, int channeif (hwmon->xe->info.has_mbx_power_limits) {drm_dbg (&hwmon->xe->drm,"disabling %s on channel %d\n" ,PWR_ATTR_TO_STR (attr), channel); -xe_hwmon_pcode_rmw_power_limit (hwmon, attr, channel,PWR_LIM_EN ,0 ); + ret =xe_hwmon_pcode_rmw_power_limit (hwmon, attr, channel,PWR_LIM_EN ,0 ); +if (ret) + goto unlock;xe_hwmon_pcode_read_power_limit (hwmon, attr, channel, ®_val); }else { reg_val =xe_mmio_rmw32 (mmio, rapl_limit,PWR_LIM_EN ,0 );
@@ -655,15 +688,19 @@ xe_hwmon_power_max_interval_store(struct device *dev, struct device_attribute *amutex_lock (&hwmon->hwmon_lock); -if (hwmon->xe->info.has_mbx_power_limits) -xe_hwmon_pcode_rmw_power_limit (hwmon, power_attr, channel,PWR_LIM_TIME , rxy); -else + ret = count; +if (hwmon->xe->info.has_mbx_power_limits) { + ret =xe_hwmon_pcode_rmw_power_limit (hwmon, power_attr, channel,PWR_LIM_TIME , rxy); +if (!ret) + ret = count; + }else { r =xe_mmio_rmw32 (mmio,xe_hwmon_get_reg (hwmon,REG_PKG_RAPL_LIMIT , channel),PWR_LIM_TIME , rxy); + }mutex_unlock (&hwmon->hwmon_lock); -return count; +return ret; }/* PSYS PL1 */
@@ -1487,22 +1524,11 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon) }else {drm_info (&hwmon->xe->drm,"Using mailbox commands for power limits\n" );/* Write default limits to read from pcode from now on. */ -xe_hwmon_pcode_rmw_power_limit (hwmon,PL1_HWMON_ATTR , -CHANNEL_CARD ,PWR_LIM |PWR_LIM_TIME , - hwmon->pl1_on_boot[CHANNEL_CARD ]); -xe_hwmon_pcode_rmw_power_limit (hwmon,PL1_HWMON_ATTR , -CHANNEL_PKG ,PWR_LIM |PWR_LIM_TIME , - hwmon->pl1_on_boot[CHANNEL_PKG ]); -xe_hwmon_pcode_rmw_power_limit (hwmon,PL2_HWMON_ATTR , -CHANNEL_CARD ,PWR_LIM |PWR_LIM_TIME , - hwmon->pl2_on_boot[CHANNEL_CARD ]); -xe_hwmon_pcode_rmw_power_limit (hwmon,PL2_HWMON_ATTR , -CHANNEL_PKG ,PWR_LIM |PWR_LIM_TIME , - hwmon->pl2_on_boot[CHANNEL_PKG ]); +if (xe_hwmon_pcode_set_default_power_limits (hwmon)) +drm_warn (&hwmon->xe->drm,"Failed to set default power limits\n" ); hwmon->scl_shift_power =PWR_UNIT ; hwmon->scl_shift_energy =ENERGY_UNIT ; hwmon->scl_shift_time =TIME_UNIT ; - hwmon->boot_power_limit_read = true; } }else {drm_info (&hwmon->xe->drm,"Using register for power limits\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 388/1005 drm/xe/hwmon: Decode mailbox temperature as sign-magnitude
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karthik Poosa <[email protected]>
[ Upstream commit c9d8ef7f6835ddfca8259c322804038799be5641 ]
The mailbox temperature is an 8-bit sign-magnitude value (bit 7 sign, bits 6:0 magnitude, range -127..127), not two's-complement. Casting the raw byte to s8 decodes negative readings incorrectly.
Add mbx_temp_decode(), store the raw byte as u8, and use it in get_mc_temp() and get_pcie_temp() so temperatures are decoded correctly.
--- drivers/gpu/drm/xe/xe_hwmon.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_hwmon.c +16 -4
@@ -104,6 +104,10 @@ enum sensor_attr_power {/* Index of memory controller in READ_THERMAL_DATA output */ #define TEMP_INDEX_MCTRL 2 +/* Mailbox temperature is sign-magnitude: bit 7 sign, bits 6:0 magnitude. */ +#define TEMP_MBX_SIGN BIT(7) +#define TEMP_MBX_MAG GENMASK(6, 0) +/* Maximum characters in hwmon label name */ #define MAX_LABEL_SIZE 16
@@ -139,8 +143,8 @@ struct xe_hwmon_thermal_info { };/** @count: no of temperature sensors available for the platform */ u8 count; -/** @value: signed value from each sensor */ -s8 value[U8_MAX ]; +/** @value: per-sensor raw mailbox temperature; bit7=sign, bits6:0=magnitude */ +u8 value[U8_MAX ];/** @vram_label: vram label names */ char vram_label[MAX_VRAM_CHANNELS ][MAX_LABEL_SIZE ]; };
@@ -821,6 +825,14 @@ static int xe_hwmon_pcode_read_thermal_info(struct xe_hwmon *hwmon)return ret; } +/* Decode an 8-bit sign-magnitude mailbox temperature to degrees Celsius. */ +static int mbx_temp_decode (u8 value) +{ +int temp = value &TEMP_MBX_MAG ; + +return (value &TEMP_MBX_SIGN ) ? -temp : temp; +} +static int get_mc_temp (struct xe_hwmon *hwmon,long *val) {struct xe_tile *root_tile =xe_device_get_root_tile (hwmon->xe);
@@ -837,7 +849,7 @@ static int get_mc_temp(struct xe_hwmon *hwmon, long *val) }for (i =TEMP_INDEX_MCTRL ; i < hwmon->temp.count -1 ; i++) - average += hwmon->temp.value[i]; + average +=mbx_temp_decode (hwmon->temp.value[i]); average /= (hwmon->temp.count -TEMP_INDEX_MCTRL -1 ); *val = average *MILLIDEGREE_PER_DEGREE ;
@@ -860,7 +872,7 @@ static int get_pcie_temp(struct xe_hwmon *hwmon, long *val) data =REG_FIELD_GET (PCIE_SENSOR_MASK , data); data =REG_FIELD_GET (TEMP_MASK , data); - *val = (s8 )data *MILLIDEGREE_PER_DEGREE ; + *val =mbx_temp_decode (data) *MILLIDEGREE_PER_DEGREE ;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 389/1005 drm/xe/hwmon: Fix thermal sensor data handling
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karthik Poosa <[email protected]>
[ Upstream commit d37dcdaa99b18995d74c2381b103e308f21e2565 ]
Read all required thermal groups in get_mc_temp() and store them in a dword-aligned buffer, avoiding unaligned pcode accesses and ensuring correct memory controller temperature reporting.
Store the pcode thermal data and thermal limit words as little-endian, so their per-byte views match the hardware layout on big-endian hosts.
--- drivers/gpu/drm/xe/xe_hwmon.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_hwmon.c +21 -12
@@ -138,13 +138,17 @@ struct xe_hwmon_thermal_info {union {/** @limit: temperatures limits */ u8 limit[TEMP_LIMIT_MAX ]; -/** @data: temperature limits in dwords */ -u32 data[DIV_ROUND_UP (TEMP_LIMIT_MAX ,sizeof (u32))]; +/** @data: temperature limits as little-endian dwords */ +__le32 data[DIV_ROUND_UP (TEMP_LIMIT_MAX ,sizeof (u32))]; };/** @count: no of temperature sensors available for the platform */ u8 count; -/** @value: per-sensor raw mailbox temperature; bit7=sign, bits6:0=magnitude */ -u8 value[U8_MAX ]; +union { +/** @value: per-sensor raw mailbox temperature; bit7=sign, bits6:0=magnitude */ +u8 value[U8_MAX +1 ]; +/** @dword: sensor values as little-endian dwords, u32-aligned for pcode reads */ +__le32 dword[DIV_ROUND_UP (U8_MAX +1 ,sizeof (u32))]; + };/** @vram_label: vram label names */ char vram_label[MAX_VRAM_CHANNELS ][MAX_LABEL_SIZE ]; };
@@ -803,16 +807,17 @@ static const struct hwmon_channel_info * const hwmon_info[] = {static int xe_hwmon_pcode_read_thermal_info (struct xe_hwmon *hwmon) {struct xe_tile *root_tile =xe_device_get_root_tile (hwmon->xe); -u32 config =0 ; +u32 config =0 , data0 =0 , data1 =0 ;int ret; ret =xe_pcode_read (root_tile,PCODE_MBOX (PCODE_THERMAL_INFO ,READ_THERMAL_LIMITS ,0 ), - &hwmon->temp.data[0 ], &hwmon->temp.data[1 ]); + &data0, &data1);if (ret)return ret; -drm_dbg (&hwmon->xe->drm,"thermal info read val 0x%x val1 0x%x\n" , - hwmon->temp.data[0 ], hwmon->temp.data[1 ]); +drm_dbg (&hwmon->xe->drm,"thermal info read val 0x%x val1 0x%x\n" , data0, data1); + hwmon->temp.data[0 ] =cpu_to_le32 (data0); + hwmon->temp.data[1 ] =cpu_to_le32 (data1); ret =xe_pcode_read (root_tile,PCODE_MBOX (PCODE_THERMAL_INFO ,READ_THERMAL_CONFIG ,0 ), &config,NULL );
@@ -836,16 +841,20 @@ static int mbx_temp_decode(u8 value)static int get_mc_temp (struct xe_hwmon *hwmon,long *val) {struct xe_tile *root_tile =xe_device_get_root_tile (hwmon->xe); -u32 *dword = (u32 *)hwmon->temp.value;s32 average =0 ;int ret, i; -for (i =0 ; i <DIV_ROUND_UP (TEMP_LIMIT_MAX ,sizeof (u32)); i++) { +guard (mutex)(&hwmon->hwmon_lock); + +for (i =0 ; i <DIV_ROUND_UP (hwmon->temp.count,sizeof (u32)); i++) { +u32 data =0 ; + ret =xe_pcode_read (root_tile,PCODE_MBOX (PCODE_THERMAL_INFO ,READ_THERMAL_DATA , i), - (dword + i),NULL ); + &data,NULL );if (ret)return ret; -drm_dbg (&hwmon->xe->drm,"thermal data for group %d val 0x%x\n" , i, dword[i]); +drm_dbg (&hwmon->xe->drm,"thermal data for group %d val 0x%x\n" , i, data); + hwmon->temp.dword[i] =cpu_to_le32 (data); }for (i =TEMP_INDEX_MCTRL ; i < hwmon->temp.count -1 ; i++)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 390/1005 drm/xe/hwmon: Add helpers to validate thermal sensor readings
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karthik Poosa <[email protected]>
[ Upstream commit f2a144e9891b397aebcfc0e88906c29bc079322d ]
Add mmio_temp_valid() and mbx_temp_valid() to check whether a temperature sensor reading is valid. An MMIO value of 0xFFFFFFFF or a mailbox value of 0xFF indicates the sensor is unavailable.
Gate these checks behind has_temp_sentinel, enabled on CRI currently.
Stable-dep-of: dbd199c775cb ("drm/xe/hwmon: Handle unavailable memory controller sensors")
--- drivers/gpu/drm/xe/xe_device_types.h | 2 ++ drivers/gpu/drm/xe/xe_hwmon.c | 27 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_pci.c | 2 ++ drivers/gpu/drm/xe/xe_pci_types.h | 1 + 4 files changed, 32 insertions(+)
drivers/gpu/drm/xe/xe_device_types.h +2 -0
@@ -219,6 +219,8 @@ struct xe_device { u8 has_sriov:1;/** @info.has_sysctrl: Supports System Controller */ u8 has_sysctrl:1; +/** @info.has_temp_sentinel: Device has temperature-unavailable sentinels */ + u8 has_temp_sentinel:1;/** @info.has_usm: Device has unified shared memory support */ u8 has_usm:1;/** @info.has_64bit_timestamp: Device supports 64-bit timestamps */
drivers/gpu/drm/xe/xe_hwmon.c +27 -0
@@ -104,6 +104,9 @@ enum sensor_attr_power {/* Index of memory controller in READ_THERMAL_DATA output */ #define TEMP_INDEX_MCTRL 2 +/* Mailbox sentinel reported for an unavailable temperature sensor */ +#define TEMP_MBX_INVALID 0xFF +/* Mailbox temperature is sign-magnitude: bit 7 sign, bits 6:0 magnitude. */ #define TEMP_MBX_SIGN BIT(7)#define TEMP_MBX_MAG GENMASK(6, 0)
@@ -830,6 +833,30 @@ static int xe_hwmon_pcode_read_thermal_info(struct xe_hwmon *hwmon)return ret; } +static inline bool mmio_temp_valid (const struct xe_hwmon *hwmon,u32 value) +{ +/* +* On platforms lacking temperature sentinel support, a value of 0 is treated +* as invalid. While 0°C is theoretically possible, it is highly unlikely for +* a discrete GPU in normal environments, making it a reasonable fallback +* indicator for invalid or uninitialized temperature readings. +* All-ones is returned when the device is off the bus, so reject it too. +*/ +if (value ==U32_MAX ) +return false; + +return hwmon->xe->info.has_temp_sentinel || value !=0 ; +} + +/* Mailbox temperature is sign-magnitude (bit 7 sign, bits 6:0 magnitude). */ +static inline bool mbx_temp_valid (const struct xe_hwmon *hwmon,u8 value) +{ +if (value ==TEMP_MBX_INVALID ) +return false; + +return hwmon->xe->info.has_temp_sentinel || value !=0 ; +} +/* Decode an 8-bit sign-magnitude mailbox temperature to degrees Celsius. */ static int mbx_temp_decode (u8 value) {
drivers/gpu/drm/xe/xe_pci.c +2 -0
@@ -483,6 +483,7 @@ static const struct xe_device_desc cri_desc = { .has_soc_remapper_telem = true, .has_sriov = true, .has_sysctrl = true, + .has_temp_sentinel = true, .max_gt_per_tile =2 ,MULTI_LRC_MASK , .require_force_probe = true,
@@ -814,6 +815,7 @@ static int xe_info_init_early(struct xe_device *xe, xe->info.has_sriov =xe_configfs_primary_gt_allowed (to_pci_dev (xe->drm.dev)) && desc->has_sriov; xe->info.has_sysctrl = desc->has_sysctrl; + xe->info.has_temp_sentinel = desc->has_temp_sentinel; xe->info.skip_guc_pc = desc->skip_guc_pc; xe->info.skip_pcode = desc->skip_pcode; xe->info.needs_scratch = desc->needs_scratch;
drivers/gpu/drm/xe/xe_pci_types.h +1 -0
@@ -60,6 +60,7 @@ struct xe_device_desc { u8 has_soc_remapper_telem:1; u8 has_sriov:1; u8 has_sysctrl:1; + u8 has_temp_sentinel:1; u8 needs_scratch:1; u8 skip_guc_pc:1; u8 skip_pcode:1;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/1005 drm/xe/hwmon: Handle unavailable memory controller sensors
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karthik Poosa <[email protected]>
[ Upstream commit dbd199c775cbedbd1acaff96e1d7f4c398e558d9 ]
Skip memory controller sensors that report invalid readings when computing the average temperature in get_mc_temp(). Return -ENXIO when no valid sensor data is available, and allow the helper to be used as an availability probe by making the output parameter optional.
--- drivers/gpu/drm/xe/xe_hwmon.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_hwmon.c +16 -4
@@ -868,8 +868,8 @@ static int mbx_temp_decode(u8 value)static int get_mc_temp (struct xe_hwmon *hwmon,long *val) {struct xe_tile *root_tile =xe_device_get_root_tile (hwmon->xe); +int ret, i, count =0 ;s32 average =0 ; -int ret, i;guard (mutex)(&hwmon->hwmon_lock);
@@ -884,11 +884,23 @@ static int get_mc_temp(struct xe_hwmon *hwmon, long *val) hwmon->temp.dword[i] =cpu_to_le32 (data); } -for (i =TEMP_INDEX_MCTRL ; i < hwmon->temp.count -1 ; i++) +for (i =TEMP_INDEX_MCTRL ; i < hwmon->temp.count -1 ; i++) { +if (!mbx_temp_valid (hwmon, hwmon->temp.value[i])) +continue ; average +=mbx_temp_decode (hwmon->temp.value[i]); + count++; + } + +if (!count) { +drm_dbg (&hwmon->xe->drm,"Memory controller temperature unavailable!\n" ); +return -ENXIO ; + } + + average /= count; + +if (val) + *val = average *MILLIDEGREE_PER_DEGREE ; - average /= (hwmon->temp.count -TEMP_INDEX_MCTRL -1 ); - *val = average *MILLIDEGREE_PER_DEGREE ;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/1005 drm/xe/tuning: Restrict Anyhit NULL-query tuning to render engines
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nitin Gote <[email protected]>
[ Upstream commit ddef200c67d445f978f323d947c8993570ae4756 ]
The "Disable NULL query for Anyhit Shader" tuning uses xe_rtp_match_first_render_or_compute to program RT_CTRL once per GT. On a GT with no render (RCS) engine, that match falls back to a compute (CCS) engine instead, so the tuning is still written even though RT_CTRL's ray-tracing logic has no hardware behind it there.
A CRI compute-only GT hits exactly this path, causing igt@xe_debugfs@check-gt-reg-sr to report a save-restore mismatch:
Mismatch on 0xe530, expected 0x400 got 0x0
Restrict the rule to ENGINE_CLASS(RENDER) so it only applies where ray-tracing hardware is actually present. Every other in-tree platform in this version range (BMG, LNL, PTL, NVL) always has a render engine, which xe_rtp_match_first_render_or_compute already resolves ahead of any compute engine, so this is a no-op for them.
--- drivers/gpu/drm/xe/xe_tuning.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_tuning.c +1 -1
@@ -116,7 +116,7 @@ static const struct xe_rtp_table_sr engine_tunings = XE_RTP_TABLE_SR( }, {XE_RTP_NAME ("Tuning: Disable NULL query for Anyhit Shader" ),XE_RTP_RULES (GRAPHICS_VERSION_RANGE (2000 ,XE_RTP_END_VERSION_UNDEFINED ), -FUNC (xe_rtp_match_first_render_or_compute)), +ENGINE_CLASS (RENDER )),XE_RTP_ACTIONS (SET (RT_CTRL ,DIS_NULL_QUERY )) }, { XE_RTP_NAME("Tuning: disable HW reporting of ctx switch to GHWSP"),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/1005 drm/xe/gsc: Fix NVL-S GSC compatibility number
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniele Ceraolo Spurio <[email protected]>
[ Upstream commit f8795bced27bb00d74cef9de33e8a5e939c05e02 ]
The compatibility number for the published GSC number is 1.0. The binary is correctly named nvl_gsc_1.bin (matching the major compatibility version number), but the driver is instead looking for compatibility 0.0 (which maps to nvl_gsc_0.bin), leading to the binary not being found.
The driver supports running without GSC so this is not fatal, but all content protection features will not work without the GSC FW.
--- drivers/gpu/drm/xe/xe_uc_fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_uc_fw.c +1 -1
@@ -141,7 +141,7 @@ struct fw_blobs_by_type {/* for the GSC FW we match the compatibility version and not the release one */ #define XE_GSC_FIRMWARE_DEFS (fw_def, major_ver) \ - fw_def(NOVALAKE_S, GT_TYPE_ANY, major_ver(xe, gsc, nvl, 108, 0, 0)) \ + fw_def(NOVALAKE_S, GT_TYPE_ANY, major_ver(xe, gsc, nvl, 108, 1, 0)) \ fw_def(PANTHERLAKE, GT_TYPE_ANY, major_ver(xe, gsc, ptl, 105, 1, 0)) \ fw_def(LUNARLAKE, GT_TYPE_ANY, major_ver(xe, gsc, lnl, 104, 1, 0)) \ fw_def(METEORLAKE, GT_TYPE_ANY, major_ver(i915, gsc, mtl, 102, 1, 0))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/1005 drm/xe/lrc: Restore CTX_CS_INDIRECT_CTX_OFFSET programming for pre-Xe2
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helen Koike <[email protected]>
[ Upstream commit badac1974e098dba1a0a7f413e53f5b6ae24ab10 ]
CTX_CS_INDIRECT_CTX_OFFSET default value is not retrieved from the GPU by inhibit+context save mechanism since it is not part of the Engine Context. Thus, at restore, 0x0 is programmed back to the GPU, which is an invalid value according to the PRM.
This causes sporadic hangs on Alder Lake when executing test IntelAngleEnd2EndTestCases (error VK_DEVICE_LOST).
Fix it by partially reverting commit c9dfd66cb91e ("drm/xe/lrc: Allow INDIRECT_CTX for more engine classes"). Re-add the programming of CTX_CS_INDIRECT_CTX_OFFSET for pre-Xe2 (in theory it should apply to all platforms, but we got an unexpected behaviour on Xe2 that still requires investigation).
--- drivers/gpu/drm/xe/regs/xe_lrc_layout.h | 3 +++ drivers/gpu/drm/xe/xe_lrc.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/regs/xe_lrc_layout.h +3 -0
@@ -43,4 +43,7 @@#define INDIRECT_CTX_RING_START_UDW (0x08 + 1)#define INDIRECT_CTX_RING_CTL (0x0a + 1) +#define CTX_INDIRECT_CTX_OFFSET_MASK REG_GENMASK(15, 6) +#define CTX_INDIRECT_CTX_OFFSET_DEFAULT REG_FIELD_PREP(CTX_INDIRECT_CTX_OFFSET_MASK, 0xd) +#endif
drivers/gpu/drm/xe/xe_lrc.c +4 -4
@@ -1461,15 +1461,15 @@ setup_indirect_ctx(struct xe_lrc *lrc, struct xe_hw_engine *hwe)finish_bo (&state);kfree (state.buffer); -/* -* Enable INDIRECT_CTX leaving INDIRECT_CTX_OFFSET at its default: it -* varies per engine class, but the default is good enough -*/ xe_lrc_write_ctx_reg (lrc,CTX_CS_INDIRECT_CTX , (xe_bo_ggtt_addr (lrc->bo) + state.offset) |/* Size in CLs. */ (state.written *sizeof (u32) /64 )); +if (GRAPHICS_VER (lrc_to_xe (lrc)) <20 ) +xe_lrc_write_ctx_reg (lrc, +CTX_CS_INDIRECT_CTX_OFFSET , +CTX_INDIRECT_CTX_OFFSET_DEFAULT );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/1005 drm/xe: Fix build with DRM_XE=y and CONFIGFS_FS=m
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rodrigo Vivi <[email protected]>
[ Upstream commit da475c094342b6d5c8bc020b19d6900130bed047 ]
When xe is built-in but configfs is a module, xe_configfs.o is not linked into xe, while IS_ENABLED(CONFIG_CONFIGFS_FS) in xe_configfs.h still exposes the real declarations, leading to undefined references.
Use IS_REACHABLE() so this case falls back to the stubs, the same as CONFIGFS_FS=n.
--- drivers/gpu/drm/xe/xe_configfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_configfs.h +1 -1
@@ -14,7 +14,7 @@struct pci_dev ; -#if IS_ENABLED (CONFIG_CONFIGFS_FS ) +#if IS_REACHABLE (CONFIG_CONFIGFS_FS )int xe_configfs_init (void );void xe_configfs_exit (void );void xe_configfs_check_device (struct pci_dev *pdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/1005 drm/xe/gt: Use GT ordered workqueue for wedging
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raag Jadav <[email protected]>
[ Upstream commit 8801081e5991e4939dc2d04564c46f33c3efe18d ]
Currently, xe_gt_declare_wedged() stops GuC CT and initiates exec queue teardown synchronously. This can result in tdr timeout in cases where the device is declared wedged while jobs are still in-flight.
Introduce a worker for GT specific wedge handling and queue the teardown on GT ordered workqueue, so we don't disrupt the scheduler while jobs are still in-flight.
While at it, introduce for_each_initialized_gt() macro and use it for wedging GT. This helps avoid races in case the device is declared wedged in probe sequence before GT is initialized.
--- drivers/gpu/drm/xe/xe_device.c | 2 +- drivers/gpu/drm/xe/xe_device.h | 4 ++++ drivers/gpu/drm/xe/xe_gt.c | 39 ++++++++++++++++++++++++-------- drivers/gpu/drm/xe/xe_gt_types.h | 9 ++++++++ drivers/gpu/drm/xe/xe_guc.c | 1 - 5 files changed, 44 insertions(+), 11 deletions(-)
drivers/gpu/drm/xe/xe_device.c +1 -1
@@ -1482,7 +1482,7 @@ void xe_device_declare_wedged(struct xe_device *xe) dev_name(xe->drm.dev)); } -for_each_gt (gt, xe, id) +for_each_initialized_gt (gt, xe, id)xe_gt_declare_wedged (gt);if (xe_device_wedged (xe)) {
drivers/gpu/drm/xe/xe_device.h +4 -0
@@ -139,6 +139,10 @@ static inline bool xe_device_uc_enabled(struct xe_device *xe) for_each_gt((gt__), (tile__)->xe, (id__)) \ for_each_if((gt__)->tile == (tile__)) +#define for_each_initialized_gt (gt__, xe__, id__) \ + for_each_gt((gt__), (xe__), (id__)) \ + for_each_if(READ_ONCE((gt__)->initialized)) +static inline struct xe_force_wake *gt_to_fw (struct xe_gt *gt) {return >->pm.fw;
drivers/gpu/drm/xe/xe_gt.c +30 -9
@@ -172,6 +172,7 @@ static void xe_gt_enable_comp_1wcoh(struct xe_gt *gt) }static void gt_reset_worker (struct work_struct *w); +static void gt_wedge_worker (struct work_struct *w);static int emit_job_sync (struct xe_exec_queue *q,struct xe_bb *bb,long timeout_jiffies,bool force_reset)
@@ -543,6 +544,8 @@ int xe_gt_init_early(struct xe_gt *gt)xe_gt_mcr_init_early (gt);xe_pat_init (gt); +INIT_WORK (>->reset.worker, gt_reset_worker); +INIT_WORK (>->wedge.worker, gt_wedge_worker);return 0 ; }
@@ -621,16 +624,21 @@ static int gt_init_with_gt_forcewake(struct xe_gt *gt)return 0 ; } -static void gt_reset_worker_disable (void *arg) +static void gt_worker_disable (void *arg) {struct xe_gt *gt = arg; +WRITE_ONCE (gt->initialized, false); +if (disable_work_sync (>->reset.worker))/* * If gt_reset_worker was halted from executing, take care of * releasing the rpm reference here. */ xe_pm_runtime_put (gt_to_xe (gt)); + +if (disable_work_sync (>->wedge.worker)) +xe_pm_runtime_put (gt_to_xe (gt)); }static int gt_init_with_all_forcewake (struct xe_gt *gt)
@@ -703,7 +711,7 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt)xe_gt_sriov_pf_init_hw (gt);/* Last action registered here so devres drains resets before teardown */ - err =devm_add_action_or_reset (xe->drm.dev, gt_reset_worker_disable, gt); + err =devm_add_action_or_reset (xe->drm.dev, gt_worker_disable, gt);if (err)return err;
@@ -715,7 +723,7 @@ static void xe_gt_fini(void *arg)struct xe_gt *gt = arg;int i; -gt_reset_worker_disable (gt); +gt_worker_disable (gt);for (i =0 ; i <XE_ENGINE_CLASS_MAX ; ++i)xe_hw_fence_irq_finish (>->fence_irq[i]);
@@ -728,8 +736,6 @@ int xe_gt_init(struct xe_gt *gt)int err;int i; -INIT_WORK (>->reset.worker, gt_reset_worker); -for (i =0 ; i <XE_ENGINE_CLASS_MAX ; ++i) { gt->ring_ops[i] =xe_ring_ops_get (gt, i);xe_hw_fence_irq_init (>->fence_irq[i]);
@@ -759,7 +765,7 @@ int xe_gt_init(struct xe_gt *gt) err =gt_init_with_all_forcewake (gt);if (err) { -gt_reset_worker_disable (gt); +gt_worker_disable (gt);return err; }
@@ -775,6 +781,8 @@ int xe_gt_init(struct xe_gt *gt)return err; } +/* Must be last */ +WRITE_ONCE (gt->initialized, true);return 0 ; }
@@ -1192,6 +1200,15 @@ struct xe_hw_engine *xe_gt_any_hw_engine(struct xe_gt *gt)return NULL ; } +static void gt_wedge_worker (struct work_struct *w) +{ +struct xe_gt *gt =container_of (w,typeof (*gt), wedge.worker); + +xe_uc_declare_wedged (>->uc); +xe_tlb_inval_reset (>->tlb_inval); +xe_pm_runtime_put (gt_to_xe (gt)); +} +/** * xe_gt_declare_wedged() - Declare GT wedged * @gt: the GT object
@@ -1201,8 +1218,12 @@ struct xe_hw_engine *xe_gt_any_hw_engine(struct xe_gt *gt)*/ void xe_gt_declare_wedged (struct xe_gt *gt) { -xe_gt_assert (gt,gt_to_xe (gt)->wedged.mode); +struct xe_device *xe =gt_to_xe (gt); -xe_uc_declare_wedged (>->uc); -xe_tlb_inval_reset (>->tlb_inval); +xe_gt_assert (gt, xe->wedged.mode); +xe_uc_reset_prepare (>->uc); + +xe_pm_runtime_get_noresume (xe); +if (!queue_work (gt->ordered_wq, >->wedge.worker)) +xe_pm_runtime_put (xe); }
drivers/gpu/drm/xe/xe_gt_types.h +9 -0
@@ -213,6 +213,12 @@ struct xe_gt {struct work_struct worker; } reset; +/** @wedge: state for GT wedge */ +struct { +/** @wedge.worker: worker for GT wedge to be done async */ +struct work_struct worker; + } wedge; +/** @tlb_inval: TLB invalidation state */ struct xe_tlb_inval tlb_inval;
@@ -390,6 +396,9 @@ struct xe_gt {/** @eu_stall: EU stall counters subsystem per gt info */ struct xe_eu_stall_gt *eu_stall; + +/** @initialized: GT is initialized */ + bool initialized; };#endif
drivers/gpu/drm/xe/xe_guc.c +0 -1
@@ -1837,7 +1837,6 @@ void xe_guc_declare_wedged(struct xe_guc *guc) {xe_gt_assert (guc_to_gt (guc),guc_to_xe (guc)->wedged.mode); -xe_guc_reset_prepare (guc);xe_guc_ct_stop (&guc->ct);xe_guc_submit_wedge (guc); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/1005 drm/xe/hw_error: Guard csc_hw_error_work() with runtime PM
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raag Jadav <[email protected]>
[ Upstream commit a890a885b982f73e6e984e828ffda06b5121c4b6 ]
xe_device_declare_wedged() callers are expected to hold a runtime PM reference. Fix it.
--- drivers/gpu/drm/xe/xe_hw_error.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/xe/xe_hw_error.c +2 -0
@@ -14,6 +14,7 @@#include "xe_drm_ras.h" #include "xe_hw_error.h" #include "xe_mmio.h" +#include "xe_pm.h" #include "xe_survivability_mode.h" #define GT_HW_ERROR_MAX_ERR_BITS 16
@@ -170,6 +171,7 @@ static void csc_hw_error_work(struct work_struct *work)struct xe_tile *tile =container_of (work,typeof (*tile), csc_hw_error_work);struct xe_device *xe =tile_to_xe (tile); +guard (xe_pm_runtime)(xe);xe_survivability_mode_runtime_enable (xe); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/1005 drm/xe: Move xe_device_wedged_fini() registration to xe_device_probe_early()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raag Jadav <[email protected]>
[ Upstream commit 031cc955b33b0d171fe50c870a9e601e80f14cea ]
The device can be declared wedged while processing boot-time hardware errors, which can result in PM reference leak if driver probe fails before xe_device_wedged_fini() is registered.
Early register the required cleanup action and fix this.
--- drivers/gpu/drm/xe/xe_device.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_device.c +6 -4
@@ -760,6 +760,8 @@ static int xe_device_vram_alloc(struct xe_device *xe)return 0 ; } +static void xe_device_wedged_fini (struct drm_device *drm,void *arg); +/** * xe_device_probe_early: Device early probe * @xe: xe device instance
@@ -828,6 +830,10 @@ int xe_device_probe_early(struct xe_device *xe)if (err)return err; + err =drmm_add_action_or_reset (&xe->drm, xe_device_wedged_fini, xe); +if (err) +return err; +return 0 ; }ALLOW_ERROR_INJECTION (xe_device_probe_early,ERRNO );/* See xe_pci_probe() */
@@ -1148,10 +1154,6 @@ int xe_device_probe(struct xe_device *xe)detect_preproduction_hw (xe); - err =drmm_add_action_or_reset (&xe->drm, xe_device_wedged_fini, xe); -if (err) - goto err_unregister_display; -/* * Process and log any errors detected by hardware. Possible results can * include declaring the device as wedged, which must be done only after
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/1005 drm/xe/pci_error: Flush GT wedge worker before bus reset
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raag Jadav <[email protected]>
[ Upstream commit 1eb526467c96ddaf87791c2b3cefa9f93ff45358 ]
With GT wedging now done async, make sure the wedge worker is flushed to avoid side-effects during PCI bus reset.
--- drivers/gpu/drm/xe/xe_pci_error.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_pci_error.c +3 -1
@@ -29,8 +29,10 @@ static void prepare_device_for_reset(struct pci_dev *pdev)xe_device_set_in_reset (xe); -for_each_gt (gt, xe, id) +for_each_gt (gt, xe, id) {xe_gt_declare_wedged (gt); +flush_work (>->wedge.worker); + }pci_disable_device (pdev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/1005 drm/xe: Rebind BOs evicted before the first LR queue
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arvind Yadav <[email protected]>
[ Upstream commit b52dcc698250e08eabdc4554a6fdb4d6f909133f ]
A VM bind can evict BOs before the first LR exec queue is added. There is no preempt fence to trigger at that point.
When the queue is added later, its new preempt fence is not triggered. The exec IOCTL does not validate or rebind BOs in preempt fence mode, and the rebind worker skips that work because no preempt fence is waiting. The first exec can then use stale mappings.
Trigger the new preempt fence in xe_vm_add_compute_exec_queue() when the VM has evicted BOs or pending rebinds. This keeps the queue suspended until the rebind worker validates the BOs and restores their mappings.
--- drivers/gpu/drm/xe/xe_vm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_vm.c +8 -1
@@ -269,8 +269,15 @@ int xe_vm_add_compute_exec_queue(struct xe_vm *vm, struct xe_exec_queue *q)* Check to see if a preemption on VM is in flight or userptr * invalidation, if so trigger this preempt fence to sync state with * other preempt fences on the VM. +* +* Also trigger it if eviction or rebinding is pending. BOs evicted +* before the first exec queue was added had no preempt fence to +* trigger. Suspend this queue until the rebind worker restores +* the mappings. */ - wait =__xe_vm_userptr_needs_repin (vm) ||preempt_fences_waiting (vm); + wait =__xe_vm_userptr_needs_repin (vm) ||preempt_fences_waiting (vm) || + !list_empty (&vm->gpuvm.evict.list) || + !list_empty (&vm->rebind_list);if (wait)dma_fence_enable_signaling (pfence);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/1005 drm/xe: Toggle the D3Cold enable flag at runtime resume
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vinay Belgaumkar <[email protected]>
[ Upstream commit e42459b16cbf1cbcebfc1ab406140cca204fd831 ]
We enable this flag during runtime suspend, need to set it back to false early during resume to maintain consistency in pci driver's internal state. d3cold_toggle() updates the root port's ability to go into d3cold via the dev->no_d3cold flag. With this patch, we are ensuring this internal state remains consistent with that of the endpoint.
v2: Clarify the commit message (Matt Auld)
v3: Add fixes (Karthik Poosa)
--- drivers/gpu/drm/xe/xe_pci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/xe/xe_pci.c +3 -0
@@ -1404,6 +1404,9 @@ static int xe_pci_runtime_resume(struct device *dev)struct xe_device *xe =pdev_to_xe_device (pdev);int err; +if (xe->d3cold.allowed) +d3cold_toggle (pdev,D3COLD_DISABLE ); + err =pci_set_power_state (pdev,PCI_D0 );if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/1005 drm/xe: Access GT MMIO after pcode init
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vinay Belgaumkar <[email protected]>
[ Upstream commit fc0ba46fd8278ed3e3a2c111b25036cb62dfe078 ]
Allow pcode initialization to complete before we start poking around the GT MMIO space during resume as these accesses go through sgunit. We do write to MMIO registers in xe_wa_apply_tile_workarounds(), but those are in uncore space. Those accesses remain viable even during d3cold suspend.
v2: Clarify about xe_wa_apply_tile_workarounds (Karthik Poosa)
v3: Add fixes tag (Anshuman)
--- drivers/gpu/drm/xe/xe_pm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/xe/xe_pm.c +6 -6
@@ -239,9 +239,6 @@ int xe_pm_resume(struct xe_device *xe)drm_dbg (&xe->drm,"Resuming device\n" );trace_xe_pm_resume (xe,__builtin_return_address (0 )); -for_each_gt (gt, xe, id) -xe_gt_idle_disable_c6 (gt); -for_each_tile (tile, xe, id)xe_wa_apply_tile_workarounds (tile);
@@ -249,6 +246,9 @@ int xe_pm_resume(struct xe_device *xe)if (err)return err; +for_each_gt (gt, xe, id) +xe_gt_idle_disable_c6 (gt); +xe_display_pm_resume_early (xe);/*
@@ -677,13 +677,13 @@ int xe_pm_runtime_resume(struct xe_device *xe)xe_rpm_lockmap_acquire (xe);if (xe->d3cold.allowed) { -for_each_gt (gt, xe, id) -xe_gt_idle_disable_c6 (gt); - err =xe_pcode_ready (xe, true);if (err) goto out; +for_each_gt (gt, xe, id) +xe_gt_idle_disable_c6 (gt); +xe_display_pm_resume_early (xe);/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/1005 drm/xe/xe_late_bind_fw: Fix firmware leak on missing manifest entry
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Badal Nilawar <[email protected]>
[ Upstream commit 74f1a6f03f2d46537f929a1b13f7dcd378437a4d ]
Release firmware when the "LTES" manifest entry is not found in the firmware header.
--- drivers/gpu/drm/xe/xe_late_bind_fw.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_late_bind_fw.c +8 -7
@@ -335,19 +335,19 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id)if (fw->size >XE_LB_MAX_PAYLOAD_SIZE ) {drm_err (&xe->drm,"Firmware %s size %zu is larger than max pay load size %u\n" , lb_fw->blob_path, fw->size,XE_LB_MAX_PAYLOAD_SIZE ); -release_firmware (fw); -return -ENODATA ; + ret = -ENODATA ; + goto release_fw; } ret =parse_lb_layout (lb_fw, fw->data, fw->size,"LTES" );if (ret) -return ret; + goto release_fw; lb_fw->payload_size = fw->size; lb_fw->payload =drmm_kzalloc (&xe->drm, lb_fw->payload_size,GFP_KERNEL );if (!lb_fw->payload) { -release_firmware (fw); -return -ENOMEM ; + ret = -ENOMEM ; + goto release_fw; } drm_info(&xe->drm, "Using %s firmware from %s version %u.%u.%u.%u\n",
@@ -356,10 +356,11 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id) lb_fw->version.hotfix, lb_fw->version.build);memcpy ((void *)lb_fw->payload, fw->data, lb_fw->payload_size); -release_firmware (fw);INIT_WORK (&lb_fw->work, xe_late_bind_work); -return 0 ; +release_fw: +release_firmware (fw); +return ret; }static int xe_late_bind_fw_init (struct xe_late_bind *late_bind)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/1005 drm/xe/svm: Preserve default PAT index when resetting VMA attributes
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arvind Yadav <[email protected]>
[ Upstream commit e800602296e8668b4cf143fc12d7cee4b31e64aa ]
xe_vma_set_default_attributes() replaces the VMA attributes with a default structure. It sets pat_index to the saved default PAT index, but leaves default_pat_index zero.
When the saved default is non-zero, the two fields no longer match. xe_vma_has_default_mem_attrs() then reports that the reset VMA has non-default attributes, triggering a warning in xe_vm_alloc_vma() during SVM garbage collection. A later reset also uses the incorrect zero value.
Preserve default_pat_index when restoring the default attributes.
--- drivers/gpu/drm/xe/xe_svm.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/xe/xe_svm.c +1 -0
@@ -330,6 +330,7 @@ static void xe_vma_set_default_attributes(struct xe_vma *vma)struct xe_vma_mem_attr default_attr = { .preferred_loc.devmem_fd =DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE , .preferred_loc.migration_policy =DRM_XE_MIGRATE_ALL_PAGES , + .default_pat_index = vma->attr.default_pat_index, .pat_index = vma->attr.default_pat_index, .atomic_access =DRM_XE_ATOMIC_UNDEFINED , .purgeable_state =XE_MADV_PURGEABLE_WILLNEED ,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/1005 drm/xe/guc: Fix race around q->guc->suspend_pending access
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jagmeet Randhawa <[email protected]>
[ Upstream commit a869bd4d65bc131082568743418b3876c46c3b7b ]
q->guc->suspend_pending is accessed without any common lock. __suspend_fence_signal(), called from guc_exec_queue_kill() and the suspend-timeout ban path, clears the flag asynchronously. Meanwhile handle_sched_done(), guc_exec_queue_stop() and __guc_exec_queue_process_msg_suspend() check the flag and then call suspend_fence_signal(), which asserts that it is still set.
As the check and suspend_fence_signal() are not atomic, the clear can land in between and trip the xe_gt_assert(q->guc->suspend_pending).
Rather than serializing those clears, drop them. Signalling the suspend fence from kill or from the suspend-timeout ban completes a suspend while the queue may still be executing on the hardware, so neither is a valid place to do it. Split the wake up out of __suspend_fence_signal() into suspend_wait_wake() and use that in guc_exec_queue_kill(), so a waiter still observes the killed state immediately rather than waiting out the full timeout - guc_exec_queue_wait_suspend_done() already breaks on exec_queue_killed(). The suspend-timeout ban needs no wake at all, as the waiter that timed out is its caller.
suspend_pending now stays set on a killed or banned queue until it is torn down, so relax the !suspend_pending assert in __guc_exec_queue_resume() to permit that state.
handle_sched_done() and guc_exec_queue_stop() can still race with each other, so take the per-queue msg_lock, which already covers the set on the suspend path, across their check-then-act. In handle_sched_done() the flag is snapshotted under the lock and deregister_exec_queue() is kept outside it. __guc_exec_queue_process_msg_suspend() is left unlocked: it runs on the scheduler message worker, which guc_exec_queue_stop() parks via xe_sched_submission_stop() before touching the flag.
v2: Document that sched->msg_lock also protects
guc->suspend_pending, which indicates a suspend message is in
flight, in addition to the sched->msgs list (Niranjana)v3: Drop __suspend_fence_signal() from guc_exec_queue_kill() and
guc_exec_queue_suspend_timeout_ban() rather than serializing them with msg_lock, keeping only the wake up in kill and guarding the !suspend_pending assert in resume (Matthew, Niranjana)
Stable-dep-of: eb1f465e9119 ("drm/xe/guc: Do not attribute a TDR disable to a pending suspend")
--- drivers/gpu/drm/xe/xe_gpu_scheduler_types.h | 5 +- drivers/gpu/drm/xe/xe_guc_exec_queue_types.h | 5 +- drivers/gpu/drm/xe/xe_guc_submit.c | 58 ++++++++++++++------ 3 files changed, 49 insertions(+), 19 deletions(-)
drivers/gpu/drm/xe/xe_gpu_scheduler_types.h +4 -1
@@ -47,7 +47,10 @@ struct xe_gpu_scheduler {const struct xe_sched_backend_ops *ops;/** @msgs: list of messages to be processed in @work_process_msg */ struct list_head msgs; -/** @msg_lock: Message lock */ +/** +* @msg_lock: Protects @msgs and guc->suspend_pending (indicates a +* suspend message is in flight) of exec queues on this scheduler. +*/ spinlock_t msg_lock;/** @work_process_msg: processes messages */ struct work_struct work_process_msg;
drivers/gpu/drm/xe/xe_guc_exec_queue_types.h +4 -1
@@ -52,7 +52,10 @@ struct xe_guc_exec_queue {u16 id;/** @suspend_wait: wait queue used to wait on pending suspends */ wait_queue_head_t suspend_wait; -/** @suspend_pending: a suspend of the exec_queue is pending */ +/** +* @suspend_pending: a suspend of the exec_queue is pending. +* Protected by @sched.msg_lock. +*/ bool suspend_pending;/** * @suspend_count: Reference count of active suspend requests. The
drivers/gpu/drm/xe/xe_guc_submit.c +41 -17
128 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/1005 drm/xe/guc: Do not attribute a TDR disable to a pending suspend
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jagmeet Randhawa <[email protected]>
[ Upstream commit eb1f465e9119f7680458218a63bbb8d32844908e ]
handle_sched_done() treats any SCHED_DONE with runnable_state 0 as the completion of a suspend whenever q->guc->suspend_pending is set. That is not sufficient to tell apart the two producers of a scheduling disable.
When a queue is suspended, __guc_exec_queue_suspend() sets suspend_pending and queues a SUSPEND message. If a job times out before that message runs, guc_exec_queue_timedout_job() stops submission, which traps the message, bans the queue and issues a disable of its own via disable_scheduling(). When the GuC acknowledges that disable, suspend_pending is still set, so handle_sched_done() misattributes the reply to the trapped SUSPEND message.
This signals the suspend fence for a queue that was never suspended, tripping the exec_queue_suspended() assert in suspend_fence_signal(), and skips the wake_up_all() the TDR is waiting on, so the TDR stalls for its full 5s timeout and then triggers an unnecessary GT reset.
The suspend path marks the queue suspended before disabling scheduling, and a trapped SUSPEND message never does, so exec_queue_suspended() distinguishes the two cases. Use it to qualify the attribution, the same way the VF migration replay path already does. The trapped message is not
lost: it completes the suspend once submission restarts at the end of the TDR.
While here, wake guc->ct.wq after clearing pending_disable rather than before, so a waiter observes the updated state on its first re-check, and wake unconditionally since the suspend and destroy paths have waiters too.
v2: Rebase onto drm-xe-next. The suspend_pending check moved under
sched->msg_lock in commit cf4171a20d13 ("drm/xe/guc: Fix race around q->guc->suspend_pending access"), so the exec_queue_suspended() qualification is folded into that locked snapshot rather than reinstating an unlocked check. No functional change from v1.
--- drivers/gpu/drm/xe/xe_guc_submit.c | 48 ++++++++++++++++++------------ 1 file changed, 29 insertions(+), 19 deletions(-)
drivers/gpu/drm/xe/xe_guc_submit.c +29 -19
@@ -3128,8 +3128,17 @@ static void handle_sched_done(struct xe_guc *guc, struct xe_exec_queue *q,xe_gt_assert (guc_to_gt (guc), runnable_state ==0 );xe_gt_assert (guc_to_gt (guc),exec_queue_pending_disable (q)); +/* +* A TDR stops the scheduler, which can trap a queued SUSPEND +* message, and then issues a disable of its own. suspend_pending +* is still set in that case, so only attribute this SCHED_DONE +* to a suspend if the SUSPEND message actually ran, i.e. it +* marked the queue suspended before disabling scheduling. The +* trapped message completes the suspend once submission +* restarts. +*/ xe_sched_msg_lock (&q->guc->sched); - was_pending = q->guc->suspend_pending; + was_pending = q->guc->suspend_pending &&exec_queue_suspended (q);if (was_pending) {clear_exec_queue_pending_disable (q);suspend_fence_signal (q);
@@ -3137,26 +3146,27 @@ static void handle_sched_done(struct xe_guc *guc, struct xe_exec_queue *q,xe_sched_msg_unlock (&q->guc->sched);if (!was_pending) { -if (exec_queue_banned (q)) { -smp_wmb (); -wake_up_all (&guc->ct.wq); - } -if (exec_queue_destroyed (q)) { -/* -* Make sure to clear the pending_disable only -* after sampling the destroyed state. We want -* to ensure we don't trigger the unregister too -* early with something intending to only -* disable scheduling. The caller doing the -* destroy must wait for an ongoing -* pending_disable before marking as destroyed. -*/ -clear_exec_queue_pending_disable (q); +/* +* Make sure to clear the pending_disable only after +* sampling the destroyed state. We want to ensure we +* don't trigger the unregister too early with something +* intending to only disable scheduling. The caller +* doing the destroy must wait for an ongoing +* pending_disable before marking as destroyed. +*/ +bool destroyed =exec_queue_destroyed (q); + +clear_exec_queue_pending_disable (q); +if (destroyed)deregister_exec_queue (guc, q); - }else { -clear_exec_queue_pending_disable (q); - } } + +/* +* Wake after pending_disable is cleared, not before, so waiters +* such as the TDR see the updated state on the first re-check. +*/ +smp_wmb (); +wake_up_all (&guc->ct.wq); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/1005 gpiolib: fix GPIO descriptor leak in gpiod_get_array()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit b2a161687acdc297aa91fec7fa0966b5aecf0d16 ]
In gpiod_get_array(), descs->ndescs is used as the loop induction variable and is only incremented at the end of each iteration. When krealloc() fails on the first iteration (when index is 0), descs->desc[0] has already been acquired via gpiod_get_index(), but descs->ndescs is still 0. Consequently, gpiod_put_array() frees descs without releasing descs->desc[0], leaking the descriptor.
Fix this by using a dedicated loop induction variable and incrementing descs->ndescs immediately upon storing the retrieved descriptor. Additionally, since the fast-path array_info setup only executes for the first element (index 0), simplify the bitmap_set() calls to start at bit 0 for count bits instead of calculating offsets from the loop index.
--- drivers/gpio/gpiolib.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
drivers/gpio/gpiolib.c +14 -20
@@ -5223,21 +5223,21 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,if (!descs)return ERR_PTR (-ENOMEM ); -for (descs->ndescs =0 ; descs->ndescs < count; descs->ndescs++) { - desc =gpiod_get_index (dev, con_id, descs->ndescs, flags); +for (int i =0 ; i < count; i++) { + desc =gpiod_get_index (dev, con_id, i, flags);if (IS_ERR (desc)) {gpiod_put_array (descs);return ERR_CAST (desc); } - descs->desc[descs->ndescs] = desc; + descs->desc[descs->ndescs++] = desc; gdev =gpiod_to_gpio_device (desc);/* * If pin hardware number of array member 0 is also 0, select * its chip as a candidate for fast bitmap processing path. */ -if (descs->ndescs ==0 &&gpiod_hwgpio (desc) ==0 ) { +if (i ==0 &&gpiod_hwgpio (desc) ==0 ) {struct gpio_descs *array; bitmap_size = BITS_TO_LONGS(gdev->ngpio > count ?
@@ -5262,10 +5262,8 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev, array_info->desc = descs->desc; array_info->size = count; array_info->gdev = gdev; -bitmap_set (array_info->get_mask, descs->ndescs, - count - descs->ndescs); -bitmap_set (array_info->set_mask, descs->ndescs, - count - descs->ndescs); +bitmap_set (array_info->get_mask,0 , count); +bitmap_set (array_info->set_mask,0 , count); descs->info = array_info; }
@@ -5275,38 +5273,34 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,/* Unmark array members which don't belong to the 'fast' chip */ if (array_info->gdev != gdev) { -__clear_bit (descs->ndescs, array_info->get_mask); -__clear_bit (descs->ndescs, array_info->set_mask); +__clear_bit (i, array_info->get_mask); +__clear_bit (i, array_info->set_mask); }/* * Detect array members which belong to the 'fast' chip * but their pins are not in hardware order. */ -else if (gpiod_hwgpio (desc) != descs->ndescs) { +else if (gpiod_hwgpio (desc) != i) {/* * Don't use fast path if all array members processed so * far belong to the same chip as this one but its pin * hardware number is different from its array index. */ -if (bitmap_full (array_info->get_mask, descs->ndescs)) { +if (bitmap_full (array_info->get_mask, i)) { array_info =NULL ; }else { -__clear_bit (descs->ndescs, - array_info->get_mask); -__clear_bit (descs->ndescs, - array_info->set_mask); +__clear_bit (i, array_info->get_mask); +__clear_bit (i, array_info->set_mask); } }else { dflags =READ_ONCE (desc->flags);/* Exclude open drain or open source from fast output */ if (test_bit (GPIOD_FLAG_OPEN_DRAIN , &dflags) ||test_bit (GPIOD_FLAG_OPEN_SOURCE , &dflags)) -__clear_bit (descs->ndescs, - array_info->set_mask); +__clear_bit (i, array_info->set_mask);/* Identify 'fast' pins which require invertion */ if (gpiod_is_active_low (desc)) -__set_bit (descs->ndescs, - array_info->invert_mask); +__set_bit (i, array_info->invert_mask); } }if (array_info)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/1005 gpiolib: fix fast-path cancellation in gpiod_get_array()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit 51c85306270972f672737dc5e28332e2b41b26f1 ]
In gpiod_get_array(), when a pin on the same chip is not in hardware order and the preceding pins form a contiguous block, the fast path is cancelled by setting array_info to NULL. However, descs->info was already populated with the array_info pointer during the first iteration, leaving descs->info pointing to the aborted array_info. Consequently, subsequent array operations still use the fast path with remaining bits set in the masks and wrong hardware pin numbers.
Clear descs->info alongside array_info when cancelling the fast path so callers do not erroneously use the aborted array_info.
--- drivers/gpio/gpiolib.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpio/gpiolib.c +1 -0
@@ -5287,6 +5287,7 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,* hardware number is different from its array index. */ if (bitmap_full (array_info->get_mask, i)) { + descs->info =NULL ; array_info =NULL ; }else {__clear_bit (i, array_info->get_mask);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/1005 gpiolib: of: return -ENOENT from of_gpio_count() stub
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit e20e4b8cda2b4d7dd32dbd2c0875a15d92545f04 ]
gpiod_count() and its firmware backends are expected to return either a positive number of GPIOs or a negative error code (-ENOENT) when no GPIOs are assigned. However, the !CONFIG_OF_GPIO stub for of_gpio_count() returns 0 instead of -ENOENT. This causes gpiod_count() to skip the platform_gpio_count() fallback (which triggers when count < 0) and erroneously return 0 to callers.
Change the stub to return -ENOENT to match the real of_gpio_count() implementation and the other error-returning stubs in gpiolib-of.h.
--- drivers/gpio/gpiolib-of.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-of.h +1 -1
@@ -46,7 +46,7 @@ static inline bool of_gpiochip_instance_match(struct gpio_chip *gc,static inline int of_gpio_count (const struct fwnode_handle *fwnode,const char *con_id) { -return 0 ; +return -ENOENT ; } static inline int of_gpiochip_get_lflags(struct gpio_chip *chip, struct fwnode_reference_args *gpiospec,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 410/1005 ASoC: soc-core: copy the DAI link names into the card
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tyler Baker <[email protected]>
[ Upstream commit 33a130f6ed8c75ed59b12889a417a57fb80d0abf ]
snd_soc_of_get_dai_link_codecs() and snd_soc_of_get_dai_link_cpus() keep a DAI name owned by the component, which is freed when the component unbinds, so the card cannot bind again afterwards.
Copy the name onto the card device, as simple-card and audio-graph-card do since commit aa173b70d372 ("ASoC: generic: keep fallback dai_name stable across rebind").
--- sound/soc/soc-core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
sound/soc/soc-core.c +16 -0
@@ -3610,6 +3610,18 @@ void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link) }EXPORT_SYMBOL_GPL (snd_soc_of_put_dai_link_codecs); +/* dai_name belongs to the component, which can unbind before the card. */ +static int snd_soc_of_dup_dai_name (struct device *dev, +struct snd_soc_dai_link_component *dlc) +{ +if (!dlc->dai_name) +return 0 ; + + dlc->dai_name =devm_kstrdup_const (dev, dlc->dai_name,GFP_KERNEL ); + +return dlc->dai_name ?0 : -ENOMEM ; +} +/* * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree * @dev: Card device
@@ -3639,6 +3651,8 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,/* Parse the list */ for_each_link_codecs (dai_link, index, component) { ret =snd_soc_of_get_dlc (of_node,NULL , component, index); +if (!ret) + ret =snd_soc_of_dup_dai_name (dev, component);if (ret) goto err; }
@@ -3694,6 +3708,8 @@ int snd_soc_of_get_dai_link_cpus(struct device *dev,/* Parse the list */ for_each_link_cpus (dai_link, index, component) { ret =snd_soc_of_get_dlc (of_node,NULL , component, index); +if (!ret) + ret =snd_soc_of_dup_dai_name (dev, component);if (ret) goto err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 411/1005 ASoC: qcom: common: Add generic headset jack helpers
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongyang Zhao <[email protected]>
[ Upstream commit 7f8dd07370f8c17f8f98f0fa98691635828b0dac ]
qcom_snd_wcd_jack_setup() combines creation of the card-level headset jack with the WCD-specific operation of attaching jack detection to codecs on the TX codec DMA links. External codecs connected over MI2S also provide component jack detection, but cannot use the WCD-specific DAI filtering.
Factor the common jack allocation, DAPM pin registration and headset button mappings into a private initializer. Reuse it from the existing WCD path and add a generic setup helper which attaches the jack to every codec component in a runtime.
Treat -ENOTSUPP as a no-op because snd_soc_component_set_jack() uses it for components which do not provide a set_jack callback.
Add a matching cleanup helper so machine drivers can detach component jack detection when the DAI link exits. The WCD setup behavior remains unchanged.
Stable-dep-of: 704251f9dad3 ("ASoC: qcom: x1e80100: recreate the headset jack on card rebind")
--- sound/soc/qcom/common.c | 61 +++++++++++++++++++++++++++++++++++------ sound/soc/qcom/common.h | 3 ++ 2 files changed, 56 insertions(+), 8 deletions(-)
sound/soc/qcom/common.c +53 -8
@@ -339,13 +339,11 @@ static struct snd_soc_jack_pin qcom_headset_jack_pins[] = { }, }; -int qcom_snd_wcd_jack_setup (struct snd_soc_pcm_runtime *rtd, -struct snd_soc_jack *jack,bool *jack_setup) +static int qcom_snd_headset_jack_init (struct snd_soc_card *card, +struct snd_soc_jack *jack, +bool *jack_setup) { -struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); -struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtd,0 ); -struct snd_soc_card *card = rtd->card; -int rval, i; +int rval;if (!*jack_setup) { rval = snd_soc_card_jack_new_pins(card, "Headset Jack",
@@ -369,6 +367,55 @@ int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd, *jack_setup = true; } +return 0 ; +} + +int qcom_snd_headset_jack_setup (struct snd_soc_pcm_runtime *rtd, +struct snd_soc_jack *jack,bool *jack_setup) +{ +struct snd_soc_dai *codec_dai; +struct snd_soc_card *card = rtd->card; +int rval, i; + + rval =qcom_snd_headset_jack_init (card, jack, jack_setup); +if (rval) +return rval; + +for_each_rtd_codec_dais (rtd, i, codec_dai) { + rval =snd_soc_component_set_jack (codec_dai->component, jack,NULL ); +if (rval !=0 && rval != -ENOTSUPP ) { +dev_warn (card->dev,"Failed to set jack: %d\n" , rval); +qcom_snd_headset_jack_cleanup (rtd); +return rval; + } + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (qcom_snd_headset_jack_setup); + +void qcom_snd_headset_jack_cleanup (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_soc_dai *codec_dai; +int i; + +for_each_rtd_codec_dais (rtd, i, codec_dai) +snd_soc_component_set_jack (codec_dai->component,NULL ,NULL ); +} +EXPORT_SYMBOL_GPL (qcom_snd_headset_jack_cleanup); + +int qcom_snd_wcd_jack_setup (struct snd_soc_pcm_runtime *rtd, +struct snd_soc_jack *jack,bool *jack_setup) +{ +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtd,0 ); +struct snd_soc_card *card = rtd->card; +int rval, i; + + rval =qcom_snd_headset_jack_init (card, jack, jack_setup); +if (rval) +return rval; +switch (cpu_dai->id) {case LPI_MI2S_RX_0 :case TX_CODEC_DMA_TX_0 :
@@ -388,8 +435,6 @@ int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd,default :break ; } - -return 0 ; }EXPORT_SYMBOL_GPL (qcom_snd_wcd_jack_setup);
sound/soc/qcom/common.h +3 -0
@@ -24,6 +24,9 @@ int qcom_snd_apply_dai_tdm_slots_cfg(struct snd_soc_pcm_runtime *rtd,const struct qcom_snd_tdm_slot_cfg *cpu_cfg, const struct qcom_snd_tdm_slot_cfg *codec_cfg);int qcom_snd_apply_dai_tdm_slots (struct snd_soc_pcm_runtime *rtd); +int qcom_snd_headset_jack_setup (struct snd_soc_pcm_runtime *rtd, +struct snd_soc_jack *jack,bool *jack_setup); +void qcom_snd_headset_jack_cleanup (struct snd_soc_pcm_runtime *rtd);int qcom_snd_wcd_jack_setup (struct snd_soc_pcm_runtime *rtd,struct snd_soc_jack *jack,bool *jack_setup); int qcom_snd_dp_jack_setup(struct snd_soc_pcm_runtime *rtd,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 412/1005 ASoC: qcom: x1e80100: recreate the headset jack on card rebind
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tyler Baker <[email protected]>
[ Upstream commit 704251f9dad3cb5f93ef64ff2d547868d42de319 ]
The headset jack is only created while jack_setup is false and nothing clears it, so after a card rebind it is not created again and the codecs keep a pointer to the freed jack.
Clear it on link exit, as sc8280xp does.
--- sound/soc/qcom/x1e80100.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
sound/soc/qcom/x1e80100.c +18 -0
@@ -68,6 +68,23 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)return qcom_snd_wcd_jack_setup (rtd, &data->jack, &data->jack_setup); } +static void x1e80100_snd_exit (struct snd_soc_pcm_runtime *rtd) +{ +struct x1e80100_snd_data *data =snd_soc_card_get_drvdata (rtd->card); +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); + +switch (cpu_dai->id) { +case DISPLAY_PORT_RX_0 : + case DISPLAY_PORT_RX_1 ... DISPLAY_PORT_RX_7: +return ; +default : +break ; + } + +qcom_snd_headset_jack_cleanup (rtd); + data->jack_setup = false; +} +static int x1e80100_be_hw_params_fixup (struct snd_soc_pcm_runtime *rtd,struct snd_pcm_hw_params *params) {
@@ -172,6 +189,7 @@ static void x1e80100_add_be_ops(struct snd_soc_card *card)for_each_card_prelinks (card, i, link) {if (link->no_pcm ==1 ) { link->init = x1e80100_snd_init; + link->exit = x1e80100_snd_exit; link->be_hw_params_fixup = x1e80100_be_hw_params_fixup; link->ops = &x1e80100_be_ops; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/1005 drm/panfrost: Enable cycle counting when perfcnt is enabled
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Boris Brezillon <[email protected]>
[ Upstream commit 99a2e2b1690f48b074bf14a3b7d5d52f45d26ecc ]
If we don't do that, we end up with invalid timestamps in the block headers.
We also need to skip the warning on the cycle counter reference being other than 0 during device reset, because of perfcnt's lingering ref.
Ideally this would be dealt with by splitting the reset sequence into pre and post stages, so that a hypothetical panfrost_perfcnt_pre_reset() would release the cycle counter reference. In the absence thereof, we just make do.
--- drivers/gpu/drm/panfrost/panfrost_gpu.c | 7 +++---- drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/panfrost/panfrost_gpu.c +3 -4
@@ -94,11 +94,10 @@ int panfrost_gpu_soft_reset(struct panfrost_device *pfdev) GPU_IRQ_CLEAN_CACHES_COMPLETED);/* -* All in-flight jobs should have released their cycle -* counter references upon reset, but let us make sure +* Even though all in-flight jobs should have released their cycle counter +* references upon reset, perfcnt's might still hang about. */ -if (drm_WARN_ON (&pfdev->base,atomic_read (&pfdev->cycle_counter.use_count) !=0 )) -atomic_set (&pfdev->cycle_counter.use_count,0 ); +atomic_set (&pfdev->cycle_counter.use_count,0 );return 0 ; }
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +3 -0
@@ -17,6 +17,7 @@#include "panfrost_device.h" #include "panfrost_features.h" #include "panfrost_gem.h" +#include "panfrost_gpu.h" #include "panfrost_issues.h" #include "panfrost_job.h" #include "panfrost_mmu.h"
@@ -52,6 +53,7 @@ static void panfrost_perfcnt_hw_disable(struct panfrost_device *pfdev)gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 );if (perfcnt->owns_as_ref) { +panfrost_cycle_counter_put (pfdev);panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu); perfcnt->owns_as_ref = false; }
@@ -81,6 +83,7 @@ static int panfrost_perfcnt_hw_enable(struct panfrost_device *pfdev)return ret; perfcnt->owns_as_ref = true; +panfrost_cycle_counter_get (pfdev); as = ret; cfg = GPU_PERFCNT_CFG_AS(as) |
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/1005 ASoC: amd: ps: guard adata->sdw dereferences with NULL check in IRQ handler
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vijendar Mukunda <[email protected]>
[ Upstream commit 41e06aaef9c000c1bb52d8a6f73ae66c9bd36d83 ]
The ACP external IRQ handler is registered before sdw_amd_probe() assigns adata->sdw, so a stray interrupt in the probe window could reach the adata->sdw->pdev[i] dereference with adata->sdw still NULL.
The same window exists on the teardown side: after sdw_amd_exit() frees the context but before adata->sdw is cleared by the caller.
Add NULL checks for adata->sdw in acp63_irq_handler() before dereferencing ->pdev[0] and ->pdev[1], and in handle_acp70_sdw_wake_event() for the same reason. The interrupt-status register write that acknowledges the IRQ is kept outside the guard so the hardware bit is always cleared regardless of whether the SoundWire context is live.
--- sound/soc/amd/ps/pci-ps.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
sound/soc/amd/ps/pci-ps.c +20 -12
@@ -26,16 +26,20 @@ static void handle_acp70_sdw_wake_event(struct acp63_dev_data *adata)struct amd_sdw_manager *amd_manager;if (adata->acp70_sdw0_wake_event) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); -if (amd_manager) -pm_request_resume (amd_manager->dev); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +pm_request_resume (amd_manager->dev); + } adata->acp70_sdw0_wake_event =0 ; }if (adata->acp70_sdw1_wake_event) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); -if (amd_manager) -pm_request_resume (amd_manager->dev); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +pm_request_resume (amd_manager->dev); + } adata->acp70_sdw1_wake_event =0 ; } }
@@ -209,18 +213,22 @@ static irqreturn_t acp63_irq_handler(int irq, void *dev_id) ext_intr_stat =readl (adata->acp63_base +ACP_EXTERNAL_INTR_STAT );if (ext_intr_stat &ACP_SDW0_STAT ) {writel (ACP_SDW0_STAT , adata->acp63_base +ACP_EXTERNAL_INTR_STAT ); - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; } ext_intr_stat1 =readl (adata->acp63_base +ACP_EXTERNAL_INTR_STAT1 );if (ext_intr_stat1 &ACP_SDW1_STAT ) {writel (ACP_SDW1_STAT , adata->acp63_base +ACP_EXTERNAL_INTR_STAT1 ); - amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/1005 ASoC: SOF: amd: guard adata->sdw dereferences with NULL check in IRQ handler
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vijendar Mukunda <[email protected]>
[ Upstream commit 34ea81a7f284a13d825279fdede36b7f793f9936 ]
The ACP external IRQ handler is registered before sdw_amd_probe() assigns adata->sdw, so a stray interrupt in the probe window could reach the adata->sdw->pdev[i] dereference with adata->sdw still NULL.
The same window exists on the teardown side: after sdw_amd_exit() frees the context but before adata->sdw is cleared by the caller.
Add NULL checks for adata->sdw in acp_irq_handler() before dereferencing ->pdev[0] and ->pdev[1], and in amd_sof_handle_acp70_sdw_wake_event() for the same reason. The interrupt-status register write that acknowledges the IRQ is kept outside the guard so the hardware bit is always cleared regardless of whether the SoundWire context is live.
--- sound/soc/sof/amd/acp.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
sound/soc/sof/amd/acp.c +20 -12
@@ -430,16 +430,20 @@ static void amd_sof_handle_acp70_sdw_wake_event(struct acp_dev_data *adata)struct amd_sdw_manager *amd_manager;if (adata->acp70_sdw0_wake_event) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); -if (amd_manager) -pm_request_resume (amd_manager->dev); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +pm_request_resume (amd_manager->dev); + } adata->acp70_sdw0_wake_event =0 ; }if (adata->acp70_sdw1_wake_event) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); -if (amd_manager) -pm_request_resume (amd_manager->dev); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +pm_request_resume (amd_manager->dev); + } adata->acp70_sdw1_wake_event =0 ; } }
@@ -531,10 +535,12 @@ static irqreturn_t acp_irq_handler(int irq, void *dev_id) val =snd_sof_dsp_read (sdev,ACP_DSP_BAR , desc->ext_intr_stat);if (val &ACP_SDW0_IRQ_MASK ) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev);snd_sof_dsp_write (sdev,ACP_DSP_BAR , desc->ext_intr_stat,ACP_SDW0_IRQ_MASK ); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; }
@@ -560,11 +566,13 @@ static irqreturn_t acp_irq_handler(int irq, void *dev_id)if (desc->ext_intr_stat1) { val =snd_sof_dsp_read (sdev,ACP_DSP_BAR , desc->ext_intr_stat1);if (val &ACP_SDW1_IRQ_MASK ) { - amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev);snd_sof_dsp_write (sdev,ACP_DSP_BAR , desc->ext_intr_stat1,ACP_SDW1_IRQ_MASK ); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; }switch (adata->pci_rev) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/1005 cgroup/cpuset: Reset partition data when an invalid partition stays invalid
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ridong Chen <[email protected]>
[ Upstream commit ba4834fc81ddc0b500843c827c09d3ff95a317a9 ]
When cpuset.cpus or cpuset.cpus.exclusive of a partition root is changed, update_cpumask() and update_exclusive_cpumask() copy the new effective_xcpus computed for the trial cpuset into the cpuset, and call reset_partition_data() only if the partition was valid before and is invalid now:
if ((old_prs > 0) && !is_partition_valid(cs)) reset_partition_data(cs);
An invalid partition root (old_prs < 0) that stays invalid is not covered. Its effective_xcpus is then left with the trial value, which is computed from user_xcpus() and so falls back to cpuset.cpus when cpuset.cpus.exclusive is cleared. As an invalid partition root does not own any exclusive CPUs, and rm_siblings_excl_cpus() treats a non-empty effective_xcpus of a sibling without cpuset.cpus.exclusive as owned, those CPUs can then no longer be claimed by a sibling:
# A1: cpuset.cpus=2-3, cpuset.cpus.exclusive=2-3, root, with tasks
# offline CPUs 2-3 -> A1 becomes invalid echo > A1/cpuset.cpus.exclusive cat A1/cpuset.cpus.exclusive.effective # 2-3, expected empty echo 3 > B1/cpuset.cpus.exclusive # -EINVAL
Reset the partition data whenever the cpuset is a partition root, valid or not, and ends up invalid. As effective_xcpus may be cleared by that, also force update_cpumasks_hier() to update the subtree, so that the effective_xcpus of the descendants doesn't keep the released CPUs. Add test cases for it.
--- kernel/cgroup/cpuset.c | 10 ++++++++-- tools/testing/selftests/cgroup/test_cpuset_prs.sh | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
kernel/cgroup/cpuset.c +8 -2
@@ -2640,8 +2640,11 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,spin_lock_irq (&callback_lock);cpumask_copy (cs->cpus_allowed, trialcs->cpus_allowed);cpumask_copy (cs->effective_xcpus, trialcs->effective_xcpus); -if ((old_prs >0 ) && !is_partition_valid (cs)) +if (old_prs && !is_partition_valid (cs)) {reset_partition_data (cs); +/* effective_xcpus may be cleared, update the subtree too */ + force = true; + }spin_unlock_irq (&callback_lock);/* effective_cpus/effective_xcpus will be updated here */
@@ -2705,8 +2708,11 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,spin_lock_irq (&callback_lock);cpumask_copy (cs->exclusive_cpus, trialcs->exclusive_cpus);cpumask_copy (cs->effective_xcpus, trialcs->effective_xcpus); -if ((old_prs >0 ) && !is_partition_valid (cs)) +if (old_prs && !is_partition_valid (cs)) {reset_partition_data (cs); +/* effective_xcpus may be cleared, update the subtree too */ + force = true; + }spin_unlock_irq (&callback_lock);/*
tools/testing/selftests/cgroup/test_cpuset_prs.sh +6 -0
@@ -364,6 +364,12 @@ TEST_MATRIX=( # cpuset.cpus is allowed, but those extra CPUs are ignored. " C2-3:P1 C3:P1 . . . C2-4 . . 0 A1:|A2:2-3 A1:P1|A2:P1" + # Clearing cpuset.cpus.exclusive of an invalid partition releases its + # exclusive CPUs, including those of its descendants, so a sibling + # can claim them. + " CX2-3:P1 . . C3 T:O2=0:O3=0:X . . X3 0 XA1:|XB1:3 A1:P-1" + " CX2-3:P1 X3 . C3 T:O2=0:O3=0:X . . X3 0 XA1:|XA2:|XB1:3 A1:P-1" + # A child cannot recover until its exclusive CPUs are available again. " CX1-4:P1 CX3-4:P1 . . X1-2 . . . 0 A1:1-2|A2:1-2|XA2: A1:P1|A2:P-1" " CX1-4:P1 CX3-4:P1 . . X1-2:X1-4 . . . 0 A1:1-2|A2:3-4|XA2:3-4 A1:P1|A2:P1"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/1005 ASoC: amd: acp: es83xx: Enable speaker amplifier after the codec output
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Leyva <[email protected]>
[ Upstream commit f392763d73356760eac3e4ab7c87b0855be0d4bb ]
The speaker amplifier GPIO is driven from a SUPPLY widget. DAPM powers supplies before the rest of the path, so the amplifier is enabled while the ES8316 headphone driver and charge pump, which also feed the speakers, are still powering up. This results in an audible pop every time the speaker output is powered on.
Move the speaker GPIO handling to the Speaker endpoint widget, which DAPM powers up last and powers down first, and give the codec output a short time to settle before enabling the amplifier.
The headphone path is left unchanged: the Headphone endpoint widget shares its power-up rank with the codec output drivers, so moving it would not guarantee the same ordering, and it could not be tested.
--- sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c +9 -7
@@ -18,6 +18,7 @@#include <linux/input.h> #include <linux/io.h> #include <linux/acpi.h> +#include <linux/delay.h> #include <linux/dmi.h> #include <linux/string_choices.h> #include "../acp-mach.h"
@@ -60,6 +61,8 @@ static const struct snd_pcm_hw_constraint_list constraints_channels = {#define ES83xx_12288_KHZ_MCLK_FREQ (48000 * 256)#define ES83xx_48_MHZ_MCLK_FREQ (48000 * 1000) +#define ES83XX_AMP_ON_DELAY_MS 50 +static int acp3x_es83xx_headphone_power_event (struct snd_soc_dapm_widget *w,struct snd_kcontrol *kcontrol,int event); static int acp3x_es83xx_speaker_power_event(struct snd_soc_dapm_widget *w,
@@ -114,7 +117,7 @@ static struct snd_soc_jack_pin es83xx_jack_pins[] = { };static const struct snd_soc_dapm_widget acp3x_es83xx_widgets[] = { -SND_SOC_DAPM_SPK ("Speaker" ,NULL ), +SND_SOC_DAPM_SPK ("Speaker" , acp3x_es83xx_speaker_power_event),SND_SOC_DAPM_HP ("Headphone" ,NULL ),SND_SOC_DAPM_MIC ("Headset Mic" ,NULL ),SND_SOC_DAPM_MIC ("Internal Mic" ,NULL ),
@@ -122,9 +125,6 @@ static const struct snd_soc_dapm_widget acp3x_es83xx_widgets[] = {SND_SOC_DAPM_SUPPLY ("Headphone Power" ,SND_SOC_NOPM ,0 ,0 , acp3x_es83xx_headphone_power_event, SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), -SND_SOC_DAPM_SUPPLY ("Speaker Power" ,SND_SOC_NOPM ,0 ,0 , - acp3x_es83xx_speaker_power_event, - SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), };static const struct snd_soc_dapm_route acp3x_es83xx_audio_map[] = {
@@ -138,7 +138,6 @@ static const struct snd_soc_dapm_route acp3x_es83xx_audio_map[] = {*/ {"Speaker", NULL, "HPOL"}, {"Speaker", NULL, "HPOR"}, - {"Speaker", NULL, "Speaker Power"}, };
@@ -186,10 +185,13 @@ static int acp3x_es83xx_speaker_power_event(struct snd_soc_dapm_widget *w,struct acp3x_es83xx_private *priv =get_mach_priv (card);dev_dbg (priv->codec_dev,"speaker power event: %d\n" , event); -if (SND_SOC_DAPM_EVENT_ON (event)) +if (SND_SOC_DAPM_EVENT_ON (event)) { +/* Let the codec output settle before enabling the amplifier */ +msleep (ES83XX_AMP_ON_DELAY_MS ); priv->speaker_on = true; -else + }else { priv->speaker_on = false; + }gpiod_set_value_cansleep (priv->gpio_speakers, priv->speaker_on);gpiod_set_value_cansleep (priv->gpio_headphone, priv->headphone_on);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/1005 btrfs: zoned: only change active zone counter on successful (de)activation
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit 5e79f39fbeea78703ac389c67a810406fa09bc94 ]
btrfs_zone_activate() unconditionally decrements the reserved_active_zones counter regardless if btrfs_dev_set_active_zone() fails to set the zone active, i.e. because it raced with another call that already set the bit in the bitmask, or not.
This can lead to a double decrement of the counter in case the bit has already been set.
Only decrement the counter *iff* btrfs_dev_set_active_zone() successfully marked the zone in the bitmap.
Mirror this behaviour when clearing the bit again.
--- fs/btrfs/zoned.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
fs/btrfs/zoned.c +18 -8
@@ -1131,11 +1131,13 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start,return pos; } -static bool btrfs_dev_set_active_zone (struct btrfs_device *device,u64 pos) +static bool btrfs_dev_set_active_zone (struct btrfs_device *device,u64 pos,bool *new) {struct btrfs_zoned_device_info *zone_info = device->zone_info;unsigned int zno = (pos >> zone_info->zone_size_shift); + *new = false; +/* We can use any number of zones */ if (zone_info->max_active_zones ==0 )return true;
@@ -1147,23 +1149,29 @@ static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos)if (test_and_set_bit (zno, zone_info->active_zones)) {/* Someone already set the bit */ atomic_inc (&zone_info->active_zones_left); + }else { + *new = true; } }return true; } -static void btrfs_dev_clear_active_zone (struct btrfs_device *device,u64 pos) +static bool btrfs_dev_clear_active_zone (struct btrfs_device *device,u64 pos) {struct btrfs_zoned_device_info *zone_info = device->zone_info;unsigned int zno = (pos >> zone_info->zone_size_shift);/* We can use any number of zones */ if (zone_info->max_active_zones ==0 ) -return ; +return false; -if (test_and_clear_bit (zno, zone_info->active_zones)) +if (test_and_clear_bit (zno, zone_info->active_zones)) {atomic_inc (&zone_info->active_zones_left); +return true; + } + +return false; } int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical,
@@ -2416,6 +2424,7 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)u64 physical;const bool is_data = (block_group->flags &BTRFS_BLOCK_GROUP_DATA );bool ret; +bool new;int i;if (!btrfs_is_zoned (block_group->fs_info))
@@ -2469,12 +2478,12 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) goto out_unlock; } -if (!btrfs_dev_set_active_zone (device, physical)) { +if (!btrfs_dev_set_active_zone (device, physical, &new)) {/* Cannot activate the zone */ ret = false; goto out_unlock; } -if (!is_data) +if (!is_data && new) zinfo->reserved_active_zones--; }
@@ -2521,6 +2530,7 @@ static int call_zone_finish(struct btrfs_block_group *block_group,struct btrfs_device *device = stripe->dev;const u64 physical = stripe->physical;struct btrfs_zoned_device_info *zinfo = device->zone_info; +bool cleared;int ret;if (!device->bdev)
@@ -2542,9 +2552,9 @@ static int call_zone_finish(struct btrfs_block_group *block_group,return ret; } -if (!(block_group->flags &BTRFS_BLOCK_GROUP_DATA )) + cleared =btrfs_dev_clear_active_zone (device, physical); +if (!(block_group->flags &BTRFS_BLOCK_GROUP_DATA ) && cleared) zinfo->reserved_active_zones++; -btrfs_dev_clear_active_zone (device, physical);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/1005 btrfs: zoned: fix possible UAF in wait_eb_writebacks()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit 8ca411c7ad2c02ae65ae208a3f7483d6e0159c4f ]
wait_eb_writebacks() iterates the fs_info->buffer_tree xarray and waits for the writeback of these extent-buffers. Waiting for writeback needs to be done without the rcu_read_lock() held (because it can sleep) and thus the loop drops the rcu_read_lock() before calling into wait_on_extent_buffer_writeback(). But extent_buffers are freed through RCU, so if btrfs_release_extent_buffer_rcu() is scheduled while we're still waiting on the writeback, the extent_buffer will be freed causing a use-after-free.
Similar to what is done in find_extent_buffer_nolock(), get a reference to the extent_buffer before calling into wait_on_extent_buffer_writeback() so a successful writeback does not free the extent_buffer while we still have a reference to it.
--- fs/btrfs/zoned.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/btrfs/zoned.c +8 -0
@@ -2517,8 +2517,16 @@ static void wait_eb_writebacks(struct btrfs_block_group *block_group)continue ;if (eb->start >= end)break ; +/* +* Skip if we can't get the refcount for the extent buffer, +* i.e. because it was already written back. Otherwise an eb +* disappering underneath us can cause a use-after-free. +*/ +if (!refcount_inc_not_zero (&eb->refs)) +continue ;rcu_read_unlock ();wait_on_extent_buffer_writeback (eb); +free_extent_buffer (eb);rcu_read_lock (); }rcu_read_unlock ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/1005 btrfs: zoned: requeue block group if zone reset bails out
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit c5f878eefdd4f559422a68bf49b6f59e7c10e70e ]
btrfs_reset_unused_block_groups() drops the block-group from fs_info->unused_bgs before performing the work that can actually fail, the actual submission of a REQ_OP_ZONE_RESET.
Every failed operation after this leaves the block-group dangling, physically reset, but the in-memory structures aren't and it is not requeued to be reset on fs_info->unused_bgs.
Instead of bailing out, re-add this block-group to fs_info->unused_bgs list.
--- fs/btrfs/zoned.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
fs/btrfs/zoned.c +22 -6
@@ -3141,6 +3141,8 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num {struct btrfs_fs_info *fs_info = space_info->fs_info;const sector_t zone_size_sectors = fs_info->zone_size >>SECTOR_SHIFT ; +LIST_HEAD (retry_list); +int ret =0 ;if (!btrfs_is_zoned (fs_info))return 0 ;
@@ -3182,11 +3184,10 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num }if (!found) {spin_unlock (&fs_info->unused_bgs_lock); -return 0 ; + goto out; }list_del_init (&bg->bg_list); -btrfs_put_block_group (bg);spin_unlock (&fs_info->unused_bgs_lock);/*
@@ -3200,7 +3201,6 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 numfor (int i =0 ; i < map->num_stripes; i++) {struct btrfs_io_stripe *stripe = &map->stripes[i];unsigned int nofs_flags; -int ret; nofs_flags =memalloc_nofs_save (); ret = blkdev_zone_mgmt(stripe->dev->bdev, REQ_OP_ZONE_RESET,
@@ -3210,7 +3210,7 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 numif (ret) {up_read (&fs_info->dev_replace.rwsem); -return ret; + goto requeue; } }up_read (&fs_info->dev_replace.rwsem);
@@ -3221,7 +3221,7 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 numif (bg->ro) {spin_unlock (&bg->lock);spin_unlock (&space_info->lock); -continue ; + goto requeue; } reclaimed = bg->alloc_offset;
@@ -3250,12 +3250,28 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 numbtrfs_return_free_space (space_info, reclaimed);spin_unlock (&space_info->lock); +btrfs_put_block_group (bg); +if (num_bytes <= reclaimed)break ; num_bytes -= reclaimed; +continue ; + +requeue: +list_add_tail (&bg->bg_list, &retry_list); + +if (ret) + goto out; } -return 0 ; +out: +if (!list_empty (&retry_list)) { +spin_lock (&fs_info->unused_bgs_lock); +list_splice_tail (&retry_list, &fs_info->unused_bgs); +spin_unlock (&fs_info->unused_bgs_lock); + } + +return ret; }void btrfs_show_zoned_stats (struct btrfs_fs_info *fs_info,struct seq_file *seq)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/1005 btrfs: zoned: dont wait for ordered extents in do_zone_finish()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit bcad7df05237382237ad1517411721d839174009 ]
do_zone_finish() calls btrfs_wait_ordered_roots(), which holds fs_info->ordered_operations_mutex while waiting for writeback. It can be reached from writeback itself:
cow_file_range()
`-> btrfs_reserve_extent()
`-> find_free_extent()
`-> btrfs_zone_finish_one_bg()
`-> do_zone_finish()If another task holds the mutex and waits for that writeback, this deadlocks.
In general, we want to ensure all writes in the block group to complete before finishing the zone, as relocation does. However, the current callers do not need the wait (or cannot wait) in do_zone_finish():
- Relocation already waits for reservations and ordered extents itself before calling btrfs_zone_finish().
- btrfs_delete_unused_bgs() checks that ->reserved is zero and sets the block group read-only while holding groups_sem, so there can be no in-flight data write.
- btrfs_zone_finish_one_bg() is called from the allocation path and cannot wait.
Dropping the wait is still safe. Once the block group is read-only, ->reserved can only drop, and for data it only drops after the ordered extent's I/O has completed. So if ->reserved is zero, no data write is left in flight. If it is non-zero, do_zone_finish() returns -EAGAIN, which all callers handle.
This makes btrfs_zone_finish_one_bg() fail with -EAGAIN when it races with an allocation in the selected block group.
--- fs/btrfs/zoned.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/btrfs/zoned.c +4 -3
@@ -2610,9 +2610,10 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ/* Ensure all writes in this block group finish */ btrfs_wait_block_group_reservations (block_group); -/* No need to wait for NOCOW writers. Zoned mode does not allow that */ -btrfs_wait_ordered_roots (fs_info,U64_MAX , block_group); -/* Wait for extent buffers to be written. */ +/* +* No need to wait for NOCOW writers, as zoned mode does not +* allow that, only wait for extent buffers to be written. +*/ if (is_metadata)wait_eb_writebacks (block_group);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/1005 btrfs: zoned: fix lockdep splat on mount
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit 04df03585f0d8ef2727e043119bba2cdfac2d8d7 ]
When mounting a filesystem on a zoned drive passed into a VM via a virtio-blk disk lockdep sporadically complains about a possible deadlock between BTRFS' dev_replace::rwsem and virtio-blk's vdev_mutex:
======================================================
WARNING: possible circular locking dependency detected
7.3.0-rc6+ #317 Not tainted
------------------------------------------------------
mount/7418 is trying to acquire lock:
ffff888102c07860 (&vblk->vdev_mutex){+.+.}-{4:4}, at: virtblk_report_zones+0xda/0x440
but task is already holding lock:
ffff8881fd725ea8 (&fs_info->dev_replace.rwsem){++++}-{4:4}, at: btrfs_load_block_group_zone_info+0x186/0xe50
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #4 (&fs_info->dev_replace.rwsem){++++}-{4:4}:
down_read+0x42/0x170
btrfs_map_block+0x1a6/0xe70
btrfs_submit_bbio+0x1a3/0x910
submit_one_bio+0x93/0xd0
btrfs_readahead+0x1c4/0x200
read_pages+0x56/0x200
page_cache_ra_order+0x27c/0x410
filemap_get_pages+0x12f/0x4a0
filemap_read+0xed/0x400
vfs_read+0x240/0x340
ksys_read+0x61/0xd0
do_syscall_64+0xa3/0x4f0
entry_SYSCALL_64_after_hwframe+0x76/0x7e-> #3 (mapping.invalidate_lock#3){++++}-{4:4}:
down_read+0x42/0x170
filemap_fault+0xb0/0x1a40
__do_fault+0x34/0xc0
__handle_mm_fault+0x919/0x1db0
handle_mm_fault+0x97/0x240
do_user_addr_fault+0x21d/0x690
exc_page_fault+0x8e/0x230
asm_exc_page_fault+0x26/0x30-> #2 (vm_lock){++++}-{0:0}:
__vma_start_exclude_readers+0x91/0x1b0
__vma_start_write+0x47/0xd0
vma_expand+0x4c/0x2a0
relocate_vma_down+0x126/0x200
setup_arg_pages+0x240/0x3e0
load_elf_binary+0x1be/0x1860
bprm_execve+0x2d2/0x7b0
kernel_execve+0x107/0x130
kernel_init+0xc2/0x130
ret_from_fork+0x1ff/0x2f0
ret_from_fork_asm+0x1a/0x30-> #1 (&mm->mmap_lock){++++}-{4:4}:
__might_fault+0x68/0xa0
_copy_to_user+0x22/0x70
blkdev_copy_zone_to_user+0x22/0x40
virtblk_report_zones+0x297/0x440
blkdev_report_zones_ioctl+0xfd/0x130
blkdev_ioctl+0x20f/0x2c0
__x64_sys_ioctl+0x86/0xd0
do_syscall_64+0xa3/0x4f0
entry_SYSCALL_64_after_hwframe+0x76/0x7e-> #0 (&vblk->vdev_mutex){+.+.}-{4:4}:
__lock_acquire+0x15a8/0x2850
lock_acquire+0xea/0x2f0
__mutex_lock+0xa7/0x10d0
virtblk_report_zones+0xda/0x440
blkdev_report_zones_cached+0x162/0x190
btrfs_get_dev_zones+0xdc/0x2c0
btrfs_load_block_group_zone_info+0x2b6/0xe50
btrfs_read_block_groups+0x338/0xc80
open_ctree+0x1aca/0x24b3
btrfs_get_tree.cold+0x105/0x26c
vfs_get_tree+0x28/0xb0
__do_sys_fsconfig+0x324/0x690
do_syscall_64+0xa3/0x4f0
entry_SYSCALL_64_after_hwframe+0x76/0x7eother info that might help us debug this:
Chain exists of: &vblk->vdev_mutex --> mapping.invalidate_lock#3 --> &fs_info->dev_replace.rwsem Possible unsafe locking scenario:
CPU0 CPU1
---- ----
rlock(&fs_info->dev_replace.rwsem);
lock(mapping.invalidate_lock#3);
lock(&fs_info->dev_replace.rwsem); lock(&vblk->vdev_mutex);
*** DEADLOCK ***
locks held by mount/7418: 3, last CPU#0:
#0: ffff888110aa6868 (&fc->uapi_mutex){+.+.}-{4:4}, at: __do_sys_fsconfig+0x2ae/0x690
#1: ffff888112ba20e8 (&type->s_umount_key#31/1){+.+.}-{4:4}, at: sget_fc+0x148/0x8d0
#2: ffff8881fd725ea8 (&fs_info->dev_replace.rwsem){++++}-{4:4}, at: btrfs_load_block_group_zone_info+0x186/0xe50
Holding the rwsem was widened in 0090d6e1b210 ("btrfs: zoned: fix use-after-free due to race with dev replace"), but it now also covers calling into blkdev_report_zones_cached(). The device replace ioctl() only works on a mounted filesystem and the only caller with setting 'new' to false is read_one_block_group() which is only called during mount, so it is safe to drop the rwsem before calling into blkdev_report_zones_cached().
--- fs/btrfs/zoned.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/btrfs/zoned.c +3 -4
@@ -1393,11 +1393,13 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,return 0 ; } +ASSERT (!test_bit (BTRFS_FS_OPEN , &fs_info->flags)); +up_read (&dev_replace->rwsem); + nofs_flag =memalloc_nofs_save (); ret =btrfs_get_dev_zone (device, info->physical, &zone);memalloc_nofs_restore (nofs_flag);if (ret) { -up_read (&dev_replace->rwsem);if (ret != -EIO && ret != -EOPNOTSUPP )return ret; info->alloc_offset =WP_MISSING_DEV ;
@@ -1409,7 +1411,6 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,"zoned: unexpected conventional zone %llu on device %s (devid %llu)" , zone.start <<SECTOR_SHIFT ,rcu_dereference (device->name), device->devid); -up_read (&dev_replace->rwsem);return -EIO ; }
@@ -1437,8 +1438,6 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,break ; } -up_read (&dev_replace->rwsem); -return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/1005 btrfs: zstd: prevent leak of workspace below maximum level
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit bb66a38f5812f2c04abd4eb6e586a12b5a95172a ]
When putting a workspace we always protect the workspace for the maximum level from reclaim, since it can be used not just for that level but as well for any level below it. However the logic is flawed because if we do the put for a workspace at level 10 for example (maximum is level 15) and there is currently no idle workspace for the maximum level because all are currently being used, we don't add the workspace to the LRU list and that can result in leaking it if we don't get more compression or decompression requests for level 10 or any level below 10.
Fix this by skipping the addition to the LRU list only if the level of the workspace matches the maximum level too (besides the list of idle workspaces for the maximum level being empty).
--- fs/btrfs/zstd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/zstd.c +2 -1
@@ -347,7 +347,8 @@ void zstd_put_workspace(struct btrfs_fs_info *fs_info, struct list_head *ws)/* A node is only taken off the lru if we are the corresponding level */ if (clip_level (workspace->req_level) == workspace->level) {/* Hide a max level workspace from reclaim */ -if (list_empty (&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL -1 ])) { +if (workspace->level ==ZSTD_BTRFS_MAX_LEVEL -1 && +list_empty (&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL -1 ])) {INIT_LIST_HEAD (&workspace->lru_list); }else { workspace->last_used = jiffies;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/1005 btrfs: handle zero num_stripes in btrfs_chunk_item_size()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cheng Yongkang <[email protected]>
[ Upstream commit 8416012aa6e794a6464e073ab236f4ff862935ac ]
validate_sys_chunk_array() calls btrfs_chunk_item_size() with the on-disk num_stripes before btrfs_check_chunk_valid() has checked the chunk. With CONFIG_BTRFS_ASSERT=y, a zero-stripe system chunk trips ASSERT(num_stripes) instead of being rejected:
assertion failed: num_stripes, in fs/btrfs/volumes.h:714 kernel BUG at fs/btrfs/volumes.h:714!
RIP: 0010:btrfs_validate_super+0x3ce7/0x4210 Call Trace: open_ctree btrfs_get_tree vfs_get_tree do_new_mount
Drop the assertion and compute the size as the chunk header plus num_stripes stripes. The size is unchanged for num_stripes > 0, and a zero-stripe chunk now reaches btrfs_check_chunk_valid(), which rejects it, so the mount fails with -EUCLEAN.
--- fs/btrfs/volumes.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/volumes.h +2 -3
@@ -711,9 +711,8 @@ static inline enum btrfs_map_op btrfs_op(const struct bio *bio)static inline unsigned long btrfs_chunk_item_size (int num_stripes) { -ASSERT (num_stripes); -return sizeof (struct btrfs_chunk ) + -sizeof (struct btrfs_stripe ) * (num_stripes -1 ); +return offsetof(struct btrfs_chunk , stripe) + +sizeof (struct btrfs_stripe ) * num_stripes; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/1005 tcp: rate limit receive queue collapsing
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit c2213d9b61c1d6e99645a636630ee767c7542f78 ]
When a socket is over its receive buffer limit and its sk_rcvbuf can not grow, every incoming segment that needs memory goes through tcp_prune_queue(), which runs tcp_collapse_ofo_queue() and tcp_collapse() on the receive queue. Both walk their whole queue, even when there is nothing left to collapse.
A peer can trigger this walk per packet, without refilling memory:
1) The segment lands last in the out-of-order queue. Since commit b0e01253a764 ("tcp: refine tcp_prune_ofo_queue() logic"), tcp_prune_ofo_queue() drops nothing, the segment is dropped and the queues are unchanged. The peer can send it again forever.
2) The segment lands second to last: one skb is pruned, and one small segment fills that space again.
3) The out-of-order queue is empty and the receive queue alone is over the limit (application not reading). Collapsing frees nothing, the out-of-order segment is dropped, and the window is not closed.
4) Collapsing frees just one skb, enough to queue the segment. The next segment is over the limit again.
Only allow a collapse if at least 1/8 of sk_rcvbuf of new memory was queued in the receive queues since the previous collapse. This restores the "12.5 % of the queue capacity" amortization of the 2018 SegmentSmack fixes (CVE-2018-5390), using the same unit as the sk_rcvbuf limit, so that peers sending small (bloated) segments are not penalized.
The credit is the net growth of sk_rmem_alloc in tcp_queue_rcv() and tcp_data_queue_ofo(), so that:
- Coalescing a segment into the tailroom of the previous skb charges no memory, and earns no credit.
- An out-of-order segment replacing or covering queued skbs only earns the memory it adds.
- Duplicates earn nothing.
- Data moved from the out-of-order queue to the receive queue (tcp_ofo_queue()) is not credited twice.
In-order data is credited too, so that a receive queue filled by bloated in-order segments can still be collapsed when a hole appears.
In-order segments are rate limited as well: a peer could otherwise send small in-order segments that each trigger a collapse freeing a single skb, enough to queue the segment, while the out-of-order queue holds many skbs that can not be collapsed.
The credit is tracked in a new u32 tp->rcv_collapse_credit, placed in a hole of the tcp_sock_write_rx group: no other field moves, and tcp_sock size is unchanged. tcp_queue_rcv() now samples sk_rmem_alloc, and writes the credit until it saturates at sk_rcvbuf, so that the fast path stops writing it after a full buffer of new memory. Saturating at the goal would not work: sk_rcvbuf, and the goal with it, can grow later (for instance in tcp_clamp_window(), just before the goal is checked), and a socket over its limit can not earn more credit until the application reads.
When collapsing is not allowed, tcp_prune_queue() goes directly to tcp_prune_ofo_queue(), which is cheap in the cases above.
A regular flow can see a difference when it goes over its limit before 1/8 of sk_rcvbuf of new memory was queued since the previous collapse:
out-of-order skbs can be pruned (even for an in-order segment filling a hole), and an in-order segment that still does not fit is dropped, with a zero window advertised, where a collapse might have made room.
--- .../networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 1 + net/ipv4/tcp.c | 2 + net/ipv4/tcp_input.c | 55 +++++++++++++++---- 4 files changed, 48 insertions(+), 11 deletions(-)
Documentation/networking/net_cachelines/tcp_sock.rst +1 -0
@@ -106,6 +106,7 @@ u32[3] received_ecn_bytes read_mostly read_w u8:4 received_ce_pending read_mostly read_write u32[3] delivered_ecn_bytes read_write u16 pkts_acked_ewma read_write +u32 rcv_collapse_credit read_write tcp_queue_rcv,tcp_data_queue_ofo,tcp_prune_queue u8:2 syn_ect_snt write_mostly read_write u8:2 syn_ect_rcv read_mostly read_write u8:2 accecn_minlen write_mostly read_write
include/linux/tcp.h +1 -0
@@ -356,6 +356,7 @@ struct tcp_sock {u32 rcv_rtt_last_tsecr;u32 delivered_ecn_bytes[3 ];u16 pkts_acked_ewma;/* Pkts acked EWMA for AccECN cep heuristic */ +u32 rcv_collapse_credit;/* memory queued since last collapse */ struct {u32 rtt_us;u32 seq;
net/ipv4/tcp.c +2 -0
@@ -3492,6 +3492,7 @@ int tcp_disconnect(struct sock *sk, int flags) tp->rx_opt.dsack =0 ; tp->rx_opt.num_sacks =0 ; tp->rcv_ooopack =0 ; + tp->rcv_collapse_credit =0 ;/* Clean up fastopen related fields */
@@ -5306,6 +5307,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_last_tsecr); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, delivered_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, pkts_acked_ewma); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_collapse_credit); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_est); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcvq_space); }
net/ipv4/tcp_input.c +44 -11
100 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/1005 ASoC: es9356: fix the capture gain dB scale
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zachary Huang <[email protected]>
[ Upstream commit 412a061ebf8ce0d4d49fc7352dba8d641257b3a6 ]
The two capture gain controls are declared with a TLV step of 3 (FU33, analog mic) and 6 (FU11, DMIC). The TLV step is expressed in 0.01 dB units, so this advertises 0.03 dB and 0.06 dB per step: with a value range of 0..10 and 0..3 the whole controls appear to span only 0.30 dB and 0.18 dB.
The hardware steps are 3 dB and 6 dB, i.e. 0..30 dB and 0..18 dB. Measured on a MECHREVO WUJIE 14SAH (ES9356 on SoundWire link 0) by recording the same signal at all four FU11 settings:
FU11=0 rms 523 (-35.9 dBFS)
FU11=1 rms 1007 (-30.3 dBFS)
FU11=2 rms 2011 (-24.2 dBFS)
FU11=3 rms 3794 (-18.7 dBFS)That is about +6 dB per step, matching the hardware definition rather than the advertised 0.06 dB.
Because userspace (alsamixer, PipeWire/WirePlumber) derives the volume from this TLV, the capture gain currently looks like a control without any usable range, which is also why the default setting seems impossible to raise from the desktop.
--- sound/soc/codecs/es9356.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/es9356.c +2 -2
@@ -59,8 +59,8 @@ static int es9356_sdw_component_probe(struct snd_soc_component *component) } static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -9600, 12, 0); -static const DECLARE_TLV_DB_SCALE(amic_gain_tlv, 0, 3, 0); -static const DECLARE_TLV_DB_SCALE(dmic_gain_tlv, 0, 6, 0); +static const DECLARE_TLV_DB_SCALE(amic_gain_tlv, 0, 300, 0); +static const DECLARE_TLV_DB_SCALE(dmic_gain_tlv, 0, 600, 0);static const struct snd_kcontrol_new es9356_sdca_controls[] = { SDCA_SINGLE_Q78_TLV("FU41 Left Playback Volume",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/1005 NFSv4.1: retain MDS I/O until both thresholds are met
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit eab627dcd18a18a44a2cbee47df3058d3637ba0d ]
When both size and I/O thresholds are configured, pnfs_within_mdsthreshold() uses size && io to decide whether to keep I/O on the MDS. Both variables indicate an unmet threshold, so reaching only one threshold returns false and may trigger pNFS layout acquisition while the other threshold remains unmet.
Use logical OR instead of AND to stay with MDS I/O until both thresholds are met, as recommended by RFC 8881 Section 5.12.6. The new RFC contains the same threshold selection rule as RFC 5661 which is referenced in function comment.
--- fs/nfs/pnfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/pnfs.c +1 -1
@@ -2071,7 +2071,7 @@ static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx,break ; }if (size_set && io_set) { -if (size && io) +if (size || io) ret = true; }else if (size || io) ret = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 428/1005 NFS: honor UTIME_NOW atime with explicit mtime
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 2ffcf17d26dabef5793aeadf75a23c595a72be08 ]
When utimensat() requests UTIME_NOW for atime and an explicit mtime, the VFS sets ATTR_ATIME but not ATTR_ATIME_SET (as it should). The delegated explicit-mtime path calls nfs_set_timestamps_to_ts(), which skips atime, but nfs_setattr() then clears ATTR_ATIME, allowing the syscall to succeed without updating atime.
The delegated explicit-mtime path already updates ctime locally. The VFS also supplies the requested atime value in ia_atime, even when ATTR_ATIME_SET is absent.
Check ATTR_ATIME instead of ATTR_ATIME_SET to also apply the UTIME_NOW atime value supplied by the VFS.
--- fs/nfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/inode.c +1 -1
@@ -644,7 +644,7 @@ static void nfs_set_timestamps_to_ts(struct inode *inode, struct iattr *attr)inode_maybe_inc_iversion (inode, updated); cache_flags |=NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ; } -if (attr->ia_valid &ATTR_ATIME_SET ) { +if (attr->ia_valid &ATTR_ATIME ) {inode_set_atime_to_ts (inode, attr->ia_atime); cache_flags |=NFS_INO_INVALID_ATIME ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/1005 NFS: update ctime for atime-only UTIME_NOW requests
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit a38d7cc8c90f0d093550487c2905b51db0be1522 ]
When an NFS client holds a timestamp delegation, utimensat() with atime set to UTIME_NOW and mtime set to UTIME_OMIT reaches nfs_setattr() with ATTR_TIMES_SET but without ATTR_ATIME_SET.
There may be other paths that can reach here as well.
The delegated-atime fast path treats this as an implicit atime update, clears ATTR_ATIME and returns success without updating ctime.
Add check for ATTR_TIMES_SET along with ATTR_ATIME_SET (OR) so explicit timestamp requests use the normal SETATTR path while incidental atime updates can keep using the local shortcut.
--- fs/nfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/inode.c +1 -1
@@ -740,7 +740,7 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, }else if (nfs_have_delegated_atime (inode) && attr->ia_valid &ATTR_ATIME && !(attr->ia_valid &ATTR_MTIME )) { -if (!(attr->ia_valid &ATTR_ATIME_SET )) { +if (!(attr->ia_valid & (ATTR_ATIME_SET |ATTR_TIMES_SET ))) {nfs_update_delegated_atime (inode); attr->ia_valid &= ~ATTR_ATIME ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/1005 NFS: Fix inverted cross-directory rename check
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit b9d518902ff1969f93d2b4787951d98e50ab0181 ]
nfs_rename_is_unsafe_cross_dir() returns false for cross-directory renames, causing nfs_rename() to skip nfs_sync_inode() even when filehandles may expire on rename. Same-directory renames may instead trigger unnecessary synchronization.
Current condition directly contradicts the function name/comments.
Return false for same-directory renames so cross-directory renames reach the existing filehandle-volatility check. Keep the conservative fallback unchanged..
--- fs/nfs/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/dir.c +1 -1
@@ -2735,7 +2735,7 @@ static bool nfs_rename_is_unsafe_cross_dir(struct dentry *old_dentry, {struct nfs_server *server =NFS_SB (old_dentry->d_sb); -if (old_dentry->d_parent != new_dentry->d_parent) +if (old_dentry->d_parent == new_dentry->d_parent)return false;if (server->fh_expire_type &NFS_FH_RENAME_UNSAFE )return !(server->fh_expire_type &NFS_FH_NOEXPIRE_WITH_OPEN );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 431/1005 NFS: restore directory index when resuming readdir
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 89b91409b2342e7629b1271eba315a0f06495247 ]
nfs_readdir() restores the cached folio index and cookie when resuming directory iteration, but leaves current_index at zero. In 32-bit index mode, nfs_readdir_search_for_cookie() then reports a folio-relative offset instead of the absolute entry position.
Restore current_index from the saved logical folio index before searching the cache.
This solution relies on the current behavior of nfs_readdir_seek_next_array(), where folio_index advances by one and current_index advances by nfs_readdir_array_maxentries() for each full, nonterminal folio.
--- fs/nfs/dir.c | 2 ++ 1 file changed, 2 insertions(+)
fs/nfs/dir.c +2 -0
@@ -1253,6 +1253,8 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)spin_lock (&file->f_lock); desc->dir_cookie = dir_ctx->dir_cookie; desc->folio_index = dir_ctx->page_index; + desc->current_index = (loff_t )desc->folio_index * +nfs_readdir_array_maxentries (); desc->last_cookie = dir_ctx->last_cookie; desc->attr_gencount = dir_ctx->attr_gencount; desc->eof = dir_ctx->eof;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 432/1005 SUNRPC: wake poll waiters when an empty pipe is unlinked
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 702d55edc017632a0c39c1d4bdd579bdbadfd730 ]
When an empty rpc_pipefs pipe is unlinked, rpc_purge_list() returns without waking the pipe wait queue. An existing epoll waiter can remain blocked even though rpc_pipe_poll() reports EPOLLHUP and EPOLLERR for the disconnected pipe.
Wake the wait queue after clearing RPC_I(inode)->pipe so existing poll waiters are notified regardless of whether messages were purged.
--- net/sunrpc/rpc_pipe.c | 1 + 1 file changed, 1 insertion(+)
net/sunrpc/rpc_pipe.c +1 -0
@@ -191,6 +191,7 @@ rpc_close_pipes(struct dentry *dentry)cancel_delayed_work_sync (&pipe->queue_timeout);rpc_inode_setowner (inode,NULL );RPC_I (inode)->pipe =NULL ; +wake_up (&RPC_I (inode)->waitq);inode_unlock (inode); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 433/1005 sunrpc: instantiate rpc_pipefs dentry before publishing it
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 0cd6e563938a5b2f88ce0008eda32f9617c9d81f ]
rpc_mkpipe_dentry() publishes pipe->dentry before d_make_persistent() attaches its inode. A concurrent rpc_queue_upcall() or rpc_timeout_upcall_queue() can conceivably dereference the dentry while d_inode() is NULL.
Attach the inode before publishing the dentry, restoring the ordering used before the rpc_pipefs conversion refactor.
--- net/sunrpc/rpc_pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/rpc_pipe.c +1 -1
@@ -666,8 +666,8 @@ int rpc_mkpipe_dentry(struct dentry *parent, const char *name, rpci->private = private; rpci->pipe = pipe;rpc_inode_setowner (inode, private); - pipe->dentry = dentry;// borrowed d_make_persistent (dentry, inode); + pipe->dentry = dentry;// borrowed fsnotify_create (dir, dentry);simple_done_creating (dentry);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 434/1005 SUNRPC: preserve fatal network errors during RPC binding
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 30150b94c70eff4bf916d7d367ecf75de25d5337 ]
call_bind_status() initializes status to -EIO. When an unbound transport's port lookup fails with -ENETDOWN or -ENETUNREACH and RPC_TASK_NETUNREACH_FATAL is set, the function exits the switch without updating status. The RPC task then reports -EIO instead of the network error.
This can occur during NFSv3 port discovery with nconnect, when an additional transport has not yet bound.
Preserve task->tk_status in the fatal branch. Leave the nonfatal retry handling unchanged.
--- net/sunrpc/clnt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/sunrpc/clnt.c +3 -1
@@ -2125,8 +2125,10 @@ call_bind_status(struct rpc_task *task) goto retry_timeout;case -ENETDOWN :case -ENETUNREACH : -if (task->tk_flags &RPC_TASK_NETUNREACH_FATAL ) +if (task->tk_flags &RPC_TASK_NETUNREACH_FATAL ) { + status = task->tk_status;break ; + } fallthrough;case -ECONNREFUSED :/* connection problems */ case -ECONNRESET :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 435/1005 SUNRPC: preserve timeout policy when cloning clients
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 5b0ac1f82201c2ab2d9c31ed568cc782bac6a399 ]
rpc_clone_client() and rpc_clone_client_set_auth() leave the timeout argument unset, causing rpc_new_client() to use the transport defaults instead of the parent's configured timeout. This also affects pNFS data-server clients and changes their request timeout and initial RTT calculations.
Use the parent's cl_timeout when no timeout is specified. Preserve explicitly supplied timeout overrides.
--- net/sunrpc/clnt.c | 2 ++ 1 file changed, 2 insertions(+)
net/sunrpc/clnt.c +2 -0
@@ -653,6 +653,8 @@ static struct rpc_clnt *__rpc_clone_client(struct rpc_create_args *args, } args->servername = xprt->servername; args->nodename = clnt->cl_nodename; +if (!args->timeout) + args->timeout = clnt->cl_timeout; new =rpc_new_client (args, xps, xprt, clnt);if (IS_ERR (new))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 436/1005 SUNRPC: preserve transport security policy when cloning clients
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 7783534ce5fee57adf1b9025745c9af2e1ce2ccd ]
RPC client cloning does not copy the parent's transport security policy into the new client. Clones consequently lose their TLS policy and certificate/key serials, even though the shared transport remains protected.
When NFSv4 migration replaces a cloned client's TLS transport, the missing security policy causes xs_setup_tcp_tls() to return -EACCES.
Copy the parent's cl_xprtsec into the clone arguments before creating the new client.
--- net/sunrpc/clnt.c | 1 + 1 file changed, 1 insertion(+)
net/sunrpc/clnt.c +1 -0
@@ -653,6 +653,7 @@ static struct rpc_clnt *__rpc_clone_client(struct rpc_create_args *args, } args->servername = xprt->servername; args->nodename = clnt->cl_nodename; + args->xprtsec = clnt->cl_xprtsec;if (!args->timeout) args->timeout = clnt->cl_timeout;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 437/1005 SUNRPC: Balance switch queue length on transport removal
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 8acd94f02a960c8936df25a7af9c02c8ea87064d ]
When call_connect_status() moves a task off a transport marked for removal, it decrements xprt->queuelen but leaves the switch's xps_queuelen unchanged. The stale count persists after the task finishes and skews multipath transport selection.
Decrement xps_queuelen alongside xprt->queuelen, matching the normal transport release path.
--- net/sunrpc/clnt.c | 1 + 1 file changed, 1 insertion(+)
net/sunrpc/clnt.c +1 -0
@@ -2262,6 +2262,7 @@ call_connect_status(struct rpc_task *task)xprt_release (task); value =atomic_long_dec_return (&xprt->queuelen); +atomic_long_dec (&xps->xps_queuelen);if (value ==0 )rpc_xprt_switch_remove_xprt (xps, saved, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 438/1005 SUNRPC: Balance queue accounting when relocating a task
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit f14b157168ac106cfac6d577e08726488b1b886c ]
When rpc_task_set_transport() relocates a movable task from an offline transport, it releases the request and drops the transport reference without decrementing the old transport's queuelen or the switch's xps_queuelen. Releasing the task later only accounts for the replacement transport.
The stale counts affect transport selection and can prevent xprt_delete_locked() from removing an otherwise idle transport.
Use rpc_task_release_xprt() to balance the previous assignment before selecting a replacement. Pass clnt explicitly because rpc_task_set_client() can assign a transport before tk_client is initialized.
--- net/sunrpc/clnt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/clnt.c +1 -1
@@ -1197,7 +1197,7 @@ void rpc_task_set_transport(struct rpc_task *task, struct rpc_clnt *clnt) (task->tk_flags & RPC_TASK_MOVEABLE)))return ;xprt_release (task); -xprt_put (task->tk_xprt); +rpc_task_release_xprt (clnt, task->tk_xprt); }if (task->tk_flags &RPC_TASK_NO_ROUND_ROBIN ) task->tk_xprt =rpc_task_get_first_xprt (clnt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 439/1005 NFS/localio: hold the client across an asynchronous LOCALIO probe
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Snitzer <[email protected]>
[ Upstream commit 000a87910213562ff09f5bc38cd366ce34fccf71 ]
nfs_local_probe_async() queues the client's own cl_local_probe_work without a reference on the client, and nfs_free_client() does not cancel it. The work takes a reference only once it runs. If the last nfs_put_client() comes first, for example at umount after an NFSv3 I/O queued a throttled probe, the client is freed with its work queued, and the work then runs on freed memory.
Take the reference when the work is queued, and drop it when the work has run. If the work is already queued, it already holds a reference, and the one just taken is dropped.
--- fs/nfs/localio.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/nfs/localio.c +10 -3
@@ -203,15 +203,22 @@ void nfs_local_probe_async_work(struct work_struct *work)struct nfs_client *clp = container_of(work, struct nfs_client, cl_local_probe_work); -if (!refcount_inc_not_zero (&clp->cl_count)) -return ;nfs_local_probe (clp); +/* The reference nfs_local_probe_async() took for this work */ nfs_put_client (clp); } +/* +* The work is part of the client, so it holds a reference on the client +* from when it is queued until it has run: the last nfs_put_client() +* cannot free the client under a queued probe. +*/ void nfs_local_probe_async (struct nfs_client *clp) { -queue_work (nfsiod_workqueue, &clp->cl_local_probe_work); +if (!refcount_inc_not_zero (&clp->cl_count)) +return ; +if (!queue_work (nfsiod_workqueue, &clp->cl_local_probe_work)) +nfs_put_client (clp);/* already queued, with its reference */ }EXPORT_SYMBOL_GPL (nfs_local_probe_async);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 440/1005 ublk: publish a new device by its id only once it is set up
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Korenberg <[email protected]>
[ Upstream commit e5c463e5074a940c644d54d8fc29aba06709aab0 ]
ADD_DEV stores the device in ublk_index_idr when it allocates the id, and control commands find it there as soon as ublk_add_chdev() has initialized its struct device, before the char device is added. If dev_set_name() or cdev_device_add() then fails, ublk_add_chdev() drops the initial reference to free the device. A DEL_DEV that found the device meanwhile waits for ublk_ctl_mutex, then calls ublk_remove():cdev_device_del() of a device that was never added, and a second put of the initial reference, which frees the device under the callers still holding references.
Reserve the id with a NULL entry, which idr_find() and the idr iterators skip, and store the device once ublk_add_chdev() succeeded.
--- drivers/block/ublk_drv.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/block/ublk_drv.c +21 -2
@@ -4403,14 +4403,18 @@ static int ublk_alloc_dev_number(struct ublk_device *ub, int idx)int i = idx;int err; +/* +* Only reserve the id: the device is published by +* ublk_publish_dev_number() once it is fully set up. +*/ spin_lock (&ublk_idr_lock);/* allocate id, if @id >= 0, we're requesting that specific id */ if (i >=0 ) { - err =idr_alloc (&ublk_index_idr, ub, i, i +1 ,GFP_NOWAIT ); + err =idr_alloc (&ublk_index_idr,NULL , i, i +1 ,GFP_NOWAIT );if (err == -ENOSPC ) err = -EEXIST ; }else { - err =idr_alloc (&ublk_index_idr, ub,0 ,UBLK_MAX_UBLKS , + err =idr_alloc (&ublk_index_idr,NULL ,0 ,UBLK_MAX_UBLKS ,GFP_NOWAIT ); }spin_unlock (&ublk_idr_lock);
@@ -4421,6 +4425,19 @@ static int ublk_alloc_dev_number(struct ublk_device *ub, int idx)return err; } +/* +* Make the device visible to control commands by its id. Before its char +* device is added, DEL_DEV could find it and remove a char device that was +* never added, and drop the reference that ublk_add_chdev() drops on +* failure. +*/ +static void ublk_publish_dev_number (struct ublk_device *ub) +{ +spin_lock (&ublk_idr_lock); +WARN_ON_ONCE (idr_replace (&ublk_index_idr, ub, ub->ub_number) !=NULL ); +spin_unlock (&ublk_idr_lock); +} +static void ublk_free_dev_number (struct ublk_device *ub) {spin_lock (&ublk_idr_lock);
@@ -4971,6 +4988,8 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header)* ublk_add_chdev() will cleanup everything if it fails. */ ret =ublk_add_chdev (ub); +if (!ret) +ublk_publish_dev_number (ub); goto out_unlock; out_deinit_queues:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 441/1005 net: skbuff: preserve fclone lifetime when freeing stolen heads
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 86706ffa990ecd46a4326f8eecbccbbd60a6cb8d ]
skb_morph() can give an skb from skbuff_fclone_cache a page-fragment head without changing its fclone tag. IPv4 reassembly can produce such an skb, which can subsequently reach the GRO stolen-head path.
napi_skb_free_stolen_head() puts the shell into the ordinary NAPI skb cache without dropping its fclone_ref. If the embedded companion is still live, KASAN poisons it along with the original, and later cache reuse or eviction can overwrite or free the allocation underneath it. A mirrored batman-adv DAT packet retained in a plug qdisc reproduces a KASAN use-after-free in plug_dequeue().
Use kfree_skbmem() for fclones in napi_skb_free_stolen_head(), retaining NAPI caching for ordinary skb heads. Also use kfree_skbmem() in kfree_skb_partial(), whose stolen-head branch has the same assumption about the allocation cache. This releases the shell according to its allocation kind and preserves any live companion without freeing the data that has been transferred to the receiving skb.
--- net/core/skbuff.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/core/skbuff.c +5 -1
@@ -1504,6 +1504,10 @@ void napi_skb_free_stolen_head(struct sk_buff *skb)skb_orphan (skb); skb->slow_gro =0 ; } +if (skb->fclone !=SKB_FCLONE_UNAVAILABLE ) { +kfree_skbmem (skb); +return ; + }napi_skb_cache_put (skb); }
@@ -6192,7 +6196,7 @@ void kfree_skb_partial(struct sk_buff *skb, bool head_stolen) {if (head_stolen) {skb_release_head_state (skb); -kmem_cache_free (net_hotdata.skbuff_cache, skb); +kfree_skbmem (skb); }else {__kfree_skb (skb); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 442/1005 xsk: fix list corruption in xsk_buff_add_frag()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 94ae1259175f566ed5a33f37b09b6f32a1b2d8af ]
In aligned mode, a fill ring address maps straight to its pool->heads[] entry. If user space posts the same address twice, a driver can pass xsk_buff_add_frag() a buffer that is the head of the frame or is already on pool->xskb_list or pool->free_list.
Re-adding a linked node corrupts the list. With buffers A, B, C, B, xsk_rcv_zc() emits two descriptors instead of four and leaves the list head pointing at a self-linked B. When the Rx ring later has no room for a frame, the xsk_buff_free() cleanup follows B into pool->free_list and passes the list head to xp_free():
BUG: kernel NULL pointer dereference, address: 00000000000000c0 RIP: 0010:xp_free+0x1a/0x50 Call Trace: xsk_rcv_zc+0xca/0x200
The head is not on any list and needs a separate check. Adding it as its own frag lets bpf_xdp_adjust_tail() free the in-use head and wrap sinfo->nr_frags to 255.
Reject such buffers before adding them to the frags array, as commit e37b2abca804 ("xsk: fix NULL pointer dereference in __xsk_rcv()") does in the copy path. Callers already drop the frame on failure.
Unaligned mode is not affected, as each fill ring entry gets its own xskb from pool->free_heads[].
Reproduced with a KUnit test feeding synthetic buffers to xsk_rcv_zc(), by Nagato Shiratana.
--- include/net/xdp_sock_drv.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/net/xdp_sock_drv.h +5 -2
@@ -160,15 +160,18 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)static inline bool xsk_buff_add_frag (struct xdp_buff *head,struct xdp_buff *xdp) { + struct xdp_buff_xsk *frag = container_of(xdp, struct xdp_buff_xsk, xdp);const void *data = xdp->data; -struct xdp_buff_xsk *frag; + +/* Duplicate fill ring entries map to the same xskb in aligned mode */ +if (unlikely (xdp == head || !list_empty (&frag->list_node))) +return false;if (!__xdp_buff_add_frag (head,virt_to_netmem (data),offset_in_page (data), xdp->data_end - data, xdp->frame_sz, false))return false; - frag = container_of(xdp, struct xdp_buff_xsk, xdp);list_add_tail (&frag->list_node, &frag->pool->xskb_list);return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 443/1005 i40e: xsk: fix xsk_buff_add_frag() error handling in Rx
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit a259b7ec09efec032d5521dc2eb751a959c11d15 ]
When xsk_buff_add_frag() fails, i40e_clean_rx_irq_zc() frees the frame but stays on the current descriptor, so the next poll restarts from the freed head. If the frags array was full, the retry passes on a frame missing the freed frags, with its head already on the free list. If the buffer is a duplicate, every poll fails the same way and the queue stalls.
Free the current buffer along with the frame and move on to the next descriptor, as ice does. The rest of the dropped frame is received as a new frame. xp_free() skips a duplicate already freed with the frame.
--- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +14 -6
@@ -459,16 +459,24 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget)xsk_buff_set_size (bi, size);xsk_buff_dma_sync_for_cpu (bi); -if (!first) +if (++next_to_process == count) + next_to_process =0 ; + +if (!first) { first = bi; -else if (!xsk_buff_add_frag (first, bi)) { + }else if (!xsk_buff_add_frag (first, bi)) { +/* Drop what has been gathered so far. xp_free() skips +* @bi if it duplicates a buffer that is already on a +* pool list. Remaining buffers of this packet, if any, +* will be processed as a new packet. +*/ xsk_buff_free (first); -break ; +xsk_buff_free (bi); + next_to_clean = next_to_process; + first =NULL ; +continue ; } -if (++next_to_process == count) - next_to_process =0 ; -if (i40e_is_non_eop (rx_ring, rx_desc))continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 444/1005 ice: xsk: fix leaking Rx buffers in multi-buffer path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 8b7bd01b9c56c0d1f65d0e2ad304b775e0d709e3 ]
ice_clean_rx_irq_zc() consumes a descriptor without freeing its buffer when a frag has zero length or when xsk_buff_add_frag() fails, which happens if the frags array is full or the fill ring has duplicates. Such buffers are lost to user space until the socket is closed.
Free the buffer in both cases. xp_free() skips a duplicate already freed with the frame.
--- drivers/net/ethernet/intel/ice/ice_xsk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_xsk.c +4 -1
@@ -618,8 +618,11 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring,if (!first) { first = xdp; - }else if (likely (size) && !xsk_buff_add_frag (first, xdp)) { + }else if (unlikely (!size)) { +xsk_buff_free (xdp); + }else if (!xsk_buff_add_frag (first, xdp)) {xsk_buff_free (first); +xsk_buff_free (xdp); first =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 445/1005 ice: xsk: do not free in-flight frags on XDP_TX completion
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 5a9b5e315e101dfa02af5d8d3b27d893ba3e5566 ]
ice_xmit_xdp_tx_zc() takes the frags of a multi-buffer frame off pool->xskb_list but leaves XDP_FLAGS_HAS_FRAGS set on the head. When the head completes, xsk_buff_free() frees whatever is on the list at that point, which are the frags of a frame still being received.
If ice_xmit_xdp_tx_zc() completes such a head while cleaning the ring before sending another frame, xsk_buff_get_frag() returns NULL and xsk_buff_xdp_get_dma() dereferences it.
Clear the flag on the head once its frags are on the ring. As xdp_get_buff_len() then covers only the head, count Rx bytes before running the XDP program, like libeth does.
--- drivers/net/ethernet/intel/ice/ice_xsk.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_xsk.c +8 -1
@@ -493,6 +493,11 @@ static int ice_xmit_xdp_tx_zc(struct xdp_buff *xdp, tx_desc->cmd_type_offset_bsz |=cpu_to_le64 (ICE_TX_DESC_CMD_EOP <<ICE_TXD_QW1_CMD_S ); +/* Each frag is now freed via its own Tx buffer. Completing the head +* must not release what is on the pool's frag list at that time. +*/ +xdp_buff_clear_frags_flag (head); +return ICE_XDP_TX ; busy:
@@ -592,6 +597,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring,struct sk_buff *skb;u16 stat_err_bits;u16 vlan_tci; +u32 xdp_len; rx_desc =ICE_RX_DESC (rx_ring, ntc);
@@ -634,6 +640,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, ((struct libeth_xdp_buff *)first)->desc = rx_desc; + xdp_len =xdp_get_buff_len (first); xdp_res =ice_run_xdp_zc (rx_ring, first, xdp_prog, xdp_ring, xsk_pool);if (likely (xdp_res & (ICE_XDP_TX |ICE_XDP_REDIR ))) {
@@ -648,7 +655,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, goto construct_skb; } - total_rx_bytes +=xdp_get_buff_len (first); + total_rx_bytes += xdp_len; total_rx_packets++; first =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 446/1005 libeth: xsk: do not free in-flight frags on XDP_TX completion
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 90e5d84086d95ac45197028b98ad9059b245fc1c ]
libeth_xsk_tx_queue_bulk() takes the frags of a multi-buffer frame off pool->xskb_list but leaves XDP_FLAGS_HAS_FRAGS set on the head. When the head completes, libeth_xsk_buff_free_slow() frees whatever is on the list at that point.
The XDPSQ can be completed by a bulk flush while the frags of a frame are being queued, or by its cleanup timer while a partial Rx frame is stashed. Those frags are then freed while in use, and the frame being queued is sent truncated.
Clear the flag on the head once all of its frags are queued.
--- include/net/libeth/xsk.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
include/net/libeth/xsk.h +8 -2
@@ -77,11 +77,17 @@ libeth_xsk_tx_queue_bulk(struct libeth_xdp_tx_bulk *bq,if (!libeth_xsk_tx_queue_head (bq, xdp)) goto out; -for (const struct libeth_xdp_buff *head = xdp; ; ) { +for (struct libeth_xdp_buff *head = xdp; ; ) { xdp =container_of (xsk_buff_get_frag (&head->base),typeof (*xdp), base); -if (!xdp) +if (!xdp) { +/* Each frag is now freed via its own SQE. Freeing +* the head must not release what is on the pool's +* frag list at that time. +*/ +xdp_buff_clear_frags_flag (&head->base);break ; + }if (unlikely (bq->count ==LIBETH_XDP_TX_BULK ) &&unlikely (!flush_bulk (bq,LIBETH_XDP_TX_XSK ))) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 447/1005 i40e: xsk: fix multi-buffer XDP_PASS skb construction
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chenguang Zhao <[email protected]>
[ Upstream commit 76b41e83e69ae4ab23cc3535e36b780ea17e76c2 ]
When AF_XDP ZC receives a multi-buffer frame and the XDP program returns XDP_PASS, i40e_construct_skb_zc() copies frags into a new skb. The copy used skb_frag_page() as the memcpy source (page metadata instead of packet data) and passed a virtual address to __skb_fill_page_desc_noacc(), which expects a struct page *.
Use skb_frag_address() for the copy, attach frags with skb_add_rx_frag() so len/data_len/truesize are updated, and on dev_alloc_page() failure free the skb via the shared out path so xsk_buff_free() still runs and previously attached pages are released by kfree_skb.
--- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +5 -8
@@ -318,22 +318,19 @@ static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring, goto out;for (int i =0 ; i < nr_frags; i++) { -struct skb_shared_info *skinfo =skb_shinfo (skb);skb_frag_t *frag = &sinfo->frags[i]; +unsigned int frag_size =skb_frag_size (frag);struct page *page; -void *addr; page =dev_alloc_page ();if (!page) {dev_kfree_skb (skb); -return NULL ; + skb =NULL ; + goto out; } - addr =page_to_virt (page); -memcpy (addr,skb_frag_page (frag),skb_frag_size (frag)); - -__skb_fill_page_desc_noacc (skinfo, skinfo->nr_frags++, - addr,0 ,skb_frag_size (frag)); +memcpy (page_to_virt (page),skb_frag_address (frag), frag_size); +skb_add_rx_frag (skb, i, page,0 , frag_size,PAGE_SIZE ); } out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 448/1005 ice: xsk: free stashed Rx frame when cleaning the ring
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit d5e7a86b7cd6c38a628635baace7eb2fdce14a43 ]
ice_clean_rx_irq_zc() stashes a partially received multi-buffer frame in rx_ring->xsk, with its frags on pool->xskb_list. next_to_clean is already past its buffers, so ice_xsk_clean_rx_ring(), which walks next_to_clean..next_to_use, misses the frame, and ice_vsi_cfg_rxq() later clears the pointer via ring->xdp.data.
The buffers are lost to user space and, as the pool outlives the ring across ifdown/ifup or a reset, the stale frags are taken as frags of the next frame. Before commit 93f53db9f9dc ("ice: switch to Page Pool"), the frame was tracked by rx_ring->first_desc and leaked the same way.
Free the stashed frame when cleaning the ring.
--- drivers/net/ethernet/intel/ice/ice_xsk.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/intel/ice/ice_xsk.c +5 -0
@@ -912,6 +912,11 @@ void ice_xsk_clean_rx_ring(struct ice_rx_ring *rx_ring)if (xdp_rxq_info_is_reg (&rx_ring->xdp_rxq))xdp_rxq_info_unreg (&rx_ring->xdp_rxq); +if (rx_ring->xsk) { +xsk_buff_free (&rx_ring->xsk->base); + rx_ring->xsk =NULL ; + } +while (ntc != ntu) {struct xdp_buff *xdp = *ice_xdp_buf (rx_ring, ntc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 449/1005 idpf: free stashed XSk Rx frame when releasing the queue
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Fijalkowski <[email protected]>
[ Upstream commit 3cbee39da8251098e2631a106fafcaebc7c8e66b ]
idpf_xskrq_poll() stashes a partially received multi-buffer frame in rxq->xsk, with its frags on pool->xskb_list. Nothing frees or clears rxq->xsk on queue release, as idpf_rx_desc_rel() only returns the page stash sharing its storage for non-XSk queues.
On ifdown, the buffers are lost to user space and, as the pool outlives the queue, the stale frags are taken as frags of the next frame. If the pool is disabled on a running interface, the queue restarts in page mode with rxq->xdp.data still pointing to an xskb of the pool, which is freed later. The page path then takes it for a partial frame, writes frag info through it and returns it to a page pool.
Free the stashed frame and clear the pointer when the XSk state of the queue is cleared, while the pool is still attached.
--- drivers/net/ethernet/intel/idpf/xsk.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/intel/idpf/xsk.c +5 -0
@@ -134,6 +134,11 @@ void idpf_xsk_clear_queue(void *q, enum virtchnl2_queue_type type)if (!idpf_queue_has_clear (XSK , rxq))return ; +if (rxq->xsk) { +libeth_xsk_buff_free_slow (rxq->xsk); + rxq->xsk =NULL ; + } + rxq->pool =NULL ;break ;case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 450/1005 net: usb: lan78xx: resume phylink on non-reset USB resume
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stefano Munari <[email protected]>
[ Upstream commit be9587c47db16faaca5415f533637755c65a4eb0 ]
lan78xx_suspend() calls phylink_suspend(dev->phylink, false) on an open interface, which always stops phylink and halts the PHY. The matching phylink_resume() is only called from lan78xx_reset_resume(). When the USB device stays powered across system sleep (e.g. s2idle) and the USB core calls .resume instead, the link stays down until the interface is brought down and up by hand. The ifdown triggers:
WARNING: drivers/net/phy/phy.c:1670 at phy_stop+0x44/0xc8 called from state HALTED
Move phylink_resume() to the end of lan78xx_resume(), which both resume paths go through, and call it only if the resume succeeded and the interface was open, mirroring lan78xx_suspend(). As a side effect, lan78xx_reset_resume() no longer starts phylink on a closed interface.
Tested on a Raspberry Pi 3B+ (LAN7515) with s2idle: the link now comes back up on its own after resume and ifdown no longer warns.
--- drivers/net/usb/lan78xx.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/net/usb/lan78xx.c +7 -9
@@ -5370,6 +5370,12 @@ static int lan78xx_resume(struct usb_interface *intf) out:mutex_unlock (&dev->dev_mutex); +if (!ret && dev_open) { +rtnl_lock (); +phylink_resume (dev->phylink); +rtnl_unlock (); + } +return ret; }
@@ -5384,15 +5390,7 @@ static int lan78xx_reset_resume(struct usb_interface *intf)if (ret <0 )return ret; - ret =lan78xx_resume (intf); -if (ret <0 ) -return ret; - -rtnl_lock (); -phylink_resume (dev->phylink); -rtnl_unlock (); - -return 0 ; +return lan78xx_resume (intf); }static const struct usb_device_id products[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 451/1005 net: raw: fix ICMP unreachable sent when receive queue is full
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 45441a94d50200f1478c52857725e6df624bf2ad ]
It's found in a raw socket application. When the application doesn't read packets in time, the client receives ICMP Protocol Unreachable, which makes the client abort the session.
The reason is that the server hits the sk_rcvbuf limit, and raw_v4_input() skips the socket before setting 'delivered', so it returns 0. Then ip_protocol_deliver_rcu() sees 'raw' is 0, thinks no one handles this protocol and calls icmp_send() to send ICMP Protocol Unreachable.
IPv6 has the same issue, ip6_protocol_deliver_rcu() sends ICMPv6 Parameter Problem instead.
Also, we'd better run icmp_filter() and ip_mc_sf_allow() (icmpv6_filter() for IPv6) before we check sk_rcvbuf, otherwise packets rejected by ICMP_FILTER/ICMPV6_FILTER or the multicast filter are counted in sk_drops. So move the check right before skb_clone().
--- net/ipv4/raw.c | 15 ++++++++------- net/ipv6/raw.c | 15 ++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-)
net/ipv4/raw.c +8 -7
@@ -182,18 +182,19 @@ static int raw_v4_input(struct net *net, struct sk_buff *skb, iph->saddr, iph->daddr, dif, sdif))continue ; -if (atomic_read (&sk->sk_rmem_alloc) >= -READ_ONCE (sk->sk_rcvbuf)) { -sk_drops_inc (sk); -continue ; - } - delivered =1 ;if ((iph->protocol !=IPPROTO_ICMP || !icmp_filter (sk, skb)) &&ip_mc_sf_allow (sk, iph->daddr, iph->saddr, skb->dev->ifindex, sdif)) { -struct sk_buff *clone =skb_clone (skb,GFP_ATOMIC ); +struct sk_buff *clone; + +if (atomic_read (&sk->sk_rmem_alloc) >= +READ_ONCE (sk->sk_rcvbuf)) { +sk_drops_inc (sk); +continue ; + } + clone =skb_clone (skb,GFP_ATOMIC );/* Not releasing hash table! */ if (clone)raw_rcv (sk, clone);
net/ipv6/raw.c +8 -7
@@ -160,12 +160,6 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr) inet6_iif(skb), inet6_sdif(skb)))continue ; -if (atomic_read (&sk->sk_rmem_alloc) >= -READ_ONCE (sk->sk_rcvbuf)) { -sk_drops_inc (sk); -continue ; - } - delivered = true;switch (nexthdr) {case IPPROTO_ICMPV6 :
@@ -197,8 +191,15 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)if (filtered <0 )break ;if (filtered ==0 ) { -struct sk_buff *clone =skb_clone (skb,GFP_ATOMIC ); +struct sk_buff *clone; + +if (atomic_read (&sk->sk_rmem_alloc) >= +READ_ONCE (sk->sk_rcvbuf)) { +sk_drops_inc (sk); +continue ; + } + clone =skb_clone (skb,GFP_ATOMIC );/* Not releasing hash table! */ if (clone)rawv6_rcv (sk, clone);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 452/1005 spi: virtio: move teardown to .remove()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francesco Valla <[email protected]>
[ Upstream commit 9060f5ba658c9b0a7332be55b3d8abfc2b08618b ]
The .remove() callback is not marked as optional for a virtio_driver, and thus a missing one is a bug. Moreover, the virtio framework expects a driver to reset the device it controls during teardown and explicitly checks for this reading the device status and WARNing in case it is still running. Any devm cleanup action gets however called after that check, leading to the WARN_ON condition to always be true for spi-virtio; thus, an empty remove() is not an option.
Move the cleanup actions to the .remove() callback of the driver and adapt the surrounding code to the new behavior.
--- drivers/spi/spi-virtio.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/spi/spi-virtio.c +15 -11
@@ -319,10 +319,8 @@ static int virtio_spi_find_vqs(struct virtio_spi_priv *priv) }/* Function must not be called before virtio_spi_find_vqs() has been run */ -static void virtio_spi_del_vq (void *data) +static void virtio_spi_del_vq (struct virtio_device *vdev) { -struct virtio_device *vdev = data; -virtio_reset_device (vdev); vdev->config->del_vqs (vdev); }
@@ -351,21 +349,26 @@ static int virtio_spi_probe(struct virtio_device *vdev)if (ret)return dev_err_probe (&vdev->dev, ret,"Cannot setup virtqueues\n" ); -/* Register cleanup for virtqueues using devm */ - ret =devm_add_action_or_reset (&vdev->dev, virtio_spi_del_vq, vdev); -if (ret) -return dev_err_probe (&vdev->dev, ret,"Cannot register virtqueue cleanup\n" ); -virtio_device_ready (vdev); -/* Use devm version to register controller */ - ret =devm_spi_register_controller (&vdev->dev, ctrl); -if (ret) + ret =spi_register_controller (ctrl); +if (ret) { +virtio_spi_del_vq (vdev);return dev_err_probe (&vdev->dev, ret,"Cannot register controller\n" ); + }return 0 ; } +static void virtio_spi_remove (struct virtio_device *vdev) +{ +struct spi_controller *ctrl =dev_get_drvdata (&vdev->dev); + +spi_unregister_controller (ctrl); + +virtio_spi_del_vq (vdev); +} +static int virtio_spi_freeze (struct device *dev) {struct spi_controller *ctrl =dev_get_drvdata (dev);
@@ -419,6 +422,7 @@ static struct virtio_driver virtio_spi_driver = { }, .id_table = virtio_spi_id_table, .probe = virtio_spi_probe, + .remove = virtio_spi_remove, };module_virtio_driver (virtio_spi_driver);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 453/1005 af_unix: Convert unsigned long to u64 for GC.
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit d5f898d4c47217ce42506698a3a98741393217b7 ]
Lim Chanyoun reported that unix_vertex_max_scc_index could wrap around on 32-bit kernels, which confuses GC into purging a live socket receive queue.
I apparently designed GC with u64 in mind to avoid wraparound. [0]
Let's make it true on 32-bit kernels.
Note that unix_vertex.{out_degree,index} are converted for consistency; they are bounded by the number of allocated objects and do not exceed UINT_MAX on 32-bit kernels.
--- net/unix/garbage.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
net/unix/garbage.c +14 -14
@@ -78,9 +78,9 @@ struct unix_vertex {struct list_head edges;struct list_head entry;struct list_head scc_entry; -unsigned long out_degree; -unsigned long index; -unsigned long scc_index; +u64 out_degree; +u64 index; +u64 scc_index; };struct unix_edge {
@@ -148,8 +148,8 @@ enum unix_vertex_index { UNIX_VERTEX_INDEX_START, }; -static unsigned long unix_vertex_unvisited_index =UNIX_VERTEX_INDEX_MARK1 ; -static unsigned long unix_vertex_max_scc_index =UNIX_VERTEX_INDEX_START ; +static u64 unix_vertex_unvisited_index =UNIX_VERTEX_INDEX_MARK1 ; +static u64 unix_vertex_max_scc_index =UNIX_VERTEX_INDEX_START ;static void unix_add_edge (struct scm_fp_list *fpl,struct unix_edge *edge) {
@@ -372,7 +372,7 @@ static bool unix_vertex_dead(struct unix_vertex *vertex) }static LIST_HEAD (unix_visited_vertices); -static unsigned long unix_vertex_grouped_index =UNIX_VERTEX_INDEX_MARK2 ; +static u64 unix_vertex_grouped_index =UNIX_VERTEX_INDEX_MARK2 ;static bool unix_scc_dead (struct list_head *scc) {
@@ -450,14 +450,14 @@ static bool unix_scc_cyclic(struct list_head *scc)return false; } -static unsigned long __unix_walk_scc (struct unix_vertex *vertex, -unsigned long *last_index, -struct sk_buff_head *hitlist) +static u64 __unix_walk_scc (struct unix_vertex *vertex, +u64 *last_index, +struct sk_buff_head *hitlist) { -unsigned long cyclic_sccs =0 ;LIST_HEAD (vertex_stack);struct unix_edge *edge;LIST_HEAD (edge_stack); +u64 cyclic_sccs =0 ; next_vertex:/* Push vertex to vertex_stack and mark it as on-stack
@@ -553,12 +553,12 @@ static unsigned long __unix_walk_scc(struct unix_vertex *vertex,return cyclic_sccs; } -static unsigned long unix_graph_cyclic_sccs; +static u64 unix_graph_cyclic_sccs;static void unix_walk_scc (struct sk_buff_head *hitlist) { -unsigned long last_index =UNIX_VERTEX_INDEX_START ; -unsigned long cyclic_sccs =0 ; +u64 last_index =UNIX_VERTEX_INDEX_START ; +u64 cyclic_sccs =0 ; unix_vertex_max_scc_index =UNIX_VERTEX_INDEX_START ;
@@ -582,7 +582,7 @@ static void unix_walk_scc(struct sk_buff_head *hitlist)static void unix_walk_scc_fast (struct sk_buff_head *hitlist) { -unsigned long cyclic_sccs = unix_graph_cyclic_sccs; +u64 cyclic_sccs = unix_graph_cyclic_sccs;while (!list_empty (&unix_unvisited_vertices)) {struct unix_vertex *vertex;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 454/1005 af_unix: Remove gc_in_progress check in unix_peek_fpl().
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 0edbc945eb9edd0086f25b151a79cfe4adc0dfa8 ]
unix_vertex_dead() and unix_peek_fpl() are synchronised with unix_peek_seq to prevent GC from purging a live socket's recvq.
unix_peek_fpl() skips the synchronisation if gc_in_progress is false.
However, on weakly ordered arch, GC might have already started working while the write to gc_in_progress is buffered.
This does not occur on x86.
This is an unlikely path that happens only when AF_UNIX fd is peeked so not worth complicating.
Instead of adding memory barriers in unix_gc() and unix_peek_fpl(), let's simply remove the broken short-circuit.
--- net/unix/garbage.c | 3 --- 1 file changed, 3 deletions(-)
net/unix/garbage.c +0 -3
@@ -329,9 +329,6 @@ void unix_peek_fpl(struct scm_fp_list *fpl)if (!fpl || !fpl->count_unix)return ; -if (!READ_ONCE (gc_in_progress)) -return ; -/* Invalidate the final refcnt check in unix_vertex_dead(). */ spin_lock (&unix_peek_lock);raw_write_seqcount_barrier (&unix_peek_seq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 455/1005 net/mlx5: Bridge, fix bogus MDB offload errors
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gal Pressman <[email protected]>
[ Upstream commit c714f324eac17b2df03419b5cd5368687efd8e27 ]
MDB add operations are queued on the switchdev deferred queue (SWITCHDEV_F_DEFER), while vlan object deletions are handled synchronously.
A 'bridge vlan del' can overtake an MDB add that is still queued, and the vlan is already gone by the time the driver is called.
The two operations are independent in practice: in my test, the MDB add is triggered by assigning the VF an IPv6 address (hence joining a solicited-node multicast group), while another process deletes the vlan from its representor.
Racing 'bridge mdb add' against concurrent 'bridge vlan del' could result in:
[ 5390.967651] mlx5_core 0000:08:00.0: E-Switch: Failed to lookup bridge port vlan metadata (vport=1)
[ 5390.969120] mlx5_core 0000:08:00.1: E-Switch: Failed to lookup bridge port vlan metadata to create MDB (MAC=33:33:ff:12:00:05,vid=2204,vport=1)
[ 5390.971676] mlx5_core 0000:08:00.1 eth4: Failed to add Port Multicast Database entry (object id=2) with error: -EINVAL (-22).
Failure in updating the port's Multicast Database could lead to
multicast forwarding issues.The error cannot reach anyone that could do anything with it, switchdev returned success to the bridge as soon as the MDB object was queued, and the errno only flags the entry as offload failed.
The end result is correct either way, if the MDB has been offloaded before the vlan was deleted, mlx5_esw_bridge_port_mdb_vlan_flush() would have removed it.
The FDB path already treats this as a harmless race, mlx5_esw_bridge_port_vlan_lookup() reports it on 'info' logging level and skips the offload. mlxsw did the same in [1].
Skip the MDB offload, report on 'info' logging level and return -EOPNOTSUPP: switchdev_port_obj_add_deferred() does not log it, and br_switchdev_mdb_complete() skips the port group flag update.
[1] Commit 17b334a876fe ("mlxsw: spectrum_switchdev: Don't warn about valid situations")
--- .../ethernet/mellanox/mlx5/core/esw/bridge.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +11 -10
@@ -1867,26 +1867,27 @@ int mlx5_esw_bridge_port_mdb_add(struct net_device *dev, u16 vport_num, u16 esw_ port =mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, br_offloads);if (!port) { -esw_warn (br_offloads->esw->dev, +/* MDB is added asynchronously from the switchdev deferred +* queue while port might have been deleted concurrently. +*/ +esw_info (br_offloads->esw->dev,"Failed to lookup bridge port to add MDB (MAC=%pM,vport=%u)\n" , addr, vport_num); -NL_SET_ERR_MSG_FMT_MOD (extack, -"Failed to lookup bridge port to add MDB (MAC=%pM,vport=%u)" , - addr, vport_num); -return -EINVAL ; +return -EOPNOTSUPP ; } bridge = port->bridge;if (bridge->flags &MLX5_ESW_BRIDGE_VLAN_FILTERING_FLAG && vid) { vlan =mlx5_esw_bridge_vlan_lookup (vid, port);if (!vlan) { -esw_warn (br_offloads->esw->dev, +/* MDB is added asynchronously from the switchdev +* deferred queue while vlan might have been deleted +* concurrently. +*/ +esw_info (br_offloads->esw->dev,"Failed to lookup bridge port vlan metadata to create MDB (MAC=%pM,vid=%u,vport=%u)\n" , addr, vid, vport_num); -NL_SET_ERR_MSG_FMT_MOD (extack, -"Failed to lookup vlan metadata for MDB (MAC=%pM,vid=%u,vport=%u)" , - addr, vid, vport_num); -return -EINVAL ; +return -EOPNOTSUPP ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 456/1005 ipv6: ignore link state in gateway check
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yaroslav Dudkov <[email protected]>
[ Upstream commit b76bcf3fff9332076d92de47a80d12fd3d5268e2 ]
IPv6 route cannot be added in table when all
following conditions are true:
- gateway is not link-local address
- ignore_routes_with_linkdown=1 on device
- nexthop has no carrier
- gateway is not present or covered by any route in table already Also multipath routes addition is invalidated by kernel even if only one of added nexthops satisfies all above conditions.
Reproducer:
ip netns add t
ip -n t link add va type veth peer name vb ip -n t link set va up
ip -n t addr add fd00::1/64 dev va nodad
ip netns exec t sysctl -w \
net.ipv6.conf.va.ignore_routes_with_linkdown=1
ip -n t -6 route add 2001:db8::/64 via fd00::2 dev va
# added ip -n t -6 route add 2001:db8::/64 table 100 via fd00::2 dev va # RTNETLINK answers: No route to host ip -n t -6 route show table all ip netns del t
Route should be added because:
- RT6_LOOKUP_F_IGNORE_LINKSTATE in commit d5d32e4b7668 ("net: ipv6: Do not consider link state for nexthop validation") was added for this
- the same route is valid in main table (when no specifying table id while adding route)
- fib6_nh_init() initializes nexthops with no carrier
- IPv4 already does this (fib_check_nh_v4_gw() ignores link state using the FIB_LOOKUP_IGNORE_LINKSTATE flag)
Before commit b2c709cce682 ("ipv6: Convert gateway validation to use fib6_info") rt6_lookup() was used for checking if nexthop is valid, rt6_lookup called rt6_device_match() which does not check the link state. After change rt6_lookup() to fib6_lookup() find_match() under fib6_lookup() started to invalidate linkdown devices, because RT6_LOOKUP_F_IGNORE_LINKSTATE is not passed to it.
Adding RT6_LOOKUP_F_IGNORE_LINKSTATE to flags for ip6_route_check_nh() solves the problem. RT6_LOOKUP_F_IGNORE_LINKSTATE is already used inside the first search ip6_nh_lookup_table() and fixes the bug in second search fib6_lookup(). Also RT6_LOOKUP_F_IGNORE_LINKSTATE isn't read inside fib6_select_path().
--- net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
@@ -3483,9 +3483,9 @@ static int ip6_route_check_nh(struct net *net,netdevice_tracker *dev_tracker, struct inet6_dev **idev) { + int flags = RT6_LOOKUP_F_IFACE | RT6_LOOKUP_F_IGNORE_LINKSTATE;const struct in6_addr *gw_addr = &cfg->fc_gateway;struct net_device *dev = _dev ? *_dev :NULL ; -int flags =RT6_LOOKUP_F_IFACE ;struct fib6_result res = {};int err = -EHOSTUNREACH ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 457/1005 team: fix promisc/allmulti leak in team_port_add error path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit ff618cb00a645f1e3f89068c5fbda3f3a7f4ae63 ]
team_port_add() increments the port's promiscuity and allmulti counts before calling team_dev_type_check_change(). If the latter fails, the error path does not undo these increments, leaving the port in promiscuous and allmulti mode even though it was not successfully added to the team.
Undo the promiscuity increment under err_set_slave_allmulti and the allmulti increment under err_set_dev_type, so each error label only reverts what was successfully applied, matching the cleanup performed by team_port_del().
With the promiscuity rollback now living under err_set_slave_allmulti, the inline dev_set_promiscuity(port_dev, -1) in the dev_set_allmulti() failure branch becomes redundant: that branch already jumps to err_set_slave_allmulti, which undoes the promiscuity increment. Drop the inline call to avoid doing it twice.
Found by source code audit.
--- drivers/net/team/team_core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/team/team_core.c +5 -4
@@ -1365,11 +1365,8 @@ static int team_port_add(struct team *team, struct net_device *port_dev,/* set allmulti level to new slave */ if (dev->flags &IFF_ALLMULTI ) { err =dev_set_allmulti (port_dev,1 ); -if (err) { -if (dev->flags &IFF_PROMISC ) -dev_set_promiscuity (port_dev,-1 ); +if (err) goto err_set_slave_allmulti; - } } err =team_dev_type_check_change (dev, port_dev);
@@ -1397,7 +1394,11 @@ static int team_port_add(struct team *team, struct net_device *port_dev,return 0 ; err_set_dev_type: +if (dev->flags &IFF_ALLMULTI ) +dev_set_allmulti (port_dev,-1 ); err_set_slave_allmulti: +if (dev->flags &IFF_PROMISC ) +dev_set_promiscuity (port_dev,-1 ); err_set_slave_promisc:__team_option_inst_del_port (team, port);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 458/1005 net: octeontx2: fix building without DEBUGFS
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
[ Upstream commit 2007f7e37142ebdb341949dca8098f898cc871f7 ]
This error came up on my randconfig tests this week:
drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c: In function 'npc_cn20k_debugfs_init':drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c:392:55: error: 'struct rvu' has no member named 'rvu_dbg'; did you mean 'rvu_dl'?
392 | debugfs_create_file("mcam_layout", 0444, rvu->rvu_dbg.npc,
The problem here is that the rvu_dbg member is hidden in an #ifdef block, but the reference to it is not.
Remove the #ifdef and waste a few bytes in the structure in this config. Note that the debugfs_create_file() call end up ignoring the arguments, so the actual debugfs implementation is still ignored here.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 5 ----- 1 file changed, 5 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +0 -5
@@ -75,8 +75,6 @@ static inline int rvu_pcifunc_pf_mask(struct pci_dev *pdev)#define RVU_AFPF 25 -#ifdef CONFIG_DEBUG_FS -struct dump_ctx {int lf;int id;
@@ -111,7 +109,6 @@ struct rvu_debugfs {int npa_qsize_id;int nix_qsize_id; }; -#endif struct rvu_work {struct work_struct work;
@@ -648,9 +645,7 @@ struct rvu {int mcs_blk_cnt;int cpt_pf_num; -#ifdef CONFIG_DEBUG_FS struct rvu_debugfs rvu_dbg; -#endif struct rvu_devlink *rvu_dl;/* RVU switch implementation over NPC with DMAC rules */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 459/1005 net/mlx5: Use only loaded devices for PTP clock operations
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carolina Jubran <[email protected]>
[ Upstream commit 908561cc4b4db4510465f02f5323e98f2dc00fad ]
The PTP periodic worker and PTP operations access PCI registers through the function backing the PTP clock. The PTP clock remains registered when a PCI function is suspended, so these paths can still access the function after it has been unloaded.
To fix that, serialize clock hardware access with the clock mutex for all clocks and fail callbacks with -EAGAIN when there is no loaded function to service the clock. Additionally, tie the worker's lifetime to load/unload and use the devcom lock to synchronize with peer loads/unloads.
Since the periodic worker is stopped during unload, the free running counter may wrap without being sampled. Reinitialize the timecounter on load using the hardware real time clock in real time mode, or the saved PHC time plus elapsed CLOCK_BOOTTIME in free running mode.
This provides best effort PHC continuity across unload/load. In free running mode, elapsed time while unloaded is estimated using CLOCK_BOOTTIME rather than the PHC's adjusted frequency.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 248 +++++++++++++----- .../ethernet/mellanox/mlx5/core/lib/clock.h | 2 + 2 files changed, 185 insertions(+), 65 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +183 -65
@@ -80,6 +80,7 @@ enum { };struct mlx5_clock_dev_state { +bool loaded;struct mlx5_core_dev *mdev;struct mlx5_devcom_comp_dev *compdev;struct mlx5_nb pps_nb;
@@ -89,7 +90,7 @@ struct mlx5_clock_dev_state {struct mlx5_clock_priv {struct mlx5_clock clock;struct mlx5_core_dev *mdev; -struct mutex lock;/* protect mdev and used in PTP callbacks */ +struct mutex lock;/* protect mdev and serialize hardware callbacks */ struct mlx5_core_dev *event_mdev; };
@@ -100,9 +101,6 @@ static struct mlx5_clock_priv *clock_priv(struct mlx5_clock *clock)static void mlx5_clock_lockdep_assert (struct mlx5_clock *clock) { -if (!clock->shared) -return ; -lockdep_assert (lockdep_is_held (&clock_priv (clock)->lock)); }
@@ -115,20 +113,24 @@ static struct mlx5_core_dev *mlx5_clock_mdev_get(struct mlx5_clock *clock)static void mlx5_clock_lock (struct mlx5_clock *clock) { -if (!clock->shared) -return ; -mutex_lock (&clock_priv (clock)->lock); }static void mlx5_clock_unlock (struct mlx5_clock *clock) { -if (!clock->shared) -return ; -mutex_unlock (&clock_priv (clock)->lock); } +static struct mlx5_core_dev * +mlx5_clock_active_mdev_get (struct mlx5_clock *clock) +{ +struct mlx5_clock_priv *cpriv =clock_priv (clock); + +mlx5_clock_lockdep_assert (clock); + +return cpriv->mdev->clock_state->loaded ? cpriv->mdev :NULL ; +} +static bool mlx5_real_time_mode (struct mlx5_core_dev *mdev) {return (mlx5_is_real_time_rq (mdev) ||mlx5_is_real_time_sq (mdev));
@@ -333,7 +335,11 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp,int err;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (!mlx5_is_ptm_source_time_available (mdev)) { err = -EBUSY ;
@@ -359,7 +365,11 @@ static int mlx5_ptp_getcrosscycles(struct ptp_clock_info *ptp,int err;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (!mlx5_is_ptm_source_time_available (mdev)) { err = -EBUSY ;
@@ -411,6 +421,12 @@ static u64 read_internal_timer(struct cyclecounter *cc)return mlx5_read_time (mdev,NULL , false) & cc->mask; } +static void mlx5_timer_snapshot (struct mlx5_timer *timer) +{ + timer->saved_phc_ns = timer->tc.nsec; + timer->saved_boot_ns =ktime_get_boottime_ns (); +} +static void mlx5_update_clock_info_page (struct mlx5_core_dev *mdev) {struct mlx5_ib_clock_info *clock_info = mdev->clock_info;
@@ -418,6 +434,9 @@ static void mlx5_update_clock_info_page(struct mlx5_core_dev *mdev)struct mlx5_timer *timer;u32 sign; + timer = &clock->timer; +mlx5_timer_snapshot (timer); +if (!clock_info)return ;
@@ -425,7 +444,6 @@ static void mlx5_update_clock_info_page(struct mlx5_core_dev *mdev)smp_store_mb (clock_info->sign, sign |MLX5_IB_CLOCK_INFO_KERNEL_UPDATING ); - timer = &clock->timer; clock_info->cycles = timer->tc.cycle_last; clock_info->mult = timer->cycles.mult; clock_info->nsec = timer->tc.nsec;
@@ -471,10 +489,9 @@ static long mlx5_timestamp_overflow(struct ptp_clock_info *ptp_info) clock = container_of(ptp_info, struct mlx5_clock, ptp_info);mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); timer = &clock->timer; - -if (mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR ) +if (!mdev || mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR ) goto out;write_seqlock_irqsave (&clock->lock, flags);
@@ -531,8 +548,13 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64int err;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } err =mlx5_clock_settime (mdev, clock, ts); +unlock:mlx5_clock_unlock (clock);return err;
@@ -550,26 +572,40 @@ struct timespec64 mlx5_ptp_gettimex_real_time(struct mlx5_core_dev *mdev,return ts; } -static int mlx5_ptp_gettimex (struct ptp_clock_info *ptp,struct timespec64 *ts, -struct ptp_system_timestamp *sts) +static void mlx5_clock_gettimex (struct mlx5_core_dev *mdev, +struct mlx5_clock *clock,struct timespec64 *ts, +struct ptp_system_timestamp *sts) { - struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); -struct mlx5_core_dev *mdev;u64 cycles, ns; -mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock);if (mlx5_real_time_mode (mdev)) { *ts =mlx5_ptp_gettimex_real_time (mdev, sts); - goto out; +return ; } cycles =mlx5_read_time (mdev, sts, false); ns =mlx5_timecounter_cyc2time (clock, cycles); *ts =ns_to_timespec64 (ns); -out: +} + +static int mlx5_ptp_gettimex (struct ptp_clock_info *ptp,struct timespec64 *ts, +struct ptp_system_timestamp *sts) +{ +struct mlx5_clock *clock = + container_of(ptp, struct mlx5_clock, ptp_info); +struct mlx5_core_dev *mdev; +int err =0 ; + +mlx5_clock_lock (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } +mlx5_clock_gettimex (mdev, clock, ts, sts); +unlock:mlx5_clock_unlock (clock); -return 0 ; +return err; } static int mlx5_ptp_getcyclesx(struct ptp_clock_info *ptp,
@@ -580,14 +616,20 @@ static int mlx5_ptp_getcyclesx(struct ptp_clock_info *ptp, ptp_info);struct mlx5_core_dev *mdev;u64 cycles; +int err =0 ;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } cycles =mlx5_read_time (mdev, sts, false); *ts =ns_to_timespec64 (cycles); +unlock:mlx5_clock_unlock (clock); -return 0 ; +return err; }static int mlx5_ptp_adjtime_real_time (struct mlx5_core_dev *mdev,s64 delta)
@@ -620,7 +662,11 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)int err =0 ;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (mlx5_modify_mtutc_allowed (mdev)) { err =mlx5_ptp_adjtime_real_time (mdev, delta);
@@ -630,6 +676,7 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) }write_seqlock_irqsave (&clock->lock, flags); +timecounter_read (&timer->tc);timecounter_adjtime (&timer->tc, delta);mlx5_update_clock_info_page (mdev);write_sequnlock_irqrestore (&clock->lock, flags);
@@ -646,8 +693,13 @@ static int mlx5_ptp_adjphase(struct ptp_clock_info *ptp, s32 delta)int err;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } err =mlx5_ptp_adjtime_real_time (mdev, delta); +unlock:mlx5_clock_unlock (clock);return err;
@@ -683,7 +735,11 @@ static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)u32 mult;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (mlx5_modify_mtutc_allowed (mdev)) { err =mlx5_ptp_freq_adj_real_time (mdev, scaled_ppm);
@@ -744,7 +800,11 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp, }mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + }if (!MLX5_PPS_CAP (mdev)) { err = -EOPNOTSUPP ;
@@ -917,7 +977,11 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp,return -EBUSY ;mlx5_clock_lock (clock); - mdev =mlx5_clock_mdev_get (clock); + mdev =mlx5_clock_active_mdev_get (clock); +if (!mdev) { + err = -EAGAIN ; + goto unlock; + } rt_mode =mlx5_real_time_mode (mdev);if (!MLX5_PPS_CAP (mdev)) {
@@ -1151,7 +1215,7 @@ static u64 perout_conf_next_event_timer(struct mlx5_core_dev *mdev,struct timespec64 ts;s64 target_ns; -mlx5_ptp_gettimex (&clock->ptp_info, &ts,NULL ); +mlx5_clock_gettimex (mdev, clock, &ts,NULL );ts_next_sec (&ts); target_ns =timespec64_to_ns (&ts);
@@ -1222,8 +1286,8 @@ static void mlx5_timecounter_init(struct mlx5_core_dev *mdev) timer->nominal_c_mult = timer->cycles.mult; timer->cycles.mask =CLOCKSOURCE_MASK (41 ); -timecounter_init (&timer->tc, &timer->cycles, -ktime_to_ns (ktime_get_real ())); +timecounter_init (&timer->tc, &timer->cycles,ktime_get_real_ns ()); +mlx5_timer_snapshot (timer); }static void mlx5_init_overflow_period (struct mlx5_core_dev *mdev)
@@ -1381,9 +1445,6 @@ static void mlx5_init_clock_dev(struct mlx5_core_dev *mdev) clock->ptp); clock->ptp =NULL ; } - -if (clock->ptp) -ptp_schedule_worker (clock->ptp,0 ); }static void mlx5_destroy_clock_dev (struct mlx5_core_dev *mdev)
@@ -1530,22 +1591,53 @@ static void mlx5_clock_arm_pps_in_event(struct mlx5_clock *clock, !clock->pps_info.pin_armed[i])continue ; -if (new_mdev) { +if (new_mdev)mlx5_set_mtppse (new_mdev, i,0 ,MLX5_EVENT_MODE_REPETETIVE ); - cpriv->event_mdev = new_mdev; - }else { - cpriv->event_mdev =NULL ; - }if (old_mdev)mlx5_set_mtppse (old_mdev, i,0 ,MLX5_EVENT_MODE_DISABLE ); } + cpriv->event_mdev = new_mdev; +} + +static void mlx5_set_timecounter (struct mlx5_core_dev *mdev,u64 ns) +{ +struct mlx5_clock *clock = mdev->clock; +struct mlx5_timer *timer; +unsigned long flags; + + timer = &clock->timer; +mlx5_clock_lockdep_assert (clock); + +write_seqlock_irqsave (&clock->lock, flags); +timecounter_init (&timer->tc, &timer->cycles, ns); +mlx5_update_clock_info_page (mdev); +write_sequnlock_irqrestore (&clock->lock, flags); +} + +static void mlx5_save_timecounter (struct mlx5_core_dev *mdev) +{ +struct mlx5_clock *clock = mdev->clock; +struct mlx5_timer *timer; +unsigned long flags; + + timer = &clock->timer; +mlx5_clock_lockdep_assert (clock); + +if (mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR ) +return ; + +write_seqlock_irqsave (&clock->lock, flags); +timecounter_read (&timer->tc); +mlx5_update_clock_info_page (mdev); +write_sequnlock_irqrestore (&clock->lock, flags); }void mlx5_clock_load (struct mlx5_core_dev *mdev) {struct mlx5_clock *clock = mdev->clock;struct mlx5_clock_priv *cpriv; +bool start;if (!MLX5_CAP_GEN (mdev, device_frequency_khz))return ;
@@ -1554,18 +1646,32 @@ void mlx5_clock_load(struct mlx5_core_dev *mdev)MLX5_NB_INIT (&mdev->clock_state->pps_nb, mlx5_pps_event,PPS_EVENT );mlx5_eq_notifier_register (mdev, &mdev->clock_state->pps_nb); -if (!clock->shared) { -mlx5_clock_arm_pps_in_event (clock, mdev,NULL ); -return ; - } - cpriv =clock_priv (clock); -mlx5_devcom_comp_lock (mdev->clock_state->compdev); +if (clock->shared) +mlx5_devcom_comp_lock (mdev->clock_state->compdev);mlx5_clock_lock (clock); -if (mdev == cpriv->mdev && mdev != cpriv->event_mdev) + start = !cpriv->mdev->clock_state->loaded; + mdev->clock_state->loaded = true; +if (start) { +struct mlx5_timer *timer = &clock->timer; +u64 ns; + + cpriv->mdev = mdev; +if (mlx5_real_time_mode (mdev)) + ns =mlx5_read_time (mdev,NULL , true); +else + ns = timer->saved_phc_ns + +ktime_get_boottime_ns () - timer->saved_boot_ns; + +mlx5_set_timecounter (mdev, ns);mlx5_clock_arm_pps_in_event (clock, mdev, cpriv->event_mdev); + }mlx5_clock_unlock (clock); -mlx5_devcom_comp_unlock (mdev->clock_state->compdev); + +if (start && clock->ptp) +ptp_schedule_worker (clock->ptp,0 ); +if (clock->shared) +mlx5_devcom_comp_unlock (mdev->clock_state->compdev); }void mlx5_clock_unload (struct mlx5_core_dev *mdev)
@@ -1573,30 +1679,42 @@ void mlx5_clock_unload(struct mlx5_core_dev *mdev)struct mlx5_core_dev *peer_dev, *next =NULL ;struct mlx5_clock *clock = mdev->clock;struct mlx5_devcom_comp_dev *pos; +struct mlx5_clock_priv *cpriv; +bool stop;if (!MLX5_CAP_GEN (mdev, device_frequency_khz))return ; -if (!clock->shared) { -mlx5_clock_arm_pps_in_event (clock,NULL , mdev); - goto out; - } - -mlx5_devcom_comp_lock (mdev->clock_state->compdev); -mlx5_devcom_for_each_peer_entry (mdev->clock_state->compdev, peer_dev, pos) { -if (peer_dev->clock && peer_dev != mdev) { - next = peer_dev; -break ; +if (clock->shared) { +mlx5_devcom_comp_lock (mdev->clock_state->compdev); +mlx5_devcom_for_each_peer_entry (mdev->clock_state->compdev, + peer_dev, pos) { +if (peer_dev->clock == clock && + peer_dev->clock_state->loaded) { + next = peer_dev; +break ; + } } }mlx5_clock_lock (clock); -if (mdev ==clock_priv (clock)->event_mdev) + cpriv =clock_priv (clock); + mdev->clock_state->loaded = false; +if (mdev == cpriv->mdev && next) + cpriv->mdev = next; +if (mdev == cpriv->event_mdev)mlx5_clock_arm_pps_in_event (clock, next, mdev); + stop = !cpriv->mdev->clock_state->loaded; +if (!mlx5_real_time_mode (cpriv->mdev)) +mlx5_save_timecounter (cpriv->mdev);mlx5_clock_unlock (clock); -mlx5_devcom_comp_unlock (mdev->clock_state->compdev); -out: +/* Keep devcom locked to prevent a peer from restarting the worker. */ +if (stop && clock->ptp) +ptp_cancel_worker_sync (clock->ptp); +if (clock->shared) +mlx5_devcom_comp_unlock (mdev->clock_state->compdev); +mlx5_eq_notifier_unregister (mdev, &mdev->clock_state->pps_nb);cancel_work_sync (&mdev->clock_state->out_work); }
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h +2 -0
@@ -50,6 +50,8 @@ struct mlx5_timer {struct timecounter tc;u32 nominal_c_mult;unsigned long overflow_period; +u64 saved_phc_ns; +u64 saved_boot_ns; };struct mlx5_clock {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 460/1005 net/mlx5: Lag, free steering resources on LAG destroy failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Bloch <[email protected]>
[ Upstream commit deceb70d1303105e4368a19b251a6fd94428eb11 ]
When firmware fails to destroy LAG, driver returns before releasing the steering resources, leaking the associated software objects.
The bond is no longer eligible for offload, and the driver cannot prevent its teardown. Release the steering resources even if LAG destruction fails. Preserve the error logging and return the original error after cleanup.
--- drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +1 -2
@@ -1096,7 +1096,6 @@ int mlx5_deactivate_lag(struct mlx5_lag *ldev)"Failed to deactivate VF LAG; driver restart required\n" "Make sure all VFs are unbound prior to VF LAG activation or deactivation\n"); } -return err; }if (test_bit (MLX5_LAG_MODE_FLAG_HASH_BASED , &flags)) {
@@ -1106,7 +1105,7 @@ int mlx5_deactivate_lag(struct mlx5_lag *ldev)if (mlx5_lag_has_drop_rule (ldev))mlx5_lag_drop_rule_cleanup (ldev); -return 0 ; +return err; }bool mlx5_lag_check_prereq (struct mlx5_lag *ldev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 461/1005 net: protect negative destination advice with RCU
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 4b77d2792c3e482afa108c08f224ea6fa396d80b ]
SO_CNX_ADVICE calls __dst_negative_advice() while holding the socket lock. Connected UDP sends can still invalidate or replace sk_dst_cache without that lock. A concurrent sk_dst_check() can drop the final destination reference and allow an RCU callback to destroy it while __dst_negative_advice() retains only a borrowed pointer. This can cause a use-after-free while accessing dst->ops or running the negative_advice callback.
The writer-side ordering fixed by commit 92f1655aa2b2 ("net: fix __dst_negative_advice() race") does not protect this reader from an independent cache replacement.
Hold an RCU read-side critical section across the lookup and callback. This follows the datagram release callbacks and covers IPv4, IPv6, and XFRM advice without changing cache-reset or reference-ownership rules.
--- include/net/sock.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/net/sock.h +4 -1
@@ -2214,10 +2214,13 @@ sk_dst_get(const struct sock *sk)static inline void __dst_negative_advice (struct sock *sk) { -struct dst_entry *dst =__sk_dst_get (sk); +struct dst_entry *dst; +rcu_read_lock (); + dst =__sk_dst_get (sk);if (dst && dst->ops->negative_advice) dst->ops->negative_advice (sk, dst); +rcu_read_unlock (); }static inline void dst_negative_advice (struct sock *sk)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 462/1005 net: require a full socket in sock_confirm_neigh()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit c78b47704934e44442f4e48bfdcc99039e3b85a5 ]
An skb can retain dst_pending_confirm after its original output and socket owner have changed. For example, a raw MSG_CONFIRM packet can cross veth, have a TCP request socket assigned by TPROXY, and be bridged into gretap. Neighbor output for the outer packet then calls sock_confirm_neigh() with the request socket in skb->sk.
The helper unconditionally treats a non-NULL skb->sk as a full socket when accessing sk_dst_pending_confirm. TCP request and TIME_WAIT sockets do not contain that field. This produces an out-of-bounds four-byte read and, if the word is nonzero, an out-of-bounds four-byte zero write. A KASAN-enabled kernel reports:
BUG: KASAN: slab-out-of-bounds in ip_finish_output2+0xc9f/0xd60 Read of size 4 at addr ffff8880bdc3d880 by task tproxy_dst_conf/1771
Require sk_fullsock() before accessing the socket field, moving the existing helper earlier in the header to make it available here. Keep neigh_confirm() independent of the socket type so the skb's neighbor confirmation still works, including for socketless packets. This also covers the IPv6, VRF, and BPF neighbor-output callers.
--- include/net/sock.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
include/net/sock.h +10 -9
@@ -2283,6 +2283,14 @@ struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie);struct dst_entry *sk_dst_check (struct sock *sk,u32 cookie); +/* This helper checks if a socket is a full socket, +* ie _not_ a timewait or request socket. +*/ +static inline bool sk_fullsock (const struct sock *sk) +{ +return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT |TCPF_NEW_SYN_RECV ); +} +static inline void sk_dst_confirm (struct sock *sk) {if (!READ_ONCE (sk->sk_dst_pending_confirm))
@@ -2294,7 +2302,8 @@ static inline void sock_confirm_neigh(struct sk_buff *skb, struct neighbour *n)if (skb_get_dst_pending_confirm (skb)) {struct sock *sk = skb->sk; -if (sk &&READ_ONCE (sk->sk_dst_pending_confirm)) +if (sk &&sk_fullsock (sk) && +READ_ONCE (sk->sk_dst_pending_confirm))WRITE_ONCE (sk->sk_dst_pending_confirm,0 );neigh_confirm (n); }
@@ -3027,14 +3036,6 @@ skb_sk_is_prefetched(struct sk_buff *skb)#endif /* CONFIG_INET */ } -/* This helper checks if a socket is a full socket, -* ie _not_ a timewait or request socket. -*/ -static inline bool sk_fullsock (const struct sock *sk) -{ -return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT |TCPF_NEW_SYN_RECV ); -} -static inline bool sk_is_refcounted (struct sock *sk) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 463/1005 ipvlan: make outbound skb headers writable
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit a45dbf182137275f44ad7c8bc8acd23f7af6b2cf ]
In L3 and L3S modes, ipvlan_process_v4_outbound() and ipvlan_process_v6_outbound() hand the skb to ip_local_out() and ip6_local_out(). The IP output path assumes it owns the network header:__ip_local_out() rewrites tot_len and the header checksum, and transport-mode XFRM can memmove the network header into the headroom when xfrm_skb_check_space() finds enough room, without copying.
The skb reaching ipvlan can have its header shared with another skb, for example after an AF_PACKET tap on the ipvlan device or a tc mirred mirror action. pskb_network_may_pull() only makes the header linear; it does not unshare an already linear head. The writes above then modify the other skb. If that skb is on the receive path and its IPv4 header was already validated, IPv4 option processing can use the modified header, write past the linear data, and corrupt skb_shared_info.
Use skb_cow_head() before taking header pointers and entering the local IP output path, like ip_forward() does with skb_cow() before it touches the header. Only checking skb_header_cloned() is enough here: skbs that TCP transmits are clones of the write-queue skb, whose header area has been released with __skb_header_release(). Their headers are private, so they are not copied, which avoids a reallocation for every TCP segment sent through an ipvlan slave.
If the allocation fails, the existing error accounting and drop paths are used. L2 mode is unaffected.
[edumazet: use skb_cow_head() instead of skb_unclone() to avoid
copying every TCP segment, reword changelog]
--- drivers/net/ipvlan/ipvlan_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ipvlan/ipvlan_core.c +4 -2
@@ -438,7 +438,8 @@ static noinline_for_stack int ipvlan_process_v4_outbound(struct sk_buff *skb) .flowi4_mark = skb->mark, }; -if (!pskb_network_may_pull (skb,sizeof (struct iphdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct iphdr )) || +skb_cow_head (skb,0 )) goto err; ip4h =ip_hdr (skb);
@@ -504,7 +505,8 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb)struct net_device *dev = skb->dev;int err, ret =NET_XMIT_DROP ; -if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr ))) { +if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr )) || +skb_cow_head (skb,0 )) {DEV_STATS_INC (dev, tx_errors);kfree_skb (skb);return ret;
Signature · 1 line
2.53.0