From: Jakub Kicinski <kuba@kernel.org>
To: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
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 21:13:43 -0700 [thread overview]
Message-ID: <20230411211343.43b6833a@kernel.org> (raw)
In-Reply-To: <ZDYqIj4Fg3tlGKd5@P9FQF9L96D.corp.robot.car>
On Tue, 11 Apr 2023 20:48:50 -0700 Roman Gushchin wrote:
> > 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;
> > }
>
> I think this version is slightly worse because it adds an unconditional
> if statement, which can be removed with certain config options.
> I can master a version with a helper function, if it's preferable.
>
> But if you like this one, it's fine too, let me know, I'll send an updated
> version.
Yup, IMHO this looks better. More likely that someone reading the code
will spot the trickiness.
I suspect we could clear that bit unconditionally, if the branch is
a concern. The code seems to assume that buffers it gets are 8B aligned
already, regardless of CONFIG_MACB_USE_HWSTAMP.
Drivers commonly save the DMA address to a SW ring (here I think
rx_skbuff plays this role but only holds single ptr per entry)
so that they don't have to access potentially uncached descriptor
ring. But that'd be too large of a change for a fix.
next prev parent reply other threads:[~2023-04-12 4:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-07 17:24 [PATCH net] net: macb: fix a memory corruption in extended buffer descriptor mode 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
2023-04-12 3:48 ` Roman Gushchin
2023-04-12 4:13 ` Jakub Kicinski [this message]
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=20230411211343.43b6833a@kernel.org \
--to=kuba@kernel.org \
--cc=lars@metafoo.de \
--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;
as well as URLs for NNTP newsgroup(s).