public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Anton Blanchard <anton@samba.org>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Paul Jackson <pj@sgi.com>,
	ak@muc.de, Andrew Morton <akpm@osdl.org>,
	Linux Arch list <linux-arch@vger.kernel.org>
Subject: [PATCH] [ppc64] Fix compat NUMA API on big endian 64bit
Date: Wed, 8 Sep 2004 10:43:44 +1000	[thread overview]
Message-ID: <20040908004344.GE25278@krispykreme> (raw)
In-Reply-To: <20040908004040.GD25278@krispykreme>


Switch the NUMA API to use compat_get_bitmap/compat_put_bitmap. In order
to use compat_alloc_userspace instead of set_fs tricks, we have to do a
few copies.

This is what we are currently using on ppc64 but are willing to
entertain the idea of going to a 32bit bitmap, especially considering
how much hoops we have to go through to get it right in this patch.

Signed-off-by: Anton Blanchard <anton@samba.org>

diff -puN mm/mempolicy.c~numa_api mm/mempolicy.c
--- gr_work/mm/mempolicy.c~numa_api	2004-09-04 21:14:44.595414365 -0500
+++ gr_work-anton/mm/mempolicy.c	2004-09-05 09:19:10.475691107 -0500
@@ -525,20 +525,82 @@ asmlinkage long sys_get_mempolicy(int __
 }
 
 #ifdef CONFIG_COMPAT
-/* The other functions are compatible */
+
 asmlinkage long compat_get_mempolicy(int __user *policy,
-				  unsigned __user *nmask, unsigned  maxnode,
-				  unsigned addr, unsigned  flags)
+				     compat_ulong_t __user *nmask,
+				     compat_ulong_t maxnode,
+				     compat_ulong_t addr, compat_ulong_t flags)
 {
 	long err;
 	unsigned long __user *nm = NULL;
+	unsigned long nr_bits, alloc_size;
+	DECLARE_BITMAP(bm, MAX_NUMNODES);
+
+	nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES);
+	alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
+
 	if (nmask)
-		nm = compat_alloc_user_space(ALIGN(maxnode-1, 64) / 8);
-	err = sys_get_mempolicy(policy, nm, maxnode, addr, flags);
-	if (!err && copy_in_user(nmask, nm, ALIGN(maxnode-1, 32)/8))
-		err = -EFAULT;
+		nm = compat_alloc_user_space(alloc_size);
+
+	err = sys_get_mempolicy(policy, nm, nr_bits+1, addr, flags);
+
+	if (!err && nmask) {
+		err = copy_from_user(bm, nm, alloc_size);
+		/* ensure entire bitmap is zeroed */
+		err |= clear_user(nmask, ALIGN(maxnode-1, 8) / 8);
+		err |= compat_put_bitmap(nmask, bm, nr_bits);
+	}
+
 	return err;
 }
+
+asmlinkage long compat_set_mempolicy(int mode, compat_ulong_t __user *nmask,
+				     compat_ulong_t maxnode)
+{
+	long err;
+	unsigned long __user *nm = NULL;
+	unsigned long nr_bits, alloc_size;
+	DECLARE_BITMAP(bm, MAX_NUMNODES);
+
+	nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES);
+	alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
+
+	if (nmask) {
+		err = compat_get_bitmap(bm, nmask, nr_bits);
+		nm = compat_alloc_user_space(alloc_size);
+		err |= copy_to_user(nm, bm, alloc_size);
+	}
+
+	if (err)
+		return -EFAULT;
+
+	return sys_set_mempolicy(mode, nm, nr_bits+1);
+}
+
+asmlinkage long compat_mbind(compat_ulong_t start, compat_ulong_t len,
+			     compat_ulong_t mode, compat_ulong_t __user *nmask,
+			     compat_ulong_t maxnode, compat_ulong_t flags)
+{
+	long err;
+	unsigned long __user *nm = NULL;
+	unsigned long nr_bits, alloc_size;
+	DECLARE_BITMAP(bm, MAX_NUMNODES);
+
+	nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES);
+	alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
+
+	if (nmask) {
+		err = compat_get_bitmap(bm, nmask, nr_bits);
+		nm = compat_alloc_user_space(alloc_size);
+		err |= copy_to_user(nm, bm, alloc_size);
+	}
+
+	if (err)
+		return -EFAULT;
+
+	return sys_mbind(start, len, mode, nm, nr_bits+1, flags);
+}
+
 #endif
 
 /* Return effective policy for a VMA */

  reply	other threads:[~2004-09-08  0:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040831183655.58d784a3.pj@sgi.com>
     [not found] ` <20040904133701.GE33964@muc.de>
     [not found]   ` <20040904171417.67649169.pj@sgi.com>
     [not found]     ` <Pine.LNX.4.58.0409041717230.4735@ppc970.osdl.org>
     [not found]       ` <20040904180548.2dcdd488.pj@sgi.com>
     [not found]         ` <Pine.LNX.4.58.0409041827280.2331@ppc970.osdl.org>
     [not found]           ` <20040904204850.48b7cfbd.pj@sgi.com>
     [not found]             ` <Pine.LNX.4.58.0409042055460.2331@ppc970.osdl.org>
     [not found]               ` <20040904211749.3f713a8a.pj@sgi.com>
     [not found]                 ` <20040904215205.0a067ab8.pj@sgi.com>
     [not found]                   ` <20040906182330.GA79122@muc.de>
     [not found]                     ` <Pine.LNX.4.58.0409061147220.28608@ppc970.osdl.org>
     [not found]                       ` <20040906141142.663941fb.pj@sgi.com>
2004-09-07 14:40                         ` [PATCH] Fix argument checking in sched_setaffinity Linus Torvalds
2004-09-07 14:48                           ` Geert Uytterhoeven
2004-09-07 14:49                           ` Andi Kleen
2004-09-07 21:44                             ` Ralf Baechle
2004-09-07 22:55                               ` Paul Jackson
2004-09-08  6:58                                 ` Andi Kleen
2004-09-08  7:26                                   ` Paul Jackson
2004-09-08  0:26                             ` Anton Blanchard
2004-09-07 14:50                           ` Matthew Wilcox
2004-09-08  0:24                           ` Anton Blanchard
2004-09-08  0:33                             ` [PATCH] [ppc64] compat_get_bitmap/compat_put_bitmap Anton Blanchard
2004-09-08  0:40                               ` [PATCH] [ppc64] Fix compat cpu affinity on big endian 64bit Anton Blanchard
2004-09-08  0:43                                 ` Anton Blanchard [this message]
2004-09-08  5:22                                 ` Andrew Morton
2004-09-08  5:34                                   ` Anton Blanchard
2004-09-08  5:43                                     ` Andrew Morton

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=20040908004344.GE25278@krispykreme \
    --to=anton@samba.org \
    --cc=ak@muc.de \
    --cc=akpm@osdl.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=pj@sgi.com \
    --cc=torvalds@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