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 3/5] avoid /dev/kmem oopses with DEBUG_VIRTUAL
Date: Wed, 10 Apr 2013 16:32:53 -0700 [thread overview]
Message-ID: <20130410233253.250AD1EA@viggo.jf.intel.com> (raw)
In-Reply-To: <20130410233249.7FFCB63B@viggo.jf.intel.com>
DEBUG_VIRTUAL, ensures that when __pa() is only called on
addresses for which its results are correct. For everything
else, we BUG_ON().
This changes the /dev/kmem ordering so that we check pfn_valid()
_before_ we call __pa(). This ensures we're not calling __pa()
with gibberish and avoids the BUG_ON() in those cases, instead
returning the error to userspace _before_ the __pa() call.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---
linux.git-davehans/drivers/char/mem.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff -puN drivers/char/mem.c~make-devmem-work-on-highmem3a drivers/char/mem.c
--- linux.git/drivers/char/mem.c~make-devmem-work-on-highmem3a 2013-04-10 16:23:45.361087291 -0700
+++ linux.git-davehans/drivers/char/mem.c 2013-04-10 16:23:45.365087295 -0700
@@ -347,9 +347,6 @@ static int mmap_kmem(struct file *file,
*/
if (kernel_vaddr >= high_memory)
return -EIO;
- /* Turn a kernel-virtual address into a physical page frame */
- pfn = __pa(kernel_vaddr) >> PAGE_SHIFT;
-
/*
* RED-PEN: on some architectures there is more mapped memory than
* available in mem_map which pfn_valid checks for. Perhaps should add a
@@ -360,6 +357,9 @@ static int mmap_kmem(struct file *file,
if (!pfn_valid(pfn))
return -EIO;
+ /* Turn a kernel-virtual address into a physical page frame */
+ pfn = __pa(kernel_vaddr) >> PAGE_SHIFT;
+
vma->vm_pgoff = pfn;
return mmap_mem(file, vma);
}
_
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 ` Dave Hansen [this message]
2013-04-10 23:32 ` [PATCH 4/5] break up slow_virt_to_phys() Dave Hansen
2013-04-11 12:29 ` 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=20130410233253.250AD1EA@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