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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D52BC7EE26 for ; Mon, 1 May 2023 03:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233110AbjEADQ7 (ORCPT ); Sun, 30 Apr 2023 23:16:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233034AbjEADNy (ORCPT ); Sun, 30 Apr 2023 23:13:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DEA846A8; Sun, 30 Apr 2023 20:05:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8CE6261779; Mon, 1 May 2023 03:05:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D32BBC433A0; Mon, 1 May 2023 03:05:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682910303; bh=L4+K2FOZGL2vNUkKFgGDiM/jDho4psOTn0+IDn0nViY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VH0OAMiImEEO4Nl4JzPP2Xc8F0iEZp2fRTAcQ+Yyw8AF1ZCr67ViAgPWnfABgc9T2 9LS8HVrh047P9E2z58U2/l+DDAKcHC8sRXdXCWAus5jxWrdoh0/v9/O0eV3MvYhqNy TyiJNXB3IlgcH1ENSiVzhugMBvA4t8nAKt6BMnW/ePGDI5chfAtD4I/2C5oJw9rXlp nB8wZhIaGYXNa50MNuTibRBH+OxaDYRS1w4dIcJWX2QwA7mCFmiYUQIHp2L8h1uo5x heXMaEyo/HB++Y1teNOorOwT0nimeqq3t16kkjuqG1CCkJ+UBEZBEvY8b2OlNsSs6F dztt0QwAuGBBQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arnaud Pouliquen , Mathieu Poirier , Sasha Levin , andersson@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-remoteproc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.15 10/17] remoteproc: stm32_rproc: Add mutex protection for workqueue Date: Sun, 30 Apr 2023 23:04:27 -0400 Message-Id: <20230501030435.3254695-10-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230501030435.3254695-1-sashal@kernel.org> References: <20230501030435.3254695-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Arnaud Pouliquen [ Upstream commit 35bdafda40cc343ad2ba2cce105eba03a70241cc ] 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 kernel dump. Call trace: virtqueue_add_inbuf virtqueue_add_inbuf rpmsg_recv_single rpmsg_recv_done vring_interrupt stm32_rproc_mb_vq_work process_one_work worker_thread kthread Suggested-by: Mathieu Poirier Signed-off-by: Arnaud Pouliquen Link: https://lore.kernel.org/r/20230331160634.3113031-1-arnaud.pouliquen@foss.st.com Signed-off-by: Mathieu Poirier Signed-off-by: Sasha Levin --- drivers/remoteproc/stm32_rproc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index b643efcf995a1..bc91d99db60f2 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -287,8 +287,16 @@ static void stm32_rproc_mb_vq_work(struct work_struct *work) struct stm32_mbox *mb = container_of(work, struct stm32_mbox, vq_work); struct rproc *rproc = dev_get_drvdata(mb->client.dev); + mutex_lock(&rproc->lock); + + if (rproc->state != RPROC_RUNNING) + goto unlock_mutex; + if (rproc_vq_interrupt(rproc, mb->vq_id) == IRQ_NONE) dev_dbg(&rproc->dev, "no message found in vq%d\n", mb->vq_id); + +unlock_mutex: + mutex_unlock(&rproc->lock); } static void stm32_rproc_mb_callback(struct mbox_client *cl, void *data) -- 2.39.2