From: Rusty Russell <rusty@rustcorp.com.au>
To: Andrew Morton <akpm@osdl.org>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>,
Pavel Machek <pavel@ucw.cz>,
virtualization <virtualization@lists.osdl.org>,
lkml - Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/4] Prep for paravirt: Be careful about touching BIOS address space
Date: Mon, 30 Oct 2006 13:35:01 +1100 [thread overview]
Message-ID: <1162175701.9802.24.camel@localhost.localdomain> (raw)
In-Reply-To: <20061027215037.cd69b2a3.akpm@osdl.org>
On Fri, 2006-10-27 at 21:50 -0700, Andrew Morton wrote:
> On Fri, 27 Oct 2006 21:33:08 -0700
> Jeremy Fitzhardinge <jeremy@goop.org> wrote:
>
> > Andrew Morton wrote:
> > > It'd be better to use include/linux/uaccess.h:probe_kernel_address() for
> > > this operation.
> > >
> > Ah, yes, that was the precedent I was thinking of,
>
> We've done open-coded __get_user() in various places in the past. The difference with
> probe_kernel_address() is that it doesn't get deadlocked on mmap_sem().
>
> > but I guess it would
> > be better to just use it directly. It's a relatively new interface,
> > isn't it?
>
> Yeah. New enough that nobody's tried using it on non-x86 ;) It needs
> to do set_fs(KERNEL_DS).
And the function name is misleading: it really does get a value, not
merely probe an address. And the arguments are reversed from
__get_user, just to add fun.
Andrew, please replace
prep-for-paravirt-be-careful-about-touching-bios-warning-fix.patch
Subject: Be careful about touching BIOS address space
BIOS ROM areas may not be mapped into the guest address space, so be careful
when touching those addresses to make sure they appear to be mapped.
At Andrew's request, fix probe_kernel_address for non-x86.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (modified)
diff -r 9a6c8ceba677 arch/i386/kernel/setup.c
--- a/arch/i386/kernel/setup.c Mon Oct 30 11:34:30 2006 +1100
+++ b/arch/i386/kernel/setup.c Mon Oct 30 13:15:33 2006 +1100
@@ -47,6 +47,7 @@
#include <linux/crash_dump.h>
#include <linux/dmi.h>
#include <linux/pfn.h>
+#include <linux/uaccess.h>
#include <video/edid.h>
@@ -270,7 +271,14 @@ static struct resource standard_io_resou
.flags = IORESOURCE_BUSY | IORESOURCE_IO
} };
-#define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
+static inline int romsignature(const unsigned char *x)
+{
+ unsigned short sig;
+ int ret = 0;
+ if (probe_kernel_address((const unsigned short *)x, sig) == 0)
+ ret = (sig == 0xaa55);
+ return ret;
+}
static int __init romchecksum(unsigned char *rom, unsigned long length)
{
diff -r 9a6c8ceba677 arch/i386/pci/pcbios.c
--- a/arch/i386/pci/pcbios.c Mon Oct 30 11:34:30 2006 +1100
+++ b/arch/i386/pci/pcbios.c Mon Oct 30 13:15:02 2006 +1100
@@ -5,6 +5,7 @@
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/module.h>
+#include <linux/uaccess.h>
#include "pci.h"
#include "pci-functions.h"
@@ -314,6 +315,10 @@ static struct pci_raw_ops * __devinit pc
for (check = (union bios32 *) __va(0xe0000);
check <= (union bios32 *) __va(0xffff0);
++check) {
+ long sig;
+ if (probe_kernel_address(&check->fields.signature, sig))
+ continue;
+
if (check->fields.signature != BIOS32_SIGNATURE)
continue;
length = check->fields.length * 16;
diff -r 9a6c8ceba677 include/linux/uaccess.h
--- a/include/linux/uaccess.h Mon Oct 30 11:34:30 2006 +1100
+++ b/include/linux/uaccess.h Mon Oct 30 13:10:39 2006 +1100
@@ -34,10 +34,13 @@ static inline unsigned long __copy_from_
#define probe_kernel_address(addr, retval) \
({ \
long ret; \
+ mm_segment_t old_fs = get_fs(); \
\
+ set_fs(KERNEL_DS); \
inc_preempt_count(); \
ret = __get_user(retval, addr); \
dec_preempt_count(); \
+ set_fs(old_fs); \
ret; \
})
next prev parent reply other threads:[~2006-10-30 2:35 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-27 3:38 [PATCH 1/4] Prep for paravirt: move pagetable includes Rusty Russell
2006-10-27 3:42 ` [PATCH 1/4] Prep for paravirt: Be careful about touching BIOS address space Rusty Russell
2006-10-27 3:43 ` [PATCH 2/4] Prep for paravirt: cpu_detect extraction Rusty Russell
2006-10-27 3:45 ` [PATCH 3/4] Prep for paravirt: desc.h clearer parameter names, some code motion Rusty Russell
2006-10-27 3:46 ` [PATCH 4/4] Prep for paravirt: rearrange processor.h Rusty Russell
2006-10-29 20:01 ` [PATCH] Re: [PATCH 3/4] Prep for paravirt: desc.h clearer parameter names, some code motion Don Mullis
2006-10-29 21:06 ` Andi Kleen
2006-10-29 21:44 ` Don Mullis
2006-10-30 0:05 ` Rusty Russell
2006-10-27 11:30 ` [PATCH 1/4] Prep for paravirt: Be careful about touching BIOS address space Pavel Machek
2006-10-27 21:31 ` Jeremy Fitzhardinge
2006-10-27 21:41 ` Andrew Morton
2006-10-28 4:33 ` Jeremy Fitzhardinge
2006-10-28 4:50 ` Andrew Morton
2006-10-30 2:35 ` Rusty Russell [this message]
2006-10-29 20:01 ` Don Mullis
2006-10-27 10:30 ` [PATCH 1/4] Prep for paravirt: move pagetable includes Zachary Amsden
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=1162175701.9802.24.camel@localhost.localdomain \
--to=rusty@rustcorp.com.au \
--cc=akpm@osdl.org \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=virtualization@lists.osdl.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;
as well as URLs for NNTP newsgroup(s).