Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp477326ybl; Wed, 11 Dec 2019 22:58:19 -0800 (PST) X-Google-Smtp-Source: APXvYqyJVb7v8MlGpPQCpxN0JdjGT5f58HlMn6cv91agPo0A2psZPxHugQ23I20wJZo7vLxBtWaF X-Received: by 2002:a05:6830:1691:: with SMTP id k17mr6689908otr.282.1576133898932; Wed, 11 Dec 2019 22:58:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576133898; cv=none; d=google.com; s=arc-20160816; b=0d3xV/pJT0xtv9JtD5XikKqMzqFN3UVz0nvPq/2HFTEiCKGOY/LK2PFTya0z4mhnvn 73f4cOZ58ugnKgGq7uZGBFHyOz6BXsWp5yPX3X9eJ7jj4NyXhwLW4nHU9cx87CvA33/8 KLN3Ob6lvXIrjwmWHC8f1ohf3g7JerroKiTKwhU+gsG7HGy1/KurE3Y1V6gQq56wWEs0 TZA/KGi8NV5+REpyKZ9q420daTOjAdIYlZ0IsxzTcGotlQsrGXNcIkjNrfXQ+rpswasZ IvClyg7wiZmQ4TD7lQDK4y56eFk1LsOvDdTQ6eLmsEcJ7tnL5BJYFI57hcLL86IFobIc 3HzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Ax2ZUv3ImSrASpu/ZSBPTJ2sk/mbghRo8ZpVw2jpKxI=; b=uCNMyyJxASN0J1/bpYMdz60dLFK13yZcgqIv0kcHY+5uWA3KZHDZ/jLWD9jdbnw8f3 BBJ+rv3Awu1tGaOvk6/vUwslJ52sAXzpPAYlmXqcHsgOoba3cBe6dpjC8r/bYVsZy0PC WqbRIq8hB4i8QbyNwrMJ7WjEy5eNPOAr2S4g6Lu9wWFzNoLuTfq776SpMlUaiHINdyn+ uBmKjmJAjYQgC3eAy7dMOQD+yIoSmerrEc+Q8Xj9N9Q5gmyGq55Zvckje0lhNcKc/71e 1EZCXN27tzI9ExIIH1T9ytActbQurodVLsU3Y7Dxp3quwT0MkcmCibNXtU4jrobYHg4O 3jJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KbiayEhi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u16si2552353otq.92.2019.12.11.22.58.05; Wed, 11 Dec 2019 22:58:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KbiayEhi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728035AbfLLG5i (ORCPT + 99 others); Thu, 12 Dec 2019 01:57:38 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:36134 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbfLLG5h (ORCPT ); Thu, 12 Dec 2019 01:57:37 -0500 Received: by mail-yb1-f193.google.com with SMTP id i72so94088ybg.3 for ; Wed, 11 Dec 2019 22:57:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ax2ZUv3ImSrASpu/ZSBPTJ2sk/mbghRo8ZpVw2jpKxI=; b=KbiayEhiIFcWZKYx7nfN2WA2VlPQM+BYTCvl5HhXzsozSBzvhVwP0560df0XhVcSDv 2gXROBRO427WyQExSULqmEvjMUrQhWfVjO2ZBsyjj46QMB/ZFtB3ORKq9mzhuJdvhilk 6QGw2wqD9fibCvKKTdTR4+Ra8LnoZcU9YUFIA3Y80Y3WRxDIgKfN5dOV+hNGb3d8Vg1Y yqmf06PR17LyOMfXs08XmqAQgK9Yra8YJn3BmRbvFxhZZ6HGLmeRSZKvtQO83EdmHMEJ nERx9nlFoz5vyPrtL6CUROUucOm3S2SyOWveOILM9u6SiWJF/TwugJRxNln21zNcKcfN 0Alw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ax2ZUv3ImSrASpu/ZSBPTJ2sk/mbghRo8ZpVw2jpKxI=; b=O1CY0DQgnD6OtDXaDEFrqeDU/2YNmrWDsqfS8YkaJUJih3wv/8SMjb/6SJCAc0V7/4 4Gw7/FiP6loj4DtD7+eJj2HLdO6He+gsqFyfeblo1WAfWtBq8+aJPZGH+bxjqk+KhUzE onfBwVJ1YiPOjW04wVRqAAEusn33ehOFzmB8nr4x5oEFNQ5zX5M9cvAz+xwYl/siCSkJ 5f5MMAvGFZwgfflh5aPf+I1fPQLb59awgMGYKeHmSD7YTiC87mtzRqG8l1poswNW4sal 8kEKUGlYdMDsfv2qN66RU2OAy5E5DDn99gt0yX2nI8HiYG0Z8NszIEFA1pgaSl6ozWF2 1tmw== X-Gm-Message-State: APjAAAXD741UxTi+/0gBz0CZ7kAm4h9xSVy9EsCEZSuDxfi0VS6/euLF AzvNU0qcD2uB3AQmNjKLMvW9P7wlGtCtYKDCt2Fm6A== X-Received: by 2002:a25:60c6:: with SMTP id u189mr3154886ybb.173.1576133855768; Wed, 11 Dec 2019 22:57:35 -0800 (PST) MIME-Version: 1.0 References: <20191212160622.021517d3@canb.auug.org.au> <20191212060200.GW2889@paulmck-ThinkPad-P72> In-Reply-To: From: Eric Dumazet Date: Wed, 11 Dec 2019 22:57:24 -0800 Message-ID: Subject: Re: linux-next: build warning after merge of the rcu tree To: "Paul E. McKenney" Cc: Stephen Rothwell , Linux Next Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 11, 2019 at 10:38 PM Eric Dumazet wrote: > > On Wed, Dec 11, 2019 at 10:02 PM Paul E. McKenney wrote: > > > > On Thu, Dec 12, 2019 at 04:06:22PM +1100, Stephen Rothwell wrote: > > > Hi all, > > > > > > After merging the rcu (I think) tree, today's linux-next build (x86_64 > > > allnoconfig) produced this warning: > > > > > > kernel/time/timer.c: In function 'schedule_timeout': > > > kernel/time/timer.c:969:20: warning: 'timer.expires' may be used uninitialized in this function [-Wmaybe-uninitialized] > > > 969 | long diff = timer->expires - expires; > > > | ~~~~~^~~~~~~~~ > > > > > > Introduced by (bisected to) commit > > > > > > c4127fce1d02 ("timer: Use hlist_unhashed_lockless() in timer_pending()") > > > > > > x86_64-linux-gnu-gcc (Debian 9.2.1-21) 9.2.1 20191130 > > > > Well, if the timer is pending, then ->expires has to have been > > initialized, but off where the compiler cannot see it, such as during a > > previous call to __mod_timer(). And the change may have made it harder > > for the compiler to see all of these relationships, but... > > > > I don't see this warning with gcc version 7.4.0. Just out of curiosity, > > what are you running, Stephen? > > > > Eric, any thoughts for properly educating the compiler on this one? > > Ah... the READ_ONCE() apparently turns off the compiler ability to > infer that this branch should not be taken. > > Since __mod_timer() is inlined we could perhaps add a new option > > diff --git a/kernel/time/timer.c b/kernel/time/timer.c > index 4820823515e9..8bbce552568b 100644 > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -944,6 +944,7 @@ static struct timer_base *lock_timer_base(struct > timer_list *timer, > > #define MOD_TIMER_PENDING_ONLY 0x01 > #define MOD_TIMER_REDUCE 0x02 > +#define MOD_TIMER_NOTPENDING 0x04 > > static inline int > __mod_timer(struct timer_list *timer, unsigned long expires, unsigned > int options) > @@ -960,7 +961,7 @@ __mod_timer(struct timer_list *timer, unsigned > long expires, unsigned int option > * the timer is re-modified to have the same timeout or ends up in the > * same array bucket then just return: > */ > - if (timer_pending(timer)) { > + if (!(options & MOD_TIMER_NOTPENDING) && timer_pending(timer)) { > /* > * The downside of this optimization is that it can result in > * larger granularity than you would get from adding a new > @@ -1891,7 +1892,7 @@ signed long __sched schedule_timeout(signed long timeout) > > timer.task = current; > timer_setup_on_stack(&timer.timer, process_timeout, 0); > - __mod_timer(&timer.timer, expire, 0); > + __mod_timer(&timer.timer, expire, MOD_TIMER_NOTPENDING); > schedule(); > del_singleshot_timer_sync(&timer.timer); Also add_timer() can benefit from the same hint, since it seems inlined as well. (untested patch) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 4820823515e9..568564ae3597 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -944,6 +944,7 @@ static struct timer_base *lock_timer_base(struct timer_list *timer, #define MOD_TIMER_PENDING_ONLY 0x01 #define MOD_TIMER_REDUCE 0x02 +#define MOD_TIMER_NOTPENDING 0x04 static inline int __mod_timer(struct timer_list *timer, unsigned long expires, unsigned int options) @@ -960,7 +961,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires, unsigned int option * the timer is re-modified to have the same timeout or ends up in the * same array bucket then just return: */ - if (timer_pending(timer)) { + if (!(options & MOD_TIMER_NOTPENDING) && timer_pending(timer)) { /* * The downside of this optimization is that it can result in * larger granularity than you would get from adding a new @@ -1133,7 +1134,7 @@ EXPORT_SYMBOL(timer_reduce); void add_timer(struct timer_list *timer) { BUG_ON(timer_pending(timer)); - mod_timer(timer, timer->expires); + __mod_timer(timer, timer->expires, MOD_TIMER_NOTPENDING); } EXPORT_SYMBOL(add_timer); @@ -1891,7 +1892,7 @@ signed long __sched schedule_timeout(signed long timeout) timer.task = current; timer_setup_on_stack(&timer.timer, process_timeout, 0); - __mod_timer(&timer.timer, expire, 0); + __mod_timer(&timer.timer, expire, MOD_TIMER_NOTPENDING); schedule(); del_singleshot_timer_sync(&timer.timer);