Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2422EC10F0E for ; Thu, 18 Apr 2019 17:55:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E331C217D7 for ; Thu, 18 Apr 2019 17:55:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CODxKYTU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389577AbfDRRzE (ORCPT ); Thu, 18 Apr 2019 13:55:04 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44154 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388301AbfDRRzE (ORCPT ); Thu, 18 Apr 2019 13:55:04 -0400 Received: by mail-pg1-f196.google.com with SMTP id i2so1522120pgj.11 for ; Thu, 18 Apr 2019 10:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IVXHPdTHQl1BowApaVGIFFnEarPJ+21IIUepvPB9KJM=; b=CODxKYTUMEeUbgUKLXVn59gHJ/5M+YrcSvP7uUMiUEprvMyoNoPEpNSvUBnnLMyXoe KVeG0kYWpRUgiGjY4PINwTMVsbYv8H1XA7NZoSY0IJOYCdnQrFPRCRQe88TZH0n78YHw If2DYknUTj3DLwpE3WeOjBRNaRfqNZFrFxOe6v/OeV6Q07wdmYRZQcqIwIZ85hYBEJhE DsXodHO67GWH4/iE02AFfZuDGNwfOI+gTVmBEKSubLfo1TkoTv3OvrLhvxpsor5jR413 nQ9yGk1YpAakd5BErQqAa+bi9sMFS0nmztNs05xW45GLMTc9p/LoCVWokz/Frtp3miPx Im/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IVXHPdTHQl1BowApaVGIFFnEarPJ+21IIUepvPB9KJM=; b=djIRqRCt/oTRY9f0b6XOyiWa78QDQGeV2qX53hlwPhxikeErN+auBxr4Sy6UxQJbe+ 4RNdXNjXH8BdndyC3nR2mBU2NL0vfKgs4YU73HK6KlPDeBZ1/oDnrIVo+VQvWq5pjR2I bSFJAF7hYlnU0iYPmiftPv76IgdyhhkHV38mX0OczfFjBsAZzoEfKZtmVTPxmD3Au8vu trpXjeDH9on+2OUTOZUeBz/7mh/l5Hm5Bq8JhMQo5Zv48Lp/1zgvlwlUylcrzLAw/6Oo CqNi6Md6wNlizr236bmzq0jQvD+yfdi1pW78P6dOYePeYKUuuqAoV4aU4dkSe60wlRsA VXzg== X-Gm-Message-State: APjAAAU3vCs5GPLURUUu+FA1tU9hZTormyXW0uwoh77e078LFDDMb5x/ idjVdJGc4rMPUfng5Rp++gU= X-Google-Smtp-Source: APXvYqwBNnhijYSYHdTx8JDxj/VMnf3BaxR/fK3/O4g7yK1nucHUzhW2vSXLK0iyAlqzHNTsP506XQ== X-Received: by 2002:a65:47c6:: with SMTP id f6mr89573299pgs.173.1555610103580; Thu, 18 Apr 2019 10:55:03 -0700 (PDT) Received: from [172.20.52.230] ([2620:10d:c090:200::3:2773]) by smtp.gmail.com with ESMTPSA id b7sm4845232pfj.67.2019.04.18.10.55.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 10:55:02 -0700 (PDT) From: "Jonathan Lemon" To: "=?utf-8?b?QmrDtnJuIFTDtnBlbA==?=" Cc: Netdev , "Karlsson, Magnus" , kernel-team@fb.com, "Jesper Dangaard Brouer" , maciej.fijalkowski@intel.com Subject: Re: [PATCH RFC] xdp: Support zero-copy XDP_TX from AF_XDP sockets. Date: Thu, 18 Apr 2019 10:55:02 -0700 X-Mailer: MailMate (1.12.4r5594) Message-ID: <68FE1809-84AE-4A38-8D01-EED0252460EC@gmail.com> In-Reply-To: References: <20190417195853.2819390-1-jonathan.lemon@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 18 Apr 2019, at 3:10, Björn Töpel wrote: > On Wed, 17 Apr 2019 at 21:58, Jonathan Lemon > wrote: >> >> When the XDP program attached to a zero-copy AF_XDP socket returns >> XDP_TX, >> queue the umem frame on the XDP TX ring, and arrange for it to be >> released >> via the ZCA free routine, which should place it back onto the reuseq. >> > > There are a bunch of compiler errors, but I'll leave them out from the > comments! Yes, sigh - generated from the wrong tree. I did compile it, honest! >> +static int i40e_xmit_rcvd_zc(struct i40e_ring *rx_ring, struct >> xdp_buff *xdp) >> +{ >> + struct i40e_ring *xdp_ring; >> + struct i40e_tx_desc *tx_desc; >> + struct i40e_tx_buffer *tx_bi; >> + struct xdp_frame *xdpf; >> + dma_addr_t dma; >> + >> + xdp_ring = rx_ring->vsi->xdp_rings[rx_ring->queue_index]; >> + >> + if (!unlikely(I40E_DESC_UNUSED(xdp_ring))) { >> + xdp_ring->tx_stats.tx_busy++; >> + return I40E_XDP_CONSUMED; >> + } >> + xpdf = convert_to_xdp_frame_keep_zc(xdp); >> + if (unlikely(!xpdf) >> + return I40E_XDP_CONSUMED; >> + xpdf->handle = xdp->handle; >> + >> + dma = xdp_umem_get_dma(rx_ring->xsk_umem, xdp->handle); >> + tx_bi = &xdp_ring->tx_bi[xdp_ring->next_to_use]; >> + tx_bi->bytecount = xpdf->len; >> + tx_bi->gso_segs = 1; >> + tx_bi->xdpf = xdpf; >> + tx_bi->tx_flags = I40E_TX_FLAGS_ZC_FRAME; >> + >> + tx_desc = I40E_TX_DESC(xdp_ring, xdp_ring->next_to_use); >> + tx_desc->buffer_addr = cpu_to_le64(dma); >> + tx_desc->cmd_type_offset_bsz = >> build_ctob(I40E_TX_DESC_CMD_ICRC | >> + >> I40E_TX_DESC_CMD_EOP, >> + 0, xpdf->len, 0); >> + smp_wmb(); >> + >> + xdp_ring->next_to_use++; >> + if (xdp_ring->next_to_use == xdp_ring->count) >> + xdp_ring->next_to_use = 0; >> + >> + tx_bi->next_to_watch = tx_desc; >> + >> + return I40E_XDP_TX; >> +} > > What you're basically doing here is a AF_XDP Tx, but triggered from > the Rx path, and instead of completion (after the packet is sent) to > the completion ring, it's recycled to the Rx HW ring (via zca_free). I > like the idea but we need more plumbing first. Let me expand; > Unfortunately, the current recycle mechanism requires that at the > point of recycling, there has to be space in Rx ring. In the XDP_TX > case, there's no completion ring, and we cannot guarantee that there's > space on Rx ring (since Rx and Tx are asynchronous). Yes - this is why it's an RFC. Your current design keeps the RX reuse context in the driver itself, instead of using the reuse queue provided by umem. I believe the driver only uses it when the ring is torn down, so this needs to be addressed. Since we're transmitting something that was just received, on TX completion the buffer should logically be placed back into the fill queue, but with the current SPSC mechanism, this isn't possible. Hence the ReuseQ. I think this should be transparently be made part of the FQ mechanism, so the RQ is always checked before using the FQ. I believe xsk_umem_peek_addr_rq() was added for this purpose, but should really be the main API. > IOW, Rx recycling > can currently *only* be done in an Rx context. I was assuming that the Tx was part of the same VSI, so the Rx ring would be accessible from the napi_poll() routine. > What I would like to do, is moving i40e-xsk to Jesper's page-pool, > instead of the existing recycle mechanism. Then we could return the > descriptor to the pool, if the Rx ring doesn't have space for the > completed/sent buffer. Hm, not sure how this would help? The xdp_return() goes to the ZCA free routine for zero-copy buffers, bypassing the page pool, doesn't it? > TL;DR version: Passing zc-frames in XDP_TX cannot be done properly > until the Rx recycle mechanism is more robust. :-( Agree. So i40e_zca_free() would look more like: if (space in rx_bi) /* locally cache buffer */ i40e_reuse_rx_buffer_zc(rx, buf); else xsk_umem_fq_reuse(rx->umem, buf) and the the two alloc_rx_buffers_*_zc() would need to be adjusted? -- Jonathan