Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * fs/ioprio.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2004 Jens Axboe <axboe@kernel.dk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Helper functions for setting/querying io priorities of processes. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * system calls closely mimmick getpriority/setpriority, see the man page for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * those. The prio argument is a composite of prio class and prio data, where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * the data argument has meaning within that class. The standard scheduling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * classes have 8 distinct prio levels, with 0 being the highest prio and 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * being the lowest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * IOW, setting BE scheduling class with prio 2 is done ala:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * unsigned int prio = (IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT) | 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * ioprio_set(PRIO_PROCESS, pid, prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * See also Documentation/block/ioprio.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/ioprio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/cred.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/sched/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/pid_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) int set_task_ioprio(struct task_struct *task, int ioprio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct io_context *ioc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	const struct cred *cred = current_cred(), *tcred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	tcred = __task_cred(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (!uid_eq(tcred->uid, cred->euid) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	    !uid_eq(tcred->uid, cred->uid) && !capable(CAP_SYS_NICE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	err = security_task_setioprio(task, ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	ioc = get_task_io_context(task, GFP_ATOMIC, NUMA_NO_NODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (ioc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		ioc->ioprio = ioprio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		put_io_context(ioc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) EXPORT_SYMBOL_GPL(set_task_ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) int ioprio_check_cap(int ioprio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int class = IOPRIO_PRIO_CLASS(ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int data = IOPRIO_PRIO_DATA(ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	switch (class) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		case IOPRIO_CLASS_RT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			 * Originally this only checked for CAP_SYS_ADMIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			 * which was implicitly allowed for pid 0 by security
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			 * modules such as SELinux. Make sure we check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			 * CAP_SYS_ADMIN first to avoid a denial/avc for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			 * possibly missing CAP_SYS_NICE permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_NICE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			/* rt has prio field too */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		case IOPRIO_CLASS_BE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			if (data >= IOPRIO_BE_NR || data < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		case IOPRIO_CLASS_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		case IOPRIO_CLASS_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			if (data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct task_struct *p, *g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct user_struct *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct pid *pgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	kuid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ret = ioprio_check_cap(ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	ret = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	switch (which) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		case IOPRIO_WHO_PROCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			if (!who)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 				p = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				p = find_task_by_vpid(who);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				ret = set_task_ioprio(p, ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		case IOPRIO_WHO_PGRP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			if (!who)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				pgrp = task_pgrp(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				pgrp = find_vpid(who);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 				ret = set_task_ioprio(p, ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			} while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		case IOPRIO_WHO_USER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			uid = make_kuid(current_user_ns(), who);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			if (!uid_valid(uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			if (!who)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				user = current_user();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				user = find_user(uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			if (!user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			for_each_process_thread(g, p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				if (!uid_eq(task_uid(p), uid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				    !task_pid_vnr(p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				ret = set_task_ioprio(p, ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 					goto free_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) free_uid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			if (who)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				free_uid(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int get_task_ioprio(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	ret = security_task_getioprio(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	ret = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, IOPRIO_NORM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	task_lock(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (p->io_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		ret = p->io_context->ioprio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	task_unlock(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int ioprio_best(unsigned short aprio, unsigned short bprio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (!ioprio_valid(aprio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		aprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (!ioprio_valid(bprio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	return min(aprio, bprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	struct task_struct *g, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct user_struct *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct pid *pgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	kuid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	int ret = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	int tmpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	switch (which) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		case IOPRIO_WHO_PROCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			if (!who)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				p = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				p = find_task_by_vpid(who);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				ret = get_task_ioprio(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		case IOPRIO_WHO_PGRP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			if (!who)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 				pgrp = task_pgrp(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				pgrp = find_vpid(who);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 				tmpio = get_task_ioprio(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				if (tmpio < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				if (ret == -ESRCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 					ret = tmpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 					ret = ioprio_best(ret, tmpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			} while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		case IOPRIO_WHO_USER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			uid = make_kuid(current_user_ns(), who);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			if (!who)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 				user = current_user();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 				user = find_user(uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			if (!user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			for_each_process_thread(g, p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				if (!uid_eq(task_uid(p), user->uid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				    !task_pid_vnr(p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 				tmpio = get_task_ioprio(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				if (tmpio < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				if (ret == -ESRCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 					ret = tmpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 					ret = ioprio_best(ret, tmpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			if (who)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				free_uid(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }