Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4254408rwb; Sun, 7 Aug 2022 19:27:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR5KL9HZM0ZcuSJgdEngsQYRWEsvNITRlAm0q9562yDJAN2AKxMH0btkDDZTwTmiCxb1ts4c X-Received: by 2002:a17:907:6d91:b0:731:39eb:c00a with SMTP id sb17-20020a1709076d9100b0073139ebc00amr4939782ejc.6.1659925649051; Sun, 07 Aug 2022 19:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659925649; cv=none; d=google.com; s=arc-20160816; b=DUR17FohloQ+PTR/cfQa5a8ls+Aybx2f7IpXDZF57QSNe00yjp+aaLjMjB4b3TED5W ysAy4LCyLhvhA+VDh9ZnH1WQENBvb83odOGsJLg/F5iF4u4ZsH+KeDIYCgONEpe6w0Q2 KNOm4cod8AZEs4Pdce+NlTCv8Il5r9YI3fKwQTdSB+l4ZjCNFGxIYcI/6xBmzduixDXP uJCJLw1korLcy8BTGj0gcSo6geAy7cSKkBBJ1ipLTow1ww0m+W7ex9iEu2k/6QBW7upG HlnYzs/HllRK7H7f1gOvlc8c+6RfSPALA7upCrGchs82gyjpoxYiDY36piazvkiZf/yi 3L8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q2l/K0sOI99Xrlqos3Djka3b+UmOZbI5DkTTL2xJQQw=; b=pOzertSLmLc63EsVrH0lwN5k2AJwKEgg81u63KkopWKS3Den4AwHRmArm6oOs+rtTi 3+eYVECOopPjpetMMVyqzvr3Zrk2MlXjQlC+jEhYs63Cp+GOIUUt+dlrTyBFXlsf/xdO Lc5RpNQ+Up0yXPcbsF7JnjaO5RmIYvbY7fdOUglZNnGILtRMGkmjHOmFpmeLtJHzG3dh D3cO6i2hy1ejQSmy3KiMlwYzlECmqoBIrcU3mx0ekNzhMU4xGT8N8exNh8s8gEgJCJ7w Ib2JUFSvayRZVvF/sfdUkHcssw7epef0aPCObEBOVlRS0KMnF73bIm2npCu5QSqYCBCz Eidw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DnNhBepP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hz2-20020a1709072ce200b0073068883291si9637227ejc.836.2022.08.07.19.27.04; Sun, 07 Aug 2022 19:27:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DnNhBepP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242601AbiHHBiq (ORCPT + 99 others); Sun, 7 Aug 2022 21:38:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242374AbiHHBhh (ORCPT ); Sun, 7 Aug 2022 21:37:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB4A2E01B; Sun, 7 Aug 2022 18:33:48 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 826EA60DF4; Mon, 8 Aug 2022 01:33:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A011BC43470; Mon, 8 Aug 2022 01:33:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659922427; bh=qD8iqtAHW8h3e52RnPcjZiRtkyWciAJc3DN0Ssk+n1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DnNhBepP2Rh4UqV8MUCk4dToM1ovhFpCWxRWopgmKi0/+6CJ1+pxbi8Zaad1ck6sQ Hvn1E58lqiCqJ9aBwKBA0+mch6e/Hx/Wgw+CE3AEaW4zgPDLncRX3xiJTiYpTOohqk HWUumwBI+8cKpp+vGgaqJlx06uqMaKgemdgUoy+8u/0ImPL0G/gApr+htbxXViRjgP AHtHBtK9mAZfbWkUrN8X8sxttmqwbaSEAR3MfpBqvlTRHQO0xU/osa94rq0l2601Zl MJtpJvtcVyhBYhWoOiXnPj3vfuCFGthB07cjg0rCu9jnPuJeBoEyojbfE8v8XRtacT gabfDl+2xyFbA== 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.19 58/58] wait: Fix __wait_event_hrtimeout for RT/DL tasks Date: Sun, 7 Aug 2022 21:31:16 -0400 Message-Id: <20220808013118.313965-58-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220808013118.313965-1-sashal@kernel.org> References: <20220808013118.313965-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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