From nobody Tue Feb 10 07:39:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 546BDEB64D9 for ; Thu, 15 Jun 2023 10:57:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343569AbjFOK47 (ORCPT ); Thu, 15 Jun 2023 06:56:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237522AbjFOK4p (ORCPT ); Thu, 15 Jun 2023 06:56:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF9CE57 for ; Thu, 15 Jun 2023 03:56:43 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686826600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HnRJ4BIMXrLrKTGUlPJ8sVKrQcH4Bmp7z7V6Nvmam2E=; b=yD9FO0dPz8eQKZePW0PeLhYL/WLYKB2IhaUy/ucvC2SXNY2V+Yw9YUeERi/QlR0hjC57dW 0sjxeII3sB/CeGfR4afQZwAYMK/pmKYGheKPIqXBgMaLL3apyy3aZcZLdFzW8SEzAB1Huu bWAIRTDAwNRuQe/IQ5qUfPoD9IXMUtbzgApBFR5SOvnN8uSUxP6iFA+Pmn4DqcDzO/DyLf xoyDM1NJm3Vkb1WQZB2ji0/CCQg/mC2BmJFdt24Rrv9dICbHn3rjC2jacSeHKy4s07S/P5 JNR2Znh+IUQJb4RjHejF20Tg0/9IawM97tasNLRvPY3x0Ogm9aKK/Vj5XL+g9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686826600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HnRJ4BIMXrLrKTGUlPJ8sVKrQcH4Bmp7z7V6Nvmam2E=; b=Rb3rKLPV0N/m2dlUp9CM1zjKKVltaAnt6gA+DqpqHSlG9tsSH0xYMONJKz9+9YZaa+pFkq QFKWCbhQ39P4WXAQ== To: linux-kernel@vger.kernel.org Cc: "Eric W. Biederman" , Oleg Nesterov , Peter Zijlstra , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v3 1/2] signal: Add proper comment about the preempt-disable in ptrace_stop(). Date: Thu, 15 Jun 2023 12:56:26 +0200 Message-Id: <20230615105627.1311437-2-bigeasy@linutronix.de> In-Reply-To: <20230615105627.1311437-1-bigeasy@linutronix.de> References: <20230615105627.1311437-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Commit 53da1d9456fe7 ("fix ptrace slowness") added a preempt-disable section between read_unlock() and the following schedule() invocation without explaining why it is needed. Replace the comment with an explanation why this is needed. Clarify that it is needed for correctness but for performance reasons. Acked-by: Oleg Nesterov Signed-off-by: Sebastian Andrzej Siewior --- kernel/signal.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index 2547fa73bde51..da017a5461163 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2313,10 +2313,21 @@ static int ptrace_stop(int exit_code, int why, unsi= gned long message, do_notify_parent_cldstop(current, false, why); =20 /* - * Don't want to allow preemption here, because - * sys_ptrace() needs this task to be inactive. + * The previous do_notify_parent_cldstop() invocation woke ptracer. + * One a PREEMPTION kernel this can result in preemption requirement + * which will be fulfilled after read_unlock() and the ptracer will be + * put on the CPU. + * The ptracer is in wait_task_inactive(, __TASK_TRACED) waiting for + * this task wait in schedule(). If this task gets preempted then it + * remains enqueued on the runqueue. The ptracer will observe this and + * then sleep for a delay of one HZ tick. In the meantime this task + * gets scheduled, enters schedule() and will wait for the ptracer. * - * XXX: implement read_unlock_no_resched(). + * This preemption point is not bad from correctness point of view but + * extends the runtime by one HZ tick time due to the ptracer's sleep. + * The preempt-disable section ensures that there will be no preemption + * between unlock and schedule() and so improving the performance since + * the ptracer has no reason to sleep. */ preempt_disable(); read_unlock(&tasklist_lock); --=20 2.40.1