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 X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A76EC47404 for ; Sun, 6 Oct 2019 00:57:48 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CC92F222C8 for ; Sun, 6 Oct 2019 00:57:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="G2K1CIgQ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="AtxqRVoQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC92F222C8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eaXP4TNYHlvlxJA3JN9AsX1fx7F62dMvfrq8V1+GCYw=; b=G2K1CIgQazLatk KoWQPEIOZfsufwTaXkMCvdPfNgs++p+14VVR6UKNsVYdcg9MkSWuECT6AKaUcF3Pqgc0tpMq5tpV8 +LnDbCb/3EeI7dediUoTAYV2sKczKXA8g6BzDMT1IoX2PCBOR2Xe+mlhrpGIL8xToWx+zslqUvZdt fgGIthU7OEPru8lxhHsy2JqbqiAT56iI2fIfQqXgrtAqqctt2gvpZAtePORlCaoEHENs8GWnbaDpr z+SgSTsI9jRiLD5CKfNpmF1AWMFX1YA08tfOJc/ns3QHEO7B+LH93G14sokJADio9KpMJPRkapTa/ lJkrdUxlezafksnsitqw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGurr-0007jM-9Y; Sun, 06 Oct 2019 00:57:47 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iGuro-0007j0-Dz for linux-arm-kernel@lists.infradead.org; Sun, 06 Oct 2019 00:57:45 +0000 Received: from dragon (li937-157.members.linode.com [45.56.119.157]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC021222C0; Sun, 6 Oct 2019 00:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570323464; bh=rmuqA41XcdwAILHT6rtO2iZ544NaVH4xAkRw9fxgCdk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AtxqRVoQyOuSCL/hDq8q+6R5FNqEWIiN9D9kdbruEqaNizgTF8W+MwqSw8gvDPaAY w2TNiXkFdmBdlmpbYg7cjHC/bgfwehLNyicI6ukWL6FJ7VbKyyMeXd++Elrdg/P5z5 UDz+7IA0O22zpB3o/DbquwWIpXPwsUPYCsTIZ080= Date: Sun, 6 Oct 2019 08:57:30 +0800 From: Shawn Guo To: Leonard Crestez Subject: Re: [PATCH] firmware: imx: warn on unexpected RX Message-ID: <20191006005729.GE7150@dragon> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191005_175744_490824_CB2CAD63 X-CRM114-Status: GOOD ( 20.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dong Aisheng , Anson Huang , Jassi Brar , linux-imx@nxp.com, kernel@pengutronix.de, Fabio Estevam , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Sep 04, 2019 at 10:54:58AM +0300, Leonard Crestez wrote: > The imx_scu_call_rpc function function returns the result inside the s/function function/function > same "msg" struct containing the transmitted message. This is > implemented by holding a pointer to msg (which is usually on the stack) > in sc_imx_rpc and writing to it from imx_scu_rx_callback. > > This means that if the have_resp parameter is incorrect or SCU sends an > unexpected for any reason the most likely result is kernel stack unexpected response I fixed them up and applied the patch. Shawn > corruption. > > Fix this by only setting sc_imx_rpc.msg for the duration of the > imx_scu_call_rpc call and warning in imx_scu_rx_callback if unset. > > Print the unexpected response data to help debugging. > > Signed-off-by: Leonard Crestez > --- > drivers/firmware/imx/imx-scu.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/firmware/imx/imx-scu.c b/drivers/firmware/imx/imx-scu.c > index 04a24a863d6e..869be7a5172c 100644 > --- a/drivers/firmware/imx/imx-scu.c > +++ b/drivers/firmware/imx/imx-scu.c > @@ -105,10 +105,16 @@ static void imx_scu_rx_callback(struct mbox_client *c, void *msg) > struct imx_sc_chan *sc_chan = container_of(c, struct imx_sc_chan, cl); > struct imx_sc_ipc *sc_ipc = sc_chan->sc_ipc; > struct imx_sc_rpc_msg *hdr; > u32 *data = msg; > > + if (!sc_ipc->msg) { > + dev_warn(sc_ipc->dev, "unexpected rx idx %d 0x%08x, ignore!\n", > + sc_chan->idx, *data); > + return; > + } > + > if (sc_chan->idx == 0) { > hdr = msg; > sc_ipc->rx_size = hdr->size; > dev_dbg(sc_ipc->dev, "msg rx size %u\n", sc_ipc->rx_size); > if (sc_ipc->rx_size > 4) > @@ -163,11 +169,12 @@ int imx_scu_call_rpc(struct imx_sc_ipc *sc_ipc, void *msg, bool have_resp) > return -EINVAL; > > mutex_lock(&sc_ipc->lock); > reinit_completion(&sc_ipc->done); > > - sc_ipc->msg = msg; > + if (have_resp) > + sc_ipc->msg = msg; > sc_ipc->count = 0; > ret = imx_scu_ipc_write(sc_ipc, msg); > if (ret < 0) { > dev_err(sc_ipc->dev, "RPC send msg failed: %d\n", ret); > goto out; > @@ -185,10 +192,11 @@ int imx_scu_call_rpc(struct imx_sc_ipc *sc_ipc, void *msg, bool have_resp) > hdr = msg; > ret = hdr->func; > } > > out: > + sc_ipc->msg = NULL; > mutex_unlock(&sc_ipc->lock); > > dev_dbg(sc_ipc->dev, "RPC SVC done\n"); > > return imx_sc_to_linux_errno(ret); > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel