From patchwork Fri Jan 3 18:59:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13925818 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2B74A1FBC97 for ; Fri, 3 Jan 2025 18:59:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930800; cv=none; b=EJh3w0UnXli+nrhYsPp5uNORtCp1pCmAzOzgBESyF1fJIpGJrAWSUf5D5cfqSTWwQawsDT2i+fkgv7VV3Cl3pNLG8WjBixYHuw5WGccaZv0vMxYp75idsUyx6lvDolE8qtF1RXyUnq4kmSOOcAKpf/orhz7epKNFgaR5STQCOK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930800; c=relaxed/simple; bh=hu7EJAQ65piJvg4PzI7AJMlpKtDBcmVQhUaYx2F/CSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PMTLS4WD+GfGkLtge6j6zCyuUks7LWlczeaCUrJ44SApmTtldp+HKcKQYxiRDfqcZ9U2BcgS4cHvBlaMWjCvDeHAy08GkbzbLqOZtaYEjx5xRg5JD14uYQoEB+fFJYNUlrXcxDZjbZMfZEAANB8w0iffE1DjAEwv+gI8KXK5nu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EYyPyxsu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EYyPyxsu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C2ACC4CEDC; Fri, 3 Jan 2025 18:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735930799; bh=hu7EJAQ65piJvg4PzI7AJMlpKtDBcmVQhUaYx2F/CSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EYyPyxsug7xZvR3zC7UJcMyTU41wdcdekauDgPf70WMyBohrslCtsYntIBhUa8oj6 4n/I3UOlGR4oNtGJaVkIaz4Sb6eujBGNCCM2suZh7KmXXTiHTG4ytsDzUbZMe0bsTv xqJY2V0v/jjK9tP0Wd3p+0LsuTrnbvnLpHf6wJZjE0Q6o0hT5eSfiZciCBWA9CFJFO S2S0BcO1uXc4PMX54Zcrq9i9hZfHHsCXclHpyv1gz7ggCZzjgYLyhoC8pMIvpUmdBW Z8chrvYGmkNH0OHWiaGr0+6ndVogjQolQ6v49nVllqRIv3h2jxZKjlTCWL6UyhB5tq WRNls9CfT4GoA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, dw@davidwei.uk, almasrymina@google.com, jdamato@fastly.com, Jakub Kicinski Subject: [PATCH net-next 1/8] net: make sure we retain NAPI ordering on netdev->napi_list Date: Fri, 3 Jan 2025 10:59:46 -0800 Message-ID: <20250103185954.1236510-2-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103185954.1236510-1-kuba@kernel.org> References: <20250103185954.1236510-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Netlink code depends on NAPI instances being sorted by ID on the netdev list for dump continuation. We need to be able to find the position on the list where we left off if dump does not fit in a single skb, and in the meantime NAPI instances can come and go. This was trivially true when we were assigning a new ID to every new NAPI instance. Since we added the NAPI config API, we try to retain the ID previously used for the same queue, but still add the new NAPI instance at the start of the list. This is fine if we reset the entire netdev and all NAPIs get removed and added back. If driver replaces a NAPI instance during an operation like DEVMEM queue reset, or recreates a subset of NAPI instances in other ways we may end up with broken ordering, and therefore Netlink dumps with either missing or duplicated entries. At this stage the problem is theoretical. Only two drivers support queue API, bnxt and gve. gve recreates NAPIs during queue reset, but it doesn't support NAPI config. bnxt supports NAPI config but doesn't recreate instances during reset. We need to save the ID in the config as soon as it is assigned because otherwise the new NAPI will not know what ID it will get at enable time, at the time it is being added. Signed-off-by: Jakub Kicinski Reviewed-by: Eric Dumazet --- net/core/dev.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index faa23042df38..dffa8f71d5cc 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6713,13 +6713,14 @@ static void napi_restore_config(struct napi_struct *n) n->gro_flush_timeout = n->config->gro_flush_timeout; n->irq_suspend_timeout = n->config->irq_suspend_timeout; /* a NAPI ID might be stored in the config, if so use it. if not, use - * napi_hash_add to generate one for us. It will be saved to the config - * in napi_disable. + * napi_hash_add to generate one for us. */ - if (n->config->napi_id) + if (n->config->napi_id) { napi_hash_add_with_id(n, n->config->napi_id); - else + } else { napi_hash_add(n); + n->config->napi_id = n->napi_id; + } } static void napi_save_config(struct napi_struct *n) @@ -6727,10 +6728,39 @@ static void napi_save_config(struct napi_struct *n) n->config->defer_hard_irqs = n->defer_hard_irqs; n->config->gro_flush_timeout = n->gro_flush_timeout; n->config->irq_suspend_timeout = n->irq_suspend_timeout; - n->config->napi_id = n->napi_id; napi_hash_del(n); } +/* Netlink wants the NAPI list to be sorted by ID, if adding a NAPI which will + * inherit an existing ID try to insert it at the right position. + */ +static void +netif_napi_dev_list_add(struct net_device *dev, struct napi_struct *napi) +{ + unsigned int new_id, pos_id; + struct list_head *higher; + struct napi_struct *pos; + + new_id = UINT_MAX; + if (napi->config && napi->config->napi_id) + new_id = napi->config->napi_id; + + higher = &dev->napi_list; + list_for_each_entry(pos, &dev->napi_list, dev_list) { + if (pos->napi_id >= MIN_NAPI_ID) + pos_id = pos->napi_id; + else if (pos->config) + pos_id = pos->config->napi_id; + else + pos_id = UINT_MAX; + + if (pos_id <= new_id) + break; + higher = &pos->dev_list; + } + list_add_rcu(&napi->dev_list, higher); /* adds after higher */ +} + void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight) { @@ -6757,7 +6787,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, napi->list_owner = -1; set_bit(NAPI_STATE_SCHED, &napi->state); set_bit(NAPI_STATE_NPSVC, &napi->state); - list_add_rcu(&napi->dev_list, &dev->napi_list); + netif_napi_dev_list_add(dev, napi); /* default settings from sysfs are applied to all NAPIs. any per-NAPI * configuration will be loaded in napi_enable From patchwork Fri Jan 3 18:59:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13925819 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8C21B1FC7DF for ; Fri, 3 Jan 2025 19:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930800; cv=none; b=WuOZCK4qnHerOVljv/qr/rZ0NDN/u/4kQBj3CfAJmgWRfy4Pl1+L6jsWOW641tWZP7IA+jn1m86/8Fjj6P6NzFnZ31UgiVvfrkUubNDQQ8ze4IEytjpurRABPkFpcDmSRNOzmqNGxPi2UZj/h9kC2UxsVKATlLrmvXdXiIDUSEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930800; c=relaxed/simple; bh=sOmE9/sMV0g5Q2kmkrnlKjdUKpmYLt+d0ahRY+RFwi0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gWKhdkwQ7Y6Rz+hgl5jQSyYgXX8qAMy3bJMyZ8p8qeJwsp/JnqmEpJYBegDCNOjGj7hHIkjgi1rxcrH2md4mrIxNhBzpWmsH92s0GKRhCBdYLqYqEBA4n7A+0i31cDBVy1CPEuhMBW3aRQDXOA7V2w8r3+jaAMPPb0x9VL3pR/g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S5dF5NOz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S5dF5NOz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB36CC4CEDE; Fri, 3 Jan 2025 18:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735930800; bh=sOmE9/sMV0g5Q2kmkrnlKjdUKpmYLt+d0ahRY+RFwi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S5dF5NOzHkVQ3t8b6JOnVa76IqpnBdcb5ScdE15DX0vSBDejxjqpRH6t5amEbp1tW 2wttXiwNf8vI1wl2MwRoftYbBz14UHtaPqUaU0rou5RR1C/6GfhmGuAdJbzU/nlqk2 fgMxlkZSE9QGReS8JBj8Vpw/P55E+H6+RxIzJeIftoheuQR6iN0teTqlaj5aUTiQXI b3C7osc+KkvQrXjtfnt2AncQrskdUX6XxR1HcY/U9LgfDbdOHh4jarkxTpGgy35mKz LkFdg1IbPszYfIryW8XFf6ykIDR7x4dNpMtDY70YDACUHneMmxu+AlqsTYhLD5MC4d NDycvhc20C6rA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, dw@davidwei.uk, almasrymina@google.com, jdamato@fastly.com, Jakub Kicinski Subject: [PATCH net-next 2/8] netdev: define NETDEV_INTERNAL Date: Fri, 3 Jan 2025 10:59:47 -0800 Message-ID: <20250103185954.1236510-3-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103185954.1236510-1-kuba@kernel.org> References: <20250103185954.1236510-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Linus suggested during one of past maintainer summits (in context of a DMA_BUF discussion) that symbol namespaces can be used to prevent unwelcome but in-tree code from using all exported functions. Create a namespace for netdev. Export netdev_rx_queue_restart(), drivers may want to use it since it gives them a simple and safe way to restart a queue to apply config changes. But it's both too low level and too actively developed to be used outside netdev. Signed-off-by: Jakub Kicinski Reviewed-by: Eric Dumazet --- Documentation/networking/netdevices.rst | 10 ++++++++++ net/core/netdev_rx_queue.c | 1 + 2 files changed, 11 insertions(+) diff --git a/Documentation/networking/netdevices.rst b/Documentation/networking/netdevices.rst index 857c9784f87e..1d37038e9fbe 100644 --- a/Documentation/networking/netdevices.rst +++ b/Documentation/networking/netdevices.rst @@ -297,3 +297,13 @@ struct napi_struct synchronization rules Context: softirq will be called with interrupts disabled by netconsole. + +NETDEV_INTERNAL symbol namespace +================================ + +Symbols exported as NETDEV_INTERNAL can only be used in networking +core and drivers which exclusively flow via the main networking list and trees. +Note that the inverse is not true, most symbols outside of NETDEV_INTERNAL +are not expected to be used by random code outside netdev either. +Symbols may lack the designation because they predate the namespaces, +or simply due to an oversight. diff --git a/net/core/netdev_rx_queue.c b/net/core/netdev_rx_queue.c index e217a5838c87..db82786fa0c4 100644 --- a/net/core/netdev_rx_queue.c +++ b/net/core/netdev_rx_queue.c @@ -79,3 +79,4 @@ int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx) return err; } +EXPORT_SYMBOL_NS_GPL(netdev_rx_queue_restart, "NETDEV_INTERNAL"); From patchwork Fri Jan 3 18:59:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13925820 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D483D1FC7EE for ; Fri, 3 Jan 2025 19:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930800; cv=none; b=jXxQYvA3YCBP8DetWUF29CCgh5H9z0I3DWZGZg4svl351xlk6PZ5jAo/TChi9Y/fnsenVhLhUbVwIxqntY/uWoJd+wMC1QeifLUasLJVSY2OZGrf4/T8Xzqzy6plEA7j73yroVnXMMH2c9aemKx6YIOUiBnzVAM89xRJdJ3If6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930800; c=relaxed/simple; bh=tV5zLWFMk8yMVzcMw10uFwKyi2eIAuQKaTNRMYjBWm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nMQHOTA3Ei1vpTgDBac06hkhgdaMkL+qRCzatWBVvBU9oXpky717pJoY+9Mvvm1tvGs5NO3O7HSTYIeAyicv+XiVB/q55eOov7JipoJkjTu9Rsl6QLhQVgGSXjhGIwmADkjUYzmfiyhNUJpPF5+MDAujfAp23L5dfT/QNGJJX3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l7gUAA2v; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l7gUAA2v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4763BC4CED7; Fri, 3 Jan 2025 19:00:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735930800; bh=tV5zLWFMk8yMVzcMw10uFwKyi2eIAuQKaTNRMYjBWm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l7gUAA2v87H4oZ1lM5rk0Ttv53daGpVzh4SJS+eaThmYRPdRPPm4mTrsku/vePSSL TQSgumoFkFaX5mFcaTorOkh34JV6SraPvhygyXYCTGdCJsACm6N4oPtgE08FHXh1TQ n4n2rlOo2gZaYGXfpKOxL+xb9Fgg1t6MKkym3eQlNIRFjtgLNLGD+5ib6c2V4ilGMw guAzZ8x8i/DVvx+zGblDJ3iXqozdYHSKRG8MIwQ1GFdLztjvjg7yRPc/mrBHaG4SMg MfugaYvnrHJrQ6RijoAVeSVlf2vqmM2sXsPSw5q2QSLh4rbAARBAk011+92xlTvKeb JTfa8L9i9ubDA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, dw@davidwei.uk, almasrymina@google.com, jdamato@fastly.com, Jakub Kicinski Subject: [PATCH net-next 3/8] netdevsim: support NAPI config Date: Fri, 3 Jan 2025 10:59:48 -0800 Message-ID: <20250103185954.1236510-4-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103185954.1236510-1-kuba@kernel.org> References: <20250103185954.1236510-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Link the NAPI instances to their configs. This will be needed to test that NAPI config doesn't break list ordering. Signed-off-by: Jakub Kicinski Reviewed-by: Eric Dumazet --- drivers/net/netdevsim/netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index e068a9761c09..a4aacd372cdd 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -390,7 +390,7 @@ static int nsim_init_napi(struct netdevsim *ns) for (i = 0; i < dev->num_rx_queues; i++) { rq = &ns->rq[i]; - netif_napi_add(dev, &rq->napi, nsim_poll); + netif_napi_add_config(dev, &rq->napi, nsim_poll, i); } for (i = 0; i < dev->num_rx_queues; i++) { From patchwork Fri Jan 3 18:59:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13925821 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5F2161FCD04 for ; Fri, 3 Jan 2025 19:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930801; cv=none; b=KbkYScUNpHQGxQdGR82L7gJ1lEAN4s3uahAMR/69Cr4P7HcXg+k/sCj2Z7sJii9WwFlyRcxkdz3EExo8WVjR0NoLhHbR8Pj7251wL4mTTYUSVajaJU97rC5xA7plnbrU4pVrIjlj+DEAshfsroApB8KW/YpdNle6w9foyGSGa8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930801; c=relaxed/simple; bh=lWdqjdz3Q8Z/bU1gvZsxjA8UZ68ZbhNo/PSacBzpivI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fY+p2th9zqHR6f/aA+DMgFoVNQQwQ5usss36IcPur5GA7SyrTbiS9fDUezCNtrjrbOtXQZ6KyztnYGwo5cejLo1HqvzXXJzGcIoySoJd8P7auMmGlrYR3lq74sIh/TfGsd6p8URuZplA+jnKNhb/6dxaTlu6eirN4oPG1hO8SZU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nk1UHclc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nk1UHclc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A564EC4CEE1; Fri, 3 Jan 2025 19:00:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735930800; bh=lWdqjdz3Q8Z/bU1gvZsxjA8UZ68ZbhNo/PSacBzpivI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nk1UHclcADbbLcCV6az8q4jhMqvESb/qDLpiZA/q8jSZjALlTxO17fZFoM22g6uvG ZLHRytO6VR7Sifc3ubLPxSr5g1/vTkA7psN7d0QO7/0TOoECz+2UKgV1usYIi6vtJE y9vew+iSenyTd1K69hsnkFImkA208JuJ2t1EJ7JaGPSbDQ0EW1VoqssoQ+QMMRG4Ti wLaVIei+QkM2Lsf+XWH7qUCwFyRpOjBn0uX/g4zbcUUoDSbHIcCw3xo6SeqUyqmklc 5soK5QEoZwLCg6xPnFgTkCQcWMqA6ozsyGFt6Q+kMIUomzc+9a3ATRmYPae/eN7zYK vbRwXzP6KcSpA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, dw@davidwei.uk, almasrymina@google.com, jdamato@fastly.com, Jakub Kicinski Subject: [PATCH net-next 4/8] netdevsim: allocate rqs individually Date: Fri, 3 Jan 2025 10:59:49 -0800 Message-ID: <20250103185954.1236510-5-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103185954.1236510-1-kuba@kernel.org> References: <20250103185954.1236510-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Make nsim->rqs an array of pointers and allocate them individually so that we can swap them out one by one. Signed-off-by: Jakub Kicinski Reviewed-by: Eric Dumazet --- drivers/net/netdevsim/netdev.c | 43 ++++++++++++++++++++----------- drivers/net/netdevsim/netdevsim.h | 2 +- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index a4aacd372cdd..7487697ac417 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -69,7 +69,7 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev) rxq = skb_get_queue_mapping(skb); if (rxq >= peer_dev->num_rx_queues) rxq = rxq % peer_dev->num_rx_queues; - rq = &peer_ns->rq[rxq]; + rq = peer_ns->rq[rxq]; skb_tx_timestamp(skb); if (unlikely(nsim_forward_skb(peer_dev, skb, rq) == NET_RX_DROP)) @@ -388,13 +388,13 @@ static int nsim_init_napi(struct netdevsim *ns) int err, i; for (i = 0; i < dev->num_rx_queues; i++) { - rq = &ns->rq[i]; + rq = ns->rq[i]; netif_napi_add_config(dev, &rq->napi, nsim_poll, i); } for (i = 0; i < dev->num_rx_queues; i++) { - rq = &ns->rq[i]; + rq = ns->rq[i]; err = nsim_create_page_pool(rq); if (err) @@ -405,12 +405,12 @@ static int nsim_init_napi(struct netdevsim *ns) err_pp_destroy: while (i--) { - page_pool_destroy(ns->rq[i].page_pool); - ns->rq[i].page_pool = NULL; + page_pool_destroy(ns->rq[i]->page_pool); + ns->rq[i]->page_pool = NULL; } for (i = 0; i < dev->num_rx_queues; i++) - __netif_napi_del(&ns->rq[i].napi); + __netif_napi_del(&ns->rq[i]->napi); return err; } @@ -421,7 +421,7 @@ static void nsim_enable_napi(struct netdevsim *ns) int i; for (i = 0; i < dev->num_rx_queues; i++) { - struct nsim_rq *rq = &ns->rq[i]; + struct nsim_rq *rq = ns->rq[i]; netif_queue_set_napi(dev, i, NETDEV_QUEUE_TYPE_RX, &rq->napi); napi_enable(&rq->napi); @@ -448,7 +448,7 @@ static void nsim_del_napi(struct netdevsim *ns) int i; for (i = 0; i < dev->num_rx_queues; i++) { - struct nsim_rq *rq = &ns->rq[i]; + struct nsim_rq *rq = ns->rq[i]; napi_disable(&rq->napi); __netif_napi_del(&rq->napi); @@ -456,8 +456,8 @@ static void nsim_del_napi(struct netdevsim *ns) synchronize_net(); for (i = 0; i < dev->num_rx_queues; i++) { - page_pool_destroy(ns->rq[i].page_pool); - ns->rq[i].page_pool = NULL; + page_pool_destroy(ns->rq[i]->page_pool); + ns->rq[i]->page_pool = NULL; } } @@ -628,7 +628,7 @@ nsim_pp_hold_write(struct file *file, const char __user *data, if (!netif_running(ns->netdev) && val) { ret = -ENETDOWN; } else if (val) { - ns->page = page_pool_dev_alloc_pages(ns->rq[0].page_pool); + ns->page = page_pool_dev_alloc_pages(ns->rq[0]->page_pool); if (!ns->page) ret = -ENOMEM; } else { @@ -682,10 +682,21 @@ static int nsim_queue_init(struct netdevsim *ns) if (!ns->rq) return -ENOMEM; - for (i = 0; i < dev->num_rx_queues; i++) - skb_queue_head_init(&ns->rq[i].skb_queue); + for (i = 0; i < dev->num_rx_queues; i++) { + ns->rq[i] = kzalloc(sizeof(**ns->rq), GFP_KERNEL); + if (!ns->rq[i]) + goto err_free_prev; + + skb_queue_head_init(&ns->rq[i]->skb_queue); + } return 0; + +err_free_prev: + while (i--) + kfree(ns->rq[i]); + kfree(ns->rq); + return -ENOMEM; } static void nsim_queue_free(struct netdevsim *ns) @@ -693,9 +704,11 @@ static void nsim_queue_free(struct netdevsim *ns) struct net_device *dev = ns->netdev; int i; - for (i = 0; i < dev->num_rx_queues; i++) - skb_queue_purge_reason(&ns->rq[i].skb_queue, + for (i = 0; i < dev->num_rx_queues; i++) { + skb_queue_purge_reason(&ns->rq[i]->skb_queue, SKB_DROP_REASON_QUEUE_PURGE); + kfree(ns->rq[i]); + } kvfree(ns->rq); ns->rq = NULL; diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index bf02efa10956..80fde64f4a7a 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -101,7 +101,7 @@ struct netdevsim { struct nsim_dev *nsim_dev; struct nsim_dev_port *nsim_dev_port; struct mock_phc *phc; - struct nsim_rq *rq; + struct nsim_rq **rq; u64 tx_packets; u64 tx_bytes; From patchwork Fri Jan 3 18:59:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13925822 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9AF6B1FCD16 for ; Fri, 3 Jan 2025 19:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930801; cv=none; b=BLhpElNTUxacuW9sh42uvJl9qxkspErdHpSradHqUPpbnNKz+Jvj25hWD2VFZasvy24NjBLMiCvCsYPiY2Pu/FKFIbzaa+7SVARTv6HFZtAr8tRJ5HKCuePZPE4uhDn2lVdfG70tIWv4lQzudm74oO/qT0+GUHq2XAHO+fDX3os= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930801; c=relaxed/simple; bh=+QdaajbVH+JdcdBgna3omp4zm8NtLGUZk29mchUZBK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ebpDqsSpzXZ8fB5KAbIq+a5jb7x9VebXU5ONM/1ZoXzi1Wmbo/8Qxa7KS8XRUVnhxRAzh6bMGuRfvcaOpOceV6iq+astDN8dtsPaOe7cuPC9MSsfFZQ70goZkZskTKNjWXEc/lTLMbTa0OwLhAVNHmuH4fErlrSBoF5m33BBumg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oe0Ts7x8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oe0Ts7x8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 100C3C4CEDC; Fri, 3 Jan 2025 19:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735930801; bh=+QdaajbVH+JdcdBgna3omp4zm8NtLGUZk29mchUZBK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oe0Ts7x80G1j1O00E7OoH1YUDdJimoT0lMh5rZldDNWbuxI3/ogI7VgYjtQ77qoFn qYbkciZ6xm5IU2TXs5I4OnjnMJEa7/6fseBIKOSjWubcIaO97nFOPiYpu2Ocauy0E6 niKI6Cfx6Ly8RaL0reWbrLZbjBx9gm/bwDti+HwoXqzqvRUQbc5cxb4HQXtRbO2p4I 1eF9y0Mfz0loE0M/DNDM7BrgUfHpo03x4Su2wJsSrl4smdqw2CjJSLsaSXmovdGJh8 BnbNONjlw0Cjh8doLFb3SIR4TOr1/gV7O/NQaQGtPJ0rrvdN7jzospvzFMkqkE7wP7 /CHRrL7AAISlg== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, dw@davidwei.uk, almasrymina@google.com, jdamato@fastly.com, Jakub Kicinski Subject: [PATCH net-next 5/8] netdevsim: add queue alloc/free helpers Date: Fri, 3 Jan 2025 10:59:50 -0800 Message-ID: <20250103185954.1236510-6-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103185954.1236510-1-kuba@kernel.org> References: <20250103185954.1236510-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org We'll need the code to allocate and free queues in the queue management API, factor it out. Signed-off-by: Jakub Kicinski Reviewed-by: Eric Dumazet --- drivers/net/netdevsim/netdev.c | 35 +++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 7487697ac417..e1bd3c1563b7 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -595,6 +595,24 @@ static const struct netdev_stat_ops nsim_stat_ops = { .get_base_stats = nsim_get_base_stats, }; +static struct nsim_rq *nsim_queue_alloc(void) +{ + struct nsim_rq *rq; + + rq = kzalloc(sizeof(*rq), GFP_KERNEL); + if (!rq) + return NULL; + + skb_queue_head_init(&rq->skb_queue); + return rq; +} + +static void nsim_queue_free(struct nsim_rq *rq) +{ + skb_queue_purge_reason(&rq->skb_queue, SKB_DROP_REASON_QUEUE_PURGE); + kfree(rq); +} + static ssize_t nsim_pp_hold_read(struct file *file, char __user *data, size_t count, loff_t *ppos) @@ -683,11 +701,9 @@ static int nsim_queue_init(struct netdevsim *ns) return -ENOMEM; for (i = 0; i < dev->num_rx_queues; i++) { - ns->rq[i] = kzalloc(sizeof(**ns->rq), GFP_KERNEL); + ns->rq[i] = nsim_queue_alloc(); if (!ns->rq[i]) goto err_free_prev; - - skb_queue_head_init(&ns->rq[i]->skb_queue); } return 0; @@ -699,16 +715,13 @@ static int nsim_queue_init(struct netdevsim *ns) return -ENOMEM; } -static void nsim_queue_free(struct netdevsim *ns) +static void nsim_queue_uninit(struct netdevsim *ns) { struct net_device *dev = ns->netdev; int i; - for (i = 0; i < dev->num_rx_queues; i++) { - skb_queue_purge_reason(&ns->rq[i]->skb_queue, - SKB_DROP_REASON_QUEUE_PURGE); - kfree(ns->rq[i]); - } + for (i = 0; i < dev->num_rx_queues; i++) + nsim_queue_free(ns->rq[i]); kvfree(ns->rq); ns->rq = NULL; @@ -754,7 +767,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns) nsim_macsec_teardown(ns); nsim_bpf_uninit(ns); err_rq_destroy: - nsim_queue_free(ns); + nsim_queue_uninit(ns); err_utn_destroy: rtnl_unlock(); nsim_udp_tunnels_info_destroy(ns->netdev); @@ -836,7 +849,7 @@ void nsim_destroy(struct netdevsim *ns) nsim_macsec_teardown(ns); nsim_ipsec_teardown(ns); nsim_bpf_uninit(ns); - nsim_queue_free(ns); + nsim_queue_uninit(ns); } rtnl_unlock(); if (nsim_dev_port_is_pf(ns->nsim_dev_port)) From patchwork Fri Jan 3 18:59:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13925823 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2930D1FCF7D for ; Fri, 3 Jan 2025 19:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930802; cv=none; b=Z8Db6blLwlWB7wvBzn+FGt/k1xqeqHzK5s5dlW6R8AcEiXvbJWY7gtSzavhscEkYxxCzEbOB3HACmEmkiRztUqHrCjz3OKO901+7D6GzvR4r+xuwxb4Wbp7N0iumNSUJMG0IlmsRi6kGVzArL8EDB2Di2OzL/ff6BlE6e7oJEq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930802; c=relaxed/simple; bh=GB8er5N5aTfpvBvUiPDisLOcyXBV9UmnYw5M58Mqxm8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FpRhtaKYwKtAVn3l2xl5gZMtZ77Cy/znJV8S0QwhQ3dw7r79WOU3/w3uJdF3WcKuP7G1BsG3xyjHN7SxMV+Z/yLwCPwb9R/ROke+DiUtCowaCNlt91eeTnOZA1SdDo1WWfHagWl1p1pGWNBCUMz3l6LzMMLb7qiPjEd6XguwugY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RrUZ2hbv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RrUZ2hbv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 700C8C4CED2; Fri, 3 Jan 2025 19:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735930801; bh=GB8er5N5aTfpvBvUiPDisLOcyXBV9UmnYw5M58Mqxm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RrUZ2hbvd4FKwJZhecauxtaR54xSD8HBB4RrBhNfXFeKBMl5StYOvSB/uvvZ+VwIT FpTGXbuHwb5T909aKcLWkGlEn/OKy8ahX1VQEHqrvwciXzMfk/8OIfTBltX3mvaYRT AKJrihzXeUMM5rCNG+wfwzFvXZg/ofdxHvXzvSd39KNkUlhqg5qRvehFKcWQmM+F92 PtWGS/k7owFF+iXdcnvmcmHqV60zor4c5Tkq/0O0MHpvLJ5ZYj+wX6CkWqeM+NTUvY 2/9SbxsUXW4hP0ehOsfYJanKkQSZtb0QWmxt8diqIqiJr1RcOrIkOKJjeZyiNpReLl bUl9G4vmGpK4w== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, dw@davidwei.uk, almasrymina@google.com, jdamato@fastly.com, Jakub Kicinski Subject: [PATCH net-next 6/8] netdevsim: add queue management API support Date: Fri, 3 Jan 2025 10:59:51 -0800 Message-ID: <20250103185954.1236510-7-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103185954.1236510-1-kuba@kernel.org> References: <20250103185954.1236510-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add queue management API support. We need a way to reset queues to test NAPI reordering, the queue management API provides a handy scaffolding for that. Signed-off-by: Jakub Kicinski Acked-by: Stanislav Fomichev --- drivers/net/netdevsim/netdev.c | 135 +++++++++++++++++++++++++++--- drivers/net/netdevsim/netdevsim.h | 2 + 2 files changed, 125 insertions(+), 12 deletions(-) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index e1bd3c1563b7..86614292314a 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -359,25 +359,24 @@ static int nsim_poll(struct napi_struct *napi, int budget) return done; } -static int nsim_create_page_pool(struct nsim_rq *rq) +static int nsim_create_page_pool(struct page_pool **p, struct napi_struct *napi) { - struct page_pool_params p = { + struct page_pool_params params = { .order = 0, .pool_size = NSIM_RING_SIZE, .nid = NUMA_NO_NODE, - .dev = &rq->napi.dev->dev, - .napi = &rq->napi, + .dev = &napi->dev->dev, + .napi = napi, .dma_dir = DMA_BIDIRECTIONAL, - .netdev = rq->napi.dev, + .netdev = napi->dev, }; + struct page_pool *pool; - rq->page_pool = page_pool_create(&p); - if (IS_ERR(rq->page_pool)) { - int err = PTR_ERR(rq->page_pool); + pool = page_pool_create(¶ms); + if (IS_ERR(pool)) + return PTR_ERR(pool); - rq->page_pool = NULL; - return err; - } + *p = pool; return 0; } @@ -396,7 +395,7 @@ static int nsim_init_napi(struct netdevsim *ns) for (i = 0; i < dev->num_rx_queues; i++) { rq = ns->rq[i]; - err = nsim_create_page_pool(rq); + err = nsim_create_page_pool(&rq->page_pool, &rq->napi); if (err) goto err_pp_destroy; } @@ -613,6 +612,117 @@ static void nsim_queue_free(struct nsim_rq *rq) kfree(rq); } +/* Queue reset mode is controled by ns->rq_reset_mode. + * - normal - new NAPI new pool (old NAPI enabled when new added) + * - mode 1 - allocate new pool (NAPI is only disabled / enabled) + * - mode 2 - new NAPI new pool (old NAPI removed before new added) + * - mode 3 - new NAPI new pool (old NAPI disabled when new added) + */ +struct nsim_queue_mem { + struct nsim_rq *rq; + struct page_pool *pp; +}; + +static int +nsim_queue_mem_alloc(struct net_device *dev, void *per_queue_mem, int idx) +{ + struct nsim_queue_mem *qmem = per_queue_mem; + struct netdevsim *ns = netdev_priv(dev); + int err; + + if (ns->rq_reset_mode > 3) + return -EINVAL; + + if (ns->rq_reset_mode == 1) + return nsim_create_page_pool(&qmem->pp, &ns->rq[idx]->napi); + + qmem->rq = nsim_queue_alloc(); + if (!qmem->rq) + return -ENOMEM; + + err = nsim_create_page_pool(&qmem->rq->page_pool, &qmem->rq->napi); + if (err) + goto err_free; + + if (!ns->rq_reset_mode) + netif_napi_add_config(dev, &qmem->rq->napi, nsim_poll, idx); + + return 0; + +err_free: + nsim_queue_free(qmem->rq); + return err; +} + +static void nsim_queue_mem_free(struct net_device *dev, void *per_queue_mem) +{ + struct nsim_queue_mem *qmem = per_queue_mem; + struct netdevsim *ns = netdev_priv(dev); + + if (qmem->pp) + page_pool_destroy(qmem->pp); + if (qmem->rq) { + if (!ns->rq_reset_mode) + netif_napi_del(&qmem->rq->napi); + page_pool_destroy(qmem->rq->page_pool); + nsim_queue_free(qmem->rq); + } +} + +static int +nsim_queue_start(struct net_device *dev, void *per_queue_mem, int idx) +{ + struct nsim_queue_mem *qmem = per_queue_mem; + struct netdevsim *ns = netdev_priv(dev); + + if (ns->rq_reset_mode == 1) { + ns->rq[idx]->page_pool = qmem->pp; + napi_enable(&ns->rq[idx]->napi); + return 0; + } + + /* netif_napi_add()/_del() should normally be called from alloc/free, + * here we want to test various call orders. + */ + if (ns->rq_reset_mode == 2) { + netif_napi_del(&ns->rq[idx]->napi); + netif_napi_add_config(dev, &qmem->rq->napi, nsim_poll, idx); + } else if (ns->rq_reset_mode == 3) { + netif_napi_add_config(dev, &qmem->rq->napi, nsim_poll, idx); + netif_napi_del(&ns->rq[idx]->napi); + } + + ns->rq[idx] = qmem->rq; + napi_enable(&ns->rq[idx]->napi); + + return 0; +} + +static int nsim_queue_stop(struct net_device *dev, void *per_queue_mem, int idx) +{ + struct nsim_queue_mem *qmem = per_queue_mem; + struct netdevsim *ns = netdev_priv(dev); + + napi_disable(&ns->rq[idx]->napi); + + if (ns->rq_reset_mode == 1) { + qmem->pp = ns->rq[idx]->page_pool; + page_pool_disable_direct_recycling(qmem->pp); + } else { + qmem->rq = ns->rq[idx]; + } + + return 0; +} + +static const struct netdev_queue_mgmt_ops nsim_queue_mgmt_ops = { + .ndo_queue_mem_size = sizeof(struct nsim_queue_mem), + .ndo_queue_mem_alloc = nsim_queue_mem_alloc, + .ndo_queue_mem_free = nsim_queue_mem_free, + .ndo_queue_start = nsim_queue_start, + .ndo_queue_stop = nsim_queue_stop, +}; + static ssize_t nsim_pp_hold_read(struct file *file, char __user *data, size_t count, loff_t *ppos) @@ -739,6 +849,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns) ns->phc = phc; ns->netdev->netdev_ops = &nsim_netdev_ops; ns->netdev->stat_ops = &nsim_stat_ops; + ns->netdev->queue_mgmt_ops = &nsim_queue_mgmt_ops; err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev); if (err) diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 80fde64f4a7a..8c50969b1240 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -103,6 +103,8 @@ struct netdevsim { struct mock_phc *phc; struct nsim_rq **rq; + int rq_reset_mode; + u64 tx_packets; u64 tx_bytes; u64 tx_dropped; From patchwork Fri Jan 3 18:59:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13925824 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 39E191FC7DF for ; Fri, 3 Jan 2025 19:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930802; cv=none; b=qYphnkQoSYTaJj1ZsB2ehKAppHOTJYBdBX26cVJECkDROvDAahulqHKPpGc4dbZcS5+f8bOU9AFMd0mD3pRIgi/5AtxEc18uvfkYzV8C9NRkhccE7QnShHb91c5uWjG37CTPe99OsRPxYTk3OW0ddudytvNGZyLXt5EO7g8Sok4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930802; c=relaxed/simple; bh=WAw6OslHeff7CgXJrV3yhDAtX/gjSDBfWLnZ5jRR0No=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dv3TJAPRxELLpD8kpUlPDi7K4BTVx7O6Ur3EFE/WCIRI47bSN9z1DjGtYJb7IWuopDzu6MV5pPG1QO2UsqEwRPzd5+rRZFe7LChlokjhrsjG9W8vp35IXiwlz/WzpsILv4DHYU1YOBHM4fv+lHuOqMXIBOo1ydbXrcWouw/joLE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e6ipKp5O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e6ipKp5O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D01C7C4CEDF; Fri, 3 Jan 2025 19:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735930802; bh=WAw6OslHeff7CgXJrV3yhDAtX/gjSDBfWLnZ5jRR0No=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e6ipKp5OuVBXVz/GV8cIaKd0BbRrAUgPgQeGLl8X8goZD8aMFdQ6kbZLzxa4hM2Bn 3q1tVvQR8Y8Gt99Wuf9nHw1jeP2qCI4tJmbRAN+v+rqZiMO96JF7tLNsNF31BoYq0x fyZ3ul1IB487yy1OEPSChTrRwzBp8D7e+HXiSSH1BbPnbB/nYQX8cJzl4Bm4sOMpwr P5q2gMLITTe/duRwrAVOrBy/0wkdMsonOEDbVpjDodhXIV+1eOHdfc6kwEdUqL70v0 FPadY065pNSj5xVwDuu1gNbwfhQbJ32DgBwXCkkOyB67s/UQMyyCxk5TzmAqJXN7qd FekKWhLsS2PDQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, dw@davidwei.uk, almasrymina@google.com, jdamato@fastly.com, Jakub Kicinski Subject: [PATCH net-next 7/8] netdevsim: add debugfs-triggered queue reset Date: Fri, 3 Jan 2025 10:59:52 -0800 Message-ID: <20250103185954.1236510-8-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103185954.1236510-1-kuba@kernel.org> References: <20250103185954.1236510-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Support triggering queue reset via debugfs for an upcoming test. Signed-off-by: Jakub Kicinski Acked-by: Stanislav Fomichev --- drivers/net/netdevsim/netdev.c | 55 +++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdevsim.h | 1 + 2 files changed, 56 insertions(+) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 86614292314a..65605d2eb943 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,8 @@ #include "netdevsim.h" +MODULE_IMPORT_NS("NETDEV_INTERNAL"); + #define NSIM_RING_SIZE 256 static int nsim_napi_rx(struct nsim_rq *rq, struct sk_buff *skb) @@ -723,6 +726,54 @@ static const struct netdev_queue_mgmt_ops nsim_queue_mgmt_ops = { .ndo_queue_stop = nsim_queue_stop, }; +static ssize_t +nsim_qreset_write(struct file *file, const char __user *data, + size_t count, loff_t *ppos) +{ + struct netdevsim *ns = file->private_data; + unsigned int queue, mode; + char buf[32]; + ssize_t ret; + + if (count >= sizeof(buf)) + return -EINVAL; + if (copy_from_user(buf, data, count)) + return -EFAULT; + buf[count] = '\0'; + + ret = sscanf(buf, "%u %u", &queue, &mode); + if (ret != 2) + return -EINVAL; + + rtnl_lock(); + if (!netif_running(ns->netdev)) { + ret = -ENETDOWN; + goto exit_unlock; + } + + if (queue >= ns->netdev->real_num_rx_queues) { + ret = -EINVAL; + goto exit_unlock; + } + + ns->rq_reset_mode = mode; + ret = netdev_rx_queue_restart(ns->netdev, queue); + ns->rq_reset_mode = 0; + if (ret) + goto exit_unlock; + + ret = count; +exit_unlock: + rtnl_unlock(); + return ret; +} + +static const struct file_operations nsim_qreset_fops = { + .open = simple_open, + .write = nsim_qreset_write, + .owner = THIS_MODULE, +}; + static ssize_t nsim_pp_hold_read(struct file *file, char __user *data, size_t count, loff_t *ppos) @@ -935,6 +986,9 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port) ns->pp_dfs = debugfs_create_file("pp_hold", 0600, nsim_dev_port->ddir, ns, &nsim_pp_hold_fops); + ns->qr_dfs = debugfs_create_file("queue_reset", 0600, + nsim_dev_port->ddir, ns, + &nsim_qreset_fops); return ns; @@ -949,6 +1003,7 @@ void nsim_destroy(struct netdevsim *ns) struct netdevsim *peer; debugfs_remove(ns->pp_dfs); + debugfs_remove(ns->qr_dfs); rtnl_lock(); peer = rtnl_dereference(ns->peer); diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 8c50969b1240..a70f62af4c88 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -136,6 +136,7 @@ struct netdevsim { struct page *page; struct dentry *pp_dfs; + struct dentry *qr_dfs; struct nsim_ethtool ethtool; struct netdevsim __rcu *peer; From patchwork Fri Jan 3 18:59:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13925825 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F0ABF1FCFF1 for ; Fri, 3 Jan 2025 19:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930803; cv=none; b=Gb6Cp+60rshhzXhGNcLioPOlFEZUuYnT/BwTmh9G8WPFFW87ZvSQEGxnlwDiBsCgVPN3e3YFr8ljIHDuAJBC1M7/CSkJVQp4TwtvDkE20Ze+N5nT/dMyw9dXHzeawsEj8V9iIlaPOXzkdiWlD7TuZa683iodRQWuTgCm67m6PnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735930803; c=relaxed/simple; bh=gvHX7VWjxDX0RbahGVYfmherI0/uEt5X+Q/OTPYMd8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eVr6SPqIvu1tvAn2yz+aThFL8KW/dN4yjduy7cxH3cwg8qNwrBS+JTc0qPnEjuaroprZPJvxL+6MybVHmSFbsrdVSPyhW1UxHOQAvViG0plqef+Dv5L/nh85G/PH5J88YiVI3zJyRoX4X0jGo6SoD1zPkpwAi1xAItgif0Rynog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AVczcvz8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AVczcvz8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FA89C4CECE; Fri, 3 Jan 2025 19:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735930802; bh=gvHX7VWjxDX0RbahGVYfmherI0/uEt5X+Q/OTPYMd8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AVczcvz8bFfBsBvvnh9jPNZeO5SuLrWzOQXsFWnGeR0JBVicBK9++7rzRUuioXYNv gcyydoEmM0l0PaSYtUYRknCEQ37a6ewDwpVP3OZUG9prvS16zOO5fjUstDfLAb5gKh LIPW/HVpUngY66mIdOOH4dESDzeZHUhO7juSsK9qfiK+AcE3nTpRW25O8dMMBUk5gE GmySKiDMif/6ZwRRq3TbeCzkE4WpsNQ4TGCN8Q9aIJADtEuzXhYM2RaT/LWIEMCfCn /RT+1vuFkGXlUHxj9XsY3JGBVYc5WeSpu0QqGpLlsDvC3JvhY8cxQNrMnjG9DEq5Z0 xfBhX1hVK1uEQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, dw@davidwei.uk, almasrymina@google.com, jdamato@fastly.com, Jakub Kicinski Subject: [PATCH net-next 8/8] selftests: net: test listing NAPI vs queue resets Date: Fri, 3 Jan 2025 10:59:53 -0800 Message-ID: <20250103185954.1236510-9-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103185954.1236510-1-kuba@kernel.org> References: <20250103185954.1236510-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Test listing netdevsim NAPIs before and after a single queue has been reset (and NAPIs re-added). Start from resetting the middle queue because edge cases (first / last) may actually be less likely to trigger bugs. # ./tools/testing/selftests/net/nl_netdev.py KTAP version 1 1..4 ok 1 nl_netdev.empty_check ok 2 nl_netdev.lo_check ok 3 nl_netdev.page_pool_check ok 4 nl_netdev.napi_list_check # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Jakub Kicinski Acked-by: Stanislav Fomichev --- tools/testing/selftests/net/nl_netdev.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/nl_netdev.py b/tools/testing/selftests/net/nl_netdev.py index 93d9d914529b..93e8cb671c3d 100755 --- a/tools/testing/selftests/net/nl_netdev.py +++ b/tools/testing/selftests/net/nl_netdev.py @@ -18,6 +18,23 @@ from lib.py import NetdevFamily, NetdevSimDev, ip ksft_eq(len(lo_info['xdp-rx-metadata-features']), 0) +def napi_list_check(nf) -> None: + with NetdevSimDev(queue_count=100) as nsimdev: + nsim = nsimdev.nsims[0] + + ip(f"link set dev {nsim.ifname} up") + + napis = nf.napi_get({'ifindex': nsim.ifindex}, dump=True) + ksft_eq(len(napis), 100) + + for q in [50, 0, 99]: + for i in range(4): + nsim.dfs_write("queue_reset", f"{q} {i}") + napis = nf.napi_get({'ifindex': nsim.ifindex}, dump=True) + ksft_eq(len(napis), 100, + comment=f"queue count after reset queue {q} mode {i}") + + def page_pool_check(nf) -> None: with NetdevSimDev() as nsimdev: nsim = nsimdev.nsims[0] @@ -89,7 +106,7 @@ from lib.py import NetdevFamily, NetdevSimDev, ip def main() -> None: nf = NetdevFamily() - ksft_run([empty_check, lo_check, page_pool_check], + ksft_run([empty_check, lo_check, page_pool_check, napi_list_check], args=(nf, )) ksft_exit()