From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54634CA9EB9 for ; Sat, 26 Oct 2019 13:29:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2AE74206DD for ; Sat, 26 Oct 2019 13:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572096559; bh=ixFLvos1aJl7DrgTalODnZ5vGMYZq/u5taDo7azZAEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=MmbnuZoJOvjG3I4VXHXyqO2Dgk8dMmkFA7Ve6l5Kad+u3VSapKsgvykbxFuAUD1Lr QjdsxqatXh6SNItbgqKiLnay9R8AZdBoOVZv05GxtmAunZG08hB98fWZTesk4MWT8+ 3zd+cG0g0XksOiVguGmQaFf9pcX1pgVjndKyJCjw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729298AbfJZN3R (ORCPT ); Sat, 26 Oct 2019 09:29:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:42262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728640AbfJZNUb (ORCPT ); Sat, 26 Oct 2019 09:20:31 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 69B332070B; Sat, 26 Oct 2019 13:20:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572096031; bh=ixFLvos1aJl7DrgTalODnZ5vGMYZq/u5taDo7azZAEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zvIxMJDU27cb2tLgy7jjV20LlymYphgTqwnrfwRznE27VyH+UoauIYu0gkBhNoLzy XTPK9U1OtF6yM+12ZQmCz5xkRdXxrIWLyQkzlAPPNzrgU2eZKJNr//l9khJgYhJrOY RqKq73Xkc6QwjVgyUrFxyKt5Sdrhqdspra0w/j8g= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , Thomas Gleixner , Sasha Levin Subject: [PATCH AUTOSEL 4.19 41/59] hrtimer: Annotate lockless access to timer->base Date: Sat, 26 Oct 2019 09:18:52 -0400 Message-Id: <20191026131910.3435-41-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191026131910.3435-1-sashal@kernel.org> References: <20191026131910.3435-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit ff229eee3d897f52bd001c841f2d3cce8853ecdc ] 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 Signed-off-by: Sasha Levin --- 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 e1a549c9e3991..64d20241cf89f 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -169,7 +169,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)) @@ -249,7 +249,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); @@ -258,10 +258,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.20.1