Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1262273imm; Fri, 5 Oct 2018 23:12:05 -0700 (PDT) X-Google-Smtp-Source: ACcGV61oIC0+O4VVkIWOU1gaDgBeEoo3ZyIz4Cm/0rNl9aQ1HjXzOW1Ma5WhtFfqJiRKZPEokixp X-Received: by 2002:a63:6f45:: with SMTP id k66-v6mr12577602pgc.360.1538806325136; Fri, 05 Oct 2018 23:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538806325; cv=none; d=google.com; s=arc-20160816; b=b8ICFju9frcvGPLqXz9vw0Ctg3U0vFYu/4igWkD9PjOvjIQztk18FY+XtnmjyySddJ oz5/PJRupTjjbuJiDR+q6nGC0ERicobPQ3YmSdibrJiMV/slhdFSXm7huwed36ImTqQr 9AVwaHokxoIROKr26PcWsHN5fXsxdOjGh/ioYep5Ai3t4X0Hu3DraCiFR8IRk3fkp3Ge Z622ukujv8TVEyx2qjIf2PXX4l5Lwle8Ore8ViJzoqbHo3vDS0WEehBN089EqzBGc92O NtIwehaTWcG8MxjuEMMw1Bl6xUlQTaTDcBGK5fGvqDE3kE8gHZjaAQu2KL6QTrZeo22O W0Nw== 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; bh=eXyUJcxUKxIfZ18D8V9yTL19MJVlzPeToQWLyuw2dLo=; b=RssA52+L+GIQ3OV219zHBOlU4C/2vLniOw18Jaz7h/tZ5ZCZEzE7n4cs8UsHUGM/Ps 4t3dmjTBfeKL9/e9T0FaTu4KuZwZOjHH7vFB0gMG4vAKudEYp+cK78oBSqubIN1mADfD 1CyFV4CX3JP/5qCfF5FDWf3xOXD05wTPwcwOnqsTdBa6470fJN660d4S0giuw29/N9JO abgkcNRemzF+ZsMfZNWtljJ+DUl3JneUS5tNZu1fGyL1WGAvRe/IrSIMXgE+d3uSyFo7 qeQuhRaCHAZqBdpZptRcqmLs8OKm6rn+QdcH9SwAO6fei72wuGM5uWuqBrq5Fm8/6sqN OfSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iFwM3fPW; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p71-v6si11201392pfk.275.2018.10.05.23.11.19; Fri, 05 Oct 2018 23:12:05 -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=@linaro.org header.s=google header.b=iFwM3fPW; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727788AbeJFNM7 (ORCPT + 99 others); Sat, 6 Oct 2018 09:12:59 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35018 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727606AbeJFNM6 (ORCPT ); Sat, 6 Oct 2018 09:12:58 -0400 Received: by mail-pf1-f194.google.com with SMTP id l17-v6so1661441pff.2 for ; Fri, 05 Oct 2018 23:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=eXyUJcxUKxIfZ18D8V9yTL19MJVlzPeToQWLyuw2dLo=; b=iFwM3fPWPv0XeZt6QT+qdKCokT8wjzO4AW3KIO1uv3kDGiEYLDKKpEfz9o5UyipxUA W9n73mqfniizW3EmMWxN3TjvQ0fk4ao94XQYrY4zM3y6PnGGvH3YvTQwZ/m9z6D05JNJ xrWZOfPpRx3s1V6320KJsWpciKAO2FDmv7IVo= 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=eXyUJcxUKxIfZ18D8V9yTL19MJVlzPeToQWLyuw2dLo=; b=jwgcG4lzwDg3nqIdjNuwdNVRHsgyndUSWEXpT9HMmdaQPYYF0tJE8Ef+8KrIYjGhhJ fKDikDMhkITt5PEky0n5ECzZALrV5gtAdnWNP6rEZcmdZaMo1eX+G8bFIqsCWZiCFz2V vrDJI22p/BFohWVeeH6iuH72mPrmYvemSokUVPMWhodN2nbniK+tALMvFrkeKrkesN6m 3NvAIZ0LWGSENCY0UvoeXurdYpE07BCRk1xPib4p7065tj1rRvMds8+BOdIW/vuk7aRP C2Y8g5EgQ33H5pKzbWT/DGhPOyln6bxVvfOuP4oXnPOfunhLs5L05mFlOO62gh+pVYWU B/QA== X-Gm-Message-State: ABuFfohddadSBqgGd65lmjqfGY7UK0SJtCS/zKXCmsOc8v20sBR5PtAG OtKWAHOJA00XQHskeu7YfARA+HvKbmPMXQ== X-Received: by 2002:a63:4658:: with SMTP id v24-v6mr13112631pgk.425.1538806255625; Fri, 05 Oct 2018 23:10:55 -0700 (PDT) Received: from builder (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id j5-v6sm10369705pgm.79.2018.10.05.23.10.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Oct 2018 23:10:54 -0700 (PDT) Date: Fri, 5 Oct 2018 23:13:41 -0700 From: Bjorn Andersson To: Suman Anna Cc: Ohad Ben-Cohen , Loic Pallardy , Arnaud Pouliquen , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/5] remoteproc: Fix unbalanced boot with sysfs for no auto-boot rprocs Message-ID: <20181006061341.GC12063@builder> References: <20180915003725.17549-1-s-anna@ti.com> <20180915003725.17549-2-s-anna@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180915003725.17549-2-s-anna@ti.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 14 Sep 17:37 PDT 2018, Suman Anna wrote: > The remoteproc core performs automatic boot and shutdown of a remote > processor during rproc_add() and rproc_del() for remote processors > supporting 'auto-boot'. The remoteproc devices not using 'auto-boot' > require either a remoteproc client driver or a userspace client to > use the sysfs 'state' variable to perform the boot and shutdown. The > in-kernel client drivers hold the corresponding remoteproc driver > module's reference count when they acquire a rproc handle through > the rproc_get_by_phandle() API, but there is no such support for > userspace applications performing the boot through sysfs interface. > > The shutdown of a remoteproc upon removing a remoteproc platform > driver is automatic only with 'auto-boot' and this can cause a > remoteproc with no auto-boot to stay powered on and never freed > up if booted using the sysfs interface without a matching stop, > and when the remoteproc driver module is removed or unbound from > the device. This will result in a memory leak as well as the > corresponding remoteproc ida being never deallocated. Fix this > by holding a module reference count for the remoteproc's driver > during a sysfs 'start' and releasing it during the sysfs 'stop' > operation. > This prevents you from rmmod'ing the remoteproc driver, but it does not prevent you from issuing an unbind of the driver - resulting in the same issue. I would prefer if we made sure that rproc_del() always cleaned up any resources (and stopped the remoteproc processor), but I'm uncertain of how to deal with remote processors that are supposed to survive Linux shutting down. But I'm also uncertain how we can make the remoteproc core ensure that no dynamic resources are leaked in such scenario. Regards, Bjorn > Signed-off-by: Suman Anna > --- > drivers/remoteproc/remoteproc_sysfs.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c > index 47be411400e5..2142b3ea726e 100644 > --- a/drivers/remoteproc/remoteproc_sysfs.c > +++ b/drivers/remoteproc/remoteproc_sysfs.c > @@ -11,6 +11,7 @@ > * GNU General Public License for more details. > */ > > +#include > #include > > #include "remoteproc_internal.h" > @@ -100,14 +101,27 @@ static ssize_t state_store(struct device *dev, > if (rproc->state == RPROC_RUNNING) > return -EBUSY; > > + /* > + * prevent underlying implementation from being removed > + * when remoteproc does not support auto-boot > + */ > + if (!rproc->auto_boot && > + !try_module_get(dev->parent->driver->owner)) > + return -EINVAL; > + > ret = rproc_boot(rproc); > - if (ret) > + if (ret) { > dev_err(&rproc->dev, "Boot failed: %d\n", ret); > + if (!rproc->auto_boot) > + module_put(dev->parent->driver->owner); > + } > } else if (sysfs_streq(buf, "stop")) { > if (rproc->state != RPROC_RUNNING) > return -EINVAL; > > rproc_shutdown(rproc); > + if (!rproc->auto_boot) > + module_put(dev->parent->driver->owner); > } else { > dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); > ret = -EINVAL; > -- > 2.18.0 >