From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756245AbbDXJMG (ORCPT ); Fri, 24 Apr 2015 05:12:06 -0400 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:47698 "EHLO e06smtp15.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756159AbbDXJMD (ORCPT ); Fri, 24 Apr 2015 05:12:03 -0400 Date: Fri, 24 Apr 2015 11:11:56 +0200 From: Heiko Carstens To: Rik van Riel Cc: linux-kernel@vger.kernel.org, Andy Lutomirsky , Frederic Weisbecker , Peter Zijlstra , Luiz Capitulino , Marcelo Tosatti , Clark Williams Subject: Re: [PATCH] context_tracking: remove local_irq_save from __acct_update_integrals Message-ID: <20150424091156.GB4089@osiris> References: <20150423215713.3334ae6f@annuminas.surriel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150423215713.3334ae6f@annuminas.surriel.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15042409-0021-0000-0000-000003B1FDA4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 23, 2015 at 09:57:13PM -0400, Rik van Riel wrote: > diff --git a/kernel/tsacct.c b/kernel/tsacct.c > index 975cb49e32bf..0b967f116a6b 100644 > --- a/kernel/tsacct.c > +++ b/kernel/tsacct.c > @@ -126,23 +126,29 @@ static void __acct_update_integrals(struct task_struct *tsk, > if (likely(tsk->mm)) { > cputime_t time, dtime; > struct timeval value; > - unsigned long flags; > u64 delta; > > - local_irq_save(flags); > time = stime + utime; > dtime = time - tsk->acct_timexpd; > + /* > + * This code is called both from irq context and from > + * task context. There is a race where irq context advances > + * tsk->acct_timexpd to a value larger than time, creating > + * a negative value. In that case, the irq has already > + * updated the statistics. > + */ > + if (unlikely((signed long)dtime <= 0)) > + return; FWIW, I think you either need a barrier() before the if-statement or use READ_ONCE() when reading tsk->acct_timexpd above. Otherwise the compiler could (in theory at least) generate code which would translate to if (unlikely(time <= tsk->acct_timexpd)) in order to achieve the same result, no? Besides that cputime_t might be 64 bit in size, therefore you don't have much of a guarentee that reading tsk->acct_timexpd happens atomically on 32 bit architectures, so you _may_ end up with garbage, no?