Received: by 10.192.165.148 with SMTP id m20csp2271687imm; Thu, 3 May 2018 13:27:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoj96iUUVjTRnDvJ3P2wqDLy4p19kCgRB5NncMmPrwZm+BUmt3lySFDjZBpvmdxbrBOAF38 X-Received: by 2002:a17:902:5597:: with SMTP id g23-v6mr25298072pli.347.1525379222606; Thu, 03 May 2018 13:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525379222; cv=none; d=google.com; s=arc-20160816; b=Lq5m9wCIgOmGKFTGo/o4SimpnD5wYyIx32NKLls+28/gAqnPeS9+anqCJbbZbrJKo8 DowjV66et2Go8Uu6sN5/lLSgNtmdhaprsIdnl0ny2Atm70IbeJbtXysT5ZzlOtDW6TW+ I6HW8Onf+GukSEIwI/BDiOpr+/R9wJwrbLTk7E8Q5j7O6CDStNrnKfDX+ZYxxdB0kCtW EbgTGw3ouQrPaNr+UV4gjcRXvHYos8xKivqcm/ueYHa1+GuB5nm3xzBWq5vV+z4ya5xf eJOJUZEtUDFEFQPbDi54LvT9bZ+792O3zyS5PGv3Q7KKovB1w12f5vlga9+o6+O2bUue J5/Q== 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=EZGtGFN3T3Er64VX+fhjZdgS9/6d1huBdtiDb7rblQc=; b=YS3d97rMU6/HLXZSd1gL589n/plTrot1V96OJTmNPoo3+ecRoxLRmG0C4hEvkdqcwB arBrne+DxaG3udc59W/UuWZ+wAuvSXhJQAk8KoLV8nmH7mviF2iWNm9lAIFFrnwDjqvi XCBs+mZhMXL91tXZgEzbCGTcgeYbHEkeaJ6jK901+KkY9tbfj5iOgJTu4vImftAzgn6a WLigY7vMZDbsR4ivX55c2B1pcx+J9PJQdqS6MuZbIoc3Fg+Mru9if9Gpr2gxZKzvfOA8 pt/il+8CcdwJVd1H/gdA9eh2uZTiBSatfRFHPvbBXm5Bu0WQT60Rc0YJ4SqrO6Ie3BVQ UwRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=me46pMEj; dkim=fail header.i=@chromium.org header.s=google header.b=SJmRpKeV; 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 t135-v6si12036215pgc.656.2018.05.03.13.26.47; Thu, 03 May 2018 13:27:02 -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=me46pMEj; dkim=fail header.i=@chromium.org header.s=google header.b=SJmRpKeV; 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 S1751464AbeECU0M (ORCPT + 99 others); Thu, 3 May 2018 16:26:12 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:42637 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750911AbeECU0J (ORCPT ); Thu, 3 May 2018 16:26:09 -0400 Received: by mail-vk0-f68.google.com with SMTP id j7-v6so11944055vkc.9 for ; Thu, 03 May 2018 13:26:09 -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=EZGtGFN3T3Er64VX+fhjZdgS9/6d1huBdtiDb7rblQc=; b=me46pMEjvOQ939MFUK8erL+KURYF3NeI3oEc4g/cKhj1q5psaiSezvAu71KJrzeudT aomT94U588Vc5Z1Qw6pR6raXIhh0A2+mJ4O5ArrO2xBDdMMeLL5/bl3m+YYeiCFoNYl+ KgIGaJ7TaAm8kSDJwAsNc2TQb8fpn33e6fURapPopMS1tKCMHIQEYcyV1X+3WJYlmZSX w29HMz5WR0/2yJT0UYCkxvFR58YXy62OX7SzAlZL2KGxpbiwcrY7Xjw8NemMw4PRBaFe UEwK/AvRd4hHUoBjCrcPqhKXoPYQ8Jd8BJ8bTfN9y9UhsLK6vpNiF5yYF4DJzCDRaD4c Ejrg== 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=EZGtGFN3T3Er64VX+fhjZdgS9/6d1huBdtiDb7rblQc=; b=SJmRpKeVZy4P9/BqswHMurWSJWAtvA2pr8g2WmsxxE5DewQ3+2Bkf6kCkUBwuR46fe xJsQdwYarwFEf92bb0e3fnCnzn3mD46HTgh6Y3X9TisNEtG+2CqCuHIViqvozeKBGFPY LSy7kOO8Dr+rJA0rtvb99//q2w6uCW9JL52Sk= 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=EZGtGFN3T3Er64VX+fhjZdgS9/6d1huBdtiDb7rblQc=; b=LnvEUZcdFg70UJsbDVh/nZDH4NYDz5FAIluQOfS0iRLtjjDBwe/uXOpYNklCJDSnFw dcuw53GYkgSg7oai3j4hOf6MXFyeVYRaQ4h+GLgVA0+Xu2ohGZHCsGZI4/zV8mimrRAz BaG72lpEWLiz6qfBVbGh5qQtX4DlDxyqYnQCRj9NMDpa0RuAIbl4yWPniQy9dg15lNHA YoruK3VgTdwrTIRZjqvVf7pdf7mMmmJFskQcnINZtX7g9OS3zsial/D9TasraX/pXrcX Uctecfd+ELmihgRclXpECfis7PCIXvTpqws0BohAULpko8Aq0RkCfISThVxf0zDwJgV3 HBaA== X-Gm-Message-State: ALQs6tCribIoEW7G9oc0UfvWUxI2pRAxoYn1fyBwdGkESC2SH+zWs7na +1EQtuXg5YCQJaRP43ZfohwNHAjBP6PhfF4I12c5Cw== X-Received: by 2002:a1f:8a8f:: with SMTP id m137-v6mr17677256vkd.90.1525379168390; Thu, 03 May 2018 13:26:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.48.82 with HTTP; Thu, 3 May 2018 13:26:07 -0700 (PDT) In-Reply-To: <20180502193749.31004-5-ilina@codeaurora.org> References: <20180502193749.31004-1-ilina@codeaurora.org> <20180502193749.31004-5-ilina@codeaurora.org> From: Doug Anderson Date: Thu, 3 May 2018 13:26:07 -0700 X-Google-Sender-Auth: -F14cquRcejZH_PP8bZ9N9HzczU 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 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'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. -Doug