From patchwork Tue Jun 5 14:15:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Streetman X-Patchwork-Id: 925495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 410Ykb6nc0z9s0W; Wed, 6 Jun 2018 00:16:07 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1fQCkk-0007cO-1q; Tue, 05 Jun 2018 14:16:02 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1fQCki-0007ad-3O for kernel-team@lists.ubuntu.com; Tue, 05 Jun 2018 14:16:00 +0000 Received: from mail-yb0-f198.google.com ([209.85.213.198]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1fQCkh-0002TT-Pc for kernel-team@lists.ubuntu.com; Tue, 05 Jun 2018 14:15:59 +0000 Received: by mail-yb0-f198.google.com with SMTP id f141-v6so1953984yba.15 for ; Tue, 05 Jun 2018 07:15:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=FSnR+E7xArbcv4sFiyij3xJkZdDQwJ9W6U5ODI6iVfo=; b=YWk5OlabG2nPiUR8RFfs/HQiDJHDDIcUw1xLx+/Jk3y0dEFR+fSauAVL4Xfbzl0uru j+BEKxL/QDAorkZJEIKC+sqZsaiJeRuBemHnCmb6Q0Us7lAjHwonO4WyhvQpayvexyB9 2kv0y89ShSRDM1u5NZJX7jzrqyVcINNkTSO7AkI8zu5eJn4cis+VAfJlr5noH2aQghvg 2DEkFT/Wog4siCkAVqA8Vud/f3Vj7aFHeKcfmRELvVO1HVyYmkBtyHYaXF22e4bIO7xt ljPYvWXtBpRuOOK9RaSv5Tr56klChtqHaSIWxURy72Q/20QBl6f4cHjIpx9LY+1a39FL NTtQ== X-Gm-Message-State: ALKqPwdJ4a6e72aWKpI28vDoZqHCsCUkwjqWNKglZfuv30kzGoT/bJfh fVNgKVn3jvrRHFI6jLKxUg1cEHgU7RTXKPYDNrxsnJbWH7QSgXdr/Tb7ikTs4htn14HSkKDXNVi naUpD0kcWLlVe+JRRDnxESzIm5XoEHmNBnhhdO99E3g== X-Received: by 2002:a81:4705:: with SMTP id u5-v6mr13220352ywa.350.1528208158748; Tue, 05 Jun 2018 07:15:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJx2m+yBp8xZsbdAPqK6EMA/b/y0YCnBwjJT1UpRgoHCP4qEjQOdOFdxq49A90B5gdQW3rmOA== X-Received: by 2002:a81:4705:: with SMTP id u5-v6mr13220343ywa.350.1528208158512; Tue, 05 Jun 2018 07:15:58 -0700 (PDT) Received: from thorin.lan (45-27-90-188.lightspeed.rlghnc.sbcglobal.net. [45.27.90.188]) by smtp.gmail.com with ESMTPSA id z10-v6sm4493948ywg.84.2018.06.05.07.15.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jun 2018 07:15:58 -0700 (PDT) From: Dan Streetman To: kernel-team@lists.ubuntu.com Subject: [Trusty][PATCHv2 1/2] UBUNTU: SAUCE: Backport helper function netdev_upper_get_next_dev_rcu Date: Tue, 5 Jun 2018 10:15:39 -0400 Message-Id: <20180605141540.12813-2-dan.streetman@canonical.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605141540.12813-1-dan.streetman@canonical.com> References: <20180605141540.12813-1-dan.streetman@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Vlad Yasevich BugLink: https://bugs.launchpad.net/bugs/1771480 This partial backport adds the function netdev_upper_get_next_dev_rcu() and iterator macro netdev_for_each_upper_dev_rcu() from upstream commit: commit 44a4085538c844e79d6ee6bcf46fabf7c57a9a38 Author: Vlad Yasevich Date: Fri May 16 17:20:38 2014 -0400 bonding: Fix stacked device detection in arp monitoring These are used in the next patch in this series. The rest of the changes from the upstream commit are not included in this backport. (backported from 44a4085538c844e79d6ee6bcf46fabf7c57a9a38) Signed-off-by: Dan Streetman --- include/linux/netdevice.h | 9 +++++++++ net/core/dev.c | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 21ced47b9664..6e56f3af821c 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2927,9 +2927,18 @@ extern int bpf_jit_enable; bool netdev_has_upper_dev(struct net_device *dev, struct net_device *upper_dev); bool netdev_has_any_upper_dev(struct net_device *dev); +struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev, + struct list_head **iter); struct net_device *netdev_all_upper_get_next_dev_rcu(struct net_device *dev, struct list_head **iter); +/* iterate through upper list, must be called under RCU read lock */ +#define netdev_for_each_upper_dev_rcu(dev, updev, iter) \ + for (iter = &(dev)->adj_list.upper, \ + updev = netdev_upper_get_next_dev_rcu(dev, &(iter)); \ + updev; \ + updev = netdev_upper_get_next_dev_rcu(dev, &(iter))) + /* iterate through upper list, must be called under RCU read lock */ #define netdev_for_each_all_upper_dev_rcu(dev, updev, iter) \ for (iter = &(dev)->all_adj_list.upper, \ diff --git a/net/core/dev.c b/net/core/dev.c index 1d37e93ad23c..efb8f8f39863 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4538,6 +4538,32 @@ void *netdev_adjacent_get_private(struct list_head *adj_list) } EXPORT_SYMBOL(netdev_adjacent_get_private); +/** + * netdev_upper_get_next_dev_rcu - Get the next dev from upper list + * @dev: device + * @iter: list_head ** of the current position + * + * Gets the next device from the dev's upper list, starting from iter + * position. The caller must hold RCU read lock. + */ +struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev, + struct list_head **iter) +{ + struct netdev_adjacent *upper; + + WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_rtnl_is_held()); + + upper = list_entry_rcu((*iter)->next, struct netdev_adjacent, list); + + if (&upper->list == &dev->adj_list.upper) + return NULL; + + *iter = &upper->list; + + return upper->dev; +} +EXPORT_SYMBOL(netdev_upper_get_next_dev_rcu); + /** * netdev_all_upper_get_next_dev_rcu - Get the next dev from upper list * @dev: device