Stefano Stabellini
2011-Feb-16 17:51 UTC
[Xen-devel] [PATCH 0/7] Xen PV on HVM fixes and improvements
Hi all, this patch series is a collection of fixes and improvements for Linux running as Xen PV on HVM guest. Most of the patches have already been sent to the list at least once, some have already been acked. The list of patches with diffstat follows: Stefano Stabellini (7): xen: no need to delay xen_setup_shutdown_event for hvm guests anymore xen: do not use xen_info on HVM, set pv_info name to "Xen HVM" xen-blkfront: handle Xen major numbers other than XENVBD xen: make the ballon driver work for hvm domains xen: PV on HVM: support PV spinlocks xen: enable event channels to send and receive IPIs for PV on HVM guests xen: fix compile issue if XEN is enabled but XEN_PVHVM is disabled arch/x86/xen/enlighten.c | 6 ++- arch/x86/xen/smp.c | 42 ++++++++++++++++++++ arch/x86/xen/suspend.c | 2 + arch/x86/xen/xen-ops.h | 2 + drivers/block/xen-blkfront.c | 79 +++++++++++++++++++++++++++++++++++-- drivers/xen/balloon.c | 14 ++++-- drivers/xen/manage.c | 17 ++------ drivers/xen/platform-pci.c | 3 - include/xen/interface/io/blkif.h | 21 ++++++++++ 9 files changed, 158 insertions(+), 28 deletions(-) A branch with these patches on 2.6.38-rc5 is available here: git://xenbits.xen.org/people/sstabellini/linux-pvhvm.git 2.6.38-rc5-pvhvm Cheers, Stefano _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
stefano.stabellini@eu.citrix.com
2011-Feb-16 17:53 UTC
[Xen-devel] [PATCH 1/7] xen: no need to delay xen_setup_shutdown_event for hvm guests anymore
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Now that xenstore_ready is used correctly for PV on HVM guests too, we don''t need to delay the initialization of xen_setup_shutdown_event anymore. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Acked-by: Jeremy Fitzhardinge <jeremy@goop.org> --- drivers/xen/manage.c | 17 ++++------------- drivers/xen/platform-pci.c | 3 --- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index db8c4c4..459cf8e 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c @@ -281,27 +281,18 @@ static int shutdown_event(struct notifier_block *notifier, return NOTIFY_DONE; } -static int __init __setup_shutdown_event(void) -{ - /* Delay initialization in the PV on HVM case */ - if (xen_hvm_domain()) - return 0; - - if (!xen_pv_domain()) - return -ENODEV; - - return xen_setup_shutdown_event(); -} - int xen_setup_shutdown_event(void) { static struct notifier_block xenstore_notifier = { .notifier_call = shutdown_event }; + + if (!xen_domain()) + return -ENODEV; register_xenstore_notifier(&xenstore_notifier); return 0; } EXPORT_SYMBOL_GPL(xen_setup_shutdown_event); -subsys_initcall(__setup_shutdown_event); +subsys_initcall(xen_setup_shutdown_event); diff --git a/drivers/xen/platform-pci.c b/drivers/xen/platform-pci.c index afbe041..319dd0a 100644 --- a/drivers/xen/platform-pci.c +++ b/drivers/xen/platform-pci.c @@ -156,9 +156,6 @@ static int __devinit platform_pci_init(struct pci_dev *pdev, if (ret) goto out; xenbus_probe(NULL); - ret = xen_setup_shutdown_event(); - if (ret) - goto out; return 0; out: -- 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
stefano.stabellini@eu.citrix.com
2011-Feb-16 17:53 UTC
[Xen-devel] [PATCH 2/7] xen: do not use xen_info on HVM, set pv_info name to "Xen HVM"
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Acked-by: Jeremy Fitzhardinge <jeremy@goop.org> --- arch/x86/xen/enlighten.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 50542ef..2f67e2e 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -1284,8 +1284,7 @@ static int init_hvm_pv_info(int *major, int *minor) xen_setup_features(); - pv_info = xen_info; - pv_info.kernel_rpl = 0; + pv_info.name = "Xen HVM"; xen_domain_type = XEN_HVM_DOMAIN; -- 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
stefano.stabellini@eu.citrix.com
2011-Feb-16 17:53 UTC
[Xen-devel] [PATCH 3/7] xen-blkfront: handle Xen major numbers other than XENVBD
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> This patch makes sure blkfront handles correctly virtual device numbers corresponding to Xen emulated IDE and SCSI disks: in those cases blkfront translates the major number to XENVBD and the minor number to a low xvd minor. Note: this behaviour is different from what old xenlinux PV guests used to do: they used to steal an IDE or SCSI major number and use it instead. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Acked-by: Jeremy Fitzhardinge <jeremy@goop.org> --- drivers/block/xen-blkfront.c | 79 +++++++++++++++++++++++++++++++++++-- include/xen/interface/io/blkif.h | 21 ++++++++++ 2 files changed, 95 insertions(+), 5 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index d7aa39e..64d9c6d 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -120,6 +120,10 @@ static DEFINE_SPINLOCK(minor_lock); #define EXTENDED (1<<EXT_SHIFT) #define VDEV_IS_EXTENDED(dev) ((dev)&(EXTENDED)) #define BLKIF_MINOR_EXT(dev) ((dev)&(~EXTENDED)) +#define EMULATED_HD_DISK_MINOR_OFFSET (0) +#define EMULATED_HD_DISK_NAME_OFFSET (EMULATED_HD_DISK_MINOR_OFFSET / 256) +#define EMULATED_SD_DISK_MINOR_OFFSET (EMULATED_HD_DISK_MINOR_OFFSET + (4 * 16)) +#define EMULATED_SD_DISK_NAME_OFFSET (EMULATED_HD_DISK_NAME_OFFSET + 4) #define DEV_NAME "xvd" /* name in /dev */ @@ -434,6 +438,65 @@ static void xlvbd_flush(struct blkfront_info *info) info->feature_flush ? "enabled" : "disabled"); } +static int xen_translate_vdev(int vdevice, int *minor, unsigned int *offset) +{ + int major; + major = BLKIF_MAJOR(vdevice); + *minor = BLKIF_MINOR(vdevice); + switch (major) { + case XEN_IDE0_MAJOR: + *offset = (*minor / 64) + EMULATED_HD_DISK_NAME_OFFSET; + *minor = ((*minor / 64) * PARTS_PER_DISK) + + EMULATED_HD_DISK_MINOR_OFFSET; + break; + case XEN_IDE1_MAJOR: + *offset = (*minor / 64) + 2 + EMULATED_HD_DISK_NAME_OFFSET; + *minor = (((*minor / 64) + 2) * PARTS_PER_DISK) + + EMULATED_HD_DISK_MINOR_OFFSET; + break; + case XEN_SCSI_DISK0_MAJOR: + *offset = (*minor / PARTS_PER_DISK) + EMULATED_SD_DISK_NAME_OFFSET; + *minor = *minor + EMULATED_SD_DISK_MINOR_OFFSET; + break; + case XEN_SCSI_DISK1_MAJOR: + case XEN_SCSI_DISK2_MAJOR: + case XEN_SCSI_DISK3_MAJOR: + case XEN_SCSI_DISK4_MAJOR: + case XEN_SCSI_DISK5_MAJOR: + case XEN_SCSI_DISK6_MAJOR: + case XEN_SCSI_DISK7_MAJOR: + *offset = (*minor / PARTS_PER_DISK) + + ((major - XEN_SCSI_DISK1_MAJOR + 1) * 16) + + EMULATED_SD_DISK_NAME_OFFSET; + *minor = *minor + + ((major - XEN_SCSI_DISK1_MAJOR + 1) * 16 * PARTS_PER_DISK) + + EMULATED_SD_DISK_MINOR_OFFSET; + break; + case XEN_SCSI_DISK8_MAJOR: + case XEN_SCSI_DISK9_MAJOR: + case XEN_SCSI_DISK10_MAJOR: + case XEN_SCSI_DISK11_MAJOR: + case XEN_SCSI_DISK12_MAJOR: + case XEN_SCSI_DISK13_MAJOR: + case XEN_SCSI_DISK14_MAJOR: + case XEN_SCSI_DISK15_MAJOR: + *offset = (*minor / PARTS_PER_DISK) + + ((major - XEN_SCSI_DISK8_MAJOR + 8) * 16) + + EMULATED_SD_DISK_NAME_OFFSET; + *minor = *minor + + ((major - XEN_SCSI_DISK8_MAJOR + 8) * 16 * PARTS_PER_DISK) + + EMULATED_SD_DISK_MINOR_OFFSET; + break; + case XENVBD_MAJOR: + *offset = *minor / PARTS_PER_DISK; + break; + default: + printk(KERN_WARNING "blkfront: your disk configuration is " + "incorrect, please use an xvd device instead\n"); + return -ENODEV; + } + return 0; +} static int xlvbd_alloc_gendisk(blkif_sector_t capacity, struct blkfront_info *info, @@ -441,7 +504,7 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, { struct gendisk *gd; int nr_minors = 1; - int err = -ENODEV; + int err; unsigned int offset; int minor; int nr_parts; @@ -456,12 +519,20 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, } if (!VDEV_IS_EXTENDED(info->vdevice)) { - minor = BLKIF_MINOR(info->vdevice); - nr_parts = PARTS_PER_DISK; + err = xen_translate_vdev(info->vdevice, &minor, &offset); + if (err) + return err; + nr_parts = PARTS_PER_DISK; } else { minor = BLKIF_MINOR_EXT(info->vdevice); nr_parts = PARTS_PER_EXT_DISK; + offset = minor / nr_parts; + if (xen_hvm_domain() && offset <= EMULATED_HD_DISK_NAME_OFFSET + 4) + printk(KERN_WARNING "blkfront: vdevice 0x%x might conflict with " + "emulated IDE disks,\n\t choose an xvd device name" + "from xvde on\n", info->vdevice); } + err = -ENODEV; if ((minor % nr_parts) == 0) nr_minors = nr_parts; @@ -475,8 +546,6 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, if (gd == NULL) goto release; - offset = minor / nr_parts; - if (nr_minors > 1) { if (offset < 26) sprintf(gd->disk_name, "%s%c", DEV_NAME, ''a'' + offset); diff --git a/include/xen/interface/io/blkif.h b/include/xen/interface/io/blkif.h index c2d1fa4..68dd2b4 100644 --- a/include/xen/interface/io/blkif.h +++ b/include/xen/interface/io/blkif.h @@ -91,4 +91,25 @@ DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response); #define VDISK_REMOVABLE 0x2 #define VDISK_READONLY 0x4 +/* Xen-defined major numbers for virtual disks, they look strangely + * familiar */ +#define XEN_IDE0_MAJOR 3 +#define XEN_IDE1_MAJOR 22 +#define XEN_SCSI_DISK0_MAJOR 8 +#define XEN_SCSI_DISK1_MAJOR 65 +#define XEN_SCSI_DISK2_MAJOR 66 +#define XEN_SCSI_DISK3_MAJOR 67 +#define XEN_SCSI_DISK4_MAJOR 68 +#define XEN_SCSI_DISK5_MAJOR 69 +#define XEN_SCSI_DISK6_MAJOR 70 +#define XEN_SCSI_DISK7_MAJOR 71 +#define XEN_SCSI_DISK8_MAJOR 128 +#define XEN_SCSI_DISK9_MAJOR 129 +#define XEN_SCSI_DISK10_MAJOR 130 +#define XEN_SCSI_DISK11_MAJOR 131 +#define XEN_SCSI_DISK12_MAJOR 132 +#define XEN_SCSI_DISK13_MAJOR 133 +#define XEN_SCSI_DISK14_MAJOR 134 +#define XEN_SCSI_DISK15_MAJOR 135 + #endif /* __XEN_PUBLIC_IO_BLKIF_H__ */ -- 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
stefano.stabellini@eu.citrix.com
2011-Feb-16 17:53 UTC
[Xen-devel] [PATCH 4/7] xen: make the ballon driver work for hvm domains
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- drivers/xen/balloon.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 43f9f02..9294f25 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -232,7 +232,7 @@ static int increase_reservation(unsigned long nr_pages) set_phys_to_machine(pfn, frame_list[i]); /* Link back into the page tables if not highmem. */ - if (pfn < max_low_pfn) { + if (!xen_hvm_domain() && pfn < max_low_pfn) { int ret; ret = HYPERVISOR_update_va_mapping( (unsigned long)__va(pfn << PAGE_SHIFT), @@ -280,7 +280,7 @@ static int decrease_reservation(unsigned long nr_pages) scrub_page(page); - if (!PageHighMem(page)) { + if (!xen_hvm_domain() && !PageHighMem(page)) { ret = HYPERVISOR_update_va_mapping( (unsigned long)__va(pfn << PAGE_SHIFT), __pte_ma(0), 0); @@ -392,15 +392,19 @@ static struct notifier_block xenstore_notifier; static int __init balloon_init(void) { - unsigned long pfn, extra_pfn_end; + unsigned long pfn, nr_pages, extra_pfn_end; struct page *page; - if (!xen_pv_domain()) + if (!xen_domain()) return -ENODEV; pr_info("xen_balloon: Initialising balloon driver.\n"); - balloon_stats.current_pages = min(xen_start_info->nr_pages, max_pfn); + if (xen_pv_domain()) + nr_pages = xen_start_info->nr_pages; + else + nr_pages = max_pfn; + balloon_stats.current_pages = min(nr_pages, max_pfn); balloon_stats.target_pages = balloon_stats.current_pages; balloon_stats.balloon_low = 0; balloon_stats.balloon_high = 0; -- 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
stefano.stabellini@eu.citrix.com
2011-Feb-16 17:53 UTC
[Xen-devel] [PATCH 5/7] xen: PV on HVM: support PV spinlocks
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Initialize PV spinlocks on boot CPU right after native_smp_prepare_cpus (that switch to APIC mode and initialize APIC routing); on secondary CPUs on CPU_UP_PREPARE. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- arch/x86/xen/enlighten.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 2f67e2e..9c1628b 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -1330,6 +1330,8 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self, switch (action) { case CPU_UP_PREPARE: per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu]; + if (xen_have_vector_callback) + xen_init_lock_cpu(cpu); break; default: break; @@ -1341,6 +1343,20 @@ static struct notifier_block __cpuinitdata xen_hvm_cpu_notifier = { .notifier_call = xen_hvm_cpu_notify, }; +static void xen_hvm_spinlock_init(void) +{ + if (!xen_have_vector_callback) + return; + xen_init_lock_cpu(0); + xen_init_spinlocks(); +} + +static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus) +{ + native_smp_prepare_cpus(max_cpus); + xen_hvm_spinlock_init(); +} + static void __init xen_hvm_guest_init(void) { int r; @@ -1360,6 +1376,7 @@ static void __init xen_hvm_guest_init(void) x86_init.irqs.intr_init = xen_init_IRQ; xen_hvm_init_time_ops(); xen_hvm_init_mmu_ops(); + smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus; } static bool __init xen_hvm_platform(void) -- 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
stefano.stabellini@eu.citrix.com
2011-Feb-16 17:53 UTC
[Xen-devel] [PATCH 6/7] xen: enable event channels to send and receive IPIs for PV on HVM guests
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Enable the usage of event channels to send and receive IPIs when running as a PV on HVM guest. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- arch/x86/xen/enlighten.c | 16 +--------------- arch/x86/xen/smp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ arch/x86/xen/xen-ops.h | 2 ++ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 9c1628b..fe02574 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -1343,20 +1343,6 @@ static struct notifier_block __cpuinitdata xen_hvm_cpu_notifier = { .notifier_call = xen_hvm_cpu_notify, }; -static void xen_hvm_spinlock_init(void) -{ - if (!xen_have_vector_callback) - return; - xen_init_lock_cpu(0); - xen_init_spinlocks(); -} - -static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus) -{ - native_smp_prepare_cpus(max_cpus); - xen_hvm_spinlock_init(); -} - static void __init xen_hvm_guest_init(void) { int r; @@ -1370,13 +1356,13 @@ static void __init xen_hvm_guest_init(void) if (xen_feature(XENFEAT_hvm_callback_vector)) xen_have_vector_callback = 1; + xen_hvm_smp_init(); register_cpu_notifier(&xen_hvm_cpu_notifier); xen_unplug_emulated_devices(); have_vcpu_info_placement = 0; x86_init.irqs.intr_init = xen_init_IRQ; xen_hvm_init_time_ops(); xen_hvm_init_mmu_ops(); - smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus; } static bool __init xen_hvm_platform(void) diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c index 72a4c79..2300d4b 100644 --- a/arch/x86/xen/smp.c +++ b/arch/x86/xen/smp.c @@ -509,3 +509,45 @@ void __init xen_smp_init(void) xen_fill_possible_map(); xen_init_spinlocks(); } + +static void xen_hvm_spinlock_init(void) +{ + if (!xen_have_vector_callback) + return; + xen_init_lock_cpu(0); + xen_init_spinlocks(); +} + +static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus) +{ + native_smp_prepare_cpus(max_cpus); + WARN_ON(xen_smp_intr_init(0)); + xen_hvm_spinlock_init(); +} + +static int __cpuinit xen_hvm_cpu_up(unsigned int cpu) +{ + int rc; + rc = native_cpu_up(cpu); + WARN_ON (xen_smp_intr_init(cpu)); + return rc; +} + +static void xen_hvm_cpu_die(unsigned int cpu) +{ + unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu), NULL); + unbind_from_irqhandler(per_cpu(xen_callfunc_irq, cpu), NULL); + unbind_from_irqhandler(per_cpu(xen_debug_irq, cpu), NULL); + unbind_from_irqhandler(per_cpu(xen_callfuncsingle_irq, cpu), NULL); + native_cpu_die(cpu); +} + +void __init xen_hvm_smp_init(void) +{ + smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus; + smp_ops.smp_send_reschedule = xen_smp_send_reschedule; + smp_ops.cpu_up = xen_hvm_cpu_up; + smp_ops.cpu_die = xen_hvm_cpu_die; + smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi; + smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi; +} diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 9d41bf9..3112f55 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h @@ -64,10 +64,12 @@ void xen_setup_vcpu_info_placement(void); #ifdef CONFIG_SMP void xen_smp_init(void); +void __init xen_hvm_smp_init(void); extern cpumask_var_t xen_cpu_initialized_map; #else static inline void xen_smp_init(void) {} +static inline void xen_hvm_smp_init(void) {} #endif #ifdef CONFIG_PARAVIRT_SPINLOCKS -- 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
stefano.stabellini@eu.citrix.com
2011-Feb-16 17:53 UTC
[Xen-devel] [PATCH 7/7] xen: fix compile issue if XEN is enabled but XEN_PVHVM is disabled
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- arch/x86/xen/suspend.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c index 9bbd63a..4a3d3dd 100644 --- a/arch/x86/xen/suspend.c +++ b/arch/x86/xen/suspend.c @@ -28,6 +28,7 @@ void xen_pre_suspend(void) void xen_hvm_post_suspend(int suspend_cancelled) { +#ifdef CONFIG_XEN_PVHVM int cpu; xen_hvm_init_shared_info(); xen_callback_vector(); @@ -37,6 +38,7 @@ void xen_hvm_post_suspend(int suspend_cancelled) xen_setup_runstate_info(cpu); } } +#endif } void xen_post_suspend(int suspend_cancelled) -- 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Feb-22 19:19 UTC
[Xen-devel] Re: [PATCH 3/7] xen-blkfront: handle Xen major numbers other than XENVBD
On Wed, Feb 16, 2011 at 05:53:03PM +0000, stefano.stabellini@eu.citrix.com wrote:> From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> > > This patch makes sure blkfront handles correctly virtual device numbers > corresponding to Xen emulated IDE and SCSI disks: in those cases > blkfront translates the major number to XENVBD and the minor number to a > low xvd minor. > > Note: this behaviour is different from what old xenlinux PV guests used > to do: they used to steal an IDE or SCSI major number and use it > instead. > > Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> > Acked-by: Jeremy Fitzhardinge <jeremy@goop.org> > --- > drivers/block/xen-blkfront.c | 79 +++++++++++++++++++++++++++++++++++-- > include/xen/interface/io/blkif.h | 21 ++++++++++ > 2 files changed, 95 insertions(+), 5 deletions(-) > > diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c > index d7aa39e..64d9c6d 100644 > --- a/drivers/block/xen-blkfront.c > +++ b/drivers/block/xen-blkfront.c > @@ -120,6 +120,10 @@ static DEFINE_SPINLOCK(minor_lock); > #define EXTENDED (1<<EXT_SHIFT) > #define VDEV_IS_EXTENDED(dev) ((dev)&(EXTENDED)) > #define BLKIF_MINOR_EXT(dev) ((dev)&(~EXTENDED)) > +#define EMULATED_HD_DISK_MINOR_OFFSET (0) > +#define EMULATED_HD_DISK_NAME_OFFSET (EMULATED_HD_DISK_MINOR_OFFSET / 256)0 / 256 ? Why not just 0?> +#define EMULATED_SD_DISK_MINOR_OFFSET (EMULATED_HD_DISK_MINOR_OFFSET + (4 * 16)) > +#define EMULATED_SD_DISK_NAME_OFFSET (EMULATED_HD_DISK_NAME_OFFSET + 4) > > #define DEV_NAME "xvd" /* name in /dev */ > > @@ -434,6 +438,65 @@ static void xlvbd_flush(struct blkfront_info *info) > info->feature_flush ? "enabled" : "disabled"); > } > > +static int xen_translate_vdev(int vdevice, int *minor, unsigned int *offset) > +{ > + int major; > + major = BLKIF_MAJOR(vdevice); > + *minor = BLKIF_MINOR(vdevice); > + switch (major) { > + case XEN_IDE0_MAJOR: > + *offset = (*minor / 64) + EMULATED_HD_DISK_NAME_OFFSET; > + *minor = ((*minor / 64) * PARTS_PER_DISK) + > + EMULATED_HD_DISK_MINOR_OFFSET; > + break; > + case XEN_IDE1_MAJOR: > + *offset = (*minor / 64) + 2 + EMULATED_HD_DISK_NAME_OFFSET; > + *minor = (((*minor / 64) + 2) * PARTS_PER_DISK) + > + EMULATED_HD_DISK_MINOR_OFFSET; > + break; > + case XEN_SCSI_DISK0_MAJOR: > + *offset = (*minor / PARTS_PER_DISK) + EMULATED_SD_DISK_NAME_OFFSET; > + *minor = *minor + EMULATED_SD_DISK_MINOR_OFFSET; > + break; > + case XEN_SCSI_DISK1_MAJOR: > + case XEN_SCSI_DISK2_MAJOR: > + case XEN_SCSI_DISK3_MAJOR: > + case XEN_SCSI_DISK4_MAJOR: > + case XEN_SCSI_DISK5_MAJOR: > + case XEN_SCSI_DISK6_MAJOR: > + case XEN_SCSI_DISK7_MAJOR: > + *offset = (*minor / PARTS_PER_DISK) + > + ((major - XEN_SCSI_DISK1_MAJOR + 1) * 16) + > + EMULATED_SD_DISK_NAME_OFFSET; > + *minor = *minor + > + ((major - XEN_SCSI_DISK1_MAJOR + 1) * 16 * PARTS_PER_DISK) + > + EMULATED_SD_DISK_MINOR_OFFSET; > + break; > + case XEN_SCSI_DISK8_MAJOR: > + case XEN_SCSI_DISK9_MAJOR: > + case XEN_SCSI_DISK10_MAJOR: > + case XEN_SCSI_DISK11_MAJOR: > + case XEN_SCSI_DISK12_MAJOR: > + case XEN_SCSI_DISK13_MAJOR: > + case XEN_SCSI_DISK14_MAJOR: > + case XEN_SCSI_DISK15_MAJOR: > + *offset = (*minor / PARTS_PER_DISK) + > + ((major - XEN_SCSI_DISK8_MAJOR + 8) * 16) + > + EMULATED_SD_DISK_NAME_OFFSET; > + *minor = *minor + > + ((major - XEN_SCSI_DISK8_MAJOR + 8) * 16 * PARTS_PER_DISK) + > + EMULATED_SD_DISK_MINOR_OFFSET; > + break; > + case XENVBD_MAJOR: > + *offset = *minor / PARTS_PER_DISK; > + break; > + default: > + printk(KERN_WARNING "blkfront: your disk configuration is " > + "incorrect, please use an xvd device instead\n"); > + return -ENODEV; > + } > + return 0; > +} > > static int xlvbd_alloc_gendisk(blkif_sector_t capacity, > struct blkfront_info *info, > @@ -441,7 +504,7 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, > { > struct gendisk *gd; > int nr_minors = 1; > - int err = -ENODEV; > + int err; > unsigned int offset; > int minor; > int nr_parts; > @@ -456,12 +519,20 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, > } > > if (!VDEV_IS_EXTENDED(info->vdevice)) { > - minor = BLKIF_MINOR(info->vdevice); > - nr_parts = PARTS_PER_DISK; > + err = xen_translate_vdev(info->vdevice, &minor, &offset); > + if (err) > + return err; > + nr_parts = PARTS_PER_DISK; > } else { > minor = BLKIF_MINOR_EXT(info->vdevice); > nr_parts = PARTS_PER_EXT_DISK; > + offset = minor / nr_parts; > + if (xen_hvm_domain() && offset <= EMULATED_HD_DISK_NAME_OFFSET + 4) > + printk(KERN_WARNING "blkfront: vdevice 0x%x might conflict with " > + "emulated IDE disks,\n\t choose an xvd device name" > + "from xvde on\n", info->vdevice); > } > + err = -ENODEV; > > if ((minor % nr_parts) == 0) > nr_minors = nr_parts; > @@ -475,8 +546,6 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, > if (gd == NULL) > goto release; > > - offset = minor / nr_parts; > - > if (nr_minors > 1) { > if (offset < 26) > sprintf(gd->disk_name, "%s%c", DEV_NAME, ''a'' + offset); > diff --git a/include/xen/interface/io/blkif.h b/include/xen/interface/io/blkif.h > index c2d1fa4..68dd2b4 100644 > --- a/include/xen/interface/io/blkif.h > +++ b/include/xen/interface/io/blkif.h > @@ -91,4 +91,25 @@ DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response); > #define VDISK_REMOVABLE 0x2 > #define VDISK_READONLY 0x4 > > +/* Xen-defined major numbers for virtual disks, they look strangely > + * familiar */ > +#define XEN_IDE0_MAJOR 3 > +#define XEN_IDE1_MAJOR 22 > +#define XEN_SCSI_DISK0_MAJOR 8 > +#define XEN_SCSI_DISK1_MAJOR 65 > +#define XEN_SCSI_DISK2_MAJOR 66 > +#define XEN_SCSI_DISK3_MAJOR 67 > +#define XEN_SCSI_DISK4_MAJOR 68 > +#define XEN_SCSI_DISK5_MAJOR 69 > +#define XEN_SCSI_DISK6_MAJOR 70 > +#define XEN_SCSI_DISK7_MAJOR 71 > +#define XEN_SCSI_DISK8_MAJOR 128 > +#define XEN_SCSI_DISK9_MAJOR 129 > +#define XEN_SCSI_DISK10_MAJOR 130 > +#define XEN_SCSI_DISK11_MAJOR 131 > +#define XEN_SCSI_DISK12_MAJOR 132 > +#define XEN_SCSI_DISK13_MAJOR 133 > +#define XEN_SCSI_DISK14_MAJOR 134 > +#define XEN_SCSI_DISK15_MAJOR 135 > + > #endif /* __XEN_PUBLIC_IO_BLKIF_H__ */ > -- > 1.5.6.5_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Feb-22 19:30 UTC
[Xen-devel] Re: [PATCH 6/7] xen: enable event channels to send and receive IPIs for PV on HVM guests
On Wed, Feb 16, 2011 at 05:53:06PM +0000, stefano.stabellini@eu.citrix.com wrote:> From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> > > Enable the usage of event channels to send and receive IPIs when > running as a PV on HVM guest.Why not squash this with the other patch? After this, the only thing that the other patch had done was to add in the ''xen_hvm_cpu_notify'' function a call to setup the spinlocks..> > Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> > --- > arch/x86/xen/enlighten.c | 16 +--------------- > arch/x86/xen/smp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > arch/x86/xen/xen-ops.h | 2 ++ > 3 files changed, 45 insertions(+), 15 deletions(-) > > diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c > index 9c1628b..fe02574 100644 > --- a/arch/x86/xen/enlighten.c > +++ b/arch/x86/xen/enlighten.c > @@ -1343,20 +1343,6 @@ static struct notifier_block __cpuinitdata xen_hvm_cpu_notifier = { > .notifier_call = xen_hvm_cpu_notify, > }; > > -static void xen_hvm_spinlock_init(void) > -{ > - if (!xen_have_vector_callback) > - return; > - xen_init_lock_cpu(0); > - xen_init_spinlocks(); > -} > - > -static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus) > -{ > - native_smp_prepare_cpus(max_cpus); > - xen_hvm_spinlock_init(); > -} > - > static void __init xen_hvm_guest_init(void) > { > int r; > @@ -1370,13 +1356,13 @@ static void __init xen_hvm_guest_init(void) > > if (xen_feature(XENFEAT_hvm_callback_vector)) > xen_have_vector_callback = 1; > + xen_hvm_smp_init(); > register_cpu_notifier(&xen_hvm_cpu_notifier); > xen_unplug_emulated_devices(); > have_vcpu_info_placement = 0; > x86_init.irqs.intr_init = xen_init_IRQ; > xen_hvm_init_time_ops(); > xen_hvm_init_mmu_ops(); > - smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus; > } > > static bool __init xen_hvm_platform(void) > diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c > index 72a4c79..2300d4b 100644 > --- a/arch/x86/xen/smp.c > +++ b/arch/x86/xen/smp.c > @@ -509,3 +509,45 @@ void __init xen_smp_init(void) > xen_fill_possible_map(); > xen_init_spinlocks(); > } > + > +static void xen_hvm_spinlock_init(void) > +{ > + if (!xen_have_vector_callback) > + return; > + xen_init_lock_cpu(0); > + xen_init_spinlocks(); > +} > + > +static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus) > +{ > + native_smp_prepare_cpus(max_cpus); > + WARN_ON(xen_smp_intr_init(0)); > + xen_hvm_spinlock_init();Why not merge ''xen_hvm_spinlock_init'' in here?> +} > + > +static int __cpuinit xen_hvm_cpu_up(unsigned int cpu) > +{ > + int rc; > + rc = native_cpu_up(cpu); > + WARN_ON (xen_smp_intr_init(cpu)); > + return rc; > +} > + > +static void xen_hvm_cpu_die(unsigned int cpu) > +{ > + unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu), NULL); > + unbind_from_irqhandler(per_cpu(xen_callfunc_irq, cpu), NULL); > + unbind_from_irqhandler(per_cpu(xen_debug_irq, cpu), NULL); > + unbind_from_irqhandler(per_cpu(xen_callfuncsingle_irq, cpu), NULL); > + native_cpu_die(cpu); > +} > + > +void __init xen_hvm_smp_init(void) > +{ > + smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus; > + smp_ops.smp_send_reschedule = xen_smp_send_reschedule; > + smp_ops.cpu_up = xen_hvm_cpu_up; > + smp_ops.cpu_die = xen_hvm_cpu_die; > + smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi; > + smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi; > +} > diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h > index 9d41bf9..3112f55 100644 > --- a/arch/x86/xen/xen-ops.h > +++ b/arch/x86/xen/xen-ops.h > @@ -64,10 +64,12 @@ void xen_setup_vcpu_info_placement(void); > > #ifdef CONFIG_SMP > void xen_smp_init(void); > +void __init xen_hvm_smp_init(void); > > extern cpumask_var_t xen_cpu_initialized_map; > #else > static inline void xen_smp_init(void) {} > +static inline void xen_hvm_smp_init(void) {} > #endif > > #ifdef CONFIG_PARAVIRT_SPINLOCKS > -- > 1.5.6.5_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Feb-22 19:31 UTC
[Xen-devel] Re: [PATCH 5/7] xen: PV on HVM: support PV spinlocks
> +static void xen_hvm_spinlock_init(void) > +{ > + if (!xen_have_vector_callback) > + return; > + xen_init_lock_cpu(0); > + xen_init_spinlocks(); > +} > + > +static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus) > +{ > + native_smp_prepare_cpus(max_cpus); > + xen_hvm_spinlock_init(); > +}You could squash those two together. Ah, next patch does something interesting. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stefano Stabellini
2011-Feb-25 15:38 UTC
[Xen-devel] Re: [PATCH 3/7] xen-blkfront: handle Xen major numbers other than XENVBD
On Tue, 22 Feb 2011, Konrad Rzeszutek Wilk wrote:> > @@ -120,6 +120,10 @@ static DEFINE_SPINLOCK(minor_lock); > > #define EXTENDED (1<<EXT_SHIFT) > > #define VDEV_IS_EXTENDED(dev) ((dev)&(EXTENDED)) > > #define BLKIF_MINOR_EXT(dev) ((dev)&(~EXTENDED)) > > +#define EMULATED_HD_DISK_MINOR_OFFSET (0) > > +#define EMULATED_HD_DISK_NAME_OFFSET (EMULATED_HD_DISK_MINOR_OFFSET / 256) > > 0 / 256 ? Why not just 0?Because if we set EMULATED_HD_DISK_MINOR_OFFSET to something different from 0, then the divison by 256 would matter. If you look at the code below you''ll see that: offset = minor / nr_parts; where nr_parts is 256 and offset is the the device name offset. EMULATED_HD_DISK_MINOR_OFFSET is the offset of the variable "minor" and EMULATED_HD_DISK_NAME_OFFSET is the offset of the variable "offset". _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stefano Stabellini
2011-Feb-25 15:40 UTC
[Xen-devel] Re: [PATCH 6/7] xen: enable event channels to send and receive IPIs for PV on HVM guests
On Tue, 22 Feb 2011, Konrad Rzeszutek Wilk wrote:> On Wed, Feb 16, 2011 at 05:53:06PM +0000, stefano.stabellini@eu.citrix.com wrote: > > From: Stefano Stabellini <stefano.stabellini@eu.citrix.com> > > > > Enable the usage of event channels to send and receive IPIs when > > running as a PV on HVM guest. > > Why not squash this with the other patch? After this, the only thing > that the other patch had done was to add in the ''xen_hvm_cpu_notify'' function > a call to setup the spinlocks..Yeah, I''ll do that.> > Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> > > --- > > arch/x86/xen/enlighten.c | 16 +--------------- > > arch/x86/xen/smp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > > arch/x86/xen/xen-ops.h | 2 ++ > > 3 files changed, 45 insertions(+), 15 deletions(-) > > > > diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c > > index 9c1628b..fe02574 100644 > > --- a/arch/x86/xen/enlighten.c > > +++ b/arch/x86/xen/enlighten.c > > @@ -1343,20 +1343,6 @@ static struct notifier_block __cpuinitdata xen_hvm_cpu_notifier = { > > .notifier_call = xen_hvm_cpu_notify, > > }; > > > > -static void xen_hvm_spinlock_init(void) > > -{ > > - if (!xen_have_vector_callback) > > - return; > > - xen_init_lock_cpu(0); > > - xen_init_spinlocks(); > > -} > > - > > -static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus) > > -{ > > - native_smp_prepare_cpus(max_cpus); > > - xen_hvm_spinlock_init(); > > -} > > - > > static void __init xen_hvm_guest_init(void) > > { > > int r; > > @@ -1370,13 +1356,13 @@ static void __init xen_hvm_guest_init(void) > > > > if (xen_feature(XENFEAT_hvm_callback_vector)) > > xen_have_vector_callback = 1; > > + xen_hvm_smp_init(); > > register_cpu_notifier(&xen_hvm_cpu_notifier); > > xen_unplug_emulated_devices(); > > have_vcpu_info_placement = 0; > > x86_init.irqs.intr_init = xen_init_IRQ; > > xen_hvm_init_time_ops(); > > xen_hvm_init_mmu_ops(); > > - smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus; > > } > > > > static bool __init xen_hvm_platform(void) > > diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c > > index 72a4c79..2300d4b 100644 > > --- a/arch/x86/xen/smp.c > > +++ b/arch/x86/xen/smp.c > > @@ -509,3 +509,45 @@ void __init xen_smp_init(void) > > xen_fill_possible_map(); > > xen_init_spinlocks(); > > } > > + > > +static void xen_hvm_spinlock_init(void) > > +{ > > + if (!xen_have_vector_callback) > > + return; > > + xen_init_lock_cpu(0); > > + xen_init_spinlocks(); > > +} > > + > > +static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus) > > +{ > > + native_smp_prepare_cpus(max_cpus); > > + WARN_ON(xen_smp_intr_init(0)); > > + xen_hvm_spinlock_init(); > > Why not merge ''xen_hvm_spinlock_init'' in here? >sure _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel