From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 1FD461CA9D for ; Thu, 9 Nov 2023 12:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DNX5qZp4" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77BC72D73 for ; Thu, 9 Nov 2023 04:00:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699531258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6eDiBFLAnCrKz/HLR+x0JbeNr1epw8uPCaTepk4XHCs=; b=DNX5qZp46/L/dMKjFewutad11Q5iQRgQL2GwxLlJKkC/muSKLZqLbtQYdBogYivnleG5Mz TTwDh4TL2aJvkQqlDjbmF2Q40UXKc/5Ab4/LRdfG8W9+i68X0UbYB6r9iPuqKBom1UGUJL vdg0EzxujQ237I91I0a6rm62vuB/CVE= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-466-PASpnVQENECFRpnEa4P6Kg-1; Thu, 09 Nov 2023 07:00:57 -0500 X-MC-Unique: PASpnVQENECFRpnEa4P6Kg-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9bf1047cb28so64900466b.2 for ; Thu, 09 Nov 2023 04:00:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699531256; x=1700136056; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6eDiBFLAnCrKz/HLR+x0JbeNr1epw8uPCaTepk4XHCs=; b=HTY3ixiFZBYlB/WN6VtJsiOU9bk4cO8mSfV2SV2ZJ7RHwJce5mxep2qE/edAUZegU+ zP9buetWWBhd+TUAKpEDV0BxeWucPPm9U7A3K9OrLqGemX0Ooe4qgOEM6NVhK/a1pYD5 s+wyYmObAVGkkq5D0iCC+nieGWuROniUjkXzmxl1dOSplGX9eUmRUlC+3vK6oYbksnu/ bDvqM5tAD5tpkeZIKkuPmz+q6yFb4ms6OGm5EI4tU/qz9ZbOTptoFafYKtCXA1BFUHcx n96DnO0E8WJovDLTZZ9QYlC+uia8x72GQfs3xNNB+Qed5JNg9TzETSNcYfMLDI8jN/SS U2CQ== X-Gm-Message-State: AOJu0Yy/4kSjpj+rEbmVsj3/D406O2OrwJxFzlB7s72iTZe7QSHrmU7K 0Jy7M75eH8aqb9e//oHeQfP1TLpAWklelItSudCxtajRTRmt2qzg7gJ0p/W1QS4Vq10Fqc/DDE3 X18NYQJBIGNS7d5kK X-Received: by 2002:a17:906:c10c:b0:9da:ede1:12b0 with SMTP id do12-20020a170906c10c00b009daede112b0mr4147308ejc.19.1699531256083; Thu, 09 Nov 2023 04:00:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiSGqYF9oN/EASaOZpvyHTXGo5qMc9peSAyaQSqNz6dFHoiBc0UQOM8QPa5WXgzBjhS7oiYg== X-Received: by 2002:a17:906:c10c:b0:9da:ede1:12b0 with SMTP id do12-20020a170906c10c00b009daede112b0mr4147283ejc.19.1699531255774; Thu, 09 Nov 2023 04:00:55 -0800 (PST) Received: from redhat.com ([2a02:14f:1f4:2044:be5a:328c:4b98:1420]) by smtp.gmail.com with ESMTPSA id n22-20020a170906841600b009b27d4153c0sm2456322ejx.178.2023.11.09.04.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 04:00:55 -0800 (PST) Date: Thu, 9 Nov 2023 07:00:51 -0500 From: "Michael S. Tsirkin" To: Xuan Zhuo Cc: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jason Wang , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Subject: Re: [PATCH net-next v2 17/21] virtio_net: xsk: rx: skip dma unmap when rq is bind with AF_XDP Message-ID: <20231109070015-mutt-send-email-mst@kernel.org> References: <20231107031227.100015-1-xuanzhuo@linux.alibaba.com> <20231107031227.100015-18-xuanzhuo@linux.alibaba.com> <20231109031347-mutt-send-email-mst@kernel.org> <1699528202.3090942-4-xuanzhuo@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1699528202.3090942-4-xuanzhuo@linux.alibaba.com> On Thu, Nov 09, 2023 at 07:10:02PM +0800, Xuan Zhuo wrote: > On Thu, 9 Nov 2023 03:15:03 -0500, "Michael S. Tsirkin" wrote: > > On Tue, Nov 07, 2023 at 11:12:23AM +0800, Xuan Zhuo wrote: > > > When rq is bound with AF_XDP, the buffer dma is managed > > > by the AF_XDP APIs. So the buffer got from the virtio core should > > > skip the dma unmap operation. > > > > > > Signed-off-by: Xuan Zhuo > > > > > > I don't get it - is this like a bugfix? > > I want focus on this. So let it as an independent commit. > > > And why do we need our own flag and checks? > > Doesn't virtio core DTRT? > > > struct vring_virtqueue { > [....] > > /* Do DMA mapping by driver */ > bool premapped; > > We can not. > > So I add own flag. > > Thanks. Still don't get it. Why not check the premapped flag? > > > > > > --- > > > drivers/net/virtio/main.c | 8 +++++--- > > > drivers/net/virtio/virtio_net.h | 3 +++ > > > drivers/net/virtio/xsk.c | 1 + > > > 3 files changed, 9 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/net/virtio/main.c b/drivers/net/virtio/main.c > > > index 15943a22e17d..a318b2533b94 100644 > > > --- a/drivers/net/virtio/main.c > > > +++ b/drivers/net/virtio/main.c > > > @@ -430,7 +430,7 @@ static void *virtnet_rq_get_buf(struct virtnet_rq *rq, u32 *len, void **ctx) > > > void *buf; > > > > > > buf = virtqueue_get_buf_ctx(rq->vq, len, ctx); > > > - if (buf && rq->do_dma) > > > + if (buf && rq->do_dma_unmap) > > > virtnet_rq_unmap(rq, buf, *len); > > > > > > return buf; > > > @@ -561,8 +561,10 @@ static void virtnet_set_premapped(struct virtnet_info *vi) > > > > > > /* disable for big mode */ > > > if (vi->mergeable_rx_bufs || !vi->big_packets) { > > > - if (!virtqueue_set_dma_premapped(vi->rq[i].vq)) > > > + if (!virtqueue_set_dma_premapped(vi->rq[i].vq)) { > > > vi->rq[i].do_dma = true; > > > + vi->rq[i].do_dma_unmap = true; > > > + } > > > } > > > } > > > } > > > @@ -3944,7 +3946,7 @@ void virtnet_rq_free_unused_buf(struct virtqueue *vq, void *buf) > > > > > > rq = &vi->rq[i]; > > > > > > - if (rq->do_dma) > > > + if (rq->do_dma_unmap) > > > virtnet_rq_unmap(rq, buf, 0); > > > > > > virtnet_rq_free_buf(vi, rq, buf); > > > diff --git a/drivers/net/virtio/virtio_net.h b/drivers/net/virtio/virtio_net.h > > > index 1242785e311e..2005d0cd22e2 100644 > > > --- a/drivers/net/virtio/virtio_net.h > > > +++ b/drivers/net/virtio/virtio_net.h > > > @@ -135,6 +135,9 @@ struct virtnet_rq { > > > /* Do dma by self */ > > > bool do_dma; > > > > > > + /* Do dma unmap after getting buf from virtio core. */ > > > + bool do_dma_unmap; > > > + > > > struct { > > > struct xsk_buff_pool *pool; > > > > > > diff --git a/drivers/net/virtio/xsk.c b/drivers/net/virtio/xsk.c > > > index e737c3353212..b09c473c29fb 100644 > > > --- a/drivers/net/virtio/xsk.c > > > +++ b/drivers/net/virtio/xsk.c > > > @@ -210,6 +210,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct virtnet_rq * > > > xdp_rxq_info_unreg(&rq->xsk.xdp_rxq); > > > > > > rq->xsk.pool = pool; > > > + rq->do_dma_unmap = !pool; > > > > > > virtnet_rx_resume(vi, rq); > > > > > > -- > > > 2.32.0.3.g01195cf9f > > > >