From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Andrey Konovalov <andreyknvl@google.com>,
Victor Chibotaru <tchibo@google.com>,
syzkaller <syzkaller@googlegroups.com>,
Mark Rutland <mark.rutland@arm.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/3] kcov: remove useless barrier()s
Date: Tue, 19 Sep 2017 17:29:40 +0300 [thread overview]
Message-ID: <62a9c122-1527-3466-bbb9-4e2035a160e4@virtuozzo.com> (raw)
In-Reply-To: <CACT4Y+bv6E_DLYEdF0yBC69=gNV++CS7AzN28-jPYoH6JWNdeQ@mail.gmail.com>
On 09/19/2017 04:54 PM, Dmitry Vyukov wrote:
> On Tue, Sep 19, 2017 at 3:52 PM, Andrey Ryabinin
> <aryabinin@virtuozzo.com> wrote:
>>
>>
>> On 09/19/2017 03:57 PM, Dmitry Vyukov wrote:
>>> On Tue, Sep 19, 2017 at 2:46 PM, Andrey Ryabinin
>>> <aryabinin@virtuozzo.com> wrote:
>>>> As comment says barriers needed for preempt_schedule_irq() case
>>>> where in_interrupt() returns false. But we don't use in_interrupt()
>>>> since b274c0bb394c ("kcov: properly check if we are in an interrupt").
>>>>
>>>> Now we use in_task() which handles preempt_schedule_irq() case properly,
>>>> thus no barrier required.
>>>
>>>
>>> Are you sure in_task() handles preempt_schedule_irq() correctly?
>>> They seem to differ only by SOFTIRQ_MASK vs SOFTIRQ_OFFSET, and that
>>> only differs in local_bh_disable sections. But preempt_schedule_irq()
>>> does not seem to have anything to do softirq/local_bh_disable. It's
>>> called from real interrupts, right? So I would expect that in_task()
>>> returns true in preempt_schedule_irq().
>>
>> Indeed, you're right. I checked this only on !PREEMPT kernel, where this worked.
>>
>> Still, I think that barrier() in __sanitizer_cov_trace_pc() is not needed. AFAIU it needed
>> to make sure that load of t->kcov_area isn't moved before load of t->kcov_mode, but I don't
>> think that compiler is allowed to make such reorder. That would be a bug in the compiler.
>
Ugh, it should have saied READ_ONCE(area[0]) instead of t->kcov_area.
>
> Why? C compiler is allowed to fuse/reorder loads from the same base
> object. Also stores can be reordered.
>
Ok, right. t->kcov_area can be loaded before t->kcov_mode, and it's fine. But deference of the kcov_area
(READ_ONCE(area[0])) can't be moved before kcov_mode check. And this barrier intended to prevent such move, right?
>
>>>> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
>>>> ---
>>>> kernel/kcov.c | 10 ----------
>>>> 1 file changed, 10 deletions(-)
>>>>
>>>> diff --git a/kernel/kcov.c b/kernel/kcov.c
>>>> index 14cc8c1a7cad..b7fbcbef88c1 100644
>>>> --- a/kernel/kcov.c
>>>> +++ b/kernel/kcov.c
>>>> @@ -71,14 +71,6 @@ void notrace __sanitizer_cov_trace_pc(void)
>>>>
>>>> ip -= kaslr_offset();
>>>>
>>>> - /*
>>>> - * There is some code that runs in interrupts but for which
>>>> - * in_interrupt() returns false (e.g. preempt_schedule_irq()).
>>>> - * READ_ONCE()/barrier() effectively provides load-acquire wrt
>>>> - * interrupts, there are paired barrier()/WRITE_ONCE() in
>>>> - * kcov_ioctl_locked().
>>>> - */
>>>> - barrier();
>>>> area = t->kcov_area;
>>>> /* The first word is number of subsequent PCs. */
>>>> pos = READ_ONCE(area[0]) + 1;
>>>> @@ -228,8 +220,6 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigned int cmd,
>>>> /* Cache in task struct for performance. */
>>>> t->kcov_size = kcov->size;
>>>> t->kcov_area = kcov->area;
>>>> - /* See comment in __sanitizer_cov_trace_pc(). */
>>>> - barrier();
>>>> WRITE_ONCE(t->kcov_mode, kcov->mode);
>>>> t->kcov = kcov;
>>>> kcov->t = t;
>>>> --
>>>> 2.13.5
>>>>
>>
next prev parent reply other threads:[~2017-09-19 14:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-19 12:46 [PATCH 1/3] kcov: remove #ifdef CONFIG_RANDOMIZE_BASE Andrey Ryabinin
2017-09-19 12:46 ` [PATCH 2/3] kcov: remove pointless current != NULL check Andrey Ryabinin
2017-09-19 12:57 ` Dmitry Vyukov
2017-09-19 13:32 ` Mark Rutland
2017-09-19 12:46 ` [PATCH 3/3] kcov: remove useless barrier()s Andrey Ryabinin
2017-09-19 12:57 ` Dmitry Vyukov
2017-09-19 13:52 ` Andrey Ryabinin
2017-09-19 13:54 ` Dmitry Vyukov
2017-09-19 14:29 ` Andrey Ryabinin [this message]
2017-09-19 14:42 ` Dmitry Vyukov
2017-09-19 13:03 ` [PATCH 1/3] kcov: remove #ifdef CONFIG_RANDOMIZE_BASE Dmitry Vyukov
2017-09-19 13:30 ` Mark Rutland
2017-09-19 13:47 ` Dmitry Vyukov
2017-09-29 16:20 ` Andrey Ryabinin
2017-09-21 22:16 ` kbuild test robot
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=62a9c122-1527-3466-bbb9-4e2035a160e4@virtuozzo.com \
--to=aryabinin@virtuozzo.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@google.com \
--cc=dvyukov@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=syzkaller@googlegroups.com \
--cc=tchibo@google.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
all inboxes | Powered by JetHome®