Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp67485imm; Thu, 10 May 2018 15:38:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqcjphDquO0yNVXYoLJkDk2C4ZNpggSF6reQe8join3RbJtrYatai1j/V/ppFbvmQ4Y69kd X-Received: by 2002:a62:230b:: with SMTP id j11-v6mr2982496pfj.177.1525991906663; Thu, 10 May 2018 15:38:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525991906; cv=none; d=google.com; s=arc-20160816; b=nNUncaZ0Nu87EIrux1TyAbFLVw/3fl0OFWBTV9sndw44uJdSZTkg0SGePB6x3Yz5Qn xHS+ctkTTbOGpMl0oqj6kMePWwM2/EWevFJEV1OcsodJTStecGMymv30RNiC8Du2h3wd ecR/oQlDYBI2FQ/yFW+7a8cx9FNDO2ObpAo2wQyNaDZvJN9neFWlP2gG+BMjgLFQx/CI GBSJrbNWkTTeX7Ofwpy6IxRVVlQbKoaibcAjZw0VuGrdy3YlXGNsN8Q42Xg/ccsyoKZo O88WDb4cOyEOqQxlWTC5x7BRrTmMRNL51CR4HAWVly0wCM38uO88Ue2Cw0gXJyi/f0by 5jcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=+/7e/mQY0uD0KL5yCpJoJgzXqiVofP8zMg5pNIrjWhc=; b=ugYOzc4a7QJXCNlOp9B1WsFYfg+BmiQMToWhKpmNgviSktQYy4YjcfIUErjbtRc4ig tJiVubPHnaHVBrxuKhok/J1Dno9uLdmzos5uEz2HpZHL4KfvHu4KIgNwRIyk114gFdaK XpkSkjBMrXg4MC4FgSbZL4G3KzOsWOzyCxTgzWIxSkUJ0mSdEFRRnU2jpPOY2fJoP9F0 7cRX7MsoCf9PqoJhg0QclcQ2OrN50r45EwMfoiA27YTNbWc1j4ftbDc6qjdJGbkEzaBE c7MJuoVP7siEKvmv6svr6sMxouXCb38GL4qLdZRxb9QO+1JLkGm1PpKIiZt6ibarW50w LBBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=wD0qBdGI; dkim=fail header.i=@chromium.org header.s=google header.b=Z4Nck6TW; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1-v6si1595683plt.316.2018.05.10.15.38.11; Thu, 10 May 2018 15:38:26 -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=fail header.i=@google.com header.s=20161025 header.b=wD0qBdGI; dkim=fail header.i=@chromium.org header.s=google header.b=Z4Nck6TW; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751217AbeEJWh7 (ORCPT + 99 others); Thu, 10 May 2018 18:37:59 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:42171 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750746AbeEJWh4 (ORCPT ); Thu, 10 May 2018 18:37:56 -0400 Received: by mail-vk0-f68.google.com with SMTP id j7-v6so2172837vkc.9 for ; Thu, 10 May 2018 15:37:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=+/7e/mQY0uD0KL5yCpJoJgzXqiVofP8zMg5pNIrjWhc=; b=wD0qBdGIpdCyP8qbgZEMBxdtZiupalspOfBdwmOTTf2F/CrW8ZcfOXqG0D6ZXC+i3N Ntl+TQqNH78Cyht3Qnfbbp/pqULZeLvtIldOs5kNdTV9YCUd2PSa8kpdTAuM/NB2TN/F drasq6LDP36lv3pa80K6c0VeEq7EJ0DelscqxBqyIeMfkgxmpGeLYm0AYX6YZ9ULo7t1 R8tIL+pr7e4C6fCq9XFa6KoSEHje8UOXSFbGj/czG4KD4Wh1AAr/EV+OLmQo8Wwpwd0e JkpgDtAcRVZLEjP4JvuxBRqiUCO9QD5oqVeAR63IvijYuHXP+/EseCh/0p0OxOSaNi1q g1ZA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=+/7e/mQY0uD0KL5yCpJoJgzXqiVofP8zMg5pNIrjWhc=; b=Z4Nck6TWnAkrUhMKaWgcUPtw+wylQEu1UkPwZLqwMsqhcat9DM9c3ny41I76hdQSw2 PhG+IYYWq15usCEA3LaqG1ELyPu7Tp0B7PxNEPH76ww0q1Ak3Eg30QohLa/zsuvTvA03 /rt70TvmTYGt5fuAVujiR5VJBpl2MwSpF59l8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=+/7e/mQY0uD0KL5yCpJoJgzXqiVofP8zMg5pNIrjWhc=; b=fd2EYLotLrrV3PZb4yzn9YzW1PzuMYTA35VpXHw1fmCZHU+3U3nMGhZaxvdttrs3UV YlxjrxTwvRXZ1vf7fNm5HqlraGoJBG007E3mwz3YqMk6vkgYvddThwu13GZWxKwZprT5 bC/GYfX0Lq1s5grbuxFz01lqbSEbaVL9sRPjiAp/NAB4s07rQIzAl9TzzcYiAeOU/v0d Fm08swRUcbJneeMqNyou62W5EhKnYlk5dDQFb8sF6NRxAzDuvKGFO+UqOKuy3mq+3Rvk ePBfNLMsh/uKZr2b/+8UzLE31xdJ3ydWgfWqnCj4mbwnBYWwT2cDewOrwTXaAqnUNJjQ rfHQ== X-Gm-Message-State: ALKqPwe2BVPgO6541T+qYgwdBD5VW5HhaxGu6vHwgVvkiFs1mjUmsoUe JLMxze0q5/M8SziOUagxFkiX0s/gNqYYyo/EX4Z2lw== X-Received: by 2002:a1f:1e04:: with SMTP id e4-v6mr2258625vke.117.1525991875433; Thu, 10 May 2018 15:37:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.48.82 with HTTP; Thu, 10 May 2018 15:37:54 -0700 (PDT) In-Reply-To: References: <20180502193749.31004-1-ilina@codeaurora.org> <20180502193749.31004-5-ilina@codeaurora.org> From: Doug Anderson Date: Thu, 10 May 2018 15:37:54 -0700 X-Google-Sender-Auth: aqXToxiUp9zo3vSfzQ5nIPJ6kQo Message-ID: Subject: Re: [PATCH v7 04/10] drivers: qcom: rpmh: add RPMH helper functions To: Lina Iyer 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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'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. -Doug