[PATCH 4/5] break up slow_virt_to_phys()

From: Dave Hansen
Date: Wed Apr 10 2013 - 19:38:04 EST



I need to use slow_virt_to_phys()'s functionality for addresses
which might not be valid. So, I need a copy which can cleanly
return errors instead of doing a BUG_ON().

Signed-off-by: Dave Hansen <dave@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
---

linux.git-davehans/arch/x86/mm/pageattr.c | 40 +++++++++++++++++++-----------
1 file changed, 26 insertions(+), 14 deletions(-)

diff -puN arch/x86/mm/pageattr.c~break-up-slow-virt_to_phys arch/x86/mm/pageattr.c
--- linux.git/arch/x86/mm/pageattr.c~break-up-slow-virt_to_phys 2013-04-10 16:23:45.571087500 -0700
+++ linux.git-davehans/arch/x86/mm/pageattr.c 2013-04-10 16:23:45.574087504 -0700
@@ -363,18 +363,7 @@ pte_t *lookup_address(unsigned long addr
}
EXPORT_SYMBOL_GPL(lookup_address);

-/*
- * This is necessary because __pa() does not work on some
- * kinds of memory, like vmalloc() or the alloc_remap()
- * areas on 32-bit NUMA systems. The percpu areas can
- * end up in this kind of memory, for instance.
- *
- * This could be optimized, but it is only intended to be
- * used at inititalization time, and keeping it
- * unoptimized should increase the testing coverage for
- * the more obscure platforms.
- */
-phys_addr_t slow_virt_to_phys(void *__virt_addr)
+int kernel_lookup_vaddr(void *__virt_addr, phys_addr_t *result)
{
unsigned long virt_addr = (unsigned long)__virt_addr;
phys_addr_t phys_addr;
@@ -385,12 +374,35 @@ phys_addr_t slow_virt_to_phys(void *__vi
pte_t *pte;

pte = lookup_address(virt_addr, &level);
- BUG_ON(!pte);
+ if (!pte)
+ return -EFAULT;
psize = page_level_size(level);
pmask = page_level_mask(level);
offset = virt_addr & ~pmask;
phys_addr = pte_pfn(*pte) << PAGE_SHIFT;
- return (phys_addr | offset);
+ *result = (phys_addr | offset);
+ return 0;
+}
+
+/*
+ * This is necessary because __pa() does not work on some
+ * kinds of memory, like vmalloc() or the alloc_remap()
+ * areas on 32-bit NUMA systems. The percpu areas can
+ * end up in this kind of memory, for instance.
+ *
+ * This could be optimized, but it is only intended to be
+ * used at inititalization time, and keeping it
+ * unoptimized should increase the testing coverage for
+ * the more obscure platforms.
+ */
+phys_addr_t slow_virt_to_phys(void *virt_addr)
+{
+ phys_addr_t result;
+ int ret;
+
+ ret = kernel_lookup_vaddr(virt_addr, &result);
+ BUG_ON(ret);
+ return result;
}
EXPORT_SYMBOL_GPL(slow_virt_to_phys);

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