All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Borislav Petkov <bp@alien8.de>
Cc: "Richard W.M. Jones" <rjones@redhat.com>,
	Chuck Ebbert <cebbert.lkml@gmail.com>,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [BUG 4.2-rc8] Interrupt occurs while apply_alternatives() is patching the handler
Date: Thu, 3 Sep 2015 12:41:47 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.11.1509031232340.15006@nanos> (raw)
In-Reply-To: <20150903085046.GA19397@nazgul.tnic>

On Thu, 3 Sep 2015, Borislav Petkov wrote:
> On Wed, Sep 02, 2015 at 11:11:55AM +0200, Thomas Gleixner wrote:
> >  static void __init_or_module add_nops(void *insns, unsigned int len)
> >  {
> > +	unsigned long flags;
> > +
> > +	local_irq_save(flags);
> >  	while (len > 0) {
> 
> I guess you want to optimize the len==0 case to not disable interrupts
> needlessly:
> 
> 	if (!len)
> 		return;
> 
> 	local_irq_save(flags);
> 	while (len > 0)
> 		...

Nah. I rather put the local_irq_save into optimize_nops(). All other
callers of add_nops() are operating on a buffer and use text_poke
after that. Aside of that optimize_nops() is missing a sync_core().

Updated patch below.

Thanks,

	tglx

----------------->
Subject: x86/alternatives: Make optimize_nops() interrupt safe and synced
From: Thomas Gleixner <tglx@linutronix.de>
Date: Thu, 03 Sep 2015 12:34:55 +0200

optimize_nops() is buggy in two aspects:

- It's not disabling interrupts across the modification
- It's lacking a sync_core() call

Fixes: 4fd4b6e5537c 'x86/alternatives: Use optimized NOPs for padding'
Reported-by: "Richard W.M. Jones" <rjones@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/alternative.c |    5 +++++
 1 file changed, 5 insertions(+)

Index: tip/arch/x86/kernel/alternative.c
===================================================================
--- tip.orig/arch/x86/kernel/alternative.c
+++ tip/arch/x86/kernel/alternative.c
@@ -338,10 +338,15 @@ done:
 
 static void __init_or_module optimize_nops(struct alt_instr *a, u8 *instr)
 {
+	unsigned long flags;
+
 	if (instr[0] != 0x90)
 		return;
 
+	local_irq_save(flags);
 	add_nops(instr + (a->instrlen - a->padlen), a->padlen);
+	sync_core();
+	local_irq_restore(flags);
 
 	DUMP_BYTES(instr, a->instrlen, "%p: [%d:%d) optimized NOPs: ",
 		   instr, a->instrlen - a->padlen, a->padlen);



  reply	other threads:[~2015-09-03 10:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-31  2:37 Chuck Ebbert
2015-09-01  6:20 ` Richard W.M. Jones
2015-09-02  9:11   ` Thomas Gleixner
2015-09-02 19:05     ` Richard W.M. Jones
2015-09-03  7:53       ` Richard W.M. Jones
2015-09-03  8:50     ` Borislav Petkov
2015-09-03 10:41       ` Thomas Gleixner [this message]
2015-09-03 12:43         ` Josh Boyer
2015-09-03 13:01           ` Thomas Gleixner
2015-09-03 15:48         ` Richard W.M. Jones
2015-09-03 19:30         ` [tip:x86/urgent] x86/alternatives: Make optimize_nops() interrupt safe and synced tip-bot for Thomas Gleixner
2015-09-04  7:40         ` [BUG 4.2-rc8] Interrupt occurs while apply_alternatives() is patching the handler Richard W.M. Jones
2015-09-04 12:02         ` Borislav Petkov
2015-09-04 13:37           ` Thomas Gleixner
2015-09-05 15:25             ` Borislav Petkov

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=alpine.DEB.2.11.1509031232340.15006@nanos \
    --to=tglx@linutronix.de \
    --cc=bp@alien8.de \
    --cc=cebbert.lkml@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rjones@redhat.com \
    --cc=x86@kernel.org \
    --subject='Re: [BUG 4.2-rc8] Interrupt occurs while apply_alternatives() is patching the handler' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.