Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp366981rwl; Tue, 11 Apr 2023 20:17:15 -0700 (PDT) X-Google-Smtp-Source: AKy350aWIA3HIvx91ytXDGMdtHfDxj5zoHremSChiRaguQaochhp6fbkjv1m4OUOlzO8W3HJt+1G X-Received: by 2002:a17:90a:8405:b0:246:a599:1ccd with SMTP id j5-20020a17090a840500b00246a5991ccdmr888753pjn.16.1681269435185; Tue, 11 Apr 2023 20:17:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681269435; cv=none; d=google.com; s=arc-20160816; b=xPBIE/Io4Wu96986OyaLgCZn4n2yvJxbkQv8wiIepDYx+VOaDMMoSRsYr6nZoiljtM T5K6Pkj9bD/TaLS5Gi47YNGXCsfZ+OnIYIxYPgO6rPqhfD+/p1UWUSFhiLHIxqwBbql3 65PVqgTzYi/C1/vSMPNjpOmJ+7/aias94AYhDwidu768p0Od9f9yEx0yVi7AKALin69p xMxgkyLGmc/8owiphcCtQK+xmmrGnFY5B7gnfsDXfZ5S18Z+cxWYw+3VdmQ2jJmKveRw 86JguLT+3/rdbBpndC7xXGWzeuVdELlLsKGquoI5LdIlgmReYBvlKGuZbuORPJmzIr8V WDEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=zod9V2xsFQscz6pBYpVMwNkVtwPutEMxzbmVvqs5Dow=; b=oHfyIrRPBjAn4TeF7XYjcI2fZJcJ0lxjHxBciIWgPALDT+IfYHij+3pRu9LLQOZ3K8 mD8VVARI1I15hOR+sZVAB3v04NSOQkhSAmuwX4NQTdhqMuwNfff4k/w668+20pmNXPei pFLRthPVneIHcDUh6VXTQDEuXhlR37cGP81ewrwMQS6vNFQbe8WuKTEwaPSxNZfxOVmh NBIpMmdY1FsOmkUHzXL8pL+XQ8f8YivA6OPiUhB/iMP2btEGjqT/QUXsoko+IGegqyWs tnCwb0O0x34RRyHa2IRGzG7r+p1+lAHCgnwmpqACuUW2zulZVr5m9nEDR22Flg05T9GX fWPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metafoo.de header.s=default2002 header.b=jRbzgwB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=metafoo.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t12-20020a170902b20c00b001a1abc91980si14613333plr.211.2023.04.11.20.17.03; Tue, 11 Apr 2023 20:17:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metafoo.de header.s=default2002 header.b=jRbzgwB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=metafoo.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229531AbjDLDN7 (ORCPT + 99 others); Tue, 11 Apr 2023 23:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbjDLDN5 (ORCPT ); Tue, 11 Apr 2023 23:13:57 -0400 Received: from www381.your-server.de (www381.your-server.de [78.46.137.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 865D410F1; Tue, 11 Apr 2023 20:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=zod9V2xsFQscz6pBYpVMwNkVtwPutEMxzbmVvqs5Dow=; b=jRbzgwB42uTEo/ukPU/+4I3Lyf xh0Ty85hNaPmdtO4RiR42+uyJEL/3Mgdqin41DBC2W+0vOW7I29tMqRapJfbkvkjv9G+EZGXR5EHC dR0tOJhSP8/03XKOXePlKbR0/LMQeySgVgmn8cwht9ajTLKxzmCf1CLbG8hmKmnzEqsI9jE82kMKA mWIDEtVNgtKhd1RN7ImYuepQEoG/YYqKlM0P/cymPOcXesrgVtZx32UNu+Gc6xGKgOhYYAJ1uVrNj 5wb71JcXfyX7VVvYM+So/VFdhiQ93e3ouKoXTq+doqPespdzOMPI88CkJoi4ot0HNr6pwZh9f5pj5 E75q+VMA==; Received: from sslproxy06.your-server.de ([78.46.172.3]) by www381.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pmQvh-00021o-Mi; Wed, 12 Apr 2023 05:13:53 +0200 Received: from [2604:5500:c0e5:eb00:da5e:d3ff:feff:933b] by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmQvh-000TbH-CH; Wed, 12 Apr 2023 05:13:53 +0200 Message-ID: <6c025530-e2f1-955f-fa5f-8779db23edde@metafoo.de> Date: Tue, 11 Apr 2023 20:13:51 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH net] net: macb: fix a memory corruption in extended buffer descriptor mode Content-Language: en-US To: Jakub Kicinski , Roman Gushchin Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Rafal Ozieblo References: <20230407172402.103168-1-roman.gushchin@linux.dev> <20230411184814.5be340a8@kernel.org> From: Lars-Peter Clausen In-Reply-To: <20230411184814.5be340a8@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.103.8/26872/Tue Apr 11 09:26:30 2023) X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/11/23 18:48, Jakub Kicinski wrote: > On Fri, 7 Apr 2023 10:24:02 -0700 Roman Gushchin wrote: >> The problem is resolved by extending the MACB_RX_WADDR_SIZE >> in the extended mode. >> >> Fixes: 7b4296148066 ("net: macb: Add support for PTP timestamps in DMA descriptors") >> Signed-off-by: Roman Gushchin >> Co-developed-by: Lars-Peter Clausen >> Signed-off-by: Lars-Peter Clausen >> --- >> drivers/net/ethernet/cadence/macb.h | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h >> index c1fc91c97cee..1b330f7cfc09 100644 >> --- a/drivers/net/ethernet/cadence/macb.h >> +++ b/drivers/net/ethernet/cadence/macb.h >> @@ -826,8 +826,13 @@ struct macb_dma_desc_ptp { >> #define MACB_RX_USED_SIZE 1 >> #define MACB_RX_WRAP_OFFSET 1 >> #define MACB_RX_WRAP_SIZE 1 >> +#ifdef MACB_EXT_DESC >> +#define MACB_RX_WADDR_OFFSET 3 >> +#define MACB_RX_WADDR_SIZE 29 >> +#else >> #define MACB_RX_WADDR_OFFSET 2 >> #define MACB_RX_WADDR_SIZE 30 >> +#endif > Changing register definition based on Kconfig seems a bit old school. > > Where is the extended descriptor mode enabled? Is it always on if > Kconfig is set or can it be off for some platforms based on other > capabilities? Judging by macb_dma_desc_get_size() small descriptors > can still be used even with EXT_DESC? > > If I'm grepping correctly thru the painful macro magic this register > is only used in macb_get_addr(). It'd seem a bit more robust to me > to open code the extraction of the address based on bp->hw_dma_cap > in that one function. > > In addition to maintainers please also CC Harini Katakam > on v2. We had an alternative patch which fixes this based on runtime settings. But it didn't seem to be worth it considering the runtime overhead, even though it is small. The skb buffer address is guaranteed to be cacheline aligned, otherwise the DMA wouldn't work at all. So we know that the LSBs must always be 0. We could even unconditionally define MACB_RX_WADDR_OFFSET as 3. Alternative runtime base patch: diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index d13fb1d31821..1a40d5a26f36 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -1042,6 +1042,10 @@ static dma_addr_t macb_get_addr(struct macb *bp, struct macb_dma_desc *desc)         }  #endif         addr |= MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, desc->addr)); +#ifdef CONFIG_MACB_USE_HWSTAMP +       if (bp->hw_dma_cap & HW_DMA_CAP_PTP) +               addr &= ~GEM_BIT(DMA_RXVALID_OFFSET); +#endif         return addr;  }