From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (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 C079079DAF; Thu, 1 Feb 2024 06:01:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706767268; cv=none; b=BbdWgXhkMZbFO4mFV2EQMG7slYisZu9sBEabul8IV5+emCWMtWXRxyKHeJWRQNYUHr7iqaXI2P6CwycVhLduSFwYbD39QfMeJ5+iEyLdQ+7/vnGWWMHQMxkN6ZwXbEtBHSIPwFZAEP7RGevABLuU6xboLBxy2NetOTOXChPgzKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706767268; c=relaxed/simple; bh=OSfWm0Cv54Tjo1qbzali/LaPJkHOmXhcoj7cbZQForM=; h=Message-ID:Subject:Date:From:To:Cc:References:In-Reply-To: Content-Type; b=aDdbuVo2ItesQNAQ9OkX9VVePLWzEYCtnhref9FySUWLuUNr82p3HHzJoPxIvh7U6kxD8wl0J0UTTu93fM7pVToacqTKkpmShfEoh5yhRalhJonuyWexhYgVLWiPVgCH4qXWAKlU7GXGuqiuVHZwLSCLJUx7ngbULrVPgC7pNhE= 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=v8wHP4Kw; arc=none smtp.client-ip=115.124.30.101 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="v8wHP4Kw" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1706767262; h=Message-ID:Subject:Date:From:To:Content-Type; bh=+X9URvqMFwi5HlX6CS16ZlVcfG6G7YCThFlcfQTyeJk=; b=v8wHP4Kw6A2J4H7xoBcINDCL6DAde0IfksikeDWIE8cOGbTIiLtKWEhpVwQ6ZJvx6ZAVJXR3+6L1wnFEffYu7vbPR0uDaeLMVm280raQHODVqS/YM2jqOfwpFACip11JZ7olJ8MfSPAmLE4uolOgWBtHE4izt+9CYB7PvYZnYH0= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R791e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=36;SR=0;TI=SMTPD_---0W.obMGn_1706767259; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0W.obMGn_1706767259) by smtp.aliyun-inc.com; Thu, 01 Feb 2024 14:01:00 +0800 Message-ID: <1706766995.312187-2-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH vhost 17/17] virtio_net: sq support premapped mode Date: Thu, 1 Feb 2024 13:56:35 +0800 From: Xuan Zhuo To: Jason Wang Cc: virtualization@lists.linux.dev, Richard Weinberger , Anton Ivanov , Johannes Berg , "Michael S. Tsirkin" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Vadim Pasternak , Bjorn Andersson , Mathieu Poirier , Cornelia Huck , Halil Pasic , Eric Farman , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Benjamin Berg , Yang Li , linux-um@lists.infradead.org, netdev@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, bpf@vger.kernel.org References: <20240130114224.86536-1-xuanzhuo@linux.alibaba.com> <20240130114224.86536-18-xuanzhuo@linux.alibaba.com> <1706757660.3554723-2-xuanzhuo@linux.alibaba.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: On Thu, 1 Feb 2024 13:36:46 +0800, Jason Wang wrote: > On Thu, Feb 1, 2024 at 11:28=E2=80=AFAM Xuan Zhuo wrote: > > > > On Wed, 31 Jan 2024 17:12:47 +0800, Jason Wang wr= ote: > > > On Tue, Jan 30, 2024 at 7:43=E2=80=AFPM Xuan Zhuo wrote: > > > > > > > > If the xsk is enabling, the xsk tx will share the send queue. > > > > But the xsk requires that the send queue use the premapped mode. > > > > So the send queue must support premapped mode. > > > > > > > > Signed-off-by: Xuan Zhuo > > > > --- > > > > drivers/net/virtio_net.c | 167 +++++++++++++++++++++++++++++++++++= +++- > > > > 1 file changed, 163 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > > > index 226ab830870e..cf0c67380b07 100644 > > > > --- a/drivers/net/virtio_net.c > > > > +++ b/drivers/net/virtio_net.c > > > > @@ -46,6 +46,7 @@ module_param(napi_tx, bool, 0644); > > > > #define VIRTIO_XDP_REDIR BIT(1) > > > > > > > > #define VIRTIO_XDP_FLAG BIT(0) > > > > +#define VIRTIO_DMA_FLAG BIT(1) > > > > > > > > /* RX packet size EWMA. The average packet size is used to determi= ne the packet > > > > * buffer size when refilling RX rings. As the entire RX ring may = be refilled > > > > @@ -140,6 +141,21 @@ struct virtnet_rq_dma { > > > > u16 need_sync; > > > > }; > > > > > > > > +struct virtnet_sq_dma { > > > > + union { > > > > + struct virtnet_sq_dma *next; > > > > + void *data; > > > > + }; > > > > + dma_addr_t addr; > > > > + u32 len; > > > > + bool is_tail; > > > > +}; > > > > + > > > > +struct virtnet_sq_dma_head { > > > > + struct virtnet_sq_dma *free; > > > > + struct virtnet_sq_dma *head; > > > > > > Any reason the head must be a pointer instead of a simple index? > > > > > > The head is used for kfree. > > Maybe I need to rename it. > > > > About the index(next) of the virtnet_sq_dma. > > If we use the index, the struct will be: > > > > struct virtnet_sq_dma { > > dma_addr_t addr; > > u32 len; > > > > u32 next; > > void *data > > }; > > > > The size of virtnet_sq_dma is same. > > Ok. > > > > > > > > > > > > +}; > > > > + > > > > /* Internal representation of a send virtqueue */ > > > > struct send_queue { > > > > /* Virtqueue associated with this send _queue */ > > > > @@ -159,6 +175,8 @@ struct send_queue { > > > > > > > > /* Record whether sq is in reset state. */ > > > > bool reset; > > > > + > > > > + struct virtnet_sq_dma_head dmainfo; > > > > }; > > > > > > > > .... > > > > > > + > > > > +static int virtnet_sq_init_dma_mate(struct send_queue *sq) > > > > +{ > > > > + struct virtnet_sq_dma *d; > > > > + int size, i; > > > > + > > > > + size =3D virtqueue_get_vring_size(sq->vq); > > > > + > > > > + size +=3D MAX_SKB_FRAGS + 2; > > > > > > Is this enough for the case where an indirect descriptor is used? > > > > > > This is for the case, when the ring is full, the xmit_skb is called. > > > > I will add comment. > > Just to make sure we are at the same page. > > I meant, we could have more pending #sg than allocated here. > > For example, we can have up to (vring_size - 2 - MAX_SKB_FRAGS) * > MAX_SKB_FRAGS number of pending sgs? > Oh, my was wrong. But the max value a But shouldn't the maximum value be vring_size * (2 + MAX_SKB_FRAGS)? And for the reason above, we should allocate (vring_size + 1) * (2 + MAX_SK= B_FRAGS); Thanks. > Thanks > > > > > Thanks. > > > > > > > > > > Thanks > > > > > >