Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp391020rdb; Thu, 18 Jan 2024 06:45:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfxnOjZB4NrI9ZCwduSR86OD7zikzkSi/qLk0dh9yw0Ms+r1gna1T2SICCwHfdpqwSmUQt X-Received: by 2002:a05:6a20:9194:b0:19a:9f65:a971 with SMTP id v20-20020a056a20919400b0019a9f65a971mr1314183pzd.59.1705589103473; Thu, 18 Jan 2024 06:45:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705589103; cv=pass; d=google.com; s=arc-20160816; b=U9YmggsNqnTVEdDf+eO73NyPY5Y9Uv1ucrw6y6JXQB/BvEtbmA9vHb4il4zyf2/Xvz 4fH79iDszEpcTVrZrlvk6TfpgChmoCl2d1NwsEhdpBWFJkPR2HrbK4jNhiKtjjsaFDat eSylExp4fiK1YuDnOZasToQIBDrTXbZaYN+SFoQz9eYZQU++Vn38lM6yMYvmbXc7kmaT 3wG5wb/8V5mzAwrYDV54vQ1BM2aR2bBTvDKMzbvR2DYcpXhxvq9oW40tLoXPKPikpIfP yChsYRfOvfxKnYO2K6TstY7/G5p7okX7CVMGKoQr3M8y6idb+DDwH0cVURO7x3LYfTS1 0GDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=EAfojegdiXJIKHxZiJfRlX3GDRGmp24yjKb+rApBqxQ=; fh=akdBP+UeyzwdrNwv+uFQbL4BTB7jjMKh/cUXKOhzHgw=; b=k70L6mVPtAhnAo64v1UisWB6kfmTbZAajPkorFmkkwTLiSfF/ZKieD8OjXGWydT9rn SJMBiWmoIyIAHp5cc40R0SZuftA754YXl54dC2qPxMwzy2GzIBtRigJ4M/7xk3d83VLx +pHVUpbIvddDN7PFlPqIHFkr+0F0siP7E784X92fC6/oO0j9e2P4/uI52C97BuBhGPR2 QeoHtqPuMubEy/XkTraG6A8Ov2jQahmy5sgdwgvj0Mm28DTa1mj1Mok8r8qxYA/A9o7N r+ypVulFROqiimVzDkARQ0z4W6zj5RAnOew8Tm2/Vlhazz16qatBcFvrVKfJ0uWzPPmR BpVg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OmfPqywr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-30219-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30219-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j6-20020a056a00130600b006d9b4294509si3973236pfu.200.2024.01.18.06.45.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 06:45:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30219-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OmfPqywr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-30219-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30219-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EA6A628225D for ; Thu, 18 Jan 2024 14:45:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 463D11DA2A; Thu, 18 Jan 2024 14:44:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OmfPqywr" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70DD2646; Thu, 18 Jan 2024 14:44:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705589095; cv=none; b=XjHO98/vVqsB8VTqXEskc8BXj1r8ygmUkyAlHvnEDMkL+X3Md3paN58zjxBdwRj1PrtCT/vJcJZORsgVCv+Fz++7oCZDs5XzMOlUJTx1icB1U+fXHIdSuUlU6rTI93FLZx5Z8pcRsxQxw1v3BOxrhB0WVcJWutVojKnZchme96k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705589095; c=relaxed/simple; bh=FIWDXh4TMq/7lMeI0IsyQDpPlkd6cnqeXUZhP3qX+A4=; h=Received:DKIM-Signature:Received:Date:From:To:Cc:Subject: Message-ID:Reply-To:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=rPkS8VEk9xFotx7xJCr1tDhS6u2xcGdUZOSZv61tiuJS8SaSv0FVB7aCkaAwi14nNTRns9RJhNN0hmW8s1+Ge3gGZCLyMwVvkkbjFDKB6WIIV7YL6Mzu3GDpT891Qk5LuPaq7wrPq/tVuTvohh+fEo6fUOuJAWDcC3HPz+fOJ34= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OmfPqywr; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBA55C433C7; Thu, 18 Jan 2024 14:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705589094; bh=FIWDXh4TMq/7lMeI0IsyQDpPlkd6cnqeXUZhP3qX+A4=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=OmfPqywrN5vo9zYO6l/kHSO0GOcSt6zCu+Wvibnqme2XW7kQSLfgRs0oWVczAxoXe d6NWhfOKeQzHtrGjDkmxJlAEDlDzn3aD8aNL9vRJZEm0SjDI+MQR6heyuF2Kv6CW7I 773MMllTjQ9wrci5Imq1JsL9U1M5cYXzd6kpocvZLYQDtVCWtxChhMg/+ixVvuyszl kvdhYJNQgYKH9322x923TgetLy3Ir43rUh4POtkDWjS+AUPtvnW4hZb6NEV/nwBkaV tNYjpb78YnDRALYsi4jarc2aLh02j7nV1vdnmHF+qZRk/fceXJFO19DW67eglBw8bc zbcaUrPpDWnew== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 50520CE0546; Thu, 18 Jan 2024 06:44:54 -0800 (PST) Date: Thu, 18 Jan 2024 06:44:54 -0800 From: "Paul E. McKenney" To: Steven Rostedt Cc: Chen Zhongjin , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, yangjihong1@huawei.com, naveen.n.rao@linux.ibm.com, anil.s.keshavamurthy@intel.com, davem@davemloft.net, mhiramat@kernel.org, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, pmladek@suse.com, dianders@chromium.org, npiggin@gmail.com, mpe@ellerman.id.au, jkl820.git@gmail.com, juerg.haefliger@canonical.com, rick.p.edgecombe@intel.com, eric.devolder@oracle.com, mic@digikod.net Subject: Re: [PATCH v2] kprobes: Use synchronize_rcu_tasks_rude in kprobe_optimizer Message-ID: <47e87ff3-2925-4671-89a6-067f36f25d19@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20240118021842.290665-1-chenzhongjin@huawei.com> <20240117212646.5f0ddf0c@gandalf.local.home> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240117212646.5f0ddf0c@gandalf.local.home> On Wed, Jan 17, 2024 at 09:26:46PM -0500, Steven Rostedt wrote: > On Thu, 18 Jan 2024 02:18:42 +0000 > Chen Zhongjin wrote: > > > There is a deadlock scenario in kprobe_optimizer(): > > > > pid A pid B pid C > > kprobe_optimizer() do_exit() perf_kprobe_init() > > mutex_lock(&kprobe_mutex) exit_tasks_rcu_start() mutex_lock(&kprobe_mutex) > > synchronize_rcu_tasks() zap_pid_ns_processes() // waiting kprobe_mutex > > // waiting tasks_rcu_exit_srcu kernel_wait4() > > // waiting pid C exit > > > > To avoid this deadlock loop, use synchronize_rcu_tasks_rude() in kprobe_optimizer() > > rather than synchronize_rcu_tasks(). synchronize_rcu_tasks_rude() can also promise > > that all preempted tasks have scheduled, but it will not wait tasks_rcu_exit_srcu. > > > > Did lockdep detect this? If not, we should fix that. > > I'm also thinking if we should find another solution, as this seems more of > a work around than a fix. My suggestion is at 526b12e4-4bb0-47b1-bece-66b47bfc0a92@paulmck-laptop. Better suggestions are of course welcome. ;-) > > Fixes: a30b85df7d59 ("kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT=y") > > Signed-off-by: Chen Zhongjin > > --- > > v1 -> v2: Add Fixes tag > > --- > > arch/Kconfig | 2 +- > > kernel/kprobes.c | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/arch/Kconfig b/arch/Kconfig > > index f4b210ab0612..dc6a18854017 100644 > > --- a/arch/Kconfig > > +++ b/arch/Kconfig > > @@ -104,7 +104,7 @@ config STATIC_CALL_SELFTEST > > config OPTPROBES > > def_bool y > > depends on KPROBES && HAVE_OPTPROBES > > - select TASKS_RCU if PREEMPTION > > + select TASKS_RUDE_RCU > > Is this still a bug if PREEMPTION is not enabled? Both "select" clauses would be needed for this patch, if I understand correctly. Thanx, Paul > -- Steve > > > > > config KPROBES_ON_FTRACE > > def_bool y > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > > index d5a0ee40bf66..09056ae50c58 100644 > > --- a/kernel/kprobes.c > > +++ b/kernel/kprobes.c > > @@ -623,7 +623,7 @@ static void kprobe_optimizer(struct work_struct *work) > > * Note that on non-preemptive kernel, this is transparently converted > > * to synchronoze_sched() to wait for all interrupts to have completed. > > */ > > - synchronize_rcu_tasks(); > > + synchronize_rcu_tasks_rude(); > > > > /* Step 3: Optimize kprobes after quiesence period */ > > do_optimize_kprobes(); >