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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95E26C19F2A for ; Mon, 8 Aug 2022 01:42:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242780AbiHHBmq (ORCPT ); Sun, 7 Aug 2022 21:42:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242820AbiHHBlG (ORCPT ); Sun, 7 Aug 2022 21:41:06 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 836DF12ACE; Sun, 7 Aug 2022 18:35:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 42335CE0F71; Mon, 8 Aug 2022 01:34:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 612D5C433C1; Mon, 8 Aug 2022 01:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659922497; bh=qD8iqtAHW8h3e52RnPcjZiRtkyWciAJc3DN0Ssk+n1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bhpK7aIIcgSLkPuxJBOIDhrAbY92RBL5sQ0Uf31GGCV20gDEDD6JFpmxIL/Oc+Gou SRQOgdkdZVBtVK6qnLPXQrpWpePRcgXu0K3HfkmWvM2JFG15ThGPcRBiHfUOqa63Az woZj2Zg5s1DcZFr67/LeEfPk0TTse0TsmMicm+iMJ0fDuJEwfwcaABGDFk3RJ3w8Nk VblMkkfTbt6xVW8F5Xam5r9rQInPL9GX/q4mpD77t1bpz2juSqfam7m4Ow0yHisCIm ReGNI2rusPdJAZtB09gbsA5rie4gDCCqbGa61MvQJHMfKa+ilY0kh0gAjtBm8A4e5E ORSI+fvShFkpQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Juri Lelli , Bruno Goncalves , Thomas Gleixner , Daniel Bristot de Oliveira , Valentin Schneider , Sasha Levin , mingo@redhat.com, peterz@infradead.org, vincent.guittot@linaro.org Subject: [PATCH AUTOSEL 5.18 21/53] wait: Fix __wait_event_hrtimeout for RT/DL tasks Date: Sun, 7 Aug 2022 21:33:16 -0400 Message-Id: <20220808013350.314757-21-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220808013350.314757-1-sashal@kernel.org> References: <20220808013350.314757-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juri Lelli [ Upstream commit cceeeb6a6d02e7b9a74ddd27a3225013b34174aa ] Changes to hrtimer mode (potentially made by __hrtimer_init_sleeper on PREEMPT_RT) are not visible to hrtimer_start_range_ns, thus not accounted for by hrtimer_start_expires call paths. In particular, __wait_event_hrtimeout suffers from this problem as we have, for example: fs/aio.c::read_events wait_event_interruptible_hrtimeout __wait_event_hrtimeout hrtimer_init_sleeper_on_stack <- this might "mode |= HRTIMER_MODE_HARD" on RT if task runs at RT/DL priority hrtimer_start_range_ns WARN_ON_ONCE(!(mode & HRTIMER_MODE_HARD) ^ !timer->is_hard) fires since the latter doesn't see the change of mode done by init_sleeper Fix it by making __wait_event_hrtimeout call hrtimer_sleeper_start_expires, which is aware of the special RT/DL case, instead of hrtimer_start_range_ns. Reported-by: Bruno Goncalves Signed-off-by: Juri Lelli Signed-off-by: Thomas Gleixner Reviewed-by: Daniel Bristot de Oliveira Reviewed-by: Valentin Schneider Link: https://lore.kernel.org/r/20220627095051.42470-1-juri.lelli@redhat.com Signed-off-by: Sasha Levin --- include/linux/wait.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/wait.h b/include/linux/wait.h index 851e07da2583..58cfbf81447c 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -544,10 +544,11 @@ do { \ \ hrtimer_init_sleeper_on_stack(&__t, CLOCK_MONOTONIC, \ HRTIMER_MODE_REL); \ - if ((timeout) != KTIME_MAX) \ - hrtimer_start_range_ns(&__t.timer, timeout, \ - current->timer_slack_ns, \ - HRTIMER_MODE_REL); \ + if ((timeout) != KTIME_MAX) { \ + hrtimer_set_expires_range_ns(&__t.timer, timeout, \ + current->timer_slack_ns); \ + hrtimer_sleeper_start_expires(&__t, HRTIMER_MODE_REL); \ + } \ \ __ret = ___wait_event(wq_head, condition, state, 0, 0, \ if (!__t.task) { \ -- 2.35.1