Skip to contentSkip to conversation

x86, hvm: Allow delivery of timer interrupts to VCPUs != 0.

PATCH In review Kouya Shimura 2 participants 8 messages Jul 3, 2009 – Jul 7, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, hvm: Allow delivery of timer interrupts to VCPUs != 0.

This patch is needed for kexec/kdump since kdump may halt VCPU#0.

xen/arch/x86/hvm/i8254.c +1 -1
diff -r 80839a223746 xen/arch/x86/hvm/i8254.c
@@ -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 ? : pt_i8259_target(vpit_domain(pit)))
 
 #define RW_STATE_LSB 1
 #define RW_STATE_MSB 2
xen/arch/x86/hvm/rtc.c +1 -1
diff -r 80839a223746 xen/arch/x86/hvm/rtc.c
@@ -32,7 +32,7 @@
 #define vcpu_vrtc(vcpu)  (domain_vrtc((vcpu)->domain))
 #define vrtc_domain(rtc) (container_of((rtc), struct domain, \
                                        arch.hvm_domain.pl_time.vrtc))
-#define vrtc_vcpu(rtc)   (vrtc_domain(rtc)->vcpu[0])
+#define vrtc_vcpu(rtc)   (rtc->pt.vcpu ? : pt_i8259_target(vrtc_domain(rtc)))
 
 static void rtc_periodic_cb(struct vcpu *v, void *opaque)
 {
xen/arch/x86/hvm/vlapic.c +3 -0
diff -r 80839a223746 xen/arch/x86/hvm/vlapic.c
@@ -809,7 +809,10 @@ void vlapic_adjust_i8259_target(struct d
 
     for_each_vcpu ( d, v )
         if ( __vlapic_accept_pic_intr(v) )
+        {
+            pt_adjust_i8259_target(v);
             goto found;
+        }
 
     v = d->vcpu ? d->vcpu[0] : NULL;
 
xen/arch/x86/hvm/vpt.c +54 -2

71 lines not on this page · raw message

xen/include/asm-x86/hvm/vpt.h +5 -1
diff -r 80839a223746 xen/include/asm-x86/hvm/vpt.h
@@ -142,6 +142,10 @@ void pt_intr_post(struct vcpu *v, struct
 void pt_intr_post(struct vcpu *v, struct hvm_intack intack);
 void pt_reset(struct vcpu *v);
 void pt_migrate(struct vcpu *v);
+void pt_adjust_i8259_target(struct vcpu *v);
+
+#define pt_i8259_target(d) \
+    ((d)->arch.hvm_domain.i8259_target ? : (d)->vcpu[0])
 
 /* Is given periodic timer active? */
 #define pt_active(pt) ((pt)->on_list)
@@ -158,7 +162,7 @@ void create_periodic_time(
 void create_periodic_time(
     struct vcpu *v, struct periodic_time *pt, uint64_t delta,
     uint64_t period, uint8_t irq, time_cb *cb, void *data);
-void destroy_periodic_time(struct periodic_time *pt);
+int destroy_periodic_time(struct periodic_time *pt);
 
 int pv_pit_handler(int port, int data, int write);
 void pit_reset(struct domain *d);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

This doesn't look too bad, given the current vpt interface we have. My main comment is regarding vpit_vcpu(), vrtc_vcpu() and vhpet.vcpu. Seems all of these could unconditionally use i8259_target. I suggest also introducing vhpet_vcpu(), and then pointing all three *_vcpu() macros at pt_i8259_target() only. And get rid of the vhpet.vcpu field.

Would that work okay?

-- Keir

Quoted 4 lines · Kouya Shimura

This patch is needed for kexec/kdump since kdump may halt VCPU#0.

#2 lore raw
Quoted 7 lines · Keir Fraser

This doesn't look too bad, given the current vpt interface we have. My main comment is regarding vpit_vcpu(), vrtc_vcpu() and vhpet.vcpu. Seems all of these could unconditionally use i8259_target. I suggest also introducing vhpet_vcpu(), and then pointing all three *_vcpu() macros at pt_i8259_target() only. And get rid of the vhpet.vcpu field.

Would that work okay?

Probably no problem, but may I modify vlapic.c as follows?

xen/arch/x86/hvm/vlapic.c +4 -6
diff -r 80839a223746 xen/arch/x86/hvm/vlapic.c
@@ -809,12 +809,11 @@ void vlapic_adjust_i8259_target(struct d
     for_each_vcpu ( d, v )
         if ( __vlapic_accept_pic_intr(v) )
-            goto found;
-
-    v = d->vcpu ? d->vcpu[0] : NULL;
-
- found:
-    d->arch.hvm_domain.i8259_target = v;
+        {
+            d->arch.hvm_domain.i8259_target = v;
+            return;
+        }
 }
 

The reasons are:
- I'm afraid that d->arch.hvm_domain.i8259_target == NULL
- if vcpu[0] is halted and all vlapic.LVT0 are masked, timer doesn't work even when vlapic will be unmasked not as ExtINT mode.

So, I think that the last __vlapic_accept_pic_intr'ed vcpu should be reserved in d->arch.hvm_domain.i8259_target.

Thanks,
Kouya

#3 lore raw
Quoted 1 line · Kouya Shimura

- I'm afraid that d->arch.hvm_domain.i8259_target == NULL

If VCPUj is != NULL then VCPUi is also != NULL for all i < j. So this is not a concern: there's always a VCPU0 if there are any VCPUs at all.

Quoted 3 lines

- if vcpu[0] is halted and all vlapic.LVT0 are masked, timer doesn't work even when vlapic will be unmasked not as ExtINT mode.

Not sure what you mean? If legacy IRQs are routed through the IOAPIC then it does not matter whether LAPIC.LVT0 is masked. And __vlapic_accept_pic_intr() correctly handles that. If virtual wire mode is not through the IOAPIC then of course LVT0 mask does matter, but I think we have that case correct too.

Quoted 2 lines

So, I think that the last __vlapic_accept_pic_intr'ed vcpu should be reserved in d->arch.hvm_domain.i8259_target.

I don't think the logic needs to change.

-- Keir

#4 lore raw

Hi Keir,

You are correct. I misunderstood the issue.
With your suggestion (always use i8259_target), i8259_target in kdump transits as: NULL=>vcpu1=>vcpu0=>vcpu1.
In this case, timer interrupts were missed in my previous patch, but that was my fault. (I felt weird that i8259_target points vcpu0 in spite of the halt)

I'll post two patches per your suggestion. one is cleanup of hpet.c and the other is for delivery of timer interrupts.

Thanks,
Kouya

Quoted 23 lines · Keir Fraser
Quoted 1 line · Kouya Shimura

- I'm afraid that d->arch.hvm_domain.i8259_target == NULL

If VCPUj is != NULL then VCPUi is also != NULL for all i < j. So this is not a concern: there's always a VCPU0 if there are any VCPUs at all.

Quoted 3 lines

- if vcpu[0] is halted and all vlapic.LVT0 are masked, timer doesn't work even when vlapic will be unmasked not as ExtINT mode.

Not sure what you mean? If legacy IRQs are routed through the IOAPIC then it does not matter whether LAPIC.LVT0 is masked. And __vlapic_accept_pic_intr() correctly handles that. If virtual wire mode is not through the IOAPIC then of course LVT0 mask does matter, but I think we have that case correct too.

Quoted 2 lines

So, I think that the last __vlapic_accept_pic_intr'ed vcpu should be reserved in d->arch.hvm_domain.i8259_target.

I don't think the logic needs to change.

-- Keir

#5 lore raw

PATCH 1/2 x86, hvm: cleanup hpet.c as well as i8254.c or rtc.c

# HG changeset patch
# User Kouya Shimura <[email protected]> # Date 1246859649 -32400
# Node ID 73e220236f6e50ac8de2470e88e91b75e3c2d01f # Parent c23d71600634232c08da32086a17679634c13d4b x86,hvm: cleanup hpet.c as well as i8254.c or rtc.c

- introduce macros: domain_vhpet, vcpu_vhpet, vhpet_domain, vhpet_vcpu
- remove *vcpu field from struct HPETState
- modify guest_time_hpet() takes *vhpet instead of *vcpu as 1st argument

xen/arch/x86/hvm/hpet.c +21 -15
diff -r c23d71600634 -r 73e220236f6e xen/arch/x86/hvm/hpet.c
@@ -24,6 +24,12 @@
 #include <xen/sched.h>
 #include <xen/event.h>
 
+#define domain_vhpet(d)    (&(d)->arch.hvm_domain.pl_time.vhpet)
+#define vcpu_vhpet(vcpu)   (domain_vhpet((vcpu)->domain))
+#define vhpet_domain(hpet) (container_of((hpet), struct domain, \
+                                         arch.hvm_domain.pl_time.vhpet))
+#define vhpet_vcpu(hpet)   (vhpet_domain(hpet)->vcpu[0])
+
 #define HPET_BASE_ADDRESS   0xfed00000ULL
 #define HPET_MMAP_SIZE      1024
 #define S_TO_NS  1000000000ULL           /* 1s  = 10^9  ns */
@@ -31,7 +37,8 @@
 
 /* Frequency_of_Xen_systeme_time / frequency_of_HPET = 16 */
 #define STIME_PER_HPET_TICK 16
-#define guest_time_hpet(v) (hvm_get_guest_time(v) / STIME_PER_HPET_TICK)
+#define guest_time_hpet(hpet) \
+    (hvm_get_guest_time(vhpet_vcpu(hpet)) / STIME_PER_HPET_TICK)
 
 #define HPET_ID         0x000
 #define HPET_PERIOD     0x004
@@ -94,7 +101,7 @@ static inline uint64_t hpet_read_maincou
     ASSERT(spin_is_locked(&h->lock));
 
     if ( hpet_enabled(h) )
-        return guest_time_hpet(h->vcpu) + h->mc_offset;
+        return guest_time_hpet(h) + h->mc_offset;
     else 
         return h->hpet.mc64;
 }
@@ -176,7 +183,7 @@ static int hpet_read(
     struct vcpu *v, unsigned long addr, unsigned long length,
     unsigned long *pval)
 {
-    HPETState *h = &v->domain->arch.hvm_domain.pl_time.vhpet;
+    HPETState *h = vcpu_vhpet(v);
     unsigned long result;
     uint64_t val;
 
@@ -230,7 +237,7 @@ static void hpet_set_timer(HPETState *h,
     {
         /* HPET specification requires PIT shouldn't generate
          * interrupts if LegacyReplacementRoute is set for timer0 */
-        PITState *pit = &h->vcpu->domain->arch.hvm_domain.pl_time.vpit;
+        PITState *pit = &vhpet_domain(h)->arch.hvm_domain.pl_time.vpit;
         pit_stop_channel0_irq(pit);
     }
 
@@ -272,7 +279,7 @@ static void hpet_set_timer(HPETState *h,
      * being enabled (now).
      */
     oneshot = !timer_is_periodic(h, tn);
-    create_periodic_time(h->vcpu, &h->pt[tn],
+    create_periodic_time(vhpet_vcpu(h), &h->pt[tn],
                          hpet_tick_to_ns(h, diff),
                          oneshot ? 0 : hpet_tick_to_ns(h, h->hpet.period[tn]),
                          irq, NULL, NULL);
@@ -290,7 +297,7 @@ static int hpet_write(
     struct vcpu *v, unsigned long addr,
     unsigned long length, unsigned long val)
 {
-    HPETState *h = &v->domain->arch.hvm_domain.pl_time.vhpet;
+    HPETState *h = vcpu_vhpet(v);
     uint64_t old_val, new_val;
     int tn, i;
 
@@ -323,7 +330,7 @@ static int hpet_write(
         if ( !(old_val & HPET_CFG_ENABLE) && (new_val & HPET_CFG_ENABLE) )
         {
             /* Enable main counter and interrupt generation. */
-            h->mc_offset = h->hpet.mc64 - guest_time_hpet(h->vcpu);
+            h->mc_offset = h->hpet.mc64 - guest_time_hpet(h);
             for ( i = 0; i < HPET_TIMER_NUM; i++ )
             {
                 h->hpet.comparator64[i] =
@@ -337,7 +344,7 @@ static int hpet_write(
         else if ( (old_val & HPET_CFG_ENABLE) && !(new_val & HPET_CFG_ENABLE) )
         {
             /* Halt main counter and disable interrupt generation. */
-            h->hpet.mc64 = h->mc_offset + guest_time_hpet(h->vcpu);
+            h->hpet.mc64 = h->mc_offset + guest_time_hpet(h);
             for ( i = 0; i < HPET_TIMER_NUM; i++ )
                 if ( timer_enabled(h, i) )
                     set_stop_timer(i);
@@ -487,13 +494,13 @@ struct hvm_mmio_handler hpet_mmio_handle
 
 static int hpet_save(struct domain *d, hvm_domain_context_t *h)
 {
-    HPETState *hp = &d->arch.hvm_domain.pl_time.vhpet;
+    HPETState *hp = domain_vhpet(d);
     int rc;
 
     spin_lock(&hp->lock);
 
     /* Write the proper value into the main counter */
-    hp->hpet.mc64 = hp->mc_offset + guest_time_hpet(hp->vcpu);
+    hp->hpet.mc64 = hp->mc_offset + guest_time_hpet(hp);
 
     /* Save the HPET registers */
     rc = _hvm_init_entry(h, HVM_SAVE_CODE(HPET), 0, HVM_SAVE_LENGTH(HPET));
@@ -531,7 +538,7 @@ static int hpet_save(struct domain *d, h
 
 static int hpet_load(struct domain *d, hvm_domain_context_t *h)
 {
-    HPETState *hp = &d->arch.hvm_domain.pl_time.vhpet;
+    HPETState *hp = domain_vhpet(d);
     struct hvm_hw_hpet *rec;
     uint64_t cmp;
     int i;
@@ -572,7 +579,7 @@ static int hpet_load(struct domain *d, h
 #undef C
     
     /* Recalculate the offset between the main counter and guest time */
-    hp->mc_offset = hp->hpet.mc64 - guest_time_hpet(hp->vcpu);
+    hp->mc_offset = hp->hpet.mc64 - guest_time_hpet(hp);
 
     /* restart all timers */
 
@@ -590,14 +597,13 @@ HVM_REGISTER_SAVE_RESTORE(HPET, hpet_sav
 
 void hpet_init(struct vcpu *v)
 {
-    HPETState *h = &v->domain->arch.hvm_domain.pl_time.vhpet;
+    HPETState *h = vcpu_vhpet(v);
     int i;
 
     memset(h, 0, sizeof(HPETState));
 
     spin_lock_init(&h->lock);
 
-    h->vcpu = v;
     h->stime_freq = S_TO_NS;
 
     h->hpet_to_ns_scale = ((S_TO_NS * STIME_PER_HPET_TICK) << 10) / h->stime_freq;
@@ -622,7 +628,7 @@ void hpet_deinit(struct domain *d)
 void hpet_deinit(struct domain *d)
 {
     int i;
-    HPETState *h = &d->arch.hvm_domain.pl_time.vhpet;
+    HPETState *h = domain_vhpet(d);
 
     spin_lock(&h->lock);
 
xen/include/asm-x86/hvm/vpt.h +0 -1
diff -r c23d71600634 -r 73e220236f6e xen/include/asm-x86/hvm/vpt.h
@@ -92,7 +92,6 @@ struct hpet_registers {
 
 typedef struct HPETState {
     struct hpet_registers hpet;
-    struct vcpu *vcpu;
     uint64_t stime_freq;
     uint64_t hpet_to_ns_scale; /* hpet ticks to ns (multiplied by 2^10) */
     uint64_t hpet_to_ns_limit; /* max hpet ticks convertable to ns      */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#6 lore raw

PATCH 2/2 x86, hvm: Allow delivery of timer interrupts to VCPUs != 0

# HG changeset patch
# User Kouya Shimura <[email protected]>
# Date 1246862381 -32400
# Node ID a0d51bbdca910b3ea25cdb8e6f533a01af332a8e # Parent 73e220236f6e50ac8de2470e88e91b75e3c2d01f x86,hvm: Allow delivery of timer interrupts to VCPUs != 0

This patch is needed for kexec/kdump since VCPU#0 is halted.

xen/arch/x86/hvm/hpet.c +1 -1
diff -r 73e220236f6e -r a0d51bbdca91 xen/arch/x86/hvm/hpet.c
@@ -28,7 +28,7 @@
 #define vcpu_vhpet(vcpu)   (domain_vhpet((vcpu)->domain))
 #define vhpet_domain(hpet) (container_of((hpet), struct domain, \
                                          arch.hvm_domain.pl_time.vhpet))
-#define vhpet_vcpu(hpet)   (vhpet_domain(hpet)->vcpu[0])
+#define vhpet_vcpu(hpet)   (pt_i8259_target(vhpet_domain(hpet)))
 
 #define HPET_BASE_ADDRESS   0xfed00000ULL
 #define HPET_MMAP_SIZE      1024
xen/arch/x86/hvm/i8254.c +1 -1
diff -r 73e220236f6e -r a0d51bbdca91 xen/arch/x86/hvm/i8254.c
@@ -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)   (pt_i8259_target(vpit_domain(pit)))
 
 #define RW_STATE_LSB 1
 #define RW_STATE_MSB 2
xen/arch/x86/hvm/rtc.c +1 -1
diff -r 73e220236f6e -r a0d51bbdca91 xen/arch/x86/hvm/rtc.c
@@ -32,7 +32,7 @@
 #define vcpu_vrtc(vcpu)  (domain_vrtc((vcpu)->domain))
 #define vrtc_domain(rtc) (container_of((rtc), struct domain, \
                                        arch.hvm_domain.pl_time.vrtc))
-#define vrtc_vcpu(rtc)   (vrtc_domain(rtc)->vcpu[0])
+#define vrtc_vcpu(rtc)   (pt_i8259_target(vrtc_domain(rtc)))
 
 static void rtc_periodic_cb(struct vcpu *v, void *opaque)
 {
xen/arch/x86/hvm/vlapic.c +5 -1
diff -r 73e220236f6e -r a0d51bbdca91 xen/arch/x86/hvm/vlapic.c
@@ -814,7 +814,11 @@ void vlapic_adjust_i8259_target(struct d
     v = d->vcpu ? d->vcpu[0] : NULL;
 
  found:
-    d->arch.hvm_domain.i8259_target = v;
+    if ( d->arch.hvm_domain.i8259_target != v )
+    {
+        d->arch.hvm_domain.i8259_target = v;
+        pt_adjust_i8259_target(v);
+    }
 }
 
 int vlapic_has_pending_irq(struct vcpu *v)
xen/arch/x86/hvm/vpt.c +50 -0

53 lines not on this page · raw message

xen/include/asm-x86/hvm/vpt.h +4 -0
diff -r 73e220236f6e -r a0d51bbdca91 xen/include/asm-x86/hvm/vpt.h
@@ -141,6 +141,10 @@ void pt_intr_post(struct vcpu *v, struct
 void pt_intr_post(struct vcpu *v, struct hvm_intack intack);
 void pt_reset(struct vcpu *v);
 void pt_migrate(struct vcpu *v);
+void pt_adjust_i8259_target(struct vcpu *v);
+
+#define pt_i8259_target(d) \
+    ((d)->arch.hvm_domain.i8259_target ? : (d)->vcpu[0])
 
 /* Is given periodic timer active? */
 #define pt_active(pt) ((pt)->on_list)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Applied
#7 lore raw

Re: [PATCH 2/2] x86, hvm: Allow delivery of timer interrupts to VCPUs != 0

I applied your patches, thanks. Feel free to submit something similar for passthrough IRQ handling.

-- Keir