public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Yang, Sheng" <sheng.yang@intel.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: "kvm-devel" <kvm@vger.kernel.org>, Avi Kivity <avi@qumranet.com>
Subject: Re: [PATCH 5/9] kvm-x86: Enable NMI Watchdog via in-kernel PIT source
Date: Tue, 23 Sep 2008 14:10:32 +0800	[thread overview]
Message-ID: <200809231410.33041.sheng.yang@intel.com> (raw)
In-Reply-To: <48D394F6.6050606@siemens.com>

On Friday 19 September 2008 20:03:02 Jan Kiszka wrote:
> LINT0 of the LAPIC can be used to route PIT events as NMI watchdog
> ticks into the guest. This patch aligns the in-kernel irqchip emulation
> with the user space irqchip with already supports this feature. The
> trick is to route PIT interrupts to all LAPIC's LVT0 lines.
>
> Rebased patch and slightly polished patch originally posted by Sheng
> Yang.

Signed-off-by: Sheng Yang <sheng.yang@intel.com>

Thanks for pick up this patch again! 

Have you test some Windows guest with this watchdog? Last time I dropped it 
because it cause BSOD on some version of Windows(IRQ_NOT_EQUAL_OR_LESS). I 
don't remember the exactly situation there, but you may have a try. 

-- 
regards
Yang, Sheng
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  arch/x86/kvm/i8254.c |   15 +++++++++++++++
>  arch/x86/kvm/irq.h   |    1 +
>  arch/x86/kvm/lapic.c |   32 ++++++++++++++++++++++++++++----
>  3 files changed, 44 insertions(+), 4 deletions(-)
>
> Index: b/arch/x86/kvm/i8254.c
> ===================================================================
> --- a/arch/x86/kvm/i8254.c
> +++ b/arch/x86/kvm/i8254.c
> @@ -594,10 +594,25 @@ void kvm_free_pit(struct kvm *kvm)
>
>  static void __inject_pit_timer_intr(struct kvm *kvm)
>  {
> +       struct kvm_vcpu *vcpu;
> +       int i;
> +
>         mutex_lock(&kvm->lock);
>         kvm_set_irq(kvm, 0, 1);
>         kvm_set_irq(kvm, 0, 0);
>         mutex_unlock(&kvm->lock);
> +
> +       /*
> +        * Provideds NMI watchdog support in IOAPIC mode.
> +        * The route is: PIT -> PIC -> LVT0 in NMI mode,
> +        * timer IRQs will continue to flow through the IOAPIC.
> +        */
> +       for (i = 0; i < KVM_MAX_VCPUS; ++i) {
> +               vcpu = kvm->vcpus[i];
> +               if (!vcpu)
> +                       continue;
> +               kvm_apic_local_deliver(vcpu, APIC_LVT0);
> +       }
>  }
>
>  void kvm_inject_pit_timer_irqs(struct kvm_vcpu *vcpu)
> Index: b/arch/x86/kvm/irq.h
> ===================================================================
> --- a/arch/x86/kvm/irq.h
> +++ b/arch/x86/kvm/irq.h
> @@ -93,6 +93,7 @@ void kvm_unregister_irq_ack_notifier(str
>  void kvm_timer_intr_post(struct kvm_vcpu *vcpu, int vec);
>  void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu);
>  void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu);
> +int kvm_apic_local_deliver(struct kvm_vcpu *vcpu, int lvt_type);
>  void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu);
>  void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu);
>  void __kvm_migrate_timers(struct kvm_vcpu *vcpu);
> Index: b/arch/x86/kvm/lapic.c
> ===================================================================
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -382,6 +382,14 @@ static int __apic_accept_irq(struct kvm_
>                 }
>                 break;
>
> +       case APIC_DM_EXTINT:
> +               /*
> +                * Should only be called by kvm_apic_local_deliver() with
> LVT0, +                * before NMI watchdog was enabled. Already handled
> by +                * kvm_apic_accept_pic_intr().
> +                */
> +               break;
> +
>         default:
>                 printk(KERN_ERR "TODO: unsupported delivery mode %x\n",
>                        delivery_mode);
> @@ -749,6 +757,9 @@ static void apic_mmio_write(struct kvm_i
>         case APIC_LVTTHMR:
>         case APIC_LVTPC:
>         case APIC_LVT0:
> +               if (val == APIC_DM_NMI)
> +                       apic_debug("Receive NMI setting on APIC_LVT0 "
> +                               "for cpu %d\n", apic->vcpu->vcpu_id);
>         case APIC_LVT1:
>         case APIC_LVTERR:
>                 /* TODO: Check vector */
> @@ -965,12 +976,25 @@ int apic_has_pending_timer(struct kvm_vc
>         return 0;
>  }
>
> -static int __inject_apic_timer_irq(struct kvm_lapic *apic)
> +int kvm_apic_local_deliver(struct kvm_vcpu *vcpu, int lvt_type)
>  {
> -       int vector;
> +       struct kvm_lapic *apic = vcpu->arch.apic;
> +       int vector, mode, trig_mode;
> +       u32 reg;
> +
> +       if (apic && apic_enabled(apic)) {
> +               reg = apic_get_reg(apic, lvt_type);
> +               vector = reg & APIC_VECTOR_MASK;
> +               mode = reg & APIC_MODE_MASK;
> +               trig_mode = reg & APIC_LVT_LEVEL_TRIGGER;
> +               return __apic_accept_irq(apic, mode, vector, 1, trig_mode);
> +       }
> +       return 0;
> +}
>
> -       vector = apic_lvt_vector(apic, APIC_LVTT);
> -       return __apic_accept_irq(apic, APIC_DM_FIXED, vector, 1, 0);
> +static inline int __inject_apic_timer_irq(struct kvm_lapic *apic)
> +{
> +       return kvm_apic_local_deliver(apic->vcpu, APIC_LVTT);
>  }
>
>  static enum hrtimer_restart apic_timer_fn(struct hrtimer *data)



  parent reply	other threads:[~2008-09-23  6:10 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-19 12:06 [PATCH 0/9] Enhance NMI support of KVM - v2 Jan Kiszka
2008-09-19 11:59 ` [PATCH 1/9] VMX: include all IRQ window exits in statistics Jan Kiszka
2008-09-19 12:01 ` [PATCH 2/9] VMX: refactor/fix IRQ and NMI injectability determination Jan Kiszka
2008-09-19 12:01 ` [PATCH 3/9] VMX: refactor IRQ and NMI window enabling Jan Kiszka
2008-09-19 12:02 ` [PATCH 4/9] VMX: fix real-mode NMI support Jan Kiszka
2008-09-19 12:03 ` [PATCH 5/9] kvm-x86: Enable NMI Watchdog via in-kernel PIT source Jan Kiszka
2008-09-19 16:55   ` Jan Kiszka
2008-09-23  6:10   ` Yang, Sheng [this message]
2008-09-23 15:04     ` Jan Kiszka
2008-09-24 10:18       ` Yang, Sheng
2008-09-19 12:03 ` [PATCH 6/9] kvm-x86: Support for user space injected NMIs Jan Kiszka
2008-09-19 12:03 ` [PATCH 7/9] VMX: Provide support " Jan Kiszka
2008-09-19 12:04 ` [PATCH 8/9] VMX: work around lacking VNMI support Jan Kiszka
2008-09-21 14:31   ` Gleb Natapov
2008-09-21 16:57     ` Jan Kiszka
2008-09-21 18:08       ` Jan Kiszka
2008-09-22  6:41       ` Gleb Natapov
2008-09-22  7:19         ` Jan Kiszka
2008-09-22  7:39           ` Gleb Natapov
2008-09-22  7:48             ` Jan Kiszka
2008-09-19 12:05 ` [PATCH 9/9] kvm: Enable NMI support for userspace irqchip Jan Kiszka
2008-09-19 12:10 ` [PATCH 0/9] Enhance NMI support of KVM - v2 Jan Kiszka

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=200809231410.33041.sheng.yang@intel.com \
    --to=sheng.yang@intel.com \
    --cc=avi@qumranet.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.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