Xen PCI + Xen PCI frontend driver.
Subsystems (10)
PATCH v8 1/1 Xen PCI + Xen PCI frontend driver.
This patch set contains the supporting patches and the driver itself for Xen Paravirtualized (PV) domains to use PCI pass-through devices (the git tree is git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen.git devel/xen-pcifront-0.8). This patch-set is also utilized in Stefano's PV on HVM MSI/MSI-X patchset [1].
Changelog since v7 [http://lwn.net/Articles/408418/] posting:
- Added Reviewed-by/Acked-by on some of the patches.
- Fleshed out comments.
- Ditched the io_apic.c idea and used Thomas Gleixner idea.
The Xen PCI frontend driver can be used by PV guests on IOMMU hardware (or IOMMU-less). Without the hardware IOMMU you have a potential security hole wherein a guest domain can use the hardware to map pages outside its memory range and slurp pages up. As such, this is more restricted to a Privileged PV domain, aka - device driver domain (similar to Qubes but a poor-man mechanism [2]).
The first set of patches are specific to the Xen subsystem, where we introduce an IRQ chip for Physical IRQs, along with the supporting harness code:
xen: Don't disable the I/O space
xen: define BIOVEC_PHYS_MERGEABLE()
xen: implement pirq type event channels
xen: identity map gsi->irqs
xen: dynamically allocate irq & event structures
xen: set pirq name to something useful.
xen: statically initialize cpu_evtchn_mask_p
xen: Find an unbound irq number in reverse order (high to low).
xen: Provide a variant of xen_poll_irq with timeout.
xen: fix shared irq device passthrough
The next set of patches expose functionality for module drivers to be able to enumerate and iomap (using the _PAGE_IOMAP flag) PCI devices.
x86/io_apic: add get_nr_irqs_gsi()
x86/PCI: Clean up pci_cache_line_size x86/PCI: make sure _PAGE_IOMAP it set on pci mappings x86/PCI: Export pci_walk_bus function.
The next two patches abstract the MSI/MSI-X architecture calls so that the default native one (used on bare-metal) can be overwritten when running in virtualized mode (right now on Xen). The implementation is a simple function pointer structure.
msi: Introduce default_[teardown|setup]_msi_irqs with fallback.
x86: Introduce x86_msi_ops
Next, the Xen PCI stub driver. I've put it in the same location where other sub-platform PCI drivers are. It hooks up to the
PCI legacy IRQ setup ('pcibios_enable_irq'), and MSI/MSI-X allocation/de-allocation (via the x86_msi_ops introduced in earlier patches).
xen/x86/PCI: Add support for the Xen PCI subsystem
Lastly, the Xen PCI front-end driver which is responsible for hooking up to the PCI configuration read/write methods via the 'pci_scan_bus_parented' call. In essence all pci_conf_read/write in the guest will be tunneled via pcifront_bus_[read|write] methods. The MSI/MSI-X calls will be handled by the Xen-PCI front-end driver as well. We also need to add a new state so updating the XenBus:
xenbus: Xen paravirtualised PCI hotplug support.
xenbus: prevent warnings on unhandled enumeration values
xen-pcifront: Xen PCI frontend driver.
The last three are two bug fixes and updating the MAINTAINERs file with my name:
xen/pci: Request ACS when Xen-SWIOTLB is activated.
MAINTAINERS: Add myself for Xen PCI and Xen SWIOTLB maintainer.
swiotlb-xen: On x86-32 builts, select SWIOTLB instead of depending on it.
The shortlog and the diffstat:
Alex Nixon (3):
xen: Don't disable the I/O space
x86/PCI: Clean up pci_cache_line_size xen/x86/PCI: Add support for the Xen PCI subsystem
Gerd Hoffmann (1):
xen: set pirq name to something useful.
Jeremy Fitzhardinge (7):
xen: define BIOVEC_PHYS_MERGEABLE()
xen: implement pirq type event channels x86/io_apic: add get_nr_irqs_gsi()
xen: identity map gsi->irqs
xen: dynamically allocate irq & event structures
xen: statically initialize cpu_evtchn_mask_p x86/PCI: make sure _PAGE_IOMAP it set on pci mappings
Konrad Rzeszutek Wilk (7):
xen: Find an unbound irq number in reverse order (high to low).
xen: Provide a variant of xen_poll_irq with timeout.
xen: fix shared irq device passthrough
x86/PCI: Export pci_walk_bus function.
xen/pci: Request ACS when Xen-SWIOTLB is activated.
MAINTAINERS: Add myself for Xen PCI and Xen SWIOTLB maintainer.
swiotlb-xen: On x86-32 builts, select SWIOTLB instead of depending on it.
Noboru Iwamatsu (1):
xenbus: prevent warnings on unhandled enumeration values
Ryan Wilson (1):
xen-pcifront: Xen PCI frontend driver.
Stefano Stabellini (1):
x86: Introduce x86_msi_ops
Thomas Gleixner (1):
msi: Introduce default_[teardown|setup]_msi_irqs with fallback.
Yosuke Iwamatsu (1):
xenbus: Xen paravirtualised PCI hotplug support.
MAINTAINERS | 14 + arch/x86/Kconfig | 5 + arch/x86/include/asm/io.h | 13 + arch/x86/include/asm/io_apic.h | 1 + arch/x86/include/asm/pci.h | 33 +- arch/x86/include/asm/pci_x86.h | 1 + arch/x86/include/asm/x86_init.h | 9 + arch/x86/include/asm/xen/pci.h | 53 ++ arch/x86/kernel/apic/io_apic.c | 9 +- arch/x86/kernel/x86_init.c | 7 + arch/x86/pci/Makefile | 1 + arch/x86/pci/common.c | 17 +- arch/x86/pci/i386.c | 2 + arch/x86/pci/xen.c | 147 +++++ arch/x86/xen/enlighten.c | 3 + arch/x86/xen/pci-swiotlb-xen.c | 4 + arch/x86/xen/setup.c | 2 - drivers/block/xen-blkfront.c | 2 + drivers/input/xen-kbdfront.c | 2 + drivers/net/xen-netfront.c | 2 + drivers/pci/Kconfig | 15 + drivers/pci/Makefile | 2 + drivers/pci/bus.c | 1 + drivers/pci/msi.c | 14 +- drivers/pci/xen-pcifront.c | 1157 ++++++++++++++++++++++++++++++++++++ drivers/video/xen-fbfront.c | 2 + drivers/xen/Kconfig | 3 +- drivers/xen/Makefile | 2 +- drivers/xen/biomerge.c | 13 + drivers/xen/events.c | 345 ++++++++++- drivers/xen/xenbus/xenbus_client.c | 2 + include/xen/events.h | 18 + include/xen/interface/io/pciif.h | 112 ++++ include/xen/interface/io/xenbus.h | 8 +- 34 files changed, 1987 insertions(+), 34 deletions(-)
P.S.
[1]. git://xenbits.xen.org/people/sstabellini/linux-pvhvm.git 2.6.36-rc1-pvhvm-pirq-v3
[2]: http://qubes-os.org/ which utilizes hardware IOMMU to run seperate domains wherein each has specific access to hardware.
[3] Some of the authors of the patches have moved on, so their e-mails are bouncing. I am purposly making the 'From' a valid email so that the patches do show up on LKML. The git tree contains their proper old email addresses.
PATCH 1/23 xen: Don't disable the I/O space
From: Alex Nixon <[email protected]>
If a guest domain wants to access PCI devices through the frontend driver (coming later in the patch series), it will need access to the I/O space.
[ Impact: Allow for domU IO access, preparing for pci passthrough ]
--- arch/x86/xen/setup.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
arch/x86/xen/setup.c +0 -2
@@ -260,7 +260,5 @@ void __init xen_arch_setup(void) pm_idle = xen_idle; -paravirt_disable_iospace (); -fiddle_vdso (); }
Signature · 1 line
1.7.0.4
PATCH 2/23 xen: define BIOVEC_PHYS_MERGEABLE()
In reply to Konrad Rzeszutek WilkFrom: Jeremy Fitzhardinge <[email protected]>
Impact: allow Xen control of bio merging
When running in Xen domain with device access, we need to make sure the block subsystem doesn't merge requests across pages which aren't machine physically contiguous. To do this, we define our own BIOVEC_PHYS_MERGEABLE. When CONFIG_XEN isn't enabled, or we're not running in a Xen domain, this has identical behaviour to the normal implementation. When running under Xen, we also make sure the underlying machine pages are the same or adjacent.
--- arch/x86/include/asm/io.h | 13 +++++++++++++ drivers/xen/Makefile | 2 +- drivers/xen/biomerge.c | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletions(-) create mode 100644 drivers/xen/biomerge.c
arch/x86/include/asm/io.h +13 -0
@@ -41,6 +41,8 @@#include <asm-generic/int-ll64.h> #include <asm/page.h> +#include <xen/xen.h> +#define build_mmio_read (name, size, type, reg, barrier) \ static inline type name(const volatile void __iomem *addr) \ { type ret; asm volatile("mov" size " %1,%0":reg (ret) \
@@ -349,6 +351,17 @@ extern void __iomem *early_memremap(resource_size_t phys_addr,extern void early_iounmap (void __iomem *addr,unsigned long size);extern void fixup_early_ioremap (void ); +#ifdef CONFIG_XEN +struct bio_vec ; + +extern bool xen_biovec_phys_mergeable (const struct bio_vec *vec1, +const struct bio_vec *vec2); + +#define BIOVEC_PHYS_MERGEABLE (vec1, vec2) \ + (__BIOVEC_PHYS_MERGEABLE(vec1, vec2) && \ + (!xen_domain() || xen_biovec_phys_mergeable(vec1, vec2))) +#endif /* CONFIG_XEN */ +#define IO_SPACE_LIMIT 0xffff#endif /* _ASM_X86_IO_H */
drivers/xen/Makefile +1 -1
@@ -1,4 +1,4 @@ -obj-y += grant-table.o features.o events.o manage.o +obj-y += grant-table.o features.o events.o manage.o biomerge.o obj-y += xenbus/ nostackp := $(call cc-option, -fno-stack-protector)
drivers/xen/biomerge.c new file +13 -0
@@ -0,0 +1,13 @@ +#include <linux/bio.h> +#include <linux/io.h> +#include <xen/page.h> + +bool xen_biovec_phys_mergeable (const struct bio_vec *vec1, +const struct bio_vec *vec2) +{ +unsigned long mfn1 =pfn_to_mfn (page_to_pfn (vec1->bv_page)); +unsigned long mfn2 =pfn_to_mfn (page_to_pfn (vec2->bv_page)); + +return __BIOVEC_PHYS_MERGEABLE (vec1, vec2) && + ((mfn1 == mfn2) || ((mfn1+1 ) == mfn2)); +}
Signature · 1 line
1.7.0.4
PATCH 3/23 xen: implement pirq type event channels
In reply to Konrad Rzeszutek WilkFrom: Jeremy Fitzhardinge <[email protected]>
A privileged PV Xen domain can get direct access to hardware. In order for this to be useful, it must be able to get hardware interrupts.
Being a PV Xen domain, all interrupts are delivered as event channels. PIRQ event channels are bound to a pirq number and an interrupt vector. When a IO APIC raises a hardware interrupt on that vector, it is delivered as an event channel, which we can deliver to the appropriate device driver(s).
This patch simply implements the infrastructure for dealing with pirq event channels.
[ Impact: integrate hardware interrupts into Xen's event scheme ]
--- drivers/xen/events.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++++- include/xen/events.h | 11 +++ 2 files changed, 252 insertions(+), 2 deletions(-)
drivers/xen/events.c +241 -2
@@ -16,7 +16,7 @@* (typically dom0). * 2. VIRQs, typically used for timers. These are per-cpu events. * 3. IPIs. -* 4. Hardware interrupts. Not supported at present. +* 4. PIRQs - Hardware interrupts. * * Jeremy Fitzhardinge <[email protected]>, XenSource Inc, 2007 */
@@ -46,6 +46,9 @@#include <xen/interface/hvm/hvm_op.h> #include <xen/interface/hvm/params.h> +/* Leave low irqs free for identity mapping */ +#define LEGACY_IRQS 16 +/* * This lock protects updates to the following mapping and reference-count * arrays. The lock does not need to be acquired to read the mapping tables.
@@ -89,10 +92,12 @@ struct irq_infoenum ipi_vector ipi;struct {unsigned short gsi; -unsigned short vector; +unsigned char vector; +unsigned char flags; } pirq; } u; }; +#define PIRQ_NEEDS_EOI (1 << 0)static struct irq_info irq_info[NR_IRQS ];
@@ -113,6 +118,7 @@ static inline unsigned long *cpu_evtchn_mask(int cpu)static struct irq_chip xen_dynamic_chip;static struct irq_chip xen_percpu_chip; +static struct irq_chip xen_pirq_chip;/* Constructor for packed IRQ information. */ static struct irq_info mk_unbound_info (void )
@@ -225,6 +231,15 @@ static unsigned int cpu_from_evtchn(unsigned int evtchn)return ret; } +static bool pirq_needs_eoi (unsigned irq) +{ +struct irq_info *info =info_for_irq (irq); + +BUG_ON (info->type !=IRQT_PIRQ ); + +return info->u.pirq.flags &PIRQ_NEEDS_EOI ; +} +static inline unsigned long active_evtchns (unsigned int cpu,struct shared_info *sh,unsigned int idx)
@@ -366,6 +381,210 @@ static int find_unbound_irq(void)return irq; } +static bool identity_mapped_irq (unsigned irq) +{ +/* only identity map legacy irqs */ +return irq <LEGACY_IRQS ; +} + +static void pirq_unmask_notify (int irq) +{ +struct physdev_eoi eoi = { .irq = irq }; + +if (unlikely (pirq_needs_eoi (irq))) { +int rc =HYPERVISOR_physdev_op (PHYSDEVOP_eoi, &eoi); +WARN_ON (rc); + } +} + +static void pirq_query_unmask (int irq) +{ +struct physdev_irq_status_query irq_status; +struct irq_info *info =info_for_irq (irq); + +BUG_ON (info->type !=IRQT_PIRQ ); + + irq_status.irq = irq; +if (HYPERVISOR_physdev_op (PHYSDEVOP_irq_status_query, &irq_status)) + irq_status.flags =0 ; + + info->u.pirq.flags &= ~PIRQ_NEEDS_EOI ; +if (irq_status.flags & XENIRQSTAT_needs_eoi) + info->u.pirq.flags |=PIRQ_NEEDS_EOI ; +} + +static bool probing_irq (int irq) +{ +struct irq_desc *desc =irq_to_desc (irq); + +return desc && desc->action ==NULL ; +} + +static unsigned int startup_pirq (unsigned int irq) +{ +struct evtchn_bind_pirq bind_pirq; +struct irq_info *info =info_for_irq (irq); +int evtchn =evtchn_from_irq (irq); + +BUG_ON (info->type !=IRQT_PIRQ ); + +if (VALID_EVTCHN (evtchn)) + goto out; + + bind_pirq.pirq = irq; +/* NB. We are happy to share unless we are probing. */ + bind_pirq.flags =probing_irq (irq) ?0 :BIND_PIRQ__WILL_SHARE ; +if (HYPERVISOR_event_channel_op (EVTCHNOP_bind_pirq, &bind_pirq) !=0 ) { +if (!probing_irq (irq)) +printk (KERN_INFO "Failed to obtain physical IRQ %d\n" , + irq); +return 0 ; + } + evtchn = bind_pirq.port; + +pirq_query_unmask (irq); + + evtchn_to_irq[evtchn] = irq; +bind_evtchn_to_cpu (evtchn,0 ); + info->evtchn = evtchn; + +out: +unmask_evtchn (evtchn); +pirq_unmask_notify (irq); + +return 0 ; +} + +static void shutdown_pirq (unsigned int irq) +{ +struct evtchn_close close; +struct irq_info *info =info_for_irq (irq); +int evtchn =evtchn_from_irq (irq); + +BUG_ON (info->type !=IRQT_PIRQ ); + +if (!VALID_EVTCHN (evtchn)) +return ; + +mask_evtchn (evtchn); + + close.port = evtchn; +if (HYPERVISOR_event_channel_op (EVTCHNOP_close, &close) !=0 ) +BUG (); + +bind_evtchn_to_cpu (evtchn,0 ); + evtchn_to_irq[evtchn] =-1 ; + info->evtchn =0 ; +} + +static void enable_pirq (unsigned int irq) +{ +startup_pirq (irq); +} + +static void disable_pirq (unsigned int irq) +{ +} + +static void ack_pirq (unsigned int irq) +{ +int evtchn =evtchn_from_irq (irq); + +move_native_irq (irq); + +if (VALID_EVTCHN (evtchn)) { +mask_evtchn (evtchn); +clear_evtchn (evtchn); + } +} + +static void end_pirq (unsigned int irq) +{ +int evtchn =evtchn_from_irq (irq); +struct irq_desc *desc =irq_to_desc (irq); + +if (WARN_ON (!desc)) +return ; + +if ((desc->status & (IRQ_DISABLED |IRQ_PENDING )) == + (IRQ_DISABLED |IRQ_PENDING )) { +shutdown_pirq (irq); + }else if (VALID_EVTCHN (evtchn)) { +unmask_evtchn (evtchn); +pirq_unmask_notify (irq); + } +} + +static int find_irq_by_gsi (unsigned gsi) +{ +int irq; + +for (irq =0 ; irq <NR_IRQS ; irq++) { +struct irq_info *info =info_for_irq (irq); + +if (info ==NULL || info->type !=IRQT_PIRQ ) +continue ; + +if (gsi_from_irq (irq) == gsi) +return irq; + } + +return -1 ; +} + +/* +* Allocate a physical irq, along with a vector. We don't assign an +* event channel until the irq actually started up. Return an +* existing irq if we've already got one for the gsi. +*/ +int xen_allocate_pirq (unsigned gsi) +{ +int irq; +struct physdev_irq irq_op; + +spin_lock (&irq_mapping_update_lock); + + irq =find_irq_by_gsi (gsi); +if (irq !=-1 ) { +printk (KERN_INFO "xen_allocate_pirq: returning irq %d for gsi %u\n" , + irq, gsi); + goto out;/* XXX need refcount? */ + } + +if (identity_mapped_irq (gsi)) { + irq = gsi; +dynamic_irq_init (irq); + }else + irq =find_unbound_irq (); + +set_irq_chip_and_handler_name (irq, &xen_pirq_chip, + handle_level_irq,"pirq" ); + + irq_op.irq = irq; +if (HYPERVISOR_physdev_op (PHYSDEVOP_alloc_irq_vector, &irq_op)) { +dynamic_irq_cleanup (irq); + irq = -ENOSPC ; + goto out; + } + + irq_info[irq] =mk_pirq_info (0 , gsi, irq_op.vector); + +out: +spin_unlock (&irq_mapping_update_lock); + +return irq; +} + +int xen_vector_from_irq (unsigned irq) +{ +return vector_from_irq (irq); +} + +int xen_gsi_from_irq (unsigned irq) +{ +return gsi_from_irq (irq); +} +int bind_evtchn_to_irq (unsigned int evtchn) {int irq;
@@ -965,6 +1184,26 @@ static struct irq_chip xen_dynamic_chip __read_mostly = { .retrigger = retrigger_dynirq, }; +static struct irq_chip xen_pirq_chip__read_mostly = { + .name ="xen-pirq" , + + .startup = startup_pirq, + .shutdown = shutdown_pirq, + + .enable = enable_pirq, + .unmask = enable_pirq, + + .disable = disable_pirq, + .mask = disable_pirq, + + .ack = ack_pirq, + .end = end_pirq, + + .set_affinity = set_affinity_irq, + + .retrigger = retrigger_dynirq, +}; +static struct irq_chip xen_percpu_chip__read_mostly = { .name ="xen-percpu" ,
include/xen/events.h +11 -0
@@ -63,4 +63,15 @@ int xen_set_callback_via(uint64_t via);void xen_evtchn_do_upcall (struct pt_regs *regs);void xen_hvm_evtchn_do_upcall (void ); +/* Allocate an irq for a physical interrupt, given a gsi. "Legacy" +* GSIs are identity mapped; others are dynamically allocated as +* usual. */ +int xen_allocate_pirq (unsigned gsi); + +/* Return vector allocated to pirq */ +int xen_vector_from_irq (unsigned pirq); + +/* Return gsi allocated to pirq */ +int xen_gsi_from_irq (unsigned pirq); +#endif /* _XEN_EVENTS_H */
Signature · 1 line
1.7.0.4
PATCH 4/23 x86/io_apic: add get_nr_irqs_gsi()
In reply to Konrad Rzeszutek WilkFrom: Jeremy Fitzhardinge <[email protected]>
Impact: new interface to get max GSI
Add get_nr_irqs_gsi() to return nr_irqs_gsi. Xen will use this to determine how many irqs it needs to reserve for hardware irqs.
--- arch/x86/include/asm/io_apic.h | 1 + arch/x86/kernel/apic/io_apic.c | 5 +++++ 2 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/include/asm/io_apic.h +1 -0
@@ -169,6 +169,7 @@ extern void mask_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries);extern int restore_IO_APIC_setup (struct IO_APIC_route_entry **ioapic_entries);extern void probe_nr_irqs_gsi (void ); +extern int get_nr_irqs_gsi (void ); extern int setup_ioapic_entry(int apic, int irq, struct IO_APIC_route_entry *entry,
arch/x86/kernel/apic/io_apic.c +5 -0
@@ -3862,6 +3862,11 @@ void __init probe_nr_irqs_gsi(void)printk (KERN_DEBUG "nr_irqs_gsi: %d\n" , nr_irqs_gsi); } +int get_nr_irqs_gsi (void ) +{ +return nr_irqs_gsi; +} +#ifdef CONFIG_SPARSE_IRQ int __init arch_probe_nr_irqs (void ) {
Signature · 1 line
1.7.0.4
PATCH 5/23 xen: identity map gsi->irqs
In reply to Konrad Rzeszutek WilkFrom: Jeremy Fitzhardinge <[email protected]>
Impact: preserve compat with native
Reserve the lower irq range for use for hardware interrupts so we can identity-map them.
--- drivers/xen/events.c | 23 +++++++++++++++++------ 1 files changed, 17 insertions(+), 6 deletions(-)
drivers/xen/events.c +17 -6
@@ -33,6 +33,7 @@#include <asm/ptrace.h> #include <asm/irq.h> #include <asm/idle.h> +#include <asm/io_apic.h> #include <asm/sync_bitops.h> #include <asm/xen/hypercall.h> #include <asm/xen/hypervisor.h>
@@ -46,9 +47,6 @@#include <xen/interface/hvm/hvm_op.h> #include <xen/interface/hvm/params.h> -/* Leave low irqs free for identity mapping */ -#define LEGACY_IRQS 16 -/* * This lock protects updates to the following mapping and reference-count * arrays. The lock does not need to be acquired to read the mapping tables.
@@ -351,12 +349,24 @@ static void unmask_evtchn(int port)put_cpu (); } +static int get_nr_hw_irqs (void ) +{ +int ret =1 ; + +#ifdef CONFIG_X86_IO_APIC + ret =get_nr_irqs_gsi (); +#endif + +return ret; +} +static int find_unbound_irq (void ) {int irq;struct irq_desc *desc; +int start =get_nr_hw_irqs (); -for (irq =0 ; irq < nr_irqs; irq++) { +for (irq = start; irq < nr_irqs; irq++) { desc =irq_to_desc (irq);/* only 0->15 have init'd desc; handle irq > 16 */ if (desc ==NULL )
@@ -383,8 +393,8 @@ static int find_unbound_irq(void)static bool identity_mapped_irq (unsigned irq) { -/* only identity map legacy irqs */ -return irq <LEGACY_IRQS ; +/* identity map all the hardware irqs */ +return irq <get_nr_hw_irqs (); }static void pirq_unmask_notify (int irq)
@@ -553,6 +563,7 @@ int xen_allocate_pirq(unsigned gsi)if (identity_mapped_irq (gsi)) { irq = gsi; +irq_to_desc_alloc_node (irq,0 );dynamic_irq_init (irq); }else irq =find_unbound_irq ();
Signature · 1 line
1.7.0.4
PATCH 6/23 xen: dynamically allocate irq & event structures
In reply to Konrad Rzeszutek WilkFrom: Jeremy Fitzhardinge <[email protected]>
Dynamically allocate the irq_info and evtchn_to_irq arrays, so that
1) the irq_info array scales to the actual number of possible irqs, and 2) we don't needlessly increase the static size of the kernel when we aren't running under Xen.
Derived on patch from Mike Travis <[email protected]>.
[Impact: reduce memory usage ]
[v2: Conflict in drivers/xen/events.c: Replaced alloc_bootmen with kcalloc ]
--- drivers/xen/events.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
drivers/xen/events.c +10 -6
@@ -28,6 +28,7 @@#include <linux/string.h> #include <linux/bootmem.h> #include <linux/slab.h> +#include <linux/irqnr.h> #include <asm/desc.h> #include <asm/ptrace.h>
@@ -97,11 +98,9 @@ struct irq_info };#define PIRQ_NEEDS_EOI (1 << 0) -static struct irq_info irq_info[NR_IRQS ]; +static struct irq_info *irq_info; -static int evtchn_to_irq[NR_EVENT_CHANNELS ] = { - [0 ...NR_EVENT_CHANNELS -1 ] =-1 -}; +static int *evtchn_to_irq;struct cpu_evtchn_s {unsigned long bits[NR_EVENT_CHANNELS /BITS_PER_LONG ]; };
@@ -529,7 +528,7 @@ static int find_irq_by_gsi(unsigned gsi) {int irq; -for (irq =0 ; irq <NR_IRQS ; irq++) { +for (irq =0 ; irq < nr_irqs; irq++) {struct irq_info *info =info_for_irq (irq);if (info ==NULL || info->type !=IRQT_PIRQ )
@@ -1269,7 +1268,12 @@ void __init xen_init_IRQ(void) cpu_evtchn_mask_p =kcalloc (nr_cpu_ids,sizeof (struct cpu_evtchn_s ),GFP_KERNEL ); -BUG_ON (cpu_evtchn_mask_p ==NULL ); + irq_info =kcalloc (nr_irqs,sizeof (*irq_info),GFP_KERNEL ); + + evtchn_to_irq =kcalloc (NR_EVENT_CHANNELS ,sizeof (*evtchn_to_irq), +GFP_KERNEL ); +for (i =0 ; i <NR_EVENT_CHANNELS ; i++) + evtchn_to_irq[i] =-1 ;init_evtchn_cpu_bindings ();
Signature · 1 line
1.7.0.4
PATCH 7/23 xen: set pirq name to something useful.
In reply to Konrad Rzeszutek WilkFrom: Gerd Hoffmann <[email protected]>
Impact: cleanup
Make pirq show useful information in /proc/interrupts
[v2: Removed the parts for arch/x86/xen/pci.c ]
--- drivers/xen/events.c | 4 ++-- include/xen/events.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/xen/events.c +2 -2
@@ -546,7 +546,7 @@ static int find_irq_by_gsi(unsigned gsi)* event channel until the irq actually started up. Return an * existing irq if we've already got one for the gsi. */ -int xen_allocate_pirq (unsigned gsi) +int xen_allocate_pirq (unsigned gsi,char *name) {int irq;struct physdev_irq irq_op;
@@ -568,7 +568,7 @@ int xen_allocate_pirq(unsigned gsi) irq =find_unbound_irq ();set_irq_chip_and_handler_name (irq, &xen_pirq_chip, - handle_level_irq,"pirq" ); + handle_level_irq, name); irq_op.irq = irq;if (HYPERVISOR_physdev_op (PHYSDEVOP_alloc_irq_vector, &irq_op)) {
include/xen/events.h +1 -1
@@ -66,7 +66,7 @@ void xen_hvm_evtchn_do_upcall(void);/* Allocate an irq for a physical interrupt, given a gsi. "Legacy" * GSIs are identity mapped; others are dynamically allocated as * usual. */ -int xen_allocate_pirq (unsigned gsi); +int xen_allocate_pirq (unsigned gsi,char *name);/* Return vector allocated to pirq */ int xen_vector_from_irq (unsigned pirq);
Signature · 1 line
1.7.0.4
PATCH 8/23 xen: statically initialize cpu_evtchn_mask_p
In reply to Konrad Rzeszutek WilkFrom: Jeremy Fitzhardinge <[email protected]>
Sometimes cpu_evtchn_mask_p can get used early, before it has been allocated. Statically initialize it with an initdata version to catch any early references.
--- drivers/xen/events.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
drivers/xen/events.c +6 -1
@@ -104,7 +104,12 @@ static int *evtchn_to_irq;struct cpu_evtchn_s {unsigned long bits[NR_EVENT_CHANNELS /BITS_PER_LONG ]; }; -static struct cpu_evtchn_s *cpu_evtchn_mask_p; + +static __initdata struct cpu_evtchn_s init_evtchn_mask = { + .bits[0 ... (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ] = ~0ul , +}; +static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; +static inline unsigned long *cpu_evtchn_mask (int cpu) {return cpu_evtchn_mask_p[cpu].bits;
Signature · 1 line
1.7.0.4
Re: [PATCH 08/23] xen: statically initialize cpu_evtchn_mask_p
drivers/xen/events.c static int *evtchn_to_irq; · line 115
Quoted 10 lines · Konrad Rzeszutek Wilk
drivers/xen/events.c +6
-1-static struct cpu_evtchn_s *cpu_evtchn_mask_p; + +static __initdata struct cpu_evtchn_s init_evtchn_mask = { + .bits[0 ... (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ] = ~0ul , +}; +static struct cpu_evtchn_s *cpu_evtchn_mask_p =&init_evtchn_mask; +static inline unsigned long *cpu_evtchn_mask (int cpu) {return cpu_evtchn_mask_p[cpu].bits;
This causes a modpost warning:
WARNING: drivers/xen/built-in.o(.data+0x0): Section mismatch in reference from the variable cpu_evtchn_mask_p to the variable .init.data:init_evtchn_mask
The variable cpu_evtchn_mask_p references
the variable __initdata init_evtchn_mask
If the reference is valid then annotate the
variable with __init* or __refdata (see linux/init.h) or name the variable:
*driver, *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console,
This is harmless, the variable is initialized to non-init data in an __init function. The added noise is ugly, though.
Paolo
Re: [Xen-devel] Re: [PATCH 08/23] xen: statically initialize cpu_evtchn_mask_p
Quoted 21 lines · Paolo Bonzini
Review
Quoted 10 lines · Konrad Rzeszutek Wilk
(quoted diff) +6
-1-static struct cpu_evtchn_s *cpu_evtchn_mask_p; + +static __initdata struct cpu_evtchn_s init_evtchn_mask = { + .bits[0 ... (NR_EVENT_CHANNELS/BITS_PER_LONG)-1] = ~0ul, +}; +static struct cpu_evtchn_s *cpu_evtchn_mask_p =&init_evtchn_mask; + static inline unsigned long *cpu_evtchn_mask(int cpu) { return cpu_evtchn_mask_p[cpu].bits;This causes a modpost warning:
WARNING: drivers/xen/built-in.o(.data+0x0): Section mismatch in reference from the variable
cpu_evtchn_mask_pto the variable .init.data:init_evtchn_maskThe variable
cpu_evtchn_mask_preferences
the variable__initdatainit_evtchn_mask
Quoted 6 lines
If the reference is valid then annotate the
variable with __init* or__refdata(seelinux/init.h) or name the variable:
*driver,*_template,*_timer,*_sht,*_ops,*_probe,*_probe_one,*_console,This is harmless, the variable is initialized to non-init data in an
__initfunction. The added noise is ugly, though.
Does this help? If I understand the comment which precedes __initref correctly it is intended to address precisely this situation.
Ian.
8<---------
xen: events: mark cpu_evtchn_mask_p as __refdata
This variable starts out pointing at init_evtchn_mask which is marked __initdata but is set to point to a non-init data region in xen_init_IRQ which is itself an __init function so this is safe.
drivers/xen/events.c +1 -1
@@ -114,7 +114,7 @@ struct cpu_evtchn_s {static __initdata struct cpu_evtchn_s init_evtchn_mask = { .bits[0 ... (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ] = ~0ul , }; -static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; +static struct __refdata cpu_evtchn_s *cpu_evtchn_mask_p =
&init_evtchn_mask;
static inline unsigned long *cpu_evtchn_mask(int cpu) {
Re: Re: [PATCH 08/23] xen: statically initialize cpu_evtchn_mask_p
Quoted 56 lines · Ian Campbell
Quoted 21 lines · Paolo Bonzini
Review
Quoted 10 lines · Konrad Rzeszutek Wilk
(quoted diff) +6
-1-static struct cpu_evtchn_s *cpu_evtchn_mask_p; + +static __initdata struct cpu_evtchn_s init_evtchn_mask = { + .bits[0 ... (NR_EVENT_CHANNELS/BITS_PER_LONG)-1] = ~0ul, +}; +static struct cpu_evtchn_s *cpu_evtchn_mask_p =&init_evtchn_mask; + static inline unsigned long *cpu_evtchn_mask(int cpu) { return cpu_evtchn_mask_p[cpu].bits;This causes a modpost warning:
WARNING: drivers/xen/built-in.o(.data+0x0): Section mismatch in reference from the variable
cpu_evtchn_mask_pto the variable .init.data:init_evtchn_maskThe variable
cpu_evtchn_mask_preferences
the variable__initdatainit_evtchn_maskQuoted 6 lines
If the reference is valid then annotate the
variable with __init* or__refdata(seelinux/init.h) or name the variable:
*driver,*_template,*_timer,*_sht,*_ops,*_probe,*_probe_one,*_console,This is harmless, the variable is initialized to non-init data in an
__initfunction. The added noise is ugly, though.Does this help? If I understand the comment which precedes
__initrefcorrectly it is intended to address precisely this situation.Ian.
8<---------xen: events: mark
cpu_evtchn_mask_pas__refdataThis variable starts out pointing at
init_evtchn_maskwhich is marked__initdatabut is set to point to a non-init data region inxen_init_IRQwhich is itself an__initfunction so this is safe.Signed-off-by Ian Campbell <[email protected]>drivers/xen/events.c +1
-1@@ -114,7 +114,7 @@ struct cpu_evtchn_s {static __initdata struct cpu_evtchn_s init_evtchn_mask = { .bits[0 ... (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ] = ~0ul , }; -static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; +static struct __refdata cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask;static inline unsigned long *cpu_evtchn_mask (int cpu)
Quoted 2 lines
{
This does indeed fix it. Although you need __refdata to follow the complete struct name 'struct cpu_evtchn_s' rather than just 'struct', i.e.
drivers/xen/events.c +1 -1
@@ -114,7 +114,7 @@ struct cpu_evtchn_s {static __initdata struct cpu_evtchn_s init_evtchn_mask = { .bits[0 ... (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ] = ~0ul , }; -static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; +static struct cpu_evtchn_s __refdata *cpu_evtchn_mask_p =
&init_evtchn_mask;
static inline unsigned long *cpu_evtchn_mask(int cpu) {
Ian, are you going to push this to lkml in one of your batches?
Drew
Re: Re: [PATCH 08/23] xen: statically initialize cpu_evtchn_mask_p
Quoted 79 lines · Andrew Jones
Quoted 56 lines · Ian Campbell
Quoted 21 lines · Paolo Bonzini
Review
Quoted 10 lines · Konrad Rzeszutek Wilk
(quoted diff) +6
-1-static struct cpu_evtchn_s *cpu_evtchn_mask_p; + +static __initdata struct cpu_evtchn_s init_evtchn_mask = { + .bits[0 ... (NR_EVENT_CHANNELS/BITS_PER_LONG)-1] = ~0ul, +}; +static struct cpu_evtchn_s *cpu_evtchn_mask_p =&init_evtchn_mask; + static inline unsigned long *cpu_evtchn_mask(int cpu) { return cpu_evtchn_mask_p[cpu].bits;This causes a modpost warning:
WARNING: drivers/xen/built-in.o(.data+0x0): Section mismatch in reference from the variable
cpu_evtchn_mask_pto the variable .init.data:init_evtchn_maskThe variable
cpu_evtchn_mask_preferences
the variable__initdatainit_evtchn_maskQuoted 6 lines
If the reference is valid then annotate the
variable with __init* or__refdata(seelinux/init.h) or name the variable:
*driver,*_template,*_timer,*_sht,*_ops,*_probe,*_probe_one,*_console,This is harmless, the variable is initialized to non-init data in an
__initfunction. The added noise is ugly, though.Does this help? If I understand the comment which precedes
__initrefcorrectly it is intended to address precisely this situation.Ian.
8<---------xen: events: mark
cpu_evtchn_mask_pas__refdataThis variable starts out pointing at
init_evtchn_maskwhich is marked__initdatabut is set to point to a non-init data region inxen_init_IRQwhich is itself an__initfunction so this is safe.Signed-off-by Ian Campbell <[email protected]>drivers/xen/events.c +1
-1@@ -114,7 +114,7 @@ struct cpu_evtchn_s {static __initdata struct cpu_evtchn_s init_evtchn_mask = { .bits[0 ... (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ] = ~0ul , }; -static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; +static struct __refdata cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask;static inline unsigned long *cpu_evtchn_mask (int cpu)Quoted 2 lines
{
This does indeed fix it. Although you need
__refdatato follow the complete struct name 'structcpu_evtchn_s' rather than just 'struct', i.e.drivers/xen/events.c +1
-1@@ -114,7 +114,7 @@ struct cpu_evtchn_s {static __initdata struct cpu_evtchn_s init_evtchn_mask = { .bits[0 ... (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ] = ~0ul , }; -static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; +static struct cpu_evtchn_s __refdata *cpu_evtchn_mask_p = &init_evtchn_mask;static inline unsigned long *cpu_evtchn_mask (int cpu){
Quoted 1 line
Ian, are you going to push this to lkml in one of your batches?
Sure.
Can I add an Acked- and/or Tested-by from you?
Ian.
Re: Re: [PATCH 08/23] xen: statically initialize cpu_evtchn_mask_p
Quoted 80 lines · Ian Campbell
Quoted 79 lines · Andrew Jones
Quoted 56 lines · Ian Campbell
Quoted 21 lines · Paolo Bonzini
Review
Quoted 10 lines · Konrad Rzeszutek Wilk
(quoted diff) +6
-1-static struct cpu_evtchn_s *cpu_evtchn_mask_p; + +static __initdata struct cpu_evtchn_s init_evtchn_mask = { + .bits[0 ... (NR_EVENT_CHANNELS/BITS_PER_LONG)-1] = ~0ul, +}; +static struct cpu_evtchn_s *cpu_evtchn_mask_p =&init_evtchn_mask; + static inline unsigned long *cpu_evtchn_mask(int cpu) { return cpu_evtchn_mask_p[cpu].bits;This causes a modpost warning:
WARNING: drivers/xen/built-in.o(.data+0x0): Section mismatch in reference from the variable
cpu_evtchn_mask_pto the variable .init.data:init_evtchn_maskThe variable
cpu_evtchn_mask_preferences
the variable__initdatainit_evtchn_maskQuoted 6 lines
If the reference is valid then annotate the
variable with __init* or__refdata(seelinux/init.h) or name the variable:
*driver,*_template,*_timer,*_sht,*_ops,*_probe,*_probe_one,*_console,This is harmless, the variable is initialized to non-init data in an
__initfunction. The added noise is ugly, though.Does this help? If I understand the comment which precedes
__initrefcorrectly it is intended to address precisely this situation.Ian.
8<---------xen: events: mark
cpu_evtchn_mask_pas__refdataThis variable starts out pointing at
init_evtchn_maskwhich is marked__initdatabut is set to point to a non-init data region inxen_init_IRQwhich is itself an__initfunction so this is safe.Signed-off-by Ian Campbell <[email protected]>drivers/xen/events.c +1
-1@@ -114,7 +114,7 @@ struct cpu_evtchn_s {static __initdata struct cpu_evtchn_s init_evtchn_mask = { .bits[0 ... (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ] = ~0ul , }; -static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; +static struct __refdata cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask;static inline unsigned long *cpu_evtchn_mask (int cpu)Quoted 2 lines
{
This does indeed fix it. Although you need
__refdatato follow the complete struct name 'structcpu_evtchn_s' rather than just 'struct', i.e.drivers/xen/events.c +1
-1@@ -114,7 +114,7 @@ struct cpu_evtchn_s {static __initdata struct cpu_evtchn_s init_evtchn_mask = { .bits[0 ... (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ] = ~0ul , }; -static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; +static struct cpu_evtchn_s __refdata *cpu_evtchn_mask_p = &init_evtchn_mask;static inline unsigned long *cpu_evtchn_mask (int cpu){
Quoted 6 lines
Quoted 1 line
Ian, are you going to push this to lkml in one of your batches?
Sure.
Can I add an Acked- and/or Tested-by from you?
Sure. Either-or or both. I ack it and have tested it.
Drew
PATCH 9/23 xen: Find an unbound irq number in reverse order (high to low).
In reply to Konrad Rzeszutek WilkIn earlier Xen Linux kernels, the IRQ mapping was a straight 1:1 and the find_unbound_irq started looking around 256 for open IRQs and up. IRQs from 0 to 255 were reserved for PCI devices. Previous to this patch, the 'find_unbound_irq' started looking at get_nr_hw_irqs() number. For privileged domain where the ACPI information is available that returns the upper-bound of what the GSIs. For non-privileged PV domains, where ACPI is no-existent the get_nr_hw_irqs() reports the IRQ_LEGACY (16). With PCI passthrough enabled, and with PCI cards that have IRQs pinned to a higher number than 16 we collide with previously allocated IRQs. Specifically the PCI IRQs collide with the IPI's for Xen functions (as they are allocated earlier).
For example:
00:00.11 USB Controller: ATI Technologies Inc SB700 USB OHCI1 Controller (prog-if 10 [OHCI])
... Interrupt: pin A routed to IRQ 18
[root@localhost ~]# cat /proc/interrupts | head
CPU0 CPU1 CPU2
16: 38186 0 0 xen-dyn-virq timer0 17: 149 0 0 xen-dyn-ipi spinlock0 18: 962 0 0 xen-dyn-ipi resched0
and when the USB controller is loaded, the kernel reports:
IRQ handler type mismatch for IRQ 18
current handler: resched0
One way to fix this is to reverse the logic when looking for un-used IRQ numbers and start with the highest available number. With that, we would get:
CPU0 CPU1 CPU2
... snip ..
292: 35 0 0 xen-dyn-ipi callfunc0 293: 3992 0 0 xen-dyn-ipi resched0 294: 224 0 0 xen-dyn-ipi spinlock0 295: 57183 0 0 xen-dyn-virq timer0 NMI: 0 0 0 Non-maskable interrupts
.. snip ..
And interrupts for PCI cards are now accessible.
This patch also includes the fix, found by Ian Campbell, titled "xen: fix off-by-one error in find_unbound_irq."
--- drivers/xen/events.c | 24 +++++++++++++++++++----- 1 files changed, 19 insertions(+), 5 deletions(-)
drivers/xen/events.c +19 -5
@@ -370,7 +370,11 @@ static int find_unbound_irq(void)struct irq_desc *desc;int start =get_nr_hw_irqs (); -for (irq = start; irq < nr_irqs; irq++) { +if (start == nr_irqs) + goto no_irqs; + +/* nr_irqs is a magic value. Must not use it.*/ +for (irq = nr_irqs-1 ; irq > start; irq--) { desc =irq_to_desc (irq);/* only 0->15 have init'd desc; handle irq > 16 */ if (desc ==NULL )
@@ -383,8 +387,8 @@ static int find_unbound_irq(void)break ; } -if (irq == nr_irqs) -panic ("No available IRQ to bind to: increase nr_irqs!\n" ); +if (irq == start) + goto no_irqs; desc =irq_to_desc_alloc_node (irq,0 );if (WARN_ON (desc ==NULL ))
@@ -393,6 +397,9 @@ static int find_unbound_irq(void)dynamic_irq_init_keep_chip_data (irq);return irq; + +no_irqs: +panic ("No available IRQ to bind to: increase nr_irqs!\n" ); }static bool identity_mapped_irq (unsigned irq)
@@ -546,8 +553,15 @@ static int find_irq_by_gsi(unsigned gsi)return -1 ; } -/* -* Allocate a physical irq, along with a vector. We don't assign an +/* xen_allocate_irq might allocate irqs from the top down, as a +* consequence don't assume that the irq number returned has a low value +* or can be used as a pirq number unless you know otherwise. +* +* One notable exception is when xen_allocate_irq is called passing an +* hardware gsi as argument, in that case the irq number returned +* matches the gsi number passed as first argument. + +* Note: We don't assign an * event channel until the irq actually started up. Return an * existing irq if we've already got one for the gsi. */
Signature · 1 line
1.7.0.4
PATCH 10/23 xen: Provide a variant of xen_poll_irq with timeout.
In reply to Konrad Rzeszutek WilkThe 'xen_poll_irq_timeout' provides a method to pass in the poll timeout for IRQs if requested. We also export those two poll functions as Xen PCI fronted uses them.
--- drivers/xen/events.c | 17 ++++++++++++----- include/xen/events.h | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/xen/events.c +12 -5
@@ -1140,7 +1140,7 @@ void xen_clear_irq_pending(int irq)if (VALID_EVTCHN (evtchn))clear_evtchn (evtchn); } - +EXPORT_SYMBOL (xen_clear_irq_pending);void xen_set_irq_pending (int irq) {int evtchn =evtchn_from_irq (irq);
@@ -1160,9 +1160,9 @@ bool xen_test_irq_pending(int irq)return ret; } -/* Poll waiting for an irq to become pending. In the usual case, the -irq will be disabled so it won't deliver an interrupt. */ -void xen_poll_irq (int irq) +/* Poll waiting for an irq to become pending with timeout. In the usual case, +* the irq will be disabled so it won't deliver an interrupt. */ +void xen_poll_irq_timeout (int irq,u64 timeout) {evtchn_port_t evtchn =evtchn_from_irq (irq);
@@ -1170,13 +1170,20 @@ void xen_poll_irq(int irq)struct sched_poll poll; poll.nr_ports =1 ; - poll.timeout =0 ; + poll.timeout = timeout;set_xen_guest_handle (poll.ports, &evtchn);if (HYPERVISOR_sched_op (SCHEDOP_poll, &poll) !=0 )BUG (); } } +EXPORT_SYMBOL (xen_poll_irq_timeout); +/* Poll waiting for an irq to become pending. In the usual case, the +* irq will be disabled so it won't deliver an interrupt. */ +void xen_poll_irq (int irq) +{ +xen_poll_irq_timeout (irq,0 /* no timeout */ ); +}void xen_irq_resume (void ) {
include/xen/events.h +4 -0
@@ -53,6 +53,10 @@ bool xen_test_irq_pending(int irq);irq will be disabled so it won't deliver an interrupt. */ void xen_poll_irq (int irq); +/* Poll waiting for an irq to become pending with a timeout. In the usual case, +* the irq will be disabled so it won't deliver an interrupt. */ +void xen_poll_irq_timeout (int irq,u64 timeout); +/* Determine the IRQ which is bound to an event channel */ unsigned irq_from_evtchn (unsigned int evtchn);
Signature · 1 line
1.7.0.4
PATCH 11/23 xen: fix shared irq device passthrough
In reply to Konrad Rzeszutek WilkIn driver/xen/events.c, whether bind_pirq is shareable or not is determined by desc->action is NULL or not. But in __setup_irq, startup(irq) is invoked before desc->action is assigned with new action. So desc->action in startup_irq is always NULL, and bind_pirq is always not shareable. This results in pt_irq_create_bind failure when passthrough a device which shares irq to other devices.
This patch doesn't use probing_irq to determine if pirq is shareable or not, instead set shareable flag in irq_info according to trigger mode in xen_allocate_pirq. Set level triggered interrupts shareable. Thus use this flag to set bind_pirq flag accordingly.
[v2: arch/x86/xen/pci.c no more, so file skipped]
--- drivers/xen/events.c | 11 ++++++++--- include/xen/events.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-)
drivers/xen/events.c +8 -3
@@ -97,6 +97,7 @@ struct irq_info } u; };#define PIRQ_NEEDS_EOI (1 << 0) +#define PIRQ_SHAREABLE (1 << 1)static struct irq_info *irq_info;
@@ -446,6 +447,7 @@ static unsigned int startup_pirq(unsigned int irq)struct evtchn_bind_pirq bind_pirq;struct irq_info *info =info_for_irq (irq);int evtchn =evtchn_from_irq (irq); +int rc;BUG_ON (info->type !=IRQT_PIRQ );
@@ -454,8 +456,10 @@ static unsigned int startup_pirq(unsigned int irq) bind_pirq.pirq = irq;/* NB. We are happy to share unless we are probing. */ - bind_pirq.flags =probing_irq (irq) ?0 :BIND_PIRQ__WILL_SHARE ; -if (HYPERVISOR_event_channel_op (EVTCHNOP_bind_pirq, &bind_pirq) !=0 ) { + bind_pirq.flags = info->u.pirq.flags &PIRQ_SHAREABLE ? +BIND_PIRQ__WILL_SHARE :0 ; + rc =HYPERVISOR_event_channel_op (EVTCHNOP_bind_pirq, &bind_pirq); +if (rc !=0 ) {if (!probing_irq (irq))printk (KERN_INFO "Failed to obtain physical IRQ %d\n" , irq);
@@ -565,7 +569,7 @@ static int find_irq_by_gsi(unsigned gsi)* event channel until the irq actually started up. Return an * existing irq if we've already got one for the gsi. */ -int xen_allocate_pirq (unsigned gsi,char *name) +int xen_allocate_pirq (unsigned gsi,int shareable,char *name) {int irq;struct physdev_irq irq_op;
@@ -597,6 +601,7 @@ int xen_allocate_pirq(unsigned gsi, char *name) } irq_info[irq] =mk_pirq_info (0 , gsi, irq_op.vector); + irq_info[irq].u.pirq.flags |= shareable ?PIRQ_SHAREABLE :0 ; out:spin_unlock (&irq_mapping_update_lock);
include/xen/events.h +1 -1
@@ -70,7 +70,7 @@ void xen_hvm_evtchn_do_upcall(void);/* Allocate an irq for a physical interrupt, given a gsi. "Legacy" * GSIs are identity mapped; others are dynamically allocated as * usual. */ -int xen_allocate_pirq (unsigned gsi,char *name); +int xen_allocate_pirq (unsigned gsi,int shareable,char *name);/* Return vector allocated to pirq */ int xen_vector_from_irq (unsigned pirq);
Signature · 1 line
1.7.0.4
PATCH 12/23 x86/PCI: Clean up pci_cache_line_size
In reply to Konrad Rzeszutek WilkFrom: Alex Nixon <[email protected]>
Separate out x86 cache_line_size initialisation code into its own function (so it can be shared by Xen later in this patch series)
[ Impact: cleanup ]
--- arch/x86/include/asm/pci_x86.h | 1 + arch/x86/pci/common.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-)
arch/x86/include/asm/pci_x86.h +1 -0
@@ -47,6 +47,7 @@ enum pci_bf_sort_state {extern unsigned int pcibios_max_latency;void pcibios_resource_survey (void ); +void pcibios_set_cache_line_size (void );/* pci-pc.c */
arch/x86/pci/common.c +10 -7
@@ -421,16 +421,10 @@ struct pci_bus * __devinit pcibios_scan_root(int busnum)return bus; } - -int __init pcibios_init (void ) +void __init pcibios_set_cache_line_size (void ) {struct cpuinfo_x86 *c = &boot_cpu_data; -if (!raw_pci_ops) { -printk (KERN_WARNING "PCI: System does not support PCI\n" ); -return 0 ; - } -/* * Set PCI cacheline size to that of the CPU if the CPU has reported it. * (For older CPUs that don't support cpuid, we se it to 32 bytes
@@ -445,7 +439,16 @@ int __init pcibios_init(void) pci_dfl_cache_line_size =32 >>2 ;printk (KERN_DEBUG "PCI: Unknown cacheline size. Setting to 32 bytes\n" ); } +} + +int __init pcibios_init (void ) +{ +if (!raw_pci_ops) { +printk (KERN_WARNING "PCI: System does not support PCI\n" ); +return 0 ; + } +pcibios_set_cache_line_size ();pcibios_resource_survey ();if (pci_bf_sort >= pci_force_bf)
Signature · 1 line
1.7.0.4
PATCH 13/23 x86/PCI: make sure _PAGE_IOMAP it set on pci mappings
In reply to Konrad Rzeszutek WilkFrom: Jeremy Fitzhardinge <[email protected]>
When mapping pci space via /sys or /proc, make sure we're really doing a hardware mapping by setting _PAGE_IOMAP.
[ Impact: bugfix; make PCI mappings map the right pages ]
--- arch/x86/pci/i386.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/pci/i386.c +2 -0
@@ -311,6 +311,8 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,*/ prot |= _PAGE_CACHE_UC_MINUS; + prot |= _PAGE_IOMAP;/* creating a mapping for IO */ + vma->vm_page_prot =__pgprot (prot); if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
Signature · 1 line
1.7.0.4
Re: [PATCH 13/23] x86/PCI: make sure _PAGE_IOMAP it set on pci mappings
Quoted 22 lines · On Tue, 12 Oct 2010 11:44:21 -0400 Konrad Rzeszutek Wilk…
From: Jeremy Fitzhardinge <[email protected]>
When mapping pci space via /sys or /proc, make sure we're really doing a hardware mapping by setting
_PAGE_IOMAP.[ Impact: bugfix; make PCI mappings map the right pages ]
Signed-off-by Jeremy Fitzhardinge <[email protected]>Reviewed-by Konrad Rzeszutek Wilk <[email protected]>Reviewed-by "H. Peter Anvin" <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Cc Jesse Barnes <[email protected]>--- arch/x86/pci/i386.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)arch/x86/pci/i386.c +0
-0
arch/x86/pci/i386.c int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, · line 318
Quoted 8 lines
arch/x86/pci/i386.c +2
-0@@ -311,6 +311,8 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,*/ prot |= _PAGE_CACHE_UC_MINUS; + prot |= _PAGE_IOMAP;/* creating a mapping for IO */ + vma->vm_page_prot =__pgprot (prot); if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
Looks fine.
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
PATCH 14/23 x86/PCI: Export pci_walk_bus function.
In reply to Konrad Rzeszutek WilkIn preperation of modularizing Xen-pcifront the pci_walk_bus needs to be exported so that the xen-pcifront module can walk call the pci subsystem to walk the PCI devices and claim them.
--- drivers/pci/bus.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/pci/bus.c +1 -0
@@ -299,6 +299,7 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), }up_read (&pci_bus_sem); } +EXPORT_SYMBOL_GPL (pci_walk_bus);EXPORT_SYMBOL (pci_bus_alloc_resource);EXPORT_SYMBOL_GPL (pci_bus_add_device);
Signature · 1 line
1.7.0.4
PATCH 15/23 msi: Introduce default_[teardown|setup]_msi_irqs with fallback.
In reply to Konrad Rzeszutek WilkFrom: Thomas Gleixner <[email protected]>
Introduce an override for the arch_[teardown|setup]_msi_irqs that can be utilized to fallback to the default arch_* code.
If a platform wants to utilize the code paths defined
in driver/pci/msi.c it has to define HAVE_DEFAULT_MSI_TEARDOWN_IRQS or HAVE_DEFAULT_MSI_SETUP_IRQS. Otherwise the old mechanism of over-ridding the arch_* works fine.
--- drivers/pci/msi.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
drivers/pci/msi.c +12 -2
@@ -35,7 +35,12 @@ int arch_msi_check_device(struct pci_dev *dev, int nvec, int type)#endif #ifndef arch_setup_msi_irqs -int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +# define arch_setup_msi_irqs default_setup_msi_irqs +# define HAVE_DEFAULT_MSI_SETUP_IRQS +#endif + +#ifdef HAVE_DEFAULT_MSI_SETUP_IRQS +int default_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) {struct msi_desc *entry;int ret;
@@ -60,7 +65,12 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)#endif #ifndef arch_teardown_msi_irqs -void arch_teardown_msi_irqs (struct pci_dev *dev) +# define arch_teardown_msi_irqs default_teardown_msi_irqs +# define HAVE_DEFAULT_MSI_TEARDOWN_IRQS +#endif + +#ifdef HAVE_DEFAULT_MSI_TEARDOWN_IRQS +void default_teardown_msi_irqs (struct pci_dev *dev) {struct msi_desc *entry;
Signature · 1 line
1.7.0.4
PATCH 16/23 x86: Introduce x86_msi_ops
In reply to Konrad Rzeszutek WilkFrom: Stefano Stabellini <[email protected]>
Introduce an x86 specific indirect mechanism to setup MSIs. The MSI setup functions become function pointers in an x86_msi_ops struct, that defaults to the implementation in io_apic.c and msi.c.
--- arch/x86/include/asm/pci.h | 33 +++++++++++++++++++++++++++++++-- arch/x86/include/asm/x86_init.h | 9 +++++++++ arch/x86/kernel/apic/io_apic.c | 4 ++-- arch/x86/kernel/x86_init.c | 7 +++++++ 4 files changed, 49 insertions(+), 4 deletions(-)
arch/x86/include/asm/pci.h +31 -2
@@ -7,6 +7,7 @@#include <linux/string.h> #include <asm/scatterlist.h> #include <asm/io.h> +#include <asm/x86_init.h> #ifdef __KERNEL__
@@ -94,8 +95,36 @@ static inline void early_quirks(void) { }extern void pci_iommu_alloc (void ); -/* MSI arch hook */ -#define arch_setup_msi_irqs arch_setup_msi_irqs +#ifdef CONFIG_PCI_MSI +/* MSI arch specific hooks */ +static inline int x86_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +{ +return x86_msi.setup_msi_irqs (dev, nvec, type); +} + +static inline void x86_teardown_msi_irqs (struct pci_dev *dev) +{ + x86_msi.teardown_msi_irqs (dev); +} + +static inline void x86_teardown_msi_irq (unsigned int irq) +{ + x86_msi.teardown_msi_irq (irq); +} +#define arch_setup_msi_irqs x86_setup_msi_irqs +#define arch_teardown_msi_irqs x86_teardown_msi_irqs +#define arch_teardown_msi_irq x86_teardown_msi_irq +/* implemented in arch/x86/kernel/apic/io_apic. */ +int native_setup_msi_irqs (struct pci_dev *dev,int nvec,int type); +void native_teardown_msi_irq (unsigned int irq); +/* default to the implementation in drivers/lib/msi.c */ +#define HAVE_DEFAULT_MSI_TEARDOWN_IRQS +void default_teardown_msi_irqs (struct pci_dev *dev); +#else +#define native_setup_msi_irqs NULL +#define native_teardown_msi_irq NULL +#define default_teardown_msi_irqs NULL +#endif #define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys)
arch/x86/include/asm/x86_init.h +9 -0
@@ -154,9 +154,18 @@ struct x86_platform_ops {int (*i8042_detect)(void ); }; +struct pci_dev ; + +struct x86_msi_ops { +int (*setup_msi_irqs)(struct pci_dev *dev,int nvec,int type); +void (*teardown_msi_irq)(unsigned int irq); +void (*teardown_msi_irqs)(struct pci_dev *dev); +}; +extern struct x86_init_ops x86_init;extern struct x86_cpuinit_ops x86_cpuinit;extern struct x86_platform_ops x86_platform; +extern struct x86_msi_ops x86_msi;extern void x86_init_noop (void );extern void x86_init_uint_noop (unsigned int unused);
arch/x86/kernel/apic/io_apic.c +2 -2
@@ -3533,7 +3533,7 @@ static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq)return 0 ; } -int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +int native_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) {unsigned int irq;int ret, sub_handle;
@@ -3594,7 +3594,7 @@ error:return ret; } -void arch_teardown_msi_irq (unsigned int irq) +void native_teardown_msi_irq (unsigned int irq) {destroy_irq (irq); }
arch/x86/kernel/x86_init.c +7 -0
@@ -6,10 +6,12 @@#include <linux/init.h> #include <linux/ioport.h> #include <linux/module.h> +#include <linux/pci.h> #include <asm/bios_ebda.h> #include <asm/paravirt.h> #include <asm/pci_x86.h> +#include <asm/pci.h> #include <asm/mpspec.h> #include <asm/setup.h> #include <asm/apic.h>
@@ -99,3 +101,8 @@ struct x86_platform_ops x86_platform = { };EXPORT_SYMBOL_GPL (x86_platform); +struct x86_msi_ops x86_msi = { + .setup_msi_irqs = native_setup_msi_irqs, + .teardown_msi_irq = native_teardown_msi_irq, + .teardown_msi_irqs = default_teardown_msi_irqs, +};
Signature · 1 line
1.7.0.4
PATCH 17/23 xen/x86/PCI: Add support for the Xen PCI subsystem
In reply to Konrad Rzeszutek WilkFrom: Alex Nixon <[email protected]>
The frontend stub lives in arch/x86/pci/xen.c, alongside other sub-arch PCI init code (e.g. olpc.c).
It provides a mechanism for Xen PCI frontend to setup/destroy legacy interrupts, MSI/MSI-X, and PCI configuration operations.
--- arch/x86/Kconfig | 5 ++ arch/x86/include/asm/xen/pci.h | 53 ++++++++++++++ arch/x86/pci/Makefile | 1 + arch/x86/pci/xen.c | 147 ++++++++++++++++++++++++++++++++++++++++ arch/x86/xen/enlighten.c | 3 + drivers/xen/events.c | 32 ++++++++- include/xen/events.h | 3 + 7 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 arch/x86/include/asm/xen/pci.h create mode 100644 arch/x86/pci/xen.c
arch/x86/Kconfig +5 -0
@@ -1925,6 +1925,11 @@ config PCI_OLPC def_bool y depends on PCI && OLPC && (PCI_GOOLPC || PCI_GOANY) +config PCI_XEN + def_bool y + depends on PCI && XEN + select SWIOTLB_XEN + config PCI_DOMAINS def_bool y depends on PCI
arch/x86/include/asm/xen/pci.h new file +53 -0
53 lines not on this page · raw message
arch/x86/pci/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_PCI_BIOS) += pcbios.o obj-$(CONFIG_PCI_MMCONFIG) += mmconfig_$(BITS).o direct.o mmconfig-shared.o obj-$(CONFIG_PCI_DIRECT) += direct.o obj-$(CONFIG_PCI_OLPC) += olpc.o +obj-$(CONFIG_PCI_XEN) += xen.o obj-y += fixup.o obj-$(CONFIG_ACPI) += acpi.o
arch/x86/pci/xen.c new file +147 -0
147 lines not on this page · raw message
arch/x86/xen/enlighten.c +3 -0
@@ -45,6 +45,7 @@#include <asm/paravirt.h> #include <asm/apic.h> #include <asm/page.h> +#include <asm/xen/pci.h> #include <asm/xen/hypercall.h> #include <asm/xen/hypervisor.h> #include <asm/fixmap.h>
@@ -1220,6 +1221,8 @@ asmlinkage void __init xen_start_kernel(void)add_preferred_console ("xenboot" ,0 ,NULL );add_preferred_console ("tty" ,0 ,NULL );add_preferred_console ("hvc" ,0 ,NULL ); +if (pci_xen) + x86_init.pci.arch_init = pci_xen_init; }else {/* Make sure ACS will be enabled */ pci_request_acs ();
drivers/xen/events.c +30 -2
@@ -583,7 +583,9 @@ int xen_allocate_pirq(unsigned gsi, int shareable, char *name) goto out;/* XXX need refcount? */ } -if (identity_mapped_irq (gsi)) { +/* If we are a PV guest, we don't have GSIs (no ACPI passed). Therefore +* we are using the !xen_initial_domain() to drop in the function.*/ +if (identity_mapped_irq (gsi) || !xen_initial_domain ()) { irq = gsi;irq_to_desc_alloc_node (irq,0 );dynamic_irq_init (irq);
@@ -594,7 +596,13 @@ int xen_allocate_pirq(unsigned gsi, int shareable, char *name) handle_level_irq, name); irq_op.irq = irq; -if (HYPERVISOR_physdev_op (PHYSDEVOP_alloc_irq_vector, &irq_op)) { + irq_op.vector =0 ; + +/* Only the privileged domain can do this. For non-priv, the pcifront +* driver provides a PCI bus that does the call to do exactly +* this in the priv domain. */ +if (xen_initial_domain () && +HYPERVISOR_physdev_op (PHYSDEVOP_alloc_irq_vector, &irq_op)) {dynamic_irq_cleanup (irq); irq = -ENOSPC ; goto out;
@@ -609,6 +617,26 @@ out:return irq; } +int xen_destroy_irq (int irq) +{ +struct irq_desc *desc; +int rc = -ENOENT ; + +spin_lock (&irq_mapping_update_lock); + + desc =irq_to_desc (irq); +if (!desc) + goto out; + + irq_info[irq] =mk_unbound_info (); + +dynamic_irq_cleanup (irq); + +out: +spin_unlock (&irq_mapping_update_lock); +return rc; +} +int xen_vector_from_irq (unsigned irq) {return vector_from_irq (irq);
include/xen/events.h +3 -0
@@ -72,6 +72,9 @@ void xen_hvm_evtchn_do_upcall(void);* usual. */ int xen_allocate_pirq (unsigned gsi,int shareable,char *name); +/* De-allocates the above mentioned physical interrupt. */ +int xen_destroy_irq (int irq); +/* Return vector allocated to pirq */ int xen_vector_from_irq (unsigned pirq);
Signature · 1 line
1.7.0.4
PATCH 18/23 xenbus: Xen paravirtualised PCI hotplug support.
In reply to Konrad Rzeszutek WilkFrom: Yosuke Iwamatsu <[email protected]>
The Xen PCI front driver adds two new states that are utilizez for PCI hotplug support. This is a patch pulled from the linux-2.6-xen-sparse tree.
--- drivers/xen/xenbus/xenbus_client.c | 2 ++ include/xen/interface/io/xenbus.h | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletions(-)
drivers/xen/xenbus/xenbus_client.c +2 -0
@@ -50,6 +50,8 @@ const char *xenbus_strstate(enum xenbus_state state) [ XenbusStateConnected ] = "Connected", [ XenbusStateClosing ] = "Closing", [ XenbusStateClosed ] = "Closed", + [XenbusStateReconfiguring] = "Reconfiguring", + [XenbusStateReconfigured] = "Reconfigured", };return (state <ARRAY_SIZE (name)) ? name[state] :"INVALID" ; }
include/xen/interface/io/xenbus.h +7 -1
@@ -27,8 +27,14 @@ enum xenbus_state XenbusStateClosing =5 ,/* The device is being closed due to an error or an unplug event. */ - XenbusStateClosed =6 + XenbusStateClosed =6 , +/* +* Reconfiguring: The device is being reconfigured. +*/ + XenbusStateReconfiguring =7 , + + XenbusStateReconfigured =8 };#endif /* _XEN_PUBLIC_IO_XENBUS_H */
Signature · 1 line
1.7.0.4
PATCH 19/23 xenbus: prevent warnings on unhandled enumeration values
In reply to Konrad Rzeszutek WilkFrom: Noboru Iwamatsu <[email protected]>
XenbusStateReconfiguring/XenbusStateReconfigured were introduced by c/s 437, but aren't handled in many switch statements.
.. also pulled from the linux-2.6-sparse-tree tree.
--- drivers/block/xen-blkfront.c | 2 ++ drivers/input/xen-kbdfront.c | 2 ++ drivers/net/xen-netfront.c | 2 ++ drivers/video/xen-fbfront.c | 2 ++ 4 files changed, 8 insertions(+), 0 deletions(-)
drivers/block/xen-blkfront.c +2 -0
@@ -1125,6 +1125,8 @@ static void blkback_changed(struct xenbus_device *dev,case XenbusStateInitialising:case XenbusStateInitWait:case XenbusStateInitialised: +case XenbusStateReconfiguring: +case XenbusStateReconfigured:case XenbusStateUnknown:case XenbusStateClosed:break ;
drivers/input/xen-kbdfront.c +2 -0
@@ -276,6 +276,8 @@ static void xenkbd_backend_changed(struct xenbus_device *dev,switch (backend_state) {case XenbusStateInitialising:case XenbusStateInitialised: +case XenbusStateReconfiguring: +case XenbusStateReconfigured:case XenbusStateUnknown:case XenbusStateClosed:break ;
drivers/net/xen-netfront.c +2 -0
@@ -1610,6 +1610,8 @@ static void backend_changed(struct xenbus_device *dev,switch (backend_state) {case XenbusStateInitialising:case XenbusStateInitialised: +case XenbusStateReconfiguring: +case XenbusStateReconfigured:case XenbusStateConnected:case XenbusStateUnknown:case XenbusStateClosed:
drivers/video/xen-fbfront.c +2 -0
@@ -631,6 +631,8 @@ static void xenfb_backend_changed(struct xenbus_device *dev,switch (backend_state) {case XenbusStateInitialising:case XenbusStateInitialised: +case XenbusStateReconfiguring: +case XenbusStateReconfigured:case XenbusStateUnknown:case XenbusStateClosed:break ;
Signature · 1 line
1.7.0.4
PATCH 20/23 xen-pcifront: Xen PCI frontend driver.
In reply to Konrad Rzeszutek WilkFrom: Ryan Wilson <[email protected]>
This is a port of the 2.6.18 Xen PCI front driver with fixes to make it build under 2.6.34 and later (for the full list of
changes: git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen.git
historic/xen-pcifront-0.1). It also includes the fixes
to make it work properly.
--- drivers/pci/Kconfig | 15 + drivers/pci/Makefile | 2 + drivers/pci/xen-pcifront.c | 1157 ++++++++++++++++++++++++++++++++++++++ include/xen/interface/io/pciif.h | 112 ++++ 4 files changed, 1286 insertions(+), 0 deletions(-) create mode 100644 drivers/pci/xen-pcifront.c create mode 100644 include/xen/interface/io/pciif.h
drivers/pci/Kconfig +15 -0
@@ -40,6 +40,21 @@ config PCI_STUB When in doubt, say N. +config XEN_PCIDEV_FRONTEND + tristate "Xen PCI Frontend" + depends on PCI && X86 && XEN + select HOTPLUG + select PCI_XEN + default y + help + The PCI device frontend driver allows the kernel to import arbitrary + PCI devices from a PCI backend to support PCI driver domains. + +config XEN_PCIDEV_FE_DEBUG + bool + depends on PCI_DEBUG + default n + config HT_IRQ bool "Interrupts on hypertransport devices" default y
drivers/pci/Makefile +2 -0
@@ -65,6 +65,8 @@ obj-$(CONFIG_PCI_SYSCALL) += syscall.o obj-$(CONFIG_PCI_STUB) += pci-stub.o +obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o + ifeq ($(CONFIG_PCI_DEBUG),y) EXTRA_CFLAGS += -DDEBUG endif
drivers/pci/xen-pcifront.c new file +1157 -0
1,157 lines not on this page · raw message
include/xen/interface/io/pciif.h new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH 20/23] xen-pcifront: Xen PCI frontend driver.
Quoted 16 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
drivers/pci/Kconfig +8
-0@@ -40,6 +40,21 @@ config PCI_STUB When in doubt, say N. +config XEN_PCIDEV_FRONTEND + tristate "Xen PCI Frontend" + depends on PCI && X86 && XEN + select HOTPLUG + select PCI_XEN + default y + help + The PCI device frontend driver allows the kernel to importarbitrary
drivers/pci/Kconfig config PCI_STUB · line 56
Quoted 6 lines
drivers/pci/Kconfig +6
-0+ PCI devices from a PCI backend to support PCI driver domains. + +config XEN_PCIDEV_FE_DEBUG + bool + depends on PCI_DEBUG + default n
A bool without prompt, (pointlessly) defaulting to 'n', and without getting selected anywhere has no way to get set to 'y'...
Quoted 25 lines
drivers/pci/Kconfig +1
-0+ config HT_IRQ bool "Interrupts on hypertransport devices" default ydrivers/pci/xen-pcifront.c new file +18
-0@@ -0,0 +1,1157 @@ +/* +* Xen PCI Frontend. +* +* Author: Ryan Wilson <[email protected]> +*/ +#include <linux/module.h> +#include <linux/init.h> +#include <linux/mm.h> +#include <xen/xenbus.h> +#include <xen/events.h> +#include <xen/grant_table.h> +#include <xen/page.h> +#include <linux/spinlock.h> +#include <linux/pci.h> +#include <linux/msi.h> +#include <xen/xenbus.h> +#include <xen/interface/io/pciif.h> +#include <asm/xen/pci.h>
drivers/pci/xen-pcifront.c line 28
Quoted 10 lines
drivers/pci/xen-pcifront.c new file +10
-0+#include <linux/interrupt.h> +#include <asm/atomic.h> +#include <linux/workqueue.h> +#include <linux/bitops.h> +#include <linux/time.h> + + +#ifndef __init_refok +#define __init_refok +#endif
???
Quoted 43 lines
drivers/pci/xen-pcifront.c new file +43
-0+ +#define INVALID_GRANT_REF (0) +#define INVALID_EVTCHN (-1) + + +struct pci_bus_entry { +struct list_head list; +struct pci_bus *bus; +}; + +#define _PDEVB_op_active (0) +#define PDEVB_op_active (1 << (_PDEVB_op_active)) + +struct pcifront_device { +struct xenbus_device *xdev; +struct list_head root_buses; + +int evtchn; +int gnt_ref; + +int irq; + +/* Lock this when doing any operations in sh_info */ +spinlock_t sh_info_lock; +struct xen_pci_sharedinfo *sh_info; +struct work_struct op_work; +unsigned long flags; + +}; + +struct pcifront_sd { +int domain; +struct pcifront_device *pdev; +}; + +static inline struct pcifront_device * +pcifront_get_pdev (struct pcifront_sd *sd) +{ +return sd->pdev; +} + +static inline void pcifront_init_sd(struct pcifront_sd *sd, + unsigned int domain, unsigned int bus,
drivers/pci/xen-pcifront.c line 81
Quoted 10 lines
drivers/pci/xen-pcifront.c new file +10
-0+ struct pcifront_device *pdev) +{ + sd->domain = domain; + sd->pdev = pdev; +} + +static inline void pcifront_setup_root_resources (struct pci_bus *bus, +struct pcifront_sd *sd) +{ +}
???
drivers/pci/xen-pcifront.c line 84
Quoted 3 lines
drivers/pci/xen-pcifront.c new file +3
-0+ + +DEFINE_SPINLOCK (pcifront_dev_lock);
static?
Quoted 2 lines
...
+voidpcifront_do_aer(struct work_struct *data)
static?
Quoted 2 lines
...
+irqreturn_tpcifront_handler_aer(int irq, void *dev)
static?
Quoted 2 lines
...
+intpcifront_connect(struct pcifront_device *pdev)
static?
Quoted 2 lines
...
+voidpcifront_disconnect(struct pcifront_device *pdev)
static?
drivers/pci/xen-pcifront.c line 750
Quoted 9 lines
...
drivers/pci/xen-pcifront.c new file +8
-0+static void free_pdev (struct pcifront_device *pdev) +{ +dev_dbg (&pdev->xdev->dev,"freeing pdev @ 0x%p\n" , pdev); + +pcifront_free_roots (pdev); + +/*For PCIE_AER error handling job*/ +flush_scheduled_work ();
if (pdev->irq > 0)
drivers/pci/xen-pcifront.c line 758
Quoted 8 lines
drivers/pci/xen-pcifront.c new file +8
-0+unbind_from_irqhandler (pdev->irq, pdev); + +if (pdev->evtchn !=INVALID_EVTCHN ) +xenbus_free_evtchn (pdev->xdev, pdev->evtchn); + +if (pdev->gnt_ref !=INVALID_GRANT_REF ) +gnttab_end_foreign_access (pdev->gnt_ref,0 /* r/w page */ , + (unsigned long )pdev->sh_info);
else free_page((unsigned long)pdev->sh_info);
Quoted 15 lines
drivers/pci/xen-pcifront.c new file +15
-0+ +dev_set_drvdata (&pdev->xdev->dev,NULL ); + +kfree (pdev); +} + +static int pcifront_publish_info (struct pcifront_device *pdev) +{ +int err =0 ; +struct xenbus_transaction trans; + + err =xenbus_grant_ring (pdev->xdev,virt_to_mfn (pdev->sh_info)); +if (err <0 ) + goto out; +
drivers/pci/xen-pcifront.c line 783
Quoted 10 lines
drivers/pci/xen-pcifront.c new file +10
-0+ pdev->gnt_ref = err; + + err =xenbus_alloc_evtchn (pdev->xdev, &pdev->evtchn); +if (err) + goto out; + + err =bind_evtchn_to_irqhandler (pdev->evtchn, pcifront_handler_aer, +0 ,"pcifront" , pdev); +if (err <0 ) { +xenbus_free_evtchn (pdev->xdev, pdev->evtchn);
You're leaking the grant ref here. I think it's better to not do any cleanup here, and instead call free_pdev() on error in pcifront_xenbus_probe() (see below).
drivers/pci/xen-pcifront.c line 839
Quoted 13 lines
drivers/pci/xen-pcifront.c new file +12
-0+xenbus_dev_fatal (pdev->xdev, err,"Failed to bind evtchn to " +"irqhandler.\n" ); +return err; + } + pdev->irq = err; +static int __devinit pcifront_try_connect (struct pcifront_device *pdev) +{ +int err = -EFAULT ; +int i, num_roots, len; +char str[64 ]; +unsigned int domain, bus; +
The original code had a per-device lock here and in subsequent functions. Is this being dropped due to implicit serialization through only running in the context of the single xenbus thread?
Quoted 5 lines
...
drivers/pci/xen-pcifront.c new file +4
-0+static int pcifront_xenbus_probe (struct xenbus_device *xdev, +const struct xenbus_device_id *id) +{ +int err =0 ;
drivers/pci/xen-pcifront.c line 1108
Quoted 10 lines
drivers/pci/xen-pcifront.c new file +10
-0+struct pcifront_device *pdev =alloc_pdev (xdev); + +if (pdev ==NULL ) { + err = -ENOMEM ; +xenbus_dev_fatal (xdev, err, +"Error allocating pcifront_device struct" ); + goto out; + } + + err =pcifront_publish_info (pdev);
if (err) free_pdev(pdev);
drivers/pci/xen-pcifront.c line 185
Quoted 5 lines
drivers/pci/xen-pcifront.c new file +4
-0+ +out: +return err; +}
Jan
Re: [PATCH 20/23] xen-pcifront: Xen PCI frontend driver.
Hey Jan,
Thank you for taking your time to look at this patch. Will fix up, test it, and if there are no issues, have it ready tomorrow.
Quoted 193 lines · On Wednesday 13 October 2010 05:36:59 Jan Beulich wrote:
Quoted 18 lines
Quoted 2 lines
Quoted 2 lines
On 12.10.10 at 17:44, Konrad Rzeszutek Wilk <[email protected]> wrote:
drivers/pci/Kconfig +8
-0@@ -40,6 +40,21 @@ config PCI_STUB When in doubt, say N. +config XEN_PCIDEV_FRONTEND + tristate "Xen PCI Frontend" + depends on PCI && X86 && XEN + select HOTPLUG + select PCI_XEN + default y + help + The PCI device frontend driver allows the kernel to importarbitrary
drivers/pci/Kconfig config PCI_STUB · line 56
Quoted 6 lines
drivers/pci/Kconfig +6
-0+ PCI devices from a PCI backend to support PCI driver domains. + +config XEN_PCIDEV_FE_DEBUG + bool + depends on PCI_DEBUG + default nA bool without prompt, (pointlessly) defaulting to 'n', and without getting selected anywhere has no way to get set to 'y'...
Quoted 25 lines
drivers/pci/Kconfig +1
-0+ config HT_IRQ bool "Interrupts on hypertransport devices" default ydrivers/pci/xen-pcifront.c new file +18
-0@@ -0,0 +1,1157 @@ +/* +* Xen PCI Frontend. +* +* Author: Ryan Wilson <[email protected]> +*/ +#include <linux/module.h> +#include <linux/init.h> +#include <linux/mm.h> +#include <xen/xenbus.h> +#include <xen/events.h> +#include <xen/grant_table.h> +#include <xen/page.h> +#include <linux/spinlock.h> +#include <linux/pci.h> +#include <linux/msi.h> +#include <xen/xenbus.h> +#include <xen/interface/io/pciif.h> +#include <asm/xen/pci.h> drivers/pci/xen-pcifront.c line 28
Quoted 10 lines
drivers/pci/xen-pcifront.c new file +10
-0+#include <linux/interrupt.h> +#include <asm/atomic.h> +#include <linux/workqueue.h> +#include <linux/bitops.h> +#include <linux/time.h> + + +#ifndef __init_refok +#define __init_refok +#endif ???
Quoted 43 lines
drivers/pci/xen-pcifront.c new file +43
-0+ +#define INVALID_GRANT_REF (0) +#define INVALID_EVTCHN (-1) + + +struct pci_bus_entry { +struct list_head list; +struct pci_bus *bus; +}; + +#define _PDEVB_op_active (0) +#define PDEVB_op_active (1 << (_PDEVB_op_active)) + +struct pcifront_device { +struct xenbus_device *xdev; +struct list_head root_buses; + +int evtchn; +int gnt_ref; + +int irq; + +/* Lock this when doing any operations in sh_info */ +spinlock_t sh_info_lock; +struct xen_pci_sharedinfo *sh_info; +struct work_struct op_work; +unsigned long flags; + +}; + +struct pcifront_sd { +int domain; +struct pcifront_device *pdev; +}; + +static inline struct pcifront_device * +pcifront_get_pdev (struct pcifront_sd *sd) +{ +return sd->pdev; +} + +static inline void pcifront_init_sd(struct pcifront_sd *sd, + unsigned int domain, unsigned int bus,drivers/pci/xen-pcifront.c line 81
Quoted 10 lines
drivers/pci/xen-pcifront.c new file +10
-0+ struct pcifront_device *pdev) +{ + sd->domain = domain; + sd->pdev = pdev; +} + +static inline void pcifront_setup_root_resources (struct pci_bus *bus, +struct pcifront_sd *sd) +{ +}???
drivers/pci/xen-pcifront.c line 84
Quoted 3 lines
drivers/pci/xen-pcifront.c new file +3
-0+ + +DEFINE_SPINLOCK (pcifront_dev_lock);static?
Quoted 2 lines
...
+voidpcifront_do_aer(struct work_struct *data)static?
Quoted 2 lines
...
+irqreturn_tpcifront_handler_aer(int irq, void *dev)static?
Quoted 2 lines
...
+intpcifront_connect(struct pcifront_device *pdev)static?
Quoted 2 lines
...
+voidpcifront_disconnect(struct pcifront_device *pdev)static?
drivers/pci/xen-pcifront.c line 750
Quoted 9 lines
...
drivers/pci/xen-pcifront.c new file +8
-0+static void free_pdev (struct pcifront_device *pdev) +{ +dev_dbg (&pdev->xdev->dev,"freeing pdev @ 0x%p\n" , pdev); + +pcifront_free_roots (pdev); + +/*For PCIE_AER error handling job*/ +flush_scheduled_work ();if (pdev->irq > 0)drivers/pci/xen-pcifront.c line 758
Quoted 8 lines
drivers/pci/xen-pcifront.c new file +8
-0+unbind_from_irqhandler (pdev->irq, pdev); + +if (pdev->evtchn !=INVALID_EVTCHN ) +xenbus_free_evtchn (pdev->xdev, pdev->evtchn); + +if (pdev->gnt_ref !=INVALID_GRANT_REF ) +gnttab_end_foreign_access (pdev->gnt_ref,0 /* r/w page */ , + (unsigned long )pdev->sh_info);else free_page((unsigned long)pdev->sh_info);Quoted 21 lines
drivers/pci/xen-pcifront.c new file +21
-0+ +dev_set_drvdata (&pdev->xdev->dev,NULL ); + +kfree (pdev); +} + +static int pcifront_publish_info (struct pcifront_device *pdev) +{ +int err =0 ; +struct xenbus_transaction trans; + + err =xenbus_grant_ring (pdev->xdev,virt_to_mfn (pdev->sh_info)); +if (err <0 ) + goto out; + + pdev->gnt_ref = err; + + err =xenbus_alloc_evtchn (pdev->xdev, &pdev->evtchn); +if (err) + goto out; +
Quoted 8 lines
drivers/pci/xen-pcifront.c line 783
Quoted 4 lines
drivers/pci/xen-pcifront.c new file +4
-0+ err =bind_evtchn_to_irqhandler (pdev->evtchn, pcifront_handler_aer, +0 ,"pcifront" , pdev); +if (err <0 ) { +xenbus_free_evtchn (pdev->xdev, pdev->evtchn);You're leaking the grant ref here. I think it's better to not do any cleanup here, and instead call
free_pdev()on error inpcifront_xenbus_probe()(see below).
Excellent. Will do!
Quoted 10 lines
Quoted 10 lines
drivers/pci/xen-pcifront.c new file +8
-0+xenbus_dev_fatal (pdev->xdev, err,"Failed to bind evtchn to " +"irqhandler.\n" ); +return err; + } + pdev->irq = err; +static int __devinit pcifront_try_connect (struct pcifront_device *pdev) +{ +int err = -EFAULT ;
Quoted 8 lines
drivers/pci/xen-pcifront.c line 839
Quoted 4 lines
drivers/pci/xen-pcifront.c new file +4
-0+int i, num_roots, len; +char str[64 ]; +unsigned int domain, bus; +The original code had a per-device lock here and in subsequent functions. Is this being dropped due to implicit serialization through only running in the context of the single xenbus thread?
Yes!
Quoted 27 lines
Quoted 6 lines
...
drivers/pci/xen-pcifront.c new file +4
-0+static int pcifront_xenbus_probe (struct xenbus_device *xdev, +const struct xenbus_device_id *id) +{ +int err =0 ;drivers/pci/xen-pcifront.c line 1108
Quoted 10 lines
drivers/pci/xen-pcifront.c new file +10
-0+struct pcifront_device *pdev =alloc_pdev (xdev); + +if (pdev ==NULL ) { + err = -ENOMEM ; +xenbus_dev_fatal (xdev, err, +"Error allocating pcifront_device struct" ); + goto out; + } + + err =pcifront_publish_info (pdev);if (err) free_pdev(pdev);drivers/pci/xen-pcifront.c line 185
Quoted 5 lines
drivers/pci/xen-pcifront.c new file +4
-0+ +out: +return err; +}Jan
Re: [PATCH 20/23] xen-pcifront: Xen PCI frontend driver.
Quoted 4 lines · Konrad Rzeszutek Wilk
Hey Jan,
Thank you for taking your time to look at this patch. Will fix up, test it, and if there are no issues, have it ready tomorrow.
Attached (and inline) is the updated version of this patch. If I missed anything please do point it out to me! If this is to your satisfaction, can I put a Reviewed-by tag on the patch?
Thank you.
Quoted 1 line
From
7e865c880aa5942c4c22bd67618b2e9fc1788da6Mon Sep 17 00:00:00 2001
From: Ryan Wilson <[email protected]>
Date: Mon, 2 Aug 2010 21:31:05 -0400
Subject: [PATCH] xen-pcifront: Xen PCI frontend driver.
This is a port of the 2.6.18 Xen PCI front driver with fixes to make it build under 2.6.34 and later (for the full list of
changes: git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen.git
historic/xen-pcifront-0.1). It also includes the fixes
to make it work properly.
--- drivers/pci/Kconfig | 21 + drivers/pci/Makefile | 2 + drivers/pci/xen-pcifront.c | 1152 ++++++++++++++++++++++++++++++++++++++ include/xen/interface/io/pciif.h | 112 ++++ 4 files changed, 1287 insertions(+), 0 deletions(-) create mode 100644 drivers/pci/xen-pcifront.c create mode 100644 include/xen/interface/io/pciif.h
drivers/pci/Kconfig +21 -0
@@ -40,6 +40,27 @@ config PCI_STUB When in doubt, say N. +config XEN_PCIDEV_FRONTEND + tristate "Xen PCI Frontend" + depends on PCI && X86 && XEN + select HOTPLUG + select PCI_XEN + default y + help + The PCI device frontend driver allows the kernel to import arbitrary + PCI devices from a PCI backend to support PCI driver domains. + +config XEN_PCIDEV_FE_DEBUG + bool "Xen PCI Frontend debugging" + depends on XEN_PCIDEV_FRONTEND && PCI_DEBUG + help + Say Y here if you want the Xen PCI frontend to produce a bunch of debug + messages to the system log. Select this if you are having a + problem with Xen PCI frontend support and want to see more of what is + going on. + + When in doubt, say N. + config HT_IRQ bool "Interrupts on hypertransport devices" default y
drivers/pci/Makefile +2 -0
@@ -65,6 +65,8 @@ obj-$(CONFIG_PCI_SYSCALL) += syscall.o obj-$(CONFIG_PCI_STUB) += pci-stub.o +obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o + ifeq ($(CONFIG_PCI_DEBUG),y) EXTRA_CFLAGS += -DDEBUG endif
drivers/pci/xen-pcifront.c new file +1152 -0
1,152 lines not on this page · raw message
include/xen/interface/io/pciif.h new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
1.7.1
Quoted 1 line
From
7e865c880aa5942c4c22bd67618b2e9fc1788da6Mon Sep 17 00:00:00 2001
From: Ryan Wilson <[email protected]>
Date: Mon, 2 Aug 2010 21:31:05 -0400
Subject: [PATCH] xen-pcifront: Xen PCI frontend driver.
This is a port of the 2.6.18 Xen PCI front driver with fixes to make it build under 2.6.34 and later (for the full list of
changes: git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen.git
historic/xen-pcifront-0.1). It also includes the fixes
to make it work properly.
--- drivers/pci/Kconfig | 21 + drivers/pci/Makefile | 2 + drivers/pci/xen-pcifront.c | 1152 ++++++++++++++++++++++++++++++++++++++ include/xen/interface/io/pciif.h | 112 ++++ 4 files changed, 1287 insertions(+), 0 deletions(-) create mode 100644 drivers/pci/xen-pcifront.c create mode 100644 include/xen/interface/io/pciif.h
drivers/pci/Kconfig +21 -0
@@ -40,6 +40,27 @@ config PCI_STUB When in doubt, say N. +config XEN_PCIDEV_FRONTEND + tristate "Xen PCI Frontend" + depends on PCI && X86 && XEN + select HOTPLUG + select PCI_XEN + default y + help + The PCI device frontend driver allows the kernel to import arbitrary + PCI devices from a PCI backend to support PCI driver domains. + +config XEN_PCIDEV_FE_DEBUG + bool "Xen PCI Frontend debugging" + depends on XEN_PCIDEV_FRONTEND && PCI_DEBUG + help + Say Y here if you want the Xen PCI frontend to produce a bunch of debug + messages to the system log. Select this if you are having a + problem with Xen PCI frontend support and want to see more of what is + going on. + + When in doubt, say N. + config HT_IRQ bool "Interrupts on hypertransport devices" default y
drivers/pci/Makefile +2 -0
@@ -65,6 +65,8 @@ obj-$(CONFIG_PCI_SYSCALL) += syscall.o obj-$(CONFIG_PCI_STUB) += pci-stub.o +obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o + ifeq ($(CONFIG_PCI_DEBUG),y) EXTRA_CFLAGS += -DDEBUG endif
drivers/pci/xen-pcifront.c new file +1152 -0
1,152 lines not on this page · raw message
include/xen/interface/io/pciif.h new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
1.7.1
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
[Xen-devel] Re: [PATCH 20/23] xen-pcifront: Xen PCI frontend driver.
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Quoted 4 lines · Konrad Rzeszutek Wilk
Hey Jan,
Thank you for taking your time to look at this patch. Will fix up, test it, and if there are no issues, have it ready tomorrow.
Attached (and inline) is the updated version of this patch. If I missed anything
please do point it out to me!
There's one more missing "static", and one incorrect change to free_pdev() you did.
Also, any word on the pdev_lock you dropped from the original implementation?
Quoted 1 line
If this is to your satisfaction, can I put a Reviewed-by tag on the patch?
Feel free to do so.
drivers/pci/xen-pcifront.c
Quoted 4 lines
drivers/pci/xen-pcifront.c new file +1
-0+int __devinit pcifront_scan_bus(struct pcifront_device *pdev,
static?
drivers/pci/xen-pcifront.c line 739
Quoted 11 lines
...
drivers/pci/xen-pcifront.c new file +10
-0+static void free_pdev (struct pcifront_device *pdev) +{ +dev_dbg (&pdev->xdev->dev,"freeing pdev @ 0x%p\n" , pdev); + +pcifront_free_roots (pdev); + +/*For PCIE_AER error handling job*/ +flush_scheduled_work (); + +if (pdev->irq)
if (pdev->irq > 0)
It gets initialized to -1 in alloc_pdev(). It may be debatable whether it should be >= 0 - I'm not sure if the pv-ops code allows IRQ 0 to be used. If it doesn't, initializing to 0 in alloc_pdev() would be an alternative.
Quoted 29 lines
drivers/pci/xen-pcifront.c new file +29
-0+unbind_from_irqhandler (pdev->irq, pdev); + +if (pdev->evtchn !=INVALID_EVTCHN ) +xenbus_free_evtchn (pdev->xdev, pdev->evtchn); + +if (pdev->gnt_ref !=INVALID_GRANT_REF ) +gnttab_end_foreign_access (pdev->gnt_ref,0 /* r/w page */ , + (unsigned long )pdev->sh_info); +else +free_page ((unsigned long )pdev->sh_info); + +dev_set_drvdata (&pdev->xdev->dev,NULL ); + +kfree (pdev); +} + +static int pcifront_publish_info (struct pcifront_device *pdev) +{ +int err =0 ; +struct xenbus_transaction trans; + + err =xenbus_grant_ring (pdev->xdev,virt_to_mfn (pdev->sh_info)); +if (err <0 ) + goto out; + + pdev->gnt_ref = err; + + err =xenbus_alloc_evtchn (pdev->xdev, &pdev->evtchn); +if (err)
drivers/pci/xen-pcifront.c line 778
Quoted 10 lines
drivers/pci/xen-pcifront.c new file +10
-0+ goto out; + + err =bind_evtchn_to_irqhandler (pdev->evtchn, pcifront_handler_aer, +0 ,"pcifront" , pdev); +if (err <0 ) { +/* +xenbus_free_evtchn(pdev->xdev, pdev->evtchn); +xenbus_dev_fatal(pdev->xdev, err, "Failed to bind evtchn to " +"irqhandler.\n"); +*/
Why are you commenting it out rather than removing it?
Jan
Re: [Xen-devel] Re: [PATCH 20/23] xen-pcifront: Xen PCI frontend driver.
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Quoted 4 lines · Konrad Rzeszutek Wilk
Hey Jan,
Thank you for taking your time to look at this patch. Will fix up, test it, and if there are no issues, have it ready tomorrow.
Quoted 6 lines
Quoted 3 lines
Attached (and inline) is the updated version of this patch. If I missed anything
please do point it out to me!There's one more missing "static", and one incorrect change to
free_pdev()you did.
Fixed.
Quoted 3 lines
Also, any word on the
pdev_lockyou dropped from the original implementation?
Yes. The reason for dropping it was that the xenwatch thread provides the neccessary locking for the states. So no more need for this spin_lock.
Quoted 4 lines
Quoted 2 lines
If this is to your satisfaction, can I put a Reviewed-by tag on the patch?
Feel free to do so.
Thank you.
Quoted 7 lines
drivers/pci/xen-pcifront.c
Quoted 5 lines
drivers/pci/xen-pcifront.c new file +1
-0+int __devinit pcifront_scan_bus(struct pcifront_device *pdev,static?
Yup, done.
Quoted 15 lines
drivers/pci/xen-pcifront.c line 739
Quoted 12 lines
...
drivers/pci/xen-pcifront.c new file +10
-0+static void free_pdev (struct pcifront_device *pdev) +{ +dev_dbg (&pdev->xdev->dev,"freeing pdev @ 0x%p\n" , pdev); + +pcifront_free_roots (pdev); + +/*For PCIE_AER error handling job*/ +flush_scheduled_work (); + +if (pdev->irq)if (pdev->irq > 0)
Quoted 4 lines
It gets initialized to -1 in
alloc_pdev(). It may be debatable whether it should be >= 0 - I'm not sure if the pv-ops code allows IRQ 0 to be used. If it doesn't, initializing to 0 inalloc_pdev()would be an alternative.
I made it '>=' The Xen PCI (arch/x86/pci/xen.c) and Xen Events (riers/xen/events.c) are both OK with an IRQ of zero. So lets be uniform and be OK here too.
Quoted 34 lines
Quoted 34 lines
drivers/pci/xen-pcifront.c new file +33
-0+unbind_from_irqhandler (pdev->irq, pdev); + +if (pdev->evtchn !=INVALID_EVTCHN ) +xenbus_free_evtchn (pdev->xdev, pdev->evtchn); + +if (pdev->gnt_ref !=INVALID_GRANT_REF ) +gnttab_end_foreign_access (pdev->gnt_ref,0 /* r/w page */ , + (unsigned long )pdev->sh_info); +else +free_page ((unsigned long )pdev->sh_info); + +dev_set_drvdata (&pdev->xdev->dev,NULL ); + +kfree (pdev); +} + +static int pcifront_publish_info (struct pcifront_device *pdev) +{ +int err =0 ; +struct xenbus_transaction trans; + + err =xenbus_grant_ring (pdev->xdev,virt_to_mfn (pdev->sh_info)); +if (err <0 ) + goto out; + + pdev->gnt_ref = err; + + err =xenbus_alloc_evtchn (pdev->xdev, &pdev->evtchn); +if (err) + goto out; + + err =bind_evtchn_to_irqhandler (pdev->evtchn, pcifront_handler_aer, +0 ,"pcifront" , pdev);
Quoted 8 lines
drivers/pci/xen-pcifront.c line 778
Quoted 6 lines
drivers/pci/xen-pcifront.c new file +6
-0+if (err <0 ) { +/* +xenbus_free_evtchn(pdev->xdev, pdev->evtchn); +xenbus_dev_fatal(pdev->xdev, err, "Failed to bind evtchn to " +"irqhandler.\n"); +*/ Why are you commenting it out rather than removing it?
Umm. I was in a hurry to test it out and just in case it would fail I made it a comment. And then forgot about it. Removed that comented out section of code.
Quoted 8 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 21/23 xen/pci: Request ACS when Xen-SWIOTLB is activated.
In reply to Konrad Rzeszutek WilkIt used to done in the Xen startup code but that is not really appropiate.
--- arch/x86/xen/pci-swiotlb-xen.c | 4 ++++ drivers/xen/Kconfig | 2 +- 2 files changed, 5 insertions(+), 1 deletions(-)
arch/x86/xen/pci-swiotlb-xen.c +4 -0
@@ -1,6 +1,7 @@/* Glue code to lib/swiotlb-xen.c */ #include <linux/dma-mapping.h> +#include <linux/pci.h> #include <xen/swiotlb-xen.h> #include <asm/xen/hypervisor.h>
@@ -54,5 +55,8 @@ void __init pci_xen_swiotlb_init(void)if (xen_swiotlb) {xen_swiotlb_init (1 ); dma_ops = &xen_swiotlb_dma_ops; + +/* Make sure ACS will be enabled */ +pci_request_acs (); } }
drivers/xen/Kconfig +1 -1
@@ -74,6 +74,6 @@ config XEN_PLATFORM_PCI config SWIOTLB_XEN def_bool y - depends on SWIOTLB + depends on PCI && SWIOTLB endmenu
Signature · 1 line
1.7.0.4
PATCH 22/23 MAINTAINERS: Add myself for Xen PCI and Xen SWIOTLB maintainer.
In reply to Konrad Rzeszutek Wilk--- MAINTAINERS | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
MAINTAINERS +14 -0
@@ -6486,6 +6486,20 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/mjg59/platform-drivers-x86. S: Maintained F: drivers/platform/x86 +XEN PCI SUBSYSTEM +M: Konrad Rzeszutek Wilk <[email protected]> +L: [email protected] +S: Supported +F: arch/x86/pci/*xen* +F: drivers/pci/*xen* + +XEN SWIOTLB SUBSYSTEM +M: Konrad Rzeszutek Wilk <[email protected]> +L: [email protected] +S: Supported +F: arch/x86/xen/*swiotlb* +F: drivers/xen/*swiotlb* + XEN HYPERVISOR INTERFACE M: Jeremy Fitzhardinge <[email protected]> M: Chris Wright <[email protected]>
Signature · 1 line
1.7.0.4
PATCH 23/23 swiotlb-xen: On x86-32 builts, select SWIOTLB instead of depending on it.
In reply to Konrad Rzeszutek WilkWe used to depend on CONFIG_SWIOTLB, but that is disabled by default. So when compiling we get this compile error:
arch/x86/xen/pci-swiotlb-xen.c: In function 'pci_xen_swiotlb_detect':arch/x86/xen/pci-swiotlb-xen.c:48: error: lvalue required as left operand of assignment
Fix it by actually activating the SWIOTLB library.
--- drivers/xen/Kconfig | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/xen/Kconfig +2 -1
@@ -74,6 +74,7 @@ config XEN_PLATFORM_PCI config SWIOTLB_XEN def_bool y - depends on PCI && SWIOTLB + depends on PCI + select SWIOTLB endmenu
Signature · 1 line
1.7.0.4