Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp3105422pxy; Wed, 4 Aug 2021 02:25:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxD8uYV1ebpuGdl3IkJidQmfgzjDFtOhGCfI8/JIXyj+Y+XATjNG1bTJqugZ/VEPDUBloED X-Received: by 2002:a17:906:94cd:: with SMTP id d13mr25603248ejy.158.1628069155025; Wed, 04 Aug 2021 02:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628069155; cv=none; d=google.com; s=arc-20160816; b=trF2KaCMIFnZ5T3bZ0vLxhpTuwUD3uxafYFSy5GmRUd5I6SQ0hnzHwKPVIBGOMTOAL 3anrmVtIU+7P2MLz4rparpel+zitoYtl20kL2U4H1JRX9pRyEPAnszyHDCOrB/72ZZWN 2poISlm1BILl1lMxlLE6aYH4JnA+9Em41OzMLdtrJsVGCKc5pW1cxV5EHg2grE7rF/N5 o5IlGcnTrlNmTDHAcjZXVoGSj844IbBS+rn+xt2Jz56wRS6Qoj31a6kGwCVeEtgmerW+ dk5eHYkuzacE9dR3fzu9QBTqNl5sjRPC8vRJIvJVv3tZxNeZhD96+Sbm2DeGRsqeC+Ad F31g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Xk31UhNafub9P5nKXSEElBMAA8dZPZ+P+xyLP7cczrY=; b=IM46fp8WUYYFOIfCXIJz/Y/fmiCgRC+vvlxz91s3sx1HPk6wNNHZxxEzsImTMQ+s2U VYI9TotlI+caJ8jYsozHd4oVACfkK5lnMxfFsccFN0K8GVD30tgxdWZHOuEZL+K5rcgD KKmHux5C8A2TpI/PWSA4RJ9SWE2roMjAFEF5CtdOt8dK5I5AQLwDNG0Cx+fWFytOKd2n C1ZvO9qhiX5xXdMO9+PCzm8v085QGKMpIfDggML9eAA95qnM9P8I3pb/JxBugxY7QhF3 ctu2n6Y2+l9qu+7th/FJEbAEL49UszpRMEsfqrZq1kNb+pgRemiYBeGn0trJhJB7vWNv FnhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o7si1488728edv.68.2021.08.04.02.25.31; Wed, 04 Aug 2021 02:25:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236642AbhHDIkt (ORCPT + 99 others); Wed, 4 Aug 2021 04:40:49 -0400 Received: from foss.arm.com ([217.140.110.172]:57608 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236477AbhHDIks (ORCPT ); Wed, 4 Aug 2021 04:40:48 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4C39831B; Wed, 4 Aug 2021 01:40:36 -0700 (PDT) Received: from e120937-lin (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 025663F66F; Wed, 4 Aug 2021 01:40:34 -0700 (PDT) Date: Wed, 4 Aug 2021 09:40:32 +0100 From: Cristian Marussi To: Rishabh Bhatnagar Cc: sudeep.holla@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, avajid@codeaurora.org, adharmap@codeaurora.org Subject: Re: [PATCH] firmware: arm_scmi: Free mailbox channels if probe fails Message-ID: <20210804084032.GS6592@e120937-lin> References: <1628029342-3638-1-git-send-email-rishabhb@codeaurora.org> <20210804083358.GR6592@e120937-lin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210804083358.GR6592@e120937-lin> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 04, 2021 at 09:33:58AM +0100, Cristian Marussi wrote: > On Tue, Aug 03, 2021 at 03:22:22PM -0700, Rishabh Bhatnagar wrote: > > Mailbox channels for the base protocol are setup during probe. > > There can be a scenario where probe fails to acquire the base > > protocol due to a timeout leading to cleaning up of all device > > managed memory including the scmi_mailbox structure setup during > > mailbox_chan_setup function. > > [ 12.735104]arm-scmi soc:qcom,scmi: timed out in resp(caller: version_get+0x84/0x140) > > [ 12.735224]arm-scmi soc:qcom,scmi: unable to communicate with SCMI > > [ 12.735947]arm-scmi: probe of soc:qcom,scmi failed with error -110 > > > > Now when a message arrives at cpu slightly after the timeout, the mailbox > > controller will try to call the rx_callback of the client and might end > > up accessing freed memory. > > [ 12.758363][ C0] Call trace: > > [ 12.758367][ C0] rx_callback+0x24/0x160 > > [ 12.758372][ C0] mbox_chan_received_data+0x44/0x94 > > [ 12.758386][ C0] __handle_irq_event_percpu+0xd4/0x240 > > This patch frees the mailbox channels setup during probe and adds some more > > error handling in case the probe fails. > > > > Change-Id: I1214ec2c4c92c4a3ca5fa73de11e0e403b13b46a > > Signed-off-by: Rishabh Bhatnagar > > Hi Rishabh, > > Good catch, thanks for this. > Hi again, sorry forgot one thing. > > --- > > drivers/firmware/arm_scmi/driver.c | 11 +++++++++-- > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c > > index 9b2e8d4..518c7b9 100644 > > --- a/drivers/firmware/arm_scmi/driver.c > > +++ b/drivers/firmware/arm_scmi/driver.c > > @@ -1430,7 +1430,7 @@ static int scmi_probe(struct platform_device *pdev) > > > > ret = scmi_xfer_info_init(info); > > if (ret) > > - return ret; > > + goto clear_txrx_setup; > > > > if (scmi_notification_init(handle)) > > dev_err(dev, "SCMI Notifications NOT available.\n"); > > @@ -1443,7 +1443,7 @@ static int scmi_probe(struct platform_device *pdev) > > ret = scmi_protocol_acquire(handle, SCMI_PROTOCOL_BASE); > > if (ret) { > > dev_err(dev, "unable to communicate with SCMI\n"); > > - return ret; > > + goto notification_exit; > > } > > > > mutex_lock(&scmi_list_mutex); > > @@ -1482,6 +1482,13 @@ static int scmi_probe(struct platform_device *pdev) > > } > > > > return 0; > > + > > +notification_exit: > > + scmi_notification_exit(&info->handle); > > +clear_txrx_setup: > > + idr_for_each(&info->tx_idr, info->desc->ops->chan_free, &info->tx_idr); > > + idr_for_each(&info->rx_idr, info->desc->ops->chan_free, &info->rx_idr); > > + return ret; > > } > > > > Shouldn't we also clear the internal IDRs memory allocs after these > idr_for_each() adding a couple of: > > idr_destroy(&info->tx_idr); > > idr_destroy(&info->rx_idr); > > like scmi_remove() does ? > Maybe it could be worth at this point unifying this common "cleanup-all-channels" logic shared between scmi_probe()-error-path and scmi_remove() into its own helper function to call from both sites. Thanks, Cristian