Stefano Stabellini
2012-Jan-30 16:20 UTC
[PATCH v3 0/2] use pirq_eoi_map in modern Linux kernels
Hi all, this small patch series consists of two patches: a patch for Xen and a patch for Linux. The Xen patch implements PHYSDEVOP_pirq_eoi_gmfn_v2, a new version of PHYSDEVOP_pirq_eoi_gmfn that does not change the semantics of PHYSDEVOP_eoi. The Linux patch introduces pirq_eoi_map in drivers/xen/events.c, using PHYSDEVOP_pirq_eoi_gmfn_v2. This version of the patch series addresses Konrad''s comment to the Linux patch and fixes a typo in the Xen patch. Cheers, Stefano
Stefano Stabellini
2012-Jan-30 16:21 UTC
[PATCH v3 1/2] Introduce PHYSDEVOP_pirq_eoi_gmfn_v2
PHYSDEVOP_pirq_eoi_gmfn subtly changes the semantics of PHYSDEVOP_eoi. In order to improve the interface this patch: - renames PHYSDEVOP_pirq_eoi_gmfn to PHYSDEVOP_pirq_eoi_gmfn_v1; - introduces PHYSDEVOP_pirq_eoi_gmfn_v2, that is like PHYSDEVOP_pirq_eoi_gmfn_v1 but it doesn''t modify the behaviour of another hypercall; - bump __XEN_LATEST_INTERFACE_VERSION__; - #define PHYSDEVOP_pirq_eoi_gmfn to PHYSDEVOP_pirq_eoi_gmfn_v1 or PHYSDEVOP_pirq_eoi_gmfn_v2 depending on the __XEN_INTERFACE_VERSION. Changes in v3: - fix a typo (__XEN_INTERFACE_VERSION instead of __XEN_INTERFACE_VERSION__). Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- xen/arch/ia64/xen/domain.c | 1 + xen/arch/ia64/xen/hypercall.c | 7 +++++-- xen/arch/x86/domain.c | 1 + xen/arch/x86/physdev.c | 7 +++++-- xen/include/asm-ia64/domain.h | 3 +++ xen/include/asm-x86/domain.h | 3 +++ xen/include/public/physdev.h | 16 +++++++++++++++- xen/include/public/xen-compat.h | 2 +- 8 files changed, 34 insertions(+), 6 deletions(-) diff --git a/xen/arch/ia64/xen/domain.c b/xen/arch/ia64/xen/domain.c index 1ea5a90..a31bd32 100644 --- a/xen/arch/ia64/xen/domain.c +++ b/xen/arch/ia64/xen/domain.c @@ -1731,6 +1731,7 @@ int domain_relinquish_resources(struct domain *d) if (d->arch.pirq_eoi_map != NULL) { put_page(virt_to_page(d->arch.pirq_eoi_map)); d->arch.pirq_eoi_map = NULL; + d->arch.auto_unmask = 0; } /* Tear down shadow mode stuff. */ diff --git a/xen/arch/ia64/xen/hypercall.c b/xen/arch/ia64/xen/hypercall.c index 130675e..18930bf 100644 --- a/xen/arch/ia64/xen/hypercall.c +++ b/xen/arch/ia64/xen/hypercall.c @@ -65,7 +65,7 @@ static long __do_pirq_guest_eoi(struct domain *d, int pirq) { if ( pirq < 0 || pirq >= NR_IRQS ) return -EINVAL; - if ( d->arch.pirq_eoi_map ) { + if ( d->arch.auto_unmask ) { spin_lock(&d->event_lock); evtchn_unmask(pirq_to_evtchn(d, pirq)); spin_unlock(&d->event_lock); @@ -508,7 +508,8 @@ long do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg) break; } - case PHYSDEVOP_pirq_eoi_gmfn: { + case PHYSDEVOP_pirq_eoi_gmfn_v1: + case PHYSDEVOP_pirq_eoi_gmfn_v2: { struct physdev_pirq_eoi_gmfn info; unsigned long mfn; @@ -531,6 +532,8 @@ long do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg) } current->domain->arch.pirq_eoi_map = mfn_to_virt(mfn); + if ( cmd == PHYSDEVOP_pirq_eoi_gmfn_v1 ) + current->domain->arch.auto_unmask = 1; ret = 0; break; } diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 61d83c8..a540af7 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2125,6 +2125,7 @@ int domain_relinquish_resources(struct domain *d) put_page_and_type( mfn_to_page(d->arch.pv_domain.pirq_eoi_map_mfn)); d->arch.pv_domain.pirq_eoi_map = NULL; + d->arch.pv_domain.auto_unmask = 0; } } diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index f280c28..df92cc7 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -271,7 +271,7 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg) break; } if ( !is_hvm_domain(v->domain) && - v->domain->arch.pv_domain.pirq_eoi_map ) + v->domain->arch.pv_domain.auto_unmask ) evtchn_unmask(pirq->evtchn); if ( !is_hvm_domain(v->domain) || domain_pirq_to_irq(v->domain, eoi.irq) > 0 ) @@ -293,7 +293,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg) break; } - case PHYSDEVOP_pirq_eoi_gmfn: { + case PHYSDEVOP_pirq_eoi_gmfn_v2: + case PHYSDEVOP_pirq_eoi_gmfn_v1: { struct physdev_pirq_eoi_gmfn info; unsigned long mfn; @@ -329,6 +330,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg) ret = -ENOSPC; break; } + if ( cmd == PHYSDEVOP_pirq_eoi_gmfn_v1 ) + v->domain->arch.pv_domain.auto_unmask = 1; put_gfn(current->domain, info.gmfn); ret = 0; diff --git a/xen/include/asm-ia64/domain.h b/xen/include/asm-ia64/domain.h index 12dc3bd..31d7d32 100644 --- a/xen/include/asm-ia64/domain.h +++ b/xen/include/asm-ia64/domain.h @@ -186,6 +186,9 @@ struct arch_domain { /* Shared page for notifying that explicit PIRQ EOI is required. */ unsigned long *pirq_eoi_map; unsigned long pirq_eoi_map_mfn; + /* set auto_unmask to 1 if you want PHYSDEVOP_eoi to automatically + * unmask the event channel */ + bool_t auto_unmask; /* Address of efi_runtime_services_t (placed in domain memory) */ void *efi_runtime; diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index 00bbaeb..fb2cfd2 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -231,6 +231,9 @@ struct pv_domain /* Shared page for notifying that explicit PIRQ EOI is required. */ unsigned long *pirq_eoi_map; unsigned long pirq_eoi_map_mfn; + /* set auto_unmask to 1 if you want PHYSDEVOP_eoi to automatically + * unmask the event channel */ + bool_t auto_unmask; /* Pseudophysical e820 map (XENMEM_memory_map). */ spinlock_t e820_lock; diff --git a/xen/include/public/physdev.h b/xen/include/public/physdev.h index 6e23295..b78eeba 100644 --- a/xen/include/public/physdev.h +++ b/xen/include/public/physdev.h @@ -49,7 +49,15 @@ DEFINE_XEN_GUEST_HANDLE(physdev_eoi_t); * will automatically get unmasked. The page registered is used as a bit * array indexed by Xen''s PIRQ value. */ -#define PHYSDEVOP_pirq_eoi_gmfn 17 +#define PHYSDEVOP_pirq_eoi_gmfn_v1 17 +/* + * Register a shared page for the hypervisor to indicate whether the + * guest must issue PHYSDEVOP_eoi. This hypercall is very similar to + * PHYSDEVOP_pirq_eoi_gmfn_v1 but it doesn''t change the semantics of + * PHYSDEVOP_eoi. The page registered is used as a bit array indexed by + * Xen''s PIRQ value. + */ +#define PHYSDEVOP_pirq_eoi_gmfn_v2 28 struct physdev_pirq_eoi_gmfn { /* IN */ xen_pfn_t gmfn; @@ -325,6 +333,12 @@ DEFINE_XEN_GUEST_HANDLE(physdev_pci_device_t); #define PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY XENIRQSTAT_needs_eoi #define PHYSDEVOP_IRQ_SHARED XENIRQSTAT_shared +#if __XEN_INTERFACE_VERSION__ < 0x00040200 +#define PHYSDEVOP_pirq_eoi_gmfn PHYSDEVOP_pirq_eoi_gmfn_v1 +#else +#define PHYSDEVOP_pirq_eoi_gmfn PHYSDEVOP_pirq_eoi_gmfn_v2 +#endif + #endif /* __XEN_PUBLIC_PHYSDEV_H__ */ /* diff --git a/xen/include/public/xen-compat.h b/xen/include/public/xen-compat.h index 2e38003..d8c55bf 100644 --- a/xen/include/public/xen-compat.h +++ b/xen/include/public/xen-compat.h @@ -27,7 +27,7 @@ #ifndef __XEN_PUBLIC_XEN_COMPAT_H__ #define __XEN_PUBLIC_XEN_COMPAT_H__ -#define __XEN_LATEST_INTERFACE_VERSION__ 0x0003020a +#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040200 #if defined(__XEN__) || defined(__XEN_TOOLS__) /* Xen is built with matching headers and implements the latest interface. */ -- 1.7.2.5
The pirq_eoi_map is a bitmap offered by Xen to check which pirqs need to be EOI''d without having to issue an hypercall every time. We use PHYSDEVOP_pirq_eoi_gmfn_v2 to map the bitmap, then if we succeed we use pirq_eoi_map to check whether pirqs need eoi. Changes in v3: - explicitly use PHYSDEVOP_pirq_eoi_gmfn_v2 rather than PHYSDEVOP_pirq_eoi_gmfn; - introduce pirq_check_eoi_map, a function to check if a pirq needs an eoi using the map; -rename pirq_needs_eoi into pirq_needs_eoi_flag; - introduce a function pointer called pirq_needs_eoi that is going to be set to the right implementation depending on the availability of PHYSDEVOP_pirq_eoi_gmfn_v2. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- drivers/xen/events.c | 26 +++++++++++++++++++++++--- include/xen/interface/physdev.h | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/drivers/xen/events.c b/drivers/xen/events.c index 6e075cd..cc5fc40 100644 --- a/drivers/xen/events.c +++ b/drivers/xen/events.c @@ -37,6 +37,7 @@ #include <asm/idle.h> #include <asm/io_apic.h> #include <asm/sync_bitops.h> +#include <asm/xen/page.h> #include <asm/xen/pci.h> #include <asm/xen/hypercall.h> #include <asm/xen/hypervisor.h> @@ -108,6 +109,8 @@ struct irq_info { #define PIRQ_SHAREABLE (1 << 1) static int *evtchn_to_irq; +static unsigned long *pirq_eoi_map; +static bool (*pirq_needs_eoi)(unsigned irq); static DEFINE_PER_CPU(unsigned long [NR_EVENT_CHANNELS/BITS_PER_LONG], cpu_evtchn_mask); @@ -268,10 +271,14 @@ static unsigned int cpu_from_evtchn(unsigned int evtchn) return ret; } -static bool pirq_needs_eoi(unsigned irq) +static bool pirq_check_eoi_map(unsigned irq) { - struct irq_info *info = info_for_irq(irq); + return test_bit(irq, pirq_eoi_map); +} +static bool pirq_needs_eoi_flag(unsigned irq) +{ + struct irq_info *info = info_for_irq(irq); BUG_ON(info->type != IRQT_PIRQ); return info->u.pirq.flags & PIRQ_NEEDS_EOI; @@ -1693,7 +1700,7 @@ void xen_callback_vector(void) {} void __init xen_init_IRQ(void) { - int i; + int i, rc; evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq), GFP_KERNEL); @@ -1707,6 +1714,8 @@ void __init xen_init_IRQ(void) for (i = 0; i < NR_EVENT_CHANNELS; i++) mask_evtchn(i); + pirq_needs_eoi = pirq_needs_eoi_flag; + if (xen_hvm_domain()) { xen_callback_vector(); native_init_IRQ(); @@ -1714,8 +1723,19 @@ void __init xen_init_IRQ(void) * __acpi_register_gsi can point at the right function */ pci_xen_hvm_init(); } else { + struct physdev_pirq_eoi_gmfn eoi_gmfn; + irq_ctx_init(smp_processor_id()); if (xen_initial_domain()) pci_xen_initial_domain(); + + pirq_eoi_map = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO); + eoi_gmfn.gmfn = virt_to_mfn(pirq_eoi_map); + rc = HYPERVISOR_physdev_op(PHYSDEVOP_pirq_eoi_gmfn_v2, &eoi_gmfn); + if (rc != 0) { + free_page((unsigned long) pirq_eoi_map); + pirq_eoi_map = NULL; + } else + pirq_needs_eoi = pirq_check_eoi_map; } } diff --git a/include/xen/interface/physdev.h b/include/xen/interface/physdev.h index c1080d9..1775722 100644 --- a/include/xen/interface/physdev.h +++ b/include/xen/interface/physdev.h @@ -39,6 +39,27 @@ struct physdev_eoi { }; /* + * Register a shared page for the hypervisor to indicate whether the guest + * must issue PHYSDEVOP_eoi. The semantics of PHYSDEVOP_eoi change slightly + * once the guest used this function in that the associated event channel + * will automatically get unmasked. The page registered is used as a bit + * array indexed by Xen''s PIRQ value. + */ +#define PHYSDEVOP_pirq_eoi_gmfn_v1 17 +/* + * Register a shared page for the hypervisor to indicate whether the + * guest must issue PHYSDEVOP_eoi. This hypercall is very similar to + * PHYSDEVOP_pirq_eoi_gmfn_v1 but it doesn''t change the semantics of + * PHYSDEVOP_eoi. The page registered is used as a bit array indexed by + * Xen''s PIRQ value. + */ +#define PHYSDEVOP_pirq_eoi_gmfn_v2 28 +struct physdev_pirq_eoi_gmfn { + /* IN */ + unsigned long gmfn; +}; + +/* * Query the status of an IRQ line. * @arg == pointer to physdev_irq_status_query structure. */ -- 1.7.2.5