All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2 of 6] early PV on HVM
@ 2010-04-22 15:15 Stefano Stabellini
  2010-04-22 23:42 ` Jeremy Fitzhardinge
  0 siblings, 1 reply; 4+ messages in thread
From: Stefano Stabellini @ 2010-04-22 15:15 UTC (permalink / raw)
  To: xen-devel

From: Sheng Yang <sheng@linux.intel.com>

this patch:

- adds a xen_guest_init hook in setup.c right after kvm_guest_init;

- initializes basic pv on hvm features in xen_guest_init;

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Yaozu (Eddie) Dong <eddie.dong@intel.com>

---
 arch/x86/kernel/apic/io_apic.c    |    2 +-
 arch/x86/kernel/setup.c           |    2 +
 arch/x86/xen/enlighten.c          |   87 +++++++++++++++++++++++++++++++++++++
 drivers/input/xen-kbdfront.c      |    2 +-
 drivers/video/xen-fbfront.c       |    2 +-
 drivers/xen/events.c              |    2 +
 drivers/xen/xenbus/xenbus_probe.c |   17 ++++++-
 include/xen/xen.h                 |    2 +
 8 files changed, 110 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index cc03c43..93b15d9 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -3565,7 +3565,7 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
 	if (type == PCI_CAP_ID_MSI && nvec > 1)
 		return 1;
 
-	if (xen_domain())
+	if (xen_pv_domain())
 		return xen_pci_setup_msi_irqs(dev, nvec, type);
 
 	node = dev_to_node(&dev->dev);
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 9ba9f9f..4e99d0f 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -49,6 +49,7 @@
 #include <asm/pci-direct.h>
 #include <linux/init_ohci1394_dma.h>
 #include <linux/kvm_para.h>
+#include <xen/xen.h>
 
 #include <linux/errno.h>
 #include <linux/kernel.h>
@@ -1010,6 +1011,7 @@ void __init setup_arch(char **cmdline_p)
 	probe_nr_irqs_gsi();
 
 	kvm_guest_init();
+	xen_guest_init();
 
 	e820_reserve_resources();
 	e820_mark_nosave_regions(max_low_pfn);
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index a01646b..0df697a 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -34,6 +34,8 @@
 #include <xen/interface/version.h>
 #include <xen/interface/physdev.h>
 #include <xen/interface/vcpu.h>
+#include <xen/interface/memory.h>
+#include <xen/interface/hvm/hvm_op.h>
 #include <xen/features.h>
 #include <xen/page.h>
 #include <xen/hvc-console.h>
@@ -1276,3 +1278,88 @@ asmlinkage void __init xen_start_kernel(void)
 	x86_64_start_reservations((char *)__pa_symbol(&boot_params));
 #endif
 }
+
+static uint32_t xen_cpuid_base(void)
+{
+	uint32_t base, eax, ebx, ecx, edx;
+	char signature[13];
+
+	for (base = 0x40000000; base < 0x40010000; base += 0x100) {
+		cpuid(base, &eax, &ebx, &ecx, &edx);
+		*(uint32_t*)(signature + 0) = ebx;
+		*(uint32_t*)(signature + 4) = ecx;
+		*(uint32_t*)(signature + 8) = edx;
+		signature[12] = 0;
+
+		if (!strcmp("XenVMMXenVMM", signature) && ((eax - base) >= 2))
+			return base;
+	}
+
+	return 0;
+}
+
+static int init_hvm_pv_info(int *major, int *minor)
+{
+	uint32_t eax, ebx, ecx, edx, pages, msr, base;
+	u64 pfn;
+
+	base = xen_cpuid_base();
+	if (!base)
+		return -EINVAL;
+
+	cpuid(base + 1, &eax, &ebx, &ecx, &edx);
+
+	*major = eax >> 16;
+	*minor = eax & 0xffff;
+	printk(KERN_INFO "Xen version %d.%d.\n", *major, *minor);
+
+	cpuid(base + 2, &pages, &msr, &ecx, &edx);
+
+	pfn = __pa(hypercall_page);
+	wrmsr_safe(msr, (u32)pfn, (u32)(pfn >> 32));
+
+	xen_setup_features();
+
+	pv_info = xen_info;
+	pv_info.kernel_rpl = 0;
+
+	xen_domain_type = XEN_HVM_DOMAIN;
+
+	return 0;
+}
+
+static void __init init_shared_info(void)
+{
+	struct xen_add_to_physmap xatp;
+	struct shared_info *shared_info_page;
+
+	shared_info_page = (struct shared_info *) alloc_bootmem_pages(PAGE_SIZE);
+	xatp.domid = DOMID_SELF;
+	xatp.idx = 0;
+	xatp.space = XENMAPSPACE_shared_info;
+	xatp.gpfn = __pa(shared_info_page) >> PAGE_SHIFT;
+	if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
+		BUG();
+
+	HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
+
+	/* Don't do the full vcpu_info placement stuff until we have a
+	   possible map and a non-dummy shared_info. */
+	per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];
+}
+
+void __init xen_guest_init(void)
+{
+	int r;
+	int major, minor;
+
+	if (xen_pv_domain())
+		return;
+
+	r = init_hvm_pv_info(&major, &minor);
+	if (r < 0)
+		return;
+
+	init_shared_info();
+}
+
diff --git a/drivers/input/xen-kbdfront.c b/drivers/input/xen-kbdfront.c
index 0859bb0..80a072e 100644
--- a/drivers/input/xen-kbdfront.c
+++ b/drivers/input/xen-kbdfront.c
@@ -340,7 +340,7 @@ static struct xenbus_driver xenkbd_driver = {
 
 static int __init xenkbd_init(void)
 {
-	if (!xen_domain())
+	if (!xen_domain() || xen_hvm_domain())
 		return -ENODEV;
 
 	/* Nothing to do if running in dom0. */
diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
index 7ec2c90..dc72563 100644
--- a/drivers/video/xen-fbfront.c
+++ b/drivers/video/xen-fbfront.c
@@ -685,7 +685,7 @@ static struct xenbus_driver xenfb_driver = {
 
 static int __init xenfb_init(void)
 {
-	if (!xen_domain())
+	if (!xen_domain() || xen_hvm_domain())
 		return -ENODEV;
 
 	/* Nothing to do if running in dom0. */
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index 660774a..e46a1ef 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -603,6 +603,7 @@ out:
 	return irq;
 }
 
+#ifdef CONFIG_PCI_XEN
 #ifdef CONFIG_PCI_MSI
 int xen_destroy_irq(int irq)
 {
@@ -696,6 +697,7 @@ out:
 	return irq;
 }
 #endif
+#endif
 
 int xen_vector_from_irq(unsigned irq)
 {
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index ab04a1b..7d11957 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -55,6 +55,8 @@
 #include <xen/events.h>
 #include <xen/page.h>
 
+#include <xen/hvm.h>
+
 #include "xenbus_comms.h"
 #include "xenbus_probe.h"
 
@@ -708,10 +710,19 @@ static int __init xenbus_probe_init(void)
 		xen_store_interface = mfn_to_virt(xen_store_mfn);
 	} else {
 		xenstored_ready = 1;
-		xen_store_evtchn = xen_start_info->store_evtchn;
-		xen_store_mfn = xen_start_info->store_mfn;
+		if (xen_hvm_domain()) {
+			xen_store_evtchn =
+				hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
+			xen_store_mfn =
+				hvm_get_parameter(HVM_PARAM_STORE_PFN);
+			xen_store_interface =
+				ioremap(xen_store_mfn << PAGE_SHIFT, PAGE_SIZE);
+		} else {
+			xen_store_evtchn = xen_start_info->store_evtchn;
+			xen_store_mfn = xen_start_info->store_mfn;
+			xen_store_interface = mfn_to_virt(xen_store_mfn);
+		}
 	}
-	xen_store_interface = mfn_to_virt(xen_store_mfn);
 
 	/* Initialize the interface to xenstore. */
 	err = xs_init();
diff --git a/include/xen/xen.h b/include/xen/xen.h
index a164024..cb8c48b 100644
--- a/include/xen/xen.h
+++ b/include/xen/xen.h
@@ -9,8 +9,10 @@ enum xen_domain_type {
 
 #ifdef CONFIG_XEN
 extern enum xen_domain_type xen_domain_type;
+extern void xen_guest_init(void);
 #else
 #define xen_domain_type		XEN_NATIVE
+#define xen_guest_init() do { } while (0)
 #endif
 
 #define xen_domain()		(xen_domain_type != XEN_NATIVE)
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2 of 6] early PV on HVM
  2010-04-22 15:15 [PATCH 2 of 6] early PV on HVM Stefano Stabellini
@ 2010-04-22 23:42 ` Jeremy Fitzhardinge
  2010-04-23 15:34   ` Stefano Stabellini
  0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Fitzhardinge @ 2010-04-22 23:42 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: xen-devel

On 04/22/2010 08:15 AM, Stefano Stabellini wrote:
> From: Sheng Yang <sheng@linux.intel.com>
>
> this patch:
>
> - adds a xen_guest_init hook in setup.c right after kvm_guest_init;
>
> - initializes basic pv on hvm features in xen_guest_init;
>   

Looks mostly OK, except:

> diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
> index ab04a1b..7d11957 100644
> --- a/drivers/xen/xenbus/xenbus_probe.c
> +++ b/drivers/xen/xenbus/xenbus_probe.c
> @@ -55,6 +55,8 @@
>  #include <xen/events.h>
>  #include <xen/page.h>
>  
> +#include <xen/hvm.h>
> +
>  #include "xenbus_comms.h"
>  #include "xenbus_probe.h"
>  
> @@ -708,10 +710,19 @@ static int __init xenbus_probe_init(void)
>  		xen_store_interface = mfn_to_virt(xen_store_mfn);
>  	} else {
>  		xenstored_ready = 1;
> -		xen_store_evtchn = xen_start_info->store_evtchn;
> -		xen_store_mfn = xen_start_info->store_mfn;
> +		if (xen_hvm_domain()) {
> +			xen_store_evtchn =
> +				hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
> +			xen_store_mfn =
> +				hvm_get_parameter(HVM_PARAM_STORE_PFN);
> +			xen_store_interface =
> +				ioremap(xen_store_mfn << PAGE_SHIFT, PAGE_SIZE);
>   

I think I'd prefer to see these wrap 80 cols than be line-broken like this.

> +		} else {
> +			xen_store_evtchn = xen_start_info->store_evtchn;
> +			xen_store_mfn = xen_start_info->store_mfn;
> +			xen_store_interface = mfn_to_virt(xen_store_mfn);
> +		}
>  	}
> -	xen_store_interface = mfn_to_virt(xen_store_mfn);
>  
>  	/* Initialize the interface to xenstore. */
>  	err = xs_init();
> diff --git a/include/xen/xen.h b/include/xen/xen.h
> index a164024..cb8c48b 100644
> --- a/include/xen/xen.h
> +++ b/include/xen/xen.h
> @@ -9,8 +9,10 @@ enum xen_domain_type {
>  
>  #ifdef CONFIG_XEN
>  extern enum xen_domain_type xen_domain_type;
> +extern void xen_guest_init(void);
>  #else
>  #define xen_domain_type		XEN_NATIVE
> +#define xen_guest_init() do { } while (0)
>  #endif
>   

This isn't an appropriate header for this.  Something under
arch/x86/include/asm would be better.

    J

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2 of 6] early PV on HVM
  2010-04-22 23:42 ` Jeremy Fitzhardinge
@ 2010-04-23 15:34   ` Stefano Stabellini
  2010-04-23 19:09     ` Jeremy Fitzhardinge
  0 siblings, 1 reply; 4+ messages in thread
From: Stefano Stabellini @ 2010-04-23 15:34 UTC (permalink / raw)
  To: Jeremy Fitzhardinge; +Cc: xen-devel, Stefano Stabellini

On Fri, 23 Apr 2010, Jeremy Fitzhardinge wrote:
> On 04/22/2010 08:15 AM, Stefano Stabellini wrote:
> > From: Sheng Yang <sheng@linux.intel.com>
> >
> > this patch:
> >
> > - adds a xen_guest_init hook in setup.c right after kvm_guest_init;
> >
> > - initializes basic pv on hvm features in xen_guest_init;
> >   
> 
> Looks mostly OK, except:
> 
> > diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
> > index ab04a1b..7d11957 100644
> > --- a/drivers/xen/xenbus/xenbus_probe.c
> > +++ b/drivers/xen/xenbus/xenbus_probe.c
> > @@ -55,6 +55,8 @@
> >  #include <xen/events.h>
> >  #include <xen/page.h>
> >  
> > +#include <xen/hvm.h>
> > +
> >  #include "xenbus_comms.h"
> >  #include "xenbus_probe.h"
> >  
> > @@ -708,10 +710,19 @@ static int __init xenbus_probe_init(void)
> >  		xen_store_interface = mfn_to_virt(xen_store_mfn);
> >  	} else {
> >  		xenstored_ready = 1;
> > -		xen_store_evtchn = xen_start_info->store_evtchn;
> > -		xen_store_mfn = xen_start_info->store_mfn;
> > +		if (xen_hvm_domain()) {
> > +			xen_store_evtchn =
> > +				hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
> > +			xen_store_mfn =
> > +				hvm_get_parameter(HVM_PARAM_STORE_PFN);
> > +			xen_store_interface =
> > +				ioremap(xen_store_mfn << PAGE_SHIFT, PAGE_SIZE);
> >   
> 
> I think I'd prefer to see these wrap 80 cols than be line-broken like this.

Ok

> 
> > +		} else {
> > +			xen_store_evtchn = xen_start_info->store_evtchn;
> > +			xen_store_mfn = xen_start_info->store_mfn;
> > +			xen_store_interface = mfn_to_virt(xen_store_mfn);
> > +		}
> >  	}
> > -	xen_store_interface = mfn_to_virt(xen_store_mfn);
> >  
> >  	/* Initialize the interface to xenstore. */
> >  	err = xs_init();
> > diff --git a/include/xen/xen.h b/include/xen/xen.h
> > index a164024..cb8c48b 100644
> > --- a/include/xen/xen.h
> > +++ b/include/xen/xen.h
> > @@ -9,8 +9,10 @@ enum xen_domain_type {
> >  
> >  #ifdef CONFIG_XEN
> >  extern enum xen_domain_type xen_domain_type;
> > +extern void xen_guest_init(void);
> >  #else
> >  #define xen_domain_type		XEN_NATIVE
> > +#define xen_guest_init() do { } while (0)
> >  #endif
> >   
> 
> This isn't an appropriate header for this.  Something under
> arch/x86/include/asm would be better.
> 
 

I moved it to arch/x86/include/asm/xen/xen.h, is that OK?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2 of 6] early PV on HVM
  2010-04-23 15:34   ` Stefano Stabellini
@ 2010-04-23 19:09     ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 4+ messages in thread
From: Jeremy Fitzhardinge @ 2010-04-23 19:09 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: xen-devel

On 04/23/2010 08:34 AM, Stefano Stabellini wrote:
> I moved it to arch/x86/include/asm/xen/xen.h, is that OK?
>   

Do you mean asm/xen/hypervisor.h?  Looks fine.

    J

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-23 19:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-22 15:15 [PATCH 2 of 6] early PV on HVM Stefano Stabellini
2010-04-22 23:42 ` Jeremy Fitzhardinge
2010-04-23 15:34   ` Stefano Stabellini
2010-04-23 19:09     ` Jeremy Fitzhardinge

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.