Skip to contentSkip to conversation

PVH: pit related hang from guest shutdown

PATCH New Mukesh Rathor 2 participants 5 messages Mar 8, 2014 – Mar 11, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PVH: pit related hang from guest shutdown

Hi,

I just upgraded by domU and ran into this pit related hang again for pvh. During shutdown, the guest does:

  [   24.617014] pcspkr pcspkr: shutdown

this results in call to handle_pio() --> .. --> handle_pvh_io() -> ..
handle_speaker_io() causing xen to hang on :

   spin_lock(&vpit->lock);

because pit_init has not be called and the spin lock didn't get initialized.

At least I see in my earlier patches I had call to pit_init, but it seems to have fallen thru the cracks in final checkins. Anyways, here's my first cut at the proposed fix. Other alternative would be to just register handle_speaker_io handler in pit_reset, since we don't seem to be emulating pit for pvh. LMK suggestions if this fix is not very congenial.

George, I think this should be a candidate for next 4.4 RC. Fix is simple and it avoids hang in xen from pvh guest shutdown.

thanks
mukesh

#1 lore raw

PATCH 1/1 pvh: add a call to pit_init to init spinlock

During halt of a pvh guest, the guest may do speaker shutdown. This results in call to handle_speaker_io in xen. It will hang on the vpit spin lock because it has not been initialized via pit_init, which is called for both pv and hvm. This patch adds a call to it for pvh.

---
 xen/arch/x86/hvm/hvm.c   | 3 +++
 xen/arch/x86/hvm/i8254.c | 3 +++
 2 files changed, 6 insertions(+)
xen/arch/x86/hvm/hvm.c +3 -0
index 9e85c13..07e44f6 100644
@@ -1299,6 +1299,9 @@ int hvm_vcpu_initialise(struct vcpu *v)
         v->arch.hvm_vcpu.hcall_64bit = 1;    /* PVH 32bitfixme. */
         /* This is for hvm_long_mode_enabled(v). */
         v->arch.hvm_vcpu.guest_efer = EFER_SCE | EFER_LMA | EFER_LME;
+
+        if ( v->vcpu_id == 0 )
+            pit_init(v, cpu_khz);
         return 0;
     }
 
xen/arch/x86/hvm/i8254.c +3 -0
index c0d6bc2..08325b5 100644
@@ -454,6 +454,9 @@ void pit_init(struct vcpu *v, unsigned long cpu_khz)
 
     spin_lock_init(&pit->lock);
 
+    if ( is_pvh_vcpu(v) )
+        return;
+
     if ( is_hvm_domain(d) )
     {
         register_portio_handler(d, PIT_BASE, 4, handle_pit_io);
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH] pvh: add a call to pit_init to init spinlock

xen/arch/x86/hvm/hvm.c int hvm_vcpu_initialise(struct vcpu *v) · line 1304

Quoted 10 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor
xen/arch/x86/hvm/hvm.c +3 -0
@@ -1299,6 +1299,9 @@ int hvm_vcpu_initialise(struct vcpu *v)
         v->arch.hvm_vcpu.hcall_64bit = 1;    /* PVH 32bitfixme. */
         /* This is for hvm_long_mode_enabled(v). */
         v->arch.hvm_vcpu.guest_efer = EFER_SCE | EFER_LMA | EFER_LME;
+
+        if ( v->vcpu_id == 0 )
+            pit_init(v, cpu_khz);

I know I'm asking a lot, but did you consider using the opportunity to do what the HVM call site says - move this to hvm_domain_initialise()? Or, considering that PV wants this too, even move it to arch_domain_create()?

xen/arch/x86/hvm/i8254.c void pit_init(struct vcpu *v, unsigned long cpu_khz) · line 462

Quoted 12 lines
xen/arch/x86/hvm/i8254.c +3 -0
@@ -454,6 +454,9 @@ void pit_init(struct vcpu *v, unsigned long cpu_khz)
 
     spin_lock_init(&pit->lock);
 
+    if ( is_pvh_vcpu(v) )
+        return;
+
     if ( is_hvm_domain(d) )
     {
         register_portio_handler(d, PIT_BASE, 4, handle_pit_io);

So I'm confused: Both HVM and PV want the function executed to its end. Why would PVH bail early? The more that I don't think pit_reset() would do any harm to PVH. And considering the I/O model, I think the ultimate goal would need to be to switch above is_hvm_domain() to has_hvm_container_domain(). If that doesn't work right now, it should probably get another "pvh fixme" attached.

Jan

#3 lore raw

Re: [PATCH] pvh: add a call to pit_init to init spinlock

Quoted 16 lines · On Mon, 10 Mar 2014 09:10:23 +0000 "Jan Beulich" <[email protected]> wrote:

xen/arch/x86/hvm/hvm.c int hvm_vcpu_initialise(struct vcpu *v) · line 1304

Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

On 08.03.14 at 03:28, Mukesh Rathor <[email protected]> wrote:

xen/arch/x86/hvm/hvm.c +0 -0
@@ -1299,6 +1299,9 @@ int hvm_vcpu_initialise(struct vcpu *v)
         v->arch.hvm_vcpu.hcall_64bit = 1;    /* PVH 32bitfixme. */
         /* This is for hvm_long_mode_enabled(v). */
         v->arch.hvm_vcpu.guest_efer = EFER_SCE | EFER_LMA |

EFER_LME; +

xen/arch/x86/hvm/hvm.c +2 -0
+        if ( v->vcpu_id == 0 )
+            pit_init(v, cpu_khz);

I know I'm asking a lot, but did you consider using the opportunity to do what the HVM call site says - move this to hvm_domain_initialise()? Or, considering that PV wants this too, even move it to arch_domain_create()?

I started that route.. but thought it might be too intrusive for 4.4. I had it moved to hvm_domain_initialise, but arch_domain_create is even better. It's hard to anticipate what any maintainer would prefer, the impression so far is to not touch anything un-needed or un-necessary...

Quoted 6 lines
Quoted 6 lines
xen/arch/x86/hvm/i8254.c +0 -0
@@ -454,6 +454,9 @@ void pit_init(struct vcpu *v, unsigned long
 cpu_khz) 
     spin_lock_init(&pit->lock);
 
Quoted 14 lines

xen/arch/x86/hvm/i8254.c void pit_init(struct vcpu *v, unsigned long cpu_khz) · line 462

Quoted 6 lines
xen/arch/x86/hvm/i8254.c +3 -0
+    if ( is_pvh_vcpu(v) )
+        return;
+
     if ( is_hvm_domain(d) )
     {
         register_portio_handler(d, PIT_BASE, 4, handle_pit_io);

So I'm confused: Both HVM and PV want the function executed to its end. Why would PVH bail early? The more that I don't think pit_reset() would do any harm to PVH. And considering the I/O model, I think the ultimate goal would need to be to switch above is_hvm_domain() to has_hvm_container_domain(). If that doesn't work right now, it should probably get another "pvh fixme" attached.

Mostly to defer it to come back and spend time to look at pv and hvm ways, and figure which would be the best way to do it. But looking at the code again, pit_reset should also work right now for pvh.

I also see pit_deinit is not called for pv. anyways, please see patch v1.

thanks
mukesh

#4 lore raw

Re: [PATCH] pvh: add a call to pit_init to init spinlock

Quoted 21 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor
Quoted 16 lines · On Mon, 10 Mar 2014 09:10:23 +0000 "Jan Beulich" <[email protected]> wrote:

xen/arch/x86/hvm/hvm.c int hvm_vcpu_initialise(struct vcpu *v) · line 1304

Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

On 08.03.14 at 03:28, Mukesh Rathor <[email protected]> wrote:

xen/arch/x86/hvm/hvm.c +0 -0
@@ -1299,6 +1299,9 @@ int hvm_vcpu_initialise(struct vcpu *v)
         v->arch.hvm_vcpu.hcall_64bit = 1;    /* PVH 32bitfixme. */
         /* This is for hvm_long_mode_enabled(v). */
         v->arch.hvm_vcpu.guest_efer = EFER_SCE | EFER_LMA |

EFER_LME; +

xen/arch/x86/hvm/hvm.c +2 -0
+        if ( v->vcpu_id == 0 )
+            pit_init(v, cpu_khz);

I know I'm asking a lot, but did you consider using the opportunity to do what the HVM call site says - move this to hvm_domain_initialise()? Or, considering that PV wants this too, even move it to arch_domain_create()?

Quoted 4 lines

I started that route.. but thought it might be too intrusive for 4.4. I had it moved to hvm_domain_initialise, but arch_domain_create is even better. It's hard to anticipate what any maintainer would prefer, the impression so far is to not touch anything un-needed or un-necessary...

Properly done cleanup, even more so in a case like this where a comment even says this should be done, is always welcome.

Jan