From patchwork Mon Aug 21 23:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13359915 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10E8723DF for ; Mon, 21 Aug 2023 23:10:09 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1EA1130 for ; Mon, 21 Aug 2023 16:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692659408; x=1724195408; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n7yfKoEb/+5CMNMdyZVEgPorrACEW/cL+HbTA4KIup8=; b=PYzHPhtr4nu8FFodumg4pg/BCPEnStHB13Tt+bE4wGjpVFUtdHrr6dHz exUYddKYHtj4IgAiVSgTnSQNcwGpAndhULR3LXsaj17x/v3xDjzjrdvoe hs5DTauRFwgP0MX8wJ7SJ4eAzSjZtKMFhohMyC+QX+GblWNccBin8ae0R tePU3CrwFusakLODcqHgJl5AHgAMF1eI8zTJVm2MK0g9DH1ypkScjZdmJ czvUO+tMAvFwAUws+BKu6Zy4hv0xvrBVCsrAlnxgpfd30bXf3fTEtZis4 c9U6GDRqvXgzKzwBAAYq32E2y5Y90hcUbXhrvgsNHii6Fv3q/c1FcHMob A==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="404723888" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="404723888" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:10:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="765543058" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="765543058" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga008.jf.intel.com with ESMTP; 21 Aug 2023 16:10:08 -0700 Subject: [net-next PATCH v2 1/9] net: Introduce new fields for napi and queue associations From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Mon, 21 Aug 2023 16:25:15 -0700 Message-ID: <169266031496.10199.9655642930215889099.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> References: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add the napi pointer in netdev queue for tracking the napi instance for each queue. This achieves the queue<->napi mapping. Introduce new napi fields 'napi_rxq_list' and 'napi_txq_list' for rx and tx queue set associated with the napi. Add functions to associate the queue with the napi and handle their removal as well. This lists the queue/queue-set on the corresponding irq line for each napi instance. Signed-off-by: Amritha Nambiar --- include/linux/netdevice.h | 16 +++++++++++++ include/net/netdev_rx_queue.h | 3 ++ net/core/dev.c | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0896aaa91dd7..7645c0ba0995 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -346,6 +346,14 @@ struct gro_list { */ #define GRO_HASH_BUCKETS 8 +/* + * napi queue container type + */ +enum q_type { + QUEUE_RX, + QUEUE_TX, +}; + /* * Structure for NAPI scheduling similar to tasklet but with weighting */ @@ -380,6 +388,8 @@ struct napi_struct { /* control-path-only fields follow */ struct list_head dev_list; struct hlist_node napi_hash_node; + struct list_head napi_rxq_list; + struct list_head napi_txq_list; }; enum { @@ -655,6 +665,9 @@ struct netdev_queue { unsigned long state; + /* NAPI instance for the queue */ + struct napi_struct *napi; + struct list_head q_list; #ifdef CONFIG_BQL struct dql dql; #endif @@ -2609,6 +2622,9 @@ static inline void *netdev_priv(const struct net_device *dev) */ #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) +int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index, + enum q_type type); + /* Default NAPI poll() weight * Device drivers are strongly advised to not use bigger value */ diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index cdcafb30d437..66bda0dfe71c 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -21,6 +21,9 @@ struct netdev_rx_queue { #ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool; #endif + struct list_head q_list; + /* NAPI instance for the queue */ + struct napi_struct *napi; } ____cacheline_aligned_in_smp; /* diff --git a/net/core/dev.c b/net/core/dev.c index 17e6281e408c..ec4c469c9e1d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6391,6 +6391,42 @@ int dev_set_threaded(struct net_device *dev, bool threaded) } EXPORT_SYMBOL(dev_set_threaded); +/** + * netif_napi_add_queue - Associate queue with the napi + * @napi: NAPI context + * @queue_index: Index of queue + * @type: queue type as RX or TX + * + * Add queue with its corresponding napi context + */ +int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index, + enum q_type type) +{ + struct net_device *dev = napi->dev; + struct netdev_rx_queue *rxq; + struct netdev_queue *txq; + + if (!dev) + return -EINVAL; + + switch (type) { + case QUEUE_RX: + rxq = __netif_get_rx_queue(dev, queue_index); + rxq->napi = napi; + list_add_rcu(&rxq->q_list, &napi->napi_rxq_list); + break; + case QUEUE_TX: + txq = netdev_get_tx_queue(dev, queue_index); + txq->napi = napi; + list_add_rcu(&txq->q_list, &napi->napi_txq_list); + break; + default: + return -EINVAL; + } + return 0; +} +EXPORT_SYMBOL(netif_napi_add_queue); + void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight) { @@ -6426,6 +6462,9 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, */ if (dev->threaded && napi_kthread_create(napi)) dev->threaded = 0; + + INIT_LIST_HEAD(&napi->napi_rxq_list); + INIT_LIST_HEAD(&napi->napi_txq_list); } EXPORT_SYMBOL(netif_napi_add_weight); @@ -6487,6 +6526,18 @@ static void flush_gro_hash(struct napi_struct *napi) } } +static void napi_del_queues(struct napi_struct *napi) +{ + struct netdev_rx_queue *rx_queue, *rxq; + struct netdev_queue *tx_queue, *txq; + + list_for_each_entry_safe(rx_queue, rxq, &napi->napi_rxq_list, q_list) + list_del_rcu(&rx_queue->q_list); + + list_for_each_entry_safe(tx_queue, txq, &napi->napi_txq_list, q_list) + list_del_rcu(&tx_queue->q_list); +} + /* Must be called in process context */ void __netif_napi_del(struct napi_struct *napi) { @@ -6504,6 +6555,7 @@ void __netif_napi_del(struct napi_struct *napi) kthread_stop(napi->thread); napi->thread = NULL; } + napi_del_queues(napi); } EXPORT_SYMBOL(__netif_napi_del); From patchwork Mon Aug 21 23:25:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13359916 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DFDE1ADF5 for ; Mon, 21 Aug 2023 23:10:17 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21BA3133 for ; Mon, 21 Aug 2023 16:10:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692659416; x=1724195416; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Icqp0ptiYQY1altdIQOTFW55jPhSyb+cNRb1xnazPiU=; b=C4jaXWVDSVlL6NDuPa8BJ80E1eBpYs1+ZZ0fHM5GanZ91QzYpTnoofXe EbpCS/yFMsbHsT1VWxtK85/Sco1iKUKW3j9uDYFquyx/Lo/0g8BQktcqW HGOlGVWPhFuGTgQpJsbYjw71z9KP//l9CGgyT2sYSnMHr9NHQ2zQL4dc/ aXd/G3kGdaAH1O6pCgCDh2+SF5jcqjVNCarjctcMpZbBF9XUryrUmx1IR uuaGg2dNQ95YfmaphxM9gJ7B5q9rNK2bIgg0oaD2vrlSnnPoTqN8Cueug ea9pOVF5aK84dapemF1pvLevqeQLyx/VuuievR9p6zTiFMHsjYDwColjf A==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="358707650" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="358707650" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:10:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="739086017" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="739086017" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga007.fm.intel.com with ESMTP; 21 Aug 2023 16:10:13 -0700 Subject: [net-next PATCH v2 2/9] ice: Add support in the driver for associating napi with queue[s] From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Mon, 21 Aug 2023 16:25:20 -0700 Message-ID: <169266032008.10199.14729078556224584827.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> References: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org After the napi context is initialized, map the napi instance with the queue/queue-set on the corresponding irq line. Signed-off-by: Amritha Nambiar --- drivers/net/ethernet/intel/ice/ice_lib.c | 57 +++++++++++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_lib.h | 4 ++ drivers/net/ethernet/intel/ice/ice_main.c | 4 ++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 201570cd2e0b..c2b9a25db139 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -2461,6 +2461,12 @@ ice_vsi_cfg_def(struct ice_vsi *vsi, struct ice_vsi_cfg_params *params) goto unroll_vector_base; ice_vsi_map_rings_to_vectors(vsi); + + /* Associate q_vector rings to napi */ + ret = ice_vsi_add_napi_queues(vsi); + if (ret) + goto unroll_vector_base; + vsi->stat_offsets_loaded = false; if (ice_is_xdp_ena_vsi(vsi)) { @@ -2940,6 +2946,57 @@ void ice_vsi_dis_irq(struct ice_vsi *vsi) synchronize_irq(vsi->q_vectors[i]->irq.virq); } +/** + * ice_q_vector_add_napi_queues - Add queue[s] associated with the napi + * @q_vector: q_vector pointer + * + * Associate the q_vector napi with all the queue[s] on the vector + * Returns 0 on success or < 0 on error + */ +int ice_q_vector_add_napi_queues(struct ice_q_vector *q_vector) +{ + struct ice_rx_ring *rx_ring; + struct ice_tx_ring *tx_ring; + int ret = 0; + + ice_for_each_rx_ring(rx_ring, q_vector->rx) { + ret = netif_napi_add_queue(&q_vector->napi, rx_ring->q_index, + QUEUE_RX); + if (ret) + return ret; + } + ice_for_each_tx_ring(tx_ring, q_vector->tx) { + ret = netif_napi_add_queue(&q_vector->napi, tx_ring->q_index, + QUEUE_TX); + if (ret) + return ret; + } + + return ret; +} + +/** + * ice_vsi_add_napi_queues + * @vsi: VSI pointer + * + * Associate queue[s] with napi for all vectors + * Returns 0 on success or < 0 on error + */ +int ice_vsi_add_napi_queues(struct ice_vsi *vsi) +{ + int i, ret = 0; + + if (!vsi->netdev) + return ret; + + ice_for_each_q_vector(vsi, i) { + ret = ice_q_vector_add_napi_queues(vsi->q_vectors[i]); + if (ret) + return ret; + } + return ret; +} + /** * ice_vsi_release - Delete a VSI and free its resources * @vsi: the VSI being removed diff --git a/drivers/net/ethernet/intel/ice/ice_lib.h b/drivers/net/ethernet/intel/ice/ice_lib.h index f24f5d1e6f9c..21d164ac1eed 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.h +++ b/drivers/net/ethernet/intel/ice/ice_lib.h @@ -91,6 +91,10 @@ void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc); struct ice_vsi * ice_vsi_setup(struct ice_pf *pf, struct ice_vsi_cfg_params *params); +int ice_q_vector_add_napi_queues(struct ice_q_vector *q_vector); + +int ice_vsi_add_napi_queues(struct ice_vsi *vsi); + int ice_vsi_release(struct ice_vsi *vsi); void ice_vsi_close(struct ice_vsi *vsi); diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index c8286adae946..bb6be2182a7f 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -3374,9 +3374,11 @@ static void ice_napi_add(struct ice_vsi *vsi) if (!vsi->netdev) return; - ice_for_each_q_vector(vsi, v_idx) + ice_for_each_q_vector(vsi, v_idx) { netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi, ice_napi_poll); + ice_q_vector_add_napi_queues(vsi->q_vectors[v_idx]); + } } /** From patchwork Mon Aug 21 23:25:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13359917 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C4AE1ADD2 for ; Mon, 21 Aug 2023 23:10:21 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 987E6131 for ; Mon, 21 Aug 2023 16:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692659419; x=1724195419; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iyypIyAvaJ3Jb027UyVOssGsM4tLEuUykLN33R955II=; b=ALLfrcjRHKHBtjvfE9LEHoQR07PDRQFgP3kLdwNRYBcfEONJSaBNqmS4 A+QeRTJcVnZkVfEgqZXKP2E8OXun6DLzYbeQHG8liWmUNdZickPv6UNDO JpmTg0qXCiYKScZjVDhzyyg3DzG/ssUYkWZ9WCbZ6A1wgLvVFyJm2Paki oCORtMIfE9LZ+WKtyKrS+m2/8muL18fIrZBNUg2nGofyHvP2fJRNfDp09 MDAQCsi+CAXyjjic+cDGS6d+pmdrYiPrf7FKYmGfx/VnUU+Q6Oh2/gqWK aJVV3ImZPot+FzexOeSoy9q7cMhtvsdWMXVMrGDalHqIdMVDujXb7LsGU Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="358707668" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="358707668" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:10:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="739086027" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="739086027" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga007.fm.intel.com with ESMTP; 21 Aug 2023 16:10:18 -0700 Subject: [net-next PATCH v2 3/9] netdev-genl: spec: Extend netdev netlink spec in YAML for NAPI From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Mon, 21 Aug 2023 16:25:25 -0700 Message-ID: <169266032552.10199.11622842596696957776.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> References: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for napi related information. Add code generated from the spec. Signed-off-by: Amritha Nambiar --- Documentation/netlink/specs/netdev.yaml | 42 ++++++++ include/uapi/linux/netdev.h | 11 ++ net/core/netdev-genl-gen.c | 24 +++++ net/core/netdev-genl-gen.h | 2 net/core/netdev-genl.c | 10 ++ tools/include/uapi/linux/netdev.h | 11 ++ tools/net/ynl/generated/netdev-user.c | 165 +++++++++++++++++++++++++++++++ tools/net/ynl/generated/netdev-user.h | 79 +++++++++++++++ 8 files changed, 344 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index 1c7284fd535b..a068cf3b5a7e 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -68,6 +68,29 @@ attribute-sets: type: u32 checks: min: 1 + - + name: napi + attributes: + - + name: ifindex + doc: netdev ifindex + type: u32 + checks: + min: 1 + - + name: napi-id + doc: napi id + type: u32 + - + name: rx-queues + doc: list of rx queues associated with a napi + type: u32 + multi-attr: true + - + name: tx-queues + doc: list of tx queues associated with a napi + type: u32 + multi-attr: true operations: list: @@ -101,6 +124,25 @@ operations: doc: Notification about device configuration being changed. notify: dev-get mcgrp: mgmt + - + name: napi-get + doc: napi information such as napi-id, napi queues etc. + attribute-set: napi + do: + request: + attributes: + - napi-id + reply: &napi-get-op + attributes: + - napi-id + - ifindex + - rx-queues + - tx-queues + dump: + request: + attributes: + - ifindex + reply: *napi-get-op mcast-groups: list: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index c1634b95c223..28f6bad7c48e 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -48,11 +48,22 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + NETDEV_A_NAPI_IFINDEX = 1, + NETDEV_A_NAPI_NAPI_ID, + NETDEV_A_NAPI_RX_QUEUES, + NETDEV_A_NAPI_TX_QUEUES, + + __NETDEV_A_NAPI_MAX, + NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) +}; + enum { NETDEV_CMD_DEV_GET = 1, NETDEV_CMD_DEV_ADD_NTF, NETDEV_CMD_DEV_DEL_NTF, NETDEV_CMD_DEV_CHANGE_NTF, + NETDEV_CMD_NAPI_GET, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1) diff --git a/net/core/netdev-genl-gen.c b/net/core/netdev-genl-gen.c index ea9231378aa6..37cce2d64a14 100644 --- a/net/core/netdev-genl-gen.c +++ b/net/core/netdev-genl-gen.c @@ -15,6 +15,16 @@ static const struct nla_policy netdev_dev_get_nl_policy[NETDEV_A_DEV_IFINDEX + 1 [NETDEV_A_DEV_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1), }; +/* NETDEV_CMD_NAPI_GET - do */ +static const struct nla_policy netdev_napi_get_do_nl_policy[NETDEV_A_NAPI_NAPI_ID + 1] = { + [NETDEV_A_NAPI_NAPI_ID] = { .type = NLA_U32, }, +}; + +/* NETDEV_CMD_NAPI_GET - dump */ +static const struct nla_policy netdev_napi_get_dump_nl_policy[NETDEV_A_NAPI_IFINDEX + 1] = { + [NETDEV_A_NAPI_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1), +}; + /* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { { @@ -29,6 +39,20 @@ static const struct genl_split_ops netdev_nl_ops[] = { .dumpit = netdev_nl_dev_get_dumpit, .flags = GENL_CMD_CAP_DUMP, }, + { + .cmd = NETDEV_CMD_NAPI_GET, + .doit = netdev_nl_napi_get_doit, + .policy = netdev_napi_get_do_nl_policy, + .maxattr = NETDEV_A_NAPI_NAPI_ID, + .flags = GENL_CMD_CAP_DO, + }, + { + .cmd = NETDEV_CMD_NAPI_GET, + .dumpit = netdev_nl_napi_get_dumpit, + .policy = netdev_napi_get_dump_nl_policy, + .maxattr = NETDEV_A_NAPI_IFINDEX, + .flags = GENL_CMD_CAP_DUMP, + }, }; static const struct genl_multicast_group netdev_nl_mcgrps[] = { diff --git a/net/core/netdev-genl-gen.h b/net/core/netdev-genl-gen.h index 7b370c073e7d..46dab8ccd568 100644 --- a/net/core/netdev-genl-gen.h +++ b/net/core/netdev-genl-gen.h @@ -13,6 +13,8 @@ int netdev_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info); int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); +int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info); +int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); enum { NETDEV_NLGRP_MGMT, diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index c1aea8b756b6..b146679d6112 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -119,6 +119,16 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info) +{ + return -EOPNOTSUPP; +} + +int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) +{ + return -EOPNOTSUPP; +} + static int netdev_genl_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index c1634b95c223..28f6bad7c48e 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -48,11 +48,22 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + NETDEV_A_NAPI_IFINDEX = 1, + NETDEV_A_NAPI_NAPI_ID, + NETDEV_A_NAPI_RX_QUEUES, + NETDEV_A_NAPI_TX_QUEUES, + + __NETDEV_A_NAPI_MAX, + NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) +}; + enum { NETDEV_CMD_DEV_GET = 1, NETDEV_CMD_DEV_ADD_NTF, NETDEV_CMD_DEV_DEL_NTF, NETDEV_CMD_DEV_CHANGE_NTF, + NETDEV_CMD_NAPI_GET, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index 68b408ca0f7f..0cc8c0151b36 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -18,6 +18,7 @@ static const char * const netdev_op_strmap[] = { [NETDEV_CMD_DEV_ADD_NTF] = "dev-add-ntf", [NETDEV_CMD_DEV_DEL_NTF] = "dev-del-ntf", [NETDEV_CMD_DEV_CHANGE_NTF] = "dev-change-ntf", + [NETDEV_CMD_NAPI_GET] = "napi-get", }; const char *netdev_op_str(int op) @@ -58,6 +59,18 @@ struct ynl_policy_nest netdev_dev_nest = { .table = netdev_dev_policy, }; +struct ynl_policy_attr netdev_napi_policy[NETDEV_A_NAPI_MAX + 1] = { + [NETDEV_A_NAPI_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_NAPI_ID] = { .name = "napi-id", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_RX_QUEUES] = { .name = "rx-queues", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_TX_QUEUES] = { .name = "tx-queues", .type = YNL_PT_U32, }, +}; + +struct ynl_policy_nest netdev_napi_nest = { + .max_attr = NETDEV_A_NAPI_MAX, + .table = netdev_napi_policy, +}; + /* Common nested types */ /* ============== NETDEV_CMD_DEV_GET ============== */ /* NETDEV_CMD_DEV_GET - do */ @@ -178,6 +191,158 @@ void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp) free(rsp); } +/* ============== NETDEV_CMD_NAPI_GET ============== */ +/* NETDEV_CMD_NAPI_GET - do */ +void netdev_napi_get_req_free(struct netdev_napi_get_req *req) +{ + free(req); +} + +void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp) +{ + free(rsp->rx_queues); + free(rsp->tx_queues); + free(rsp); +} + +int netdev_napi_get_rsp_parse(const struct nlmsghdr *nlh, void *data) +{ + struct ynl_parse_arg *yarg = data; + struct netdev_napi_get_rsp *dst; + unsigned int n_rx_queues = 0; + unsigned int n_tx_queues = 0; + const struct nlattr *attr; + int i; + + dst = yarg->data; + + if (dst->rx_queues) + return ynl_error_parse(yarg, "attribute already present (napi.rx-queues)"); + if (dst->tx_queues) + return ynl_error_parse(yarg, "attribute already present (napi.tx-queues)"); + + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + unsigned int type = mnl_attr_get_type(attr); + + if (type == NETDEV_A_NAPI_NAPI_ID) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.napi_id = 1; + dst->napi_id = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_NAPI_IFINDEX) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.ifindex = 1; + dst->ifindex = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_NAPI_RX_QUEUES) { + n_rx_queues++; + } else if (type == NETDEV_A_NAPI_TX_QUEUES) { + n_tx_queues++; + } + } + + if (n_rx_queues) { + dst->rx_queues = calloc(n_rx_queues, sizeof(*dst->rx_queues)); + dst->n_rx_queues = n_rx_queues; + i = 0; + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + if (mnl_attr_get_type(attr) == NETDEV_A_NAPI_RX_QUEUES) { + dst->rx_queues[i] = mnl_attr_get_u32(attr); + i++; + } + } + } + if (n_tx_queues) { + dst->tx_queues = calloc(n_tx_queues, sizeof(*dst->tx_queues)); + dst->n_tx_queues = n_tx_queues; + i = 0; + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + if (mnl_attr_get_type(attr) == NETDEV_A_NAPI_TX_QUEUES) { + dst->tx_queues[i] = mnl_attr_get_u32(attr); + i++; + } + } + } + + return MNL_CB_OK; +} + +struct netdev_napi_get_rsp * +netdev_napi_get(struct ynl_sock *ys, struct netdev_napi_get_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct netdev_napi_get_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NETDEV_CMD_NAPI_GET, 1); + ys->req_policy = &netdev_napi_nest; + yrs.yarg.rsp_policy = &netdev_napi_nest; + + if (req->_present.napi_id) + mnl_attr_put_u32(nlh, NETDEV_A_NAPI_NAPI_ID, req->napi_id); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = netdev_napi_get_rsp_parse; + yrs.rsp_cmd = NETDEV_CMD_NAPI_GET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + netdev_napi_get_rsp_free(rsp); + return NULL; +} + +/* NETDEV_CMD_NAPI_GET - dump */ +void netdev_napi_get_list_free(struct netdev_napi_get_list *rsp) +{ + struct netdev_napi_get_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + rsp = next; + next = rsp->next; + + free(rsp->obj.rx_queues); + free(rsp->obj.tx_queues); + free(rsp); + } +} + +struct netdev_napi_get_list * +netdev_napi_get_dump(struct ynl_sock *ys, struct netdev_napi_get_req_dump *req) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.ys = ys; + yds.alloc_sz = sizeof(struct netdev_napi_get_list); + yds.cb = netdev_napi_get_rsp_parse; + yds.rsp_cmd = NETDEV_CMD_NAPI_GET; + yds.rsp_policy = &netdev_napi_nest; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, NETDEV_CMD_NAPI_GET, 1); + ys->req_policy = &netdev_napi_nest; + + if (req->_present.ifindex) + mnl_attr_put_u32(nlh, NETDEV_A_NAPI_IFINDEX, req->ifindex); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + netdev_napi_get_list_free(yds.first); + return NULL; +} + static const struct ynl_ntf_info netdev_ntf_info[] = { [NETDEV_CMD_DEV_ADD_NTF] = { .alloc_sz = sizeof(struct netdev_dev_get_ntf), diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index 0952d3261f4d..742cb37b6844 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -84,4 +84,83 @@ struct netdev_dev_get_ntf { void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp); +/* ============== NETDEV_CMD_NAPI_GET ============== */ +/* NETDEV_CMD_NAPI_GET - do */ +struct netdev_napi_get_req { + struct { + __u32 napi_id:1; + } _present; + + __u32 napi_id; +}; + +static inline struct netdev_napi_get_req *netdev_napi_get_req_alloc(void) +{ + return calloc(1, sizeof(struct netdev_napi_get_req)); +} +void netdev_napi_get_req_free(struct netdev_napi_get_req *req); + +static inline void +netdev_napi_get_req_set_napi_id(struct netdev_napi_get_req *req, __u32 napi_id) +{ + req->_present.napi_id = 1; + req->napi_id = napi_id; +} + +struct netdev_napi_get_rsp { + struct { + __u32 napi_id:1; + __u32 ifindex:1; + } _present; + + __u32 napi_id; + __u32 ifindex; + unsigned int n_rx_queues; + __u32 *rx_queues; + unsigned int n_tx_queues; + __u32 *tx_queues; +}; + +void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp); + +/* + * napi information such as napi-id, napi queues etc. + */ +struct netdev_napi_get_rsp * +netdev_napi_get(struct ynl_sock *ys, struct netdev_napi_get_req *req); + +/* NETDEV_CMD_NAPI_GET - dump */ +struct netdev_napi_get_req_dump { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; +}; + +static inline struct netdev_napi_get_req_dump * +netdev_napi_get_req_dump_alloc(void) +{ + return calloc(1, sizeof(struct netdev_napi_get_req_dump)); +} +void netdev_napi_get_req_dump_free(struct netdev_napi_get_req_dump *req); + +static inline void +netdev_napi_get_req_dump_set_ifindex(struct netdev_napi_get_req_dump *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} + +struct netdev_napi_get_list { + struct netdev_napi_get_list *next; + struct netdev_napi_get_rsp obj __attribute__ ((aligned (8))); +}; + +void netdev_napi_get_list_free(struct netdev_napi_get_list *rsp); + +struct netdev_napi_get_list * +netdev_napi_get_dump(struct ynl_sock *ys, struct netdev_napi_get_req_dump *req); + #endif /* _LINUX_NETDEV_GEN_H */ From patchwork Mon Aug 21 23:25:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13359918 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21AE71B7E7 for ; Mon, 21 Aug 2023 23:10:26 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 391DC131 for ; Mon, 21 Aug 2023 16:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692659425; x=1724195425; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5+FQvVqJ0cJMRlbsHxdxetncKR68ITtto6XWrYXvu8s=; b=lwbbsWvg9PCADk6y8vLuFyzJAAaSxSJqNecKTZdEmRy9k2d1M5+eBv1o PLRHBmmc8rEQuVWVXBrW8B+FsvVtlUL2CHMK/N5y80Qxhmy+xcATi0/yo 2WZNshBjcuTqTMHBWE2gJb2NikpnixZSpa4mpItXA8voHog0/B8IE8DdN FXUfOfDz8hTXUkFCtQqfVA0DZ1+FiWezp10vvONrG/EZmY9Sr1ojXvXB3 NU1DcbLr131pqbdL7WMvX4nniv7rVbGTXNg2wihoIxeEFUiQXRRBui2iH cX3wxMBdSezmT0xY92QAqM85DqCub9W23/cGwupqvwi/F4GEdUqWm5LbH A==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="358707711" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="358707711" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:10:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="739086041" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="739086041" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga007.fm.intel.com with ESMTP; 21 Aug 2023 16:10:24 -0700 Subject: [net-next PATCH v2 4/9] net: Move kernel helpers for queue index outside sysfs From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Mon, 21 Aug 2023 16:25:31 -0700 Message-ID: <169266033119.10199.3382453499474113876.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> References: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The kernel helpers for retrieving tx/rx queue index (get_netdev_queue_index and get_netdev_rx_queue_index) are restricted to sysfs, move this out for more usability. Also, replace BUG_ON with DEBUG_NET_WARN_ON_ONCE. Signed-off-by: Amritha Nambiar --- include/linux/netdevice.h | 12 ++++++++++++ include/net/netdev_rx_queue.h | 4 +--- net/core/net-sysfs.c | 11 ----------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 7645c0ba0995..4ec86d9aceb2 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2503,6 +2503,18 @@ struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev, return &dev->_tx[index]; } +static inline +unsigned int get_netdev_queue_index(struct netdev_queue *queue) +{ + struct net_device *dev = queue->dev; + unsigned int i; + + i = queue - dev->_tx; + DEBUG_NET_WARN_ON_ONCE(i >= dev->num_tx_queues); + + return i; +} + static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev, const struct sk_buff *skb) { diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index 66bda0dfe71c..ac58fa7c2532 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -42,15 +42,13 @@ __netif_get_rx_queue(struct net_device *dev, unsigned int rxq) return dev->_rx + rxq; } -#ifdef CONFIG_SYSFS static inline unsigned int get_netdev_rx_queue_index(struct netdev_rx_queue *queue) { struct net_device *dev = queue->dev; int index = queue - dev->_rx; - BUG_ON(index >= dev->num_rx_queues); + DEBUG_NET_WARN_ON_ONCE(index >= dev->num_rx_queues); return index; } #endif -#endif diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index fccaa5bac0ed..858d50503e4f 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1240,17 +1240,6 @@ static ssize_t tx_timeout_show(struct netdev_queue *queue, char *buf) return sysfs_emit(buf, fmt_ulong, trans_timeout); } -static unsigned int get_netdev_queue_index(struct netdev_queue *queue) -{ - struct net_device *dev = queue->dev; - unsigned int i; - - i = queue - dev->_tx; - BUG_ON(i >= dev->num_tx_queues); - - return i; -} - static ssize_t traffic_class_show(struct netdev_queue *queue, char *buf) { From patchwork Mon Aug 21 23:25:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13359919 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65AA41BB3F for ; Mon, 21 Aug 2023 23:10:33 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 517B0131 for ; Mon, 21 Aug 2023 16:10:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692659432; x=1724195432; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=psWUQDmleIM3iPULg/dHdOvV3gk3LN+in+Fv6kWZ8v8=; b=N24s9vjBW8qjSfp8YnpuCw34FtLfGBntjhZiQiKfNEr+qcbYEw2rFaJe xSoSTSL5Ozfinj8O/XomsGXMZupBZJT3H42ZVeSM3lDvIkmeYculld4b6 yyW+gUoivCZ9VTmRE9i8BiK4rm5gosGsiRD2HBclofxph5Z32DKO/8NDw /euZhzD8GqGtrfD8Yh39bs6V0A0B+DfXHotRv4E9Khdc1Am932SXT1IsH ommbZYYE3zE4xREgCvm9UK3FLzrTtUfVCR225xJz9rqNhftu2zRQVCKli 9aRRcnUeVij2OLWyavIBIVkrqBzlIzXaWcgcWfWsaaCvG7EYL5t7rFKPq A==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="437645828" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="437645828" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:10:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="685829226" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="685829226" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga003.jf.intel.com with ESMTP; 21 Aug 2023 16:10:29 -0700 Subject: [net-next PATCH v2 5/9] netdev-genl: Add netlink framework functions for napi From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Mon, 21 Aug 2023 16:25:36 -0700 Message-ID: <169266033666.10199.3744908214828788701.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> References: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Implement the netdev netlink framework functions for napi support. The netdev structure tracks all the napi instances and napi fields. The napi instances and associated queue[s] can be retrieved this way. Signed-off-by: Amritha Nambiar --- net/core/netdev-genl.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 3 deletions(-) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index b146679d6112..4bc6aa756001 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -5,9 +5,23 @@ #include #include #include +#include #include "netdev-genl-gen.h" +struct netdev_nl_dump_ctx { + unsigned long ifindex; + int napi_idx; +}; + +static inline struct netdev_nl_dump_ctx * +netdev_dump_ctx(struct netlink_callback *cb) +{ + NL_ASSERT_DUMP_CTX_FITS(struct netdev_nl_dump_ctx); + + return (struct netdev_nl_dump_ctx *)cb->ctx; +} + static int netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, const struct genl_info *info) @@ -101,12 +115,13 @@ int netdev_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info) int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) { + struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb); struct net *net = sock_net(skb->sk); struct net_device *netdev; int err = 0; rtnl_lock(); - for_each_netdev_dump(net, netdev, cb->args[0]) { + for_each_netdev_dump(net, netdev, ctx->ifindex) { err = netdev_nl_dev_fill(netdev, skb, genl_info_dump(cb)); if (err < 0) break; @@ -119,14 +134,158 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +static int +netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, + const struct genl_info *info) +{ + struct netdev_rx_queue *rx_queue, *rxq; + struct netdev_queue *tx_queue, *txq; + unsigned int rx_qid, tx_qid; + void *hdr; + + if (!napi->dev) + return -EINVAL; + + hdr = genlmsg_iput(rsp, info); + if (!hdr) + return -EMSGSIZE; + + if (nla_put_u32(rsp, NETDEV_A_NAPI_NAPI_ID, napi->napi_id)) + goto nla_put_failure; + + if (nla_put_u32(rsp, NETDEV_A_NAPI_IFINDEX, napi->dev->ifindex)) + goto nla_put_failure; + + list_for_each_entry_safe(rx_queue, rxq, &napi->napi_rxq_list, q_list) { + rx_qid = get_netdev_rx_queue_index(rx_queue); + if (nla_put_u32(rsp, NETDEV_A_NAPI_RX_QUEUES, rx_qid)) + goto nla_put_failure; + } + + list_for_each_entry_safe(tx_queue, txq, &napi->napi_txq_list, q_list) { + tx_qid = get_netdev_queue_index(tx_queue); + if (nla_put_u32(rsp, NETDEV_A_NAPI_TX_QUEUES, tx_qid)) + goto nla_put_failure; + } + + genlmsg_end(rsp, hdr); + return 0; + +nla_put_failure: + genlmsg_cancel(rsp, hdr); + return -EMSGSIZE; +} + +static int +netdev_nl_napi_fill(struct net_device *netdev, struct sk_buff *rsp, + const struct genl_info *info, u32 napi_id) +{ + struct napi_struct *napi, *n; + + list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list) { + if (napi->napi_id == napi_id) + return netdev_nl_napi_fill_one(rsp, napi, info); + } + return -EINVAL; +} + int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info) { - return -EOPNOTSUPP; + struct net_device *netdev; + struct sk_buff *rsp; + u32 napi_id; + int err; + + if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_NAPI_NAPI_ID)) + return -EINVAL; + + napi_id = nla_get_u32(info->attrs[NETDEV_A_NAPI_NAPI_ID]); + + rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!rsp) + return -ENOMEM; + + rtnl_lock(); + + netdev = dev_get_by_napi_id(napi_id); + if (netdev) + err = netdev_nl_napi_fill(netdev, rsp, info, napi_id); + else + err = -ENODEV; + + rtnl_unlock(); + + if (err) + goto err_free_msg; + + return genlmsg_reply(rsp, info); + +err_free_msg: + nlmsg_free(rsp); + return err; +} + +static int +netdev_nl_napi_dump_one(struct net_device *netdev, struct sk_buff *rsp, + const struct genl_info *info, int *start) +{ + struct napi_struct *napi, *n; + int err = 0; + int i = 0; + + list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list) { + if (i < *start) { + i++; + continue; + } + err = netdev_nl_napi_fill_one(rsp, napi, info); + if (err) + break; + *start = ++i; + } + return err; } int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) { - return -EOPNOTSUPP; + const struct genl_dumpit_info *info = genl_dumpit_info(cb); + struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb); + struct net *net = sock_net(skb->sk); + struct net_device *netdev; + int n_idx = ctx->napi_idx; + u32 ifindex = 0; + int err = 0; + + if (info->info.attrs[NETDEV_A_NAPI_IFINDEX]) + ifindex = nla_get_u32(info->info.attrs[NETDEV_A_NAPI_IFINDEX]); + + rtnl_lock(); + if (ifindex) { + netdev = __dev_get_by_index(net, ifindex); + if (netdev) + err = netdev_nl_napi_dump_one(netdev, skb, + genl_info_dump(cb), + &n_idx); + else + err = -ENODEV; + } else { + for_each_netdev_dump(net, netdev, ctx->ifindex) { + err = netdev_nl_napi_dump_one(netdev, skb, + genl_info_dump(cb), + &n_idx); + if (!err) + n_idx = 0; + if (err < 0) + break; + } + } + rtnl_unlock(); + + if (err != -EMSGSIZE) + return err; + + ctx->napi_idx = n_idx; + return skb->len; } static int netdev_genl_netdevice_event(struct notifier_block *nb, From patchwork Mon Aug 21 23:25:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13359920 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 323EC1BF12 for ; Mon, 21 Aug 2023 23:10:36 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40D64131 for ; Mon, 21 Aug 2023 16:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692659435; x=1724195435; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/Cr6/BKjF3eEWPCCiSVuHxvx1dcwMdTGe+K4Ej2eW8A=; b=Jsn+XcPoj92uvbtmsGaCgUzME8jMYhdaZvdw6nrE8lbavm46inkKoPz0 XpojIbgUNnSdDHF2tYglCBgpOqzOYAfnuxh5h1El5kk0F5P5GPhg3Zag8 juNgoam10DzSeka3MGP5HeS/X1XHwa+h4Fh+OHAo/GCVMLQOH2fOK5Fmf FoEA+/29xuFI7GVi9pzDJe1hs16+yef0RyAGUj5VSsZ823K1MxRVcKJF1 RVFR6c84MIxqI6x2jocF6FiAya/ly5I9Uubli+g5MO/jU/BFxpvHHGzrD Qz82sTrKXIp5AS3lv94uXNumO7QlnPIq85irnnsg8EmJZgjaLLqFNLrcZ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="437645846" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="437645846" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:10:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="685829271" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="685829271" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga003.jf.intel.com with ESMTP; 21 Aug 2023 16:10:34 -0700 Subject: [net-next PATCH v2 6/9] netdev-genl: spec: Add irq in netdev netlink YAML spec From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Mon, 21 Aug 2023 16:25:41 -0700 Message-ID: <169266034176.10199.356738804708103335.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> References: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for interrupt number among the NAPI attributes. Add code generated from the spec. Signed-off-by: Amritha Nambiar --- Documentation/netlink/specs/netdev.yaml | 5 +++++ include/uapi/linux/netdev.h | 1 + tools/include/uapi/linux/netdev.h | 1 + tools/net/ynl/generated/netdev-user.c | 6 ++++++ tools/net/ynl/generated/netdev-user.h | 2 ++ 5 files changed, 15 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index a068cf3b5a7e..aef40397b026 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -91,6 +91,10 @@ attribute-sets: doc: list of tx queues associated with a napi type: u32 multi-attr: true + - + name: irq + doc: The associated interrupt vector number for the napi + type: u32 operations: list: @@ -138,6 +142,7 @@ operations: - ifindex - rx-queues - tx-queues + - irq dump: request: attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 28f6bad7c48e..d31241e155b9 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -53,6 +53,7 @@ enum { NETDEV_A_NAPI_NAPI_ID, NETDEV_A_NAPI_RX_QUEUES, NETDEV_A_NAPI_TX_QUEUES, + NETDEV_A_NAPI_IRQ, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index 28f6bad7c48e..d31241e155b9 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -53,6 +53,7 @@ enum { NETDEV_A_NAPI_NAPI_ID, NETDEV_A_NAPI_RX_QUEUES, NETDEV_A_NAPI_TX_QUEUES, + NETDEV_A_NAPI_IRQ, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index 0cc8c0151b36..a59377c70503 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -64,6 +64,7 @@ struct ynl_policy_attr netdev_napi_policy[NETDEV_A_NAPI_MAX + 1] = { [NETDEV_A_NAPI_NAPI_ID] = { .name = "napi-id", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_RX_QUEUES] = { .name = "rx-queues", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_TX_QUEUES] = { .name = "tx-queues", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_IRQ] = { .name = "irq", .type = YNL_PT_U32, }, }; struct ynl_policy_nest netdev_napi_nest = { @@ -238,6 +239,11 @@ int netdev_napi_get_rsp_parse(const struct nlmsghdr *nlh, void *data) n_rx_queues++; } else if (type == NETDEV_A_NAPI_TX_QUEUES) { n_tx_queues++; + } else if (type == NETDEV_A_NAPI_IRQ) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.irq = 1; + dst->irq = mnl_attr_get_u32(attr); } } diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index 742cb37b6844..9edc5828ca89 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -111,6 +111,7 @@ struct netdev_napi_get_rsp { struct { __u32 napi_id:1; __u32 ifindex:1; + __u32 irq:1; } _present; __u32 napi_id; @@ -119,6 +120,7 @@ struct netdev_napi_get_rsp { __u32 *rx_queues; unsigned int n_tx_queues; __u32 *tx_queues; + __u32 irq; }; void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp); From patchwork Mon Aug 21 23:25:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13359921 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 341E91BF12 for ; Mon, 21 Aug 2023 23:10:42 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C7A1130 for ; Mon, 21 Aug 2023 16:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692659441; x=1724195441; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R4uM3VZfIVpqGLb7VGl7h2R0xjblH0vYFBp/EDmbGpg=; b=PNb3baTCdaxTQAofgOvk0BuD8qp1C5NlujEvbgXeqZIjxXWxfRdS3ENa tmxc/amcB/4O52VcT1A3rtzr3q1Unyl1ULrCYHFLmQMz/R9XRO/m/U6nR +IdO7W/BDt0WE8CdKgnb+nhe8Z3sGD3rnkeM1mKXyNw/FuW0Xqr9yOm+l ozw03EEm74MxlgQw806558p+ZCBUf8mQWCKlERdxiBv8m4AcvV7/0rHJ5 aFRJmpW1jafhAu1Ril+xlTM/6w6JWSn3FyobcYzmCHeVv2TNSKZ9YzVOF 1ke7pBi6TDE527G4ehRJhomEgsNEAhlKC7fHqF5oSscot2DQAsysGaIlY g==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="373698717" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="373698717" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:10:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="982647679" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="982647679" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga006.fm.intel.com with ESMTP; 21 Aug 2023 16:10:40 -0700 Subject: [net-next PATCH v2 7/9] net: Add NAPI IRQ support From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Mon, 21 Aug 2023 16:25:46 -0700 Message-ID: <169266034688.10199.12117427969821291880.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> References: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support to associate the interrupt vector number for a NAPI instance. Signed-off-by: Amritha Nambiar --- drivers/net/ethernet/intel/ice/ice_lib.c | 3 +++ include/linux/netdevice.h | 6 ++++++ net/core/dev.c | 1 + net/core/netdev-genl.c | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index c2b9a25db139..6c86e6ac9dfe 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -2972,6 +2972,9 @@ int ice_q_vector_add_napi_queues(struct ice_q_vector *q_vector) return ret; } + /* Also set the interrupt number for the NAPI */ + napi_set_irq(&q_vector->napi, q_vector->irq.virq); + return ret; } diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 4ec86d9aceb2..60f06bac6d24 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -390,6 +390,7 @@ struct napi_struct { struct hlist_node napi_hash_node; struct list_head napi_rxq_list; struct list_head napi_txq_list; + int irq; }; enum { @@ -2634,6 +2635,11 @@ static inline void *netdev_priv(const struct net_device *dev) */ #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) +static inline void napi_set_irq(struct napi_struct *napi, int irq) +{ + napi->irq = irq; +} + int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index, enum q_type type); diff --git a/net/core/dev.c b/net/core/dev.c index ec4c469c9e1d..10d1f0a07ba2 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6465,6 +6465,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, INIT_LIST_HEAD(&napi->napi_rxq_list); INIT_LIST_HEAD(&napi->napi_txq_list); + napi->irq = -1; } EXPORT_SYMBOL(netif_napi_add_weight); diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 4bc6aa756001..63b8690d8ba3 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -168,7 +168,11 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, goto nla_put_failure; } + if (napi->irq >= 0 && (nla_put_u32(rsp, NETDEV_A_NAPI_IRQ, napi->irq))) + goto nla_put_failure; + genlmsg_end(rsp, hdr); + return 0; nla_put_failure: From patchwork Mon Aug 21 23:25:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13359922 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D408C1BF12 for ; Mon, 21 Aug 2023 23:10:46 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD20B132 for ; Mon, 21 Aug 2023 16:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692659445; x=1724195445; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DYV6vgKNGL/3pniyUBVOvaUjNI3FC7bMVCagc7ynVS0=; b=Yfm4iCYP8TsLWbHsD7mM4cH5+7uDeYYaqXVwccrF36Z59Xcdq8DcgUEC S/okJ55XoVOFZk+wFXD0DRGXnfuUWqzp411OayXw+7XRAO82TnrJVm/rM iSrf8B8sCtDmv395hUl+K24kIKER/V5Aujb5L7N1O8ki1A+6rBk5mJfQb oTSyuliazoec14kPx0AJGV2aWUhVw1bE7gKSsdsaZwS1uR6eHE1N8lGu5 Hzu9StB1GKxQzzTL19Pk2fKP2JnPhfcnolDgi9nR/uGkdaAkfJ75bqNxI e/fgL4dwjvHp/f/VRmBJzSEMz936yW8wujiXjy0B7Kw2YYVzpIcYfveKb A==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="373698744" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="373698744" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:10:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="982647709" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="982647709" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga006.fm.intel.com with ESMTP; 21 Aug 2023 16:10:45 -0700 Subject: [net-next PATCH v2 8/9] netdev-genl: spec: Add PID in netdev netlink YAML spec From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Mon, 21 Aug 2023 16:25:52 -0700 Message-ID: <169266035228.10199.6686102970974174171.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> References: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for PID of the NAPI thread. Add code generated from the spec. Signed-off-by: Amritha Nambiar --- Documentation/netlink/specs/netdev.yaml | 5 +++++ include/uapi/linux/netdev.h | 1 + tools/include/uapi/linux/netdev.h | 1 + tools/net/ynl/generated/netdev-user.c | 6 ++++++ tools/net/ynl/generated/netdev-user.h | 2 ++ 5 files changed, 15 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index aef40397b026..3472f086d523 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -95,6 +95,10 @@ attribute-sets: name: irq doc: The associated interrupt vector number for the napi type: u32 + - + name: pid + doc: PID of the napi thread + type: s32 operations: list: @@ -143,6 +147,7 @@ operations: - rx-queues - tx-queues - irq + - pid dump: request: attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index d31241e155b9..b87ec27b2741 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -54,6 +54,7 @@ enum { NETDEV_A_NAPI_RX_QUEUES, NETDEV_A_NAPI_TX_QUEUES, NETDEV_A_NAPI_IRQ, + NETDEV_A_NAPI_PID, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index d31241e155b9..b87ec27b2741 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -54,6 +54,7 @@ enum { NETDEV_A_NAPI_RX_QUEUES, NETDEV_A_NAPI_TX_QUEUES, NETDEV_A_NAPI_IRQ, + NETDEV_A_NAPI_PID, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index a59377c70503..53a52055453d 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -65,6 +65,7 @@ struct ynl_policy_attr netdev_napi_policy[NETDEV_A_NAPI_MAX + 1] = { [NETDEV_A_NAPI_RX_QUEUES] = { .name = "rx-queues", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_TX_QUEUES] = { .name = "tx-queues", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_IRQ] = { .name = "irq", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_PID] = { .name = "pid", .type = YNL_PT_U32, }, }; struct ynl_policy_nest netdev_napi_nest = { @@ -244,6 +245,11 @@ int netdev_napi_get_rsp_parse(const struct nlmsghdr *nlh, void *data) return MNL_CB_ERROR; dst->_present.irq = 1; dst->irq = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_NAPI_PID) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.pid = 1; + dst->pid = mnl_attr_get_u32(attr); } } diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index 9edc5828ca89..b3bbcdd5b669 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -112,6 +112,7 @@ struct netdev_napi_get_rsp { __u32 napi_id:1; __u32 ifindex:1; __u32 irq:1; + __u32 pid:1; } _present; __u32 napi_id; @@ -121,6 +122,7 @@ struct netdev_napi_get_rsp { unsigned int n_tx_queues; __u32 *tx_queues; __u32 irq; + __s32 pid; }; void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp); From patchwork Mon Aug 21 23:25:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13359923 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FB701BF12 for ; Mon, 21 Aug 2023 23:10:52 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D49B130 for ; Mon, 21 Aug 2023 16:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692659451; x=1724195451; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OGRwt/afkyciGEHiVZ0pigIUDa54bQ+/IzJuRhPuc5g=; b=PskFao0pRzNkqkVQEhKjEySeh9n9ihm3lw90rQsrWx9OHM/RjHco2cQ6 Ip+zajxxhRu06pCNyMFKGQmCNbLGeg8KS+onFxFZknDzTndTNw00TKvir 9rpB0IRRTwpqkd7IIuOcZN8x10/4DCXHpEWqEH5YezXKSAOkuQ386ywEf +9kUzW/2pJrmSnTRQoc1zMiCNqKH0Bu2FiF9CNX7EBucw/6r3qmD8FQlR 0OSwHPrFoIcchqppNMEAzqpv3USUWensZLuQ960EBiXnkQh+ALFEoyok7 01IVJ8NzmA6WuKZa02gKZUcC4+QT3+Hwi2b1TE/n6+sXZeDBRfmE17CRx w==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="373698769" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="373698769" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:10:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="982647741" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="982647741" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga006.fm.intel.com with ESMTP; 21 Aug 2023 16:10:50 -0700 Subject: [net-next PATCH v2 9/9] netdev-genl: Add PID for the NAPI thread From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Mon, 21 Aug 2023 16:25:57 -0700 Message-ID: <169266035756.10199.12776067447174397659.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> References: <169266003844.10199.10450480941022607696.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org In the threaded NAPI mode, expose the PID of the NAPI thread. Signed-off-by: Amritha Nambiar --- net/core/netdev-genl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 63b8690d8ba3..47be577782e4 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -141,6 +141,7 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, struct netdev_rx_queue *rx_queue, *rxq; struct netdev_queue *tx_queue, *txq; unsigned int rx_qid, tx_qid; + pid_t pid; void *hdr; if (!napi->dev) @@ -171,6 +172,12 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, if (napi->irq >= 0 && (nla_put_u32(rsp, NETDEV_A_NAPI_IRQ, napi->irq))) goto nla_put_failure; + if (napi->thread) { + pid = task_pid_nr(napi->thread); + if (nla_put_s32(rsp, NETDEV_A_NAPI_PID, pid)) + goto nla_put_failure; + } + genlmsg_end(rsp, hdr); return 0;