From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756171AbcIGGlw (ORCPT ); Wed, 7 Sep 2016 02:41:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37126 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754491AbcIGGlu (ORCPT ); Wed, 7 Sep 2016 02:41:50 -0400 Date: Wed, 7 Sep 2016 08:38:27 +0200 From: Stanislaw Gruszka To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Giovanni Gherdovich , Linus Torvalds , Mel Gorman , Mike Galbraith , Paolo Bonzini , Rik van Riel , Thomas Gleixner , Wanpeng Li , Ingo Molnar Subject: Re: [PATCH v3] sched/cputime: Protect some other sum_exec_runtime reads on 32 bit cpus Message-ID: <20160907063826.GA16999@redhat.com> References: <1473166148-8466-1-git-send-email-sgruszka@redhat.com> <20160906190129.GO10153@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160906190129.GO10153@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 07 Sep 2016 06:41:50 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 06, 2016 at 09:01:29PM +0200, Peter Zijlstra wrote: > On Tue, Sep 06, 2016 at 02:49:08PM +0200, Stanislaw Gruszka wrote: > > diff --git a/kernel/exit.c b/kernel/exit.c > > index 2f974ae..a46f96f 100644 > > --- a/kernel/exit.c > > +++ b/kernel/exit.c > > @@ -134,7 +134,7 @@ static void __exit_signal(struct task_struct *tsk) > > sig->inblock += task_io_get_inblock(tsk); > > sig->oublock += task_io_get_oublock(tsk); > > task_io_accounting_add(&sig->ioac, &tsk->ioac); > > - sig->sum_sched_runtime += tsk->se.sum_exec_runtime; > > + sig->sum_sched_runtime += read_sum_exec_runtime(tsk); > > sig->nr_threads--; > > __unhash_process(tsk, group_dead); > > write_sequnlock(&sig->stats_lock); > > If I'm not mistaken, at this point @p is dead, sum_exec_runtime will not > ever be updated again. I think at this point find_task_by_vpid() will still return not-null pointer, hence we can update sum_exec_runtime via: posix_cpu_{clock_get(),timer_set(),timer_get()} -> cpu_clock_sample() -> task_sched_runtime() -> update_curr() if some thread will do cpuclock/cputimer related syscall for different thread and CPUCLOCK_SCHED clock. > > diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c > > index 39008d7..a2d753b 100644 > > --- a/kernel/time/posix-cpu-timers.c > > +++ b/kernel/time/posix-cpu-timers.c > > @@ -848,7 +848,7 @@ static void check_thread_timers(struct task_struct *tsk, > > tsk_expires->virt_exp = expires_to_cputime(expires); > > > > tsk_expires->sched_exp = check_timers_list(++timers, firing, > > - tsk->se.sum_exec_runtime); > > + read_sum_exec_runtime(tsk)); > > > > /* > > * Check for the special case thread timers. > > @tsk == current and IRQs are disabled, sum_exec_runtime cannot be > updated. It still can be updated via syscalls on different thread, same paths as above. > > @@ -1115,7 +1115,7 @@ static inline int fastpath_timer_check(struct task_struct *tsk) > > struct task_cputime task_sample; > > > > task_cputime(tsk, &task_sample.utime, &task_sample.stime); > > - task_sample.sum_exec_runtime = tsk->se.sum_exec_runtime; > > + task_sample.sum_exec_runtime = read_sum_exec_runtime(tsk); > > if (task_cputime_expired(&task_sample, &tsk->cputime_expires)) > > return 1; > > } > > Same. Same :-) But this could be optimized to avoid taking lock if not needed: if (expires->sum_exec_runtime != 0) task_sample.sum_exec_runtime = read_sum_exec_runtime(tsk); Stanislaw