support kexec/kdump on hvm
cover support kexec/kdump on hvm
Hi,
kexec/kdump on hvm sometimes hangs up. After some investigation, I found the cause is that kdump halts the vcpu0(bsp). Current xen hypervisor seems to assume that the bsp never be halted and delivery of some IRQs relies on running bsp.
This series of patches fix it at least kexec/kdump works.
Thanks,
Kouya
PATCH 1/2 x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
This patch is needed for kexec/kdump on hvm since kdump halts bsp.
- allow another vcpu than bsp to receive PIT IRQ
- deliver PIT IRQ to the vcpu whose LINT0 is ExtINT mode
xen/arch/x86/hvm/i8254.c +46 -8
@@ -42,7 +42,7 @@#define vcpu_vpit (vcpu) (domain_vpit((vcpu)->domain))#define vpit_domain (pit) (container_of((pit), struct domain, \ arch.hvm_domain.pl_time.vpit)) -#define vpit_vcpu (pit) (vpit_domain(pit)->vcpu[0]) +#define vpit_vcpu (pit) (pit->pt0.vcpu)#define RW_STATE_LSB 1#define RW_STATE_MSB 2
@@ -174,14 +174,11 @@ static void pit_load_count(PITState *pitif ( val ==0 ) val =0x10000 ; -if ( v ==NULL ) - pit->count_load_time[channel] =0 ; -else - pit->count_load_time[channel] =get_guest_time (v); + pit->count_load_time[channel] =get_guest_time (v); s->count = val; period =DIV_ROUND (val *SYSTEM_TIME_HZ ,PIT_FREQ ); -if ( (v ==NULL ) || !is_hvm_vcpu (v) || (channel !=0 ) ) +if ( !is_hvm_vcpu (v) || (channel !=0 ) )return ; switch ( s->mode )
@@ -397,6 +394,15 @@ static int pit_save(struct domain *d, hvreturn rc; } +static struct vcpu *find_pic_intr_accept_vcpu (struct domain *d) +{ +struct vcpu *v; +for_each_vcpu (d, v) +if (vlapic_accept_pic_intr (v) ) +return v; +return d->vcpu[0 ]; +} +static int pit_load (struct domain *d,hvm_domain_context_t *h) {PITState *pit =domain_vpit (d);
@@ -415,7 +421,8 @@ static int pit_load(struct domain *d, hv* time jitter here, but the wall-clock will have jumped massively, so * we hope the guest can handle it. */ - pit->pt0.last_plt_gtime =get_guest_time (d->vcpu[0 ]); + pit->pt0.vcpu =find_pic_intr_accept_vcpu (d); + pit->pt0.last_plt_gtime =get_guest_time (pit->pt0.vcpu);for ( i =0 ; i <3 ; i++ )pit_load_count (pit, i, pit->hw.channels[i].count);
@@ -432,7 +439,9 @@ void pit_reset(struct domain *d)struct hvm_hw_pit_channel *s;int i; -destroy_periodic_time (&pit->pt0); +if (is_hvm_domain (d) ) +destroy_periodic_time (&pit->pt0); + pit->pt0.source = PTSRC_isa;spin_lock (&pit->lock);
@@ -452,14 +461,43 @@ void pit_init(struct vcpu *v, unsigned l {PITState *pit =vcpu_vpit (v); +ASSERT (v->vcpu_id ==0 ); +spin_lock_init (&pit->lock);register_portio_handler (v->domain,PIT_BASE ,4 , handle_pit_io);register_portio_handler (v->domain,0x61 ,1 , handle_speaker_io); + pit->pt0.vcpu = v;/* VCPU0 */ +pit_reset (v->domain); } +void pit_bind_vcpu (struct vcpu *v) +{ +PITState *pit =vcpu_vpit (v); +struct periodic_time *pt = &pit->pt0; + +ASSERT (is_hvm_vcpu (v)); + +spin_lock (&pit->lock); +if ( pt->vcpu != v ) + { +/* +* Recreate the platform timer only if it was previously created +* as a periodic timer. +* For one-shot timer, the timer works along with the previous +* vcpu but kicks the new vcpu. +*/ + pt->vcpu = v; +if ( pt->cb !=NULL && !pt->one_shot ) +/* XXX: delta should be recalculated ? */ +create_periodic_time (v, pt, pt->period_cycles, pt->period_cycles, + pt->irq, pt->cb, pt->priv); + } +spin_unlock (&pit->lock); +} +void pit_deinit (struct domain *d) {PITState *pit =domain_vpit (d);
xen/arch/x86/hvm/irq.c +0 -1
@@ -348,7 +348,6 @@ struct hvm_intack hvm_vcpu_ack_pending_i intack = hvm_intack_none;break ;case hvm_intsrc_pic: -ASSERT (v->vcpu_id ==0 );if ( (vector =vpic_ack_pending_irq (v)) ==-1 ) intack = hvm_intack_none;else
xen/arch/x86/hvm/vlapic.c +7 -5
@@ -697,6 +697,9 @@ static int vlapic_write(struct vcpu *v, val |=APIC_LVT_MASKED ; val &= vlapic_lvt_mask[(offset -APIC_LVTT ) >>4 ];vlapic_set_reg (vlapic, offset, val); +if ( offset ==APIC_LVT0 && + (val & (APIC_MODE_MASK |APIC_LVT_MASKED )) ==APIC_DM_EXTINT ) +pit_bind_vcpu (vlapic_vcpu (vlapic));break ;case APIC_TMICT :
@@ -782,12 +785,11 @@ int vlapic_accept_pic_intr(struct vcpu *uint32_t lvt0 =vlapic_get_reg (vlapic,APIC_LVT0 );/* -* Only CPU0 is wired to the 8259A. INTA cycles occur if LINT0 is set up -* accept ExtInts, or if the LAPIC is disabled (so LINT0 behaves as INTR). +* INTA cycles occur if LINT0 is set up accept ExtInts, +* or if the LAPIC is disabled (so LINT0 behaves as INTR). */ -return ((v->vcpu_id ==0 ) && - (((lvt0 & (APIC_MODE_MASK |APIC_LVT_MASKED )) ==APIC_DM_EXTINT ) || -vlapic_hw_disabled (vlapic))); +return (((lvt0 & (APIC_MODE_MASK |APIC_LVT_MASKED )) ==APIC_DM_EXTINT ) || +vlapic_hw_disabled (vlapic)); }int vlapic_has_pending_irq (struct vcpu *v)
xen/include/asm-x86/hvm/vpt.h +1 -1
@@ -162,7 +162,7 @@ void destroy_periodic_time(struct periodint pv_pit_handler (int port,int data,int write);void pit_reset (struct domain *d); - +void pit_bind_vcpu (struct vcpu *v);void pit_init (struct vcpu *v,unsigned long cpu_khz);void pit_stop_channel0_irq (PITState * pit);void pit_deinit (struct domain *d);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 1/2] x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
Quoted 1 line · Kouya Shimura
This patch is needed for kexec/kdump on hvm since kdump halts bsp.
Really? Why would it do that?
These patches are pretty nasty. We can perhaps come up with a neater smaller version of them if there's a real need.
-- Keir
Re: [PATCH 1/2] x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
Quoted 5 lines · Keir Fraser
Quoted 1 line · Kouya Shimura
This patch is needed for kexec/kdump on hvm since kdump halts bsp.
Really? Why would it do that?
Not always. kdump leaves one cpu which has received a crash signal and halts all other cpus. I don't know why.
Quoted 2 lines
These patches are pretty nasty. We can perhaps come up with a neater smaller version of them if there's a real need.
Hmm, though I tried to make them small...
Could you refine them?
Thanks,
Kouya
Re: [PATCH 1/2] x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
Quoted 4 lines · Kouya Shimura
Quoted 1 line
Really? Why would it do that?
Not always. kdump leaves one cpu which has received a crash signal and halts all other cpus. I don't know why.
That seems very brave of it, if it also expects interrupts to still work! Does it really require *all* interrupts still to be functional?
Quoted 5 lines
Quoted 2 lines
These patches are pretty nasty. We can perhaps come up with a neater smaller version of them if there's a real need.
Hmm, though I tried to make them small...
Could you refine them?
Well, looking at patch 1/2 to start with, some of the issues you address are not particular to the PIT, but to any interrupt delivered via vpt.c. I suspect what you really need is a hook into vpt.c when a vcpu goes down, to move all its vpt's (except its own LAPIC one) onto another vcpu's list. And on create_periodic_time() ignore the suggested vcpu given by the caller if that vcpu is down. And disable the IRQ0_SPECIAL_ROUTING in vioapic.c if vcpu0 is down.
Patch 2/2 I suppose something like that might be acceptable. Still it'd be nice to not have every VCPU piling into hvm_dirq_assist(). Perhaps that and vpt.c could agree on who their current 'fallback vcpu' is, and have that inherit orphaned vpts and do all dirq assistance.
It's still a bit fragile and a bit of a pain in the butt though. Is kdump in HVM guests super important?
-- Keir
Re: [PATCH 1/2] x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
Hi Keir,
Thanks for your review and comments.
Quoted 7 lines · Keir Fraser
Well, looking at patch 1/2 to start with, some of the issues you address are not particular to the PIT, but to any interrupt delivered via
vpt.c. I suspect what you really need is a hook intovpt.cwhen a vcpu goes down, to move all its vpt's (except its own LAPIC one) onto another vcpu's list. And oncreate_periodic_time()ignore the suggested vcpu given by the caller if that vcpu is down. And disable theIRQ0_SPECIAL_ROUTINGinvioapic.cif vcpu0 is down.
This doesn't work since the ioapic is completely disabled.
I've found a interesting thread in LKML archives.
Subject: [PATCH] kexec: force x86_64 arches to boot kdump kernels on boot cpu
http://lkml.org/lkml/2007/11/26/346
Probably we should fix the guest bios(MP table, ioapic initialization).
I'm looking into it.
Thanks,
Kouya
Re: [PATCH 1/2] x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
Quoted 7 lines · Kouya Shimura
This doesn't work since the ioapic is completely disabled.
I've found a interesting thread in LKML archives.
Subject: [PATCH] kexec: forcex86_64arches to boot kdump kernels on boot cpu
http://lkml.org/lkml/2007/11/26/346Probably we should fix the guest
bios(MP table, ioapic initialization).
So... You want virtual wire through IO-APIC?
Still some logic changes to vpt.c will be required, since platform timers only tick and generate interrupts when vpt logic is executed on vcpu0's return-to-guest path. Same for irq passthrough (handled by your patch 2/2).
Hmmm... Okay I think this might be workable. Device passthru and vpt subsystems could be fired off of whichever vcpu owns the LAPIC identifier currently programmed into IOAPIC0:PIN0, rather than being hardwired to VCPU0.
-- Keir
Re: [PATCH 1/2] x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
Quoted 1 line · Keir Fraser
So... You want virtual wire through IO-APIC?
Yes, I'm struggling.
Quoted 3 lines
Still some logic changes to
vpt.cwill be required, since platform timers only tick and generate interrupts when vpt logic is executed on vcpu0's return-to-guest path. Same for irq passthrough (handled by your patch 2/2).
Indeed, also vioapic.c doesn't support virtual wire mode.
Quoted 4 lines
Hmmm... Okay I think this might be workable. Device passthru and vpt subsystems could be fired off of whichever vcpu owns the LAPIC identifier currently programmed into IOAPIC0:PIN0, rather than being hardwired to VCPU0.
Okay, but 2/2 patch can wait. First of all, I'll remake 1/2 patch.
Thanks,
Kouya
Re: [PATCH 1/2] x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
Quoted 6 lines · Kouya Shimura
Quoted 4 lines
Hmmm... Okay I think this might be workable. Device passthru and vpt subsystems could be fired off of whichever vcpu owns the LAPIC identifier currently programmed into IOAPIC0:PIN0, rather than being hardwired to VCPU0.
Okay, but 2/2 patch can wait. First of all, I'll remake 1/2 patch.
I'll deal with virtual wire via ioapic myself.
-- Keir
Re: Re: [PATCH 1/2] x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
Quoted 10 lines · Keir Fraser
Quoted 6 lines · Kouya Shimura
Quoted 4 lines
Hmmm... Okay I think this might be workable. Device passthru and vpt subsystems could be fired off of whichever vcpu owns the LAPIC identifier currently programmed into IOAPIC0:PIN0, rather than being hardwired to VCPU0.
Okay, but 2/2 patch can wait. First of all, I'll remake 1/2 patch.
I'll deal with virtual wire via ioapic myself.
Take a look at changeset 19877. It does the basics of what you need. Vpt.c logic probably still will need tweaking however.
-- Keir
Re: Re: [PATCH 1/2] x86, hvm: allow another vcpu to receive PIT IRQ (support kexec/kdump on hvm)
Quoted 2 lines · Keir Fraser
Take a look at changeset 19877. It does the basics of what you need.
Vpt.clogic probably still will need tweaking however.
Great! This is really what I want. Thanks a lot.
I confirmed it works with my i8254.c patch.
Just one thing. An attached patch will be necessary with debug=y build.
Thanks,
Kouya
xen/arch/x86/hvm/irq.c +0 -1
@@ -355,7 +355,6 @@ struct hvm_intack hvm_vcpu_ack_pending_i intack = hvm_intack_none;break ;case hvm_intsrc_pic: -ASSERT (v->vcpu_id ==0 );if ( (vector =vpic_ack_pending_irq (v)) ==-1 ) intack = hvm_intack_none;else
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 2/2 passthrough: deliver IRQs even if bsp is halted (support kexec/kdump on hvm)
In reply to Kouya ShimuraThis patch is needed for kexec/kdump on hvm since kdump halts bsp.
xen/drivers/passthrough/io.c +9 -2
@@ -362,6 +362,7 @@ int pt_irq_destroy_bind_vtd(int hvm_do_IRQ_dpci (struct domain *d,unsigned int mirq) {struct hvm_irq_dpci *dpci =domain_get_irq_dpci (d); +struct vcpu *v;ASSERT (spin_is_locked (&irq_desc[domain_irq_to_vector (d, mirq)].lock)); if ( !iommu_enabled || (d == dom0) || !dpci ||
@@ -378,7 +379,13 @@ int hvm_do_IRQ_dpci(struct domain *d, unif (pt_irq_need_timer (dpci->mirq[mirq].flags) )set_timer (&dpci->hvm_timer[domain_irq_to_vector (d, mirq)],NOW () +PT_IRQ_TIME_OUT ); -vcpu_kick (d->vcpu[0 ]); + +for_each_vcpu (d, v) +if ( !test_bit (_VPF_down, &v->pause_flags) ) + { +vcpu_kick (v); +break ; + }return 1 ; }
@@ -437,7 +444,7 @@ void hvm_dirq_assist(struct vcpu *v)struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;struct dev_intx_gsi_link *digl; -if ( !iommu_enabled || (v->vcpu_id !=0 ) || (hvm_irq_dpci ==NULL ) ) +if ( !iommu_enabled || (hvm_irq_dpci ==NULL ) )return ; for ( irq = find_first_bit(hvm_irq_dpci->dirq_mask, d->nr_pirqs);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
RE: [PATCH 2/2] passthrough: deliver IRQs even if bsp is halted (support kexec/kdump on hvm)
Quoted 3 lines · Kouya Shimura
This patch is needed for kexec/kdump on hvm since kdump halts bsp.
Signed-off-by Kouya Shimura <[email protected]>
It kicks every online vcpu. The result will be more unnecessary IPIs, especially the vcpu# is big. Therefore increase cost of interrupt handling of assigned devices.
Regards,
Weidong
Re: [PATCH 2/2] passthrough: deliver IRQs even if bsp is halted (support kexec/kdump on hvm)
Quoted 8 lines · Weidong
Quoted 3 lines · Kouya Shimura
This patch is needed for kexec/kdump on hvm since kdump halts bsp.
Signed-off-by Kouya Shimura <[email protected]>It kicks every online vcpu. The result will be more unnecessary IPIs, especially the vcpu# is big. Therefore increase cost of interrupt handling of assigned devices.
Actually it breaks out of the loop as soon as it kicks one. But still all vcpus will pile into hvm_dirq_assist() on every vmexit, which is quite undesirable too.
-- Keir
A message that is not in the archive (sent off-list or not yet received): 715D42877B251141A38726ABF5CABF2C054570DED3@pdsmsx503.ccr.corp.intel.com
RE: [PATCH 2/2] passthrough: deliver IRQs even if bsp is halted (support kexec/kdump on hvm)
Quoted 9 lines · Weidong
Quoted 3 lines · Kouya Shimura
This patch is needed for kexec/kdump on hvm since kdump halts bsp.
Signed-off-by Kouya Shimura <[email protected]>It kicks every online vcpu. The result will be more unnecessary IPIs, especially the vcpu# is big. Therefore increase cost of interrupt handling of assigned devices.
Sorry, I misunderstood your patch. It only kicks one online vcpu. It is no problem.
Regards,
Weidong
RE: [PATCH 2/2] passthrough: deliver IRQs even if bsp is halted (support kexec/kdump on hvm)
In reply to Kouya Shimuraxen/drivers/passthrough/io.c void hvm_dirq_assist(struct vcpu *v) · line 450
Quoted 9 lines
xen/drivers/passthrough/io.c +1
-1@@ -437,7 +444,7 @@ void hvm_dirq_assist(struct vcpu *v)struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;struct dev_intx_gsi_link *digl; -if ( !iommu_enabled || (v->vcpu_id !=0 ) || (hvm_irq_dpci ==NULL ) ) +if ( !iommu_enabled || (hvm_irq_dpci ==NULL ) )return ; for ( irq = find_first_bit(hvm_irq_dpci->dirq_mask, d->nr_pirqs);
With the patch applied, every vcpu of a domain can access the hvm_irq_dpci->dirq_mask concurrently! I think some usage of spinlock must be introduced if you'd like to do so.
Thanks,
-- Dexuan
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Kouya Shimura
Sent: 2009?6?30? 14:57
To: [email protected]
Cc: Keir Fraser
Subject: [Xen-devel] [PATCH 2/2] passthrough: deliver IRQs even if bsp is halted (support kexec/kdump on hvm)
This patch is needed for kexec/kdump on hvm since kdump halts bsp.