Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp82993rdb; Wed, 17 Jan 2024 18:25:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IH510NjuEqvU74x7imr8Pr7F7cxyg3ZbQvuLayaXzYaNJP4VdmW1EuoJA8BZkr+m2HHtUJT X-Received: by 2002:a05:6808:2e8c:b0:3bd:9a8b:4bf3 with SMTP id gt12-20020a0568082e8c00b003bd9a8b4bf3mr355438oib.2.1705544739567; Wed, 17 Jan 2024 18:25:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705544739; cv=pass; d=google.com; s=arc-20160816; b=FLpQCsg4qacQfcRkOo0pe0WE/CbiBwZXCX+yD8cB1nVGegRm7pDm0HXk4ocsyZPjSy 1/mffnPSXWhZYej4yaOYlwVGk42FNAPds75DkVV3MIxqXMYi2mZcPTtGCcu6ujvqbSsa ICX7sx7PXmpKmjJfGvDTKQKLQV8x2wu0QzQtdxjt/WxcPDSbthCEmcTJZ3KasilTlY81 1upV2z3KHtB57ofkZW1kACfK3g8lCSAq5mBMG9IyeOk6S401W4oI4D1JT3TXNYQ/sOLQ vNJv8ZHwCPou6fl1CvMSdD9nMPFkdWl8LIB3+KCPHp1T3+ZlFMweoEyVcWqhMbQsKTM9 J8DA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=W59UnH4LGnORpJJAsDzBWSILan2Fw99kVu3uh3A/R8o=; fh=sSMRczMFesi7lVOss6D8AR6FHGOpWX02o5vVE/XiDJQ=; b=vH4ZGfJWLjoYjvd3P/eJnSrtnMvmioojIGTa4a8r7V7+OQnii5tnFzYbNbS8fCVtYF OvErBtkKITDDi2zTLOWOJEdf2CXLPjuV6ev4cMgmBDZ7ze6KWcg4vkfUIkcXZKJI2PJ3 chrebsiLGoWFPQANUQaOwU13+FEm3zDFb/wIrIzOX4km3S6oSJK8JLf2Fl2rbY16FwAy 2lj0UoAX2/jnNvS7uR0bA3Q0nigahoQZKIUVvw2A5dKGBAPuGzCkLQQZ4qDS7QSAoEl2 BbfcdKNeoZkoWGYHIlyZgzR01LM9G2zZb6NaImf9+YKx6+rFQjQ2NdC65wFN//7Oo3ZP BHdQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-29657-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29657-linux.lists.archive=gmail.com@vger.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 i16-20020aa78d90000000b006d9a617d2ecsi2723090pfr.80.2024.01.17.18.25.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 18:25:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29657-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-29657-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29657-linux.lists.archive=gmail.com@vger.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 32EEA289AB1 for ; Thu, 18 Jan 2024 02:25:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0C265395; Thu, 18 Jan 2024 02:25:32 +0000 (UTC) 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 6499C2115; Thu, 18 Jan 2024 02:25:32 +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=1705544732; cv=none; b=ZZ9Mz7xeV4epI1hQ4y4+B9tm+XhINDHNw7xdm2+MUKi3iFno7IsqhkZwckFw/9xO7LMSoFuR5VYwSBgu8fqKmVMkoTS0i6C67Kkl/EH/3Bu3RH+QV7y1SfIYUSUzjPW54w4vQch2rqjy+Lm2/Zy8+C2joOeSTO2nrBQkbGUiLUY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705544732; c=relaxed/simple; bh=8LBkJof5B327L1V0yCKArqI09jJkUVrtza9uTR4uueI=; h=Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To: References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; b=Hj4KJGrw7UpTZ1sfuohhyUu4JQWyixFoSpVtUKTwjQHAz6R7L2u3Z32Tkkh9a7FMSDrrdwiIMXZckDyAXkI5X5AiZ9GudKNHJkYEB8X+xcZ22U51on4dGnUG8vDS5foFAFcSOsUiU2fJxJwh1FbUB48r9GL9VF3Dn8tU+iPdRLU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 633BFC433C7; Thu, 18 Jan 2024 02:25:29 +0000 (UTC) Date: Wed, 17 Jan 2024 21:26:46 -0500 From: Steven Rostedt To: Chen Zhongjin Cc: , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v2] kprobes: Use synchronize_rcu_tasks_rude in kprobe_optimizer Message-ID: <20240117212646.5f0ddf0c@gandalf.local.home> In-Reply-To: <20240118021842.290665-1-chenzhongjin@huawei.com> References: <20240118021842.290665-1-chenzhongjin@huawei.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit 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. > 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? -- 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();