Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1390238pxf; Fri, 12 Mar 2021 08:26:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIjFiwHDveFwxjTtHOdnZLAVW3hVbZNdy2ahEWz80sXLJd9wX80LUpvhpeLNOeS08v9rd6 X-Received: by 2002:a05:6402:3075:: with SMTP id bs21mr15165656edb.274.1615566419085; Fri, 12 Mar 2021 08:26:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615566419; cv=none; d=google.com; s=arc-20160816; b=a81RgG1mOMsrt4YqU9wcjLbl6JF2vn4ZsXzLLkrsoJISQWcPlxqz7Txu5AYVHsyiHe 0fsgnF24zantfFWEvGAbTF7kGrIqxb9CYC6IxvDquDcVKdQ/nstwYL6sZpbispkwfcrw DabH5iKjILKL96rzg2g5zCMfYwi6rr5RfvF+oZlSx4zvp/gUtEznLIOv9J05iLLRfCWf bMqxLgYVhsKRCWgPwsUOtQbk4ihIBGbhu2OhubjWrpn6JCgjRwrRhALFGSOIoHHySBtm j3vIluXmNHpKAHluqhTSqIaMKAZvXOnfQTKwCfDhHCETCnjHZvPCjJy1ZldvUjgy35Aq jiug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z++nDe1KbxQOwXuMBZocx2SGGQIMJC2S/9LC839MlY0=; b=U1jtWWWFvx6PFQ9roTt2+gqS04P9r2QsOug+RG2vrsDD3WxWebeAuPFZYi+rlCoDdn mutQ7hV6AVhxJd4q70CBSeiDlnfBrxQ/W/W/XVimZSCYei8SvoQ3hW/aMlNwnKyNOgHI +EBKydEthgrM0HQ4KKT9z5vYsGQB0yL4z/p/bUSJiSRRudQLW+Y2y/H00BZGaOCzEI1T tWv+OZ98Hi5Gm40EHAoCTDHHVkOgC+6Nita2COkegWvlU24UY1DoGb33YB62+MRSAOVK Y5sgz+h+UR+gJxtyQ0/gMSybQHiqL6DBY+NGsqvI7jmXBpiq05bho1tHE97dLE8qzRZL nF/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dEFpi8aT; 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 dj20si4608599edb.250.2021.03.12.08.26.36; Fri, 12 Mar 2021 08:26:59 -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=dEFpi8aT; 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 S232936AbhCLQZs (ORCPT + 99 others); Fri, 12 Mar 2021 11:25:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232732AbhCLQZJ (ORCPT ); Fri, 12 Mar 2021 11:25:09 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92F7EC061574 for ; Fri, 12 Mar 2021 08:25:09 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id x7-20020a17090a2b07b02900c0ea793940so10976031pjc.2 for ; Fri, 12 Mar 2021 08:25:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z++nDe1KbxQOwXuMBZocx2SGGQIMJC2S/9LC839MlY0=; b=dEFpi8aTE2Hk60yckTPByYR568S6yUjP9+TvhjVa2Mk/l9ACJ1m2UU4R6sSPSxPSMO RaV70NJQvdzkpX8/C98C7Uj+/Q46X9YPeunzqGsOfwYAQ+gykm43WATfCAszb5tyFmuv GST6g8cm1qQW1r8kYic1vLYpwNJdc1FL4JIX62mBrpdQj4+Vqvw7XVXCuYVNWd4uEPev lhue/blcKkOvz80iV6ApuJ1owjRkcHIYeDhPeGwwiMGO4ZzMpSNTWycONfAano5e7HMn rdAWBdkYF1PmTMf4Ejo0EJDDkh75vUmkeF0vJyuScsqy4vdbwwUtyP92yMSb+66mPMwu SbcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z++nDe1KbxQOwXuMBZocx2SGGQIMJC2S/9LC839MlY0=; b=FBlNhViBOzUqPDf2q2ABa/NreHjiIduViG1VE8pRZnGEck0h+4GMbmcb+mY3qPCiTX +FwTGJaiYIJ6s8ngzkNP4FdZz0CDNJpGaTUC4WXBlijDMk6sPGiB4Cjw51d789NSutCU a0of2E64oJpkmr+E+QWSFHjJ9TnfXxDT/IqyKrF8qZm0wTNsIy20JTrTjjhSL2pg0ddf IQIebM3chzcJ/hQ8tQegGMsLnS7GHvnjPg2Dgswr57cjdSXEhR2/YVXReb+5157GkwZ7 ZsD2td1jdGACMGurs57bgpmZ4++9NHXGGEdzSxpk3GscdpuywCD1UwumpjJFUv0YYmj2 YfcA== X-Gm-Message-State: AOAM5317xRhfrU+1dq6V5JIK7AhnKs6NHSh8DHf6ITw57eHlTqf4L/OM xL95ekYj2ovjs/S8MBfHx2L2cdBrgDqzcw== X-Received: by 2002:a17:902:e5c8:b029:e4:c22d:4da6 with SMTP id u8-20020a170902e5c8b02900e4c22d4da6mr14523152plf.10.1615566309105; Fri, 12 Mar 2021 08:25:09 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:08 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 12/17] remoteproc: Properly deal with the resource table when stopping Date: Fri, 12 Mar 2021 09:24:48 -0700 Message-Id: <20210312162453.1234145-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a remote processor that was attached to is stopped, special care must be taken to make sure the shutdown process is similar to what it would be had it been started by the remoteproc core. This patch takes care of that by making a copy of the resource table currently used by the remote processor. From that point on the copy is used, as if the remote processor had been started by the remoteproc core. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen Reported-by: kernel test robot --- New for V8: - Removed variable @table_ptr as it served no purpose. --- drivers/remoteproc/remoteproc_core.c | 48 +++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 0f151dbcdc36..37b3b7d494e5 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1634,6 +1634,47 @@ static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) return 0; } +static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) +{ + /* A resource table was never retrieved, nothing to do here */ + if (!rproc->table_ptr) + return 0; + + /* + * If a cache table exists the remote processor was started by + * the remoteproc core. That cache table should be used for + * the rest of the shutdown process. + */ + if (rproc->cached_table) + goto out; + + /* + * If we made it here the remote processor was started by another + * entity and a cache table doesn't exist. As such make a copy of + * the resource table currently used by the remote processor and + * use that for the rest of the shutdown process. The memory + * allocated here is free'd in rproc_shutdown(). + */ + rproc->cached_table = kmemdup(rproc->table_ptr, + rproc->table_sz, GFP_KERNEL); + if (!rproc->cached_table) + return -ENOMEM; + + /* + * Since the remote processor is being switched off the clean table + * won't be needed. Allocated in rproc_set_rsc_table(). + */ + kfree(rproc->clean_table); + +out: + /* + * Use a copy of the resource table for the remainder of the + * shutdown process. + */ + rproc->table_ptr = rproc->cached_table; + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1759,7 +1800,12 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc_stop_subdevices(rproc, crashed); /* the installed resource table is no longer accessible */ - rproc->table_ptr = rproc->cached_table; + ret = rproc_reset_rsc_table_on_stop(rproc); + if (ret) { + dev_err(dev, "can't reset resource table: %d\n", ret); + return ret; + } + /* power off the remote processor */ ret = rproc->ops->stop(rproc); -- 2.25.1