From patchwork Thu Aug 3 10:09:31 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: 130471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1066160vqx; Thu, 3 Aug 2023 04:05:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlF8ylW3Sw4W05KtfejiY7oCza6fQIT0oZfoLYc0oM6ZBVjYC0/4c/lKPi3z87sHXMIIWzoo X-Received: by 2002:a17:902:9049:b0:1af:aafb:64c8 with SMTP id w9-20020a170902904900b001afaafb64c8mr16933607plz.21.1691060743111; Thu, 03 Aug 2023 04:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691060743; cv=none; d=google.com; s=arc-20160816; b=CqLayzh40Q8BPWbcLY1uwsy1PLrWbZ+rUGb1TUrog8bLwCOdfsVvPjLM/8DjxBwV4p Sai+GcMtwjxJucVRp+KrFiHJPA4WP3kCxRU74Ye3c7l6xcfLllzOc/MxxwB8zZnDG6M6 5pB6XgFDXJHxDrgHQImu4N730M2UdyNrAWQAie5EdwWOo2cG+qbWa7joAatH5MgrpjyY G80PO0CCVlfrh1jc0Ovr9FtfSb8cF2d9hIdlAWqcEJVE7DMpk2iC9B2wKEdNsIbdlhMp ncStlGuGR4BoypmY0zBNyCEQ5ao9cJkzM7UltgiJS8oJlyY0aTja+Oj6fgZ8U35E8brW U0Mw== 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=qpjoDTQpFQHCdfIIfIOuJHC3wPs+6uNYjZf1fx8U6Tw=; fh=XmTwOPuyyn2SXWnZqO4WlLJ8UucNQ7smOIqArV3zDe4=; b=kypzJEsnBuQgOMhofTTMCZc1UZFMfy2j3mCqrppx8i3zSbJ+YlDIwXw+o5XssPcHRE 62ZbQo+63ehbbJzQginlfZd3bloH3SiK6LzqNPhbKsM8fz/7/SeVLmPs9tVi6ge0Gtke HU3vSkZsK+A3GJTTJhPzqCwFuisz3D9r5sgZoerfBG9wOEEHt70Gln0N7jH4thmHBSHm 1Q3gn18HQB1qTTgRO+tuZ4d4ZvSir9wg2RsSFOKPCZM3UjoCe9SIp+FlegX8F6stnZeo rD77s0UUKty/uhFXwVqdTbTkD9KLvpRHPoPe2MOLvwOsi8RYreRlEQcsfWYpwY1tWorF qItQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SKNtVp0P; 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 q4-20020a17090311c400b001b7e19195b7si12973507plh.29.2023.08.03.04.05.18; Thu, 03 Aug 2023 04:05:43 -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=SKNtVp0P; 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 S235215AbjHCKJx (ORCPT + 99 others); Thu, 3 Aug 2023 06:09:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235116AbjHCKJn (ORCPT ); Thu, 3 Aug 2023 06:09:43 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D600D30FD for ; Thu, 3 Aug 2023 03:09:40 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691057378; 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=qpjoDTQpFQHCdfIIfIOuJHC3wPs+6uNYjZf1fx8U6Tw=; b=SKNtVp0PYSCMMWIY+YYI0/rEZDFa7CZ1GkKHbTz+l6xNZsH6LGrAbdeTwLinBIEpNiZX5m ci4HrcSp6fFzYwPmLZ+tihX+zykBYtopjxp0DjRcseEBcb7t2OvIEvM81GdqBiUal64qWh Z4bLcqOU1+DldRbE96DIN6qvDbgRYxgISUNNvl9ypQ4bgwh1DBKNGE4yKS+fak1Dcz9l0D 7D++X2llN3febj4r/iXA+E1vM3odoUsv8xSDJZx3RaLdfKsdV8rtj1Se2ibUhGmg4NUZEe sPBFWRhOj0zzdqyWEYhQ2gfRziw2T9tQd6XAgtHaGPykTFMIipP1AszkqmPGww== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691057378; 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=qpjoDTQpFQHCdfIIfIOuJHC3wPs+6uNYjZf1fx8U6Tw=; b=+2bXTdvUtuFxSFiHu5U1NZAqrLZ+PCmxVtQrWhgnSeFRFbh76UH9GTFiD4hVl16SJgL5gU evxUBWyz9ClA6oBA== 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, 3 Aug 2023 12:09:31 +0200 Message-Id: <20230803100932.325870-2-bigeasy@linutronix.de> In-Reply-To: <20230803100932.325870-1-bigeasy@linutronix.de> References: <20230803100932.325870-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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: INBOX X-GMAIL-THRID: 1773205709799956220 X-GMAIL-MSGID: 1773205709799956220 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(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2318,10 +2318,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);