Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp52421rdb; Thu, 21 Dec 2023 02:31:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEx48by47zWmhpMeEcFFMbpbdCWMDYkHcyCYMr1NxYftwlh97j3xWEzdTN7rCrxLKMdsEvZ X-Received: by 2002:a05:6a20:be28:b0:185:876f:4f4d with SMTP id ge40-20020a056a20be2800b00185876f4f4dmr1053619pzb.32.1703154707676; Thu, 21 Dec 2023 02:31:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703154707; cv=pass; d=google.com; s=arc-20160816; b=n/DjgbrOXh9o4M9pp0cXWAqiMXjs1030dbyJVXw942XUA1RF4bZlzlCExGXhu85rHU WwxiNK+FL8Q/BbX3HnbhDe1wWvdq3fRbuWv2XX79vNn0KY8jspXUjuaMm2ITLspOTtha NdEV1/wdq7OxCAU/uowSSIhaQh/7+vHy5r4wjWtpPqrcHfTLNGsLjFG3Neu/QD9Skp30 H9gbnNfuT9TIj3ge6bk6oXYOPsOhK37wbDkHX6gHceAOvLnILXIyKNeL4HASZVR8ZDmr xdOCtDeHW82BoKylrhyTZKQgumOpMAM4x5FKUw7N8eeguoWx9gBQWAx4QlOtl5W0BQhj Rlxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:content-language:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=C5hSi6kW0BKxiA12DlSe40Arfjwiw9b/a4KsS2i+z64=; fh=APyQkxmZeeK5DZvaFvSUNTobSsjYehnR+whn/wZrdOQ=; b=Wb+tHXO5/L/DW1f7CbBMN7Pg/epQGem8RPyhSsMh4PMuHler/SXQCd3tEwIdkWK1tb mjZ3AQVUrhb5039EDEBaihTpn9SKBbvj4uEG8mrWFuOC8R0m4TT5UOkvhAdKAY8AOIx+ eJG4MMnf7vnD4CD6qxYA8Ws2r7LfFFN/RjowfAUKZ5NVOTerpJKcgbPw4PQ0ZFqve94t iF+INT2oDoSFW1lAeh+xrAFneVRsUiCWJd/Qv7P4giLToiTYHUzEA1ylO2gFVni90ETu ppRWos/Q9XHMVbt2L+0VNZmw2FR3yOpKAWZdd3v1fWQWNTEOMilorBBOP80w27g4/z1n yKHA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=cixtech.com dkim=pass dkdomain=cixtech.com dmarc=pass fromdomain=cixtech.com); spf=pass (google.com: domain of linux-kernel+bounces-8201-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8201-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id fa22-20020a056a002d1600b006d93b1e51c3si1338663pfb.140.2023.12.21.02.31.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 02:31:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8201-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=cixtech.com dkim=pass dkdomain=cixtech.com dmarc=pass fromdomain=cixtech.com); spf=pass (google.com: domain of linux-kernel+bounces-8201-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8201-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 91D4DB22CB0 for ; Thu, 21 Dec 2023 10:31:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41B1064732; Thu, 21 Dec 2023 10:31:40 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2047.outbound.protection.outlook.com [40.107.255.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E7C064146; Thu, 21 Dec 2023 10:31:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cixtech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cixtech.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dLYW98FDav+nWPveQp1pvHE80oATtFDvYrvmGW9/iDQQk8bC2kTTri2gzseYgnxtoMkqD5xDx955ebR4pk7O90RZoIgBSbVe9yAk5Ti/egicBU6Ds9Q5qrzdXfOJPWuaJfS+zlnmcOwQKvuU+ItSRcy7C4CZnyxTPWA9Or2o/nLcIhf4w1YEx0MSqXOZ0EHn3u2YO4h0Kf35R7UybMRPaYqktc9Vf5smX+3EDE7LVoMV/M8PxGob+i5xR2z2GC45F/HuBIc/3R3ZTWRrzj/8mSP6OdVJQIX+PMkRv7hEORTQKOYTpdidM1J9gkNG7gB/sS/DZSCgXOzZIvDdz3wV3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C5hSi6kW0BKxiA12DlSe40Arfjwiw9b/a4KsS2i+z64=; b=fsIXjAeS0aSZlC42eydypjeNvx8rsimB9ezOvJKS48YJR7CdNI+p5YIKs4g7l3iONKZFcOskODCjcBru3YaZmIddvZ5v0Lyf2+zFCqbvRTLJp9Cq6diQ9O4WVgSdLNoD9PCkQvoaVsNYXGptnBv53+uvsVBrJlaSm7E3XMDbbbKdb5UZSaBzZeAK8u2g8xGf5nAl+C8/rt25e1vACYEErRJVbZ1KbeKhJagTNC4OtL19NJS/LrBd7Xzi48FgZVcm+Bb9eDsstxxDl+BXqL97Pxjd8Vnon3IN8I/BfxL3l/TmQCkA8HH8JUoF3BBI+YyMEiqVp7x0Kezskz4LE8azZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cixtech.com; dmarc=pass action=none header.from=cixtech.com; dkim=pass header.d=cixtech.com; arc=none Received: from PUZPR06MB5498.apcprd06.prod.outlook.com (2603:1096:301:101::14) by JH0PR06MB6415.apcprd06.prod.outlook.com (2603:1096:990:14::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.20; Thu, 21 Dec 2023 10:31:30 +0000 Received: from PUZPR06MB5498.apcprd06.prod.outlook.com ([fe80::f3a3:b8e8:6e3f:70b1]) by PUZPR06MB5498.apcprd06.prod.outlook.com ([fe80::f3a3:b8e8:6e3f:70b1%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 10:31:29 +0000 From: Xinglong Yang To: Cristian Marussi , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" CC: "sudeep.holla@arm.com" , "vincent.guittot@linaro.org" , "stable@vger.kernel.org" Subject: RE: [PATCH] firmware: arm_scmi: Check Mailbox/SMT channel for consistency Thread-Topic: [PATCH] firmware: arm_scmi: Check Mailbox/SMT channel for consistency Thread-Index: AQHaM2j73q0S6m9b4UmorQvngEo3CLCzio0g Date: Thu, 21 Dec 2023 10:31:29 +0000 Message-ID: References: <20231220172112.763539-1-cristian.marussi@arm.com> In-Reply-To: <20231220172112.763539-1-cristian.marussi@arm.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cixtech.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PUZPR06MB5498:EE_|JH0PR06MB6415:EE_ x-ms-office365-filtering-correlation-id: 80d67579-9247-48d4-40c4-08dc020ffe8b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RdatFF+7BDTGR/Dt/tv8YnnIXxCOUSS420G/ixGYG2b+o1wK5OsjfxSULgYMd6+AzmZnXx5OOjdqjsb2srjmbdKTVryxWQ0YfA9IpMByI7kEejjTJcO1UM0XZjni0kgm6Xu8iE50BEtfHSSWd/bhYX9FWC3gEonqou2dlGs+Gr7+y/s9+oA3gySeuDkFSG4e2AJ96mk6u1E+a9oCJAX2jVDg45/bDQREXfFwPxWUs5j3mVW6i22McAUbS2msvHS+ZKQGodEAUO2hWQd078JSOFtUaDZCvPa9+yOA/jpvqk0ksXVVynMTn8X/H+GH0dFJvvbTEjGhkVgshOZB1YiS3IlkJotSL5G4iByAsG3C8Ju1p6imWRLUmvVcpccrSGDWdXnlzz91DgjI76bBCddrY6mOwbBze16s3D/vo53paWMDV4/HZ1xzm1K8FOPVXtL3tO/gzekdOUVyn6TgSWPtsDjJrEbvkPt+xc0GeSywIGs1KsEM43hHVOtV0UX39IiT/KeC36aTVeUwYpDr6TsO5adY9xsnl4ri5RMXIqs6Uw+rvZ0gAJ9S8XE0CbJqd3okorUrYPpD1EQouCqWe0/9szJo9ujeqBOCeect6Vre5D8= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB5498.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39840400004)(376002)(346002)(396003)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(2906002)(5660300002)(15650500001)(6506007)(9686003)(41300700001)(26005)(83380400001)(122000001)(71200400001)(45080400002)(478600001)(966005)(38100700002)(7696005)(38070700009)(66556008)(66476007)(64756008)(66446008)(66946007)(44832011)(76116006)(8676002)(8936002)(33656002)(54906003)(110136005)(316002)(86362001)(4326008)(52536014)(55016003);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?XP/6du1ofuNes8V5tKfJhh4NrahJ0HPhhGsGaeZIuC4JtKFyZhdiuSeZ6ehb?= =?us-ascii?Q?uwSpMl1rWA3CjT33irk/GlxAGLrfW+3/TS21CBuwfl0b1HWMuzv8jdP1zTXd?= =?us-ascii?Q?YHgDwad4mhRLRc4h2J+q7AL0WfkVlHOVqSprItqd7bzjSbjKyVUGWgDKH2Vt?= =?us-ascii?Q?CuDVpc6nih7MHrVVazW5LWc2DemypNCbK4xDlUzKfm5BkVbNADll1J1QePuB?= =?us-ascii?Q?ZFBxXf9YpaVWJ7HNTFpsrxrklpRKf8RVVvOCc5e4ThSr9wMXyifHYNSnyhnm?= =?us-ascii?Q?hfnhrn5uDyrHaWAZ4uSRyNgdMJWWACfKgEqsAOhMvBirSwKtb7ND+uDnQE4e?= =?us-ascii?Q?vXOVXcaIwSLclNqJA3h9kxq10JIS2j3eAvBlMlJwi1LOX/1SFfnUkzWolHU0?= =?us-ascii?Q?c2rhYI+KQOK/JAjKYtqvXO78mXT5Q+OpzwL9fLR4CxJ+Mqzw9Rlpzb6UN4wA?= =?us-ascii?Q?aXMET6H3rkaOSI9CGw/rN/WtV8W6N2Bhv2rdR3tb2zWkeNgwxC6GHAvyOh6O?= =?us-ascii?Q?kjD8hQ0fliGDqF3e5QaStWr+jJcmdP7BJ9AJLzpAR3lnARA1gyKAaRwadeai?= =?us-ascii?Q?5xZNDVG9SGaku4hkSjmtBRQ3UT3oa+tRuLcyYMg65qPa8YOYiFg87g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QiD4GAbIFO5vo/vjn4clTMxp/h8tOhTVSBcmH2w?= =?us-ascii?Q?lzm/XUCXdbtn+WDhrEl5INmuX3Jf9DBVF3M32CbW?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: cixtech.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5498.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 80d67579-9247-48d4-40c4-08dc020ffe8b X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Dec 2023 10:31:29.7499 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0409f77a-e53d-4d23-943e-ccade7cb4811 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 8l1Fg+SGVagXG0VrFb7JLfzY3GD8O8NLylqETcgX7/wLIjpdyxXUEyJEW0olnGUjNjr5sJLHhJcBpnydAKoJUs3diJs056hS1MmfqIY4MA4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB6415 Hi, Cristian This patch successfully solves the bug. From: Cristian Marussi Sent: Thursday, December = 21, 2023 1:21 AM > On reception of a completion interrupt the SMT memory area is accessed to > retrieve the message header at first and then, if the message sequence > number identifies a transaction which is still pending, the related > payload is fetched too. > > When an SCMI command times out the channel ownership remains with the > platform until eventually a late reply is received and, as a consequence, > any further transmission attempt remains pending, waiting for the channel > to be relinquished by the platform. > > Once that late reply is received the channel ownership is given back > to the agent and any pending request is then allowed to proceed and > overwrite the SMT area of the just delivered late reply; then the wait fo= r > the reply to the new request starts. > > It has been observed that the spurious IRQ related to the late reply can > be wrongly associated with the freshly enqueued request: when that > happens > the SCMI stack in-flight lookup procedure is fooled by the fact that the > message header now present in the SMT area is related to the new pending > transaction, even though the real reply has still to arrive. > > This race-condition on the A2P channel can be detected by looking at the > channel status bits: a genuine reply from the platform will have set the > channel free bit before triggering the completion IRQ. > > Add a consistency check to validate such condition in the A2P ISR. > > Reported-by: Xinglong Yang > Closes: > https://lore.k/ > ernel.org%2Fall%2FPUZPR06MB54981E6FA00D82BFDBB864FBF08DA%40PUZP > R06MB5498.apcprd06.prod.outlook.com%2F&data=3D05%7C02%7Cxinglong.ya > ng%40cixtech.com%7C669e9ff5e6764a77791208dc01801b8e%7C0409f77ae53 > d4d23943eccade7cb4811%7C1%7C0%7C638386896955072826%7CUnknown% > 7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haW > wiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3DT1DOD7KfY%2FJNJHacHtX > d5wcfde%2Fd5UDqGvyW4vuYwYU%3D&reserved=3D0 > Fixes: 5c8a47a5a91d ("firmware: arm_scmi: Make scmi core independent of > the transport type") > CC: stable@vger.kernel.org # 5.15+ > Signed-off-by: Cristian Marussi > --- > drivers/firmware/arm_scmi/common.h | 1 + > drivers/firmware/arm_scmi/mailbox.c | 14 ++++++++++++++ > drivers/firmware/arm_scmi/shmem.c | 6 ++++++ > 3 files changed, 21 insertions(+) > > diff --git a/drivers/firmware/arm_scmi/common.h > b/drivers/firmware/arm_scmi/common.h > index 3b7c68a11fd0..0956c2443840 100644 > --- a/drivers/firmware/arm_scmi/common.h > +++ b/drivers/firmware/arm_scmi/common.h > @@ -329,6 +329,7 @@ void shmem_fetch_notification(struct > scmi_shared_mem __iomem *shmem, > void shmem_clear_channel(struct scmi_shared_mem __iomem *shmem); > bool shmem_poll_done(struct scmi_shared_mem __iomem *shmem, > struct scmi_xfer *xfer); > +bool shmem_channel_free(struct scmi_shared_mem __iomem *shmem); > > /* declarations for message passing transports */ > struct scmi_msg_payld; > diff --git a/drivers/firmware/arm_scmi/mailbox.c > b/drivers/firmware/arm_scmi/mailbox.c > index 19246ed1f01f..b8d470417e8f 100644 > --- a/drivers/firmware/arm_scmi/mailbox.c > +++ b/drivers/firmware/arm_scmi/mailbox.c > @@ -45,6 +45,20 @@ static void rx_callback(struct mbox_client *cl, void *= m) > { > struct scmi_mailbox *smbox =3D client_to_scmi_mailbox(cl); > > + /* > + * An A2P IRQ is NOT valid when received while the platform still= has > + * the ownership of the channel, because the platform at first re= leases > + * the SMT channel and then sends the completion interrupt. > + * > + * This addresses a possible race condition in which a spurious I= RQ from > + * a previous timed-out reply which arrived late could be wrongly > + * associated with the next pending transaction. > + */ > + if (cl->knows_txdone && !shmem_channel_free(smbox->shmem)) { > + dev_warn(smbox->cinfo->dev, "Ignoring spurious A2P IRQ !\= n"); > + return; > + } > + > scmi_rx_callback(smbox->cinfo, shmem_read_header(smbox->shmem), > NULL); > } > > diff --git a/drivers/firmware/arm_scmi/shmem.c > b/drivers/firmware/arm_scmi/shmem.c > index 87b4f4d35f06..517d52fb3bcb 100644 > --- a/drivers/firmware/arm_scmi/shmem.c > +++ b/drivers/firmware/arm_scmi/shmem.c > @@ -122,3 +122,9 @@ bool shmem_poll_done(struct scmi_shared_mem > __iomem *shmem, > (SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR | > SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE); > } > + > +bool shmem_channel_free(struct scmi_shared_mem __iomem *shmem) > +{ > + return (ioread32(&shmem->channel_status) & > + SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE); > +} > -- > 2.34.1 Thanks, Xinglong