vhpet: add support for level triggered interrupts
v4 cover vhpet: add support for level triggered interrupts
Hello,
The following series add support for level trigger interrupts to vhpet. Level triggered interrupts are not an optional feature of the hpet spec, so they must be implemented in order to have a complete emulated hpet implementation in Xen.
The extra patch adds some basic testing of hpet (mainly the level triggered interrupts) to xtf.
The Xen series can be found at:
git://xenbits.xen.org/people/royger/xen.git vhpet.v4
Thanks, Roger.
Roger Pau Monne (2):
vpt: add support for level interrupts
vhpet: add support for level triggered interrupts
xen/arch/x86/hvm/hpet.c | 54 +++++++++++++++++++++++++++-------- xen/arch/x86/hvm/i8254.c | 4 +-- xen/arch/x86/hvm/irq.c | 15 ++++++++++ xen/arch/x86/hvm/rtc.c | 2 +- xen/arch/x86/hvm/vlapic.c | 8 +++--- xen/arch/x86/hvm/vpt.c | 48 +++++++++++++++++++++++++------ xen/include/asm-x86/hvm/irq.h | 3 +- xen/include/asm-x86/hvm/vpt.h | 3 +- 8 files changed, 107 insertions(+), 30 deletions(-)
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 1/2 vpt: add support for level interrupts
Level trigger interrupts will be asserted regardless of whether the interrupt is masked, and thus the callback will also be executed.
Add a new 'level' parameter to create_periodic_time in order to create level triggered timers. None of the current users of vpt are switched to use level triggered interrupts yet.
Note that periodic level triggered interrupts are not supported. This is because level triggered interrupts always require a deassert of the IO-APIC pin, which should be done by the caller of vpt at which point the caller should also reset the timer if required.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v3:
- Clarify why level triggered interrupts are always asserted.
- Expand commit message to explain why periodic level triggered interrupts are not supported by vpt.
- Switch the create check to use a conditional in order to avoid checking the source twice.
--- xen/arch/x86/hvm/hpet.c | 2 +- xen/arch/x86/hvm/i8254.c | 4 +-- xen/arch/x86/hvm/rtc.c | 2 +- xen/arch/x86/hvm/vlapic.c | 8 +++--- xen/arch/x86/hvm/vpt.c | 48 ++++++++++++++++++++++++++++------- xen/include/asm-x86/hvm/vpt.h | 3 ++- 6 files changed, 49 insertions(+), 18 deletions(-)
xen/arch/x86/hvm/hpet.c +1 -1
@@ -302,7 +302,7 @@ static void hpet_set_timer(HPETState *h, unsigned int 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 ); + irq,NULL ,NULL , false); } static inline uint64_t hpet_fixup_reg(
xen/arch/x86/hvm/i8254.c +2 -2
@@ -191,14 +191,14 @@ static void pit_load_count(PITState *pit, int channel, int val)/* Periodic timer. */ TRACE_2D (TRC_HVM_EMUL_PIT_START_TIMER , period, period);create_periodic_time (v, &pit->pt0, period, period,0 , pit_time_fired, - &pit->count_load_time[channel]); + &pit->count_load_time[channel], false);break ;case 1 :case 4 :/* One-shot timer. */ TRACE_2D (TRC_HVM_EMUL_PIT_START_TIMER , period,0 );create_periodic_time (v, &pit->pt0, period,0 ,0 , pit_time_fired, - &pit->count_load_time[channel]); + &pit->count_load_time[channel], false);break ;default :TRACE_0D (TRC_HVM_EMUL_PIT_STOP_TIMER );
xen/arch/x86/hvm/rtc.c +1 -1
@@ -156,7 +156,7 @@ static void rtc_timer_update(RTCState *s) {TRACE_2D (TRC_HVM_EMUL_RTC_START_TIMER , delta, period);create_periodic_time (v, &s->pt, delta, period, -RTC_IRQ , rtc_pf_callback, s); +RTC_IRQ , rtc_pf_callback, s, false); } else s->check_ticks_since = now;
xen/arch/x86/hvm/vlapic.c +4 -4
@@ -762,7 +762,7 @@ static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt,create_periodic_time (current, &vlapic->pt, delta, is_periodic ? period :0 , vlapic->pt.irq, is_periodic ? vlapic_pt_cb :NULL , - &vlapic->timer_last_update); + &vlapic->timer_last_update, false); vlapic->timer_last_update = vlapic->pt.last_plt_gtime;if ( !tmict_updated )
@@ -1166,7 +1166,7 @@ void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value) TRC_PAR_LONG(0LL), vlapic->pt.irq);create_periodic_time (v, &vlapic->pt, delta,0 , vlapic->pt.irq, vlapic_tdt_pt_cb, - &vlapic->timer_last_update); + &vlapic->timer_last_update, false); vlapic->timer_last_update = vlapic->pt.last_plt_gtime; }else
@@ -1180,7 +1180,7 @@ void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value) TRC_PAR_LONG(0LL), vlapic->pt.irq);create_periodic_time (v, &vlapic->pt,0 ,0 , vlapic->pt.irq, vlapic_tdt_pt_cb, - &vlapic->timer_last_update); + &vlapic->timer_last_update, false); vlapic->timer_last_update = vlapic->pt.last_plt_gtime; }else
@@ -1431,7 +1431,7 @@ static void lapic_rearm(struct vlapic *s)vlapic_lvtt_period (s) ? period :0 , s->pt.irq,vlapic_lvtt_period (s) ? vlapic_pt_cb :NULL , - &s->timer_last_update); + &s->timer_last_update, false); s->timer_last_update = s->pt.last_plt_gtime; }
xen/arch/x86/hvm/vpt.c +39 -9
89 lines not on this page · raw message
xen/include/asm-x86/hvm/vpt.h +2 -1
@@ -42,6 +42,7 @@ struct periodic_time {bool do_not_freeze;bool irq_issued;bool warned_timeout_too_short; +bool level;#define PTSRC_isa 1/* ISA time source */ #define PTSRC_lapic 2/* LAPIC time source */ #define PTSRC_ioapic 3/* IOAPIC time source */
@@ -169,7 +170,7 @@ void pt_may_unmask_irq(struct domain *d, struct periodic_time *vlapic_pt);*/ 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); +uint64_t period,uint8_t irq,time_cb *cb,void *data,bool level);void destroy_periodic_time (struct periodic_time *pt);int pv_pit_handler (int port,int data,int write);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v4 1/2] vpt: add support for level interrupts
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 17.07.18 at 12:38, <[email protected]> wrote:
Level trigger interrupts will be asserted regardless of whether the interrupt is masked, and thus the callback will also be executed.
Add a new 'level' parameter to
create_periodic_timein order to create level triggered timers. None of the current users of vpt are switched to use level triggered interrupts yet.
Quoted 6 lines
Note that periodic level triggered interrupts are not supported. This is because level triggered interrupts always require a deassert of the IO-APIC pin, which should be done by the caller of vpt at which point the caller should also reset the timer if required.
Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 2/2 vhpet: add support for level triggered interrupts
In reply to Roger Pau MonneLevel triggered interrupts are not an optional feature of HPET, and must be implemented in order to comply with the HPET specification.
Implement them by adding a callback to the timer which sets the interrupt bit in the general interrupt status register. Further interrupts (in case of periodic mode) will not be injected until the bit is cleared.
In order to reset the interrupts when the status bit is clear Xen must also detect accesses to such register.
While there convert tn and i in hpet_write to unsigned.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Stefan Bader <[email protected]>
---
Changes since v3:
- Change pointer cast to use unsigned long.
- Use test and set instead of two separate operations.
- Remove comment about irq usage.
--- xen/arch/x86/hvm/hpet.c | 54 +++++++++++++++++++++++++++-------- xen/arch/x86/hvm/irq.c | 15 ++++++++++ xen/include/asm-x86/hvm/irq.h | 3 +- 3 files changed, 59 insertions(+), 13 deletions(-)
xen/arch/x86/hvm/hpet.c +42 -12
@@ -223,6 +223,17 @@ static void hpet_stop_timer(HPETState *h, unsigned int tn,hpet_get_comparator (h, tn, guest_time); } +static void hpet_timer_fired (struct vcpu *v,void *data) +{ +unsigned int tn = (unsigned long )data; +HPETState *h =vcpu_vhpet (v); + +write_lock (&h->lock); +if (__test_and_set_bit (tn, &h->hpet.isr) ) +ASSERT_UNREACHABLE (); +write_unlock (&h->lock); +} +/* the number of HPET tick that stands for * 1/(2^10) second, namely, 0.9765625 milliseconds */ #define HPET_TINY_TIME_SPAN ((h->stime_freq >> 10) / STIME_PER_HPET_TICK)
@@ -244,7 +255,8 @@ static void hpet_set_timer(HPETState *h, unsigned int tn,pit_stop_channel0_irq (&vhpet_domain (h)->arch.vpit); } -if ( !timer_enabled (h, tn) ) +if ( !timer_enabled (h, tn) || + (timer_level (h, tn) &&test_bit (tn, &h->hpet.isr)) )return ;if ( !timer_int_route_valid (h, tn) )
@@ -293,8 +305,12 @@ static void hpet_set_timer(HPETState *h, unsigned int tn,* timer we also need the period which may be different because time may * have elapsed between the time the comparator was written and the timer * being enabled (now). +* +* NB: set periodic timers as oneshot if interrupt type is set to level +* because the user must ack the interrupt (by writing 1 to the interrupt +* status register) before another interrupt can be delivered. */ - oneshot = !timer_is_periodic (h, tn); + oneshot = !timer_is_periodic (h, tn) ||timer_level (h, tn); TRACE_2_LONG_4D(TRC_HVM_EMUL_HPET_START_TIMER, tn, irq, TRC_PAR_LONG(hpet_tick_to_ns(h, diff)), TRC_PAR_LONG(oneshot ? 0LL :
@@ -302,7 +318,8 @@ static void hpet_set_timer(HPETState *h, unsigned int 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 , false); + irq,timer_level (h, tn) ? hpet_timer_fired :NULL , + (void *)(unsigned long )tn,timer_level (h, tn)); } static inline uint64_t hpet_fixup_reg(
@@ -338,7 +355,7 @@ static int hpet_write(HPETState *h =vcpu_vhpet (v);uint64_t old_val, new_val;uint64_t guest_time; -int tn, i; +unsigned int tn, i;/* Acculumate a bit mask of timers whos state is changed by this write. */ unsigned long start_timers =0 ;
@@ -394,6 +411,27 @@ static int hpet_write( }break ; +case HPET_STATUS : +/* write 1 to clear. */ +while ( new_val ) + { +bool active; + + i =find_first_set_bit (new_val); +if ( i >=HPET_TIMER_NUM ) +break ; +__clear_bit (i, &new_val); + active =__test_and_clear_bit (i, &h->hpet.isr); +if ( active ) + { +hvm_ioapic_deassert (v->domain,timer_int_route (h, i)); +if (hpet_enabled (h) &&timer_enabled (h, i) && +timer_level (h, i) &&timer_is_periodic (h, i) ) +set_start_timer (i); + } + } +break ; +case HPET_COUNTER : h->hpet.mc64 = new_val;if (hpet_enabled (h) )
@@ -415,14 +453,6 @@ static int hpet_write(timer_sanitize_int_route (h, tn); -if (timer_level (h, tn) ) - { -gdprintk (XENLOG_ERR , -"HPET: level triggered interrupt not supported now\n" ); -domain_crash (current->domain); -break ; - } -if ( new_val &HPET_TN_32BIT ) { h->hpet.timers[tn].cmp = (uint32_t )h->hpet.timers[tn].cmp;
xen/arch/x86/hvm/irq.c +15 -0
@@ -61,6 +61,21 @@ int hvm_ioapic_assert(struct domain *d, unsigned int gsi, bool level)return vector; } +void hvm_ioapic_deassert (struct domain *d,unsigned int gsi) +{ +struct hvm_irq *hvm_irq =hvm_domain_irq (d); + +if ( gsi >= hvm_irq->nr_gsis ) + { +ASSERT_UNREACHABLE (); +return ; + } + +spin_lock (&d->arch.hvm_domain.irq_lock); + hvm_irq->gsi_assert_count[gsi]--; +spin_unlock (&d->arch.hvm_domain.irq_lock); +} +static void assert_irq (struct domain *d,unsigned ioapic_gsi,unsigned pic_irq) {assert_gsi (d, ioapic_gsi);
xen/include/asm-x86/hvm/irq.h +2 -1
@@ -207,8 +207,9 @@ int hvm_set_pci_link_route(struct domain *d, u8 link, u8 isa_irq);int hvm_inject_msi (struct domain *d,uint64_t addr,uint32_t data); -/* Assert an IO APIC pin. */ +/* Assert/deassert an IO APIC pin. */ int hvm_ioapic_assert (struct domain *d,unsigned int gsi,bool level); +void hvm_ioapic_deassert (struct domain *d,unsigned int gsi);void hvm_maybe_deassert_evtchn_irq (void );void hvm_assert_evtchn_irq (struct vcpu *v);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 17.07.18 at 12:38, <[email protected]> wrote:
Level triggered interrupts are not an optional feature of HPET, and must be implemented in order to comply with the HPET specification.
Implement them by adding a callback to the timer which sets the interrupt bit in the general interrupt status register. Further interrupts (in case of periodic mode) will not be injected until the bit is cleared.
Quoted 7 lines
In order to reset the interrupts when the status bit is clear Xen must also detect accesses to such register.
While there convert tn and i in
hpet_writeto unsigned.Reported-by Stefan Bader <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 1/1 add HPET functional test
In reply to Roger Pau MonneIn order to test HPET level trigger interrupts.
Note that the test doesn't check that the interrupt is injected correctly, only that the status bits are properly set an acknowledged when using HPET with level triggered interrupts.
---
Cc: Andrew Cooper <[email protected]>
--- arch/x86/hpet.c | 3 ++ arch/x86/include/arch/hpet.h | 55 +++++++++++++++++++++ docs/all-tests.dox | 2 + include/xtf/libc.h | 3 ++ tests/hpet/Makefile | 9 ++++ tests/hpet/main.c | 96 ++++++++++++++++++++++++++++++++++++ 6 files changed, 168 insertions(+) create mode 100644 tests/hpet/Makefile create mode 100644 tests/hpet/main.c
arch/x86/hpet.c +3 -0
@@ -68,6 +68,9 @@ void hpet_init_timer(unsigned int nr, unsigned int irq, uint64_t ticks,hpet_write64 (HPET_CFG , cfg & ~HPET_CFG_ENABLE );hpet_write64 (HPET_COUNTER ,0 ); +/* Clear any pending status bit. */ +hpet_timer_status_clear (nr); +/* Configure timer and setup comparator. */ hpet_write32 (HPET_Tn_CFG (nr), tm.raw);hpet_write64 (HPET_Tn_CMP (nr), ticks);
arch/x86/include/arch/hpet.h +55 -0
70 lines not on this page · raw message
docs/all-tests.dox +2 -0
@@ -20,6 +20,8 @@ and functionality. @subpage test-fpu-exception-emulation - FPU Exception Emulation. Covers XSA-190. +@subpage test-hpet - HPET functional test. + @subpage test-invlpg - `invlpg` instruction behaviour. @subpage test-lbr-tsx-vmentry - Haswell and later LBR/TSX Vmentry failure test.
include/xtf/libc.h +3 -0
@@ -35,6 +35,9 @@ void *memcpy(void *dst, const void *src, size_t n);int memcmp (const void *s1,const void *s2,size_t n);#define memcmp (s1, s2, n) __builtin_memcmp(s1, s2, n) +int ffs (int v); +#define ffs (v) __builtin_ffs(v) +size_t strnlen (const char *str,size_t max); int __printf(3, 0)
tests/hpet/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +include $(ROOT)/build/common.mk + +NAME := hpet +CATEGORY := functional +TEST-ENVS := hvm64 + +obj-perenv += main.o + +include $(ROOT)/build/gen.mk
tests/hpet/main.c new file +96 -0
96 lines not on this page · raw message
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel