Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4062329ybp; Sun, 13 Oct 2019 21:16:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtzeaRvkP7lbL2yweCjxaC3Q20vDnsBut01xdrlkHuuyRsaQnSlXqw6F14502Z/uv+Pa15 X-Received: by 2002:a17:907:39b:: with SMTP id ss27mr26068213ejb.151.1571026572583; Sun, 13 Oct 2019 21:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571026572; cv=none; d=google.com; s=arc-20160816; b=fSWkJvXyPqwzclqnRA2O6ZnsS2MRY/cXKG68cVtr33HI3Y5fpkmPW3tAvbKEmEReCP m+uecunGziHqB53K91HHOT9zVJZukQkukfmBxCF1WkUZRDidXm724+fKylXt3YhMtaa+ 4OICS8byOOePhxHVUNiK38yMc1qDf4l/4IbhIjdrOj4ccV07M914HFmKe8EoE01GEct6 rM0mzzn0PGIguzGXrBMXOcw1Z+93oYDk9Jn3Qd8uKAGO+GVX2txsXW3iFfMIOsYu5pms 0AtyHWDPWzV86xieZWIEPg/rCxp47uMGxCwJf4E11SUaCuVI2H2LSiiffu+jgxtXiuUY 9whA== 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=L3BMUwPSJ/HjM9WytH1tdamwbktegXbEoq7zL16k21c=; b=OE/YAhx9rrWukdS2Ak+OMa1rqDLkKoZjdMweu0bo9g9mcOQjMiYKFDjmyvNzGgoEzl 2ZnVtwwKqmOlqn75HSbpoOdE0/wpilFq70uHJ/bnLnFI7C8bY6aiNY1byFrk3fC2pB4O fviu66l+MZSwNMsEywcM9+/FAA+wkg0Zt7yKPkh4TRkvoveLE0B2y/TqQdxtPs3gKB1J IUOItFD+bnIEcXZ1SkE5RK9qnCWdLXqcj4i3Skq8awVDNJ9wqKeZ6l5Dii537qOJaazr tySMxNKTa4v7lxeQvZwlItMjnRW5exNC5QE3W6n5wtJs8/nFewBWbVlL/ABe1oKglchw HUlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="gw4/KBjG"; 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 qp4si10158708ejb.171.2019.10.13.21.15.49; Sun, 13 Oct 2019 21:16:12 -0700 (PDT) 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="gw4/KBjG"; 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 S1725793AbfJNEKl (ORCPT + 99 others); Mon, 14 Oct 2019 00:10:41 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:33922 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725280AbfJNEKl (ORCPT ); Mon, 14 Oct 2019 00:10:41 -0400 Received: by mail-yw1-f65.google.com with SMTP id d192so5679817ywa.1 for ; Sun, 13 Oct 2019 21:10:40 -0700 (PDT) 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=L3BMUwPSJ/HjM9WytH1tdamwbktegXbEoq7zL16k21c=; b=gw4/KBjGGradjyOMFOw+MHrp/GOC/fsz3tUtYDaZ+Jwzr/gJKYaYDXyIIG4Q1jIoL8 rM499wQWo3ET3U84sJ0ZcwDRB/Zb4XsGMjaYSZx8eBFT07L6o1Aj+HljridfLhx78nXT Ey5a8SPaZ3fjm68WQ9K5FQDJrxuVS60zB+evIDXnFzOvMyT4ge3EZP+clO2HMehmM4M+ gCfg4xTFb8QwTeDrsEqZ0rFsjt0hJG+riG0Flp6doP1cKtsWoUUByGZoGI5MoA7GcyJU wxZRN3n6NuuMKnbwjLKb9oIp/DShbbIaTzbh+Auy7ZDV8IdJBfhtVyGqwySzgNMUrtMj plgQ== 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=L3BMUwPSJ/HjM9WytH1tdamwbktegXbEoq7zL16k21c=; b=O1j5UOld1/+4+W/ngC+4Czs89Np7RI9+Y171kqiH88S4NC5Sl3p9UYjRTkQ5teZUqv l3LYFBLBApnjGrurCb1tA1s5nTyAnWDz9QzfRdQ5A2YQxslYq8bT/1j92c7m5UjYz50g ozNc+4AcEijeqxDnUsUur94jHCY8qojFwE43jtFUHxPjrh5TYeyBznUlFktjmDBMD/6v VKfW/6Ng1XCfNowbXBHoo7+J8s0V60NCsKwxXZjsRnVZb6rcFMQDMNnDZccnGQcqaUuz Ij7NrFEFnzp5i/Th11pp02EZBD4IxGk3/HEEE4JCRAPPdKz/yspDrMUjuE8uf82fL+v8 73/A== X-Gm-Message-State: APjAAAXpUaUZEIZl8gjaa5xH098T1iLz7t/D4B6wM2h+wE+h5YUjIhob gmXTqJod904kUwjE7BFv+dIGdmFmdNMeSb9JSEbEkA== X-Received: by 2002:a81:748a:: with SMTP id p132mr11298492ywc.174.1571026239951; Sun, 13 Oct 2019 21:10:39 -0700 (PDT) MIME-Version: 1.0 References: <20191008173204.180879-1-edumazet@google.com> In-Reply-To: <20191008173204.180879-1-edumazet@google.com> From: Eric Dumazet Date: Sun, 13 Oct 2019 21:10:28 -0700 Message-ID: Subject: Re: [PATCH] hrtimer: annotate lockless access to timer->base To: Thomas Gleixner Cc: linux-kernel , Eric Dumazet , Julien Grall 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 Tue, Oct 8, 2019 at 10:32 AM Eric Dumazet wrote: > > Followup to commit dd2261ed45aa ("hrtimer: Protect lockless access > to timer->base") > > lock_hrtimer_base() fetches timer->base without lock exclusion. > > Compiler is allowed to read timer->base twice (even if considered dumb) > and we could end up trying to lock migration_base and > return &migration_base. > > base = timer->base; > if (likely(base != &migration_base)) { > > /* compiler reads timer->base again, and now (base == &migration_base) > > raw_spin_lock_irqsave(&base->cpu_base->lock, *flags); > if (likely(base == timer->base)) > return base; /* == &migration_base ! */ > > Similarly the write sides should use WRITE_ONCE() to avoid > store tearing. > > Signed-off-by: Eric Dumazet > Cc: Julien Grall > Cc: Thomas Gleixner > --- > kernel/time/hrtimer.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c > index 0d4dc241c0fb498036c91a571e65cb00f5d19ba6..65605530ee349c9682690c4fccb43aa9284d4287 100644 > --- a/kernel/time/hrtimer.c > +++ b/kernel/time/hrtimer.c > @@ -164,7 +164,7 @@ struct hrtimer_clock_base *lock_hrtimer_base(const struct hrtimer *timer, > struct hrtimer_clock_base *base; > > for (;;) { > - base = timer->base; > + base = READ_ONCE(timer->base); > if (likely(base != &migration_base)) { > raw_spin_lock_irqsave(&base->cpu_base->lock, *flags); > if (likely(base == timer->base)) > @@ -244,7 +244,7 @@ switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base, > return base; > > /* See the comment in lock_hrtimer_base() */ > - timer->base = &migration_base; > + WRITE_ONCE(timer->base, &migration_base); > raw_spin_unlock(&base->cpu_base->lock); > raw_spin_lock(&new_base->cpu_base->lock); > > @@ -253,10 +253,10 @@ switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base, > raw_spin_unlock(&new_base->cpu_base->lock); > raw_spin_lock(&base->cpu_base->lock); > new_cpu_base = this_cpu_base; > - timer->base = base; > + WRITE_ONCE(timer->base, base); > goto again; > } > - timer->base = new_base; > + WRITE_ONCE(timer->base, new_base); > } else { > if (new_cpu_base != this_cpu_base && > hrtimer_check_target(timer, new_base)) { > -- > 2.23.0.581.g78d2f28ef7-goog > Any news on this patch ? If more information is needed, let me know. Maybe I need to point to : commit b831275a3553c32091222ac619cfddd73a5553fb timers: Plug locking race vs. timer migration Thanks