public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] xen: don't drop NX bit
@ 2008-06-16 22:01 Jeremy Fitzhardinge
  2008-06-16 22:35 ` [stable] " Greg KH
  2008-06-20 12:59 ` Ingo Molnar
  0 siblings, 2 replies; 7+ messages in thread
From: Jeremy Fitzhardinge @ 2008-06-16 22:01 UTC (permalink / raw)
  To: the arch/x86 maintainers; +Cc: Stable Kernel, Linux Kernel Mailing List

When converting the pfn/mfn in a pagetable entry, make sure we mask
out the protection flags properly.  Formerly, this code was losing the
NX bit, and not dealing with extra Xen-defined software flags in ptes.

Because NX is now enforced properly, we must put the hypercall page
into the .text segment so that it is executable.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: Stable Kernel <stable@kernel.org>
---
 arch/x86/xen/mmu.c      |   56 ++++++++++++++++++++++++++---------------------
 arch/x86/xen/xen-head.S |    2 -
 2 files changed, 32 insertions(+), 26 deletions(-)

===================================================================
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -323,46 +323,54 @@
 		preempt_enable();
 }
 
+/* Assume pteval_t is equivalent to all the other *val_t types. */
+static pteval_t pte_mfn_to_pfn(pteval_t val)
+{
+	if (val & _PAGE_PRESENT) {
+		unsigned long mfn = (val & PTE_MASK) >> PAGE_SHIFT;
+		pteval_t flags = val & ~PTE_MASK;
+		val = (mfn_to_pfn(mfn) << PAGE_SHIFT) | flags;
+	}
+
+	return val;
+}
+
+static pteval_t pte_pfn_to_mfn(pteval_t val)
+{
+	if (val & _PAGE_PRESENT) {
+		unsigned long pfn = (val & PTE_MASK) >> PAGE_SHIFT;
+		pteval_t flags = val & ~PTE_MASK;
+		val = (pfn_to_mfn(pfn) << PAGE_SHIFT) | flags;
+	}
+
+	return val;
+}
+
 pteval_t xen_pte_val(pte_t pte)
 {
-	pteval_t ret = pte.pte;
-
-	if (ret & _PAGE_PRESENT)
-		ret = machine_to_phys(XMADDR(ret)).paddr | _PAGE_PRESENT;
-
-	return ret;
+	return pte_mfn_to_pfn(pte.pte);
 }
 
 pgdval_t xen_pgd_val(pgd_t pgd)
 {
-	pgdval_t ret = pgd.pgd;
-	if (ret & _PAGE_PRESENT)
-		ret = machine_to_phys(XMADDR(ret)).paddr | _PAGE_PRESENT;
-	return ret;
+	return pte_mfn_to_pfn(pgd.pgd);
 }
 
 pte_t xen_make_pte(pteval_t pte)
 {
-	if (pte & _PAGE_PRESENT)
-		pte = phys_to_machine(XPADDR(pte)).maddr;
-
-	return (pte_t){ .pte = pte };
+	pte = pte_pfn_to_mfn(pte);
+	return native_make_pte(pte);
 }
 
 pgd_t xen_make_pgd(pgdval_t pgd)
 {
-	if (pgd & _PAGE_PRESENT)
-		pgd = phys_to_machine(XPADDR(pgd)).maddr;
-
-	return (pgd_t){ pgd };
+	pgd = pte_pfn_to_mfn(pgd);
+	return native_make_pgd(pgd);
 }
 
 pmdval_t xen_pmd_val(pmd_t pmd)
 {
-	pmdval_t ret = native_pmd_val(pmd);
-	if (ret & _PAGE_PRESENT)
-		ret = machine_to_phys(XMADDR(ret)).paddr | _PAGE_PRESENT;
-	return ret;
+	return pte_mfn_to_pfn(pmd.pmd);
 }
 
 void xen_set_pud_hyper(pud_t *ptr, pud_t val)
@@ -421,9 +429,7 @@
 
 pmd_t xen_make_pmd(pmdval_t pmd)
 {
-	if (pmd & _PAGE_PRESENT)
-		pmd = phys_to_machine(XPADDR(pmd)).maddr;
-
+	pmd = pte_pfn_to_mfn(pmd);
 	return native_make_pmd(pmd);
 }
 
===================================================================
--- a/arch/x86/xen/xen-head.S
+++ b/arch/x86/xen/xen-head.S
@@ -18,7 +18,7 @@
 
 	__FINIT
 
-.pushsection .bss.page_aligned
+.pushsection .text
 	.align PAGE_SIZE_asm
 ENTRY(hypercall_page)
 	.skip 0x1000



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

* Re: [stable] [PATCH 2/2] xen: don't drop NX bit
  2008-06-16 22:01 [PATCH 2/2] xen: don't drop NX bit Jeremy Fitzhardinge
@ 2008-06-16 22:35 ` Greg KH
  2008-06-16 22:51   ` Jeremy Fitzhardinge
  2008-06-17 23:13   ` Chris Wright
  2008-06-20 12:59 ` Ingo Molnar
  1 sibling, 2 replies; 7+ messages in thread
From: Greg KH @ 2008-06-16 22:35 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: the arch/x86 maintainers, Stable Kernel,
	Linux Kernel Mailing List

On Mon, Jun 16, 2008 at 03:01:56PM -0700, Jeremy Fitzhardinge wrote:
> When converting the pfn/mfn in a pagetable entry, make sure we mask
> out the protection flags properly.  Formerly, this code was losing the
> NX bit, and not dealing with extra Xen-defined software flags in ptes.
> 
> Because NX is now enforced properly, we must put the hypercall page
> into the .text segment so that it is executable.
> 
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Cc: Stable Kernel <stable@kernel.org>

While it's great that you tell the stable people about this, but is it
realistic?  Is anyone using Xen as contained in the mainline kernel
these days?

If a distro were to be based on 2.6.25 and we take this patch, they will
just revert it back out due to their very large Xen patchset they apply
on top to get a "working" Xen version, right?

thanks,

greg k-h

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

* Re: [stable] [PATCH 2/2] xen: don't drop NX bit
  2008-06-16 22:35 ` [stable] " Greg KH
@ 2008-06-16 22:51   ` Jeremy Fitzhardinge
  2008-06-16 23:37     ` Greg KH
  2008-06-17 23:13   ` Chris Wright
  1 sibling, 1 reply; 7+ messages in thread
From: Jeremy Fitzhardinge @ 2008-06-16 22:51 UTC (permalink / raw)
  To: Greg KH; +Cc: the arch/x86 maintainers, Stable Kernel,
	Linux Kernel Mailing List

Greg KH wrote:
> While it's great that you tell the stable people about this, but is it
> realistic?  Is anyone using Xen as contained in the mainline kernel
> these days?
>   

Yes, it's what Redhat is shipping in Fedora 9.

> If a distro were to be based on 2.6.25 and we take this patch, they will
> just revert it back out due to their very large Xen patchset they apply
> on top to get a "working" Xen version, right?
>   

No.  RH is using upstream Xen now.  I don't know what the other distros 
are doing, but Novell is considering it, at least.

    J

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

* Re: [stable] [PATCH 2/2] xen: don't drop NX bit
  2008-06-16 22:51   ` Jeremy Fitzhardinge
@ 2008-06-16 23:37     ` Greg KH
  2008-06-17 23:14       ` Chris Wright
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2008-06-16 23:37 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: the arch/x86 maintainers, Stable Kernel,
	Linux Kernel Mailing List

On Mon, Jun 16, 2008 at 03:51:37PM -0700, Jeremy Fitzhardinge wrote:
> Greg KH wrote:
>> While it's great that you tell the stable people about this, but is it
>> realistic?  Is anyone using Xen as contained in the mainline kernel
>> these days?
>>   
>
> Yes, it's what Redhat is shipping in Fedora 9.

Wow, great, I didn't realize this!  Nevermind then :)

>> If a distro were to be based on 2.6.25 and we take this patch, they will
>> just revert it back out due to their very large Xen patchset they apply
>> on top to get a "working" Xen version, right?
>>   
>
> No.  RH is using upstream Xen now.  I don't know what the other distros are 
> doing, but Novell is considering it, at least.

Heh, Novell isn't using it right now, look at the series of patches in
opensuse 11.0 for proof of that :(

Ok, no objection from me, when these hit Linus's tree we'll add them to
the -stable queue.

thanks,

greg k-h

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

* Re: [stable] [PATCH 2/2] xen: don't drop NX bit
  2008-06-16 22:35 ` [stable] " Greg KH
  2008-06-16 22:51   ` Jeremy Fitzhardinge
@ 2008-06-17 23:13   ` Chris Wright
  1 sibling, 0 replies; 7+ messages in thread
From: Chris Wright @ 2008-06-17 23:13 UTC (permalink / raw)
  To: Greg KH
  Cc: Jeremy Fitzhardinge, the arch/x86 maintainers, Stable Kernel,
	Linux Kernel Mailing List

* Greg KH (greg@kroah.com) wrote:
> On Mon, Jun 16, 2008 at 03:01:56PM -0700, Jeremy Fitzhardinge wrote:
> > When converting the pfn/mfn in a pagetable entry, make sure we mask
> > out the protection flags properly.  Formerly, this code was losing the
> > NX bit, and not dealing with extra Xen-defined software flags in ptes.
> > 
> > Because NX is now enforced properly, we must put the hypercall page
> > into the .text segment so that it is executable.
> > 
> > Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> > Cc: Stable Kernel <stable@kernel.org>
> 
> While it's great that you tell the stable people about this, but is it
> realistic?  Is anyone using Xen as contained in the mainline kernel
> these days?
> 
> If a distro were to be based on 2.6.25 and we take this patch, they will
> just revert it back out due to their very large Xen patchset they apply
> on top to get a "working" Xen version, right?

Fedora uses proper pv-ops for Xen.  It's a good -stable candidate.

Acked-by: Chris Wright <chrisw@sous-sol.org>

thanks,
-chris

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

* Re: [stable] [PATCH 2/2] xen: don't drop NX bit
  2008-06-16 23:37     ` Greg KH
@ 2008-06-17 23:14       ` Chris Wright
  0 siblings, 0 replies; 7+ messages in thread
From: Chris Wright @ 2008-06-17 23:14 UTC (permalink / raw)
  To: Greg KH
  Cc: Jeremy Fitzhardinge, the arch/x86 maintainers, Stable Kernel,
	Linux Kernel Mailing List

* Greg KH (greg@kroah.com) wrote:
> Heh, Novell isn't using it right now, look at the series of patches in
> opensuse 11.0 for proof of that :(

Yeah, be much better when the fwd porting madness has stopped.

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

* Re: [PATCH 2/2] xen: don't drop NX bit
  2008-06-16 22:01 [PATCH 2/2] xen: don't drop NX bit Jeremy Fitzhardinge
  2008-06-16 22:35 ` [stable] " Greg KH
@ 2008-06-20 12:59 ` Ingo Molnar
  1 sibling, 0 replies; 7+ messages in thread
From: Ingo Molnar @ 2008-06-20 12:59 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: the arch/x86 maintainers, Stable Kernel,
	Linux Kernel Mailing List


* Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> When converting the pfn/mfn in a pagetable entry, make sure we mask 
> out the protection flags properly.  Formerly, this code was losing the 
> NX bit, and not dealing with extra Xen-defined software flags in ptes.
>
> Because NX is now enforced properly, we must put the hypercall page 
> into the .text segment so that it is executable.

applied all three fix patches to tip/x86/xen, thanks Jeremy.

i have also cherry-picked them into x86/urgent, to push v2.6.26-wards if 
they passes testing. The commits are [in that order]:

# x86/urgent: 4653938: xen: Use wmb instead of rmb in xen_evtchn_do_upcall().
# x86/urgent: 05345b0: xen: mask unwanted pte bits in __supported_pte_mask
# x86/urgent: ebb9cfe: xen: don't drop NX bit

	Ingo

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

end of thread, other threads:[~2008-06-20 12:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-16 22:01 [PATCH 2/2] xen: don't drop NX bit Jeremy Fitzhardinge
2008-06-16 22:35 ` [stable] " Greg KH
2008-06-16 22:51   ` Jeremy Fitzhardinge
2008-06-16 23:37     ` Greg KH
2008-06-17 23:14       ` Chris Wright
2008-06-17 23:13   ` Chris Wright
2008-06-20 12:59 ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox