From patchwork Thu Jun 15 10:56:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 108441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp557951vqr; Thu, 15 Jun 2023 04:24:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ400CKehHE7Hs+55RV4u2JFm4fkbRPM/l6U77qt3AJAQqPiO+Z0aNIFhyfa4i+s5YbqgNfP X-Received: by 2002:a17:907:31ce:b0:957:2d2a:e8a2 with SMTP id xf14-20020a17090731ce00b009572d2ae8a2mr18479780ejb.27.1686828292360; Thu, 15 Jun 2023 04:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686828292; cv=none; d=google.com; s=arc-20160816; b=aesYMmCAaGpwcCRidW/Q4qySOucsROqePcLxS4s9pszdkJ942vzUQjWRsJwWvsUX1A JEgh8v88voZ2I9wa8p3r1nQG6BmCROTAPb4L22QEQfBMptPyNxnUQbPO3oH2AsUXzOmr B2ls/6ALvJgiti5gjw+OyU2sxHzg65v7M4wk7VkTcw6JUwEjuQXEYk/OKrOROZC+DLWu bllx2LxB1dKJTIiRyrm5gbfAlwLsCV1o5Ana1Vq7atfl9ZO2DAHh/Wv9wb9mBE30yqoi OMZRac/LjoL5wQr++/rJ8yLNKlLovScKb/TsE23gzi1zuAVhCO+lg43hWIkakHHDBYLO Gi4w== 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:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=HnRJ4BIMXrLrKTGUlPJ8sVKrQcH4Bmp7z7V6Nvmam2E=; b=z2tcQPoQrRKccESZA7VI2LErY8/DD6qBV8UHJkFnvatcPS+af/7egq8JuByVzBpYe8 /mmbKFyNgLsnyWrh2hPWiNd8zrD/JwHLI70Tx1mPS4mJ7LiIC/GTv3jqSKKwiXkoMqzL 1Jt7M/F3/EnxpxRkOgRqJex185GuUZLscrF3Ur7ooqO/RaunCwDKH/molE7hfKMaplti TZ+b2nT7SgMbwkN64lIEFbaEbNHt6R3eujwFLl/WLIm+ekwxLcacVYdsrspl1FVEQEGM Kv6XAyx5LNkTkmoexIH2E+r2F3TRwh3kEehGa0sZK3EP68ZYhHNX5+KKDhwWAkrLO+6z VOyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yD9FO0dP; dkim=neutral (no key) header.i=@linutronix.de header.b=Rb3rKLPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c9-20020a170906924900b009537ef82da3si9403689ejx.993.2023.06.15.04.24.27; Thu, 15 Jun 2023 04:24:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yD9FO0dP; dkim=neutral (no key) header.i=@linutronix.de header.b=Rb3rKLPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245355AbjFOK46 (ORCPT + 99 others); Thu, 15 Jun 2023 06:56:58 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768767663263274215?= X-GMAIL-MSGID: =?utf-8?q?1768767663263274215?= 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, unsigned long message, do_notify_parent_cldstop(current, false, why); /* - * 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); From patchwork Thu Jun 15 10:56:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 108438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp557653vqr; Thu, 15 Jun 2023 04:24:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4p+ra+z5v4MFKQtTeTRhGFlGgYohncdvWNJ4UvU2e49MFa+gdu+/PtQ4urkSSEQFYGeZlZ X-Received: by 2002:a2e:8ec8:0:b0:2b3:4acd:8477 with SMTP id e8-20020a2e8ec8000000b002b34acd8477mr3449876ljl.10.1686828255079; Thu, 15 Jun 2023 04:24:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686828255; cv=none; d=google.com; s=arc-20160816; b=C5dwyIPZb293y38pwcZh73VaAHRHwGUUOSX2xAoebZkQ3dfmi9R6fUQELbAu7BMKNB UgFiVeeNd7FpkX8TTRyD7jTDuK40Acw3lY8Zg068yH7aui6RW+FUi0f5xF9oQjMHeAxe igZ/zjGsyZPuID9nsPiNMDXVSW3KSQ6MQoPN4vnkR1I4Oj4Tv6UV/hNSp8r+7Q56Jlho cPWgTzU7Ydj8gwY77rF/jjkLvz8Sa+2DbGG/X9stSOpGsBTydpTEFJVXjAW64pmXYFJM +msPekHo3b0AR1RLenV26zp9NlxLf4x+JyB+vdz0IVNk5CWxKSNEJQqrVJfQs6DFZBhm 2TkQ== 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:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=I/QLlkP12aZg2OG62D74WUAk4h5OegU8e3v3LQUZTFk=; b=V4T4+pCYgZW2k8NAIfofZVcIQBY7yFvW2sJfFz7q1fm3oWZ9QbGCDWhlQgeCyEWkVb +qjtPOuLx8x7j5J947ykdxYUNKTAmor4ATF3725FhzWdRaMDbRfGMBu2EJ9Sl9CNjCT+ SBHGOxjnXwua1b5uTfLjgPuP5kxj8B7lqGzgzkkbmJII9XHATQGeATdLDnldTj9yKao6 gALMblI4ZVa65hpV9pGtSZ9adh/P0LMwZot7+PNqb9UFwwEGEkqu1iEJQxASercCRYDG pfqprDzEo20ILxXG7YGpP4SmASGj8cROxHH7cWCsg436SFjn9u0SCLRQt7Zs24cDu0bR bp5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZUbs71h1; dkim=neutral (no key) header.i=@linutronix.de header.b=ggyL+eW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n2-20020aa7c442000000b0051a2cc8c485si412317edr.295.2023.06.15.04.23.50; Thu, 15 Jun 2023 04:24:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZUbs71h1; dkim=neutral (no key) header.i=@linutronix.de header.b=ggyL+eW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240340AbjFOK4v (ORCPT + 99 others); Thu, 15 Jun 2023 06:56:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238074AbjFOK4p (ORCPT ); Thu, 15 Jun 2023 06:56:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF381A2 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=I/QLlkP12aZg2OG62D74WUAk4h5OegU8e3v3LQUZTFk=; b=ZUbs71h1JxlcirLnjh96NF0dj08tpsOtNdYeN750JN+DnI94kftP24X6Ei1sYjMuCvdbbW SlaP7MRfaAWkqAxqxqKKWOagPkcxtHWl0icsRhJUnUwhBdE2VmWkhND9lO0I+HfLog5Aki L8dL303ixRxZ7sFPaxPsxHoEkRj+yIWt037CFnS0ng0Cr31Rs7SHJ+OGnBTg+e55ron1Oi Fd04WmRxo8H4CN+8hLRhfzzIFoy+3lba7XUqzCRVayZ4tFYodz+7Gmgg0AE51t8Xr6xA+y 2TAKNT42biJ7NLEHi5NyC6VJ3jky8/TOji47halPux/b0Z47Asf1vxZzzFdPLQ== 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=I/QLlkP12aZg2OG62D74WUAk4h5OegU8e3v3LQUZTFk=; b=ggyL+eW02COW//bhBK3KlTKd60ubVbq/Q6p4lXVX1rIuoTmVll0DeBr+qgdLI/EBxtSX3T btBb0YyjAqniYTAA== To: linux-kernel@vger.kernel.org Cc: "Eric W. Biederman" , Oleg Nesterov , Peter Zijlstra , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH v3 2/2] signal: Don't disable preemption in ptrace_stop() on PREEMPT_RT. Date: Thu, 15 Jun 2023 12:56:27 +0200 Message-Id: <20230615105627.1311437-3-bigeasy@linutronix.de> In-Reply-To: <20230615105627.1311437-1-bigeasy@linutronix.de> References: <20230615105627.1311437-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768767624549486381?= X-GMAIL-MSGID: =?utf-8?q?1768767624549486381?= On PREEMPT_RT keeping preemption disabled during the invocation of cgroup_enter_frozen() is a problem because the function acquires css_set_lock which is a sleeping lock on PREEMPT_RT and must not be acquired with disabled preemption. The preempt-disabled section is only for performance optimisation reasons and can be avoided. Extend the comment and don't disable preemption before scheduling on PREEMPT_RT. Acked-by: Oleg Nesterov Signed-off-by: Sebastian Andrzej Siewior --- kernel/signal.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index da017a5461163..e887cd684d17a 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2328,11 +2328,20 @@ static int ptrace_stop(int exit_code, int why, unsigned long message, * 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. + * + * On PREEMPT_RT locking tasklist_lock does not disable preemption. + * Therefore the task can be preempted (after + * do_notify_parent_cldstop()) before unlocking tasklist_lock so there + * is no benefit in doing this. The optimisation is harmful on + * PEEMPT_RT because the spinlock_t (in cgroup_enter_frozen()) must not + * be acquired with disabled preemption. */ - preempt_disable(); + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + preempt_disable(); read_unlock(&tasklist_lock); cgroup_enter_frozen(); - preempt_enable_no_resched(); + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) + preempt_enable_no_resched(); schedule(); cgroup_leave_frozen(true);