From patchwork Mon Jul 8 11:25:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 13726436 X-Patchwork-Delegate: kuba@kernel.org Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 166117E0EA; Mon, 8 Jul 2024 11:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720437957; cv=none; b=sUDd8vPUgceF8oo/S6+AuT3iCN3s5ekjzVJr8Jxu3E2Ac8pCzWXkjaHK/OGNqw3hoT6Ggi4YWd2/SQ2v/0j0IZjlw4um0m1lYTHZTJ/Jv8K7NMH52PlpDZAkPCo+hHpapZ0BEnMO/aoiL3wXuk6SJs7NrImJqqafqgm4ouZOB+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720437957; c=relaxed/simple; bh=rGJc5hEPMzfyjL/iFsdlvssJlEZJwSgpRlS/qvXgYF4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ABWOB+swi17HSj3yGptpUxMdP/ytFq1GEcBKxiI2ecKGzJgxwjsT+oM1J970ZR1zNcxECKlsbMnrZHALQvsm+4ckhjV2XfmaUiNvTsA8Uv8X742IV1TEPdrRE30hlLdevcnQ5lrwoQZgwyGL53+NJdimDKBKpYXqfwViTDtLcac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=sNC2I1zx; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="sNC2I1zx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1720437947; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=MCa21Uiv2zEGi7Rr1bqY3eqwGd+Po10RpvvMm6XC6b8=; b=sNC2I1zxZbUTz6oxYtdoHjnDo6UjtWgyML1r/wj3YNcmT7jTumhfiBILir6VcZVvlxjgOL/lfkbEjIfRY+dvcgvEU4AqWPjSFJT2Tgqp6axM8v3grXMvZDI/CviGJzG0eWixLxOpkz0x50M2MGzalxI7mmvg5a8LUkYCXkj7pE8= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R341e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032014031;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0WA4mZfP_1720437945; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0WA4mZfP_1720437945) by smtp.aliyun-inc.com; Mon, 08 Jul 2024 19:25:45 +0800 From: Xuan Zhuo To: netdev@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , virtualization@lists.linux.dev, bpf@vger.kernel.org Subject: [PATCH net-next v8 07/10] virtio_net: xsk: support wakeup Date: Mon, 8 Jul 2024 19:25:34 +0800 Message-Id: <20240708112537.96291-8-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240708112537.96291-1-xuanzhuo@linux.alibaba.com> References: <20240708112537.96291-1-xuanzhuo@linux.alibaba.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Git-Hash: 74fbc055cff2 X-Patchwork-Delegate: kuba@kernel.org xsk wakeup is used to trigger the logic for xsk xmit by xsk framework or user. Virtio-net does not support to actively generate an interruption, so it tries to trigger tx NAPI on the local cpu. Signed-off-by: Xuan Zhuo Acked-by: Jason Wang --- drivers/net/virtio_net.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c4f5ebd10092..665b4925e545 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1054,6 +1054,29 @@ static void check_sq_full_and_disable(struct virtnet_info *vi, } } +static int virtnet_xsk_wakeup(struct net_device *dev, u32 qid, u32 flag) +{ + struct virtnet_info *vi = netdev_priv(dev); + struct send_queue *sq; + + if (!netif_running(dev)) + return -ENETDOWN; + + if (qid >= vi->curr_queue_pairs) + return -EINVAL; + + sq = &vi->sq[qid]; + + if (napi_if_scheduled_mark_missed(&sq->napi)) + return 0; + + local_bh_disable(); + virtqueue_napi_schedule(&sq->napi, sq->vq); + local_bh_enable(); + + return 0; +} + static int __virtnet_xdp_xmit_one(struct virtnet_info *vi, struct send_queue *sq, struct xdp_frame *xdpf) @@ -5399,6 +5422,7 @@ static const struct net_device_ops virtnet_netdev = { .ndo_vlan_rx_kill_vid = virtnet_vlan_rx_kill_vid, .ndo_bpf = virtnet_xdp, .ndo_xdp_xmit = virtnet_xdp_xmit, + .ndo_xsk_wakeup = virtnet_xsk_wakeup, .ndo_features_check = passthru_features_check, .ndo_get_phys_port_name = virtnet_get_phys_port_name, .ndo_set_features = virtnet_set_features,