From patchwork Wed Oct 19 22:46:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13012443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 805E6C43217 for ; Wed, 19 Oct 2022 22:47:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 04F0F6B0071; Wed, 19 Oct 2022 18:47:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F404E6B0073; Wed, 19 Oct 2022 18:47:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E084C6B0074; Wed, 19 Oct 2022 18:47:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D17D96B0071 for ; Wed, 19 Oct 2022 18:47:06 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9AA0216087D for ; Wed, 19 Oct 2022 22:47:06 +0000 (UTC) X-FDA: 80039186052.15.26E53C5 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf23.hostedemail.com (Postfix) with ESMTP id ED79A140010 for ; Wed, 19 Oct 2022 22:47:04 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E55A6B8261E; Wed, 19 Oct 2022 22:47:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0562DC4347C; Wed, 19 Oct 2022 22:47:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666219621; bh=U+1luf3mbgyTSKOMl8vtX4dFmH8rl+GKNY2TDjN1IyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XMSKFGEu/uzR3N52gimUSRvlUY77ksX6bwSP5MEEbrhoYubbKoJVO455NMN69R4xj x9GRwiRrinWyIWvqcLaI+JhV5ZHw0Ow+vjol3spPlLV+EDFsRspfhySJYB1hNYEyDD aSGLKC8qpWBT4nbxwHNQOo7RmG1Z0Y+5PDZjmaBTcnkG3j3YRGb2Ycr+/iXr0GVAM8 f3R8P+eO4JCLRSgp7mHQtfS9keccHmF/hGloP0UzUPKujvCNZbkgV3dyp0o5SzcWdJ GLdFjAAokYxUviKsgseded/9rmE6dJI2yUYwAvyjELLvaU6fXnXMYEQiD9ItgNieST uSvkQeYinB1kw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id AD5D05C0A04; Wed, 19 Oct 2022 15:47:00 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, rostedt@goodmis.org, "Paul E. McKenney" , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org Subject: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking Date: Wed, 19 Oct 2022 15:46:56 -0700 Message-Id: <20221019224659.2499511-5-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20221019224652.GA2499358@paulmck-ThinkPad-P17-Gen-1> References: <20221019224652.GA2499358@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666219625; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vaBNEjQiN5imowm/0xL8cBoXu3aflqCt38ox8eogPH0=; b=WgmC2gBiNVuCeBjbfUQldCbHIMA9yovGgSPhaBjs6JSTY5h+jpTPyoSiZHslmEAFBasek8 WnhJU3QAFc7mPwvsrr97kWgIqCt9Jx/DTMoZZtSlnXZS8KYgE92B7SIVq79mKDjlZALo/E /CsB8A64/poBzqXbqZIHrPEhdo7CXSs= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XMSKFGEu; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of "SRS0=xkCN=2U=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 145.40.68.75 as permitted sender) smtp.mailfrom="SRS0=xkCN=2U=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666219625; a=rsa-sha256; cv=none; b=HYPTqBUb9LYOIiZDMnA5uumNTCQnZsGNWS6wplRC82CPDcHOpg5+WyYU7Fc60oC/Ce9QR+ 1XI81WVVxbtOlQt/syLkT4waMpRrHlpSMLCcUKJ6WAiG5B+6eTADwzZwpc3Jyr9SA/A4F/ 2e0AxWUb+gCVSDoax66XjQ4DDElIr1o= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XMSKFGEu; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of "SRS0=xkCN=2U=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 145.40.68.75 as permitted sender) smtp.mailfrom="SRS0=xkCN=2U=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: ED79A140010 X-Rspam-User: X-Stat-Signature: souyj1f3gb8fuzesjchk54zeo3ue9ioh X-HE-Tag: 1666219624-281142 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: It is not obvious to the casual user why it is absolutely necessary to acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring a lock in that structure. Therefore, add a comment explaining this point. Signed-off-by: Paul E. McKenney Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Andrew Morton Cc: Vlastimil Babka Cc: Roman Gushchin Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Acked-by: Vlastimil Babka --- include/linux/slab.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/slab.h b/include/linux/slab.h index 90877fcde70bd..446303e385265 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -76,6 +76,12 @@ * rcu_read_lock before reading the address, then rcu_read_unlock after * taking the spinlock within the structure expected at that address. * + * Note that it is not possible to acquire a lock within a structure + * allocated with SLAB_DESTROY_BY_RCU without first acquiring a reference + * as described above. The reason is that SLAB_DESTROY_BY_RCU pages are + * not zeroed before being given to the slab, which means that any locks + * must be initialized after each and every kmem_struct_alloc(). + * * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU. */ /* Defer freeing slabs to RCU */