From nobody Fri Dec 19 10:48:30 2025 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013009.outbound.protection.outlook.com [40.107.201.9]) (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 0456428D83D for ; Thu, 9 Oct 2025 23:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054306; cv=fail; b=i447XRFlZsOEe+etGkRKd3cE7DH2K/mhBRTSBifkgoTuiookf0FFNcbo2rLs25FdZx4eASLN/pfQaalQQOtxY+zJi8RS6GgJhpCWGtAjaT5KlJXOP5mpzSea7SESfkOiOEd3em8R14ns3ah42q7Jn5f42juqrqizv8pUkUDkyTY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054306; c=relaxed/simple; bh=L1o+fPwP3iQgZ845uumg/DXr1Fyq+bMbq/IaXwFbBWc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KNdNJ0jd1+44GHgSuyeIBRtvjqeDjQhfCyUcl3yOa9w2NQctTcepzCIAlphwRuK84GLyorG7HmyWoXvjZSF4ljQXHxIxwlObJe564+oQosR3QmRKOk4tkAc6KTHawaoPFX9Hax3am/w5+dLKVwN7/GWG8nSANgm/Mv6Q1OZGAyg= 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=qE6YL5mt; arc=fail smtp.client-ip=40.107.201.9 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="qE6YL5mt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vn257RAShohCOqDaE0d5nuUngRFm7utNg7rjFyHNkRZTHOHdJMeZ8Nh6A2gvZOEr5N0rh2iAmcIzG+YDLzftNiaD8PVBnaM9m/fS/VQ37VgE45v0vF3YoUrOaWL4W4PtQmRLK9fn+QdqlzsqiXyesjX1lde4RBUaec3jPt0Mbr/ZnXpp533D95fQGe20B+0crvgUFVp+Xw6F3HiVZRw4nloQFCIgVLPh2OYETTRaMv2KoOzVJzvKG9nuPlnjt0H9F2dOkJuJAFRTVB70ObmwuDCYAKQLEpxl55DUZcw2lEiP02OkwI2QjbxKpDZr8ppNq5dFCAN+cvCA+SnXmM12wg== 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=6toszXUe1Ds/fq20+NhRrkRrjPtESk0AuBs8KWj6TeA=; b=c/SmBijhc8BLyY/k8U9afmKzGUII5RzKd5u7aod7a4Ly5Ep4q4SO+jGkA1yOG1O/N11ZNofwtVQnSp1ZOW29AWDhAKSQLm29xj7itJpHPw/bbdxvOGaRHYp9e907CwGeiCufVvEXx4PuSBRKbe+Q8MWlyQJHesJr+Ff0DN5k9l5WPh7Xf9dQ13fjalGK6KgRG0NH5uleTwTLyQPJ7F7543l7a9XX2Mmh4vm14k+bEg/S8YRbiqDdioOzA78BDLQegQrc3UAn3NsK0fORHeU/a5Yx1yR6DvZ2x7A9euvpu9E0fD5GiQdGZ7P3G2XqVRr5vQGhuuYjKHi99mdGtxpzdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=6toszXUe1Ds/fq20+NhRrkRrjPtESk0AuBs8KWj6TeA=; b=qE6YL5mtc1birExHi1NZ1nIpRPb+r8Hz4eTLCyYAdQtyzGi4mgyV4oHgdi6Qxp87WxrmePzwxOOHMzpvvehTMoR9/cjWoDQgl0m6BNEJ+IhuulhTPPk3L5BVN252hMlMStCvJaE0BzInI9kmwVMz/QLuGHu78J6+3VoZKLwB8fo= Received: from DS7PR03CA0225.namprd03.prod.outlook.com (2603:10b6:5:3ba::20) by SA5PPF916D632A9.namprd12.prod.outlook.com (2603:10b6:80f:fc04::8d6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.21; Thu, 9 Oct 2025 23:58:20 +0000 Received: from DS3PEPF000099E1.namprd04.prod.outlook.com (2603:10b6:5:3ba:cafe::db) by DS7PR03CA0225.outlook.office365.com (2603:10b6:5:3ba::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:19 +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 DS3PEPF000099E1.mail.protection.outlook.com (10.167.17.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:19 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:58:13 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 01/15] iommu/amd: Rename DEV_DOMID_MASK to DTE_DOMID_MASK Date: Thu, 9 Oct 2025 23:57:41 +0000 Message-ID: <20251009235755.4497-2-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E1:EE_|SA5PPF916D632A9:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a415b68-1c7c-4001-4134-08de078fb8e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014|7416014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?5TcEKABjNyYkPJ78bivW0TMzXT18h9LWzVMLIjBKlbnRkTRuE6Z5MwRkU3e1?= =?us-ascii?Q?GGRvdKIDWRf3gzJQI7EMy5kUtHGcIqsj/lOOAyuieo3uH0i1mdo+dULGqOtO?= =?us-ascii?Q?xylX2zqgT2keCdHe9NXd9iu+i3yt1/Z/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Wn9SyV/tA19wrWuuDRgdNF2YNbxEDiyk3QOyutPD5svufjKAA?= =?us-ascii?Q?JUnw5QiH3CWAu/1mahF0ZnrJhrxJfZB8JXj13QHll0HqxepGx9uq4N90Jeeo?= =?us-ascii?Q?6I0NMocpjrlCo5Dt+mS2xAg0UCJG/3ZLh3tVYRv5VJOeoJ9kxiVHf3Maey9F?= =?us-ascii?Q?MvE4d8LyleZnkdPAHQ2GQNxqm/MdXULKV3E6B9+SLMqKYsK+xHhATHw7zpG2?= =?us-ascii?Q?CvOrFqa36zYkb7MSI2QJqrRZ2UiXzWnyEGMXG6lVEVmc3BnX1LkHPQGMYx7H?= =?us-ascii?Q?nFe6QzS642ZoNCyGgUD9lQamjmOMtWsT8MRadvced/mAV8nwpeuRSemgfkyq?= =?us-ascii?Q?A5yniYHgoNRkKp8Zh/FmYsTYFr9zTeWC22AOhd3mcLWqBn+Ez9a1kJLu6Ck2?= =?us-ascii?Q?Y6iFcwl/VAe8dY29Pl005FzEZBLj535XlETZ57v7JP0TpNa8EbpnNAeOgQmy?= =?us-ascii?Q?e/2m+AK7MqwpKjj6n4WjlSEyD61bHIyRJsD+Qs5l9TWM2sqgHlKjAiNwkWP1?= =?us-ascii?Q?+btDwPk7iSO1avYbLkA=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014)(7416014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:58:19.6214 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a415b68-1c7c-4001-4134-08de078fb8e6 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: DS3PEPF000099E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA5PPF916D632A9 Content-Type: text/plain; charset="utf-8" Also change the define to use GENMASK_ULL instead. There is no functional change. Reviewed-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 2 +- drivers/iommu/amd/iommu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index a698a2e7ce2a..556f1df32d53 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -422,7 +422,7 @@ =20 #define DTE_FLAG_IOTLB BIT_ULL(32) #define DTE_FLAG_MASK (0x3ffULL << 32) -#define DEV_DOMID_MASK 0xffffULL +#define DTE_DOMID_MASK GENMASK_ULL(15, 0) =20 #define DTE_GCR3_14_12 GENMASK_ULL(60, 58) #define DTE_GCR3_30_15 GENMASK_ULL(31, 16) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index b57a6993179d..a9b17d31a969 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2094,7 +2094,7 @@ static void set_dte_entry(struct amd_iommu *iommu, if (dev_data->ats_enabled) new.data[1] |=3D DTE_FLAG_IOTLB; =20 - old_domid =3D READ_ONCE(dte->data[1]) & DEV_DOMID_MASK; + old_domid =3D READ_ONCE(dte->data[1]) & DTE_DOMID_MASK; new.data[1] |=3D domid; =20 /* --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012009.outbound.protection.outlook.com [40.107.209.9]) (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 6B3BE28AAE0 for ; Thu, 9 Oct 2025 23:58:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.209.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054318; cv=fail; b=ZNUwyv/V0Evo4Iw5w5SNpa1yZG8nUTOgDR3TL3G8N449NejSyyq42q5zDleuvT0hJim8sKkcFQ4ELhStrUhX+8YodIvO/O4ZhwsdoBQn1awOmVWiR4xcC7orjRzGmg/Cycqzjii92NzpPbR3AAd/TOETffDxwZpcNfOBUEXLkzM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054318; c=relaxed/simple; bh=IFCBuqhggIF2sS15l0bY+H4I8w6yiWBseC1OfE93gCQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OMaLnUNJcL0duI9PE39hzFcXqW9mNSFy7c4U5AxhKK+BQWA4NjzdlkF9oRQcCy0LlOzoxdgfbLAzL3mhBrZBFONxF7Y2rxMNUOOqwRQCAcvp7RxPW+jr/uHL2hgW4NgfPYpfIQK8id/l+LtiCY2PqQnMxXD1WlqemwOlIgTnWRU= 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=v+lD97/E; arc=fail smtp.client-ip=40.107.209.9 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="v+lD97/E" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mmjv2diJK2mADxEptiTgOUz7Hqg8BG244wutoTpRAccLXo1g4Vw474v5FSMIbSVwcewg35+TY45czMRZw64/s2VZ+R8B+QrJrbN1+iEEco05DZaocn15wd8x2CUjPENOdhl5Nsqv3bG9sVxHOAYNUwiTC2Ww/UMs9oJIS9TtacdRZV7Ejm5lXMhi5LwgAqI9SxNwcgp4jan5j64NK45V7wwCsEgHg91vxz+tmNRlxSZewUG2BRj9zMW01IuzLalLq2drvKsdhhn3VWGJ33K6hipeLbVxve6stJ4QyGeC6GvjeuksNPpRpdeqGapnGdhNCUtAqMmvd4LBx61EffMIHA== 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=DBHZojDm71ybcYgHUqHxnA1QW+Tzcd5PZdrRem0KGsc=; b=tu1Xs0uN2LAvoOD3r+gVHcx2FzKYzf5bICY9wvWEyMCXNQ0PHKeGrZYDzSpDX9sDr4EeYa/iVjzhIyXBj3uUnxFQEgPpmPdEYy2ayObUd9/NCt2OM2osvLu1bVvuYTxftA6ZNnIPm6wHMYW1WLzUN5CtYh2PF6YXxpxTuhfCXRqCtLip+el5PIIIkGdoAVq/QebJerNMQeuqhJjdgFsorAn+dqExZywXUdF7V239xLHQ22DWRCT0XczclNE1u/FELzBL5L7oAkN/XUDEywPVTrgAB0ek/7RSBPODFzOxXax92D8bUUCu9nSDSjkfUgYNiLoQyTbnra/eG79aQCHTrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=DBHZojDm71ybcYgHUqHxnA1QW+Tzcd5PZdrRem0KGsc=; b=v+lD97/EeozmqxdDNshDdIK3r/r6QKOZQsiub3m7ayiLUf0acrjAz7GIVw+wzVoOeIm9Nla3s7MELYStFZZWt4aRnSR17wfsk4aJe2sYFQjePi69iizHWibJwqZ0ermfpYH319gYBEAxEADuKtO7qExkVU61p6idnwINEh1eIdw= Received: from CH0PR04CA0001.namprd04.prod.outlook.com (2603:10b6:610:76::6) by DS0PR12MB6416.namprd12.prod.outlook.com (2603:10b6:8:cb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9; Thu, 9 Oct 2025 23:58:30 +0000 Received: from DS3PEPF000099E0.namprd04.prod.outlook.com (2603:10b6:610:76:cafe::fc) by CH0PR04CA0001.outlook.office365.com (2603:10b6:610:76::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:58: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 DS3PEPF000099E0.mail.protection.outlook.com (10.167.17.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:28 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:58:19 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 02/15] iommu/amd: Make amd_iommu_pdom_id_alloc() non-static Date: Thu, 9 Oct 2025 23:57:42 +0000 Message-ID: <20251009235755.4497-3-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E0:EE_|DS0PR12MB6416:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d097525-14ae-4324-1594-08de078fbe51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|36860700013|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?HQaR79YrYAAjyR+yL7eyFdEwCXwrYc0J92zAo5FIglhIKuNAnaTWuozwutnr?= =?us-ascii?Q?5a6watZtAutR9TKN1fFkDkG4zxx2/qzeWT0ML9W+IpR3dIWHmib6yZrRBvm0?= =?us-ascii?Q?PhLUtzvv4ni9AlIuCybbAMjnomXUZShmj+zRi6aiD1axVxSAIx7lgVqTNGg2?= =?us-ascii?Q?FNfN7Kp3+eRm0+52xsLd728xnq0jCi9C+3t8DLOe3NKTsOZ9ml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q/lx4WFGG1IOgKU3ugF/CH+1?= =?us-ascii?Q?I+Ep6/KArMnAs/vJ6GxLWMvCRb3jmVU4lgJ9CN6tEfD9Cr+hdTAABmJXYsK/?= =?us-ascii?Q?BJ2taclB6NzL3fnQd2Zdv8T4JZPiye4xaX6pRHXaOOl5mt1+xeezQJ1Vop/f?= =?us-ascii?Q?2dBX5IUeUlkE7XgeAji8wqbHs7w0v75Ymdx1xzYltEZKIC5RDxjtmRvKuWPR?= =?us-ascii?Q?+/MJOhYgDA1VsJAgF9ghKZ/wf3HFdYoITXQfm+8LH/ij5CmwCmiQuGMPIejp?= =?us-ascii?Q?3BJf3wpjzUJXqDCSfXvkVQCNu8NQgUu9pE5oJ0a1uorvRQmuBO7y/EXBvKRm?= =?us-ascii?Q?prHbnqwfnmiIjW28LCZMpYA8CU7y1e7LBAhKKj+Eidpco6Kbqs59h3w528ot?= =?us-ascii?Q?MWxduq2JJ9Pk9cMCsGtdrGRITojky0NGluBRJZyAHcduhxOcePCPXZx1ELW8?= =?us-ascii?Q?SCm/ZEyaLMfxpPyGGIQ=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(82310400026)(36860700013)(1800799024)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:58:28.7077 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5d097525-14ae-4324-1594-08de078fbe51 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: DS3PEPF000099E0.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6416 Content-Type: text/plain; charset="utf-8" This will be reused in a new iommufd.c file for nested translation. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 1 + drivers/iommu/amd/iommu.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 9b4b589a54b5..6ea549816a1f 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -26,6 +26,7 @@ void amd_iommu_set_rlookup_table(struct amd_iommu *iommu,= u16 devid); void iommu_feature_enable(struct amd_iommu *iommu, u8 bit); void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu, gfp_t gfp, size_t size); +int amd_iommu_pdom_id_alloc(void); =20 #ifdef CONFIG_AMD_IOMMU_DEBUGFS void amd_iommu_debugfs_setup(void); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index a9b17d31a969..78b3e5485006 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1818,7 +1818,7 @@ int amd_iommu_complete_ppr(struct device *dev, u32 pa= sid, int status, int tag) * *************************************************************************= ***/ =20 -static int pdom_id_alloc(void) +int amd_iommu_pdom_id_alloc(void) { return ida_alloc_range(&pdom_ids, 1, MAX_DOMAIN_ID - 1, GFP_ATOMIC); } @@ -1906,7 +1906,7 @@ static int setup_gcr3_table(struct gcr3_tbl_info *gcr= 3_info, return -EBUSY; =20 /* Allocate per device domain ID */ - domid =3D pdom_id_alloc(); + domid =3D amd_iommu_pdom_id_alloc(); if (domid <=3D 0) return -ENOSPC; gcr3_info->domid =3D domid; @@ -2489,7 +2489,7 @@ struct protection_domain *protection_domain_alloc(voi= d) if (!domain) return NULL; =20 - domid =3D pdom_id_alloc(); + domid =3D amd_iommu_pdom_id_alloc(); if (domid <=3D 0) { kfree(domain); return NULL; @@ -2681,7 +2681,7 @@ void amd_iommu_init_identity_domain(void) domain->ops =3D &identity_domain_ops; domain->owner =3D &amd_iommu_ops; =20 - identity_domain.id =3D pdom_id_alloc(); + identity_domain.id =3D amd_iommu_pdom_id_alloc(); =20 protection_domain_init(&identity_domain); } --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010011.outbound.protection.outlook.com [52.101.201.11]) (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 E3DC4292B2E for ; Thu, 9 Oct 2025 23:58:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054321; cv=fail; b=sXeW4/fVwFikwiA8yjY6rHYwYgsSSrfl3N2b2NKI2ltByyaTMwdZKQcSJvH+vh/wP93R91MIuqoEDRWSjwKEzYnzy5urM7OE5O+lznf2ue31nFgqzmp9G8Z33m//ZeUGIMvZjdhRuhtl682PBfAEqnNLas8MQhMuog00k32vl5Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054321; c=relaxed/simple; bh=iTE09CCYSeryEtoRAGfVV7A6m86/DM71IcUibf9d8zs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Dg57sawcdcjma0DsvWDEtE1xLBxy6WwNXHQRirZulUKQzudEWwX62bVNHCNqMFvFU63lpqx46uHMIrATT7m7ON+ZRdFRrLO93/nIAJKXkB2bS2pPi+I75jmNpXcP+5EA2HbzXMdmDBZ0YWTUzq/EdOEgAMQY2gsrdsW7YtU44n8= 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=SPISZhlh; arc=fail smtp.client-ip=52.101.201.11 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="SPISZhlh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lMI2UQnVAEcfPD/gd3zJC4+uZS23gRaAGp087JqY8Ptan5ivychZHGoclWbW6HQ1EmiWR7eVK9RWIB5vh1us9dA+DbbhOdxQ5wxNggqRZ6x0o0cV2xvALbUWfwo68ZfIW2SotwPFBr7UqZgPANpc+1akx+3Q1RIejfnRpV9lxTMN1J9YyPqyovya/uBxrF7HrsnsVLAIwTMGdye0OzrtIwQ35ky59PfxwZ08i79XOeEShKdWgAz7Z/ZUbpijLT213RbRKKQa2wrswiJrMg1pEP9S5Y32JGLvl8S8O9aGl+kC69i58NpHI47N7KcV06pGHzrgxI3tPi8xY8t3iAMvJg== 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=eAlS5qFsEZ07oTwIkHsPwXm6KYLU6EP22U/6rswKoFg=; b=qOdEESPd6Tm2kaBG6SiZtQUmGMBfVVmOTFkI4CWpmVK0zPQdR5d38mQmXxyxJjl5muPJMjCoBZVkzPsWznmJsGxbpqae52vfDwJC8sSiYkq9KE+VOVyZvegjYtREJT+5RyKC1XbIj3sCHH/bSgv7huFzjv8wtcOrYaof24SinpPoTHqO8rFLdpPJUocN7/FtA65QPFzy8oS+d8/NQ6gxd09rsj2pmB/mQwD/qJvKvGV//sPoIma+4ukK5+a1rg/xUskC1uLEXOuuB084YrX7RRwv8tNYV7FBtLwv9p0xfU79LDYO7fOEgGMi2khBMoM56hxW6suFJJyvx6YZA45Bhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=eAlS5qFsEZ07oTwIkHsPwXm6KYLU6EP22U/6rswKoFg=; b=SPISZhlhmGExDCzKtxaxVC2GCcwqshluB3woX6xPdbBPuPfgiVnXJU1SRZSvFvliuYZNpzfVzgrkmiqgMXMl8/20VUnT4xO/54kYamgwhvM6m0gdKVX8+kmYBRVfbtItClLxeaLwUOXlqineLIu1KlQzY5loYKYuMMkBZnYR0UQ= Received: from CH0PR04CA0017.namprd04.prod.outlook.com (2603:10b6:610:76::22) by CH3PR12MB9249.namprd12.prod.outlook.com (2603:10b6:610:1bc::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9; Thu, 9 Oct 2025 23:58:32 +0000 Received: from DS3PEPF000099E0.namprd04.prod.outlook.com (2603:10b6:610:76:cafe::6e) by CH0PR04CA0017.outlook.office365.com (2603:10b6:610:76::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:32 +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 DS3PEPF000099E0.mail.protection.outlook.com (10.167.17.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:32 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:58:25 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 03/15] iommu/amd: Make amd_iommu_pdom_id_free() non-static Date: Thu, 9 Oct 2025 23:57:43 +0000 Message-ID: <20251009235755.4497-4-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E0:EE_|CH3PR12MB9249:EE_ X-MS-Office365-Filtering-Correlation-Id: f7440706-62ce-48c2-3100-08de078fc0aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|82310400026|376014|36860700013|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?bPf2wgtC9wYT+3R1X2yV7uC14aN3aoQbOdcPR04aiBfNrcMQBMiCER9DkT5O?= =?us-ascii?Q?jcObITL/tGPAFNB9RRJ1aZmN2yARR4JyOdmiAdxRX1O2XwJ0NlN1eA0AVRp6?= =?us-ascii?Q?9/Rky69ICHIQVdEpBYtcerR5dA6I79qNZE3KjwsFyaz0t+M214ClPE8KvaGl?= =?us-ascii?Q?04CkrOmubhJMMvIBo0MD9kFItbmW9DfrBw0p/+A2jvoXqtTVl5uk7zg2nR53?= =?us-ascii?Q?Dq79wV21c5FPf7kXbCveoauKhi87sRvXQKJeLaEFrFlVIgbNQ0YnVbVxu126?= =?us-ascii?Q?yqEyDxw5GTBdSDaeDgsYViPXdNpCitFicpGbMoIg6ZAdr5Z45bqrEHk/M9Y8?= =?us-ascii?Q?hKMv+eBfvPtjJauWK+jpp+lHwumxAxvCDmEW/luYBPiXKJwUuJyzs4wIPSvy?= =?us-ascii?Q?8hVk5UA2PzPH7Qtf/PfDZkQeZxQs3FImnqUzEpUPMQFAkgpxAmXKApKHWz6Z?= =?us-ascii?Q?S5ieCcTwBrM/reF1OAOMz9Squik7+fFHQebm1mJMxS5ihhRLhtk8/eiPgX3k?= =?us-ascii?Q?TCKGz2FeIx2oqVfngdDgNynSx6/woMYhFc2qofduVUWRZ4+6OVu3WArngw2D?= =?us-ascii?Q?SGSv8sW7sRovpjxX6+hygvifmkwgbzhs7r3Yd0MjkQq8zBGo8gEDqrgXff+d?= =?us-ascii?Q?WlzK4WHxqw7JQIh9X6IXuYH5E5DjDVMKzFlW/ThWINXvreQmo0srC8BRQsIk?= =?us-ascii?Q?+d2KFoPmmHC+A9OUBiDEYnt+eAqP5JDrAeBhw9weda9Rbf7zn+TU/e0rza6x?= =?us-ascii?Q?F0VatgcNowOQ9h/JOARzbNttAb6AvEx6nRT33vmtSm3pZlCmkOzMhmUecRbO?= =?us-ascii?Q?tvJxaLK9yJw7EwObz10BgRSXR+msE4ghR2p8ALdmLDHFQPTQYaGYKhUDa7ju?= =?us-ascii?Q?nuY3CT4MishYSkKs/mAQNw56TDsutoXZN/D9kTySy0So2ijbobxkiTRWMEyS?= =?us-ascii?Q?w1ifzwimAX79JOgbUTTfMWF3aq3I1/B8N/LWlKgDt0LTET2PeG6g3vuE6e42?= =?us-ascii?Q?vT8R7QAuRo8xdupk36ghVLfuwldjrNTnoawlt2X8moJCi1M3ZlDGNvVG8WGj?= =?us-ascii?Q?Rll/JvI6BKwOfae3WUPd1irz/dAPFua2GjGe6PwWULimUeX5CV0FkYorQXFk?= =?us-ascii?Q?DR3NELsMDAeNhIOyWegxBtIC79q/qQEW/zlTZ//SoAHG2X9z2yL5UCjZ1hbS?= =?us-ascii?Q?v/zClaqeV1WAE2anTsnKtXKBa6Fis0zsdwOj7rGs0D23BHbUH01eKApOJdF5?= =?us-ascii?Q?llnkFuZiySBkNpGa2ZWUPykAzPAIMhYHw2YraCnSHGpThgQ5R4Ui8aJsFHLI?= =?us-ascii?Q?vVAuysKz+t/M7WYDdCRdjM3QvdwaGMoBnmBrfDlx/dT8NybPBmPy7BiAySaH?= =?us-ascii?Q?0ZYfZFFCCEU5hm3X94cEx9BsOg9/FOb11XA0t9akpfl5SzG8oU5hy3kFtzp7?= =?us-ascii?Q?67Bcc01+vo2TvYE4Eqq75+CUHcvcxpWTuqEyyK6HdIKYmSaTk5eMkBNZWroE?= =?us-ascii?Q?th7kSuV/KUYCz3WmNv2v1als3wJO18U0zfyWBy3gA0YGBC5LNCkfZCEB81jd?= =?us-ascii?Q?0M9wF6INj2KN4eBKeXc=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(82310400026)(376014)(36860700013)(1800799024)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:58:32.6475 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7440706-62ce-48c2-3100-08de078fc0aa 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: DS3PEPF000099E0.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9249 Content-Type: text/plain; charset="utf-8" This will be reused in a new iommufd.c file for nested translation. Reviewed-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 1 + drivers/iommu/amd/iommu.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 6ea549816a1f..322c8c73444a 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -27,6 +27,7 @@ void iommu_feature_enable(struct amd_iommu *iommu, u8 bit= ); void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu, gfp_t gfp, size_t size); int amd_iommu_pdom_id_alloc(void); +void amd_iommu_pdom_id_free(int id); =20 #ifdef CONFIG_AMD_IOMMU_DEBUGFS void amd_iommu_debugfs_setup(void); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 78b3e5485006..0b61059e485d 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1823,7 +1823,7 @@ int amd_iommu_pdom_id_alloc(void) return ida_alloc_range(&pdom_ids, 1, MAX_DOMAIN_ID - 1, GFP_ATOMIC); } =20 -static void pdom_id_free(int id) +void amd_iommu_pdom_id_free(int id) { ida_free(&pdom_ids, id); } @@ -1870,7 +1870,7 @@ static void free_gcr3_table(struct gcr3_tbl_info *gcr= 3_info) gcr3_info->glx =3D 0; =20 /* Free per device domain ID */ - pdom_id_free(gcr3_info->domid); + amd_iommu_pdom_id_free(gcr3_info->domid); =20 iommu_free_pages(gcr3_info->gcr3_tbl); gcr3_info->gcr3_tbl =3D NULL; @@ -1913,7 +1913,7 @@ static int setup_gcr3_table(struct gcr3_tbl_info *gcr= 3_info, =20 gcr3_info->gcr3_tbl =3D iommu_alloc_pages_node_sz(nid, GFP_ATOMIC, SZ_4K); if (gcr3_info->gcr3_tbl =3D=3D NULL) { - pdom_id_free(domid); + amd_iommu_pdom_id_free(domid); return -ENOMEM; } =20 @@ -2573,7 +2573,7 @@ do_iommu_domain_alloc(struct device *dev, u32 flags, domain->pd_mode =3D pgtable; ret =3D pdom_setup_pgtable(domain, dev); if (ret) { - pdom_id_free(domain->id); + amd_iommu_pdom_id_free(domain->id); kfree(domain); return ERR_PTR(ret); } @@ -2631,7 +2631,7 @@ void amd_iommu_domain_free(struct iommu_domain *dom) WARN_ON(!list_empty(&domain->dev_list)); if (domain->domain.type & __IOMMU_DOMAIN_PAGING) free_io_pgtable_ops(&domain->iop.pgtbl.ops); - pdom_id_free(domain->id); + amd_iommu_pdom_id_free(domain->id); kfree(domain); } =20 --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013020.outbound.protection.outlook.com [40.93.201.20]) (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 D65AF28C864 for ; Thu, 9 Oct 2025 23:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054330; cv=fail; b=A+77ahVHEjaQpaclY7fTuMU+jqZgy9WwMvAZJBUOzCHu+ZjiIlkm4O7HR7eyiGL5H4nkcduyo8oIqx2mY2ZaD+CVTInAZ6doYdga1w77BLV2SVNwEQnmE4OVPTSqk6ZPGmpAmqW313SNVfewObNPKH73o1krf5oDBxPWnG7CnGc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054330; c=relaxed/simple; bh=wxkHwguqR7b27G2jKrNKFTz9BrsCmBKm9mmCGSMuWIA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Tk06suNfK7FHVwKkwFnqmwRFr72IqSfDaQ9JJfmR2VVG6gYyZQZAKLbW9JLB/p/9JzIBI7oEhyqfFPY8dY42HKonIrB0aoY8inShAlV41xadGwTlkgl9rxDHj3/hEERH0CywuHGz3ztG9u3SjfKMKc4FCUEAJdKfrHHI1PAVbfQ= 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=ZYsqyIn5; arc=fail smtp.client-ip=40.93.201.20 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="ZYsqyIn5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mXEAzuURK/mG7/cP5J3ip0pgDz60OeT+nw8EtRAooUdlRgIHNSrfKV4ANChju6RhhnK+L0ZkmPPtDtFUALu+cdVeG6h48tDFw7/vmbsNrJijkiMAzZRyddOfj2Pig52P6+fGReg/gV2dm2MhhFypGnTjn3HIaQrC+hvrLwfPlL233JOnU5tY9X2z7Wodd2iSsKtYZnj/PHfB8YpwbCZSou/H2cNu7VUoVFZ1MfA9K0VOyHzdV9CvDEy0rdeSb28N5dfQyHt19aycYGvgknF/Xo6WWk7oNzgffZTJIqbn742Xq+tB2h1M+7Ohg2aWSNax9Z/4YvLDgC9PIFR1Rg+uhw== 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=oDiYJEDSvmlcNBDGre8gX6wtxHBcG3kadFsDk6thQ68=; b=WI+YDvKPFf5jdoF8rHokxkFbnerlWvof2GJ2FIA5lAySUvrTy1A9W2hN2qUT/MvS4ID2K91TiCwjFQAzfaGPlTAMQAySf2mRrkTZ7JPmguRLu9I3NRdiFSBrjMJlNc2XQf+9UxJVQOF54WOQo3sJtc8b72MyhaqJWReteEfBIdtLHyD+7aW4g/XmWysdOXfFvALfUNT4t8V2FY/pO9w+x+f8qsEzWgr7v2qT9DsWGMjp2z8qcpa1fVtOgWGAPmIWOrf2gOIWTqbYOIHCRrR+6F34eJjohj8maZAAXWsE5y6i1GkRa4KKzpuI51y4feZAiiSSbdbvTcu2zJEQ0qh1Mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=oDiYJEDSvmlcNBDGre8gX6wtxHBcG3kadFsDk6thQ68=; b=ZYsqyIn5DjVN/l9kbRvzVc+j8Z5Y0Jno12XfPajbh83yHKGgiQ8Hj7ojkbxGs/LYnh8r2eqE3wfNVmvvJVQKXzIupOpeDDrlNtvnb49EJOikB8J81KzNBY/1SLyNb6mq/LZQGBYzdpkP9uay/YHlqvqcLnLZADVXKGriTXxlsKk= Received: from CH0PR04CA0009.namprd04.prod.outlook.com (2603:10b6:610:76::14) by DS0PR12MB7559.namprd12.prod.outlook.com (2603:10b6:8:134::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.10; Thu, 9 Oct 2025 23:58:38 +0000 Received: from DS3PEPF000099E0.namprd04.prod.outlook.com (2603:10b6:610:76:cafe::9b) by CH0PR04CA0009.outlook.office365.com (2603:10b6:610:76::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9182.20 via Frontend Transport; Thu, 9 Oct 2025 23:58:38 +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 DS3PEPF000099E0.mail.protection.outlook.com (10.167.17.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:38 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:58:30 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 04/15] iommu/amd: Make amd_iommu_device_flush_dte() non-static Date: Thu, 9 Oct 2025 23:57:44 +0000 Message-ID: <20251009235755.4497-5-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E0:EE_|DS0PR12MB7559:EE_ X-MS-Office365-Filtering-Correlation-Id: 348ab90a-84b1-45bd-aa38-08de078fc428 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|1800799024|36860700013|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?S7wZAB8G1XEyjCFNJ+MlwkURob25A9eE4M9XMPcJYjapKWqyJ6a0YSPegOjx?= =?us-ascii?Q?kB36mVfyehSX/1hixdGbFtMHLYOt5Jzw+kAYGOXbmC5G5bQsJRHzxUHGKN//?= =?us-ascii?Q?k+o3Hs8j0Ee9QMnDWqeaMPq3K6psHtSqNupk7wdmUsLs8VHX3ROBVJkniEo2?= =?us-ascii?Q?LfoZAOU42YvXbCxTl1nWpPSq3gIMHSqPXSdmNtgwHkmS4n4YYlyVxk0pN3ff?= =?us-ascii?Q?5xp8M6ipU5hDN8IMxQaFWMKhaCuqTt1YRnMuxFHYOppXM0Z0lTs9tTNDPqec?= =?us-ascii?Q?titbNRAcQXjrtQMaJVyRCVGuArSDJCmb7zBcVe5MqFWXI40ur/1IcZmIIB93?= =?us-ascii?Q?46SilcpLekTQxT52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us-ascii?Q?Jr14b4vxEPPDf15b8mHSxYgkVAPyDcvc9lYKi0IUHMvZAilbDUM7zNf96iwp?= =?us-ascii?Q?bcPlkxiQc1kXs8DYJqaTtYkWP78NOiwKPYkyuQzum1yq3FgdDVKduY1VK9lL?= =?us-ascii?Q?qZE10dj9o22/H6V4KQqaxJRb4kqo4VMc7O5nBCVst57Wx/bD6bHygLTss3md?= =?us-ascii?Q?VSoOb8SZICIsaa0Q+6NK9biYjkS4EKm+pdb06BlYz58KWU1NOhYH8bQPSBva?= =?us-ascii?Q?1J5bl+WqmSRaTHaB0hU2uj7m3Aes5cpZB6tmqwNnk7eyysdu3qUFu4OfhKqF?= =?us-ascii?Q?CLG6LWA6jipkOPxiCXA=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(82310400026)(1800799024)(36860700013)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:58:38.5085 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 348ab90a-84b1-45bd-aa38-08de078fc428 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: DS3PEPF000099E0.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7559 Content-Type: text/plain; charset="utf-8" This will be reused in a new iommufd.c file for nested translation. Reviewed-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 3 +++ drivers/iommu/amd/iommu.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 322c8c73444a..079fb1d44c00 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -188,4 +188,7 @@ void amd_iommu_domain_set_pgtable(struct protection_dom= ain *domain, struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid); =20 +/* DTE */ +int amd_iommu_device_flush_dte(struct iommu_dev_data *dev_data); + #endif /* AMD_IOMMU_H */ diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 0b61059e485d..fad74d2bc1b1 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1562,7 +1562,7 @@ static int device_flush_dte_alias(struct pci_dev *pde= v, u16 alias, void *data) /* * Command send function for invalidating a device table entry */ -static int device_flush_dte(struct iommu_dev_data *dev_data) +int amd_iommu_device_flush_dte(struct iommu_dev_data *dev_data) { struct amd_iommu *iommu =3D get_amd_iommu_from_dev_data(dev_data); struct pci_dev *pdev =3D NULL; @@ -1788,7 +1788,7 @@ void amd_iommu_update_and_flush_device_table(struct p= rotection_domain *domain) } =20 list_for_each_entry(dev_data, &domain->dev_list, list) - device_flush_dte(dev_data); + amd_iommu_device_flush_dte(dev_data); =20 domain_flush_complete(domain); } @@ -2144,7 +2144,7 @@ static void dev_update_dte(struct iommu_dev_data *dev= _data, bool set) clear_dte_entry(iommu, dev_data); =20 clone_aliases(iommu, dev_data->dev); - device_flush_dte(dev_data); + amd_iommu_device_flush_dte(dev_data); iommu_completion_wait(iommu); } =20 @@ -2874,7 +2874,7 @@ static int amd_iommu_set_dirty_tracking(struct iommu_= domain *domain, spin_unlock(&dev_data->dte_lock); =20 /* Flush device DTE */ - device_flush_dte(dev_data); + amd_iommu_device_flush_dte(dev_data); domain_flush =3D true; } =20 --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010021.outbound.protection.outlook.com [52.101.56.21]) (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 516E0296BC4 for ; Thu, 9 Oct 2025 23:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.21 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054329; cv=fail; b=pvlzeOeZrqaf+/4WXpfHWoeMVawPxb0vY8+CIUIhqREcHOnsK5gTWVQKmixd4oLQ0CkzDaSB3XHEL6YWXRJOSenjbu9BPE1KiIkG1yN8GUSTS0bYolx5486SzfxkcZ9PmCA1VTuhmO1dZfmP/IsJnYAU12/7b6RXoBQKXLhL5zQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054329; c=relaxed/simple; bh=gn6xpLP1QjIQG6ns6GPR0XtG7tjfWq8j9jgl5AS97I8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OgLL4jE+aysAC2Nmb+lg/A6IWGs6vT0v2zaLPqNGi2qt3dbvxC8u+QdfM4vO5+kJME7clln8z+wwO9W1glf3/CAw3lcqDd54OYbS3Lg6FhJf+U8QD3UvZLBuWyZf4YvqVW2LdJRtswTUFPyE1RXkWwVweAplxN+7aIyaP8K5Mkw= 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=ovJCpBuz; arc=fail smtp.client-ip=52.101.56.21 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="ovJCpBuz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nUzLw0Jk6dQv7d5R+nrfuKFqYwWsewKKrjJGezP3hmfnopmV+oDd6wiqQh2RR05sQLAF5x/PrN6Q2j8tkHAWXdo6zqyRCo56iTvvBWfga+JpmZxVaQk2toqXYu5JDofWTrWsbb+fV9ujp4m2u4D97Zz7FFWNgdVjD7WpzQhZJzfTgAyt4YFVgdj4sgqH3ETlOQA+nLK+opncCvKlcQS8s1/9vMl0bQv0I1lPEUr9Qpnqqc6yPe2hrEEvnMTW1LcLrDNP/c4syg4lG8qpJorxfcgWaoUontrG/MEN7FQNAzh4jiKk1rU+1i3CdCv6IXST2RTsQMS9ShoihDeaWPsl2Q== 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=1DZhN/4ljDXwl7CFS2tNrXY+OE2PYoXg9r/V4Je9hjI=; b=LdxQy8b//x77AJhRbyoPaCxenzUXmOcYzZsRYN75XRMfNTNaP3l5gGmBqUa0JtpP7jDb10wDbhXgQz5+NMCSwf2bJgfDo1gwqy00C2q7BZIlvY/s66hNTeI9WC0OYx9D7uBI5fmqYYFA4Wc9HVf8JHqvKBEnlLY9L7DyOviDYjDfjdO1HLEN6AFjx3+3c96XbTM9FPJRBKuDZvIViX/kIiW0ATaiO1lmOcmlXvK2ctC414p3oELzhAo1UnNMPoszF2OdJGIR9Q7qU/ugBkifxh78ZkSNijRkyb4MWA8DLV3TShgWOMewDg99AjcY+oawzvwaETGN3MvT+znPS1xyYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=1DZhN/4ljDXwl7CFS2tNrXY+OE2PYoXg9r/V4Je9hjI=; b=ovJCpBuz9crJ6ccocxhjFm91TRh1hPyaTEGRd/25cPJP8fUEGyxfVwBbTN3HvKc9Juk/K26dFI9XWOS8TGro1M2x4LKiHDHIenoSiwyMRD5aZvcj4HniaV+ObGjRZpLC72KBS3NqpGdyUSN+tCuj3UVfkk8aNdpowSVJG+6ijgw= Received: from CH5P220CA0020.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::18) by MN0PR12MB6151.namprd12.prod.outlook.com (2603:10b6:208:3c5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9; Thu, 9 Oct 2025 23:58:42 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::fb) by CH5P220CA0020.outlook.office365.com (2603:10b6:610:1ef::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:58:40 +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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:41 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:58:36 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 05/15] iommu/amd: Make amd_iommu_update_dte256() non-static Date: Thu, 9 Oct 2025 23:57:45 +0000 Message-ID: <20251009235755.4497-6-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|MN0PR12MB6151:EE_ X-MS-Office365-Filtering-Correlation-Id: 948ac02d-c715-4ae6-98b0-08de078fc620 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Jmk7BAvSENcqRJ9JgUIDELZCQndJ14lfbZqIUr2xtMdJgaVUn8R07paqwuzc?= =?us-ascii?Q?AyCujNogxD5ryQF3wpgbtg7P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-ascii?Q?JmTU7kHVtg3v4wsF5uG1kW+SxvPQ/YYogtlVDlwmb5mF34C8FdnpiohOw+xv?= =?us-ascii?Q?Ri6l1zLjto3kPAB9G0DvaapLW0+pnO6II00KaG1piQdGf0eLzz/h7N4/HOEx?= =?us-ascii?Q?o5i+0Ifxf4IXuxEte7ifUbfq7Ot+C7e/XYJPG7034LJ3HiYkVk5xcOrlMWP2?= =?us-ascii?Q?tf7PjG4+41DzLKW6Y+wq2rCbgRc/au2zXXGH2wXzhUf9M80yOtzVqG18i1i9?= =?us-ascii?Q?AXOGmLJeIrDGtHWURzuiXECk29iY3Onm2tP8evjJ36r30oj6quq4VgLJ9WNq?= =?us-ascii?Q?CJFaK4N0uTxx+4c65l4NReEYr4+SmTl3s7wbVHW3WdXLVKLa/p+tW30S9JCZ?= =?us-ascii?Q?j6QMGHod+3ki16QnwOIMyvZ34G39o24TQICai6bc82obWD4sKrd2UUMbOBDD?= =?us-ascii?Q?xuhwnjLSu+qefS/FRQNmExtyvn8aUNMcUd7LRIimGwC8ZzpmSG8ezgirp0o2?= =?us-ascii?Q?cyI4NDnjUhcSUXwVZJype4HbyXLDZS8wdZ3pGvvC+UNc79TD2/lUfZi5Taff?= =?us-ascii?Q?DT7Fu+4UJM5w4Xpx0FAGNx5Ui2/+0s5GYxUQvHpxfxZRghDATmuXOnUZIhoZ?= =?us-ascii?Q?nVeggEloNkI6fhiZ/5o=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:58:41.8142 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 948ac02d-c715-4ae6-98b0-08de078fc620 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6151 Content-Type: text/plain; charset="utf-8" This will be reused in a new iommufd.c file for nested translation. Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 3 +++ drivers/iommu/amd/iommu.c | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 079fb1d44c00..eb46e8914eaf 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -190,5 +190,8 @@ struct iommu_dev_data *search_dev_data(struct amd_iommu= *iommu, u16 devid); =20 /* DTE */ int amd_iommu_device_flush_dte(struct iommu_dev_data *dev_data); +void amd_iommu_update_dte256(struct amd_iommu *iommu, + struct iommu_dev_data *dev_data, + struct dev_table_entry *new); =20 #endif /* AMD_IOMMU_H */ diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index fad74d2bc1b1..3f2c61509b60 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -132,8 +132,9 @@ static void write_dte_lower128(struct dev_table_entry *= ptr, struct dev_table_ent * This function is used only by code, which updates DMA translation part = of the DTE. * So, only consider control bits related to DMA when updating the entry. */ -static void update_dte256(struct amd_iommu *iommu, struct iommu_dev_data *= dev_data, - struct dev_table_entry *new) +void amd_iommu_update_dte256(struct amd_iommu *iommu, + struct iommu_dev_data *dev_data, + struct dev_table_entry *new) { unsigned long flags; struct dev_table_entry *dev_table =3D get_dev_table(iommu); @@ -413,7 +414,7 @@ static int clone_alias(struct pci_dev *pdev, u16 alias,= void *data) ret =3D -EINVAL; goto out; } - update_dte256(iommu, alias_data, &new); + amd_iommu_update_dte256(iommu, alias_data, &new); =20 amd_iommu_set_rlookup_table(iommu, alias); out: @@ -2109,7 +2110,7 @@ static void set_dte_entry(struct amd_iommu *iommu, =20 set_dte_gcr3_table(iommu, dev_data, &new); =20 - update_dte256(iommu, dev_data, &new); + amd_iommu_update_dte256(iommu, dev_data, &new); =20 /* * A kdump kernel might be replacing a domain ID that was copied from @@ -2130,7 +2131,7 @@ static void clear_dte_entry(struct amd_iommu *iommu, = struct iommu_dev_data *dev_ struct dev_table_entry *dte =3D &get_dev_table(iommu)[dev_data->devid]; =20 make_clear_dte(dev_data, dte, &new); - update_dte256(iommu, dev_data, &new); + amd_iommu_update_dte256(iommu, dev_data, &new); } =20 /* Update and flush DTE for the given device */ --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011040.outbound.protection.outlook.com [52.101.52.40]) (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 14412289E13 for ; Thu, 9 Oct 2025 23:58:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054339; cv=fail; b=tEuv9Jmd1m+6DwhyccMzdSAJRzHFohBP9D4fhrRqnSvYlyxJHWqU+DUWvkGlAu7o4qLn0Ygxw3dQQCiS09Fwizf4hIyUzf5BMztEwRPrzxY0+FkehhfmryHer/SjmYBl/HgreywwuM5g+8ER7Fr60Ubl/1NApmX6GVha3ROG4s0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054339; c=relaxed/simple; bh=dK78iuNw1GU0LUpbCsuLchi9/xmz8emrp0kXFd1benA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bHbNqtxaG2uhvkWeExR0maqTAxdnQb43uC592siqidLZESzpjGJg8IJXigpuSQCfuWjXj9DK4d3QTh+Wz9JyBlxzj8rqeByb+nhLD3kVDZ1RGLbX5a1pyECQ5qnTb4BEclU7C4D9WpRjGEvuqzgC4w2hu+7Afp5I0wyraf4aMvM= 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=C9glYGK9; arc=fail smtp.client-ip=52.101.52.40 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="C9glYGK9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=I5aX5ALTGpCWE5qWKxYTzdsa2LIu5CIOLDZGZYk3qWFEvHhX/rvZoRWNVy2zM4eXB8Ld/Y37qWWfTKZ178GgmmxAmzGzxlEvPX5X9mUFJRcNH5iK5/l5f/u0CUfJq2rOHRk6F8qPJQgYtwCJzPbf6Fw+GjfsWcs+1ZVUpVod0DdVIUAjdKJbCEmHtVVl2IRl7HzmHj5XKzE5LOChdbr3xByGtiAcLP966+AGfm42qDyLlZqKnnp09iFHiXTa4p4o7YOHmdKE96QR2d/n6AV8+KksToV6C+2jFm0fDTVv3d2cT19kGhLiP5G12jhGerh1e5FowQFj8GqQJe4RoN1svg== 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=h1rp0LwEkQtGMRq0olWXngTjy+D5DA/0En9iQJ/qp6c=; b=ElpthjWBsfWBMLgtZ6ajLFUUZmD4zbl2RbmCODqi1LO1ALr2JbSJA+6UlbXVOYzJM6zpXbJ/Aqqdyig8+cQfeX2C74jj0nZwvPKu4A5GVz/gSDNNIbvx20p0SSoyBMiMiWcbTnO/WV4tZhocIaHKxNAiWc7yqtPi52cD3okbwwLFvefLUsY3jAM1GTFJ9pShZ4akT2rY7ID7/TxHgDRBMQIhK+ZZZ8oRJ/pKZTF008KeVBwhWOrz4c0M9nkmiqcfMmpn6G73Y9onbOXE15KNAKNsREbfBVS0OJy0c5qEZj9aNKGaCOxjQwrLtLyAM/aAF29Z6ZmUz6F9NwMBPhQ2jQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=h1rp0LwEkQtGMRq0olWXngTjy+D5DA/0En9iQJ/qp6c=; b=C9glYGK9/UrNgRpdwVLUnQ/GP7Lq+4XZNxiId1JgWPbwuyeOPmsD9NYXRfoXPWm7zxCl0ThnzB4LrCe+6LytpAzdbCkfdGkQodGX8p20u1DT/Bi8nDnpZuAS0nAc/eo1LgWqOzuKwuqt3UZF76HMI+pcrvBnVcC5230zoqvu/eY= Received: from CH5P220CA0023.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::20) by BL1PR12MB5755.namprd12.prod.outlook.com (2603:10b6:208:392::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.10; Thu, 9 Oct 2025 23:58:50 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::e9) by CH5P220CA0023.outlook.office365.com (2603:10b6:610:1ef::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:58:47 +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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:49 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:58:41 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 06/15] iommu/amd: Make amd_iommu_make_clear_dte() non-static inline Date: Thu, 9 Oct 2025 23:57:46 +0000 Message-ID: <20251009235755.4497-7-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|BL1PR12MB5755:EE_ X-MS-Office365-Filtering-Correlation-Id: f8962dc8-42f6-4311-dc59-08de078fcad3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|7416014|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?E4VkAo5egPJUwLtH4qosmVcf2WFwFJ4Vh8f9K1k3zpYVOQUjKd3RDy7iBmMS?= =?us-ascii?Q?ZqVmmQreqfSCiHId8A1SYYkgot9oAtn/eM5grrwu+evmBRrMJkqDHDVB+b/y?= =?us-ascii?Q?dt2bPnCsTeoQ+AXO3oLq2hj84C3UcyQuXX5g9kkSMhkg+pwCnByFgG7mBOaO?= =?us-ascii?Q?jRPGLaCQaj/P3E8CpcH3umOCcO8QUlbgXbfHMQSv2opjKSuoiQIvtHzpJop5?= =?us-ascii?Q?aTv2eWDBsdfW5oCMVz1/mOjj+0hnmAYD43vf7L4ND16S2KcyeF7kCRHTq6hT?= =?us-ascii?Q?gR+K4z7xBAhhV9YQe+Zo3vVfFeRrGCN8W9l3588yEW4eJAJmY0LhSTNQHaEI?= =?us-ascii?Q?bn0iTLIa2YGf1pNIlvAi2sBJyOp8vXtZRqkCjuSl/UTxC98FxUG8l8PGoV1u?= =?us-ascii?Q?6PnWatPlxDQek9qWrIzo9jWbqE5Id7wC3Vz2Zd3og7XYbJtnOZ9+QYvAM42P?= =?us-ascii?Q?LSve/BhDzbH3MAv101vLioQLbZ3YLeKejzGP3uV+Ue+MSpzRNCUNJIJt4NOO?= =?us-ascii?Q?bLnj7YA1s9OmoYQJmsWWe9DH3OmnMW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sTQ1rpIepDYMgLYKpXO3HWpl7CDDneGderO/36+6JT6SAHFiLmEEV6tkEK/?= =?us-ascii?Q?tilWf385knxvsvnfZEfjAQlLB2er/gwogjsJosKan4DcBUNXrLyxqTP2BZI2?= =?us-ascii?Q?x9k3+S1JQ6Ecjsoq3QM=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(7416014)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:58:49.7002 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8962dc8-42f6-4311-dc59-08de078fcad3 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5755 Content-Type: text/plain; charset="utf-8" This will be reused in a new iommufd.c file for nested translation. Also, remove unused function parameter ptr. Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 7 +++++++ drivers/iommu/amd/iommu.c | 13 ++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index eb46e8914eaf..c7cb4a80d44a 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -193,5 +193,12 @@ int amd_iommu_device_flush_dte(struct iommu_dev_data *= dev_data); void amd_iommu_update_dte256(struct amd_iommu *iommu, struct iommu_dev_data *dev_data, struct dev_table_entry *new); +static inline void +amd_iommu_make_clear_dte(struct iommu_dev_data *dev_data, struct dev_table= _entry *new) +{ + /* All existing DTE must have V bit set */ + new->data128[0] =3D DTE_FLAG_V; + new->data128[1] =3D 0; +} =20 #endif /* AMD_IOMMU_H */ diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 3f2c61509b60..386ac96b2c02 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2008,14 +2008,6 @@ int amd_iommu_clear_gcr3(struct iommu_dev_data *dev_= data, ioasid_t pasid) return ret; } =20 -static void make_clear_dte(struct iommu_dev_data *dev_data, struct dev_tab= le_entry *ptr, - struct dev_table_entry *new) -{ - /* All existing DTE must have V bit set */ - new->data128[0] =3D DTE_FLAG_V; - new->data128[1] =3D 0; -} - /* * Note: * The old value for GCR3 table and GPT have been cleared from caller. @@ -2068,7 +2060,7 @@ static void set_dte_entry(struct amd_iommu *iommu, else domid =3D domain->id; =20 - make_clear_dte(dev_data, dte, &new); + amd_iommu_make_clear_dte(dev_data, &new); =20 if (domain->iop.mode !=3D PAGE_MODE_NONE) new.data[0] |=3D iommu_virt_to_phys(domain->iop.root); @@ -2128,9 +2120,8 @@ static void set_dte_entry(struct amd_iommu *iommu, static void clear_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data= *dev_data) { struct dev_table_entry new =3D {}; - struct dev_table_entry *dte =3D &get_dev_table(iommu)[dev_data->devid]; =20 - make_clear_dte(dev_data, dte, &new); + amd_iommu_make_clear_dte(dev_data, &new); amd_iommu_update_dte256(iommu, dev_data, &new); } =20 --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011040.outbound.protection.outlook.com [52.101.52.40]) (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 990AD29B764 for ; Thu, 9 Oct 2025 23:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054342; cv=fail; b=NpM15MI2YeD74iEIlhODyz+wbBBnoPBmMrPVZWN7th5Eb57e1vzoMQv/JUGyuYbSCvlWcWZPyzJJE3Lf3XflpMQNOCe2+LEK+BLbd/S95gl49XcFgbVIlSbqLva/mvtE+CLjGMBaIyoB9hhCxo4/p3j3sGGq4VCJ7h+VqipGlco= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054342; c=relaxed/simple; bh=Ok/cM8ese5HL4McIaRLtL77VpEJEHVsaHuaPBMt6gKQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o84VOT0q0ReLGE//z3DBf4z4TI4wBflwMmbf63hMxkP/IHiJIL3FtO1dt6FR6kdyu67pBvoPNYouuzve8cLZzjKAqtZUjZbcFEbaWmCRNvH8KaXlJIyHxpNWnR7dKEydEJ+SGMsCXbxvwCLUv7sF76rAV7H5jR2GDiMEQE9+GcE= 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=YJHz6w6Y; arc=fail smtp.client-ip=52.101.52.40 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="YJHz6w6Y" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Vg5o/euQuR7/j2p384/JfAA1Jma6QmZDE3HV3R755yjSrdk7uxQxENZFSuXCci/1M5YgoDtYapfxF5kYk0dMuQEwBReuut2Scjt8315xI6h5OGdntENgHeELeS47DwjICNnBUrTg0TApURWMoMK0XAxAHGvyVZEUwcofoqP91lHI5U6eOK8baBLSRedrGbQU7bHgKziqmJCjwI4CHYJ0ToIQdO2DZG7Aor8qYoo1BF1R4H10D7vW6fD0mWtL7a7ya0N1vDwebtoE3LdnBIfctpB7Lra4refUBYlaW/E+QPEYkHLPnWgvGcp5Vs5eeSywrMxGrfasB0ZkTCYxNRLIIg== 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=3M28cYGNqz9F9QhqOm8yirZ+3BjaFb3Yd6KvB5xY6PE=; b=w+F4DyaBHc1yOWMwxJbplfAhmxn4KniviYT0TSsHt8rW1RObYtpa2iRLj3FmZq7HAQGjNo4apqw3YwvhJxGrBknXm89qk1uTb+Zn3n538aqj8+QSRb8VvPiqOUN9Ec+FGWUO2Degwy52IOWirRJhaCqvilufIAOYFZUTAm+P+/tgSmNPhLiJOZolWTPtABeDhPx1q49HyIxL/zw/zjU4lnpPKWbBed+2DLNCSR1GHktwbeguluI7OTstlTioFTJbdAJDqOWVtSiqG9PL6VLihwsF4tJN7YjBtEDgiqV2pzLf9vz5nSHGCPTqogAy7hzwM1tNKLiuRDJXC5VWKGD0oA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=3M28cYGNqz9F9QhqOm8yirZ+3BjaFb3Yd6KvB5xY6PE=; b=YJHz6w6YVn80/6RdBRxr3i8wUaK6Ue9NmYdzjQSyyRvmKizk/wo4BQekqqpIdTT6wET2gWGYXAHGdNUuBhNlOWf2k7RdbKg9jNAA9xg/JYRThOkhobqIPLNCIYMERxynf/sYAhVbdtnEOpY2Pz5Tp38rvzu1Gzl3TpGl+o9rxP0= Received: from CH5P220CA0020.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::18) by BL1PR12MB5755.namprd12.prod.outlook.com (2603:10b6:208:392::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.10; Thu, 9 Oct 2025 23:58:54 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::4b) by CH5P220CA0020.outlook.office365.com (2603:10b6:610:1ef::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:58:52 +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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:54 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:58:47 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 07/15] iommu/amd: Make amd_iommu_completion_wait() non-static Date: Thu, 9 Oct 2025 23:57:47 +0000 Message-ID: <20251009235755.4497-8-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|BL1PR12MB5755:EE_ X-MS-Office365-Filtering-Correlation-Id: b2004135-56b7-4784-3bf6-08de078fcd71 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|7416014|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?HoLW2FRwWjoJGaC7E0UrO6Nc28X6W3C6ypyyzqFuuE20jAkX2NvLxOu8ivcf?= =?us-ascii?Q?wNL3bnaMaR7fxRQs3L93QoCRGaNx4xzxpwYN2aNbFVI2F1iOiOSW4510+4YL?= =?us-ascii?Q?eVFf71T0wY3dvn2Zy06sPrOtCJ16z93j2LsF3Sj0e+0kxSeT2Z09pmQcGImz?= =?us-ascii?Q?ziavGmElgmM/SRBBttZk34qHl5Bjvpmnxkt8PSWy7M4ZB5gSPcnHpWsp1Tsy?= =?us-ascii?Q?zygwdyD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XRGlUNcwB?= =?us-ascii?Q?z5B+f4BUM69JF1Sy6+D/St6Q8uezOvfzVL3FjTCBdOpr8MskBu9d7Ip89yI7?= =?us-ascii?Q?Trwn3VmSLZKyr4nlysQy5hQnvPz3hiiI1QjhlJk1/PfbYI9fuCMtm/FaRfi6?= =?us-ascii?Q?TORLvho3osv4rU4g9MVgJEqBEDGvVOitc6jCiFKMQp+mHKpRlK15p7yeEDZL?= =?us-ascii?Q?7nJh08GGHKN0Wsg3W4HKd/0UUvciolk2YG1XdBC4baLANSuAsX2NRrVRyGgW?= =?us-ascii?Q?7iEgEdp49DI/Mp0pqX0MuI6RbGTn8tPPSeDND5vg3WCgNRIo4IjapYbuzR9p?= =?us-ascii?Q?wbkxQt9MY4TUuQSKVQmJHkan7cybxEImLS2Bcv2MRSFWXvCm0iROSmsn6bVS?= =?us-ascii?Q?I63Py5ci3wzyhyKtELhnzl3QxWLUXFAhFit/p06OmhTlZ2dQ7lAWDx9ZS/Vy?= =?us-ascii?Q?tueiKcpW09Zi+9MCE+k=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(7416014)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:58:54.0872 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2004135-56b7-4784-3bf6-08de078fcd71 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5755 Content-Type: text/plain; charset="utf-8" This will be reused in a new iommufd.c file for nested translation. Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 1 + drivers/iommu/amd/iommu.c | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index c7cb4a80d44a..d533bb8851ea 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -187,6 +187,7 @@ void amd_iommu_domain_set_pgtable(struct protection_dom= ain *domain, u64 *root, int mode); struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid); +int amd_iommu_completion_wait(struct amd_iommu *iommu); =20 /* DTE */ int amd_iommu_device_flush_dte(struct iommu_dev_data *dev_data); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 386ac96b2c02..e0bfcda678a8 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1392,7 +1392,7 @@ static int iommu_queue_command(struct amd_iommu *iomm= u, struct iommu_cmd *cmd) * This function queues a completion wait command into the command * buffer of an IOMMU */ -static int iommu_completion_wait(struct amd_iommu *iommu) +int amd_iommu_completion_wait(struct amd_iommu *iommu) { struct iommu_cmd cmd; unsigned long flags; @@ -1431,7 +1431,7 @@ static void domain_flush_complete(struct protection_d= omain *domain) * We need to wait for completion of all commands. */ xa_for_each(&domain->iommu_array, i, pdom_iommu_info) - iommu_completion_wait(pdom_iommu_info->iommu); + amd_iommu_completion_wait(pdom_iommu_info->iommu); } =20 static int iommu_flush_dte(struct amd_iommu *iommu, u16 devid) @@ -1449,7 +1449,7 @@ static void iommu_flush_dte_sync(struct amd_iommu *io= mmu, u16 devid) =20 ret =3D iommu_flush_dte(iommu, devid); if (!ret) - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); } =20 static void amd_iommu_flush_dte_all(struct amd_iommu *iommu) @@ -1460,7 +1460,7 @@ static void amd_iommu_flush_dte_all(struct amd_iommu = *iommu) for (devid =3D 0; devid <=3D last_bdf; ++devid) iommu_flush_dte(iommu, devid); =20 - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); } =20 /* @@ -1479,7 +1479,7 @@ static void amd_iommu_flush_tlb_all(struct amd_iommu = *iommu) iommu_queue_command(iommu, &cmd); } =20 - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); } =20 static void amd_iommu_flush_tlb_domid(struct amd_iommu *iommu, u32 dom_id) @@ -1490,7 +1490,7 @@ static void amd_iommu_flush_tlb_domid(struct amd_iomm= u *iommu, u32 dom_id) dom_id, IOMMU_NO_PASID, false); iommu_queue_command(iommu, &cmd); =20 - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); } =20 static void amd_iommu_flush_all(struct amd_iommu *iommu) @@ -1500,7 +1500,7 @@ static void amd_iommu_flush_all(struct amd_iommu *iom= mu) build_inv_all(&cmd); =20 iommu_queue_command(iommu, &cmd); - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); } =20 static void iommu_flush_irt(struct amd_iommu *iommu, u16 devid) @@ -1523,7 +1523,7 @@ static void amd_iommu_flush_irt_all(struct amd_iommu = *iommu) for (devid =3D 0; devid <=3D last_bdf; devid++) iommu_flush_irt(iommu, devid); =20 - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); } =20 void amd_iommu_flush_all_caches(struct amd_iommu *iommu) @@ -1748,7 +1748,7 @@ void amd_iommu_dev_flush_pasid_pages(struct iommu_dev= _data *dev_data, if (dev_data->ats_enabled) device_flush_iotlb(dev_data, address, size, pasid, true); =20 - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); } =20 static void dev_flush_pasid_all(struct iommu_dev_data *dev_data, @@ -2137,7 +2137,7 @@ static void dev_update_dte(struct iommu_dev_data *dev= _data, bool set) =20 clone_aliases(iommu, dev_data->dev); amd_iommu_device_flush_dte(dev_data); - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); } =20 /* @@ -2421,7 +2421,7 @@ static struct iommu_device *amd_iommu_probe_device(st= ruct device *dev) =20 out_err: =20 - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); =20 if (FEATURE_NUM_INT_REMAP_SUP_2K(amd_iommu_efr2)) dev_data->max_irqs =3D MAX_IRQS_PER_TABLE_2K; @@ -3255,7 +3255,7 @@ static struct irq_remap_table *alloc_irq_table(struct= amd_iommu *iommu, set_remap_table_entry(iommu, alias, table); =20 out_wait: - iommu_completion_wait(iommu); + amd_iommu_completion_wait(iommu); =20 out_unlock: spin_unlock_irqrestore(&iommu_table_lock, flags); --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010020.outbound.protection.outlook.com [52.101.201.20]) (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 ACB0C295DA6 for ; Thu, 9 Oct 2025 23:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054349; cv=fail; b=VdMd4mC8XhOBLTavbIuB6tVsQ8Rss2uyhapvQcwijvvwnoMTcp/aVfthlWrIwYVmPMBl7qApg+vJMJoWzN16hg9q5wNESQo62s0w9iUu42NHdDRRHFr2J5kstVXZClQy6D+h82U2Ix1JHPFy751zVqAcoc95AgLYfAuIexN6d2M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054349; c=relaxed/simple; bh=8FWOQD4lv6MveqPTtoUHsWXORHCb1a5ALm5U2qLhj0k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jL8BvrQZAbQgOuk4ZERwNk6UYqs2DmgjDEOdZaB+lmijdVV39taw/CPid3OqfgoaAYSCSyE/o43XGgraxNsHOTjiK4ILwEPPE88zODZ22n8o3/BybfPIFrnPR0oewXlLv5wXAz1NkjBndRWxmUM5nf1RmKkf30Q331iOZ7v5KNM= 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=UDV5luOt; arc=fail smtp.client-ip=52.101.201.20 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="UDV5luOt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wTCOvr7j8U+tROHZ4BTYJApkQhumzeNInZRIqB+IJjG6hMYscVXjAjh8iRTUf+LOzQDNXFtrEP83xM72LZyegcNlkdRB9xJZa8wBRWs7S19QzcvdwnzmXb5KnyylBRZjBFPaVCbQs/o/Bsj0CHD0CpNjWNXqG2cYOiSvuo++6T4c69lQdI1O4GZYBpnoY3TVWHQIhZhlI4vUuph0gOG2yhS62gJDO407TP6W05ghCI64Rw30ixqg96gIdFfxJZpLtXpy9/53jdK9euxZY+JxcLbzQScsCd7mGw8/zIerUYZxunLV3llc+BoN44EEMHxICS3iXzUtceXF+gYWWiTvwQ== 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=qbfva/eTRZ3kvBB7tQIrSgyV40JWqCGZBB1z8+gemYg=; b=ayfwJ1ofm4V56ICvW+0bpax7VD0ZGqNT61mn7G3wkhbPMsX5Svg3YCqlEwcTrYUJYYBgcaYTJIdHLeJ8jRdGlSLefiuWnmIAVJPcmA9h7DuFFTDBGxmirDcnz6u4OqbfzAkuiN0G0R/iv6lC9GrJCkSrPqnyXdAPMk8jk3RPyP9N+BGL+uAzS2yovn1HZ/4oCtLunORYRmeE+Kik4FwukmaRYP6xQFBxqyxmlf8NTFTL7N5Skbjz43Qu/G257OmorOxTonf1DB9LnEeKNji7pSxo+wL77vKEy+bvUWZ6yo1PMp6U2E7/eUIJ/0tGs85GHxNI6EMsxqN/zEpjQ6hXiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=qbfva/eTRZ3kvBB7tQIrSgyV40JWqCGZBB1z8+gemYg=; b=UDV5luOtS80qEddmQtFhavwyeDxoKfuT2DZ9kcEa8O/rnzXH3gsSKcgmymGelRJ44eayQCNWVx6iJm/kW+FBT4zSppCI/txfNkcZgD3onwHuZBqsaA797ZAeIEDto8lNlY4iIRR7iwztuoqjQnQQlFzG/hvTi0kb43xUncx1k8w= Received: from CH5P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::27) by SJ0PR12MB6879.namprd12.prod.outlook.com (2603:10b6:a03:484::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.10; Thu, 9 Oct 2025 23:58:59 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::87) by CH5P220CA0013.outlook.office365.com (2603:10b6:610:1ef::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:58:56 +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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:58:59 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:58:53 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 08/15] iommufd: Introduce data struct for AMD nested domain allocation Date: Thu, 9 Oct 2025 23:57:48 +0000 Message-ID: <20251009235755.4497-9-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|SJ0PR12MB6879:EE_ X-MS-Office365-Filtering-Correlation-Id: 470e8ee0-ce11-4921-465d-08de078fd07f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700013|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?IOUeHECkvk70Tlw9ZM0rReavdrvKOakONcsDzm/n/LY+FD+tiYKycibkv/d0?= =?us-ascii?Q?pAIuWFVVaVnmu0Nig0H9pKue/zU1NDY4AJWk6rgQsqq4MAeXqzSP+EfOngTV?= =?us-ascii?Q?EBuh26H0/vtz1T0+ii3OTm7l6ZWmkp+bWS4FKiIvlHEjJhkQJB6V4eUQ5jQn?= =?us-ascii?Q?E5aBTR9UXx3ICslEANEQX4lA4d2fwZYMFxlbO3HErB0v2VZVsB2+EEzMeyER?= =?us-ascii?Q?2/vDey85JtN8DLgSjnRTlAoZHnzGxjp4GSk+UcegJKwKVQ0vvLl0GOl2CkOx?= =?us-ascii?Q?e5Hsw+HVoGUxpB+awfPp5l7myoNZn6hCq257iBh7f9PvLUVyLcwl6MS0B1lG?= =?us-ascii?Q?WU78jBoE0DvI2nvOgKyEoiJUgaczQnwe69QXEte/UJzMaxddlJiUbxzEAT9s?= =?us-ascii?Q?aDkMmbsFK3GhJ2JmQKC1/Gsu9pX2WXHYzRHVXMRMwNz2F738W7nY7DoBkXuq?= =?us-ascii?Q?cQnlTWvqYS3hEI4MGEqHuvhaxugQGbRmzvoor2AwAs3w/R2BRu1kBMDiRSSI?= =?us-ascii?Q?9rVF80uaizhWwDbuFJca/PQ8E6hsxMfUP3E+pQZI19hzgz/DVJ8ut8vxMC/M?= =?us-ascii?Q?u5Zz6jRkTuxUjDZNcW8rpyd2OdOpQGFl3OZYxf0r2C3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RaL7ks+EcAJ9Ek2G/BpzBEH6qnABHv3mTWu2p+40aYKYSmYGVKQv6BcG+A?= =?us-ascii?Q?CYwHnxwGN7CUR5HgNVo=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(82310400026)(36860700013)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:58:59.2119 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 470e8ee0-ce11-4921-465d-08de078fd07f 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6879 Content-Type: text/plain; charset="utf-8" Introduce IOMMU_HWPT_DATA_AMD_GUEST data type for IOMMU guest page table, which is used for stage-1 in nested translation. The data structure contains information necessary for setting up the AMD HW-vIOMMU support. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit --- include/uapi/linux/iommufd.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index efb52709c0a2..d111ee1dc572 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -455,16 +455,27 @@ struct iommu_hwpt_arm_smmuv3 { __aligned_le64 ste[2]; }; =20 +/** + * struct iommu_hwpt_amd_guest - AMD IOMMU guest I/O page table data + * (IOMMU_HWPT_DATA_AMD_GUEST) + * @dte: Guest Device Table Entry (DTE) + */ +struct iommu_hwpt_amd_guest { + __aligned_u64 dte[4]; +}; + /** * enum iommu_hwpt_data_type - IOMMU HWPT Data Type * @IOMMU_HWPT_DATA_NONE: no data * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table + * @IOMMU_HWPT_DATA_AMD_GUEST: AMD IOMMU guest page table */ enum iommu_hwpt_data_type { IOMMU_HWPT_DATA_NONE =3D 0, IOMMU_HWPT_DATA_VTD_S1 =3D 1, IOMMU_HWPT_DATA_ARM_SMMUV3 =3D 2, + IOMMU_HWPT_DATA_AMD_GUEST =3D 3, }; =20 /** --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011031.outbound.protection.outlook.com [52.101.52.31]) (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 C62D128B4F0 for ; Thu, 9 Oct 2025 23:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.31 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054352; cv=fail; b=oJfXIsfiSVi1/7ELX7LasXcA5ignL/XxQ8JAHBf0DwV7W3tsqoYx9ylSz1AdTu4VsJdsxZX06Wl16rXVIHq7A8cIeUvoGX+m6IcuUnvhisdne3WYCpkkQbi90gzgyRjpV8oHCV8YteLGvqjzMFlYnBrojsg+g2lTm2m5iNdY96c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054352; c=relaxed/simple; bh=85LSuVESoVvXqgYw+uwK/Q6KK8sQFgdHnRB4FxHa9R4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tTaS5FldVkzG5MtC5ucU+VjHrZKb6+C98SOcUKB8wtCsflSBo/Str8DXR9l/ql8TEttEuCUmef1zUzeuwcez/EnVODTiTSujrkSGXdN9rCBvTFEluPYvoIDAXYasOJFMS7q5mb4TsOEF1w/mjM0uADUhlPT1gndBaJ5QP6542h4= 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=Gvjmt9bL; arc=fail smtp.client-ip=52.101.52.31 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="Gvjmt9bL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j+1GiuD6fiwhjMT/q0cHHLQkLBvPRDvRXjAPUyVvkdwYLyrZjXR8pOCreg7Km+HlI0cPMciMYInVbiLdG84M8RB1Nkj8Fy+kw2b/T9sD0BlB+JFeS6EhmPo5AfT2Xi2lvV+JD8bQJac1VR1BfKoUJs6FUgoNdorNqIpN11m2ynaR8pCBulWvY2IRO/55yrzuHAkQaND38XaatrE7xTnh7xpgmQikKKumCkGd0KKvnr0wCWMmm4rQzt/OhpLDdBvwSUeNdYXiKfqMdfDCPlZIQir8dbuyespqW+zhyos1kLUAiHbh04u+0hJEu5YKmoOejxCZVrqCo19epc26siMCVA== 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=njQFmJ3FvbhKuEhnbs9S+Ncl1ubyom44WTRQmyzozWk=; b=M6N5Pn0P3fGKBwW0T1wrG1CFRpkKCJr2XQeQa/XvWmTGo1YeNt+D+2vPtl6N0mWoFuyn0xx+LoX6vxfLXeEfncMYeKXRzxd0QvoGGGnS22+2EgfDARWisnsw+awDyI3NoGmPnlaq/WntnmWhGmr2aXrOG6RK51e/mUCrgsb5fpRODopOuAbSOP19M6A3r66Qv1qgPB/o5pI+7WoKX7z4lCp0eMEeymO9QIQB7HoiCy+DQ2ALGXRGZMby51FEkB6rhRKoYaYX4+gOaubjK8koVO+PqQvvYE4sF5ks0T5w39mZA3o2YOQclA5lOyloGv2Vrym+rZxuedo6IjWlCGGNjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=njQFmJ3FvbhKuEhnbs9S+Ncl1ubyom44WTRQmyzozWk=; b=Gvjmt9bLDa6hiVz2ZWNvKFwaK5LnUyN7ZEujXs2VCJSqBeQoXr6BfbpjCSWz9pfjjwaEB6dzjeL8RVnr9WFpCbVrAfxstYXLYpZKfRkMsLVPg7pHa8nOnP43lDCiOENjVnjcDLZcGTvQdVYxpKEq+ZkOh+K6PzzEPklSLqO7JLw= Received: from CH2PR03CA0007.namprd03.prod.outlook.com (2603:10b6:610:59::17) by MN2PR12MB4158.namprd12.prod.outlook.com (2603:10b6:208:15f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9; Thu, 9 Oct 2025 23:59:04 +0000 Received: from DS3PEPF000099DB.namprd04.prod.outlook.com (2603:10b6:610:59:cafe::48) by CH2PR03CA0007.outlook.office365.com (2603:10b6:610:59::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9182.20 via Frontend Transport; Thu, 9 Oct 2025 23:59:04 +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 DS3PEPF000099DB.mail.protection.outlook.com (10.167.17.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:59:04 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:58:58 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 09/15] iommu/amd: Always enable GCR3TRPMode when supported. Date: Thu, 9 Oct 2025 23:57:49 +0000 Message-ID: <20251009235755.4497-10-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DB:EE_|MN2PR12MB4158:EE_ X-MS-Office365-Filtering-Correlation-Id: 10ffeeb1-6eb4-4dbe-afa3-08de078fd39a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?c/4lRpQft1XrvNj8I82Owj8YvymBP9GNKEumYWnipN67lD7hEYdFejA7X/02?= =?us-ascii?Q?ZhH7WhyPc2YUy05wzkl6Bx+SHyjzu1K9Gibb6Az6Ov4hDCBnc2SepLGHgCaT?= =?us-ascii?Q?+n93PqzJWRRdYA57cF7w71YqRblkjHOFpgBdkAG+jrtutz44diSr9Vq5pPOE?= =?us-ascii?Q?3CNWjDyjK2GgZ6sAcknz+xaITjSmdagu4TT0DnCf/tZFuUQ2rc8N2cwbuuyS?= =?us-ascii?Q?HwoqO368fP3eGnApP50hNeQDlS1hq10R24rAFsDIJKc2odP3cYUz5ojJ5tVM?= =?us-ascii?Q?NfXBCYkqg3a+1FzsTdW0ysY8TtUBQpfJPB+Lve4Y4iSMDjVJ1XwRVcoYcV8q?= =?us-ascii?Q?ms7oaErJpigXQC0En8uKMf+0C+32zSq3aH73B9TmilK/EH6cSYMd76TJLg9X?= =?us-ascii?Q?Xw+c634slTTdSALlCNxV+7xIczl3TTShd+NA4lnjnTdO2B5Tt6+Y6iadCo+k?= =?us-ascii?Q?O/P9owWggrZ6IRuXg1SrI1Tn/5sSFpD8SejCD6GqlGBLFyeKup3w8lwYUNI2?= =?us-ascii?Q?ryTibYQddT7IEoo+vdLmE14EC41J5eDaDA6J36KWA+Uqbov5iqZ9WFGxhd7Q?= =?us-ascii?Q?+8jy23D5on8u+LpK2DN7vojWkSFlW+XHH65fCLgedK6/otC413GZ7wQaQLMV?= =?us-ascii?Q?7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gwhSzI2zige1djejP4b1hhfJxL?= =?us-ascii?Q?fhb+m9nS2VI429TRAsQ=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:59:04.4232 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 10ffeeb1-6eb4-4dbe-afa3-08de078fd39a 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: DS3PEPF000099DB.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4158 Content-Type: text/plain; charset="utf-8" The GCR3TRPMode feature allows the DTE[GCR3TRP] field to be configured with GPA (instead of SPA). This simplifies the implementation, and is a pre-requisite for nested translation support. Therefore, always enable this feature if available. Signed-off-by: Suravee Suthikulpanit Reviewed-by: Jason Gunthorpe --- drivers/iommu/amd/amd_iommu_types.h | 1 + drivers/iommu/amd/init.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index 556f1df32d53..9226edd8af69 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -185,6 +185,7 @@ #define CONTROL_EPH_EN 45 #define CONTROL_XT_EN 50 #define CONTROL_INTCAPXT_EN 51 +#define CONTROL_GCR3TRPMODE 58 #define CONTROL_IRTCACHEDIS 59 #define CONTROL_SNPAVIC_EN 61 =20 diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index f2991c11867c..c45a4bd89569 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1122,6 +1122,9 @@ static void iommu_enable_gt(struct amd_iommu *iommu) return; =20 iommu_feature_enable(iommu, CONTROL_GT_EN); + + if (check_feature2(FEATURE_GCR3TRPMODE)) + iommu_feature_enable(iommu, CONTROL_GCR3TRPMODE); } =20 /* sets a specific bit in the device table entry. */ --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011023.outbound.protection.outlook.com [40.107.208.23]) (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 49A7C28AAE0 for ; Thu, 9 Oct 2025 23:59:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.23 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054373; cv=fail; b=QOWRVx8OVb5+H5SLOxXtQQwvZFlCdNgoTsnOe6C6EN8nbHb7XPX9ojtQyBShdPGkMfI+3qB8P6oVsW9GwLpxjj2o5P/MMw7oDGl7/cXNZCPdDUaCHeL0huTy2NeCZChaRVSdqgKaVGoKdFNcWnYK481g3QNBhChKn2s39H2vW/I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054373; c=relaxed/simple; bh=4BaWPeMqgnrboJXHz75SJEvgGcoRVv1pdCQWbEeXu5U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D1emA1UVPWWCLad3N6RK9sYiDK/KPaxj1l2YLDNXjhXDdGZ/ihKF+O98abFLh6mEbAjgXzn67aEcPPl+t6cj/UYEP2lWyWSsHxAqd1nKad2TOOMwuvXTALJUC2+7/mBVadGHnIfxL5hS6hSre8wd4NgZjjQ9fUBvbGxsXhU/foA= 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=U2hR4HT3; arc=fail smtp.client-ip=40.107.208.23 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="U2hR4HT3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QewfmUNL1sdvnyiaxA2S3LKH8vSCKl7iSrQ8n5dkm+I2X3bUXP08LOjuNHBFa4h6KqPJVTgdScqWLHIwaldIR34vZyqXNPL83LWr7KOrhCzv1Vg5Kt2SBfvvTNhZ+ZcQ8hPpWYFn+BrRcVQclgbMSZ83t57VUtD4bkmi+4JHRkmdl7mA4rSfy2Qf8bBt3QRQQQXf9M6RADrWrW9s+sfFYBZOe/bDsCwuqKezz2Rly2+sBF2QlUbLtr+IDiWaekDjJcoENIyAEzfd6OaK9Ltnrar8eT36pi782Wt3kxNvlEian4YX9X0N7i8MU0dUCiMl7KyeljOsCmoq4Chf4Hw1lQ== 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=NrNdX/D052zAX+/C9eAE0B/flWKj7KYsRf1sCfqpkrI=; b=GAQ/+1t00KTh1yCTLOHf17XN7WEpo98VGwJPpkzQy9L8cmjJa4KSB8CHItHYZURwTTzIlATPUbv1lE98BJo4tien+TiDYgYFtjfa1sCnkYDgfyV3jo8GyOVK8mND4Cdn+YZ+OfKWjIsM7IjeLA8IRKoz6gihWGuCZ3qNJ12n57nA/I+5FSSeY0ummmCqXqwZjZs+jCXD7vN638xPaqHhbAS4JGk4yUfGLA5bRQcY2LyokJomVkMTti/I5d0svR9/K8MAnLzrvktCynEGGMjnAtgutgeX5rVmvoT2/X5LkddypJ6MhPwJsBipI37aQlRxb8nTsBxS680K8vhozq2Z0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=NrNdX/D052zAX+/C9eAE0B/flWKj7KYsRf1sCfqpkrI=; b=U2hR4HT3sqUX9ADOGOWxhqJTMPZyRe3GIB7xQQPfdLHsww0z+sTZAhGuEfkSTnrlwxIRcayyhyn9dmZ2QnFum8X+SEjOS0DgEp7sjUkPFp2udmMd18du5z/yavl3xQbYg5urrZyZH6/BX2GOufJqe4wPHUr3DdUcWZrxvWU+GnI= Received: from CH5P220CA0017.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::8) by DS7PR12MB5765.namprd12.prod.outlook.com (2603:10b6:8:74::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9; Thu, 9 Oct 2025 23:59:26 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::7d) by CH5P220CA0017.outlook.office365.com (2603:10b6:610:1ef::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:59:26 +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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:59:26 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:59:04 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 10/15] iommu/amd: Add support for nest parent domain allocation Date: Thu, 9 Oct 2025 23:57:50 +0000 Message-ID: <20251009235755.4497-11-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|DS7PR12MB5765:EE_ X-MS-Office365-Filtering-Correlation-Id: dcbf6991-f002-4480-8dc8-08de078fe096 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?wfk54WA13u0Uzfd8na8GgDewu9cU90/b2KkTvXj6iaBo7x7rZJmUE8uYqzDX?= =?us-ascii?Q?JGmTznoUTRvVuZwVg9nbWW1CgG0JwsaaPwHoAgQ2EzZpZA8uCq7wocf4Qfth?= =?us-ascii?Q?9hpaoPOGF+wXT13xguFutG5JMTW2/1aCStdXrtcoC+VkHjtwoCLmb3trV+/B?= =?us-ascii?Q?lRxpEvVKkXqIYvkpC9ubNRnaDmxOifcWwrRgSVrs4A0RGsvblyPmX4Caff5n?= =?us-ascii?Q?5pRZOkT0kBnCp68AHE+b0SfozP31W+b6LQdrgWiloaBDKEXx9rk+S2RMZW6D?= =?us-ascii?Q?U2MA46dXuVJbXSJLZFlrNOoRjMGuKdqgnTI2/9eb/W6O0eG4/TSrODHi5BVq?= =?us-ascii?Q?f6aYUII+mMZdOfjGfzmlA/FzAoThRp0FFGvodYaK+fjDozvUHYdotOmVzi6m?= =?us-ascii?Q?cMH3ghOvJVPlCisZ/SJPqDJFH3j5xDgTXSevlSPTcLX1vBfqEJbcT8+jLvBu?= =?us-ascii?Q?d4dhtF+vTJiSYFAjInIDX55yqGFEAsFf4vWr5Wfa5Ol+w+Y/8YQikyaKhgz6?= =?us-ascii?Q?K+ZOjRgDZDuEDRb+CvfeuWVVgaiF18U0t4bOGwwwszurDBwEc0tX9s8cN+gi?= =?us-ascii?Q?pe4W6bCRFs1vcJPPIgH4HlF0bQz3Fod3bwkzLPRdXQuW1Q50GTm6BcEcXONY?= =?us-ascii?Q?2JlMD+XBQYtLM7chgMr6GiZQo+IXP/Xo1vgSyJPL+N7y1AEAV8cXh187F/qD?= =?us-ascii?Q?cVuUUQWaSUB4u/k7XSnw7e1RorQxQZVhQTZUMMufQ9TyeoltSYmNwE3ZB46w?= =?us-ascii?Q?LmI7Asiqcbk2qA8AcGvyxNmMdiKD8eG8zpDNQCJ2FGjEDijvg+Pu3pgXofdO?= =?us-ascii?Q?F3wOx9fxHo7g8lJC7tzEgkhLBKsUKLYLVgx0GimL+2EJpf83FRok6RnKTWqJ?= =?us-ascii?Q?PG/tcSz0bnCGEn2epBwDUwnzicOQSsIWe+/osXfgI46WfCwEwGy8OVupIrjU?= =?us-ascii?Q?rHNGLUUdgGYHukU6X9c0prb8nJeSO6OorBaWLBf4MtjYr9ICqjbwx/MhuLgZ?= =?us-ascii?Q?VXTD/xDgSqUeqKxS27ajndmFcHXk1gltz9FTMgjTLU/EderRVdokXS+Bh+jP?= =?us-ascii?Q?jes7rwdetZe8PWmmURqtniPc1bRpo/Us8EpCqBBJnbJLxCxaEOzra+o2aJi2?= =?us-ascii?Q?ePoC4qGmdeTwqZw3byq2w4zexJTJV746s28b0yiA7gcmOC7Sz79FcigNDClv?= =?us-ascii?Q?mK9Ek3KmT4aZNQ8DCT7TTNTNEsjWInYs/mdR5p7WmIJZrBjJaFQckqK0/Dy+?= =?us-ascii?Q?/NuRh7kdh/63f9OlMxiX9Yrwc2SrGsP71n4Y1vvFjduymovvXi5mPof5nWTb?= =?us-ascii?Q?dTxEWj/yO6Gl9qFQX4sLaku7GzMgvIiovK0+bjg6S1jmwyznKHmxeMd4Kess?= =?us-ascii?Q?LOUnSTM6uHKTChBxLjcc1wKqRwxla9swMcOoPiEbIoRIf8EXPvxLiAbigN6R?= =?us-ascii?Q?Zarmt2GSRr550PUPiuDUwPS1fKCDx4buRYOM5LIITTSGyhbSrKQ0k8XEVmGu?= =?us-ascii?Q?5PDSQ5zOLkh5lKzIt0pdz2WMPq42UyeJPma5PtfjL/G7acZPcQPIUWMY8X0R?= =?us-ascii?Q?9cCIM2g63eSYs6BQLjE=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:59:26.2067 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dcbf6991-f002-4480-8dc8-08de078fe096 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5765 Content-Type: text/plain; charset="utf-8" To support nested translation, the nest parent domain is allocated with IOMMU_HWPT_ALLOC_NEST_PARENT flag, and stores information of the v1 page table for stage 2 (i.e. GPA->SPA). Also, only support nest parent domain on AMD system, which can support the Guest CR3 Table (GCR3TRPMode) feature. This feature is required in order to program DTE[GCR3 Table Root Pointer] with the GPA. Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit Reviewed-by: Jason Gunthorpe --- drivers/iommu/amd/amd_iommu_types.h | 1 + drivers/iommu/amd/iommu.c | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index 9226edd8af69..c34604cf1811 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -107,6 +107,7 @@ =20 =20 /* Extended Feature 2 Bits */ +#define FEATURE_GCR3TRPMODE BIT_ULL(3) #define FEATURE_SNPAVICSUP GENMASK_ULL(7, 5) #define FEATURE_SNPAVICSUP_GAM(x) \ (FIELD_GET(FEATURE_SNPAVICSUP, x) =3D=3D 0x1) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index e0bfcda678a8..e489e360bb77 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2584,6 +2584,14 @@ do_iommu_domain_alloc(struct device *dev, u32 flags, return &domain->domain; } =20 +static inline bool is_nest_parent_supported(u32 flags) +{ + /* Only allow nest parent when these features are supported */ + return check_feature(FEATURE_GT) && + check_feature(FEATURE_GIOSUP) && + check_feature2(FEATURE_GCR3TRPMODE); +} + static struct iommu_domain * amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags, const struct iommu_user_data *user_data) @@ -2591,16 +2599,28 @@ amd_iommu_domain_alloc_paging_flags(struct device *= dev, u32 flags, { struct amd_iommu *iommu =3D get_amd_iommu_from_dev(dev); const u32 supported_flags =3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING | - IOMMU_HWPT_ALLOC_PASID; + IOMMU_HWPT_ALLOC_PASID | + IOMMU_HWPT_ALLOC_NEST_PARENT; =20 if ((flags & ~supported_flags) || user_data) return ERR_PTR(-EOPNOTSUPP); =20 switch (flags & supported_flags) { case IOMMU_HWPT_ALLOC_DIRTY_TRACKING: - /* Allocate domain with v1 page table for dirty tracking */ - if (!amd_iommu_hd_support(iommu)) + case IOMMU_HWPT_ALLOC_NEST_PARENT: + case IOMMU_HWPT_ALLOC_DIRTY_TRACKING | IOMMU_HWPT_ALLOC_NEST_PARENT: + /* + * Allocate domain with v1 page table for dirty tracking + * and/or Nest parent. + */ + if ((flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING) && + !amd_iommu_hd_support(iommu)) + break; + + if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && + !is_nest_parent_supported(flags)) break; + return do_iommu_domain_alloc(dev, flags, PD_MODE_V1); case IOMMU_HWPT_ALLOC_PASID: /* Allocate domain with v2 page table if IOMMU supports PASID. */ --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012012.outbound.protection.outlook.com [40.107.200.12]) (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 0DC64299ABF for ; Thu, 9 Oct 2025 23:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.200.12 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054376; cv=fail; b=HFvK5LnrPeMEHg3TyFqE5qsaT6TvLnrSq71dnQPFPAmgcMIIecsIcCSymBkeJuzxnARIz2JNubPPKdpK2QHajNpGgCbOWJMd+C1WvJrqg4/rp2TWleUxQT1IzkHSjMrBeLh5Q5d9730OoZxJAxNqSMhvrmcFv5VmODdPuj9mqvg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054376; c=relaxed/simple; bh=wbLO+eea67yOh+nlVBwgvQaM4ULGrkcMBT7dLEiQYTo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qdnV3JfqRftO71x1GX3mrgp5G7rlPtVQ2c4yPaaZes5pRlZHuOl+qJubHTqT34UvcuQXvJst70jfPJvVjI4qtUUj3pucHBtaKD/n0TyPVqOQsSC9NBUjoMHvi4T9f9JzTjxyk82F8TERUfqYra62muBZVUfMR7tJkphvX0BQvO8= 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=XHhfoHGQ; arc=fail smtp.client-ip=40.107.200.12 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="XHhfoHGQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=N1Hm0A2n9geWfvKRKT/rOj6Gvzsh7WqyuKi6xJx/MEwM7dlSnwpKAmeC4MHG2jkFABQ90pELxeCn22lqzEDm3WzWgiwF26jRP11OFRxc5jONxWlVr1INXlirIvCN9sGCtvX+WYmXy+LkpVp82l0tXlweVlnWOQ+adPRCT6d4FqNClrjoYANJbeFxae4hsUF7t31v+CTbwgzvknfDNbj3K5UpJtkza+3UXu8pMU0CxPCxPqBU1r6RhlYmIS7pD9h9ucLC5377OtqhiIbi/p48KilBSP2pYgXycmWp2qkM+Y8ffiwX0jITmOP8wIfRB2Amt0NGm2P/bFGnk3uJEINutQ== 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=E340rlk9aybsfWue2gzYVU56FfgO9MBJXsVwivvkl0E=; b=x+8/ffYRb2Cs7m1DiLk7W0ZF/Oa4rysQMppIkqZUwH42v9vuQUzip62Xhis/tzM6OWQ8tk2rVG5y9UQ3kghhOTA8Zf4h5sqyN4QalGk8SU1UzMcqdTVPDHeX4vXSHlB7Zrex6c8gTCluAEExrpkVA1Ribc0NPq3g9iRpzjH9jPEWN+E0GwFtB8HKeIPGBdSvdccTduOiDszUs1KakiGP9Gduzcl9zgTHQ0ov4rPkt4yupr2ZCE786TLGxHOkJeVv1GQtiMjgpFKmyjRwgcvnRgTlIvA6K0NC0XQkygZC5+W84ylzXOD4fOGc6E2Xte2466eRwyF9S/owc+Hbn+D4ig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=E340rlk9aybsfWue2gzYVU56FfgO9MBJXsVwivvkl0E=; b=XHhfoHGQfrCuvi2uyVXnfUKeWmg54K7upow30grkGUddRT0q8xVL5SMrITNVEkthR+A9E3SW+XweHLXeOu1/2GzwNk1jiv7NpoIm/Ep/Vg046QaMHfsuJNkXnM0eAFG9jJ7mTY1u1HGH4hOp8S5VVBWgHvqwhHwvjXSPfG8cNOI= Received: from CH5P220CA0003.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::21) by PH0PR12MB8798.namprd12.prod.outlook.com (2603:10b6:510:28d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9; Thu, 9 Oct 2025 23:59:28 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::de) by CH5P220CA0003.outlook.office365.com (2603:10b6:610:1ef::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:59:25 +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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:59:28 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:59:09 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 11/15] iommu/amd: Add support for nested domain allocation Date: Thu, 9 Oct 2025 23:57:51 +0000 Message-ID: <20251009235755.4497-12-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|PH0PR12MB8798:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c83a3d8-4976-4c5b-44d9-08de078fe1e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Sww/S8EUPRFSVB40VyElK/D8gqUjBMTqbIC+SepgjAFNar8HF7LhV5J/mRn3?= =?us-ascii?Q?OWnzm+NPKfptirVVtpChTzvI7Hq9nvMbFxP7rltaMCQtXHiVdqutV7gqSeM4?= =?us-ascii?Q?uGmRn4C2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UhZLBQTuZbZzy?= =?us-ascii?Q?A1DiX8cOmE6JTSgjoyM6d7GxOgEaG0Oo7ttuDUtHat1Y/PJFBaWxh9/Y/utW?= =?us-ascii?Q?VY70VkPZRfIN2SeUGQ1GhlTDEmyLEcKeUws4tm0xe7XyAU4TAmpve5zC9AbZ?= =?us-ascii?Q?80dNgSoCChiK1Gy+MokkMCyRbvZ6F2bprm8kcL73ZD/YnBsAffBmtKzesVsn?= =?us-ascii?Q?ZPru8o+em48ZcIXFsRscc9mnysUj7vXAs1WoYx48Zu9096cINRbBmqMzcy7R?= =?us-ascii?Q?AlJfA+QfN/SfosVkd6mK6qawwz+xt9dhLMcRfIdOPIxL420NowLFury5TDck?= =?us-ascii?Q?jWykbmZLTrL9gH1C1oj6qObKLWv9fIag1EZuw8VQUN6lMs2qiyyCtFkgMEgp?= =?us-ascii?Q?KqYtY0Tm7jeGLwklgtdgeNYiHHTXFudcuarTY9s0KGft4XRhPAl76YV4ZKn5?= =?us-ascii?Q?ToNtlrMBFeuh3LGWsrA+ORcZFzh5qJqysJ5rDpNBy1ks3IaBEQGC5FME79A+?= =?us-ascii?Q?DaxJ8fA/mFssejTPJ+wrrt+ZBZ3vqdP0tytVgBVJ9mL0dQfir+ZnxvkrNu9M?= =?us-ascii?Q?baQPhhvYmW0y6yGmz+A=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:59:28.3931 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c83a3d8-4976-4c5b-44d9-08de078fe1e4 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8798 Content-Type: text/plain; charset="utf-8" The nested domain is allocated with IOMMU_DOMAIN_NESTED type to store stage-1 translation (i.e. GVA->GPA). This includes the GCR3 root pointer table along with guest page tables. The struct iommu_hwpt_amd_guest contains this information, and is passed from user-space as a parameter of the struct iommu_ops.domain_alloc_nested(). Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit Reviewed-by: Jason Gunthorpe --- drivers/iommu/amd/Makefile | 2 +- drivers/iommu/amd/amd_iommu.h | 4 ++ drivers/iommu/amd/amd_iommu_types.h | 31 +++++++---- drivers/iommu/amd/nested.c | 84 +++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 drivers/iommu/amd/nested.c diff --git a/drivers/iommu/amd/Makefile b/drivers/iommu/amd/Makefile index 5ae46d99a45b..afa12ca2110e 100644 --- a/drivers/iommu/amd/Makefile +++ b/drivers/iommu/amd/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y +=3D iommu.o init.o quirks.o io_pgtable.o io_pgtable_v2.o ppr.o pasi= d.o -obj-$(CONFIG_AMD_IOMMU_IOMMUFD) +=3D iommufd.o +obj-$(CONFIG_AMD_IOMMU_IOMMUFD) +=3D iommufd.o nested.o obj-$(CONFIG_AMD_IOMMU_DEBUGFS) +=3D debugfs.o diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index d533bb8851ea..3730d8bbe6dc 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -202,4 +202,8 @@ amd_iommu_make_clear_dte(struct iommu_dev_data *dev_dat= a, struct dev_table_entry new->data128[1] =3D 0; } =20 +/* NESTED */ +struct iommu_domain * +amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags, + const struct iommu_user_data *user_data); #endif /* AMD_IOMMU_H */ diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index c34604cf1811..9374e6f7a19d 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -20,6 +20,8 @@ #include #include =20 +#include + /* * Maximum number of IOMMUs supported */ @@ -586,6 +588,25 @@ struct pdom_iommu_info { u32 refcnt; /* Count of attached dev/pasid per domain/IOMMU */ }; =20 +/* + * Structure defining one entry in the device table + */ +struct dev_table_entry { + union { + u64 data[4]; + u128 data128[2]; + }; +}; + +/* + * Nested domain is specifically used for nested translation + */ +struct nested_domain { + struct iommu_domain domain; /* generic domain handle used by iommu core c= ode */ + u16 id; /* the domain id written to the device table = */ + struct iommu_hwpt_amd_guest gdte; /* Guest vIOMMU DTE */ +}; + /* * This structure contains generic data for IOMMU protection domains * independent of their use. @@ -895,16 +916,6 @@ extern struct list_head amd_iommu_pci_seg_list; */ extern struct list_head amd_iommu_list; =20 -/* - * Structure defining one entry in the device table - */ -struct dev_table_entry { - union { - u64 data[4]; - u128 data128[2]; - }; -}; - /* * Structure defining one entry in the command buffer */ diff --git a/drivers/iommu/amd/nested.c b/drivers/iommu/amd/nested.c new file mode 100644 index 000000000000..0ab5d65ec283 --- /dev/null +++ b/drivers/iommu/amd/nested.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#define dev_fmt(fmt) "AMD-Vi: " fmt + +#include +#include + +#include "amd_iommu.h" + +static const struct iommu_domain_ops nested_domain_ops; + +static inline struct nested_domain *to_ndomain(struct iommu_domain *dom) +{ + return container_of(dom, struct nested_domain, domain); +} + +/* + * This function is assigned to struct iommufd_viommu_ops.alloc_domain_nes= ted() + * during the call to struct iommu_ops.viommu_init(). + */ +struct iommu_domain * +amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags, + const struct iommu_user_data *user_data) +{ + int ret; + struct iommu_hwpt_amd_guest gdte; + struct nested_domain *ndom; + + if (user_data->type !=3D IOMMU_HWPT_DATA_AMD_GUEST) + return ERR_PTR(-EOPNOTSUPP); + + ret =3D iommu_copy_struct_from_user(&gdte, user_data, + IOMMU_HWPT_DATA_AMD_GUEST, + dte); + if (ret) + return ERR_PTR(ret); + + ndom =3D kzalloc(sizeof(*ndom), GFP_KERNEL); + if (!ndom) + return ERR_PTR(-ENOMEM); + + ndom->domain.ops =3D &nested_domain_ops; + ndom->domain.type =3D IOMMU_DOMAIN_NESTED; + memcpy(&ndom->gdte, &gdte, sizeof(gdte)); + + /* + * Normally, when a guest has multiple pass-through devices, + * the IOMMU driver setup DTEs with the same stage-2 table and + * use the same host domain ID (hDomId). In case of nested translation, + * if the guest setup different stage-1 tables with same PASID, + * IOMMU would use the same TLB tag. This will results in TLB + * aliasing issue. + * + * Workaround the issue by allocating per-device hDomID for nested + * domain (i.e. ndom->id). This require per-device IOMMU TLB invalidation + * with corresponded hDomId on the host side when updating stage-2 table. + */ + ndom->id =3D amd_iommu_pdom_id_alloc(); + if (ndom->id <=3D 0) { + ret =3D -ENOSPC; + goto out_err; + } + + return &ndom->domain; +out_err: + kfree(ndom); + return ERR_PTR(ret); +} + +static void nested_domain_free(struct iommu_domain *dom) +{ + struct nested_domain *ndom =3D to_ndomain(dom); + + amd_iommu_pdom_id_free(ndom->id); + kfree(ndom); +} + +static const struct iommu_domain_ops nested_domain_ops =3D { + .free =3D nested_domain_free, +}; + --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011033.outbound.protection.outlook.com [40.93.194.33]) (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 9A40E29AAF8 for ; Thu, 9 Oct 2025 23:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.33 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054378; cv=fail; b=qfngTA8JK5sGtuPCgHamLCEMgUFzBnJHDeWmp5uW5QxtOeQqqqf+tEFVHDrbRDKFdehPScHbX4aY7D/CCJJDrUlvrLa5xJdkFFtQEsCr5SyH7Ul+JQ7PK0/NLoAKQgO9RqdrQ7ARtG2HsfhDJWXhrY6Vu+0A3nGv0WQzRZQ+27E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054378; c=relaxed/simple; bh=4KcDhi7rRGz1rTw4/Jdwp2bPAaCKtXsOh7z2zPLnwG0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hKmYa1AdyNnSeoBNHVlVQYrCIiaST+BK+tUqP69Wyf7YkZ1mRiXcqtRQYuxgF6EiWs/TKXGMGNppa7T7G3j7EMHOu6qLfNQ97OY+Ov3zOV7m19dv6OiavcwwUX0u0p8bxGywMG5UhRKZKzL7r/JNrk7JECSX++hJj8v+gRilEEY= 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=G/2CYniT; arc=fail smtp.client-ip=40.93.194.33 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="G/2CYniT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=B5jZe2TXvgh20P31h+HjojQKFdcWzrr+r2FI0qyRkF2LiLRdSU401SEvMMz29oNFacRBGKhU5tScksec/qzB9ELbu9Pflre3sVrQGUe7SC74HqoDvWbrxUnRS3jv9ZVvvA4agQOZ4dQ2BaEyaIqLQVqVFQRm9H2DITHghdzofZljghfIvBR9jBkqWemru7zBTDo3An0jezOXyMHn+gwtnp6SwvMZoPqLJriaMwZrvbmpkKbiqgkN91zyMLD/FNu8ORRkvYPUNiu53FpQI1EKS2dlq/VgQGO0sdszs1rGjUFW3er+K7CJyTAcBsA7AVe5rAoSv+4aQaiNayZlbtQZ6g== 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=7+63goECuo5ejyUOG2zBZiza/vDlQE0qecXU0Iwf1cw=; b=hzPXD9itDbD0ElBooAtWfHUQH8bTRjZy6p9uatp24eroHwopUskx2yicuNyNCcT7TIwvXdKj1tmTYGgivt7pX4OksX9WbUoJOzIgWEZDSFJQVapPH5cbF30yGlyUwM676e7VUh+NbBwes+V1CZNW+OLjqfouRq8o0dquGzDISOf5IdkjxT81U3CrOnnhpG0tzaTOthxHfobWIHZHAZ5tTfqCDzK0v89P5Srw6IhZmPTaccmHI45s4vbGdz5xCG+3uZb0H4y3DVydXh7zLKotLKnlECopjmrHzIijRAzoEc7OmtbdAfb5tlkOlrPf9C29ZwVg4CwdlotpXHiVRmKpAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=7+63goECuo5ejyUOG2zBZiza/vDlQE0qecXU0Iwf1cw=; b=G/2CYniTupo4AENZDNHbkDkPCCBMiSMpJqyguNIZO2QhUzBHdUpthHU7A7foy6BwnDSf1j2m+hOl5xIIkX3ZCo+lL5uKm7RSuQoF8oEiDpTgr7yKZC7o4JeyPZG4xv1bpoU0krB9Vi1tNS4wTm2pAN7eAb2WKvlFRwpxEVraIMQ= Received: from CH5P220CA0020.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::18) by BL1PR12MB5874.namprd12.prod.outlook.com (2603:10b6:208:396::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.20; Thu, 9 Oct 2025 23:59:30 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::59) by CH5P220CA0020.outlook.office365.com (2603:10b6:610:1ef::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:59: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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:59:29 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:59:15 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 12/15] iommu/amd: Validate guest DTE for nested translation Date: Thu, 9 Oct 2025 23:57:52 +0000 Message-ID: <20251009235755.4497-13-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|BL1PR12MB5874:EE_ X-MS-Office365-Filtering-Correlation-Id: b6334fb6-45f1-41d1-0472-08de078fe2d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|82310400026|36860700013|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?bEu4siqZlGeGzzRIRY5B92x3kgSokjrwFKGYFJQ44qGMx+gEp1ro9FWHMyd3?= =?us-ascii?Q?kf6lUG3tYcU+UMXfMCgkpz4odCzArmWBeSjoDYQLgLGkOpOB+X6Q9ZwWFSCM?= =?us-ascii?Q?hZMtElG8I2RXLHfHnd4r5vBtmawQfB+3T8q/EWeviOl6YvGWFa27Ghhx9rpm?= =?us-ascii?Q?0Io3zdeLLpJ6Irs0Z2+MNSJW7KJ6r8OPZ17tCIKhjnr23rxsiUEqpqDQOQ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qD7F3VMg7lDmekfxvlsHYCQmmHjERffvaFOi4?= =?us-ascii?Q?ySOokeOy1jEmK6u67GN8Bf20i76zuOTN2EHaa3J975LrqjPkMQLV1MNne1+v?= =?us-ascii?Q?FInSnIYz/BLxHvnMJAcZOXsJtRtb0pPcdT7Ynx3M1zYgn07LVVsK4kXtDreU?= =?us-ascii?Q?29gonT71XVCVYhnBZe61Jk5Cufe5Mu3YevWUDERpDrrujE6tS4I+7SFmUK0d?= =?us-ascii?Q?vKxwsEt3RBUNspH9S3beEKCvyuWUcqfPvGdmI+VAPY466+ZhJknF4kuUdhXn?= =?us-ascii?Q?LOz1VmQu++oRlaNDxXD4fvT3lX7R5zcUPBsKwEmEdyJe1DZuQZx2TokhoYF0?= =?us-ascii?Q?eeolFL3aoLCMJnhii15hJpcx9IDVRbAna952gYBWiAlUDf2BwUtUze6A0Jce?= =?us-ascii?Q?DYGPWbX8Raj/ChBZsSHYW7ZDje+qn0qJWq6ecGReCOGk9Rf3O+fRIVReQm7I?= =?us-ascii?Q?Zg0IhdyxuoSWvZwI2Kk=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(82310400026)(36860700013)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:59:29.9971 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6334fb6-45f1-41d1-0472-08de078fe2d9 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5874 Content-Type: text/plain; charset="utf-8" To make sure that configuration for host (v1) and guest (v2) page tables are valid before allocate nested domain. Suggested-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit Reviewed-by: Jason Gunthorpe --- drivers/iommu/amd/amd_iommu_types.h | 2 ++ drivers/iommu/amd/nested.c | 41 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index 9374e6f7a19d..a68b5c2fc0a2 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -418,6 +418,8 @@ #define DTE_FLAG_V BIT_ULL(0) #define DTE_FLAG_TV BIT_ULL(1) #define DTE_FLAG_HAD (3ULL << 7) +#define DTE_MODE_MASK GENMASK_ULL(11, 9) +#define DTE_HOST_TRP GENMASK_ULL(51, 12) #define DTE_FLAG_GIOV BIT_ULL(54) #define DTE_FLAG_GV BIT_ULL(55) #define DTE_GLX GENMASK_ULL(57, 56) diff --git a/drivers/iommu/amd/nested.c b/drivers/iommu/amd/nested.c index 0ab5d65ec283..3307c925d3c1 100644 --- a/drivers/iommu/amd/nested.c +++ b/drivers/iommu/amd/nested.c @@ -17,6 +17,43 @@ static inline struct nested_domain *to_ndomain(struct io= mmu_domain *dom) return container_of(dom, struct nested_domain, domain); } =20 +static int validate_gdte_nested(struct iommu_hwpt_amd_guest *gdte) +{ + u32 gpt_level =3D FIELD_GET(DTE_GPT_LEVEL_MASK, gdte->dte[2]); + + /* Must be zero: Mode, Host-TPR */ + if (FIELD_GET(DTE_MODE_MASK, gdte->dte[0]) !=3D 0 || + FIELD_GET(DTE_HOST_TRP, gdte->dte[0]) !=3D 0) + return -EINVAL; + + /* Must be non-zero: V, GIOV, GV, GCR3 TRP */ + if (FIELD_GET(DTE_FLAG_V, gdte->dte[0]) =3D=3D 0 || + FIELD_GET(DTE_FLAG_GIOV, gdte->dte[0]) =3D=3D 0 || + FIELD_GET(DTE_FLAG_GV, gdte->dte[0]) =3D=3D 0 || + (FIELD_GET(DTE_GCR3_14_12, gdte->dte[0]) =3D=3D 0 && + FIELD_GET(DTE_GCR3_30_15, gdte->dte[1]) =3D=3D 0 && + FIELD_GET(DTE_GCR3_51_31, gdte->dte[1]) =3D=3D 0)) + return -EINVAL; + + /* Valid Guest Paging Mode values are 0 and 1 */ + if (gpt_level !=3D 0 && gpt_level !=3D 1) + return -EINVAL; + + /* GLX =3D 3 is reserved */ + if (FIELD_GET(DTE_GLX, gdte->dte[0]) =3D=3D 3) + return -EINVAL; + + /* + * We need to check host capability before setting + * the Guest Paging Mode + */ + if (gpt_level =3D=3D GUEST_PGTABLE_5_LEVEL && + amd_iommu_gpt_level < PAGE_MODE_5_LEVEL) + return -EOPNOTSUPP; + + return 0; +} + /* * This function is assigned to struct iommufd_viommu_ops.alloc_domain_nes= ted() * during the call to struct iommu_ops.viommu_init(). @@ -38,6 +75,10 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *vio= mmu, u32 flags, if (ret) return ERR_PTR(ret); =20 + ret =3D validate_gdte_nested(&gdte); + if (ret) + return ERR_PTR(ret); + ndom =3D kzalloc(sizeof(*ndom), GFP_KERNEL); if (!ndom) return ERR_PTR(-ENOMEM); --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012068.outbound.protection.outlook.com [52.101.53.68]) (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 586DD29B224 for ; Thu, 9 Oct 2025 23:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.53.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054380; cv=fail; b=bm/7IJ06lIOOan6UMPBNKcX1VXADIQNLwpoc+5jJ29WW6GL9eF5arJlLIFcvIEQkumQCr/j9rcFeSfB8WYMWQmaP1F5sYyWJxoiVSVcB4ctCpJah6p+8x3dokJTK5XtMt5qTqYqb+rbTT3lQ8XokUOBMI1mhP88t2E+v/D7q/Hw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054380; c=relaxed/simple; bh=F8iOORZj24OsOlCstT5pMu3zs5mT0Ls33qdoZ9KCukI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lrfUUFle0WaLZgoij9Ot1YGXyKA8KOBtTyKtt+uUohDlsFrmNOYVr4iEkLtEqI5KkbyTEOYVcAey7LVtculumkBgeHxCALaaO+rycgyNgVAtmLteZjb2VdGtTLA2DjyahwOpYIbFxsF5v4iiKp9Ij2gVNuQ6yuU8GMqx7DF3NtU= 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=SuC/pK52; arc=fail smtp.client-ip=52.101.53.68 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="SuC/pK52" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pII9cO2S0z84rjt0/PYZWE8ipNLzY6JNG7a+SO/GxJm86K9dZZ6QkGaP1T9dXfuhgsVVaRI5Qm5E1bKbQyZqXFN998JCOSf0C2ltGh6keBjD5dPCSBRv8IKKlBEHaCLh6b63qb3/ztBCUgQTD+aDF2bQCF9VdBXAFIpwajYSPkecEyuQt937yGiWjJLuPIdYEezMkwSthSZygBgz0J3lD+rGZ3zoVXYkXU0zOd2FTgQ1ftGuz3xid6HWy9Cu00L1B9naFy+8vVQkOmkQomCZnaaOfrJm8GfgorV7lEvb4d+FWpiXyaaIpoB+PLyAbMMTMgbMxyeu1MSEydDz3M+pqA== 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=ts++y/btPWbJIZgOynvyL5XPULDL+fPjcxLF4XD1CV0=; b=wcpOrZ9k/QowupEmBcsCZSJzEB34kQq6GFj4z4M2vuXNNNXqRSUsUMbv2FqdxVbHuIKiSvPhhkMF/xXaV2NH0hczVrufqw+n+iXBjiOXFtEUIkXMlhwb6wRhfYf5Z+c6vrczOUo6giQgJRTO3R8w4RJTi287UZOTxGCxiKjTjc1IB3PVvNsFpq3hkqRcvLqgKOi8jSWlIpfttB2dUxOIBSTcaDogMGAkRbTvMZsWRcX4T8/P6ePCCz86N1j49tUzSJlgEDtMfxZuKrsCeGKQdWMZq18gcEOVHq14uAzSkZpwLViN2bdl2AcPOIhRlLzL7+R5Wg7kL/NzuTUV42uiPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=ts++y/btPWbJIZgOynvyL5XPULDL+fPjcxLF4XD1CV0=; b=SuC/pK521G2PAXe07jV+CgBPeFGXpz3O/eBLnKk8ddSmIIJWJdlYhNqJLofPF+/b7W1PHj/0dyMknG8lsePMlJoqqjYBd0Q0cWAWjQXAqrIthNEdKPUoBc7tm9GiGZDfF1Gd6ceOTMKYrnP5D4y9E2ON17MusrDGHS9lBCMMq0Y= Received: from CH5P220CA0024.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::23) by CH3PR12MB8306.namprd12.prod.outlook.com (2603:10b6:610:12c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.10; Thu, 9 Oct 2025 23:59:31 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::ae) by CH5P220CA0024.outlook.office365.com (2603:10b6:610:1ef::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:59:31 +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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:59:31 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:59:21 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 13/15] iommu/amd: Refactor persistent DTE bits programming into amd_iommu_make_clear_dte() Date: Thu, 9 Oct 2025 23:57:53 +0000 Message-ID: <20251009235755.4497-14-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|CH3PR12MB8306:EE_ X-MS-Office365-Filtering-Correlation-Id: f92d9d7b-1e4f-4081-bd38-08de078fe3e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|1800799024|82310400026|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?qughkFQBNypUOOyFtoCUod9E2AbVW9uorXlW1gRKRrT+qqpKjiyETpAoa2Yq?= =?us-ascii?Q?8/oKo/Vf/R8W1Yf0CeyI3CinjT7QzhGZjwIWtKbbPGpL77tZWD/qm8Ua2Ao/?= =?us-ascii?Q?pSGBSngGbxGJG+cHu4iYVX958qd7MK1r3BO1qRHAU8jV/VGE/4gdzCjLETW4?= =?us-ascii?Q?pqYXtyXFKxtMfs3lNK/Np79ikm5AiV5tQ6vJXhorzfnG0nB8gEiofxQ1TssT?= =?us-ascii?Q?UtePFpnRBWs7l5CHmEbBbcMy/XU6oz/c4P0HRf1fH9hQOLDai4PNDTrpbtuL?= =?us-ascii?Q?y9v3QM3s8Bm1RKGWtx3n4AXiGk6YcLElCkF88rPk3N8Fss40I2xMWo3Y3uOc?= =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0YXNmK2VYAoowhqOg8rNiUs?= =?us-ascii?Q?pNX0SdDv/WjYwlgCT5J5Eomj1AUFI2CYMCUQpmnnbhZjHOucko/D4jPlmVsm?= =?us-ascii?Q?jcMp0KKnE225gRLZkWUw1BVhMXJHTKqhKDAoaMII5Ejs4ui7cX9O/nXquDsr?= =?us-ascii?Q?Bms+Q//wR79RcaPOYGta2KKw00ICHWzCEWiP0YeDAy0dRxKfMfz0KhaNtu7p?= =?us-ascii?Q?6wRZDq/CgfUhzDrZvyAh/AJT0arm+VY8GzGSQQukBXcxLWowWeg/l/Zmodsv?= =?us-ascii?Q?wL8enbyf/iEAEWXgCnapgSTmARI+iumvN4ukTvLpQ2rfM52dhZfbU1VgdmR1?= =?us-ascii?Q?sZsGQtfaYzMCZxylvN4=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(7416014)(1800799024)(82310400026)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:59:31.7460 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f92d9d7b-1e4f-4081-bd38-08de078fe3e3 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8306 Content-Type: text/plain; charset="utf-8" To help avoid duplicate logic when programing DTE for nested translation. Note that this commit changes behavior of detached and blocking modes, where DTE bit fields for interrupt pass-through (i.e. Lint0, Lint1, NMI, INIT, ExtInt) and System management message could be affected. These DTE bits are specified in the IVRS table for specific devices, and should be persistent. Suggested-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit Reviewed-by: Jason Gunthorpe --- drivers/iommu/amd/amd_iommu.h | 13 +++++++++++++ drivers/iommu/amd/iommu.c | 11 ----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 3730d8bbe6dc..cfb63de7732a 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -197,9 +197,22 @@ void amd_iommu_update_dte256(struct amd_iommu *iommu, static inline void amd_iommu_make_clear_dte(struct iommu_dev_data *dev_data, struct dev_table= _entry *new) { + struct dev_table_entry *initial_dte; + struct amd_iommu *iommu =3D get_amd_iommu_from_dev(dev_data->dev); + /* All existing DTE must have V bit set */ new->data128[0] =3D DTE_FLAG_V; new->data128[1] =3D 0; + + /* + * Restore cached persistent DTE bits, which can be set by information + * in IVRS table. See set_dev_entry_from_acpi(). + */ + initial_dte =3D amd_iommu_get_ivhd_dte_flags(iommu->pci_seg->id, dev_data= ->devid); + if (initial_dte) { + new->data128[0] |=3D initial_dte->data128[0]; + new->data128[1] |=3D initial_dte->data128[1]; + } } =20 /* NESTED */ diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index e489e360bb77..ffb1adfd75c0 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2049,7 +2049,6 @@ static void set_dte_entry(struct amd_iommu *iommu, { u16 domid; u32 old_domid; - struct dev_table_entry *initial_dte; struct dev_table_entry new =3D {}; struct protection_domain *domain =3D dev_data->domain; struct gcr3_tbl_info *gcr3_info =3D &dev_data->gcr3_info; @@ -2090,16 +2089,6 @@ static void set_dte_entry(struct amd_iommu *iommu, old_domid =3D READ_ONCE(dte->data[1]) & DTE_DOMID_MASK; new.data[1] |=3D domid; =20 - /* - * Restore cached persistent DTE bits, which can be set by information - * in IVRS table. See set_dev_entry_from_acpi(). - */ - initial_dte =3D amd_iommu_get_ivhd_dte_flags(iommu->pci_seg->id, dev_data= ->devid); - if (initial_dte) { - new.data128[0] |=3D initial_dte->data128[0]; - new.data128[1] |=3D initial_dte->data128[1]; - } - set_dte_gcr3_table(iommu, dev_data, &new); =20 amd_iommu_update_dte256(iommu, dev_data, &new); --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013002.outbound.protection.outlook.com [40.93.196.2]) (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 CAF932BD016 for ; Thu, 9 Oct 2025 23:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054382; cv=fail; b=gr2QZ9HDkM4z+dj64wPsfaw67iQXRuFeb99lu+dkOu9uFs2TgNdeb2BRKJJV8q6ZjkZddoYkncNtjrj5w28Gw+o3YZ8t2S6CYn8vis8rLVV8OKlSK6V+kyXJiE2TXSmHprftiCfg7bzU1t+myz7qAJ2hXj4EPZCY/kdmsQuh9Oc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054382; c=relaxed/simple; bh=v4WQ66kiK/wSsxL8TQ8IIz12Rfr+cKNGiK1SP4jrlzw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uiqSb2PR+VduWU72fDhirlTE9vIyugVxHfQUz0cL8Mcbl+MNF9fZ35R+J1NRxZ91SBreKh92gG+WFYZGkHFhAsVrqVInF0goccmw8ESKCNY4WWU/zQylQoUszHn2WkuF7pS/rxNkB+//7fzFlCiyE4Uwym1se9QKB6PY1yJR7LU= 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=IXA4yU4m; arc=fail smtp.client-ip=40.93.196.2 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="IXA4yU4m" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EauyUwIY1W7sMwPKX3vIGeDbwEcHO/8Dm+OiWJ2Lk6El6B3iUVhTy96ZSPKp8E9OpuXwVmVMT2q1fVQswHRP6/uKd+XRQDcoyYr6dqYKe0UyeIGN9U1AJE3WYxm1Aj6e/NKK2jcQadM7ikUiP4ERE8zBBqz4KGyL07K2vyJ3DvcoWlvxWi+5EuyGL4z8TikQRjreohiYSqaM5RPvKxG+3iXrl6T3VTC2MAiVfdrx/iunAUrQXm6grI/8815qXtzUW4ZFe6BMERUkM5sukm+oNVcvM6HFese4USocTiqKy2p5M6jl0Zk3VB8AORXOPomZTGpnLguEZZb3BO1yj9XGnQ== 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=hBQN1ned3RgcZgSbZD1XVPU8mfQuhTST/vxm0Z+MP/4=; b=aFbZ5PF2b6Dc44qQee6551/dpYVYoX2daD+jyoxxkncxsq/vvBz6PmbgSWNMD9BOPNX5CdjVO6zXblBxLi+JczRIR/OvCluE7T+uguxZyYY3PM08xJ0PiqvME2RMSM/y7VFCDUp65xk1t9AKn3QNIcdEfRTxLcdF8nCViVk3ZNP0I+1wuJjwDlG5r2fYS6NmKC68Z2dW3sTwmAGKqbrGeeXu+AbpNE9Dl4IyH2j+cIeSuQgvL2kPkx0MwBwL5O5JTF24Vy1r1gA90YoPjx2eOfIBRHPdoGoFkFTVP6xZHPu0OKPP7S/5moZ5Bff9bCgvDUzfTChB3HD/mWzboD0wUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=hBQN1ned3RgcZgSbZD1XVPU8mfQuhTST/vxm0Z+MP/4=; b=IXA4yU4mnyqmi1hdNXByFaK4fz46fu/9C+aQAcip+knuNJDVxneSDIIHl5ooPTSwCHcJCNf6t45miHa5gLzLTrM8bTDAgJQz2R5a+J9p3ZSi9BwrvETn2eqHjFRUzHEV117bcBPGFeHuRKS8iMDnswMUA/Ye0NlGUi2ULtkwJlQ= Received: from CH5P220CA0009.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::11) by IA1PR12MB6305.namprd12.prod.outlook.com (2603:10b6:208:3e7::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.10; Thu, 9 Oct 2025 23:59:33 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:610:1ef:cafe::68) by CH5P220CA0009.outlook.office365.com (2603:10b6:610:1ef::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:59:33 +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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:59:33 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:59:26 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 14/15] iommu/amd: Refactor logic to program the host page table in DTE Date: Thu, 9 Oct 2025 23:57:54 +0000 Message-ID: <20251009235755.4497-15-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|IA1PR12MB6305:EE_ X-MS-Office365-Filtering-Correlation-Id: 0df102ec-a33f-43b6-26ef-08de078fe4d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|1800799024|36860700013|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?3E97z/iw0C1Dy8JJ8z5vAXQGvgPi0+0Kt+tP3lB2kOeI+LNqjMtgXqDvlx1P?= =?us-ascii?Q?0tuJzdPq8sKBaAGY8hoHuUayfrfk3d1nP47mzffkxkzmEZ9rIEIs3O1WMObI?= =?us-ascii?Q?PYnetuCX/PuWvEm3e57/jTKJL01hCsY7z/eq/0VMmWJy58ClHVfT/Lm5My5p?= =?us-ascii?Q?jjvUu0dGCmxXnVI1xgEd7uAojQsgkaQ09D/0m8fbtQy9oLlZ4mw8MNOZMXdF?= =?us-ascii?Q?l/KyfG3eShhCyFDEyYH1lAknjaTzwo3bg8BdysMRihjuhDcmq61o6y14pULC?= =?us-ascii?Q?kNInUP4zgnUrkYUcKAQJbAeogtb1T8eSVCM+QkQL2/l8oamTCowxckAAmvDQ?= =?us-ascii?Q?K+kAP54EkWLK31cXIjpdwQuX/snhujv4Q6yBKHoqbua04Mj4GSh7p64+pQAe?= =?us-ascii?Q?foRmTuZVPFjxmwyf7+bSGncGmdrjSNSPnYZbscyul0QTcSDDiopZrjY6m/l0?= =?us-ascii?Q?Q4uNNXvMpkbke4/rhMX5KF35dK0t6Mkk64nQaH5lcAq4kTauaiZFn/bTVEYR?= =?us-ascii?Q?vuOz3R0YkVMVptUzmycuYhRl1VkvAPiDUZRljPQc8DOTyEnTXMjEddPTNkhk?= =?us-ascii?Q?8L9JY0w02FvYq66mutYzAHCeRri7u+UouVsmVkAreIrIpRV6zAH6dss+MDiw?= =?us-ascii?Q?qK5l37JifPYof6MDSt/cLX7eRtnyjITObFq+ZabirWSjqE6/huncqRSCGuXY?= =?us-ascii?Q?ZGRe72jtCWCMImvzRF6E3Vm8v5Oh9c1UacST8pIpib38CBWre6US8ugBaVMH?= =?us-ascii?Q?4w7PX86j+r1lwRZ3jCBbBQ10cdVt/e0NZ8u0palvceTiHnw07FIhFa0jdxUQ?= =?us-ascii?Q?+Zap3kycDaYXCDbVmGHqWkKBUVV+N3hTXBfWjUfwwwtQ5k5TVNbkkrSkJSEB?= =?us-ascii?Q?wJrxpNCs5bVZ5uGxmQoy0NezntRD962y6D7nME/RpVh91coeofdV2Gz+baKn?= =?us-ascii?Q?/07cks/qXjMAoZ8E7wxXU34dCC3AeMB4THl8ihyS9leYmvllmeCDZe6FXNgd?= =?us-ascii?Q?lZT08ObM231OgFtLu6CxrKwWdxXxiZ6hzh6AD+Z3NpfhL0YkaHhyBjvb014M?= =?us-ascii?Q?vXXdO6ptjlutl6mu/4kFIEbNXaUmF+jpyCoc35G0R/Wbgmb0cv5+MGzCZmCK?= =?us-ascii?Q?RlHVZ0CLk0QMq8XjJyUnyhIoMSpE6jlpQykkY3dBZDZ1m2i9UcAHXSf9j6DO?= =?us-ascii?Q?Zp3h9ClRQ+Q/4V4C1bQX6wJPcaOjKbzkx4RD7dA3w2gGEVivwW+OdCtixoo8?= =?us-ascii?Q?TOZG3ZmA/5bzcPjTJdmu0C8k+X6VQdOrwASk4oESwONRilisr+mRN4m/GJL3?= =?us-ascii?Q?Lz7XYu1WxF8CxGZSaEpqhqPQ4Gb+5ZwPv6igkYvqtFodGj5wuCcPm7C9pczr?= =?us-ascii?Q?kzc3wFiVS2rRZr9QSX13NrAihMenH2cA8BwXmlH/3Z7brBLZh+mDul529HD8?= =?us-ascii?Q?4oR4xa37ncEPYqLx52c6vLNPtNJHFiON8XfxTx+DUDh+fJ7tC4hOkJpGzh/l?= =?us-ascii?Q?JAR0CS4k2p6Q5InYMEoar5m36rzJMEPvJW0xBnyQewP8mFYy0H33fniU3p1P?= =?us-ascii?Q?xIT11dnrpk8hTPDUcCg=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(1800799024)(36860700013)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:59:33.3409 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0df102ec-a33f-43b6-26ef-08de078fe4d8 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6305 Content-Type: text/plain; charset="utf-8" Introduce the set_dte_v1() helper function to configure IOMMU host (v1) page table into DTE. There is no functional change. Suggested-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 54 +++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index ffb1adfd75c0..2a536d02aeab 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2044,6 +2044,32 @@ static void set_dte_gcr3_table(struct amd_iommu *iom= mu, target->data[2] |=3D FIELD_PREP(DTE_GPT_LEVEL_MASK, GUEST_PGTABLE_4_LEVE= L); } =20 +static void set_dte_v1(struct iommu_dev_data *dev_data, + struct protection_domain *domain, u16 domid, + struct dev_table_entry *new) +{ + /* + * When SNP is enabled, we can only support TV=3D1 with non-zero domain I= D. + * This is prevented by the SNP-enable and IOMMU_DOMAIN_IDENTITY check in + * do_iommu_domain_alloc(). + */ + WARN_ON(amd_iommu_snp_en && (domid =3D=3D 0)); + + if (domain->iop.mode !=3D PAGE_MODE_NONE) + new->data[0] |=3D iommu_virt_to_phys(domain->iop.root); + + new->data[0] |=3D FIELD_PREP(DTE_MODE_MASK, domain->iop.mode); + new->data[0] |=3D DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_TV; + + if (domain->dirty_tracking) + new->data[0] |=3D DTE_FLAG_HAD; + + if (dev_data->ats_enabled) + new->data[1] |=3D DTE_FLAG_IOTLB; + + new->data[1] |=3D domid; +} + static void set_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data *dev_data) { @@ -2061,36 +2087,14 @@ static void set_dte_entry(struct amd_iommu *iommu, =20 amd_iommu_make_clear_dte(dev_data, &new); =20 - if (domain->iop.mode !=3D PAGE_MODE_NONE) - new.data[0] |=3D iommu_virt_to_phys(domain->iop.root); - - new.data[0] |=3D (domain->iop.mode & DEV_ENTRY_MODE_MASK) - << DEV_ENTRY_MODE_SHIFT; - - new.data[0] |=3D DTE_FLAG_IR | DTE_FLAG_IW; + old_domid =3D READ_ONCE(dte->data[1]) & DTE_DOMID_MASK; =20 - /* - * When SNP is enabled, we can only support TV=3D1 with non-zero domain I= D. - * This is prevented by the SNP-enable and IOMMU_DOMAIN_IDENTITY check in - * do_iommu_domain_alloc(). - */ - WARN_ON(amd_iommu_snp_en && (domid =3D=3D 0)); - new.data[0] |=3D DTE_FLAG_TV; + set_dte_v1(dev_data, domain, domid, &new); + set_dte_gcr3_table(iommu, dev_data, &new); =20 if (dev_data->ppr) new.data[0] |=3D 1ULL << DEV_ENTRY_PPR; =20 - if (domain->dirty_tracking) - new.data[0] |=3D DTE_FLAG_HAD; - - if (dev_data->ats_enabled) - new.data[1] |=3D DTE_FLAG_IOTLB; - - old_domid =3D READ_ONCE(dte->data[1]) & DTE_DOMID_MASK; - new.data[1] |=3D domid; - - set_dte_gcr3_table(iommu, dev_data, &new); - amd_iommu_update_dte256(iommu, dev_data, &new); =20 /* --=20 2.34.1 From nobody Fri Dec 19 10:48:30 2025 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010046.outbound.protection.outlook.com [40.93.198.46]) (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 504E52BD5BF for ; Thu, 9 Oct 2025 23:59:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054384; cv=fail; b=jA8bATn48U8gTiG+RmSRTgGgt2vpkwet80bFY5rcDTocZ2FqcMElHNiRLNKizQYaGMmibmuG4YpbAWOlCx/nspi4GJLsXwTdQBvuMtJpVg0aZ0iBZiUDLcg0sfzIFKJGsYd7xLboTxFpKWJwV/MNPvOEOxuttiflVkk55Ev3rcA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760054384; c=relaxed/simple; bh=ut6reaH0FEBHZjcIZ/bb7fV3yepkHmBPaJEowvHQC1U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q36jFmN8Nvb63sjvdw5gCucyMajSvP/ir44FG0GTRmpERsiBavQYjgPSQ0kOhfaliB8L7Ta6Eoqu880O5jHvLp0T5R0EpLqpSPuYjdAuNZGvTKx2HII1NPVIaLmTuzKjkpyFEMOKWsFT7fVqnKaly857kif52GiuxFb4wqwQaXE= 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=4xZiud3o; arc=fail smtp.client-ip=40.93.198.46 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="4xZiud3o" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b2k4G6DKNPqDNUQZ5MNnd+hkxe2cwRJMM0TJ+F5OUqoY1ye0wLBwy3W/fzutFOCFbihUlFjD9nYbtdQydCPAAd2CtgCpwkvMiA3xz+lMWKKlrndRlyKXcI9aXDWA18daVY8zjBmHQhtsJHHn5twDaGeHane3pHVEacnKUJe3Cy2p/W9RYvbPGsOERijmYB9OSnoTzTBsI37eYQwAP4gDgRl9tklvoiNbUZ0cxTJUKsyqn35bTxH/sZ0+EREip8QzApcQZ5VDTyX3+QkHv6YdH5EMgC/CQeLGx8EawmPJZMHfXI6SQEHH7MSZkxAWJArYdS9N44GflXFXHNIKH+Z4ZA== 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=GVfpwYlhAZ24t32we4trRp1mV2NsC3725Che5nPL/JQ=; b=zKWYWXPy1UttMSgE2vnICpRTZbQGAPWqMf4u2p7RI8A4jXNNYXFl0uIV3gtq+YfUcU0W67O1zc2qPgD3artS/eXOOq6+rfvKD4iBKxyTGmBi5X/gfr38Sn8QiR7OxrTxwe9PRLKhcnS09RYTRz6QRUwDI+6NySGmrfiPOEYCrFjRde8K88BaZ+ZX/WYLzBYCcqhVbwvCk3Hm+B82QO5Ia2pyrM9DvE2vrKjtIAaW42XcvA1SXK7Qq6vCLZt7TnH7EsKUz13CfsReM6uDLdME13SgpB4nrdDn7ixbhyqygeXrF6YvY0hQvj+QPAkQC0oqwFVabPekIfL+0UnvjoSUmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.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=GVfpwYlhAZ24t32we4trRp1mV2NsC3725Che5nPL/JQ=; b=4xZiud3oFzIYhWtoFVqQZz8GCliCViiWE+K32K7P3nbQ858OVMcnWIvJyMw/OevxiU3z3JvJu0V2SfsBSoLM77OEsjqdMkQ6qN/k4GgJOuNl4TaW79rY3SByC0opA/2QmQCZrd4BahWboYCZt/GVffptmDCoWKyDY+LEg8sBBrc= Received: from DM6PR03CA0053.namprd03.prod.outlook.com (2603:10b6:5:100::30) by MN2PR12MB4173.namprd12.prod.outlook.com (2603:10b6:208:1d8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9; Thu, 9 Oct 2025 23:59:38 +0000 Received: from DS3PEPF000099DF.namprd04.prod.outlook.com (2603:10b6:5:100:cafe::2c) by DM6PR03CA0053.outlook.office365.com (2603:10b6:5:100::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.10 via Frontend Transport; Thu, 9 Oct 2025 23:59:33 +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 DS3PEPF000099DF.mail.protection.outlook.com (10.167.17.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.9 via Frontend Transport; Thu, 9 Oct 2025 23:59:38 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) 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; Thu, 9 Oct 2025 16:59:32 -0700 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3 15/15] iommu/amd: Add support for nested domain attach/detach Date: Thu, 9 Oct 2025 23:57:55 +0000 Message-ID: <20251009235755.4497-16-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251009235755.4497-1-suravee.suthikulpanit@amd.com> References: <20251009235755.4497-1-suravee.suthikulpanit@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: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DF:EE_|MN2PR12MB4173:EE_ X-MS-Office365-Filtering-Correlation-Id: 9cbd28ce-562a-4ef8-b574-08de078fe7a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?e/iIP84tpbZkWa/C2uuhTfT7sUSXu0iotCcxyyr7BLLcMsvS4Txf56PlquIX?= =?us-ascii?Q?8hWezqq87Dz+1gErhT5GX5LCBnWqjvoTU+qOvwbNbSwAMI0j3n9Zu094uUq/?= =?us-ascii?Q?UR2ZAWs+nkFOJjX/ZMkqUGfZ7CymPJLIq7gDKHfqtShPXKRXPaATO1C6IJjR?= =?us-ascii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Sc94D41k4j1j2KSrlTsaoO1/Jx?= =?us-ascii?Q?MjbhvpNUWgrHeFExG6Zz5IuJvK1AAapiAn9aGRbkMP8kie7ciBS70fSY0oMh?= =?us-ascii?Q?MPQb8asnJoPGWm4LrtNsnV4CvZUHR7iOFoRkx1aNjp8LOpBEXPODW1diCAij?= =?us-ascii?Q?GRDgRFAczI3Z5YVq6FFxQxK6fuBDjhXQke2VAg6HmpA+LQ2IFPla0YyVvLB7?= =?us-ascii?Q?I+nh35QpyotCY1kXRLYDcKgh9Vp/zghPgo5byIHtcL70QrQhH9nEf4YYJNpP?= =?us-ascii?Q?I3jQkoqtHPCy8xOBEnTu33vcq0whWPkAJfFJgNzjOe7sd+drxJnwVuwuAmmL?= =?us-ascii?Q?1PSkpqsfHceopyMNw3IvBRm1TJgiFSeVJz05IHCOfdfMSmZuqm0HM7he6NYX?= =?us-ascii?Q?npLTA0XSbFDVLcmTmTfZidIDlRIhuFbo4xriFjCNp6whanw5H0YDO3hJrakF?= =?us-ascii?Q?RIb2HUh1IaTjg24iYOBe9rsg88AP5LswEzNBC120teAkNlz/P7QnvAZdG52H?= =?us-ascii?Q?mtJRkXzbitdQ8OCIb1c=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2025 23:59:38.0310 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9cbd28ce-562a-4ef8-b574-08de078fe7a2 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: DS3PEPF000099DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4173 Content-Type: text/plain; charset="utf-8" Introduce set_dte_nested() to program guest translation settings in the host DTE when attaches the nested domain to a device. In addition, introduce struct amd_iommu_viommu, which stores reference to the nest parent domain assigned during the call to struct iommu_ops.viommu_init(). Information in the nest parent domain is needed when setting up the DTE for nested translation. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 3 ++ drivers/iommu/amd/amd_iommu_types.h | 8 ++++ drivers/iommu/amd/iommu.c | 8 ++-- drivers/iommu/amd/nested.c | 66 +++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index cfb63de7732a..98351b0cb9a0 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -190,6 +190,9 @@ struct iommu_dev_data *search_dev_data(struct amd_iommu= *iommu, u16 devid); int amd_iommu_completion_wait(struct amd_iommu *iommu); =20 /* DTE */ +void amd_iommu_set_dte_v1(struct iommu_dev_data *dev_data, + struct protection_domain *domain, u16 domid, + struct dev_table_entry *new); int amd_iommu_device_flush_dte(struct iommu_dev_data *dev_data); void amd_iommu_update_dte256(struct amd_iommu *iommu, struct iommu_dev_data *dev_data, diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index a68b5c2fc0a2..683ee288c636 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include =20 @@ -420,6 +421,7 @@ #define DTE_FLAG_HAD (3ULL << 7) #define DTE_MODE_MASK GENMASK_ULL(11, 9) #define DTE_HOST_TRP GENMASK_ULL(51, 12) +#define DTE_FLAG_PPR BIT_ULL(52) #define DTE_FLAG_GIOV BIT_ULL(54) #define DTE_FLAG_GV BIT_ULL(55) #define DTE_GLX GENMASK_ULL(57, 56) @@ -590,6 +592,11 @@ struct pdom_iommu_info { u32 refcnt; /* Count of attached dev/pasid per domain/IOMMU */ }; =20 +struct amd_iommu_viommu { + struct iommufd_viommu core; + struct protection_domain *parent; /* nest parent domain for this viommu */ +}; + /* * Structure defining one entry in the device table */ @@ -607,6 +614,7 @@ struct nested_domain { struct iommu_domain domain; /* generic domain handle used by iommu core c= ode */ u16 id; /* the domain id written to the device table = */ struct iommu_hwpt_amd_guest gdte; /* Guest vIOMMU DTE */ + struct amd_iommu_viommu *viommu; /* AMD hw-viommu this nested domain bel= ong to */ }; =20 /* diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 2a536d02aeab..013914fc8a4f 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2044,9 +2044,9 @@ static void set_dte_gcr3_table(struct amd_iommu *iomm= u, target->data[2] |=3D FIELD_PREP(DTE_GPT_LEVEL_MASK, GUEST_PGTABLE_4_LEVE= L); } =20 -static void set_dte_v1(struct iommu_dev_data *dev_data, - struct protection_domain *domain, u16 domid, - struct dev_table_entry *new) +void amd_iommu_set_dte_v1(struct iommu_dev_data *dev_data, + struct protection_domain *domain, u16 domid, + struct dev_table_entry *new) { /* * When SNP is enabled, we can only support TV=3D1 with non-zero domain I= D. @@ -2089,7 +2089,7 @@ static void set_dte_entry(struct amd_iommu *iommu, =20 old_domid =3D READ_ONCE(dte->data[1]) & DTE_DOMID_MASK; =20 - set_dte_v1(dev_data, domain, domid, &new); + amd_iommu_set_dte_v1(dev_data, domain, domid, &new); set_dte_gcr3_table(iommu, dev_data, &new); =20 if (dev_data->ppr) diff --git a/drivers/iommu/amd/nested.c b/drivers/iommu/amd/nested.c index 3307c925d3c1..ca3d3001c87f 100644 --- a/drivers/iommu/amd/nested.c +++ b/drivers/iommu/amd/nested.c @@ -63,6 +63,7 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *viom= mu, u32 flags, const struct iommu_user_data *user_data) { int ret; + struct amd_iommu_viommu *aviommu =3D container_of(viommu, struct amd_iomm= u_viommu, core); struct iommu_hwpt_amd_guest gdte; struct nested_domain *ndom; =20 @@ -85,6 +86,7 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *viom= mu, u32 flags, =20 ndom->domain.ops =3D &nested_domain_ops; ndom->domain.type =3D IOMMU_DOMAIN_NESTED; + ndom->viommu =3D aviommu; memcpy(&ndom->gdte, &gdte, sizeof(gdte)); =20 /* @@ -111,6 +113,69 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *v= iommu, u32 flags, return ERR_PTR(ret); } =20 +static void set_dte_nested(struct amd_iommu *iommu, + struct iommu_domain *dom, + struct iommu_dev_data *dev_data) +{ + struct protection_domain *parent; + struct dev_table_entry new =3D {0}; + struct nested_domain *ndom =3D to_ndomain(dom); + struct iommu_hwpt_amd_guest *gdte =3D &ndom->gdte; + + /* + * The nest parent domain is attached during the call to the + * struct iommu_ops.viommu_init(), which will be stored as part + * of the struct amd_iommu_viommu.parent. + */ + if (WARN_ON(!ndom->viommu || !ndom->viommu->parent)) + return; + + parent =3D ndom->viommu->parent; + amd_iommu_make_clear_dte(dev_data, &new); + + /* + * Use nested domain ID to program DTE. + * See amd_iommu_alloc_domain_nested(). + */ + amd_iommu_set_dte_v1(dev_data, parent, ndom->id, &new); + + /* Guest PPR */ + new.data[0] |=3D gdte->dte[0] & DTE_FLAG_PPR; + + /* Guest translation stuff */ + new.data[0] |=3D gdte->dte[0] & (DTE_GLX | DTE_FLAG_GV | DTE_FLAG_GIOV); + + /* GCR3 table */ + new.data[0] |=3D gdte->dte[0] & DTE_GCR3_14_12; + new.data[1] |=3D gdte->dte[1] & (DTE_GCR3_30_15 | DTE_GCR3_51_31); + + /* Guest paging mode */ + new.data[2] |=3D gdte->dte[2] & DTE_GPT_LEVEL_MASK; + + amd_iommu_update_dte256(iommu, dev_data, &new); +} + +static int nested_attach_device(struct iommu_domain *dom, struct device *d= ev) +{ + struct iommu_dev_data *dev_data =3D dev_iommu_priv_get(dev); + struct amd_iommu *iommu =3D get_amd_iommu_from_dev_data(dev_data); + int ret =3D 0; + + if (WARN_ON(dom->type !=3D IOMMU_DOMAIN_NESTED)) + return -EINVAL; + + mutex_lock(&dev_data->mutex); + + /* Update device table entry */ + set_dte_nested(iommu, dom, dev_data); + amd_iommu_device_flush_dte(dev_data); + amd_iommu_completion_wait(iommu); + + mutex_unlock(&dev_data->mutex); + + return ret; +} + static void nested_domain_free(struct iommu_domain *dom) { struct nested_domain *ndom =3D to_ndomain(dom); @@ -120,6 +185,7 @@ static void nested_domain_free(struct iommu_domain *dom) } =20 static const struct iommu_domain_ops nested_domain_ops =3D { + .attach_dev =3D nested_attach_device, .free =3D nested_domain_free, }; =20 --=20 2.34.1