From nobody Mon Feb 9 08:29:34 2026 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 EC5C521B195 for ; Fri, 10 Jan 2025 20:26:23 +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=1736540785; cv=none; b=A95mXEE7U2gmBvHcRa3u9dnvz+hd7tbGEmoMxKIVphDq/KJycQyBwxGqerdUcOo8utapPRn1WoG/4P8t4aE3WuYJ3lwvehbW9dswjZLJwY23qq9nB6DSNv8TMCglM2tuELwH0wZEbZrvU+lkaFvvTcMXlus5o2n4WbBWjLIsh3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540785; c=relaxed/simple; bh=nXNvmseKjVxOB/p5zaC6W1Bj1mcIQTUBPceRSuG8Qpc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tHTZOi8gZq6xVgFospAAYAND0FadfpofU0lvoS+eGbaXFn807bhOIn5zoIRfD1B/hVY66NRsJdhm2MzK5KXnXKqgxpd0LykACEktJda12kh4/OsKDR0QYoscQR6hpQ07LUgISrjYXPGivYCoIUxPkbt0pUJJGaGo6wLHgmW38r8= 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=HdN1EntK; 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="HdN1EntK" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2161eb95317so41533605ad.1 for ; Fri, 10 Jan 2025 12:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1736540783; x=1737145583; 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=X5Wc1BZX0qLlows6HUppLFsWMw9e/cDJxHu3IFsmtDc=; b=HdN1EntKBzkb1cXTgZAYrIJ6FR+5I3pTkOF5vWJK8noPEtwZbxc9hKaH52DqH5LfUI +loYiLY+Ok7H3vynSCZdMJL+nk+cBD7sFKBWChm2PtbTPej3/kukUmrg8NVBUQqbxCu1 okIRvaLjWtNJK2s75UoBh710/F1qjILMOokIo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736540783; x=1737145583; 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=X5Wc1BZX0qLlows6HUppLFsWMw9e/cDJxHu3IFsmtDc=; b=mcZ3wocryyeSI1v+glduB2fc4Y0Vt+iiKPCRCN7FcJWRaTiV0gy93Hyi+AVPXuo6Ql TLx5fRSbbux/A9IiTbgWU0HxblW85MXNmSsSrIwJI0NZEpv0O7LXKwPgb6926vAvMMQv Xl3h2iZPguSHavkGfjRhyYWCntarDb/78CCqMGR63vb4WLqAIhvq8zoxic+BNxnleO2A KH/h9K3/ff9e/RtTD911qLjb/a5FGWdhoPFbjPW673PSLIkemSTFPfqVTEJ/ECY06DKl BMfiyCaLDnDaAZHkNWYXdEvNe08DpkNRabZ7rb0A56rT4DPbX1U1sF7AdVUuShEQcLK5 eG9Q== X-Forwarded-Encrypted: i=1; AJvYcCXOx98IDpITOVoqskT0r+dKuPG6rDWnoFPPMwVqStonz95SAn2RoJeu4YE4D8JR3wYd3jbO0Di0+PoJlLY=@vger.kernel.org X-Gm-Message-State: AOJu0Yzj5n5vnLIJRo0FY0hPI/NqTpHPFq5/ZOrt14bDeBf6i4EYYLcI 29vJSY0z7ap4b2PYhCjUczTtQ8xPl+Z+n5iPNcGypifLlkcrP/xpJttB1tD2WPg= X-Gm-Gg: ASbGncvxSQGlk4kiD3Q5Jyn1XJkQpZ3RTC8N3q6gkVFD/CbwbNOiQxSE6i2L0GT4gYt j+k2YrBCmudLE+T/xR92dfJtC/p9gSvMrFo1l2QFCpxSsldJT6512EEwneH9+BWDc6mQYri8hG3 oR4haWS2bbtRdiPUPP0d/PtwRK8P+soNaEjMFMihZsFutqU5C6Yb6PhcXq35mrxm5eQVYolkGC7 3o3E3M0WBWTh2/jQkkOkK/HPbiCyMKH2ab94vJbUfE/EKwaDJQ5rrAnoMPjpB/R X-Google-Smtp-Source: AGHT+IGIJhOnEc3zWaTR7ImuwsB7dqzjQabiuroM48+nisL8PT0O38c5xZ0k4VU0MQuusWD0teh7Jg== X-Received: by 2002:a17:90b:520f:b0:2ee:db8a:29f0 with SMTP id 98e67ed59e1d1-2f548f1b7e6mr16773814a91.27.1736540783484; Fri, 10 Jan 2025 12:26:23 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f22eb8esm17091825ad.166.2025.01.10.12.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 12:26:22 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: mkarsten@uwaterloo.ca, Joe Damato , "Michael S. Tsirkin" , Jason Wang , 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 3/3] virtio_net: Map NAPIs to queues Date: Fri, 10 Jan 2025 20:26:04 +0000 Message-Id: <20250110202605.429475-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250110202605.429475-1-jdamato@fastly.com> References: <20250110202605.429475-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 Reviewed-by: Gerhard Engleder --- drivers/net/virtio_net.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 4e88d352d3eb..8f0f26cc5a94 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2804,14 +2804,28 @@ static void virtnet_napi_do_enable(struct virtqueue= *vq, } =20 static void virtnet_napi_enable_lock(struct virtqueue *vq, - struct napi_struct *napi) + struct napi_struct *napi, + bool need_rtnl) { + struct virtnet_info *vi =3D vq->vdev->priv; + int q =3D vq2rxq(vq); + virtnet_napi_do_enable(vq, napi); + + if (q < vi->curr_queue_pairs) { + if (need_rtnl) + rtnl_lock(); + + netif_queue_set_napi(vi->dev, q, NETDEV_QUEUE_TYPE_RX, napi); + + if (need_rtnl) + rtnl_unlock(); + } } =20 static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *= napi) { - virtnet_napi_enable_lock(vq, napi); + virtnet_napi_enable_lock(vq, napi, false); } =20 static void virtnet_napi_tx_enable(struct virtnet_info *vi, @@ -2848,9 +2862,13 @@ 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 + rtnl_lock(); + netif_queue_set_napi(vi->dev, i, NETDEV_QUEUE_TYPE_RX, NULL); + rtnl_unlock(); napi_disable(&rq->napi); + still_empty =3D !try_fill_recv(vi, rq, GFP_KERNEL); - virtnet_napi_enable_lock(rq->vq, &rq->napi); + virtnet_napi_enable_lock(rq->vq, &rq->napi, true); =20 /* In theory, this can happen: if we don't get any buffers in * we will *never* try to fill again. @@ -3048,6 +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); + netif_queue_set_napi(vi->dev, qp_index, NETDEV_QUEUE_TYPE_RX, NULL); napi_disable(&vi->rq[qp_index].napi); xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); } @@ -3317,8 +3336,10 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, s= truct net_device *dev) static void virtnet_rx_pause(struct virtnet_info *vi, struct receive_queue= *rq) { bool running =3D netif_running(vi->dev); + int q =3D vq2rxq(rq->vq); =20 if (running) { + netif_queue_set_napi(vi->dev, q, NETDEV_QUEUE_TYPE_RX, NULL); napi_disable(&rq->napi); virtnet_cancel_dim(vi, &rq->dim); } @@ -5943,6 +5964,8 @@ 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++) { + netif_queue_set_napi(vi->dev, i, NETDEV_QUEUE_TYPE_RX, + NULL); napi_disable(&vi->rq[i].napi); virtnet_napi_tx_disable(&vi->sq[i].napi); } --=20 2.25.1