From: Jochen Henneberg <jh@henneberg-systemdesign.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org,
Giuseppe Cavallaro <peppe.cavallaro@st.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Ong Boon Leong <boon.leong.ong@intel.com>,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net V2 1/2] net: stmmac: Premature loop termination check was ignored on rx
Date: Mon, 20 Mar 2023 10:04:54 +0100 [thread overview]
Message-ID: <87r0tj23eh.fsf@henneberg-systemdesign.com> (raw)
In-Reply-To: <20230318190125.175b0fea@kernel.org>
Jakub Kicinski <kuba@kernel.org> writes:
> On Sat, 18 Mar 2023 09:38:12 +0100 Jochen Henneberg wrote:
>> > Are you sure? Can you provide more detailed analysis?
>> > Do you observe a problem / error in real life or is this theoretical?
>>
>> This is theoretical, I was hunting another bug and just stumbled over
>> the check which is, I think you agree, pointless right now. I did not
>> try to force execute that code path.
>
> If you have the HW it's definitely worth doing. There is a fault
> injection infra in Linus which allows to fail memory allocations.
> Or you can just make a little patch to the driver to fake failing
> every 1000th allocation.
>
I have the hardware available and will do the check.
>> > As far as I can tell only path which jumps to read_again after doing
>> > count++ is via the drain_data jump, but I can't tell how it's
>> > discarding subsequent segments in that case..
>> >
>> >> -read_again:
>> >> buf1_len = 0;
>> >> buf2_len = 0;
>> >> entry = next_entry;
>>
>> Correct. The read_again is triggered in case that the segment is not the
>> last segment of the frame:
>>
>> if (likely(status & rx_not_ls))
>> goto read_again;
>>
>> So in case there is no skb (queue error) it will keep increasing count
>> until the last segment has been found with released device DMA
>> ownership. So skb will not change while the goto loop is running, the
>> only thing that will change is that subsequent segments release device
>> DMA ownership. The dirty buffers are then cleaned up from
>> stmmac_rx_refill().
>
> To be clear - I'm only looking at stmmac_rx(), that ZC one is even more
> confusing.
>
> Your patch makes sense, but I think it's not enough to make this code
> work in case of memory allocation failure. AFAIU the device supports
> scatter - i.e. receiving a single frame in multiple chunks. Each time
> thru the loop we process one (or two?) chunks. But the code uses
> skb == NULL to decide whether it's the first chunk or not. So in case
> of memory allocation error it will treat the second chunk as the first
> (since skb will be NULL) and we'll get a malformed frame with missing
> chunks sent to the stack. The driver should discard the entire frame
> on failure..
>
Understood. However, this forces me to read the code and datahseet very
carefully to understand the details. I will do that, however, it will
take me some time.
For the ST and Synopsys people:
I could imagine that you would be able to fix this much faster than
I can, so if they want to work on this please let me know so I don't
waste my time on doing double work.
>> I think the driver code is really hard to read I have planned to cleanup
>> things later, however, this patch simply tries to prevent us from
>> returning a value greater than limit which could happen and would
>> definitely be wrong.
next prev parent reply other threads:[~2023-03-20 9:12 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-14 12:37 [PATCH net 0/2] net: stmmac: Premature loop termination check was ignored Jochen Henneberg
2023-03-14 12:37 ` [PATCH net 1/2] " Jochen Henneberg
2023-03-14 14:44 ` Piotr Raczynski
2023-03-14 15:01 ` Jochen Henneberg
2023-03-15 8:59 ` Piotr Raczynski
2023-03-15 9:13 ` Jochen Henneberg
2023-03-14 12:37 ` [PATCH net 2/2] " Jochen Henneberg
2023-03-16 7:59 ` [PATCH net V2 0/2] " Jochen Henneberg
2023-03-16 7:59 ` [PATCH net V2 1/2] net: stmmac: Premature loop termination check was ignored on rx Jochen Henneberg
2023-03-17 12:32 ` Piotr Raczynski
2023-03-18 5:21 ` Jakub Kicinski
2023-03-18 8:38 ` Jochen Henneberg
2023-03-19 2:01 ` Jakub Kicinski
2023-03-20 9:04 ` Jochen Henneberg [this message]
2023-03-20 18:36 ` Jakub Kicinski
2023-03-21 18:53 ` Jochen Henneberg
2023-03-16 7:59 ` [PATCH net V2 2/2] net: stmmac: Premature loop termination check was ignored on ZC rx Jochen Henneberg
2023-03-17 12:32 ` Piotr Raczynski
2023-03-16 23:20 ` [PATCH net V2 0/2] net: stmmac: Premature loop termination check was ignored Horatiu Vultur
2023-03-17 12:31 ` Piotr Raczynski
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=87r0tj23eh.fsf@henneberg-systemdesign.com \
--to=jh@henneberg-systemdesign.com \
--cc=alexandre.torgue@foss.st.com \
--cc=boon.leong.ong@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=joabreu@synopsys.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peppe.cavallaro@st.com \
/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).