Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4191869ybb; Mon, 23 Mar 2020 15:34:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvDqS3N/7F3Z7daMIspChatAHu+7lNJ00OPbPT4Ylx889WyD4+Smgh7ni8k/UK9Jcg2njv8 X-Received: by 2002:aca:706:: with SMTP id 6mr1194804oih.115.1585002884024; Mon, 23 Mar 2020 15:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585002884; cv=none; d=google.com; s=arc-20160816; b=wOrbZ1tA4TGmpU7kYoirZVc38ibUwRV9aYtb1IAolMx68GiI7ZV3FvDPh8wYQ90jFj GwYGM2UzM5LAUvuntlIn7r+P07YS3mvZzcAgvukvLxY/GxYhk7vrmQactwWdDejGhUZ5 UXWZCij6Z71NGlmBI2MaiB/R85RTORl3CGnxeNDH7YoPeS+uZ512lOzn3R7vTxChUztw ovMJFt2Y+loX3RzJJkPTTU0U9d6LMfWU1KZSX8lRoANSGLKEfQMKHiZHsaBf/kZeM8sR 7w8q5Ac1idPhk5FhTu6QQhBuP+eiOQFQ+miG+ukL6boP2X9UNKg1O9pogA72+7+aVJvA PeuQ== 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=0+ekX362XTPZJu3MhQATXIXqUXtG5s7CcnngEAL+Izo=; b=PSOJFc2Wui8iUULzPNatgsF7sLhUvc7wZ2xsbVoSu+Hj63nS58WYowailttu9ZS1AX GSSRBf3SpcZGmk1U4+8idsNNUuMM5/hoLuLCfTeCmLnfox3hCI7AqnGbT6QHQh/CjnIm uyPlxjf4l2XNhzWgbTqjYbWHgRUcGBiMvPeii/OHh42h7zmU5xMD+0KQybUjymwG02SK 96QFeIYIdL0kbYobq7ZO1ngzHESBKi3kxsMN0RRPKOPGFTf4lKZ7qrgbykzzuKw/8wz3 4Fr2qVURGXOlsWU5G1ny/aZNBOzgl1NZIMcph1Yi5MBvo+EPblHiHj7txVi0Sw6KRSGU VJNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b1NZ3QUp; 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 9si402121oip.112.2020.03.23.15.34.29; Mon, 23 Mar 2020 15:34:44 -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=b1NZ3QUp; 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 S1726987AbgCWWdG (ORCPT + 99 others); Mon, 23 Mar 2020 18:33:06 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42778 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbgCWWdG (ORCPT ); Mon, 23 Mar 2020 18:33:06 -0400 Received: by mail-pg1-f196.google.com with SMTP id h8so7944579pgs.9 for ; Mon, 23 Mar 2020 15:33:05 -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=0+ekX362XTPZJu3MhQATXIXqUXtG5s7CcnngEAL+Izo=; b=b1NZ3QUpB8kyqAwX+eyh8GUPAXNDdOo1fCa5qf2EFSFPVbJdg07sptzq6SiNSW34i5 ZWmyQbOPpGEoDsMvWnvurtNfNzkCUyns53hEoX3dawG18/5impvl8lZn5WXph6sSYxA8 jm04jXIkWWISgkibF1MGcD4GUIygaajwRfRxRQoYb421YVaARMC13jM/IlQCMSuMsY91 Azu/HDfOmz33wfgnx4n7F8dFgSNDMnsJD1XjNMbDDueKcb6MNqCPk8fC/X9RRFeGrgKF s1D3IWrT7WQO4jO5rzwukZcpKmhpsS13Aby/O2uyxX96wlFbaVOKsVs/8BUrsVU97CSQ n7sA== 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=0+ekX362XTPZJu3MhQATXIXqUXtG5s7CcnngEAL+Izo=; b=mrx3McRvk0jzsfzNUML9f3kt7GcLft6W+wNSFzScZ0EWNurYjpP5RC6PyW7lhK1XhS cpgwsidodq5u/jdSRPTAHD4if7jRwXUTjZ9TQ6hkC6+0X4OyalrCa7rI0aKX6C1OpA2b G4svqtNSuR/97P3wMZ1NR7bsT0natvZtbM+JlTTw1wApSUy6uST76f5oJMOM/ox9neVF v/X8B6p2INIW+vO4+VSQY88fLYsY1SEEBTQpd8gr9SGxm7mbEKrQtlwQuH4JurQsj1xH apcHWrfY3zgrOtLaUFYZSBTapxmxA0DmPzhpcuV0GYS7/sdALmeeDMzpW39GnHgobqIT z4ww== X-Gm-Message-State: ANhLgQ21H2MVACMRdgfhq4HO+FLTbdhL6HLn2ha1dsnAMqecnEE8WnHB JdkIqlM9fQ923h17k0B3NYznvg== X-Received: by 2002:a63:4912:: with SMTP id w18mr23539999pga.122.1585002784637; Mon, 23 Mar 2020 15:33:04 -0700 (PDT) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id e9sm14427742pfl.179.2020.03.23.15.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 15:33:04 -0700 (PDT) Date: Mon, 23 Mar 2020 16:33:02 -0600 From: Mathieu Poirier To: Bjorn Andersson Cc: Andy Gross , Ohad Ben-Cohen , linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/4] remoteproc: Introduce "panic" callback in ops Message-ID: <20200323223302.GC30464@xps15> References: <20200310063817.3344712-1-bjorn.andersson@linaro.org> <20200310063817.3344712-3-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200310063817.3344712-3-bjorn.andersson@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 09, 2020 at 11:38:15PM -0700, Bjorn Andersson wrote: > Introduce generic support for handling kernel panics in remoteproc > drivers, in order to allow operations needed for aiding in post mortem > system debugging, such as flushing caches etc. > > The function can return a number of milliseconds needed by the remote to > "settle" and the core will wait the longest returned duration before > returning from the panic handler. > > Signed-off-by: Bjorn Andersson > --- > > Change since v3: > - Migrate from mutex_trylock() to using RCU > - Turned the timeout to unsigned long > > drivers/remoteproc/remoteproc_core.c | 44 ++++++++++++++++++++++++++++ > include/linux/remoteproc.h | 3 ++ > 2 files changed, 47 insertions(+) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index f0a77c30c6b1..2024a98930bf 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -16,6 +16,7 @@ > > #define pr_fmt(fmt) "%s: " fmt, __func__ > > +#include > #include > #include > #include > @@ -43,6 +44,7 @@ > > static DEFINE_MUTEX(rproc_list_mutex); > static LIST_HEAD(rproc_list); > +static struct notifier_block rproc_panic_nb; > > typedef int (*rproc_handle_resource_t)(struct rproc *rproc, > void *, int offset, int avail); > @@ -2219,10 +2221,51 @@ void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type) > } > EXPORT_SYMBOL(rproc_report_crash); > > +static int rproc_panic_handler(struct notifier_block *nb, unsigned long event, > + void *ptr) > +{ > + unsigned int longest = 0; > + struct rproc *rproc; > + unsigned int d; > + > + rcu_read_lock(); > + list_for_each_entry_rcu(rproc, &rproc_list, node) { > + if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) > + continue; > + > + d = rproc->ops->panic(rproc); > + longest = max(longest, d); > + } > + rcu_read_unlock(); > + > + /* > + * Delay for the longest requested duration before returning. > + * This can be used by the remoteproc drivers to give the remote > + * processor time to perform any requested operations (such as flush > + * caches), where means for signalling the Linux side isn't available There is a problem with the above sentence. > + * while in panic. > + */ > + mdelay(longest); > + > + return NOTIFY_DONE; > +} > + > +static void __init rproc_init_panic(void) > +{ > + rproc_panic_nb.notifier_call = rproc_panic_handler; > + atomic_notifier_chain_register(&panic_notifier_list, &rproc_panic_nb); > +} > + > +static void __exit rproc_exit_panic(void) > +{ > + atomic_notifier_chain_unregister(&panic_notifier_list, &rproc_panic_nb); > +} > + > static int __init remoteproc_init(void) > { > rproc_init_sysfs(); > rproc_init_debugfs(); > + rproc_init_panic(); > > return 0; > } > @@ -2232,6 +2275,7 @@ static void __exit remoteproc_exit(void) > { > ida_destroy(&rproc_dev_index); > > + rproc_exit_panic(); > rproc_exit_debugfs(); > rproc_exit_sysfs(); > } > diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h > index 16ad66683ad0..5959d6247dc0 100644 > --- a/include/linux/remoteproc.h > +++ b/include/linux/remoteproc.h > @@ -369,6 +369,8 @@ enum rsc_handling_status { > * expects to find it > * @sanity_check: sanity check the fw image > * @get_boot_addr: get boot address to entry point specified in firmware > + * @panic: optional callback to react to system panic, core will delay > + * panic at least the returned number of milliseconds > */ > struct rproc_ops { > int (*start)(struct rproc *rproc); > @@ -383,6 +385,7 @@ struct rproc_ops { > int (*load)(struct rproc *rproc, const struct firmware *fw); > int (*sanity_check)(struct rproc *rproc, const struct firmware *fw); > u32 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw); > + unsigned long (*panic)(struct rproc *rproc); > }; > > /** > -- > 2.24.0 >