Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp946583rwb; Wed, 26 Jul 2023 05:33:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlHHxwCVAXIvktWKPkg5dCEB3MAskKW5V5cGuwIgL1eP7iYRow9G82xAi0ETW5IU9scCqazt X-Received: by 2002:a17:906:2101:b0:99b:b0b2:3f9 with SMTP id 1-20020a170906210100b0099bb0b203f9mr1594399ejt.2.1690374804654; Wed, 26 Jul 2023 05:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690374804; cv=none; d=google.com; s=arc-20160816; b=UojVTLlokm+nsHorWBTvaZv/8iD2bdeDP5pnouIpK9Qne8GCipRJhVXEIUzDn1LZ53 ra+Npf1TyfsdvRlDWiPWXquJuRVOq2WJK06DBjCT7kI0GTjLxPPOQ2YH4Dt9kzaleOPq eMn410ZUeoPZxp1P1JE4uFHK7ogew5CF8ec4iUGaV/OK5OcmxSgQp6Md7N+gdEy+VgHJ OA4TgEnZdHhcuIKtb+RX2zyvxn5z8Mmd+Ydd+8gHNmA0Ie8mSkvhjbj6ECLCzp8Q94LE deWa1bEn28M3ifI2sCh+qfIEmT5AlABfrpqKUuxZ17vFZKy8R5acagmECO0SD6JL+1aJ U4JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=4JEsl63hPBo5DWeojho2M2rHGbIcrkQx6tLrefGuC/I=; fh=kqMNReDS2kYDVO22tJ2ucCbkln9QzEC35JS2i0UcTdk=; b=RzCuYfWwKkFJavfOD8N9PcF5pQ8yjuasJM0PclJ21lzHv/mCHOLz+J2qhm2dWchAus tbz2wSF1sc3vn7fhyaZ9Ba0OIJJ3Fx9RkUJrDiUy+CsmRhYXBI+lJdQ2BBFSbtQFbYri dBOn/oBvBqNlyQExPDqAqHIqxhSq3XKgHbSBHhNn1oNyMcpxqhpGQO37IswJSUEdQr0K VU35TTDXV14jAPYDN21yBG3F9cAr1s6QIjdcMnMAW49LdEcXH8e6Qs6E6uhUSxqCJIGB ivOt+kaGRSxD5KnHBrBRknl9l5z26tC+NcJssICpsoOumQniSN0AI7yErfjLQmuVXdfY VKhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 d18-20020a17090648d200b0099bc0eee3a8si941117ejt.154.2023.07.26.05.32.54; Wed, 26 Jul 2023 05:33:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234325AbjGZLyt (ORCPT + 99 others); Wed, 26 Jul 2023 07:54:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234354AbjGZLyr (ORCPT ); Wed, 26 Jul 2023 07:54:47 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F061188; Wed, 26 Jul 2023 04:54:42 -0700 (PDT) Received: from martin by viti.kaiser.cx with local (Exim 4.89) (envelope-from ) id 1qOd63-0005Ck-Pc; Wed, 26 Jul 2023 13:54:27 +0200 Date: Wed, 26 Jul 2023 13:54:27 +0200 From: Martin Kaiser To: Alexey Romanov Cc: "narmstrong@baylibre.com" , "neil.armstrong@linaro.org" , "olivia@selenic.com" , "herbert@gondor.apana.org.au" , "robh+dt@kernel.org" , "krzysztof.kozlowski+dt@linaro.org" , "conor+dt@kernel.org" , "khilman@baylibre.com" , "jbrunet@baylibre.com" , "martin.blumenstingl@googlemail.com" , "f.fainelli@gmail.com" , "hkallweit1@gmail.com" , "linux-arm-kernel@lists.infradead.org" , "linux-amlogic@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-crypto@vger.kernel.org" , kernel Subject: Re: [PATCH v1 1/3] drivers: rng: add check status bit feature Message-ID: <20230726115427.aigzl2wjgc6ccyt6@viti.kaiser.cx> References: <20230725141252.98848-1-avromanov@sberdevices.ru> <20230725141252.98848-2-avromanov@sberdevices.ru> <20230725195901.n2klvgz7outqaatk@viti.kaiser.cx> <20230726075243.f37sjcurmog3eunh@cab-wsm-0029881> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230726075243.f37sjcurmog3eunh@cab-wsm-0029881> User-Agent: NeoMutt/20170113 (1.7.2) Sender: Martin Kaiser X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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-crypto@vger.kernel.org Hi Alexey, Alexey Romanov (AVRomanov@sberdevices.ru) wrote: > > > +static int meson_rng_wait_status(void __iomem *cfg_addr, int bit) > > > +{ > > > + u32 status; > > > + u32 cnt = 0; > > > + > > > + do { > > > + status = readl_relaxed(cfg_addr) & BIT(bit); > > > + cpu_relax(); > > > + } while (status && (cnt++ < RETRY_CNT)); > > > + > > Could you use readl_relaxed_poll_timeout here instead of open coding the > > loop? > At first I also thought about this API. But later I came to the > conclusion that it is inappropriate here: > 1. We can't call rng_read from an atomic context. Agreed. A hwrng read function may sleep (an example for this is exynos_trng_do_read). But this doesn't prevent us from using readl_relaxed_poll_timeout. > 2. RNG for me looks like a very lightweight primitive to me that > should work quiclky. > But, now I looked again at the API and realized that we can use > readl_relaxed_poll_timeout_atomic() instead of > readl_relaxed_poll_timeout(). What do you think? Ok, if you know that your rng hardware won't need much time to set the bit that you're checking, you may use readl_relaxed_poll_timeout_atomic. stm32_rtc_set_alarm does something similar. Best regards, Martin