Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1671522pxb; Fri, 20 Aug 2021 10:58:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiLdNrxfjozC1i6jGQorQrwglhB1qFwXcrn75sEkZPUel7N9FpjflCo+8oxgaRK1RrIWgO X-Received: by 2002:a6b:2bd6:: with SMTP id r205mr17179395ior.122.1629482297303; Fri, 20 Aug 2021 10:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629482297; cv=none; d=google.com; s=arc-20160816; b=bpaxwMr05sI1fnD7+6hcgfglHuTV9JIk0T8wvpP77S33/pT9XeSNQIFqTIywi9sfWB oiriLb0G1fxle7nHFHRmCE7Q4F4afm0cxe3NQXgzoKuno94d0n3BDG0FJoU8wbKAgcUQ JseBxRTh7sitdpGpUIj/VxnY6YKPWOOv2bemAS8KKRyCSNO95RwpcQK4U5lhhxa5LuLi gSqenu/a5rnLVNUq0xo9uw6/4N3iOoILdK5Avisf4aDkPmJARg2+GWBsISnbNzCAOhkV GuJj/DjPCT9dO4aiCuLpNfr9BVLSInGs6ytkmVhok49FMAjrZNq/e05SZjBfm28EbjR4 HcNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature:dkim-filter; bh=NyBdUbvIh6ra+fRiPtFryDwRJJTsn1FOlzJwY1TSk5g=; b=v9Mn1/n4EZNIOc8gCpGUZ2MK+dBkqUBAJINZWOmlOENOdiuodb6PxmRjA+yZ1RO2R1 tG4hNk1tpj3sgdBnhlWTrC8wWoO5VlVZP47DQ3GnAFHWejUJQt5ibjm69mAA+aAUeJ8p 2JVH/SILsUIsXu8cfkOOaQyp+QGhn+KL+qY4mnnpa+/7ES7lNg2rgGzpJ+6GtkrBCxVw YZGx1buoTCopQkHxkE/Qt8IqOaqoGEGe0p3iJ6ahj2RNeoY0b+zhOccPpj0eG8wxgEPT wdn6LJSNbZfWh1jn1LiiSQJ597ywV43TSlcfZMB2jpoDkhTERXXAyl9S4NVHGjJtw+hg z6xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fBI0+e4j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g2si6849402iob.28.2021.08.20.10.58.04; Fri, 20 Aug 2021 10:58:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fBI0+e4j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235218AbhHTR5s (ORCPT + 99 others); Fri, 20 Aug 2021 13:57:48 -0400 Received: from linux.microsoft.com ([13.77.154.182]:40722 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbhHTR5s (ORCPT ); Fri, 20 Aug 2021 13:57:48 -0400 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by linux.microsoft.com (Postfix) with ESMTPSA id EB50820C33D3; Fri, 20 Aug 2021 10:57:09 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EB50820C33D3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1629482230; bh=NyBdUbvIh6ra+fRiPtFryDwRJJTsn1FOlzJwY1TSk5g=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=fBI0+e4jkvdO+mv8dnEqvWMOOJ+r75DdAyR+ldrH8i2NNpycl2d65d7iRssAkSXP+ 55aGxhy6eX57TAv8yT72hs/Er5wdcHxqhO7EhAkG/USZxH5rjTNF11kdaFWCQsqJRY t8vC+IH//b76uKOd/UCLXqNEm+NqkddIA8YmkeHs= Received: by mail-pg1-f180.google.com with SMTP id c17so9928611pgc.0; Fri, 20 Aug 2021 10:57:09 -0700 (PDT) X-Gm-Message-State: AOAM533cJ2vNYCGMiS/+pcQRZySZWF3EHmwiJj2uidlTokH/bK5/0fof MIYEVNTrvoAuMxxDX2MLsl1SL2lQMBfl7G8moHc= X-Received: by 2002:a63:1422:: with SMTP id u34mr1488406pgl.326.1629482229456; Fri, 20 Aug 2021 10:57:09 -0700 (PDT) MIME-Version: 1.0 References: <20210614022504.24458-1-mcroce@linux.microsoft.com> <871r71azjw.wl-maz@kernel.org> <202417ef-f8ae-895d-4d07-1f9f3d89b4a4@gmail.com> <87o8a49idp.wl-maz@kernel.org> <20210812121835.405d2e37@linux.microsoft.com> <874kbuapod.wl-maz@kernel.org> <87wnohqty1.wl-maz@kernel.org> <87fsv4qdzm.wl-maz@kernel.org> <87mtpcyrdv.wl-maz@kernel.org> <87h7fkyqpv.wl-maz@kernel.org> <87fsv4ypfn.wl-maz@kernel.org> In-Reply-To: <87fsv4ypfn.wl-maz@kernel.org> From: Matteo Croce Date: Fri, 20 Aug 2021 19:56:33 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH net-next] stmmac: align RX buffers To: Marc Zyngier Cc: Eric Dumazet , Thierry Reding , netdev@vger.kernel.org, Linux Kernel Mailing List , linux-riscv , Giuseppe Cavallaro , Alexandre Torgue , "David S. Miller" , Jakub Kicinski , Palmer Dabbelt , Paul Walmsley , Drew Fustini , Emil Renner Berthing , Jon Hunter , Will Deacon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 20, 2021 at 7:51 PM Marc Zyngier wrote: > > On Fri, 20 Aug 2021 18:35:45 +0100, > Matteo Croce wrote: > > > > On Fri, Aug 20, 2021 at 7:24 PM Marc Zyngier wrote: > > > > > > On Fri, 20 Aug 2021 18:14:30 +0100, > > > Matteo Croce wrote: > > > > > > > > On Fri, Aug 20, 2021 at 7:09 PM Marc Zyngier wrote: > > > > > > > > > > On Fri, 20 Aug 2021 17:38:14 +0100, > > > > > Matteo Croce wrote: > > > > > > > > > > > > On Fri, Aug 20, 2021 at 6:26 PM Marc Zyngier wrote: > > > > > > > > > > > > > > On Fri, 20 Aug 2021 11:37:03 +0100, > > > > > > > Matteo Croce wrote: > > > > > > > > > > > > > > > > On Thu, Aug 19, 2021 at 6:29 PM Marc Zyngier wrote: > > > > > > > > > > > > > > [...] > > > > > > > > > > > > > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h > > > > > > > > > index fcdb1d20389b..244aa6579ef4 100644 > > > > > > > > > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h > > > > > > > > > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h > > > > > > > > > @@ -341,7 +341,7 @@ static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv) > > > > > > > > > if (stmmac_xdp_is_enabled(priv)) > > > > > > > > > return XDP_PACKET_HEADROOM + NET_IP_ALIGN; > > > > > > > > > > > > > > > > > > - return NET_SKB_PAD + NET_IP_ALIGN; > > > > > > > > > + return 8 + NET_IP_ALIGN; > > > > > > > > > } > > > > > > > > > > > > > > > > > > void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue); > > > > > > > > > > > > > > > > > > I don't see the system corrupting packets anymore. Is that exactly > > > > > > > > > what you had in mind? This really seems to point to a basic buffer > > > > > > > > > overflow. > > > > > > > > > > > > > > [...] > > > > > > > > > > > > > > > Sorry, I meant something like: > > > > > > > > > > > > > > > > - return NET_SKB_PAD + NET_IP_ALIGN; > > > > > > > > + return 8; > > > > > > > > > > > > > > > > I had some hardware which DMA fails if the receive buffer was not word > > > > > > > > aligned, but this seems not the case, as 8 + NET_IP_ALIGN = 10, and > > > > > > > > it's not aligned too. > > > > > > > > > > > > > > No error in that case either, as expected. Given that NET_SKB_PAD is > > > > > > > likely to expand to 64, it is likely a DMA buffer overflow which > > > > > > > probably only triggers for large-ish packets. > > > > > > > > > > > > > > Now, we're almost at -rc7, and we don't have a solution in sight. > > > > > > > > > > > > > > Can we please revert this until we have an understanding of what is > > > > > > > happening? I'll hopefully have more cycles to work on the issue once > > > > > > > 5.14 is out, and hopefully the maintainers of this driver can chime in > > > > > > > (they have been pretty quiet so far). > > > > > > > > > > > > > > Thanks, > > > > > > > > > > > > > > M. > > > > > > > > > > > > > > -- > > > > > > > Without deviation from the norm, progress is not possible. > > > > > > > > > > > > Last try, what about adding only NET_IP_ALIGN and leaving NET_SKB_PAD? > > > > > > > > > > > > - return NET_SKB_PAD + NET_IP_ALIGN; > > > > > > + return NET_IP_ALIGN; > > > > > > > > > > > > I think that alloc_skb adds another NET_SKB_PAD anyway. > > > > > > > > > > I don't see any packet corruption with this. However, this doesn't > > > > > prove that this is correct either. What was the rational for adding > > > > > NET_SKB_PAD the first place? > > > > > > > > > > > > > I think it's wrong. The original offset was 0, and to align it to the > > > > boundary we need to add just NET_IP_ALIGN, which is two. > > > > NET_SKB_PAD is a much bigger value, (I think 64), which is used to > > > > reserve space to prepend an header, e.g. with tunnels. > > > > > > How about the other adjustments that Eric mentioned regarding the size > > > of the buffer? Aren't they required? > > > > > > > I guess that if stmmac_rx_buf1_len() needed such adjustment, it would > > be already broken when XDP is in use. > > When you use XDP, stmmac_rx_offset() adds a pretty big headroom of 256 > > byte, which would easily trigger an overflow if not accounted. > > Did you try attaching a simple XDP program on a stock 5.13 kernel? > > Yes, as mentioned in [1], to which you replied... > > M. > > [1] https://lore.kernel.org/r/87wnohqty1.wl-maz@kernel.org > Great. So I doubt that the adjustment is needed. Does it work with all the frame size? -- per aspera ad upstream