From nobody Sun Dec 14 13:49:49 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B11CD1917F1 for ; Thu, 16 Jan 2025 05:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006808; cv=none; b=TPacdWQ3wbqGSmOvbjpS8HvynS5Owb/IKPyZ3QLtGgaXahud2RpnzRXQTzy8ztrKSMA519RHH6Y3n3PoDIJsC8C4P+LxPOUbcG7UiXxn/Ftf8yPJUuHQv3zGYQ4zqSMTd0ku+Z3NGsie3ovldTxZq7i20WYP3baWJdQB4CndR78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006808; c=relaxed/simple; bh=mVwktbWSoWFP1usMOPYKCXwzUeeubnCUrVQ2w9l1YuQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gOx/mv41H+BVTz7grCnIfH+jDz+RjTIstk5Q1FoynOF4ll0d+jqMkt6qSfN4oU8xVRspGoUve4nTaV7ICC3eZtH2Y8Hu7iYgZIESkymP7biI24T2YDw7eaD5AYrL+YbkRliBKHgdOGOIEUO37WfgQBGT89fwnalKGwQepqKhIP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=W8IuDHzq; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="W8IuDHzq" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2166022c5caso7491885ad.2 for ; Wed, 15 Jan 2025 21:53:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1737006806; x=1737611606; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bC/KHeKZrs1tP54amz5eEuxLD6Mq90VAvd7Bs8DlJ+8=; b=W8IuDHzqCQSok1vUWamvq63rULHrmt1A/F775C09EjKjhEwSa8c/zip+VYutvPsW77 zIFSpp3ShLwE1KuLMPbtgfq5+Zr2UZvSWa+P3PmBb2p2LcMR1VPKauF9Gs0P6GBYhjRY bzH4655x9QpzIpxWW/s2PO5BX/h8Aer6RdDMU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737006806; x=1737611606; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bC/KHeKZrs1tP54amz5eEuxLD6Mq90VAvd7Bs8DlJ+8=; b=Y7IzN0vCuIPrPnCgFUEgWpuypOC8I4iGo/goa3pxKgvycy1EO13wZpt8WMdWXoA6VR GHVtdIq67/ukFH2FNwHXKvs+eqCmruSbYqv4REQnHZ0rhxcfN383SV4LoruDJAETmMAp V0gThj4pDCC081wCjzGe1ZEyia8PZfR9sWukLS3q1dG7VZ7UPTwvn2dbXTHowH6hA3oa Pp4NyXuYoj8WtHgORBd7Obt520ztajPhNihaztj2GAx0mOBKjioXpJ3yQs/PUuUFLRGY LhJ+L026Jx29010QCoV+iP3ZOFUEkALC6N8FbK8v38Me8k9EASPA9ABMWVDArZwiMhFZ EyZA== X-Forwarded-Encrypted: i=1; AJvYcCW3kTyo2Y882uAo8Nh3SbSK+gHQO/YT118Q7Vpxlh88zRlPSM/aFYXzz4E/toZ1dYUzcPXtQFVGjFjl/hc=@vger.kernel.org X-Gm-Message-State: AOJu0YxZXhB9Uh1O5gUOSbR4snsDDMcKLMzeWFnTMNodlL7fMJ0fAmn9 KnY+wS8VzBafglbWQI8wcjgv08PMU7YWFuhPirx7tLhsU94ayetRroWL2VsJW4o= X-Gm-Gg: ASbGncv2FsdG8ygMugpeqXTUkdqWwck2cLm74Gd6J75i7S6IGClyTTwu7jVOpODfEl+ UsVhZCbaAPqtPk/gvBMyEBZZJ5QIsgviv0+WubpVZJixBhk08ef1Q+UnEee0THYQnyOOpPGzxfZ C0Hx/LE82o+rqskAFxsun0f40KgBI7JvG97PC3k6lIAI4CHSntOau0ssToWC5PpOmGKpQF0CfcI 8qq1kll8ic4jpd6XpoHMN+u5NucQ8xWohiagRZu2yUwO5SErJMVFW67Dbb4PkMR X-Google-Smtp-Source: AGHT+IGntTkOMJEdO2lJ/RT1ILNh9iXtgR2mfbiueSHch1JtTC7D230UEJorte+y+OkqI+IHqifhdA== X-Received: by 2002:a17:902:e5c2:b0:215:b33b:e26d with SMTP id d9443c01a7336-21a83f55103mr529430015ad.21.1737006805997; Wed, 15 Jan 2025 21:53:25 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f22c991sm91249655ad.168.2025.01.15.21.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 21:53:25 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: gerhard@engleder-embedded.com, jasowang@redhat.com, leiyang@redhat.com, mkarsten@uwaterloo.ca, Jakub Kicinski , Joe Damato , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Andrew Lunn , Sebastian Andrzej Siewior , Lorenzo Bianconi , Alexander Lobakin , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v2 1/4] net: protect queue -> napi linking with netdev_lock() Date: Thu, 16 Jan 2025 05:52:56 +0000 Message-Id: <20250116055302.14308-2-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250116055302.14308-1-jdamato@fastly.com> References: <20250116055302.14308-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jakub Kicinski netdev netlink is the only reader of netdev_{,rx_}queue->napi, and it already holds netdev->lock. Switch protection of the writes to netdev->lock as well. Add netif_queue_set_napi_locked() for API completeness, but the expectation is that most current drivers won't have to worry about locking any more. Today they jump thru hoops to take rtnl_lock. Signed-off-by: Jakub Kicinski Reviewed-by: Joe Damato --- v2: - Added in v2 from Jakub. include/linux/netdevice.h | 9 +++++++-- include/net/netdev_rx_queue.h | 2 +- net/core/dev.c | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 8308d9c75918..c7201642e9fb 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -690,7 +690,7 @@ struct netdev_queue { * slow- / control-path part */ /* NAPI instance for the queue - * Readers and writers must hold RTNL + * Readers and writers must hold netdev->lock */ struct napi_struct *napi; =20 @@ -2458,7 +2458,8 @@ struct net_device { * Partially protects (writers must hold both @lock and rtnl_lock): * @up * - * Also protects some fields in struct napi_struct. + * Also protects some fields in: + * struct napi_struct, struct netdev_queue, struct netdev_rx_queue * * Ordering: take after rtnl_lock. */ @@ -2685,6 +2686,10 @@ static inline void *netdev_priv(const struct net_dev= ice *dev) void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index, enum netdev_queue_type type, struct napi_struct *napi); +void netif_queue_set_napi_locked(struct net_device *dev, + unsigned int queue_index, + enum netdev_queue_type type, + struct napi_struct *napi); =20 static inline void netdev_lock(struct net_device *dev) { diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index 596836abf7bf..9fcac0b43b71 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -23,7 +23,7 @@ struct netdev_rx_queue { struct xsk_buff_pool *pool; #endif /* NAPI instance for the queue - * Readers and writers must hold RTNL + * Readers and writers must hold netdev->lock */ struct napi_struct *napi; struct pp_memory_provider_params mp_params; diff --git a/net/core/dev.c b/net/core/dev.c index 782ae3ff3f8d..528478cd8615 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6851,14 +6851,24 @@ EXPORT_SYMBOL(dev_set_threaded); */ void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index, enum netdev_queue_type type, struct napi_struct *napi) +{ + netdev_lock(dev); + netif_queue_set_napi_locked(dev, queue_index, type, napi); + netdev_unlock(dev); +} +EXPORT_SYMBOL(netif_queue_set_napi); + +void netif_queue_set_napi_locked(struct net_device *dev, + unsigned int queue_index, + enum netdev_queue_type type, + struct napi_struct *napi) { struct netdev_rx_queue *rxq; struct netdev_queue *txq; =20 if (WARN_ON_ONCE(napi && !napi->dev)) return; - if (dev->reg_state >=3D NETREG_REGISTERED) - ASSERT_RTNL(); + netdev_assert_locked_or_invisible(dev); =20 switch (type) { case NETDEV_QUEUE_TYPE_RX: @@ -6873,7 +6883,7 @@ void netif_queue_set_napi(struct net_device *dev, uns= igned int queue_index, return; } } -EXPORT_SYMBOL(netif_queue_set_napi); +EXPORT_SYMBOL(netif_queue_set_napi_locked); =20 static void napi_restore_config(struct napi_struct *n) { --=20 2.25.1 From nobody Sun Dec 14 13:49:49 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5868E193077 for ; Thu, 16 Jan 2025 05:53:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006809; cv=none; b=ad47Q4BvxLXTmfPjXSVIKGZ0M/r6aqhb4wT7xk6RuVqxvB4D7WaGAp/vaiplODk1wCUWSnYmjha86p0xj3eMVOwOuFCNXTkX7y45qyRniYFnPEszCULNUtkV7c91eG2b6cO+0AGaRwtyXGZ6xw/0Pz6a4IeJ0N4bYMMvU5pUKtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006809; c=relaxed/simple; bh=QoUuXeDBulZSbVMdrI5zM6Eg9lCr5hgBtBOzJbP8zEQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A5IXrHowlMB3FnRNeGu7ljLDODCRowecWf9D8zcfCnPsrLN3wA2F0zR8NaZ9e4GQCyGLn8WGli//EH+m1GYVCWmIYKniJn5kD60aak5vqLZMYAmxlvGPGcHZGcu1VQ2dVscZK1PeDBklcAoOb3UgPW8Be/0NdxNszHSL7Z1WI1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=hsHPwB+j; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="hsHPwB+j" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2165cb60719so7982065ad.0 for ; Wed, 15 Jan 2025 21:53:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1737006807; x=1737611607; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9sIKGTHIeBOioZLiUeQpKiV7N2jyLH+xFiew0830fKc=; b=hsHPwB+jmjdxpSXHZqDnT8mOjpoLwOJerTD332SuBOQOHBbfj7Bv29/2fjLKjOnf6T kqvuLJQ/90xeszBnuZMtDCbtLSqKYyvAESp+tYiBNipwWEx5sAJV8EC03cO9vbDmi1xX KEMB958LwJ+i9gtsVOGd8mkceI8cYwFwep8jE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737006807; x=1737611607; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9sIKGTHIeBOioZLiUeQpKiV7N2jyLH+xFiew0830fKc=; b=JnJgTsu5vHVLIGPLm2pX5arWA5Mc0597cUfAelHn788Q2vedi1PoD82/HNpmfCb7OC vfWHh4gQAKtgFcclOOqVVF+sR+aqh4loSzIWK/PTwQ7xEDl62cQCG6tJGtma69gf/43R AyEZz1sTO6fZBEA2SHScf+kMg89xGMTOh+I9ba4q6uBxu+xc2Vqn4qnhHynA+YeQL1RT 0cyA90fbcGMACtpfbJH957GH7ZOJjU668yRgtNMZO10sA8msYank4yKEvvpF8W93uM72 bPUuYSKuThOYEhBNnxCNdHimWZAG++SdUeUF7+DCDzf1qyfKNga3r3EKJrs6zMtAzPxF drTg== X-Forwarded-Encrypted: i=1; AJvYcCVMQpjUkHKevaIeAROaUw67O9EI7q1kc6gbtQauaRQL9nmEe+AqmxE+rE2uxXugdBl6+Setyn6rExgfRTY=@vger.kernel.org X-Gm-Message-State: AOJu0YzR0bd7dfBJbjpT7vDot+ZPiQKwIWvyBOfJ9YZPY6O+wmd++83k S4+Fa1fbqufoVgGvAJ2PkO0KML0kDOAXZB7oF1YuOzwMLYGPe8WOb4lUS21vHSA= X-Gm-Gg: ASbGncu0s99qZrKdw9p02EXGeulyczx9lSSEYk41tXK6RImogN/lnqTjlVijf+7DuvS djcIUc5MN/U4x7IvSqqBIREFx/EINAguKuleEWrXvWOWEehsrglC6rLqnONGoZmUnOn2FF4XooM 6vTlw8mwbSV/WSIqBzIUP34Xe5WoXCi9Utp/oFsutCYrlawBOZekA2qkP/7DxGc6NTNYJf12TU5 4Hk4oNU7rEpoJHtupq+b90OaaT8wRnZbB4MJKXRsCNWpg/+Tp3I21uwuSmirj/R X-Google-Smtp-Source: AGHT+IEJCssTOUws+b72W8uZUvjCTPp85OZ9h1VVGxQI7rHP+zFi1sj5ShlGmZbXcEUCTdHWY7Z3FA== X-Received: by 2002:a17:902:9a09:b0:21a:8dec:e596 with SMTP id d9443c01a7336-21a8dece7e5mr344365815ad.35.1737006807678; Wed, 15 Jan 2025 21:53:27 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f22c991sm91249655ad.168.2025.01.15.21.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 21:53:27 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: gerhard@engleder-embedded.com, jasowang@redhat.com, leiyang@redhat.com, mkarsten@uwaterloo.ca, Joe Damato , "Michael S. Tsirkin" , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev (open list:VIRTIO CORE AND NET DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v2 2/4] virtio_net: Prepare for NAPI to queue mapping Date: Thu, 16 Jan 2025 05:52:57 +0000 Message-Id: <20250116055302.14308-3-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250116055302.14308-1-jdamato@fastly.com> References: <20250116055302.14308-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Slight refactor to prepare the code for NAPI to queue mapping. No functional changes. Signed-off-by: Joe Damato Reviewed-by: Gerhard Engleder Tested-by: Lei Yang --- v2: - Previously patch 1 in the v1. - Added Reviewed-by and Tested-by tags to commit message. No functional changes. drivers/net/virtio_net.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7646ddd9bef7..cff18c66b54a 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2789,7 +2789,8 @@ static void skb_recv_done(struct virtqueue *rvq) virtqueue_napi_schedule(&rq->napi, rvq); } =20 -static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *= napi) +static void virtnet_napi_do_enable(struct virtqueue *vq, + struct napi_struct *napi) { napi_enable(napi); =20 @@ -2802,6 +2803,11 @@ static void virtnet_napi_enable(struct virtqueue *vq= , struct napi_struct *napi) local_bh_enable(); } =20 +static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *= napi) +{ + virtnet_napi_do_enable(vq, napi); +} + static void virtnet_napi_tx_enable(struct virtnet_info *vi, struct virtqueue *vq, struct napi_struct *napi) @@ -2817,7 +2823,7 @@ static void virtnet_napi_tx_enable(struct virtnet_inf= o *vi, return; } =20 - return virtnet_napi_enable(vq, napi); + virtnet_napi_do_enable(vq, napi); } =20 static void virtnet_napi_tx_disable(struct napi_struct *napi) --=20 2.25.1 From nobody Sun Dec 14 13:49:49 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4982E195808 for ; Thu, 16 Jan 2025 05:53:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006811; cv=none; b=K86pZcaWU0odQ7j7BHNG4wZgj1xw2BZTEsaFatvoMpA3z/VoUgW73gkv4M2cHyjQ08k4Ucmbx8S/SGSSXABG0FN9aER8tG5SgsFVvAMSPPL+IJBQLLGGcCiZsrF9UTsnNShwr29blKYBMN4R1fqvAmx/Q1bBBHPLMC4yaj+1cBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006811; c=relaxed/simple; bh=yJvHEqdHpoC28W6nXw4OZ31j2d6z3msHRmx43NIpiUQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pmkUUbCq03RhDxkFhAnUtbKN2zs0Bmo6yzGR91th1foRVy0umHH5g1NhjFrtT4dEkZJBB4/IU/lWqy2Xru0kf91wm1pxGhv88DQooeGRWsifGlRCUBIUwvV8rjNDJGiepBJaT26p91FKes+DZUOK4BdOraqF1mmdQXFMMxM7s+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=oprsE6mQ; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="oprsE6mQ" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21649a7bcdcso7840115ad.1 for ; Wed, 15 Jan 2025 21:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1737006809; x=1737611609; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XcY+kSjeMMu9asV4FI3bEFO3nH1Uxd3geQomjlGuQlg=; b=oprsE6mQGDWzDzFGb8J8iaeQOzuEOBAKNbiT03ljfZE2+dx8+0teuzBfJBKoTB5rmh klN+6yP3MYjQS04WbpzT1K6dAGxnxhjB+QYuXluV/812rzHR4ACN5AIOp53eJ04feIrW qjVIhxGWfTXnMsXxGTAe7aiPTCaD76FU6GJZc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737006809; x=1737611609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XcY+kSjeMMu9asV4FI3bEFO3nH1Uxd3geQomjlGuQlg=; b=DdE2R+EWymEsruZsdICGIJ455aOob3qXKwWCKQ3QIPwRL6sbdvK+whL/qY38uhpFbT RoroKu2RBwZBU48N6mU+5gMCEiNTzngT0C4aM838iTvYcb92plZGl6vFiH1l+HH2wfzZ t7WH/+b5cwSEeRxiLqxObXOMaI36MOPXoU4zk09JEip2veeb3ljXrWzh9XTC4PR+5k9k UxtU9WfUSXBAXVfS/xLGx2MEp3HqgBZYwORThFkV1GxUG/JOyARtIrd/T0cepNJhZNvc RNLPdmiAnyG23kJW65OTWCkmKlgM+Mc4ly7s/+Tit9/lPdG3kGTGBRvc8yMMirMiAFqw 3rfw== X-Forwarded-Encrypted: i=1; AJvYcCWJcHGS31adO3lg3f+Onrtdf3+mt1JZgx0mhFPNz4yK/VHOrjUNfccQel4sdDPbtv85khtMwuScvmgGoHE=@vger.kernel.org X-Gm-Message-State: AOJu0YxB49iThNsG+hM7L5O29NPtKARbV61OQntTZN6Le0UDszUwKezs qfMS2NhFEMBtz5XFZI/sevG6EVwwtsnUn0MTKXj5iUrmKS9qdLLcetzdD6gjMknDYlolBEtjIGN G X-Gm-Gg: ASbGncuwjsgbq5IH5E8tRwOG+r4+V/5PitIEBhgeOSJI7U35aUJ6MuvPAMBLgpTuYoM yxG2vdCbWci0Q1uPauS9DIQAhKDn7AyqjUJHC1QnI0xGP/OJ7KJAaAa2/AV21IBTn6AMeatyOC0 Y3I+KlSOIr4SeRSTwuYiOfi7bjw+EXDKQ/bqLzBcXjq6ud4EJnarn8oaY+zcfZUe0HwJzmpmU1G wkLRTCtu9rW3n2qLX54rho4Ctc8dKDwTH0KrfFPnVYqsy98QdAHbuLnPCAeOgQN X-Google-Smtp-Source: AGHT+IFGBkkanzsZABlx+kwVbhQWzWrd9fcJLyyqg9XrcMim/tp4HH707mqDKYrn2ErGZPkhsWUDLA== X-Received: by 2002:a17:903:2311:b0:210:fce4:11ec with SMTP id d9443c01a7336-21a83f42687mr507328185ad.1.1737006809538; Wed, 15 Jan 2025 21:53:29 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f22c991sm91249655ad.168.2025.01.15.21.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 21:53:29 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: gerhard@engleder-embedded.com, jasowang@redhat.com, leiyang@redhat.com, mkarsten@uwaterloo.ca, Joe Damato , "Michael S. Tsirkin" , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , virtualization@lists.linux.dev (open list:VIRTIO CORE AND NET DRIVERS), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:XDP (eXpress Data Path):Keyword:(?:\b|_)xdp(?:\b|_)) Subject: [PATCH net-next v2 3/4] virtio_net: Map NAPIs to queues Date: Thu, 16 Jan 2025 05:52:58 +0000 Message-Id: <20250116055302.14308-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250116055302.14308-1-jdamato@fastly.com> References: <20250116055302.14308-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use netif_queue_set_napi to map NAPIs to queue IDs so that the mapping can be accessed by user apps. $ ethtool -i ens4 | grep driver driver: virtio_net $ sudo ethtool -L ens4 combined 4 $ ./tools/net/ynl/pyynl/cli.py \ --spec Documentation/netlink/specs/netdev.yaml \ --dump queue-get --json=3D'{"ifindex": 2}' [{'id': 0, 'ifindex': 2, 'napi-id': 8289, 'type': 'rx'}, {'id': 1, 'ifindex': 2, 'napi-id': 8290, 'type': 'rx'}, {'id': 2, 'ifindex': 2, 'napi-id': 8291, 'type': 'rx'}, {'id': 3, 'ifindex': 2, 'napi-id': 8292, 'type': 'rx'}, {'id': 0, 'ifindex': 2, 'type': 'tx'}, {'id': 1, 'ifindex': 2, 'type': 'tx'}, {'id': 2, 'ifindex': 2, 'type': 'tx'}, {'id': 3, 'ifindex': 2, 'type': 'tx'}] Note that virtio_net has TX-only NAPIs which do not have NAPI IDs, so the lack of 'napi-id' in the above output is expected. Signed-off-by: Joe Damato --- v2: - Eliminate RTNL code paths using the API Jakub introduced in patch 1 of this v2. - Added virtnet_napi_disable to reduce code duplication as suggested by Jason Wang. drivers/net/virtio_net.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index cff18c66b54a..c6fda756dd07 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2803,9 +2803,18 @@ static void virtnet_napi_do_enable(struct virtqueue = *vq, local_bh_enable(); } =20 -static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *= napi) +static void virtnet_napi_enable(struct virtqueue *vq, + struct napi_struct *napi) { + struct virtnet_info *vi =3D vq->vdev->priv; + int q =3D vq2rxq(vq); + u16 curr_qs; + virtnet_napi_do_enable(vq, napi); + + curr_qs =3D vi->curr_queue_pairs - vi->xdp_queue_pairs; + if (!vi->xdp_enabled || q < curr_qs) + netif_queue_set_napi(vi->dev, q, NETDEV_QUEUE_TYPE_RX, napi); } =20 static void virtnet_napi_tx_enable(struct virtnet_info *vi, @@ -2826,6 +2835,20 @@ static void virtnet_napi_tx_enable(struct virtnet_in= fo *vi, virtnet_napi_do_enable(vq, napi); } =20 +static void virtnet_napi_disable(struct virtqueue *vq, + struct napi_struct *napi) +{ + struct virtnet_info *vi =3D vq->vdev->priv; + int q =3D vq2rxq(vq); + u16 curr_qs; + + curr_qs =3D vi->curr_queue_pairs - vi->xdp_queue_pairs; + if (!vi->xdp_enabled || q < curr_qs) + netif_queue_set_napi(vi->dev, q, NETDEV_QUEUE_TYPE_RX, NULL); + + napi_disable(napi); +} + static void virtnet_napi_tx_disable(struct napi_struct *napi) { if (napi->weight) @@ -2842,7 +2865,8 @@ static void refill_work(struct work_struct *work) for (i =3D 0; i < vi->curr_queue_pairs; i++) { struct receive_queue *rq =3D &vi->rq[i]; =20 - napi_disable(&rq->napi); + virtnet_napi_disable(rq->vq, &rq->napi); + still_empty =3D !try_fill_recv(vi, rq, GFP_KERNEL); virtnet_napi_enable(rq->vq, &rq->napi); =20 @@ -3042,7 +3066,7 @@ static int virtnet_poll(struct napi_struct *napi, int= budget) static void virtnet_disable_queue_pair(struct virtnet_info *vi, int qp_ind= ex) { virtnet_napi_tx_disable(&vi->sq[qp_index].napi); - napi_disable(&vi->rq[qp_index].napi); + virtnet_napi_disable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi); xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); } =20 @@ -3313,7 +3337,7 @@ static void virtnet_rx_pause(struct virtnet_info *vi,= struct receive_queue *rq) bool running =3D netif_running(vi->dev); =20 if (running) { - napi_disable(&rq->napi); + virtnet_napi_disable(rq->vq, &rq->napi); virtnet_cancel_dim(vi, &rq->dim); } } @@ -5932,7 +5956,7 @@ static int virtnet_xdp_set(struct net_device *dev, st= ruct bpf_prog *prog, /* Make sure NAPI is not using any XDP TX queues for RX. */ if (netif_running(dev)) { for (i =3D 0; i < vi->max_queue_pairs; i++) { - napi_disable(&vi->rq[i].napi); + virtnet_napi_disable(vi->rq[i].vq, &vi->rq[i].napi); virtnet_napi_tx_disable(&vi->sq[i].napi); } } --=20 2.25.1 From nobody Sun Dec 14 13:49:49 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62717199920 for ; Thu, 16 Jan 2025 05:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006813; cv=none; b=H+ok0qEKKvdn+38cpgZ2kwIXHGoaGK7eWSVbFuMBaDYUvoYwuotDoTMOPN249rCdbsVh5nhtf93SJkjtKs/JM4gOB+oz0wS5IkmHPyFFzCCOponmBU13UJH8b1Y9UZUROoPCMEUB+5IaeHsE8XCAaBcU1qHUOQ3BYr4J5+tELjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737006813; c=relaxed/simple; bh=UXb3rPE/1GDUYX7xYJCycggz8UdX0ho9WDF1GZTuo+k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JpzKIIA+08GiUjBHVMTSg8REjgbbvv24clB8pYnV+71cBLJUQuwBT4xVenoiPivgPZoeCi05l330/2Akig7NsfszSg4pTB1CfEy+Zb75bY3RgLccfCho3pE6F/eCoO0eCS0/MAdVHBhUKRfG4BnpblcArSqM19nZi9pYODhVq0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=mVNTyO5A; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="mVNTyO5A" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21675fd60feso10542195ad.2 for ; Wed, 15 Jan 2025 21:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1737006811; x=1737611611; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uZtsz2Rtgk1xt8CSQNH2JM2w40RollK9oAaOdJJO1B8=; b=mVNTyO5AueG417aZ80WO//Gl32jM0u9aMFWJyGBz10NMCkRZ+0iZZ3PqFVLH6xxF1P XnSBBuljpGWDmealrh6GFFXOTC7sw4IbPasu6DHLeLbfOMnEuFHH3i/Zl32Mg3zwjMI1 tTbHIHT6BwpPcdESiaS9irQsT0x6XwSbZQiD8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737006811; x=1737611611; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uZtsz2Rtgk1xt8CSQNH2JM2w40RollK9oAaOdJJO1B8=; b=kqK5pUKLSQZ3jbPwJMiL9FxczxOkgty/rydHtl+5J+PMdJP10FWUzPKBgZoBZ5eBC2 HPVAflf/77nJF7GHppnY+HprF/ZVkVEIQEImN6iga3T2r6lFOupENUSjbxtLqBcGKYON C/jvkrhYoSaDjHSdhhVDF1IJAGUn5qkWDIbjPVACiPe8HH9JohfktRZaE+LEDJDkGCyf tLVx6kPRZoH8qo6ljiO2OQhVRsY6lN48aoGqSBQfkt1CXFmrs49R8ME0QjD4Oy+n0A1A JS2VQgDXFbNd4G4EK0mbcRRl+Z6qnQDFsZzvNjfdOVGQeQ/GyB7hhTnjcJ1f5As8bHDZ BCdg== X-Forwarded-Encrypted: i=1; AJvYcCUfTFLdNoh4qxSh1SFrpOjt+d4jigq/6p5K+TVXyDChf+z2N0cFawrk1i+WVd/HzqtZ3HBh7930IBj6SmY=@vger.kernel.org X-Gm-Message-State: AOJu0YxcZPmrPtjM/tYrdvTuKdc14d3m+OSHylxcg3fAWSpmCU/qVgS1 0zJdeU5MQCAuvpObnukF+CKYP5Ozrps3wS6VgwOG9dIUp4XG8nDiHqJEsH3pSpU= X-Gm-Gg: ASbGncvIVZZAeRkpPwr+yKum5gs6acCq0Et/6jwceG1ZzVPTbXCalEphjNQ9ey82Btt 0QCsPlED1A9RxualTZGsZrFMh3eSonjAmRlD9r6mNGuYr9987ZZEXhf+yP7O76Sdj4zSvpA2UO2 3ZCtc8eR+b5uhB4e2j4/+2T0CTRJdwWw83ecPjoCCX8oBhoxjxs6m6OnRsa0DAOQ81q/FLO4qp8 QIR7pOKojnMAUjXY2APLc0uUo4SUhySELiaSW2jTeGmqAgn0L2nDYoUIhPYRKy4 X-Google-Smtp-Source: AGHT+IGKQzp0gRosRVZZiRnTi2eKc0WyUMTIwNaRCmD8fTVjAZ/tLpnB9TpD79nfRxnZfUmc/GT8fg== X-Received: by 2002:a17:902:dace:b0:216:4b5a:998b with SMTP id d9443c01a7336-21a83fe4c3bmr516333485ad.45.1737006811200; Wed, 15 Jan 2025 21:53:31 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f22c991sm91249655ad.168.2025.01.15.21.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 21:53:30 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: gerhard@engleder-embedded.com, jasowang@redhat.com, leiyang@redhat.com, mkarsten@uwaterloo.ca, Joe Damato , "Michael S. Tsirkin" , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev (open list:VIRTIO CORE AND NET DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v2 4/4] virtio_net: Use persistent NAPI config Date: Thu, 16 Jan 2025 05:52:59 +0000 Message-Id: <20250116055302.14308-5-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250116055302.14308-1-jdamato@fastly.com> References: <20250116055302.14308-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use persistent NAPI config so that NAPI IDs are not renumbered as queue counts change. $ sudo ethtool -l ens4 | tail -5 | egrep -i '(current|combined)' Current hardware settings: Combined: 4 $ ./tools/net/ynl/pyynl/cli.py \ --spec Documentation/netlink/specs/netdev.yaml \ --dump queue-get --json=3D'{"ifindex": 2}' [{'id': 0, 'ifindex': 2, 'napi-id': 8193, 'type': 'rx'}, {'id': 1, 'ifindex': 2, 'napi-id': 8194, 'type': 'rx'}, {'id': 2, 'ifindex': 2, 'napi-id': 8195, 'type': 'rx'}, {'id': 3, 'ifindex': 2, 'napi-id': 8196, 'type': 'rx'}, {'id': 0, 'ifindex': 2, 'type': 'tx'}, {'id': 1, 'ifindex': 2, 'type': 'tx'}, {'id': 2, 'ifindex': 2, 'type': 'tx'}, {'id': 3, 'ifindex': 2, 'type': 'tx'}] Now adjust the queue count, note that the NAPI IDs are not renumbered: $ sudo ethtool -L ens4 combined 1 $ ./tools/net/ynl/pyynl/cli.py \ --spec Documentation/netlink/specs/netdev.yaml \ --dump queue-get --json=3D'{"ifindex": 2}' [{'id': 0, 'ifindex': 2, 'napi-id': 8193, 'type': 'rx'}, {'id': 0, 'ifindex': 2, 'type': 'tx'}] $ sudo ethtool -L ens4 combined 8 $ ./tools/net/ynl/pyynl/cli.py \ --spec Documentation/netlink/specs/netdev.yaml \ --dump queue-get --json=3D'{"ifindex": 2}' [{'id': 0, 'ifindex': 2, 'napi-id': 8193, 'type': 'rx'}, {'id': 1, 'ifindex': 2, 'napi-id': 8194, 'type': 'rx'}, {'id': 2, 'ifindex': 2, 'napi-id': 8195, 'type': 'rx'}, {'id': 3, 'ifindex': 2, 'napi-id': 8196, 'type': 'rx'}, {'id': 4, 'ifindex': 2, 'napi-id': 8197, 'type': 'rx'}, {'id': 5, 'ifindex': 2, 'napi-id': 8198, 'type': 'rx'}, {'id': 6, 'ifindex': 2, 'napi-id': 8199, 'type': 'rx'}, {'id': 7, 'ifindex': 2, 'napi-id': 8200, 'type': 'rx'}, [...] Signed-off-by: Joe Damato Reviewed-by: Xuan Zhuo --- v2: - New in this v2. Adds persistent NAPI config so that NAPI IDs are not renumbered and napi_config settings are persisted. drivers/net/virtio_net.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c6fda756dd07..52094596e94b 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -6420,8 +6420,9 @@ static int virtnet_alloc_queues(struct virtnet_info *= vi) INIT_DELAYED_WORK(&vi->refill, refill_work); for (i =3D 0; i < vi->max_queue_pairs; i++) { vi->rq[i].pages =3D NULL; - netif_napi_add_weight(vi->dev, &vi->rq[i].napi, virtnet_poll, - napi_weight); + netif_napi_add_config(vi->dev, &vi->rq[i].napi, virtnet_poll, + i); + vi->rq[i].napi.weight =3D napi_weight; netif_napi_add_tx_weight(vi->dev, &vi->sq[i].napi, virtnet_poll_tx, napi_tx ? napi_weight : 0); --=20 2.25.1