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,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 CD36ACA9EB9 for ; Sat, 26 Oct 2019 13:26:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0E5E206DD for ; Sat, 26 Oct 2019 13:26:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572096406; bh=S1JkXx2xG+K1cof7ctG8SEgGR9X0WxecjSeAqIOsE38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=j+q8QdJWy1K5YcTvnvfMZO8LY8qtoibfQmAS8wJvL1MXJLVMcgbPLZ52ca2yMYJ2E sX6JPKLx2o0D5WK7lV328kcUT4eCDJV0SBMxS8EZa4Ey0Qj1D2E04NX/+Ehsy3sJzc GXS3PrEt7ZEkly2SPoZ1IcieBRx4Po22yT3RrRAs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728261AbfJZN0p (ORCPT ); Sat, 26 Oct 2019 09:26:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:43628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727906AbfJZNVu (ORCPT ); Sat, 26 Oct 2019 09:21:50 -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 40FE820867; Sat, 26 Oct 2019 13:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572096109; bh=S1JkXx2xG+K1cof7ctG8SEgGR9X0WxecjSeAqIOsE38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qagUN+j37J34p+W+F6mb1n+hzZ+92991EylQ74JyrfhiaDft4Kk10OPR4vedJo3nq Mpux9i5fSy9mKPIL3loCsV41F7Q7qdFz9wiapnLX4kgDVnmYQerwEriLFLYjlUUk0q tiTEepYDPwKwOHoEghYGdfixMp77Vn3ZLDxX0el0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , Thomas Gleixner , Sasha Levin Subject: [PATCH AUTOSEL 4.14 21/33] hrtimer: Annotate lockless access to timer->base Date: Sat, 26 Oct 2019 09:20:58 -0400 Message-Id: <20191026132110.4026-21-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191026132110.4026-1-sashal@kernel.org> References: <20191026132110.4026-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 d00e85ac10d66..e7ef0d830c093 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -143,7 +143,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)) @@ -235,7 +235,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); @@ -244,10 +244,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