Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp266548rwl; Thu, 30 Mar 2023 15:49:32 -0700 (PDT) X-Google-Smtp-Source: AKy350bN889O99YxeD4xUQXyhDOnu8lDpzVzmmYGbyBukwTIwDTYTwQJrgnUeLb/x2cKE/Nl0xr9 X-Received: by 2002:a17:906:224e:b0:92c:fc0:b229 with SMTP id 14-20020a170906224e00b0092c0fc0b229mr3949532ejr.0.1680216572516; Thu, 30 Mar 2023 15:49:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680216572; cv=none; d=google.com; s=arc-20160816; b=pfd96idfC5UItn+b6e9ZewXpjnOX1hcVEqAsn3FyU+Wxx9OwSXU17QV1TojbnNopIO 5bBj8k1JvzABNuHglvZ2yFeScUZcIvb92lksvCIOtqWlEq3QItAByMCY9HALjgxw4Cy+ Wla8CpRzGVewWFRiOhToTQ0gToh97DP4QCuBau36g7rJtJU2IOIUqdB7s1QV4iPK84WT AsX2ytD/GMys0sDTbPh/XKlHORvEWSeAv1d2ZOWQER0/XYoQIhcsLcpfGGjgqdFWgxZY SdO1e3AF3hp9JecTTa05oBJySNCOIeUoq97f2g3fQcHjGnyJTLqx0YKpzrKqkor3TU5O uvig== 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=8bQ9WxqF5s58FLD5Vv/wB/IbwrpwdIql74olkVQibiY=; b=r2kRRHacfW5QWRBMe2Tj+oWYajEy3tR7umsaeSNyCoupUxOawigQ/qN2JKPLs5k2Fo B5lmL04kUe4ySTEVmv5krjo5hjLxX36ZYlvc3sUto8rKrKbbecZm873dMfDcQRK0o7en HoHVJyOCqxZ2TT2rr7QSevxidWFSIaMRCJgeGhDAJoAnCB0QKts8gU/847H+wwNSDWFK nAPIJVrxmieE5rZoZnMkTo0f+CvxK3UJ8rLYGRk/X3UieZTTnsoh2Y+csJuKHohD7yo2 Rj5ywC/ZET6hdvWkFNOwr9Ew2x/elMZ7rQQyYgKHR1xMp/YP4vsrCK3794N1B2OOGbjH TyrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GKyEm7Gc; 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 j1-20020a170906094100b009476ce9b29dsi359131ejd.446.2023.03.30.15.49.07; Thu, 30 Mar 2023 15:49:32 -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=GKyEm7Gc; 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 S231375AbjC3Wsk (ORCPT + 99 others); Thu, 30 Mar 2023 18:48:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbjC3WsA (ORCPT ); Thu, 30 Mar 2023 18:48:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79F781116F; Thu, 30 Mar 2023 15:47:51 -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 E29D6621E0; Thu, 30 Mar 2023 22:47:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19758C433B4; Thu, 30 Mar 2023 22:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680216449; bh=UnyqkVnuslXzekz9+1Gncw3m0zj5nMMiSQbwc+YIH6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GKyEm7GcvRV/RG7Bioq1PMNWrDOMyvhK0n7tauJgoXIsVnAZ+oV4+tjrGIhQxcoSI hKM/Ani7w0WOHCiNaxeri9ChHGMUZ+3tuVBU97RkYgvs/SpO+KXuBMaUrGuK3isvCM KxxgJtIC9FPg40jG7M3dCFSpnfiDQQC6SarC52acH/SZkAkz9gHvDBibWn3WohLn47 DG6gRVYvVT51mDhLFjJ3dRfkXVqFH698lgSxyUeLdeKWr9TLDnO1P2CH/FWPtTzPvs 85QbyvOWl7zpK9ok9yNnnA/Q58ZviGk2u5cmzSLC8Q7ygKxvAgVCFv0hqv5ip3Nu4F 5QE9Zu976Kl1w== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 33FD8154048C; 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" Subject: [PATCH rcu 16/20] srcu: Check for readers at module-exit time Date: Thu, 30 Mar 2023 15:47:22 -0700 Message-Id: <20230330224726.662344-16-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=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,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 If a given statically allocated in-module srcu_struct structure was ever used for updates, srcu_module_going() will invoke cleanup_srcu_struct() at module-exit time. This will check for the error case of SRCU readers persisting past module-exit time. On the other hand, if this srcu_struct structure never went through a grace period, srcu_module_going() only invokes free_percpu(), which would result in strange failures if SRCU readers persisted past module-exit time. This commit therefore adds a srcu_readers_active() check to srcu_module_going(), splatting if readers have persisted and refraining from invoking free_percpu() in that case. Better to leak memory than to suffer silent memory corruption! [ paulmck: Apply Zhang, Qiang1 feedback on memory leak. ] Signed-off-by: Paul E. McKenney --- kernel/rcu/srcutree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 169a6513b739..f9dd6ed5503e 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -1911,7 +1911,8 @@ static void srcu_module_going(struct module *mod) if (!rcu_seq_state(smp_load_acquire(&ssp->srcu_sup->srcu_gp_seq_needed)) && !WARN_ON_ONCE(!ssp->srcu_sup->sda_is_static)) cleanup_srcu_struct(ssp); - free_percpu(ssp->sda); + if (!WARN_ON(srcu_readers_active(ssp))) + free_percpu(ssp->sda); } } -- 2.40.0.rc2