From nobody Sat Nov 23 01:44:10 2024 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2078.outbound.protection.outlook.com [40.107.96.78]) (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 F34811A3A95; Thu, 14 Nov 2024 19:45:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613509; cv=fail; b=O+46ith88m7FCtMuR58LRp6BBFLbVG2IjQ08ulRQW99pzyyYppunjyILk8P5vp3QKAa86DUKGC6AKLN+TyJKWXhMhYnBi6/tvgG8xr1X4DwSfgnzMxeAps2MU0WSV2DSZNb+dReRp6sANSWt3wyLFLEQxu9vLtxA73iLrTh9fcE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613509; c=relaxed/simple; bh=I6EQiYw8K0f5jXKss9BxucItbForiWMKXniF8tpRkio=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pEBcLwQ1fLaBMiKJiXuG+Rdohrim9ktd/051M96NkpdGnJof7qkxzOTt/KDLMg6wIKY9nUfYc92bwxypLmNT+5JC/7p/8NDlf3kANHaHqLNlEr58YZL+lMOn47pqtIuGxhRh4NcluM4ggTAhR2m93Y2fBuogs2cB6dG6sZi7Ta0= 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=I/UEHqIm; arc=fail smtp.client-ip=40.107.96.78 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="I/UEHqIm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cbxIoC2331fSzUwxydj7przBc8pzwblo9NNz58HpwrnL6kSY//9aN4B0w1wQdLracZlCYCuclK+nVu3/fO9oBaaudQJZ3+n/hCUw+eDfwBEVaApf2MJnkCyNacrXFx/SsbiL1otDr8mF3WPForR9isXzObxqxGJ8jXaVVwGeSkrDQZzqTlcN78wnSlMdP3vBdhA44iCkAcP7EzAAcq9Bmq9Q3W39mgnUelbi32WZrXF77BGZltP2qnKu9RbudD5e2/8FkrWMZ8WfkfBZxbQygfiGWpnQubPgbKt0c2nsOpWxeoftgM7LNExLvbZLiFqkVkNT/pygyQJan144tCqfWg== 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=hgjJpIWUMULCYTGTfsX2DraU/FvbxstiAT4/BZSQ7n8=; b=YlEPLqfss9R7qiVVfogI5uYChvrgfROJrkS+vk5jF+IWBdncW17jCe3JA0i/rxtgL95nAPvHDXJ+WVkTZoFZ7fbZQJgoG+tvo+z1RIW7rLrZ/nLU0V7sNW0GyOG4LEeWv1CqQxcakNDJVRaV3YFYo7snLrZRpdfqhLfEEAluYKo7mGmESiK09bQIFL50QgncZGjnubwEY4EyEqW/5FGqMjmzFPMMNPmkqIWZVaJ3XVxCk2rq70aeT+oKibY9oAQrOpYkvubgDTJhGwUxO5u/7YtVPNvr8UL9vfEdrVdVWITydkAObzxQYvTXP7CMj7S3p1wZr5yVCNaqkUqrQvzMFw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hgjJpIWUMULCYTGTfsX2DraU/FvbxstiAT4/BZSQ7n8=; b=I/UEHqIm7TEU+jZmriqZIAmMYhECdVmCxNqCLQbu7thGN+2XvJaYJs5Kwm/V26Rw9LiBPLGrq9q0X6F/wYYDXFbXhfCQbYlVrYkvgvrPMZXALdlHRbdwQlIcgVqNUpnD0p+MqsN3Il42uQA4O/0kBPKOdqet6eFwTOhHap8SnYs= Received: from BY5PR16CA0005.namprd16.prod.outlook.com (2603:10b6:a03:1a0::18) by SN7PR12MB6911.namprd12.prod.outlook.com (2603:10b6:806:261::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.28; Thu, 14 Nov 2024 19:45:05 +0000 Received: from MWH0EPF000989E5.namprd02.prod.outlook.com (2603:10b6:a03:1a0:cafe::99) by BY5PR16CA0005.outlook.office365.com (2603:10b6:a03:1a0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.16 via Frontend Transport; Thu, 14 Nov 2024 19:45: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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989E5.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 19:45:04 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 14 Nov 2024 13:44:58 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v11 1/9] iommu/amd: Misc ACPI IVRS debug info clean up Date: Thu, 14 Nov 2024 19:44:28 +0000 Message-ID: <20241114194436.389961-2-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114194436.389961-1-suravee.suthikulpanit@amd.com> References: <20241114194436.389961-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E5:EE_|SN7PR12MB6911:EE_ X-MS-Office365-Filtering-Correlation-Id: f1ff892a-4e1a-48c4-9aae-08dd04e4d62e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?PWw3NnC8ASMbYt2lFAsJd8ohQ8AbQMDAjRL7HNcuJ/rBZ5UdCTOnnl5/MPyt?= =?us-ascii?Q?Q+XfYEMv07GNR4RCvdT7/N5Tav5NdCv/1ksCa/COdGfC8+84js7O+1pKGsAf?= =?us-ascii?Q?pp40pWgtEHLCIZlvZ09XIwEJ5GB8n7rQPp86p/6JrqxHIxfynswUH+zm03jQ?= =?us-ascii?Q?mPUJYvNjqzYhOwHOTy1fD1kFGlpPnZhJFayqkjnpiI8gIlS9m8ZE1+fvTmGc?= =?us-ascii?Q?pt5gCWzVBYDi60hj/yh8QGHGnzj9SGKx9upHjVRoe8YD5Lirq5Mmds6u8cMd?= =?us-ascii?Q?l/sqn/nh5fViUcOFbwKlv4PNJwV7dIw5jat4wuLHlPn3kFhTmNycMAcHHSU/?= =?us-ascii?Q?BPiQQMkk7owaY/p45/f9l4nS6y7JOFuW7+K3tTrYn1S63X/lxTJnpS3IAWIF?= =?us-ascii?Q?tEt9D3eBsLZZgpLkM7QZT3xm/GehNYjTz9uBhK2KenUl/QdYHLZQL073M63e?= =?us-ascii?Q?iSXyS0DeE+uFWgIxjsQmWGmCnVkUdIyl9qOuk3jieslmAR2yLgXl4CGDW11a?= =?us-ascii?Q?EZcufcFdoCyyQPLPUKeYcbhRs7ltAGg0DWYMsi8kUxxWAlMRSFx8M3cCC62L?= =?us-ascii?Q?3aU8l7Xj4p2jiR24FFpxtZvw5QbAbU7pAYkmddwVpNV/16pDv8o9yjEUslEA?= =?us-ascii?Q?HevLqwuVtNJJM/DnnfdETAuzUKWUR4uNlue0bWaH81qfGxA+Ck1mlUBT9dwo?= =?us-ascii?Q?lROj2C0fRv4aIoc843UMiqUDk8ySkHd0vhfy8l2U24osPLGHT0Pkt/2HyIDu?= =?us-ascii?Q?U9+g0FBhQBR1uHlqrXD4jBDq0ax4Ydlx/252JSq9zK0HcMUfa1G0XuFLbSOS?= =?us-ascii?Q?NJqlAGFgInZCJopXaUDzf5bErt7bcMaqxRxnA/9G4pPmSkWyaoHcZvDi145E?= =?us-ascii?Q?o7yEOz2ADo47nVHeW2j6CY0pgCM8/hL0BjXIWHRGD69sd88aUJf5y7uuEQrH?= =?us-ascii?Q?R3yw2t2cf9qIhBSsxxqXchT/1RMkNijbueRPkDWPyTSMm76HjDTlHPI1rUh4?= =?us-ascii?Q?uLahHgoTN2gRrCLPEO8Ohx3wSwZtBJcVY5uhNogDRp7gnK3ltB8FU06XYTxo?= =?us-ascii?Q?U5rVcYswaMZW6zDPqoLsnXdlUkw20N2JakxEKNvbHIFgkBIGK4TdreU/vb3x?= =?us-ascii?Q?P/KH+NCpsXQoY6Ar2kFszy9tNX1DkzJr3sQ+H2BDdpQHOx7ccvgBL+jDbvPy?= =?us-ascii?Q?QaUo4oFBw4g8HewybBI/XopJuFxqkECFGJx65WTZiURaAMAQoqzrV2uzUZNR?= =?us-ascii?Q?U7yaR8ds8X910IU3X6bH0UrVeSGj2yWdALP8khmUYZfBqMMe0C7N/jBj6k9P?= =?us-ascii?Q?qt8HDiHTRU0NQ7Jk+TJ5Lna7bvIm1dYaXcKhWVq4CWMOGDbiLl65Rvc8hABu?= =?us-ascii?Q?PWukxqPfHKmTFFSqALT2Rq9x3s2CU4/nNyuAf3i/Q6dgniEGAw=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 19:45:04.7349 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f1ff892a-4e1a-48c4-9aae-08dd04e4d62e 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E5.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6911 Content-Type: text/plain; charset="utf-8" * Remove redundant AMD-Vi prefix. * Print IVHD device entry settings field using hex value. * Print root device of IVHD ACPI device entry using hex value. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 2 +- drivers/iommu/amd/init.c | 35 +++++++++++++---------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index fdb0357e0bb9..af87b1d094c1 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -468,7 +468,7 @@ extern bool amd_iommu_dump; #define DUMP_printk(format, arg...) \ do { \ if (amd_iommu_dump) \ - pr_info("AMD-Vi: " format, ## arg); \ + pr_info(format, ## arg); \ } while(0); =20 /* global flag if IOMMUs cache non-present entries */ diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 0e0a531042ac..3a7b2b0472fa 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1239,7 +1239,7 @@ static int __init add_acpi_hid_device(u8 *hid, u8 *ui= d, u32 *devid, entry->cmd_line =3D cmd_line; entry->root_devid =3D (entry->devid & (~0x7)); =20 - pr_info("%s, add hid:%s, uid:%s, rdevid:%d\n", + pr_info("%s, add hid:%s, uid:%s, rdevid:%#x\n", entry->cmd_line ? "cmd" : "ivrs", entry->hid, entry->uid, entry->root_devid); =20 @@ -1331,15 +1331,14 @@ static int __init init_iommu_from_acpi(struct amd_i= ommu *iommu, switch (e->type) { case IVHD_DEV_ALL: =20 - DUMP_printk(" DEV_ALL\t\t\tflags: %02x\n", e->flags); + DUMP_printk(" DEV_ALL\t\t\tsetting: %#02x\n", e->flags); =20 for (dev_i =3D 0; dev_i <=3D pci_seg->last_bdf; ++dev_i) set_dev_entry_from_acpi(iommu, dev_i, e->flags, 0); break; case IVHD_DEV_SELECT: =20 - DUMP_printk(" DEV_SELECT\t\t\t devid: %04x:%02x:%02x.%x " - "flags: %02x\n", + DUMP_printk(" DEV_SELECT\t\t\tdevid: %04x:%02x:%02x.%x flags: %#02x\n", seg_id, PCI_BUS_NUM(e->devid), PCI_SLOT(e->devid), PCI_FUNC(e->devid), @@ -1350,8 +1349,7 @@ static int __init init_iommu_from_acpi(struct amd_iom= mu *iommu, break; case IVHD_DEV_SELECT_RANGE_START: =20 - DUMP_printk(" DEV_SELECT_RANGE_START\t " - "devid: %04x:%02x:%02x.%x flags: %02x\n", + DUMP_printk(" DEV_SELECT_RANGE_START\tdevid: %04x:%02x:%02x.%x flags: = %#02x\n", seg_id, PCI_BUS_NUM(e->devid), PCI_SLOT(e->devid), PCI_FUNC(e->devid), @@ -1364,8 +1362,7 @@ static int __init init_iommu_from_acpi(struct amd_iom= mu *iommu, break; case IVHD_DEV_ALIAS: =20 - DUMP_printk(" DEV_ALIAS\t\t\t devid: %04x:%02x:%02x.%x " - "flags: %02x devid_to: %02x:%02x.%x\n", + DUMP_printk(" DEV_ALIAS\t\t\tdevid: %04x:%02x:%02x.%x flags: %#02x dev= id_to: %02x:%02x.%x\n", seg_id, PCI_BUS_NUM(e->devid), PCI_SLOT(e->devid), PCI_FUNC(e->devid), @@ -1382,9 +1379,7 @@ static int __init init_iommu_from_acpi(struct amd_iom= mu *iommu, break; case IVHD_DEV_ALIAS_RANGE: =20 - DUMP_printk(" DEV_ALIAS_RANGE\t\t " - "devid: %04x:%02x:%02x.%x flags: %02x " - "devid_to: %04x:%02x:%02x.%x\n", + DUMP_printk(" DEV_ALIAS_RANGE\t\tdevid: %04x:%02x:%02x.%x flags: %#02x= devid_to: %04x:%02x:%02x.%x\n", seg_id, PCI_BUS_NUM(e->devid), PCI_SLOT(e->devid), PCI_FUNC(e->devid), @@ -1401,8 +1396,7 @@ static int __init init_iommu_from_acpi(struct amd_iom= mu *iommu, break; case IVHD_DEV_EXT_SELECT: =20 - DUMP_printk(" DEV_EXT_SELECT\t\t devid: %04x:%02x:%02x.%x " - "flags: %02x ext: %08x\n", + DUMP_printk(" DEV_EXT_SELECT\t\tdevid: %04x:%02x:%02x.%x flags: %#02x = ext: %08x\n", seg_id, PCI_BUS_NUM(e->devid), PCI_SLOT(e->devid), PCI_FUNC(e->devid), @@ -1414,8 +1408,7 @@ static int __init init_iommu_from_acpi(struct amd_iom= mu *iommu, break; case IVHD_DEV_EXT_SELECT_RANGE: =20 - DUMP_printk(" DEV_EXT_SELECT_RANGE\t devid: " - "%04x:%02x:%02x.%x flags: %02x ext: %08x\n", + DUMP_printk(" DEV_EXT_SELECT_RANGE\tdevid: %04x:%02x:%02x.%x flags: %#= 02x ext: %08x\n", seg_id, PCI_BUS_NUM(e->devid), PCI_SLOT(e->devid), PCI_FUNC(e->devid), @@ -1428,7 +1421,7 @@ static int __init init_iommu_from_acpi(struct amd_iom= mu *iommu, break; case IVHD_DEV_RANGE_END: =20 - DUMP_printk(" DEV_RANGE_END\t\t devid: %04x:%02x:%02x.%x\n", + DUMP_printk(" DEV_RANGE_END\t\tdevid: %04x:%02x:%02x.%x\n", seg_id, PCI_BUS_NUM(e->devid), PCI_SLOT(e->devid), PCI_FUNC(e->devid)); @@ -1461,11 +1454,12 @@ static int __init init_iommu_from_acpi(struct amd_i= ommu *iommu, else var =3D "UNKNOWN"; =20 - DUMP_printk(" DEV_SPECIAL(%s[%d])\t\tdevid: %04x:%02x:%02x.%x\n", + DUMP_printk(" DEV_SPECIAL(%s[%d])\t\tdevid: %04x:%02x:%02x.%x, flags: = %#02x\n", var, (int)handle, seg_id, PCI_BUS_NUM(devid), PCI_SLOT(devid), - PCI_FUNC(devid)); + PCI_FUNC(devid), + e->flags); =20 ret =3D add_special_device(type, handle, &devid, false); if (ret) @@ -1525,11 +1519,12 @@ static int __init init_iommu_from_acpi(struct amd_i= ommu *iommu, } =20 devid =3D PCI_SEG_DEVID_TO_SBDF(seg_id, e->devid); - DUMP_printk(" DEV_ACPI_HID(%s[%s])\t\tdevid: %04x:%02x:%02x.%x\n", + DUMP_printk(" DEV_ACPI_HID(%s[%s])\t\tdevid: %04x:%02x:%02x.%x, flags:= %#02x\n", hid, uid, seg_id, PCI_BUS_NUM(devid), PCI_SLOT(devid), - PCI_FUNC(devid)); + PCI_FUNC(devid), + e->flags); =20 flags =3D e->flags; =20 --=20 2.34.1 From nobody Sat Nov 23 01:44:10 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2043.outbound.protection.outlook.com [40.107.244.43]) (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 CCF08BE4E; Thu, 14 Nov 2024 19:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613514; cv=fail; b=OMwDr6jxAbZBnGbvFUP70UDerin+DWNl7OPBJyfWtuZ2UcqgIhn8oMS8IH9/vuRm7esWnIXxMz0FXaKerAEg3GiZD/0i7wsmU8GuTDbcpIP1PhuefNbpqj1AffOehHIjK9qptZwQoZ3g9m4NupKjnmcWl+sc20doB5wISMSq5gM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613514; c=relaxed/simple; bh=BsNnwUV2R/BfqocP4sWIcX7O5HMemYytLwFFbPlqykI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IorXJDScDQFzMKNcd3Z09HNI4jPj7sh8p88xziQ2qX54u5yzszGjuW+GP7jlnzz6cQa9ExAIEwFSP0wtdxa/2s8t+uWcFYNOxTDcZ9u26rXflxOrd0i581FqJGwD3SjkCZEpD1uXqm5TYL2R3K2sm0UWXacvsTlybEFZiEshTLg= 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=FWaVeKFS; arc=fail smtp.client-ip=40.107.244.43 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="FWaVeKFS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DvxeqZhRWwVXUfd2JjbZk1Eibn9BqtgZVbdWTqcwQu8/6wjcDTKlHLtV5AlMH3HqeaFyEgHVTKplZ5LmYKxr7sZzrG6OxnAdBpvRrwOmkyeWThF5K0oHSsn3n167JU99w/+dGyS8uKU9/W7Dv3zUaCS/kyXiX7qDfbRUDoDtBMMsX/cl+O9XOGN+CZ0CI/wSq5MnYE0xkbNXhl143b9FioERPLqGhP3dEXhQIIzMT9EtKaa6lgBA8b7qlgkcpDzMK2mxzHIBDsDMRItjxsELoCD6yKNjIQ7yh5D/xQVLKwoYNWdCKVlt5oTnaAN+Bb95UAlOZsvmBgG4zqNxu2WjXA== 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=ryS1c9CjW32vCe1i9lmLhp+TuU+jW5Gxo4i6WTEQ7Bk=; b=ny4X85Z7X3tGssxKWcvK/lyfDn1dCUIDX3bdaE/jK8Ntm/VD9KPuWtLdWcVFJSfczH+HcPpHcsBG6s1oIBFfkQIymjT54OvOjvjsuKkSe7OzxQg7++JpAt7M3UG77o+qw953UkBOA6erGuOJ4EdyO+GhibvCAyylLvT1uqP09NzwS+bKXsrTin5ODB1FECUffMJ+Yqs+gdSV0pPjMyRedgBQb/Yqbxw9j3vw8JEtcxnyx+JmDuoKGfGQkdF2ri9GFB9uUFxpUejWwDoPPVdkJ5Ije9ydmyHKfmkBrpvciuH7rcdT3bi8QZC4FasbtOpdADFuC/L6B/7M3j0H1WckYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ryS1c9CjW32vCe1i9lmLhp+TuU+jW5Gxo4i6WTEQ7Bk=; b=FWaVeKFS1i5U9JNdPdvrwYZC1rcA7a7dVpECPOB78qNV72nwamfPhchGDBbr8cOAHhVBoLBbqW9wwKJhDfi+k5jV2o5JtCVPMaDZXCMNhrWSbdHgO8GI6SEv21+onqcjNkppaNg5eZqLmKQnKbKEdw5mKhdgHsEuIFRixJ/vhFo= Received: from BYAPR05CA0093.namprd05.prod.outlook.com (2603:10b6:a03:e0::34) by BL3PR12MB6428.namprd12.prod.outlook.com (2603:10b6:208:3b7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18; Thu, 14 Nov 2024 19:45:08 +0000 Received: from MWH0EPF000989E6.namprd02.prod.outlook.com (2603:10b6:a03:e0:cafe::28) by BYAPR05CA0093.outlook.office365.com (2603:10b6:a03:e0::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.16 via Frontend Transport; Thu, 14 Nov 2024 19:45:07 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989E6.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 19:45:07 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 14 Nov 2024 13:45:02 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v11 2/9] iommu/amd: Disable AMD IOMMU if CMPXCHG16B feature is not supported Date: Thu, 14 Nov 2024 19:44:29 +0000 Message-ID: <20241114194436.389961-3-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114194436.389961-1-suravee.suthikulpanit@amd.com> References: <20241114194436.389961-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E6:EE_|BL3PR12MB6428:EE_ X-MS-Office365-Filtering-Correlation-Id: 30251883-96af-40b7-967b-08dd04e4d7a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?7Qaz4t+tKiT/hoEHa6Ck/0OInAh4tAMX+hEfuFT6pyXpJIW0kuSq4dbPqD4i?= =?us-ascii?Q?MlfEv0DELoTuxDtmTbdj2GCHHE2hiCmwM0t+H6aAx4UUQpcg/vyn8ER1P1hk?= =?us-ascii?Q?VdUyN/g8PhlXvx9eqrVgJoZfvFYKWMrjfiVHCYsWEYIdHxqW4hs0P3E/ne7I?= =?us-ascii?Q?WPXtAX8YOUI2tog+G8Jgyr6EqGY5UeU+w6eEZQXhQk0kuIDcbXqDj8vtKz4E?= =?us-ascii?Q?cstsqaY29zYZwSeVS9Yi7XVe2OZN1oqJJQK8dFZJYcSruQzmAOg4ImZV68kD?= =?us-ascii?Q?Vaislxvpis/G7Wjry0mozSC6uil7GBG3PeDRqNIEtRvLZ+kr1b0fhMtoyaNY?= =?us-ascii?Q?VDnHiqJ8GeX0tre1ZkgDUpUWumiVrB6XM8hC3kwV9PzQ6gz3DkA0BSUlEXdu?= =?us-ascii?Q?3oAHZ2HjwI4cHa+i09nLl6UOKaXmsbQOiiEaiGdB1ll4Wz834C49PGrzq438?= =?us-ascii?Q?w4am642KRtARA92r/g1jHAnBI7Kl6Hkv4piyt2XW3anbTwRtIy1poBN8njHq?= =?us-ascii?Q?FK7hN3fPtAOKYKetzIxQYcWrpfmqLfid2uLjUsCUFtyJJujT/kP2L/di1C2p?= =?us-ascii?Q?g6ubwhpl4SUw3+41SwAF79UG650QUcoeT3Iklm09aIHCU/ow+7ERj7mCit2w?= =?us-ascii?Q?X5jxE9gb9Eob4FIFValDH9Ntrz4j0lGvA166qCXdWVD85Qas80/8jFwtXPJS?= =?us-ascii?Q?tTZFWEan2wcjOcZZvqOlnbdzkh1/EXbbEqqnuq/oxMoSoHoh/IyC2ljKp7UE?= =?us-ascii?Q?y3qc23VeIJiQw7X8F04iL7tvaQ9+2Fmpyy5xjWPYHop8cfiX3F+7rPAfYklC?= =?us-ascii?Q?jF0qu2VhhvSk3PrjUTUibUF21SQvKoHwDoMd+usjhffy0MGVewGF/nO4lYCG?= =?us-ascii?Q?tpnFCxpLVL99Dt9Pek0JHOuzp51NKQmbF1tFk4il8siWsS158+Hy8mWQFq+T?= =?us-ascii?Q?cJHHxZev7t22+WrruY35xNiwZBO741+CyLbHo8roClWwwMyxMBhxPweDs4+I?= =?us-ascii?Q?NildPYt+AKwFJ6RXwvq+RN8vbDErH1RCXPaTXV2u6IOkoB/REuDSsaNyVDrl?= =?us-ascii?Q?jYfzGCMrrmwyQMa8bjArWTGyT83mgy5Zyjs2RxitYWS+AxILDfNVSRAlAu97?= =?us-ascii?Q?JSH6It+Dm5VvfjEMAqGaQg6ZM2xn4915RMZbWor5MXgmv57FJmdnpFSfnkKS?= =?us-ascii?Q?iZby+qY9HLMAlbW+7i/6h33YMBJUovLS7kiS7W/93+tkuxrwWKIKNWw+7Zxe?= =?us-ascii?Q?oWqoBMX1iQqQzrD1o0IFWorvE1s4+4b496nZ5GnSACgLY0uhllJ6FZlXwRnH?= =?us-ascii?Q?VsufDQoAnygZm3EK/ReWqi6RAb4pxVcGVMLeRuMtFdPZ8rdPCAQPxzKSi35h?= =?us-ascii?Q?370awrtsVKNLhuDSKnld1HM0CVE9SLtgBCoRrA/9RbnvoGDSFQ=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 19:45:07.1596 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30251883-96af-40b7-967b-08dd04e4d7a0 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6428 Content-Type: text/plain; charset="utf-8" According to the AMD IOMMU spec, IOMMU hardware reads the entire DTE in a single 256-bit transaction. It is recommended to update DTE using 128-bit operation followed by an INVALIDATE_DEVTAB_ENTYRY command when the IV=3D1b or V=3D1b before the change. According to the AMD BIOS and Kernel Developer's Guide (BDKG) dated back to family 10h Processor [1], which is the first introduction of AMD IOMMU, AMD processor always has CPUID Fn0000_0001_ECX[CMPXCHG16B]=3D1. Therefore, it is safe to assume cmpxchg128 is available with all AMD processor w/ IOMMU. In addition, the CMPXCHG16B feature has already been checked separately before enabling the GA, XT, and GAM modes. Consolidate the detection logic, and fail the IOMMU initialization if the feature is not supported. [1] https://www.amd.com/content/dam/amd/en/documents/archived-tech-docs/pro= grammer-references/31116.pdf Reviewed-by: Jason Gunthorpe Suggested-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/init.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 3a7b2b0472fa..c1607b29ebf4 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1752,13 +1752,8 @@ static int __init init_iommu_one(struct amd_iommu *i= ommu, struct ivhd_header *h, else iommu->mmio_phys_end =3D MMIO_CNTR_CONF_OFFSET; =20 - /* - * Note: GA (128-bit IRTE) mode requires cmpxchg16b supports. - * GAM also requires GA mode. Therefore, we need to - * check cmpxchg16b support before enabling it. - */ - if (!boot_cpu_has(X86_FEATURE_CX16) || - ((h->efr_attr & (0x1 << IOMMU_FEAT_GASUP_SHIFT)) =3D=3D 0)) + /* GAM requires GA mode. */ + if ((h->efr_attr & (0x1 << IOMMU_FEAT_GASUP_SHIFT)) =3D=3D 0) amd_iommu_guest_ir =3D AMD_IOMMU_GUEST_IR_LEGACY; break; case 0x11: @@ -1768,13 +1763,8 @@ static int __init init_iommu_one(struct amd_iommu *i= ommu, struct ivhd_header *h, else iommu->mmio_phys_end =3D MMIO_CNTR_CONF_OFFSET; =20 - /* - * Note: GA (128-bit IRTE) mode requires cmpxchg16b supports. - * XT, GAM also requires GA mode. Therefore, we need to - * check cmpxchg16b support before enabling them. - */ - if (!boot_cpu_has(X86_FEATURE_CX16) || - ((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) =3D=3D 0)) { + /* XT and GAM require GA mode. */ + if ((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) =3D=3D 0) { amd_iommu_guest_ir =3D AMD_IOMMU_GUEST_IR_LEGACY; break; } @@ -3028,6 +3018,11 @@ static int __init early_amd_iommu_init(void) return -EINVAL; } =20 + if (!boot_cpu_has(X86_FEATURE_CX16)) { + pr_err("Failed to initialize. The CMPXCHG16B feature is required.\n"); + return -EINVAL; + } + /* * Validate checksum here so we don't need to do it when * we actually parse the table --=20 2.34.1 From nobody Sat Nov 23 01:44:10 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2080.outbound.protection.outlook.com [40.107.220.80]) (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 4F8661AB500; Thu, 14 Nov 2024 19:45:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613517; cv=fail; b=ZfJDB6tqAilJ0PFvECwmTNEQRaJSN1zszklO858p8vhTmyCTB/rz0r8YqqIabeJ69asN6e0Wh31CM1pw4sHGJB87b329ON4UsATSBEkhPj5EH5eWlZeC27NR9FphNTe1jryFAWdZmbWgIxc7G2z+axB6YUv18RfMzeUNH1N7HdY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613517; c=relaxed/simple; bh=jpHJ2al8FOn0Z+Q1yy1S00HSe4XZce36Tt1fSG4E2bE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z9DgGEbIACyBVZ51JxxeEDUFcAh03qc4MrM16OohEt7e8S53zch9JvmXsNE1qvrmKygdPPKq+exDRJ/gt0OtWQrNjQj6P2JJzAF1nwhnk2CPwtHSzrIeW914PBhgFAv3EpQLbsvuZhM8iQ8sSica7zSwcbpLTta65JgvPRFsvZQ= 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=jdhT+MI+; arc=fail smtp.client-ip=40.107.220.80 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="jdhT+MI+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UsdcpuqbPQTRiWyRrT14n7rtYTgeR9sUcWP3MPK/aBbr3dPvPifFbI3hstxZ1f8/V/2ABUF6sBnSu99HdVQUlAERx6L6jTxBTdshS7A/38mr9JvPf8CG+G4ck7fky6bLhNwH0bG6ECsrkLIRWGYYQQ0dcZ2cyDN082JFwqAFzWeGlxOV44P0K9qhylGjuJDMxFGcGSzvVeTw9LD6IRtAY/Kl9mE+GOBiHmejL9ZW6R+fEjutqK5mLNKdE7eT5aK81Gp0mqZD8BKpcglW563TfCxRTByyNFlOm05FCkgSAx/YXf/e2AFBdN/HtiR+PO3nRC23UBAOQUafQCfE4YnHAA== 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=zjXHdjGcX4/L11iyd2wCJPLWf1/5/zh9tSHEiecH+R4=; b=AKtzdaMR9oXgXTNde8pVpFN086f2n6nFKrjMaJEWFe7aJ0V3i82hDFiFbvqZuY7YvZAfNgsMYY653aF/Q3fadspVEEvslqH3HAx57r5scCeyonCAyLosN7fQJfzWGi3osHIi8Rvcs3+7R50YduN2EEeFeAJECOmpQ7klF0S4LirGLvkaRgQmfJ7B+E+w8FkOC5COOMgLIF/iCwUiYzpyOoVakYtfAYOxzeSnDoPkfMKBPoGtZg5SNQ/l04HQSmrw54YqSPMwtDNFjBtW1rjYHlCaevH/dm8Jm0rr38CPD4FmYZeW8G4NDxI8nyV5zsGVS6kRQ4ZApPwk+jA2ntXjSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zjXHdjGcX4/L11iyd2wCJPLWf1/5/zh9tSHEiecH+R4=; b=jdhT+MI+pz8BkOSWb8g80U0nb0+mlsSQQooL4nzEK8etfKFjHifpM7tUU2L4mcc/YWqYW4mXBRLez1xm00qZExY7zJ9nx13rdrhL9V3nTJ9ojBewgrLz0HvrdYktSyK6S3bnvaE9214G432KXp6WjUeRuu6Yu0Wrl+pacftFnRw= Received: from DM6PR03CA0092.namprd03.prod.outlook.com (2603:10b6:5:333::25) by SJ2PR12MB9237.namprd12.prod.outlook.com (2603:10b6:a03:554::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18; Thu, 14 Nov 2024 19:45:11 +0000 Received: from DS1PEPF0001709D.namprd05.prod.outlook.com (2603:10b6:5:333:cafe::f0) by DM6PR03CA0092.outlook.office365.com (2603:10b6:5:333::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17 via Frontend Transport; Thu, 14 Nov 2024 19:45:11 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0001709D.mail.protection.outlook.com (10.167.18.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 19:45:11 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 14 Nov 2024 13:45:06 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v11 3/9] iommu/amd: Introduce struct ivhd_dte_flags to store persistent DTE flags Date: Thu, 14 Nov 2024 19:44:30 +0000 Message-ID: <20241114194436.389961-4-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114194436.389961-1-suravee.suthikulpanit@amd.com> References: <20241114194436.389961-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709D:EE_|SJ2PR12MB9237:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a870175-7f90-4926-0c56-08dd04e4d9f5 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?EThVgURXrk77osCc6m6WYzoJiJCwq23VzmAwXb4mLfGJfw/mUEyVdn1UWUDR?= =?us-ascii?Q?2BgaCNUkalNpMvtW+g454FXMw3jexs5F/jmfms4SsNLccGsjf/pPMuI5uvn4?= =?us-ascii?Q?kE6r6li+O7eqwkGTx/8qkGSWiFKhOybH5xJ07S+3pqBxH2yRHMS7BQaWcgdn?= =?us-ascii?Q?O7By48njuaCFXaNrsXoIvPZ51WaAw1G24JoK8B78qgkEd1L+Z0jPZxLo9n4S?= =?us-ascii?Q?Ctj/s2RS5V/W8+pCZsV7/ZbXfZc+ixYdVKskRiNo2P9ewifPU6qVxGbtOYzK?= =?us-ascii?Q?gcTiDIAeHfrjtCph3zxV6SSuXFSeNLhRwROHccs8ECrzvW/qwFYjGat1pkh7?= =?us-ascii?Q?8QKjxHoaXX0lEyOWC64aJxAo3uMmqX2R6FEbTQwc2HidTa+uqAM3eLnb1bCm?= =?us-ascii?Q?xFcSuYRSB8MFYpQDaDSARO8XZUWmraktzZGiJRC90EDwhE9FST5j1xJ8B0Gw?= =?us-ascii?Q?fmbINYlexGxJXhPDsSw8Yd0rYDievqR6UpkqCDBRxYlI6bFfwHFm1KAtCWDV?= =?us-ascii?Q?6qr3pWu8tYiem2Q1U2YBCIBNqzTGXiDXr0u6RrKJ54ViympG4SlKi+TnZd8f?= =?us-ascii?Q?TEIGq1bULKwGBUDFvYFgi3o/itgvnHbhFlZMegzbidvI/rA9ErwzYdnrb1R/?= =?us-ascii?Q?DNGZ9j4K6E9txzF6ZgB0yKFtDF0uQ1aZah9ldhXZGP4bbBc7mg6KeAihwZpU?= =?us-ascii?Q?9e2UIqfb/qbj/kpbsWhugMSUq9io/s05gXFvB0m9xxbJYDVc0XUk1GoRMW8N?= =?us-ascii?Q?TirQ3sx2XEqS4OFKHZWkFyUARwgLwtmnv6UpZyyJVvtpPwB3Yp5+f9QPWdIT?= =?us-ascii?Q?jenxC3qhjkGnbuNZbdh3CBqbf3CmYBvejCHBAAbv8eKcJbkm0zGERemP5et/?= =?us-ascii?Q?MzjJy6vPMrYmmZXnkjs4RfclVpfZ77L7yCTUqLGt13YMWVRO3okO1tFvGihp?= =?us-ascii?Q?rkGopSijZIJJqnCzeUyWpZPC6CD+1EdpwjnheMwu0ELe4GsPo9jiyhgcBFMQ?= =?us-ascii?Q?BMp7XQVsfas6Cd//nrZZ37uNfSMetA9+/kRGaBtIVrj4Yy7J9g5kDgcFpyDh?= =?us-ascii?Q?+Ck3b5yjYDVTLn2vjv/rf/ajSO0pz9JjURjpolaDho5AWc1juEkWc25ysMyQ?= =?us-ascii?Q?mgwqtO2oGQlh+k75p/laZAPebGCdiNPZOaQCjTmYbKc6ZffKwPmuZmwxT4Tm?= =?us-ascii?Q?kwYPSnrQ+5Mwy880Cv3mVafnuRVJi2WkY8QCRyoyD7paANAqn0Ukb19XhjWW?= =?us-ascii?Q?Z64LrArEDO9wC+g6+TJFQ1COPD4mBxxiMGanJ9UJmhPVcBn6Lp0SOgmRxRqq?= =?us-ascii?Q?Bqoht4GfMbWDHXr/tkfkPswtHi9EtjffBcaLOsfNpRLTGOxSluYPOLvpU2tt?= =?us-ascii?Q?dF3g5hiA6WQSWj6Zp19ujCrSN8LPX8z6y0FBJ2GYKRVgarp6RA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.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: 14 Nov 2024 19:45:11.1467 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a870175-7f90-4926-0c56-08dd04e4d9f5 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0001709D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9237 Content-Type: text/plain; charset="utf-8" During early initialization, the driver parses IVRS IVHD block to get list of downstream devices along with their DTE flags (i.e INITPass, EIntPass, NMIPass, SysMgt, Lint0Pass, Lint1Pass). This information is currently store in the device DTE, and needs to be preserved when clearing and configuring each DTE, which makes it difficult to manage. Introduce struct ivhd_dte_flags to store IVHD DTE settings for a device or range of devices, which are stored in the amd_ivhd_dev_flags_list during initial IVHD parsing. Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 16 ++++ drivers/iommu/amd/init.c | 113 +++++++++++++++++++++------- 2 files changed, 100 insertions(+), 29 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index af87b1d094c1..ae5f1e031722 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -220,6 +220,8 @@ #define DEV_ENTRY_EX 0x67 #define DEV_ENTRY_SYSMGT1 0x68 #define DEV_ENTRY_SYSMGT2 0x69 +#define DTE_DATA1_SYSMGT_MASK GENMASK_ULL(41, 40) + #define DEV_ENTRY_IRQ_TBL_EN 0x80 #define DEV_ENTRY_INIT_PASS 0xb8 #define DEV_ENTRY_EINT_PASS 0xb9 @@ -516,6 +518,9 @@ extern struct kmem_cache *amd_iommu_irq_cache; #define for_each_pdom_dev_data_safe(pdom_dev_data, next, pdom) \ list_for_each_entry_safe((pdom_dev_data), (next), &pdom->dev_data_list, l= ist) =20 +#define for_each_ivhd_dte_flags(entry) \ + list_for_each_entry((entry), &amd_ivhd_dev_flags_list, list) + struct amd_iommu; struct iommu_domain; struct irq_domain; @@ -884,6 +889,17 @@ struct dev_table_entry { u64 data[4]; }; =20 +/* + * Structure to sture persistent DTE flags from IVHD + */ +struct ivhd_dte_flags { + struct list_head list; + u16 segid; + u16 devid_first; + u16 devid_last; + struct dev_table_entry dte; +}; + /* * One entry for unity mappings parsed out of the ACPI table. */ diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index c1607b29ebf4..015c9b045685 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -174,8 +174,8 @@ bool amd_iommu_snp_en; EXPORT_SYMBOL(amd_iommu_snp_en); =20 LIST_HEAD(amd_iommu_pci_seg_list); /* list of all PCI segments */ -LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the - system */ +LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the system */ +LIST_HEAD(amd_ivhd_dev_flags_list); /* list of all IVHD device entry setti= ngs */ =20 /* Number of IOMMUs present in the system */ static int amd_iommus_present; @@ -984,6 +984,14 @@ static void iommu_enable_gt(struct amd_iommu *iommu) } =20 /* sets a specific bit in the device table entry. */ +static void set_dte_bit(struct dev_table_entry *dte, u8 bit) +{ + int i =3D (bit >> 6) & 0x03; + int _bit =3D bit & 0x3f; + + dte->data[i] |=3D (1UL << _bit); +} + static void __set_dev_entry_bit(struct dev_table_entry *dev_table, u16 devid, u8 bit) { @@ -1136,6 +1144,19 @@ static bool copy_device_table(void) return true; } =20 +static bool search_ivhd_dte_flags(u16 segid, u16 first, u16 last) +{ + struct ivhd_dte_flags *e; + + for_each_ivhd_dte_flags(e) { + if ((e->segid =3D=3D segid) && + (e->devid_first =3D=3D first) && + (e->devid_last =3D=3D last)) + return true; + } + return false; +} + void amd_iommu_apply_erratum_63(struct amd_iommu *iommu, u16 devid) { int sysmgt; @@ -1151,27 +1172,66 @@ void amd_iommu_apply_erratum_63(struct amd_iommu *i= ommu, u16 devid) * This function takes the device specific flags read from the ACPI * table and sets up the device table entry with that information */ -static void __init set_dev_entry_from_acpi(struct amd_iommu *iommu, - u16 devid, u32 flags, u32 ext_flags) +static void __init +set_dev_entry_from_acpi_range(struct amd_iommu *iommu, u16 first, u16 last, + u32 flags, u32 ext_flags) { - if (flags & ACPI_DEVFLAG_INITPASS) - set_dev_entry_bit(iommu, devid, DEV_ENTRY_INIT_PASS); - if (flags & ACPI_DEVFLAG_EXTINT) - set_dev_entry_bit(iommu, devid, DEV_ENTRY_EINT_PASS); - if (flags & ACPI_DEVFLAG_NMI) - set_dev_entry_bit(iommu, devid, DEV_ENTRY_NMI_PASS); - if (flags & ACPI_DEVFLAG_SYSMGT1) - set_dev_entry_bit(iommu, devid, DEV_ENTRY_SYSMGT1); - if (flags & ACPI_DEVFLAG_SYSMGT2) - set_dev_entry_bit(iommu, devid, DEV_ENTRY_SYSMGT2); - if (flags & ACPI_DEVFLAG_LINT0) - set_dev_entry_bit(iommu, devid, DEV_ENTRY_LINT0_PASS); - if (flags & ACPI_DEVFLAG_LINT1) - set_dev_entry_bit(iommu, devid, DEV_ENTRY_LINT1_PASS); + int i; + struct dev_table_entry dte =3D {}; + + /* Parse IVHD DTE setting flags and store information */ + if (flags) { + struct ivhd_dte_flags *d; =20 - amd_iommu_apply_erratum_63(iommu, devid); + if (search_ivhd_dte_flags(iommu->pci_seg->id, first, last)) + return; =20 - amd_iommu_set_rlookup_table(iommu, devid); + d =3D kzalloc(sizeof(struct ivhd_dte_flags), GFP_KERNEL); + if (!d) + return; + + pr_debug("%s: devid range %#x:%#x\n", __func__, first, last); + + if (flags & ACPI_DEVFLAG_INITPASS) + set_dte_bit(&dte, DEV_ENTRY_INIT_PASS); + if (flags & ACPI_DEVFLAG_EXTINT) + set_dte_bit(&dte, DEV_ENTRY_EINT_PASS); + if (flags & ACPI_DEVFLAG_NMI) + set_dte_bit(&dte, DEV_ENTRY_NMI_PASS); + if (flags & ACPI_DEVFLAG_SYSMGT1) + set_dte_bit(&dte, DEV_ENTRY_SYSMGT1); + if (flags & ACPI_DEVFLAG_SYSMGT2) + set_dte_bit(&dte, DEV_ENTRY_SYSMGT2); + if (flags & ACPI_DEVFLAG_LINT0) + set_dte_bit(&dte, DEV_ENTRY_LINT0_PASS); + if (flags & ACPI_DEVFLAG_LINT1) + set_dte_bit(&dte, DEV_ENTRY_LINT1_PASS); + + /* Apply erratum 63, which needs info in initial_dte */ + if (FIELD_GET(DTE_DATA1_SYSMGT_MASK, dte.data[1]) =3D=3D 0x1) + dte.data[0] |=3D DTE_FLAG_IW; + + memcpy(&d->dte, &dte, sizeof(dte)); + d->segid =3D iommu->pci_seg->id; + d->devid_first =3D first; + d->devid_last =3D last; + list_add_tail(&d->list, &amd_ivhd_dev_flags_list); + } + + for (i =3D first; i <=3D last; i++) { + if (flags) { + struct dev_table_entry *dev_table =3D get_dev_table(iommu); + + memcpy(&dev_table[i], &dte, sizeof(dte)); + } + amd_iommu_set_rlookup_table(iommu, i); + } +} + +static void __init set_dev_entry_from_acpi(struct amd_iommu *iommu, + u16 devid, u32 flags, u32 ext_flags) +{ + set_dev_entry_from_acpi_range(iommu, devid, devid, flags, ext_flags); } =20 int __init add_special_device(u8 type, u8 id, u32 *devid, bool cmd_line) @@ -1332,9 +1392,7 @@ static int __init init_iommu_from_acpi(struct amd_iom= mu *iommu, case IVHD_DEV_ALL: =20 DUMP_printk(" DEV_ALL\t\t\tsetting: %#02x\n", e->flags); - - for (dev_i =3D 0; dev_i <=3D pci_seg->last_bdf; ++dev_i) - set_dev_entry_from_acpi(iommu, dev_i, e->flags, 0); + set_dev_entry_from_acpi_range(iommu, 0, pci_seg->last_bdf, e->flags, 0); break; case IVHD_DEV_SELECT: =20 @@ -1428,14 +1486,11 @@ static int __init init_iommu_from_acpi(struct amd_i= ommu *iommu, =20 devid =3D e->devid; for (dev_i =3D devid_start; dev_i <=3D devid; ++dev_i) { - if (alias) { + if (alias) pci_seg->alias_table[dev_i] =3D devid_to; - set_dev_entry_from_acpi(iommu, - devid_to, flags, ext_flags); - } - set_dev_entry_from_acpi(iommu, dev_i, - flags, ext_flags); } + set_dev_entry_from_acpi_range(iommu, devid_start, devid, flags, ext_fla= gs); + set_dev_entry_from_acpi(iommu, devid_to, flags, ext_flags); break; case IVHD_DEV_SPECIAL: { u8 handle, type; --=20 2.34.1 From nobody Sat Nov 23 01:44:10 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2050.outbound.protection.outlook.com [40.107.244.50]) (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 0A6DFBE4E; Thu, 14 Nov 2024 19:45:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613520; cv=fail; b=JlQparyyjfQm6Gmgxz7WTJPzbXHgSHnZIzxi9Zw+Ep3fjgoDRarLKU+vWKRydj/ceDgYzrZs8X5J3fmJaOpB81p2tMtIuSaYJRkxcCEzLWzGNUHpi+O8O5Pj79AZJyB2BtXjCWRGDj4la7WAy2xkV61mtSWfzVOeWI6ORteJcm4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613520; c=relaxed/simple; bh=aqOOkxtxrHq9FyXo0yTVnpObYgB2GADdbwg821CPCgc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mGSG1FaaqfxS4Lc25gks0d7vfOZBEPC325PYjJ85gPFMbW3anngHuMUOqp1PdeghR4mNRpjODIjQVYgKcBA7Gmz4PPdMCsPGzsVpZrWH8CECAayq4SiFFPgq0yXxqWlJKRA2Ukkx+WYNm1LYrLG1LwGlVypZsRsoa9ZQvpCbBBs= 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=3JnRGJKQ; arc=fail smtp.client-ip=40.107.244.50 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="3JnRGJKQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tTdIs4uGB9ZsnoDXnHJ1iXjgc5N9ZeA3lZe3k2bbDZVF2bSn6lkL3E+9PopSaBpqPk6lDTafKUCxnits5T4kD+RtqMPaKQC0IjSkarDE2WtZAipxSMH/04+hHIwh0MNqeeaBaydlP6hO0LkbQm+qj6kyHFGXRyjqqkyfplCvgDGUYHRU+xC5nB2q9erQm607QFY6Z9keYwwW86LGXgKnHYKkKYNnvXWv7P80kSS8+i+/6bhOWGwSGge/P0Pn5ZGbHVAdjndDcGYKbE6IUkFbkPZPO7URE0RoO6JSPRklgEZqUAspfRpaIVq98kruoK1mU4HxunjrKf8fHp4jRQiWwQ== 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=KDYxgIDGppc7nsmlPgsXp5/B7SogmpnnGXWxJ6ePU7k=; b=SXPv1ehQnuzNoxfi55INdbOK7hnCU54cothvouNk5SXQJRdCSPq9Y8ITuN1cvr0yuZMbYSRaxmAeS/OpnoSXTjFNEE68+uPXN7WPBy1OCGT3miPgVQrhOYhRnOOBVJ81zYuWOBOmdzOwt/trowYqVb+1lUxNGx6g1sqX/D/AfIvCI/vwGEhRkd/rdNmlvp+kuqRF+rCe4WXJgBgTZspU3cABR1u+mh4AaK4k0aOH3Jobz2IJ+nTn06MRTYEs10lv8gW0xFBR5D2Hd3gJMVt3RuTqTys+1w5pKqSehz76AS/4kAb1IM+ykl86zvmWaAb338rDmNkIYhTc08Vh4w0h9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KDYxgIDGppc7nsmlPgsXp5/B7SogmpnnGXWxJ6ePU7k=; b=3JnRGJKQKp03Cdr9itaRAjZI1zJD2oHbZNbElsfeVaninT4+NGeSyxWCWokDCEs2tdEE73+zkNuSlLJxdIpUI3rztpIwBiNrJg0eDm3Dai1b8G42WovWi+4X9P8KVxh2g7yFCAvBdeKMGCumXsOXLBBzJDybOSbVEwZ6I8ouSaM= Received: from SJ0PR13CA0238.namprd13.prod.outlook.com (2603:10b6:a03:2c1::33) by PH7PR12MB7820.namprd12.prod.outlook.com (2603:10b6:510:268::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.28; Thu, 14 Nov 2024 19:45:16 +0000 Received: from MWH0EPF000989EA.namprd02.prod.outlook.com (2603:10b6:a03:2c1:cafe::b7) by SJ0PR13CA0238.outlook.office365.com (2603:10b6:a03:2c1::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17 via Frontend Transport; Thu, 14 Nov 2024 19:45:16 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989EA.mail.protection.outlook.com (10.167.241.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 19:45:15 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 14 Nov 2024 13:45:10 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v11 4/9] iommu/amd: Introduce helper function to update 256-bit DTE Date: Thu, 14 Nov 2024 19:44:31 +0000 Message-ID: <20241114194436.389961-5-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114194436.389961-1-suravee.suthikulpanit@amd.com> References: <20241114194436.389961-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989EA:EE_|PH7PR12MB7820:EE_ X-MS-Office365-Filtering-Correlation-Id: d637c0c4-769c-4d4e-58b4-08dd04e4dcb5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?nhvqHUUpBSzCDqtxtRq5yp6gFZM9CYDMd5XqUqUIJq1Axux1yoFlQIXLoiE6?= =?us-ascii?Q?pxSYNeuSeb82pszz0gSPUVSs8a+DsUJQ3TSH2k7Mqm1bTnjPxEFNEkz2eSfM?= =?us-ascii?Q?0gydY5HhPc9hgy4L2DKyN0nHZY8MWCUpfNVgQihUBQtz9eThxQlAvWjt9bs6?= =?us-ascii?Q?+DP/HKZsMGDKMLEDvOMnQ1UgYmgy9kdyjKHk8J1ewKwDk8irYE1hk67E2lll?= =?us-ascii?Q?l4Av/ikUyu1Bor8i65VhwrAFO4qrYJRCcr+z2/VEXp8salcSKDMYDfpfsJj+?= =?us-ascii?Q?2HV71OD3d5BLZQxM4fyvxJAnx1JgU5+Oxu/RLfH3+rkHnnefbr6Cj6tcgPJW?= =?us-ascii?Q?ohr2oBXjwlszezdxzx9CNrNL01vBN6GPUA4eJWYaUwrKB20xhktix16ZLzHl?= =?us-ascii?Q?qGHlysZ7UhVvxytg3eFJET/uVSdTLi0yK7JJh4toIUpQXZ+BEmbev7K4k8Pj?= =?us-ascii?Q?saeGXWZl0QoW8yUwEu89kjAzJkSIEMNN0EpvWpTgASc1ITwC6d0ibkuw5MFV?= =?us-ascii?Q?Las8PYOkBIKU2nXIiNuRMD6KZWjs8asC0Tqivqq0Pxs8INkQU8UxuG8Wpb7k?= =?us-ascii?Q?kPfuPxZktFekBi+xDWWlqnLK5rUfYgbWPJtCjEAot/iJrTaBUjKJqcRQ9Uop?= =?us-ascii?Q?t75I7crb3ip13a9cpawcm9Lmj6+vIhRnnqSOU3CVXbg218IbrWN2xR6mvkCa?= =?us-ascii?Q?tDXps7PfuhqXWQH6hVLPzN4Q2yREH0u10RBMkdaNdJLPJs4nXHCoQhUT+xZ+?= =?us-ascii?Q?ehWjkXqfuEZI6Mn60OvyVSbN3wxFZ5sc1zKXM2oOTPXkL8GRslTh8YFJIO7x?= =?us-ascii?Q?h5BWsO7UCrlSfQgE2B9BBEvy480ujsSxsam5/10/BPMpgV2xsNbNkjyy8hRp?= =?us-ascii?Q?nYoirSkvPFExBj1wnseEObbqdECD6rXc5CXRy4YMBVG6zvbSkwx0aAtQKiCb?= =?us-ascii?Q?qvIxCkgPfx370knYpEiPFrsen13d61L/C2ORUXBjThhF3+xW8CW8W/L05ZcH?= =?us-ascii?Q?GilExRfjHPmXq353iIsXViwkTTzfSKs3fEPQn30shZC72rncHwU9OYCenA5M?= =?us-ascii?Q?Y+C5it91DnILrc0NjGJ2TbLDbj8afQMFWyW7jzvnyhidJ4s9cn2KpwOK6lVI?= =?us-ascii?Q?biPgGCKWJgMLJ4SQnU91qd5UCtMFz0syTiJmVG/OVxzcOaHtCzS/9Vm8XfjZ?= =?us-ascii?Q?FnrpaHA8W104+IxUHERRnBfEzAPCwpMvNYLw84QO/pShtrlqWk2s49Dnig1z?= =?us-ascii?Q?XS6Pz8+K8ELLTIXCUAmIlvZ3EnpvS3MbQ1H5zWMKtthKCzdNiEG6XYKhlEOQ?= =?us-ascii?Q?3Nhrxk2aCgjOsG1CQe8mjtIUXcd1PeXdypArR74HHZRNiHQROEIS2iRXPETa?= =?us-ascii?Q?hKaUK566ZkJkR0sJrVougg24ihPcDLcGckHdHOlzyKFtfHbmbA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(7416014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 19:45:15.6842 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d637c0c4-769c-4d4e-58b4-08dd04e4dcb5 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989EA.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7820 Content-Type: text/plain; charset="utf-8" The current implementation does not follow 128-bit write requirement to update DTE as specified in the AMD I/O Virtualization Techonology (IOMMU) Specification. Therefore, modify the struct dev_table_entry to contain union of u128 data array, and introduce a helper functions update_dte256() to update DTE using two 128-bit cmpxchg operations to update 256-bit DTE with the modified structure, and take into account the DTE[V, GV] bits when programming the DTE to ensure proper order of DTE programming and flushing. In addition, introduce a per-DTE spin_lock struct dev_data.dte_lock to provide synchronization when updating the DTE to prevent cmpxchg128 failure. Suggested-by: Jason Gunthorpe Suggested-by: Uros Bizjak Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit Acked-by: Uros Bizjak . --- drivers/iommu/amd/amd_iommu_types.h | 10 ++- drivers/iommu/amd/iommu.c | 123 ++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index ae5f1e031722..ea7922b06325 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -427,9 +427,13 @@ #define DTE_GCR3_SHIFT_C 43 =20 #define DTE_GPT_LEVEL_SHIFT 54 +#define DTE_GPT_LEVEL_MASK GENMASK_ULL(55, 54) =20 #define GCR3_VALID 0x01ULL =20 +/* DTE[128:179] | DTE[184:191] */ +#define DTE_DATA2_INTR_MASK ~GENMASK_ULL(55, 52) + #define IOMMU_PAGE_MASK (((1ULL << 52) - 1) & ~0xfffULL) #define IOMMU_PTE_PRESENT(pte) ((pte) & IOMMU_PTE_PR) #define IOMMU_PTE_DIRTY(pte) ((pte) & IOMMU_PTE_HD) @@ -842,6 +846,7 @@ struct devid_map { struct iommu_dev_data { /*Protect against attach/detach races */ struct mutex mutex; + spinlock_t dte_lock; /* DTE lock for 256-bit access */ =20 struct list_head list; /* For domain->dev_list */ struct llist_node dev_data_list; /* For global dev_data_list */ @@ -886,7 +891,10 @@ extern struct list_head amd_iommu_list; * Structure defining one entry in the device table */ struct dev_table_entry { - u64 data[4]; + union { + u64 data[4]; + u128 data128[2]; + }; }; =20 /* diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 5ce8e6504ba7..7e0b62f2268a 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -83,12 +83,125 @@ static int amd_iommu_attach_device(struct iommu_domain= *dom, static void set_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data *dev_data); =20 +static void iommu_flush_dte_sync(struct amd_iommu *iommu, u16 devid); + /*************************************************************************= *** * * Helper functions * *************************************************************************= ***/ =20 +static __always_inline void amd_iommu_atomic128_set(__int128 *ptr, __int12= 8 val) +{ + /* + * Note: + * We use arch_try_cmpxchg128_local() because: + * - Need cmpxchg16b instruction mainly for 128-bit store to DTE + * (not necessary for cmpxchg since this function is already + * protected by a spin_lock for this DTE). + * - Neither need LOCK_PREFIX nor try loop because of the spin_lock. + */ + arch_try_cmpxchg128_local(ptr, ptr, val); +} + +static void write_dte_upper128(struct dev_table_entry *ptr, struct dev_tab= le_entry *new) +{ + struct dev_table_entry old; + + old.data128[1] =3D ptr->data128[1]; + /* + * Preserve DTE_DATA2_INTR_MASK. This needs to be + * done here since it requires to be inside + * spin_lock(&dev_data->dte_lock) context. + */ + new->data[2] &=3D ~DTE_DATA2_INTR_MASK; + new->data[2] |=3D old.data[2] & DTE_DATA2_INTR_MASK; + + amd_iommu_atomic128_set(&ptr->data128[1], new->data128[1]); +} + +static void write_dte_lower128(struct dev_table_entry *ptr, struct dev_tab= le_entry *new) +{ + amd_iommu_atomic128_set(&ptr->data128[0], new->data128[0]); +} + +/* + * Note: + * IOMMU reads the entire Device Table entry in a single 256-bit transacti= on + * but the driver is programming DTE using 2 128-bit cmpxchg. So, the driv= er + * need to ensure the following: + * - DTE[V|GV] bit is being written last when setting. + * - DTE[V|GV] bit is being written first when clearing. + * + * 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) +{ + unsigned long flags; + struct dev_table_entry *dev_table =3D get_dev_table(iommu); + struct dev_table_entry *ptr =3D &dev_table[dev_data->devid]; + + spin_lock_irqsave(&dev_data->dte_lock, flags); + + if (!(ptr->data[0] & DTE_FLAG_V)) { + /* Existing DTE is not valid. */ + write_dte_upper128(ptr, new); + write_dte_lower128(ptr, new); + iommu_flush_dte_sync(iommu, dev_data->devid); + } else if (!(new->data[0] & DTE_FLAG_V)) { + /* Existing DTE is valid. New DTE is not valid. */ + write_dte_lower128(ptr, new); + write_dte_upper128(ptr, new); + iommu_flush_dte_sync(iommu, dev_data->devid); + } else if (!FIELD_GET(DTE_FLAG_GV, ptr->data[0])) { + /* + * Both DTEs are valid. + * Existing DTE has no guest page table. + */ + write_dte_upper128(ptr, new); + write_dte_lower128(ptr, new); + iommu_flush_dte_sync(iommu, dev_data->devid); + } else if (!FIELD_GET(DTE_FLAG_GV, new->data[0])) { + /* + * Both DTEs are valid. + * Existing DTE has guest page table, + * new DTE has no guest page table, + */ + write_dte_lower128(ptr, new); + write_dte_upper128(ptr, new); + iommu_flush_dte_sync(iommu, dev_data->devid); + } else if (FIELD_GET(DTE_GPT_LEVEL_MASK, ptr->data[2]) !=3D + FIELD_GET(DTE_GPT_LEVEL_MASK, new->data[2])) { + /* + * Both DTEs are valid and have guest page table, + * but have different number of levels. So, we need + * to upadte both upper and lower 128-bit value, which + * require disabling and flushing. + */ + struct dev_table_entry clear =3D {}; + + /* First disable DTE */ + write_dte_lower128(ptr, &clear); + iommu_flush_dte_sync(iommu, dev_data->devid); + + /* Then update DTE */ + write_dte_upper128(ptr, new); + write_dte_lower128(ptr, new); + iommu_flush_dte_sync(iommu, dev_data->devid); + } else { + /* + * Both DTEs are valid and have guest page table, + * and same number of levels. We just need to only + * update the lower 128-bit. So no need to disable DTE. + */ + write_dte_lower128(ptr, new); + } + + spin_unlock_irqrestore(&dev_data->dte_lock, flags); +} + static inline bool pdom_is_v2_pgtbl_mode(struct protection_domain *pdom) { return (pdom && (pdom->pd_mode =3D=3D PD_MODE_V2)); @@ -209,6 +322,7 @@ static struct iommu_dev_data *alloc_dev_data(struct amd= _iommu *iommu, u16 devid) return NULL; =20 mutex_init(&dev_data->mutex); + spin_lock_init(&dev_data->dte_lock); dev_data->devid =3D devid; ratelimit_default_init(&dev_data->rs); =20 @@ -1261,6 +1375,15 @@ static int iommu_flush_dte(struct amd_iommu *iommu, = u16 devid) return iommu_queue_command(iommu, &cmd); } =20 +static void iommu_flush_dte_sync(struct amd_iommu *iommu, u16 devid) +{ + int ret; + + ret =3D iommu_flush_dte(iommu, devid); + if (!ret) + iommu_completion_wait(iommu); +} + static void amd_iommu_flush_dte_all(struct amd_iommu *iommu) { u32 devid; --=20 2.34.1 From nobody Sat Nov 23 01:44:10 2024 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2063.outbound.protection.outlook.com [40.107.237.63]) (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 2C5761A7273; Thu, 14 Nov 2024 19:45:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613532; cv=fail; b=a0CpRAwOunWPWJv0U0qPrc7ZyrIOXLg4mHxT1K58yv8w9N5grOAAIMi32NGL82ZiVsys5IUBencArbieV5k1PJzZYqQxZj1bfKrc0rm8F1cVpBdQW035KpLjY1G4hXMAQCz9vx1V/3DBAoUdyKGRycMzx5xTmwD+Nf7lUZDpYO8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613532; c=relaxed/simple; bh=PVeFMuYQvPc4Z9EFgnRoM8UBCA5/QxHSforThYuCECE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MBVreplwOECQsVtwqvZod95k0DPBFV4OiXeuRLXhOh8NqxVYlI/ImtpVIGlG8Ybf32wmjsOj9F7yEAWNM76hvoPBbXma5h4usgO99JkkXP4fJqkSiwL3YIzHyBOMWDn1kGbGAgqSuaBH51vjYJkTVEzDZrA6kMGHQ+/+cjrrEAI= 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=iLJtgWTh; arc=fail smtp.client-ip=40.107.237.63 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="iLJtgWTh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lzO9fcF1jzt8oyWC3VjW23duUN69CRkx/ePP+eAzrSSpsc0PI8S2osc1PPedDTKgNROuEmTZK6gCBVcTpBn5S6tjgcZRV91BM/XW5QkWQ2zvtMt/R47G1JKQ9dcaCubfEzT1IWQTbYV5SKvtm7ALYRP2ZPtphpv1Tuz017XvIDNd1MNA9KDT4pHtkTfa2CuyBRPcE7+QK75IJaGz746oJ5czTEbSV3LaNwo1ZBEnz8q+TfNsAwc+RG+Um/rJOf6yVq3e0qOBYz000pCRzipbIbXuX0FwM4+zmPeiH5g33KDRgh/kVBRsx/3kAbBBCiMsJxJc0fcATgqrwCJt3prmTw== 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=jOrXtdCdL+e7Hal6X6Ahv0U5lOZOePElZBx6wpLou4A=; b=cBHEl86alFg1cyo1wLJu6QfF/92tgGjx4Lj7ohuLWJMNl3twrV3BFUdTbn/pFRRe5cZvIgj23qgY1JGSTQdS9p7kNcqmCLFKfFl1q0MzUscO9xMe1pJ2Typ1rrJJRCmag6YeCI2Z7X8+7iAQfXM2Iaij+SJqSm+wdITcOomPB117lH5U7pomTBqeiB5uWTjWafWd+Bv7w+5SbTF4QxV96562tmwj1E4HoGnlu7g/bAPu3+leXfO9DEc6vgdBKV7pelxZWybK4/44SJUi3aoEXupSqwBYqQMPhU3+V8hb27S6McPjdwu0/RtRDgD/TIlc8akaj+MUU++RL3gMcGjvSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jOrXtdCdL+e7Hal6X6Ahv0U5lOZOePElZBx6wpLou4A=; b=iLJtgWThlJG5G8wGhFq42aRZMgxm54Iiu2MC1YxGTRr5Ws6sSbO3u8hKDcoYXq/PjbmyQD1He6Hh59I2wyAqlmxr4lcO6MJwlwhB0OXSPfVEhnJ67GawTiZMXtuuucuIfpnMlJOWIaDTbo5znn65iw/GhlhMAzglVPFY/wk6JH0= Received: from BYAPR05CA0105.namprd05.prod.outlook.com (2603:10b6:a03:e0::46) by PH7PR12MB6933.namprd12.prod.outlook.com (2603:10b6:510:1b7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.28; Thu, 14 Nov 2024 19:45:20 +0000 Received: from MWH0EPF000989E6.namprd02.prod.outlook.com (2603:10b6:a03:e0:cafe::6b) by BYAPR05CA0105.outlook.office365.com (2603:10b6:a03:e0::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.15 via Frontend Transport; Thu, 14 Nov 2024 19:45:20 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989E6.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 19:45:20 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 14 Nov 2024 13:45:15 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v11 5/9] iommu/amd: Modify set_dte_entry() to use 256-bit DTE helpers Date: Thu, 14 Nov 2024 19:44:32 +0000 Message-ID: <20241114194436.389961-6-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114194436.389961-1-suravee.suthikulpanit@amd.com> References: <20241114194436.389961-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E6:EE_|PH7PR12MB6933:EE_ X-MS-Office365-Filtering-Correlation-Id: df07596d-ff36-46e4-509d-08dd04e4df73 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|1800799024|7416014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?bZXO0j/X/KApp/kDci/dhqtmt1moJu8FI+jATebkcD9QKLWJsrnbua4NIn5p?= =?us-ascii?Q?OV6YoIFfInVNEOc1hEaVrIsdvAVMMfaTvifKXIvPJaO67Qlmx8nCwi8An2HL?= =?us-ascii?Q?HUO/a1OJTebEM20LC+dTeXtuzerTfbuwKU6XhXiEE+PBOGbuaVu+lDqUU8rs?= =?us-ascii?Q?z2GuAudRIiv1UEL9LG2y5giyP+x9IhJRPVxe6/M3Ap51+EtXnmEshBXzrGts?= =?us-ascii?Q?sOmGrAWxqQgDLJ5M0U+q1rwkKLuipmJ8qdpwdXmo+SV7AOWla5dZTn9HUwUi?= =?us-ascii?Q?jcXC2NA9Aorso0Qz0UWGOI7/raghBHVRYUKTBcu/7yfWjgqXkc1I2Vs5A1pE?= =?us-ascii?Q?gA2SawDjvGin4s3yFAQJbqtMC80CSeY1oyi3kjYKHAQdqrJSSAK+dsk0tFTG?= =?us-ascii?Q?HLiyz2AGQfGauzLbOjcxlRS8+no1YiwZaqqduDY+WE73QQA46WoyVkmG9IiZ?= =?us-ascii?Q?aOL59hwLjTSRCUb6TAwHH4TLE9bCrQABhhpujaB9fgxhZuuNLTuOu5lS0YOH?= =?us-ascii?Q?nkRfOzVX8mbZgkbSkfPFoNx4urB9dhRWUPUfhUlHfzFBHxx46EDVSTxEZgrP?= =?us-ascii?Q?juZXiub/dKjSY7C9ODhibyn5xxAPGvQGL7oBRsQiWG515OrtXL0BZOnVUqqB?= =?us-ascii?Q?IWIvWsBwdYpDeUQYL/cSfj1k5/watQ99dpsrgaRyq5UHCPYUlyT5HQmIVset?= =?us-ascii?Q?n3kU6hDrG1qJkF/rt39wZUy2qQ25wu6MuxP1ZVOQfwM2RbmUVikzN705JPi8?= =?us-ascii?Q?UiSDRUne5Moe69tTFNjxJ//lzXDoakae7lmxxVengzFW5PzOjypJw468Hvy5?= =?us-ascii?Q?Y3hTFNvg0i2YKybZfRxMlWGpYlSrwS5tuoijnKlYtOGpd5Xp639bDlhXf0wM?= =?us-ascii?Q?kOSlJtqUaCUPzF48URAunTbY6SlY7FlNOfNILwlmlOueBVOu7zO1TO8/dvaa?= =?us-ascii?Q?ZVampd31zDFVdMAVqLllMfkMtN5HthYwHJzFyA4eLhfvqyB8xT/De7AdAfjX?= =?us-ascii?Q?sif/sUtaVYAcV32XXZVYBnM9kWhqmxz9lhsTloHDKhZcq6Jmv8b/XigjlRoD?= =?us-ascii?Q?OxQvC2mpWEXFu+NXlQKwjnNZohkgqa19uiqXkTscJBPR1wV6FDE3OzQRNxO8?= =?us-ascii?Q?kAt8J4rx/aIrEVP9mjiEoUaB8sdR3K/xjOlkDzn2Nso/4w9AJ1cFqCfj29+d?= =?us-ascii?Q?wjdQ+13MrZSRXCSI7KrXlDjtzI9+jnbVl0WwEDD9q2zU4KwS/sMSUmmXC+ia?= =?us-ascii?Q?9P6gzVtp7I579quN8LFChK2nIoRxDzFjWYkZ8R3G+NpmkKHIfdIS39HUo6Il?= =?us-ascii?Q?9IsP6WXFEj6zdTBiI3G9ifvEmYuGa5pNKaGH7q06LDjkyAjRpNCUtr2FoleF?= =?us-ascii?Q?Pzt2WNNnXQxgyFaZUG0wH0QRvT7SzGt0KhI/sSfwD4pP3hgHwA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(82310400026)(1800799024)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 19:45:20.2221 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df07596d-ff36-46e4-509d-08dd04e4df73 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6933 Content-Type: text/plain; charset="utf-8" Also, the set_dte_entry() is used to program several DTE fields (e.g. stage1 table, stage2 table, domain id, and etc.), which is difficult to keep track with current implementation. Therefore, separate logic for clearing DTE (i.e. make_clear_dte) and another function for setting up the GCR3 Table Root Pointer, GIOV, GV, GLX, and GuestPagingMode into another function set_dte_gcr3_table(). Signed-off-by: Suravee Suthikulpanit Reviewed-by: Jason Gunthorpe --- drivers/iommu/amd/amd_iommu.h | 2 + drivers/iommu/amd/amd_iommu_types.h | 13 +-- drivers/iommu/amd/init.c | 30 ++++++- drivers/iommu/amd/iommu.c | 129 ++++++++++++++++------------ 4 files changed, 106 insertions(+), 68 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 38509e1019e9..f9260bb8fc85 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -183,3 +183,5 @@ void amd_iommu_domain_set_pgtable(struct protection_dom= ain *domain, struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); =20 #endif + +struct dev_table_entry *amd_iommu_get_ivhd_dte_flags(u16 segid, u16 devid); diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index ea7922b06325..0bbda60d3cdc 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -409,8 +409,7 @@ #define DTE_FLAG_HAD (3ULL << 7) #define DTE_FLAG_GIOV BIT_ULL(54) #define DTE_FLAG_GV BIT_ULL(55) -#define DTE_GLX_SHIFT (56) -#define DTE_GLX_MASK (3) +#define DTE_GLX GENMASK_ULL(57, 56) #define DTE_FLAG_IR BIT_ULL(61) #define DTE_FLAG_IW BIT_ULL(62) =20 @@ -418,13 +417,9 @@ #define DTE_FLAG_MASK (0x3ffULL << 32) #define DEV_DOMID_MASK 0xffffULL =20 -#define DTE_GCR3_VAL_A(x) (((x) >> 12) & 0x00007ULL) -#define DTE_GCR3_VAL_B(x) (((x) >> 15) & 0x0ffffULL) -#define DTE_GCR3_VAL_C(x) (((x) >> 31) & 0x1fffffULL) - -#define DTE_GCR3_SHIFT_A 58 -#define DTE_GCR3_SHIFT_B 16 -#define DTE_GCR3_SHIFT_C 43 +#define DTE_GCR3_14_12 GENMASK_ULL(60, 58) +#define DTE_GCR3_30_15 GENMASK_ULL(31, 16) +#define DTE_GCR3_51_31 GENMASK_ULL(63, 43) =20 #define DTE_GPT_LEVEL_SHIFT 54 #define DTE_GPT_LEVEL_MASK GENMASK_ULL(55, 54) diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 015c9b045685..1e4b8040c374 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1089,11 +1089,9 @@ static bool __copy_device_table(struct amd_iommu *io= mmu) } /* If gcr3 table existed, mask it out */ if (old_devtb[devid].data[0] & DTE_FLAG_GV) { - tmp =3D DTE_GCR3_VAL_B(~0ULL) << DTE_GCR3_SHIFT_B; - tmp |=3D DTE_GCR3_VAL_C(~0ULL) << DTE_GCR3_SHIFT_C; + tmp =3D (DTE_GCR3_30_15 | DTE_GCR3_51_31); pci_seg->old_dev_tbl_cpy[devid].data[1] &=3D ~tmp; - tmp =3D DTE_GCR3_VAL_A(~0ULL) << DTE_GCR3_SHIFT_A; - tmp |=3D DTE_FLAG_GV; + tmp =3D (DTE_GCR3_14_12 | DTE_FLAG_GV); pci_seg->old_dev_tbl_cpy[devid].data[0] &=3D ~tmp; } } @@ -1144,6 +1142,30 @@ static bool copy_device_table(void) return true; } =20 +struct dev_table_entry *amd_iommu_get_ivhd_dte_flags(u16 segid, u16 devid) +{ + struct ivhd_dte_flags *e; + unsigned int best_len =3D UINT_MAX; + struct dev_table_entry *dte =3D NULL; + + for_each_ivhd_dte_flags(e) { + /* + * Need to go through the whole list to find the smallest range, + * which contains the devid. + */ + if ((e->segid =3D=3D segid) && + (e->devid_first <=3D devid) && (devid <=3D e->devid_last)) { + unsigned int len =3D e->devid_last - e->devid_first; + + if (len < best_len) { + dte =3D &(e->dte); + best_len =3D len; + } + } + } + return dte; +} + static bool search_ivhd_dte_flags(u16 segid, u16 first, u16 last) { struct ivhd_dte_flags *e; diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 7e0b62f2268a..cc778056bcd5 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1944,90 +1944,109 @@ int amd_iommu_clear_gcr3(struct iommu_dev_data *de= v_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. + */ +static void set_dte_gcr3_table(struct amd_iommu *iommu, + struct iommu_dev_data *dev_data, + struct dev_table_entry *target) +{ + struct gcr3_tbl_info *gcr3_info =3D &dev_data->gcr3_info; + u64 gcr3; + + if (!gcr3_info->gcr3_tbl) + return; + + pr_debug("%s: devid=3D%#x, glx=3D%#x, gcr3_tbl=3D%#llx\n", + __func__, dev_data->devid, gcr3_info->glx, + (unsigned long long)gcr3_info->gcr3_tbl); + + gcr3 =3D iommu_virt_to_phys(gcr3_info->gcr3_tbl); + + target->data[0] |=3D DTE_FLAG_GV | + FIELD_PREP(DTE_GLX, gcr3_info->glx) | + FIELD_PREP(DTE_GCR3_14_12, gcr3 >> 12); + if (pdom_is_v2_pgtbl_mode(dev_data->domain)) + target->data[0] |=3D DTE_FLAG_GIOV; + + target->data[1] |=3D FIELD_PREP(DTE_GCR3_30_15, gcr3 >> 15) | + FIELD_PREP(DTE_GCR3_51_31, gcr3 >> 31); + + /* Guest page table can only support 4 and 5 levels */ + if (amd_iommu_gpt_level =3D=3D PAGE_MODE_5_LEVEL) + target->data[2] |=3D FIELD_PREP(DTE_GPT_LEVEL_MASK, GUEST_PGTABLE_5_LEVE= L); + else + target->data[2] |=3D FIELD_PREP(DTE_GPT_LEVEL_MASK, GUEST_PGTABLE_4_LEVE= L); +} + static void set_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data *dev_data) { - u64 pte_root =3D 0; - u64 flags =3D 0; - u32 old_domid; - u16 devid =3D dev_data->devid; 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 dev_table_entry *dev_table =3D get_dev_table(iommu); struct gcr3_tbl_info *gcr3_info =3D &dev_data->gcr3_info; + struct dev_table_entry *dte =3D &get_dev_table(iommu)[dev_data->devid]; =20 if (gcr3_info && gcr3_info->gcr3_tbl) domid =3D dev_data->gcr3_info.domid; else domid =3D domain->id; =20 + make_clear_dte(dev_data, dte, &new); + if (domain->iop.mode !=3D PAGE_MODE_NONE) - pte_root =3D iommu_virt_to_phys(domain->iop.root); + new.data[0] =3D iommu_virt_to_phys(domain->iop.root); =20 - pte_root |=3D (domain->iop.mode & DEV_ENTRY_MODE_MASK) + new.data[0] |=3D (domain->iop.mode & DEV_ENTRY_MODE_MASK) << DEV_ENTRY_MODE_SHIFT; =20 - pte_root |=3D DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V; + new.data[0] |=3D DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V; =20 /* - * When SNP is enabled, Only set TV bit when IOMMU - * page translation is in use. + * 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(). */ - if (!amd_iommu_snp_en || (domid !=3D 0)) - pte_root |=3D DTE_FLAG_TV; - - flags =3D dev_table[devid].data[1]; - - if (dev_data->ats_enabled) - flags |=3D DTE_FLAG_IOTLB; + WARN_ON(amd_iommu_snp_en && (domid =3D=3D 0)); + new.data[0] |=3D DTE_FLAG_TV; =20 if (dev_data->ppr) - pte_root |=3D 1ULL << DEV_ENTRY_PPR; + new.data[0] |=3D 1ULL << DEV_ENTRY_PPR; =20 if (domain->dirty_tracking) - pte_root |=3D DTE_FLAG_HAD; - - if (gcr3_info && gcr3_info->gcr3_tbl) { - u64 gcr3 =3D iommu_virt_to_phys(gcr3_info->gcr3_tbl); - u64 glx =3D gcr3_info->glx; - u64 tmp; - - pte_root |=3D DTE_FLAG_GV; - pte_root |=3D (glx & DTE_GLX_MASK) << DTE_GLX_SHIFT; + new.data[0] |=3D DTE_FLAG_HAD; =20 - /* First mask out possible old values for GCR3 table */ - tmp =3D DTE_GCR3_VAL_B(~0ULL) << DTE_GCR3_SHIFT_B; - flags &=3D ~tmp; - - tmp =3D DTE_GCR3_VAL_C(~0ULL) << DTE_GCR3_SHIFT_C; - flags &=3D ~tmp; - - /* Encode GCR3 table into DTE */ - tmp =3D DTE_GCR3_VAL_A(gcr3) << DTE_GCR3_SHIFT_A; - pte_root |=3D tmp; - - tmp =3D DTE_GCR3_VAL_B(gcr3) << DTE_GCR3_SHIFT_B; - flags |=3D tmp; - - tmp =3D DTE_GCR3_VAL_C(gcr3) << DTE_GCR3_SHIFT_C; - flags |=3D tmp; + if (dev_data->ats_enabled) + new.data[1] |=3D DTE_FLAG_IOTLB; =20 - if (amd_iommu_gpt_level =3D=3D PAGE_MODE_5_LEVEL) { - dev_table[devid].data[2] |=3D - ((u64)GUEST_PGTABLE_5_LEVEL << DTE_GPT_LEVEL_SHIFT); - } + old_domid =3D READ_ONCE(dte->data[1]) & DEV_DOMID_MASK; + new.data[1] |=3D domid; =20 - /* GIOV is supported with V2 page table mode only */ - if (pdom_is_v2_pgtbl_mode(domain)) - pte_root |=3D DTE_FLAG_GIOV; + /* + * 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 - flags &=3D ~DEV_DOMID_MASK; - flags |=3D domid; + set_dte_gcr3_table(iommu, dev_data, &new); =20 - old_domid =3D dev_table[devid].data[1] & DEV_DOMID_MASK; - dev_table[devid].data[1] =3D flags; - dev_table[devid].data[0] =3D pte_root; + update_dte256(iommu, dev_data, &new); =20 /* * A kdump kernel might be replacing a domain ID that was copied from --=20 2.34.1 From nobody Sat Nov 23 01:44:10 2024 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2057.outbound.protection.outlook.com [40.107.223.57]) (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 CBECCBE4E; Thu, 14 Nov 2024 19:45:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613533; cv=fail; b=JPpvwBO25nn9eo6Ajxxf3cwldTCL8cztC1piHONAkCNGZ3LoJmEYUQ/6WVcr+887FXWlqTjW5e2pjOe3EsDU6r/KXyBYqOkBUc7GBRKGy4sFQgpjH/zpGPBZWBDGkFiZqeA8gK2VWgcIspcyjwFgaOcuOXRDtwlwF8aOcCe0yr0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613533; c=relaxed/simple; bh=4TMaHMTAqqp1srFkIKkt3p3hmI8c6rB+VN71d1v3dA4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=goUAZURSKO5ZuR5cOt/F+RJe71ArfARpMQcK9Vbk8I9q7kuEOWEatkNhSGquQZpN8XG4rDORI8g8dQRiEGeNvr6BH3R4za7Ad+2yWd8rgPHPkkP7t/FykRdYTfG51ahabes6EVu8OgYlw4UWvThtkDDCBrjg0r/gx+roQHYisq0= 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=VKUn1hiu; arc=fail smtp.client-ip=40.107.223.57 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="VKUn1hiu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=H1ZIyjPhp5yrAF28RvRkta1C9njK+bW1qJKussTUPLYIy7PTO1RrqzWLwEccFSPnp/sOCR54ErKCaixp6HRVjwaycOD23NRnZ/s9FhWW9ytlXTLQWMP+gJfnbX8MPt9Fra3Kg6hF9lnzFQGwTKmlIu85024E4wisAN/10US04U8wIDj4am0rhAIvf/rnE9G3R556zD27rFJWOavcGvPXablESCXezdxHsJVhvKEASZC3TV1/XjmlJBAvaW5cm651oRSORhbI8Ga9egINUgX1qhxB951Q5goiwPhqsH8ssxzhcf5cG5CEXSUAXfvAQel61aibfDWeoJZV2ExL1C8PMA== 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=fnlw9nFRMBEw7x+UvQGIppYrBwoJ/xMg/xv3jU5lR7w=; b=Cdemlud28ceJLE0G7Kos0Dmvh1a7ZwRmkwZWq6SFLMB1licoIgxAUUP3LY7bQzMnCTARHN88BwODV2QraIA9jphBTgJy6uM/IcsLdbBM/RYd0ZRCQCb1dmCbzgeY8+9h7YXAxc8Vos578VziK7LjKoNxRvVo2EwEz9N+n6qmhPpMtwlgPm0wMi4VjSopQBQSMebQJAtWS1XG70v73d1DVrOerg67pkD/qbWIgFVTGf035U5bzNX6biGZf17V8d2NAsjXceBZCBZjR9w8MvsA+0oiccOJJM9h6taLPf77DkjUt1WQdxBuzFK4+Qjmv9gayldVHdiy6iYDctR4RzGJjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fnlw9nFRMBEw7x+UvQGIppYrBwoJ/xMg/xv3jU5lR7w=; b=VKUn1hiuMgvERJim+LeyZisfE731OCy8Uey5eFdrtkgVEfY07E17+HJT0ofuGTWhoROB7DyTsZPPQA1TIE0NAr17lJqqnjcWfxQKys2CS//55bt99cBglS5+2DfJlXH+ADjDM1razzjH+kcmG4P5ap4s8MOSHyJSGpoG8nUmX5g= Received: from MW4PR03CA0247.namprd03.prod.outlook.com (2603:10b6:303:b4::12) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Thu, 14 Nov 2024 19:45:25 +0000 Received: from MWH0EPF000989E8.namprd02.prod.outlook.com (2603:10b6:303:b4:cafe::8d) by MW4PR03CA0247.outlook.office365.com (2603:10b6:303:b4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.16 via Frontend Transport; Thu, 14 Nov 2024 19:45:24 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989E8.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 19:45:24 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 14 Nov 2024 13:45:19 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v11 6/9] iommu/amd: Introduce helper function get_dte256() Date: Thu, 14 Nov 2024 19:44:33 +0000 Message-ID: <20241114194436.389961-7-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114194436.389961-1-suravee.suthikulpanit@amd.com> References: <20241114194436.389961-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E8:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: e306c839-cc00-4c98-6ec9-08dd04e4e1f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?akbxtio5oke81sZxU33Q1Qab7T+vd2XRRmEvaSGkslYxpYp9s3laDfujcjWW?= =?us-ascii?Q?MQEkPfJj0HErQ5gx9Yn5P7xRmN5xK40OKQ1ejfh/naBQiHSfqNADCOECcy84?= =?us-ascii?Q?kq9RWy4BIKbsrTWZl+yhxPPfrLufz+a4pLgP4foG9tUGXgjvTejgV+HjMeRc?= =?us-ascii?Q?kBkATtjjfq1mTpI4V/ebkoFp6rNZ0f4eweW9p5kHsTqPM50Cx29BDgfSD2BR?= =?us-ascii?Q?ScdN7JyBSPt+6IpGYi0PGcXAYqaJkG4vlylz+b4A9WqjsrpdTiqQCAtKXcut?= =?us-ascii?Q?RnGkSgvIOzZ6kxf2uIHLpj7EHQNmWBRl7qXQ4Gpln+SLukOgsf180pS4valx?= =?us-ascii?Q?JGF+PVWeVsS2yOtKa/dH5mt44reJgJkv3ASu3QlErKKlLGm5F4upirRoMGyP?= =?us-ascii?Q?ahcBIf8ROROHUwEeWzfBUQ/N6NOwy2Cufjsj5gshcFI/zD6uMqEZ2h/+p1hN?= =?us-ascii?Q?6q8VG95oYTMVQVkczjdOBVXZYqTt9efgUwLN/yQrUBxSGxkrEpkRP8RhPeGs?= =?us-ascii?Q?7QxNCWa2l9OBsUqhvXfBMVcdOunOJ/A5/vf93d/C47Bjm32EGQgRJFMaXHgJ?= =?us-ascii?Q?u6FtRQjUVRlcbyDxKn1uWErSQD8Axhc4vquB7u7EU3raapy7VmsqDCmze1TZ?= =?us-ascii?Q?FyhsfXe3f1Ghj6fYITUT4jjZEiN/rgpkimQT/i1TOcBsGgoOLi1UtP3MYWmt?= =?us-ascii?Q?09DQqtaBkjLHxtsLhdWnA8ocbNBUdc9B31lGUKmo7KMu24k1F9TvIPPG6JvS?= =?us-ascii?Q?J4zkriB3ZkVvk1d2oowTaLe02WJHU0snU/+ocl8pXwj1kEJfXNFxZTc90etG?= =?us-ascii?Q?SF4/bA17bIc6PDbq5q62sl0tXGdDBEPAARMZMcOp5jVvSNIWBHZg1gLetsW/?= =?us-ascii?Q?rUWTOPHwsGSRukPGdplJbokbrkTd9ll9Q94MxVdqdA8vrmi0HjbbAi+6ku+V?= =?us-ascii?Q?sZQIwL+CH3q91CjpM4WEtE8I6WhRe9qgHYA7OGsl5I+jqP9+YsJwOBPL2UBT?= =?us-ascii?Q?4mEakKKWt49LOMcDXELtUiEDMlhEMW6RYADsKZcXjQs6TGvo1q0DpE3D5Ql5?= =?us-ascii?Q?Ph1uWs4dvhrZKmdzxTuiu2+sY79wrJFMk/eo4raf2DSlmE0/nFhH1F2W+Neg?= =?us-ascii?Q?K7wcDxthtTWPXBlMLaDvKViuVgm3M2mm1mbGQHT/lMuFh0WD9AgyDTSyat1m?= =?us-ascii?Q?1gXJSBUazED7OFsMoSXu8fsejgd9sitl3uqIp0bkwAl6av61dL2/3R57+Ltl?= =?us-ascii?Q?+m6hnTwbfs7dgaR9T6ayeb6pRwwudgRR+wtDlxEF3ua+cda83tWtbCm/DQaK?= =?us-ascii?Q?skHn3ifUa/tdIW4k4D7WyXPQAGwXBq3rOwjFt6NwD65V+r3+eKEScq8WYMM7?= =?us-ascii?Q?SzAaWVkJTz6XoTrleabnSluK7vwXjX1cWGU3w7yadrAp5rJWGQ=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 19:45:24.4641 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e306c839-cc00-4c98-6ec9-08dd04e4e1f3 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E8.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 Content-Type: text/plain; charset="utf-8" And use it in clone_alias() along with update_dte256(). Also use get_dte256() in dump_dte_entry(). Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 62 ++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index cc778056bcd5..8f1de15c07a2 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -85,6 +85,8 @@ static void set_dte_entry(struct amd_iommu *iommu, =20 static void iommu_flush_dte_sync(struct amd_iommu *iommu, u16 devid); =20 +static struct iommu_dev_data *find_dev_data(struct amd_iommu *iommu, u16 d= evid); + /*************************************************************************= *** * * Helper functions @@ -202,6 +204,21 @@ static void update_dte256(struct amd_iommu *iommu, str= uct iommu_dev_data *dev_da spin_unlock_irqrestore(&dev_data->dte_lock, flags); } =20 +static void get_dte256(struct amd_iommu *iommu, struct iommu_dev_data *dev= _data, + struct dev_table_entry *dte) +{ + unsigned long flags; + struct dev_table_entry *ptr; + struct dev_table_entry *dev_table =3D get_dev_table(iommu); + + ptr =3D &dev_table[dev_data->devid]; + + spin_lock_irqsave(&dev_data->dte_lock, flags); + dte->data128[0] =3D ptr->data128[0]; + dte->data128[1] =3D ptr->data128[1]; + spin_unlock_irqrestore(&dev_data->dte_lock, flags); +} + static inline bool pdom_is_v2_pgtbl_mode(struct protection_domain *pdom) { return (pdom && (pdom->pd_mode =3D=3D PD_MODE_V2)); @@ -350,9 +367,11 @@ static struct iommu_dev_data *search_dev_data(struct a= md_iommu *iommu, u16 devid =20 static int clone_alias(struct pci_dev *pdev, u16 alias, void *data) { + struct dev_table_entry new; struct amd_iommu *iommu; - struct dev_table_entry *dev_table; + struct iommu_dev_data *dev_data, *alias_data; u16 devid =3D pci_dev_id(pdev); + int ret =3D 0; =20 if (devid =3D=3D alias) return 0; @@ -361,13 +380,27 @@ static int clone_alias(struct pci_dev *pdev, u16 alia= s, void *data) if (!iommu) return 0; =20 - amd_iommu_set_rlookup_table(iommu, alias); - dev_table =3D get_dev_table(iommu); - memcpy(dev_table[alias].data, - dev_table[devid].data, - sizeof(dev_table[alias].data)); + /* Copy the data from pdev */ + dev_data =3D dev_iommu_priv_get(&pdev->dev); + if (!dev_data) { + pr_err("%s : Failed to get dev_data for 0x%x\n", __func__, devid); + ret =3D -EINVAL; + goto out; + } + get_dte256(iommu, dev_data, &new); =20 - return 0; + /* Setup alias */ + alias_data =3D find_dev_data(iommu, alias); + if (!alias_data) { + pr_err("%s : Failed to get alias dev_data for 0x%x\n", __func__, alias); + ret =3D -EINVAL; + goto out; + } + update_dte256(iommu, alias_data, &new); + + amd_iommu_set_rlookup_table(iommu, alias); +out: + return ret; } =20 static void clone_aliases(struct amd_iommu *iommu, struct device *dev) @@ -640,6 +673,12 @@ static int iommu_init_device(struct amd_iommu *iommu, = struct device *dev) return -ENOMEM; =20 dev_data->dev =3D dev; + + /* + * The dev_iommu_priv_set() needes to be called before setup_aliases. + * Otherwise, subsequent call to dev_iommu_priv_get() will fail. + */ + dev_iommu_priv_set(dev, dev_data); setup_aliases(iommu, dev); =20 /* @@ -653,8 +692,6 @@ static int iommu_init_device(struct amd_iommu *iommu, s= truct device *dev) dev_data->flags =3D pdev_get_caps(to_pci_dev(dev)); } =20 - dev_iommu_priv_set(dev, dev_data); - return 0; } =20 @@ -685,10 +722,13 @@ static void iommu_ignore_device(struct amd_iommu *iom= mu, struct device *dev) static void dump_dte_entry(struct amd_iommu *iommu, u16 devid) { int i; - struct dev_table_entry *dev_table =3D get_dev_table(iommu); + struct dev_table_entry dte; + struct iommu_dev_data *dev_data =3D find_dev_data(iommu, devid); + + get_dte256(iommu, dev_data, &dte); =20 for (i =3D 0; i < 4; ++i) - pr_err("DTE[%d]: %016llx\n", i, dev_table[devid].data[i]); + pr_err("DTE[%d]: %016llx\n", i, dte.data[i]); } =20 static void dump_command(unsigned long phys_addr) --=20 2.34.1 From nobody Sat Nov 23 01:44:10 2024 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2073.outbound.protection.outlook.com [40.107.102.73]) (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 34EEF1AC884; Thu, 14 Nov 2024 19:45:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613534; cv=fail; b=okB7E1GJCeo2GNFj2FSXpjZQqcRE+df5mzhC4PG3kwRjOh9vocK/8wUjsmrdJt80KbF/StBplJkKkqXq7fux7x7OMmQsGb170EQxAlCZLFYH39L7vrlb35s3+TYjJ+ojGzIUOATWLfnJVoweiyMaTq9k1AzZAcz5m3yL/G893dU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613534; c=relaxed/simple; bh=3LutQPCRym9Ipba6rDwB+D90hnu57+hwxY48vzsEV6o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oQNC/tbHsvk7GaBaxm4EMpRnckF+JVM986/zOQcF4VnXtQQ79E8R8QgyoZwek/pLUXBq9sqYAdkhKphiwqOeCeG8MoH8PW5cqn7xuSTs6J6XSuAuEfM5xr+sAcaW9FqxZCAzcZz3jiFLc25+QRVghBH7L4ZIq7prvKJZyMMTHQs= 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=MA8FCktg; arc=fail smtp.client-ip=40.107.102.73 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="MA8FCktg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q9ByVHpCWoSVv4l9dB5dcYo9SjcykAJqg+/R5DCX8krb3r1AUu2x5/FlrjL9pAwW7KcTH2dBThrpW35W1Hdy3F+ZtKPnvTC63Hi3Wa+udpcKVkMtMrVLYP/lHczR3yfcKpzsxegOBOlAdh+h5zdV9L13Nf6Pnwlu6sZSWTbp/LnQqCKnvH/LlyTBsdoDQNm3cjjcTTXfBP9FudgmeXkGDu0GUwydVCLE8hCZHQsp7jOfWVhEfIU0fIzZyWblA427UdyETejaSiZrjEn8XHsx5Xs6LWTxuhPXljJveKnX3IBMb0vhd3EKdM8zrmWBGmKOzWk1z59IlZ0DGrW4JroTTA== 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=pRTvE9NMOR1EgcwPA4vYuGwGy/DlsU01+HLuB1/WbXo=; b=kN7aDkqn7unWGWJDZ+EX1y6pPPCr6bHDkTtpJTSAeHstfxcIOCsduQ0v1DfIFNI+JAv7IgfiBuKQf8Qztr4GuiJH66ObhOCEtBhiHCoV/fhEdpBOb7YRWuPBrhf/PPK2vMzuNJ2dKIVMa43mD50JvkFT1J3S2WFpQTkamIS88Hmv2k6CNQvMz9LhhNHF7P3CxKHWYpRAGnzIgpkT0gtU01wTwyMDgrSjpqVhwf2yFJzLJqgO69hU82mP/cN8g3fJOAFwuOgLkASWuDihu7n2sDUtDurK9d1yUZ4NYgPIdcnBAlrZJUizzx/kxVOVsIqyP0j0i8q9LHkvjZT9vN2wlw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pRTvE9NMOR1EgcwPA4vYuGwGy/DlsU01+HLuB1/WbXo=; b=MA8FCktgopmgVfafmXuEqCbkqobp9Lghvf7Z2MKBx8svUA5h3a589QC/e/lu5MOeTd9lct9BKqn+NsSIBqCjMpC/1VZgkiZxAdG2V5S3nI6RdKmRVNRx84PDb0pQQRJh0myz6DJ0vgejUNyFjet0eVcvDT9gi2umhnmt8W7pvUA= Received: from SJ0PR13CA0235.namprd13.prod.outlook.com (2603:10b6:a03:2c1::30) by IA0PR12MB8930.namprd12.prod.outlook.com (2603:10b6:208:481::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18; Thu, 14 Nov 2024 19:45:29 +0000 Received: from MWH0EPF000989EA.namprd02.prod.outlook.com (2603:10b6:a03:2c1:cafe::e5) by SJ0PR13CA0235.outlook.office365.com (2603:10b6:a03:2c1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.16 via Frontend Transport; Thu, 14 Nov 2024 19:45:29 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989EA.mail.protection.outlook.com (10.167.241.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 19:45:29 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 14 Nov 2024 13:45:23 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v11 7/9] iommu/amd: Modify clear_dte_entry() to avoid in-place update Date: Thu, 14 Nov 2024 19:44:34 +0000 Message-ID: <20241114194436.389961-8-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114194436.389961-1-suravee.suthikulpanit@amd.com> References: <20241114194436.389961-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989EA:EE_|IA0PR12MB8930:EE_ X-MS-Office365-Filtering-Correlation-Id: fbc42927-af0c-400a-7729-08dd04e4e4a9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?eLOzS9LMefEoERFXiDFWxRrX7iju2OdpHQpLxpQglkcFPSafgkObT/0fUrp3?= =?us-ascii?Q?iapJUypx//vf7NrSkT6yq2FlOwvu0VarZcAAkuCjC2FpkT40lEKPaGN+9B+S?= =?us-ascii?Q?8MKUM31z2tMRnaVaeKnnP3HxYI45UXykjhHd+Z81w5RuuK+WrUDnsjGsYWJZ?= =?us-ascii?Q?0g9Fu2nitYVg0Gogpja9tte9G22Yo0N6Sag23gDNSCpPl+yhLwPYIqwBt+PK?= =?us-ascii?Q?p5bg7ZMh8mAe0sPqpvwYljhTB5KsZ5Mvm1tWzUw/2sDC6RaXBapnow+yZBhe?= =?us-ascii?Q?g4jThM3aAsnREr91/iCKR9lA4VWyLOZl0hXo7HhfvTUvQuKvfJJP/9GCw7QB?= =?us-ascii?Q?L69KH5jWCY2o2PJZq16qV2/HPyD/UVCAomeiPgA0RbKaYw+4SQ4x07pHhRAu?= =?us-ascii?Q?v7AQi+CIhVeyCTcS/KbjF35cHPBC5CPzsJOb/h5ZATUUhLpM7NszCfPhlm8X?= =?us-ascii?Q?VVTVsM4wYXsh2bjKlh0iXvOhnfL6abzA2KROeZOHwkInCeKu3OJLG3eyQiTH?= =?us-ascii?Q?5e8zPoiwtB7SDiiQnw9+arWomsXTWgGAbAcL1Mtkkhrqb1axue5aWkgZKk+F?= =?us-ascii?Q?gGy0AY9e29UZb3vzWOtxtEuSPZHtnKvTqCCKTGtLpH8MepzePBWO6OFY0mJM?= =?us-ascii?Q?wZU3cx806AHd+4gPnrCWC60zlYOzoUCLfS6wELhEnLUIO0djsVRs6pfXTYPk?= =?us-ascii?Q?MmolDPg9TDGwhkzNPr1l5I7y2KGY0PySw7z8ovuX5qGHwm79qwO95M+RCo+P?= =?us-ascii?Q?omti+uvERBixPUh2bxCn9roxL6LH+ukg32J+srHeTVK50ehruWWa4cOpZcfG?= =?us-ascii?Q?WlrLBCTMeCW5b2aGoQfUN7taGra276/7MOe0El4PiPA2JpNGfnnJ2trDHSWI?= =?us-ascii?Q?hJblOyNgaL5weF2tt8DaEQar8eCDeA9S4kXhPbSz2iOX3TSP+K7roVctAai1?= =?us-ascii?Q?BCEc69vXZa52ACJ0/6JDQuwQyu1fv72O+lmSwDzIkbP1gVOswsM+v8aEyERz?= =?us-ascii?Q?pxtNOzLfAPVVmQV0T7o4zsJAg1b+tcYxIDfbG0TvayBtrRSMhrXdBHLuPA+L?= =?us-ascii?Q?Lu+AKNHQkAo2Yb4hyJHQeGzn0FL01He5ACEMjEuG5HmpBFL1awisa97WKkch?= =?us-ascii?Q?fstN5BIi2J9qZRrvsnL2doJ4+FFXzwcB5onzHvKRBiqxtkEASblBivHJUIVM?= =?us-ascii?Q?GmUHWz27td4DSgUrUyEXYLjmCT/u8qqpjbjSumX5f+DdrMIqxtUO+oXe8/E1?= =?us-ascii?Q?mFFRC6Y6WEySFipnkln0edIZ64kKd3xZArcrbOyWl1V+2J5sed1Gg0jsWdnd?= =?us-ascii?Q?1MXblBtOeAzSgkFPKZigf/HNilcaLVw5Iyglo7N1gTMnhVS2p3k8d1rWbZlX?= =?us-ascii?Q?XsYfxdE/2/GIZs3CYoSCmQFaOtB11wwVxiH7RR7ysjd2NjrwSg=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 19:45:29.0281 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fbc42927-af0c-400a-7729-08dd04e4e4a9 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989EA.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8930 Content-Type: text/plain; charset="utf-8" By reusing the make_clear_dte() and update_dte256(). Also, there is no need to set TV bit for non-SNP system when clearing DTE for blocked domain, and no longer need to apply erratum 63 in clear_dte() since it is already stored in struct ivhd_dte_flags and apply in set_dte_entry(). Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 8f1de15c07a2..70002fe3994f 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2098,19 +2098,16 @@ static void set_dte_entry(struct amd_iommu *iommu, } } =20 -static void clear_dte_entry(struct amd_iommu *iommu, u16 devid) +/* + * Clear DMA-remap related flags to block all DMA (blockeded domain) + */ +static void clear_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data= *dev_data) { - struct dev_table_entry *dev_table =3D get_dev_table(iommu); - - /* remove entry from the device table seen by the hardware */ - dev_table[devid].data[0] =3D DTE_FLAG_V; - - if (!amd_iommu_snp_en) - dev_table[devid].data[0] |=3D DTE_FLAG_TV; - - dev_table[devid].data[1] &=3D DTE_FLAG_MASK; + struct dev_table_entry new =3D {}; + struct dev_table_entry *dte =3D &get_dev_table(iommu)[dev_data->devid]; =20 - amd_iommu_apply_erratum_63(iommu, devid); + make_clear_dte(dev_data, dte, &new); + update_dte256(iommu, dev_data, &new); } =20 /* Update and flush DTE for the given device */ @@ -2121,7 +2118,7 @@ static void dev_update_dte(struct iommu_dev_data *dev= _data, bool set) if (set) set_dte_entry(iommu, dev_data); else - clear_dte_entry(iommu, dev_data->devid); + clear_dte_entry(iommu, dev_data); =20 clone_aliases(iommu, dev_data->dev); device_flush_dte(dev_data); --=20 2.34.1 From nobody Sat Nov 23 01:44:10 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2066.outbound.protection.outlook.com [40.107.93.66]) (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 0F8EC1ADFFD; Thu, 14 Nov 2024 19:45:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613537; cv=fail; b=kJOcGSfLB93g+7Vj7MteDuo4JZRDoW+f4EbSvc7kOmhdQkMO7uvbutpC5cELpg/AqFMGP0acIYZsCNMYTlLI8DnEIQzfSZaIhae8d2UPl/wijCMkdTqOrHlM6+ACoFZftA/PM3wKkq+ICNKohg0gv5ZY5TNyzkNSTWPAbTAqI6w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613537; c=relaxed/simple; bh=oSb3N/XXPFRcHfdk1XRU9RwQmplICbmCl3SuxQtfNd8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XpAPGsJn/J10Ttd27LOZ7qomA915XPOBYdUntx3s7u9T83Q6fvoPxJtTpzyVzfeRh3h/BQZVHPFpYi3ZHt48eeoPgL/vPAq+zp84OO8k1Ru+nzTUW9/1S8xbMJpqf+zJXXPD72yXxXU+eDOQUIIArXlADfoBKW0xmZLsCh+LHvQ= 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=CuZwM80t; arc=fail smtp.client-ip=40.107.93.66 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="CuZwM80t" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=g4D706AQy8r3gacJwWdipSDtAk/yLqRPdWVd7AhDF7gkGxPQWSjh94ex1knM2lioST4d4KsaVg1gcNVmULAW2KzRQtiN7/k12OVAwKD2kFut2zDe2OYSOCdBF2FdXPPDlow4DPShIpmcgv40v3oo7zoP/MCyk8SzvzxiD71aMqPOmHVWBr6gq5xF33GSqZiJoFWrQD3byeBJNAEXIIZZWRqtdfO9NWkVPUFpsBgKdX6G1qK5xyLXgELnEWeX0nLNI4JYEwVLiq582hniIHYYUS9TqjELItfVqdRZ4iWWiZL5F+LuTjKoh+K+/oJQT2Gwn31Shz8QP7kcTA3iNb1LsQ== 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=oaEp/0eo+Lf8t0wRv4JgBilkavW0ldXTrbiU8osfi0E=; b=Rc2frXSTd9amPhvlZ6gjuaxwFjaqgr6fnSSaP6NG4WGcBv+n99BP+BTYhtodzQPgHM1WuYw6TQ1/rSh/cnyAwX8XPf26jqvP23Vv/rlg+3pM7ugeu683Vpo8s8022rt4ZBcLoUw46r/jE/rLd8od4UtD3uqELThbkJtf9DZ8mAguNyhTdMVeBx2ZYvrQBCYj64jxnnoZsGSRIRozg3V0rATY+hosuE2Go8JFPt6zGVsBhyibR6DXWNp9A0/NP4D6xDvJ2+4Eko4aC0MCEgL/+pIwSLTCvWG5N8K9x1lGAefNq5eCDKO9qrPqzwEmk0YaMBiSkvfx87JlHAHSWZ12VQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oaEp/0eo+Lf8t0wRv4JgBilkavW0ldXTrbiU8osfi0E=; b=CuZwM80tnJCu9Ks6PajEMR8IjDYuSEBR+Ng50b+yyG9B7tA0mWnr68X1tBRfakBTaslbPDjoHBX8p1r8KP0kxM7wtn8O6hjTEfoBcb0Z0z4qQ+ycDPOq2sMIJzhOiUYYXrxIRweKre4ELMsotU+/9HIGPt+xxLHxBhI/O8qZdE8= Received: from BYAPR01CA0050.prod.exchangelabs.com (2603:10b6:a03:94::27) by DS0PR12MB7993.namprd12.prod.outlook.com (2603:10b6:8:14b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.19; Thu, 14 Nov 2024 19:45:33 +0000 Received: from MWH0EPF000989E9.namprd02.prod.outlook.com (2603:10b6:a03:94:cafe::1f) by BYAPR01CA0050.outlook.office365.com (2603:10b6:a03:94::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.16 via Frontend Transport; Thu, 14 Nov 2024 19:45: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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989E9.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 19:45:33 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 14 Nov 2024 13:45:28 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v11 8/9] iommu/amd: Lock DTE before updating the entry with WRITE_ONCE() Date: Thu, 14 Nov 2024 19:44:35 +0000 Message-ID: <20241114194436.389961-9-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114194436.389961-1-suravee.suthikulpanit@amd.com> References: <20241114194436.389961-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E9:EE_|DS0PR12MB7993:EE_ X-MS-Office365-Filtering-Correlation-Id: c2db6deb-cdc9-445d-58fd-08dd04e4e716 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Z0YBW6DPsyxMM3JFvKZd4GgMGxy1+KChGzwJO2qwVHmAbx+bUGOXTGLl7AP0?= =?us-ascii?Q?cBimyOr/6iKnULA8qJG14YzOTQM0pCTzJYdG04xo/6rANgD8vxcy5hlgzJBa?= =?us-ascii?Q?M1oA3ZRylkLmomQM6LkJYy4rWbav5GgIMmn/yimQwBODJAVLG7Evs6qHd5Dn?= =?us-ascii?Q?pZosF7K/Ye2HyhvBt/A4JC5F1e1kf72aaIjrrzJRlkq5El82xxMkGI4+0yx9?= =?us-ascii?Q?LDLIuPlDBEEYHJjD18P+yNyt9OpvDgrg0bmWUQNllzN396Xds2K1qD+2dnoV?= =?us-ascii?Q?8/Hn/HMMDd8DEM8ugnz+wqSGEzAmUavAVMnyD7jbtqpetqefln2KnIlHp0PP?= =?us-ascii?Q?Bk4TANffaE2Z6Wh6JPmncgtf0B08cm1Re8tFzl0+IWpWN8lr4HwAG4+a9c6U?= =?us-ascii?Q?huN1binnk9P+5+WKoTO3QmewfSlCy052RM21pDaycxl4n3iGc1Vo91SbaxiC?= =?us-ascii?Q?B/Bek7up6RXnsWbTg4ts4Swm4HGqny8aqgdsHVcSLM9qSR2kwNvRtxRpmBsG?= =?us-ascii?Q?o1lX89JknKxboeEE4xa6dIZjqtimCVmydbLCfobCZXZVadbmac0yYb1/svds?= =?us-ascii?Q?bgG1WhboTWJzJXXIX1kgh/qMWYpa3Cj62JlSeUUPHRF5gaESTjHkpwBEtbEL?= =?us-ascii?Q?6ZMhobmPYvwmroVhtSVE+y5BFi4570ihM16x04r4oUhSBbQQUw0USqlFiOug?= =?us-ascii?Q?4W+rBz59IRbFkXxmkrRDtjRFFCMvuIdKV4P9pG8XnUR5PDSTnqq6cx0X+XHO?= =?us-ascii?Q?k3MiCRoqufIuEGhlchDqipwRgp86KvvgMm+30dQeRnEO8ccQYOkJiiRHD61m?= =?us-ascii?Q?b7bBY3LJtT2gIM2InT77+g6MUjt1SSgdbeM16wRg62IcJCtxgIaF+/aE/t55?= =?us-ascii?Q?2BRI3EGfizIDIrZteFNY0+f8Y+Gs1VfVtzZCSiasR/ij1cjEO3T8SMWPAGDs?= =?us-ascii?Q?bNv7tNhf54hJaqWqyHBfg9vbn5CYSxL3Zb07/IxukgGPb6CgsA0j9s8k2Rbz?= =?us-ascii?Q?yAZc75lCZqzzxUI8EZDa3dK+Ho/2bZDyVzuMVKtNzV/bH6WdaQEkNx2MmZbm?= =?us-ascii?Q?0DuzMIMFeHayGIBKx6ZBdZ8q0vuNBFV+3Fxu13a/6OF5o6EyQ/f0nJljITOF?= =?us-ascii?Q?cZLgJLAB5MsWZJihyGsQAKDaYuIsG4CNAIU9ZVHF8q38mkYhBCmMQF9dM8Mh?= =?us-ascii?Q?T1hIWwzmqLgzwMhr4AeGwDE2JKeOq6SAQK2Sn+8DNva5grhLcoWxA159I4pi?= =?us-ascii?Q?hCLJeU3jnD3n/c5xA4RvFdb0cFFFvI5rmkRF+ui8HtqgDgAgWkNonSeSQjBH?= =?us-ascii?Q?/bGxQNX+wF8AjRBZSnDZXPpPNGHOjyGOXviATqe1BKufxXYea9miE+mUVse/?= =?us-ascii?Q?ee2Kgu03Efk1QVl03sf3e1OH6GedLxsQoHTDQKuyqvw6E+vTUQ=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 19:45:33.0815 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c2db6deb-cdc9-445d-58fd-08dd04e4e716 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7993 Content-Type: text/plain; charset="utf-8" When updating only within a 64-bit tuple of a DTE, just lock the DTE and use WRITE_ONCE() because it is writing to memory read back by HW. Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 1 + drivers/iommu/amd/iommu.c | 43 +++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index f9260bb8fc85..7b43894f6b90 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -185,3 +185,4 @@ struct dev_table_entry *get_dev_table(struct amd_iommu = *iommu); #endif =20 struct dev_table_entry *amd_iommu_get_ivhd_dte_flags(u16 segid, u16 devid); +struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 70002fe3994f..65225100cb23 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -347,7 +347,7 @@ static struct iommu_dev_data *alloc_dev_data(struct amd= _iommu *iommu, u16 devid) return dev_data; } =20 -static struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16= devid) +struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid) { struct iommu_dev_data *dev_data; struct llist_node *node; @@ -2838,12 +2838,12 @@ static int amd_iommu_set_dirty_tracking(struct iomm= u_domain *domain, bool enable) { struct protection_domain *pdomain =3D to_pdomain(domain); - struct dev_table_entry *dev_table; + struct dev_table_entry *dte; struct iommu_dev_data *dev_data; bool domain_flush =3D false; struct amd_iommu *iommu; unsigned long flags; - u64 pte_root; + u64 new; =20 spin_lock_irqsave(&pdomain->lock, flags); if (!(pdomain->dirty_tracking ^ enable)) { @@ -2852,16 +2852,15 @@ static int amd_iommu_set_dirty_tracking(struct iomm= u_domain *domain, } =20 list_for_each_entry(dev_data, &pdomain->dev_list, list) { + spin_lock(&dev_data->dte_lock); iommu =3D get_amd_iommu_from_dev_data(dev_data); - - dev_table =3D get_dev_table(iommu); - pte_root =3D dev_table[dev_data->devid].data[0]; - - pte_root =3D (enable ? pte_root | DTE_FLAG_HAD : - pte_root & ~DTE_FLAG_HAD); + dte =3D &get_dev_table(iommu)[dev_data->devid]; + new =3D dte->data[0]; + new =3D (enable ? new | DTE_FLAG_HAD : new & ~DTE_FLAG_HAD); + dte->data[0] =3D new; + spin_unlock(&dev_data->dte_lock); =20 /* Flush device DTE */ - dev_table[dev_data->devid].data[0] =3D pte_root; device_flush_dte(dev_data); domain_flush =3D true; } @@ -3128,17 +3127,23 @@ static void iommu_flush_irt_and_complete(struct amd= _iommu *iommu, u16 devid) static void set_dte_irq_entry(struct amd_iommu *iommu, u16 devid, struct irq_remap_table *table) { - u64 dte; - struct dev_table_entry *dev_table =3D get_dev_table(iommu); + u64 new; + struct dev_table_entry *dte =3D &get_dev_table(iommu)[devid]; + struct iommu_dev_data *dev_data =3D search_dev_data(iommu, devid); + + if (dev_data) + spin_lock(&dev_data->dte_lock); =20 - dte =3D dev_table[devid].data[2]; - dte &=3D ~DTE_IRQ_PHYS_ADDR_MASK; - dte |=3D iommu_virt_to_phys(table->table); - dte |=3D DTE_IRQ_REMAP_INTCTL; - dte |=3D DTE_INTTABLEN; - dte |=3D DTE_IRQ_REMAP_ENABLE; + new =3D READ_ONCE(dte->data[2]); + new &=3D ~DTE_IRQ_PHYS_ADDR_MASK; + new |=3D iommu_virt_to_phys(table->table); + new |=3D DTE_IRQ_REMAP_INTCTL; + new |=3D DTE_INTTABLEN; + new |=3D DTE_IRQ_REMAP_ENABLE; + WRITE_ONCE(dte->data[2], new); =20 - dev_table[devid].data[2] =3D dte; + if (dev_data) + spin_unlock(&dev_data->dte_lock); } =20 static struct irq_remap_table *get_irq_table(struct amd_iommu *iommu, u16 = devid) --=20 2.34.1 From nobody Sat Nov 23 01:44:10 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2081.outbound.protection.outlook.com [40.107.220.81]) (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 900B31AF0B2; Thu, 14 Nov 2024 19:45:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613542; cv=fail; b=DDDf6/D7WODmlrpuAu4DvdFs7c5wheUOycFxcz5gSn1ZGfG1QOWHZTNwE+LqWO5+yscPYHKjtsOFBQMiaasroC5w4riMDWQG/+n6Ao9Y2TDOzZOMJh63SncahPf042P4ExZ+EPwdPAHflxnH5Gz4DP8AhcEbbBLPZG4JKkY70es= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731613542; c=relaxed/simple; bh=pD3CmY8Vf1E5rTziOoui/AnVhcJWQmAJJ32cDLUAJww=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cNrdLnhw/2ay5vTYZOP0G1U1F+FlXSXjIL7+TllVc61II51nal5nPlpgpwVwexJIw3/3nMysMBo2fmyrC/DrGHeSbSL3pRasq5L548o/VzhL4arFBLzesRPo8rS7zB0ED2mLbUx/CbiEQeejj6CvgemdrM+AhI1R/7undrXrFsE= 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=PGDTKCju; arc=fail smtp.client-ip=40.107.220.81 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="PGDTKCju" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QM52Jfdv+aalJf4NDCgJ2vsQADj380ReqSOGtufut4MJDOctlM/0IdXapjd2m6E3pgBgjAxmT/N938eV1IQ6/mXDFNpG3Dbozop8Y075t5L+BtjIsgKHD9JAd3rK7lcP29iAoQiw0HgespC4a5n3l674SE7qhOBYJAD/VCSo/vpMGQGscMwNUh0PyEf3+Qq+moSVSrhu6wfhWit7IS84qgNI3r3GqDKFP5LRDYfoqqdqHPtzGIsiG5Tv2AWgzbUnFb07TeFK9zztvkWqoi4JcHVbwKzD/IYtu6uDd0eXFbGuoMQ8kt1aggMtxL524wVqUXlENkh9rVNjp1DcNz63rw== 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=WbvGlNcV3r/+rLNLwnQcH/ZmbvXRuw3wEjKIZO0sv+U=; b=N+BVpBntSjGQRWuFsZFk8PSjeg47CaEwXsMeZOtrS43rbEV3+dVLC2G7TuqbAe80ej3tGit8pDOL8JYPLYYgMWqcy1VnuKDUUf4UPE01pp7KPLhOAVyqVH16HZ6JKo/6TrKDWWN4uZ3nrzzE/MECNz7KnwDyKbG7+Ns4zqMfqwc+HseZbiz4FZcwDaNYTyBzaDGwz7RI7jrlzGUYhs20TqKjZTFan5h6aPUXMxQRJN2SihEPuw3SibydPLsqxeEaaygvvl+f+9cRGjbjVCPRNaJRwXsqmn/wH/8zXABltWzgxsUwzeUkfcGnF2Xlcq4kOJjxotTFTGwt8FSQx7zjiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WbvGlNcV3r/+rLNLwnQcH/ZmbvXRuw3wEjKIZO0sv+U=; b=PGDTKCju1gVsnKOefNe4eVGOC6+lgeKZbHELw4EDAMBuNwnuXBfy9SNEvOlR841IXPnpwgM4RAq+GnyYGpy+opkOFSs/1Ifyd4taTTvH2vu7yYcuQq7RilRbhpOr5edENr5o+iVNEMO6DLRY8GJ/NeDZ00IBM8JnJgwN7kI6OQ0= Received: from SJ0PR13CA0216.namprd13.prod.outlook.com (2603:10b6:a03:2c1::11) by BN5PR12MB9464.namprd12.prod.outlook.com (2603:10b6:408:2ab::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18; Thu, 14 Nov 2024 19:45:38 +0000 Received: from MWH0EPF000989EA.namprd02.prod.outlook.com (2603:10b6:a03:2c1:cafe::d7) by SJ0PR13CA0216.outlook.office365.com (2603:10b6:a03:2c1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18 via Frontend Transport; Thu, 14 Nov 2024 19:45:37 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989EA.mail.protection.outlook.com (10.167.241.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 19:45:37 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 14 Nov 2024 13:45:32 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v11 9/9] iommu/amd: Remove amd_iommu_apply_erratum_63() Date: Thu, 14 Nov 2024 19:44:36 +0000 Message-ID: <20241114194436.389961-10-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114194436.389961-1-suravee.suthikulpanit@amd.com> References: <20241114194436.389961-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989EA:EE_|BN5PR12MB9464:EE_ X-MS-Office365-Filtering-Correlation-Id: c405112a-d4e6-44e5-7bbb-08dd04e4e99b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?+/n/GOhCJtyovQXpG09Wnnq+j4va3Jek909nBGOyvAdpoPlROcxm0W+IRBA6?= =?us-ascii?Q?zmhmUMF7s3fV6E+JP3uZtL7hj2oO0mqcVAym8wN3Cjwnrm0RkgwfyNoz4XaL?= =?us-ascii?Q?/tdVkXVm1/Gy8Am2BORttoaYPgBN3/Yi0bKKNpcoovhZ7fNfx5ZrolKLj6GB?= =?us-ascii?Q?sM10su7cxmJDJub4Vpi0z5szTKWSAItcLkK1mpSyqhYqtS9pfAkkPg2uYvd9?= =?us-ascii?Q?HIZTftLV2GfwFXVn1Nj5HnIa7GW9ka0cKaKaUpxQJrnEVmWzW9XRPRUDNihw?= =?us-ascii?Q?bCPs2ESnC4bO5z+FvyKNA1yzXarE4Zhn3/sFcdxenJ/vD5/F3r24euk+aZuN?= =?us-ascii?Q?+ABXNL64sVZ2d0LmZoJplwEUNzYTT2mfyLGXoHUDzcCap2J08qANi2An54JG?= =?us-ascii?Q?xdJq+VP5bcG4DcgWOiI2nS0RZ0MEoOzu5fd2SHoBV5l4U+yFwpTiARLoNIgX?= =?us-ascii?Q?2NA5qQAhsuR/yhcHf/BMnav8qK7BjLqxPWp2VopXByx0UuKhBwh5zEzq3dqj?= =?us-ascii?Q?swqIuK/ilpDU6Gh19THn0TO36Nx25FLR+p0YVS+XB6s+dbiwu76D3S6uC+Hj?= =?us-ascii?Q?/+acu9HbAMTguq2CdTQ7KI+nlBCY4K56Zn48OwivXhA7pnT5NkkC0g5cXC+3?= =?us-ascii?Q?lSwmrjMbx7yMECgD5/Nhb/CGxHFIc54QdakA2ZwewAcBpGVCw/arMDTXncdk?= =?us-ascii?Q?FqKKcBpfqOjI3R4kmUAvBcEb6uR2UoTAS3MPorWn+UcDyvfK1ZBCC0pEVLU1?= =?us-ascii?Q?glzf+19WF6YtyyZwGykt7fnL82O5QKi+IZ9h4GgGJKQoS2YUFQXuGeuDBKSi?= =?us-ascii?Q?PlmwvycTEInP6l8JZMBBjgNVu0bwiQjpKDclZ56HYZjbd+Yp/I0U84zGRgUs?= =?us-ascii?Q?o1OviNFj9R489d0MsrupurABBDZs/53YFOFaBZHFuBlLC2uORuWYrXkHg0Sg?= =?us-ascii?Q?pPuANQhAvWfAo0g5ol/WYSGItSW7edbhm7YwVXdsPZEyup0CQGCF8dTyNB07?= =?us-ascii?Q?J9ygwUnc3Sw8DTAxjR1fdtBg8qFBhEt8Rlp7S0gfiEdR3LMfdKmY4P9q/Seq?= =?us-ascii?Q?hw58dFQDwP9GTSkb2ki4AKJnDHzXAnmiItIE3AzIygxxuIXX+S0ZCGQQP5UC?= =?us-ascii?Q?Imf+Gbkz/epF1QCtYX7MWvGqM1VeikI6umPLC7j6ROVM77Wcg/rxpkM6OWHv?= =?us-ascii?Q?CteBhH0apl89pVXJzN1pS7SM3RfK67iwJ6L9hkLeTPafyVrP2bUWG952IqF4?= =?us-ascii?Q?eiIk7aOVsLXV1ZUzLuQd9i2lC3xzzvWGAgDrrWZQkiD2qraDmjU5+mGPK4Yy?= =?us-ascii?Q?m7XxIRqlrHQsRGCvuFnyW5+tYkGt9cTSjFS5F4YvDUVVqndN0Svim78b+U45?= =?us-ascii?Q?VUYHxulTnviIVJLNPiPgrfmnPSgpXuob4MQiSotaQWRw8tx34w=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 19:45:37.3251 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c405112a-d4e6-44e5-7bbb-08dd04e4e99b 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989EA.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN5PR12MB9464 Content-Type: text/plain; charset="utf-8" Also replace __set_dev_entry_bit() with set_dte_bit() and remove unused helper functions. Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 1 - drivers/iommu/amd/init.c | 50 +++-------------------------------- 2 files changed, 3 insertions(+), 48 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 7b43894f6b90..621ffb5d8669 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -16,7 +16,6 @@ irqreturn_t amd_iommu_int_thread_evtlog(int irq, void *da= ta); irqreturn_t amd_iommu_int_thread_pprlog(int irq, void *data); irqreturn_t amd_iommu_int_thread_galog(int irq, void *data); irqreturn_t amd_iommu_int_handler(int irq, void *data); -void amd_iommu_apply_erratum_63(struct amd_iommu *iommu, u16 devid); void amd_iommu_restart_log(struct amd_iommu *iommu, const char *evt_type, u8 cntrl_intr, u8 cntrl_log, u32 status_run_mask, u32 status_overflow_mask); diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 1e4b8040c374..41294807452d 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -992,38 +992,6 @@ static void set_dte_bit(struct dev_table_entry *dte, u= 8 bit) dte->data[i] |=3D (1UL << _bit); } =20 -static void __set_dev_entry_bit(struct dev_table_entry *dev_table, - u16 devid, u8 bit) -{ - int i =3D (bit >> 6) & 0x03; - int _bit =3D bit & 0x3f; - - dev_table[devid].data[i] |=3D (1UL << _bit); -} - -static void set_dev_entry_bit(struct amd_iommu *iommu, u16 devid, u8 bit) -{ - struct dev_table_entry *dev_table =3D get_dev_table(iommu); - - return __set_dev_entry_bit(dev_table, devid, bit); -} - -static int __get_dev_entry_bit(struct dev_table_entry *dev_table, - u16 devid, u8 bit) -{ - int i =3D (bit >> 6) & 0x03; - int _bit =3D bit & 0x3f; - - return (dev_table[devid].data[i] & (1UL << _bit)) >> _bit; -} - -static int get_dev_entry_bit(struct amd_iommu *iommu, u16 devid, u8 bit) -{ - struct dev_table_entry *dev_table =3D get_dev_table(iommu); - - return __get_dev_entry_bit(dev_table, devid, bit); -} - static bool __copy_device_table(struct amd_iommu *iommu) { u64 int_ctl, int_tab_len, entry =3D 0; @@ -1179,17 +1147,6 @@ static bool search_ivhd_dte_flags(u16 segid, u16 fir= st, u16 last) return false; } =20 -void amd_iommu_apply_erratum_63(struct amd_iommu *iommu, u16 devid) -{ - int sysmgt; - - sysmgt =3D get_dev_entry_bit(iommu, devid, DEV_ENTRY_SYSMGT1) | - (get_dev_entry_bit(iommu, devid, DEV_ENTRY_SYSMGT2) << 1); - - if (sysmgt =3D=3D 0x01) - set_dev_entry_bit(iommu, devid, DEV_ENTRY_IW); -} - /* * This function takes the device specific flags read from the ACPI * table and sets up the device table entry with that information @@ -2637,9 +2594,9 @@ static void init_device_table_dma(struct amd_iommu_pc= i_seg *pci_seg) return; =20 for (devid =3D 0; devid <=3D pci_seg->last_bdf; ++devid) { - __set_dev_entry_bit(dev_table, devid, DEV_ENTRY_VALID); + set_dte_bit(&dev_table[devid], DEV_ENTRY_VALID); if (!amd_iommu_snp_en) - __set_dev_entry_bit(dev_table, devid, DEV_ENTRY_TRANSLATION); + set_dte_bit(&dev_table[devid], DEV_ENTRY_TRANSLATION); } } =20 @@ -2667,8 +2624,7 @@ static void init_device_table(void) =20 for_each_pci_segment(pci_seg) { for (devid =3D 0; devid <=3D pci_seg->last_bdf; ++devid) - __set_dev_entry_bit(pci_seg->dev_table, - devid, DEV_ENTRY_IRQ_TBL_EN); + set_dte_bit(&pci_seg->dev_table[devid], DEV_ENTRY_IRQ_TBL_EN); } } =20 --=20 2.34.1