Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4583278ybp; Mon, 14 Oct 2019 07:00:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+5DukCOVe1809ZjiKLEQjQiPl93o2YqYNNgdBAQp1fzgw012rMf10fvzKl7v9b8nRisNV X-Received: by 2002:a05:6402:64f:: with SMTP id u15mr27766099edx.231.1571061646841; Mon, 14 Oct 2019 07:00:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571061646; cv=none; d=google.com; s=arc-20160816; b=f/4VPsTo714sj1hw6Vzy+4o0rqkJNNq3KlM2vucsFgBmUrBZgK5+uans4VFWrHQweQ V3yxJrBkPU8wz8qMr4BxWi9tdwHabULZc0YsDlRD9FhhEW0AYOVgHb2snNWRCgJGxW9Y 2KIjDgM00GevAwESeihvNdrIjdA1NThv70B0C9ICsL+EKBkDdsWRYXtqtorh1uvp7aqc M78J3fIKlGmm+aV0NNg9Ha7Fp5a8Wx2NL7S0393PK5+VXi6r5yWxxJp/pvns8X1oKutd klmYMU9HbfErbfih73AwwtGJ1kb1rdYL5VxJ5d2ZZzcw3A94xusHupYgEGkAnfAhBM3i wQkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=Vbjs6H1FkyB6a/O+9pipfZIRC3UQniMvI/ZcfkNXGCU=; b=UKAUC+qF7/+vWgF91Q7QrXBNGHrI7BvooLY0LejDZFDXlENg76G8+bFlona5+GiFXq 6Xjr56sOEbSyPyDZ/QUCI32SHGDzzgCzp8qFq3h/pg5ZszZXDwBc+B1W/V6WDMDCXtV4 aMPrOKpiTCYlYjss1RgtX5PIAvmzDaSa0saGlzgj5A7hGgn5AeHHyA6phTKwhNn1nlgw 2LjXuo8U/VnMppOwQ5BbanbRCQUfNGvfumt4FGaF0Zwq1hMaIDV7JO4it/xWK63ysuj1 3RB3kK6Rj3g7jWQhl/rq0zo2eWzR1jpb7Biks/dINDNRWUGZ6C7hc5JKQyaB83hRTAjI 4qjg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9si10178333ejx.426.2019.10.14.07.00.21; Mon, 14 Oct 2019 07:00:46 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732408AbfJNN65 (ORCPT + 99 others); Mon, 14 Oct 2019 09:58:57 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38750 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730477AbfJNN64 (ORCPT ); Mon, 14 Oct 2019 09:58:56 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iK0s7-0000rw-9o; Mon, 14 Oct 2019 15:58:51 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id E10C21C010B; Mon, 14 Oct 2019 15:58:50 +0200 (CEST) Date: Mon, 14 Oct 2019 13:58:50 -0000 From: "tip-bot2 for Eric Dumazet" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/urgent] hrtimer: Annotate lockless access to timer->base Cc: Eric Dumazet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20191008173204.180879-1-edumazet@google.com> References: <20191008173204.180879-1-edumazet@google.com> MIME-Version: 1.0 Message-ID: <157106153080.9978.2971873792879229342.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the timers/urgent branch of tip: Commit-ID: ff229eee3d897f52bd001c841f2d3cce8853ecdc Gitweb: https://git.kernel.org/tip/ff229eee3d897f52bd001c841f2d3cce8853ecdc Author: Eric Dumazet AuthorDate: Tue, 08 Oct 2019 10:32:04 -07:00 Committer: Thomas Gleixner CommitterDate: Mon, 14 Oct 2019 15:51:49 +02:00 hrtimer: Annotate lockless access to timer->base 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) which 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 must use WRITE_ONCE() to avoid store tearing. Signed-off-by: Eric Dumazet Signed-off-by: Thomas Gleixner Link: https://lkml.kernel.org/r/20191008173204.180879-1-edumazet@google.com --- 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 0d4dc24..6560553 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 @@ again: 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 @@ again: 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)) {