Skip to contentSkip to conversation

cpuset: return -EINVAL for legacy non-subset child creation attempt

PATCH Mike Galbraith 2 participants 3 messages Dec 1, 2015 – Dec 2, 2015

lore
Share & tools
lore
#0 lore raw

A legacy hierarchy child set that is not a subset of its parent is not a permissions issue, it's an invalid configuration. Return -EINVAL.

---
 kernel/cpuset.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/cpuset.c +1 -2
@@ -472,7 +472,7 @@ static int validate_change(struct cpuset
 	par = parent_cs(cur);
 
 	/* On legacy hiearchy, we must be a subset of our parent cpuset. */
-	ret = -EACCES;
+	ret = -EINVAL;
 	if (!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
 	    !is_cpuset_subset(trial, par))
 		goto out;
@@ -481,7 +481,6 @@ static int validate_change(struct cpuset
 	 * If either I or some sibling (!= me) is exclusive, we can't
 	 * overlap
 	 */
-	ret = -EINVAL;
 	cpuset_for_each_child(c, css, par) {
 		if ((is_cpu_exclusive(trial) || is_cpu_exclusive(c)) &&
 		    c != cur &&
#1 lore raw
Quoted 3 lines · Mike Galbraith

A legacy hierarchy child set that is not a subset of its parent is not a permissions issue, it's an invalid configuration. Return -EINVAL.

It's sometimes arguable which errno should be used. In this case I don't see why we can't use EACCES. It's even documented in man page.

EACCES Attempted to add, using write(2), a CPU or memory node to a
cpuset, when that CPU or memory node was not already in its par- ent.

Let's see another example. In mmap manual:

EACCES A file descriptor refers to a non-regular file.

We can argue fd of a non-regular file is an invalid configuration, but here we return EACCES.

Quoted 27 lines
---
  kernel/cpuset.c |    3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
kernel/cpuset.c +1 -2
@@ -472,7 +472,7 @@ static int validate_change(struct cpuset
  	par = parent_cs(cur);
 
  	/* On legacy hiearchy, we must be a subset of our parent cpuset. */
-	ret = -EACCES;
+	ret = -EINVAL;
  	if (!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
  	    !is_cpuset_subset(trial, par))
  		goto out;
@@ -481,7 +481,6 @@ static int validate_change(struct cpuset
  	 * If either I or some sibling (!= me) is exclusive, we can't
  	 * overlap
  	 */
-	ret = -EINVAL;
  	cpuset_for_each_child(c, css, par) {
  		if ((is_cpu_exclusive(trial) || is_cpu_exclusive(c)) &&
  		    c != cur &&
#2 lore raw
Quoted 12 lines · Zefan Li
Quoted 3 lines · Mike Galbraith

A legacy hierarchy child set that is not a subset of its parent is not a permissions issue, it's an invalid configuration. Return -EINVAL.

It's sometimes arguable which errno should be used. In this case I don't see why we can't use EACCES. It's even documented in man page.

EACCES Attempted to add, using write(2), a CPU or memory node to a
cpuset, when that CPU or memory node was not already in its par- ent.

Quoted 6 lines

Let's see another example. In mmap manual:

EACCES A file descriptor refers to a non-regular file.

We can argue fd of a non-regular file is an invalid configuration, but here we return EACCES.

Ok, works for me (official -ENOPE -> gripee), thanks.

-Mike