mm/mempolicy.c: Remove unnecessary nodemask check in kernel_migrate_pages()
Subsystems (4)
PATCH 1/1 mm/mempolicy.c: Remove unnecessary nodemask check in kernel_migrate_pages()
1) task_nodes = cpuset_mems_allowed(current);
-> cpuset_mems_allowed() guaranteed to return some non-empty
subset of node_states[N_MEMORY].
2) nodes_and(*new, *new, task_nodes);
-> after nodes_and(), the 'new' should be empty or appropriate
nodemask(online node and with memory).
After 1) and 2), we could remove unnecessary check whether the 'new' AND node_states[N_MEMORY] is empty.
---
[QUESTION]
SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
const unsigned long __user *, old_nodes, const unsigned long __user *, new_nodes)
{
return kernel_migrate_pages(pid, maxnode, old_nodes, new_nodes);
}The migrate_pages() takes pid argument, witch is the ID of the process whose pages are to be moved. should the cpuset_mems_allowed(current) be cpuset_mems_allowed(task)?
mm/mempolicy.c | 4 ---- 1 file changed, 4 deletions(-)
mm/mempolicy.c +0 -4
@@ -1467,10 +1467,6 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode,if (nodes_empty (*new)) goto out_put; -nodes_and (*new, *new, node_states[N_MEMORY ]); -if (nodes_empty (*new)) - goto out_put; - err =security_task_movememory (task);if (err) goto out_put;
Signature · 1 line
2.20.1
Quoted 3 lines · Kefeng Wang
1)
task_nodes=cpuset_mems_allowed(current);
->cpuset_mems_allowed()guaranteed to return some non-empty
subset of node_states[N_MEMORY].
Right, there's an explicit guarantee.
Quoted 6 lines
2)
nodes_and(*new, *new, task_nodes);
-> afternodes_and(), the 'new' should be empty or appropriate
nodemask(online node and with memory).After 1) and 2), we could remove unnecessary check whether the 'new' AND node_states[N_MEMORY] is empty.
Yeah looks like the check is there due to evolution of the code, where initially it was added to prevent calling the syscall with bogus nodes, but now that's achieved by cpuset_mems_allowed().
Quoted 8 lines
Cc Andrea Arcangeli <[email protected]>Cc Andrew Morton <[email protected]>Cc Dan Williams <[email protected]>Cc Michal Hocko <[email protected]>Cc Oscar Salvador <[email protected]>Cc Vlastimil Babka <[email protected]>Signed-off-by Kefeng Wang <[email protected]>
Quoted 7 lines
---
[QUESTION]
SYSCALL_DEFINE4(migrate_pages,
pid_t, pid, unsigned long, maxnode,
const unsigned long__user*,old_nodes, const unsigned long__user*,new_nodes)
Quoted 7 lines
{ return kernel_migrate_pages(pid, maxnode, old_nodes, new_nodes); }The
migrate_pages()takes pid argument, witch is the ID of the process whose pages are to be moved. should thecpuset_mems_allowed(current)becpuset_mems_allowed(task)?
The check for cpuset_mems_allowed(task) is just above the code you change, so the new nodes have to be subset of the target task's cpuset.
But they also have to be allowed by the calling task's cpuset. In manpage of migrate_pages(2), this is hinted by the NOTES "Use get_mempolicy(2) with the MPOL_F_MEMS_ALLOWED flag to obtain the set of nodes that are allowed by the calling process's cpuset..."
But perhaps the manpage should be better clarified:
- the EINVAL case includes "Or, none of the node IDs specified by new_nodes are on-line and allowed by the process's current cpuset context, or none of the specified nodes contain memory." - this should probably say "calling process" to disambiguate
- the EPERM case should mention that new_nodes have to be subset of the target process' cpuset context. The caller should also have CAP_SYS_NICE and ptrace_may_access()
Quoted 19 lines
mm/mempolicy.c | 4 ---- 1 file changed, 4 deletions(-)mm/mempolicy.c +0
-4@@ -1467,10 +1467,6 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode,if (nodes_empty (*new)) goto out_put; -nodes_and (*new, *new, node_states[N_MEMORY ]); -if (nodes_empty (*new)) - goto out_put; - err =security_task_movememory (task);if (err) goto out_put;
Quoted 1 line · Vlastimil Babka
On 8/6/19 4:36 AM, Kefeng Wang wrote:
[...]
Quoted 23 lines
Quoted 6 lines
[QUESTION]
SYSCALL_DEFINE4(migrate_pages,
pid_t, pid, unsigned long, maxnode,
const unsigned long__user*,old_nodes, const unsigned long__user*,new_nodes)Quoted 7 lines
{ return kernel_migrate_pages(pid, maxnode, old_nodes, new_nodes); }The
migrate_pages()takes pid argument, witch is the ID of the process whose pages are to be moved. should thecpuset_mems_allowed(current)becpuset_mems_allowed(task)?The check for
cpuset_mems_allowed(task)is just above the code you change, so the new nodes have to be subset of the target task's cpuset.
But they also have to be allowed by the calling task's cpuset. In manpage ofmigrate_pages(2), this is hinted by the NOTES "Useget_mempolicy(2)with theMPOL_F_MEMS_ALLOWEDflag to obtain the set of nodes that are allowed by the calling process's cpuset..."But perhaps the manpage should be better clarified:
Quoted 7 lines
- the EINVAL case includes "Or, none of the node IDs specified by
new_nodesare on-line and allowed by the process's current cpuset context, or none of the specified nodes contain memory." - this should probably say "calling process" to disambiguate
- the EPERM case should mention thatnew_nodeshave to be subset of the target process' cpuset context. The caller should also haveCAP_SYS_NICEandptrace_may_access()
Get it, thanks for your detail explanation.