riscv: vector: init vector context with proper vlenb
Subsystems (11)
Sasha Levin
maintainerPATCH 1/1 riscv: vector: init vector context with proper vlenb
From: Sergey Matyukevich <[email protected]>
[ Upstream commit ef3ff40346db8476a9ef7269fc9d1837e7243c40 ]
The vstate in thread_struct is zeroed when the vector context is initialized. That includes read-only register vlenb, which holds the vector register length in bytes. Zeroed state persists until mstatus.VS becomes 'dirty' and a context switch saves the actual hardware values.
This can expose the zero vlenb value to the user-space in early debug scenarios, e.g. when ptrace attaches to a traced process early, before any vector instruction except the first one was executed.
Fix this by specifying proper vlenb on vector context init.
---
LLM Generated explanations, may be completely bogus:
The calculation riscv_v_vsize / 32 is used consistently throughout the codebase (e.g., arch/riscv/kvm/vcpu_vector.c:26 and arch/riscv/include/asm/vector.h:157), confirming it's the correct formula.
### Summary of Analysis
**What the bug is:**
When RISC-V vector context is first allocated (either for kernel preemptive V use or on the first user-space vector instruction), the __riscv_v_ext_state structure is zeroed, including the vlenb field. The vlenb field represents the vector register length in bytes — a read-only hardware property. This zero value persists until a context switch with mstatus.VS == dirty causes the hardware values to be saved.
**User impact:**
When ptrace (debuggers like GDB/LLDB) attaches to a process early — before any vector instruction has been executed or before a context switch has saved hardware values — ptrace reads vlenb as 0 instead of the actual hardware value. This is incorrect data being exposed to userspace, which can cause debuggers and tracing tools to malfunction.
**Fix characteristics:**
- **Small and surgical**: The core fix is a single line addition:
ctx->vlenb = riscv_v_vsize / 32;
- **Function rename**: riscv_v_thread_zalloc → riscv_v_thread_ctx_alloc (reflects that it now does more than zalloc)
- **Obviously correct**: Uses the same formula as everywhere else in the kernel (riscv_v_vsize / 32)
- **Well-tested**: Has Reviewed-by and Tested-by from Andy Chiu, the RISC-V vector subsystem author
- **No new features**: Fixes incorrect initialization of existing state
- **Low risk**: Only affects RISC-V vector state initialization; the value being set is identical to what hardware would provide
**Stable criteria check:**
1. Obviously correct and tested — YES (reviewed + tested by maintainer, formula used elsewhere)
2. Fixes a real bug — YES (incorrect data exposed to userspace via ptrace)
3. Important issue — YES (debugging tools get wrong hardware info; incorrect userspace-visible state)
4. Small and contained — YES (one functional line change + rename)
5. No new features — YES (fixes existing behavior)
**Dependencies:**
The code structure with riscv_v_thread_zalloc exists in stable trees (it was introduced with RISC-V V extension support). The fix is self- contained and should apply cleanly or with minimal adjustment.
**Risk assessment:**
Very low risk. The fix adds a single assignment of a value that would eventually be set by hardware anyway. The formula riscv_v_vsize / 32 is well-established and used identically in multiple other places. The worst case if this were somehow wrong would be an incorrect vlenb value — but since it's using exactly the same calculation as the rest of the kernel, this is essentially zero risk.
**YES**
arch/riscv/kernel/vector.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
arch/riscv/kernel/vector.c +8 -4
@@ -111,8 +111,8 @@ bool insn_is_vector(u32 insn_buf)return false; } -static int riscv_v_thread_zalloc (struct kmem_cache *cache, -struct __riscv_v_ext_state *ctx) +static int riscv_v_thread_ctx_alloc (struct kmem_cache *cache, +struct __riscv_v_ext_state *ctx) {void *datap;
@@ -122,13 +122,15 @@ static int riscv_v_thread_zalloc(struct kmem_cache *cache, ctx->datap = datap;memset (ctx,0 , offsetof(struct __riscv_v_ext_state , datap)); + ctx->vlenb = riscv_v_vsize /32 ; +return 0 ; }void riscv_v_thread_alloc (struct task_struct *tsk) {#ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE -riscv_v_thread_zalloc (riscv_v_kernel_cachep, &tsk->thread.kernel_vstate); +riscv_v_thread_ctx_alloc (riscv_v_kernel_cachep, &tsk->thread.kernel_vstate);#endif }
@@ -214,12 +216,14 @@ bool riscv_v_first_use_handler(struct pt_regs *regs)* context where VS has been off. So, try to allocate the user's V * context and resume execution. */ -if (riscv_v_thread_zalloc (riscv_v_user_cachep, ¤t->thread.vstate)) { +if (riscv_v_thread_ctx_alloc (riscv_v_user_cachep, ¤t->thread.vstate)) {force_sig (SIGBUS );return true; } +riscv_v_vstate_on (regs);riscv_v_vstate_set_restore (current, regs); +return true; }
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale() trace event
From: Keita Morisaki <[email protected]>
[ Upstream commit 9672ed3de7d772ceddd713c769c05e832fc69bae ]
The ufs_mtk_clk_scale() trace event currently stores the address of the name string directly via __field(const char *, name). This pointer may become invalid after the module is unloaded, causing page faults when the trace buffer is subsequently accessed.
This can occur because the MediaTek UFS driver can be configured as a loadable module (tristate in Kconfig), meaning the name string passed to the trace event may reside in module memory that becomes invalid after module unload.
Fix this by using __string() and __assign_str() to copy the string contents into the ring buffer instead of storing the pointer. This ensures the trace data remains valid regardless of module state.
This change increases the memory usage for each ftrace entry by a few bytes (clock names are typically 7-15 characters like "ufs_sel" or "ufs_sel_max_src") compared to storing an 8-byte pointer.
Note that this change does not affect anything unless all of the following conditions are met:
- CONFIG_SCSI_UFS_MEDIATEK is enabled
- ftrace tracing is enabled
- The ufs_mtk_clk_scale event is enabled in ftrace
---
LLM Generated explanations, may be completely bogus:
The ufs_mtk_clk_scale trace event was introduced in August 2022 (kernel 6.1 era), so this buggy code exists in multiple stable trees (6.1.y, 6.6.y, and later).
### 8. CONCLUSION
This is a textbook stable backport candidate:
- **Fixes a real crash** (page fault / use-after-free on dangling pointer)
- **Extremely small and contained** (4-line change in one file)
- **Uses well-established patterns** (__string()/__assign_str()/__get_str()) that are the correct and standard approach
- **Zero risk of regression** — this is strictly more correct than the original code
- **Affected code exists in stable trees** dating back to at least 6.1
- **Reviewed and accepted** by the relevant maintainers
- **Self-contained** — no dependencies on other patches
The fix is small, surgical, and meets all stable kernel criteria.
**YES**
drivers/ufs/host/ufs-mediatek-trace.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/ufs/host/ufs-mediatek-trace.h +3 -3
@@ -33,19 +33,19 @@ TRACE_EVENT(ufs_mtk_clk_scale, TP_ARGS(name, scale_up, clk_rate),TP_STRUCT__entry ( -__field (const char *,name ) +__string (name ,name )__field (bool, scale_up) __field(unsigned long, clk_rate) ),TP_fast_assign ( - __entry->name = name; + __assign_str(name); __entry->scale_up = scale_up; __entry->clk_rate = clk_rate; ),TP_printk ("ufs: clk (%s) scaled %s @ %lu" , - __entry->name, +__get_str (name), __entry->scale_up ?"up" :"down" , __entry->clk_rate) );
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 hisi_acc_vfio_pci: update status after RAS error
In reply to Sasha LevinFrom: Longfang Liu <[email protected]>
[ Upstream commit 8be14dd48dfee0df91e511acceb4beeb2461a083 ]
After a RAS error occurs on the accelerator device, the accelerator device will be reset. The live migration state will be abnormal after reset, and the original state needs to be restored during the reset process.
Therefore, reset processing needs to be performed in a live migration scenario.
---
LLM Generated explanations, may be completely bogus:
This confirms the critical finding.
### 3. Bug Classification: Logic Error Causing Failed Reset After RAS Error
The old condition was:
```c
if (hisi_acc_vdev->core_device.vdev.migration_flags !=
VFIO_MIGRATION_STOP_COPY)
return;
```But migration_flags is set to VFIO_MIGRATION_STOP_COPY | VFIO_MIGRATION_PRE_COPY (line 1590), which is 0x1 | 0x4 = 0x5, not 0x1.
So the condition migration_flags != VFIO_MIGRATION_STOP_COPY evaluates to 0x5 != 0x1 = **TRUE**, causing the function to **always return early** and **never perform the reset**.
This means:
- After a RAS error, the device resets
- The migration state becomes inconsistent
- The hisi_acc_vf_reset() call that should restore state is **never reached**
- The device is left in a broken/inconsistent migration state
The new condition !mig_ops correctly checks whether migration is supported (the pointer is non-NULL when migration ops are registered), which aligns with how the VFIO core itself checks for migration capability.
### 4. Scope and Risk Assessment
- **Change size**: 2 lines modified (one condition check)
- **Files touched**: 1 file
- **Risk**: Very low - the change is a simple condition check improvement
- **Scope**: Well-contained to the AER reset handler for HiSilicon accelerator VFIO devices
### 5. User Impact
- **Who is affected**: Users of HiSilicon accelerators (SEC, HPRE, ZIP engines) with live migration enabled, especially in cloud/virtualization environments
- **Severity**: After a RAS error during live migration, the device state would not be properly restored, potentially causing:
- Failed live migrations
- Corrupted device state
- Guest VM malfunction after host-side RAS recovery
### 6. Stability Indicators
- Merged by Alex Williamson (VFIO subsystem maintainer)
- The fix is obviously correct - the old check was demonstrably wrong due to the exact equality comparison against a bitmask field that has multiple bits set
### 7. Dependency Check
This change is self-contained. It doesn't depend on other commits. The mig_ops field has existed in struct vfio_device since the VFIO migration rework (which is present in recent stable kernels).
### Conclusion
This is a clear bug fix. The old condition had a logic error that caused the migration reset handler to be completely non-functional — it would **always** return early because migration_flags was set to STOP_COPY | PRE_COPY but was compared with exact equality to just STOP_COPY. The fix is minimal (2 lines), obviously correct, and addresses a real data integrity/reliability issue during RAS error recovery in live migration scenarios. The change was accepted by the VFIO maintainer.
The only consideration is whether mig_ops exists in stable tree versions, but since it's part of the VFIO migration rework that preceded the addition of PRE_COPY support, it should be present in any kernel that has this driver with PRE_COPY capability.
**YES**
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1 -2
@@ -1192,8 +1192,7 @@ static void hisi_acc_vf_pci_aer_reset_done(struct pci_dev *pdev) {struct hisi_acc_vf_core_device *hisi_acc_vdev =hisi_acc_drvdata (pdev); -if (hisi_acc_vdev->core_device.vdev.migration_flags != -VFIO_MIGRATION_STOP_COPY ) +if (!hisi_acc_vdev->core_device.vdev.mig_ops)return ;mutex_lock (&hisi_acc_vdev->state_mutex);
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 hisi_acc_vfio_pci: fix the queue parameter anomaly issue
In reply to Sasha LevinFrom: Longfang Liu <[email protected]>
[ Upstream commit c3cbc276c2a33b04fc78a86cdb2ddce094cb3614 ]
When the number of QPs initialized by the device, as read via vft, is zero, it indicates either an abnormal device configuration or an abnormal read result.
Returning 0 directly in this case would allow the live migration operation to complete successfully, leading to incorrect parameter configuration after migration and preventing the service from recovering normal functionality. Therefore, in such situations, an error should be returned to roll back the live migration operation.
---
LLM Generated explanations, may be completely bogus:
This confirms the function qm_get_vft():
- Returns negative on error (from hisi_qm_mb())
- Returns qp_num (positive) on success, which is (masked_value) + 1
Wait — looking at line 93, qp_num = (... & ...) + 1, the +1 means the minimum return value on the success path would be 1, not 0. Let me think about this more carefully...
Actually, since the masked value could theoretically be 0xFFFFFFFF (all bits set in the mask), adding 1 could wrap to 0 due to integer overflow. But more practically, if the hardware register returns unexpected values, the result could indeed be 0. The commit message says "the number of QPs initialized by the device, as read via vft, is zero" — so this is a real scenario they've observed.
The fix is self-contained and does not depend on any other commits. The vf_qm_check_match function and qm_get_vft have existed since the driver was introduced.
### 8. Summary
| Criterion | Assessment | |---|---| | Fixes real bug | Yes — incorrect success return on abnormal state | | Bug severity | High — silent data corruption during live migration | | Patch size | Minimal — 1 line | | Risk of regression | Very low — only affects the zero-QP edge case | | Self-contained | Yes — no dependencies | | Stable criteria met | Yes — all criteria satisfied |
The fix is small, surgical, obviously correct, and prevents a real-world issue where live migration silently succeeds with broken device configuration. It meets all stable kernel criteria.
**YES**
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1 -1
@@ -426,7 +426,7 @@ static int vf_qm_check_match(struct hisi_acc_vf_core_device *hisi_acc_vdev, ret =qm_get_vft (vf_qm, &vf_qm->qp_base);if (ret <=0 ) {dev_err (dev,"failed to get vft qp nums\n" ); -return ret; +return ret <0 ? ret : -EINVAL ; }if (ret != vf_data->qp_num) {
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 scsi: buslogic: Reduce stack usage
In reply to Sasha LevinFrom: Arnd Bergmann <[email protected]>
[ Upstream commit e17f0d4cc006265dd92129db4bf9da3a2e4a4f66 ]
Some randconfig builds run into excessive stack usage with gcc-14 or higher, which use __attribute__((cold)) where earlier versions did not do that:
drivers/scsi/BusLogic.c: In function 'blogic_init':drivers/scsi/BusLogic.c:2398:1: error: the frame size of 1680 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
The problem is that a lot of code gets inlined into blogic_init() here. Two functions stick out, but they are a bit different:
- blogic_init_probeinfo_list() actually uses a few hundred bytes of kernel stack, which is a problem in combination with other functions that also do. Marking this one as noinline means that the stack slots get get reused between function calls
- blogic_reportconfig() has a few large variables, but whenever it is not inlined into its caller, the compiler is actually smart enough to reuse stack slots for these automatically, so marking it as noinline saves most of the stack space by itself.
The combination of both of these should avoid the problem entirely.
---
LLM Generated explanations, may be completely bogus:
## Analysis of commit: "scsi: buslogic: Reduce stack usage"
### Commit Message Analysis
The commit addresses a **build failure** (-Werror=frame-larger-than=) that occurs with gcc-14 or higher on certain randconfig builds. The function blogic_init() exceeds the 1536-byte stack frame limit (reaching 1680 bytes) due to excessive inlining by the compiler.
The fix is to mark two functions as noinline_for_stack:
1. blogic_init_probeinfo_list() - uses significant stack space that compounds with other inlined functions
2. blogic_reportconfig() - has large local variables that the compiler can reuse stack slots for when not inlined
### Code Change Analysis
The change is extremely minimal and surgical:
- **Two functions** have their declarations changed from static ... __init to static noinline_for_stack ... __init
- **Zero logic changes** - no behavior modification whatsoever
- **Zero new code paths** - the functions still do exactly the same thing
- The noinline_for_stack annotation is a well-established kernel mechanism specifically designed for this purpose
### Classification: Build Fix
This is a **build fix** — one of the explicitly allowed exception categories for stable backports. With gcc-14+, the kernel fails to compile with -Werror=frame-larger-than= enabled in certain configurations. Build failures prevent users from building the kernel at all, which is a critical issue.
### Scope and Risk Assessment
- **Lines changed**: Effectively 2 lines (function signature annotations only)
- **Files touched**: 1 (drivers/scsi/BusLogic.c)
- **Risk**: Extremely low. noinline_for_stack only prevents the compiler from inlining these functions. Since they are __init functions (called once during initialization and then discarded), the negligible performance impact of preventing inlining is irrelevant.
- **Regression potential**: Near zero. The functions still execute identically; only their calling convention changes slightly.
### User Impact
- Users building kernels with gcc-14 or newer (increasingly common as distributions adopt newer toolchains) will hit build failures on certain configurations
- The BusLogic SCSI driver is a legacy driver, but it still has users and is compiled in many kernel configs
- Build failures are binary — either you can build or you can't — making this high impact for affected configurations
### Stability Indicators
- **Author**: Arnd Bergmann — a very well-known and respected kernel developer who regularly contributes build fixes and architecture improvements
- **Reviewer**: Martin K. Petersen — SCSI subsystem maintainer
- The fix uses noinline_for_stack, the standard kernel annotation for exactly this type of stack reduction
### Dependency Check
- No dependencies on other commits
- The noinline_for_stack macro has been available in the kernel for many years
- The BusLogic driver exists in all stable trees
### Conclusion
This is a textbook stable backport candidate:
1. **Build fix** — explicitly allowed in stable rules
2. **Trivially correct** — annotation-only change with no logic modification
3. **Zero risk** of regression — functions behave identically
4. **Real impact** — prevents build failure with modern gcc versions
5. **Tiny scope** — 2 annotation additions in a single file
6. **Well-established pattern** — noinline_for_stack is the standard kernel solution for this class of problem
**YES**
drivers/scsi/BusLogic.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/BusLogic.c +4 -2
@@ -920,7 +920,8 @@ static int __init blogic_init_fp_probeinfo(struct blogic_adapter *adapter)a particular probe order. */ -static void __init blogic_init_probeinfo_list (struct blogic_adapter *adapter) +static noinline_for_stack void __init +blogic_init_probeinfo_list (struct blogic_adapter *adapter) {/* If a PCI BIOS is present, interrogate it for MultiMaster and
@@ -1690,7 +1691,8 @@ static bool __init blogic_rdconfig(struct blogic_adapter *adapter)blogic_reportconfig reports the configuration of Host Adapter. */ -static bool __init blogic_reportconfig (struct blogic_adapter *adapter) +static noinline_for_stack bool __init +blogic_reportconfig (struct blogic_adapter *adapter) {unsigned short alltgt_mask = (1 << adapter->maxdev) -1 ;unsigned short sync_ok, fast_ok;
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 tracing: Fix false sharing in hwlat get_sample()
In reply to Sasha LevinFrom: Colin Lord <[email protected]>
[ Upstream commit f743435f988cb0cf1f521035aee857851b25e06d ]
The get_sample() function in the hwlat tracer assumes the caller holds hwlat_data.lock, but this is not actually happening. The result is unprotected data access to hwlat_data, and in per-cpu mode can result in false sharing which may show up as false positive latency events.
The specific case of false sharing observed was primarily between hwlat_data.sample_width and hwlat_data.count. These are separated by just 8B and are therefore likely to share a cache line. When one thread modifies count, the cache line is in a modified state so when other threads read sample_width in the main latency detection loop, they fetch the modified cache line. On some systems, the fetch itself may be slow enough to count as a latency event, which could set up a self reinforcing cycle of latency events as each event increments count which then causes more latency events, continuing the cycle.
The other result of the unprotected data access is that hwlat_data.count can end up with duplicate or missed values, which was observed on some systems in testing.
Convert hwlat_data.count to atomic64_t so it can be safely modified without locking, and prevent false sharing by pulling sample_width into a local variable.
One system this was tested on was a dual socket server with 32 CPUs on each numa node. With settings of 1us threshold, 1000us width, and 2000us window, this change reduced the number of latency events from 500 per second down to approximately 1 event per minute. Some machines tested did not exhibit measurable latency from the false sharing.
---
LLM Generated explanations, may be completely bogus:
## Analysis of the Commit
### 1. Commit Message Analysis
The commit message is very detailed and clearly describes:
- **The bug**: get_sample() assumes hwlat_data.lock is held, but it's not actually held. This leads to unprotected data access and false sharing in per-cpu mode.
- **The specific false sharing**: hwlat_data.sample_width and hwlat_data.count are 8 bytes apart, likely sharing a cache line. When one thread modifies count, other threads reading sample_width in the latency detection loop fetch the modified cache line, causing measurable latency.
- **The self-reinforcing cycle**: The latency from cache line fetch triggers a latency event, which increments count, which causes more cache line invalidation, which causes more latency events — a vicious cycle.
- **The data race**: hwlat_data.count can end up with duplicate or missed values due to unprotected concurrent access.
- **Concrete test results**: On a dual-socket 32-CPUs-per-node server, latency events dropped from 500/sec to ~1/min.
Keywords: "false sharing", "false positive latency events", "unprotected data access", "duplicate or missed values."
### 2. Code Change Analysis
The changes are minimal and surgical:
1. **hwlat_data.count converted from u64 to atomic64_t**: This fixes a real data race where multiple threads could concurrently increment count without synchronization, leading to lost updates (duplicate/missed values). The atomic64_inc_return() replaces hwlat_data.count++; s.seqnum = hwlat_data.count; with a single atomic operation.
2. **sample_width pulled into a local variable with READ_ONCE()**:
u64 sample_width = READ_ONCE(hwlat_data.sample_width); is used instead of reading hwlat_data.sample_width in the hot loop (do { ... } while (total <= sample_width)). This:
- Prevents the CPU from repeatedly fetching a cache line that may be bouncing between cores
- Eliminates the false sharing between sample_width and count
- Uses READ_ONCE() for proper load semantics
3. **Init path updated**: hwlat_data.count = 0 → atomic64_set(&hwlat_data.count, 0) — consistent with the type change.
4. **Comment fix**: Removes the incorrect claim that get_sample() is "called with hwlat_data.lock held."
### 3. Bug Classification
This commit fixes **multiple real bugs**:
1. **Data race on hwlat_data.count**: Concurrent unsynchronized access to a shared counter. This is a real correctness bug — sequence numbers can be duplicated or skipped.
2. **False sharing causing false positive latency detection**: The hwlat tracer is producing bogus results (500 events/sec vs 1/min). This is a **functional correctness bug** — the tracer is reporting phantom hardware latency that doesn't exist. Users relying on hwlat tracer results would be misled.
3. **Self-reinforcing feedback loop**: The false sharing creates a pathological cycle that makes the tracer practically unusable on some multi-socket systems.
### 4. Scope and Risk Assessment
- **Lines changed**: ~15 lines of actual code changes across 4 hunks in a single file
- **Files touched**: 1 (kernel/trace/trace_hwlat.c)
- **Risk**: Very low. The changes are:
- Converting a counter to atomic (well-understood primitive)
- Caching a value in a local variable (safe, the value doesn't need to be re-read)
- Using READ_ONCE() (standard kernel pattern)
- **Subsystem**: Tracing — self-contained, well-maintained by Steven Rostedt
- **Could it break something?**: Extremely unlikely. The atomic64 operations are well-tested primitives, and caching sample_width is semantically equivalent (the width doesn't change during a sample).
### 5. User Impact
- **Who is affected**: Anyone using the hwlat tracer in per-cpu mode on multi-socket systems
- **Severity**: The tracer produces wildly incorrect results (500x false positives) on affected systems
- **Real-world impact**: Users trying to validate hardware latency characteristics for real-time workloads would get completely misleading data
- **The data race on count**: Could cause sequence number issues that affect trace analysis tooling
### 6. Stability Indicators
- **Signed-off by Steven Rostedt** (tracing subsystem maintainer) — high confidence
- **Concrete test data** provided showing dramatic improvement
- **Link to mailing list** discussion provided
- The fix uses standard kernel primitives (atomic64_t, READ_ONCE) — well-understood patterns
### 7. Dependency Check
- No dependencies on other commits
- atomic64_t and READ_ONCE() are available in all stable kernel versions
- The hwlat tracer exists in all recent stable trees (introduced in v4.9)
### Stable Kernel Rules Assessment
1. **Obviously correct and tested**: Yes — tested on real hardware with measurable improvement
2. **Fixes a real bug**: Yes — data race + false sharing causing incorrect tracer output
3. **Important issue**: Yes — tracer producing 500x false positive latency events, plus data race on counter
4. **Small and contained**: Yes — ~15 lines in one file
5. **No new features**: Correct — this is a pure bug fix
6. **Applies cleanly**: Should apply cleanly to recent stable trees
### Risk vs Benefit
- **Risk**: Near zero — atomic counter and local variable caching are trivially safe changes
- **Benefit**: High — fixes a data race and makes the hwlat tracer produce correct results on multi-socket systems
**YES**
kernel/trace/trace_hwlat.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
kernel/trace/trace_hwlat.c +7 -8
@@ -102,9 +102,9 @@ struct hwlat_sample {/* keep the global state somewhere. */ static struct hwlat_data { - struct mutex lock; /* protect changes */ + struct mutex lock; /* protect changes */ - u64 count; /* total since reset */ + atomic64_t count; /* total since reset */ u64 sample_window; /* total sampling window (on+off) */ u64 sample_width; /* active sampling portion of window */
@@ -193,8 +193,7 @@ void trace_hwlat_callback(bool enter)* get_sample - sample the CPU TSC and look for likely hardware latencies * * Used to repeatedly capture the CPU TSC (or similar), looking for potential -* hardware-induced latency. Called with interrupts disabled and with -* hwlat_data.lock held. +* hardware-induced latency. Called with interrupts disabled. */ static int get_sample (void ) {
@@ -204,6 +203,7 @@ static int get_sample(void)time_type start, t1, t2, last_t2;s64 diff, outer_diff, total, last_total =0 ;u64 sample =0 ; +u64 sample_width =READ_ONCE (hwlat_data.sample_width);u64 thresh = tracing_thresh;u64 outer_sample =0 ;int ret =-1 ;
@@ -267,7 +267,7 @@ static int get_sample(void)if (diff > sample) sample = diff;/* only want highest value */ - }while (total <= hwlat_data.sample_width); + }while (total <= sample_width);barrier ();/* finish the above in the view for NMIs */ trace_hwlat_callback_enabled = false;
@@ -285,8 +285,7 @@ static int get_sample(void)if (kdata->nmi_total_ts)do_div (kdata->nmi_total_ts,NSEC_PER_USEC ); - hwlat_data.count++; - s.seqnum = hwlat_data.count; + s.seqnum =atomic64_inc_return (&hwlat_data.count); s.duration = sample; s.outer_duration = outer_sample; s.nmi_total_ts = kdata->nmi_total_ts;
@@ -832,7 +831,7 @@ static int hwlat_tracer_init(struct trace_array *tr) hwlat_trace = tr; - hwlat_data.count =0 ; +atomic64_set (&hwlat_data.count,0 ); tr->max_latency =0 ; save_tracing_thresh = tracing_thresh;
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 vhost: fix caching attributes of MMIO regions by setting them explicitly
In reply to Sasha LevinFrom: Kommula Shiva Shankar <[email protected]>
[ Upstream commit 5145b277309f3818e2db507f525d19ac3b910922 ]
Explicitly set non-cached caching attributes for MMIO regions. Default write-back mode can cause CPU to cache device memory, causing invalid reads and unpredictable behavior.
Invalid read and write issues were observed on ARM64 when mapping the notification area to userspace via mmap.
Message-Id: <[email protected]>
---
LLM Generated explanations, may be completely bogus:
The mmap functionality has been there since ddd89d0a059d8 which introduced doorbell mapping. This fix would apply to all stable trees that have this function.
### Summary
This is a textbook stable kernel fix:
1. **Obviously correct**: MMIO must be mapped non-cacheable; this is a fundamental hardware requirement. Every other MMIO mmap in the kernel uses pgprot_noncached() or similar.
2. **Fixes a real bug**: Invalid reads/writes on ARM64 — this causes device malfunction and potential data corruption.
3. **Small and contained**: Single line addition, no side effects.
4. **No new features**: Just corrects existing mmap behavior to follow hardware requirements.
5. **Low risk**: pgprot_noncached() is the standard, well-understood kernel API for this exact purpose.
6. **High-quality review**: Three expert maintainers reviewed/acked/committed.
7. **Self-contained**: No dependencies on other commits.
**YES**
drivers/vhost/vdpa.c | 1 + 1 file changed, 1 insertion(+)
drivers/vhost/vdpa.c +1 -0
@@ -1527,6 +1527,7 @@ static int vhost_vdpa_mmap(struct file *file, struct vm_area_struct *vma)if (vma->vm_end - vma->vm_start != notify.size)return -ENOTSUPP ; + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);vm_flags_set (vma,VM_IO |VM_PFNMAP |VM_DONTEXPAND |VM_DONTDUMP ); vma->vm_ops = &vhost_vdpa_vm_ops;return 0 ;
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 hisi_acc_vfio_pci: resolve duplicate migration states
In reply to Sasha LevinFrom: Longfang Liu <[email protected]>
[ Upstream commit 8c6ac1730a977234dff74cc1753b4a953f59be7b ]
In special scenarios involving duplicate migrations, after the first migration is completed, if the original VF device is used again and then migrated to another destination, the state indicating data migration completion for the VF device is not reset. This results in the second migration to the destination being skipped without performing data migration.
After the modification, it ensures that a complete data migration is performed after the subsequent migration.
---
LLM Generated explanations, may be completely bogus:
### 3. Understanding the Bug Mechanism
Now the bug is crystal clear:
1. **vf_qm_check_match()** (line 401-453) performs VF device matching/validation during migration. Once matching succeeds, it sets match_done = true (line 451).
2. On subsequent calls, if match_done is already true, it **skips all validation** (line 411: early return 0).
3. **The bug**: When the device is opened for a second migration, match_done is never reset to 0. So vf_qm_check_match() returns immediately without performing the actual data migration matching, effectively **skipping the migration data transfer**.
4. **The fix**: Reset match_done = 0 in hisi_acc_vfio_pci_open_device(), ensuring that each time the device is opened for a new migration, matching starts fresh.
### 4. Classification
This is a **clear functional bug fix**. It fixes incorrect behavior where sequential VFIO device migrations fail silently after the first one. The second migration appears to succeed but doesn't actually transfer data.
### 5. Scope and Risk Assessment
- **One line change**: hisi_acc_vdev->match_done = 0;
- **Single file**: drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
- **Minimal risk**: The change simply resets a state flag when a device is opened, which is the expected correct behavior
- **Located in the right place**: Inside the open_device function where other state is already being initialized (mig_state, dev_opened)
- **Under proper locking**: Inside the open_mutex critical section
- **Driver-specific**: Only affects HiSilicon accelerator VFIO devices, no risk to other subsystems
### 6. User Impact
- **Who is affected**: Users of HiSilicon accelerator hardware (common in Huawei/HiSilicon server platforms) performing VFIO-based VM live migration
- **Severity**: HIGH — silent data migration failure means VM state is silently corrupted or lost during the second migration. The VM may crash or behave incorrectly on the new host
- **Frequency**: Any time a VM is migrated more than once (a standard operation in cloud/datacenter environments for load balancing, maintenance, etc.)
### 7. Stable Kernel Criteria Check
- **Obviously correct**: Yes — resetting state on device open is clearly the right thing to do
- **Fixes a real bug**: Yes — second migrations silently fail
- **Small and contained**: Yes — single line addition in a single file
- **No new features**: Correct — this is purely a state reset bug fix
- **Tested**: Accepted by the VFIO maintainer (Alex Williamson)
### 8. Dependency Check
No dependencies on other commits. The match_done field and the open_device function structure already exist in stable trees that have the HiSilicon VFIO migration support.
### Conclusion
This is a textbook stable backport candidate: a one-line fix for a clear functional bug (state not being reset between migrations) that causes silent data migration failures in production environments. The fix is minimal, obviously correct, properly placed under existing locking, and carries essentially zero regression risk.
**YES**
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1 -0
@@ -1547,6 +1547,7 @@ static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev) } hisi_acc_vdev->mig_state =VFIO_DEVICE_STATE_RUNNING ; hisi_acc_vdev->dev_opened = true; + hisi_acc_vdev->match_done =0 ;mutex_unlock (&hisi_acc_vdev->open_mutex); }
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 ata: libata: avoid long timeouts on hot-unplugged SATA DAS
In reply to Sasha LevinFrom: Henry Tseng <[email protected]>
[ Upstream commit 151cabd140322205e27dae5c4bbf261ede0056e3 ]
When a SATA DAS enclosure is connected behind a Thunderbolt PCIe switch, hot-unplugging the whole enclosure causes pciehp to tear down the PCI hierarchy before the SCSI layer issues SYNCHRONIZE CACHE and START STOP UNIT for the disks.
libata still queues these commands and the AHCI driver tries to access the HBA registers even though the PCI channel is already offline. This results in a series of timeouts and error recovery attempts, e.g.:
[ 824.778346] pcieport 0000:00:07.0: pciehp: Slot(14): Link Down
[ 891.612720] ata8.00: qc timeout after 5000 msecs (cmd 0xec)
[ 902.876501] ata8.00: qc timeout after 10000 msecs (cmd 0xec)
[ 934.107998] ata8.00: qc timeout after 30000 msecs (cmd 0xec)
[ 936.206431] sd 7:0:0:0: [sda] Synchronize Cache(10) failed:
Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
...
[ 1006.298356] ata1.00: qc timeout after 5000 msecs (cmd 0xec)
[ 1017.561926] ata1.00: qc timeout after 10000 msecs (cmd 0xec)
[ 1048.791790] ata1.00: qc timeout after 30000 msecs (cmd 0xec)
[ 1050.890035] sd 0:0:0:0: [sdb] Synchronize Cache(10) failed:
Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OKWith this patch applied, the same hot-unplug looks like:
[ 59.965496] pcieport 0000:00:07.0: pciehp: Slot(14): Link Down
[ 60.002502] sd 7:0:0:0: [sda] Synchronize Cache(10) failed:
Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
...
[ 60.103050] sd 0:0:0:0: [sdb] Synchronize Cache(10) failed:
Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OKIn this test setup with two disks, the hot-unplug sequence shrinks from about 226 seconds (~3.8 minutes) between the Link Down event and the last SYNCHRONIZE CACHE failure to under a second. Without this patch the total delay grows roughly with the number of disks, because each disk gets its own SYNCHRONIZE CACHE and qc timeout series.
If the underlying PCI device is already gone, these commands cannot succeed anyway. Avoid issuing them by introducing ata_adapter_is_online(), which checks pci_channel_offline() for PCI-based hosts. It is used from ata_scsi_find_dev() to return NULL, causing the SCSI layer to fail new commands with DID_BAD_TARGET immediately, and from ata_qc_issue() to bail out before touching the HBA registers.
Since such failures would otherwise trigger libata error handling, ata_adapter_is_online() is also consulted from ata_scsi_port_error_handler(). When the adapter is offline, libata skips ap->ops->error_handler(ap) and completes error handling using the existing path, rather than running a full EH sequence against a dead adapter.
With this change, SYNCHRONIZE CACHE and START STOP UNIT commands issued during hot-unplug fail quickly once the PCI channel is offline, without qc timeout spam or long libata EH delays.
---
LLM Generated explanations, may be completely bogus:
### Dependency Check Results
All dependencies are confirmed to exist in the current tree:
1. **pci_channel_offline()** - inline function in include/linux/pci.h (long-established API)
2. **sys_err label in ata_qc_issue()** - exists at the expected location
3. **AC_ERR_HOST_BUS** - defined in include/linux/libata.h
4. **ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED pattern** - exists in ata_scsi_port_error_handler()
5. **ata_scsi_find_dev() structure** - matches expected layout
The commit is **self-contained** with no dependencies on other recent commits. All APIs it uses are long-established kernel infrastructure.
### 8. SUMMARY
**Problem:** Hot-unplugging SATA DAS via Thunderbolt causes minutes-long timeout cascades because libata keeps trying to issue commands and run error handling against a dead PCI device.
**Fix:** Check pci_channel_offline() at three strategic points to fail fast when the PCI device is already gone.
**Meets stable criteria:**
- **Obviously correct:** Uses established pci_channel_offline() API; conservative (only triggers when PCI channel is definitely offline)
- **Fixes a real bug:** Minutes-long hangs during hot-unplug
- **Important issue:** System hangs/unresponsiveness, scales with number of disks
- **Small and contained:** ~30 lines across 4 files, all within libata
- **No new features:** Just error detection and fast-fail for an already-broken state
- **No new APIs:** The new helper is internal to libata (libata.h, not libata-scsi.h or public headers)
**Risk vs Benefit:**
- **Benefit:** HIGH - eliminates minutes-long hangs for Thunderbolt dock users with SATA storage
- **Risk:** LOW - only changes behavior when PCI channel is already offline (device is dead anyway), uses existing error paths
**YES** - This is a well-crafted, maintainer-approved fix for a real user-facing issue (extended timeouts/hangs on hot-unplug). It's small, self-contained, uses established APIs, follows existing patterns in the codebase, and has no dependencies on other commits. The fix is conservative (only triggers when PCI is already offline) and the risk of regression is minimal.
**YES**
drivers/ata/libata-core.c | 24 ++++++++++++++++++++++++ drivers/ata/libata-eh.c | 3 ++- drivers/ata/libata-scsi.c | 3 +++ drivers/ata/libata.h | 1 + 4 files changed, 30 insertions(+), 1 deletion(-)
drivers/ata/libata-core.c +24 -0
@@ -2358,6 +2358,24 @@ static bool ata_dev_check_adapter(struct ata_device *dev,return false; } +bool ata_adapter_is_online (struct ata_port *ap) +{ +struct device *dev; + +if (!ap || !ap->host) +return false; + + dev = ap->host->dev; +if (!dev) +return false; + +if (dev_is_pci (dev) && +pci_channel_offline (to_pci_dev (dev))) +return false; + +return true; +} +static int ata_dev_config_ncq (struct ata_device *dev,char *desc,size_t desc_sz) {
@@ -5082,6 +5100,12 @@ void ata_qc_issue(struct ata_queued_cmd *qc) qc->flags |=ATA_QCFLAG_ACTIVE ; ap->qc_active |=1ULL << qc->tag; +/* Make sure the device is still accessible. */ +if (!ata_adapter_is_online (ap)) { + qc->err_mask |=AC_ERR_HOST_BUS ; + goto sys_err; + } +/* * We guarantee to LLDs that they will have at least one * non-zero sg if the command is a data command.
drivers/ata/libata-eh.c +2 -1
@@ -736,7 +736,8 @@ void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap)spin_unlock_irqrestore (ap->lock, flags);/* invoke EH, skip if unloading or suspended */ -if (!(ap->pflags & (ATA_PFLAG_UNLOADING |ATA_PFLAG_SUSPENDED ))) +if (!(ap->pflags & (ATA_PFLAG_UNLOADING |ATA_PFLAG_SUSPENDED )) && +ata_adapter_is_online (ap)) ap->ops->error_handler (ap);else {/* if unloading, commence suicide */
drivers/ata/libata-scsi.c +3 -0
@@ -2982,6 +2982,9 @@ ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev) {struct ata_device *dev =__ata_scsi_find_dev (ap, scsidev); +if (!ata_adapter_is_online (ap)) +return NULL ; +if (unlikely (!dev || !ata_dev_enabled (dev)))return NULL ;
drivers/ata/libata.h +1 -0
@@ -94,6 +94,7 @@ extern int atapi_check_dma(struct ata_queued_cmd *qc);extern void swap_buf_le16 (u16 *buf,unsigned int buf_words);extern bool ata_phys_link_online (struct ata_link *link);extern bool ata_phys_link_offline (struct ata_link *link); +bool ata_adapter_is_online (struct ata_port *ap);extern void ata_dev_init (struct ata_device *dev);extern void ata_link_init (struct ata_port *ap,struct ata_link *link,int pmp);extern int sata_link_init_spd (struct ata_link *link);
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 RDMA/rtrs-clt: For conn rejection use actual err number
In reply to Sasha LevinFrom: Md Haris Iqbal <[email protected]>
[ Upstream commit fc290630702b530c2969061e7ef0d869a5b6dc4f ]
When the connection establishment request is rejected from the server side, then the actual error number sent back should be used.
---
LLM Generated explanations, may be completely bogus:
## Analysis of RDMA/rtrs-clt: For conn rejection use actual err number
### Commit Message Analysis
The commit message says: "When the connection establishment request is rejected from the server side, then the actual error number sent back should be used." This is a bug fix — the function was discarding the server-provided error code and always returning -ECONNRESET, regardless of what the server actually reported.
### Code Change Analysis
The change is small and surgical, touching only the rtrs_rdma_conn_rejected() function in drivers/infiniband/ulp/rtrs/rtrs-clt.c:
1. **Initialization change**: int status, errno; → int status, errno = -ECONNRESET; — initializes errno to the previous hard-coded return value as a default.
2. **Return value change**: return -ECONNRESET; → return errno; — now returns the actual error number from the server's rejection message.
**What this fixes**: Previously, when the server rejected a connection and sent back a specific error code (e.g., -EBUSY), the function would parse and log the error correctly but then discard it, always returning -ECONNRESET. This means the caller couldn't distinguish between different rejection reasons. The most important case is -EBUSY, which tells the client that a previous session still exists and it should reconnect later — with the old code, the caller couldn't differentiate this from a generic connection reset.
**Fallback behavior**: If the rejection message is malformed or too short (else branch), errno retains its default -ECONNRESET value, preserving the old behavior for that case. This is clean and safe.
### Bug Classification
This is a **real bug fix** — incorrect error propagation. The function was designed to extract the error number from the server's rejection message but then threw it away. This could cause:
- Incorrect reconnection behavior (treating -EBUSY like -ECONNRESET)
- Misleading error reporting to upper layers
- Potentially infinite reconnection loops or incorrect session management decisions
### Scope and Risk Assessment
- **Lines changed**: ~3 lines of actual logic change
- **Files touched**: 1
- **Complexity**: Very low
- **Risk**: Very low — the default initialization ensures backward- compatible behavior for the malformed-message path, and the fix simply propagates information that was already being parsed but discarded
- **Subsystem**: RDMA/rtrs (RDMA Transport) — used for high-performance storage over RDMA networks
### Review and Testing
- Has Reviewed-by: from two reviewers (Grzegorz Prajsner and Jack Wang)
- Merged by Leon Romanovsky (RDMA subsystem maintainer)
- Part of a patch series (patch 10), but this change is self-contained — it doesn't depend on other patches in the series
### User Impact
Users of rtrs (RDMA transport for block storage) could experience incorrect reconnection behavior when the server rejects connections. The -EBUSY case is particularly important — without the proper error code, the client can't handle "session still exists" rejections appropriately, potentially leading to connection failures or suboptimal retry behavior.
### Stable Kernel Criteria Check
1. **Obviously correct and tested**: Yes — simple, well-reviewed, logical fix
2. **Fixes a real bug**: Yes — incorrect error code propagation
3. **Important issue**: Moderate — affects connection management in RDMA storage, could cause reconnection failures
4. **Small and contained**: Yes — 3 lines changed in 1 file
5. **No new features**: Correct — this fixes existing behavior
6. **Applies cleanly**: Likely — the change is simple and localized
### Risk vs Benefit
- **Risk**: Minimal — the default initialization preserves backward compatibility, and the fix is straightforward
- **Benefit**: Correct error propagation enables proper connection rejection handling, especially for the -EBUSY case
The fix is small, surgical, well-reviewed, and fixes a real bug where error information was being discarded. It meets all stable kernel criteria.
**YES**
drivers/infiniband/ulp/rtrs/rtrs-clt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +2 -2
@@ -1923,7 +1923,7 @@ static int rtrs_rdma_conn_rejected(struct rtrs_clt_con *con,struct rtrs_path *s = con->c.path;const struct rtrs_msg_conn_rsp *msg;const char *rej_msg; -int status, errno; +int status, errno = -ECONNRESET ;u8 data_len; status = ev->status;
@@ -1945,7 +1945,7 @@ static int rtrs_rdma_conn_rejected(struct rtrs_clt_con *con, status, rej_msg); } -return -ECONNRESET ; +return errno; }void rtrs_clt_close_conns (struct rtrs_clt_path *clt_path,bool wait)
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 1/1 um: Preserve errno within signal handler
In reply to Sasha LevinFrom: Tiwei Bie <[email protected]>
[ Upstream commit f68b2d5a907b53eed99cf2efcaaae116df73c298 ]
We rely on errno to determine whether a syscall has failed, so we need to ensure that accessing errno is async-signal-safe. Currently, we preserve the errno in sig_handler_common(), but it doesn't cover every possible case. Let's do it in hard_handler() instead, which is the signal handler we actually register.
---
LLM Generated explanations, may be completely bogus:
## Analysis of "um: Preserve errno within signal handler"
### Commit Message Analysis
The commit message clearly describes a bug fix: errno is not being properly preserved in all signal handler code paths. The fix moves the errno save/restore from sig_handler_common() to hard_handler(), which is the actual registered signal handler. This ensures errno preservation covers all cases, not just those that go through sig_handler_common().
### Code Change Analysis
The change is very small and surgical:
1. **Removes** int save_errno = errno; and errno = save_errno; from sig_handler_common() (lines removed from inner function)
2. **Adds** int save_errno = errno; and errno = save_errno; to hard_handler() (lines added to outer function)
This is a simple relocation of the errno save/restore to a higher-level function that covers more code paths.
### Bug Mechanism
The bug is about **async-signal-safety**. When a signal handler fires, it can interrupt code that just set errno (e.g., after a failed syscall). If the signal handler calls functions that modify errno (which many do), the original errno value is lost. The caller then sees a corrupted errno and may make incorrect decisions.
The previous code preserved errno only in sig_handler_common(), but looking at the handlers[] array, hard_handler() dispatches to multiple handlers:
- sig_handler (which calls sig_handler_common)
- timer_alarm_handler
- sigusr1_handler
The timer_alarm_handler and sigusr1_handler paths were **NOT** covered by the errno preservation in sig_handler_common(). This means those signal handlers could corrupt errno.
### Classification
This is a **real bug fix**. Corrupted errno in UML (User Mode Linux) can lead to:
- Incorrect syscall failure detection
- Spurious error handling paths being taken
- Potentially hard-to-diagnose undefined behavior
This falls into the category of a **data corruption / correctness bug** — the kernel relies on errno to determine syscall success/failure, and a corrupted errno can cause incorrect control flow.
### Scope and Risk Assessment
- **Lines changed**: ~6 lines (3 removed, 3 added)
- **Files touched**: 1 file (arch/um/os-Linux/signal.c)
- **Complexity**: Extremely low — just moving save/restore to a higher scope
- **Risk of regression**: Minimal. The errno save/restore pattern is well-understood and the change just moves it to a more encompassing location. It's logically identical for the paths that already went through sig_handler_common(), and adds coverage for paths that didn't.
### User Impact
This affects UML (User Mode Linux) users. While UML is a niche architecture, the bug is real — signal handlers corrupting errno can lead to subtle, hard-to-diagnose failures. The fix is obviously correct.
### Stability Indicators
- Signed off by the UML maintainer (Johannes Berg)
- The pattern of saving/restoring errno in signal handlers is a well- established correctness requirement (POSIX async-signal-safety)
- The fix is trivially verifiable by inspection
### Dependency Check
This commit is self-contained. It has no dependencies on other patches. The code it modifies (hard_handler() and sig_handler_common()) has been present in stable kernels for a long time.
### Verdict
This is a small, obviously correct bug fix that:
- Fixes a real async-signal-safety bug (errno corruption)
- Is extremely contained (6 lines in 1 file)
- Has near-zero regression risk
- Affects a real code path (signal handling in UML)
- Meets all stable kernel criteria
**YES**
arch/um/os-Linux/signal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/um/os-Linux/signal.c +3 -3
@@ -36,7 +36,6 @@ void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *, void *mc) =static void sig_handler_common (int sig,struct siginfo *si,mcontext_t *mc) {struct uml_pt_regs r; -int save_errno = errno; r.is_user =0 ;if (sig ==SIGSEGV ) {
@@ -50,8 +49,6 @@ static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)unblock_signals_trace (); (*sig_info[sig])(sig, si, &r, mc); - - errno = save_errno; }/*
@@ -207,8 +204,11 @@ static void hard_handler(int sig, siginfo_t *si, void *p) {ucontext_t *uc = p;mcontext_t *mc = &uc->uc_mcontext; +int save_errno = errno; (*handlers[sig])(sig, (struct siginfo *)si, mc); + + errno = save_errno; }void set_handler (int sig)
Signature · 1 line
2.51.0