Received: by 10.192.165.148 with SMTP id m20csp4485022imm; Tue, 8 May 2018 09:09:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoBX6FF8sWhBKentDle+JXhMbl8xl0NOycFBQva6X0msH1RlBpPOvEMZwFDqJ7lPawj8nDX X-Received: by 2002:a65:5183:: with SMTP id h3-v6mr32622236pgq.58.1525795780961; Tue, 08 May 2018 09:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525795780; cv=none; d=google.com; s=arc-20160816; b=UfxyGCNcMxiI+I6+ga1H45EzPEMkoG5tfG8SgtfnqxiewEGkCCIRGCSLzv5dsNWULG zznik3DWPU2paw8Z/Y1FEy6oY7DmAOq0DZv57GHg+eWtLl1Q+3JMkWVhE1aTSirl8eyQ MMzSIrn24vPtesd56uScvdk9IvnXpVNU6E0pGsjZ7evkd7BGjmprModqTW9csD+NxobA akH84lqKgD/kXsuDaHyZ50/uYFsMewtKxnVykNgydHvq354R1urSgmp9YkSViCnPGDTQ yiqNBMGEf9jSpg6QjZ50+rgm1biTUQ9mObUwxu9Zh3CYhhyaT56mATcAoux1FNner9iA PT/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=m+b7wu2isRhrS6RnT8QWtqmsnjuNCzcrByFofFd/SaQ=; b=1H5JPTUsmHEEEQrgspzwwvkZqaeoLKsTH03b/N0rDy8bbXJpEBSHIFdvmK+uFGh9z7 JK9rD0ruD4piggfY+MHJEz9oPMHVyvM5x6jTTXA4nJu+bjLSGkGOTQPEfaIz/Gsge0KC iHt0HCIdwQWvbFOqpAV1ZPmXKa5ys8qBw6Re05lWIDN0bIUZV5h++fs5uvI/a7j7MtzM hFEsNSZDqLm0XdxchG+8wdRoy1HAn496XojrUtAoin0vLHRXX7ZHUM1cco2fX+VuVB5n vzuhg2Wten+wXOB94KD2vkYXpwB2f4Hha5C7Abs3vGfPjyAmZ+kOj/lQDv1OpVrZXp2i EGRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=jr9u7Ei4; dkim=pass header.i=@codeaurora.org header.s=default header.b=PyH1MK6v; 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 k4-v6si9205261pll.118.2018.05.08.09.09.26; Tue, 08 May 2018 09:09:40 -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=jr9u7Ei4; dkim=pass header.i=@codeaurora.org header.s=default header.b=PyH1MK6v; 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 S1755432AbeEHQFN (ORCPT + 99 others); Tue, 8 May 2018 12:05:13 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:40504 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754920AbeEHQFL (ORCPT ); Tue, 8 May 2018 12:05:11 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 1C9F260B23; Tue, 8 May 2018 16:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525795511; bh=+HAQB+xG/PXSeblhmCdxwvh3yck3ctW+EaYyd7UtZYE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jr9u7Ei4USP7hllZQzhtVXhQVQ0DjzhTv4md9Dw9XkkkJmeTUL8nbSDm09r/UBr+b lYq9MgMOUo81z2/TEsGAnxzPfOGTMdkRrK11OMIHcKTq2k3OvhQAoEzcZY3odnQLL3 Y0jhoyly5CQRXfZycdmoE9VnVAxB7JzfRZf34qME= 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 mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id F246860386; Tue, 8 May 2018 16:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525795510; bh=+HAQB+xG/PXSeblhmCdxwvh3yck3ctW+EaYyd7UtZYE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PyH1MK6vlbFWo4uuft8T7JLUs/lUr6DLU3XIc+zMQ09OuDP324LCTb9ojKvdg+4mX ZBjL9LWesveCnFvYhT3dMiO21g5h4EGm5MKwQKp3ivYdCa4tN0n7ocY+rPo5k2lqkk 0vR8l402hUbBvwB9clusHfpxWDl06I6ArN3IwK0I= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 08 May 2018 10:05:09 -0600 From: ilina@codeaurora.org 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 , dianders@google.com Subject: Re: [PATCH v7 04/10] drivers: qcom: rpmh: add RPMH helper functions In-Reply-To: References: <20180502193749.31004-1-ilina@codeaurora.org> <20180502193749.31004-5-ilina@codeaurora.org> Message-ID: X-Sender: ilina@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > 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. Thanks, Lina