Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4598521iog; Wed, 22 Jun 2022 02:00:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sC3i+5U/+A+GFe0GQlr8dZgRra2yHToYTUYMsAKfha0OEq0nDcx24NQ0VlC6ZPF+4TSDpJ X-Received: by 2002:aa7:900a:0:b0:525:1e54:e64e with SMTP id m10-20020aa7900a000000b005251e54e64emr16927066pfo.35.1655888416839; Wed, 22 Jun 2022 02:00:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655888416; cv=none; d=google.com; s=arc-20160816; b=KAcH1/xuxz4y6Zb5SBjAAELBoeNZF3OS3xeLLCYGrriJR4B0nmWMhhnG5r6XhzkYxN Zgi5iAWKObKT+1HH5Qig7kiYIv+ZDriVeeldAsPodDXXhSamsEMJSJrxtcKM91sfv+PV hhEQJ23kWmeLLlUJxZMZ9NIZBoRz1vg0bTOBngMwp9LdhlV/2mjKFBZcbVhdqcEVDF3k ofFTKO37aR+ew53Chwpm709uvn5hqlDb7oqp5XvQE15AmXdusfSQ+ISwyIkwoROIxBTm kDM5sNEi/0foQbYGv+YqIChX2ILi9BkDM0UNiUNlR/EkZkJDbM1LkQ/2DBk4GUlv3ogi d7pg== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=GBC3J2A9HebSyrbidRiXqolJ35197hP/IXkvxaIZ+5U=; b=DNyx37GXzZDSHkqqsZcdat3Tzck18374AxK/qmhYhYCXW921Qgd5/OYxH7C8G1SKWJ WYJOsSJ4nSFLvHBpU60m7eWdBvYctNDKqucGdLGizMhcqpYHO9KfoeATIe1nLzy/vKSD W5fsWJ7prBQmQjp2h3Jt/mLNP8XPe5dESZLWfmvWhNSkmZ/2ULbvViUxDTk79xxUim+K l8J+3fA2JNb/n8X2Qd3oB5EwiaZoK+YKIGalK8NeVhlqe+B+SpPojPUU/G/jt2N8hPtl gyxT7FsYwe9DxiDee16ezffZxVM+BsjYm5w3vED4oez3IMTFt3mxkXyQ2viUC+ZwdByQ 3Ozw== 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 x8-20020a170902820800b001619b733920si21633581pln.51.2022.06.22.02.00.03; Wed, 22 Jun 2022 02:00:16 -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 S235225AbiFVIfZ (ORCPT + 99 others); Wed, 22 Jun 2022 04:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235752AbiFVIfX (ORCPT ); Wed, 22 Jun 2022 04:35:23 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E715C381B4 for ; Wed, 22 Jun 2022 01:35:21 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o3vpW-0007nL-A9; Wed, 22 Jun 2022 10:35:18 +0200 Message-ID: Subject: Re: [PATCH RFC 1/2] regmap: add option to disable debugfs From: Lucas Stach To: Aisheng Dong , Mark Brown Cc: "linux-kernel@vger.kernel.org" , "dongas86@gmail.com" , Peng Fan , "shawnguo@kernel.org" Date: Wed, 22 Jun 2022 10:35:17 +0200 In-Reply-To: References: <20220620134758.1286480-1-aisheng.dong@nxp.com> <20220620134758.1286480-2-aisheng.dong@nxp.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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-kernel@vger.kernel.org Am Mittwoch, dem 22.06.2022 um 08:18 +0000 schrieb Aisheng Dong: > > From: Lucas Stach > > Sent: Wednesday, June 22, 2022 4:08 PM > > > > Hi Aisheng, hi Mark, > > > > Am Dienstag, dem 21.06.2022 um 18:16 +0000 schrieb Aisheng Dong: > > > > From: Mark Brown > > > > Sent: Tuesday, June 21, 2022 11:32 PM > > > > > > > > On Tue, Jun 21, 2022 at 02:56:58PM +0000, Aisheng Dong wrote: > > > > > > > > > > so if we can't satisfy the read from the cache then we'll > > > > > > hit > > > > > > the cache_only check and return -EBUSY before we start > > > > > > trying to > > > > > > do any physical I/O. The debugfs code will handle that > > > > > > gracefully, indicating that it couldn't get a value for the > > > > > > volatile register by showing all Xs for the value. If none > > > > > > of > > > > > > the registers are cached then the file won't be terribly > > > > > > useful > > > > > > but it at least shouldn't cause any > > > > errors with accessing the device when it's powered down. > > > > > > > > > That means we have to use cache_only mode to workaround the > > > > > issue, > > > > > right? > > > > > I saw that cache_only mode has to be explicated > > > > > enable/disable by > > > > > driver, commonly used in device rpm in kernel right now. > > > > > > > > Yes. > > > > > > > > > However, things are a little bit complicated on i.MX that 1) > > > > > imx > > > > > blkctl needs follow strict registers r/w flow interleaved > > > > > with > > > > > handshakes with upstream gpc power operations and delay may > > > > > be > > > > > needed between registers writing > > > > > 2) blkctl itself does not enable runtime pm, it simply call > > > > > rpm to > > > > > resume upstream power domains devices and necessary clocks > > > > > before > > > > > r/w > > > > registers. > > > > > > > > I'm not sure I fully understand the issue here? If the driver > > > > can > > > > safely manage the hardware surely it can safely manage cache > > > > only > > > > mode too? If there are duplicate resumes then cache only > > > > enable/disable is a boolean flag rather than refcounted so that > > > > shouldn't be a problem. > > > > > > > > > > I still can't see an easy and safe to way to do it. > > > What I'm wondering is whether it's worth to do it if need to > > > introducing considerable complexities in driver to overcome this > > > issue > > > if it can be simply disabled. > > > Anyway, I will try to investigate it. > > > > > > > > Furthermore, current imx blkctl is a common driver used by > > > > > many > > > > > devices > > > > [1]. > > > > > Introducing volatile registers and cache may bloat the driver > > > > > a > > > > > lot > > > > unnecessarily. > > > > > > > > You don't actually need to have a cache to use cache only mode, > > > > if > > > > there are no cached registers then you'll just get -EBUSY on > > > > any > > > > access to the registers but that's hopefully fine since at the > > > > minute things will just fall over anyway. > > > > You shouldn't even need to flag registers as volatile if > > > > there's no > > > > cache since it's not really relevant without a cache. > > > > > > > > > > After a quick try initially, I found two issues: > > > 1. There's a warning dump if using cache_only without cache void > > > regcache_cache_only(struct regmap *map, bool enable) { > > >         map->lock(map->lock_arg); > > >         WARN_ON(map->cache_bypass && enable); > > >         ... > > > } > > > 2. It seems _regmap_write() did not handle cache_only case well > > > without cache. > > > It may still writes HW even for cache_only mode? > > > > > > I guess we may need fix those two issues first before we can > > > safely > > > use it? > > > > > Why would you write to a cache only regmap. The debugfs interface > > only > > allows to dump the registers, no? > > I mean the _regmap_write() called in driver even we claim it's cache > only. > Not dumping registers from debugfs. That should obviously never happen, as the regmap should only be marked cache-only while the power domain is collapsed. Writing any register in this state is invalid usage and the WARN_ON is totally warranted. > > > > > I think it wouldn't be too hard to fix this for the blk-ctrl > > drivers. > > I'll give it a try today. > > > > Great, looking forward to see it. > > > > > > The simplest way for i.MX case may be just disabling debugfs > > > > > as it > > > > > can't reflect the actually HW state without power. So we > > > > > would > > > > > wish the > > > > regmap core could provide an option to users. > > > > > > > > The goal here is to describe the regmap itself so that there's > > > > less > > > > fragility as things change and we don't needlessly disable > > > > anything > > > > else that happens to be added to debugfs in the future due to > > > > having > > > > an overly generic flag, and we get the ability to directly > > > > catch > > > > access to the hardware that misses doing power management > > > > properly > > > > while we're at it. > > > > > > > > We already have a way to describe it being unsafe to access the > > > > hardware, we may as well use it. > > > > > > > > > And I noticed that syscon [2] seems have the same issue since > > > > > the > > > > > following > > > > commit: > > > > > > > > > commit 9b947a13e7f6017f18470f665992dbae267852b3 > > > > > Author: David Lechner > > > > > Date: Mon Feb 19 15:43:02 2018 -0600 > > > > > > > > >     regmap: use debugfs even when no device > > > > > > > > >     This registers regmaps with debugfs even when they do not > > > > > have > > > > > an > > > > >     associated device. For example, this is common for syscon > > > > > regmaps. > > > > > > > > That's a different thing, that's due to us naming the directory > > > > after the struct device but syscons being created before we > > > > have > > > > that struct device available. > > > > > > Yes, but syscon has the same issue that the system may hang if > > > dump > > > registers through debugfs without power on. > > > How would you suggest for this case as syscon is also a common > > > driver? > > > > > This is a general issue. If something uses a syscon that is inside > > a > > power-domain where the runtime PM is controlled by some other > > entity, how > > is it safe to use the syscon at all? Every access might end up > > locking up the > > system. So those syscons really need to learn some kind of runtime > > PM > > handling. > > The regmap core does not support runtime pm. > It may be unsafe to dumping registers through debugfs. Right, that is a general issue, not only for debugfs. Any access to a syscon inside a power-domain may hang the system, as the syscon has no way to ensure that the power domain is up. Regards, Lucas