Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1452668rdb; Fri, 16 Feb 2024 17:28:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXismRFPexK48bEY4U5Vyu0GnGLbLBQWwECN2TpqJLFgl7AfzVnTptypTRFzwc9mrJ7aPazQeMD+nW2r450Mm4pmb2T3vtxJ8uAWFXF2g== X-Google-Smtp-Source: AGHT+IEL+IpLHxHoAZLeEFURp4/Vz1UbURykR+ndegF7ueDjC5zL9f5tpJ2+wjPMdWTRVemO5mmc X-Received: by 2002:a17:902:7ec2:b0:1da:192f:3eb2 with SMTP id p2-20020a1709027ec200b001da192f3eb2mr4952083plb.46.1708133332726; Fri, 16 Feb 2024 17:28:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708133332; cv=pass; d=google.com; s=arc-20160816; b=x8ed6fe6KHfwGcrXeWZ8kZRllON4W+rDKsxoLy4A5SyYk7e8frLqrGq0HkSJO530oU dkUE5Jc6xJvp8ateHmpW5a9bk/3QkM3z/SFH7Ojhdg7QLWm06LlZiLrctMhDYtJMQY3H Gol4UbSc8X6qybLkAlZ+g7nhXkgy9dXQ4VnTmCmSjlFQry2+PUntcEe9UNT7i5ynkdoy tEhgVqUonJvgbz/p6JudFvv4IILDtC1tlNE8gq30fwIqXoZMzlgQ6PWN15MOGMdYE4Ye g/gJfyZvpfLJgasmbao16UO9FA7qw34CTXf76+DJEQ4YzuKaceS0AAApGf3iL5yM4GHj pmlw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:feedback-id:dkim-signature; bh=hviMEBDsjs4mPn8ckWbDhMJvstiAXO/xVzEmAIrjOf0=; fh=NnPehC6FTgCewrlY7Hxnfdpmaj9TQEbqxjLp6tItBEw=; b=zIXp9LVLRHO6s9buKZI80TgN2oe8l3pXGaPaWBF+fqdfNPN+70wN+AU0KTnK/sgPbG yQM5vVAGz0hxe+W2EOTwIwU6tv03oOZjSQf2ncCmGvahrpp3yI5kd/WYCEiKqvS0scuC kCHoun3cC1ff0Nptu+Qaj5LiJ1KIXXxXtu4R8OWhGUeeP8sXpNyXVc85FO0dhSjmqdxl srLret0RFMSShK7gmZoIT9COAyq7ACvFoYVpBb+aBiWoCpZgUe4MMwVOQd6k2cgnvxY8 VPJlk+Eq4nCjrvPUi4WsLY03/flz1VlkS9wYlLdASupTJxmBJgRZef6HcRdunCNeftvZ qOXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Nq3WjxKR; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69644-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69644-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jv11-20020a170903058b00b001da17ce989dsi688825plb.278.2024.02.16.17.28.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:28:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69644-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Nq3WjxKR; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69644-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69644-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5AF6F2844F2 for ; Sat, 17 Feb 2024 01:28:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AB551CD15; Sat, 17 Feb 2024 01:28:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nq3WjxKR" Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FE0D1CA98; Sat, 17 Feb 2024 01:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708133288; cv=none; b=IdKVK64tK94YhYiA7HuibPttaLdipcbrbubGrERrQwsxgPkFTZSBd+Hg9WWmvwTxzko2kOzCdu4axaQVxIKN8DNF0sSDEW4XzNNOXDpDDFyAYEA9DPbu+HKAWCk11XkLrqEnfzrrySBIXaheT5HJF5/Z2Gn/wH7my3VOePSri8M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708133288; c=relaxed/simple; bh=guwEaF/rDbBs7UTfGuQDT1thFEEvaDXW74LeCy5xw24=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Th2l7A9GAGNKcisD+5G/3ztPHxXz4Fv38xwNxYDlbLpXk8Jp/jhka0HcBeJ9WVkFYD7Rg8Bb+Hqg9HL3+zv8dCznJbSBKzn8Epw9H9PfycLUAxjZ2dQeF8GzSjYaXOJFXsh75GjxH5tFF0oryQYuGe28Q0/UNETBQebJoQ564eQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Nq3WjxKR; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6869233d472so6436016d6.2; Fri, 16 Feb 2024 17:28:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708133285; x=1708738085; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=hviMEBDsjs4mPn8ckWbDhMJvstiAXO/xVzEmAIrjOf0=; b=Nq3WjxKR6mU7gcOf1RMVTeXpEGP2bL1Uguoao7B4FA1xQpubnhz8BepxH4+Up2OM9D 1UCLLVz4JVgSV2mhR7xKJDN5T2ViXDJ6nZrY2FfZ+0QEu57ILCqnZma27ME7VdqsqIUg VGg5FrxqSrdlZO+tOKZN0KRpIxuYZaw59lXnASvxhCZZKs8xQiXU6EpaiTwYxud4VXJy nOurVsaIE0n0u7vixkYW9dLtbdJcHQzMT5kG4nTknqKgZMz8gtl8UxKIC08GgTmw0xIb KbwRBDD74S7AcLmrxver2KZoIEt51ma28cshOr6OmSdBzLWQEtmkJy1LXlPD4KMe5RGn Ij8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708133285; x=1708738085; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=hviMEBDsjs4mPn8ckWbDhMJvstiAXO/xVzEmAIrjOf0=; b=YY6ZpRPZa9LIvMVO/jEONU6yrO/cHx9mjHfkzjuyFq7wYddT//LqoKyy0LCiLeY3KI O5B/Oxtw1zw/pYWfri3bOtjEP4YaUn4LZ4Ez7YrQIxJlSyx2xJ148q9U5Dm+ZwT0SYs7 iwUsLton7/SXG4XJdFnDxg8k3Q2s02j8/43M7/EsHV2MQfOd2JLgKd6YngQ5CzIwTpr4 dziUliFnWZyJSqm//zlT3I2WK4Zop1ytPVrCCAHRcAXL1+wZ4ygIF9p/m3xWcpK4yQAz xOxhEKADcAOX1/D7TvjWkzGCUWl2JGMfP/KdktePN7EDfBTJLB0daJEb7WIoSAIH0JUT OAUw== X-Forwarded-Encrypted: i=1; AJvYcCWIdoIzal5a7NVUe0LzlxWuvNPnggD7e/N8lyuwJK8KcakVJRBpq6MX7I87kOKhYxN1LG9Wf2GQQ/bstiUwmr02fhDw X-Gm-Message-State: AOJu0Yx5o8IyLiD0eI5DELcgFUCMxmCC2Lpew91TmBR0ZberCfUbLaTT UDVPpbJLciw1J0KrW3NbPkUtwsFTSwtALJ2T4Z7EEs6X25YVywh2 X-Received: by 2002:a0c:ab17:0:b0:68f:ff3:299c with SMTP id h23-20020a0cab17000000b0068f0ff3299cmr6889855qvb.26.1708133285236; Fri, 16 Feb 2024 17:28:05 -0800 (PST) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id lg21-20020a056214549500b0068f1bc6c57asm481938qvb.69.2024.02.16.17.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:28:04 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id 6EDA31200043; Fri, 16 Feb 2024 20:28:04 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 16 Feb 2024 20:28:04 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefgdefgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhepgffhffevhffhvdfgjefgkedvlefgkeegveeuheelhfeivdegffejgfetuefg heeinecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhp vghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrd hfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Feb 2024 20:28:03 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org, rcu@vger.kernel.org Cc: Neeraj Upadhyay , "Paul E. McKenney" , Chen Zhongjin , Yang Jihong , Boqun Feng , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang Subject: [PATCH v2 4/6] rcu-tasks: Maintain lists to eliminate RCU-tasks/do_exit() deadlocks Date: Fri, 16 Feb 2024 17:27:39 -0800 Message-ID: <20240217012745.3446231-5-boqun.feng@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240217012745.3446231-1-boqun.feng@gmail.com> References: <20240217012745.3446231-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Paul E. McKenney" This commit continues the elimination of deadlocks involving do_exit() and RCU tasks by causing exit_tasks_rcu_start() to add the current task to a per-CPU list and causing exit_tasks_rcu_stop() to remove the current task from whatever list it is on. These lists will be used to track tasks that are exiting, while still accounting for any RCU-tasks quiescent states that these tasks pass though. [ paulmck: Apply Frederic Weisbecker feedback. ] Link: https://lore.kernel.org/all/20240118021842.290665-1-chenzhongjin@huawei.com/ Reported-by: Chen Zhongjin Reported-by: Yang Jihong Signed-off-by: Paul E. McKenney Tested-by: Yang Jihong Tested-by: Chen Zhongjin Signed-off-by: Boqun Feng --- kernel/rcu/tasks.h | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h index 4a5d562e3189..68a8adf7de8e 100644 --- a/kernel/rcu/tasks.h +++ b/kernel/rcu/tasks.h @@ -1151,25 +1151,48 @@ struct task_struct *get_rcu_tasks_gp_kthread(void) EXPORT_SYMBOL_GPL(get_rcu_tasks_gp_kthread); /* - * Contribute to protect against tasklist scan blind spot while the - * task is exiting and may be removed from the tasklist. See - * corresponding synchronize_srcu() for further details. + * Protect against tasklist scan blind spot while the task is exiting and + * may be removed from the tasklist. Do this by adding the task to yet + * another list. + * + * Note that the task will remove itself from this list, so there is no + * need for get_task_struct(), except in the case where rcu_tasks_pertask() + * adds it to the holdout list, in which case rcu_tasks_pertask() supplies + * the needed get_task_struct(). */ -void exit_tasks_rcu_start(void) __acquires(&tasks_rcu_exit_srcu) +void exit_tasks_rcu_start(void) { - current->rcu_tasks_idx = __srcu_read_lock(&tasks_rcu_exit_srcu); + unsigned long flags; + struct rcu_tasks_percpu *rtpcp; + struct task_struct *t = current; + + WARN_ON_ONCE(!list_empty(&t->rcu_tasks_exit_list)); + preempt_disable(); + rtpcp = this_cpu_ptr(rcu_tasks.rtpcpu); + t->rcu_tasks_exit_cpu = smp_processor_id(); + raw_spin_lock_irqsave_rcu_node(rtpcp, flags); + if (!rtpcp->rtp_exit_list.next) + INIT_LIST_HEAD(&rtpcp->rtp_exit_list); + list_add(&t->rcu_tasks_exit_list, &rtpcp->rtp_exit_list); + raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags); + preempt_enable(); } /* - * Contribute to protect against tasklist scan blind spot while the - * task is exiting and may be removed from the tasklist. See - * corresponding synchronize_srcu() for further details. + * Remove the task from the "yet another list" because do_exit() is now + * non-preemptible, allowing synchronize_rcu() to wait beyond this point. */ -void exit_tasks_rcu_stop(void) __releases(&tasks_rcu_exit_srcu) +void exit_tasks_rcu_stop(void) { + unsigned long flags; + struct rcu_tasks_percpu *rtpcp; struct task_struct *t = current; - __srcu_read_unlock(&tasks_rcu_exit_srcu, t->rcu_tasks_idx); + WARN_ON_ONCE(list_empty(&t->rcu_tasks_exit_list)); + rtpcp = per_cpu_ptr(rcu_tasks.rtpcpu, t->rcu_tasks_exit_cpu); + raw_spin_lock_irqsave_rcu_node(rtpcp, flags); + list_del_init(&t->rcu_tasks_exit_list); + raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags); } /* -- 2.43.0