From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3FD0CC4332F for ; Wed, 12 Oct 2022 09:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=M7502ku/e5fNA/A4P57/PEIN2TvPT0EuGK/VPGQbd3g=; b=MacXnhWmnk38D8 gWpdywljL60ldQHCS2hJgf5ZwboQ1PiZQ87fEunhz13G3oqS0rWP3gQ0VGXCxygFgadLEBs35bIJN cYeiEXKfftKNalcuqx1wdF9MmWY5UyRG4LMNL3USckmPlDzR5f6urz4pU5kKes3jm0qCNLwDiWV41 hs2pOQM0bIVxe7UXbNhKPz2Sz6zGAYhmE7HOsCnsUCZx0/pSXzHHiwJthYxPDSDT/5DB/fJV+HNBw jE6Mw5GEx6T55W5NOkVCLPhS3LbAfKj2gY86OtWNNvs+XDOxEew8cA9+JHlF4KFwikWfgFMb2Y4rs 8ZQyiidc4WY08Z+u05ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oiXtO-007UlN-JZ; Wed, 12 Oct 2022 09:19:10 +0000 Received: from mx07-00178001.pphosted.com ([185.132.182.106]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oiXtK-007Ukf-NA for linux-arm-kernel@lists.infradead.org; Wed, 12 Oct 2022 09:19:08 +0000 Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29C93s5T002826; Wed, 12 Oct 2022 11:18:47 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=message-id : date : mime-version : subject : to : references : from : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=QeR3StUuPI4Ywk33EQuu/st80pAWGF0S/quurB7Ni1I=; b=k0HWvn+3u29vlgk7no3ReOnv3TShymClSjjdusvbSokuG2dlmJ388UIWNh9HKx8Up2DF PpwAPS7XhV3D37a4Cu2N1pJ9xJeShG0klxdlrGwouyYAU5UkYiegV5g2w6P8cHIFXCL5 exkqUXCQaKX+BBn8hPBY39oxW2EFgoiuGAqSCITbi7jD5uD/vc/fNdnUo2x0rDOuP5Xz CrJ1XVOfdv54/x1iuRJUV5NerD3f/nOh5TWboJs4NvrmBoDK54z7ZG+JyJ6VVykG7pOC xu9CtXxO7dDFfYNP3CLSzwQsT0W0cMMn4t//znz6fHEQq9dRPpfbrXbM2Bktjymu9jg5 dw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3k5tmag3rd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Oct 2022 11:18:47 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0BE43100034; Wed, 12 Oct 2022 11:18:42 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 05DBD2194F3; Wed, 12 Oct 2022 11:18:42 +0200 (CEST) Received: from [10.201.22.54] (10.75.127.123) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2375.31; Wed, 12 Oct 2022 11:18:38 +0200 Message-ID: <48b74c23-7d11-deff-8bf7-0dfb45c80e37@foss.st.com> Date: Wed, 12 Oct 2022 11:18:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v2] remoteproc: imx_dsp_rproc: Add mutex protection for workqueue Content-Language: en-US To: Shengjiu Wang , , , , , , , , , , , References: <1664524216-19949-1-git-send-email-shengjiu.wang@nxp.com> From: Arnaud POULIQUEN In-Reply-To: <1664524216-19949-1-git-send-email-shengjiu.wang@nxp.com> X-Originating-IP: [10.75.127.123] X-ClientProxiedBy: GPXDAG2NODE4.st.com (10.75.127.68) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-12_04,2022-10-11_02,2022-06-22_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221012_021907_088968_4B3E3DE4 X-CRM114-Status: GOOD ( 31.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Mathieu, On 9/30/22 09:50, Shengjiu Wang wrote: > The workqueue may execute late even after remoteproc is stopped or > stopping, some resources (rpmsg device and endpoint) have been > released in rproc_stop_subdevices(), then rproc_vq_interrupt() > accessing these resources will cause kennel dump. > > Call trace: > virtqueue_add_split+0x1ac/0x560 > virtqueue_add_inbuf+0x4c/0x60 > rpmsg_recv_done+0x15c/0x294 > vring_interrupt+0x6c/0xa4 > rproc_vq_interrupt+0x30/0x50 > imx_dsp_rproc_vq_work+0x24/0x40 [imx_dsp_rproc] > process_one_work+0x1d0/0x354 > worker_thread+0x13c/0x470 > kthread+0x154/0x160 > ret_from_fork+0x10/0x20 > > Add mutex protection in imx_dsp_rproc_vq_work(), if the state is > not running, then just skip calling rproc_vq_interrupt(). > > Also the flush workqueue operation can't be added in rproc stop > for the same reason. The call sequence is > > rproc_shutdown > -> rproc_stop > ->rproc_stop_subdevices > ->rproc->ops->stop() > ->imx_dsp_rproc_stop > ->flush_work > -> rproc_vq_interrupt > > The resource needed by rproc_vq_interrupt has been released in > rproc_stop_subdevices, so flush_work is not safe to be called in > imx_dsp_rproc_stop. > > Fixes: ec0e5549f358 ("remoteproc: imx_dsp_rproc: Add remoteproc driver for DSP on i.MX") > Signed-off-by: Shengjiu Wang > Reviewed-by: Peng Fan > --- > changes in v2: > - update commit message > > drivers/remoteproc/imx_dsp_rproc.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/drivers/remoteproc/imx_dsp_rproc.c b/drivers/remoteproc/imx_dsp_rproc.c > index 899aa8dd12f0..95da1cbefacf 100644 > --- a/drivers/remoteproc/imx_dsp_rproc.c > +++ b/drivers/remoteproc/imx_dsp_rproc.c > @@ -347,9 +347,6 @@ static int imx_dsp_rproc_stop(struct rproc *rproc) > struct device *dev = rproc->dev.parent; > int ret = 0; > > - /* Make sure work is finished */ > - flush_work(&priv->rproc_work); > - > if (rproc->state == RPROC_CRASHED) { > priv->flags &= ~REMOTE_IS_READY; > return 0; > @@ -432,9 +429,18 @@ static void imx_dsp_rproc_vq_work(struct work_struct *work) > { > struct imx_dsp_rproc *priv = container_of(work, struct imx_dsp_rproc, > rproc_work); > + struct rproc *rproc = priv->rproc; > + > + mutex_lock(&rproc->lock); > + > + if (rproc->state != RPROC_RUNNING) > + goto unlock_mutex; > > rproc_vq_interrupt(priv->rproc, 0); > rproc_vq_interrupt(priv->rproc, 1); > + > +unlock_mutex: > + mutex_unlock(&rproc->lock); > } I guess that this fix the issue in case of the use of a work queue for the notification. As I reproduced the issue on stm32 only one time without fix, difficult for me to test the fix... I also have a look on some other drivers It seems not applicable for some other drivers such as TI k3 R5[1] that call virtio under interrupt context ( if I have well understood). An alternative to try to fix that in a more generic way could be to call rproc_remove_virtio_dev in the subdev->unprepare, instead of subdev->stop. This should postpone the virtio unregister after the stop of the coprocessor. Of course it is only a suggestion/area of improvement, this fix LGTM. [1]https://elixir.bootlin.com/linux/v6.0/source/drivers/remoteproc/ti_k3_r5_remoteproc.c#L180 Regards, Arnaud > > /** _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel