Message ID | 20230614122323.37957-1-wander@redhat.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1212198vqr; Wed, 14 Jun 2023 05:33:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6bn9weGyQ7c79au1PMoAGgOS80oY6GdXQcsSdorhd7LI2mqxNdNoMsgGksspiTD7PeEB8N X-Received: by 2002:a17:902:c40c:b0:1aa:ff24:f8f0 with SMTP id k12-20020a170902c40c00b001aaff24f8f0mr12959129plk.4.1686746020744; Wed, 14 Jun 2023 05:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686746020; cv=none; d=google.com; s=arc-20160816; b=jxVgTskZmFnI91hRkWK7Wl585v17/MROTMKdGNJxkz9VmC/upjrkY0n0lF69pCPDhQ r/lS4XySjEFMy8e/JcakFq8MsPoUyviyc0VTgoHsO8xK3msJTvdkn/fTq+5bC425x0Jx d4RtbNNcaXel0rIJU/q4/Hx6IdydvqLJwBJWZONyzMI9R25AXVeH2OQ31lmJf7bNE2/U SkmPAwVNHnE1eLNlmHXwbQ74TF1A47yV0ZN1V8suoT7GB1YuOBLIIssifDQLqcQY6PT1 +q+TCCRrwxMsgIa9KXYy6vOQVLH4CQtwd6iIBUAjvEyQQt+a5wqjvFntOB84DCbp8Iq6 q7WA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=jFRmKE1gKyWwlU8dIHCT74Dsw8jBXXe3UgEOZvAo7zE=; b=vdjZJDlGOqV02kOPKWeHys8WBk/74ClgpMYWRQhVjND1Z7eGD0IcydTiKW0VH1t/aM Kd86FbYVWQRH5wgrI6ZVue8misep27zfiFHS3t3rotycgNa9VAPQS7fEfH6S66+RXvNL B0zDHzrZ7pteMDD30bV1Ej1F80z5gfPO3JXListumFjqy7rLs7jlBVcFHZy8QU++0DUh goLp5NXAzt2H3/TkwSmm8llGWmyzK2lrkXkKq1cE5fUUHVWYy6Z3nU3Yee+UzAuR7LgI c3WZ8a+cUT6ZVGbdGm/8zc2jeIRoQIUQSJJukvu66zJVb6/LXOH82yJrfW91zgRVIXP3 t2Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=O7lU3DQ9; 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 ba12-20020a170902720c00b001b3df9e8a2fsi3898350plb.427.2023.06.14.05.32.56; Wed, 14 Jun 2023 05:33:40 -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=@redhat.com header.s=mimecast20190719 header.b=O7lU3DQ9; 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 S236466AbjFNMZT (ORCPT <rfc822;n2h9z4@gmail.com> + 99 others); Wed, 14 Jun 2023 08:25:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244275AbjFNMY1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 14 Jun 2023 08:24:27 -0400 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 200DA109 for <linux-kernel@vger.kernel.org>; Wed, 14 Jun 2023 05:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686745420; 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; bh=jFRmKE1gKyWwlU8dIHCT74Dsw8jBXXe3UgEOZvAo7zE=; b=O7lU3DQ9yjdW4CgonJ0628Y/7ywtF5+ixhxq7aiywk9ViaAecjXTLsTXQCnwaRAICiNz+0 NSiXlulCVS/qFkb0RiHpLPa8VHG4CeLIwPl2s82Mbk49UPld5HG5P2XuCQXT3DwoVBXiGq PA5flDfW1HPKasbvNX2GqUonGD/G80M= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-30-loLNedIZPRWdGegD93GlIw-1; Wed, 14 Jun 2023 08:23:34 -0400 X-MC-Unique: loLNedIZPRWdGegD93GlIw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4EC0B3C1C4C9; Wed, 14 Jun 2023 12:23:33 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.33.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4693240B4CD8; Wed, 14 Jun 2023 12:23:28 +0000 (UTC) From: Wander Lairson Costa <wander@redhat.com> To: "Christian Brauner (Microsoft)" <brauner@kernel.org>, "Michael S. Tsirkin" <mst@redhat.com>, Mike Christie <michael.christie@oracle.com>, Peter Zijlstra <peterz@infradead.org>, Wander Lairson Costa <wander@redhat.com>, Kefeng Wang <wangkefeng.wang@huawei.com>, Oleg Nesterov <oleg@redhat.com>, Andrew Morton <akpm@linux-foundation.org>, "Liam R. Howlett" <Liam.Howlett@oracle.com>, Suren Baghdasaryan <surenb@google.com>, Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, Andrei Vagin <avagin@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, linux-kernel@vger.kernel.org (open list) Cc: Hu Chunyu <chuhu@redhat.com>, Valentin Schneider <vschneid@redhat.com>, Sebastian Andrzej Siewior <bigeasy@linutronix.de>, Paul McKenney <paulmck@kernel.org>, Steven Rostedt <rostedt@goodmis.org>, Luis Goncalves <lgoncalv@redhat.com> Subject: [PATCH v10 0/2] kernel/fork: beware of __put_task_struct calling context Date: Wed, 14 Jun 2023 09:23:20 -0300 Message-Id: <20230614122323.37957-1-wander@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768681395122027382?= X-GMAIL-MSGID: =?utf-8?q?1768681395122027382?= |
Series |
kernel/fork: beware of __put_task_struct calling context
|
|
Message
Wander Lairson Costa
June 14, 2023, 12:23 p.m. UTC
Under PREEMPT_RT, __put_task_struct() indirectly acquires sleeping locks. Therefore, it can't be called from an non-preemptible context. Instead of calling __put_task_struct() directly, we defer it using call_rcu(). 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. Changelog ========= v1: * Initial implementation fixing the splat. v2: * Isolate the logic in its own function. * Fix two more cases caught in review. v3: * Change __put_task_struct() to handle the issue internally. v4: * Explain why call_rcu() is safe to call from interrupt context. v5: * Explain why __put_task_struct() doesn't conflict with put_task_sruct_rcu_user. v6: * As per Sebastian's review, revert back the implementation of v2 with a distinct function. * Add a check in put_task_struct() to warning when called from a non-sleepable context. * Address more call sites. v7: * Fix typos. * Add an explanation why the new function doesn't conflict with delayed_free_task(). v8: * Bring back v5. * Fix coding style. v9: * Reorganize to not need ___put_task_struct() by Oleg's suggestion. v10: * Add a patch preventing a splat when compile with CONFIG_PROVE_RAW_LOCK_NESTING. Reported-by: Hu Chunyu <chuhu@redhat.com> Suggested-by: Oleg Nesterov <oleg@redhat.com> Suggested-by: Valentin Schneider <vschneid@redhat.com> Suggested-by: Peter Zijlstra <peterz@infradead.org> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Paul McKenney <paulmck@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Luis Goncalves <lgoncalv@redhat.com> Wander Lairson Costa (2): kernel/fork: beware of __put_task_struct calling context sched: avoid false lockdep splat in put_task_struct() include/linux/sched/task.h | 38 +++++++++++++++++++++++++++++++++++++- kernel/fork.c | 8 ++++++++ 2 files changed, 45 insertions(+), 1 deletion(-)
Comments
On Wed, Jun 14, 2023 at 09:23:20AM -0300, Wander Lairson Costa wrote: > Under PREEMPT_RT, __put_task_struct() indirectly acquires sleeping > locks. Therefore, it can't be called from an non-preemptible context. > > Instead of calling __put_task_struct() directly, we defer it using > call_rcu(). 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. > > Wander Lairson Costa (2): > kernel/fork: beware of __put_task_struct calling context > sched: avoid false lockdep splat in put_task_struct() Thanks!