Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp963998pxb; Tue, 3 Nov 2020 18:11:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJy03+IGNHYRzKQjAuwSvV5ajDyJpyNyhl5/RuRWZDPmBe/rwvbiXliVCyl+b7QWO0tmZh3f X-Received: by 2002:a17:906:16d6:: with SMTP id t22mr11038290ejd.376.1604455896224; Tue, 03 Nov 2020 18:11:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604455896; cv=none; d=google.com; s=arc-20160816; b=GKofPIp2LkE/JaQGWmDz8nheKldEp6278D4ac1eKWz01sWLq78Mu2PvmzojitXCIy9 TIYI2y1mRe/F5cjF+DzOFbMm9zPr7eMLXCS7dvaZOV3AJl0JhHY+6FLpxfz1o0OAI+mf 0V84aKhgGDnY12Yy9GawXXHKhX6aLZ7P1R8Or4CG1cMgJJNAUNRHsjDog4z3zr2fSeo+ cV2BCxMCsVP2LOTzgfYxr14UBBVTIKo73ekV+AqLmgrqU9Tn8kMXRgXpxAGosw9vBL90 1DJIIN/3YdICeAeccRSjyxlWkmBVrqQsqMixmFen2d3XsOS2GKFVmqelByNupyLjXy4q VO3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=MuO2VXC8VTPBdBAik3RWIFVr3lYfu2pNZ2zj+uBk4nA=; b=waVtWeZ3Lx8sUQ4yGUErM85OYgAGoqpYI0GtUXNKjChtu/yTQR5hldjcH+MndQIWj1 DplT24f/q3Mb0s3Fmp3oHYNCG7zvzcFHfx+1u9cEB8l0QFvTtCjE2A5px2V1GVLAcL7q 8nIVljO/wRJ5hgOde3B5m8XUuQdXXOUGVAlk3vdIQlZzFZlRP8ueaZSUCdbXtvFjw+8K t+m5uBSgoBoocHIZwbYltoy+I+cXWH3OcNRvuaS5jmLmLzzNA/zoXxp0DV/6mpRtwrYp KYdvzkdf/Wd7KuY2uzsrQDiDwst0jDf186+etmFGa+0wadwXsUXylr9EAp7VyFhly0yW 0+YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XWGEK+Is; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a24si478106ejt.53.2020.11.03.18.11.13; Tue, 03 Nov 2020 18:11:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XWGEK+Is; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730417AbgKDCI6 (ORCPT + 99 others); Tue, 3 Nov 2020 21:08:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:51866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725765AbgKDCI5 (ORCPT ); Tue, 3 Nov 2020 21:08:57 -0500 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6D092206F9; Wed, 4 Nov 2020 02:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604455736; bh=qBXpwdmJhHsoLx/QiLWblIhxH+snDEjjhdDpYvqd8xc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XWGEK+Is04g6D8jeNxQI5tV+j7EfqX2Z30zToLYe+0pBIuuBsbO7N13ByuG7g5Qg/ amU2sV4+14md/egFLm+EzhreyhNSKGvwvTX3kCPDCpuKFPVJlunwh6998BDWzZulMk YEkpsrLW0WAMGfaF336UOI/ESQiwrl8vg7HHKKtw= Date: Wed, 4 Nov 2020 11:08:52 +0900 From: Masami Hiramatsu To: Steven Rostedt Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Peter Zijlstra , Eddy_Wu@trendmicro.com, x86@kernel.org, davem@davemloft.net, naveen.n.rao@linux.ibm.com, anil.s.keshavamurthy@intel.com, linux-arch@vger.kernel.org, cameron@moodycamel.com, oleg@redhat.com, will@kernel.org, paulmck@kernel.org Subject: Re: [PATCH v5 14/21] kprobes: Remove NMI context check Message-Id: <20201104110852.5dcace1aa7f912020ca1be2e@kernel.org> In-Reply-To: <20201103110913.2d7b4cea@rorschach.local.home> References: <159870598914.1229682.15230803449082078353.stgit@devnote2> <159870615628.1229682.6087311596892125907.stgit@devnote2> <20201030213831.04e81962@oasis.local.home> <20201102141138.1fa825113742f3bea23bc383@kernel.org> <20201102145334.23d4ba691c13e0b6ca87f36d@kernel.org> <20201102160234.fa0ae70915ad9e2b21c08b85@kernel.org> <20201102092726.57cb643f@gandalf.local.home> <20201103143938.704c7974e93c854511580c38@kernel.org> <20201103110913.2d7b4cea@rorschach.local.home> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 3 Nov 2020 11:09:13 -0500 Steven Rostedt wrote: > On Tue, 3 Nov 2020 14:39:38 +0900 > Masami Hiramatsu wrote: > > > Ah, OK. This looks good to me. > > > > BTW, in_nmi() in pre_handler_kretprobe() always be true because > > now int3 is treated as an NMI. So you can always pass 1 there. > > What about the below patch then? kretprobe_hash_lock() and kretprobe_table_lock() will be called from outside of the kprobe pre_handler context. So, please keep in_nmi() in those functions. for the pre_handler_kretprobe(), this looks good to me. Thank you, > > Acked-by: Masami Hiramatsu > > Thanks! > > From 29ac1a5c9068df06f3196173d4325c8076759551 Mon Sep 17 00:00:00 2001 > From: "Steven Rostedt (VMware)" > Date: Mon, 2 Nov 2020 09:17:49 -0500 > Subject: [PATCH] kprobes: Tell lockdep about kprobe nesting > > 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 > Signed-off-by: Steven Rostedt (VMware) > --- > kernel/kprobes.c | 23 +++++++++++++++++++---- > 1 file changed, 19 insertions(+), 4 deletions(-) > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 8a12a25fa40d..30889ea5514f 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -1249,7 +1249,12 @@ __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. > + */ > + raw_spin_lock_irqsave_nested(hlist_lock, *flags, 1); > } > NOKPROBE_SYMBOL(kretprobe_hash_lock); > > @@ -1258,7 +1263,12 @@ 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. > + */ > + raw_spin_lock_irqsave_nested(hlist_lock, *flags, 1); > } > NOKPROBE_SYMBOL(kretprobe_table_lock); > > @@ -2028,7 +2038,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); > @@ -2039,7 +2054,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.25.4 > -- Masami Hiramatsu