mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAlr753gACgkQONu9yGCS aT7p/Q//TIC9EKe21E2Lb1Kh4lL5SDjmwe/rkA3PxiqxbkXfUDBehMCfDk4YVNVG TlH1TXOubzpS/8cZJPRFHEkrYXPKIA3+hKlAvJukUJCBQqmW1ILEAX5m7jrSmf+B tLe/r0ijOtlfB1xQdUs5RxXGIndw0gMGhpo/QTXPAC0hGh0Ykd8v2s4YAjxOvdKw z4DaUKtZGEPBWFVK/Bx1Fv3iAmJMt2yerERUqz8MVegYXJt+2RUGoJtsxHuvOk1p 9q0lzHBWYihQVt1tJ0es/8cB7WsYt8txnVmeN907sryUhDjvTWIxQJb5jEV0gxxK AL89PHy4Hfki6l6r+tqYi92frFda8aLfsaSseOhlmqsv0MlwngW2dx3UbjaYd4If IQA6n0hWHuxUvjrjsPpsMAa4lvTW+/kFilb0mD6Vixy3ru+/RelKnuawJm6kbMNu Cb8QSVSJrhvC/UZLvwO7a3viJdKoI5B9pTh5FTKcY5wUPI1k01pg3WlWNxmnv4ZJ LPImR06aoJYhvbutf94AvxbCOt/au8sY4s/yk9oHgvGUEIccrGYf3BwX6ciWRt4b r4ZN92C9ZuD+u/ATFgi/akngtjjixw5YrZ20aX86dYcBZ25hYOiIMoc482tYQ12Z 1vqyvKg9o1oMypG9orF09PWstbNRu3ihGATKdXL9lfAhDklOTKc= =zWTK -----END PGP SIGNATURE----- Merge 4.14.41 into android-4.14 Changes in 4.14.41 ipvs: fix rtnl_lock lockups caused by start_sync_thread netfilter: ebtables: don't attempt to allocate 0-sized compat array kcm: Call strp_stop before strp_done in kcm_attach crypto: af_alg - fix possible uninit-value in alg_bind() netlink: fix uninit-value in netlink_sendmsg net: fix rtnh_ok() net: initialize skb->peeked when cloning net: fix uninit-value in __hw_addr_add_ex() dccp: initialize ireq->ir_mark ipv4: fix uninit-value in ip_route_output_key_hash_rcu() soreuseport: initialise timewait reuseport field inetpeer: fix uninit-value in inet_getpeer memcg: fix per_node_info cleanup perf: Remove superfluous allocation error check tcp: fix TCP_REPAIR_QUEUE bound checking bdi: wake up concurrent wb_shutdown() callers. bdi: Fix oops in wb_workfn() KVM: PPC: Book3S HV: Fix trap number return from __kvmppc_vcore_entry KVM: PPC: Book3S HV: Fix guest time accounting with VIRT_CPU_ACCOUNTING_GEN KVM: PPC: Book3S HV: Fix VRMA initialization with 2MB or 1GB memory backing arm64: Add work around for Arm Cortex-A55 Erratum 1024718 compat: fix 4-byte infoleak via uninitialized struct field gpioib: do not free unrequested descriptors gpio: fix aspeed_gpio unmask irq gpio: fix error path in lineevent_create rfkill: gpio: fix memory leak in probe error path libata: Apply NOLPM quirk for SanDisk SD7UB3Q*G1001 SSDs dm integrity: use kvfree for kvmalloc'd memory tracing: Fix regex_match_front() to not over compare the test string z3fold: fix reclaim lock-ups mm: sections are not offlined during memory hotremove mm, oom: fix concurrent munlock and oom reaper unmap, v3 ceph: fix rsize/wsize capping in ceph_direct_read_write() can: kvaser_usb: Increase correct stats counter in kvaser_usb_rx_can_msg() can: hi311x: Acquire SPI lock on ->do_get_berr_counter can: hi311x: Work around TX complete interrupt erratum drm/vc4: Fix scaling of uni-planar formats drm/i915: Fix drm:intel_enable_lvds ERROR message in kernel log drm/nouveau: Fix deadlock in nv50_mstm_register_connector() drm/atomic: Clean old_state/new_state in drm_atomic_state_default_clear() drm/atomic: Clean private obj old_state/new_state in drm_atomic_state_default_clear() net: atm: Fix potential Spectre v1 atm: zatm: Fix potential Spectre v1 PCI / PM: Always check PME wakeup capability for runtime wakeup support PCI / PM: Check device_may_wakeup() in pci_enable_wake() cpufreq: schedutil: Avoid using invalid next_freq Revert "Bluetooth: btusb: Fix quirk for Atheros 1525/QCA6174" Bluetooth: btusb: Add Dell XPS 13 9360 to btusb_needs_reset_resume_table Bluetooth: btusb: Only check needs_reset_resume DMI table for QCA rome chipsets thermal: exynos: Reading temperature makes sense only when TMU is turned on thermal: exynos: Propagate error value from tmu_read() nvme: add quirk to force medium priority for SQ creation smb3: directory sync should not return an error sched/autogroup: Fix possible Spectre-v1 indexing for sched_prio_to_weight[] tracing/uprobe_event: Fix strncpy corner case perf/x86: Fix possible Spectre-v1 indexing for hw_perf_event cache_* perf/x86/cstate: Fix possible Spectre-v1 indexing for pkg_msr perf/x86/msr: Fix possible Spectre-v1 indexing in the MSR driver perf/core: Fix possible Spectre-v1 indexing for ->aux_pages[] perf/x86: Fix possible Spectre-v1 indexing for x86_pmu::event_map() KVM: PPC: Book3S HV: Fix handling of large pages in radix page fault handler KVM: x86: remove APIC Timer periodic/oneshot spikes Linux 4.14.41 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
273 lines
6.5 KiB
C
273 lines
6.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include "sched.h"
|
|
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/kallsyms.h>
|
|
#include <linux/utsname.h>
|
|
#include <linux/security.h>
|
|
#include <linux/export.h>
|
|
#include <linux/nospec.h>
|
|
|
|
unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
|
|
static struct autogroup autogroup_default;
|
|
static atomic_t autogroup_seq_nr;
|
|
|
|
void __init autogroup_init(struct task_struct *init_task)
|
|
{
|
|
autogroup_default.tg = &root_task_group;
|
|
kref_init(&autogroup_default.kref);
|
|
init_rwsem(&autogroup_default.lock);
|
|
init_task->signal->autogroup = &autogroup_default;
|
|
}
|
|
|
|
void autogroup_free(struct task_group *tg)
|
|
{
|
|
kfree(tg->autogroup);
|
|
}
|
|
|
|
static inline void autogroup_destroy(struct kref *kref)
|
|
{
|
|
struct autogroup *ag = container_of(kref, struct autogroup, kref);
|
|
|
|
#ifdef CONFIG_RT_GROUP_SCHED
|
|
/* We've redirected RT tasks to the root task group... */
|
|
ag->tg->rt_se = NULL;
|
|
ag->tg->rt_rq = NULL;
|
|
#endif
|
|
sched_offline_group(ag->tg);
|
|
sched_destroy_group(ag->tg);
|
|
}
|
|
|
|
static inline void autogroup_kref_put(struct autogroup *ag)
|
|
{
|
|
kref_put(&ag->kref, autogroup_destroy);
|
|
}
|
|
|
|
static inline struct autogroup *autogroup_kref_get(struct autogroup *ag)
|
|
{
|
|
kref_get(&ag->kref);
|
|
return ag;
|
|
}
|
|
|
|
static inline struct autogroup *autogroup_task_get(struct task_struct *p)
|
|
{
|
|
struct autogroup *ag;
|
|
unsigned long flags;
|
|
|
|
if (!lock_task_sighand(p, &flags))
|
|
return autogroup_kref_get(&autogroup_default);
|
|
|
|
ag = autogroup_kref_get(p->signal->autogroup);
|
|
unlock_task_sighand(p, &flags);
|
|
|
|
return ag;
|
|
}
|
|
|
|
static inline struct autogroup *autogroup_create(void)
|
|
{
|
|
struct autogroup *ag = kzalloc(sizeof(*ag), GFP_KERNEL);
|
|
struct task_group *tg;
|
|
|
|
if (!ag)
|
|
goto out_fail;
|
|
|
|
tg = sched_create_group(&root_task_group);
|
|
if (IS_ERR(tg))
|
|
goto out_free;
|
|
|
|
kref_init(&ag->kref);
|
|
init_rwsem(&ag->lock);
|
|
ag->id = atomic_inc_return(&autogroup_seq_nr);
|
|
ag->tg = tg;
|
|
#ifdef CONFIG_RT_GROUP_SCHED
|
|
/*
|
|
* Autogroup RT tasks are redirected to the root task group
|
|
* so we don't have to move tasks around upon policy change,
|
|
* or flail around trying to allocate bandwidth on the fly.
|
|
* A bandwidth exception in __sched_setscheduler() allows
|
|
* the policy change to proceed.
|
|
*/
|
|
free_rt_sched_group(tg);
|
|
tg->rt_se = root_task_group.rt_se;
|
|
tg->rt_rq = root_task_group.rt_rq;
|
|
#endif
|
|
tg->autogroup = ag;
|
|
|
|
sched_online_group(tg, &root_task_group);
|
|
return ag;
|
|
|
|
out_free:
|
|
kfree(ag);
|
|
out_fail:
|
|
if (printk_ratelimit()) {
|
|
printk(KERN_WARNING "autogroup_create: %s failure.\n",
|
|
ag ? "sched_create_group()" : "kzalloc()");
|
|
}
|
|
|
|
return autogroup_kref_get(&autogroup_default);
|
|
}
|
|
|
|
bool task_wants_autogroup(struct task_struct *p, struct task_group *tg)
|
|
{
|
|
if (tg != &root_task_group)
|
|
return false;
|
|
/*
|
|
* If we race with autogroup_move_group() the caller can use the old
|
|
* value of signal->autogroup but in this case sched_move_task() will
|
|
* be called again before autogroup_kref_put().
|
|
*
|
|
* However, there is no way sched_autogroup_exit_task() could tell us
|
|
* to avoid autogroup->tg, so we abuse PF_EXITING flag for this case.
|
|
*/
|
|
if (p->flags & PF_EXITING)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
void sched_autogroup_exit_task(struct task_struct *p)
|
|
{
|
|
/*
|
|
* We are going to call exit_notify() and autogroup_move_group() can't
|
|
* see this thread after that: we can no longer use signal->autogroup.
|
|
* See the PF_EXITING check in task_wants_autogroup().
|
|
*/
|
|
sched_move_task(p);
|
|
}
|
|
|
|
static void
|
|
autogroup_move_group(struct task_struct *p, struct autogroup *ag)
|
|
{
|
|
struct autogroup *prev;
|
|
struct task_struct *t;
|
|
unsigned long flags;
|
|
|
|
BUG_ON(!lock_task_sighand(p, &flags));
|
|
|
|
prev = p->signal->autogroup;
|
|
if (prev == ag) {
|
|
unlock_task_sighand(p, &flags);
|
|
return;
|
|
}
|
|
|
|
p->signal->autogroup = autogroup_kref_get(ag);
|
|
/*
|
|
* We can't avoid sched_move_task() after we changed signal->autogroup,
|
|
* this process can already run with task_group() == prev->tg or we can
|
|
* race with cgroup code which can read autogroup = prev under rq->lock.
|
|
* In the latter case for_each_thread() can not miss a migrating thread,
|
|
* cpu_cgroup_attach() must not be possible after cgroup_exit() and it
|
|
* can't be removed from thread list, we hold ->siglock.
|
|
*
|
|
* If an exiting thread was already removed from thread list we rely on
|
|
* sched_autogroup_exit_task().
|
|
*/
|
|
for_each_thread(p, t)
|
|
sched_move_task(t);
|
|
|
|
unlock_task_sighand(p, &flags);
|
|
autogroup_kref_put(prev);
|
|
}
|
|
|
|
/* Allocates GFP_KERNEL, cannot be called under any spinlock */
|
|
void sched_autogroup_create_attach(struct task_struct *p)
|
|
{
|
|
struct autogroup *ag = autogroup_create();
|
|
|
|
autogroup_move_group(p, ag);
|
|
/* drop extra reference added by autogroup_create() */
|
|
autogroup_kref_put(ag);
|
|
}
|
|
EXPORT_SYMBOL(sched_autogroup_create_attach);
|
|
|
|
/* Cannot be called under siglock. Currently has no users */
|
|
void sched_autogroup_detach(struct task_struct *p)
|
|
{
|
|
autogroup_move_group(p, &autogroup_default);
|
|
}
|
|
EXPORT_SYMBOL(sched_autogroup_detach);
|
|
|
|
void sched_autogroup_fork(struct signal_struct *sig)
|
|
{
|
|
sig->autogroup = autogroup_task_get(current);
|
|
}
|
|
|
|
void sched_autogroup_exit(struct signal_struct *sig)
|
|
{
|
|
autogroup_kref_put(sig->autogroup);
|
|
}
|
|
|
|
static int __init setup_autogroup(char *str)
|
|
{
|
|
sysctl_sched_autogroup_enabled = 0;
|
|
|
|
return 1;
|
|
}
|
|
|
|
__setup("noautogroup", setup_autogroup);
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
|
|
{
|
|
static unsigned long next = INITIAL_JIFFIES;
|
|
struct autogroup *ag;
|
|
unsigned long shares;
|
|
int err, idx;
|
|
|
|
if (nice < MIN_NICE || nice > MAX_NICE)
|
|
return -EINVAL;
|
|
|
|
err = security_task_setnice(current, nice);
|
|
if (err)
|
|
return err;
|
|
|
|
if (nice < 0 && !can_nice(current, nice))
|
|
return -EPERM;
|
|
|
|
/* this is a heavy operation taking global locks.. */
|
|
if (!capable(CAP_SYS_ADMIN) && time_before(jiffies, next))
|
|
return -EAGAIN;
|
|
|
|
next = HZ / 10 + jiffies;
|
|
ag = autogroup_task_get(p);
|
|
|
|
idx = array_index_nospec(nice + 20, 40);
|
|
shares = scale_load(sched_prio_to_weight[idx]);
|
|
|
|
down_write(&ag->lock);
|
|
err = sched_group_set_shares(ag->tg, shares);
|
|
if (!err)
|
|
ag->nice = nice;
|
|
up_write(&ag->lock);
|
|
|
|
autogroup_kref_put(ag);
|
|
|
|
return err;
|
|
}
|
|
|
|
void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m)
|
|
{
|
|
struct autogroup *ag = autogroup_task_get(p);
|
|
|
|
if (!task_group_is_autogroup(ag->tg))
|
|
goto out;
|
|
|
|
down_read(&ag->lock);
|
|
seq_printf(m, "/autogroup-%ld nice %d\n", ag->id, ag->nice);
|
|
up_read(&ag->lock);
|
|
|
|
out:
|
|
autogroup_kref_put(ag);
|
|
}
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
int autogroup_path(struct task_group *tg, char *buf, int buflen)
|
|
{
|
|
if (!task_group_is_autogroup(tg))
|
|
return 0;
|
|
|
|
return snprintf(buf, buflen, "%s-%ld", "/autogroup", tg->autogroup->id);
|
|
}
|