From patchwork Tue Jun 6 13:16:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 103821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3395281vqr; Tue, 6 Jun 2023 06:29:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5c4XXYsu9K50+lBQDf7bop/kbumwQeC1h+0gMD1V+SQvqUaMz6VXiwwwKC8IIP9jVLN8Ug X-Received: by 2002:a05:6a20:d90b:b0:107:10b6:4c8a with SMTP id jd11-20020a056a20d90b00b0010710b64c8amr1199268pzb.24.1686058170294; Tue, 06 Jun 2023 06:29:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686058170; cv=none; d=google.com; s=arc-20160816; b=zyC1syTm9Pb0Zb1T7P5tYSBkAwFMVBozpsffn2kMgmmGTsC0CgenZRag/W5ZHN0MET AsF2y9/ey2i4FFlgg/BiodD9YGba1JdRYeFXBfeDxzpYXBZKumXCp3AvWZyuVPqgv7gl KfqvyUL2uLLVv9Xrm6hOo2HXlKqtmFXlEzA920/PmeyAd3RZ9Fk7l6QSVmw/DzuQyRlx bYUhRGvCq+PyYfeckFJ9d2e8ZauGVWDm8vXjB+j8ChGVLTE0Y9ei0W6y9RxzK71GZtP1 MbSIqScSZRPiRZem5TPmISGcXIm4p8dRAcWoJDoQTxFBRIr8CQG4BfzyW34VXyxaNVO7 ByNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:dkim-signature:dkim-signature:date; bh=TnnwGQjwBJKNKyeoriEOiM1KFg3/YDdFChAUa/K2FB0=; b=B385wCu96InhgRep6vO6/XyJYEJmPr1blrffEPf/i89fKyMyzx9wNM90PV2q5Nz4zr LzckPyhuuVzSJ0/Mi9rwlDmkipd/Ox4tSzM6uI58vYxqK4YI240tVMeZvN6BUm5MzFsM rdCoq4xerI9ROVZbZnwAcf+ieEmNFuWm/DSQ9MhOuqGFduePDocPyuZhk0GmgQzQZfwE NWRvjciNKxqzVMfeDzfMkHcd9haiVgOMbODC5oR4Lhj9XqBDu7wW0jHpojEIdXJHGFBw h0zGlgWwMF6qBQA+uPkM11MzAfMlhTAGDZNQHgg9Ewwy/qx9XLCMDSojzaqO6M3Y8rdq vwjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=a8aXfBKn; 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 j19-20020a170902759300b001ae52127485si7110530pll.433.2023.06.06.06.29.17; Tue, 06 Jun 2023 06:29:30 -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=a8aXfBKn; 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 S238019AbjFFNQh (ORCPT + 99 others); Tue, 6 Jun 2023 09:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237850AbjFFNQg (ORCPT ); Tue, 6 Jun 2023 09:16:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A050F10C3 for ; Tue, 6 Jun 2023 06:16:25 -0700 (PDT) Date: Tue, 6 Jun 2023 15:16:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686057383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TnnwGQjwBJKNKyeoriEOiM1KFg3/YDdFChAUa/K2FB0=; b=a8aXfBKn/IZyYqgFSLg9sq8bcadvMZ2xUAAA4h/iYmpYz/0dYTDs9F2pa2cnYqNSumyJrc h16hD8Q+bP2vMjJikVozrCcJ46aF2LPtbPGz6NQoZDIh9Clyojmk6kb8Uyksun2tOGMMuk pSnnWyxaOQcvnW55FXzx28xGkHgmirWnSL0ftYZrLIFCaLwxDDbfIkvqqWTl+umnIMqqzZ 8MSYnA8X3ZapZrF1uz9DIlvf6nMIJLBv27o7t9SlDxlyumy8QDIn0uOltFxhYjsCvqdixQ rWV1PL6WmOuvxMqPawxdweSODTppa7NUNPr3KA4H8pyiwPU9mr9HT5+mt/KmtA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686057383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TnnwGQjwBJKNKyeoriEOiM1KFg3/YDdFChAUa/K2FB0=; b=2/rp97Sq+RaZMj/w2kuIhza8UlmzuhCDhIVyADr4hDXYRtgT076EtiTSUMagixW2eIp6vq Vi9FlZOmzNvJblAQ== From: Sebastian Andrzej Siewior To: Oleg Nesterov Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, "Eric W. Biederman" , Thomas Gleixner Subject: [PATCH 2/2 v2] signal: Don't disable preemption in ptrace_stop() on PREEMPT_RT. Message-ID: <20230606131621.nbXfkFvG@linutronix.de> References: <20230606085524.2049961-1-bigeasy@linutronix.de> <20230606085524.2049961-3-bigeasy@linutronix.de> <20230606110447.GA7542@redhat.com> <20230606111418.GA906324@hirez.programming.kicks-ass.net> <20230606113853.GC7542@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230606113853.GC7542@redhat.com> 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?1767960131688345573?= 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 Acked-by: Oleg Nesterov --- Is this better? v1…v2: - Extend the comment to note that preemption isn't disabled due to the lock to make it obvious that the optimisation isn't just harmful but also pointless. kernel/signal.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index da017a5461163..dcb0b1fbcb3a8 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);