From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 8FE9123D4 for ; Fri, 10 Nov 2023 05:33:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bax7+73u" Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 1780E83720 for ; Fri, 10 Nov 2023 05:33:39 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 1780E83720 Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bax7+73u X-Virus-Scanned: amavisd-new at osuosl.org X-Spam-Flag: NO X-Spam-Score: -2.099 X-Spam-Level: Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6bzoUhOYnaP2 for ; Fri, 10 Nov 2023 05:33:37 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id BC70083419 for ; Fri, 10 Nov 2023 05:33:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org BC70083419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699594416; 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=KA0v3OBMTeHRtp+JBUoL+seQE2z12N8pOIFQ7+xs9p8=; b=bax7+73uxU1/cu491BSPcmOPr0ER6gBdsr/NOfKTbAo0cWbSBwbRfFD/JtJFYEi/JWTtH6 V98PE46U/a0/kP9qodnQIideUFcESqzi+XZ8ED60osGW8ha8ANU2mgO1l6a47sp7+H3rce LqS8OXACsKS3B6vuB8xQhZ7tPwDSuF4= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-yOVt1-vKNhu9gPHjziuldw-1; Fri, 10 Nov 2023 00:33:34 -0500 X-MC-Unique: yOVt1-vKNhu9gPHjziuldw-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9ddae43f3f7so126859866b.3 for ; Thu, 09 Nov 2023 21:33:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699594413; x=1700199213; 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=KA0v3OBMTeHRtp+JBUoL+seQE2z12N8pOIFQ7+xs9p8=; b=xIvPYPxuynZQVLs9Tyh2ibiazYMmxjwqG+WZ4+lV8uucwm/qkX0erPpcGh1iS82nIg wuq1c337dNPLmf/y5ev8Ds5N4PiRznLgooD2iGhLSo0XqyL4yVuY9nhQRXvAt6jZysCe ZkbzijzuYnxJ6z9YWAfWU/fE2/Onf7Ig5Au7yaSIOKHtQnZyi08Ae7WZSAPNtaTcY1w4 VMkAtPfZLIt8Ptrs3XaiGzTcoL3BqjO8HpMmzKe0hAu9Z0RndUiVDnoJUirnAY7Ij0ZS rippfz5J7xxPMTJncf7jzcYddNgU8ox0Xw3dhF/6juJjfnpcNqFKRnm7k1dMdPmmy2Bz 5B2g== X-Gm-Message-State: AOJu0Ywiqs0GvnQFMj/UlUmu7+PoStIMlWS9qDU7ulxXO7mZMbKAyNkd jILcYTTqjAkc/aA3y0viP5PwHYqF1fFZj8ZANMzyfQuhYgrnEysYNR0cMNyvy5PCo15qpvNQIUD cjDV+fEoD69MoZN0wygiZIgITGyxeO+KFzQGKa0aOBw== X-Received: by 2002:a17:907:26c4:b0:9d2:20ee:b18b with SMTP id bp4-20020a17090726c400b009d220eeb18bmr5823226ejc.42.1699594413700; Thu, 09 Nov 2023 21:33:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBbBn5im1hOWZJw1AgpLiSs3sWtFi9jJ5Mxh5qC987b7swzUCnrRO1vlcquRH3RcU71Up0TQ== X-Received: by 2002:a17:907:26c4:b0:9d2:20ee:b18b with SMTP id bp4-20020a17090726c400b009d220eeb18bmr5823208ejc.42.1699594413357; Thu, 09 Nov 2023 21:33:33 -0800 (PST) Received: from redhat.com ([2a02:14f:1f4:2044:be5a:328c:4b98:1420]) by smtp.gmail.com with ESMTPSA id y27-20020a170906071b00b009b285351817sm3385639ejb.116.2023.11.09.21.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 21:33:32 -0800 (PST) Date: Fri, 10 Nov 2023 00:33:27 -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: <20231110003305-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> <20231109070015-mutt-send-email-mst@kernel.org> <1699580836.3647869-2-xuanzhuo@linux.alibaba.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <1699580836.3647869-2-xuanzhuo@linux.alibaba.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Nov 10, 2023 at 09:47:16AM +0800, Xuan Zhuo wrote: > On Thu, 9 Nov 2023 07:00:51 -0500, "Michael S. Tsirkin" wrote: > > 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? > > premapped is in the struct vring_virtqueue. > > We can not access it from the driver. If it's useful, move it. > > > > > > > > > > > > > > > --- > > > > > 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 > > > > > > > > > > > >