From patchwork Tue Jun 6 08:55:23 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: 103678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3254831vqr; Tue, 6 Jun 2023 02:13:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7LNIRJt4PZOPUEiU6LQ39zNkHAjFoB48h/yOlZ73+HW/MD55ZTmAnTI7G4ogaE0OVMO009 X-Received: by 2002:a05:6214:5008:b0:626:1589:68e4 with SMTP id jo8-20020a056214500800b00626158968e4mr1745581qvb.43.1686042826910; Tue, 06 Jun 2023 02:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686042826; cv=none; d=google.com; s=arc-20160816; b=J1h1umxI4QryFTnH6WpygYPO+xs3XDribYD3gZuhEO1JL9gA0+hcEyJyEuHobd57ME afOOIaML0YzHZ0WOndsmK9/EKx9X27+KmsPo27q6/6EFD8+jK/g/GOQ+lKx4arq2WOPL pUJ5cz2zWdiuhZOoP/uN0uXgZ8i30NF7aLEq9g6LtK7wrGAlTT7pgEE6FX0zF0srMowW zPmlP4nQgfzl/rVxKtowi+i0po6q1NYtR5TW08BDc1ORZxMLIgCbDn1fbltJGulxWqQc VztEVKOVtSQj4cS/9iKIUqC2An3BssK1fwcjc/MB95bBbfxp7LLcOlkzaEPRqDYLk1vs T1AA== 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=Cd+JUiL0ywRxwd2ZYcL8vrhCuZmD85iBs9FdcgWCwPc=; b=mM2M+1bocRUrunLdkcDaLboSkCL+bkVdNqww5MOTMisqkKAa4v6dIsoXJaWivpcb0w YOVkaHPv2mjAXiRKMJaK+yFa0pnbUMG6CAx8z+OobXOPtMAbvi1lyONcr7vJP3jLrBgE HcvAbJwua4V8Zu7clBM271eGavDjBEona6XcztRiQqTwtLVr7eq9ct0p+iA3tvIKxqlC 5/8QxptaYl8djnjY3H/fq9ETL738aEz+Vq49ySBCBvG6IuXzxAIUUY1FVAT9ImO+N2a+ /NopPJy97wSSa2KA7a7k844q6LESjw6Hx9Hp1/M/pSZBqo/2jjC//cg7KuRM+HPS2Ox4 Iy6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=E2YAC+kT; dkim=neutral (no key) header.i=@linutronix.de; 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 c10-20020ac87dca000000b003efb4b57c89si5920216qte.781.2023.06.06.02.13.32; Tue, 06 Jun 2023 02:13:46 -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=E2YAC+kT; dkim=neutral (no key) header.i=@linutronix.de; 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 S237296AbjFFIz4 (ORCPT + 99 others); Tue, 6 Jun 2023 04:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235325AbjFFIzt (ORCPT ); Tue, 6 Jun 2023 04:55:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C6B2E8 for ; Tue, 6 Jun 2023 01:55:48 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686041747; 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=Cd+JUiL0ywRxwd2ZYcL8vrhCuZmD85iBs9FdcgWCwPc=; b=E2YAC+kTU9nvRfmyvFVDUWuloG/YvTpHJUW/MMkr8gGPtrs7xX7CR67odfyY3LR9gtvWQB D1TmXGOYD7Iw01LmMuieMr/YXK6HzSI4FbQjmN/U/zVdHj6FWLfYer8RR3G6y9se0nxRsc CWG/GL3QRq8Ex6zWyBrjihfWSsS271qsDhc3s4bS+u58zdB+B2t3+idIgVZ2yRereqOQrF WcDSLnJN/CJhKGtHHHNa73SBQ+/TNSZGODlsBb/ESeq9PE9v2h6k3vtR5IWn2KpYedkmQB TSWH+KI8fqXYPcj5AtLNsYV/2+iIsWgABbMAnIXonHeu+F2JKh/mLkqZu9gTnA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686041747; 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=Cd+JUiL0ywRxwd2ZYcL8vrhCuZmD85iBs9FdcgWCwPc=; b=WuR/aNAYTnmyD095A4LuzBzetucWJac5WMktFBXrvgD2zPHMbG6tgZbenLLOt2ptQSxHKf lm2X0eDM1jjzqbAA== To: linux-kernel@vger.kernel.org Cc: "Eric W. Biederman" , Oleg Nesterov , Peter Zijlstra , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH REPOST 1/2] signal: Add proper comment about the preempt-disable in ptrace_stop(). Date: Tue, 6 Jun 2023 10:55:23 +0200 Message-Id: <20230606085524.2049961-2-bigeasy@linutronix.de> In-Reply-To: <20230606085524.2049961-1-bigeasy@linutronix.de> References: <20230606085524.2049961-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,URIBL_BLOCKED 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?1767944043137454398?= X-GMAIL-MSGID: =?utf-8?q?1767944043137454398?= 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. Signed-off-by: Sebastian Andrzej Siewior Acked-by: Oleg Nesterov --- 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 Tue Jun 6 08:55:24 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: 103679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3254848vqr; Tue, 6 Jun 2023 02:13:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4DQHpwj5yU8iX98tNx3x3w1NKBAuKIDFL9lwnGBInzAVZNuHtFolX1Bz1VrT4dyiqUw+pq X-Received: by 2002:a17:90a:1996:b0:255:c061:9e5b with SMTP id 22-20020a17090a199600b00255c0619e5bmr1245660pji.37.1686042828146; Tue, 06 Jun 2023 02:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686042828; cv=none; d=google.com; s=arc-20160816; b=hqZ9nbchEa0LDD/iOwK4oW7QbpsK2rPzV+0VFJerIJkgSlmjhTjWvmqrJkH0lu3P2G J3JT7sYEox+BMWHB8GNvxvAN1epTDvSB+mA1/192K2IiPOd0tjH81QRc8T6Yv6ZbPfx3 x/8iBkRwW525p4Vrtjnc6WsOrduU/M+sGmTX430NY6mKfLCyML6m6QZCTsz5V7dZcmc0 FroQrJi4gOYNgWDAQKUOaPYY391i7hx2UyPLrvxFZkBM8u+d5pz2+/udMydMD9CbygBw I1OLQch07O7poqGdLUjdZzsvshL3P+yqGe1kzKunAl6isUf8jt2D98GzkjzM32cptHG0 v1TA== 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=FExOD5E8HJtGy/lm1D7DIYTsTEtzFIwKcZPbLrNzZPE=; b=eSqcBER6+buzhI8gf6/k2PQ5ViTtL/nYf4a2ZjGwqXlzC/ZLkgZCjYqxH0iAoPZcOs UbYEHCBtvSsdrJXwb6plSqnW1rezdgNmX0ZdZ89/3r34cMNjaZuDEKUR6J4/JCPLKuRg Tx5YV5Kv4ATS90ncRLd/Ihaxvdd/R2Q3k89TBNknXfmi9X0MV1ynFDlCT/e9TCyW20GY o8t8goyuXWNQpUBwHwgz0qkvWEtIJAjqhqeFyRcIt8goLDsTniOsqNQUc+v9ZNQTB68N Lprmdj55jKx/cde2HiNclPoxE9mQTdO4JlcFjCZfwaf2TjHVU1J3hTIIvd4/MhlN0T12 zxog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tftlDy4X; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 g5-20020a17090a128500b00252d84b7af0si6960511pja.181.2023.06.06.02.13.36; Tue, 06 Jun 2023 02:13:48 -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=tftlDy4X; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S235325AbjFFI4A (ORCPT + 99 others); Tue, 6 Jun 2023 04:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236627AbjFFIzu (ORCPT ); Tue, 6 Jun 2023 04:55:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E46EEA for ; Tue, 6 Jun 2023 01:55:48 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686041747; 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=FExOD5E8HJtGy/lm1D7DIYTsTEtzFIwKcZPbLrNzZPE=; b=tftlDy4XknmZgpUOkAK9spHUoXUymEYXhvGp8Mi84sBJhmSus1Q2hCVNc+glOyG0RkYJ4q XjMNM6qo0PSUnDMmWBHEdLb2BUYrAJCRwDEWe122xr8ft93TorEyGBfvd0TY5vqT7NrqvL QTDZiaysFVl/+k8vQwJzwTaE7dQPfFbB7FTkA1NMfxhvzdVA4rGyJVp0Yk0E/d9l08h5X5 Ptlb7RCUo4TiCcrEfmGI59m2HEjZql4d/8zUKlclohrDD1T9S2C7ki/RgNGvqYfcFYy6oG dJFHFGeqprFB5EfAdGTV468f2zKp7jZJMgheWy6523CHjQJDn+ZYq9NkLmYvCQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686041747; 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=FExOD5E8HJtGy/lm1D7DIYTsTEtzFIwKcZPbLrNzZPE=; b=Qgdn5lAt6sr9Rgf+wlV5JethHHVroIcnnXwYK0rSnbfsrdjqYsviPU0ZyubGn58uCDQasW NKwkTEQplbPP0fAQ== To: linux-kernel@vger.kernel.org Cc: "Eric W. Biederman" , Oleg Nesterov , Peter Zijlstra , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH REPOST 2/2] signal: Don't disable preemption in ptrace_stop() on PREEMPT_RT. Date: Tue, 6 Jun 2023 10:55:24 +0200 Message-Id: <20230606085524.2049961-3-bigeasy@linutronix.de> In-Reply-To: <20230606085524.2049961-1-bigeasy@linutronix.de> References: <20230606085524.2049961-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,URIBL_BLOCKED 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?1767944044240367394?= X-GMAIL-MSGID: =?utf-8?q?1767944044240367394?= 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. Signed-off-by: Sebastian Andrzej Siewior --- kernel/signal.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index da017a5461163..9e07b3075c72e 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2328,11 +2328,16 @@ 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. + * + * This optimisation is not doable on PREEMPT_RT due to the spinlock_t + * within the preempt-disable section. */ - 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);