From patchwork Mon Apr 8 19:04:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13621522 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 1ED241420D8 for ; Mon, 8 Apr 2024 19:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712603083; cv=none; b=Xd0KUQGOYcnlqvEn3aOAl2FrEDvBBR7JCeA6Kx2FCQNM2H3MpdnU8XHh/ddMlHi2dtX/rpXarXEsB3mAYlK0I2HVV4sprujlvkmyTjFrQo/qwbSfBIVYOCmu5jVp0yiRMkLUSNCCjAKRRYVVhFLVV4b7WRzKfYO8eQpEnl1aefY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712603083; c=relaxed/simple; bh=bUJeVELf/0h7eqzXkRcJF5AAYU2ToZalQ8Ai+iW8LJw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Qi5gbV4QcJIeAuz/jbZq+xPZ/N0BAvNPDe7/L72GibtfCPd1r+5VM6eq2idkn1mI1E0OGbTwGe3vJBN7iXeA+CHydntfmIZXeQ0FBjuLHYSfDGVvwTaGC+yTq9FD1JOurU7qZB82bAco/EURWjEsBF2Jg/tabwjJLdVJbDujfGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4ugaytZo; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4ugaytZo" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61510f72bb3so81721077b3.0 for ; Mon, 08 Apr 2024 12:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712603081; x=1713207881; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SCOobaFxiB8VywykUvfRGdsWgiL4TXNUBVDqreGXQy0=; b=4ugaytZo3Nhfar8d8IdqjJEho4oMgii5fuwVlS9b6Q3yH64EilRS19NRdFfAOS+n2b 28y5thFP2O/+tnl7C7GuAUDHSEZtr+m+xbJAxql81hy6GxPTLJfOXkWqL2JcVRPeyeRN l4ju6zvj8imxunAlFGBcpmo//xAnRE/z5FGx1l2cOASAB4OaGGtHE+XwbFaO7CKWsjK6 Tr3OUh7917Sx9ANyRM4K50UfptQh79+Gi0QOPTnCgAn21f2rs2t4h0HYgQooqoDVcbIP jrvGftEZp7JxEsIYEWyAiXmFMIGUV5mTgQg9GY6YcIVt4oOxIkqKf4uFnbqDsztuNJkY YI4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712603081; x=1713207881; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SCOobaFxiB8VywykUvfRGdsWgiL4TXNUBVDqreGXQy0=; b=lL1fcpTn6MtIVyR5XfHBW0qBrY90G8oQfofpwS5L1X3VXzUrySlRjmPeqaWBWcW6kr yWPOYfmnfB6bLlImKDXGD6M4auDOUlxvajKsWzIDit429aMxgjJNtrtkgFGjBvCZ/zsE b28MYjrwRnjidx9+ZjEfGn1QlpZ3sqOzdnl/RjWhzLt8vnyHVjHUWKFqNPjjL/tSrL9n Pn5Z7SgYsRyJAvDrr+c2jNGu/zv1QftseT6G6gVMYdRo9S2uOlVLIPbejm28w6O7DpdY 2kZ6+PPShoMFQh/rFJSYwGz0bfK+rmIrQyyo1c+iMpU+rsYpMoGJlMvKHPtfmukd3LB0 IpNA== X-Forwarded-Encrypted: i=1; AJvYcCUjYQ1Pmb4MhQwBzQmCDa6Q4BGSkiKy8kxJwABZOIMShy0hsX3VUSoHGLHkG92St4X83eUNhGTVsc7qhQ6nGIDXrWQqcLZR X-Gm-Message-State: AOJu0YyIs0dQ8mGEGBeHzv7neGBJ7qEjF2LuQ59GNl6BE5MTReSjJ7hG uGugM0jY0OKoL2rNVb5xV5gSREmej/OHOeRe6jlJ8JCDmtkeuowXAGzKcVyCIyq3s4MtoFcJBTH c7xLSphHPgw== X-Google-Smtp-Source: AGHT+IE7sqnv0RPb9psfPSVRWnf26rpSGKrAF00DmsN+zsJDLfOoZnIxCtr0Iptx99yQQHcHYLkQoLdShfppQQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:7156:0:b0:617:f232:85c with SMTP id m83-20020a817156000000b00617f232085cmr1682420ywc.6.1712603081055; Mon, 08 Apr 2024 12:04:41 -0700 (PDT) Date: Mon, 8 Apr 2024 19:04:35 +0000 In-Reply-To: <20240408190437.2214473-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240408190437.2214473-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408190437.2214473-2-edumazet@google.com> Subject: [PATCH net-next 1/3] bonding: no longer use RTNL in bonding_show_bonds() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jay Vosburgh , Andy Gospodarek , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org netdev structures are already RCU protected. Change bond_init() and bond_uninit() to use RCU enabled list_add_tail_rcu() and list_del_rcu(). Then bonding_show_bonds() can use rcu_read_lock() while iterating through bn->dev_list. Signed-off-by: Eric Dumazet Acked-by: Jay Vosburgh --- drivers/net/bonding/bond_main.c | 4 ++-- drivers/net/bonding/bond_sysfs.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index c9f0415f780ab0a9ecb26424795695eff951421a..08e9bdbf450afdc103931249259c58a08665dc02 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -5933,7 +5933,7 @@ static void bond_uninit(struct net_device *bond_dev) bond_set_slave_arr(bond, NULL, NULL); - list_del(&bond->bond_list); + list_del_rcu(&bond->bond_list); bond_debug_unregister(bond); } @@ -6347,7 +6347,7 @@ static int bond_init(struct net_device *bond_dev) spin_lock_init(&bond->stats_lock); netdev_lockdep_set_classes(bond_dev); - list_add_tail(&bond->bond_list, &bn->dev_list); + list_add_tail_rcu(&bond->bond_list, &bn->dev_list); bond_prepare_sysfs_group(bond); diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 2805135a7205ba444ccaf412df33f621f55a729a..9132033f85fb0e33093e97c55f885a997c95cb4a 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -37,12 +37,12 @@ static ssize_t bonding_show_bonds(const struct class *cls, { const struct bond_net *bn = container_of_const(attr, struct bond_net, class_attr_bonding_masters); - int res = 0; struct bonding *bond; + int res = 0; - rtnl_lock(); + rcu_read_lock(); - list_for_each_entry(bond, &bn->dev_list, bond_list) { + list_for_each_entry_rcu(bond, &bn->dev_list, bond_list) { if (res > (PAGE_SIZE - IFNAMSIZ)) { /* not enough space for another interface name */ if ((PAGE_SIZE - res) > 10) @@ -55,7 +55,7 @@ static ssize_t bonding_show_bonds(const struct class *cls, if (res) buf[res-1] = '\n'; /* eat the leftover space */ - rtnl_unlock(); + rcu_read_unlock(); return res; } From patchwork Mon Apr 8 19:04:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13621523 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 7C94113F006 for ; Mon, 8 Apr 2024 19:04:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712603085; cv=none; b=en3C6slFCIt1vBG5JDEYT25zJCwqB8bSKr16PZcarGtFuhwyRitjauVysySH5D9oNCJiqbHE/rb/qglgrVSlpP8WacMqFPabo/5KAfq8R/y6oM7yhB4Etsezvzp1L9/+ivcc7t5txFsbttdPiZqOT0d3hEjN9g4bI8vs7QL9utI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712603085; c=relaxed/simple; bh=4G+TiPVu/ybLaQ4K2c4JOUc4TMKiA9ya6HYe/TgwC8w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fN5Elw0m+4wfKZKm9/NXlTEaPomTeV52oICm5hhy9GPpLKIegVF2yYG1JfkMv61ybMlfUuCPiWcuewVhE1fsHksAsPHQiAdWKD07LXritPPXKFdmVNXPd+iMEAQicGj48fqvyQKCBbHxQwZuo6HzMrq2K1JEack10NRle+fu8HE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=g6Hf2AW9; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="g6Hf2AW9" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60a20c33f06so56274607b3.2 for ; Mon, 08 Apr 2024 12:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712603082; x=1713207882; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oOXhkQgI/agt07trD6VJWCcnX+2mbEQKTSXSaTtmwmo=; b=g6Hf2AW9uITmhpzRtiNMe7/ELCHD2dZh6N7Fim23VYRidG+rU8yt1pP+qbvMy0nTaP 8QqwjLHcrgZXmp+PERjRPU5QATjPttViFY+SpKCjHTRCkLJX9BtP3BfsNI21oQ3ZkOQp JUqz+VNbYZMYpw/dqoZdnv3WWaRGK9QQQsLlxp9UzBKAiFkpe77BTsYN6ueN0Yt1iY6F TrTC1rsG//cVTF6qvsoCd5prIv29uFVb0HqwPsILi7ngZwfI76PEzCQmXYDtOMLJ6taT UiozUd7BNfuxaWCAkHY+68mTZLeKxApBNvRRebo4Y1cBj87w6mxHvX9lm6x+adb4RNEl eL4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712603082; x=1713207882; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oOXhkQgI/agt07trD6VJWCcnX+2mbEQKTSXSaTtmwmo=; b=iIbXDy7mXfSMtQGOb5YuQ0osmapKOwDUNoGaNeGEl0aAv0C3z8wiHJ/vQK2c87Ugnu CdmckgeMdrfpAtNd/EncWjnwODDSZDl5uYzamUVaSHfzmfF+2p2jYk40dRTLO6HlwFgr caGrQQ9hkY0qPJ5CGSWj/0B5QgQFmfFn57EkZnoChZBlXwb7kJut2UaNs8XA6WXBdF5l M9gfkbBAs42tfORsbaoWyp9mUxAoY4FGX0AdpcuTPKuAB/oBDwVtJiWBTJdxD0qHaYBg oU45Wmxoj4ql9XMVq7XZzHkKDCKshbToDd5cawUzilOdFJ2NCLmFYCJVxX6mQkin74eM Dqtw== X-Forwarded-Encrypted: i=1; AJvYcCWwP8SQWq7vBsCZeb/vEej+jx9kd6NIq5ZXp2wS5xV+L8+/oXXu/dQMiSAOvtKgx0g59Z2rxizS3grK6/Nkto5L/1XhJVzc X-Gm-Message-State: AOJu0Yx0invpxeDFhytZIVDqtgW5KaoPJvV1naqmakjAbABaPeKKamMO usqZVuXWRzDGnVtCYb8idC9hlndVak0hWUQ4TplodjBOKknhKQLvmrZkzkyibgsic7ANEYVuzct aOPinXyDfIA== X-Google-Smtp-Source: AGHT+IHU/uJORMNSDsci40QqYa6FwOiCZiXNrRu4fIBkw1Z6GVKh/2BmQHXM0rrx5WnZF1fRr6o7VK4hpoiNgw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:d7c3:0:b0:615:768:ceb2 with SMTP id z186-20020a0dd7c3000000b006150768ceb2mr2285545ywd.9.1712603082527; Mon, 08 Apr 2024 12:04:42 -0700 (PDT) Date: Mon, 8 Apr 2024 19:04:36 +0000 In-Reply-To: <20240408190437.2214473-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240408190437.2214473-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408190437.2214473-3-edumazet@google.com> Subject: [PATCH net-next 2/3] bonding: no longer use RTNL in bonding_show_slaves() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jay Vosburgh , Andy Gospodarek , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Slave devices are already RCU protected, simply switch to bond_for_each_slave_rcu(), Signed-off-by: Eric Dumazet Acked-by: Jay Vosburgh --- drivers/net/bonding/bond_sysfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 9132033f85fb0e33093e97c55f885a997c95cb4a..75ee7ca369034ef6fa58fc9399b566dd7044fedc 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -170,10 +170,9 @@ static ssize_t bonding_show_slaves(struct device *d, struct slave *slave; int res = 0; - if (!rtnl_trylock()) - return restart_syscall(); + rcu_read_lock(); - bond_for_each_slave(bond, slave, iter) { + bond_for_each_slave_rcu(bond, slave, iter) { if (res > (PAGE_SIZE - IFNAMSIZ)) { /* not enough space for another interface name */ if ((PAGE_SIZE - res) > 10) @@ -184,7 +183,7 @@ static ssize_t bonding_show_slaves(struct device *d, res += sysfs_emit_at(buf, res, "%s ", slave->dev->name); } - rtnl_unlock(); + rcu_read_unlock(); if (res) buf[res-1] = '\n'; /* eat the leftover space */ From patchwork Mon Apr 8 19:04:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13621524 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 3F6AC14535A for ; Mon, 8 Apr 2024 19:04:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712603086; cv=none; b=jL8kP2pBdiOEeQK4SvkAd/tt16b+iJ97WSEgDeGaDQW1H/+iQlwlFsjN4T3f3XgEKXiN4Jq/yLGlv7jw+6vCk8NCFInD5G/GAv5SBAu+rwCOuTxEblVZg8c7OSNjP27+Ewu7/cqH3Eloe4plr/jN2uxz/1eZKtsYU9k4/jNjUJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712603086; c=relaxed/simple; bh=qbOui7asl3gajjDWUWGn/0raYrWjYh8fvjtr7oXZ3v4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B4lVjGSO/TYPwCN0CV610hCLoHYZVKMHu8hLAohMLX1i7p/vb5AgV/m1Jc9I0TywC0eIAZht8KGpiWZnuT4Udjs8k8nE0sVf9UxreYDs2mgtkQvNCA48HCss0sCV3eRmch2NcqpHtGxYRwqvkIEiNlEAU+mF2WwTq253HW6fICE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RzlRs4Ca; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RzlRs4Ca" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6150e36ca0dso70259077b3.1 for ; Mon, 08 Apr 2024 12:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712603084; x=1713207884; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9YFwpua1V9N06H0cwOIhR311m3BvdWhu1fWCYs6M3do=; b=RzlRs4CaA/OAHHCCKwP0IxB2nRgqj/KHqkESkiYaMM7uDXV9m4SfpFOc9iMDPxcXRo mx2a8XqGnjDxi/dM/JqvWml0nzlTLelRjAuxZoR5E9IvckQkqBT8ruJf63LH0gxKRYc4 un/PPEEj60+h3+IoX1Uqm31Ym9BAQ+8iGbvkuxu4tXhmLMEJE0QSUcz8gMDkV2T+7Fgw W+ctJ6GYalKmwA80umnQ91T3i1afAATQ1M2QMRmLgWa3DMjU4EBCweAcEDaD8rgy21JA 0AkkwX2Rxq/ZWk1mVNYvLXsTzQgKlrIoecsLuevj+szzxR/FmbYixi+jZAedlUzJbWMT 0OPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712603084; x=1713207884; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9YFwpua1V9N06H0cwOIhR311m3BvdWhu1fWCYs6M3do=; b=IJFaaXu3IcjVd2Acjx0s2VNskRmgOqwLhYphvNXGIqzc/Kf5yWMm+pDgQVyFlHkF5r 5aUS93maTOLfGflE6KjDXYw92L5PeVI6XM6v2iMIsSCkoQ8ETYNi6v3Mmd6ng8SNdDHU ES+EnnqtSpAGQA0dAYbuyzwUQTPyTsr2muE348Lq0fVf/mG1IP2rRL0SSyUuFEaSBiUP UF3KIRR9XcdYFVPQ0oZzm0u3tcn0R+3wkZ3xhsPKursHUW1a+vhQSzh73R/A++ccEmgi +FemAvZDYflCtcS5dC84iJ4ixdPtEigB1eOQVrNNnLrGgh46u4LoYgypoDQe82WZJGF7 B3cw== X-Forwarded-Encrypted: i=1; AJvYcCUs4Q7Jst8h48CNBEgp680MiZke6NXdRrF5aBnVpW/LTTTifkF3TqOTJCkPw8Zc6Pa/V204IGEdBbVjApwSSG1bWBNm/dT4 X-Gm-Message-State: AOJu0Yx/o7vB3eYiGCevQ+4ynQLdRImRmUnp5jVIWho6RAhdUMWnTkfP 9Eg5HJoskluWKw2q4PvMRkgNetxfsU7TaYUj/KQbDpRlWyu2Rq8VUgwIOC8ehKhW0v5sRMEC+Wu cdy9AhWjOpQ== X-Google-Smtp-Source: AGHT+IFOajzXu4ciC9lRgMO2q3G1iQc3DZBnLs5jw5/F0RryqTfOBy8e0mNMbm/LLnHOWlx821hE7xLCRACCGQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1083:b0:dc6:b982:cfa2 with SMTP id v3-20020a056902108300b00dc6b982cfa2mr758626ybu.8.1712603084180; Mon, 08 Apr 2024 12:04:44 -0700 (PDT) Date: Mon, 8 Apr 2024 19:04:37 +0000 In-Reply-To: <20240408190437.2214473-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240408190437.2214473-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408190437.2214473-4-edumazet@google.com> Subject: [PATCH net-next 3/3] bonding: no longer use RTNL in bonding_show_queue_id() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jay Vosburgh , Andy Gospodarek , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Annotate lockless reads of slave->queue_id. Annotate writes of slave->queue_id. Switch bonding_show_queue_id() to rcu_read_lock() and bond_for_each_slave_rcu(). Signed-off-by: Eric Dumazet Acked-by: Jay Vosburgh --- drivers/net/bonding/bond_main.c | 2 +- drivers/net/bonding/bond_netlink.c | 3 ++- drivers/net/bonding/bond_options.c | 2 +- drivers/net/bonding/bond_procfs.c | 2 +- drivers/net/bonding/bond_sysfs.c | 10 +++++----- drivers/net/bonding/bond_sysfs_slave.c | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 08e9bdbf450afdc103931249259c58a08665dc02..b3a7d60c3a5ca60be1d9eed184ec1dad593a182b 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -5245,7 +5245,7 @@ static inline int bond_slave_override(struct bonding *bond, /* Find out if any slaves have the same mapping as this skb. */ bond_for_each_slave_rcu(bond, slave, iter) { - if (slave->queue_id == skb_get_queue_mapping(skb)) { + if (READ_ONCE(slave->queue_id) == skb_get_queue_mapping(skb)) { if (bond_slave_is_up(slave) && slave->link == BOND_LINK_UP) { bond_dev_queue_xmit(bond, skb, slave->dev); diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c index 29b4c3d1b9b6ff873fe067e80bedf7cb681d18f1..2a6a424806aa603ad8a00ca797e9e22d38bd0435 100644 --- a/drivers/net/bonding/bond_netlink.c +++ b/drivers/net/bonding/bond_netlink.c @@ -51,7 +51,8 @@ static int bond_fill_slave_info(struct sk_buff *skb, slave_dev->addr_len, slave->perm_hwaddr)) goto nla_put_failure; - if (nla_put_u16(skb, IFLA_BOND_SLAVE_QUEUE_ID, slave->queue_id)) + if (nla_put_u16(skb, IFLA_BOND_SLAVE_QUEUE_ID, + READ_ONCE(slave->queue_id))) goto nla_put_failure; if (nla_put_s32(skb, IFLA_BOND_SLAVE_PRIO, slave->prio)) diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c index 4cdbc7e084f4b4cb3b150656aa765531806d8ad9..0cacd7027e352dbf3204d82b7ce1672469a186de 100644 --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -1589,7 +1589,7 @@ static int bond_option_queue_id_set(struct bonding *bond, goto err_no_cmd; /* Actually set the qids for the slave */ - update_slave->queue_id = qid; + WRITE_ONCE(update_slave->queue_id, qid); out: return ret; diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c index 43be458422b3f9448d96383b0fb140837562f446..7edf72ec816abd8b66917bdecd2c93d237629ffa 100644 --- a/drivers/net/bonding/bond_procfs.c +++ b/drivers/net/bonding/bond_procfs.c @@ -209,7 +209,7 @@ static void bond_info_show_slave(struct seq_file *seq, seq_printf(seq, "Permanent HW addr: %*phC\n", slave->dev->addr_len, slave->perm_hwaddr); - seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id); + seq_printf(seq, "Slave queue ID: %d\n", READ_ONCE(slave->queue_id)); if (BOND_MODE(bond) == BOND_MODE_8023AD) { const struct port *port = &SLAVE_AD_INFO(slave)->port; diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 75ee7ca369034ef6fa58fc9399b566dd7044fedc..1e13bb17051567e2b5d9451ceef47f2cf1a588ec 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -625,10 +625,9 @@ static ssize_t bonding_show_queue_id(struct device *d, struct slave *slave; int res = 0; - if (!rtnl_trylock()) - return restart_syscall(); + rcu_read_lock(); - bond_for_each_slave(bond, slave, iter) { + bond_for_each_slave_rcu(bond, slave, iter) { if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { /* not enough space for another interface_name:queue_id pair */ if ((PAGE_SIZE - res) > 10) @@ -637,12 +636,13 @@ static ssize_t bonding_show_queue_id(struct device *d, break; } res += sysfs_emit_at(buf, res, "%s:%d ", - slave->dev->name, slave->queue_id); + slave->dev->name, + READ_ONCE(slave->queue_id)); } if (res) buf[res-1] = '\n'; /* eat the leftover space */ - rtnl_unlock(); + rcu_read_unlock(); return res; } diff --git a/drivers/net/bonding/bond_sysfs_slave.c b/drivers/net/bonding/bond_sysfs_slave.c index 313866f2c0e49ac96299ffea307b1613955713ec..36d0e8440b5b94464b3226ce1a04f32361de5aa6 100644 --- a/drivers/net/bonding/bond_sysfs_slave.c +++ b/drivers/net/bonding/bond_sysfs_slave.c @@ -53,7 +53,7 @@ static SLAVE_ATTR_RO(perm_hwaddr); static ssize_t queue_id_show(struct slave *slave, char *buf) { - return sysfs_emit(buf, "%d\n", slave->queue_id); + return sysfs_emit(buf, "%d\n", READ_ONCE(slave->queue_id)); } static SLAVE_ATTR_RO(queue_id);