All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] posix-cpu-timers: Graceful handling of reaped processes
@ 2020-02-28 17:07 Eric W. Biederman
  2020-02-28 17:08 ` [PATCH 1/5] posix-cpu-timers: cpu_clock_sample_group no longer needs siglock Eric W. Biederman
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Eric W. Biederman @ 2020-02-28 17:07 UTC (permalink / raw)
  To: linux-kernel; +Cc: Oleg Nesterov, Thomas Gleixner


Oleg, Thomas,

The posic cpu timer code does not handle processes that is is using as a
clock source exiting and being reaped at all well.  In most cases the
code pins the entire task struct for no good reason.  In the
multi-threaded exec case where the thread group leader exits but the
thread group remains the posix cpu timers just stop working when it
should not.

To solve that problems requires checking if the target processes is
still alive before proceeding.  Replacing cpu.task with a struct pid
pointer is the easiest way I can see to add that extra checking and
extra indirection needed.

So here is my fix.  Oleg, Thomas and if you guys could take a look and
see I made any mistakes I would appreciate it.

Thomas if you want these changes you can have them otherwise I will take
them through my tree.  

Eric W. Biederman (5):
      posix-cpu-timers: cpu_clock_sample_group no longer needs siglock
      posix-cpu-timers: Remove unnecessary locking around cpu_clock_sample_group
      posix-cpu-timers: Pass the task into arm_timer
      posix-cpu-timers: Store a reference to a pid not a task
      posix-cpu-timers: Stop disabling timers on mt-exec

 include/linux/posix-timers.h   |   2 +-
 kernel/exit.c                  |  11 +---
 kernel/time/posix-cpu-timers.c | 137 +++++++++++++++++++----------------------
 3 files changed, 67 insertions(+), 83 deletions(-)

Eric

^ permalink raw reply	[flat|nested] 14+ messages in thread
* [tip: timers/core] posix-cpu-timers: Pass the task into arm_timer()
@ 2020-02-29 20:49 tip-bot2 for Eric W. Biederman
  0 siblings, 0 replies; 14+ messages in thread
From: tip-bot2 for Eric W. Biederman @ 2020-02-29 20:49 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Eric W. Biederman, Thomas Gleixner, x86, LKML

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     197ba902548386e966bb7848d3148a130bb01bd9
Gitweb:        https://git.kernel.org/tip/197ba902548386e966bb7848d3148a130bb01bd9
Author:        Eric W. Biederman <ebiederm@xmission.com>
AuthorDate:    Fri, 28 Feb 2020 11:09:46 -06:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Sat, 29 Feb 2020 21:44:46 +01:00

posix-cpu-timers: Pass the task into arm_timer()

The task has been already computed to take siglock before calling
arm_timer. So pass the benefit of that labor into arm_timer().

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

---
 kernel/time/posix-cpu-timers.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 40c2d83..ef936c5 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -482,12 +482,11 @@ void posix_cpu_timers_exit_group(struct task_struct *tsk)
  * Insert the timer on the appropriate list before any timers that
  * expire later.  This must be called with the sighand lock held.
  */
-static void arm_timer(struct k_itimer *timer)
+static void arm_timer(struct k_itimer *timer, struct task_struct *p)
 {
 	int clkidx = CPUCLOCK_WHICH(timer->it_clock);
 	struct cpu_timer *ctmr = &timer->it.cpu;
 	u64 newexp = cpu_timer_getexpires(ctmr);
-	struct task_struct *p = ctmr->task;
 	struct posix_cputimer_base *base;
 
 	if (CPUCLOCK_PERTHREAD(timer->it_clock))
@@ -660,7 +659,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
 	 */
 	cpu_timer_setexpires(ctmr, new_expires);
 	if (new_expires != 0 && val < new_expires) {
-		arm_timer(timer);
+		arm_timer(timer, p);
 	}
 
 	unlock_task_sighand(p, &flags);
@@ -980,7 +979,7 @@ static void posix_cpu_timer_rearm(struct k_itimer *timer)
 	/*
 	 * Now re-arm for the new expiry time.
 	 */
-	arm_timer(timer);
+	arm_timer(timer, p);
 	unlock_task_sighand(p, &flags);
 }
 

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-03-04  8:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-28 17:07 [PATCH 0/5] posix-cpu-timers: Graceful handling of reaped processes Eric W. Biederman
2020-02-28 17:08 ` [PATCH 1/5] posix-cpu-timers: cpu_clock_sample_group no longer needs siglock Eric W. Biederman
2020-03-01 10:27   ` [tip: timers/core] posix-cpu-timers: cpu_clock_sample_group() " tip-bot2 for Eric W. Biederman
2020-02-28 17:09 ` [PATCH 2/5] posix-cpu-timers: Remove unnecessary locking around cpu_clock_sample_group Eric W. Biederman
2020-03-01 10:27   ` [tip: timers/core] " tip-bot2 for Eric W. Biederman
2020-02-28 17:09 ` [PATCH 3/5] posix-cpu-timers: Pass the task into arm_timer Eric W. Biederman
2020-03-01 10:27   ` [tip: timers/core] posix-cpu-timers: Pass the task into arm_timer() tip-bot2 for Eric W. Biederman
2020-02-28 17:11 ` [PATCH 4/5] posix-cpu-timers: Store a reference to a pid not a task Eric W. Biederman
2020-03-01 10:27   ` [tip: timers/core] " tip-bot2 for Eric W. Biederman
2020-03-04  8:57   ` tip-bot2 for Eric W. Biederman
2020-02-28 17:15 ` [PATCH 5/5] posix-cpu-timers: Stop disabling timers on mt-exec Eric W. Biederman
2020-03-01 10:27   ` [tip: timers/core] " tip-bot2 for Eric W. Biederman
2020-03-04  8:57   ` tip-bot2 for Eric W. Biederman
2020-02-29 20:49 [tip: timers/core] posix-cpu-timers: Pass the task into arm_timer() tip-bot2 for Eric W. Biederman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.