Received: by 10.192.165.148 with SMTP id m20csp494458imm; Fri, 4 May 2018 13:50:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp9eEkWrxjNhH+HqB8vE/oX7h8QI8TLqGamPxTgTmHpaacKXFzx3amb0u8L66oPDxOyf6n/ X-Received: by 2002:a63:6fc8:: with SMTP id k191-v6mr23484166pgc.330.1525467049267; Fri, 04 May 2018 13:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525467049; cv=none; d=google.com; s=arc-20160816; b=HwLra0qqMi1yKql4PKiUPl8czhmuecAyXBt06HzeBuq1zb7ncUMO6XDD3iBZneMnZw YkkIrFjxxnyli9V6pxUN7PZT/YEQfwlXZ8UNQazlKNCGYSVkuQHlebfw/aC+MbB91lzb kZ8mB+z/o9UVqkPu08h4odusvf3581puXhqjXjmRD/3Ha9vlpIyTURcg4ujkFqkJsKCL kIAOnY5+vyYmGnrEerumetfclT0a82CHimqJTJwcSVS8gKo3KPSW7/EKjuUs1G9eapJQ 0g4/FYuPwlpY1qMj0S4yibzjluqmX8+O4E0MCdmSrJVBZLLpgSlHbRr7Iu8dQgTY3uGL RCnw== 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:dkim-signature:arc-authentication-results; bh=zhkuoa9rFpOB5RqPLued7Gfy1AXKTvOHBfZBBcCRSZA=; b=u05/dKKuakMMPw5BcUyXc8OBrgSxfYvUS6ervfu7jPLY0i38QnigwakE+jsLXlx9Z+ SUmISc3eWgXtSAPoq8kzl149U/+H9g1DxGd9zhroU11VIk0lHkTqQpbnrjgenc5usgcb /Yev+KHFxzknBm2FzDgP9mOOsFRy52SRKkFrnoWzgs7kUxYTt1+I6Un32lKMqiXifsHW BRn+60KBfoZddQ82+N3oN6IkLPOoCAwRkznwb60OsV3djaWmzDalXzLkC3j6q/GSfMcg 8NQRRifme7RJU4NJNS+eOfDgp0ZYkB6gFVT4vfM5yR3YbAJ023cbB/1ajE59AyOUwTw1 k6WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KvTbyDhC; 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=pass (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 63-v6si16912228plf.524.2018.05.04.13.50.24; Fri, 04 May 2018 13:50:49 -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=@chromium.org header.s=google header.b=KvTbyDhC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751796AbeEDUuK (ORCPT + 99 others); Fri, 4 May 2018 16:50:10 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34258 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751769AbeEDUuH (ORCPT ); Fri, 4 May 2018 16:50:07 -0400 Received: by mail-pf0-f196.google.com with SMTP id a14so18341172pfi.1 for ; Fri, 04 May 2018 13:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zhkuoa9rFpOB5RqPLued7Gfy1AXKTvOHBfZBBcCRSZA=; b=KvTbyDhCjuoWDlPtrvUIjwptvxljXwjb38apZZGWW5iVeQAF2/gsmFCY7EhCwtE2fg UxMpxMJPdu7WCV16dm2iTLvNbjviyIOp+Uo1pRU1MD7zSk81xHrr7oEx7JWL1ZCL8Nr8 B5aJpxFpRVsEwjMoxFPe/q6z8jVDDEY5mqPKk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zhkuoa9rFpOB5RqPLued7Gfy1AXKTvOHBfZBBcCRSZA=; b=Bp+Eh5S2mOEhHT+AgPVRcDp3d7ig5/re/gIwibOVNNf28yCMDG3cdERvd1nRK5yt5Y 8minV1S2uXQRCKSSYLMfpRrjz1R/+pHIug/AKaXwnKGLZm+iQCCuMETCuEEUxBCLz6kI +/rzqsiTCMnOFfbvoId5XeOTcvGYIvo2WRcwVUxWEzRsiVO09GOJLj06yR/xQW0uLzCy iUE3be3ZsRCQ09EvXghWWvrGYNUa9alw0/WnKHlljaoVxBTTZz8EiYyLtdwl1kTXnfSc KaNsgteYq5ujkCiWx+kr2AHWKyKmUxSMgo7cxuVseQ+RTABnwJoUtbS9WxfMKZE5iOCG ePYg== X-Gm-Message-State: ALQs6tBvML1gT9iGNEz3pFzb5T9e6uQIPD8F9eEr2+73t4DoVE0OVYoW NgjhcNUWKAtca290Tz0a1TBbKtvJzGM= X-Received: by 10.98.14.83 with SMTP id w80mr3835438pfi.236.1525467007004; Fri, 04 May 2018 13:50:07 -0700 (PDT) Received: from localhost ([2620:0:1000:1501:8e2d:4727:1211:622]) by smtp.gmail.com with ESMTPSA id 70-v6sm26323257pgd.75.2018.05.04.13.50.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 May 2018 13:50:05 -0700 (PDT) Date: Fri, 4 May 2018 13:50:05 -0700 From: Matthias Kaehlcke To: Doug Anderson Cc: Lina Iyer , 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: <20180504205005.GC19594@google.com> References: <20180502193749.31004-1-ilina@codeaurora.org> <20180502193749.31004-5-ilina@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 03, 2018 at 01:26:07PM -0700, Doug Anderson wrote: > 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? I agree that the list doesn't seem to be very useful. > 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(). Actually adding a lock was my suggestion, but to protect against another race that is still/again present with your patch: > if (!rpmh_rsc[i].drv) { > rpmh_rsc[i].drv = drv; This could be executed concurrently with both/all instances seeing rpmh_rsc[i].drv == NULL and then clobbering each other. > spin_lock_init(&rpmh_rsc[i].lock); > INIT_LIST_HEAD(&rpmh_rsc[i].cache); > return &rpmh_rsc[i]; > }