Commit f85b3a02 authored by Benjamin Segall's avatar Benjamin Segall Committed by Wentao Guan
Browse files

posix-cpu-timers: Clear TICK_DEP_BIT_POSIX_TIMER on clone

stable inclusion
from stable-v6.6.61
commit 203003c4ff18f95ae697fe5c24c9674463f48067
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IB4YVY

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=203003c4ff18f95ae697fe5c24c9674463f48067



--------------------------------

[ Upstream commit b5413156bad91dc2995a5c4eab1b05e56914638a ]

When cloning a new thread, its posix_cputimers are not inherited, and
are cleared by posix_cputimers_init(). However, this does not clear the
tick dependency it creates in tsk->tick_dep_mask, and the handler does
not reach the code to clear the dependency if there were no timers to
begin with.

Thus if a thread has a cputimer running before clone/fork, all
descendants will prevent nohz_full unless they create a cputimer of
their own.

Fix this by entirely clearing the tick_dep_mask in copy_process().
(There is currently no inherited state that needs a tick dependency)

Process-wide timers do not have this problem because fork does not copy
signal_struct as a baseline, it creates one from scratch.

Fixes: b7878300 ("posix-cpu-timers: Migrate to use new tick dependency mask model")
Signed-off-by: default avatarBen Segall <bsegall@google.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarFrederic Weisbecker <frederic@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/xm26o737bq8o.fsf@google.com


Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
(cherry picked from commit 203003c4ff18f95ae697fe5c24c9674463f48067)
[Conflicts: include context]
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent 9d22d5b7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -259,12 +259,19 @@ static inline void tick_dep_set_task(struct task_struct *tsk,
	if (tick_nohz_full_enabled())
		tick_nohz_dep_set_task(tsk, bit);
}

static inline void tick_dep_clear_task(struct task_struct *tsk,
				       enum tick_dep_bits bit)
{
	if (tick_nohz_full_enabled())
		tick_nohz_dep_clear_task(tsk, bit);
}

static inline void tick_dep_init_task(struct task_struct *tsk)
{
	atomic_set(&tsk->tick_dep_mask, 0);
}

static inline void tick_dep_set_signal(struct task_struct *tsk,
				       enum tick_dep_bits bit)
{
@@ -298,6 +305,7 @@ static inline void tick_dep_set_task(struct task_struct *tsk,
				     enum tick_dep_bits bit) { }
static inline void tick_dep_clear_task(struct task_struct *tsk,
				       enum tick_dep_bits bit) { }
static inline void tick_dep_init_task(struct task_struct *tsk) { }
static inline void tick_dep_set_signal(struct task_struct *tsk,
				       enum tick_dep_bits bit) { }
static inline void tick_dep_clear_signal(struct signal_struct *signal,
+2 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@
#include <linux/sched/grid_qos.h>
#endif
#include <linux/share_pool.h>
#include <linux/tick.h>

#include <asm/pgalloc.h>
#include <linux/uaccess.h>
@@ -2516,6 +2517,7 @@ __latent_entropy struct task_struct *copy_process(
	acct_clear_integrals(p);

	posix_cputimers_init(&p->posix_cputimers);
	tick_dep_init_task(p);

	p->io_context = NULL;
	audit_set_context(p, NULL);