From patchwork Fri Jan 10 20:26:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13935459 X-Patchwork-Delegate: kuba@kernel.org 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 22B9921578A for ; Fri, 10 Jan 2025 20:26:20 +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=1736540782; cv=none; b=NLXjmrygogDXq3WWHYs4pEvP7wX4mnW4Yf2Ht79Wn/+iVvyPFIiugNf1RsvNJZ7uXY1h9ut4eVG5JKeyvixu6nA/CmHjPhO4RR/JD99LZ3VCgp7t2wR40fXAkhbL6Yymk87Wsg7tqmPUfdJQNETTD5puUb8yCPmrKKTLSz1zPvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540782; c=relaxed/simple; bh=L//1ItUL/phY7fZdnQAHFMdHc+JAiSoz2Yj9uNn6Lyc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TqCl8bpCd67GFfG474ZfpT5hTjDKSJh7+fUJJYJt4RRiAlWhucTEX1/o57EaWEA5S51pghJwUh7M2yfj0vpuGHPE54Lj6QL5OLFMD0WNkz07RKIl30yDolP3l/oObyOnfDPdJNXuuymz6kMsKAV9xtBeHWgUrlVYvdBvpTqAa3k= 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=fIpWSx1T; 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="fIpWSx1T" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21661be2c2dso40446085ad.1 for ; Fri, 10 Jan 2025 12:26:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1736540780; x=1737145580; 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=lYBtxkIddVIdjfELPff+6zSxWcfnw5xo+urXkFqVelo=; b=fIpWSx1TcEHg+cMQTbr3vp2AsUt+f89yhfUWQDiExFbfNnVE+KyA+ink+4flsQysJ2 wEUIDSJAbxWpFNBU+0yio3GyiQ3tHDKx963dnxYrONmqehce9qd2IsBq6nPLLsEoW/EY 6+VwzmQIXRtrNTjXlBj5n9wi+mt5biBFc2o7Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736540780; x=1737145580; 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=lYBtxkIddVIdjfELPff+6zSxWcfnw5xo+urXkFqVelo=; b=Runcoa7dJPtZthDDav4syOEPx4Ygd5ZRBo5z7qaUg5O2zRjcmf+rAuwN9YoFCmn7W3 BpbTwmkpJxI7il90NL21XGeuvp9KxmAzgwrPTmtfA0vjYBg7uhG4fXCNaVKUwvoolgOf ZaKC2PgA8W6HU9vOLfoMOHL7PdVmpmu9On6umFLS5GLVAp0N9fp5d0jKpL6mpwcE/rLH ORMG8DKcpSNrpK8VwjAoekVAvNoC8t7PghLhGP5CAyNBfz6GPnfqB6XkpPmQ9PsFDyLU I/DMRiYLIZiSg0qEyoJSuFufuqkIgcg24ZuGHoQTVdZ27GJHNYLd9Qu0JwK3IwZEDZWw GS2w== X-Gm-Message-State: AOJu0YzSqQZ0jFVg6E1coAV6kPpjz5zfGLbtIxSEEIK5J6OwKgCBpx1E 50MSd9mtPqunrCRjKvMaNjT39B7AouQTu4SKnG3EYfmH+RUOVtTS9pGtdrlp1x9VfzNFauI00Ar 7HTmi1Mb1Go0irn2fYgt+5Lj5ZrlRaN6JRnkh4M5B2vrqR07t27S2FNgst9Y/0zbfpodc+rFz6A xTtGK3jCub7t8q62QBlgLHN0ZN+BjiDePUP0w= X-Gm-Gg: ASbGncvb45mGMo5NkmE2dghDTpChz1UhF+jPgMGjv5l5QJ9rhr7/3ebmvJO5vB41nqu syplocuVZQMEHsf0Eiv7oPIFe1ehSb3UTrpb9rEUiqfEsPc/LtYtlwxlin8DBf8r6ZMmZs5nhir iZQ7io7nDFhmyC5W6jUrPzYkp7OsIvmts8DVM+aZux8VMHiSF4hcwIyOSRtkzvYj/MAJ8Y4Ax/v GfTpi4E36DAQWRF4Q+aAvpqeXv/8D6bpfj+VfiICyimY23amSX3xrbfrMIPAh4G X-Google-Smtp-Source: AGHT+IE/1wk47T+YBogVHpi2dklAZot8YbzIIrliuB0Q46BizHw8aPtqwioCvHXYsjt1ulmmZpPd0w== X-Received: by 2002:a17:902:ea08:b0:215:9894:5679 with SMTP id d9443c01a7336-21a83da498emr183024235ad.0.1736540779765; Fri, 10 Jan 2025 12:26:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 12:26:18 -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_P=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 1/3] virtio_net: Prepare for NAPI to queue mapping Date: Fri, 10 Jan 2025 20:26:02 +0000 Message-Id: <20250110202605.429475-2-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: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Slight refactor to prepare the code for NAPI to queue mapping. No functional changes. Signed-off-by: Joe Damato Reviewed-by: Gerhard Engleder --- 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); } -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); @@ -2802,6 +2803,11 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) local_bh_enable(); } +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_info *vi, return; } - return virtnet_napi_enable(vq, napi); + virtnet_napi_do_enable(vq, napi); } static void virtnet_napi_tx_disable(struct napi_struct *napi) From patchwork Fri Jan 10 20:26:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13935460 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 3820B21B1BF for ; Fri, 10 Jan 2025 20:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540785; cv=none; b=UFY8QvTQII0vo8mbibkCk7hmq3uE7elkxt+S4IvFLj3ykLEeuPwFEyM6ACuByE/x1VxBfso023A6RFqiZehaK5yfbNhqJx8VewpKEVOXYnrPfAF9PfGmpelP2W+wfk26iW8LVOf+aFUS8MUTcn2xawHQknx/dqwsF5Oqm4bxEW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540785; c=relaxed/simple; bh=z8f+xuxsM4TN11cQa7K629H96IgZ46RfWlBQbRy438c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M0ycFORZ6aDFpHNbf0f555oeNJ/e37et9ydkZrU+3PjRJk3PLvSjUEVBPE0fjrYTs6pzN1AAK9Tp7ZcOQ51A7JFNGCNr93nOrNrTktm2mnadc/B9zSSTTiZf+/25QQr7OtEvR14ZkZ/kosJWYGVacT57J1H33HX0hkrKcfGKd/c= 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=gp5aYnAY; arc=none smtp.client-ip=209.85.216.50 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="gp5aYnAY" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2ee8e8e29f6so3366722a91.0 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=3Ik/OAXhd/zh+RJRbmUQzcFN2s3YuP0CmCWofX99x/A=; b=gp5aYnAYEQfwMWPhkjTTo6N3CLV14Ga1Ta6uQtOinO1zVB7leANLUrv4Uhk+hV4W8t RehtH3vA+4TLLzAW5KHeTd4y2frd3EWEpMsVrtMTziKQys7AOqyT4rO7ksWaFqvF5VBb FySkdRuL/SWC3QdrZxSf9It2AdqWLtCV8ElBs= 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=3Ik/OAXhd/zh+RJRbmUQzcFN2s3YuP0CmCWofX99x/A=; b=X4ZDt165NbUZ0a3TBOgyaCAl2IV9bK8+6VHikJ/UW093ONBvtoJdFWiS4iqpY395OJ e5ZcYc0NhSNwp0FWLlYrr8QqltYnxHoMoJh3m58dcIY8KnXdp0WCrr/pGdYH78sWojut 8Q6eUiWhBnmU0E/JIGuu9W9Jd+A70b/sJEGbG3DCZUyPcnI3DianUZu/M/CreIz0Tsa3 1FkTbW7T2APh4kb7MDq3TchsrHRU0olhK2mLGE0Pvv0r279ZcPv3KwYJxxIHHvfutFcP b20wvQXhL1wE2pTNXOBs4Sb8RQHq2jiExEkpfUoY2h44S7pSZXFrSGwQQiYFnp1QSE6E dsAg== X-Gm-Message-State: AOJu0YwWS9U7x5Lr9G1mIbQ3u+PxtGCsR1Ng6vxT1DzMI1hrN9WrVWB9 fl3zL9DAEUdOAHoeIQ8leHEYhyt2bntZx5shzkLEp5OC0im7603/EbAZmi58XNKcjyFCu1nI/2G N6kp3szUbl4ZEdWaXY+sGbHu9USqRUTMgsHCVY0xHVEKDYVHNUcVJh5gdSFJCuIDdgAhsFVAEyJ EQPTPA/V++dkEytT1c5Ne1M6lkFnNm9XLRzZI= X-Gm-Gg: ASbGnctFdIdFWG+rqzF7D2ICPZZfSRYu9qq2O1R+wfgh8zvSrQNYdwZP4tIHoOQnOWL ktZY3AOBvvRQsH0EQAN50K7LVOusL/F8+zIvMsBJvHaHSv7eP039fpFmcJVsEkdY1pSbB5jBZv0 j09spb8Q7b7vbVggPaBwqJ75WCcyoCEUnbSvgg7EvsW+KY7pFRfjCWJo+SgLPQs/U6V5J5O5FBS g6PtsijA4Ctlml/ptaJ2qddoGJJue3t0MuSFgncljm1CVGMoCGF9uDYiH33V1gB X-Google-Smtp-Source: AGHT+IGukifaC2WcNQEFeWzn03HlxqND0jHU8i/CmAXEOKXmIs5P2HeRfZRbh+3c5FScxgk06QKRWg== X-Received: by 2002:a17:90b:6d0:b0:2ee:889b:b11e with SMTP id 98e67ed59e1d1-2f5490bd257mr17730230a91.30.1736540781585; Fri, 10 Jan 2025 12:26:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 12:26:21 -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_P=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 2/3] virtio_net: Hold RTNL for NAPI to queue mapping Date: Fri, 10 Jan 2025 20:26:03 +0000 Message-Id: <20250110202605.429475-3-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: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Prepare for NAPI to queue mapping by holding RTNL in code paths where NAPIs will be mapped to queue IDs and RTNL is not currently held. Signed-off-by: Joe Damato Reviewed-by: Gerhard Engleder --- drivers/net/virtio_net.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index cff18c66b54a..4e88d352d3eb 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2803,11 +2803,17 @@ static void virtnet_napi_do_enable(struct virtqueue *vq, local_bh_enable(); } -static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) +static void virtnet_napi_enable_lock(struct virtqueue *vq, + struct napi_struct *napi) { virtnet_napi_do_enable(vq, napi); } +static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) +{ + virtnet_napi_enable_lock(vq, napi); +} + static void virtnet_napi_tx_enable(struct virtnet_info *vi, struct virtqueue *vq, struct napi_struct *napi) @@ -2844,7 +2850,7 @@ static void refill_work(struct work_struct *work) napi_disable(&rq->napi); still_empty = !try_fill_recv(vi, rq, GFP_KERNEL); - virtnet_napi_enable(rq->vq, &rq->napi); + virtnet_napi_enable_lock(rq->vq, &rq->napi); /* In theory, this can happen: if we don't get any buffers in * we will *never* try to fill again. @@ -5621,8 +5627,11 @@ static void virtnet_freeze_down(struct virtio_device *vdev) netif_tx_lock_bh(vi->dev); netif_device_detach(vi->dev); netif_tx_unlock_bh(vi->dev); - if (netif_running(vi->dev)) + if (netif_running(vi->dev)) { + rtnl_lock(); virtnet_close(vi->dev); + rtnl_unlock(); + } } static int init_vqs(struct virtnet_info *vi); @@ -5642,7 +5651,9 @@ static int virtnet_restore_up(struct virtio_device *vdev) enable_rx_mode_work(vi); if (netif_running(vi->dev)) { + rtnl_lock(); err = virtnet_open(vi->dev); + rtnl_unlock(); if (err) return err; } From patchwork Fri Jan 10 20:26:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13935461 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 8A83F21B908 for ; Fri, 10 Jan 2025 20:26:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540786; cv=none; b=CLJg6yxU7GUlDblUKedcG8pV9vb3x0SZfCIWlHR+Ym+1aOj9KFE1tV6CDozm+9YGy/FfIs5Y1I2bWYWJnkKkimVo3qmqVuKOxkR1BVxDlBOe6hld3RuZPYLQZ1ovI7q5v2VkmnTDXPxFCAOTSFywoOm5QPzdD9eV5puSUbYoZqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540786; c=relaxed/simple; bh=nXNvmseKjVxOB/p5zaC6W1Bj1mcIQTUBPceRSuG8Qpc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qJoSgRXb45jEZGlwF4CmOEOJHM9/IZjo/SPFA08qEAIrD1Jt3sScZF/8g6yk+t/bJ9R6OXptmxnnHI6srW5Nx6FH04MHTiAkkwznhg4pewKxjl4lQNi72DLxXdn1m4h0ap14PUUrMzGczwD80OJ74N2hs/N+CpkkXRsNhwtwP78= 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.216.43 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-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2ee709715d9so3508948a91.3 for ; Fri, 10 Jan 2025 12:26:24 -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=CXPo9Uio1orYt4WVwZ/5VY6RVxHGQ3w2fAvJrmJIKpVR57hU1FmF6QHTTngt639DbI WuLCffvrsUt8FdapCoZzbkrdO21vFV/kcnpGWsh1TLhZ+G2ahnY5JA6t6oN0GBJnoPyK w5GB7ZC0YpdGybdevX8ZJdk2wQctm+ZtHpeLQWaYvLVMBybnBsRa8RjpOatJupMe6gpG 7TCihe/FmkQ5SzTTwtfuSUWM1S0jzWOP5kcRnWhxTA2uVqWlR7bVQWOtpDVmKC5njJQX Rl/SXLvqleB8Psrc+c7K+mRMciBMa1REe9TTstSdEUgcNeCV83C1wF5E2GsAykeKKMQs uaMA== X-Gm-Message-State: AOJu0YyeZ+x4H1hM8s6UEf4uCM5X3nKYIP7XG1u6xmbj1NITI4yUxV+C /hvrF3PrAr3STL9Jij5gAHwt3zza7OI2jlawODfkdgfCy8YDEF+b4M8xfWkgoCDTgIR4u7MUJJ5 JBnJiILo02HY/LN9z7qQoZZ+8LMWKZsz8D9ZaitnqQxVw9h8Jq97GfWAfcDFeigDfq+dnfcj071 PBYwpNq9oz12TBP/nKUftHcZ1Zsg4KYTXA/us= X-Gm-Gg: ASbGnctgjbGKavghhirH5TjG7yBzqBYDGvS7SaP5psgSYgHRxrClgIVQiFOL7wUfCAq luiiyfh4PPZxPUfd7LSFjXbWZKs3X6/DaMzfOlCC43e3a8VQ2wJM5QngX+LNP6+LqzzZpjSiHWf 6ZJvwFMC7XtDIQV6ahuGUFxoOTWIZHY+GljRJGj6GRJrG8CrplhNvSOnmNu4WEVD5Xo4ko7CLt+ +XxHkrZbkXbpkx6TS85BDT0arA6o1y6SoMt8ykOk+J5R4J6eCJWqPBfMxLhF9GL 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_P=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: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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='{"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, } static void virtnet_napi_enable_lock(struct virtqueue *vq, - struct napi_struct *napi) + struct napi_struct *napi, + bool need_rtnl) { + struct virtnet_info *vi = vq->vdev->priv; + int q = 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(); + } } 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); } static void virtnet_napi_tx_enable(struct virtnet_info *vi, @@ -2848,9 +2862,13 @@ static void refill_work(struct work_struct *work) for (i = 0; i < vi->curr_queue_pairs; i++) { struct receive_queue *rq = &vi->rq[i]; + rtnl_lock(); + netif_queue_set_napi(vi->dev, i, NETDEV_QUEUE_TYPE_RX, NULL); + rtnl_unlock(); napi_disable(&rq->napi); + still_empty = !try_fill_recv(vi, rq, GFP_KERNEL); - virtnet_napi_enable_lock(rq->vq, &rq->napi); + virtnet_napi_enable_lock(rq->vq, &rq->napi, true); /* 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_index) { 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, struct net_device *dev) static void virtnet_rx_pause(struct virtnet_info *vi, struct receive_queue *rq) { bool running = netif_running(vi->dev); + int q = vq2rxq(rq->vq); 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, struct bpf_prog *prog, /* Make sure NAPI is not using any XDP TX queues for RX. */ if (netif_running(dev)) { for (i = 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); }