XEN tools for ARM with Virtualization Extensions - Patch #2
Second patch submitted with changes based on comments on first patch.
Quoted 45 lines
Quoted 1 line
From
551f174c9653def01890fadd2dd769ab8a9acde7Mon Sep 17 00:00:002001
Quoted 8 lines
From: Eric Trudeau <[email protected]>
Date: Thu, 11 Jul 2013 20:03:51 -0400
Subject: [PATCH] Add support for Guest physdev irqs--- xen/arch/arm/domain.c | 16 ++++++++++++++++ xen/arch/arm/gic.c | 15 ++++++++++----- xen/arch/arm/physdev.c | 48++++++++++++++++++++++++++++++++++++++++++++++--
Quoted 20 lines
xen/arch/arm/vgic.c | 5 +---- 4 files changed, 73 insertions(+), 11 deletions(-)xen/arch/arm/domain.c +2
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,22 @@ fail:return rc; }xen/arch/arm/domain.c fail: · line 527
Quoted 10 lines
xen/arch/arm/domain.c +10
-0+static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +}As you may know,
release_irqwill spin until the flagsIRQ_INPROGRESSis unset. This is done my the maintenance handler.
Quoted 3 lines
Now, let say the domain has crashed and the IRQ is not yet EOIed, then you will spin forever.
I put a timeout in the IRQ_INPROGRESS check in release_irq() of 100 attempts with a 1 msec delay per loop iteration.
Quoted 94 lines
xen/arch/arm/domain.c fail: · line 531
Quoted 4 lines
xen/arch/arm/domain.c +2
-0+void arch_domain_destroy (struct domain *d) { +if (d->irq_caps !=NULL )You don't need this check.
During the domain create, Xen ensures thatirq_capsis not NULL.xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, const
Quoted 26 lines
xen/arch/arm/domain.c +1
-0+release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);xen/arch/arm/gic.c +2
-1@@ -510,7 +510,7 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags;@@ -522,6 +522,7 @@ void __init release_irq(unsigned int irq) action = desc->action; desc->action =NULL ; desc->status |=IRQ_DISABLED ; + desc->status &= ~IRQ_GUEST ;spin_lock (&gic.lock); desc->handler->shutdown (desc);@@ -707,6 +708,12 @@ int gic_route_irq_to_guest(struct domain *d, conststruct
dt_irq*irq,xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, const
Quoted 13 lines
xen/arch/arm/gic.c +6
-0spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + } + desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;@@ -715,12 +722,10 @@ int gic_route_irq_to_guest(struct domain *d, conststruct
dt_irq*irq,Quoted 22 lines
xen/arch/arm/gic.c +2
-4gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;xen/arch/arm/physdev.c +0
-0@@ -9,12 +9,56 @@#include <xen/lib.h> #include <xen/errno.h> #include <asm/hypercall.h> xen/arch/arm/physdev.c line 16
Quoted 10 lines
xen/arch/arm/physdev.c +5
-1+#include <public/physdev.h> +#include <xen/guest_access.h> +#include <xen/irq.h> +#include <xen/sched.h> +#include <asm/gic.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { - printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 13 lines
xen/arch/arm/physdev.c +12
-1-return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: { +physdev_map_pirq_t map; +struct dt_irq irq; +struct domain *d; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ;
Quoted 9 lines
xen/arch/arm/physdev.c line 38
Quoted 6 lines
xen/arch/arm/physdev.c +6
-0+ + d =rcu_lock_domain_by_any_id (map.domid); +if ( d ==NULL ) { + ret = -ESRCH ; +break ; + }Missing sanity check on the map.pirq value.
I added a check for (map.pirq < gic_number_lines()). This is the sanity check that is done in gic_route_irq(). Should this be less than or equal or are the device tree SPI irq numbers 0-based before they are offset by 32?
Quoted 8 lines
xen/arch/arm/physdev.c line 42
Quoted 4 lines
xen/arch/arm/physdev.c +4
-0+ irq.irq = map.pirq; + irq.type =DT_IRQ_TYPE_LEVEL_MASK ; + + ret =gic_route_irq_to_guest (d, &irq,"GuestIRQ" );Do you plan to handle non 1:1 IRQ mapping?
How does work your the IRQ mapping if the IRQ is already mapped to dom0?
See comment below about sticking with 1:1 irq mapping.
Quoted 30 lines
xen/arch/arm/physdev.c line 55
Quoted 13 lines
xen/arch/arm/physdev.c +13
-0+if (!ret) +printk ("%s gic_route_irq_to_guest added IRQ %d to dom%d\n" , + __FUNCTION__, irq.irq, d->domain_id); + +rcu_unlock_domain (d); + +if (!ret &&__copy_to_guest (arg, &map,1 ) ) + ret = -EFAULT ; +break ; + } + +default : + printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 16 lines
xen/arch/arm/physdev.c +5
-0+ ret = -ENOSYS ; +break ; + } + +return ret; }/* xen/arch/arm/vgic.c +0
-0@@ -82,10 +82,7 @@ int domain_vgic_init(struct domain *d)/* Currently nr_lines in vgic and gic doesn't have the same meanings * Here nr_lines = number of SPIs */
Quoted 9 lines
xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d) · line 85
Quoted 5 lines
xen/arch/arm/vgic.c +1
-4-if ( d->domain_id ==0 ) - d->arch.vgic.nr_lines =gic_number_lines () -32 ; -else - d->arch.vgic.nr_lines =0 ;/* We don't need SPIs for the guest */ + d->arch.vgic.nr_lines = d->nr_pirqs -32 ;If you want to stick on the 1:1 mapping, the best solution is to set "
nr_linestogic_number_lines()- 32" for all the domains.
I will stick with 1:1 mapping for guest IRQs and use gic_number_lines() - 32.
Quoted 2 lines
--
Julien Grall
Patch #2 begins here:
--------------------------------------------
Quoted 1 line
From
924441c3eddb1765cb4fb0e94f6b62177195837dMon Sep 17 00:00:00 2001
From: Eric Trudeau <[email protected]>
Date: Fri, 12 Jul 2013 14:54:24 -0400
Subject: [PATCH] xen/arm: Add support for 1:1 IRQ mapping into guest domains
on ARM
ARM guests will now have the ability to access 1:1 mapped IRQs.
The irqs list in the domain configuration file is used. A SPI irq number must include the offset of 32. For example, if the device tree irq number is 76 for a SPI, then the irqs field in the dom.cfg file would be:
irqs = [ 108 ]
Only level-triggered IRQs are supported at this time.
When an IRQ is released on destruction of the guest, any in-progress handlers are given at least a 100 msec to complete.
--- xen/arch/arm/domain.c | 15 ++++++++++++++ xen/arch/arm/gic.c | 29 ++++++++++++++++++-------- xen/arch/arm/physdev.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-- xen/arch/arm/vgic.c | 5 +---- 4 files changed, 91 insertions(+), 14 deletions(-)
xen/arch/arm/domain.c +15 -0
@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);
@@ -513,8 +515,21 @@ fail:return rc; } +static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +} + +void arch_domain_destroy (struct domain *d) { +release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);
xen/arch/arm/gic.c +21 -8
@@ -30,6 +30,7 @@#include <xen/device_tree.h> #include <asm/p2m.h> #include <asm/domain.h> +#include <xen/delay.h> #include <asm/gic.h>
@@ -510,11 +511,12 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags; -struct irqaction *action; +struct irqaction *action; +int inprogresschecks; desc =irq_to_desc (irq);
@@ -530,8 +532,15 @@ void __init release_irq(unsigned int irq)spin_unlock_irqrestore (&desc->lock,flags); -/* Wait to make sure it's not being used on another CPU */ -do {smp_mb (); }while ( desc->status &IRQ_INPROGRESS ); +/* Wait a little while to make sure it's not being used on another CPU +* But not indefinitely, because a guest may have crashed */ +for (inprogresschecks =0 ; (inprogresschecks <100 ); inprogresschecks++) { +smp_mb (); +if ( desc->status &IRQ_INPROGRESS ) +mdelay (1 ); +else +break ; + }if (action && action->free_on_release)xfree (action);
@@ -708,6 +717,12 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + } + desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;
@@ -716,12 +731,10 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;
xen/arch/arm/physdev.c +54 -2
66 lines not on this page · raw message
xen/arch/arm/vgic.c +1 -4
@@ -82,10 +82,7 @@ int domain_vgic_init(struct domain *d)/* Currently nr_lines in vgic and gic doesn't have the same meanings * Here nr_lines = number of SPIs */ -if ( d->domain_id ==0 ) - d->arch.vgic.nr_lines =gic_number_lines () -32 ; -else - d->arch.vgic.nr_lines =0 ;/* We don't need SPIs for the guest */ + d->arch.vgic.nr_lines =gic_number_lines () -32 ; d->arch.vgic.shared_irqs = xzalloc_array(struct vgic_irq_rank, DOMAIN_NR_RANKS(d));
--
1.8.1.2
Quoted 15 lines · Eric Trudeau
Patch #2 begins here:
--------------------------------------------From
924441c3eddb1765cb4fb0e94f6b62177195837dMon Sep 17 00:00:00 2001
From: Eric Trudeau <[email protected]>
Date: Fri, 12 Jul 2013 14:54:24 -0400
Subject: [PATCH] xen/arm: Add support for 1:1 IRQ mapping into guest domains
on ARMARM guests will now have the ability to access 1:1 mapped IRQs.
The irqs list in the domain configuration file is used. A SPI irq number must include the offset of 32. For example, if the device tree irq number is 76 for a SPI, then the irqs field in the dom.cfg file would be:
Quoted 6 lines
irqs = [ 108 ]Only level-triggered IRQs are supported at this time.
When an IRQ is released on destruction of the guest, any in-progress handlers are given at least a 100 msec to complete.
Overall it's pretty good patch, but I don't like the busy loop. I admit that it's an improvement over what we have today but release_irq wasn't actually called by anybody until now.
Quoted 75 lines
Signed-off-by Eric Trudeau <[email protected]>--- xen/arch/arm/domain.c | 15 ++++++++++++++ xen/arch/arm/gic.c | 29 ++++++++++++++++++-------- xen/arch/arm/physdev.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-- xen/arch/arm/vgic.c | 5 +---- 4 files changed, 91 insertions(+), 14 deletions(-)xen/arch/arm/domain.c +15
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,21 @@ fail:return rc; } +static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +} + +void arch_domain_destroy (struct domain *d) { +release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);xen/arch/arm/gic.c +4
-3@@ -30,6 +30,7 @@#include <xen/device_tree.h> #include <asm/p2m.h> #include <asm/domain.h> +#include <xen/delay.h> #include <asm/gic.h> @@ -510,11 +511,12 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags; -struct irqaction *action; +struct irqaction *action; +int inprogresschecks; desc =irq_to_desc (irq);@@ -530,8 +532,15 @@ void __init release_irq(unsigned int irq)spin_unlock_irqrestore (&desc->lock,flags); -/* Wait to make sure it's not being used on another CPU */
xen/arch/arm/gic.c void __init release_irq(unsigned int irq) · line 543
Quoted 10 lines
xen/arch/arm/gic.c +9
-1-do {smp_mb (); }while ( desc->status &IRQ_INPROGRESS ); +/* Wait a little while to make sure it's not being used on another CPU +* But not indefinitely, because a guest may have crashed */ +for (inprogresschecks =0 ; (inprogresschecks <100 ); inprogresschecks++) { +smp_mb (); +if ( desc->status &IRQ_INPROGRESS ) +mdelay (1 ); +else +break ; + }
Can we use a timer based watchdog instead to avoid the busy loop? Looping for 100ms means wasting a considerable amount of time.
Quoted 67 lines
xen/arch/arm/gic.c +7
-4if (action && action->free_on_release)xfree (action);@@ -708,6 +717,12 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + } desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;@@ -716,12 +731,10 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;xen/arch/arm/physdev.c +23
-2@@ -9,12 +9,64 @@#include <xen/lib.h> #include <xen/errno.h> #include <asm/hypercall.h> +#include <public/physdev.h> +#include <xen/guest_access.h> +#include <xen/irq.h> +#include <xen/sched.h> +#include <asm/gic.h> +#include <xsm/xsm.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { -printk ("%s %d cmd=%d: not implemented yet\n" , __func__, __LINE__, cmd); -return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: { +physdev_map_pirq_t map; +struct dt_irq irq; +struct domain *d; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ; + + d =rcu_lock_domain_by_any_id (map.domid); +if ( d ==NULL ) { + ret = -ESRCH ; +break ;
xen/arch/arm/physdev.c line 48
Quoted 10 lines
xen/arch/arm/physdev.c +10
-0+ } + + ret =xsm_map_domain_pirq (XSM_TARGET , d); + +if (!ret && (map.pirq >=gic_number_lines ())) + ret = -EINVAL ; + +if (!ret) { + irq.irq = map.pirq; + irq.type =DT_IRQ_TYPE_LEVEL_MASK ;
You should add a comment here to explain why you are hardcoding level, even if it's just a temporary limitation.
xen/arch/arm/physdev.c line 51
Quoted 2 lines
xen/arch/arm/physdev.c +2
-0+ ret =gic_route_irq_to_guest (d, &irq,"GuestIRQ" ); +if (!ret)
Code style (even though I admit that we are not following it to the letter ourselves). See CODING_STYLE.
xen/arch/arm/physdev.c line 58
Quoted 7 lines
xen/arch/arm/physdev.c +7
-0+dprintk (XENLOG_G_INFO ,"dom%d: gic_route_irq_to_guest mapped in IRQ %d\n" , + d->domain_id, irq.irq); + } + +rcu_unlock_domain (d); + +if (!ret &&__copy_to_guest (arg, &map,1 ) )
Shouldn't you be copying back the irq number written by gic_route_irq_to_guest in map.irq?
Quoted 30 lines
xen/arch/arm/physdev.c +11
-0+ ret = -EFAULT ; +break ; + } + +default : +printk ("%s %d cmd=%d: not implemented yet\n" , __func__, __LINE__, cmd); + ret = -ENOSYS ; +break ; + } + +return ret; }/* xen/arch/arm/vgic.c +1
-4@@ -82,10 +82,7 @@ int domain_vgic_init(struct domain *d)/* Currently nr_lines in vgic and gic doesn't have the same meanings * Here nr_lines = number of SPIs */ -if ( d->domain_id ==0 ) - d->arch.vgic.nr_lines =gic_number_lines () -32 ; -else - d->arch.vgic.nr_lines =0 ;/* We don't need SPIs for the guest */ + d->arch.vgic.nr_lines =gic_number_lines () -32 ; d->arch.vgic.shared_irqs = xzalloc_array(struct vgic_irq_rank, DOMAIN_NR_RANKS(d));
Quoted 207 lines · Stefano Stabellini
Quoted 15 lines · Eric Trudeau
Patch #2 begins here:
--------------------------------------------From
924441c3eddb1765cb4fb0e94f6b62177195837dMon Sep 17 00:00:00 2001
From: Eric Trudeau <[email protected]>
Date: Fri, 12 Jul 2013 14:54:24 -0400
Subject: [PATCH] xen/arm: Add support for 1:1 IRQ mapping into guest domains
on ARMARM guests will now have the ability to access 1:1 mapped IRQs.
The irqs list in the domain configuration file is used. A SPI irq number must include the offset of 32. For example, if the device tree irq number is 76 for a SPI, then the irqs field in the dom.cfg file would be:
Quoted 6 lines
irqs = [ 108 ]Only level-triggered IRQs are supported at this time.
When an IRQ is released on destruction of the guest, any in-progress handlers are given at least a 100 msec to complete.
Overall it's pretty good patch, but I don't like the busy loop. I admit that it's an improvement over what we have today but
release_irqwasn't actually called by anybody until now.Quoted 75 lines
Signed-off-by Eric Trudeau <[email protected]>--- xen/arch/arm/domain.c | 15 ++++++++++++++ xen/arch/arm/gic.c | 29 ++++++++++++++++++-------- xen/arch/arm/physdev.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-- xen/arch/arm/vgic.c | 5 +---- 4 files changed, 91 insertions(+), 14 deletions(-)xen/arch/arm/domain.c +15
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,21 @@ fail:return rc; } +static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +} + +void arch_domain_destroy (struct domain *d) { +release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);xen/arch/arm/gic.c +4
-3@@ -30,6 +30,7 @@#include <xen/device_tree.h> #include <asm/p2m.h> #include <asm/domain.h> +#include <xen/delay.h> #include <asm/gic.h> @@ -510,11 +511,12 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags; -struct irqaction *action; +struct irqaction *action; +int inprogresschecks; desc =irq_to_desc (irq);@@ -530,8 +532,15 @@ void __init release_irq(unsigned int irq)spin_unlock_irqrestore (&desc->lock,flags); -/* Wait to make sure it's not being used on another CPU */ xen/arch/arm/gic.c void __init release_irq(unsigned int irq) · line 543
Quoted 10 lines
xen/arch/arm/gic.c +9
-1-do {smp_mb (); }while ( desc->status &IRQ_INPROGRESS ); +/* Wait a little while to make sure it's not being used on another CPU +* But not indefinitely, because a guest may have crashed */ +for (inprogresschecks =0 ; (inprogresschecks <100 ); inprogresschecks++) { +smp_mb (); +if ( desc->status &IRQ_INPROGRESS ) +mdelay (1 ); +else +break ; + }Can we use a timer based watchdog instead to avoid the busy loop? Looping for 100ms means wasting a considerable amount of time.
Quoted 67 lines
xen/arch/arm/gic.c +7
-4if (action && action->free_on_release)xfree (action);@@ -708,6 +717,12 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + } desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;@@ -716,12 +731,10 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;xen/arch/arm/physdev.c +23
-2@@ -9,12 +9,64 @@#include <xen/lib.h> #include <xen/errno.h> #include <asm/hypercall.h> +#include <public/physdev.h> +#include <xen/guest_access.h> +#include <xen/irq.h> +#include <xen/sched.h> +#include <asm/gic.h> +#include <xsm/xsm.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { -printk ("%s %d cmd=%d: not implemented yet\n" , __func__, __LINE__, cmd); -return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: { +physdev_map_pirq_t map; +struct dt_irq irq; +struct domain *d; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ; + + d =rcu_lock_domain_by_any_id (map.domid); +if ( d ==NULL ) { + ret = -ESRCH ; +break ;xen/arch/arm/physdev.c line 48
Quoted 10 lines
xen/arch/arm/physdev.c +10
-0+ } + + ret =xsm_map_domain_pirq (XSM_TARGET , d); + +if (!ret && (map.pirq >=gic_number_lines ())) + ret = -EINVAL ; + +if (!ret) { + irq.irq = map.pirq; + irq.type =DT_IRQ_TYPE_LEVEL_MASK ;You should add a comment here to explain why you are hardcoding level, even if it's just a temporary limitation.
xen/arch/arm/physdev.c line 51
Quoted 2 lines
xen/arch/arm/physdev.c +2
-0+ ret =gic_route_irq_to_guest (d, &irq,"GuestIRQ" ); +if (!ret)Code style (even though I admit that we are not following it to the letter ourselves). See
CODING_STYLE.
Quoted 10 lines
xen/arch/arm/physdev.c line 58
Quoted 7 lines
xen/arch/arm/physdev.c +7
-0+dprintk (XENLOG_G_INFO ,"dom%d: gic_route_irq_to_guest mapped in IRQ %d\n" , + d->domain_id, irq.irq); + } + +rcu_unlock_domain (d); + +if (!ret &&__copy_to_guest (arg, &map,1 ) )Shouldn't you be copying back the irq number written by
gic_route_irq_to_guestin map.irq?
That's fine because pirq is used to return the IRQ number into the guest. Here, as we have 1:1 mapping, the value is same. But in the future, a physical IRQ will be mapped to a different number into the guest
--
Julien Grall
Quoted 40 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: Monday, July 15, 2013 6:08 PM
To: Stefano Stabellini
Cc: Eric Trudeau; xen-devel; [email protected]; Ian Campbell
Subject: Re: [Xen-devel] [XenARM] XEN tools for ARM with Virtualization Extensions - Patch #2Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Eric Trudeau
Patch #2 begins here:
--------------------------------------------From
924441c3eddb1765cb4fb0e94f6b62177195837dMon Sep 17 00:00:002001
Quoted 3 lines
Quoted 3 lines
From: Eric Trudeau <[email protected]>
Date: Fri, 12 Jul 2013 14:54:24 -0400
Subject: [PATCH] xen/arm: Add support for 1:1 IRQ mapping into guestdomains
Quoted 20 lines
Quoted 8 lines
on ARM
ARM guests will now have the ability to access 1:1 mapped IRQs.
The irqs list in the domain configuration file is used. A SPI irq number must include the offset of 32. For example, if the device tree irq number is 76 for a SPI, then the irqs field in the dom.cfg file would be:
Quoted 6 lines
irqs = [ 108 ]Only level-triggered IRQs are supported at this time.
When an IRQ is released on destruction of the guest, any in-progress handlers are given at least a 100 msec to complete.
Overall it's pretty good patch, but I don't like the busy loop. I admit that it's an improvement over what we have today but
release_irqwasn't actually called by anybody until now.
Quoted 90 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Eric Trudeau <[email protected]>--- xen/arch/arm/domain.c | 15 ++++++++++++++ xen/arch/arm/gic.c | 29 ++++++++++++++++++-------- xen/arch/arm/physdev.c | 56++++++++++++++++++++++++++++++++++++++++++++++++--
Quoted 84 lines
Quoted 70 lines
xen/arch/arm/vgic.c | 5 +---- 4 files changed, 91 insertions(+), 14 deletions(-)xen/arch/arm/domain.c +15
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,21 @@ fail:return rc; } +static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +} + +void arch_domain_destroy (struct domain *d) { +release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);xen/arch/arm/gic.c +4
-3@@ -30,6 +30,7 @@#include <xen/device_tree.h> #include <asm/p2m.h> #include <asm/domain.h> +#include <xen/delay.h> #include <asm/gic.h> @@ -510,11 +511,12 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags; -struct irqaction *action; +struct irqaction *action; +int inprogresschecks; desc =irq_to_desc (irq);@@ -530,8 +532,15 @@ void __init release_irq(unsigned int irq)spin_unlock_irqrestore (&desc->lock,flags); -/* Wait to make sure it's not being used on another CPU */ xen/arch/arm/gic.c void __init release_irq(unsigned int irq) · line 543
Quoted 10 lines
xen/arch/arm/gic.c +9
-1-do {smp_mb (); }while ( desc->status &IRQ_INPROGRESS ); +/* Wait a little while to make sure it's not being used on another CPU +* But not indefinitely, because a guest may have crashed */ +for (inprogresschecks =0 ; (inprogresschecks <100 ); inprogresschecks++) { +smp_mb (); +if ( desc->status &IRQ_INPROGRESS ) +mdelay (1 ); +else +break ; + }Can we use a timer based watchdog instead to avoid the busy loop? Looping for 100ms means wasting a considerable amount of time.
Can you kindly point me to an example in the Hypervisor code of a use case as an example of how I would implement the timer-based watchdog?
Quoted 105 lines
Quoted 4 lines
xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, const
Quoted 4 lines
xen/arch/arm/gic.c +0
-0if (action && action->free_on_release)xfree (action);@@ -708,6 +717,12 @@ int gic_route_irq_to_guest(struct domain *d, conststruct
dt_irq*irq,Quoted 9 lines
Quoted 9 lines
xen/arch/arm/gic.c +5
-0spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + }Quoted 4 lines
xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d,
Quoted 4 lines
xen/arch/arm/gic.c +0
-0desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;@@ -716,12 +731,10 @@ int gic_route_irq_to_guest(struct domain *d,const struct
dt_irq*irq,Quoted 30 lines
Quoted 30 lines
xen/arch/arm/gic.c +2
-4gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;xen/arch/arm/physdev.c +6
-0@@ -9,12 +9,64 @@#include <xen/lib.h> #include <xen/errno.h> #include <asm/hypercall.h> +#include <public/physdev.h> +#include <xen/guest_access.h> +#include <xen/irq.h> +#include <xen/sched.h> +#include <asm/gic.h> +#include <xsm/xsm.h> Quoted 3 lines
xen/arch/arm/physdev.c
Quoted 3 lines
xen/arch/arm/physdev.c +0
-1int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { - printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 33 lines
Quoted 18 lines
xen/arch/arm/physdev.c +17
-1-return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: { +physdev_map_pirq_t map; +struct dt_irq irq; +struct domain *d; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ; + + d =rcu_lock_domain_by_any_id (map.domid); +if ( d ==NULL ) { + ret = -ESRCH ; +break ;xen/arch/arm/physdev.c line 48
Quoted 10 lines
xen/arch/arm/physdev.c +10
-0+ } + + ret =xsm_map_domain_pirq (XSM_TARGET , d); + +if (!ret && (map.pirq >=gic_number_lines ())) + ret = -EINVAL ; + +if (!ret) { + irq.irq = map.pirq; + irq.type =DT_IRQ_TYPE_LEVEL_MASK ;You should add a comment here to explain why you are hardcoding level, even if it's just a temporary limitation.
Quoted 8 lines
xen/arch/arm/physdev.c line 51
Quoted 2 lines
xen/arch/arm/physdev.c +2
-0+ ret =gic_route_irq_to_guest (d, &irq,"GuestIRQ" ); +if (!ret)Code style (even though I admit that we are not following it to the letter ourselves). See
CODING_STYLE.Quoted 1 line
xen/arch/arm/physdev.c +1
-0+ dprintk(XENLOG_G_INFO, "dom%d: gic_route_irq_to_guestmapped in IRQ %d\n",
Quoted 9 lines
xen/arch/arm/physdev.c line 58
Quoted 6 lines
xen/arch/arm/physdev.c +6
-0+ d->domain_id, irq.irq); + } + +rcu_unlock_domain (d); + +if (!ret &&__copy_to_guest (arg, &map,1 ) )Shouldn't you be copying back the irq number written by
gic_route_irq_to_guestin map.irq?
Quoted 4 lines
That's fine because pirq is used to return the IRQ number into the guest. Here, as we have 1:1 mapping, the value is same. But in the future, a physical IRQ will be mapped to a different number into the guest
Correct. gic_route_irq_to_guest() only supports 1:1 mapping. Later, if non-1:1 mapping is supported the new implementation would use the map.pirq to return the guest IRQ used. Presumably, we would have support at that time for updating the device tree for Linux guests to obtain this "assigned" IRQ.
Quoted 131 lines · Eric Trudeau
Quoted 40 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: Monday, July 15, 2013 6:08 PM
To: Stefano Stabellini
Cc: Eric Trudeau; xen-devel; [email protected]; Ian Campbell
Subject: Re: [Xen-devel] [XenARM] XEN tools for ARM with Virtualization Extensions - Patch #2Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Eric Trudeau
Patch #2 begins here:
--------------------------------------------From
924441c3eddb1765cb4fb0e94f6b62177195837dMon Sep 17 00:00:002001
Quoted 3 lines
Quoted 3 lines
From: Eric Trudeau <[email protected]>
Date: Fri, 12 Jul 2013 14:54:24 -0400
Subject: [PATCH] xen/arm: Add support for 1:1 IRQ mapping into guestdomains
Quoted 20 lines
Quoted 8 lines
on ARM
ARM guests will now have the ability to access 1:1 mapped IRQs.
The irqs list in the domain configuration file is used. A SPI irq number must include the offset of 32. For example, if the device tree irq number is 76 for a SPI, then the irqs field in the dom.cfg file would be:
Quoted 6 lines
irqs = [ 108 ]Only level-triggered IRQs are supported at this time.
When an IRQ is released on destruction of the guest, any in-progress handlers are given at least a 100 msec to complete.
Overall it's pretty good patch, but I don't like the busy loop. I admit that it's an improvement over what we have today but
release_irqwasn't actually called by anybody until now.Quoted 90 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Eric Trudeau <[email protected]>--- xen/arch/arm/domain.c | 15 ++++++++++++++ xen/arch/arm/gic.c | 29 ++++++++++++++++++-------- xen/arch/arm/physdev.c | 56++++++++++++++++++++++++++++++++++++++++++++++++--
Quoted 84 lines
Quoted 70 lines
xen/arch/arm/vgic.c | 5 +---- 4 files changed, 91 insertions(+), 14 deletions(-)xen/arch/arm/domain.c +15
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,21 @@ fail:return rc; } +static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +} + +void arch_domain_destroy (struct domain *d) { +release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);xen/arch/arm/gic.c +4
-3@@ -30,6 +30,7 @@#include <xen/device_tree.h> #include <asm/p2m.h> #include <asm/domain.h> +#include <xen/delay.h> #include <asm/gic.h> @@ -510,11 +511,12 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags; -struct irqaction *action; +struct irqaction *action; +int inprogresschecks; desc =irq_to_desc (irq);@@ -530,8 +532,15 @@ void __init release_irq(unsigned int irq)spin_unlock_irqrestore (&desc->lock,flags); -/* Wait to make sure it's not being used on another CPU */ xen/arch/arm/gic.c void __init release_irq(unsigned int irq) · line 543
Quoted 10 lines
xen/arch/arm/gic.c +9
-1-do {smp_mb (); }while ( desc->status &IRQ_INPROGRESS ); +/* Wait a little while to make sure it's not being used on another CPU +* But not indefinitely, because a guest may have crashed */ +for (inprogresschecks =0 ; (inprogresschecks <100 ); inprogresschecks++) { +smp_mb (); +if ( desc->status &IRQ_INPROGRESS ) +mdelay (1 ); +else +break ; + }Can we use a timer based watchdog instead to avoid the busy loop? Looping for 100ms means wasting a considerable amount of time.
Quoted 2 lines
Can you kindly point me to an example in the Hypervisor code of a use case as an example of how I would implement the timer-based watchdog?
I think that Julien's suggestion to EOI the irq from here it's better.
Quoted 110 lines
Quoted 105 lines
Quoted 4 lines
xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, const
Quoted 4 lines
xen/arch/arm/gic.c +0
-0if (action && action->free_on_release)xfree (action);@@ -708,6 +717,12 @@ int gic_route_irq_to_guest(struct domain *d, conststruct
dt_irq*irq,Quoted 9 lines
Quoted 9 lines
xen/arch/arm/gic.c +5
-0spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + }Quoted 4 lines
xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d,
Quoted 4 lines
xen/arch/arm/gic.c +0
-0desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;@@ -716,12 +731,10 @@ int gic_route_irq_to_guest(struct domain *d,const struct
dt_irq*irq,Quoted 30 lines
Quoted 30 lines
xen/arch/arm/gic.c +2
-4gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;xen/arch/arm/physdev.c +6
-0@@ -9,12 +9,64 @@#include <xen/lib.h> #include <xen/errno.h> #include <asm/hypercall.h> +#include <public/physdev.h> +#include <xen/guest_access.h> +#include <xen/irq.h> +#include <xen/sched.h> +#include <asm/gic.h> +#include <xsm/xsm.h> Quoted 3 lines
xen/arch/arm/physdev.c
Quoted 3 lines
xen/arch/arm/physdev.c +0
-1int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { - printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 33 lines
Quoted 18 lines
xen/arch/arm/physdev.c +17
-1-return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: { +physdev_map_pirq_t map; +struct dt_irq irq; +struct domain *d; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ; + + d =rcu_lock_domain_by_any_id (map.domid); +if ( d ==NULL ) { + ret = -ESRCH ; +break ;xen/arch/arm/physdev.c line 48
Quoted 10 lines
xen/arch/arm/physdev.c +10
-0+ } + + ret =xsm_map_domain_pirq (XSM_TARGET , d); + +if (!ret && (map.pirq >=gic_number_lines ())) + ret = -EINVAL ; + +if (!ret) { + irq.irq = map.pirq; + irq.type =DT_IRQ_TYPE_LEVEL_MASK ;You should add a comment here to explain why you are hardcoding level, even if it's just a temporary limitation.
Quoted 8 lines
xen/arch/arm/physdev.c line 51
Quoted 2 lines
xen/arch/arm/physdev.c +2
-0+ ret =gic_route_irq_to_guest (d, &irq,"GuestIRQ" ); +if (!ret)Code style (even though I admit that we are not following it to the letter ourselves). See
CODING_STYLE.Quoted 1 line
xen/arch/arm/physdev.c +1
-0+ dprintk(XENLOG_G_INFO, "dom%d: gic_route_irq_to_guestmapped in IRQ %d\n",
Quoted 9 lines
xen/arch/arm/physdev.c line 58
Quoted 6 lines
xen/arch/arm/physdev.c +6
-0+ d->domain_id, irq.irq); + } + +rcu_unlock_domain (d); + +if (!ret &&__copy_to_guest (arg, &map,1 ) )Shouldn't you be copying back the irq number written by
gic_route_irq_to_guestin map.irq?Quoted 4 lines
That's fine because pirq is used to return the IRQ number into the guest. Here, as we have 1:1 mapping, the value is same. But in the future, a physical IRQ will be mapped to a different number into the guest
Quoted 4 lines
Correct.
gic_route_irq_to_guest()only supports 1:1 mapping. Later, if non-1:1 mapping is supported the new implementation would use the map.pirq to return the guest IRQ used. Presumably, we would have support at that time for updating the device tree for Linux guests to obtain this "assigned" IRQ.
Thinking more about this, a better interface and more similar to the x86 version of this hypercall would be the following:
map.index is used by the caller to ask for the machine irq to map
map.pirq is used by the caller to ask for the guest irq number to use (right now map.pirq is going to be equal to map.index or -1, see below)
If map.pirq is < 0, then Xen is free to choose the guest irq number it prefers. Either way, Xen should update the map.pirq field.
Of course all this would need to be documented :-)
Quoted 47 lines · Eric Trudeau
Second patch submitted with changes based on comments on first patch.
Quoted 45 lines
Quoted 1 line
From
551f174c9653def01890fadd2dd769ab8a9acde7Mon Sep 17 00:00:002001
Quoted 8 lines
From: Eric Trudeau <[email protected]>
Date: Thu, 11 Jul 2013 20:03:51 -0400
Subject: [PATCH] Add support for Guest physdev irqs--- xen/arch/arm/domain.c | 16 ++++++++++++++++ xen/arch/arm/gic.c | 15 ++++++++++----- xen/arch/arm/physdev.c | 48++++++++++++++++++++++++++++++++++++++++++++++--
Quoted 20 lines
xen/arch/arm/vgic.c | 5 +---- 4 files changed, 73 insertions(+), 11 deletions(-)xen/arch/arm/domain.c +2
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,22 @@ fail:return rc; }xen/arch/arm/domain.c fail: · line 527
Quoted 10 lines
xen/arch/arm/domain.c +10
-0+static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +}As you may know,
release_irqwill spin until the flagsIRQ_INPROGRESSis unset. This is done my the maintenance handler.
Quoted 6 lines
Quoted 3 lines
Now, let say the domain has crashed and the IRQ is not yet EOIed, then you will spin forever.
I put a timeout in the
IRQ_INPROGRESScheck inrelease_irq()of 100 attempts with a 1 msec delay per loop iteration.
If we plan to only use release_irq when a domain is destroyed, this check is useless,
so it should be removed.
An IRQ stays with the flag IRQ_INPROGRESS until Xen will eoi it. If the domain has crashed or received an hard shutdown (ie xl destroy), the IRQ will
remain "inflight" and can never come up again.
You need to check if the IRQ is still inflight and, if yes, eoi it.
Quoted 104 lines
Quoted 94 lines
xen/arch/arm/domain.c fail:
Quoted 4 lines
xen/arch/arm/domain.c +2
-0+void arch_domain_destroy (struct domain *d) { +if (d->irq_caps !=NULL )You don't need this check.
During the domain create, Xen ensures thatirq_capsis not NULL.xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, const
Quoted 26 lines
xen/arch/arm/domain.c +1
-0+release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);xen/arch/arm/gic.c +2
-1@@ -510,7 +510,7 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags;@@ -522,6 +522,7 @@ void __init release_irq(unsigned int irq) action = desc->action; desc->action =NULL ; desc->status |=IRQ_DISABLED ; + desc->status &= ~IRQ_GUEST ;spin_lock (&gic.lock); desc->handler->shutdown (desc);@@ -707,6 +708,12 @@ int gic_route_irq_to_guest(struct domain *d, conststruct
dt_irq*irq,xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, const
Quoted 13 lines
xen/arch/arm/gic.c +6
-0spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + } + desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;@@ -715,12 +722,10 @@ int gic_route_irq_to_guest(struct domain *d, conststruct
dt_irq*irq,Quoted 22 lines
xen/arch/arm/gic.c +2
-4gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;xen/arch/arm/physdev.c +0
-0@@ -9,12 +9,56 @@#include <xen/lib.h> #include <xen/errno.h> #include <asm/hypercall.h> xen/arch/arm/physdev.c line 16
Quoted 10 lines
xen/arch/arm/physdev.c +5
-1+#include <public/physdev.h> +#include <xen/guest_access.h> +#include <xen/irq.h> +#include <xen/sched.h> +#include <asm/gic.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { - printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 13 lines
xen/arch/arm/physdev.c +12
-1-return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: { +physdev_map_pirq_t map; +struct dt_irq irq; +struct domain *d; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ;Quoted 9 lines
xen/arch/arm/physdev.c line 39
Quoted 6 lines
xen/arch/arm/physdev.c +6
-0+ + d =rcu_lock_domain_by_any_id (map.domid); +if ( d ==NULL ) { + ret = -ESRCH ; +break ; + }Missing sanity check on the map.pirq value.
Quoted 3 lines
I added a check for (map.pirq <
gic_number_lines()). This is the sanity check that is done ingic_route_irq(). Should this be less than or equal or are the device tree SPI irq numbers 0-based before they are offset by 32?
Your sanity check looks good to me. gic_number_lines returns the exact number of IRQ (SPI + SGI + PPI).
Quoted 10 lines
Quoted 8 lines
xen/arch/arm/physdev.c line 50
Quoted 4 lines
xen/arch/arm/physdev.c +4
-0+ irq.irq = map.pirq; + irq.type =DT_IRQ_TYPE_LEVEL_MASK ; + + ret =gic_route_irq_to_guest (d, &irq,"GuestIRQ" );Do you plan to handle non 1:1 IRQ mapping?
How does work your the IRQ mapping if the IRQ is already mapped to dom0?See comment below about sticking with 1:1 irq mapping.
I think you didn't answer to the second question. How do you tell to Xen : "Don't map
this IRQ in dom0"? Do you manually remove the node from dom0 DTS or do you have an automatic way?
Quoted 271 lines
Quoted 30 lines
xen/arch/arm/physdev.c
Quoted 13 lines
xen/arch/arm/physdev.c +13
-0+if (!ret) +printk ("%s gic_route_irq_to_guest added IRQ %d to dom%d\n" , + __FUNCTION__, irq.irq, d->domain_id); + +rcu_unlock_domain (d); + +if (!ret &&__copy_to_guest (arg, &map,1 ) ) + ret = -EFAULT ; +break ; + } + +default : + printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 16 lines
xen/arch/arm/physdev.c +5
-0+ ret = -ENOSYS ; +break ; + } + +return ret; }/* xen/arch/arm/vgic.c +0
-0@@ -82,10 +82,7 @@ int domain_vgic_init(struct domain *d)/* Currently nr_lines in vgic and gic doesn't have the same meanings * Here nr_lines = number of SPIs */ Quoted 9 lines
xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d)
Quoted 5 lines
xen/arch/arm/vgic.c +1
-4-if ( d->domain_id ==0 ) - d->arch.vgic.nr_lines =gic_number_lines () -32 ; -else - d->arch.vgic.nr_lines =0 ;/* We don't need SPIs for the guest */ + d->arch.vgic.nr_lines = d->nr_pirqs -32 ;If you want to stick on the 1:1 mapping, the best solution is to set "
nr_linestogic_number_lines()- 32" for all the domains.I will stick with 1:1 mapping for guest IRQs and use
gic_number_lines()- 32.Quoted 2 lines
--
Julien GrallPatch #2 begins here:
--------------------------------------------From
924441c3eddb1765cb4fb0e94f6b62177195837dMon Sep 17 00:00:00 2001
From: Eric Trudeau <[email protected]>
Date: Fri, 12 Jul 2013 14:54:24 -0400
Subject: [PATCH] xen/arm: Add support for 1:1 IRQ mapping into guest domains
on ARMARM guests will now have the ability to access 1:1 mapped IRQs.
The irqs list in the domain configuration file is used. A SPI irq number must include the offset of 32. For example, if the device tree irq number is 76 for a SPI, then the irqs field in the dom.cfg file would be:
irqs = [ 108 ]Only level-triggered IRQs are supported at this time.
When an IRQ is released on destruction of the guest, any in-progress handlers are given at least a 100 msec to complete.
Signed-off-by Eric Trudeau <[email protected]>--- xen/arch/arm/domain.c | 15 ++++++++++++++ xen/arch/arm/gic.c | 29 ++++++++++++++++++-------- xen/arch/arm/physdev.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-- xen/arch/arm/vgic.c | 5 +---- 4 files changed, 91 insertions(+), 14 deletions(-)xen/arch/arm/domain.c +15
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,21 @@ fail:return rc; } +static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +} + +void arch_domain_destroy (struct domain *d) { +release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);xen/arch/arm/gic.c +21
-8@@ -30,6 +30,7 @@#include <xen/device_tree.h> #include <asm/p2m.h> #include <asm/domain.h> +#include <xen/delay.h> #include <asm/gic.h> @@ -510,11 +511,12 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags; -struct irqaction *action; +struct irqaction *action; +int inprogresschecks; desc =irq_to_desc (irq);@@ -530,8 +532,15 @@ void __init release_irq(unsigned int irq)spin_unlock_irqrestore (&desc->lock,flags); -/* Wait to make sure it's not being used on another CPU */ -do {smp_mb (); }while ( desc->status &IRQ_INPROGRESS ); +/* Wait a little while to make sure it's not being used on another CPU +* But not indefinitely, because a guest may have crashed */ +for (inprogresschecks =0 ; (inprogresschecks <100 ); inprogresschecks++) { +smp_mb (); +if ( desc->status &IRQ_INPROGRESS ) +mdelay (1 ); +else +break ; + }if (action && action->free_on_release)xfree (action);@@ -708,6 +717,12 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + } + desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;@@ -716,12 +731,10 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;xen/arch/arm/physdev.c +54
-2@@ -9,12 +9,64 @@#include <xen/lib.h> #include <xen/errno.h> #include <asm/hypercall.h> +#include <public/physdev.h> +#include <xen/guest_access.h> +#include <xen/irq.h> +#include <xen/sched.h> +#include <asm/gic.h> +#include <xsm/xsm.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { -printk ("%s %d cmd=%d: not implemented yet\n" , __func__, __LINE__, cmd); -return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: { +physdev_map_pirq_t map; +struct dt_irq irq; +struct domain *d; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ; + + d =rcu_lock_domain_by_any_id (map.domid); +if ( d ==NULL ) { + ret = -ESRCH ; +break ; + } + + ret =xsm_map_domain_pirq (XSM_TARGET , d); + +if (!ret && (map.pirq >=gic_number_lines ())) + ret = -EINVAL ; + +if (!ret) { + irq.irq = map.pirq; + irq.type =DT_IRQ_TYPE_LEVEL_MASK ; + + ret =gic_route_irq_to_guest (d, &irq,"GuestIRQ" ); +if (!ret) +dprintk (XENLOG_G_INFO ,"dom%d: gic_route_irq_to_guest mapped in IRQ %d\n" , + d->domain_id, irq.irq); + } + +rcu_unlock_domain (d); + +if (!ret &&__copy_to_guest (arg, &map,1 ) ) + ret = -EFAULT ; +break ; + } + +default : +printk ("%s %d cmd=%d: not implemented yet\n" , __func__, __LINE__, cmd); + ret = -ENOSYS ; +break ; + } + +return ret; }/* xen/arch/arm/vgic.c +1
-5@@ -82,10 +82,7 @@ int domain_vgic_init(struct domain *d)/* Currently nr_lines in vgic and gic doesn't have the same meanings * Here nr_lines = number of SPIs */ -if ( d->domain_id ==0 ) - d->arch.vgic.nr_lines =gic_number_lines () -32 ; -else - d->arch.vgic.nr_lines =0 ;/* We don't need SPIs for the guest */ + d->arch.vgic.nr_lines =gic_number_lines () -32 ; d->arch.vgic.shared_irqs = xzalloc_array(struct vgic_irq_rank, DOMAIN_NR_RANKS(d)); --
Quoted 1 line
1.8.1.2
--
Julien Grall
Quoted 67 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: Monday, July 15, 2013 7:14 PM
To: Eric Trudeau
Cc: xen-devel; [email protected]; Ian Campbell
Subject: Re: [Xen-devel] [XenARM] XEN tools for ARM with Virtualization Extensions - Patch #2Quoted 47 lines · Eric Trudeau
Second patch submitted with changes based on comments on first patch.
Quoted 45 lines
Quoted 1 line
From
551f174c9653def01890fadd2dd769ab8a9acde7Mon Sep 17 00:00:002001
Quoted 8 lines
From: Eric Trudeau <[email protected]>
Date: Thu, 11 Jul 2013 20:03:51 -0400
Subject: [PATCH] Add support for Guest physdev irqs--- xen/arch/arm/domain.c | 16 ++++++++++++++++ xen/arch/arm/gic.c | 15 ++++++++++----- xen/arch/arm/physdev.c | 48++++++++++++++++++++++++++++++++++++++++++++++--
Quoted 20 lines
xen/arch/arm/vgic.c | 5 +---- 4 files changed, 73 insertions(+), 11 deletions(-)xen/arch/arm/domain.c +2
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,22 @@ fail:return rc; }xen/arch/arm/domain.c fail: · line 527
Quoted 10 lines
xen/arch/arm/domain.c +10
-0+static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +}As you may know,
release_irqwill spin until the flagsIRQ_INPROGRESSis unset. This is done my the maintenance handler.Quoted 6 lines
Quoted 3 lines
Now, let say the domain has crashed and the IRQ is not yet EOIed, then you will spin forever.
I put a timeout in the
IRQ_INPROGRESScheck inrelease_irq()of 100 attempts with a 1 msec delay per loop iteration.If we plan to only use
release_irqwhen a domain is destroyed, this check is useless,
so it should be removed.
Quoted 7 lines
An IRQ stays with the flag
IRQ_INPROGRESSuntil Xen will eoi it. If the domain has crashed or received an hard shutdown (ie xl destroy), the IRQ will
remain "inflight" and can never come up again.You need to check if the IRQ is still inflight and, if yes, eoi it.
I will have to research this implementation as I am not familiar with the flow and functions in the IRQ handler code. If you have any suggestions, please let me know. Is it simply a matter of checking IRQ_INFLIGHT bit in the desc->status word and then calling a function to EOI the interrupt?
Quoted 122 lines
Quoted 30 lines
Quoted 30 lines
xen/arch/arm/domain.c fail:
Quoted 4 lines
xen/arch/arm/domain.c +2
-0+void arch_domain_destroy (struct domain *d) { +if (d->irq_caps !=NULL )You don't need this check.
During the domain create, Xen ensures thatirq_capsis not NULL.Quoted 23 lines
xen/arch/arm/domain.c +1
-0+release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);xen/arch/arm/gic.c +2
-1@@ -510,7 +510,7 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags;@@ -522,6 +522,7 @@ void __init release_irq(unsigned int irq) action = desc->action; desc->action =NULL ; desc->status |=IRQ_DISABLED ; + desc->status &= ~IRQ_GUEST ;Quoted 3 lines
Quoted 3 lines
xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d,
Quoted 3 lines
xen/arch/arm/gic.c +0
-0spin_lock (&gic.lock); desc->handler->shutdown (desc);@@ -707,6 +708,12 @@ int gic_route_irq_to_guest(struct domain *d,const
Quoted 13 lines
Quoted 13 lines
struct
dt_irq*irq,Quoted 12 lines
xen/arch/arm/gic.c +6
-0spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + } + desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;Quoted 1 line
Quoted 1 line
xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d,
Quoted 1 line
xen/arch/arm/gic.c +0
-0@@ -715,12 +722,10 @@ int gic_route_irq_to_guest(struct domain *d,const
Quoted 57 lines
Quoted 47 lines
struct
dt_irq*irq,Quoted 22 lines
xen/arch/arm/gic.c +2
-4gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;xen/arch/arm/physdev.c +0
-0@@ -9,12 +9,56 @@#include <xen/lib.h> #include <xen/errno.h> #include <asm/hypercall.h> xen/arch/arm/physdev.c line 16
Quoted 10 lines
xen/arch/arm/physdev.c +5
-1+#include <public/physdev.h> +#include <xen/guest_access.h> +#include <xen/irq.h> +#include <xen/sched.h> +#include <asm/gic.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { - printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 13 lines
xen/arch/arm/physdev.c +12
-1-return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: { +physdev_map_pirq_t map; +struct dt_irq irq; +struct domain *d; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ;Quoted 9 lines
xen/arch/arm/physdev.c line 39
Quoted 6 lines
xen/arch/arm/physdev.c +6
-0+ + d =rcu_lock_domain_by_any_id (map.domid); +if ( d ==NULL ) { + ret = -ESRCH ; +break ; + }Missing sanity check on the map.pirq value.
Quoted 3 lines
I added a check for (map.pirq <
gic_number_lines()). This is the sanity check that is done ingic_route_irq(). Should this be less than or equal or are the device tree SPI irq numbers 0-based before they are offset by 32?Your sanity check looks good to me.
gic_number_linesreturns the exact number of IRQ (SPI + SGI + PPI).Quoted 9 lines
Quoted 8 lines
xen/arch/arm/physdev.c line 50
Quoted 4 lines
xen/arch/arm/physdev.c +4
-0+ irq.irq = map.pirq; + irq.type =DT_IRQ_TYPE_LEVEL_MASK ; + + ret =gic_route_irq_to_guest (d, &irq,"GuestIRQ" );Do you plan to handle non 1:1 IRQ mapping?
How does work your the IRQ mapping if the IRQ is already mapped to dom0?
Quoted 6 lines
Quoted 1 line
See comment below about sticking with 1:1 irq mapping.
I think you didn't answer to the second question. How do you tell to Xen : "Don't map
this IRQ in dom0"? Do you manually remove the node from dom0 DTS or do you have an automatic way?
The gic_route_irq_to_guest call fails if Dom0 (or any other domain) has the IRQ routed to it because of the check for (desc->action != NULL).
I removed the device tree node from the Dom0 device tree. The use case we have is for some devices to be handled (not virtualized) by Dom0 or privileged guest domains exclusively.
Quoted 286 lines
Quoted 43 lines
Quoted 31 lines
Quoted 4 lines
xen/arch/arm/physdev.c +3
-0+if (!ret) +printk ("%s gic_route_irq_to_guest added IRQ %d to dom%d\n" , + __FUNCTION__, irq.irq, d->domain_id);xen/arch/arm/physdev.c
Quoted 10 lines
xen/arch/arm/physdev.c +10
-0+ +rcu_unlock_domain (d); + +if (!ret &&__copy_to_guest (arg, &map,1 ) ) + ret = -EFAULT ; +break ; + } + +default : + printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 16 lines
xen/arch/arm/physdev.c +5
-0+ ret = -ENOSYS ; +break ; + } + +return ret; }/* xen/arch/arm/vgic.c +0
-0@@ -82,10 +82,7 @@ int domain_vgic_init(struct domain *d)/* Currently nr_lines in vgic and gic doesn't have the same meanings * Here nr_lines = number of SPIs */ Quoted 9 lines
xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d)
Quoted 5 lines
xen/arch/arm/vgic.c +1
-4-if ( d->domain_id ==0 ) - d->arch.vgic.nr_lines =gic_number_lines () -32 ; -else - d->arch.vgic.nr_lines =0 ;/* We don't need SPIs for the guest */ + d->arch.vgic.nr_lines = d->nr_pirqs -32 ;If you want to stick on the 1:1 mapping, the best solution is to set "
nr_linestogic_number_lines()- 32" for all the domains.I will stick with 1:1 mapping for guest IRQs and use
gic_number_lines()- 32.Quoted 7 lines
Quoted 2 lines
--
Julien GrallPatch #2 begins here:
--------------------------------------------From
924441c3eddb1765cb4fb0e94f6b62177195837dMon Sep 17 00:00:002001
Quoted 3 lines
From: Eric Trudeau <[email protected]>
Date: Fri, 12 Jul 2013 14:54:24 -0400
Subject: [PATCH] xen/arm: Add support for 1:1 IRQ mapping into guestdomains
Quoted 12 lines
on ARM
ARM guests will now have the ability to access 1:1 mapped IRQs.
The irqs list in the domain configuration file is used. A SPI irq number must include the offset of 32. For example, if the device tree irq number is 76 for a SPI, then the irqs field in the dom.cfg file would be:
irqs = [ 108 ]Only level-triggered IRQs are supported at this time.
Quoted 8 lines
When an IRQ is released on destruction of the guest, any in-progress handlers are given at least a 100 msec to complete.
Signed-off-by Eric Trudeau <[email protected]>--- xen/arch/arm/domain.c | 15 ++++++++++++++ xen/arch/arm/gic.c | 29 ++++++++++++++++++-------- xen/arch/arm/physdev.c | 56++++++++++++++++++++++++++++++++++++++++++++++++--
xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, const
Quoted 84 lines
xen/arch/arm/vgic.c | 5 +---- 4 files changed, 91 insertions(+), 14 deletions(-)xen/arch/arm/domain.c +15
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,21 @@ fail:return rc; } +static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +} + +void arch_domain_destroy (struct domain *d) { +release_domain_irqs (d);p2m_teardown (d);domain_vgic_free (d);domain_uart0_free (d);xen/arch/arm/gic.c +13
-4@@ -30,6 +30,7 @@#include <xen/device_tree.h> #include <asm/p2m.h> #include <asm/domain.h> +#include <xen/delay.h> #include <asm/gic.h> @@ -510,11 +511,12 @@ void gic_route_spis(void) } } -void __init release_irq (unsigned int irq) +void release_irq (unsigned int irq) {struct irq_desc *desc;unsigned long flags; -struct irqaction *action; +struct irqaction *action; +int inprogresschecks; desc =irq_to_desc (irq);@@ -530,8 +532,15 @@ void __init release_irq(unsigned int irq)spin_unlock_irqrestore (&desc->lock,flags); -/* Wait to make sure it's not being used on another CPU */ -do {smp_mb (); }while ( desc->status &IRQ_INPROGRESS ); +/* Wait a little while to make sure it's not being used on another CPU +* But not indefinitely, because a guest may have crashed */ +for (inprogresschecks =0 ; (inprogresschecks <100 ); inprogresschecks++) { +smp_mb (); +if ( desc->status &IRQ_INPROGRESS ) +mdelay (1 ); +else +break ; + }if (action && action->free_on_release)xfree (action);@@ -708,6 +717,12 @@ int gic_route_irq_to_guest(struct domain *d, conststruct
dt_irq*irq,xen/arch/arm/gic.c int gic_route_irq_to_guest(struct domain *d, const
Quoted 13 lines
xen/arch/arm/gic.c +6
-0spin_lock_irqsave (&desc->lock, flags);spin_lock (&gic.lock); +if ( desc->action !=NULL ) + { + retval = -EBUSY ; + goto out; + } + desc->handler = &gic_guest_irq_type; desc->status |=IRQ_GUEST ;@@ -716,12 +731,10 @@ int gic_route_irq_to_guest(struct domain *d, conststruct
dt_irq*irq,Quoted 23 lines
xen/arch/arm/gic.c +2
-4gic_set_irq_properties (irq->irq, level,1u <<smp_processor_id (),0xa0 ); retval =__setup_irq (desc, irq->irq, action); -if (retval) { -xfree (action); - goto out; - } out: +if (retval) +xfree (action);spin_unlock (&gic.lock);spin_unlock_irqrestore (&desc->lock, flags);return retval;xen/arch/arm/physdev.c +1
-0@@ -9,12 +9,64 @@#include <xen/lib.h> #include <xen/errno.h> #include <asm/hypercall.h> +#include <public/physdev.h> xen/arch/arm/physdev.c line 16
Quoted 10 lines
xen/arch/arm/physdev.c +5
-1+#include <xen/guest_access.h> +#include <xen/irq.h> +#include <xen/sched.h> +#include <asm/gic.h> +#include <xsm/xsm.h> int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { - printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 22 lines
xen/arch/arm/physdev.c +21
-1-return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: { +physdev_map_pirq_t map; +struct dt_irq irq; +struct domain *d; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ; + + d =rcu_lock_domain_by_any_id (map.domid); +if ( d ==NULL ) { + ret = -ESRCH ; +break ; + } + + ret =xsm_map_domain_pirq (XSM_TARGET , d); +xen/arch/arm/physdev.c
Quoted 10 lines
xen/arch/arm/physdev.c +10
-0+if (!ret && (map.pirq >=gic_number_lines ())) + ret = -EINVAL ; + +if (!ret) { + irq.irq = map.pirq; + irq.type =DT_IRQ_TYPE_LEVEL_MASK ; + + ret =gic_route_irq_to_guest (d, &irq,"GuestIRQ" ); +if (!ret) + dprintk(XENLOG_G_INFO, "dom%d: gic_route_irq_to_guest mappedin IRQ %d\n",
xen/arch/arm/physdev.c
Quoted 12 lines
xen/arch/arm/physdev.c +12
-0+ d->domain_id, irq.irq); + } + +rcu_unlock_domain (d); + +if (!ret &&__copy_to_guest (arg, &map,1 ) ) + ret = -EFAULT ; +break ; + } + +default : + printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__,cmd);
Quoted 25 lines
xen/arch/arm/physdev.c +5
-0+ ret = -ENOSYS ; +break ; + } + +return ret; }/* xen/arch/arm/vgic.c +1
-5@@ -82,10 +82,7 @@ int domain_vgic_init(struct domain *d)/* Currently nr_lines in vgic and gic doesn't have the same meanings * Here nr_lines = number of SPIs */ -if ( d->domain_id ==0 ) - d->arch.vgic.nr_lines =gic_number_lines () -32 ; -else - d->arch.vgic.nr_lines =0 ;/* We don't need SPIs for the guest */ + d->arch.vgic.nr_lines =gic_number_lines () -32 ; d->arch.vgic.shared_irqs = xzalloc_array(struct vgic_irq_rank, DOMAIN_NR_RANKS(d)); --Quoted 1 line
1.8.1.2
--
Julien Grall
Quoted 67 lines · Eric Trudeau
Quoted 67 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: Monday, July 15, 2013 7:14 PM
To: Eric Trudeau
Cc: xen-devel; [email protected]; Ian Campbell
Subject: Re: [Xen-devel] [XenARM] XEN tools for ARM with Virtualization Extensions - Patch #2Quoted 47 lines · Eric Trudeau
Second patch submitted with changes based on comments on first patch.
Quoted 45 lines
Quoted 1 line
From
551f174c9653def01890fadd2dd769ab8a9acde7Mon Sep 17 00:00:002001
Quoted 8 lines
From: Eric Trudeau <[email protected]>
Date: Thu, 11 Jul 2013 20:03:51 -0400
Subject: [PATCH] Add support for Guest physdev irqs--- xen/arch/arm/domain.c | 16 ++++++++++++++++ xen/arch/arm/gic.c | 15 ++++++++++----- xen/arch/arm/physdev.c | 48++++++++++++++++++++++++++++++++++++++++++++++--
Quoted 20 lines
xen/arch/arm/vgic.c | 5 +---- 4 files changed, 73 insertions(+), 11 deletions(-)xen/arch/arm/domain.c +2
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,22 @@ fail:return rc; }xen/arch/arm/domain.c fail: · line 527
Quoted 10 lines
xen/arch/arm/domain.c +10
-0+static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +}As you may know,
release_irqwill spin until the flagsIRQ_INPROGRESSis unset. This is done my the maintenance handler.Quoted 6 lines
Quoted 3 lines
Now, let say the domain has crashed and the IRQ is not yet EOIed, then you will spin forever.
I put a timeout in the
IRQ_INPROGRESScheck inrelease_irq()of 100 attempts with a 1 msec delay per loop iteration.If we plan to only use
release_irqwhen a domain is destroyed, this check is useless,
so it should be removed.
Quoted 7 lines
Quoted 7 lines
An IRQ stays with the flag
IRQ_INPROGRESSuntil Xen will eoi it. If the domain has crashed or received an hard shutdown (ie xl destroy), the IRQ will
remain "inflight" and can never come up again.You need to check if the IRQ is still inflight and, if yes, eoi it.
I think that Julien is right: we need to call something similar to xen/arch/arm/gic.c:maintenance_interrupt. I would refactor the code there into a separate function that ends up being called by maintenance_interrupt and release_irq.
Quoted 4 lines
I will have to research this implementation as I am not familiar with the flow and functions in the IRQ handler code. If you have any suggestions, please let me know. Is it simply a matter of checking
IRQ_INFLIGHTbit in thedesc->statusword and then calling a function to EOI the interrupt?
First we need to make sure that the domain is paused and about to be destroyed otherwise we risk breaking the gic/vgic interface. Then we need to check whether the irq is currently inflight, looking at the inflight queue, see for example xen/arch/arm/vgic.c:vgic_vcpu_inject_irq. If the irq is inflight we need to check whether it's actually in one of the LR registers or just in the lr_queue. See xen/arch/arm/gic.c:gic_set_guest_irq to see how the lr_queue works. If the irq is queued there, just remove it from the lr_queue, EOI it and remove it from the inflight queue. If the irq is not present in lr_queue, it means it's in one of the LR registers. In that case we can call something similar to maintenance_interrupt to remove it from the LR, EOI the interrupt and remove it from the inflight queue.
Quoted 87 lines · Stefano Stabellini
Quoted 67 lines · Eric Trudeau
Quoted 67 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: Monday, July 15, 2013 7:14 PM
To: Eric Trudeau
Cc: xen-devel; [email protected]; Ian Campbell
Subject: Re: [Xen-devel] [XenARM] XEN tools for ARM with Virtualization Extensions - Patch #2Quoted 47 lines · Eric Trudeau
Second patch submitted with changes based on comments on first patch.
Quoted 45 lines
Quoted 1 line
From
551f174c9653def01890fadd2dd769ab8a9acde7Mon Sep 17 00:00:002001
Quoted 8 lines
From: Eric Trudeau <[email protected]>
Date: Thu, 11 Jul 2013 20:03:51 -0400
Subject: [PATCH] Add support for Guest physdev irqs--- xen/arch/arm/domain.c | 16 ++++++++++++++++ xen/arch/arm/gic.c | 15 ++++++++++----- xen/arch/arm/physdev.c | 48++++++++++++++++++++++++++++++++++++++++++++++--
Quoted 20 lines
xen/arch/arm/vgic.c | 5 +---- 4 files changed, 73 insertions(+), 11 deletions(-)xen/arch/arm/domain.c +2
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,22 @@ fail:return rc; }xen/arch/arm/domain.c fail: · line 527
Quoted 10 lines
xen/arch/arm/domain.c +10
-0+static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +}As you may know,
release_irqwill spin until the flagsIRQ_INPROGRESSis unset. This is done my the maintenance handler.Quoted 6 lines
Quoted 3 lines
Now, let say the domain has crashed and the IRQ is not yet EOIed, then you will spin forever.
I put a timeout in the
IRQ_INPROGRESScheck inrelease_irq()of 100 attempts with a 1 msec delay per loop iteration.If we plan to only use
release_irqwhen a domain is destroyed, this check is useless,
so it should be removed.Quoted 7 lines
Quoted 7 lines
An IRQ stays with the flag
IRQ_INPROGRESSuntil Xen will eoi it. If the domain has crashed or received an hard shutdown (ie xl destroy), the IRQ will
remain "inflight" and can never come up again.You need to check if the IRQ is still inflight and, if yes, eoi it.
I think that Julien is right: we need to call something similar to xen/arch/arm/gic.c:maintenance_interrupt. I would refactor the code there into a separate function that ends up being called by
maintenance_interruptandrelease_irq.Quoted 4 lines
I will have to research this implementation as I am not familiar with the flow and functions in the IRQ handler code. If you have any suggestions, please let me know. Is it simply a matter of checking
IRQ_INFLIGHTbit in thedesc->statusword and then calling a function to EOI the interrupt?
Quoted 13 lines
First we need to make sure that the domain is paused and about to be destroyed otherwise we risk breaking the gic/vgic interface. Then we need to check whether the irq is currently inflight, looking at the inflight queue, see for example xen/arch/arm/vgic.c:vgic_vcpu_inject_irq. If the irq is inflight we need to check whether it's actually in one of the LR registers or just in the
lr_queue. See xen/arch/arm/gic.c:gic_set_guest_irq to see how thelr_queueworks. If the irq is queued there, just remove it from thelr_queue, EOI it and remove it from the inflight queue. If the irq is not present inlr_queue, it means it's in one of the LR registers. In that case we can call something similar tomaintenance_interruptto remove it from the LR, EOI the interrupt and remove it from the inflight queue.
This all sounds plausible to me. I'm not sure we need to worry overly much about the impact on the guest of pulling an interrupt out from under it -- that's not ever going to be a clever thing to do and it seems like it should be up to the host and guest admin to arrange that the guest has quiesced the device. If the guest admin won't co-operate, well then they get to suffer the consequences. I guess that doesn't mean we shouldn't try and at least be a bit graceful about it if it's easy enough to do.
The thing to worry about is that the IRQ remains usable at the host level and can be assigned to someone else etc.
One thing to bare in mind is that when you EOI the interrupt, unless the guest has dealt with it you might immediately get another, which you may not currently be set up to handle.
You likely want to make sure it is at least masked at the physical level or maybe you want to try and ensure you do things in the right order such that it is routed to the host before you do the EOI. Safer to mask I think.
Ian.
Quoted 111 lines · Ian Campbell
Quoted 87 lines · Stefano Stabellini
Quoted 67 lines · Eric Trudeau
Quoted 67 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: Monday, July 15, 2013 7:14 PM
To: Eric Trudeau
Cc: xen-devel; [email protected]; Ian Campbell
Subject: Re: [Xen-devel] [XenARM] XEN tools for ARM with Virtualization Extensions - Patch #2Quoted 47 lines · Eric Trudeau
Second patch submitted with changes based on comments on first patch.
Quoted 45 lines
Quoted 1 line
From
551f174c9653def01890fadd2dd769ab8a9acde7Mon Sep 17 00:00:002001
Quoted 8 lines
From: Eric Trudeau <[email protected]>
Date: Thu, 11 Jul 2013 20:03:51 -0400
Subject: [PATCH] Add support for Guest physdev irqs--- xen/arch/arm/domain.c | 16 ++++++++++++++++ xen/arch/arm/gic.c | 15 ++++++++++----- xen/arch/arm/physdev.c | 48++++++++++++++++++++++++++++++++++++++++++++++--
Quoted 20 lines
xen/arch/arm/vgic.c | 5 +---- 4 files changed, 73 insertions(+), 11 deletions(-)xen/arch/arm/domain.c +2
-0@@ -31,6 +31,8 @@#include <asm/gic.h> #include "vtimer.h" #include "vpl011.h" +#include <xen/iocap.h> +#include <xen/irq.h> DEFINE_PER_CPU(struct vcpu *, curr_vcpu);@@ -513,8 +515,22 @@ fail:return rc; }xen/arch/arm/domain.c fail: · line 527
Quoted 10 lines
xen/arch/arm/domain.c +10
-0+static int release_domain_irqs (struct domain *d) +{ +int i; +for (i =0 ; i <= d->nr_pirqs; i++) { +if (irq_access_permitted (d, i)) { +release_irq (i); + } + } +return 0 ; +}As you may know,
release_irqwill spin until the flagsIRQ_INPROGRESSis unset. This is done my the maintenance handler.Quoted 6 lines
Quoted 3 lines
Now, let say the domain has crashed and the IRQ is not yet EOIed, then you will spin forever.
I put a timeout in the
IRQ_INPROGRESScheck inrelease_irq()of 100 attempts with a 1 msec delay per loop iteration.If we plan to only use
release_irqwhen a domain is destroyed, this check is useless,
so it should be removed.Quoted 7 lines
Quoted 7 lines
An IRQ stays with the flag
IRQ_INPROGRESSuntil Xen will eoi it. If the domain has crashed or received an hard shutdown (ie xl destroy), the IRQ will
remain "inflight" and can never come up again.You need to check if the IRQ is still inflight and, if yes, eoi it.
I think that Julien is right: we need to call something similar to xen/arch/arm/gic.c:maintenance_interrupt. I would refactor the code there into a separate function that ends up being called by
maintenance_interruptandrelease_irq.Quoted 4 lines
I will have to research this implementation as I am not familiar with the flow and functions in the IRQ handler code. If you have any suggestions, please let me know. Is it simply a matter of checking
IRQ_INFLIGHTbit in thedesc->statusword and then calling a function to EOI the interrupt?Quoted 13 lines
First we need to make sure that the domain is paused and about to be destroyed otherwise we risk breaking the gic/vgic interface. Then we need to check whether the irq is currently inflight, looking at the inflight queue, see for example xen/arch/arm/vgic.c:vgic_vcpu_inject_irq. If the irq is inflight we need to check whether it's actually in one of the LR registers or just in the
lr_queue. See xen/arch/arm/gic.c:gic_set_guest_irq to see how thelr_queueworks. If the irq is queued there, just remove it from thelr_queue, EOI it and remove it from the inflight queue. If the irq is not present inlr_queue, it means it's in one of the LR registers. In that case we can call something similar tomaintenance_interruptto remove it from the LR, EOI the interrupt and remove it from the inflight queue.This all sounds plausible to me. I'm not sure we need to worry overly much about the impact on the guest of pulling an interrupt out from under it -- that's not ever going to be a clever thing to do and it seems like it should be up to the host and guest admin to arrange that the guest has quiesced the device. If the guest admin won't co-operate, well then they get to suffer the consequences. I guess that doesn't mean we shouldn't try and at least be a bit graceful about it if it's easy enough to do.
Quoted 2 lines
The thing to worry about is that the IRQ remains usable at the host level and can be assigned to someone else etc.
Is it enough to check IRQ_INPROGRESS flags and if it's enabled Xen will need to EOI the interrupt?
So the code of release_irq could be:
1) disable/mask the IRQ
2) if IRQ_INPROGRESS => EOI it on the right CPU
Quoted 11 lines
One thing to bare in mind is that when you EOI the interrupt, unless the guest has dealt with it you might immediately get another, which you may not currently be set up to handle.
You likely want to make sure it is at least masked at the physical level or maybe you want to try and ensure you do things in the right order such that it is routed to the host before you do the EOI. Safer to mask I think.
Ian.