Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7304635rwr; Wed, 10 May 2023 06:42:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ68em25IXCN3HmwZClk+XW2Q+fnc2gyfaFoV3bxmec3e7Ph8eYaBmMfYURjHWVwQDmufWJ6 X-Received: by 2002:a05:6a00:a81:b0:62d:8376:3712 with SMTP id b1-20020a056a000a8100b0062d83763712mr25410581pfl.28.1683726175673; Wed, 10 May 2023 06:42:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683726175; cv=none; d=google.com; s=arc-20160816; b=SMV5xAn6NRAZAzipFt4Orf/X9sTzWI2IUhWTRmewp79/tRtaFpyW/8IfnJoyZM+JJZ Fy+A/YBoC7artKn7osjol5ROu/2u2hwgDEt1qRBYncn/WZKGhZ/P1JwXesG3ICxRwevo QNPJ76rykf8tv65W+pkV/umGT5WO+yuhbOSBnu9zabbUZSEtAKWxmjdorkVWSulBDpGv ljMMqFQoqViVUw9ce02rMcyvJUuknFewKvza6Q26Lz+mhbXm8+bYrbVCkvW15RTxQMMl x30C8UraLsiolzo+2dXsoP7y7sEZElS/4Jo6AULw1jD86qoP9KbVozoFWX9VlXXfHX7E lGSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=OtQRh15NAW2fKN6rYhRVoaA9NIjXRriGi0juhcP02Nk=; b=f/x2rVrjOQI8hQ7ZtCwKxBF3uduw43CkXUVU+1n04xa2tqJZXIbTx6AqaypESVq++m 8QuZ1yufxs3PSsJBUrIqUyYQGCShdq06hagxkZ8JM/IT5c2+io6D4yBIc5eoBsBk+brd 9dNMEl5Pw1Z65yV+XIhbuowt32SeH/NfgjpNtD7gM9LYbLYntOYWRu1Mvy6Uqc7vInsR 7ODb8PHZs2FwLGt2B1ifVSrdL0JYjq7u8FFV6h56WV6rjJK9mjGDkHTot0QPBUtFLyV0 tIik5w0yKc2LrqoSpqCS0KBEOKrHNljcQuilE4tQU01i+9Ih428zhvq/iFPYhES0p+dZ UY6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm3 header.b=Fei60N3N; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=az8ZNx2l; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g9-20020a63fa49000000b0051bb415165dsi4080046pgk.194.2023.05.10.06.42.39; Wed, 10 May 2023 06:42:55 -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=@arndb.de header.s=fm3 header.b=Fei60N3N; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=az8ZNx2l; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237155AbjEJNgA (ORCPT + 99 others); Wed, 10 May 2023 09:36:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235752AbjEJNf7 (ORCPT ); Wed, 10 May 2023 09:35:59 -0400 Received: from new1-smtp.messagingengine.com (new1-smtp.messagingengine.com [66.111.4.221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DB0298; Wed, 10 May 2023 06:35:58 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailnew.nyi.internal (Postfix) with ESMTP id A1D425803F9; Wed, 10 May 2023 09:35:56 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Wed, 10 May 2023 09:35:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1683725756; x=1683732956; bh=Ot QRh15NAW2fKN6rYhRVoaA9NIjXRriGi0juhcP02Nk=; b=Fei60N3N1IRxNekLDz LlNakjV6mxlgcp+mcjsPCqDoGkhdYbgZAhm4AALdN30Rod8nRMpHC0cNU5jXYuyK UG8hF4Rt60A2eKOivls83Axn1EallgBdvgo48zEtswWI2Qnao/3GLCf9eV5U+5Ok MSYBCjVB0OAItrUDOt3jTvymHnf9qu40cf1TvL7VQgQSpYqD3eaiovc6KdjxPFx/ ZbcuBOKpDa547E+GgpylHyouViTgpOUCBkBNBVyeqgfu+awEM+UV8riMIEnypIcX gLY9fA2wp3HIDkXP3lLk8/XO+L1kwXadHUjrNyRH4uTwUNxibzEmKTQtT8kBx8lM 8vjw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1683725756; x=1683732956; bh=OtQRh15NAW2fK N6rYhRVoaA9NIjXRriGi0juhcP02Nk=; b=az8ZNx2lXpcCEt9HJiIiSMtLujspS zL+7doBWdbPbYzFHretQkcpDdjKlIVnLafTQEuEVeKIRK3tVvgsbZj14J7LbGSao Shwfx5FhCtTgoSxt+Ge4ZcFA4cwWGKfzIS2/N1CBSmIuLwrO87hlSOYxecVaE5un NUdNaWMwYbqFQvO2vZ5oIxTe4g24VJly6SDNDJYRmW8fPviILc8YapMJcDl0iiw3 ME1oq4u02A3x9OCr+MXxDMhGrl4WwibcMq3qP5+aJv4Yi135vec2p9873HFJlXrC L5jHY4//HIF18PkL8CS+nPVtg+8ec31Kym8IP9/JI1QW6p5mC8Ee6svzQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeegiedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedftehr nhguuceuvghrghhmrghnnhdfuceorghrnhgusegrrhhnuggsrdguvgeqnecuggftrfgrth htvghrnhepffehueegteeihfegtefhjefgtdeugfegjeelheejueethfefgeeghfektdek teffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hrnhgusegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 254FCB60086; Wed, 10 May 2023 09:35:55 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-415-gf2b17fe6c3-fm-20230503.001-gf2b17fe6 Mime-Version: 1.0 Message-Id: <02ce0541-08cf-4e14-a9b1-c53efea85178@app.fastmail.com> In-Reply-To: <8db63020d18fc22e137e4a8f0aa15e6b9949a6f6.1683722688.git.geert+renesas@glider.be> References: <8db63020d18fc22e137e4a8f0aa15e6b9949a6f6.1683722688.git.geert+renesas@glider.be> Date: Wed, 10 May 2023 15:35:32 +0200 From: "Arnd Bergmann" To: "Geert Uytterhoeven" , "Stephen Boyd" , "Tomasz Figa" , "Sylwester Nawrocki" , "Will Deacon" , "Wolfram Sang" , "Dejin Zheng" , "Kai-Heng Feng" , "Nicholas Piggin" , "Heiko Carstens" , "Peter Zijlstra" , "Russell King" , "John Stultz" , "Thomas Gleixner" , "Tony Lindgren" , "Krzysztof Kozlowski" , "Tero Kristo" , "Ulf Hansson" , "Rafael J. Wysocki" , "Vincent Guittot" Cc: linux-arm-kernel@lists.infradead.org, Linux-Renesas , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] iopoll: Do not use timekeeping in read_poll_timeout_atomic() Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Wed, May 10, 2023, at 15:23, Geert Uytterhoeven wrote: > read_poll_timeout_atomic() uses ktime_get() to implement the timeout > feature, just like its non-atomic counterpart. However, there are > several issues with this, due to its use in atomic contexts: > > 1. When called in the s2ram path (as typically done by clock or PM > domain drivers), timekeeping may be suspended, triggering the > WARN_ON(timekeeping_suspended) in ktime_get(): > > WARNING: CPU: 0 PID: 654 at kernel/time/timekeeping.c:843 ktime_get+0x28/0x78 > > Calling ktime_get_mono_fast_ns() instead of ktime_get() would get > rid of that warning. However, that would break timeout handling, > as (at least on systems with an ARM architectured timer), the time > returned by ktime_get_mono_fast_ns() does not advance while > timekeeping is suspended. > Interestingly, (on the same ARM systems) the time returned by > ktime_get() does advance while timekeeping is suspended, despite > the warning. > > 2. Depending on the actual clock source, and especially before a > high-resolution clocksource (e.g. the ARM architectured timer) > becomes available, time may not advance in atomic contexts, thus > breaking timeout handling. > > Fix this by abandoning the idea that one can rely on timekeeping to > implement timeout handling in all atomic contexts, and switch from a > global time-based to a locally-estimated timeout handling. In most > (all?) cases the timeout condition is exceptional and an error > condition, hence any additional delays due to underestimating wall clock > time are irrelevant. > > Signed-off-by: Geert Uytterhoeven This looks reasonable to me, Acked-by: Arnd Bergmann I assume you sent this because you ran into the bug on a particular driver. It might help to be more specific about how this can be reproduced. > --- > Alternatively, one could use a mixed approach (use both > ktime_get_mono_fast_ns() and a local (under)estimate, and timeout on the > earliest occasion), but I think that would complicate things without > much gain. Agreed. Arnd