Re: [Xen-devel] [PATCH 4/6] xen/pvh: bootup and setup related changes.

2012-10-25 Thread Konrad Rzeszutek Wilk
> > > > Yes, I think that this version looks better
> > > 
> > > But doesn't boot:
> > > 
> > > (XEN) vmx_hybrid.c:710:d0 Dom:0 EPT violation 0x181 (r--/---), gpa
> > > 0x00bf421e1c, mfn 0x, type 4. (XEN)
> > > p2m-ept.c:642:d0 Walking EPT tables for domain 0 gfn bf421 (XEN)
> > > p2m-ept.c:648:d0  gfn exceeds max_mapped_pfn 4b062 (XEN)
> > > vmx_hybrid.c:717:d0  --- GLA 0xff477e1c
> > > 
> > > 
> > > I'll have to debug it, or we can go back to the prev version, which
> > > I don't think is that un-pretty :).
> > > 
> > 
> > The reason being:
> > xen_set_identity_and_release_chunk():
> > NEW : > for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn;
> > pfn++) {
> > 
> > xen_pvh_identity_map_chunk():
> > OLD: for (pfn = start_pfn; pfn < end_pfn; pfn++)
> > 
> > IOW, for PVH we need to avoid testing for max_pfn_mapped, as we are
> > mapping the entire IO space. 
> 
> Also, now your counts for released and identity are off. Can we please
> go back to the way it was? 

Lets drop this patch then for right now. Can you post an alpha-RFC of your
Xen hypervisor patches so that I can wrangle the PV and PVH in the E820
code to use same paths as much as possible.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/6] xen/pvh: bootup and setup related changes.

2012-10-23 Thread Mukesh Rathor
On Tue, 23 Oct 2012 14:07:06 +0100
Stefano Stabellini  wrote:

> On Mon, 22 Oct 2012, Konrad Rzeszutek Wilk wrote:
> > On Mon, Oct 22, 2012 at 02:34:44PM +0100, Stefano Stabellini wrote:
> > > On Sat, 20 Oct 2012, Konrad Rzeszutek Wilk wrote:
> > > > From: Mukesh Rathor 
> > > > 
> > > > for (pfn = PFN_DOWN(start); pfn < xen_max_p2m_pfn;
> > > > pfn++) { unsigned long mfn = pfn_to_mfn(pfn);
> > > > @@ -100,6 +104,7 @@ static unsigned long __init
> > > > xen_do_chunk(unsigned long start, .domid= DOMID_SELF
> > > > };
> > > > unsigned long len = 0;
> > > > +   int xlated_phys =
> > > > xen_feature(XENFEAT_auto_translated_physmap); unsigned long pfn;
> > > > int ret;
> > > >  
> > > > @@ -113,7 +118,7 @@ static unsigned long __init
> > > > xen_do_chunk(unsigned long start, continue;
> > > > frame = mfn;
> > > > } else {
> > > > -   if (mfn != INVALID_P2M_ENTRY)
> > > > +   if (!xlated_phys && mfn !=
> > > > INVALID_P2M_ENTRY) continue;
> > > > frame = pfn;
> > > > }
> > > 
> > > Shouldn't we add a "!xlated_phys &&" to the other case as well?
> > 
> > No. That is handled in xen_pvh_identity_map_chunk which
> > just does a xen_set_clr_mmio_pvh_pte call for the "released"
> > pages. But that is a bit of ... well, extra logic. I think
> > if we did this it would work and look much nicer:
> 
> Yes, I think that this version looks better

But doesn't boot:

(XEN) vmx_hybrid.c:710:d0 Dom:0 EPT violation 0x181 (r--/---), gpa 
0x00bf421e1c, mfn 0x, type 4.
(XEN) p2m-ept.c:642:d0 Walking EPT tables for domain 0 gfn bf421
(XEN) p2m-ept.c:648:d0  gfn exceeds max_mapped_pfn 4b062
(XEN) vmx_hybrid.c:717:d0  --- GLA 0xff477e1c


I'll have to debug it, or we can go back to the prev version, which
I don't think is that un-pretty :).

Mukesh


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [Xen-devel] [PATCH 4/6] xen/pvh: bootup and setup related changes.

2012-10-23 Thread Mukesh Rathor
On Tue, 23 Oct 2012 17:03:10 -0700
Mukesh Rathor  wrote:

> On Tue, 23 Oct 2012 16:47:29 -0700
> Mukesh Rathor  wrote:
> 
> > On Tue, 23 Oct 2012 14:07:06 +0100
> > Stefano Stabellini  wrote:
> > 
> > > On Mon, 22 Oct 2012, Konrad Rzeszutek Wilk wrote:
> > > > On Mon, Oct 22, 2012 at 02:34:44PM +0100, Stefano Stabellini
> > > > wrote:
> > > > > On Sat, 20 Oct 2012, Konrad Rzeszutek Wilk wrote:
> > > > > > From: Mukesh Rathor 
> > > > > > 
> > > > > > for (pfn = PFN_DOWN(start); pfn < xen_max_p2m_pfn;
> > > > > > pfn++) { unsigned long mfn = pfn_to_mfn(pfn);
> > > > > > @@ -100,6 +104,7 @@ static unsigned long __init
> > > > > > xen_do_chunk(unsigned long start, .domid= DOMID_SELF
> > > > > > };
> > > > > > unsigned long len = 0;
> > > > > > +   int xlated_phys =
> > > > > > xen_feature(XENFEAT_auto_translated_physmap); unsigned long
> > > > > > pfn; int ret;
> > > > > >  
> > > > > > @@ -113,7 +118,7 @@ static unsigned long __init
> > > > > > xen_do_chunk(unsigned long start, continue;
> > > > > > frame = mfn;
> > > > > > } else {
> > > > > > -   if (mfn != INVALID_P2M_ENTRY)
> > > > > > +   if (!xlated_phys && mfn !=
> > > > > > INVALID_P2M_ENTRY) continue;
> > > > > > frame = pfn;
> > > > > > }
> > > > > 
> > > > > Shouldn't we add a "!xlated_phys &&" to the other case as
> > > > > well?
> > > > 
> > > > No. That is handled in xen_pvh_identity_map_chunk which
> > > > just does a xen_set_clr_mmio_pvh_pte call for the "released"
> > > > pages. But that is a bit of ... well, extra logic. I think
> > > > if we did this it would work and look much nicer:
> > > 
> > > Yes, I think that this version looks better
> > 
> > But doesn't boot:
> > 
> > (XEN) vmx_hybrid.c:710:d0 Dom:0 EPT violation 0x181 (r--/---), gpa
> > 0x00bf421e1c, mfn 0x, type 4. (XEN)
> > p2m-ept.c:642:d0 Walking EPT tables for domain 0 gfn bf421 (XEN)
> > p2m-ept.c:648:d0  gfn exceeds max_mapped_pfn 4b062 (XEN)
> > vmx_hybrid.c:717:d0  --- GLA 0xff477e1c
> > 
> > 
> > I'll have to debug it, or we can go back to the prev version, which
> > I don't think is that un-pretty :).
> > 
> 
> The reason being:
> xen_set_identity_and_release_chunk():
> NEW : > for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn;
> pfn++) {
> 
> xen_pvh_identity_map_chunk():
> OLD: for (pfn = start_pfn; pfn < end_pfn; pfn++)
> 
> IOW, for PVH we need to avoid testing for max_pfn_mapped, as we are
> mapping the entire IO space. 

Also, now your counts for released and identity are off. Can we please
go back to the way it was? 

thanks
Mukesh
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [Xen-devel] [PATCH 4/6] xen/pvh: bootup and setup related changes.

2012-10-23 Thread Mukesh Rathor
On Tue, 23 Oct 2012 16:47:29 -0700
Mukesh Rathor  wrote:

> On Tue, 23 Oct 2012 14:07:06 +0100
> Stefano Stabellini  wrote:
> 
> > On Mon, 22 Oct 2012, Konrad Rzeszutek Wilk wrote:
> > > On Mon, Oct 22, 2012 at 02:34:44PM +0100, Stefano Stabellini
> > > wrote:
> > > > On Sat, 20 Oct 2012, Konrad Rzeszutek Wilk wrote:
> > > > > From: Mukesh Rathor 
> > > > > 
> > > > >   for (pfn = PFN_DOWN(start); pfn < xen_max_p2m_pfn;
> > > > > pfn++) { unsigned long mfn = pfn_to_mfn(pfn);
> > > > > @@ -100,6 +104,7 @@ static unsigned long __init
> > > > > xen_do_chunk(unsigned long start, .domid= DOMID_SELF
> > > > >   };
> > > > >   unsigned long len = 0;
> > > > > + int xlated_phys =
> > > > > xen_feature(XENFEAT_auto_translated_physmap); unsigned long
> > > > > pfn; int ret;
> > > > >  
> > > > > @@ -113,7 +118,7 @@ static unsigned long __init
> > > > > xen_do_chunk(unsigned long start, continue;
> > > > >   frame = mfn;
> > > > >   } else {
> > > > > - if (mfn != INVALID_P2M_ENTRY)
> > > > > + if (!xlated_phys && mfn !=
> > > > > INVALID_P2M_ENTRY) continue;
> > > > >   frame = pfn;
> > > > >   }
> > > > 
> > > > Shouldn't we add a "!xlated_phys &&" to the other case as well?
> > > 
> > > No. That is handled in xen_pvh_identity_map_chunk which
> > > just does a xen_set_clr_mmio_pvh_pte call for the "released"
> > > pages. But that is a bit of ... well, extra logic. I think
> > > if we did this it would work and look much nicer:
> > 
> > Yes, I think that this version looks better
> 
> But doesn't boot:
> 
> (XEN) vmx_hybrid.c:710:d0 Dom:0 EPT violation 0x181 (r--/---), gpa
> 0x00bf421e1c, mfn 0x, type 4. (XEN)
> p2m-ept.c:642:d0 Walking EPT tables for domain 0 gfn bf421 (XEN)
> p2m-ept.c:648:d0  gfn exceeds max_mapped_pfn 4b062 (XEN)
> vmx_hybrid.c:717:d0  --- GLA 0xff477e1c
> 
> 
> I'll have to debug it, or we can go back to the prev version, which
> I don't think is that un-pretty :).
> 

The reason being:
xen_set_identity_and_release_chunk():
NEW : > for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn; pfn++) {

xen_pvh_identity_map_chunk():
OLD: for (pfn = start_pfn; pfn < end_pfn; pfn++)

IOW, for PVH we need to avoid testing for max_pfn_mapped, as we are
mapping the entire IO space. 

thanks
mukesh

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/6] xen/pvh: bootup and setup related changes.

2012-10-23 Thread Stefano Stabellini
On Mon, 22 Oct 2012, Konrad Rzeszutek Wilk wrote:
> On Mon, Oct 22, 2012 at 02:34:44PM +0100, Stefano Stabellini wrote:
> > On Sat, 20 Oct 2012, Konrad Rzeszutek Wilk wrote:
> > > From: Mukesh Rathor 
> > > 
> > > In enlighten.c for PVH we can trap cpuid via vmexit, so don't
> > > need to use emulated prefix call. We also check for vector callback
> > > early on, as it is a required feature. PVH also runs at default kernel
> > > IOPL.
> > > 
> > > In setup.c, in xen_add_extra_mem() we can skip updating P2M as it's 
> > > managed
> > > by Xen. PVH maps the entire IO space, but only RAM pages need to be 
> > > repopulated.
> > > 
> > > Finally, pure PV settings are moved to a separate function that is only 
> > > called
> > > for pure PV, ie, pv with pvmmu.
> > > 
> > > Signed-off-by: Mukesh Rathor 
> > > Signed-off-by: Konrad Rzeszutek Wilk 
> > >
> > > diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
> > > index 8971a26..8cce47b 100644
> > > --- a/arch/x86/xen/setup.c
> > > +++ b/arch/x86/xen/setup.c
> > > @@ -27,6 +27,7 @@
> > >  #include 
> > >  #include 
> > >  #include 
> > > +#include "mmu.h"
> > >  #include "xen-ops.h"
> > >  #include "vdso.h"
> > >  
> > > @@ -78,6 +79,9 @@ static void __init xen_add_extra_mem(u64 start, u64 
> > > size)
> > >  
> > >   memblock_reserve(start, size);
> > >  
> > > + if (xen_feature(XENFEAT_auto_translated_physmap))
> > > + return;
> > > +
> > >   xen_max_p2m_pfn = PFN_DOWN(start + size);
> > >   for (pfn = PFN_DOWN(start); pfn < xen_max_p2m_pfn; pfn++) {
> > >   unsigned long mfn = pfn_to_mfn(pfn);
> > > @@ -100,6 +104,7 @@ static unsigned long __init xen_do_chunk(unsigned 
> > > long start,
> > >   .domid= DOMID_SELF
> > >   };
> > >   unsigned long len = 0;
> > > + int xlated_phys = xen_feature(XENFEAT_auto_translated_physmap);
> > >   unsigned long pfn;
> > >   int ret;
> > >  
> > > @@ -113,7 +118,7 @@ static unsigned long __init xen_do_chunk(unsigned 
> > > long start,
> > >   continue;
> > >   frame = mfn;
> > >   } else {
> > > - if (mfn != INVALID_P2M_ENTRY)
> > > + if (!xlated_phys && mfn != INVALID_P2M_ENTRY)
> > >   continue;
> > >   frame = pfn;
> > >   }
> > 
> > Shouldn't we add a "!xlated_phys &&" to the other case as well?
> 
> No. That is handled in xen_pvh_identity_map_chunk which
> just does a xen_set_clr_mmio_pvh_pte call for the "released"
> pages. But that is a bit of ... well, extra logic. I think
> if we did this it would work and look much nicer:

Yes, I think that this version looks better

> 
> diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
> index 8cce47b..b451a77 100644
> --- a/arch/x86/xen/setup.c
> +++ b/arch/x86/xen/setup.c
> @@ -114,9 +114,15 @@ static unsigned long __init xen_do_chunk(unsigned long 
> start,
>  
>   if (release) {
>   /* Make sure pfn exists to start with */
> - if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn)
> + if (mfn == INVALID_P2M_ENTRY || (!xlated_phys && 
> (mfn_to_pfn(mfn) != pfn)))
>   continue;
>   frame = mfn;
> + /* The hypercall PHYSDEVOP_map_iomem to release memory 
> has already
> +  * happend, so we just do a nop here. */
> + if (xlated_phys) {
> + len++;
> + continue;
> + }
>   } else {
>   if (!xlated_phys && mfn != INVALID_P2M_ENTRY)
>   continue;
> @@ -219,15 +225,24 @@ static void __init xen_set_identity_and_release_chunk(
>  {
>   unsigned long pfn;
>  
> + /* For PVH, the pfns [0..MAX] are mapped to mfn's in the EPT/NPT. The 
> mfns
> +  * are released as part of this 1:1 mapping hypercall back to the dom 
> heap.
> +  * Also, we map the entire IO space, ie, beyond max_pfn_mapped.
> +  */
> + int xlated_phys = xen_feature(XENFEAT_auto_translated_physmap);
> +
>   /*
>* If the PFNs are currently mapped, the VA mapping also needs
>* to be updated to be 1:1.
>*/
> - for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn; pfn++)
> - (void)HYPERVISOR_update_va_mapping(
> - (unsigned long)__va(pfn << PAGE_SHIFT),
> - mfn_pte(pfn, PAGE_KERNEL_IO), 0);
> -
> + for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn; pfn++) {
> + if (xlated_phys)
> + xen_set_clr_mmio_pvh_pte(pfn, pfn, 1 /* one pfn */, 1 
> /* add mapping */);
> + else
> + (void)HYPERVISOR_update_va_mapping(
> + (unsigned long)__va(pfn << PAGE_SHIFT),
> + mfn_pte(pfn, PAGE_KERNEL_IO), 0);
> + }
>  

Re: [PATCH 4/6] xen/pvh: bootup and setup related changes.

2012-10-22 Thread Konrad Rzeszutek Wilk
On Mon, Oct 22, 2012 at 02:34:44PM +0100, Stefano Stabellini wrote:
> On Sat, 20 Oct 2012, Konrad Rzeszutek Wilk wrote:
> > From: Mukesh Rathor 
> > 
> > In enlighten.c for PVH we can trap cpuid via vmexit, so don't
> > need to use emulated prefix call. We also check for vector callback
> > early on, as it is a required feature. PVH also runs at default kernel
> > IOPL.
> > 
> > In setup.c, in xen_add_extra_mem() we can skip updating P2M as it's managed
> > by Xen. PVH maps the entire IO space, but only RAM pages need to be 
> > repopulated.
> > 
> > Finally, pure PV settings are moved to a separate function that is only 
> > called
> > for pure PV, ie, pv with pvmmu.
> > 
> > Signed-off-by: Mukesh Rathor 
> > Signed-off-by: Konrad Rzeszutek Wilk 
> >
> > diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
> > index 8971a26..8cce47b 100644
> > --- a/arch/x86/xen/setup.c
> > +++ b/arch/x86/xen/setup.c
> > @@ -27,6 +27,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include "mmu.h"
> >  #include "xen-ops.h"
> >  #include "vdso.h"
> >  
> > @@ -78,6 +79,9 @@ static void __init xen_add_extra_mem(u64 start, u64 size)
> >  
> > memblock_reserve(start, size);
> >  
> > +   if (xen_feature(XENFEAT_auto_translated_physmap))
> > +   return;
> > +
> > xen_max_p2m_pfn = PFN_DOWN(start + size);
> > for (pfn = PFN_DOWN(start); pfn < xen_max_p2m_pfn; pfn++) {
> > unsigned long mfn = pfn_to_mfn(pfn);
> > @@ -100,6 +104,7 @@ static unsigned long __init xen_do_chunk(unsigned long 
> > start,
> > .domid= DOMID_SELF
> > };
> > unsigned long len = 0;
> > +   int xlated_phys = xen_feature(XENFEAT_auto_translated_physmap);
> > unsigned long pfn;
> > int ret;
> >  
> > @@ -113,7 +118,7 @@ static unsigned long __init xen_do_chunk(unsigned long 
> > start,
> > continue;
> > frame = mfn;
> > } else {
> > -   if (mfn != INVALID_P2M_ENTRY)
> > +   if (!xlated_phys && mfn != INVALID_P2M_ENTRY)
> > continue;
> > frame = pfn;
> > }
> 
> Shouldn't we add a "!xlated_phys &&" to the other case as well?

No. That is handled in xen_pvh_identity_map_chunk which
just does a xen_set_clr_mmio_pvh_pte call for the "released"
pages. But that is a bit of ... well, extra logic. I think
if we did this it would work and look much nicer:


diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index 8cce47b..b451a77 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -114,9 +114,15 @@ static unsigned long __init xen_do_chunk(unsigned long 
start,
 
if (release) {
/* Make sure pfn exists to start with */
-   if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn)
+   if (mfn == INVALID_P2M_ENTRY || (!xlated_phys && 
(mfn_to_pfn(mfn) != pfn)))
continue;
frame = mfn;
+   /* The hypercall PHYSDEVOP_map_iomem to release memory 
has already
+* happend, so we just do a nop here. */
+   if (xlated_phys) {
+   len++;
+   continue;
+   }
} else {
if (!xlated_phys && mfn != INVALID_P2M_ENTRY)
continue;
@@ -219,15 +225,24 @@ static void __init xen_set_identity_and_release_chunk(
 {
unsigned long pfn;
 
+   /* For PVH, the pfns [0..MAX] are mapped to mfn's in the EPT/NPT. The 
mfns
+* are released as part of this 1:1 mapping hypercall back to the dom 
heap.
+* Also, we map the entire IO space, ie, beyond max_pfn_mapped.
+*/
+   int xlated_phys = xen_feature(XENFEAT_auto_translated_physmap);
+
/*
 * If the PFNs are currently mapped, the VA mapping also needs
 * to be updated to be 1:1.
 */
-   for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn; pfn++)
-   (void)HYPERVISOR_update_va_mapping(
-   (unsigned long)__va(pfn << PAGE_SHIFT),
-   mfn_pte(pfn, PAGE_KERNEL_IO), 0);
-
+   for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn; pfn++) {
+   if (xlated_phys)
+   xen_set_clr_mmio_pvh_pte(pfn, pfn, 1 /* one pfn */, 1 
/* add mapping */);
+   else
+   (void)HYPERVISOR_update_va_mapping(
+   (unsigned long)__va(pfn << PAGE_SHIFT),
+   mfn_pte(pfn, PAGE_KERNEL_IO), 0);
+   }
if (start_pfn < nr_pages)
*released += xen_release_chunk(
start_pfn, min(end_pfn, nr_pages));
@@ -235,27 +250,6 @@ static void __init xen_set_identity_and_release_chunk(
*identity += set_phys_

Re: [PATCH 4/6] xen/pvh: bootup and setup related changes.

2012-10-22 Thread Stefano Stabellini
On Sat, 20 Oct 2012, Konrad Rzeszutek Wilk wrote:
> From: Mukesh Rathor 
> 
> In enlighten.c for PVH we can trap cpuid via vmexit, so don't
> need to use emulated prefix call. We also check for vector callback
> early on, as it is a required feature. PVH also runs at default kernel
> IOPL.
> 
> In setup.c, in xen_add_extra_mem() we can skip updating P2M as it's managed
> by Xen. PVH maps the entire IO space, but only RAM pages need to be 
> repopulated.
> 
> Finally, pure PV settings are moved to a separate function that is only called
> for pure PV, ie, pv with pvmmu.
> 
> Signed-off-by: Mukesh Rathor 
> Signed-off-by: Konrad Rzeszutek Wilk 
>
> diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
> index 8971a26..8cce47b 100644
> --- a/arch/x86/xen/setup.c
> +++ b/arch/x86/xen/setup.c
> @@ -27,6 +27,7 @@
>  #include 
>  #include 
>  #include 
> +#include "mmu.h"
>  #include "xen-ops.h"
>  #include "vdso.h"
>  
> @@ -78,6 +79,9 @@ static void __init xen_add_extra_mem(u64 start, u64 size)
>  
>   memblock_reserve(start, size);
>  
> + if (xen_feature(XENFEAT_auto_translated_physmap))
> + return;
> +
>   xen_max_p2m_pfn = PFN_DOWN(start + size);
>   for (pfn = PFN_DOWN(start); pfn < xen_max_p2m_pfn; pfn++) {
>   unsigned long mfn = pfn_to_mfn(pfn);
> @@ -100,6 +104,7 @@ static unsigned long __init xen_do_chunk(unsigned long 
> start,
>   .domid= DOMID_SELF
>   };
>   unsigned long len = 0;
> + int xlated_phys = xen_feature(XENFEAT_auto_translated_physmap);
>   unsigned long pfn;
>   int ret;
>  
> @@ -113,7 +118,7 @@ static unsigned long __init xen_do_chunk(unsigned long 
> start,
>   continue;
>   frame = mfn;
>   } else {
> - if (mfn != INVALID_P2M_ENTRY)
> + if (!xlated_phys && mfn != INVALID_P2M_ENTRY)
>   continue;
>   frame = pfn;
>   }

Shouldn't we add a "!xlated_phys &&" to the other case as well?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/6] xen/pvh: bootup and setup related changes.

2012-10-19 Thread Konrad Rzeszutek Wilk
From: Mukesh Rathor 

In enlighten.c for PVH we can trap cpuid via vmexit, so don't
need to use emulated prefix call. We also check for vector callback
early on, as it is a required feature. PVH also runs at default kernel
IOPL.

In setup.c, in xen_add_extra_mem() we can skip updating P2M as it's managed
by Xen. PVH maps the entire IO space, but only RAM pages need to be repopulated.

Finally, pure PV settings are moved to a separate function that is only called
for pure PV, ie, pv with pvmmu.

Signed-off-by: Mukesh Rathor 
Signed-off-by: Konrad Rzeszutek Wilk 
---
 arch/x86/xen/enlighten.c |   77 ++---
 arch/x86/xen/setup.c |   64 +++---
 2 files changed, 110 insertions(+), 31 deletions(-)

diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index e3497f2..53db37f 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -45,6 +45,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -107,6 +108,9 @@ RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
 __read_mostly int xen_have_vector_callback;
 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
 
+#define xen_pvh_domain() (xen_pv_domain() && \
+ xen_feature(XENFEAT_auto_translated_physmap) && \
+ xen_have_vector_callback)
 /*
  * Point at some empty memory to start with. We map the real shared_info
  * page as soon as fixmap is up and running.
@@ -219,8 +223,9 @@ static void __init xen_banner(void)
struct xen_extraversion extra;
HYPERVISOR_xen_version(XENVER_extraversion, &extra);
 
-   printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
-  pv_info.name);
+   pr_info("Booting paravirtualized kernel %son %s\n",
+   xen_feature(XENFEAT_auto_translated_physmap) ?
+   "with PVH extensions " : "", pv_info.name);
printk(KERN_INFO "Xen version: %d.%d%s%s\n",
   version >> 16, version & 0x, extra.extraversion,
   xen_feature(XENFEAT_mmu_pt_update_preserve_ad) ? " 
(preserve-AD)" : "");
@@ -273,12 +278,15 @@ static void xen_cpuid(unsigned int *ax, unsigned int *bx,
break;
}
 
-   asm(XEN_EMULATE_PREFIX "cpuid"
-   : "=a" (*ax),
- "=b" (*bx),
- "=c" (*cx),
- "=d" (*dx)
-   : "0" (*ax), "2" (*cx));
+   if (xen_pvh_domain())
+   native_cpuid(ax, bx, cx, dx);
+   else
+   asm(XEN_EMULATE_PREFIX "cpuid"
+   : "=a" (*ax),
+   "=b" (*bx),
+   "=c" (*cx),
+   "=d" (*dx)
+   : "0" (*ax), "2" (*cx));
 
*bx &= maskebx;
*cx &= maskecx;
@@ -1055,6 +1063,10 @@ void xen_setup_shared_info(void)
HYPERVISOR_shared_info =
(struct shared_info *)__va(xen_start_info->shared_info);
 
+   /* PVH TBD/FIXME: vcpu info placement in phase 2 */
+   if (xen_pvh_domain())
+   return;
+
 #ifndef CONFIG_SMP
/* In UP this is as good a place as any to set up shared info */
xen_setup_vcpu_info_placement();
@@ -1292,6 +1304,11 @@ static const struct machine_ops xen_machine_ops 
__initconst = {
  */
 static void __init xen_setup_stackprotector(void)
 {
+   /* PVH TBD/FIXME: investigate setup_stack_canary_segment */
+   if (xen_feature(XENFEAT_auto_translated_physmap)) {
+   switch_to_new_gdt(0);
+   return;
+   }
pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
pv_cpu_ops.load_gdt = xen_load_gdt_boot;
 
@@ -1302,6 +1319,19 @@ static void __init xen_setup_stackprotector(void)
pv_cpu_ops.load_gdt = xen_load_gdt;
 }
 
+static void __init xen_pvh_early_guest_init(void)
+{
+   if (xen_feature(XENFEAT_hvm_callback_vector))
+   xen_have_vector_callback = 1;
+
+#ifdef CONFIG_X86_32
+   if (xen_feature(XENFEAT_auto_translated_physmap)) {
+   xen_raw_printk("ERROR: 32bit PVH guests are not supported\n");
+   BUG();
+   }
+#endif
+}
+
 /* First C function to be called on Xen boot */
 asmlinkage void __init xen_start_kernel(void)
 {
@@ -1313,13 +1343,18 @@ asmlinkage void __init xen_start_kernel(void)
 
xen_domain_type = XEN_PV_DOMAIN;
 
+   xen_setup_features();
+   xen_pvh_early_guest_init();
xen_setup_machphys_mapping();
 
/* Install Xen paravirt ops */
pv_info = xen_info;
pv_init_ops = xen_init_ops;
-   pv_cpu_ops = xen_cpu_ops;
pv_apic_ops = xen_apic_ops;
+   if (xen_pvh_domain())
+   pv_cpu_ops.cpuid = xen_cpuid;
+   else
+   pv_cpu_ops = xen_cpu_ops;
 
x86_init.resources.memory_setup = xen_memory_setup;
x86_init.oem.arch_setup = xen_arch_setup;
@@ -1351,8 +1386,6 @@ asmlinkage void __init xen_start_ker