From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 63BC835DA53; Fri, 6 Mar 2026 17:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772819626; cv=none; b=IqYcWDnZe+9+LRxnLY/qWxDPjZkKk0fBfd1Af0IrzkSwBNjAtKCo977656GGzYTvMp/2KfoQAvNpUFTzVwFjx/Vgwtnvj3jE3DH/d96AgsQN0AQiY6Gx9ICqWSkgbuONa4Skh9J9Q+xJGHO/3crB4ZlG/JuCIFAbFUluUzw0V+I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772819626; c=relaxed/simple; bh=xaRaXrVUft9NCgWfvw5rWwHWlI4HGj7GGRn8sy+FOuY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=G8kHVZyyhSqCj+n7xBQZanspHusdlQGxUjlIweDZulnbCwG2KsCPYLH6YmwYoGBJ6OJwuXygZ7y+qsdkMamGnaRhJRWHKmKw1WUZ3NYacTVsIDTNXbbxUDNq/68EY5dgizFWyX42Vsw2KpFi/luhUM1sGE/2IPdI2Qxidhq6n54= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=aO99BrO1; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="aO99BrO1" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id DD8C64E42594; Fri, 6 Mar 2026 17:53:41 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 941875FF92; Fri, 6 Mar 2026 17:53:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 51EAC1036984D; Fri, 6 Mar 2026 18:53:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1772819620; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:content-language:in-reply-to:references; bh=KKNCuFHaFr6BJTaxfs+dcw4Wa/Lo3Pwr4xaWxWGksWs=; b=aO99BrO18C30kMmI4oFITYpPXe3YSJ4jRafzY4QPAeWFGOqtDvJj6FBdW3gnjcScakd4bG Pv1O2yFlz8AHrbfW8jSLVXx6z/I1LKImpmjGXPOWmRyhoHymc4NwmA6lieFibRO8KdZwcf mOT8+T7AeRGea8/Lk+z3dSZxnjvyUftDZ8wahT4pZqlG9JGUCFAUnS/WpIXFEmjslbn7xV qChx4etHzU87tH+K8fGyXhXMWH3gvGvfLXrNxIyl3y8emZdlccQ+Ez99RyxBWqwcB/5wq/ h09UeBXfJo50VmiNmwUIHGTpRLXiBVkeXYO2Vzq64OyNmgendFWkGGcEKL7MSw== Message-ID: Date: Fri, 6 Mar 2026 18:53:34 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next 8/8] net: macb: add Tx zero-copy AF_XDP support To: =?UTF-8?Q?Th=C3=A9o_Lebrun?= , Nicolas Ferre , Claudiu Beznea , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Richard Cochran Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Vladimir Kondratiev , Gregory CLEMENT , =?UTF-8?Q?Beno=C3=AEt_Monin?= , Tawfik Bayouk , Thomas Petazzoni References: <20260304-macb-xsk-v1-0-ba2ebe2bdaa3@bootlin.com> <20260304-macb-xsk-v1-8-ba2ebe2bdaa3@bootlin.com> <74089907-d7d3-4242-92a5-909812779932@bootlin.com> From: Maxime Chevallier Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 Hi, On 06/03/2026 18:18, Théo Lebrun wrote: > Hello! > > On Fri Mar 6, 2026 at 1:48 PM CET, Maxime Chevallier wrote: >> On 04/03/2026 19:24, Théo Lebrun wrote: >>> Add a new buffer type (to `enum macb_tx_buff_type`). Near the end of >>> macb_tx_complete(), we go and read the XSK buffers using >>> xsk_tx_peek_release_desc_batch() and append those buffers to our Tx >>> ring. >>> >>> Additionally, in macb_tx_complete(), we signal to the XSK subsystem >>> number of bytes completed and conditionally mark the need_wakeup >>> flag. >>> >>> Lastly, we update XSK wakeup by writing the TCOMP bit in the per-queue >>> IMR register, to ensure NAPI scheduling will take place. >>> >>> Signed-off-by: Théo Lebrun >>> --- >> >> [...] >> >>> +static void macb_xdp_xmit_zc(struct macb *bp, unsigned int queue_index, int budget) >>> +{ >>> + struct macb_queue *queue = &bp->queues[queue_index]; >>> + struct xsk_buff_pool *xsk = queue->xsk_pool; >>> + dma_addr_t mapping; >>> + u32 slot_available; >>> + size_t bytes = 0; >>> + u32 batch; >>> + >>> + guard(spinlock_irqsave)(&queue->tx_ptr_lock); >>> + >>> + /* This is a hard error, log it. */ >>> + slot_available = CIRC_SPACE(queue->tx_head, queue->tx_tail, bp->tx_ring_size); >>> + if (slot_available < 1) { >>> + netif_stop_subqueue(bp->dev, queue_index); >>> + netdev_dbg(bp->dev, "tx_head = %u, tx_tail = %u\n", >>> + queue->tx_head, queue->tx_tail); >>> + return; >>> + } >>> + >>> + batch = min_t(u32, slot_available, budget); >>> + batch = xsk_tx_peek_release_desc_batch(xsk, batch); >>> + if (!batch) >>> + return; >>> + >>> + for (u32 i = 0; i < batch; i++) { >>> + struct xdp_desc *desc = &xsk->tx_descs[i]; >>> + >>> + mapping = xsk_buff_raw_get_dma(xsk, desc->addr); >>> + xsk_buff_raw_dma_sync_for_device(xsk, mapping, desc->len); >>> + >>> + macb_xdp_submit_buff(bp, queue_index, (struct macb_tx_buff){ >>> + .ptr = NULL, >>> + .mapping = mapping, >>> + .size = desc->len, >>> + .mapped_as_page = false, >>> + .type = MACB_TYPE_XSK, >>> + }); >>> + >>> + bytes += desc->len; >>> + } >>> + >>> + /* Make newly initialized descriptor visible to hardware */ >>> + wmb(); >>> + spin_lock(&bp->lock); >>> + macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); >>> + spin_unlock(&bp->lock); >> >> this lock is also taken in interrupt context, this should probably use a >> irqsave/restore variant. Now, there are a few other parts of this driver >> that use a plain spin_lock() call and except for the paths that actually >> run in interrupt context, they don't seem correct to me :( > > I almost sent a reply agreeing with you, but actually here is the > exhaustive `spin_lock(&bp->lock)` list: > > # Function Context > ------------------------------------------ > 1 gem_wol_interrupt() irq > 2 macb_interrupt() irq > 3 macb_wol_interrupt() irq > 4 macb_tx_error_task() workqueue/user > 5 macb_tx_restart() napi/softirq > 6 macb_xdp_xmit_zc() napi/softirq > 7 macb_start_xmit() user > 8 macb_xdp_submit_frame() user > > And all contexts are safe because it always is this sequence in non-IRQ > contexts (#4-8): > > spin_lock_irqsave(&queue->tx_ptr_lock, flags); > spin_lock(&bp->lock); > spin_unlock(&bp->lock); > spin_unlock_irqrestore(&queue->tx_ptr_lock, flags); Is it because of the guard statement ? guard(spinlock_irqsave)(&queue->tx_ptr_lock); It really doesn't make it obvious that this is how it plays out :( > > So bp->tx_ptr_lock always wraps bp->lock and does the local CPU IRQ > disabling. > > (I also checked we don't risk ABBA deadlock, and we don't: all code > acquires bp->tx_ptr_lock THEN bp->lock.) > > However, there is still a bug in the code you quoted: setting > BIT(TSTART) is done twice by macb_xdp_xmit_zc(): > - once in the helper function macb_xdp_submit_buff() and, > - once in its own body (code you quoted) > This is fixed for V2! great :) Maxime