From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>,
Peter Zijlstra <peterz@infradead.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 5.4 36/42] kprobes: Tell lockdep about kprobe nesting
Date: Mon, 9 Nov 2020 22:54:34 -0500 [thread overview]
Message-ID: <20201110035440.424258-36-sashal@kernel.org> (raw)
In-Reply-To: <20201110035440.424258-1-sashal@kernel.org>
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
[ Upstream commit 645f224e7ba2f4200bf163153d384ceb0de5462e ]
Since the kprobe handlers have protection that prohibits other handlers from
executing in other contexts (like if an NMI comes in while processing a
kprobe, and executes the same kprobe, it will get fail with a "busy"
return). Lockdep is unaware of this protection. Use lockdep's nesting api to
differentiate between locks taken in INT3 context and other context to
suppress the false warnings.
Link: https://lore.kernel.org/r/20201102160234.fa0ae70915ad9e2b21c08b85@kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/kprobes.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 283c8b01ce789..2a38e3553c80b 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1215,7 +1215,13 @@ __acquires(hlist_lock)
*head = &kretprobe_inst_table[hash];
hlist_lock = kretprobe_table_lock_ptr(hash);
- raw_spin_lock_irqsave(hlist_lock, *flags);
+ /*
+ * Nested is a workaround that will soon not be needed.
+ * There's other protections that make sure the same lock
+ * is not taken on the same CPU that lockdep is unaware of.
+ * Differentiate when it is taken in NMI context.
+ */
+ raw_spin_lock_irqsave_nested(hlist_lock, *flags, !!in_nmi());
}
NOKPROBE_SYMBOL(kretprobe_hash_lock);
@@ -1224,7 +1230,13 @@ static void kretprobe_table_lock(unsigned long hash,
__acquires(hlist_lock)
{
raw_spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash);
- raw_spin_lock_irqsave(hlist_lock, *flags);
+ /*
+ * Nested is a workaround that will soon not be needed.
+ * There's other protections that make sure the same lock
+ * is not taken on the same CPU that lockdep is unaware of.
+ * Differentiate when it is taken in NMI context.
+ */
+ raw_spin_lock_irqsave_nested(hlist_lock, *flags, !!in_nmi());
}
NOKPROBE_SYMBOL(kretprobe_table_lock);
@@ -1911,7 +1923,12 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
/* TODO: consider to only swap the RA after the last pre_handler fired */
hash = hash_ptr(current, KPROBE_HASH_BITS);
- raw_spin_lock_irqsave(&rp->lock, flags);
+ /*
+ * Nested is a workaround that will soon not be needed.
+ * There's other protections that make sure the same lock
+ * is not taken on the same CPU that lockdep is unaware of.
+ */
+ raw_spin_lock_irqsave_nested(&rp->lock, flags, 1);
if (!hlist_empty(&rp->free_instances)) {
ri = hlist_entry(rp->free_instances.first,
struct kretprobe_instance, hlist);
@@ -1922,7 +1939,7 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
ri->task = current;
if (rp->entry_handler && rp->entry_handler(ri, regs)) {
- raw_spin_lock_irqsave(&rp->lock, flags);
+ raw_spin_lock_irqsave_nested(&rp->lock, flags, 1);
hlist_add_head(&ri->hlist, &rp->free_instances);
raw_spin_unlock_irqrestore(&rp->lock, flags);
return 0;
--
2.27.0
next prev parent reply other threads:[~2020-11-10 4:01 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-10 3:53 [PATCH AUTOSEL 5.4 01/42] ASoC: qcom: sdm845: set driver name correctly Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 02/42] ASoC: cs42l51: manage mclk shutdown delay Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 03/42] usb: dwc3: pci: add support for the Intel Alder Lake-S Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 04/42] opp: Reduce the size of critical section in _opp_table_kref_release() Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 05/42] usb: gadget: goku_udc: fix potential crashes in probe Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 06/42] selftests/ftrace: check for do_sys_openat2 in user-memory test Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 07/42] selftests: pidfd: fix compilation errors due to wait.h Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 08/42] ALSA: hda: Separate runtime and system suspend Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 09/42] ALSA: hda: Reinstate runtime_allow() for all hda controllers Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 10/42] gfs2: Free rd_bits later in gfs2_clear_rgrpd to fix use-after-free Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 11/42] gfs2: Add missing truncate_inode_pages_final for sd_aspace Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 12/42] gfs2: check for live vs. read-only file system in gfs2_fitrim Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 13/42] scsi: hpsa: Fix memory leak in hpsa_init_one() Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 14/42] drm/amdgpu: perform srbm soft reset always on SDMA resume Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 15/42] drm/amd/pm: perform SMC reset on suspend/hibernation Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 16/42] drm/amd/pm: do not use ixFEATURE_STATUS for checking smc running Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 17/42] mac80211: fix use of skb payload instead of header Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 18/42] cfg80211: initialize wdev data earlier Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 19/42] mac80211: always wind down STA state Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 20/42] cfg80211: regulatory: Fix inconsistent format argument Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 21/42] tracing: Fix the checking of stackidx in __ftrace_trace_stack Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 22/42] scsi: scsi_dh_alua: Avoid crash during alua_bus_detach() Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 23/42] scsi: mpt3sas: Fix timeouts observed while reenabling IRQ Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 24/42] nvme: introduce nvme_sync_io_queues Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 25/42] nvme-rdma: avoid race between time out and tear down Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 26/42] nvme-tcp: " Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 27/42] nvme-rdma: avoid repeated request completion Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 28/42] nvme-tcp: " Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 29/42] iommu/amd: Increase interrupt remapping table limit to 512 entries Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 30/42] s390/smp: move rcu_cpu_starting() earlier Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 31/42] vfio: platform: fix reference leak in vfio_platform_open Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 32/42] vfio/pci: Bypass IGD init in case of -ENODEV Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 33/42] i2c: mediatek: move dma reset before i2c reset Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 34/42] net: usb: qmi_wwan: add Telit LE910Cx 0x1230 composition Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 35/42] amd/amdgpu: Disable VCN DPG mode for Picasso Sasha Levin
2020-11-10 3:54 ` Sasha Levin [this message]
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 37/42] selftests: proc: fix warning: _GNU_SOURCE redefined Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 38/42] riscv: Set text_offset correctly for M-Mode Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 39/42] i2c: sh_mobile: implement atomic transfers Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 40/42] tpm_tis: Disable interrupts on ThinkPad T490s Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 41/42] vt: Disable KD_FONT_OP_COPY Sasha Levin
2020-11-10 3:54 ` [PATCH AUTOSEL 5.4 42/42] fork: fix copy_process(CLONE_PARENT) race with the exiting ->real_parent Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201110035440.424258-36-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).