From: Peter Zijlstra <peterz@infradead.org>
To: Marco Elver <elver@google.com>
Cc: "Paul E. McKenney" <paulmck@kernel.org>,
Will Deacon <will@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Boqun Feng <boqun.feng@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
kasan-dev <kasan-dev@googlegroups.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] kcsan: Avoid scheduler recursion by using non-instrumented preempt_{disable,enable}()
Date: Mon, 23 Nov 2020 17:08:23 +0100 [thread overview]
Message-ID: <20201123160823.GC2414@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20201123155746.GA2203226@elver.google.com>
On Mon, Nov 23, 2020 at 04:57:46PM +0100, Marco Elver wrote:
> Let me know what you prefer.
>
> @@ -288,27 +288,19 @@ static u32 kcsan_prandom_u32_max(u32 ep_ro)
> u32 res;
>
> /*
> + * Avoid recursion with scheduler by disabling KCSAN because
> + * preempt_enable_notrace() will still call into scheduler code.
> */
> + kcsan_disable_current();
> preempt_disable_notrace();
> state = raw_cpu_ptr(&kcsan_rand_state);
> res = prandom_u32_state(state);
> + preempt_enable_notrace();
> + kcsan_enable_current_nowarn();
>
> return (u32)(((u64) res * ep_ro) >> 32);
> }
This is much preferred over the other. The thing with _no_resched is that
you can miss a preemption for an unbounded amount of time, which is bad.
The _only_ valid use of _no_resched is when there's a call to schedule()
right after it.
next prev parent reply other threads:[~2020-11-23 16:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-23 13:23 Marco Elver
2020-11-23 13:55 ` Peter Zijlstra
2020-11-23 15:17 ` Marco Elver
2020-11-23 15:57 ` Marco Elver
2020-11-23 16:08 ` Peter Zijlstra [this message]
2020-11-23 19:12 ` Marco Elver
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=20201123160823.GC2414@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=boqun.feng@gmail.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=paulmck@kernel.org \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
/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®