From patchwork Thu Apr 6 20:57:11 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: 80526 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1301554vqo; Thu, 6 Apr 2023 14:08:23 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/fE0yQKhKdvtm+GCj00n3JWt7wWxm0w64XypQun3fj2ppQGtyHB3FOSmCYqD18MWkILVR X-Received: by 2002:a17:907:98b0:b0:930:800b:2803 with SMTP id ju16-20020a17090798b000b00930800b2803mr178398ejc.76.1680815303351; Thu, 06 Apr 2023 14:08:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680815303; cv=none; d=google.com; s=arc-20160816; b=BIaimZxRsEwjJUI72m0l7rLT3jtshjvK2rbwiervcE/g9dEtRciErLbgseDLjETgqK NZ52+69lM/oWWs0vkpW/gs2PyWL8n/V1LZs6FgJ7479hczVJiGiTMcLW37bD502X6lzm z0sP0nFoi3k+TVBnR7CUSG+5UOKs+JNuClFG8U56A35OtF2CJWqGvWZE3wo8fL6CIlop P05P3D8GL4zONqVgXf6JvgkYBNGlUKRyzDZSFdQqRmA+XqrGwJhq0awvGoGRdTlXtyJN ocjQBA4F0/y3Q/jdLF9dznkBw0M0/HqB589Fx5Z336Bt3tfh4OTCIdo9Am3qYHeT9pSN 2sOQ== 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=aFXiELADcPRlzfKcViV8Vwc2Nkww8T+BuhJWY9I4uvA=; b=Gj3KVWILgAA68Is8/ddTsPcLVMPNtDrd8lKzFXS9cbGson9V6h0IEke2Iziqg9u8wB 8scCpeqRo8KkvPEMOnmgDLsFONKFAyHOhihXVDLBmAv2N4j1FVYqG2qXxqD7FMCNucZ9 oHzlsZxrcUtZ0jUxBbetNHnrFuGoZl7Yd/rKoKkrJURFe48nSLWd0NCZs7hVDH+kuWv4 u9X7a8bHM3p73JLGCv+s5F8Cshgw9gWmRyC8e/K82Jet4s8Aq0PwZrUdc/zklWTU3iu9 oesLKrJ76Pw+dflvIpl9iGAA2+/A9Ljfd9X5qSOU8/4orbrG7w6FjzWrY7srpz5IPtTE 8z0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IT+nY8iH; 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 ib9-20020a1709072c6900b00930943f134esi2009753ejc.8.2023.04.06.14.07.59; Thu, 06 Apr 2023 14:08:23 -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=IT+nY8iH; 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 S238587AbjDFU5X (ORCPT + 99 others); Thu, 6 Apr 2023 16:57:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237174AbjDFU5U (ORCPT ); Thu, 6 Apr 2023 16:57:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25A92E6 for ; Thu, 6 Apr 2023 13:57:19 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1680814637; 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=aFXiELADcPRlzfKcViV8Vwc2Nkww8T+BuhJWY9I4uvA=; b=IT+nY8iHontAduYJPijfK7XGWlppk4WsZr1Zk+Hv8GJ+T0ULr6VaC8aq8yM8RK0VhM2YD0 zni6Faf6ZaS6ViPHq3cs2O8q+l2bX4bof4/Gxyqkln9d2ySrxMO2iZxiQIt2KIVyJlxvo0 j2w3vCSr3pIRkRT4WIEe3EASl1Lp5KuoQMgYeOr7UDhJFLzcubqniUkmWVcMGTOSG0kdEE fig/wXk5jyYe3sViC5T441JW/+IfuMaR7EmDSTzLc1qU5AhPN9jNyy17U5cfqvddOkrSW1 PTUTfMBG7POd5k8vayyO3On8Aaov7fwvWyWSUFtRddNaY00RJWA4JgRxBVEoSg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1680814637; 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=aFXiELADcPRlzfKcViV8Vwc2Nkww8T+BuhJWY9I4uvA=; b=x7qj5MQe6PfvqAscE5pZfbRZzENrSFiodlAiUvCBv7493K+fsawkDsLLymBf+GXax1DBDV H0SdFbvhZRFVEHBg== To: linux-kernel@vger.kernel.org Cc: "Eric W. Biederman" , Oleg Nesterov , Peter Zijlstra , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 1/2] signal: Add proper comment about the preempt-disable in ptrace_stop(). Date: Thu, 6 Apr 2023 22:57:11 +0200 Message-Id: <20230406205713.1843072-2-bigeasy@linutronix.de> In-Reply-To: <20230406205713.1843072-1-bigeasy@linutronix.de> References: <20230406205713.1843072-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1762462587811212727?= X-GMAIL-MSGID: =?utf-8?q?1762462587811212727?= 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 --- kernel/signal.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2337,10 +2337,21 @@ static int ptrace_stop(int exit_code, in 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 Apr 6 20:57:12 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: 80535 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1310550vqo; Thu, 6 Apr 2023 14:26:42 -0700 (PDT) X-Google-Smtp-Source: AKy350Y0KTEVz0t+gPEuGK0QY0WEZFCe2rGROR5O2bXWD5jdkW8f6DlDsvxk2mfmEJMolqxnvlHx X-Received: by 2002:a17:90a:e7cb:b0:234:ac93:d715 with SMTP id kb11-20020a17090ae7cb00b00234ac93d715mr13044614pjb.45.1680816402677; Thu, 06 Apr 2023 14:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680816402; cv=none; d=google.com; s=arc-20160816; b=jC3SIGJGwecJ+2iY9MD0OQnJLPYalbgByUbEsAw7o7G3oexaOdm14qLcxjpcX2kWH+ iCtgu+RgveQmzhZIcAqQgr2vSG2AdOf089sjwEKOSv5BWK8Rla3/jsqhjMgz9M5DMdLZ PFp2UGpo38CR5hS6K4WKaMGEg/I1xJpV254fZEL0aEOTBzfR9K+4n1Wq+/kdx5/Gx0jQ CW5PqnTUrtcusHzSfhqWUpPtg+IZHS5kAJbK/UIVuNhG/LSl330jRzN31+CczVO5kAKD sqZdGEofdjBJiGFeU1UEwvQd9KRq1bYoStrv9vDntXnZ8x4Y5M+hbyGkAb95zcZzO2qn z4nQ== 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=nu76zb774yFa0MN+XeDDVckETU/rIQgmqAyiuYXOZF4=; b=lT3O9hJuGbmjW0CTUcpQv3zsn0NgXwoa/MhB1khvXSlG+RsHnTnGre2/PFoRJSq4Q0 BhOPq/vcEzSgjFpwA69lc1IKcI0daEbRA/gQqE625YXPqsYnleVIA/e3c4pp9C/Q8EN6 ri6j4EgDqkRqbOHVRqt+Xyo2baHkeJiEnXTTZMAh1mE/KIy6td1vfFJHaD2+VAABI4Vt 6z4eKNO+HMZIAJu4iJDgjZyHXG4EPCTBgfuBSAlJYziO2kOT8AwCrcvY68JNQpPkkvqx +kvxUxzj2ezOpp5tdCW/52Aw7oPaBBISBNzxGH1hcgAPXFOLogsK+Ex5aPhVUmYcYpDJ 3ulQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="ok/5H9AV"; 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 q6-20020a17090a430600b002400d82df5asi2049391pjg.57.2023.04.06.14.26.30; Thu, 06 Apr 2023 14:26:42 -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="ok/5H9AV"; 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 S238615AbjDFU5Z (ORCPT + 99 others); Thu, 6 Apr 2023 16:57:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237796AbjDFU5U (ORCPT ); Thu, 6 Apr 2023 16:57:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 650C16589 for ; Thu, 6 Apr 2023 13:57:19 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1680814638; 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=nu76zb774yFa0MN+XeDDVckETU/rIQgmqAyiuYXOZF4=; b=ok/5H9AVhG4+VER7ECM77WvJqsQZU1sqfH0H6uB6goaWUVT7XjjvHYneCIQXhq5ZPxu7XM 0mv7+kQ0vFK1Zwu3OppSweFZGJTgKKd/3ijOeUjmlb22SU49pfp1ligy0ofAuPSjrZVN/G ViQCTIpnipT5yduH18OIIIGw/T7N+dDXE3pLwm46NWPCExLBpEfx+0i++TPoeOVHSO4d7S 7T5HbGYBCnwtIAN+JeiLB4dsi3/Vb8sdwxE8nfrkl8oQcRsb1ffnkL1K3DxLlFfvfe91MG XM9apuHzjpQQHgYQM1mGgvdLR1rSye7S7rb3c7tkt0/nirmRAplNQVGnf0qlVw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1680814638; 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=nu76zb774yFa0MN+XeDDVckETU/rIQgmqAyiuYXOZF4=; b=e3ECoxC2dOBtyRnv+0S4QRsRciqxy0q5gbj5g8fsovpTWXZaDSQSbtVJ2dpm4whxkszSxE aC/nrYE03vNxZ4BA== To: linux-kernel@vger.kernel.org Cc: "Eric W. Biederman" , Oleg Nesterov , Peter Zijlstra , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 2/2] signal: Don't disable preemption in ptrace_stop() on PREEMPT_RT. Date: Thu, 6 Apr 2023 22:57:12 +0200 Message-Id: <20230406205713.1843072-3-bigeasy@linutronix.de> In-Reply-To: <20230406205713.1843072-1-bigeasy@linutronix.de> References: <20230406205713.1843072-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1762463740294502897?= X-GMAIL-MSGID: =?utf-8?q?1762463740294502897?= 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(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2352,11 +2352,16 @@ static int ptrace_stop(int exit_code, in * 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);