linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, Wanpeng Li <wanpeng.li@hotmail.com>,
	Ingo Molnar <mingo@kernel.org>, Mike Galbraith <efault@gmx.de>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] x86/smp: Add irq_enter/exit() in smp_reschedule_interrupt()
Date: Mon, 17 Oct 2016 06:08:42 -0400 (EDT)	[thread overview]
Message-ID: <938757058.3991379.1476698922290.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <CANRm+CxSHMpF4LUfcF1U_8GXnwAo9beXM6C-3JaTpm7Eb3bxUw@mail.gmail.com>



----- Original Message -----
> From: "Wanpeng Li" <kernellwp@gmail.com>
> To: "Peter Zijlstra" <peterz@infradead.org>
> Cc: linux-kernel@vger.kernel.org, "Wanpeng Li" <wanpeng.li@hotmail.com>, "Ingo Molnar" <mingo@kernel.org>, "Mike
> Galbraith" <efault@gmx.de>, "Thomas Gleixner" <tglx@linutronix.de>, "Paolo Bonzini" <pbonzini@redhat.com>
> Sent: Monday, October 17, 2016 11:45:32 AM
> Subject: Re: [PATCH] x86/smp: Add irq_enter/exit() in smp_reschedule_interrupt()
> 
> Cc Paolo,
> 2016-10-17 16:22 GMT+08:00 Peter Zijlstra <peterz@infradead.org>:
> > On Mon, Oct 17, 2016 at 12:19:43PM +0800, Wanpeng Li wrote:
> >> 2016-10-16 21:39 GMT+08:00 Peter Zijlstra <peterz@infradead.org>:
> >
> >> >>   [<ffffffff9d492b95>] do_trace_write_msr+0x135/0x140
> >> >>   [<ffffffff9d06f860>] native_write_msr+0x20/0x30
> >> >>   [<ffffffff9d065fad>] native_apic_msr_eoi_write+0x1d/0x30
> >> >>   [<ffffffff9d05bd1d>] smp_reschedule_interrupt+0x1d/0x30
> >> >>   [<ffffffff9d8daec6>] reschedule_interrupt+0x96/0xa0
> >
> >> >>  __visible void smp_reschedule_interrupt(struct pt_regs *regs)
> >> >>  {
> >> >> +     irq_enter();
> >> >>       ack_APIC_irq();
> >> >>       __smp_reschedule_interrupt();
> >> >> +     irq_exit();
> >> >
> >> > Urgh, I really hate this...
> >> >
> >> > So now we're making a very frequent interrupt slower because of debug
> >> > code :/
> >>
> >> Do you have a better idea? :)
> >
> > Something like the below avoids all that. Paravirt will still need fixing.
> 
> kvm_guest_apic_eoi_write
>  -> native_apic_msr_write

kvm_guest_apic_eoi_write can use native_apic_msr_eoi_write too:

diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index f5aaf6c83222..9769d76a62c4 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -174,7 +174,7 @@ static inline void disable_local_APIC(void) { }
 static inline void lapic_update_tsc_freq(void) { }
 #endif /* !CONFIG_X86_LOCAL_APIC */
 
-#ifdef CONFIG_X86_X2APIC
+#if defined CONFIG_X86_X2APIC || defined CONFIG_KVM_GUEST
 /*
  * Make previous memory operations globally visible before
  * sending the IPI through x2apic wrmsr. We need a serializing instruction or
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index edbbfc854e39..61cc6a5e3f44 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -319,7 +319,7 @@ static void kvm_guest_apic_eoi_write(u32 reg, u32 val)
 	 */
 	if (__test_and_clear_bit(KVM_PV_EOI_BIT, this_cpu_ptr(&kvm_apic_eoi)))
 		return;
-	apic_write(APIC_EOI, APIC_EOI_ACK);
+	native_apic_msr_eoi_write(APIC_EOI, APIC_EOI_ACK);
 }
 
 static void kvm_guest_cpu_init(void)


Thanks,

Paolo

> I think you can replace the wrmsr in native_apic_msr_write() by your
> wrmsr_notrace().
> 
> Regards,
> Wanpeng Li
> 
> >
> > The thing is, many many smp_reschedule_interrupt() invocations don't
> > actually execute anything much at all and are only send to tickle the
> > return to user path (which does the actual preemption).
> >
> > Having to do the whole irq_enter/irq_exit dance just for this unlikely
> > debug case totally blows.
> >
> > ---
> >  arch/x86/include/asm/apic.h |  2 +-
> >  arch/x86/include/asm/msr.h  | 15 +++++++++++++++
> >  2 files changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
> > index f5aaf6c83222..b97bfeed6456 100644
> > --- a/arch/x86/include/asm/apic.h
> > +++ b/arch/x86/include/asm/apic.h
> > @@ -196,7 +196,7 @@ static inline void native_apic_msr_write(u32 reg, u32
> > v)
> >
> >  static inline void native_apic_msr_eoi_write(u32 reg, u32 v)
> >  {
> > -       wrmsr(APIC_BASE_MSR + (APIC_EOI >> 4), APIC_EOI_ACK, 0);
> > +       wrmsr_notrace(APIC_BASE_MSR + (APIC_EOI >> 4), APIC_EOI_ACK, 0);
> >  }
> >
> >  static inline u32 native_apic_msr_read(u32 reg)
> > diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
> > index b5fee97813cd..45c080449d5b 100644
> > --- a/arch/x86/include/asm/msr.h
> > +++ b/arch/x86/include/asm/msr.h
> > @@ -127,6 +127,16 @@ notrace static inline void native_write_msr(unsigned
> > int msr,
> >  }
> >
> >  /* Can be uninlined because referenced by paravirt */
> > +notrace static inline void native_write_msr_notrace(unsigned int msr,
> > +                                           unsigned low, unsigned high)
> > +{
> > +       asm volatile("1: wrmsr\n"
> > +                    "2:\n"
> > +                    _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_wrmsr_unsafe)
> > +                    : : "c" (msr), "a"(low), "d" (high) : "memory");
> > +}
> > +
> > +/* Can be uninlined because referenced by paravirt */
> >  notrace static inline int native_write_msr_safe(unsigned int msr,
> >                                         unsigned low, unsigned high)
> >  {
> > @@ -228,6 +238,11 @@ static inline void wrmsr(unsigned msr, unsigned low,
> > unsigned high)
> >         native_write_msr(msr, low, high);
> >  }
> >
> > +static inline void wrmsr_notrace(unsigned msr, unsigned low, unsigned
> > high)
> > +{
> > +       native_write_msr_notrace(msr, low, high);
> > +}
> > +
> >  #define rdmsrl(msr, val)                       \
> >         ((val) = native_read_msr((msr)))
> >
> 

  reply	other threads:[~2016-10-17 10:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-14  1:48 [PATCH] x86/smp: Add irq_enter/exit() in smp_reschedule_interrupt() Wanpeng Li
2016-10-14 12:19 ` [tip:x86/urgent] " tip-bot for Wanpeng Li
2016-10-16 13:39 ` [PATCH] " Peter Zijlstra
2016-10-17  4:19   ` Wanpeng Li
2016-10-17  8:22     ` Peter Zijlstra
2016-10-17  9:45       ` Wanpeng Li
2016-10-17 10:08         ` Paolo Bonzini [this message]
2016-10-17 10:23           ` Wanpeng Li
2016-10-18  0:01           ` Wanpeng Li
2016-10-19 14:01             ` Wanpeng Li
2016-10-19 14:10               ` Paolo Bonzini
2016-10-19 14:30                 ` Wanpeng Li
2016-10-24 14:32                   ` Paolo Bonzini
2016-10-25  2:52                     ` Wanpeng Li
2016-10-17 12:19       ` Wanpeng Li

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=938757058.3991379.1476698922290.JavaMail.zimbra@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=efault@gmx.de \
    --cc=kernellwp@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=wanpeng.li@hotmail.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).