From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010048.outbound.protection.outlook.com [40.93.198.48]) (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 59FAD495ACD for ; Fri, 9 Oct 2026 22:54:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.48 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791586451; cv=fail; b=NpqpCuIWL/SGglZfgnG3VrRR9yd0uRK9vrOvew+nz5O4d5HnbbKL6rq732pS0QkZUoz164jipYN+sdklkSZzRjaft3UULm0/wyzyF7rHTG7R7JzqHsXxVA+FrPvCh29q7955mkqRP6dRGDV2AP8w2zalKfo0/pBaaPmuBpkzBu8= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791586451; c=relaxed/simple; bh=Qwi3LR9lIlflWdUhDwZNKIoMbAkIAA14maB2FPXsuv4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e/xNB8xSUiXkh2bPWOjQa2hoP4+Q4PAE2HLeupH+6XEm5DybB5uyWwAL0xowrCzSobPl+//qbwpX66Pnc5Z/FuUcXKAPrChQLulOMzposMZEyeWN/gS/ZcN4aSs1Msze/amujUdZ3HJUo05RD4LaTG0iXsuhjoOC3S8xQfGzI14= 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=SCeG08fP; arc=fail smtp.client-ip=40.93.198.48 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="SCeG08fP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yIWLgPQnDDxsQFphX++1nxVqli29lwPYCz/TYNgSTmXu+sNrJP3GhjOb2GGThijr338G6xf9i1xVaT7vcrhEyQ6HstJz6/iQQxDGhrjDnv2J6y2Ic5oP/PWBbzn5DqlfKnFMA/CahyZe0yHcCQsELWq56TfTq6AZ0uvIj4PfSONMvM91IcmVBYBgWf74rtPZXvkg0DOywkjRRbs3kw3ap65Yex0aW7bchGkRhWtIehMCLl/8PJsc5hIGXU08jKlxZGfTXB3HE4/S809ovDvUjQ2hKXB/HJ0OCe8n9xXftcWqqv/ynruT3YmMlA4A90twFYek1wrBNgty2n/MUddEYQ== 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=En0wXz4r/jKqAugTI1j93kkaBdZWe8TCm4u79dkp1cw=; b=gASwliJrOt4o7Wgt5zC9r7VywxL2SZBrwUiNGbrFZBdwSMZvryGSuWNGmiFsJ5TcIjJa8k9xtQIeI4eaJ1cPstG4ZcIMHGfEdmesaFbSUdv3KJEsa+mGc2Yb3BZrnYVV7CxpIVGRETcnwCGmLzalMqaeZkmtaND2qIOMeFN67o6OkBngbXtjbG5Rq6TKtlsvCyXLpLyWMFQJBXQYM/YCi4UvvlxUyGG6JnITBsdPhnGnze3GqTtpJKyLcvIFDzgCvUka57cWJyWjvzfHI42jPXaNK8YVn6aPRtJchZoI820NsIAK2K+Yi6LIwxmPjDLcQGxzHTNJpH2I9U2G7hcLNw== 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=En0wXz4r/jKqAugTI1j93kkaBdZWe8TCm4u79dkp1cw=; b=SCeG08fPDnuokt9y3p3tx7KZt5rqrQj6q6qopv8nr494IGYBPzFaom4WRNIkI4JQz9k7Fr5/Q+mDxjC8jHx1KcF5DeQ5pHzBlHrIVz4JoBiabMnW9ekIbczTDNJ+jYYRMvXVBuk2RyEMojqxFxqHyzn4WgxsigrR+e3xuqTWEpA= Received: from BN0PR04CA0140.namprd04.prod.outlook.com (2603:10b6:408:ed::25) by DS6PR12MB745092.namprd12.prod.outlook.com (2603:10b6:8:52c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.496.17; Fri, 9 Oct 2026 22:54:03 +0000 Received: from BN2PEPF000055E0.namprd21.prod.outlook.com (2603:10b6:408:ed:cafe::e) by BN0PR04CA0140.outlook.office365.com (2603:10b6:408:ed::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.496.5 via Frontend Transport; Fri, 9 Oct 2026 22:54:02 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN2PEPF000055E0.mail.protection.outlook.com (10.167.245.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.546.0 via Frontend Transport; Fri, 9 Oct 2026 22:54:02 +0000 Received: from satlexmb07.amd.com (10.181.42.216) 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.49; Fri, 9 Oct 2026 17:53:57 -0500 Received: from xsjdavidzha51.xilinx.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.49 via Frontend Transport; Fri, 9 Oct 2026 17:53:57 -0500 From: David Zhang To: , , , , , , CC: David Zhang , , Subject: [PATCH V4 15/19] accel/amdxdna: Make populate_range common for AIE2 and AIE4 Date: Fri, 9 Oct 2026 15:53:39 -0700 Message-ID: <20261009225343.3079074-16-yidong.zhang@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261009225343.3079074-1-yidong.zhang@amd.com> References: <20261009225343.3079074-1-yidong.zhang@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055E0:EE_|DS6PR12MB745092:EE_ X-MS-Office365-Filtering-Correlation-Id: 0cc85de0-b9a4-433a-08bc-08df265836d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|36860700016|376014|82310400026|1800799024|56012099006|11063799006|4143699003|18002099003|10067099003|22082099003; X-Microsoft-Antispam-Message-Info: pVZ4pNqHWYKzhSLpxY+/SCoT305t3Fk0525Z9B2yzas/804nFaOcwFZ3z8mHyGeU/ixjmSIIfqPoLsLca7Ji2fJejU24p/cukDoKJpLdCxsUwWDB/HKAiEoDIkjmfEPliG05/etiEJBo0aqLYJZOQAETOcrq/CIV+g4mHCo7zSnrUQd7ADWNZSyuUbaan3K2zff/giYHXhPZIxeO7qfWyXhgq6HCuFxN4i+lwG9OUTCN2Ee9onTovQY1Ings33EfjPF+72tcS8gy+UPgaul3Bl3v4j1mHA/01Nw8h0xTmmdpoIkLIRa9PrBQMf8w0Vro6RdzW7TXLljgZwyrt75gzKd/a+XL31dAwwoUvYpHme03FHrQgyKuKyWIXn2Mob6bohxQPb+QTRTSkK+YJ6DWoWmjIE0llz2wUGx21NZjRRWcjo1u7YdEjI/1lpcgsB3l4rAycdy2iSHmCY3S4qL2lWKx19wq56pVUUeEfmLC5k2ajvbWXjCOo5LGYqlL2P/O0Z9oordcdmIhpSUvm6wvC7T0323jBnhm2Kc3wdfB1adGOjVy2LR/TO/Hy/Qd/9Q79CoXfb/KiAu+EC0N9i35jaL3BgVlEHh/tC0U8frmOjT/2WjkVpNBu9g4Q9HYINkDKTBCnRWWJcUOxtN7U/c8tAX5/uydS3YuhcMhT5P/es/CeBgOycwim+r4Hp8SK/QE4UqQlobIw2XV7RUc+cHsxw== 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)(23010399003)(36860700016)(376014)(82310400026)(1800799024)(56012099006)(11063799006)(4143699003)(18002099003)(10067099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zZcFpm1K9tQzhDcLVoVo08q1CUYBMw6I8Va+M3BYcthMky7Z35ShaAXKivqbmz3vgawbedcNXL+2Jqq0Jyk9ZF9DCRobIAytMG5ejZOgIQJVJKXMaZCn1+l4oC95a8sDYnfCPFfEixzZ2mKKUTc4CAgkePOW1/4/GmgVV8Q//8LuC53CqNVjstJvDwSOghclP8YfiJ4s3OVNH5Wgu8cbhaPjPnGej9uYPaRfdZSUqlisBZ3bs7Xb5k2QOQ0tpLtrgHiVtajYnIOVVTWbxzIiZnak0wXfyG7HMF77sETVdxGdjYMwnkvX2tR00HTkxcsWaTFVmKwgs1o45eFURfy2P5LVptytdnIHpLy6britv9af2TOP9FEk3YPEQ8+vpLknwiFYcZkvtt8jjRY3f7WC4Iqgh6dCnHr6qvuxoa5PS4hLjNfePi05RmnsHmUPEDl5 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2026 22:54:02.8440 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0cc85de0-b9a4-433a-08bc-08df265836d7 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: BN2PEPF000055E0.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS6PR12MB745092 When a user mapping of a BO is invalidated, the MMU notifier sets map_invalid and command submission must fault the range back in before attaching the job fence. AIE2 does this in aie2_populate_range(), which AIE4 command submission also needs. Move aie2_populate_range() from aie2_ctx.c into amdxdna_gem.c as amdxdna_populate_range(), next to the MMU notifier code, and declare it in amdxdna_gem.h. No functional change for AIE2. Signed-off-by: David Zhang --- drivers/accel/amdxdna/aie2_ctx.c | 75 +---------------------------- drivers/accel/amdxdna/amdxdna_gem.c | 73 ++++++++++++++++++++++++++++ drivers/accel/amdxdna/amdxdna_gem.h | 1 + 3 files changed, 75 insertions(+), 74 deletions(-) diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c index 8c1b29964f8f..05ed71e641c3 100644 --- a/drivers/accel/amdxdna/aie2_ctx.c +++ b/drivers/accel/amdxdna/aie2_ctx.c @@ -1105,79 +1105,6 @@ int aie2_hwctx_sync_debug_bo(struct amdxdna_hwctx *hwctx, u32 debug_bo_hdl) return ret; } -static int aie2_populate_range(struct amdxdna_gem_obj *abo) -{ - struct amdxdna_dev *xdna = to_xdna_dev(to_gobj(abo)->dev); - struct amdxdna_umap *mapp; - unsigned long timeout; - struct mm_struct *mm; - bool found; - int ret; - - timeout = msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT); -again: - found = false; - down_write(&xdna->notifier_lock); - list_for_each_entry(mapp, &abo->mem.umap_list, node) { - /* - * Skip entries that have already been unmapped. - * - * If userspace unmaps the address and later submits I/O using - * it, the IOMMU will reject the access and report a fault. - * Ignore such entries here. - */ - if (mapp->unmapped) - continue; - - if (mapp->invalid && kref_get_unless_zero(&mapp->refcnt)) { - found = true; - break; - } - } - - if (!found) { - /* - * This also covers the case where all mappings have been - * removed. There are no invalid mappings left to process. - * Any subsequent I/O using the unmapped address will be - * rejected by the IOMMU. - */ - abo->mem.map_invalid = false; - up_write(&xdna->notifier_lock); - return 0; - } - - up_write(&xdna->notifier_lock); - - mm = mapp->notifier.mm; - if (!mmget_not_zero(mm)) { - amdxdna_umap_put(mapp); - return -EFAULT; - } - - ret = hmm_range_fault_unlocked_timeout(&mapp->range, timeout); - if (ret) - goto put_mm; - - down_write(&xdna->notifier_lock); - if (mmu_interval_read_retry(&mapp->notifier, mapp->range.notifier_seq)) { - up_write(&xdna->notifier_lock); - amdxdna_umap_put(mapp); - mmput(mm); - goto again; - } - mapp->invalid = false; - up_write(&xdna->notifier_lock); - amdxdna_umap_put(mapp); - mmput(mm); - goto again; - -put_mm: - amdxdna_umap_put(mapp); - mmput(mm); - return ret == -EBUSY ? -ETIME : ret; -} - int aie2_cmd_submit(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job *job, u64 *seq) { struct amdxdna_dev *xdna = hwctx->client->xdna; @@ -1237,7 +1164,7 @@ int aie2_cmd_submit(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job *job, goto cleanup_job; } - ret = aie2_populate_range(abo); + ret = amdxdna_populate_range(abo); if (ret) goto cleanup_job; goto retry; diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c index e1b72cef51bd..320604ec157f 100644 --- a/drivers/accel/amdxdna/amdxdna_gem.c +++ b/drivers/accel/amdxdna/amdxdna_gem.c @@ -337,6 +337,79 @@ void amdxdna_umap_put(struct amdxdna_umap *mapp) kref_put(&mapp->refcnt, amdxdna_umap_release); } +int amdxdna_populate_range(struct amdxdna_gem_obj *abo) +{ + struct amdxdna_dev *xdna = to_xdna_dev(to_gobj(abo)->dev); + struct amdxdna_umap *mapp; + unsigned long timeout; + struct mm_struct *mm; + bool found; + int ret; + + timeout = msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT); +again: + found = false; + down_write(&xdna->notifier_lock); + list_for_each_entry(mapp, &abo->mem.umap_list, node) { + /* + * Skip entries that have already been unmapped. + * + * If userspace unmaps the address and later submits I/O using + * it, the IOMMU will reject the access and report a fault. + * Ignore such entries here. + */ + if (mapp->unmapped) + continue; + + if (mapp->invalid && kref_get_unless_zero(&mapp->refcnt)) { + found = true; + break; + } + } + + if (!found) { + /* + * This also covers the case where all mappings have been + * removed. There are no invalid mappings left to process. + * Any subsequent I/O using the unmapped address will be + * rejected by the IOMMU. + */ + abo->mem.map_invalid = false; + up_write(&xdna->notifier_lock); + return 0; + } + + up_write(&xdna->notifier_lock); + + mm = mapp->notifier.mm; + if (!mmget_not_zero(mm)) { + amdxdna_umap_put(mapp); + return -EFAULT; + } + + ret = hmm_range_fault_unlocked_timeout(&mapp->range, timeout); + if (ret) + goto put_mm; + + down_write(&xdna->notifier_lock); + if (mmu_interval_read_retry(&mapp->notifier, mapp->range.notifier_seq)) { + up_write(&xdna->notifier_lock); + amdxdna_umap_put(mapp); + mmput(mm); + goto again; + } + mapp->invalid = false; + up_write(&xdna->notifier_lock); + amdxdna_umap_put(mapp); + mmput(mm); + goto again; + +put_mm: + amdxdna_umap_put(mapp); + mmput(mm); + return ret == -EBUSY ? -ETIME : ret; +} + static void amdxdna_hmm_unreg_work(struct work_struct *work) { struct amdxdna_gem_obj *abo = container_of(work, struct amdxdna_gem_obj, diff --git a/drivers/accel/amdxdna/amdxdna_gem.h b/drivers/accel/amdxdna/amdxdna_gem.h index 9b4aa21a37c9..977548e19ae4 100644 --- a/drivers/accel/amdxdna/amdxdna_gem.h +++ b/drivers/accel/amdxdna/amdxdna_gem.h @@ -103,6 +103,7 @@ static inline u64 amdxdna_obj_dma_addr(struct amdxdna_gem_obj *abo) } void amdxdna_umap_put(struct amdxdna_umap *mapp); +int amdxdna_populate_range(struct amdxdna_gem_obj *abo); void amdxdna_gem_heap_free(struct amdxdna_client *client, struct amdxdna_gem_obj *abo); struct drm_gem_object * -- 2.34.1