From: Peter Zijlstra <peterz@infradead.org>
To: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/preempt: do not clear PREEMPT_NEED_RESCHED on preempt count reset
Date: Fri, 11 Nov 2016 18:22:03 +0100 [thread overview]
Message-ID: <20161111172203.GN3117@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1478523660-733-1-git-send-email-schwidefsky@de.ibm.com>
On Mon, Nov 07, 2016 at 02:01:00PM +0100, Martin Schwidefsky wrote:
> The per-cpu preempt count of x86 contains two values, the actual preempt
> count and the inverted PREEMPT_NEED_RESCHED bit. If a corrupted preempt
> count is detected the preempt_count_set function is used to reset the
> preempt count.
>
> In case the inverted PREEMPT_NEED_RESCHED bit is zero at the time of the
> reset, the preemption indication is lost. Use raw_cpu_cmpxchg_4 to reset
> only the count part and leave the PREEMPT_NEED_RESCHED bit as it is.
>
> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Thanks Martin!
I don't suppose this really hurts too much; if we hit a warn where this
restore is needed there are bigger problems, but given you've done the
patch already and it does improve consistency, I've taken it.
> ---
> arch/x86/include/asm/preempt.h | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
> index 17f2186..ec1f3c6 100644
> --- a/arch/x86/include/asm/preempt.h
> +++ b/arch/x86/include/asm/preempt.h
> @@ -24,7 +24,13 @@ static __always_inline int preempt_count(void)
>
> static __always_inline void preempt_count_set(int pc)
> {
> - raw_cpu_write_4(__preempt_count, pc);
> + int old, new;
> +
> + do {
> + old = raw_cpu_read_4(__preempt_count);
> + new = (old & PREEMPT_NEED_RESCHED) |
> + (pc & ~PREEMPT_NEED_RESCHED);
> + } while (raw_cpu_cmpxchg_4(__preempt_count, old, new) != old);
> }
>
> /*
> --
> 1.9.1
>
next prev parent reply other threads:[~2016-11-11 17:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-07 13:01 Martin Schwidefsky
2016-11-11 17:22 ` Peter Zijlstra [this message]
2016-11-16 12:12 ` [tip:sched/core] sched/x86: Do " tip-bot for Martin Schwidefsky
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=20161111172203.GN3117@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=schwidefsky@de.ibm.com \
--cc=tglx@linutronix.de \
/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
Powered by JetHome