From nobody Tue Dec 16 16:38:44 2025 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011056.outbound.protection.outlook.com [52.101.52.56]) (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 033E112DDA1 for ; Thu, 11 Dec 2025 04:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765428694; cv=fail; b=FRU4KoxAZKhlc5cYpQRCqrdS5r1iQQOyxzWKQyfHKiDzinEgx0AHzwRUlxv2fDbH/K1eqAH7O/4aLWu6iSq8bziyYEVuiUpfrOmDmBpz52UMqZTgwr4hQSPWXE+5XJnFaiDnOymnwlp6Z2syTjafRLqPdn5Wl/4XwKlQ43AXVqQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765428694; c=relaxed/simple; bh=RbmHfnkbXdm7CpUkSgPiZtB56ajUbCx9sApidZY4wgk=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fUHXrS50pZJYJ1sRuoG0hG7dZoq1adKv02P5t10S558jPJOUx8D8N54Kb6KfJQ2yomBt+F9N1eWo6YHZvvhFrfkk06cqOW+2XcrV/S8wgmVx/A9TEQKFkjJLbXsDJERvp5zzoyAB8BbTw1NZs4syKplzu9fKrMuX3wbfWtikdas= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=TJc20buM; arc=fail smtp.client-ip=52.101.52.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="TJc20buM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Uunv5+qiFBZXr5NS+Fky29ofr6DENgdVP5xVPBu8Q2RUYyn/pBDm5XklarIiX4lgXZ/gLDz+Vb1mpmAlJtMU8mOuWD/0QFvvmeB4a9b3C3loEy0RcXLI6h4YZ0UcdqoAVD1ylo2DuLzqL19Bz0C79dcqnyUqEO9VexRsvlZHvAqeEh7+COMs2Y6nEo/SxtnKs5bm7WgoKSCKJYtHx1kcKjnwqIQ55pH0Bgl8IMg77Pppf3M9qOOIchx/qXIw+KcprTSGWbu/bYEXtZF/AVk0/LhhM0UK3qy3PMJ3lC9uboTm+VH0yBeDAI2AFI2eslfuO2ddEdVePfJFtBSI/XNl/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=zxn8WniToz39K5wwpSHEsIGPGsaj/k50KHKTHP1WVhI=; b=cYVcZsQhEYffe5fgOYJTK615AVZCS++JTF4yxDkWI8C8+iJeFw/M9QdRUQEupJBbyTrVTUssAjqEQ41Ek/Kzarp+TXMpH/5n4utNw/C4VGTsYTBSbQjlJg9RiWUzds2kmjoD7lwYoun4ReaSW1oGNb/4gY2TbyWE9DCfMtbAzTitecAlL67e8smWzuPg8p9v2kBp4r8QQtocsfhTjDSYn1DMZ8t+d3GMCP5gQ9BT9Adw0SlFYUZJJ5yGD0FKaPseNccyf3aBVt/QqN5zPv2NfxUS21PX/6M7zA+AM8lVvHPwW/meSYkTz8fAaFQDIe1anUHhKOuB0O5CIMJtoGMMrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zxn8WniToz39K5wwpSHEsIGPGsaj/k50KHKTHP1WVhI=; b=TJc20buMPhiO+wqBbILBMqSObYDJeSQD6aXNgCFxIcm6UpdsOwFntPLu9BeSDO1ahYk/l8ZQ0jN0jKpVGA2VpjOIJsqhzNw90T/2CF77AqMVFhvvK70unv2FK3Xg6Sz7rbiVpeJefhLj5ldqcN16Kjb7hrZHRec/BidFz0wloKE= Received: from SJ0PR13CA0239.namprd13.prod.outlook.com (2603:10b6:a03:2c1::34) by BY5PR12MB4196.namprd12.prod.outlook.com (2603:10b6:a03:205::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9412.9; Thu, 11 Dec 2025 04:51:28 +0000 Received: from SJ1PEPF000023D9.namprd21.prod.outlook.com (2603:10b6:a03:2c1:cafe::56) by SJ0PR13CA0239.outlook.office365.com (2603:10b6:a03:2c1::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9434.5 via Frontend Transport; Thu, 11 Dec 2025 04:51:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SJ1PEPF000023D9.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9434.0 via Frontend Transport; Thu, 11 Dec 2025 04:51:28 +0000 Received: from satlexmb10.amd.com (10.181.42.219) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Wed, 10 Dec 2025 22:51:27 -0600 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb10.amd.com (10.181.42.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Wed, 10 Dec 2025 22:51:27 -0600 Received: from xsjlizhih51.xilinx.com (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Wed, 10 Dec 2025 20:51:27 -0800 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , , Subject: [PATCH V1] accel/amdxdna: Fix race where send ring appears full due to delayed head update Date: Wed, 10 Dec 2025 20:51:25 -0800 Message-ID: <20251211045125.1724604-1-lizhi.hou@amd.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023D9:EE_|BY5PR12MB4196:EE_ X-MS-Office365-Filtering-Correlation-Id: 8cdd80fa-fb63-4036-f88c-08de3870f271 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?RxruwzARLXgmvuOdZMOn6TRNLROQVs+v0CQ0ICMlptTf0BtsTYOe4QDxToNc?= =?us-ascii?Q?nqW9it9APo36bGlf6XIQ3HkyfNTM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kvRED5fHGP5Pqkj8npOpoUX4Xymh+nsK8mGQIbwGb2NovRdoxRTVqZWaLR6p?= =?us-ascii?Q?iMFwVDfC+yHI2LC0rONPcuXMEzc1ls9SrXZem23I2o3ShfkLMg2oG5TnhcpE?= =?us-ascii?Q?rHlLa0aRZhAiO0Xjd+HEz74WmgXDIZ98Xy0C9teGOe8A5tTyyEhjxsT8d5Pk?= =?us-ascii?Q?wdj53uwrqK3nHhcmTNqca4cn1NLIpQrLj6+07yi8xK2hLX84+NVOBHa4xLxk?= =?us-ascii?Q?nvJX+A27/QlmsepNzosu//aiIGPvYwvBmLN/G/8oHtmJjX1aUm5tggzLsRcl?= =?us-ascii?Q?7lbjVg0N4/1YSA1dJ3GNeODcFRpkPweuMfayPvLPE89djxKA3jtXoc2VfDbd?= =?us-ascii?Q?fbd5MJhCEvwCoggr5MUKZ7OgHuOy7oL0qhvVoCHe81dAj/5HRZOHA+r0fZNj?= =?us-ascii?Q?1q1UwmYDG90g3mH1dTBo0ehD+Gp8v5IO171sYVsEN/Ry5tRaKjqzuY+vsmOE?= =?us-ascii?Q?jediQHBPCVIkxqE6iKgUcVjSUnSXzo78D/Z36KNyxE65YtrFI6Q9kamCXOe8?= =?us-ascii?Q?C9RCwK4v4xKql9w8U+QG5ajxa+S2JRxIqdv6frpJxz58/m/u5LA20SH38hdW?= =?us-ascii?Q?viwWrtbz13nltIO1wxg=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2025 04:51:28.6908 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8cdd80fa-fb63-4036-f88c-08de3870f271 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF000023D9.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4196 Content-Type: text/plain; charset="utf-8" The firmware sends a response and interrupts the driver before advancing the mailbox send ring head pointer. As a result, the driver may observe the response and attempt to send a new request before the firmware has updated the head pointer. In this window, the send ring still appears full, causing the driver to incorrectly fail the send operation. This race can be triggered more easily in a multithreaded environment, leading to unexpected and spurious "send ring full" failures. To address this, poll the send ring head pointer for up to 100us before returning a full-ring condition. This allows the firmware time to update the head pointer. Fixes: b87f920b9344 ("accel/amdxdna: Support hardware mailbox") Signed-off-by: Lizhi Hou Reviewed-by: Mario Limonciello (AMD) --- drivers/accel/amdxdna/amdxdna_mailbox.c | 27 +++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/accel/amdxdna/amdxdna_mailbox.c b/drivers/accel/amdxdn= a/amdxdna_mailbox.c index a60a85ce564c..469242ed8224 100644 --- a/drivers/accel/amdxdna/amdxdna_mailbox.c +++ b/drivers/accel/amdxdna/amdxdna_mailbox.c @@ -191,26 +191,34 @@ mailbox_send_msg(struct mailbox_channel *mb_chann, st= ruct mailbox_msg *mb_msg) u32 head, tail; u32 start_addr; u32 tmp_tail; + int ret; =20 head =3D mailbox_get_headptr(mb_chann, CHAN_RES_X2I); tail =3D mb_chann->x2i_tail; - ringbuf_size =3D mailbox_get_ringbuf_size(mb_chann, CHAN_RES_X2I); + ringbuf_size =3D mailbox_get_ringbuf_size(mb_chann, CHAN_RES_X2I) - sizeo= f(u32); start_addr =3D mb_chann->res[CHAN_RES_X2I].rb_start_addr; tmp_tail =3D tail + mb_msg->pkg_size; =20 - if (tail < head && tmp_tail >=3D head) - goto no_space; - - if (tail >=3D head && (tmp_tail > ringbuf_size - sizeof(u32) && - mb_msg->pkg_size >=3D head)) - goto no_space; =20 - if (tail >=3D head && tmp_tail > ringbuf_size - sizeof(u32)) { +check_again: + if (tail >=3D head && tmp_tail > ringbuf_size) { write_addr =3D mb_chann->mb->res.ringbuf_base + start_addr + tail; writel(TOMBSTONE, write_addr); =20 /* tombstone is set. Write from the start of the ringbuf */ tail =3D 0; + tmp_tail =3D tail + mb_msg->pkg_size; + } + + if (tail < head && tmp_tail >=3D head) { + ret =3D read_poll_timeout(mailbox_get_headptr, head, + tmp_tail < head || tail >=3D head, + 1, 100, false, mb_chann, CHAN_RES_X2I); + if (ret) + return ret; + + if (tail >=3D head) + goto check_again; } =20 write_addr =3D mb_chann->mb->res.ringbuf_base + start_addr + tail; @@ -222,9 +230,6 @@ mailbox_send_msg(struct mailbox_channel *mb_chann, stru= ct mailbox_msg *mb_msg) mb_msg->pkg.header.id); =20 return 0; - -no_space: - return -ENOSPC; } =20 static int --=20 2.34.1