From patchwork Fri Jan 20 15:02:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wander Lairson Costa X-Patchwork-Id: 46405 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp257170wrn; Fri, 20 Jan 2023 07:18:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXtodIqXzAxnVrl7zmKlWQ+E8N4U9VX/V91jvnMQFTJTi6qZw6pyj5HepQX99BhLFJ04bwGF X-Received: by 2002:a05:6402:401d:b0:49b:5a1c:9cb5 with SMTP id d29-20020a056402401d00b0049b5a1c9cb5mr16740004eda.16.1674227919739; Fri, 20 Jan 2023 07:18:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674227919; cv=none; d=google.com; s=arc-20160816; b=oI66X6AAQFm0tTdv5cKCPVz6CXLKG+CVFoH1puU1eb6T3/eq+r1iuuL+cSvqy8dFtm uKIJ+Rgm54LXweXbxrGD0C/5NmA8PN1k03k7M2EKSR6uiNfQqrIgSms2oqw5bSlJEIv6 IGviUgqaG6O2oBvBEKA4nrTA9BfrbVnu6YP67GuE2OrI9CMUwHG7w5aaf3shz7n5GqQF A3h+W3WxtdOzB/iHXC1vK+8ZbF011OhcyioxRGirwaeE5d+vGKvnGfvLC9YN7zh+XsAA XT0UV/FaoN9rzRYqFagAmOb6+WQ8gRKq3IpeRlBs+Tm4SmGxGKR9/o+388FFnGRqqvh0 nXmg== 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:from :dkim-signature; bh=JV/ESkSwVKzhkko42aCx2p6hA+p3ybUeT3T+J1aTWFk=; b=BDZ4ewbhmkb723h84q2/x6lFvTiNg4zHbkelvJ7GRV7ssvFx7rQMyKHRDxsfGwcxAr KD57L/9kg6xC5qL/sZtyiSO2+R6zciYjTUxhmSA6YMO2FfvRh/LoYV/JXI99Qszy9cTZ tIPRDXY7T3h9EGFu/hX1RnmUUrfO15NxSfB7QH3ABWqjGmFkFZ84tx5j6/MZvnnkPe6Q RABEkxiAjBwBc4Hnb19papqinpIpyF457U9htpx1LtGoZSDS2TJEx9RZpXPrawJF7T/h oeGTa+tWN7jseaoIdUQ+VmPvYoKdwLVZcndGv17NjoloHKUGvPRDExu9ZCkJdSJoKhwf KgZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=J5ALeAYw; 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=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho38-20020a1709070ea600b0084ce55f4b7csi51715073ejc.470.2023.01.20.07.18.15; Fri, 20 Jan 2023 07:18:39 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=J5ALeAYw; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231239AbjATPEI (ORCPT + 99 others); Fri, 20 Jan 2023 10:04:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbjATPEH (ORCPT ); Fri, 20 Jan 2023 10:04:07 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38D647DF96 for ; Fri, 20 Jan 2023 07:03:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674226999; 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=JV/ESkSwVKzhkko42aCx2p6hA+p3ybUeT3T+J1aTWFk=; b=J5ALeAYwCS0mgLtuxWdUdQcOzRVo1I/kkXGEZ2RbAKNo4WnFSaaRKCos22MUAjDwN3mnjQ Uclpe2zc4/YbozVzhMgM8/xco8Uw2oNJmoK0ZAazuMs/uwweHAz3ziT7C1o3U3/DE3z0aD za7AGfru0Jz8v/iSLYCdpkUYEpmvF9I= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-490-hTSGCuu2PG2YUUno0xEQkw-1; Fri, 20 Jan 2023 10:03:18 -0500 X-MC-Unique: hTSGCuu2PG2YUUno0xEQkw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 164F8181E3F2; Fri, 20 Jan 2023 15:03:17 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.32.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69408492B02; Fri, 20 Jan 2023 15:03:01 +0000 (UTC) From: Wander Lairson Costa To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , "Eric W. Biederman" , Wander Lairson Costa , Stafford Horne , Kefeng Wang , Oleg Nesterov , Andrew Morton , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , linux-kernel@vger.kernel.org (open list) Cc: Paul McKenney Subject: [PATCH v2 1/4] sched/task: Add the put_task_struct_atomic_safe function Date: Fri, 20 Jan 2023 12:02:39 -0300 Message-Id: <20230120150246.20797-2-wander@redhat.com> In-Reply-To: <20230120150246.20797-1-wander@redhat.com> References: <20230120150246.20797-1-wander@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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?1755555214927726207?= X-GMAIL-MSGID: =?utf-8?q?1755555214927726207?= With PREEMPT_RT, it is unsafe to call put_task_struct() in atomic contexts because it indirectly acquires sleeping locks. Introduce put_task_struct_atomic_safe(), which schedules __put_task_struct() through call_rcu() when the kernel is compiled with PREEMPT_RT. A more natural approach would use a workqueue, but since in PREEMPT_RT we can't allocate dynamic memory from atomic context, the code would become more complex because we would need to put the work_struct instance in the task_struct and initialize it when we allocate a new task_struct. Signed-off-by: Wander Lairson Costa Cc: Paul McKenney Cc: Thomas Gleixner --- include/linux/sched/task.h | 21 +++++++++++++++++++++ kernel/fork.c | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 357e0068497c..80b4c5812563 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -127,6 +127,27 @@ static inline void put_task_struct_many(struct task_struct *t, int nr) void put_task_struct_rcu_user(struct task_struct *task); +extern void __delayed_put_task_struct(struct rcu_head *rhp); + +static inline void put_task_struct_atomic_safe(struct task_struct *task) +{ + if (IS_ENABLED(CONFIG_PREEMPT_RT)) { + /* + * Decrement the refcount explicitly to avoid unnecessarily + * calling call_rcu. + */ + if (refcount_dec_and_test(&task->usage)) + /* + * under PREEMPT_RT, we can't call put_task_struct + * in atomic context because it will indirectly + * acquire sleeping locks. + */ + call_rcu(&task->rcu, __delayed_put_task_struct); + } else { + put_task_struct(task); + } +} + /* Free all architecture-specific resources held by a thread. */ void release_thread(struct task_struct *dead_task); diff --git a/kernel/fork.c b/kernel/fork.c index 9f7fe3541897..3d7a4e9311b3 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -859,6 +859,14 @@ void __put_task_struct(struct task_struct *tsk) } EXPORT_SYMBOL_GPL(__put_task_struct); +void __delayed_put_task_struct(struct rcu_head *rhp) +{ + struct task_struct *task = container_of(rhp, struct task_struct, rcu); + + __put_task_struct(task); +} +EXPORT_SYMBOL_GPL(__delayed_put_task_struct); + void __init __weak arch_task_cache_init(void) { } /* From patchwork Fri Jan 20 15:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wander Lairson Costa X-Patchwork-Id: 46406 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp257202wrn; Fri, 20 Jan 2023 07:18:44 -0800 (PST) X-Google-Smtp-Source: AMrXdXtMXCvF2GL87XhqNFH+t6FKGiTWC3e8sv20PCHiM+n6nhZ/PNDUL4djAJgZOBznWvhgSUf4 X-Received: by 2002:a17:906:5d1:b0:861:7a02:1046 with SMTP id t17-20020a17090605d100b008617a021046mr14843399ejt.37.1674227924071; Fri, 20 Jan 2023 07:18:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674227924; cv=none; d=google.com; s=arc-20160816; b=nt3fnGCYvo2iG3gTCRrUyfSRi9mUs/bjMLSva+szKwaDsCKmI27b/fNSotLSy/Pk29 cBkkh8NRivw6zjSZrBTBRGKvn2NVS9y+nuMvrnE/L2lwh7zaI40A8MtpntYJk58+u6vO 2NJLNYXNMgeAW8cp4FPJynugeWZXPNr0gAnLbtEnMLqs/Lrzs9N4CK9mlrJXssUVEUHu /d7KwkZgDtrQj1a2hPChrv1BgcBTvDDuprTZZZRqB9U7iIxqpvBXp3KpygvZWMU7BCsI ty3y/EwgqdyB0NqzknRK/Ao95aEfBqr7TDEAek+AK15Hj9zJW6hXyicxVEqzaHIYJgHW H3EA== 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:to:from :dkim-signature; bh=6iRsFgdyFm9aCh9hJwwja26lzouAKLjx2fwTp+CTHC4=; b=doBIysoVfqoY68Sx6N8UNeeXjzSX9C/fMfqdJKZHjjN/bbQnb5g5nos0MeGCaX4VE6 UFxusQXaR51r0eCHdAAz9lmXTABHMMYnPuYlnsbIVcHDUxrGAZ7x1qj74CgLb4ZDMOB8 8FoscgIvGdiKuZnFyc23kmNVx8MSttqpR7MlMgLCEWjDw5XxNwhdQRt6D3kAPfYEmpYM 4KxWi0j0JisFf2Ppyd/3kpLPRNADcbw0s1UqgALS19qMqEXuhtrnUhbm+M9TIj3uclsv /mx7b/2dPRNHC0XtRh1j0qKyk7CRR50xyYdgoIVvBridgrshK8UCm+qYAo/72Oj+cC5e ASIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NeBGpfJu; 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=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq39-20020a1709073f2700b008776a3205ffsi8131431ejc.38.2023.01.20.07.18.18; Fri, 20 Jan 2023 07:18:44 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=NeBGpfJu; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231278AbjATPE2 (ORCPT + 99 others); Fri, 20 Jan 2023 10:04:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230024AbjATPEW (ORCPT ); Fri, 20 Jan 2023 10:04:22 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47F0D7CCC1 for ; Fri, 20 Jan 2023 07:03:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674227013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6iRsFgdyFm9aCh9hJwwja26lzouAKLjx2fwTp+CTHC4=; b=NeBGpfJuLOkvMoRl6iRI/RQzWMebyjXrhuvP/kniEbjccQ0kxvmIiEPg5Van3hOi73TXky r74zGYPbgeIbjTC6Oq0sYQjJ9DtLtGg4nOXVvrKB36mbQ/yQRzU6U+ghvUeBVVeJmhElgN WJLn1hZL1rYbn7qflw1SbAbP40s6nsU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-133-0x9ArX0hPPaHNE5UgIfsEQ-1; Fri, 20 Jan 2023 10:03:26 -0500 X-MC-Unique: 0x9ArX0hPPaHNE5UgIfsEQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ACE998588E7; Fri, 20 Jan 2023 15:03:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.32.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5AA8492B03; Fri, 20 Jan 2023 15:03:20 +0000 (UTC) From: Wander Lairson Costa To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , "Eric W. Biederman" , Geert Uytterhoeven , Andrew Morton , Catalin Marinas , Kefeng Wang , Wander Lairson Costa , Oleg Nesterov , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/4] sched/deadline: fix inactive_task_timer splat Date: Fri, 20 Jan 2023 12:02:40 -0300 Message-Id: <20230120150246.20797-3-wander@redhat.com> In-Reply-To: <20230120150246.20797-1-wander@redhat.com> References: <20230120150246.20797-1-wander@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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?1755555219911062044?= X-GMAIL-MSGID: =?utf-8?q?1755555219911062044?= inactive_task_timer() executes in interrupt (atomic) context. It calls put_task_struct(), which indirectly acquires sleeping locks under PREEMPT_RT. Below is an example of a splat that happened in a test environment: CPU: 1 PID: 2848 Comm: life Kdump: loaded Tainted: G W --------- Hardware name: HP ProLiant DL388p Gen8, BIOS P70 07/15/2012 Call Trace: dump_stack_lvl+0x57/0x7d mark_lock_irq.cold+0x33/0xba ? stack_trace_save+0x4b/0x70 ? save_trace+0x55/0x150 mark_lock+0x1e7/0x400 mark_usage+0x11d/0x140 __lock_acquire+0x30d/0x930 lock_acquire.part.0+0x9c/0x210 ? refill_obj_stock+0x3d/0x3a0 ? rcu_read_lock_sched_held+0x3f/0x70 ? trace_lock_acquire+0x38/0x140 ? lock_acquire+0x30/0x80 ? refill_obj_stock+0x3d/0x3a0 rt_spin_lock+0x27/0xe0 ? refill_obj_stock+0x3d/0x3a0 refill_obj_stock+0x3d/0x3a0 ? inactive_task_timer+0x1ad/0x340 kmem_cache_free+0x357/0x560 inactive_task_timer+0x1ad/0x340 ? switched_from_dl+0x2d0/0x2d0 __run_hrtimer+0x8a/0x1a0 __hrtimer_run_queues+0x91/0x130 hrtimer_interrupt+0x10f/0x220 __sysvec_apic_timer_interrupt+0x7b/0xd0 sysvec_apic_timer_interrupt+0x4f/0xd0 ? asm_sysvec_apic_timer_interrupt+0xa/0x20 asm_sysvec_apic_timer_interrupt+0x12/0x20 RIP: 0033:0x7fff196bf6f5 Use put_task_struct_atomic_safe() instead. Signed-off-by: Wander Lairson Costa Cc: Thomas Gleixner --- kernel/sched/deadline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 0d97d54276cc..03400c61a994 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1442,7 +1442,7 @@ static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer) dl_se->dl_non_contending = 0; unlock: task_rq_unlock(rq, p, &rf); - put_task_struct(p); + put_task_struct_atomic_safe(p); return HRTIMER_NORESTART; } From patchwork Fri Jan 20 15:02:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wander Lairson Costa X-Patchwork-Id: 46410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp257885wrn; Fri, 20 Jan 2023 07:19:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXt3BzjXpg454kvH2kblNZSLLa8DCJurbpecuGgqHEskOVYMBD8kfViJx2lduWwAj7Miqrfh X-Received: by 2002:a17:90a:4fa4:b0:226:f7d7:50f4 with SMTP id q33-20020a17090a4fa400b00226f7d750f4mr38574697pjh.21.1674227998763; Fri, 20 Jan 2023 07:19:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674227998; cv=none; d=google.com; s=arc-20160816; b=ARB0UKvPGoZzFD3KLS4M8SvCqvLIQ9hs/PBTRF9rsa+zAOrRMUWQWXRIypN4tdv3GZ rgR6ud1a6ZI3uLEYrBaTP+H/A4SyATmqXGBp8vVa+W9lBu/3C8ApBe7b0gswy78FNalq IJbjYfuFfhvjSfd6V0RuN0o/S+X6hDRBL+kreoemBKbOe1Yh9PDWc/EUcPg4SQcLfTSq hMjTcWE5saDMjYWwzTfMCK/tKrWGTuCr+pSHivIusmMOhjbfJbkF4t6jJoo7bWCmpLVB kRKmSyR1EzDC11TUSHxhbToJIxCMEF/pvxTIXikzXNZF2KrxN+RFPZ5b3QKUlE83MJwk xsGA== 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:to:from :dkim-signature; bh=F1TJWHWdZqDFCr8xEA0m937H+WTiVZmJanYCSnQgjrk=; b=YftExW/QxThO1TGwiLNRGSVXqGy8JiKI9Wb8VhiMMiA/bM1z6aba8b7QKYBqO9ZcCo WljS6Ns2QHkPRPongnfGrWEPD5Bax3CK7TRFwfrhChbBJwBlqzZ4p7ScKIChuJBLlLek UglEf41Dn/iyoAHtfSA+IgB2V/cxC1dYKfaNTAFLXnm8qpJePaTqndN+0BKoMER2FuTf dhRlUc1wz/YJvocamBV1Li2Qk5QNMtLY6VH8bauaVsYRE4iTZNbLs0WwFfLvIa2By7W3 88uoXkYLKjdkhLxgKeD1Eu5ir+9sCWdGwF1Y21kp87y0+vcxOFC9C/mVSz882szG7n/g oqgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aBw3t80S; 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=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c15-20020a17090a4d0f00b00218b7ae4defsi2508883pjg.134.2023.01.20.07.19.46; Fri, 20 Jan 2023 07:19:58 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=aBw3t80S; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbjATPEj (ORCPT + 99 others); Fri, 20 Jan 2023 10:04:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230429AbjATPEa (ORCPT ); Fri, 20 Jan 2023 10:04:30 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80FDB81013 for ; Fri, 20 Jan 2023 07:03:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674227022; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F1TJWHWdZqDFCr8xEA0m937H+WTiVZmJanYCSnQgjrk=; b=aBw3t80SCMtSlaTEoenyoVBHtZz+Vxk9rFf7DH2Lv66xzogqsM5cjEBtW+rvh1kRa1g1LR 3rOuEySgjIG/wSgvGemc1SpdTW3z11BQLYtsXZdkRlN+T3LwK7Tktmb7AINbZ8PTqkPohB i9grLRDACUvJucBwrv1JbVJf9ZE8RmM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-16-XksM0rtCN-K57tGpGanOQQ-1; Fri, 20 Jan 2023 10:03:35 -0500 X-MC-Unique: XksM0rtCN-K57tGpGanOQQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18E4F181E3EE; Fri, 20 Jan 2023 15:03:34 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.32.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44B13492B02; Fri, 20 Jan 2023 15:03:29 +0000 (UTC) From: Wander Lairson Costa To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , "Eric W. Biederman" , Stafford Horne , Guo Ren , Kefeng Wang , Oleg Nesterov , Wander Lairson Costa , Andrew Morton , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 3/4] sched/rt: use put_task_struct_atomic_safe() to avoid potential splat Date: Fri, 20 Jan 2023 12:02:41 -0300 Message-Id: <20230120150246.20797-4-wander@redhat.com> In-Reply-To: <20230120150246.20797-1-wander@redhat.com> References: <20230120150246.20797-1-wander@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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?1755555298193862463?= X-GMAIL-MSGID: =?utf-8?q?1755555298193862463?= rto_push_irq_work_func() is called in hardirq context, and it calls push_rt_task(), which calls put_task_struct(). If the kernel is compiled with PREEMPT_RT and put_task_struct() reaches zero usage count, it triggers a splat because __put_task_struct() indirectly acquires sleeping locks. The put_task_struct() call pairs with an earlier get_task_struct(), which makes the probability of the usage count reaches zero pretty low. In any case, let's play safe and use the atomic safe version. Signed-off-by: Wander Lairson Costa Cc: Thomas Gleixner Reviewed-by: Steven Rostedt (Google) --- kernel/sched/rt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index ed2a47e4ddae..30a4e9607bec 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -2147,7 +2147,7 @@ static int push_rt_task(struct rq *rq, bool pull) /* * Something has shifted, try again. */ - put_task_struct(next_task); + put_task_struct_atomic_safe(next_task); next_task = task; goto retry; } @@ -2160,7 +2160,7 @@ static int push_rt_task(struct rq *rq, bool pull) double_unlock_balance(rq, lowest_rq); out: - put_task_struct(next_task); + put_task_struct_atomic_safe(next_task); return ret; } From patchwork Fri Jan 20 15:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wander Lairson Costa X-Patchwork-Id: 46409 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp257608wrn; Fri, 20 Jan 2023 07:19:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXsxwX4k8YtNn1d0+GnlDHfhAerov6eOK4BiYi8VfkxavOOWX8xSw0zMSiXtk58LCOz+LyIT X-Received: by 2002:a17:907:3ea9:b0:7ff:727f:65cb with SMTP id hs41-20020a1709073ea900b007ff727f65cbmr15466488ejc.19.1674227967998; Fri, 20 Jan 2023 07:19:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674227967; cv=none; d=google.com; s=arc-20160816; b=dQpxMTVCZ+G1jQkvyYfbGMHFfXZ94AQtWwVnQ4KjhYJKQ4KN1jWmQw5bF+J333VKsx 2IpsUKhtbS21kJ31V9lzJuVtMOoa/M6QhaRMjWVBgUx+WPnXG3Qia6q2kXO3lb+0buUk Nr9qHsX+MuK3J6gvOmTwIhNUO2WmD0Y2MGsqFv0DQ7g9nnRD8mGAwikqj5uTy08o9fkq favwQJXo5tzBcvdsEzUXA6tzhVHi8vC5nE7O/bLzOTyfs1DDUGqMHLX22GjJRV0Npke8 wq3beakj1VI9+ZdjpVkRAFX14a10bvojqHZcuoXHJYsio4cplkYYipAehqtzFD4+wJo+ eg4w== 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:to:from :dkim-signature; bh=Lda/+ml5+8vWZrx9vfKLtfMa+7nWIziVhjlRSwPRz3M=; b=KK257+mz1ipFzrdH/k2b7GLHUkW3+K4pCoWaMMoI1GIKC27zyzcC8u/8e5TW6uRgHk goe4fi9bU2P0alOq1rJkc472fNtSWNqyOImI39uK7IPOST9TzlHqY52VE7/5x2Ea1nEi XlMYSZBAP1g02iCE6L8XDoEmAbQv7xs1hTLm5uL4MoU2q7CG+zh9iuiI27yGPoRL0fE5 +Djv06d8W5VAGUVJ0vEvybg8W80979rlA65GXMZsdQ4TY+BUhnzqvfYRrJTFImm3vCeH eTpoDPm5oE0Qh/Ejz+SoIGhYpo9JuOtDG3qyO/YYQ+Zu4J8RE+QCqI0k/wN/IaE8IyXP VDcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dLYPoSVO; 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=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw19-20020a1709066a1300b00877a7ce0ec4si1090577ejc.252.2023.01.20.07.19.03; Fri, 20 Jan 2023 07:19:27 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=dLYPoSVO; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231285AbjATPEl (ORCPT + 99 others); Fri, 20 Jan 2023 10:04:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231288AbjATPEc (ORCPT ); Fri, 20 Jan 2023 10:04:32 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFF84B2E66 for ; Fri, 20 Jan 2023 07:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674227028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lda/+ml5+8vWZrx9vfKLtfMa+7nWIziVhjlRSwPRz3M=; b=dLYPoSVO6rnvIsMAH9X9Bq66MUJXwYdu+oCku7s5I8eIjgZqlH2i4Qk4sN/zS26eSKFlmp VPRd5N6jYbfUGIPrHsmSYUdiM8xU8u4wVhvQLYcUCkc8aI5KRqechgR1B0VeSA/WXxylEf q9+3J5No++34u6JmW4kGpCeojZBK6fI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-554-bhRqpXYPNP-zoGd957nf9Q-1; Fri, 20 Jan 2023 10:03:43 -0500 X-MC-Unique: bhRqpXYPNP-zoGd957nf9Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43D06800DB5; Fri, 20 Jan 2023 15:03:42 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.32.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7F02492B02; Fri, 20 Jan 2023 15:03:37 +0000 (UTC) From: Wander Lairson Costa To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , "Eric W. Biederman" , Geert Uytterhoeven , Stafford Horne , "Russell King (Oracle)" , Oleg Nesterov , Wander Lairson Costa , Kefeng Wang , Andrew Morton , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 4/4] sched/core: use put_task_struct_atomic_safe() to avoid potential splat Date: Fri, 20 Jan 2023 12:02:42 -0300 Message-Id: <20230120150246.20797-5-wander@redhat.com> In-Reply-To: <20230120150246.20797-1-wander@redhat.com> References: <20230120150246.20797-1-wander@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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?1755555265743039390?= X-GMAIL-MSGID: =?utf-8?q?1755555265743039390?= push_cpu_stop() is called form a context in which it must not sleep. Since push_cpu_stop() calls put_task_struct(), it potentially can sleep under PREEMPT_RT if the usage count reaches zero. Use put_task_struct_atomic_safe(0 instead to avoid this potential splat. Signed-off-by: Wander Lairson Costa Cc: Thomas Gleixner --- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c437260e19b0..e5d0c66cb90c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2565,7 +2565,7 @@ int push_cpu_stop(void *arg) raw_spin_rq_unlock(rq); raw_spin_unlock_irq(&p->pi_lock); - put_task_struct(p); + put_task_struct_atomic_safe(p); return 0; }