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=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 192F7C3A59E for ; Wed, 21 Aug 2019 09:24:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC10422D6D for ; Wed, 21 Aug 2019 09:24:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727185AbfHUJYS (ORCPT ); Wed, 21 Aug 2019 05:24:18 -0400 Received: from foss.arm.com ([217.140.110.172]:55050 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727078AbfHUJYQ (ORCPT ); Wed, 21 Aug 2019 05:24:16 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E2474360; Wed, 21 Aug 2019 02:24:15 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CD8D63F706; Wed, 21 Aug 2019 02:24:14 -0700 (PDT) From: Julien Grall To: linux-rt-users@vger.kernel.org Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, maz@kernel.org, bigeasy@linutronix.de, rostedt@goodmis.org, Julien Grall Subject: [RT PATCH 1/3] hrtimer: Use READ_ONCE to access timer->base in hrimer_grab_expiry_lock() Date: Wed, 21 Aug 2019 10:24:07 +0100 Message-Id: <20190821092409.13225-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190821092409.13225-1-julien.grall@arm.com> References: <20190821092409.13225-1-julien.grall@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The update to timer->base is protected by the base->cpu_base->lock(). However, hrtimer_grab_expirty_lock() does not access it with the lock. So it would theorically be possible to have timer->base changed under our feet. We need to prevent the compiler to refetch timer->base so the check and the access is performed on the same base. Other access of timer->base are either done with a lock or protected with READ_ONCE(). So use READ_ONCE() in hrtimer_grab_expirty_lock(). Signed-off-by: Julien Grall --- This is rather theoritical so far as I don't have a reproducer for this. --- kernel/time/hrtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 7d7db8802131..b869e816e96a 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -932,7 +932,7 @@ EXPORT_SYMBOL_GPL(hrtimer_forward); void hrtimer_grab_expiry_lock(const struct hrtimer *timer) { - struct hrtimer_clock_base *base = timer->base; + struct hrtimer_clock_base *base = READ_ONCE(timer->base); if (base && base->cpu_base) { spin_lock(&base->cpu_base->softirq_expiry_lock); -- 2.11.0