Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp985424rwb; Thu, 8 Dec 2022 05:34:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf72UK7nDOCQ9h5FC+TFfqT2uSIdhJST7mhjjvICWwjHqcCJJJcnDK8LjvlVuggzCCcVeBM1 X-Received: by 2002:a17:90a:b382:b0:213:1fcb:3ce1 with SMTP id e2-20020a17090ab38200b002131fcb3ce1mr100788012pjr.58.1670506448189; Thu, 08 Dec 2022 05:34:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670506448; cv=none; d=google.com; s=arc-20160816; b=pXsB7RLmXgJXbFVWgjHtcUOPmfg/cg5ti1helkVP4ZZEgsNX380YTREgv+JowvlIQB gwmabykMbqEEzcD0CVV7AEVZM2TWxxsXijPvRAWE/7eOMHGfQOGpOF7hpohjk2dVqpS3 h6uyIKbMN0d9VTfQGhY9s3BHGXCmxKLC7ZhPIT4067hAXtmrfO/P6083Q3IVBZ7Aiciz 8H6DBWTG1dhcRDHT56IvPZip1YMDqj+yngHm3q6p5kftaV9UC1h9aV38OtxgJIEgzdUw AEXtlFYVQ3+BqqovEEXidRFdOVxVNRsiDNG8hkTIAt+PgmaTM5Ojm3W+w9G3qsSS5uZN A8Ng== 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 :message-id:date:subject:cc:to:from; bh=ftIPt85qIlPMqE/Km7nF62y7P3zrCCHBT4PE20o1TvM=; b=QtK4bnQYLMIlMRba1SsnVRIT4gZPxCRHjiVFjp/biLkXaDM7zU7t6yl8RuF8eL9cfl laMWvoUcX72qngwkiufdjAXTsyAnOQB8lvicUPa0TfWzM+duf0uHpMhKMPdbkOq08hZP v0kYz65yHfi52geYGPHUnCE90tmSianWl3LDEdxqtE+8y01b6wbXKGDD0PODRkgJu5xM lxnU0lSPCVPvKI07EOPL7+vd7QPyzwcKgQkKWG3TwQBQ/grwUd7cv3O5mobYuUGIpm+t TTFN6iuo4TmBQR409xOuoIH0uf1lWoFa0IpiqxWeEFSE7Bah/s0JOX26WND1njPYqCY2 QriA== 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 p5-20020a170902ebc500b001891957c097si24551402plg.91.2022.12.08.05.33.59; Thu, 08 Dec 2022 05:34:08 -0800 (PST) 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 S230241AbiLHNH6 (ORCPT + 72 others); Thu, 8 Dec 2022 08:07:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230244AbiLHNHw (ORCPT ); Thu, 8 Dec 2022 08:07:52 -0500 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2060C2EF45 for ; Thu, 8 Dec 2022 05:07:45 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed20:5574:4fdf:a801:888e]) by albert.telenet-ops.be with bizsmtp id tp7d2800K2deJRf06p7dvV; Thu, 08 Dec 2022 14:07:43 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1p3GIF-002tBF-6Q; Thu, 08 Dec 2022 13:46:27 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1p3EN6-003gqg-Pz; Thu, 08 Dec 2022 11:43:20 +0100 From: Geert Uytterhoeven To: Stephen Boyd , Krzysztof Kozlowski , Tomasz Figa , Sylwester Nawrocki , Will Deacon , Arnd Bergmann , Wolfram Sang , Dejin Zheng , Kai-Heng Feng Cc: linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] iopoll: Call cpu_relax() in busy loops Date: Thu, 8 Dec 2022 11:43:19 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE 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 It is considered good practice to call cpu_relax() in busy loops, see Documentation/process/volatile-considered-harmful.rst. This can not only lower CPU power consumption or yield to a hyperthreaded twin processor, but also allows an architecture to mitigate hardware issues (e.g. ARM Erratum 754327 for Cortex-A9 prior to r2p0) in the architecture-specific cpu_relax() implementation. As the iopoll helpers lack calls to cpu_relax(), people are sometimes reluctant to use them, and may fall back to open-coded polling loops (including cpu_relax() calls) instead. Fix this by adding calls to cpu_relax() to the iopoll helpers: - For the non-atomic case, it is sufficient to call cpu_relax() in case of a zero sleep-between-reads value, as a call to usleep_range() is a safe barrier otherwise. - For the atomic case, cpu_relax() must be called regardless of the sleep-between-reads value, as there is no guarantee all architecture-specific implementations of udelay() handle this. Signed-off-by: Geert Uytterhoeven --- This has been discussed before, but I am not aware of any patches moving forward: - "Re: [PATCH 6/7] clk: renesas: rcar-gen3: Add custom clock for PLLs" https://lore.kernel.org/all/CAMuHMdWUEhs=nwP+a0vO2jOzkq-7FEOqcJ+SsxAGNXX1PQ2KMA@mail.gmail.com/ - "Re: [PATCH v2] clk: samsung: Prevent potential endless loop in the PLL set_rate ops" https://lore.kernel.org/all/20200811164628.GA7958@kozik-lap --- include/linux/iopoll.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index 2c8860e406bd8cae..73132721d1891a2e 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -53,6 +53,8 @@ } \ if (__sleep_us) \ usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + else \ + cpu_relax(); \ } \ (cond) ? 0 : -ETIMEDOUT; \ }) @@ -95,6 +97,7 @@ } \ if (__delay_us) \ udelay(__delay_us); \ + cpu_relax(); \ } \ (cond) ? 0 : -ETIMEDOUT; \ }) -- 2.25.1