From: Roland McGrath <roland@redhat.com>
To: Andrew Morton <akpm@digeo.com>
Cc: torvalds@transmeta.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] i386 uaccess to fixmap pages
Date: Fri, 9 May 2003 03:43:07 -0700 [thread overview]
Message-ID: <200305091043.h49Ah7Z24822@magilla.sf.frob.com> (raw)
In-Reply-To: Andrew Morton's message of Friday, 9 May 2003 02:19:21 -0700 <20030509021921.166f82fc.akpm@digeo.com>
Here's an updated version of the patch. Since the support for 386s without
WP support seems to be gone, I shaved an instruction here and there by not
passing the read/write flag to the helper function.
Btw, in my build (gcc 3.2-rh, -O2, a $100 processor from last year so the
kernel build is plenty fast) the text size overhead is less than 0.5%,
which is to say 11kb (but my configuration is somewhat minimal so you may
be compiling in many more access_ok calls).
Thanks,
Roland
--- linux-2.5.69-1.1083/include/asm-i386/uaccess.h.orig Fri May 9 03:07:15 2003
+++ linux-2.5.69-1.1083/include/asm-i386/uaccess.h Fri May 9 03:25:16 2003
@@ -43,6 +43,7 @@ extern struct movsl_mask {
#endif
int __verify_write(const void *, unsigned long);
+int FASTCALL(__fixmap_range_ok(unsigned long, unsigned long));
#define __addr_ok(addr) ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg))
@@ -81,7 +82,9 @@ int __verify_write(const void *, unsigne
* checks that the pointer is in the user space range - after calling
* this function, memory access functions may still return -EFAULT.
*/
-#define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
+#define access_ok(type,addr,size) (__range_ok(addr,size) == 0 || \
+ __fixmap_range_ok((unsigned long)(addr), \
+ (size)))
/**
* verify_area: - Obsolete, use access_ok()
--- linux-2.5.69/arch/i386/lib/getuser.S.~1~ Sun May 4 16:52:49 2003
+++ linux-2.5.69-1.1083/arch/i386/lib/getuser.S Fri May 9 03:24:30 2003
@@ -29,10 +29,13 @@
__get_user_1:
GET_THREAD_INFO(%edx)
cmpl TI_ADDR_LIMIT(%edx),%eax
- jae bad_get_user
+ jae 0f
1: movzbl (%eax),%edx
xorl %eax,%eax
ret
+0: pushl $1b
+ xorl %edx,%edx
+ jmp get_user_check_fixmap
.align 4
.globl __get_user_2
@@ -41,10 +44,13 @@ __get_user_2:
jc bad_get_user
GET_THREAD_INFO(%edx)
cmpl TI_ADDR_LIMIT(%edx),%eax
- jae bad_get_user
+ jae 0f
2: movzwl -1(%eax),%edx
xorl %eax,%eax
ret
+0: pushl $2b
+ movl $1,%edx
+ jmp get_user_check_fixmap
.align 4
.globl __get_user_4
@@ -53,10 +59,26 @@ __get_user_4:
jc bad_get_user
GET_THREAD_INFO(%edx)
cmpl TI_ADDR_LIMIT(%edx),%eax
- jae bad_get_user
+ jae 0f
3: movl -3(%eax),%edx
xorl %eax,%eax
ret
+0: pushl $3b
+ movl $3,%edx
+/* jmp get_user_check_fixmap */
+
+get_user_check_fixmap:
+ pushl %eax
+ pushl %ecx
+ subl %edx,%eax /* undo address bias, %eax = addr */
+ incl %edx /* bump bias to size, %edx = size */
+ call __fixmap_range_ok
+ testl %eax,%eax
+ popl %ecx
+ popl %eax
+ jz 0f
+ ret
+0: popl %eax /* eat return address pushed by __get_user_N */
bad_get_user:
xorl %edx,%edx
--- linux-2.5.69/mm/memory.c.~1~ Sun May 4 16:53:14 2003
+++ linux-2.5.69-1.1083/mm/memory.c Fri May 9 03:23:33 2003
@@ -45,6 +45,7 @@
#include <linux/pagemap.h>
#include <linux/vcache.h>
#include <linux/rmap-locking.h>
+#include <linux/module.h>
#include <asm/pgalloc.h>
#include <asm/rmap.h>
@@ -669,6 +670,50 @@ static inline struct page *get_page_map(
}
+#ifdef FIXADDR_START
+static int fixmap_page_ok(unsigned long addr, int write, struct page **pagep)
+{
+ unsigned long pg = addr & PAGE_MASK;
+ pgd_t *pgd;
+ pmd_t *pmd;
+ pte_t *pte;
+ pgd = pgd_offset_k(pg);
+ if (!pgd)
+ return 0;
+ pmd = pmd_offset(pgd, pg);
+ if (!pmd)
+ return 0;
+ pte = pte_offset_kernel(pmd, pg);
+ if (!pte || !pte_present(*pte) || !pte_user(*pte) ||
+ !(write ? pte_write(*pte) : pte_read(*pte)))
+ return 0;
+
+ if (pagep) {
+ *pagep = pte_page(*pte);
+ get_page(*pagep);
+ }
+ return 1;
+}
+
+int __fixmap_range_ok(unsigned long addr, unsigned long size)
+{
+ unsigned long limit = addr + size;
+ if (limit < addr)
+ return 0;
+ if (addr < FIXADDR_START || limit > FIXADDR_TOP)
+ return 0;
+ do {
+ if (!fixmap_page_ok(addr, 0, NULL))
+ return 0;
+ addr += PAGE_SIZE;
+ } while (addr < limit);
+ return 1;
+}
+
+EXPORT_SYMBOL(__fixmap_range_ok);
+#endif
+
+
int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
unsigned long start, int len, int write, int force,
struct page **pages, struct vm_area_struct **vmas)
@@ -701,24 +746,9 @@ int get_user_pages(struct task_struct *t
.vm_page_prot = PAGE_READONLY,
.vm_flags = VM_READ | VM_EXEC,
};
- unsigned long pg = start & PAGE_MASK;
- pgd_t *pgd;
- pmd_t *pmd;
- pte_t *pte;
- pgd = pgd_offset_k(pg);
- if (!pgd)
- return i ? : -EFAULT;
- pmd = pmd_offset(pgd, pg);
- if (!pmd)
- return i ? : -EFAULT;
- pte = pte_offset_kernel(pmd, pg);
- if (!pte || !pte_present(*pte) || !pte_user(*pte) ||
- !(write ? pte_write(*pte) : pte_read(*pte)))
+ if (!fixmap_page_ok(start, write,
+ pages ? &pages[i] : NULL))
return i ? : -EFAULT;
- if (pages) {
- pages[i] = pte_page(*pte);
- get_page(pages[i]);
- }
if (vmas)
vmas[i] = &fixmap_vma;
i++;
next prev parent reply other threads:[~2003-05-09 10:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-09 2:03 Roland McGrath
2003-05-09 4:31 ` Andrew Morton
2003-05-09 8:55 ` Roland McGrath
2003-05-09 9:19 ` Andrew Morton
2003-05-09 9:40 ` Roland McGrath
2003-05-09 10:43 ` Roland McGrath [this message]
2003-05-09 11:42 ` Dave Jones
2003-05-09 11:55 ` Alan Cox
2003-05-09 12:40 ` Jamie Lokier
2003-05-09 16:06 ` Linus Torvalds
2003-05-09 16:38 ` Dave Hansen
2003-05-09 15:55 ` Martin J. Bligh
2003-05-09 18:20 ` William Lee Irwin III
2003-05-09 16:48 ` Linus Torvalds
2003-05-09 17:16 ` Dave Hansen
2003-05-10 3:26 ` H. Peter Anvin
2003-05-10 15:31 ` Jamie Lokier
2003-05-10 17:23 ` Ulrich Drepper
2003-05-10 19:23 ` H. Peter Anvin
2003-05-10 20:52 ` Jamie Lokier
2003-05-09 17:28 Chuck Ebbert
2003-05-09 17:49 ` Linus Torvalds
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=200305091043.h49Ah7Z24822@magilla.sf.frob.com \
--to=roland@redhat.com \
--cc=akpm@digeo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/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®