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 cpu affinity on big endian 64bit
Date: Wed, 8 Sep 2004 10:40:40 +1000 [thread overview]
Message-ID: <20040908004040.GD25278@krispykreme> (raw)
In-Reply-To: <20040908003359.GC25278@krispykreme>
Add compat sched affinity code. We can argue about how
USE_COMPAT_ULONG_CPUMASK works now that the non compat interface has changed.
The old non compat behaviour was to require a bitmap long enough in both
setaffinity and getaffinity, now its only required in getaffinity. I
could do the same for the 32bit interfaces.
Signed-off-by: Anton Blanchard <anton@samba.org>
diff -puN kernel/compat.c~compat_sys_sched_affinity kernel/compat.c
--- gr_work/kernel/compat.c~compat_sys_sched_affinity 2004-09-06 04:19:06.327399153 -0500
+++ gr_work-anton/kernel/compat.c 2004-09-07 19:36:09.127584076 -0500
@@ -412,16 +412,43 @@ compat_sys_wait4(compat_pid_t pid, compa
}
}
+/*
+ * for maximum compatability, we allow programs to use a single (compat)
+ * unsigned long bitmask if all cpus will fit. If not, you have to have
+ * at least the kernel size available.
+ */
+#define USE_COMPAT_ULONG_CPUMASK (NR_CPUS <= BITS_PER_COMPAT_LONG)
+
asmlinkage long compat_sys_sched_setaffinity(compat_pid_t pid,
unsigned int len,
compat_ulong_t __user *user_mask_ptr)
{
- unsigned long kern_mask;
+ cpumask_t kern_mask;
mm_segment_t old_fs;
int ret;
- if (get_user(kern_mask, user_mask_ptr))
- return -EFAULT;
+ if (USE_COMPAT_ULONG_CPUMASK) {
+ compat_ulong_t user_mask;
+
+ if (len < sizeof(user_mask))
+ return -EINVAL;
+
+ if (get_user(user_mask, user_mask_ptr))
+ return -EFAULT;
+
+ cpus_addr(kern_mask)[0] = user_mask;
+ } else {
+ unsigned long *k;
+
+ if (len < sizeof(kern_mask))
+ return -EINVAL;
+
+ k = cpus_addr(kern_mask);
+ ret = compat_get_bitmap(k, user_mask_ptr,
+ sizeof(kern_mask) * BITS_PER_LONG);
+ if (ret)
+ return ret;
+ }
old_fs = get_fs();
set_fs(KERNEL_DS);
@@ -436,10 +463,14 @@ asmlinkage long compat_sys_sched_setaffi
asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid, unsigned int len,
compat_ulong_t __user *user_mask_ptr)
{
- unsigned long kern_mask;
+ cpumask_t kern_mask;
mm_segment_t old_fs;
int ret;
+ if (len < (USE_COMPAT_ULONG_CPUMASK ? sizeof(compat_ulong_t)
+ : sizeof(kern_mask)))
+ return -EINVAL;
+
old_fs = get_fs();
set_fs(KERNEL_DS);
ret = sys_sched_getaffinity(pid,
@@ -447,10 +478,23 @@ asmlinkage long compat_sys_sched_getaffi
(unsigned long __user *) &kern_mask);
set_fs(old_fs);
- if (ret > 0) {
- ret = sizeof(compat_ulong_t);
- if (put_user(kern_mask, user_mask_ptr))
+ if (ret < 0)
+ return ret;
+
+ if (USE_COMPAT_ULONG_CPUMASK) {
+ if (put_user(&cpus_addr(kern_mask)[0], user_mask_ptr))
return -EFAULT;
+ ret = sizeof(compat_ulong_t);
+ } else {
+ unsigned long *k;
+
+ k = cpus_addr(kern_mask);
+ ret = compat_put_bitmap(user_mask_ptr, k,
+ sizeof(kern_mask) * BITS_PER_LONG);
+ if (ret)
+ return ret;
+
+ ret = sizeof(kern_mask);
}
return ret;
_
next prev parent 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 ` Anton Blanchard [this message]
2004-09-08 0:43 ` [PATCH] [ppc64] Fix compat NUMA API on big endian 64bit Anton Blanchard
2004-09-08 5:22 ` [PATCH] [ppc64] Fix compat cpu affinity " 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=20040908004040.GD25278@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