From: Dave Hansen <dave@sr71.net>
To: bp@alien8.de
Cc: hpa@linux.intel.com, linux-kernel@vger.kernel.org,
x86@kernel.org, Dave Hansen <dave@sr71.net>
Subject: [PATCH 4/5] break up slow_virt_to_phys()
Date: Wed, 10 Apr 2013 16:32:54 -0700 [thread overview]
Message-ID: <20130410233254.EF273179@viggo.jf.intel.com> (raw)
In-Reply-To: <20130410233249.7FFCB63B@viggo.jf.intel.com>
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@linux.vnet.ibm.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---
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);
_
next prev parent reply other threads:[~2013-04-10 23:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-10 23:32 [PATCH 0/5] [RFC] rework /dev/mem code vs. highmem and DEBUG_VIRTUAL Dave Hansen
2013-04-10 23:32 ` [PATCH 1/5] clean up checks against "high_memory" variable Dave Hansen
2013-04-11 0:44 ` Borislav Petkov
2013-04-10 23:32 ` [PATCH 2/5] make /dev/kmem return error for highmem Dave Hansen
2013-04-11 9:58 ` Borislav Petkov
2013-04-10 23:32 ` [PATCH 3/5] avoid /dev/kmem oopses with DEBUG_VIRTUAL Dave Hansen
2013-04-10 23:32 ` Dave Hansen [this message]
2013-04-11 12:29 ` [PATCH 4/5] break up slow_virt_to_phys() Borislav Petkov
2013-04-11 16:28 ` Dave Hansen
2013-04-11 17:12 ` Borislav Petkov
2013-04-10 23:32 ` [PATCH 5/5] keep /dev/kmem from triggering BUG_ON() with DEBUG_VIRTUAL Dave Hansen
2013-04-11 12:37 ` Borislav Petkov
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=20130410233254.EF273179@viggo.jf.intel.com \
--to=dave@sr71.net \
--cc=bp@alien8.de \
--cc=hpa@linux.intel.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
Powered by JetHome