Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2873857rwb; Mon, 15 Aug 2022 13:04:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR5SHa1DZsO8q609p7pDen7iCsYwHnGg/1PKThWKDhtyo2Cxo03d+an6u8Op7HlVKJkUNcS0 X-Received: by 2002:a17:90b:1181:b0:1fa:8455:35e6 with SMTP id gk1-20020a17090b118100b001fa845535e6mr4812385pjb.28.1660593870353; Mon, 15 Aug 2022 13:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660593870; cv=none; d=google.com; s=arc-20160816; b=RW8HBaTfINo0UPF34/WHw5stAq7inYfs4gK1Gf8IiSLHi5wYUqnsUHfW6ez3afP9sO kTMJ2R+th9AcazrXLr005g5NmDwSvWVmCj/2Kw4+XGQRt/w/wd8HTS7B29Tu+tPJIAFh hY0Hu8JZt8T/walM7t8cmTzPRH+gOzQZJaHWGhUA6yQzWvOEDF97UCntotw3Ikr/lSrA kCVVQgkmempyqykuNAPsXJOKUtuMeVjP7AvN7KCkDIEEF2jsDEG+IVVrBNs1Bd40Whk4 YwGxeKDHJWp/4mvuHaVh4IVZRsE5768iwLEi1hMJLrNryo8QJQ4gGoMp2gARRhe4bJfF fpqw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k+TdAerC2u/OtB2QLaa3/yVzYCpQwQaJvW3RJJsdydo=; b=aaupHaE99jsBLxDi9YNdxsmYJYQXynOsORrHqfTxZOq0+Slcs9cpj++Fu5wTqe9t3D MawXqEj6XMs580YC+28JOTKwlhRa0CNlxrmGwIqE5FLbxJ2yJh9vgsiwdUlmQVvCsVvq z0PmWULwoOmclmI/9vfP+IdcA+JlSn+ckQivDqVv87LnssJHTpvMjpI/fnusnhFbVeFg PUhHCpdTpEm2I+wjK6gMguZUOW03Vo8rkolHhvRby/7PpC9hCM70iBlgHIbR/71qjYS0 e0qWFn+lCYI/gteygB4UtAXfyevn/HkK76AnAQOyREUGxPM6VBT9nRl5EJyEXCmIV2QB VGVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Nv/1slKa"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p8-20020a170902e74800b0016d5d09a426si11151636plf.567.2022.08.15.13.04.18; Mon, 15 Aug 2022 13:04:30 -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=@linuxfoundation.org header.s=korg header.b="Nv/1slKa"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243169AbiHOScB (ORCPT + 99 others); Mon, 15 Aug 2022 14:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243431AbiHOSbF (ORCPT ); Mon, 15 Aug 2022 14:31:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DFA932B94; Mon, 15 Aug 2022 11:21:04 -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 ams.source.kernel.org (Postfix) with ESMTPS id BB1D4B81071; Mon, 15 Aug 2022 18:21:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28F9EC433C1; Mon, 15 Aug 2022 18:20:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660587660; bh=fIyATlflZQYS902OJM0Ronnev54d2XGnLkNgc18G4cI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nv/1slKaPFNxEe5pe+6ykg1uEEKY47E0fJAn/iXMsjLbqKGRJyTkDzT04aT5sxkEF ARRc8taT6XTFNu+JiRG3sRKVtPTpHCMLxOtJmnBiLn3/6rJ0Ey2exoobwIirtej3WZ hqxeer+dV4uZRbpoLd5MCAcdnFrnX4K+5bJvDylY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bruno Goncalves , Juri Lelli , Thomas Gleixner , Daniel Bristot de Oliveira , Valentin Schneider , Sasha Levin Subject: [PATCH 5.15 123/779] wait: Fix __wait_event_hrtimeout for RT/DL tasks Date: Mon, 15 Aug 2022 19:56:07 +0200 Message-Id: <20220815180342.557600521@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 d22cf2985b8f..21044562aab7 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