Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1159027pxu; Fri, 27 Nov 2020 00:47:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIhgEuQvbrigH6ExQarJEJSkQ5QuJr28WeHo9F7lma4sRNt1GSlNlhqPJPiHuYl9As1DrK X-Received: by 2002:a17:906:3953:: with SMTP id g19mr6367051eje.151.1606466852086; Fri, 27 Nov 2020 00:47:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606466852; cv=none; d=google.com; s=arc-20160816; b=AYCVzZzUrvHMaT/s1+I56/1yczvCmN/wTufjHGetV2qvzkOVXIUtmflqwuHCLZN87G 5kHwMjhgjxCIb662Aki6Ounv0N1LSqwESt530catmNYk5aLC/hbeojBjX0pEYD3ZpmqI mTXMz/o1MQQ4ij1pcQ8Q9rm0YD/Uo5QkspxZ4TuA/nmBCDDCKmZdVf+Fh7EpUM+moBJD DHhKQU9r8WAwKXaekDMEsWDRB1QQaijQjHGq/uJnOomPFwIADts79NgrHhxtvYy5TH+y 3ze8SoSmFUch2j3PCxguYsdkaTDq8NhwFeocnNfPHx1+xAhX/nmcBbEi6SsXv+wbdkUJ L8lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wGSsT9seajVOjbFERio1tYJo2XEKlH2gqwsbWcXTilg=; b=T0Dncm60PpRRmnnkGA6QAoZdfW9LkeUKkrjN/FONWhlhhyVj2ePpdnYlikhskT5Rny BZNJqFO8fw0NhNtX2adLajDzdDvrFmWyBhDKboY+LgGHLUgtv1YUdQJyLnO/CcA8ZNvp B9tT9ntDuGaLoca48QI6+0bT9sim3xLsbFYiiuhH3Z7kQmGbzXaPUJzshxfsVxCByoeR 1KAKa4rlw/yMxDwzC/SC/tcZiAam/RRri8OfQZvNXO+Dn9tnt8SWvOGLfNdcxRj87GtH VIoC2mU7iP1rIW7JigQRF3GVJg2FUecSoWjeha5wrPe37DvGx0WCv5NRmQN5vptZhsLG dgLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KlSuraKB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id p25si1828810ejx.88.2020.11.27.00.47.09; Fri, 27 Nov 2020 00:47:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KlSuraKB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2391862AbgKZWbx (ORCPT + 99 others); Thu, 26 Nov 2020 17:31:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388120AbgKZWbw (ORCPT ); Thu, 26 Nov 2020 17:31:52 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9015EC0613D4 for ; Thu, 26 Nov 2020 14:31:52 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id t37so2706348pga.7 for ; Thu, 26 Nov 2020 14:31:52 -0800 (PST) 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; bh=wGSsT9seajVOjbFERio1tYJo2XEKlH2gqwsbWcXTilg=; b=KlSuraKBJnqVtHFjN5zwb2K/A/fQkQnDE3CeKNSueLqUuC0zIGUmM/8fD/8R71bvO8 SJRCjSRBqQ6ObpW0EQVC6wij8dF7lWrYzQi7a/QkGjgsoATLLueesnWYpEJvzX81tIOa gwlFEeTD5rt0Oci1I0X5fNOvijzzIKHY8AS6yS86IGskc20HAXF6RtDum2mBNEG1xNrI LhN/SD8r+Y8F5YKV+aYAf79VOF/5jH6oZwN8utNCeYrUt9Pm9qGkQySDE8svDZlw0u9r suHroQ1eQDh4Z52/BrrhMg/OhsRtbgZ+kWt5p7VPvWxZkHFO2kK+BdzlUywOOY1O9a9h oztg== 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; bh=wGSsT9seajVOjbFERio1tYJo2XEKlH2gqwsbWcXTilg=; b=FxG9lvWUhWMFHa8/ZZnDwk75jzBlNjX5GXcaMn+0XOVkK5npFJkD+LuaIKQo9EqYYQ 0ymi4r6ERsQZEJ3qxszYWKqQAFueU3dpsLHsy9kSZCB72QPZtc4Jg2tnlq3pQZndvdqM 3L7y7gYAOaPAH7/D04ZoKYK62Xs0KwQfSkI2800feYdrv7cjRJ+tpkQNvfxzj+zzGIge aP3nYDsaIvTQiuTpnceHCgLfbiDBGyshwsh0zoJkxSEXt2P2wNGLk+715mZzWovSitku qzFP7Rjx/txgvwo84/3Tj3hwppuUvaqkHnbmRhIlKWWQKcuGjb4riAW+1FP21BFSCuEs Bshg== X-Gm-Message-State: AOAM532dtD/Byb682vyu1Z/zP/bWQ7qYeYM3oR4JQ2Uu/6HOq1C+N2D5 JJXDxG4imvJP3lLt7KVRa75UqA== X-Received: by 2002:aa7:9501:0:b029:155:3b11:d5c4 with SMTP id b1-20020aa795010000b02901553b11d5c4mr4316766pfp.76.1606429911964; Thu, 26 Nov 2020 14:31:51 -0800 (PST) Received: from xps15 (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id t13sm8158981pjq.15.2020.11.26.14.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 14:31:51 -0800 (PST) Date: Thu, 26 Nov 2020 15:31:49 -0700 From: Mathieu Poirier To: Suman Anna Cc: Bjorn Andersson , Arnaud Pouliquen , Loic Pallardy , Grzegorz Jaszczyk , Tony Lindgren , linux-remoteproc@vger.kernel.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] remoteproc: Fix unbalanced boot with sysfs for no auto-boot rprocs Message-ID: <20201126223149.GA897651@xps15> References: <20201121030156.22857-1-s-anna@ti.com> <20201121030156.22857-2-s-anna@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201121030156.22857-2-s-anna@ti.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 20, 2020 at 09:01:54PM -0600, 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. > > Signed-off-by: Suman Anna > Acked-by: Arnaud Pouliquen > --- > v2: rebased version, no changes > v1: https://patchwork.kernel.org/project/linux-remoteproc/patch/20180915003725.17549-2-s-anna@ti.com/ > > 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 d1cf7bf277c4..bd2950a246c9 100644 > --- a/drivers/remoteproc/remoteproc_sysfs.c > +++ b/drivers/remoteproc/remoteproc_sysfs.c > @@ -3,6 +3,7 @@ > * Remote Processor Framework > */ > > +#include > #include > #include > > @@ -228,14 +229,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); I tackled the same problem by fixing another problem we had in the core. Patch 2 [1] and 3 [2] of this set [3] get rid of the problem related to the auto_boot check without having to deal with module counters. Please see if that covers the use case you are dealing with. Thanks, Mathieu [1]. https://patchwork.kernel.org/project/linux-remoteproc/patch/20201126210642.897302-3-mathieu.poirier@linaro.org/ [2]. https://patchwork.kernel.org/project/linux-remoteproc/patch/20201126210642.897302-4-mathieu.poirier@linaro.org/ [3]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=391789 > } else { > dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); > ret = -EINVAL; > -- > 2.28.0 >