Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7314931rwr; Wed, 10 May 2023 06:50:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5u2suqKhQgdxjdJpDFHT5/yqcSxEiiLb4LLHBAwKVS+ibZWj4TjUvEAsJD5IgVWltv3LV4 X-Received: by 2002:a05:6a00:a14:b0:639:a518:3842 with SMTP id p20-20020a056a000a1400b00639a5183842mr24329658pfh.7.1683726658129; Wed, 10 May 2023 06:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683726658; cv=none; d=google.com; s=arc-20160816; b=TnPSJIvlwHnU5H0+nNs+fY0CHMmIARDij+DuNsErqrsxNW1XiC17/WCGlSe1bXcNF/ DWvPqXs0edKoVcDUcWZTB18RlzemdMGVxjAjr7tk7HCNasSMuzhesMphjhmA63lT1DBZ h7sHWSKAGo6hCooHJhqfjHPiOkedqLS2RrlXiA5pxqLDIq9ypVpeaqCk0HVlyMh3J2GO /KI6066uFHX9iLlM/LZAORChx58hy462caHMhWedu+KIP82NdW2ooGy+7kYhcZSStOEH rqxlGgTVm+Flqg8NhXeC/PjZLHJlt+6huPSaqfoIhDBhC1cRgrJ2WuV/4QSBYMb0sLkh t+qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=zS91rCHRMzVU4sLNkQgWQvkjcY7yseXtGTbLdKQkt+4=; b=ffooNStVWQFeBgLm4JWSpC5oQgBvq+DqBTyfp6SQn2qmf73JyXpzZxFI9nkric4DzN GG4gTBZMVtuscc1UafcHHTkccU0dct7z3ndWX4c9NVUHsA5UoraVOFsY+9IAd+IVQ3V6 1Do+F9Ebwvtzf8nqQTr/ghZEC2HYtOiWrH/6pEho6ereW63tZE67bCiTt2GcNiJX/BP0 nFbHr5mXaKspyALd/jtCjd1nTPICKULucWGPQnVsAKMnPK+3TGWf2WjnI3Utx0GZ5eBG CUKZ8/t11ma9uQSMVPbm4RxMBxM3+b+JOWE/tghYRi/c6d5XuteeYa9WXReyKHPEYd7q /GUg== ARC-Authentication-Results: i=1; mx.google.com; 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 d206-20020a621dd7000000b0063b7c4435c0si5108813pfd.54.2023.05.10.06.50.45; Wed, 10 May 2023 06:50:58 -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; 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 S237257AbjEJNr5 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 10 May 2023 09:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237264AbjEJNrx (ORCPT ); Wed, 10 May 2023 09:47:53 -0400 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 570BE449C; Wed, 10 May 2023 06:47:24 -0700 (PDT) Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-55a8019379fso67188277b3.0; Wed, 10 May 2023 06:47:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683726430; x=1686318430; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GsvbCwwIGv4dAIbBM02PnYE01RolXqtsmvWU0E9eNRk=; b=jmB2YYUS0hRXfIEBYkN3my+TfTVmkiqj07hlSZZXMxEKYAZRJRzOv13c5MmLUH2UwR w7fQ9w8GgCOVry4Pjgfu8/IXfN/jWF5Pyq/Opwue8R3UH/xf7HtyQ2CVXFy7kOBBJW46 vNKhGgqSfZUvqLDtKf8THVIeA2xIevsY5IhU/NTCwiAbGc1ViSckFf8HDwaJrmum+uJW XF23I/pRlgsVc3OWPvvK+zy3p//97MgZUK5IiB0PaVkfyQ2JA6Vo2lX6AuED5iAo96u6 sD9lYnC8F05rfUpsnOMPGThZruyTCbUpS0u2mhIcqAft7JJ+7Y5yNGq5kR+S88yuVqhp ByzQ== X-Gm-Message-State: AC+VfDxp+l0ONyI05s3Z3clF8/rN+yHe5IVQuYD+VwDKZLpnkrtRhfla oUj0egyfG8hzx2OpyDEKdy2j8PnHsvJ59Q== X-Received: by 2002:a25:54b:0:b0:b99:f279:10dc with SMTP id 72-20020a25054b000000b00b99f27910dcmr17719598ybf.28.1683726430167; Wed, 10 May 2023 06:47:10 -0700 (PDT) Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com. [209.85.219.182]) by smtp.gmail.com with ESMTPSA id 130-20020a250888000000b00ba1a0346360sm3743231ybi.13.2023.05.10.06.47.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 May 2023 06:47:09 -0700 (PDT) Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-b9a6d9dcbebso6359671276.2; Wed, 10 May 2023 06:47:08 -0700 (PDT) X-Received: by 2002:a25:c74c:0:b0:b95:9b76:34a5 with SMTP id w73-20020a25c74c000000b00b959b7634a5mr16457612ybe.64.1683726428473; Wed, 10 May 2023 06:47:08 -0700 (PDT) MIME-Version: 1.0 References: <8db63020d18fc22e137e4a8f0aa15e6b9949a6f6.1683722688.git.geert+renesas@glider.be> <02ce0541-08cf-4e14-a9b1-c53efea85178@app.fastmail.com> In-Reply-To: <02ce0541-08cf-4e14-a9b1-c53efea85178@app.fastmail.com> From: Geert Uytterhoeven Date: Wed, 10 May 2023 15:46:56 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 2/2] iopoll: Do not use timekeeping in read_poll_timeout_atomic() To: Arnd Bergmann Cc: 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 , linux-arm-kernel@lists.infradead.org, Linux-Renesas , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hi Arnd, On Wed, May 10, 2023 at 3:36 PM Arnd Bergmann wrote: > 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 Thanks! > 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. I first ran into it when converting open-coded loops to read*_poll_timeout_atomic(). Later, I also saw the issue with the existing read*_poll_timeout_atomic() calls in the R-Car SYSC driver, but only after applying additional patches from the BSP that impact the moment PM Domains are powered during s2ram. The various pointers to existing mitigations in the cover letter should give you other suggestions for how to reproduce... Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds