Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp155189rdb; Sun, 28 Jan 2024 19:06:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXF15lDfRkYMJ2uMuNxcGzvZr16md/W5fJnIH2JkZSTVCBS31H3IUjR60ENJHMDeSkJtGF X-Received: by 2002:a05:6a00:230b:b0:6dd:db87:6394 with SMTP id h11-20020a056a00230b00b006dddb876394mr1693208pfh.11.1706497561546; Sun, 28 Jan 2024 19:06:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706497561; cv=pass; d=google.com; s=arc-20160816; b=Kpzj4FsXRP2eP4n2w0fjVAXOHOq3/nU6S89yLFhm3koXNfMkaM4ECKidpu9YrH+k3J J31aj0TE0SWPRAK+RwLAlQkNnYNRifRH2r27MgFAd0U9RcT1woylCp6n987ULTQVBUjL iRdPiZovGPbsOcXqqU41Gu35wjjg1y2hU1sbWpoPlpj8ECXrsk7aJG7vKgCAYFY6ig8F rUjt1plRVhXJNrJM9zdx64yxuYREyjPMzRcvn/S4oZCm6QbmR7GL+DJp38wq38Gc6MHH klqQUt6+vXKRCPhhtMyED67SKKGuyxC0VvuQP5afFMC1kweYBL0ZjLWKqatyEXTkJUxX 68tw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=RxcHXDna7cKu/U9+4vXe/vVpNtUCeHUKRMCX5kQ7Mpk=; fh=WnvvgcMYqSP7eOEy4HwgphlmhVHDUMgATATCTWD6hks=; b=05qLdcxlg4EFyFPN2AKNkok1sfVz685OETxUhfRCtDoI5t4I4IYLuA7LQF3m9dQbXG eiFDy4IEs0vjE4GS+rBtnbKXUe9gSjf5CM1rrnSi6Rjf8pxZFaqB0mcsQNYiIAXjxk3W JCONIFsUhCEnF0Vwx06hzEakzn7npGMGUxrNX5wjmWPO+zkqEGEJwvjI4BH57QYbzbAq eS2e8peiWS3FjHTG39pEYfx0iubntHcsvxVcZeq+2JtjIyDEgJs8pTnW0OUogQrTpQJH p53O2yivNFmJ6+TjNb9TfpE3FeZ+OgORaqViRt2/nV1hMxuNAWS00+bbRAPQkuCEs2gA CaLw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PaxRgdLS; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-42116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42116-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f31-20020a056a000b1f00b006dddb17d2absi4955558pfu.68.2024.01.28.19.06.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 19:06:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PaxRgdLS; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-42116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42116-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 30D2B28360B for ; Mon, 29 Jan 2024 03:06:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0518A10949; Mon, 29 Jan 2024 03:05:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PaxRgdLS" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 477F5F9FE for ; Mon, 29 Jan 2024 03:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706497542; cv=none; b=Vj8486eESprm85Kpl30BSsfWKjKMq1t7/cuYPYRm/NmBQN4chAZq36iaBabzhuUHhDphjQdrhyWRcs99HK6SFZUHttHvZwFmtlM2lh3fKvviFMOdzrJ5rblutyi0M2ala+XSsV2dEw0cuM+3TpKtuJbHsAU0GxoTpqjoKfnypgY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706497542; c=relaxed/simple; bh=YtumUDa9xISoGxbg6DJBDnOO+Rukg7wlbjEEjxfD3UY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=t3DSeZ5mtPZ7BZpF8kYvDTuOiUJAHrSGMMZSHQb74iM5MyWmLbJ/hrMYgX0s+bYkhDInTDmeV8flbYk3aMjx36DUTNdjUw9sY3u3gYDk/zYCmzsjrH7oRxP5SMBbOBqliOaN9mFZxPt/Y56LEV5r9XBeFuJ9phKrIiZ12UdgO8I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PaxRgdLS; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706497539; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RxcHXDna7cKu/U9+4vXe/vVpNtUCeHUKRMCX5kQ7Mpk=; b=PaxRgdLSeZeHpPt3MDz4uwN8/MfvNAklAcNE9SLZ6LVZ6YB+IZZFQ+4qQSvszz4h+WH3sL BFOhwCJdgyguoJJCJpxN93Qn4LSvnLePukurR7BRGBQ8c0gbVoShEipa6vZhIDQ/2BOLqs Rc0X04PSsdlNpcRf4nc+WcvDPLFXuIk= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-aaTj1ZhBPF2sArW8nEvE4Q-1; Sun, 28 Jan 2024 22:05:37 -0500 X-MC-Unique: aaTj1ZhBPF2sArW8nEvE4Q-1 Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-3bd3b54e5c6so3382371b6e.1 for ; Sun, 28 Jan 2024 19:05:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706497536; x=1707102336; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RxcHXDna7cKu/U9+4vXe/vVpNtUCeHUKRMCX5kQ7Mpk=; b=VTEyJSmklbCfmmIG4XsguriwzeblUYyfCfvMZMfg8xopTVKZO6CyUq8cq3aRa8cEeH HPodczzaWKG/pXrtSJEFBQi8kipcoSTrro1Ck7rn57d+b0IyDnikGm+v65CxbT4cqBaH AXVNTT4fqhhsCsautx5ERpK32bCFxylQndOqK266RryYghBmHtMUViUyBMA9G4o1cOVF fwOFZk76EC8JjAKd9MVsbPuYf3B3BOejPY/Dswbf5yGDgLpa3mkuICVBPz3C6oTIbaWa 0uO84zJN81IBHf61Rc5SYrPjN51v9FBhANMMr9xiDSn2vAhhFi7h4q+L06b4pleHK+jf 0vEg== X-Gm-Message-State: AOJu0YxdB76NzqELEHV5vjGAZ3RVJCPUXNkeeyDjdiwpFndEmH78ecIS g0UBv5HYoN3wCp/6Zn1Cwvy/TwIJU1LcZypcxGSYBbQacB0UrCEFeh8eGwNizWHadulS4k1xuk4 ypoheGTdN6+heo4uxp8tOWLyhbWyFqxg+xUH9IEeNdkpfmmE6EirwlqJUa/jLeLlw8LlJN0zXU7 x4JhJ8m0S9HyT/dWmlfnN3DqTsY4kMG6CyoYP0 X-Received: by 2002:a05:6808:2096:b0:3be:68bf:f811 with SMTP id s22-20020a056808209600b003be68bff811mr445577oiw.20.1706497536651; Sun, 28 Jan 2024 19:05:36 -0800 (PST) X-Received: by 2002:a05:6808:2096:b0:3be:68bf:f811 with SMTP id s22-20020a056808209600b003be68bff811mr445564oiw.20.1706497536445; Sun, 28 Jan 2024 19:05:36 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <1706089075-16084-1-git-send-email-wangyunjian@huawei.com> <156030296fea4f7abef6ab7155ba2e32@huawei.com> In-Reply-To: <156030296fea4f7abef6ab7155ba2e32@huawei.com> From: Jason Wang Date: Mon, 29 Jan 2024 11:05:25 +0800 Message-ID: Subject: Re: [PATCH net-next 2/2] tun: AF_XDP Rx zero-copy support To: wangyunjian Cc: "mst@redhat.com" , "willemdebruijn.kernel@gmail.com" , "kuba@kernel.org" , "davem@davemloft.net" , "magnus.karlsson@intel.com" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "virtualization@lists.linux.dev" , xudingke Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jan 27, 2024 at 5:34=E2=80=AFPM wangyunjian wrote: > > > > -----Original Message----- > > > From: Jason Wang [mailto:jasowang@redhat.com] > > > Sent: Thursday, January 25, 2024 12:49 PM > > > To: wangyunjian > > > Cc: mst@redhat.com; willemdebruijn.kernel@gmail.com; kuba@kernel.org; > > > davem@davemloft.net; magnus.karlsson@intel.com; > > > netdev@vger.kernel.org; linux-kernel@vger.kernel.org; > > > kvm@vger.kernel.org; virtualization@lists.linux.dev; xudingke > > > > > > Subject: Re: [PATCH net-next 2/2] tun: AF_XDP Rx zero-copy support > > > > > > On Wed, Jan 24, 2024 at 5:38=E2=80=AFPM Yunjian Wang > > > > > wrote: > > > > > > > > Now the zero-copy feature of AF_XDP socket is supported by some > > > > drivers, which can reduce CPU utilization on the xdp program. > > > > This patch set allows tun to support AF_XDP Rx zero-copy feature. > > > > > > > > This patch tries to address this by: > > > > - Use peek_len to consume a xsk->desc and get xsk->desc length. > > > > - When the tun support AF_XDP Rx zero-copy, the vq's array maybe em= pty. > > > > So add a check for empty vq's array in vhost_net_buf_produce(). > > > > - add XDP_SETUP_XSK_POOL and ndo_xsk_wakeup callback support > > > > - add tun_put_user_desc function to copy the Rx data to VM > > > > > > Code explains themselves, let's explain why you need to do this. > > > > > > 1) why you want to use peek_len > > > 2) for "vq's array", what does it mean? > > > 3) from the view of TUN/TAP tun_put_user_desc() is the TX path, so I > > > guess you meant TX zerocopy instead of RX (as I don't see codes for > > > RX?) > > > > OK, I agree and use TX zerocopy instead of RX zerocopy. I meant RX zero= copy > > from the view of vhost-net. > > > > > > > > A big question is how could you handle GSO packets from userspace/gue= sts? > > > > Now by disabling VM's TSO and csum feature. XDP does not support GSO > > packets. > > However, this feature can be added once XDP supports it in the future. > > > > > > > > > > > > > Signed-off-by: Yunjian Wang > > > > --- > > > > drivers/net/tun.c | 165 > > > +++++++++++++++++++++++++++++++++++++++++++- > > > > drivers/vhost/net.c | 18 +++-- > > > > 2 files changed, 176 insertions(+), 7 deletions(-) > > [...] > > > > > > > > > static int peek_head_len(struct vhost_net_virtqueue *rvq, struct > > > > sock > > > > *sk) { > > > > + struct socket *sock =3D sk->sk_socket; > > > > struct sk_buff *head; > > > > int len =3D 0; > > > > unsigned long flags; > > > > > > > > - if (rvq->rx_ring) > > > > - return vhost_net_buf_peek(rvq); > > > > + if (rvq->rx_ring) { > > > > + len =3D vhost_net_buf_peek(rvq); > > > > + if (likely(len)) > > > > + return len; > > > > + } > > > > + > > > > + if (sock->ops->peek_len) > > > > + return sock->ops->peek_len(sock); > > > > > > What prevents you from reusing the ptr_ring here? Then you don't need > > > the above tricks. > > > > Thank you for your suggestion. I will consider how to reuse the ptr_rin= g. > > If ptr_ring is used to transfer xdp_descs, there is a problem: After some > xdp_descs are obtained through xsk_tx_peek_desc(), the descs may fail > to be added to ptr_ring. However, no API is available to implement the > rollback function. I don't understand, this issue seems to exist in the physical NIC as well? We get more descriptors than the free slots in the NIC ring. How did other NIC solve this issue? Thanks > > Thanks > > > > > > > > > Thanks > > > > > > > > > > > > > > spin_lock_irqsave(&sk->sk_receive_queue.lock, flags); > > > > head =3D skb_peek(&sk->sk_receive_queue); > > > > -- > > > > 2.33.0 > > > > >