Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp266009rwl; Thu, 30 Mar 2023 15:48:45 -0700 (PDT) X-Google-Smtp-Source: AKy350Y8Nt0cWc2kZT8YRRbfEAHcnQOtFyIGdgzc/2R5KD3+SIbPxYkj10tPH1tF7fZZ3bUR72s/ X-Received: by 2002:a17:906:1c4:b0:931:5145:c51f with SMTP id 4-20020a17090601c400b009315145c51fmr20880092ejj.4.1680216525404; Thu, 30 Mar 2023 15:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680216525; cv=none; d=google.com; s=arc-20160816; b=MHcPnuVzgI3kUCtdinhWw3RwC1efXT4G/hkf433EtW5R9Fjjj0SFOaF+fL8Ngcd9Fu yZvPMML1RX2WL+BdVRREk1qmKVeg91SkPd7Rx5AtWMFr/tbwOCucPBnL+v9TNftV3BC8 HHvOnARJhbFRo/9pm/dsSsIv+WTTue1NxhCCVZE3dLEda09aCoZkonp7Ty1Ti/tl7auv yiut+b9ct4/pPI1iV2L8Glm2j5YWfiM0Ne7LOa7VKl3+XS+QDMkmZUAARTUdr0f5HKGu UmGkXIM9QNEl3HDhgHymN82XFOOVS2uaHPUsXymHbfIJQovDKpvNGDoBrbxMmebYJA0K 1gJQ== 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=WIhNmGSgYMRvXjM2mFyH0PmpLn/VOx8ZjzPznK29rRA=; b=d4aomN43X6ss1eh2apyOwNG+kj4UTgS7Di4APanKQiQjoWs8bYVSCULQXIBwlTkgfE smpC8/vTxTldWZazBSAELKQLhGF7nGfWZ5dc86b7BSbl4AlfPGw4Mzji/XqnhMSaMUCg 7UCYftAjPDdJpQdTj88CrEI16S5AKmCP86ZOrs7Kst4FziHQ3Vih7/KnUELmOX+OJ8NM +9oTedELOvm/PZZZ1lmaClVb326Y5e8BbpzUXVBLA5RZ9pm8kTrXKfdwMnI9bFAdIyAm qD5tVgOK+20gwOpWS/JNrIhMNaKWuwgDjDw0AhSVVJHf0QSNL/AhNswwdvymd3cqb/4l 5Mng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BYu6zzK4; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ot7-20020a170906ccc700b00923c54e9ad0si547457ejb.585.2023.03.30.15.48.20; Thu, 30 Mar 2023 15:48:45 -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=@kernel.org header.s=k20201202 header.b=BYu6zzK4; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbjC3WsE (ORCPT + 99 others); Thu, 30 Mar 2023 18:48:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbjC3Wrv (ORCPT ); Thu, 30 Mar 2023 18:47:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BC041204E; Thu, 30 Mar 2023 15:47:31 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 0B8DF621D5; Thu, 30 Mar 2023 22:47:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67DF5C4339B; Thu, 30 Mar 2023 22:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680216448; bh=GXD9GdY8v3RIh7U3GnYda6kTJ4k3Fbay0wPf8sbul44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BYu6zzK4uYWEr++FJTeAbZu8VihfPXtIwVPZT5hBLXmEM9za5DTsHAHQhiNbBmMj9 L3fbdQ9jOu0yHiKVv+41VBbUKiLvsQludNOsrA//E98fsUrVXp2RIMbiQ6FLRI+ZaH EztDJm+zyYozrYWwqA/rP2YHK9JlofEbIwLrAKxOF+mL45+UZCT4qoZv6ba3FeI1QO JEfnI65bUm5/dxd+JVgnp5MlVJUB3gMC/eUo8L2F1RJ+oCZDOE0QQlu/tQ4bJGGv1d 4qR8SFwFXUeSZx+47sZQilv0AOfKWMTCZZQwD9xU/Fi0LhBwlJn64JAolAFiOOXUDr fjMGKWq3BTvAA== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 0455D154047F; Thu, 30 Mar 2023 15:47:28 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, hch@lst.de, "Paul E. McKenney" , Sachin Sant , "Zhang, Qiang1" Subject: [PATCH rcu 03/20] srcu: Use static init for statically allocated in-module srcu_struct Date: Thu, 30 Mar 2023 15:47:09 -0700 Message-Id: <20230330224726.662344-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.0.rc2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 Further shrinking the srcu_struct structure is eased by requiring that in-module srcu_struct structures rely more heavily on static initialization. In particular, this preserves the property that a module-load-time srcu_struct initialization can fail only due to memory-allocation failure of the per-CPU srcu_data structures. It might also slightly improve robustness by keeping the number of memory allocations that must succeed down percpu_alloc() call. This is in preparation for splitting an srcu_usage structure out of the srcu_struct structure. [ paulmck: Fold in qiang1.zhang@intel.com feedback. ] Cc: Christoph Hellwig Tested-by: Sachin Sant Tested-by: "Zhang, Qiang1" Signed-off-by: Paul E. McKenney --- include/linux/srcutree.h | 19 ++++++++++++++----- kernel/rcu/srcutree.c | 19 +++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index 488d0e5d1ba3..3ce6deee1dbe 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -108,15 +108,24 @@ struct srcu_struct { #define SRCU_STATE_SCAN1 1 #define SRCU_STATE_SCAN2 2 -#define __SRCU_STRUCT_INIT(name, pcpu_name) \ -{ \ - .sda = &pcpu_name, \ +#define __SRCU_STRUCT_INIT_COMMON(name) \ .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ .srcu_gp_seq_needed = -1UL, \ .work = __DELAYED_WORK_INITIALIZER(name.work, NULL, 0), \ - __SRCU_DEP_MAP_INIT(name) \ + __SRCU_DEP_MAP_INIT(name) + +#define __SRCU_STRUCT_INIT_MODULE(name) \ +{ \ + __SRCU_STRUCT_INIT_COMMON(name) \ } +#define __SRCU_STRUCT_INIT(name, pcpu_name) \ +{ \ + .sda = &pcpu_name, \ + __SRCU_STRUCT_INIT_COMMON(name) \ +} + + /* * Define and initialize a srcu struct at build time. * Do -not- call init_srcu_struct() nor cleanup_srcu_struct() on it. @@ -138,7 +147,7 @@ struct srcu_struct { */ #ifdef MODULE # define __DEFINE_SRCU(name, is_static) \ - is_static struct srcu_struct name; \ + is_static struct srcu_struct name = __SRCU_STRUCT_INIT_MODULE(name); \ extern struct srcu_struct * const __srcu_struct_##name; \ struct srcu_struct * const __srcu_struct_##name \ __section("___srcu_struct_ptrs") = &name diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index ab4ee58af84b..7e6e7dfb1a87 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -1873,13 +1873,14 @@ void __init srcu_init(void) static int srcu_module_coming(struct module *mod) { int i; + struct srcu_struct *ssp; struct srcu_struct **sspp = mod->srcu_struct_ptrs; - int ret; for (i = 0; i < mod->num_srcu_structs; i++) { - ret = init_srcu_struct(*(sspp++)); - if (WARN_ON_ONCE(ret)) - return ret; + ssp = *(sspp++); + ssp->sda = alloc_percpu(struct srcu_data); + if (WARN_ON_ONCE(!ssp->sda)) + return -ENOMEM; } return 0; } @@ -1888,10 +1889,16 @@ static int srcu_module_coming(struct module *mod) static void srcu_module_going(struct module *mod) { int i; + struct srcu_struct *ssp; struct srcu_struct **sspp = mod->srcu_struct_ptrs; - for (i = 0; i < mod->num_srcu_structs; i++) - cleanup_srcu_struct(*(sspp++)); + for (i = 0; i < mod->num_srcu_structs; i++) { + ssp = *(sspp++); + if (!rcu_seq_state(smp_load_acquire(&ssp->srcu_gp_seq_needed)) && + !WARN_ON_ONCE(!ssp->sda_is_static)) + cleanup_srcu_struct(ssp); + free_percpu(ssp->sda); + } } /* Handle one module, either coming or going. */ -- 2.40.0.rc2