mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: linux-kernel@vger.kernel.org, fujita.tomonori@lab.ntt.co.jp,
	iommu@lists.linux-foundation.org, albert_herranz@yahoo.es,
	x86@kernel.org
Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH 01/19] xen: use _PAGE_IOMAP in ioremap to do machine mappings
Date: Tue, 22 Jun 2010 15:42:34 -0400	[thread overview]
Message-ID: <1277235772-26757-2-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1277235772-26757-1-git-send-email-konrad.wilk@oracle.com>

From: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>

In a Xen domain, ioremap operates on machine addresses, not
pseudo-physical addresses.  We use _PAGE_IOMAP to determine whether a
mapping is intended for machine addresses.

[ Impact: allow Xen domain to map real hardware ]

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 arch/x86/include/asm/xen/page.h |    8 +---
 arch/x86/xen/mmu.c              |   71 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 018a0a4..bf5f7d3 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -112,13 +112,9 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
  */
 static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
 {
-	extern unsigned long max_mapnr;
 	unsigned long pfn = mfn_to_pfn(mfn);
-	if ((pfn < max_mapnr)
-	    && !xen_feature(XENFEAT_auto_translated_physmap)
-	    && (get_phys_to_machine(pfn) != mfn))
-		return max_mapnr; /* force !pfn_valid() */
-	/* XXX fixme; not true with sparsemem */
+	if (get_phys_to_machine(pfn) != mfn)
+		return -1; /* force !pfn_valid() */
 	return pfn;
 }
 
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index 914f046..a4dea9d 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -56,9 +56,11 @@
 #include <asm/xen/hypercall.h>
 #include <asm/xen/hypervisor.h>
 
+#include <xen/xen.h>
 #include <xen/page.h>
 #include <xen/interface/xen.h>
 #include <xen/interface/version.h>
+#include <xen/interface/memory.h>
 #include <xen/hvc-console.h>
 
 #include "multicalls.h"
@@ -377,6 +379,28 @@ static bool xen_page_pinned(void *ptr)
 	return PagePinned(page);
 }
 
+static bool xen_iomap_pte(pte_t pte)
+{
+	return xen_initial_domain() && (pte_flags(pte) & _PAGE_IOMAP);
+}
+
+static void xen_set_iomap_pte(pte_t *ptep, pte_t pteval)
+{
+	struct multicall_space mcs;
+	struct mmu_update *u;
+
+	mcs = xen_mc_entry(sizeof(*u));
+	u = mcs.args;
+
+	/* ptep might be kmapped when using 32-bit HIGHPTE */
+	u->ptr = arbitrary_virt_to_machine(ptep).maddr;
+	u->val = pte_val_ma(pteval);
+
+	MULTI_mmu_update(mcs.mc, mcs.args, 1, NULL, DOMID_IO);
+
+	xen_mc_issue(PARAVIRT_LAZY_MMU);
+}
+
 static void xen_extend_mmu_update(const struct mmu_update *update)
 {
 	struct multicall_space mcs;
@@ -453,6 +477,11 @@ void set_pte_mfn(unsigned long vaddr, unsigned long mfn, pgprot_t flags)
 void xen_set_pte_at(struct mm_struct *mm, unsigned long addr,
 		    pte_t *ptep, pte_t pteval)
 {
+	if (xen_iomap_pte(pteval)) {
+		xen_set_iomap_pte(ptep, pteval);
+		goto out;
+	}
+
 	ADD_STATS(set_pte_at, 1);
 //	ADD_STATS(set_pte_at_pinned, xen_page_pinned(ptep));
 	ADD_STATS(set_pte_at_current, mm == current->mm);
@@ -523,8 +552,25 @@ static pteval_t pte_pfn_to_mfn(pteval_t val)
 	return val;
 }
 
+static pteval_t iomap_pte(pteval_t val)
+{
+	if (val & _PAGE_PRESENT) {
+		unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
+		pteval_t flags = val & PTE_FLAGS_MASK;
+
+		/* We assume the pte frame number is a MFN, so
+		   just use it as-is. */
+		val = ((pteval_t)pfn << PAGE_SHIFT) | flags;
+	}
+
+	return val;
+}
+
 pteval_t xen_pte_val(pte_t pte)
 {
+	if (xen_initial_domain() && (pte.pte & _PAGE_IOMAP))
+		return pte.pte;
+
 	return pte_mfn_to_pfn(pte.pte);
 }
 PV_CALLEE_SAVE_REGS_THUNK(xen_pte_val);
@@ -537,7 +583,11 @@ PV_CALLEE_SAVE_REGS_THUNK(xen_pgd_val);
 
 pte_t xen_make_pte(pteval_t pte)
 {
-	pte = pte_pfn_to_mfn(pte);
+	if (unlikely(xen_initial_domain() && (pte & _PAGE_IOMAP)))
+		pte = iomap_pte(pte);
+	else
+		pte = pte_pfn_to_mfn(pte);
+
 	return native_make_pte(pte);
 }
 PV_CALLEE_SAVE_REGS_THUNK(xen_make_pte);
@@ -593,6 +643,11 @@ void xen_set_pud(pud_t *ptr, pud_t val)
 
 void xen_set_pte(pte_t *ptep, pte_t pte)
 {
+	if (xen_iomap_pte(pte)) {
+		xen_set_iomap_pte(ptep, pte);
+		return;
+	}
+
 	ADD_STATS(pte_update, 1);
 //	ADD_STATS(pte_update_pinned, xen_page_pinned(ptep));
 	ADD_STATS(pte_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU);
@@ -609,6 +664,11 @@ void xen_set_pte(pte_t *ptep, pte_t pte)
 #ifdef CONFIG_X86_PAE
 void xen_set_pte_atomic(pte_t *ptep, pte_t pte)
 {
+	if (xen_iomap_pte(pte)) {
+		xen_set_iomap_pte(ptep, pte);
+		return;
+	}
+
 	set_64bit((u64 *)ptep, native_pte_val(pte));
 }
 
@@ -1811,9 +1871,16 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
 		pte = pfn_pte(phys, prot);
 		break;
 
-	default:
+	case FIX_PARAVIRT_BOOTMAP:
+		/* This is an MFN, but it isn't an IO mapping from the
+		   IO domain */
 		pte = mfn_pte(phys, prot);
 		break;
+
+	default:
+		/* By default, set_fixmap is used for hardware mappings */
+		pte = mfn_pte(phys, __pgprot(pgprot_val(prot) | _PAGE_IOMAP));
+		break;
 	}
 
 	__native_set_fixmap(idx, pte);
-- 
1.7.0.1


  reply	other threads:[~2010-06-22 19:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-22 19:42 [PATCH] Xen-SWIOTBL v0.8.3 used for Xen PCI pass through for PV guests Konrad Rzeszutek Wilk
2010-06-22 19:42 ` Konrad Rzeszutek Wilk [this message]
2010-06-22 19:42 ` [PATCH 02/19] xen: Allow unprivileged Xen domains to create iomap pages Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 03/19] xen: Rename the balloon lock Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 04/19] xen: Add xen_create_contiguous_region Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 05/19] swiotlb-xen: Early skeleton code and explanation Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 06/19] swiotlb-xen: Copied swiotlb.c in, added xen_ prefix Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 07/19] swiotlb-xen: Make 'xen_swiotlb_alloc_coherent' work Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 08/19] swiotlb-xen: Don't allocate DMA-memory beyond 4GB in 32-bit mode Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 09/19] swiotlb-xen: Make 'xen_swiotlb_free_coherent' work Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 10/19] swiotlb-xen: Make 'xen_swiotlb_[map|unmap]_page' work Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 11/19] swiotlb-xen: Make 'xen_swiotlb_sync_single' work Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 12/19] swiotlb-xen: Make 'xen_swiotlb_map_sg_attrs' work Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 13/19] swiotlb-xen: Remove io_tlb_overflow usage Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 14/19] swiotlb-xen: Add 'xen_swiotlb_init' function Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 15/19] swiotlb-xen: Put 'swiotlb-xen.c' function declarations in the header Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 16/19] swiotlb-xen: Removing the 'struct device' in the address translation routines Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 17/19] swiotlb-xen: Coalesce usage of xen_swiotlb_map Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 18/19] pci-swiotlb-xen: Add glue code to setup dma_ops utilizing xen_swiotlb_* functions Konrad Rzeszutek Wilk
2010-06-22 19:42 ` [PATCH 19/19] x86: Detect whether we should use Xen SWIOTLB Konrad Rzeszutek Wilk
2010-06-22 21:23 ` [PATCH] Xen-SWIOTBL v0.8.3 used for Xen PCI pass through for PV guests Alex Williamson
2010-06-23 16:32   ` Konrad Rzeszutek Wilk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1277235772-26757-2-git-send-email-konrad.wilk@oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=albert_herranz@yahoo.es \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jeremy.fitzhardinge@citrix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®