Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp360183ybh; Mon, 9 Mar 2020 23:41:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuBWxe91vxCP5UfODyUmI7fvSO6XopNCZ8vTzD2V8+FtOqUwijKEYw/D/S7CwJ0kgUQrTNU X-Received: by 2002:a9d:bf5:: with SMTP id 108mr11740461oth.260.1583822491926; Mon, 09 Mar 2020 23:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583822491; cv=none; d=google.com; s=arc-20160816; b=R3lc0Q8/Yd+ilSpm2JUpI8dAxnwjP02T/o+tAs17ZbvehaJ9pl2e1ZWslkTdGuMeuX THFIZciAOEfojuha0txmCnCg0k3k3kLlHBwxGqN638vJ34U4sLLujbTw1Ww3LHVMIQWu duXZOhPzqZyGz3xu4HMA/vAMeOjI2sruTCBPfo5Acu16SmjpROcrPmJAkKoDIdZLdkIs yfRAH6Nk8ipsx7fYjbqrpX8j/ovFkmJ8Ve7bJJcuzEOOjB0U1RPXitGxg0CpUIIjPGkw 5WRD6XTU9ppMczeT39I3zc/LTIVq+RuftB4x/Q9l/Bprdo9oxsggeRXu3OVS53CIi5Jg ipmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0B7KMhj7KXyXrKRXHFaEpM25cw3DFGC+sUjtxaJiLnw=; b=w+sC1JAf81gHYBR3lkXgyEW8IAWpyTo5XWetHb2dzj6ZkOUQClo8F6/sxKm7fQOn7F J81/6wVwGElTe8be/Lo9oZ+oGQQbgh6FWe0NF1+euGmzF+yjybGBCYNwyPJ7ZANRd6gU v/7hNh15g+VjCT9JKAPqbX86arQm+O3vtTEVrn8fDw7fJR1tUb65WU83KAjSJuhFps21 r4k8BzR05M6cNF1DhZI9UQTxT1Mqd2VnAmt7FNZSrfY381miQ/o1mZgenocMPJHfoAQH TUlK/PAhbUeBrTBfRnOoykTDjPT9iogGevepmf+ukbvHIXmfPk6jdvzeEU11K1QPFzz4 hqgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sPfXTdaZ; 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 c8si7621632oto.95.2020.03.09.23.41.20; Mon, 09 Mar 2020 23:41:31 -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=sPfXTdaZ; 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 S1726426AbgCJGjz (ORCPT + 99 others); Tue, 10 Mar 2020 02:39:55 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40719 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbgCJGjz (ORCPT ); Tue, 10 Mar 2020 02:39:55 -0400 Received: by mail-pg1-f195.google.com with SMTP id t24so5872301pgj.7 for ; Mon, 09 Mar 2020 23:39:52 -0700 (PDT) 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=0B7KMhj7KXyXrKRXHFaEpM25cw3DFGC+sUjtxaJiLnw=; b=sPfXTdaZeqRKyB+o83TSVViXYP1gJ/3A0HFSP9o8PlCvRUTrhdFa5HmiKS771Y1Xf+ Dh8vUrZ2SyV6UrvE0OoGLlUizYQnaxZL27dirXjagRDQ3OgKOoHrbyo6SOVo0l/Ik9+Y q/bZdNV3PMcqvJvXmaN/wIOYJ3130Bw2UFK7/Q+2dRWU9610ZdwWDpeyG0NdT+LRPkDL o/U+3hiVRkJ7J9B+iJqEAHhLLsCj70wUX/sRXx7SA77An0tgS9IA1HiDOp+QZFb4HsPy mV2+zu3acdNxRT6yyI3PHfmTFq59hdEcH4caaf9HuKzg11lStNdEGFfclwEodlDG4AEY /rqA== 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=0B7KMhj7KXyXrKRXHFaEpM25cw3DFGC+sUjtxaJiLnw=; b=Tpg7ZKEfU5HPyvLJc9QWFfrJggEgh4iult+1zm5sWIGMyLdve9Unbs0BazpSNHT5jk Jwq4+oFtM4cuIzVMiXzAnbCLsB6LUJphmLssFFsm48Y5IFAR3nfOUd1Zk9kXTS9tXMbu MyJp/fPIb6DaADchavPPKUyzviI1t0CaQyG0UJfjUwC0xr0wGIPIMYPkEEwUj3DAcAoh dHY3dXRIFie2JOMEjGM80GO0IPzFqw1bRg9IADuXcOBvkV2sGKXU+K6xhXbJGeckQgpx JjxpQC7eYAMBePN5/h1z4df7tFTNhrVNbZq/u07uaUDsljA3m2J6mpe/1FiV4/l4YSid GG0w== X-Gm-Message-State: ANhLgQ0YFLotVASDrRchqjXOQO81PMQh2yWIz3rlRvPNUDfWhpi/c8E6 SuL+6rWXimmq6L3Rkiksn3VXyg== X-Received: by 2002:a65:5688:: with SMTP id v8mr18531819pgs.403.1583822392248; Mon, 09 Mar 2020 23:39:52 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id j38sm42398468pgi.51.2020.03.09.23.39.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 23:39:51 -0700 (PDT) From: Bjorn Andersson To: Andy Gross , Bjorn Andersson , Ohad Ben-Cohen Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Mathieu Poirier Subject: [PATCH v4 2/4] remoteproc: Introduce "panic" callback in ops Date: Mon, 9 Mar 2020 23:38:15 -0700 Message-Id: <20200310063817.3344712-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200310063817.3344712-1-bjorn.andersson@linaro.org> References: <20200310063817.3344712-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 + * 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