Keep set_task_ioprio with the other low-level code that accesses the io_context structure.
Unified · Split
| @@ -8,6 +8,7 @@ · 7 unmodified lines | ||
| 8 | 8 | #include <linux/bio.h> |
| 9 | 9 | #include <linux/blkdev.h> |
| 10 | 10 | #include <linux/slab.h> |
| 11 | +#include <linux/security.h> | |
| 11 | 12 | #include <linux/sched/task.h> |
| 12 | 13 | |
| 13 | 14 | #include "blk.h" |
| @@ -280,8 +281,8 @@ static struct io_context *create_task_io_context(struct task_struct *task, · 266 unmodified lines | ||
| 280 | 281 | * This function always goes through task_lock() and it's better to use |
| 281 | 282 | * %current->io_context + get_io_context() for %current. |
| 282 | 283 | */ |
| 283 | −struct io_context *get_task_io_context(struct task_struct *task, | |
| 284 | − gfp_t gfp_flags, int node) | |
| 284 | +static struct io_context *get_task_io_context(struct task_struct *task, | |
| 285 | + gfp_t gfp_flags, int node) | |
| 285 | 286 | { |
| 286 | 287 | struct io_context *ioc; |
| 287 | 288 | |
| @@ -298,6 +299,35 @@ struct io_context *get_task_io_context(struct task_struct *task, · 10 unmodified lines | ||
| 298 | 299 | return ioc; |
| 299 | 300 | } |
| 300 | 301 | |
| 302 | +int set_task_ioprio(struct task_struct *task, int ioprio) | |
| 303 | +{ | |
| 304 | + int err; | |
| 305 | + struct io_context *ioc; | |
| 306 | + const struct cred *cred = current_cred(), *tcred; | |
| 307 | + | |
| 308 | + rcu_read_lock(); | |
| 309 | + tcred = __task_cred(task); | |
| 310 | + if (!uid_eq(tcred->uid, cred->euid) && | |
| 311 | + !uid_eq(tcred->uid, cred->uid) && !capable(CAP_SYS_NICE)) { | |
| 312 | + rcu_read_unlock(); | |
| 313 | + return -EPERM; | |
| 314 | + } | |
| 315 | + rcu_read_unlock(); | |
| 316 | + | |
| 317 | + err = security_task_setioprio(task, ioprio); | |
| 318 | + if (err) | |
| 319 | + return err; | |
| 320 | + | |
| 321 | + ioc = get_task_io_context(task, GFP_ATOMIC, NUMA_NO_NODE); | |
| 322 | + if (ioc) { | |
| 323 | + ioc->ioprio = ioprio; | |
| 324 | + put_io_context(ioc); | |
| 325 | + } | |
| 326 | + | |
| 327 | + return err; | |
| 328 | +} | |
| 329 | +EXPORT_SYMBOL_GPL(set_task_ioprio); | |
| 330 | + | |
| 301 | 331 | int __copy_io(unsigned long clone_flags, struct task_struct *tsk) |
| 302 | 332 | { |
| 303 | 333 | struct io_context *ioc = current->io_context; |
| @@ -22,46 +22,14 @@ · 21 unmodified lines | ||
| 22 | 22 | */ |
| 23 | 23 | #include <linux/gfp.h> |
| 24 | 24 | #include <linux/kernel.h> |
| 25 | −#include <linux/export.h> | |
| 26 | 25 | #include <linux/ioprio.h> |
| 27 | 26 | #include <linux/cred.h> |
| 28 | 27 | #include <linux/blkdev.h> |
| 29 | 28 | #include <linux/capability.h> |
| 30 | −#include <linux/sched/user.h> | |
| 31 | −#include <linux/sched/task.h> | |
| 32 | 29 | #include <linux/syscalls.h> |
| 33 | 30 | #include <linux/security.h> |
| 34 | 31 | #include <linux/pid_namespace.h> |
| 35 | 32 | |
| 36 | −int set_task_ioprio(struct task_struct *task, int ioprio) | |
| 37 | −{ | |
| 38 | − int err; | |
| 39 | − struct io_context *ioc; | |
| 40 | − const struct cred *cred = current_cred(), *tcred; | |
| 41 | − | |
| 42 | − rcu_read_lock(); | |
| 43 | − tcred = __task_cred(task); | |
| 44 | − if (!uid_eq(tcred->uid, cred->euid) && | |
| 45 | − !uid_eq(tcred->uid, cred->uid) && !capable(CAP_SYS_NICE)) { | |
| 46 | − rcu_read_unlock(); | |
| 47 | − return -EPERM; | |
| 48 | − } | |
| 49 | − rcu_read_unlock(); | |
| 50 | − | |
| 51 | − err = security_task_setioprio(task, ioprio); | |
| 52 | − if (err) | |
| 53 | − return err; | |
| 54 | − | |
| 55 | − ioc = get_task_io_context(task, GFP_ATOMIC, NUMA_NO_NODE); | |
| 56 | − if (ioc) { | |
| 57 | − ioc->ioprio = ioprio; | |
| 58 | − put_io_context(ioc); | |
| 59 | − } | |
| 60 | − | |
| 61 | − return err; | |
| 62 | −} | |
| 63 | −EXPORT_SYMBOL_GPL(set_task_ioprio); | |
| 64 | − | |
| 65 | 33 | int ioprio_check_cap(int ioprio) |
| 66 | 34 | { |
| 67 | 35 | int class = IOPRIO_PRIO_CLASS(ioprio); |
| @@ -116,8 +116,6 @@ struct task_struct; · 115 unmodified lines | ||
| 116 | 116 | #ifdef CONFIG_BLOCK |
| 117 | 117 | void put_io_context(struct io_context *ioc); |
| 118 | 118 | void exit_io_context(struct task_struct *task); |
| 119 | −struct io_context *get_task_io_context(struct task_struct *task, | |
| 120 | − gfp_t gfp_flags, int node); | |
| 121 | 119 | int __copy_io(unsigned long clone_flags, struct task_struct *tsk); |
| 122 | 120 | static inline int copy_io(unsigned long clone_flags, struct task_struct *tsk) |
| 123 | 121 | { |