* [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot()
@ 2024-11-24 12:46 Sasha Levin
2024-11-24 12:46 ` [PATCH AUTOSEL 6.12 2/5] perf/x86/amd: Warn only on new bits set Sasha Levin
2024-11-24 13:13 ` [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot() Oleg Nesterov
0 siblings, 2 replies; 5+ messages in thread
From: Sasha Levin @ 2024-11-24 12:46 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Oleg Nesterov, Peter Zijlstra, Sasha Levin, mhiramat, mingo, acme,
namhyung, linux-trace-kernel, linux-perf-users
From: Oleg Nesterov <oleg@redhat.com>
[ Upstream commit c7b4133c48445dde789ed30b19ccb0448c7593f7 ]
1. Clear utask->xol_vaddr unconditionally, even if this addr is not valid,
xol_free_insn_slot() should never return with utask->xol_vaddr != NULL.
2. Add a comment to explain why do we need to validate slot_addr.
3. Simplify the validation above. We can simply check offset < PAGE_SIZE,
unsigned underflows are fine, it should work if slot_addr < area->vaddr.
4. Kill the unnecessary "slot_nr >= UINSNS_PER_PAGE" check, slot_nr must
be valid if offset < PAGE_SIZE.
The next patches will cleanup this function even more.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240929144235.GA9471@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/events/uprobes.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 4b52cb2ae6d62..cc605df73d72f 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1683,8 +1683,8 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
static void xol_free_insn_slot(struct task_struct *tsk)
{
struct xol_area *area;
- unsigned long vma_end;
unsigned long slot_addr;
+ unsigned long offset;
if (!tsk->mm || !tsk->mm->uprobes_state.xol_area || !tsk->utask)
return;
@@ -1693,24 +1693,21 @@ static void xol_free_insn_slot(struct task_struct *tsk)
if (unlikely(!slot_addr))
return;
+ tsk->utask->xol_vaddr = 0;
area = tsk->mm->uprobes_state.xol_area;
- vma_end = area->vaddr + PAGE_SIZE;
- if (area->vaddr <= slot_addr && slot_addr < vma_end) {
- unsigned long offset;
- int slot_nr;
-
- offset = slot_addr - area->vaddr;
- slot_nr = offset / UPROBE_XOL_SLOT_BYTES;
- if (slot_nr >= UINSNS_PER_PAGE)
- return;
+ offset = slot_addr - area->vaddr;
+ /*
+ * slot_addr must fit into [area->vaddr, area->vaddr + PAGE_SIZE).
+ * This check can only fail if the "[uprobes]" vma was mremap'ed.
+ */
+ if (offset < PAGE_SIZE) {
+ int slot_nr = offset / UPROBE_XOL_SLOT_BYTES;
clear_bit(slot_nr, area->bitmap);
atomic_dec(&area->slot_count);
smp_mb__after_atomic(); /* pairs with prepare_to_wait() */
if (waitqueue_active(&area->wq))
wake_up(&area->wq);
-
- tsk->utask->xol_vaddr = 0;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH AUTOSEL 6.12 2/5] perf/x86/amd: Warn only on new bits set
2024-11-24 12:46 [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot() Sasha Levin
@ 2024-11-24 12:46 ` Sasha Levin
2024-11-24 13:13 ` [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot() Oleg Nesterov
1 sibling, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2024-11-24 12:46 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Breno Leitao, Paul E . McKenney, Peter Zijlstra, Sandipan Das,
Sasha Levin, mingo, acme, namhyung, tglx, bp, dave.hansen, x86,
linux-perf-users
From: Breno Leitao <leitao@debian.org>
[ Upstream commit de20037e1b3c2f2ca97b8c12b8c7bca8abd509a7 ]
Warning at every leaking bits can cause a flood of message, triggering
various stall-warning mechanisms to fire, including CSD locks, which
makes the machine to be unusable.
Track the bits that are being leaked, and only warn when a new bit is
set.
That said, this patch will help with the following issues:
1) It will tell us which bits are being set, so, it is easy to
communicate it back to vendor, and to do a root-cause analyzes.
2) It avoid the machine to be unusable, because, worst case
scenario, the user gets less than 60 WARNs (one per unhandled bit).
Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Sandipan Das <sandipan.das@amd.com>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Link: https://lkml.kernel.org/r/20241001141020.2620361-1-leitao@debian.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/x86/events/amd/core.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 920e3a640cadd..b4a1a2576510e 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -943,11 +943,12 @@ static int amd_pmu_v2_snapshot_branch_stack(struct perf_branch_entry *entries, u
static int amd_pmu_v2_handle_irq(struct pt_regs *regs)
{
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
+ static atomic64_t status_warned = ATOMIC64_INIT(0);
+ u64 reserved, status, mask, new_bits, prev_bits;
struct perf_sample_data data;
struct hw_perf_event *hwc;
struct perf_event *event;
int handled = 0, idx;
- u64 reserved, status, mask;
bool pmu_enabled;
/*
@@ -1012,7 +1013,12 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs)
* the corresponding PMCs are expected to be inactive according to the
* active_mask
*/
- WARN_ON(status > 0);
+ if (status > 0) {
+ prev_bits = atomic64_fetch_or(status, &status_warned);
+ // A new bit was set for the very first time.
+ new_bits = status & ~prev_bits;
+ WARN(new_bits, "New overflows for inactive PMCs: %llx\n", new_bits);
+ }
/* Clear overflow and freeze bits */
amd_pmu_ack_global_status(~status);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot()
2024-11-24 12:46 [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot() Sasha Levin
2024-11-24 12:46 ` [PATCH AUTOSEL 6.12 2/5] perf/x86/amd: Warn only on new bits set Sasha Levin
@ 2024-11-24 13:13 ` Oleg Nesterov
2024-11-24 14:15 ` Sasha Levin
1 sibling, 1 reply; 5+ messages in thread
From: Oleg Nesterov @ 2024-11-24 13:13 UTC (permalink / raw)
To: Sasha Levin
Cc: linux-kernel, stable, Peter Zijlstra, mhiramat, mingo, acme,
namhyung, linux-trace-kernel, linux-perf-users
Hi Sasha,
but why do you think it makes sense to backport these "uprobes" cleanups?
Oleg.
On 11/24, Sasha Levin wrote:
>
> From: Oleg Nesterov <oleg@redhat.com>
>
> [ Upstream commit c7b4133c48445dde789ed30b19ccb0448c7593f7 ]
>
> 1. Clear utask->xol_vaddr unconditionally, even if this addr is not valid,
> xol_free_insn_slot() should never return with utask->xol_vaddr != NULL.
>
> 2. Add a comment to explain why do we need to validate slot_addr.
>
> 3. Simplify the validation above. We can simply check offset < PAGE_SIZE,
> unsigned underflows are fine, it should work if slot_addr < area->vaddr.
>
> 4. Kill the unnecessary "slot_nr >= UINSNS_PER_PAGE" check, slot_nr must
> be valid if offset < PAGE_SIZE.
>
> The next patches will cleanup this function even more.
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Link: https://lore.kernel.org/r/20240929144235.GA9471@redhat.com
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> kernel/events/uprobes.c | 21 +++++++++------------
> 1 file changed, 9 insertions(+), 12 deletions(-)
>
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 4b52cb2ae6d62..cc605df73d72f 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1683,8 +1683,8 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
> static void xol_free_insn_slot(struct task_struct *tsk)
> {
> struct xol_area *area;
> - unsigned long vma_end;
> unsigned long slot_addr;
> + unsigned long offset;
>
> if (!tsk->mm || !tsk->mm->uprobes_state.xol_area || !tsk->utask)
> return;
> @@ -1693,24 +1693,21 @@ static void xol_free_insn_slot(struct task_struct *tsk)
> if (unlikely(!slot_addr))
> return;
>
> + tsk->utask->xol_vaddr = 0;
> area = tsk->mm->uprobes_state.xol_area;
> - vma_end = area->vaddr + PAGE_SIZE;
> - if (area->vaddr <= slot_addr && slot_addr < vma_end) {
> - unsigned long offset;
> - int slot_nr;
> -
> - offset = slot_addr - area->vaddr;
> - slot_nr = offset / UPROBE_XOL_SLOT_BYTES;
> - if (slot_nr >= UINSNS_PER_PAGE)
> - return;
> + offset = slot_addr - area->vaddr;
> + /*
> + * slot_addr must fit into [area->vaddr, area->vaddr + PAGE_SIZE).
> + * This check can only fail if the "[uprobes]" vma was mremap'ed.
> + */
> + if (offset < PAGE_SIZE) {
> + int slot_nr = offset / UPROBE_XOL_SLOT_BYTES;
>
> clear_bit(slot_nr, area->bitmap);
> atomic_dec(&area->slot_count);
> smp_mb__after_atomic(); /* pairs with prepare_to_wait() */
> if (waitqueue_active(&area->wq))
> wake_up(&area->wq);
> -
> - tsk->utask->xol_vaddr = 0;
> }
> }
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot()
2024-11-24 13:13 ` [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot() Oleg Nesterov
@ 2024-11-24 14:15 ` Sasha Levin
2024-11-24 14:36 ` Oleg Nesterov
0 siblings, 1 reply; 5+ messages in thread
From: Sasha Levin @ 2024-11-24 14:15 UTC (permalink / raw)
To: Oleg Nesterov
Cc: linux-kernel, stable, Peter Zijlstra, mhiramat, mingo, acme,
namhyung, linux-trace-kernel, linux-perf-users
On Sun, Nov 24, 2024 at 02:13:57PM +0100, Oleg Nesterov wrote:
>Hi Sasha,
>
>but why do you think it makes sense to backport these "uprobes" cleanups?
If it doesn't, I'm happy to drop them. This commit was selected mostly
because of:
>> 1. Clear utask->xol_vaddr unconditionally, even if this addr is not valid,
>> xol_free_insn_slot() should never return with utask->xol_vaddr != NULL.
Which sounded to me like more than a cleanup.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot()
2024-11-24 14:15 ` Sasha Levin
@ 2024-11-24 14:36 ` Oleg Nesterov
0 siblings, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2024-11-24 14:36 UTC (permalink / raw)
To: Sasha Levin
Cc: linux-kernel, stable, Peter Zijlstra, mhiramat, mingo, acme,
namhyung, linux-trace-kernel, linux-perf-users
On 11/24, Sasha Levin wrote:
>
> On Sun, Nov 24, 2024 at 02:13:57PM +0100, Oleg Nesterov wrote:
> >Hi Sasha,
> >
> >but why do you think it makes sense to backport these "uprobes" cleanups?
>
> If it doesn't, I'm happy to drop them. This commit was selected mostly
> because of:
I'd suggest to drop.
> >>1. Clear utask->xol_vaddr unconditionally, even if this addr is not valid,
> >> xol_free_insn_slot() should never return with utask->xol_vaddr != NULL.
>
> Which sounded to me like more than a cleanup.
Sorry for confusion. This patch doesn't make much sense without the next
changes.
Oleg.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-24 14:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-24 12:46 [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot() Sasha Levin
2024-11-24 12:46 ` [PATCH AUTOSEL 6.12 2/5] perf/x86/amd: Warn only on new bits set Sasha Levin
2024-11-24 13:13 ` [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot() Oleg Nesterov
2024-11-24 14:15 ` Sasha Levin
2024-11-24 14:36 ` Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).