PATCH: sched_{s,g}etaffinity compat
Olaf Hering
olh at suse.de
Mon Aug 16 04:40:24 EST 2004
On Mon, May 10, Anton Blanchard wrote:
>
> Hi,
>
> > On "real" hardware with NR_CPUS > sizeof(long)*8, the
> > sys_sched_setaffinity and getaffinity compatibility functions break,
> > because they just convert long masks instead of the full CPU masks.
> >
> > This patches fixes this problem.
> >
> > Spotted by a ppc32 glibc make check, on a ppc64 Kernel.
>
> Unfortunately thats not enough :) We need to change between 32bit and
> 64bit bitfields (just like we do on the 32bit compat select call). Here
> is a patch from Milton from a while ago that should do it.
Probably not correct, bot -EWORKSFORME.
diff -purNX /suse/olh/kernel/kernel_exclude.txt linux-2.6.8.1.orig/kernel/compat.c linux-2.6.8.1-olh/kernel/compat.c
--- linux-2.6.8.1.orig/kernel/compat.c 2004-08-14 12:55:32.000000000 +0200
+++ linux-2.6.8.1-olh/kernel/compat.c 2004-08-15 20:23:05.000000000 +0200
@@ -383,16 +383,56 @@ 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 <= 8*sizeof(compat_ulong_t))
+
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;
+
+ kern_mask.bits[0] = user_mask;
+ } else {
+ if (len < sizeof(kern_mask))
+ return -EINVAL;
+
+ if (!access_ok(VERIFY_READ, user_mask_ptr, sizeof(kern_mask)))
+ return -EFAULT;
+ else {
+ int i, j;
+ unsigned long *k, m;
+ compat_ulong_t um;
+
+ k = &kern_mask.bits[0];
+
+ for (i=0; i < sizeof(kern_mask)/sizeof(m); i++) {
+ m = 0;
+
+ for (j = 0; j < sizeof(m)/sizeof(um); j++ ) {
+ if (__get_user(um, user_mask_ptr))
+ return -EFAULT;
+ user_mask_ptr++;
+ m |= (unsigned long)um << (8*sizeof(um)*j);
+ }
+ *k++ = m;
+ }
+ }
+ }
old_fs = get_fs();
set_fs(KERNEL_DS);
@@ -407,10 +447,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,
@@ -419,9 +463,33 @@ asmlinkage long compat_sys_sched_getaffi
set_fs(old_fs);
if (ret > 0) {
- ret = sizeof(compat_ulong_t);
- if (put_user(kern_mask, user_mask_ptr))
- return -EFAULT;
+ if (USE_COMPAT_ULONG_CPUMASK) {
+ ret = sizeof(compat_ulong_t);
+ if (put_user(kern_mask.bits[0], user_mask_ptr))
+ return -EFAULT;
+ } else {
+ int i, j, err;
+ unsigned long *k, m;
+ compat_ulong_t um;
+
+ err = ! access_ok(VERIFY_WRITE, user_mask_ptr, ret);
+
+ k = &kern_mask.bits[0];
+
+ for (i=0; i < sizeof(kern_mask)/sizeof(m) && !err; i++) {
+ m = *k++;
+
+ for (j = 0; j < sizeof(m)/sizeof(compat_ulong_t) && !err; j++ ) {
+ um = m;
+ err |= __put_user(um, user_mask_ptr);
+ user_mask_ptr++;
+ m >>= 4*sizeof(compat_ulong_t);
+ m >>= 4*sizeof(compat_ulong_t);
+ }
+ }
+ if (err)
+ ret = -EFAULT;
+ }
}
return ret;
--
USB is for mice, FireWire is for men!
sUse lINUX ag, nÜRNBERG
** Sent via the linuxppc64-dev mail list. See http://lists.linuxppc.org/
More information about the Linuxppc64-dev
mailing list