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);