From: Arnd Bergmann <arnd@arndb.de>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: linux-kernel@vger.kernel.org, stable@kernel.org,
Andi Kleen <andi@firstfloor.org>, Ken Werner <ken.werner@web.de>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Subject: Re: cpumask: fix compat getaffinity
Date: Tue, 11 May 2010 11:05:03 +0200 [thread overview]
Message-ID: <201005111105.03475.arnd@arndb.de> (raw)
In-Reply-To: <201005110913.49162.rusty@rustcorp.com.au>
On Tuesday 11 May 2010, Rusty Russell wrote:
> cpumask: use nr_cpu_ids for printing and parsing cpumasks
>
> Commit a45185d2d "cpumask: convert kernel/compat.c" broke
> libnuma, which abuses sched_getaffinity to find out NR_CPUS
> in order to parse /sys/devices/system/node/node*/cpumap.
>
> However, the result now returned reflects nr_cpu_ids, and
> cpumask_scnprintf et al. use nr_cpumask_bits which is NR_CPUS (for
> CONFIG_CPUMASK_OFFSTACK=n) or nr_cpu_ids (for
> CONFIG_CPUMASK_OFFSTACK=y).
>
> We should use nr_cpu_ids consistently.
>
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> Cc: stable@kernel.org
It looks like this changes fixes the compat case, but now
the native system call would be inconsistent with the
sysfs output.
Wouldn't you also need something like the change below
to make the return value of sched_getaffinity() independent
of NR_CPUS?
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -495,12 +495,9 @@ asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid, unsigned int len,
int ret;
cpumask_var_t mask;
unsigned long *k;
- unsigned int min_length = cpumask_size();
+ size_t size = BITS_TO_COMPAT_LONGS(nr_cpu_ids) * sizeof(compat_ulong_t);
- if (nr_cpu_ids <= BITS_PER_COMPAT_LONG)
- min_length = sizeof(compat_ulong_t);
-
- if (len < min_length)
+ if (len < size)
return -EINVAL;
if (!alloc_cpumask_var(&mask, GFP_KERNEL))
@@ -511,9 +508,9 @@ asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid, unsigned int len,
goto out;
k = cpumask_bits(mask);
- ret = compat_put_bitmap(user_mask_ptr, k, min_length * 8);
+ ret = compat_put_bitmap(user_mask_ptr, k, size * 8);
if (ret == 0)
- ret = min_length;
+ ret = size;
out:
free_cpumask_var(mask);
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -6693,8 +6693,9 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
{
int ret;
cpumask_var_t mask;
+ size_t size = BITS_TO_LONGS(nr_cpu_ids) * sizeof(long);
- if (len < cpumask_size())
+ if (len < size)
return -EINVAL;
if (!alloc_cpumask_var(&mask, GFP_KERNEL))
@@ -6702,10 +6703,10 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
ret = sched_getaffinity(pid, mask);
if (ret == 0) {
- if (copy_to_user(user_mask_ptr, mask, cpumask_size()))
+ if (copy_to_user(user_mask_ptr, mask, size))
ret = -EFAULT;
else
- ret = cpumask_size();
+ ret = size;
}
free_cpumask_var(mask);
next prev parent reply other threads:[~2010-05-11 9:05 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-07 12:45 cpumask: fix compat getaffinity Arnd Bergmann
2010-05-08 8:30 ` Rusty Russell
2010-05-08 9:11 ` Arnd Bergmann
2010-05-10 23:43 ` Rusty Russell
2010-05-11 1:47 ` KOSAKI Motohiro
2010-05-11 3:13 ` [stable] " Greg KH
2010-05-11 5:51 ` Rusty Russell
2010-05-11 6:25 ` KOSAKI Motohiro
2010-05-11 6:20 ` KOSAKI Motohiro
2010-05-11 15:20 ` Greg KH
2010-05-11 18:13 ` Arnd Bergmann
2010-05-11 21:36 ` Greg KH
2010-05-12 8:30 ` Milton Miller
2010-05-14 12:39 ` Rusty Russell
2010-05-17 6:04 ` KOSAKI Motohiro
2010-05-17 18:58 ` Arnd Bergmann
2010-05-18 0:57 ` Rusty Russell
2010-12-14 16:59 ` Josh Hunt
2010-12-15 14:40 ` Arnd Bergmann
2010-06-22 23:30 ` Rusty Russell
2010-05-11 9:05 ` Arnd Bergmann [this message]
2010-05-12 0:52 ` KOSAKI Motohiro
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=201005111105.03475.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=andi@firstfloor.org \
--cc=ken.werner@web.de \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=stable@kernel.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).