Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2665789pxu; Mon, 7 Dec 2020 12:12:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhWImw8BDb82LhKUqWPuSvASR+hy7hoJHBC+h5j9TLvq4CO8xfY5Y7Ry4cC0vTJdnS4t3A X-Received: by 2002:a17:906:2f87:: with SMTP id w7mr20405974eji.83.1607371940235; Mon, 07 Dec 2020 12:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607371940; cv=none; d=google.com; s=arc-20160816; b=yctCTbkeZBzK9c9oGl5YY463lRjC0DV3HFaOOjP2jMzQ//IEIwqNvK/MamhJ5Ves5a lOUveSuk3xlP3n18u3hM7UcRidgu8giL8scMXDU3VPWIJAq+yl4qbZ/PPeoh7ojxbogz wHt7IHhdutMF7ytjs1p38XIP05Kg5g3V0MLPLFnz6KnVLT7FFIBgcCVOMKrF0RRjdYxH YxFKTUfYGXT0g9URhbDq39uP2Jt9SynDgOEkfHj+F93ObpDXjgW6SNUL4OgbnpMaUUcj olaCiz5wRl2XrNFYwe/PwUlSTtqvCOp50I48oZLZLI46LlW8SWbnkrpqfnO0Ng1X+wAq Dh9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=0ux7RJ2Q3HzjdM2uVsV87B7RYcyHrDaubc3tAQHm7I8=; b=aWk8JWCc08SdBqznwlTKM8zCs3P7Tc1+fCz1r+rUhd5UEwDiF5DUzkBHTGFJwAhiii pdE7Z0o3E0wZMfZaHBMo7OusAl2gaMkhIcXoh9XJpv50GK3b/YzvwaxjJtXOSbby8SyW EP0obTVEQk4beGyJJdqHNso7BKA28+Lgi9WlS6aRNXFOT4Bp/B8IT8AcHnw/5Rhn8Sxo zcsZRJtw2dUxI9Ng0V27dy3nHtyoK4pIRXtkJqXMHYH0hDwLvNtL9BFebSlepBUEQQK0 2aEx7i217/cNA0MOnF9BmGOGaiJH//VaZgo4yNEpQ12fJMm2+lGSGD/av4AlXOQP6nib luzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EqQgQHyU; 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 zm13si7115835ejb.351.2020.12.07.12.11.47; Mon, 07 Dec 2020 12:12:20 -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=EqQgQHyU; 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 S1727117AbgLGUHn (ORCPT + 99 others); Mon, 7 Dec 2020 15:07:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727065AbgLGUHn (ORCPT ); Mon, 7 Dec 2020 15:07:43 -0500 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DDDEC06138C for ; Mon, 7 Dec 2020 12:06:55 -0800 (PST) Received: by mail-ej1-x643.google.com with SMTP id ga15so21325321ejb.4 for ; Mon, 07 Dec 2020 12:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0ux7RJ2Q3HzjdM2uVsV87B7RYcyHrDaubc3tAQHm7I8=; b=EqQgQHyUpXx9rPAPJBYLVVpR//Ru++8KXGV0GycNLsFaH4mmQJsrU4zfJMOorbZo61 dB4sVUgiv2vQZ8CM/nLsHZdqrEUR5EOhegc0GZ1g/epXuzabl5e7p/MiLOWPphPeQKzS GwoGBvQ+KI9sTEHHa0JOcHKAMwJUBoE76fnFCPSdWhu6enGp9EfQw9xIkfOXYOqC2llV 1wf6ZX5f+6A42hh2tLUqr7z1pBI2T1VpNUgDUUAT217U13qDpMhF/W3JZ8Hv3/U6sIL/ 4P3TMF5EWbKO19jYGwu8Z7qdm9PBVU1/JgT9tm+OZ4Rwv0i6kXNYEB+Z/BC24UljvHV8 ZOXw== 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; bh=0ux7RJ2Q3HzjdM2uVsV87B7RYcyHrDaubc3tAQHm7I8=; b=Uf3w71fWwALAlmF0PeHT21XrS5QbQGFEwplN3htiGtymUQefCjRzHiKfLHdstLnoMF 2un6ld4VgjH+rIcr0sjvB00pTQ/5WITV9R48qdAS37PzIRNQQXplKyMNe/O3WlNA720h svEuALl+GLQ0Mts6tWCLzaGGDGKhKflYG7gGt5xuHrwbm7R7u8WJbGS2OCai5pZtTxhq S54hcctSx+TctMLuxjFGiaCqp9X/aNIa2v71ZxKdoRfAlBvFas8v6qD0VTBbVAxSzWdA W4xAX4hmP5h+X1qt7f+mc/quZonWsZBMcQnH3gDOm2Nqst7LE4+HvEDrPuoXwluaLmYm HZCA== X-Gm-Message-State: AOAM532yH1xGwicIf30x2nqF4XkuBOQEUXUGlfwBq1hnSgbaSn4jKg3u 8TiVohN/kHA23N/JUCX8f6h9XuwvKQqbYIqv/xFRAg== X-Received: by 2002:a17:906:f9d7:: with SMTP id lj23mr11919678ejb.550.1607371613989; Mon, 07 Dec 2020 12:06:53 -0800 (PST) MIME-Version: 1.0 References: <20201122054135.802935-1-bjorn.andersson@linaro.org> <20201122054135.802935-3-bjorn.andersson@linaro.org> In-Reply-To: From: Bjorn Andersson Date: Mon, 7 Dec 2020 14:06:43 -0600 Message-ID: Subject: Re: [PATCH v3 2/4] remoteproc: sysmon: Expose the shutdown result To: Evan Green Cc: Andy Gross , Ohad Ben-Cohen , Siddharth Gupta , Mathieu Poirier , linux-arm-msm , "open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM" , LKML , Steev Klimaszewski , Rishabh Bhatnagar Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 7, 2020 at 2:00 PM Evan Green wrote: > > On Sat, Nov 21, 2020 at 9:43 PM Bjorn Andersson > wrote: > > > > A graceful shutdown of the Qualcomm remote processors where > > traditionally performed by invoking a shared memory state signal and > > waiting for the associated ack. > > > > This was later superseded by the "sysmon" mechanism, where some form of > > shared memory bus is used to send a "graceful shutdown request" message > > and one of more signals comes back to indicate its success. > > > > But when this newer mechanism is in effect the firmware is shut down by > > the time the older mechanism, implemented in the remoteproc drivers, > > attempts to perform a graceful shutdown - and as such it will never > > receive an ack back. > > > > This patch therefor track the success of the latest shutdown attempt in > > sysmon and exposes a new function in the API that the remoteproc driver > > can use to query the success and the necessity of invoking the older > > mechanism. > > > > Tested-by: Steev Klimaszewski > > Reviewed-by: Rishabh Bhatnagar > > Signed-off-by: Bjorn Andersson > > --- > > > > Change since v2: > > - None > > > > drivers/remoteproc/qcom_common.h | 6 +++ > > drivers/remoteproc/qcom_sysmon.c | 82 ++++++++++++++++++++++++-------- > > 2 files changed, 69 insertions(+), 19 deletions(-) > > > > diff --git a/drivers/remoteproc/qcom_common.h b/drivers/remoteproc/qcom_common.h > > index dfc641c3a98b..8ba9052955bd 100644 > > --- a/drivers/remoteproc/qcom_common.h > > +++ b/drivers/remoteproc/qcom_common.h > > @@ -51,6 +51,7 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, > > const char *name, > > int ssctl_instance); > > void qcom_remove_sysmon_subdev(struct qcom_sysmon *sysmon); > > +bool qcom_sysmon_shutdown_acked(struct qcom_sysmon *sysmon); > > #else > > static inline struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, > > const char *name, > > @@ -62,6 +63,11 @@ static inline struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, > > static inline void qcom_remove_sysmon_subdev(struct qcom_sysmon *sysmon) > > { > > } > > + > > +static inline bool qcom_sysmon_shutdown_acked(struct qcom_sysmon *sysmon) > > +{ > > + return false; > > +} > > #endif > > > > #endif > > diff --git a/drivers/remoteproc/qcom_sysmon.c b/drivers/remoteproc/qcom_sysmon.c > > index b37b111b15b3..a428b707a6de 100644 > > --- a/drivers/remoteproc/qcom_sysmon.c > > +++ b/drivers/remoteproc/qcom_sysmon.c > > @@ -44,6 +44,7 @@ struct qcom_sysmon { > > struct mutex lock; > > > > bool ssr_ack; > > + bool shutdown_acked; > > > > struct qmi_handle qmi; > > struct sockaddr_qrtr ssctl; > > @@ -115,10 +116,13 @@ static void sysmon_send_event(struct qcom_sysmon *sysmon, > > /** > > * sysmon_request_shutdown() - request graceful shutdown of remote > > * @sysmon: sysmon context > > + * > > + * Return: boolean indicator of the remote processor acking the request > > */ > > -static void sysmon_request_shutdown(struct qcom_sysmon *sysmon) > > +static bool sysmon_request_shutdown(struct qcom_sysmon *sysmon) > > { > > char *req = "ssr:shutdown"; > > + bool acked = false; > > int ret; > > > > mutex_lock(&sysmon->lock); > > @@ -141,9 +145,13 @@ static void sysmon_request_shutdown(struct qcom_sysmon *sysmon) > > if (!sysmon->ssr_ack) > > dev_err(sysmon->dev, > > "unexpected response to sysmon shutdown request\n"); > > + else > > + acked = true; > > > > out_unlock: > > mutex_unlock(&sysmon->lock); > > + > > + return acked; > > } > > > > static int sysmon_callback(struct rpmsg_device *rpdev, void *data, int count, > > @@ -297,14 +305,33 @@ static struct qmi_msg_handler qmi_indication_handler[] = { > > {} > > }; > > > > +static bool ssctl_request_shutdown_wait(struct qcom_sysmon *sysmon) > > +{ > > + int ret; > > + > > + ret = wait_for_completion_timeout(&sysmon->shutdown_comp, 10 * HZ); > > + if (ret) > > + return true; > > + > > + ret = try_wait_for_completion(&sysmon->ind_comp); > > + if (ret) > > + return true; > > + > > + dev_err(sysmon->dev, "timeout waiting for shutdown ack\n"); > > + return false; > > +} > > + > > /** > > * ssctl_request_shutdown() - request shutdown via SSCTL QMI service > > * @sysmon: sysmon context > > + * > > + * Return: boolean indicator of the remote processor acking the request > > */ > > -static void ssctl_request_shutdown(struct qcom_sysmon *sysmon) > > +static bool ssctl_request_shutdown(struct qcom_sysmon *sysmon) > > { > > struct ssctl_shutdown_resp resp; > > struct qmi_txn txn; > > + bool acked = false; > > int ret; > > > > reinit_completion(&sysmon->ind_comp); > > @@ -312,7 +339,7 @@ static void ssctl_request_shutdown(struct qcom_sysmon *sysmon) > > ret = qmi_txn_init(&sysmon->qmi, &txn, ssctl_shutdown_resp_ei, &resp); > > if (ret < 0) { > > dev_err(sysmon->dev, "failed to allocate QMI txn\n"); > > - return; > > + return false; > > } > > > > ret = qmi_send_request(&sysmon->qmi, &sysmon->ssctl, &txn, > > @@ -320,27 +347,23 @@ static void ssctl_request_shutdown(struct qcom_sysmon *sysmon) > > if (ret < 0) { > > dev_err(sysmon->dev, "failed to send shutdown request\n"); > > qmi_txn_cancel(&txn); > > - return; > > + return false; > > } > > > > ret = qmi_txn_wait(&txn, 5 * HZ); > > - if (ret < 0) > > + if (ret < 0) { > > dev_err(sysmon->dev, "failed receiving QMI response\n"); > > - else if (resp.resp.result) > > + } else if (resp.resp.result) { > > dev_err(sysmon->dev, "shutdown request failed\n"); > > - else > > + } else { > > dev_dbg(sysmon->dev, "shutdown request completed\n"); > > - > > - if (sysmon->shutdown_irq > 0) { > > - ret = wait_for_completion_timeout(&sysmon->shutdown_comp, > > - 10 * HZ); > > - if (!ret) { > > - ret = try_wait_for_completion(&sysmon->ind_comp); > > - if (!ret) > > - dev_err(sysmon->dev, > > - "timeout waiting for shutdown ack\n"); > > - } > > + acked = true; > > } > > + > > + if (sysmon->shutdown_irq > 0) > > + return ssctl_request_shutdown_wait(sysmon); > > + > > + return acked; > > } > > > > /** > > @@ -510,6 +533,9 @@ static void sysmon_stop(struct rproc_subdev *subdev, bool crashed) > > .subsys_name = sysmon->name, > > .ssr_event = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN > > }; > > + bool acked; > > + > > + sysmon->shutdown_acked = false; > > > > mutex_lock(&sysmon->state_lock); > > sysmon->state = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN; > > @@ -521,9 +547,11 @@ static void sysmon_stop(struct rproc_subdev *subdev, bool crashed) > > return; > > > > if (sysmon->ssctl_version) > > > - ssctl_request_shutdown(sysmon); > > + acked = ssctl_request_shutdown(sysmon); > > else if (sysmon->ept) > > - sysmon_request_shutdown(sysmon); > > + acked = sysmon_request_shutdown(sysmon); > > + > > + sysmon->shutdown_acked = acked; > > Guenter noticed that the 0-day bot complains about acked being > potentially uninitialized here. He put a fix for us into Chrome OS: > > https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2577656 > > Bjorn, do you want to tweak the patch in your tree? No, I prefer not to force push to the tree. I did however merge and push out Arnd's fixup to this. You can find it here: https://git.kernel.org/pub/scm/linux/kernel/git/andersson/remoteproc.git/commit/?h=for-next&id=9d7b4a40387d0f91512a74caed6654ffa23d5ce4 Regards, Bjorn