Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp903477imm; Fri, 11 May 2018 08:06:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrbXGpaG/SgC1tp3kUsTeMWfP5w9Xuj2/u9CtZ6TaWXwniGhKWIKxMj1ubgUeTD8jG7Ek9N X-Received: by 2002:a17:902:362:: with SMTP id 89-v6mr5970015pld.270.1526051208523; Fri, 11 May 2018 08:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526051208; cv=none; d=google.com; s=arc-20160816; b=yjj7nFwFATpXG7lQobKR3jnYFNpws0+I7vGP6xp8hELFi1GCigyqlFCDGinLeXLuWv Htr7iAI1YHDyTePIHN/S6qa/6WrYNFS5T6Rr2pMwZO0eeP70fNokgLVq6RpvsVze/1ri zGUZoIwnRb+owWloAEU68wol9iME2rAezZk1B6y/9FVmmH8R6FqE2/5P2baAq15emsvr pNzIQpjkxubn8hUMR9P+GIL28/qaFbcasKLCLJDCVChjdrRjVqjEVkcrekgS3cl+swjG khTpTLfRRfn7W+5KYbZbm5InrocMUASz/yC8Iz9eUJXNviriiowAptZzKYLaR604JcLp WyLw== 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:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=Jg5ikMiyrwBLyKdi8MReIKaFthki1niRX6hL7MQIfN8=; b=dxYhu/sGtzQjbKEmCKPqyPCyBMJWzg73zq3dPArH/Tvj67ioXYbmw1FogtgYNBWaxL fzC6r517+5H4+TiBSq7UQlYHs4GZRP68CLrF+zTkapzF/9CXzL/EYA3DH7pscogXcf0H H6ZN6LKw8/RMCSySske584fH8gonvskwONnrUt3tpiYoYAuOZCokRdc27UgMBAybn00y 7pJZmqCPM+EhaR2Q4t/gP5ty3BHCZBLHDJWiPAn15B4ziaJoBF9l/Pgr7jq50ck87Yoz QNffQvkN899wuUzufQO04E7lZ/9iJoiRoLb0eFDTALv+BYmj8R/50YYEy9KhZURQ5/w9 wPFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Hap0MgZu; dkim=pass header.i=@codeaurora.org header.s=default header.b=I5Whf5be; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s36-v6si3240587pld.114.2018.05.11.08.06.33; Fri, 11 May 2018 08:06:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Hap0MgZu; dkim=pass header.i=@codeaurora.org header.s=default header.b=I5Whf5be; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753167AbeEKPGR (ORCPT + 99 others); Fri, 11 May 2018 11:06:17 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:34386 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753247AbeEKPGO (ORCPT ); Fri, 11 May 2018 11:06:14 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 82EF160A06; Fri, 11 May 2018 15:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526051173; bh=I5WywkiQpXKc7fvJ6WBQo7oofSFwcTQiC+qlPUXUKtM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Hap0MgZutnODn/BT/bhfH39sKL/FOm34m/NyXTPMdADzc2jIF1upb0fk3BVR920ue pG2LDpabXspVciY5Cd5AJA5x3A1v9fbIzoFk/AjUBbMdUo9oyR0cst9MxsL7O0XCK8 UerId5x+BEh8jDkfr8okhA1JezuaqX0vsItZggHk= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from localhost (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: ilina@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 49DEF601D9; Fri, 11 May 2018 15:06:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526051172; bh=I5WywkiQpXKc7fvJ6WBQo7oofSFwcTQiC+qlPUXUKtM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I5Whf5bePv/ywuyyhEG83OUZQx6Wxim2YGdiNQJmtQEniJwobzmBKW0KmrTCcOAfb Jgb83pDmsjOrgSN7v+VNBNGgAAB+RPkFRYngt4+o9/ROlQYCBSWz5UQQgguIVl6E7B pg4R4Lrj0wEsmGMVH0q0+JrbGWm5e/DWtMz0f8Jg= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 49DEF601D9 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ilina@codeaurora.org Date: Fri, 11 May 2018 09:06:11 -0600 From: Lina Iyer To: Doug Anderson Cc: Andy Gross , David Brown , linux-arm-msm@vger.kernel.org, "open list:ARM/QUALCOMM SUPPORT" , Rajendra Nayak , Bjorn Andersson , LKML , Stephen Boyd , Evan Green Subject: Re: [PATCH v7 04/10] drivers: qcom: rpmh: add RPMH helper functions Message-ID: <20180511150611.GA30504@codeaurora.org> References: <20180502193749.31004-1-ilina@codeaurora.org> <20180502193749.31004-5-ilina@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Doug, On Thu, May 10 2018 at 16:37 -0600, Doug Anderson wrote: >Hi, > >On Tue, May 8, 2018 at 9:05 AM, wrote: >> On 2018-05-03 14:26, Doug Anderson wrote: >> Hi Doug, >> >> >>> Hi, >>> >>> On Wed, May 2, 2018 at 12:37 PM, Lina Iyer wrote: >>>> >>>> +static struct rpmh_ctrlr rpmh_rsc[RPMH_MAX_CTRLR]; >>>> +static DEFINE_SPINLOCK(rpmh_rsc_lock); >>>> + >>>> +static struct rpmh_ctrlr *get_rpmh_ctrlr(const struct device *dev) >>>> +{ >>>> + int i; >>>> + struct rsc_drv *p, *drv = dev_get_drvdata(dev->parent); >>>> + struct rpmh_ctrlr *ctrlr = ERR_PTR(-EINVAL); >>>> + unsigned long flags; >>>> + >>>> + if (!drv) >>>> + return ctrlr; >>>> + >>>> + for (i = 0; i < RPMH_MAX_CTRLR; i++) { >>>> + if (rpmh_rsc[i].drv == drv) { >>>> + ctrlr = &rpmh_rsc[i]; >>>> + return ctrlr; >>>> + } >>>> + } >>>> + >>>> + spin_lock_irqsave(&rpmh_rsc_lock, flags); >>>> + list_for_each_entry(p, &rsc_drv_list, list) { >>>> + if (drv == p) { >>>> + for (i = 0; i < RPMH_MAX_CTRLR; i++) { >>>> + if (!rpmh_rsc[i].drv) >>>> + break; >>>> + } >>>> + if (i == RPMH_MAX_CTRLR) { >>>> + ctrlr = ERR_PTR(-ENOMEM); >>>> + break; >>>> + } >>>> + rpmh_rsc[i].drv = drv; >>>> + ctrlr = &rpmh_rsc[i]; >>>> + break; >>>> + } >>>> + } >>>> + spin_unlock_irqrestore(&rpmh_rsc_lock, flags); >>> >>> >>> I may have missed something, but to me it appears that this whole >>> "rsc_drv_list" is pretty pointless. I wrote up a patch atop your >>> series to remove it at >>> >>> >>> and it simplifies the code a whole bunch. From that patch, my >>> justification was: >>> >>>> The global rsc_drv_list was (as far as I can tell) racy and not useful >>>> for anything. >>>> >>>> I say it is racy because in general you need some sort of mutual >>>> exclusion for lists. If someone is adding to a list while someone >>>> else is iterating over it then you get badness. >>>> >>>> I say it is not useful because the only user of it was >>>> get_rpmh_ctrlr() and the only thing it did was to verify that the >>>> "struct rsc_drv *" that it alrady had was in the list. How could it >>>> not be? >>> >>> >>> Note that in v7 of your series you added a spinlock around your access >>> of "rsc_drv_list", but this doesn't actually remove the race. >>> Specifically I'm pretty sure that the list primitives don't support >>> calling list_add() while someone might be iterating over the list and >>> your spinlock isn't grabbed in rpmh_rsc_probe(). >>> >>> Note that I also say in my patch: >>> >>>> NOTE: After this patch get_rpmh_ctrlr() still seems a bit fishy. I'm >>>> not sure why every caller would need its own private global cache of >>>> stuff. ...but I left that part alone. >>> >>> >> I am not sure I understand this. > >As I've said I haven't reviewed RPMh in any amount of detail and so >perhaps I don't understand something. > >OK, I dug a little more and coded up something for you. Basically >you're doing a whole bunch of iteration / extra work here to try to >come up with a way to associate an extra bit of data with each "struct >rsc_drv". Rather than that, just add an extra field into "struct >rsc_drv". Problem solved. > >See http://crosreview.com/1054646 for what I mean. > I tried to avoid such pointer references and keep it object oriented with this approach. I agree that we run through a list of 2 (at the max) RSC to get the drv* from the rpmh_ctrlr. It is not going to be expensive. Another things this helps with is that, if the driver is not a child of the RSC nodes in DT, then the drvdata of the parent would not a RSC node and accessing that would result in a crash. This offers a cleaner exit path for the error case. > >>> I'll try to dig into this more so I could just be confused, but in >>> general it seems really odd to have a spinlock and something called a >>> "cache" at this level. If we need some sort of mutual exclusion or >>> caching it seems like it should be stored in memory directly >>> associated with the RPMh device, not some external global. >>> >> The idea behind the locking is not to avoid the race between rpmh.c and >> rpmh-rsc.c. From the DT, the devices that are dependent on the RSCs are >> probed following the probe of the controller. And init is not that we are >> worried about. >> The condition here is to prevent the rpmh_rsc[] from being modified >> concurrently by drivers. > >OK, I see the point of the locking now, but not the list still. >Sounds like Matthias agrees with me that the list isn't useful. Seems >like you should squash my patch at http://crosreview.com/1042883 into >yours. > I saw your approach. I am okay with it for your tree, my approach comes out of experiences in qcom platforms and how things tend to shape up in the future. I would want you to consider my reasoning as well, before we go forward. Thanks, Lina