From patchwork Tue Nov 22 01:04:21 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: 24090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1934457wrr; Mon, 21 Nov 2022 17:16:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf5bOaliXpMBahGzAfIOVSx4vtZCm7fpE2jm00VmNtWXvsmdhNj7W61PukkLMsi2CDvlYcI0 X-Received: by 2002:a62:7b57:0:b0:56b:dd28:4f6e with SMTP id w84-20020a627b57000000b0056bdd284f6emr5326466pfc.0.1669079778047; Mon, 21 Nov 2022 17:16:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669079778; cv=none; d=google.com; s=arc-20160816; b=EJ5zZ2VTEqDWeCCBK1sxqLVd2V+eLqxdrT4zjDigtox4apNjVfp0x3YDRRa9e2ZOv3 GAfDNKqndlxnk0aCKsPCapxBxonFlkcFxXYaYA4N7V96UyH9dldp1Auv2F1EREA0W6gG 9tbxIz3jKRUiwGKjFjg4gCo/x43mCQDds1UODsMJW4G+kdDPalQneyGtybGCykSTMwHv iOCf5yOphgyEHl2WkfbGFhCc/8M/qcLA7E3GhDUTEfwvmqydh0dQbtBx3YTfN9blQ93e j70TpRf2CCSNunD21QE7PXkw06lMqrzouLk46BEx2YYFLah0JakPL2hsIt57WNYR9mSg GLUg== 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=Lv/uLvZfOF0iRiluE4xXFTPcAzql9p11wASsMjjHz2Y=; b=OQYBSRKorUxIo21b/oc3GsszAIEKOqSHdoGNibm+O3nMsByNgMgu9RrKIo9MmbSqgV R82fa9/JJxmpI2363U/hBFZh/0JlwRSq7y6d/Rw7SIV47Hsmd2O0uHqzQIQlviHMmH4i wouiaa6MjAJXpN5AgKyjN/vcuA6QEibtNHpPPB3gHvmO6dT+9v7p79+FKpA99sqDO3FS LTskupt1qQ1HOVQxfPhr3iXFjvaljndBfWUq9hcG9Alpli834MVha+RhzzRMLl7A+B6e OeCnsRNEwSdKBF6rCw+dRhq60KIqe3gMOJowiuWKd49ab6A/XoXXvA7fra7SR9WEfaGj VlcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TTez867U; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ob6-20020a17090b390600b0021111f5231bsi3026821pjb.22.2022.11.21.17.16.03; Mon, 21 Nov 2022 17:16:18 -0800 (PST) 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=TTez867U; 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 S232191AbiKVBFO (ORCPT + 99 others); Mon, 21 Nov 2022 20:05:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231954AbiKVBE0 (ORCPT ); Mon, 21 Nov 2022 20:04:26 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C2C1DF40; Mon, 21 Nov 2022 17:04:25 -0800 (PST) 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 2A4D06151E; Tue, 22 Nov 2022 01:04:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75FB9C43166; Tue, 22 Nov 2022 01:04:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669079063; bh=yoNO14jnT7/3wJpWHWo0CYgw8+T0b3nI0VWmVo/0VZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TTez867UG51Rj10O9MBv8/3v+xkdrmwVzCDqX9ISWk5WFBZYKeDXeOODA9souyOXQ 53WH/uy/84JsK2tNKVG2Jvi0x8VhcDvWhBLP0mZQqp6x2bZJqPl3z4afQjFW7ETIX+ OpceptNxp1GZpjnzC6xWRWl5nqZDjSRBvAarT3P2OOH6PRYJOzrB6Cf9iXiQGD1ZKU zr7ICASGaotS6FZUO9zEcuJPFKFuknV5yCsy84GE3hS3YoH3Yjwn9N9Tqvdy3CCXYz O2lfCRltmaMbxQLYhotx/3UEQo1EP97pAcoNAmWX2AWBVjzrcYz67tww5M5f1CF82i m1p7zPsS+2dhA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 8EC005C1C98; Mon, 21 Nov 2022 17:04:22 -0800 (PST) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Eric Dumazet , Joel Fernandes , David Ahern , "David S. Miller" , Hideaki YOSHIFUJI , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, "Paul E . McKenney" Subject: [PATCH v2 rcu 16/16] net: devinet: Reduce refcount before grace period Date: Mon, 21 Nov 2022 17:04:21 -0800 Message-Id: <20221122010421.3799681-16-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20221122010408.GA3799268@paulmck-ThinkPad-P17-Gen-1> References: <20221122010408.GA3799268@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750156997136342786?= X-GMAIL-MSGID: =?utf-8?q?1750156997136342786?= From: Eric Dumazet Currently, the inetdev_destroy() function waits for an RCU grace period before decrementing the refcount and freeing memory. This causes a delay with a new RCU configuration that tries to save power, which results in the network interface disappearing later than expected. The resulting delay causes test failures on ChromeOS. Refactor the code such that the refcount is freed before the grace period and memory is freed after. With this a ChromeOS network test passes that does 'ip netns del' and polls for an interface disappearing, now passes. Reported-by: Joel Fernandes (Google) Signed-off-by: Eric Dumazet Signed-off-by: Joel Fernandes (Google) Cc: David Ahern Cc: "David S. Miller" Cc: Hideaki YOSHIFUJI Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Signed-off-by: Paul E. McKenney --- net/ipv4/devinet.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index e8b9a9202fecd..b0acf6e19aed3 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -234,13 +234,20 @@ static void inet_free_ifa(struct in_ifaddr *ifa) call_rcu(&ifa->rcu_head, inet_rcu_free_ifa); } +static void in_dev_free_rcu(struct rcu_head *head) +{ + struct in_device *idev = container_of(head, struct in_device, rcu_head); + + kfree(rcu_dereference_protected(idev->mc_hash, 1)); + kfree(idev); +} + void in_dev_finish_destroy(struct in_device *idev) { struct net_device *dev = idev->dev; WARN_ON(idev->ifa_list); WARN_ON(idev->mc_list); - kfree(rcu_dereference_protected(idev->mc_hash, 1)); #ifdef NET_REFCNT_DEBUG pr_debug("%s: %p=%s\n", __func__, idev, dev ? dev->name : "NIL"); #endif @@ -248,7 +255,7 @@ void in_dev_finish_destroy(struct in_device *idev) if (!idev->dead) pr_err("Freeing alive in_device %p\n", idev); else - kfree(idev); + call_rcu(&idev->rcu_head, in_dev_free_rcu); } EXPORT_SYMBOL(in_dev_finish_destroy); @@ -298,12 +305,6 @@ static struct in_device *inetdev_init(struct net_device *dev) goto out; } -static void in_dev_rcu_put(struct rcu_head *head) -{ - struct in_device *idev = container_of(head, struct in_device, rcu_head); - in_dev_put(idev); -} - static void inetdev_destroy(struct in_device *in_dev) { struct net_device *dev; @@ -328,7 +329,7 @@ static void inetdev_destroy(struct in_device *in_dev) neigh_parms_release(&arp_tbl, in_dev->arp_parms); arp_ifdown(dev); - call_rcu(&in_dev->rcu_head, in_dev_rcu_put); + in_dev_put(in_dev); } int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b)