From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.196.57 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796145710; b=Qyw7opZFTjVqpOS3Xp+nWA2LtZO1lbz5ddepIwmZZEcW33MDFeKfGJg+qnMYA0qku3mf b2TyGFsYb1KBOyIK5C2AJLr07ZF4SZsOgqTC+JrfocIFKVs5Ls2PxafqMWRfsKX7P0Y9F SK6i8IG2fNeGHT5helysgHiRFy6OapMHUocryKbEDaySGUwQLGm0wTTSEfMzVgo7GQg7T cDDkMmse0dREy5/URqWl75K2kdc3yKztHcsY4pYxTv5Y/nhJbk/z6RYNstXwSHR+dpm+O /a2/wv3ELPyEF18fJxLcheqwhzNr7phY1Wb4czPrjJ95B8O0ehUUMhGDoJmvE70++DA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796145710; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:Received:Message-ID:Date:MIME-Version:User-Agent:Subject: Content-Language:To:CC:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=qTFGk4zYwevMixOVDjAkD1H8IKVjM5DaMYWl1hlOjaY=; b=kr6/RjtsgNW3HDuAWwSQDtYF4RVsiIAwNw6O5/rA3cmJWa/bJJSpgVDjCC6iR/nuF9MW uES7LQFXKTptXSntrCIjrCBfBJhJmhjZPvwKHQ0isGywnk8TOBQPlOYE32nIQuEPM6b7Y zrhglrV1J2uzEs4ELDRvCA1pl5IxLxIUoiAPi4f7td+RM/vd9RWDi+dZpTJrp1s7b8dlQ mx/XK5fwHIWL5vf7YqcrBq/A1lbhmcHkEYyLGoHVMX5Uz1oU0aml+KmSlnAflWB/vFCm2 rXZ5H2zZhDCwncZu/NQKg6EnMU9QEVeroKI9f67ypdN611hd2SvjRYPUgo/mZOPB0sg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=sXUJ0K5T; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.196.57 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013057.outbound.protection.outlook.com [40.93.196.57]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31A09606A32D for ; Tue, 1 Dec 2026 17:21:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 31A09606A32D 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, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=sXUJ0K5T ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OeecNH9KqWZ+Enwms89zO95QZWlNeR0CajZ8HeDLeGUd+HF8Tm+8YO1NVuKGEsxNX63JAML/4ayASAVt8wI2asMfXYCiadRevJ1Y8B6urXsKrTRUzoYTlFQ18p9FbRfJk/zu391YWT3KyTQEvgEs61GNwnOCCU1og2OpZ7OPcLk1EpSenccqOQQBazblRbD5m38f83rpODPx3kKl3UGacqCevIgEyYu/Plic/KdDcjLLHwLaOsy4lhe/K4y46LV0UpeCv8T83varT5hZB4pqBENCd8l2EvUBix/HTskCp9fHe0ZWWZN7tcVyCAM8aiIZl1n59Zy2fPcdNjVO4ZLqxw== 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=qTFGk4zYwevMixOVDjAkD1H8IKVjM5DaMYWl1hlOjaY=; b=RKU2v04cV/Qo5tPmbI2PmchMRACGTS8KvE/BejP8fZ8EiOfkP3981YSIrT1oK+cwTVyGm7D34kLf6nJxZJF1cHXYHnM2dmQ/HhqvAhX+bcAmYYQ45Vm3NV0hRWQ7rPpdMRgEyNnQGxnFTOFp5N3HLVJmXE1fi9yHw/pcp/kY0tcUn6/MnPab0Y91tebZkbwADOqOfD/xW6l9MkrUyOVPvXpHmPizbN1UGewYtmNP0bvWHti++nWOjkU0M1+6iFIKSp30Hybyf5xuPnOd2s6fG2IS74T92BF5vAgJY9LC/KJboGyncPNgNHr6zBtUvkUj7tqfBYLlCMjHSkn+jCuMUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=quicinc.com 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=qTFGk4zYwevMixOVDjAkD1H8IKVjM5DaMYWl1hlOjaY=; b=sXUJ0K5TS49rlCHuryUGAkLkPtGv4yXiwS1pptIe2VwfeZ9mx0b/krh1sxGwDuDrNkcuw8mKca/H7W1+ihJGqPG21qKI1sZD68LPR6JDsdODUn//lTtCQsZwGh4rD6fQoEvaZ3USHr05OcP5FHlZumG7m7jA5D6R73ij8TVUVLU= Received: from DSSP222CA0011.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:3d4::10) by SJ2PR12MB8806.namprd12.prod.outlook.com (2603:10b6:a03:4d0::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 17:21:42 +0000 Received: from DS2PEPF00006E26.namprd05.prod.outlook.com (2603:10b6:8:3d4:cafe::84) by DSSP222CA0011.outlook.office365.com (2603:10b6:8:3d4::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 17:21:41 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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=satlexmb08.amd.com; pr=C Received: from satlexmb08.amd.com (165.204.84.17) by DS2PEPF00006E26.mail.protection.outlook.com (10.167.23.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 17:21:41 +0000 Received: from Satlexmb09.amd.com (10.181.42.218) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Tue, 1 Dec 2026 11:21:41 -0600 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb09.amd.com (10.181.42.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Tue, 1 Dec 2026 11:21:41 -0600 Received: from [172.19.71.207] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Tue, 1 Dec 2026 11:21:40 -0600 Message-ID: Date: Tue, 1 Dec 2026 09:21:40 -0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH V2 5/5] accel/amdxdna: Recover hung AIE4 contexts Content-Language: en-US To: David Zhang , , , , , , CC: , References: <20261130225904.1103363-1-yidong.zhang@amd.com> <20261130225904.1103363-6-yidong.zhang@amd.com> From: Lizhi Hou In-Reply-To: <20261130225904.1103363-6-yidong.zhang@amd.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00006E26:EE_|SJ2PR12MB8806:EE_ X-MS-Office365-Filtering-Correlation-Id: c8796da9-f3f6-47be-2391-08df4fcf9106 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|36860700016|1800799024|376014|11063799006|4143699003|18002099003|261009223027099003|22082099003|10067099003|56012099006|261102123227099003|261028144727099003|261026140227099003|261026121527099003|261021123027099003|261021121427099003|261022105027099003; X-Microsoft-Antispam-Message-Info: ILM9nDOEahUdcQ06nslp5xsCY7m1jISa6Yliqb2ZAVLMmZyh+/Y9AkWpAtUq+3a1gZweBYzNDQbtgT41kwKpuO45P+UdANKU5n5tjU9o8q5wzyTxxMF9hhKbgv0ZTWLADg16CZ9Bh5rzv78+FUDi4FcHygNF4xVFPeCWF0+hQ3kBVcuqqmqi47TyzMRCBsM1AxM+G8JY4wlP033XSDtc/RnagCIkl0cStrhrOiS6F+KLdvTxoVGjeV2i7xJRAb8/2EGISgiZ4EZjKQ7CtS9zG5PY6LaREdZq+HQ9EZWwevL4nv/8qM5Y73KszmGTT8cdb1RvGa07FJRzCx5wNH4DIGISTcYxPTpNEgRrFWRZgKzUoETwBzgNvnCyzALgdEdIIQU6fXOtyIOghiBU4TWe/fo9k7prnX+thF4M+BFQ+z4cT0fbNDv+XLbtahPdrZ+DczSaFd6ko86OqjEElJgRto1uSRLI7JAFvwVZ1TxrTxeRS0dLIfaoRhrTB0cjpukGvuI1urtjf1cgmz9unbkxBtLWmVkGV+XKs/fe+v3u57T6O7ugcKvwq9EI6KtTyaHv4K7quQxeDeuD6FWFytoYNH1mvPjWte4FxvA4/ilcYmM08nwSZGzWmxVaGmHAYY7IAid9YcYD/wD7jV3rqsWXOa7y21wc8b34UzHYnp2XYKMXc8xkjjJDyLc3eVcrOTiJeKrmPCrprW8VbTqNcfjUUA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(82310400026)(36860700016)(1800799024)(376014)(11063799006)(4143699003)(18002099003)(261009223027099003)(22082099003)(10067099003)(56012099006)(261102123227099003)(261028144727099003)(261026140227099003)(261026121527099003)(261021123027099003)(261021121427099003)(261022105027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZPG0zvONWmUUQA191xAI3vaTQQBkZYB/55hY6nDk8tt6klPLHkv4YTQFAk0IJv7vOtTdYh+r24xm7DL0OMBOP/4jv2sTvjOa1CkH36uZHBy6GITa8SRJXZO+5R+1pYI9A3kXfejPtHZv4FKDYODnZ9UrfE+MP9qs7nhpALnUM1JQRmraEsU9DUY1+LYHbIbTbHNiYSEwPnI4wWM2G9ClSF5OQqnqR2Xp0m9qb0i/3ctakPGu4ijJI0bNYhdKZxegktxebzo+fFNOabJyq7t++rsn9jXF1/x8m6eIp5HeW8vMJQ5GR1fh8qwxXY2urDM9mHZixHVT3HuUVqgchhq0Hsbolo/ico7xJVAy6NeFltxvdx+qOJZaKmkFqdjtSyllTdVIeOKrX+s2DFFB3wXzm2RZ4kv7Hdy6mg2FdDxwE8qjtPetZ88ZHzQxA2txzt2Z X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 17:21:41.9061 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8796da9-f3f6-47be-2391-08df4fcf9106 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=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00006E26.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8806 On 11/30/26 14:59, David Zhang wrote: > The driver checks for a context job hung in firmware, so that the job > does not hang inside firmware. Detect the hang the same way as the > passive TDR detection in AIE2. > > Signed-off-by: David Zhang > --- > drivers/accel/amdxdna/aie4_ctx.c | 20 ++++++++--- > drivers/accel/amdxdna/aie4_error.c | 53 ++++++++++++++++++++++++++++-- > drivers/accel/amdxdna/aie4_pci.c | 2 ++ > drivers/accel/amdxdna/aie4_pci.h | 6 ++++ > 4 files changed, 74 insertions(+), 7 deletions(-) > > diff --git a/drivers/accel/amdxdna/aie4_ctx.c b/drivers/accel/amdxdna/aie4_ctx.c > index 9f61fcd6e518..25c801a89488 100644 > --- a/drivers/accel/amdxdna/aie4_ctx.c > +++ b/drivers/accel/amdxdna/aie4_ctx.c > @@ -27,7 +27,7 @@ > > #define CTX_INVALID_ID (~0U) > #define CTX_INVALID_DOORBELL AMDXDNA_INVALID_DOORBELL_OFFSET > -#define AIE4_JOB_TIMEOUT_MS 2000 > +#define AIE4_JOB_TIMEOUT_MS 10000 > > static void job_worker(struct work_struct *work); > > @@ -960,6 +960,7 @@ static void job_done(struct amdxdna_sched_job *job) > > static void job_complete(struct amdxdna_sched_job *job) > { > + AIE4_UPDATE_LAST_ACTIVE_TS(job->hwctx->client->xdna->dev_handle); > job_done(job); > } > > @@ -1090,8 +1091,16 @@ static bool aie4_hwctx_take_fault(struct amdxdna_hwctx *hwctx, > return fault; > } > > +bool aie4_hwctx_job_hung(struct amdxdna_hwctx *hwctx, u64 seq) > +{ > + unsigned long last = READ_ONCE(hwctx->client->xdna->dev_handle->last_signal_ts); > + > + return AIE4_HWCTX_CONNECTED(hwctx) && get_read_index(hwctx) <= seq && > + time_after_eq(jiffies, last + msecs_to_jiffies(AIE4_JOB_TIMEOUT_MS)); > +} > + > /* > - * Stop a context whose running job timed out, so the NPU no longer > + * Reset a context whose running job timed out, so the NPU no longer > * accesses the job BOs before the worker aborts the jobs and signals > * their fences. Paths holding dev_lock flush this worker, so do not > * block on dev_lock; if it is busy, wait for another timeout period. > @@ -1104,9 +1113,9 @@ static void job_timeout(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job *j > return; > > /* The job may have completed or the context disconnected meanwhile. */ > - if (AIE4_HWCTX_CONNECTED(hwctx) && get_read_index(hwctx) <= job->seq) { > + if (aie4_hwctx_job_hung(hwctx, job->seq)) { > XDNA_ERR(xdna, "hwctx %s job %llu timed out", hwctx->name, job->seq); > - aie4_hwctx_stop(hwctx); > + aie4_ctx_hung_queue(hwctx, job->seq); > } > mutex_unlock(&xdna->dev_lock); > } > @@ -1214,6 +1223,9 @@ void aie4_hwctx_reset(struct amdxdna_hwctx *hwctx, > XDNA_ERR(xdna, "Failed to create hwctx %s after reset, ret %d", > hwctx->name, ret); > > + /* Give every context a full timeout after the reset. */ > + AIE4_UPDATE_LAST_ACTIVE_TS(xdna->dev_handle); > + > mutex_lock(&priv->io_lock); > priv->reset_fault = false; > WRITE_ONCE(priv->resetting, false); > diff --git a/drivers/accel/amdxdna/aie4_error.c b/drivers/accel/amdxdna/aie4_error.c > index 9ca99af3e2c1..56132fc14d46 100644 > --- a/drivers/accel/amdxdna/aie4_error.c > +++ b/drivers/accel/amdxdna/aie4_error.c > @@ -148,7 +148,8 @@ static void aie4_record_async_error(struct amdxdna_dev_hdl *ndev, > > /* Reset the context with firmware ID ctx_id that existed at generation gen. */ > static void aie4_reset_hwctx_by_id(struct amdxdna_dev_hdl *ndev, u32 ctx_id, > - u64 gen, const struct aie4_async_ctx_error *ctx_err) > + u64 gen, bool timeout, u64 seq, > + const struct aie4_async_ctx_error *ctx_err) > { > struct amdxdna_dev *xdna = ndev->aie.xdna; > bool found = false; > @@ -166,6 +167,11 @@ static void aie4_reset_hwctx_by_id(struct amdxdna_dev_hdl *ndev, u32 ctx_id, > hwctx->priv->gen > gen) > continue; > found = true; > + if (timeout && !aie4_hwctx_job_hung(hwctx, seq)) > + break; > + if (timeout) > + aie4_record_async_error(ndev, AMDXDNA_ERROR_NUM_KDS_EXEC, > + 0, ctx_id); > aie4_hwctx_reset(hwctx, ctx_err); > break; > } > @@ -230,7 +236,7 @@ static void aie4_async_ctx_error(struct aie4_async_event *e) > aie4_record_async_error(ndev, aie4_ctx_error_num(ctx_err->error_type), > ctx_status, ctx_id); > > - aie4_reset_hwctx_by_id(ndev, ctx_id, e->resp_ctx_gen, ctx_err); > + aie4_reset_hwctx_by_id(ndev, ctx_id, e->resp_ctx_gen, false, 0, ctx_err); > } > > static void aie4_async_event_report(struct aie4_async_event *e) > @@ -439,7 +445,7 @@ static void aie4_async_note_worker(struct work_struct *work) > > /* There is no report, so record it like a job timeout. */ > aie4_record_async_error(ndev, AMDXDNA_ERROR_NUM_KDS_EXEC, 0, note->ctx_id); > - aie4_reset_hwctx_by_id(ndev, note->ctx_id, note->ctx_gen, NULL); > + aie4_reset_hwctx_by_id(ndev, note->ctx_id, note->ctx_gen, false, 0, NULL); > > unlock: > mutex_unlock(&xdna->dev_lock); > @@ -511,3 +517,44 @@ int aie4_async_note_cb(void *handle, u32 opcode, void __iomem *data, size_t size > queue_work(events->wq, ¬e->work); > return 0; > } > + > +struct aie4_ctx_hung_work { > + struct work_struct work; > + struct amdxdna_dev_hdl *ndev; > + u32 ctx_id; > + u64 ctx_gen; > + u64 seq; > +}; > + > +static void aie4_ctx_hung_worker(struct work_struct *work) > +{ > + struct aie4_ctx_hung_work *tw = container_of(work, struct aie4_ctx_hung_work, work); > + struct amdxdna_dev *xdna = tw->ndev->aie.xdna; > + > + mutex_lock(&xdna->dev_lock); > + aie4_reset_hwctx_by_id(tw->ndev, tw->ctx_id, tw->ctx_gen, true, tw->seq, NULL); > + mutex_unlock(&xdna->dev_lock); > + > + kfree(tw); > +} > + > +void aie4_ctx_hung_queue(struct amdxdna_hwctx *hwctx, u64 seq) > +{ > + struct amdxdna_dev_hdl *ndev = hwctx->client->xdna->dev_handle; > + struct aie4_ctx_hung_work *tw; > + > + if (!ndev->async_events) > + return; > + > + /* Runs on the fence-signalling path under dev_lock; do not reclaim. */ > + tw = kzalloc_obj(*tw, GFP_NOWAIT); > + if (!tw) > + return; > + > + tw->ndev = ndev; > + tw->ctx_id = READ_ONCE(hwctx->priv->hw_ctx_id); > + tw->ctx_gen = READ_ONCE(hwctx->priv->gen); > + tw->seq = seq; > + INIT_WORK(&tw->work, aie4_ctx_hung_worker); > + queue_work(ndev->async_events->wq, &tw->work); > +} > diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c > index 78a739573ad3..ebb87afa6afb 100644 > --- a/drivers/accel/amdxdna/aie4_pci.c > +++ b/drivers/accel/amdxdna/aie4_pci.c > @@ -499,6 +499,7 @@ static int aie4_vf_hw_start(struct amdxdna_dev_hdl *ndev) > if (ret) > goto partition_fini; > > + AIE4_UPDATE_LAST_ACTIVE_TS(ndev); > return 0; > > partition_fini: > @@ -551,6 +552,7 @@ static int aie4_classic_hw_start(struct amdxdna_dev_hdl *ndev) > if (ret) > goto partition_fini; > > + AIE4_UPDATE_LAST_ACTIVE_TS(ndev); > return 0; > > partition_fini: > diff --git a/drivers/accel/amdxdna/aie4_pci.h b/drivers/accel/amdxdna/aie4_pci.h > index 6da2810c3fb4..6d572c6f9ad2 100644 > --- a/drivers/accel/amdxdna/aie4_pci.h > +++ b/drivers/accel/amdxdna/aie4_pci.h > @@ -87,6 +87,8 @@ struct amdxdna_hwctx_priv { > #define AIE4_HWCTX_CONNECTED(hwctx) (!!READ_ONCE((hwctx)->priv->cert_comp)) > /* Set while a reset runs, and kept if the reset left the context dead. */ > #define AIE4_HWCTX_HAS_RESET(hwctx) READ_ONCE((hwctx)->priv->has_reset) > +/* Update the time stamp of the last device activity. */ > +#define AIE4_UPDATE_LAST_ACTIVE_TS(ndev) WRITE_ONCE((ndev)->last_signal_ts, jiffies) > > struct amdxdna_dev_priv { > const char *npufw_path; > @@ -143,6 +145,8 @@ struct amdxdna_dev_hdl { > /* Context switch hysteresis timeout in microseconds. */ > u32 ctx_switch_hysteresis_us; > > + /* jiffies of the last device activity: job completion, start or reset */ > + unsigned long last_signal_ts; > /* Bumped on each firmware context creation, under dev_lock. */ > u64 ctx_gen; > /* Last context error reported by firmware, under dev_lock. */ > @@ -161,6 +165,7 @@ int aie4_async_events_alloc(struct amdxdna_dev_hdl *ndev, u32 num_events); > void aie4_async_events_free(struct amdxdna_dev_hdl *ndev); > int aie4_async_events_register(struct amdxdna_dev_hdl *ndev, u32 num_events); > void aie4_async_events_stop(struct amdxdna_dev_hdl *ndev); > +void aie4_ctx_hung_queue(struct amdxdna_hwctx *hwctx, u64 seq); > int aie4_async_note_cb(void *handle, u32 opcode, void __iomem *data, size_t size); > > /* aie4_message.c */ > @@ -214,6 +219,7 @@ int aie4_hwctx_config(struct amdxdna_hwctx *hwctx, u32 type, u64 value, > int aie4_hwctx_sync_debug_bo(struct amdxdna_hwctx *hwctx, u32 debug_bo_hdl); > void aie4_hwctx_reset(struct amdxdna_hwctx *hwctx, > const struct aie4_async_ctx_error *ctx_err); > +bool aie4_hwctx_job_hung(struct amdxdna_hwctx *hwctx, u64 seq); Reviewed-by: Lizhi Hou > > /* aie4_pci.c */ > void aie4_hwctx_suspend_all(struct amdxdna_dev_hdl *ndev, int clean_jobs);