Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3862461rdb; Thu, 14 Sep 2023 05:13:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQGRLuGdid/xP7sdLULeZoh+dHoG5j281Vj4JyfKmshGkYI9J4zkSsBfQUhdtDc+92d3xW X-Received: by 2002:a17:90b:1e53:b0:26d:17e0:2f3d with SMTP id pi19-20020a17090b1e5300b0026d17e02f3dmr5220705pjb.44.1694693630764; Thu, 14 Sep 2023 05:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694693630; cv=none; d=google.com; s=arc-20160816; b=ygkpSrHSIzI9XeQxmboaPxXsz+9nAUxZKt3aCqX5AwCx6cap59R6OMclOUp7QuAYFZ TBu5xEQW/WokGwO4nGnJcywRFELlyUO8ksTNuIhboPioFaPbPv4k75KjXTq1qi8KeUxL XXjWZo9eoAKTsUYywJ3ygOB/MksZmohz2sn2RAroADTqIAiSJVeK2zReTE1DMHNiOgBF nU59DM9Y/FTTS68KliIpCaTB5kB+W1Ig3jN+7+TYzq7fVdX/nWmsp6NbIv28NVgej6py LFBDYWbWItR1XSOTRGjTwaGeygm5pI8H0S2JtePasgyBkO3t+UpbGlbwctTlCuTK+tH+ 8GhA== 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=gMgAEJY3G15P9XvBcqshjm3kc2A1s8IsqxLJD/BfLkI=; fh=/Zl1W2xIsUDh4Hm8y4wqunf82qFjBEuhBaMw8B9XUyE=; b=N/lCO7sFk93v+AI+e13u6XHnBQ41/UdVQ+OliRPeg25om48fxoA7IZODeQ/VOqgRFl sF83bC/HB6PjkRyWN4YHHkFwrNFZaVaswoU0Amf2n3d2DWh1+vqJpmTKETVsvTPlhwIg X1M3QPsn4oQ0Y4UJ31MjsER8fRycgVcnRCZrALinbB+jihB7FjX7IC3GDFQvV2tEYfak VZtKPmS0JjohzJTRglVjw+LTd/BIYBo1FsIJdug1SJ5V0ByPJhr7fCo3NEzd0SiLXv92 NjkZ7SpF8H1Dasb1hzdKEzx5mEeX/DKgR9o7ZunLiTMCizECiKQowFS9lwnLOYy31Aia GLDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id h10-20020a17090a710a00b00262e5a82047si1477257pjk.44.2023.09.14.05.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 05:13:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4CC7E81C46DC; Thu, 14 Sep 2023 05:13:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238359AbjINMNl convert rfc822-to-8bit (ORCPT + 99 others); Thu, 14 Sep 2023 08:13:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238119AbjINMNi (ORCPT ); Thu, 14 Sep 2023 08:13:38 -0400 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFACC1BF4; Thu, 14 Sep 2023 05:13:34 -0700 (PDT) Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-d7b79a4899bso905775276.2; Thu, 14 Sep 2023 05:13:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694693614; x=1695298414; 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=wCvoAaFuPyjPU6jJg4KzcxsCGGRqqM79Y530FyBZVZI=; b=nsm4AUelSdzZoMy5eLfIX4XFWnlT17GDxhS1j1OnHH+siBAE2IU/E6ljaKWm9Ngz2h TsEYLE8/k6MQVxLcHwtNmpvB0MfumdjiPZXloG+1h7HEVLop6tQXOtLx2vIz+3LZZFNV X4unHlFRsboKCAQGxC+dOiYajTpp0urPfPiXwYa+HgwcNwZyzhR1UVUKD3uyeZ1xMCIK AmqJuGhysyB8vDEyf/javDXjO/O7Q/TklcL2X+PP+osIqGkGgdM1wtSGbuycuQRC5Dhj fg4mweWEq+Ti1suKBtg2MNyKobMP6HdumVUNLceCqcxAv9TbhN+AbgDEMOOzot/ZmzAL danw== X-Gm-Message-State: AOJu0YyjoJUrQQk10/EzlpNCOzRPSaLMJS85yvc2Tt0wV4XXggSCYQbt kNhS+zSd/8WMXODUiK+9VrXH0dY13YpiFg== X-Received: by 2002:a25:7497:0:b0:d78:3a4e:c19e with SMTP id p145-20020a257497000000b00d783a4ec19emr5246688ybc.24.1694693613689; Thu, 14 Sep 2023 05:13:33 -0700 (PDT) Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com. [209.85.219.174]) by smtp.gmail.com with ESMTPSA id m196-20020a25d4cd000000b00d814d8dfd69sm304403ybf.27.2023.09.14.05.13.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Sep 2023 05:13:32 -0700 (PDT) Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-d7b79a4899bso905708276.2; Thu, 14 Sep 2023 05:13:32 -0700 (PDT) X-Received: by 2002:a25:d384:0:b0:d7b:8d0c:43ef with SMTP id e126-20020a25d384000000b00d7b8d0c43efmr5333188ybf.37.1694693611889; Thu, 14 Sep 2023 05:13:31 -0700 (PDT) MIME-Version: 1.0 References: <20230912045157.177966-1-claudiu.beznea.uj@bp.renesas.com> <20230912045157.177966-8-claudiu.beznea.uj@bp.renesas.com> In-Reply-To: <20230912045157.177966-8-claudiu.beznea.uj@bp.renesas.com> From: Geert Uytterhoeven Date: Thu, 14 Sep 2023 14:13:19 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 07/37] clk: renesas: rzg2l: lock around writes to mux register To: Claudiu Cc: mturquette@baylibre.com, sboyd@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, ulf.hansson@linaro.org, linus.walleij@linaro.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, magnus.damm@gmail.com, catalin.marinas@arm.com, will@kernel.org, prabhakar.mahadev-lad.rj@bp.renesas.com, biju.das.jz@bp.renesas.com, quic_bjorande@quicinc.com, arnd@arndb.de, konrad.dybcio@linaro.org, neil.armstrong@linaro.org, nfraprado@collabora.com, rafal@milecki.pl, wsa+renesas@sang-engineering.com, linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-gpio@vger.kernel.org, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Claudiu Beznea Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 05:13:48 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Hi Claudiu, On Tue, Sep 12, 2023 at 6:52 AM Claudiu wrote: > From: Claudiu Beznea > > SD MUX output (SD0) is further divided by 4 in G2{L, UL}. The divided > clock is SD0_DIV4. SD0_DIV4 is registered with CLK_SET_RATE_PARENT which > means a rate request for it is propagated to the MUX and could reach > rzg2l_cpg_sd_clk_mux_set_parent() concurrently with the users of SD0. > Add proper locking to avoid concurrent access on SD MUX set rate > registers. > > Fixes: eaff33646f4cb ("clk: renesas: rzg2l: Add SDHI clk mux support") > Signed-off-by: Claudiu Beznea Thanks for your patch! > --- a/drivers/clk/renesas/rzg2l-cpg.c > +++ b/drivers/clk/renesas/rzg2l-cpg.c > @@ -189,6 +189,7 @@ static int rzg2l_cpg_sd_clk_mux_set_parent(struct clk_hw *hw, u8 index) > u32 shift = GET_SHIFT(hwdata->conf); > const u32 clk_src_266 = 2; > u32 msk, val, bitmask; > + unsigned long flags; > int ret; > > /* > @@ -203,25 +204,27 @@ static int rzg2l_cpg_sd_clk_mux_set_parent(struct clk_hw *hw, u8 index) > * the index to value mapping is done by adding 1 to the index. > */ > bitmask = (GENMASK(GET_WIDTH(hwdata->conf) - 1, 0) << shift) << 16; > + spin_lock_irqsave(&priv->rmw_lock, flags); > if (index != clk_src_266) { > writel(bitmask | ((clk_src_266 + 1) << shift), priv->base + off); > > msk = off ? CPG_CLKSTATUS_SELSDHI1_STS : CPG_CLKSTATUS_SELSDHI0_STS; > > - ret = readl_poll_timeout(priv->base + CPG_CLKSTATUS, val, > - !(val & msk), 100, > - CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US); > - if (ret) { > - dev_err(priv->dev, "failed to switch clk source\n"); > - return ret; > - } > + ret = readl_poll_timeout_atomic(priv->base + CPG_CLKSTATUS, val, > + !(val & msk), 100, According to the read_poll_timeout_atomic() documentation, delay_us should be less than ~10us. > + CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US); CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US = 20 ms, which is a long timeout for an atomic poll. > + if (ret) > + goto unlock; > } > > writel(bitmask | ((index + 1) << shift), priv->base + off); > > - ret = readl_poll_timeout(priv->base + CPG_CLKSTATUS, val, > - !(val & msk), 100, > - CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US); > + ret = readl_poll_timeout_atomic(priv->base + CPG_CLKSTATUS, val, > + !(val & msk), 100, > + CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US); Likewise. > +unlock: > + spin_unlock_irqrestore(&priv->rmw_lock, flags); > + > if (ret) > dev_err(priv->dev, "failed to switch clk source\n"); The rest LGTM. 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