Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2652057rwd; Sun, 28 May 2023 21:21:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lzukl8gs5btwn3R5G7pkdERlI/oW++eJCKjx/8BriNgML5r2L5wlzEXpnKkWoUd/77fSM X-Received: by 2002:a05:6a20:3d08:b0:10b:4539:fa0a with SMTP id y8-20020a056a203d0800b0010b4539fa0amr9092387pzi.1.1685334069489; Sun, 28 May 2023 21:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685334069; cv=none; d=google.com; s=arc-20160816; b=TbICJ/B+5VnBCAfdzxDHTJ57aXrX/xF3LoI/WFzyK2A07nSTAA/kakcOQU7At38bL3 4RrGnVFdBzEDKkExWwFPETzT4He6hQfSjRijrnSRaQpZ/URp+ljEcjBtWwuMIEAmDrrD qniy8U5TmEuXn5PZmUd//i6afbdzIAmIcf8Lhr+8Klk+nk3pX3f6YIwKbb0oSZYSnBum QHtuZOO3oooV8NcrL74capd1SFulIHxFeMkgQalEly/NLtfwIn0tKzbJ7FRYMB+uJe39 ulB7/t30HKRRufHMbWU9sgha6h3e8B18IiL/yeKUL5YBNnikWQbaaOqS9HCU1xHZmRF3 LqLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=NLCcvfEGWmtkd9tloAMuy97p7N3K3ZtMl6/Co4OHM+w=; b=WBOrzjlJjV20/bYO/RA+GN6B575MT48r1uRzeNm8K8I2EhVOyZyZuzkrQl7W2DmEm5 dpW9/rp+1tN71cB1TU8w7ImhwGCjJBfOllDX67vhRy0p6TmhHH5jUL6YA+HpNSEvBO/T RyRL4ovR7XUg38V8rge0ECTFJhZV1QbNgfm+W20BZDxDb7Yjah67XxMAvSxfQteUkjGH /xk8BwptsC6g4PSfn7jRkfjZQf64Halj1PSwxkddcYj8/DgDkQEHNDmI/Axbc7yah5t1 NEwC9ZfidtT6k4frofJj6MDVPBhGMWFvN4JKPpUai1wzzbam2deIGzzyZ+MBSg/yZOou k3rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=m0a7w9aj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b186-20020a62cfc3000000b0064d56c3bfd2si8720038pfg.207.2023.05.28.21.20.53; Sun, 28 May 2023 21:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=m0a7w9aj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230390AbjE2D53 (ORCPT + 99 others); Sun, 28 May 2023 23:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbjE2D51 (ORCPT ); Sun, 28 May 2023 23:57:27 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09FDBA7; Sun, 28 May 2023 20:57:25 -0700 (PDT) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34T2KL78018014; Mon, 29 May 2023 03:57:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=qcppdkim1; bh=NLCcvfEGWmtkd9tloAMuy97p7N3K3ZtMl6/Co4OHM+w=; b=m0a7w9ajkBNFw2By3lFgMQutk36nTY6peiHp6VVuNTO7EizRdMihHJgKQguJkGPXysiU /oAg1iLGi8apv2UjUmIrn+YPTvp7d/7CONZLj5i4o9wbGhjO2p38U+4BQs/yDEa7ZI5L aNrECOHL7p7W8fMA8h7GvEcd/EpXdp5GBfQLLAqZ0G5u4mdyIDk9XDn8R48gUt5F3Ijl 0XyHXAk5Zcj4WXlaTs0EEuG5w2Z7+3sdOUhJLQ8LSixtDI1x5X9t/cU7MM5dqvkz9T1D CkxJ6ml4dyptvtDGzP2CZJCSXnxuD7DE5mHYCcIjsgVCYD5kHsZyN8S9NUl63EIgz7gK aA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3quarb2fs5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 29 May 2023 03:57:22 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 34T3vLsv012620 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 29 May 2023 03:57:21 GMT Received: from [10.50.38.182] (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Sun, 28 May 2023 20:57:17 -0700 Message-ID: <3687b420-0993-7f76-7116-114b1784de05@quicinc.com> Date: Mon, 29 May 2023 09:27:14 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] remoteproc: qcom: Add NOTIFY_FATAL event type to SSR subdevice To: Mukesh Ojha , , , , , , , CC: , , , , References: <20230503062146.3891-1-quic_viswanat@quicinc.com> Content-Language: en-US From: Vignesh Viswanathan In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: REQn884jbhSDlXu2km4bLGPdFjvXyi2i X-Proofpoint-ORIG-GUID: REQn884jbhSDlXu2km4bLGPdFjvXyi2i X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-29_01,2023-05-25_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 impostorscore=0 clxscore=1011 malwarescore=0 adultscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305290032 X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Gentle Reminder. On 5/22/2023 3:03 PM, Mukesh Ojha wrote: > > > On 5/3/2023 4:56 PM, Mukesh Ojha wrote: >> >> >> On 5/3/2023 11:51 AM, Vignesh Viswanathan wrote: >>> Currently the SSR subdevice notifies the client driver on crash of the >>> rproc from the recovery workqueue using the BEFORE_SHUTDOWN event. >>> However the client driver might be interested to know that the device >>> has crashed immediately to pause any further transactions with the >>> rproc. This calls for an event to be sent to the driver in the IRQ >>> context as soon as the rproc crashes. >>> >>> Add NOTIFY_FATAL event to SSR subdevice to atomically notify rproc has >>> crashed to the client driver. >>> >>> Validated the event in IPQ9574 and IPQ5332 by forcing the rproc to crash >>> and ensuring the registered notifier function receives the notification >>> in IRQ context. >> >> This was one of valid use case we encounter in android, We have some >> other way of doing the same thing without core kernel change with >> something called early notifiers. >> >> https://git.codelinaro.org/clo/la/kernel/msm-5.15/-/commit/7583d24de337aa1bf7c375a7da706af9b995b9a1#a840754ebb0e24e88adbf48177e1abd0830b72d2 >> >> https://git.codelinaro.org/clo/la/kernel/msm-5.15/-/commit/257de41c63a5a51a081cc7887cdaa4a46e4d1744 >> >> But good to address this if possible. > > Ack the idea of early notifier; > But here, atomic does not guarantees it to be atomic. > > Acked-by: Mukesh Ojha > > -- Mukesh > > >> >> -Mukesh >>> >>> Signed-off-by: Vignesh Viswanathan >>> --- >>>   drivers/remoteproc/qcom_common.c      | 60 +++++++++++++++++++++++++++ >>>   drivers/remoteproc/remoteproc_core.c  | 12 ++++++ >>>   include/linux/remoteproc.h            |  3 ++ >>>   include/linux/remoteproc/qcom_rproc.h | 17 ++++++++ >>>   4 files changed, 92 insertions(+) >>> >>> diff --git a/drivers/remoteproc/qcom_common.c >>> b/drivers/remoteproc/qcom_common.c >>> index a0d4238492e9..76542229aeb6 100644 >>> --- a/drivers/remoteproc/qcom_common.c >>> +++ b/drivers/remoteproc/qcom_common.c >>> @@ -84,6 +84,7 @@ struct minidump_global_toc { >>>   struct qcom_ssr_subsystem { >>>       const char *name; >>>       struct srcu_notifier_head notifier_list; >>> +    struct atomic_notifier_head atomic_notifier_list; >>>       struct list_head list; >>>   }; >>> @@ -366,6 +367,7 @@ static struct qcom_ssr_subsystem >>> *qcom_ssr_get_subsys(const char *name) >>>       } >>>       info->name = kstrdup_const(name, GFP_KERNEL); >>>       srcu_init_notifier_head(&info->notifier_list); >>> +    ATOMIC_INIT_NOTIFIER_HEAD(&info->atomic_notifier_list); >>>       /* Add to global notification list */ >>>       list_add_tail(&info->list, &qcom_ssr_subsystem_list); >>> @@ -417,6 +419,51 @@ int qcom_unregister_ssr_notifier(void *notify, >>> struct notifier_block *nb) >>>   } >>>   EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier); >>> +/** >>> + * qcom_register_ssr_atomic_notifier() - register SSR Atomic >>> notification >>> + *                     handler >>> + * @name:    Subsystem's SSR name >>> + * @nb:    notifier_block to be invoked upon subsystem's state change >>> + * >>> + * This registers the @nb notifier block as part the atomic notifier >>> + * chain for a remoteproc associated with @name. The notifier >>> block's callback >>> + * will be invoked when the remote processor crashes in atomic >>> context before >>> + * the recovery process is queued. >>> + * >>> + * Return: a subsystem cookie on success, ERR_PTR on failure. >>> + */ >>> +void *qcom_register_ssr_atomic_notifier(const char *name, >>> +                    struct notifier_block *nb) >>> +{ >>> +    struct qcom_ssr_subsystem *info; >>> + >>> +    info = qcom_ssr_get_subsys(name); >>> +    if (IS_ERR(info)) >>> +        return info; >>> + >>> +    atomic_notifier_chain_register(&info->atomic_notifier_list, nb); >>> + >>> +    return &info->atomic_notifier_list; >>> +} >>> +EXPORT_SYMBOL_GPL(qcom_register_ssr_atomic_notifier); >>> + >>> +/** >>> + * qcom_unregister_ssr_atomic_notifier() - unregister SSR Atomic >>> notification >>> + *                       handler >>> + * @notify:    subsystem cookie returned from >>> qcom_register_ssr_notifier >>> + * @nb:        notifier_block to unregister >>> + * >>> + * This function will unregister the notifier from the atomic notifier >>> + * chain. >>> + * >>> + * Return: 0 on success, %ENOENT otherwise. >>> + */ >>> +int qcom_unregister_ssr_atomic_notifier(void *notify, struct >>> notifier_block *nb) >>> +{ >>> +    return atomic_notifier_chain_unregister(notify, nb); >>> +} >>> +EXPORT_SYMBOL_GPL(qcom_unregister_ssr_atomic_notifier); >>> + >>>   static int ssr_notify_prepare(struct rproc_subdev *subdev) >>>   { >>>       struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev); >>> @@ -467,6 +514,18 @@ static void ssr_notify_unprepare(struct >>> rproc_subdev *subdev) >>>                    QCOM_SSR_AFTER_SHUTDOWN, &data); >>>   } >>> +static void ssr_notify_crash(struct rproc_subdev *subdev) >>> +{ >>> +    struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev); >>> +    struct qcom_ssr_notify_data data = { >>> +        .name = ssr->info->name, >>> +        .crashed = true, >>> +    }; >>> + >>> +    atomic_notifier_call_chain(&ssr->info->atomic_notifier_list, >>> +                   QCOM_SSR_NOTIFY_CRASH, &data); >>> +} >>> + >>>   /** >>>    * qcom_add_ssr_subdev() - register subdevice as restart >>> notification source >>>    * @rproc:    rproc handle >>> @@ -493,6 +552,7 @@ void qcom_add_ssr_subdev(struct rproc *rproc, >>> struct qcom_rproc_ssr *ssr, >>>       ssr->subdev.start = ssr_notify_start; >>>       ssr->subdev.stop = ssr_notify_stop; >>>       ssr->subdev.unprepare = ssr_notify_unprepare; >>> +    ssr->subdev.notify_crash = ssr_notify_crash; >>>       rproc_add_subdev(rproc, &ssr->subdev); >>>   } >>> diff --git a/drivers/remoteproc/remoteproc_core.c >>> b/drivers/remoteproc/remoteproc_core.c >>> index 695cce218e8c..3de0ece158ea 100644 >>> --- a/drivers/remoteproc/remoteproc_core.c >>> +++ b/drivers/remoteproc/remoteproc_core.c >>> @@ -1139,6 +1139,16 @@ static void rproc_unprepare_subdevices(struct >>> rproc *rproc) >>>       } >>>   } >>> +static void rproc_notify_crash_subdevices(struct rproc *rproc) >>> +{ >>> +    struct rproc_subdev *subdev; >>> + >>> +    list_for_each_entry_reverse(subdev, &rproc->subdevs, node) { >>> +        if (subdev->notify_crash) >>> +            subdev->notify_crash(subdev); >>> +    } >>> +} >>> + >>>   /** >>>    * rproc_alloc_registered_carveouts() - allocate all carveouts >>> registered >>>    * in the list >>> @@ -2687,6 +2697,8 @@ void rproc_report_crash(struct rproc *rproc, >>> enum rproc_crash_type type) >>>       dev_err(&rproc->dev, "crash detected in %s: type %s\n", >>>           rproc->name, rproc_crash_to_string(type)); >>> +    rproc_notify_crash_subdevices(rproc); >>> + >>>       queue_work(rproc_recovery_wq, &rproc->crash_handler); >>>   } >>>   EXPORT_SYMBOL(rproc_report_crash); >>> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h >>> index fe8978eb69f1..f3c0e0103e81 100644 >>> --- a/include/linux/remoteproc.h >>> +++ b/include/linux/remoteproc.h >>> @@ -596,6 +596,8 @@ struct rproc { >>>    * @stop: stop function, called before the rproc is stopped; the >>> @crashed >>>    *        parameter indicates if this originates from a recovery >>>    * @unprepare: unprepare function, called after the rproc has been >>> stopped >>> + * @notify_crash: notify_crash function, called in atomic context to >>> notify >>> + *          rproc has crashed and recovery is about to start >>>    */ >>>   struct rproc_subdev { >>>       struct list_head node; >>> @@ -604,6 +606,7 @@ struct rproc_subdev { >>>       int (*start)(struct rproc_subdev *subdev); >>>       void (*stop)(struct rproc_subdev *subdev, bool crashed); >>>       void (*unprepare)(struct rproc_subdev *subdev); >>> +    void (*notify_crash)(struct rproc_subdev *subdev); >>>   }; >>>   /* we currently support only two vrings per rvdev */ >>> diff --git a/include/linux/remoteproc/qcom_rproc.h >>> b/include/linux/remoteproc/qcom_rproc.h >>> index 82b211518136..f3d06900f297 100644 >>> --- a/include/linux/remoteproc/qcom_rproc.h >>> +++ b/include/linux/remoteproc/qcom_rproc.h >>> @@ -11,12 +11,14 @@ struct notifier_block; >>>    * @QCOM_SSR_AFTER_POWERUP:    Remoteproc is running (start stage) >>>    * @QCOM_SSR_BEFORE_SHUTDOWN:    Remoteproc crashed or shutting >>> down (stop stage) >>>    * @QCOM_SSR_AFTER_SHUTDOWN:    Remoteproc is down (unprepare stage) >>> + * @QCOM_SSR_NOTIFY_CRASH:    Remoteproc crashed >>>    */ >>>   enum qcom_ssr_notify_type { >>>       QCOM_SSR_BEFORE_POWERUP, >>>       QCOM_SSR_AFTER_POWERUP, >>>       QCOM_SSR_BEFORE_SHUTDOWN, >>>       QCOM_SSR_AFTER_SHUTDOWN, >>> +    QCOM_SSR_NOTIFY_CRASH, >>>   }; >>>   struct qcom_ssr_notify_data { >>> @@ -29,6 +31,10 @@ struct qcom_ssr_notify_data { >>>   void *qcom_register_ssr_notifier(const char *name, struct >>> notifier_block *nb); >>>   int qcom_unregister_ssr_notifier(void *notify, struct >>> notifier_block *nb); >>> +void *qcom_register_ssr_atomic_notifier(const char *name, >>> +                    struct notifier_block *nb); >>> +int qcom_unregister_ssr_atomic_notifier(void *notify, >>> +                    struct notifier_block *nb); >>>   #else >>>   static inline void *qcom_register_ssr_notifier(const char *name, >>> @@ -43,6 +49,17 @@ static inline int >>> qcom_unregister_ssr_notifier(void *notify, >>>       return 0; >>>   } >>> +static inline void *qcom_register_ssr_atomic_notifier(const char *name, >>> +                              struct notifier_block *nb) >>> +{ >>> +    return 0; >>> +} >>> + >>> +static inline int qcom_unregister_ssr_atomic_notifier(void *notify, >>> +                              struct notifier_block *nb) >>> +{ >>> +    return 0; >>> +} >>>   #endif >>>   #endif >>