Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp968879imm; Tue, 3 Jul 2018 03:16:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeX6KIXfIVU8edfh++gJDH226Wq/NoIoXZCV4joJaGSOXJvQSOQ10/VszA/WvoESvbYGYou X-Received: by 2002:a62:2044:: with SMTP id g65-v6mr28956708pfg.40.1530612976037; Tue, 03 Jul 2018 03:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530612976; cv=none; d=google.com; s=arc-20160816; b=b4z999goCQEf2za/VZl1EV7NXlzLrca2mUuvLSqHAULML8J6/N2uUepEM5fh3vPU9G KuEnixlyDIZKGef8Xv/3NtgZbd1WtfzO8PMBYTEQH5YtxDrTknPIhb+PielzouOX3d/t PvtKlw4Wf1ccVxcVNfTnek0r/elk1RvFjp3n83tYavD8tCuF4ujJm6DcZuAM1jhDpgmu UuyAOKzjgLB3hrSr6mbiREWx0/72wOUmfHrwD95ZSbuCxvlMCuNSEgKG8bVX/3dHyODm 5TWwwRUVrlEm2xO/0KEuZu5HhYYXfn1mZEudS5ytJh3k5lwrR3TQIGbG+QXRzKG4lvaS QYCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:arc-authentication-results; bh=EiwHKfSzIvR9rK5eXnKsGb035e/axfazoZ+21J3PVOk=; b=sLHXNXeiDYmkBTQNBDUgsoU22AovC41Qw9OtoXr70KBEmjHathjhEaVTW+1zNMt6LK tCCQ101JxmLM/ZEfUOishigIrclW1WfdaXD60tp8N2HfsHAz2ePAxHN2ht0v8TWbfqYl jeEAtxMzdLMfna5ZIiV5L5zmqjRRrFbwVIGr1+G67ZooAMDTV6ebt9gcyp/UYleXy6D/ FbtJkTkqvp9QYWL/nhoveWbbNasCMW3NjLP8XHoNh9MwGPHYjd08TwSMcaj4iaTcqS+o Jr5t0XFnSjsmAlibqDFzKk1FrP2Y2SPBM1Kojk/Oa0M1eNzRcyo5m9l15aQW6Mdimi4O kLSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VGGqe4ev; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r59-v6si765003plb.314.2018.07.03.03.16.01; Tue, 03 Jul 2018 03:16:16 -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=@gmail.com header.s=20161025 header.b=VGGqe4ev; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754722AbeGCKPU (ORCPT + 99 others); Tue, 3 Jul 2018 06:15:20 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:38432 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754673AbeGCKPS (ORCPT ); Tue, 3 Jul 2018 06:15:18 -0400 Received: by mail-qt0-f195.google.com with SMTP id c5-v6so1026499qth.5; Tue, 03 Jul 2018 03:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=EiwHKfSzIvR9rK5eXnKsGb035e/axfazoZ+21J3PVOk=; b=VGGqe4ev1vbhdBXQbsyB9enTWz4J4bNWvG5WIfL/7EFIsWBQLwOzVU/u4l3lYRLxtQ /t6dOo+STB3cW81hAH/Wl2W8Y0nVXnMv4L/sffBMAQo2Hppt0oFPcYjDzvPDR2CrUYBN KurxE45JnA4ES06AJAO418t5Ax55eJJE52FTtCjHbhZY+sPr2XYqE8b0Glptglvm1sDQ q1N7iJpcx/svk325zpXQP/NYqpSD43XbaYUDy5RMpIajmYFFu/WoDzu9YV14fyE6302S 5jE6V86WimGFtFo3ZdkWRhcXkQqQ7x2TOMkjN6oWqXSBFzpXSpZhF3OXLcyyg5UOypEQ sfTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=EiwHKfSzIvR9rK5eXnKsGb035e/axfazoZ+21J3PVOk=; b=FVqDHTf/hMlqtfI07Hl09X80pKwl7IpMABJLE8keE02M+xGd+QqlArl9U1A1ccbmbE zCtAJbFUPEtDruGF7oNPUDq0ZP+crxbgVMRu8f/4czuh/K1Yzp7n16IlY0uLdLOORQBk dz2KPq9H8gVbro7eKITpiYPpZPMNcDMzmN075GhfSFbGUngg19oizT8zcyx2biwO5Upf 3ffU9MzuVkDxWouyjzD8ZMXU/icWoyRyD5oFyOubGtuD02ubSCpXzO4OQQpLfG34D6zw w/3lav5F/YvqQOO0o5w4mfIG3XemRx+zXWEriOemLlajKwq5R3hC7IntzU2ZYf0G/3Oh ONlQ== X-Gm-Message-State: APt69E0MqjgQPhcz363RHFn+yLr4qgEc8W7iQgnS836JUiYyM0VRMqyY eHuEWGKOOBAISDXZNCETxFWyoToHb4FUQUbr4TI= X-Received: by 2002:ac8:2dc1:: with SMTP id q1-v6mr10886502qta.219.1530612917094; Tue, 03 Jul 2018 03:15:17 -0700 (PDT) MIME-Version: 1.0 References: <20180621220430.25644-1-enric.balletbo@collabora.com> <0383b4a703a0b619023c0654a4a7637419c72ebd.camel@collabora.com> <1e792d3c972998f92109c127886243e32c4cde71.camel@collabora.com> <7c67974e40afd15abfca5907b27de097@codeaurora.org> In-Reply-To: <7c67974e40afd15abfca5907b27de097@codeaurora.org> From: Enric Balletbo Serra Date: Tue, 3 Jul 2018 12:15:05 +0200 Message-ID: Subject: Re: [PATCH v3] PM / devfreq: Fix devfreq_add_device() when drivers are built as modules. To: akhilpo@codeaurora.org Cc: ezequiel@collabora.com, Enric Balletbo i Serra , linux-kernel , kernel@collabora.com, Chanwoo Choi , Kyungmin Park , MyungJoo Ham , Linux PM list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chanwoo, Any comments? Just a gentle ping to make sure the parallel conversation regarding the mutex didn't distract you :) Missatge de l'adre=C3=A7a del dia dv., 22 de juny 2018 a les 23:22: > > On 2018-06-22 22:43, Ezequiel Garcia wrote: > > Hey Akhil, > > > > On Fri, 2018-06-22 at 12:33 +0530, Akhil P Oommen wrote: > >> On 6/22/2018 6:41 AM, Ezequiel Garcia wrote: > >> > Hey Enric, > >> > > >> > On Fri, 2018-06-22 at 00:04 +0200, Enric Balletbo i Serra wrote: > >> > > When the devfreq driver and the governor driver are built as > >> > > modules, > >> > > the call to devfreq_add_device() or governor_store() fails > >> > > because > >> > > the > >> > > governor driver is not loaded at the time the devfreq driver > >> > > loads. > >> > > The > >> > > devfreq driver has a build dependency on the governor but also > >> > > should > >> > > have a runtime dependency. We need to make sure that the governor > >> > > driver > >> > > is loaded before the devfreq driver. > >> > > > >> > > This patch fixes this bug by adding a try_then_request_governor() > >> > > function. First tries to find the governor, and then, if it is > >> > > not > >> > > found, > >> > > it requests the module and tries again. > >> > > > >> > > Fixes: 1b5c1be2c88e (PM / devfreq: map devfreq drivers to > >> > > governor > >> > > using name) > >> > > Signed-off-by: Enric Balletbo i Serra >> > > om> > >> > > --- > >> > > > >> > > Changes in v3: > >> > > - Remove unneded change in dev_err message. > >> > > - Fix err returned value in case to not find the governor. > >> > > > >> > > Changes in v2: > >> > > - Add a new function to request the module and call that function > >> > > from > >> > > devfreq_add_device and governor_store. > >> > > > >> > > drivers/devfreq/devfreq.c | 65 > >> > > ++++++++++++++++++++++++++++++++----- > >> > > -- > >> > > >> > [snip snip] > >> > > - governor =3D find_devfreq_governor(devfreq- > >> > > >governor_name); > >> > > + governor =3D try_then_request_governor(devfreq- > >> > > > governor_name); > >> > > > >> > > if (IS_ERR(governor)) { > >> > > dev_err(dev, "%s: Unable to find governor for > >> > > the > >> > > device\n", > >> > > __func__); > >> > > err =3D PTR_ERR(governor); > >> > > - goto err_init; > >> > > + goto err_unregister; > >> > > } > >> > > > >> > > + mutex_lock(&devfreq_list_lock); > >> > > + > >> > > >> > I know it's not something we are introducing in this patch, > >> > but still... calling a hook with a mutex held looks > >> > fishy to me. > >> > > >> > This lock should only protect the list, unless I am missing > >> > something. > >> > > >> > > devfreq->governor =3D governor; > >> > > err =3D devfreq->governor->event_handler(devfreq, > >> > > DEVFREQ_GOV_START, > >> > > NULL); > >> > > @@ -663,14 +703,16 @@ struct devfreq *devfreq_add_device(struct > >> > > device *dev, > >> > > __func__); > >> > > goto err_init; > >> > > } > >> > > + > >> > > + list_add(&devfreq->node, &devfreq_list); > >> > > + > >> > > mutex_unlock(&devfreq_list_lock); > >> > > > >> > > return devfreq; > >> > > > >> > > err_init: > >> > > - list_del(&devfreq->node); > >> > > mutex_unlock(&devfreq_list_lock); > >> > > - > >> > > +err_unregister: > >> > > device_unregister(&devfreq->dev); > >> > > err_dev: > >> > > if (devfreq) > >> > > @@ -988,12 +1030,13 @@ static ssize_t governor_store(struct > >> > > device > >> > > *dev, struct device_attribute *attr, > >> > > if (ret !=3D 1) > >> > > return -EINVAL; > >> > > > >> > > - mutex_lock(&devfreq_list_lock); > >> > > - governor =3D find_devfreq_governor(str_governor); > >> > > + governor =3D try_then_request_governor(str_governor); > >> > > if (IS_ERR(governor)) { > >> > > - ret =3D PTR_ERR(governor); > >> > > - goto out; > >> > > + return PTR_ERR(governor); > >> > > } > >> > > + > >> > > + mutex_lock(&devfreq_list_lock); > >> > > + > >> > > if (df->governor =3D=3D governor) { > >> > > ret =3D 0; > >> > > goto out; > >> > > -- > >> > > 2.17.1 > >> > > > >> > > > >> > > >> > Regards, > >> > Eze > >> > >> Adding to Ezequiel's point, shouldn't we take more granular lock > >> (devfreq->lock) first and then call devfreq_list_lock at the time of > >> adding to the list? > >> > > > > Not sure why we should do that. devfreq->lock should be used to > > protect the struct devfreq state, while the devfreq_list_lock > > is apparently protecting the two lists (which seem unrelated > > lists). > > > > So, the two locks are not correlated. > > > > Regards, > > Eze > In governor_store(), we do 'df->governor =3D governor;' without taking > df->lock. So it is possible to switch governor while update_devfreq() is > in progress. I smell trouble there. Don't you think so? > I am assuming df->lock protects 'struct devfreq' and devfreq_list_lock > protects both device and governor lists. > > -Akhil.