From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Rainer Weikusat <rweikusat@mobileactivedefense.com>,
davem@davemloft.net, hannes@stressinduktion.org,
edumazet@google.com, dhowells@redhat.com, ying.xue@windriver.com,
"netdev\@vger.kernel.org" <netdev@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"stable\@vger.kernel.org" <stable@vger.kernel.org>,
Joseph Salisbury <joseph.salisbury@canonical.com>
Subject: Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code
Date: Sun, 07 Feb 2016 18:43:14 +0000 [thread overview]
Message-ID: <8737t4jr99.fsf@doppelsaurus.mobileactivedefense.com> (raw)
In-Reply-To: <1454713398.7627.325.camel@edumazet-glaptop2.roam.corp.google.com> (Eric Dumazet's message of "Fri, 05 Feb 2016 15:03:18 -0800")
Eric Dumazet <eric.dumazet@gmail.com> writes:
> On Fri, 2016-02-05 at 21:44 +0000, Rainer Weikusat wrote:
>> The present unix_stream_read_generic contains various code sequences of
>> the form
>>
>> err = -EDISASTER;
>> if (<test>)
>> goto out;
>>
>> This has the unfortunate side effect of possibly causing the error code
>> to bleed through to the final
>>
>> out:
>> return copied ? : err;
>>
>> and then to be wrongly returned if no data was copied because the caller
>> didn't supply a data buffer, as demonstrated by the program available at
>>
>> http://pad.lv/1540731
>>
>> Change it such that err is only set if an error condition was detected.
>
>
> Well, if you replace the traditional flow
>
> err = -XXXX;
> if (test)
> goto out;
>
> Then please add unlikely() to at least give a hint to the compiler.
There are really four of these, the two leading ones,
if (unlikely(sk->sk_state != TCP_ESTABLISHED)) {
err = -EINVAL;
goto out;
}
if (unlikely(flags & MSG_OOB)) {
err = -EOPNOTSUPP;
goto out;
}
one in between which was already in the function,
unix_state_lock(sk);
if (sock_flag(sk, SOCK_DEAD)) {
err = -ECONNRESET;
goto unlock;
}
[at the beginning of the loop]
and lastly,
unix_state_unlock(sk);
if (!timeo) {
err = -EAGAIN;
break;
}
mutex_unlock(&u->readlock);
timeo = unix_stream_data_wait(sk, timeo, last,
last_len);
As can be seen here, I've added unlikely() to the first two, left the
middle-one alone and didn't change the last one: That's not really an
error but a non-blocking read. My gut feeling about that would be that's
it's rather likely than unlikely but since I have no real information on
this, I don't know how to annotate it correctly (I'll gladly add
whatever annotation somebody else considers sensible).
> And please add a 'Fixes: .... ' tag for bug fixes.
Similarly, if you think this should be considered as 'fixing' anything
in particular, I'll also gladly add that. In my opinion, the real
problem is that the function disagrees with itself on how to use the err
variable: The start uses that to record an error which might need to be
reported, the return statement uses it to indicate that an error has
occurred. Hence, some kind of in-between translation must occur.
The mutex_lock_interruptible happened to do that but that was never it's
intended purpose.
NB: This is not an attempt to start an argument about that, it just
summarizes my understanding of the situation and I don't insist on this
viewpoint.
I'll send an updated patch with the changes so far, ie, the two
unlikelys.
next prev parent reply other threads:[~2016-02-07 18:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-05 18:50 [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code Joseph Salisbury
2016-02-05 19:59 ` Rainer Weikusat
2016-02-05 20:06 ` Joseph Salisbury
2016-02-05 21:18 ` Rainer Weikusat
2016-02-05 22:04 ` Rainer Weikusat
2016-02-05 21:44 ` Rainer Weikusat
2016-02-05 23:03 ` Eric Dumazet
2016-02-07 18:43 ` Rainer Weikusat [this message]
2016-02-07 20:39 ` Rainer Weikusat
2016-02-07 22:24 ` Rainer Weikusat
2016-02-08 3:35 ` Eric Dumazet
2016-02-05 22:30 ` [PATCH] af_unix: Don't set err in unix_stream_read_generic unless there was an error Rainer Weikusat
2016-02-07 19:20 ` Rainer Weikusat
2016-02-08 15:33 ` Rainer Weikusat
2016-02-08 18:05 ` Rainer Weikusat
2016-02-08 18:47 ` Rainer Weikusat
2016-02-16 17:51 ` David Miller
2016-02-17 0:24 ` Ben Hutchings
2016-02-17 1:07 ` David Miller
2016-02-08 18:33 ` Sergei Shtylyov
2016-02-11 21:31 ` Joseph Salisbury
2016-02-12 13:31 ` Rainer Weikusat
2016-02-13 0:18 ` Ben Hutchings
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=8737t4jr99.fsf@doppelsaurus.mobileactivedefense.com \
--to=rweikusat@mobileactivedefense.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=hannes@stressinduktion.org \
--cc=joseph.salisbury@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=ying.xue@windriver.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).