Skip to content

Commit 3734074

Browse files
Lai Jiangshantorvalds
authored andcommitted
cpusets: fix bug when adding nonexistent cpu or mem
Adding a nonexistent cpu to a cpuset will be omitted quietly. It should return -EINVAL. Example: (real_nr_cpus <= 4 < NR_CPUS or cpu#4 was just offline) # cat cpus 0-1 # /bin/echo 4 > cpus # /bin/echo $? 0 # cat cpus # The same occurs when add a nonexistent mem. This patch will fix this bug. And when *buf == "", the check is unneeded. Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Acked-by: Paul Jackson <pj@sgi.com> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent aae8679 commit 3734074

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎kernel/cpuset.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,10 @@ static int update_cpumask(struct cpuset *cs, char *buf)
797797
retval = cpulist_parse(buf, trialcs.cpus_allowed);
798798
if (retval < 0)
799799
return retval;
800+
801+
if (!cpus_subset(trialcs.cpus_allowed, cpu_online_map))
802+
return -EINVAL;
800803
}
801-
cpus_and(trialcs.cpus_allowed, trialcs.cpus_allowed, cpu_online_map);
802804
retval = validate_change(cs, &trialcs);
803805
if (retval < 0)
804806
return retval;
@@ -932,9 +934,11 @@ static int update_nodemask(struct cpuset *cs, char *buf)
932934
retval = nodelist_parse(buf, trialcs.mems_allowed);
933935
if (retval < 0)
934936
goto done;
937+
938+
if (!nodes_subset(trialcs.mems_allowed,
939+
node_states[N_HIGH_MEMORY]))
940+
return -EINVAL;
935941
}
936-
nodes_and(trialcs.mems_allowed, trialcs.mems_allowed,
937-
node_states[N_HIGH_MEMORY]);
938942
oldmem = cs->mems_allowed;
939943
if (nodes_equal(oldmem, trialcs.mems_allowed)) {
940944
retval = 0; /* Too easy - nothing to do */

0 commit comments

Comments
 (0)