public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Yinghai Lu <yhlu.kernel@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Suresh Siddha <suresh.b.siddha@intel.com>,
	Sheng Yang <sheng@linux.intel.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"avi@redhat.com" <avi@redhat.com>
Subject: Re: [PATCH v4] enable x2APIC without interrupt remapping under KVM
Date: Tue, 30 Jun 2009 10:54:57 +0300	[thread overview]
Message-ID: <20090630075457.GH20289@redhat.com> (raw)
In-Reply-To: <86802c440906300018p8c5156dy3e8d84b8c263797e@mail.gmail.com>

On Tue, Jun 30, 2009 at 12:18:19AM -0700, Yinghai Lu wrote:
> On Mon, Jun 29, 2009 at 11:45 PM, Gleb Natapov<gleb@redhat.com> wrote:
> > KVM would like to provide x2APIC interface to a guest without emulating
> > interrupt remapping device. The reason KVM prefers guest to use x2APIC
> > is that x2APIC interface is better virtualizable and provides better
> > performance than mmio xAPIC interface:
> >
> > - msr exits are faster than mmio (no page table walk, emulation)
> > - no need to read back ICR to look at the busy bit
> > - one 64 bit ICR write instead of two 32 bit writes
> > - shared code with the Hyper-V paravirt interface
> >
> > Included patch changes x2APIC enabling logic to enable it even if IR
> > initialization failed, but kernel runs under KVM and no apic id is
> > greater than 255 (if there is one spec requires BIOS to move to x2apic
> > mode before starting an OS).
> >
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
> > index 8c7c042..351d55a 100644
> > --- a/arch/x86/kernel/apic/apic.c
> > +++ b/arch/x86/kernel/apic/apic.c
> > @@ -49,6 +49,7 @@
> >  #include <asm/mtrr.h>
> >  #include <asm/smp.h>
> >  #include <asm/mce.h>
> > +#include <asm/kvm_para.h>
> >
> >  unsigned int num_processors;
> >
> > @@ -1363,52 +1364,75 @@ void enable_x2apic(void)
> >  }
> >  #endif /* CONFIG_X86_X2APIC */
> >
> > -void __init enable_IR_x2apic(void)
> > +int __init enable_IR(void)
> >  {
> >  #ifdef CONFIG_INTR_REMAP
> >        int ret;
> > -       unsigned long flags;
> > -       struct IO_APIC_route_entry **ioapic_entries = NULL;
> >
> >        ret = dmar_table_init();
> >        if (ret) {
> >                pr_debug("dmar_table_init() failed with %d:\n", ret);
> > -               goto ir_failed;
> > +               return 0;
> >        }
> >
> >        if (!intr_remapping_supported()) {
> >                pr_debug("intr-remapping not supported\n");
> > -               goto ir_failed;
> > +               return 0;
> >        }
> >
> > -
> >        if (!x2apic_preenabled && skip_ioapic_setup) {
> >                pr_info("Skipped enabling intr-remap because of skipping "
> >                        "io-apic setup\n");
> > -               return;
> > +               return 0;
> >        }
> >
> > +       if (enable_intr_remapping(x2apic_supported()))
> > +               return 0;
> > +
> > +       pr_info("Enabled Interrupt-remapping\n");
> > +
> > +       return 1;
> > +
> > +#endif
> > +       return 0;
> > +}
> > +
> > +void __init enable_IR_x2apic(void)
> > +{
> > +       unsigned long flags;
> > +       struct IO_APIC_route_entry **ioapic_entries = NULL;
> > +       int ret, x2apic_enabled = 0;
> > +
> >        ioapic_entries = alloc_ioapic_entries();
> >        if (!ioapic_entries) {
> > -               pr_info("Allocate ioapic_entries failed: %d\n", ret);
> > -               goto end;
> > +                pr_info("Allocate ioapic_entries failed\n");
> > +                goto out;
> >        }
> >
> >        ret = save_IO_APIC_setup(ioapic_entries);
> >        if (ret) {
> >                pr_info("Saving IO-APIC state failed: %d\n", ret);
> > -               goto end;
> > +               goto out;
> >        }
> >
> >        local_irq_save(flags);
> > -       mask_IO_APIC_setup(ioapic_entries);
> >        mask_8259A();
> > +       mask_IO_APIC_setup(ioapic_entries);
> >
> > -       ret = enable_intr_remapping(x2apic_supported());
> > -       if (ret)
> > -               goto end_restore;
> > +       ret = enable_IR();
> > +       if (!ret) {
> > +               /* IR is required if x2apic is enabled by BIOS even
> > +                * when running in kvm since this indicates present
> > +                * of APIC ID > 255 */
> > +               if (x2apic_preenabled || !kvm_para_available())
> > +                       goto nox2apic;
> > +               else
> > +                       /* without IR all CPUs can be addressed by IOAPIC/MSI
> > +                        * only in physical mode */
> > +                       x2apic_phys = 1;
> > +       }
> 
> how about kexec second kernel in KVM ?
> 
> x2apic_preenabled will be set in second kernel.
> 
Yes, bummer. But the similar problem exist now and without KVM. After
running x2apic enabled kernel you can't kexec kernel without x2apic
support. Shouldn't apic be reset to its initial state on reboot?

--
			Gleb.

  reply	other threads:[~2009-06-30  7:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-30  6:45 [PATCH v4] enable x2APIC without interrupt remapping under KVM Gleb Natapov
2009-06-30  7:18 ` Yinghai Lu
2009-06-30  7:54   ` Gleb Natapov [this message]
2009-06-30 18:43     ` Yinghai Lu
2009-06-30 18:53       ` Gleb Natapov
2009-06-30 15:58   ` Gleb Natapov
2009-06-30 17:00     ` Eric W. Biederman
2009-06-30 17:14       ` Avi Kivity
2009-06-30 19:24         ` Eric W. Biederman
2009-06-30 19:15       ` Gleb Natapov
2009-06-30 17:15     ` Eric W. Biederman

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=20090630075457.GH20289@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sheng@linux.intel.com \
    --cc=suresh.b.siddha@intel.com \
    --cc=yhlu.kernel@gmail.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