Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1348855pxb; Fri, 20 Aug 2021 03:40:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHrSs//V5ckm7EcPfWl3bsFCExuDjmBGQkDl5BZPPeVz7+lferEI6ONDBaoXisgSXfVana X-Received: by 2002:a17:906:2bcf:: with SMTP id n15mr21249678ejg.414.1629456044296; Fri, 20 Aug 2021 03:40:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629456044; cv=none; d=google.com; s=arc-20160816; b=Lc+Zv8ks4wkqvtLfF8bPmg5Ch4oYxjnEh2JkqlB4Onj/I8xtCHS0zwQSzrpde+bO64 YsFtfHA8aFsiLbAWlF78uuoMtUhROJFY2Bxavt5X7Al/aOUFfvSAcO3DD8GLnT2P4gCL bPZSCof3PIgdHnpABL1XGpkdI6k3HZxWkdIp0jEVxaKdW6uZhHS4SsqYfokRzn7Q4b+8 5JaFXvI2e2b5AL8CtxoK0I3IWwUXfLgLdCVA33hdPJZjdvHV0osXPlvT0ypHOndqj1qP gtxPzaFtNdIs++LlTbvUv30F8DKtJJG78wdn654mx5FVoaYCG8pYGvQ2WiAqf0LJaYpK OjwQ== 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=iZCuOLADbbT0RFS8G7uJNKKtYP+HH+o4bNtsW00FGJ0=; b=LkD6cAo87/wV/2vj/gmIoFoUM6gFkgIdsSHNyS45ouR7/HA3E6L9g0Yx2VvRLpCyMp fk12Mi6KXNprtYizKyfpIdyP9zdvDeddID98SMeIGFG0mq5+LXY6lIPkfjWkkEPZ4w2b sDX5xhjeV9sL6t+HD/aUD2Z4ZtkBMcRj1dfarvW1zq6QFPs5ah0dNB9k4hg8Fw8DoHSK 19B08/xGzgVMLQV2Vw3uSYaXzo1/lWQw4ncglwbUMiHqSrMKwYbHPUlH+uWqk+kioe0P oR/RZEyhBXimaTtR1Xh15QG38l6jHz/yWWZmsug5+RApgHrWusJFglf6ywpF7KnFZ5oU RgGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=mSOgJE8s; 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 g9si6793708ejc.431.2021.08.20.03.40.07; Fri, 20 Aug 2021 03:40:44 -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=mSOgJE8s; 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 S239093AbhHTKiS (ORCPT + 99 others); Fri, 20 Aug 2021 06:38:18 -0400 Received: from linux.microsoft.com ([13.77.154.182]:49904 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237223AbhHTKiR (ORCPT ); Fri, 20 Aug 2021 06:38:17 -0400 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by linux.microsoft.com (Postfix) with ESMTPSA id B03AC20C33D3; Fri, 20 Aug 2021 03:37:39 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B03AC20C33D3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1629455859; bh=iZCuOLADbbT0RFS8G7uJNKKtYP+HH+o4bNtsW00FGJ0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mSOgJE8smxwaE9vG5d4E8Fekp43ctCKD8sFTOFnKNfzZyaRConcmUjNjAdnRC0HVk N7r64P+EcCSC/wfMMLQ0uaAdl1Nm/DhrAGd2VjpemsBPwzrh+GpNVvVFPXZbJ/T5XP N/DTAfvgiP1lBoiFj/7DemMsJDh0eh+Usx/Q7ff8= Received: by mail-pj1-f51.google.com with SMTP id u11-20020a17090adb4b00b00181668a56d6so683719pjx.5; Fri, 20 Aug 2021 03:37:39 -0700 (PDT) X-Gm-Message-State: AOAM531stapqmUIVYAdUGRy+NWW6Yx+dMGe9BRNjnn36JwCl/HkO0GHv kot4X9MHay0Ri5MvnVkHfzSnfksJlu5XSGZV7oM= X-Received: by 2002:a17:903:4095:b029:12d:315e:5f0d with SMTP id z21-20020a1709034095b029012d315e5f0dmr15804610plc.19.1629455859101; Fri, 20 Aug 2021 03:37:39 -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> In-Reply-To: <87wnohqty1.wl-maz@kernel.org> From: Matteo Croce Date: Fri, 20 Aug 2021 12:37:03 +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 Thu, Aug 19, 2021 at 6:29 PM Marc Zyngier wrote: > > On Thu, 12 Aug 2021 12:18:48 +0100, > Matteo Croce wrote: > > > > [1 ] > > On Thu, Aug 12, 2021 at 1:05 PM Marc Zyngier wrote: > > > > > > On Thu, 12 Aug 2021 11:18:35 +0100, > > > Matteo Croce wrote: > > > > > > > > On Thu, 12 Aug 2021 10:48:03 +0200 > > > > Eric Dumazet wrote: > > > > > > > > > > > > > > > > > > > On 8/11/21 4:16 PM, Marc Zyngier wrote: > > > > > > On Wed, 11 Aug 2021 13:53:59 +0100, > > > > > > Eric Dumazet wrote: > > > > > > > > > > > >> Are you sure you do not need to adjust stmmac_set_bfsize(), > > > > > >> stmmac_rx_buf1_len() and stmmac_rx_buf2_len() ? > > > > > >> > > > > > >> Presumably DEFAULT_BUFSIZE also want to be increased by NET_SKB_PAD > > > > > >> > > > > > >> Patch for stmmac_rx_buf1_len() : > > > > > >> > > > > > >> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > > > > >> b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index > > > > > >> 7b8404a21544cf29668e8a14240c3971e6bce0c3..041a74e7efca3436bfe3e17f972dd156173957a9 > > > > > >> 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ > > > > > >> b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4508,12 > > > > > >> +4508,12 @@ static unsigned int stmmac_rx_buf1_len(struct > > > > > >> stmmac_priv *priv, /* First descriptor, not last descriptor and > > > > > >> not split header */ if (status & rx_not_ls) > > > > > >> - return priv->dma_buf_sz; > > > > > >> + return priv->dma_buf_sz - NET_SKB_PAD - > > > > > >> NET_IP_ALIGN; > > > > > >> plen = stmmac_get_rx_frame_len(priv, p, coe); > > > > > >> > > > > > >> /* First descriptor and last descriptor and not split > > > > > >> header */ > > > > > >> - return min_t(unsigned int, priv->dma_buf_sz, plen); > > > > > >> + return min_t(unsigned int, priv->dma_buf_sz - NET_SKB_PAD > > > > > >> - NET_IP_ALIGN, plen); } > > > > > >> > > > > > >> static unsigned int stmmac_rx_buf2_len(struct stmmac_priv *priv, > > > > > > > > > > > > Feels like a major deficiency of the original patch. Happy to test a > > > > > > more complete patch if/when you have one. > > > > > > > > > > I wont have time in the immediate future. > > > > > > > > > > Matteo, if you do not work on a fix, I suggest we revert > > > > > a955318fe67ec0d962760b5ee58e74bffaf649b8 stmmac: align RX buffers > > > > > > > > > > before a more polished version can be submitted. > > > > > > > > > > > > > Better to use stmmac_rx_offset() so to have the correct length when > > > > using XDP. Also, when XDP is enabled, the offset was > > > > XDP_PACKET_HEADROOM (i.e. 256 bytes) even before the change, so it > > > > could be already broken. Mark, can you try on the Jetson TX2 by > > > > attaching an XDP program and see if it works without my change? > > > > > > Sorry, you'll have to hold my hand here, as I know exactly nothing > > > about XDP.... > > > > > > > Attach the attached object with: > > > > ip link set eth0 xdp object passall.o > > > > This is an empty XDP program, its source: > > > > __attribute__((section("prog"), used)) > > int xdp_main(struct xdp_md *ctx) > > { > > return XDP_PASS; > > } > > > > Every packet will pass untouched, but the offset will be shifted from > > 0 to 256 bytes, which could trigger the problem anyway: > > Nope. On 5.13, which doesn't have the issue, adding this payload > doesn't result in any problem and the whole thing is rock solid. > > > > > > > A possible fix, which takes in account also the XDP headroom for > > > > stmmac_rx_buf1_len() only could be (only compile tested, I don't have > > > > the hardware now): > > > > > > However, this doesn't fix my issue. I still get all sort of > > > corruption. Probably stmmac_rx_buf2_len() also need adjusting (it has > > > a similar logic as its buf1 counterpart...) > > > > > > Unless you can fix it very quickly, and given that we're towards the > > > end of the cycle, I'd be more comfortable if we reverted this patch. > > > > > > > Can it be that the HW can't do DMA on an address which is not word aligned? > > What if you replace NET_SKB_PAD with, let's say, 8? > > With this: > > 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. > > Thanks, > > M. > > -- > Without deviation from the norm, progress is not possible. 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. -- per aspera ad upstream