From: Lars-Peter Clausen <lars@metafoo.de>
To: Jakub Kicinski <kuba@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Rafal Ozieblo <rafalo@cadence.com>
Subject: Re: [PATCH net] net: macb: fix a memory corruption in extended buffer descriptor mode
Date: Tue, 11 Apr 2023 20:13:51 -0700 [thread overview]
Message-ID: <6c025530-e2f1-955f-fa5f-8779db23edde@metafoo.de> (raw)
In-Reply-To: <20230411184814.5be340a8@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 <roman.gushchin@linux.dev>
>> Co-developed-by: Lars-Peter Clausen <lars@metafoo.de>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>> ---
>> 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
> <harini.katakam@xilinx.com> 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;
}
next prev parent reply other threads:[~2023-04-12 3:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-07 17:24 Roman Gushchin
2023-04-11 18:20 ` Roman Gushchin
2023-04-11 18:30 ` Conor Dooley
2023-04-11 21:20 ` Roman Gushchin
2023-04-12 1:48 ` Jakub Kicinski
2023-04-12 3:13 ` Lars-Peter Clausen [this message]
2023-04-12 3:48 ` Roman Gushchin
2023-04-12 4:13 ` Jakub Kicinski
2023-04-12 15:47 ` Nicolas.Ferre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6c025530-e2f1-955f-fa5f-8779db23edde@metafoo.de \
--to=lars@metafoo.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rafalo@cadence.com \
--cc=roman.gushchin@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®