Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1215436pxb; Fri, 22 Jan 2021 09:44:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJykPYM96BXrEvbQTakZQzD9LsK5tprMi8H3wIkB17WgVpAp5wrHFXca5MfSrojwac2FUrYk X-Received: by 2002:a17:906:578e:: with SMTP id k14mr3564989ejq.243.1611337461491; Fri, 22 Jan 2021 09:44:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611337461; cv=none; d=google.com; s=arc-20160816; b=TXmWznDF+w8jeeCf0IrVScLiA1gwTDJn38z18KW6zXcBsqqGKcNTFc31EXw5UCDiUu 2NRhJbN+snom0vObXVX7IAP/9HbseykF6MlrW6+OJxGgEn0EUBu4+s3bSynZfxhCaFNB pqIAcJrZyZby/TYEK0jv3krnPDfDpNY3w+HMAu0vIW+aMnzemtaELuns0sOES6dJ3Wmc 7rbLzPoVqdudeuLw3NqitRztExWp6jUuNUWhBkmaUot5RlZVpUuu8UCKXp1LfP0pTE4N bkJVYOiqQIE84Cudsf9FGUqKqNBREfa+o7enSYAyUyUBw1z7flE20GjmM4nJhAATLPgF YUqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3eAbnY6xA/gRZJxfscCuC7XOiulmOFHNvPNXAXuxGa8=; b=Dga7OMllbaW44+wl9INWgFky20SH6Gkn+oyXvzA/KS8sqP2EBU6qpJpqN4UI8JTDvt /DOm+tz1FUWD3RGOkEL8kSC3jkeAmOrKvt4G7XkEO9ggcn6u4mBuSAHSpNSkhuX6mmCp 5H4V7m8TPIhUmACMtfFE3XfbRCitO4U34uraY1zwM3t2owF4bMIIKiblN9YRER4lqCEX pMwCf0wgHL/5CQfCq8XvAaYykjIclzEp7wsu9Eiv4E3Qs8X945LLpTuII8ow7YK38SOK NhQWYMxtqOrHLn3BCZdi2WNwycwJddVAbLUsGsbYA/OK3vEvKavFu2WZM/qzuCiIRYPe gRow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=goHCeJXW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb13si4168356edb.8.2021.01.22.09.43.57; Fri, 22 Jan 2021 09:44:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=goHCeJXW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730079AbhAVRbD (ORCPT + 99 others); Fri, 22 Jan 2021 12:31:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729053AbhAVPtD (ORCPT ); Fri, 22 Jan 2021 10:49:03 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E010C06178B for ; Fri, 22 Jan 2021 07:48:37 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id j13so7095243edp.2 for ; Fri, 22 Jan 2021 07:48:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3eAbnY6xA/gRZJxfscCuC7XOiulmOFHNvPNXAXuxGa8=; b=goHCeJXW4a9N8IFJcoZ3YyUmIOymCqSCz//9nfnjcAad8iVVpKl8L+p1eHdtH3/4Be WE5acK0za0ULdzyvCDmSrgwR8uL9N/1MC5ihXsQuvhE94HnPA/kilQeKD1nR8qVt0Syz XBIShATeB/BwyBzl59hjU62kpr5oDMX0bLk6OP26jYvz+oJHEu5LAX9PHSHOzKEIi5ir lBhsN+clgveRvAzPaH0GDddOcUnLeMar3q0FiwK2Acso5SjfLbzwpbNBIVRg1mczQJ5D e0UNRZa5vNxbUkCQXFZ+ffqlvy1+1nIKlcfCrYST/hQ8YTA19B+TkCfcSUqhPIeFkgXo sCrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3eAbnY6xA/gRZJxfscCuC7XOiulmOFHNvPNXAXuxGa8=; b=jFBsibofZ5QCKyepAmWRbB1JJVv5/u1oqayII0Ro/Dmkcl77wvYrB10tOothepploW M90XRih9mToJQCNoDXYH6AVpHKcbrDNcAXP2+tIq/hv5lc6/V9F3wgE13crmB/yhz5Zc zH5NQzPxXBcpGnTzgpkk4ZyS9jso9SIyWKJeO1yll4oS1DJGrsb1ub5KkOtivTFvR1rf XlOHw5e/yqa12DDYO33ZJYIMp9Obsq8eFG7YAgCzqC3qaA3wfUEKB0K7lJWXnT6gmIFW 1/zmUX7g/mMnoV1iQFTdmLSd+c/HPETxW8d+PqUDj42cvp6XmkJdmC98W8ZKBYzMKV1E q5bA== X-Gm-Message-State: AOAM530dDvmz114e4Va2B9QefajqfrHtqWyVhSC31YEQpQNlGQ/V1KUR 2rIqdBqTYjVTcLZZqEU710FThGIWCOzG4uWjuqPd8A== X-Received: by 2002:a05:6402:60a:: with SMTP id n10mr3607422edv.230.1611330515907; Fri, 22 Jan 2021 07:48:35 -0800 (PST) MIME-Version: 1.0 References: <17nqrn25-rp5s-4652-o5o1-72p2oprqpq90@onlyvoer.pbz> <84r6s34s-opq7-9358-o45n-27s17084012@onlyvoer.pbz> In-Reply-To: From: Naresh Kamboju Date: Fri, 22 Jan 2021 21:18:23 +0530 Message-ID: Subject: Re: [PATCH v2] PM / clk: make PM clock layer compatible with clocks that must sleep To: "Rafael J. Wysocki" Cc: Nicolas Pitre , Geert Uytterhoeven , "Rafael J. Wysocki" , Greg Kroah-Hartman , Michael Turquette , Stephen Boyd , Russell King , Linux PM , linux-clk , open list , Mark Brown , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 22 Jan 2021 at 20:39, Rafael J. Wysocki wrote: > > On Thu, Jan 21, 2021 at 8:01 PM Rafael J. Wysocki wrote: > > > > On Thu, Jan 21, 2021 at 6:23 PM Nicolas Pitre wrote: > > > > > > The clock API splits its interface into sleepable ant atomic contexts: > > > > > > - clk_prepare/clk_unprepare for stuff that might sleep > > > > > > - clk_enable_clk_disable for anything that may be done in atomic context > > > > > > The code handling runtime PM for clocks only calls clk_disable() on > > > suspend requests, and clk_enable on resume requests. This means that > > > runtime PM with clock providers that only have the prepare/unprepare > > > methods implemented is basically useless. > > > > > > Many clock implementations can't accommodate atomic contexts. This is > > > often the case when communication with the clock happens through another > > > subsystem like I2C or SCMI. > > > > > > Let's make the clock PM code useful with such clocks by safely invoking > > > clk_prepare/clk_unprepare upon resume/suspend requests. Of course, when > > > such clocks are registered with the PM layer then pm_runtime_irq_safe() > > > can't be used, and neither pm_runtime_suspend() nor pm_runtime_resume() > > > may be invoked in atomic context. > > > > > > For clocks that do implement the enable and disable methods then > > > everything just works as before. > > > > > > Signed-off-by: Nicolas Pitre > > > > > > --- > > > > > > On Thu, 21 Jan 2021, Rafael J. Wysocki wrote: > > > > > > > So I'm going to drop this patch from linux-next until the issue is > > > > resolved, thanks! > > > > > > Here's the fixed version. > > > > Applied instead of the v1, thanks! > > > > > Changes from v1: > > > > > > - Moved clk_is_enabled_when_prepared() declaration under > > > CONFIG_HAVE_CLK_PREPARE and provided a dummy definition when that > > > config option is unset. > > > > > > diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c > > > index ced6863a16..a62fb0f9b1 100644 > > > --- a/drivers/base/power/clock_ops.c > > > +++ b/drivers/base/power/clock_ops.c > > > @@ -23,6 +23,7 @@ > > > enum pce_status { > > > PCE_STATUS_NONE = 0, > > > PCE_STATUS_ACQUIRED, > > > + PCE_STATUS_PREPARED, > > > PCE_STATUS_ENABLED, > > > PCE_STATUS_ERROR, > > > }; > > > @@ -32,8 +33,102 @@ struct pm_clock_entry { > > > char *con_id; > > > struct clk *clk; > > > enum pce_status status; > > > + bool enabled_when_prepared; > > > }; > > > > > > +/** > > > + * pm_clk_list_lock - ensure exclusive access for modifying the PM clock > > > + * entry list. > > > + * @psd: pm_subsys_data instance corresponding to the PM clock entry list > > > + * and clk_op_might_sleep count to be modified. > > > + * > > > + * Get exclusive access before modifying the PM clock entry list and the > > > + * clock_op_might_sleep count to guard against concurrent modifications. > > > + * This also protects against a concurrent clock_op_might_sleep and PM clock > > > + * entry list usage in pm_clk_suspend()/pm_clk_resume() that may or may not > > > + * happen in atomic context, hence both the mutex and the spinlock must be > > > + * taken here. > > > + */ > > > +static void pm_clk_list_lock(struct pm_subsys_data *psd) > > > +{ > > > + mutex_lock(&psd->clock_mutex); > > > + spin_lock_irq(&psd->lock); > > > +} > > > + > > > +/** > > > + * pm_clk_list_unlock - counterpart to pm_clk_list_lock(). > > > + * @psd: the same pm_subsys_data instance previously passed to > > > + * pm_clk_list_lock(). > > > + */ > > > +static void pm_clk_list_unlock(struct pm_subsys_data *psd) > > Locking annotations for sparse were missing here and above, so I've > added them by hand. > > Please double check the result in my linux-next branch (just pushed). May i request to add Reported-by: Naresh Kamboju - Naresh