From nobody Sun Nov 24 21:19:31 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2056.outbound.protection.outlook.com [40.107.92.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06F551C9DD8 for ; Fri, 1 Nov 2024 16:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478213; cv=fail; b=aJgEtjlOkli7ZRJC7uMWKWrV/qP+Kbc5mYWmj220tqDlSZPGHYqP6ljHG8oDQk1Wjio+Gfq6ASAsqkdERa2nfYbXVKCwNU3bWVg/GPO2OoQKSF37Ny3aQ4bgnBKzZB7lquQkRZzQ9wQ5BrcYXEiDpS6q/BvWfP8xnInEZfELl2c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478213; c=relaxed/simple; bh=I6EQiYw8K0f5jXKss9BxucItbForiWMKXniF8tpRkio=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l2DgaFgIycWjyUPh83TlHAecW+VqXEuVjFADPgqJ5tXyWqcd+oWSr89LA4trX3O2KAjqwh/iFdZKkhq6urJtQ5CegPU75TxBIUTF/0bi6jnJfhOmGNDWjPmnlofchwhbNFPt4WH+yqiPGVtGV3IDL9URgue/Zaw/77/JeeYaSg0= 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=pL5g7+G/; arc=fail smtp.client-ip=40.107.92.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="pL5g7+G/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T9CQbDOlR9vQkDc48mPzm7XyGHd10WJRkH8/I/M+AdYbFJ58FJik++LUGKBcV49vod1CH05WaxMy9F1OoSbFFHmGn2ONRuA8Pzp2TxMFGYjioo9kr9y/9IRJHNuTt6Z7VaFbqG1nm49xcUz/J3uZSCiXxbWcvaCagUg5SjTSZAuNKPt+obaDxhcZBkyuCRJOE/SMd2b96PwXe8dlmbNmLFNZtVhf9Zo0j77KFd9ig0I4xvbodSsJF/Qz/K90itP5R6PBYz1VWgowcqW+c0aje3oI8x6a6ECTfhS+sH4UjlMBS+k7u/M2nBoVocQjEA2UdtR5KHe4mUCQilydEZxM3w== 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=FrDso9ClcoqFGBxe20ZijbIvSToShbeHMUzFrhUdXEPOUsWQJ1+HvsDxO/IQNf5XXq/+qZ3MEqkCVa1jysvdhPw7naRL8AUQdX7Fa2v1v8Wt1rzHdjeEQCvXwNWX6A8da7hAx0CWcuaHOalNuZ/wgj3OVGvUBeVMgBPso0P2cdg4xglaUuWIAhQrYp/cnYL3rpZAzO6Yt17JWklGFx4n3akHbsGzoqJ6/qIkifywFgD5fKmj1SJClBgoQmdxVlwF/zjDnR1stDj77CWMUfjnM9bI+LFqgyot0dW4PjtZJ4kaKxF5EVt3J676x+pCa7MVB6fKWQ0cOaKMjFIzrJSBJA== 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=pL5g7+G/cY1mWdyK2EImVO4SzpbsTKf47cOUYru6WmG9DjC3a9iy6IWxtzk6h6JJpCa9MOmUYjo47x0+3C4vTg3YdSdZhJ7I7esb+SbVC22g/Mm8Dc0utQZZi4QPUBFCb9th0nVvlFpd+JBAAaviSQ6OZhuwQx7JVmOYEAQsQss= Received: from SA1P222CA0054.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:2d0::29) by IA0PR12MB8864.namprd12.prod.outlook.com (2603:10b6:208:485::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Fri, 1 Nov 2024 16:23:26 +0000 Received: from SN1PEPF0002636D.namprd02.prod.outlook.com (2603:10b6:806:2d0:cafe::56) by SA1P222CA0054.outlook.office365.com (2603:10b6:806:2d0::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.26 via Frontend Transport; Fri, 1 Nov 2024 16:23:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002636D.mail.protection.outlook.com (10.167.241.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23:26 +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; Fri, 1 Nov 2024 11:23:22 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v9 01/10] iommu/amd: Misc ACPI IVRS debug info clean up Date: Fri, 1 Nov 2024 16:22:55 +0000 Message-ID: <20241101162304.4688-2-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636D:EE_|IA0PR12MB8864:EE_ X-MS-Office365-Filtering-Correlation-Id: e190283b-100b-4431-df41-08dcfa918375 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?NDA4cyHbtglpAquYQMohnmcetrUjG1yN9/BRkkZ/8KDvTkJRMMHfaSpVekhx?= =?us-ascii?Q?kgiLcljgr2l4ohHfg0CARRSwik0sybPv120zERmYZ/93yj8X5co09bB0xBIo?= =?us-ascii?Q?B3R13p0Wk72QBG/3HTqkKavgHQucnzncLVwBb6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jFFI6GJcjCe+Z/4+AXIQpCHiYvIJbSbFRXu8e1w9uOXjCC+cPsNx?= =?us-ascii?Q?GmVPhdmUSx78EUt7bxRK1Ki8AvlNY+0jfT9cZBwXrol3IH0aZvsWZmkv+BwD?= =?us-ascii?Q?JN4ZF33mlKaU1wZs5isR5eToSZSVDhYJ9cJ80R1AO4fR9oImozSFn/G+qPYw?= =?us-ascii?Q?t9kY/tGxDWqCFRBQ+j66uYTkCeiQ86SOa9ocGepCzGwMw+kMnPTEgeyYv5ev?= =?us-ascii?Q?qAl50PlVNRvfJxGPU842ZCqTDGnlliu+6LdxC651M8jFBwC6fPOjTUFHHjTO?= =?us-ascii?Q?BpQDpOehlVPFb5Elpz5TExWNiLQydvUlkNyp4BOigVdWBtt2WPFrkZ4O6Rmd?= =?us-ascii?Q?sARJb5pnVAFEUP8fyjroJ9yXLqmNFpf/tVVpRb66bDmZojuzig=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)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:26.1728 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e190283b-100b-4431-df41-08dcfa918375 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: SN1PEPF0002636D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8864 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 Sun Nov 24 21:19:31 2024 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2057.outbound.protection.outlook.com [40.107.102.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 D2FD81CBE93 for ; Fri, 1 Nov 2024 16:23:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478217; cv=fail; b=ZCDNiVqHFl+Rq/JHibuIeTGKxhTpFMBW6j4S/LgVUcElJu7b1/3n09lg0f0NVD0nsYeERtk7effrotqy/KZYmE8S1vT7AJuNTjCmM9WtjEIlkfhugtu/kd1YlZUX+5c2lXQSOiNiGE6FZ0AlxJrVDVnB5UXDA3JxGX+HX0qP2oQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478217; c=relaxed/simple; bh=BsNnwUV2R/BfqocP4sWIcX7O5HMemYytLwFFbPlqykI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tsLsmyeDBlKn2q3FuQTrXxIRPgx4oWeqawsOimFz2t5699htw/r9thnf7+iEqfNBoIPT2vBRdlX5PkjyuVoFv3s/+3CkDjqUhC1D/J4qTfroznPyeFeiT9zBbwKEIsGpxP2rSLDgjF2q504mPurXiWQRM28BvbfMCuWAMGGh3u8= 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=KPbqvdZh; arc=fail smtp.client-ip=40.107.102.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="KPbqvdZh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OYDoaPdV8qv+vdQVMoPEcStzwfvQFaRPtkLjuv14t1jxjz2Sb0qBl8lFCDZB63i3S6n6JxILlZTXPMQp95wDtcmdyKI/q+07YrQhNc8e23i9Cf4Z4ePV7n6lY+9jbujuZcYL15Z6DHbPoWkmCHvnmdOGkqBtBQDAvhBsc0W58tatATMPEtbUZsvGVNHoTqRVvnEZ9Oum8hL/zA//dk0C6OSkZ23WEZ/xaiZPLZzuxiGWf5EEWK0Ly/7gQxBgFlUjJBqmwxl36YNo2Ky8htrpdAcyPlaMTvOLUoQCmSbS11KKbtQAxzGiRF2MZ8WW7faDkBhWYtMwMk7ihiBA2MEzew== 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=Y9OUPcqlO8cbXsGTMNDnMWwYx1DQNRdsSgbn253F7XunVkHdp3mJXrtnF7YL5g9hDnVRf4Dr808EX/bSGip5XASnLmkKe2Sxy1K9X21M8JOPTznVM3s7sgTzFBrZSy+cL8UkkAfCtnC4twfHsbS5yEV2xcUp1ACFdlfKtqTpMOGvUAjIJjFmLpcAe/gYJ25GHqV+5AeVHPsSsceH4P0JOeAWSXN6dDdv+pjLggYjajr5WOaYxn4eCyVM3MPzYLHBUL78NsrPW7rmdSbehzIqXyEJJ3thnhGzK2Q+N5A1gE+5meKs7g5DtwB+m5R9sKcizu8QCZpRV3UF3TfAlyIXuw== 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=KPbqvdZhP+4KPmzFW5JdV0ECZkHywPxOiCaYKtelJ8a/sIaXdG0qu9mEwhgdm6Dtp0HoXTzBYolRDHLLjZUL+B0D4TzQwB7lxLktgr6tf3Owy1LnZm1E55VXkr5RPuOAkITpD270/gLfd8o/+L+CVoTQ7aIYgS+cYJ+I2JYaJwE= Received: from SA1P222CA0043.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:2d0::17) by PH7PR12MB8178.namprd12.prod.outlook.com (2603:10b6:510:2b3::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Fri, 1 Nov 2024 16:23:30 +0000 Received: from SN1PEPF0002636D.namprd02.prod.outlook.com (2603:10b6:806:2d0:cafe::10) by SA1P222CA0043.outlook.office365.com (2603:10b6:806:2d0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.26 via Frontend Transport; Fri, 1 Nov 2024 16:23:30 +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 SN1PEPF0002636D.mail.protection.outlook.com (10.167.241.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23:30 +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; Fri, 1 Nov 2024 11:23:25 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v9 02/10] iommu/amd: Disable AMD IOMMU if CMPXCHG16B feature is not supported Date: Fri, 1 Nov 2024 16:22:56 +0000 Message-ID: <20241101162304.4688-3-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636D:EE_|PH7PR12MB8178:EE_ X-MS-Office365-Filtering-Correlation-Id: 7ed80360-4b68-4869-ff26-08dcfa9185dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?j13MmazrSh+4GzHx+bwMD6ka71rYCovNw/EvJX1YlR1jh/3ToQJRh307c6Id?= =?us-ascii?Q?DgjMud7Gtec98dMX64YYTXMl4zdG5BfnX5VIxOysQsxBvrJ//SKkVULkCJhz?= =?us-ascii?Q?asqySCGggyLwuKIN3iYojVUx/vij0P5vaRVkZDcAWzmvnVOQPYOBFVrGURXN?= =?us-ascii?Q?0b3fNWoEIBQqerGZRTk9CxhpsxqjlVNPaMx0YB15rRw30o+p6we1Z8/TzHy+?= =?us-ascii?Q?NSYrNgwiMnSsQuhdt882GmbmBAqfM7q59lKh7UehqXvzr/k6oqEh4mTz5rVp?= =?us-ascii?Q?Tz+rsLjiWsLhvSFPGCzoVm3tdxU95zJLYifNb0ND43cNbPm/3z1YEqOWNW+Y?= =?us-ascii?Q?9Dg3CDnrW5Ay6UVH9eBkXYSoMt0/mMFSOMiG1Y2Gh6WipeWsuvaYS9fdJfQr?= =?us-ascii?Q?3bsXDBgzbg3znevl3BNGU3weXPr0ws8BT5GNMXvsk0ozRefNy5Z9Mq1WvELX?= =?us-ascii?Q?SjEQhbOoENAw0H8unLmNlLRJZCKUSqxdxktn2bMAza6V4MAb+jvDH2s6sGkl?= =?us-ascii?Q?R6K6hVe7M9kTaODjJUn4mLukohkzFZL9QpUcWbEYbJsneyUxLcPMNSP7L6kN?= =?us-ascii?Q?+cnb18C1eoIKSCTi7+qPv8oVugcL+KkKCw9gxqujGsKuAg0ikPYqeBS7tMUu?= =?us-ascii?Q?+NzcwJ77Pa+4U0JreqYiCb6WrrY0odrIL7lVnsR7zJEi8nwQAdQlVjOCwZBf?= =?us-ascii?Q?Zj1vJPvaeHk8T1ZC1Pwr2tI3wea1D40band6mryTehx7csk5ERfeloTfDTgX?= =?us-ascii?Q?skToQ60MZ8VPbxL9lGYYMQ5doAxLfxw+NsZyqPvcKQp/A7L/p2DCERkrxkot?= =?us-ascii?Q?wtSVOOqv7HYzL8fkhILP6VNcKWbaDpbSFJ5Z6QE/3EFeb2cYXN5zFhAqoM7Y?= =?us-ascii?Q?7AF4DO9mrzXQYSc651XvZMwVNSmxlgiGFXrNnGQuaXyxuq2TcHtXS1oTr50D?= =?us-ascii?Q?Y+C/EqLlQ3ZRRqATAee0ArxrFlY2Txk/YsAiXHCrx1z4hkUm+rtF2Y+6FlIj?= =?us-ascii?Q?d001ZjdJS1tHYV9QUtl9UOxBE/oXMMEjoSA6pgWIZBkxDwScAqo/dh+/UhU7?= =?us-ascii?Q?MnGd7IWedd+NbCgr6EKxp4QHUwWG0oxn3WtHWuSjC3t4Zu+8PQs67nJCg44G?= =?us-ascii?Q?vy8isYxZIaRqzOe4lqhGDzlqjGfjb9pPZanAF5TsW1Y73tPi1mRUaZUGZ+Jb?= =?us-ascii?Q?y/x9WXlB+1q2mtW8dqBtaTOVGCHT8q4J1jh/iygn9X9nSAWl3kQ+wdhEtQfn?= =?us-ascii?Q?U5qmnQd/jMxUOyFy2ul0oNLvSeXYbEfEgJlAn1l2UYzElfoikmlepYaAYkha?= =?us-ascii?Q?j3sMoOfHl74M7Qo4MiDR/hG5bLmfhrrqhOOiV/mFh7vmKCCI4XDegMJyGwo4?= =?us-ascii?Q?mzzujuXK39YNtLWvCPZi/RDyKi4Hg/BK/EveOsyc2kNfGFULVg=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)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:30.1416 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7ed80360-4b68-4869-ff26-08dcfa9185dc 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: SN1PEPF0002636D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8178 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 Sun Nov 24 21:19:31 2024 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2043.outbound.protection.outlook.com [40.107.100.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 EE0EA1CCB50 for ; Fri, 1 Nov 2024 16:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478223; cv=fail; b=ceY1OcABd6lEcGz0/astAvjy5h3b3YAPCxmOTT8pjEPEU+Lr1VNUUjqIp3T6EhOaOlQOQr6Y4M+HOK/bhdJuGpFO0s58m6mSGzd2ieIFMRoAdhG7VBG1U8+mSpV5KvxCR/oiNShb4GpbqRTQlEgkvNo1EzYUyCGtP9aK6fseq7s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478223; c=relaxed/simple; bh=ZO9mKCEHnUVcv2smGEZRLFJh9CdlQX9zoJETQejkZq0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c9co+yPZuv9j80+bHY9WOm2COaQiqitcYmkvTwVimfEYJ+X75cvVvvUk3ra7OCBJU6gcVdyo1NYcTFKMzu9MdHJpa+ldvwh4tUr0+wEb2636HC9K+eCBH7pGIBVz/xSXXLI2w1t5Jm03FADBKqbfw/vKIHSF3w8pd80O8kYsWIU= 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=wa+9j0kn; arc=fail smtp.client-ip=40.107.100.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="wa+9j0kn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YE3gGFuPBdQngU0XyEGRbgnxfKtXxMlJ+keEDBBKoWsG9rJhP9cesUHhYR8+Vlp/7uDAE2vCt2KQdkLvmFGXYPczxQX7aQ2EB75zg5N0bCLTj3283n46lpCmsXIyvCfvwX5hLG9JeQ9kZGgEQ21fQThRuvo5+rIYN2DuaDdo1W5chGDDzz4Sb75pNEZOqeMBZTc3eCUZu82zLdBsaWDJNvTjdiP6i2dacmS5koNsI9JuQ3orTnc5uO/awuEZ08KMZV5IS0W/ctUvXPjkQxXqayV6XpHkLLaMDt39bZB8QdZbKLX/qOtKH0gRp0lRqYcvJRRYfkaNXOAbaVRISXb33w== 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=n9jPtNcs+tWTzm8P4fh+2iZVSqTuTyq1Q3rqecNaUQ4=; b=gxKHd4bqEixVWun+c/xxN7Adk+vVs/Qz1vlElNk4U2HUg/lKHi+6rroauA3DPM5xYIxkMQ5cRknvq8ZsCyDCYkBPbHCbgvPWGm6a5pxm6ECPzImnxE0RbzWTdAnRuVjo6JveOti47sMoVsTAkMxUB6yzXLacKtsPQLCTffHAIS/Ut+eiEEhIuoiP/ALEayY/nsILx/CNCZKEScUpOCKsBxlnU+Uy71F63k0IFn9Xl+bFXuwQA8wxxun6M+V1iUzAS8r5aj/i8pxpVYod8TfohdEgus/2vMh9h1CUAIcIW/8s0DFN6y0NeX+bVFewfklOC6o6jlgrwsUOhQCP0x26Xw== 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=n9jPtNcs+tWTzm8P4fh+2iZVSqTuTyq1Q3rqecNaUQ4=; b=wa+9j0knrLnwifZOOp1xUMMk91NQ1DdOKFLLQ+ptp9Xtbmc26Aaevnm/qD5QgBmxS4EgBC8d74S2PfdLCudOMUH+VsyeEtDs8xxWV51y0JZDJb2Gt2TaVa9Q67rdKfOYWavBTGpq1AdBTGcENRfdmAMp+G2gz2fnHJrY674Ps50= Received: from SA1P222CA0032.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:2d0::13) by DS0PR12MB9057.namprd12.prod.outlook.com (2603:10b6:8:c7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Fri, 1 Nov 2024 16:23:33 +0000 Received: from SN1PEPF0002636D.namprd02.prod.outlook.com (2603:10b6:806:2d0:cafe::8d) by SA1P222CA0032.outlook.office365.com (2603:10b6:806:2d0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.26 via Frontend Transport; Fri, 1 Nov 2024 16:23:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002636D.mail.protection.outlook.com (10.167.241.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23: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; Fri, 1 Nov 2024 11:23:29 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , "Uros Bizjak" , Suravee Suthikulpanit Subject: [PATCH v9 03/10] asm/rwonce: Introduce [READ|WRITE]_ONCE() support for __int128 Date: Fri, 1 Nov 2024 16:22:57 +0000 Message-ID: <20241101162304.4688-4-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636D:EE_|DS0PR12MB9057:EE_ X-MS-Office365-Filtering-Correlation-Id: d63ef0b2-485c-4f97-84dd-08dcfa9187e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?AS8Mi5kRnL9ykhNkc3BwivF557+YtUfw/D6zDvphpRiJ3ZnleDNZeqb191Lk?= =?us-ascii?Q?KnwndrvG1ULuKKZkXwtGKeYqO607WZEJyWU/E6A4fu3hJPjULMtIPGuQq3d3?= =?us-ascii?Q?JW9Nkpih3Lq9pIfiSqWzlDVLktEr+MH4QtMS7yU/MDTZ0GKkMOyEK+uw2L0B?= =?us-ascii?Q?rmKTrEX3esbr1UhdhPVtpjorQdt4YBWweO4qpjcuX7kxAM4sFNePGhEQvGKd?= =?us-ascii?Q?t89Jez5aGNgS8j5gizt8sRXxb2GFQPJqu/HCc3irsvqGlV8SIqBn9C/tf4+S?= =?us-ascii?Q?gt1fgFYJu4jB7o7E4yR+h5yfd7kRe7gV7dCMAIIa3vlY9+nIJ6d+MqLroL9d?= =?us-ascii?Q?8tGVCUC9nCI+uJl3M2TRbwUZh/L+8SowIg5pCpYZQ3QQrbYRswm4tELWqQKG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YQwFRzhMbdPjDEKoGC+9CW?= =?us-ascii?Q?yhr1i1eaeSSzNPlXzY46Ivk4Lwr70sOJxh/l3C4osoMxk1odSqz54isRL0Oy?= =?us-ascii?Q?nnxUtOHJJu614XB+Cubi1I7b6R2m5+BCh/2MGXQJyNb8Gruscw=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)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:33.6260 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d63ef0b2-485c-4f97-84dd-08dcfa9187e9 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: SN1PEPF0002636D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9057 Content-Type: text/plain; charset="utf-8" From: Uros Bizjak Currently, [READ|WRITE]_ONCE() do not support variable of type __int128. Re-define "__dword_type" from type "long long" to __int128 if supported. Reviewed-by: Jason Gunthorpe Signed-off-by: Uros Bizjak Signed-off-by: Suravee Suthikulpanit --- include/asm-generic/rwonce.h | 2 +- include/linux/compiler_types.h | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/rwonce.h b/include/asm-generic/rwonce.h index 8d0a6280e982..8bf942ad5ef3 100644 --- a/include/asm-generic/rwonce.h +++ b/include/asm-generic/rwonce.h @@ -33,7 +33,7 @@ * (e.g. a virtual address) and a strong prevailing wind. */ #define compiletime_assert_rwonce_type(t) \ - compiletime_assert(__native_word(t) || sizeof(t) =3D=3D sizeof(long long)= , \ + compiletime_assert(__native_word(t) || sizeof(t) =3D=3D sizeof(__dword_ty= pe), \ "Unsupported access size for {READ,WRITE}_ONCE().") =20 /* diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 1a957ea2f4fe..54b56ae25db7 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -469,6 +469,12 @@ struct ftrace_likely_data { unsigned type: (unsigned type)0, \ signed type: (signed type)0 =20 +#ifdef __SIZEOF_INT128__ +#define __dword_type __int128 +#else +#define __dword_type long long +#endif + #define __unqual_scalar_typeof(x) typeof( \ _Generic((x), \ char: (char)0, \ @@ -476,7 +482,7 @@ struct ftrace_likely_data { __scalar_type_to_expr_cases(short), \ __scalar_type_to_expr_cases(int), \ __scalar_type_to_expr_cases(long), \ - __scalar_type_to_expr_cases(long long), \ + __scalar_type_to_expr_cases(__dword_type), \ default: (x))) =20 /* Is this type a native word size -- useful for atomic operations */ --=20 2.34.1 From nobody Sun Nov 24 21:19:31 2024 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2046.outbound.protection.outlook.com [40.107.243.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D94B1CCEF0 for ; Fri, 1 Nov 2024 16:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478223; cv=fail; b=Mme1WQHnek3gfuQ//SotH7D0LhYCUOnpoNkKqnTR2DY/81LKajFIIdt/gcM1p7Ql+Mz3ReMagzWNkpfSN7cT5mPHzMiuiQprdfrQG3yfXgjD8m23CwLEwAMG8cAzqaqCUW3JYk+MxnVbD7sOmzMsRcrwrBW5WRVJ//yM7/kMNDo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478223; c=relaxed/simple; bh=jpHJ2al8FOn0Z+Q1yy1S00HSe4XZce36Tt1fSG4E2bE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MuMDo5ItSzd/+rmGgaXLynUHx0LtMDJI1eLu1819DBjyZMDCo/IOaAIn4Z6qPQphY2dscJFLTsqpRgMkyR22f8CBH7DhM6Q2XtHJzuPqFi2tZW/cQ8uVeTG+9OvE0oEN0xS5JVXBaXBReYmc0MEfZuwtB4+uhV3UyTGUaCO5AqQ= 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=k37Qd30S; arc=fail smtp.client-ip=40.107.243.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="k37Qd30S" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ybS4N7dODfz9Vzm/JrV2OzEcoZCza6IXQKq84hJ6sSap2ksqM2vW9nVbwb2uYPBkBmTUOzuw2HKtA93gyxm9zH2/wWhICOY5YQmgTx/f/Ay9BA11wtyM5TQL8liCADdxTtvSK66Kcfyhkq/MWAx8upehoyb0n+uNDCx3TALRmDVDl1vcYVeEkhTP99MrXQpRFlDyv4NYV8OvPWaEKwosEgXEy0BqkK34RsK8UuvVXNPNmBO89LCnQXF+In2hkrTEvArz7B2NztdqY29napUP3Fc0WeiYaU6ZCPoytSZXmiRO13jxDO2/0u9RwM0jNWwHNNy99eoqRdl6oZDqg57MnQ== 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=vX5wSgAcFYKqJNwqFSXnhOXviNg/7AsJCqb1AfjQeyhKyN91U+rYMqNkaHOwTJNBFhazqzp+mLmSmGJB9P6bf35i1FbP3YTgtCI/pKDP9Ad4EvmSkpAtnaFfX9XrRy5UyU6A/Ha4n/NNUVYLyqD2P9BHtWNR+mOIg+zeqQmQQ2ANT2IDCy7bt7p2h7cywirA532W7ZIcbdd5AUDhisc7iQzHH75VPU1hyCHI2UEWPCAkDApZpSplKkMuhyKspqV2AswnZ4C8jANkM6mlP1R68sJm+YYP0heg7YbniiTzJhl61RcBSYSTof4ojtFGCoHAEKdBYdVmqn2XZ9cTjon7zA== 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=k37Qd30SYxZQ3Bjq4t60CrVJvOck2lJ4syfbt3SkryuAWXDRO29o8QMXGaKPuaQVYGH4CIItq1L+bFEXXeUO0e15T8PUrr9yxZkZsxUwaLtMGSmdjBCptKjpHaAAycDENjmtug0p8JhGU1cbkdP8s/pwhlAnS5ZZsxss41MdVR0= Received: from SA1P222CA0046.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:2d0::14) by LV2PR12MB5775.namprd12.prod.outlook.com (2603:10b6:408:179::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Fri, 1 Nov 2024 16:23:37 +0000 Received: from SN1PEPF0002636D.namprd02.prod.outlook.com (2603:10b6:806:2d0:cafe::af) by SA1P222CA0046.outlook.office365.com (2603:10b6:806:2d0::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.23 via Frontend Transport; Fri, 1 Nov 2024 16:23: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 SN1PEPF0002636D.mail.protection.outlook.com (10.167.241.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23: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; Fri, 1 Nov 2024 11:23:33 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v9 04/10] iommu/amd: Introduce struct ivhd_dte_flags to store persistent DTE flags Date: Fri, 1 Nov 2024 16:22:58 +0000 Message-ID: <20241101162304.4688-5-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636D:EE_|LV2PR12MB5775:EE_ X-MS-Office365-Filtering-Correlation-Id: fd261420-818b-40a1-44da-08dcfa918a10 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?+PBsVwFLE706jnL+Wj46TWDgsVUXAnKNwbRIMhXRAJZnKOJ4CgTcSPKAzoP4?= =?us-ascii?Q?tkC01YK1ItNhnZree1WhPbOl3rWAB8BVYaVJKRhUT8jIUE9vFvzKoyUwRdd/?= =?us-ascii?Q?L1KEkqf4w+u3z7o2MNZXqE89xmoKxgA1xpMXA1fXyxOblMoLOzOStlLOJsnl?= =?us-ascii?Q?lkGQUSXeS7knqsQgOVguRtQCfbMjb57Ip0DZ7SqHMFh/0N8PbG7ToK/WhypB?= =?us-ascii?Q?64GCHEVWzGupCFhV/bw2m37cq2abmbzbizE+KXh1LB32T0HdhJ1rKSaUU0CZ?= =?us-ascii?Q?C1n0lx3A5lObra3MPHFIjWQrieulSwDzYJgewf7G+jA3q5xpJPVsfMit6uGG?= =?us-ascii?Q?vAXK2oODsY2RUolqmOWrcyBkw9npwqqcnk7EfMgDfFZqQvvYhxcyA1V5wJSk?= =?us-ascii?Q?/qdI6jzU9h5CeRVixTR8sgD0CSLNnV5rXU/y1Pyx2ntCWVi95PvDJB9NOMnV?= =?us-ascii?Q?QqxxCtVox+TlPK7JiY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?us-ascii?Q?/SZ1C41uvSiMO/71MoVIco123rqOleQpttGpCp6aMUp/ChRLJA=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)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:37.2510 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fd261420-818b-40a1-44da-08dcfa918a10 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: SN1PEPF0002636D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5775 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 Sun Nov 24 21:19:31 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2080.outbound.protection.outlook.com [40.107.94.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 4BC271CDFA7 for ; Fri, 1 Nov 2024 16:23:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478228; cv=fail; b=LFaoPYMCNm+oIJraUKYjARukF0wRvCwsqfgQeIcKuwhXAdH/kjGxS8n2zU8RAkIngQF1RdtwVVOnRUcUc504BpZbApNPTMMrwxkYCl6nFBzNo5/RTHtLCyYmnWrt68DDUZjEmZsCVD6UIM7EMruZhJ+1eh0DHSEJb42bbucUqSo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478228; c=relaxed/simple; bh=/mFjHimGdP4XkKktzu70OAi/aiI9nut7aHD3GE7T7OQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SFURhv67lGiOPjVPac5j5067qOJct244foP7UeNSpL9RhMUp0WuuPidc/xkLYEaUS70nhGGGHW717xcxfMRxeE7JqGAD8WmnrFKwQjJJ9xoT+HVUpotikh2xrAlN4ggI2oPRO4xnyTgPpWUR+9vuwADdzG4hUAAaUeR3W1mOr2U= 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=peUUk06K; arc=fail smtp.client-ip=40.107.94.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="peUUk06K" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Qx2453CZHb31Jecb9A6upNpjbGLAPo1IRCrSMYhJXjU7DtgHmX3icUgaKoJacCgjXIbEe3TX+lnewBX8F8g7bzI2wR92B7IvX/u3jzppI/Z9KrgsrMStkbPE06oSnm6SEu9TI8GrJRV31OAm6VjJK+X5oLMHJqJ/9TN96beNdpwM5yJ58UNnmmyWB4bhVg2ESfFaKcAahXsF8xzV5/L90LoyylvdhhXCOCd8sZyKf5bKGm49KHEERfHtXty3yLKXwlG6PRqTzZzbe2heHGQ2mbB4Ma4Fpy9nrbJJHuWYwL7VrDKl/Svfx/RWVk0tTx5CW3ArPol5x5qc24VmJScfKg== 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=jNQftm6NnawzT1lxhZ9Sqomg27slmZLwmsxL81yuA7s=; b=Qi055oudWAP0Wneto5MYQUumtN8DDJu7Y2v9r8Ugy+qSedLPml/BuJALnSQA+MX9HGRl427YeUJ0Hu1kNAwgsQXb2copBObDixhzA7DkETyONUclOH5W32UvEVLrQ/sGBI+jjnQH8IV4jQv2Dnj1FvZZkVfKJZstqDAF2Wr8OGw8roqF2Xg/bsUWZfCflEDGT5RS1qXU215fBfxjjj6Xzk5OwUTl2UfOQkNfMXHFktIVix6dIFrEu0Zi3E72Nl6N8+2LUjIPVZJUGK1CgTMVUnnysaVK/YA8sX5QIrPSmzd4mHLuHmyisFSrJvMb34//nhNvjPUeKQBZymUybmOffQ== 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=jNQftm6NnawzT1lxhZ9Sqomg27slmZLwmsxL81yuA7s=; b=peUUk06KWSfdoxnhtQcYfT6nuv7IGTEaVIqvO4lKsIB2Ga/dyFo1gXsDds337VNl8S5/t2cMEbcmuXuV8b1aUQ1Q3YLQRuKc3rnbGsZBVVe6hDf5lZEvq41NDOMGdgnhvLepxgxyTVZ18NNA8xPplivgA4kfHRVg3ZjQYQeD+Bg= Received: from SA0PR12CA0009.namprd12.prod.outlook.com (2603:10b6:806:6f::14) by SA1PR12MB9513.namprd12.prod.outlook.com (2603:10b6:806:45c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.23; Fri, 1 Nov 2024 16:23:40 +0000 Received: from SN1PEPF0002636C.namprd02.prod.outlook.com (2603:10b6:806:6f:cafe::ee) by SA0PR12CA0009.outlook.office365.com (2603:10b6:806:6f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.23 via Frontend Transport; Fri, 1 Nov 2024 16:23:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002636C.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.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23:40 +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; Fri, 1 Nov 2024 11:23:36 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v9 05/10] iommu/amd: Introduce helper function to update 256-bit DTE Date: Fri, 1 Nov 2024 16:22:59 +0000 Message-ID: <20241101162304.4688-6-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636C:EE_|SA1PR12MB9513:EE_ X-MS-Office365-Filtering-Correlation-Id: aa3a575c-0bad-4c27-3e7c-08dcfa918c32 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?f8ap+COvVNJLPH9eIJS1VtPjH6o/lHS2VKTwpSAqB4usV19h741DFlzLm3Uo?= =?us-ascii?Q?t43wyXsPtOE/DLu1JRztVaeBxYyOKMSVV4cEaQJWAsiMvonRlmcVlUx0RFga?= =?us-ascii?Q?cIr2cEXymBzaMxuGfmq1xUcEWfyOGydMuEcFYg19uqrmikWSviBDp3dR60QA?= =?us-ascii?Q?n+Gj4BWCDIk5nCaB2tMT0nyQWISLTpGs72lmEfQySZFlFJR3v4r0Flfyiye4?= =?us-ascii?Q?g5j82wwab7+tBVj1zSabbW5DD6v6P/b4kxbZfGObpHAc5Gz+UWVvBxCF9zNa?= =?us-ascii?Q?14HWnUtTxxMsk8zZvLsdWovRaqlZvjDwIA/omptk0ca3QGi5b2thO92L96HT?= =?us-ascii?Q?ndf1nLyMKemHKVeaNXfVgfciNdBX/zq/6GTodweg5+CJMQ93o7Z/lrCIkViw?= =?us-ascii?Q?0VdapX1xwR9G7TxmQeFIELbURl+ZKYnLV2gs2kMC3siARX+vbrVKek+MoOiw?= =?us-ascii?Q?wQaZMYS6zBFbwpClZ02Rao+2tfBF0dRVYLpfzVkOe4LukqD3MYCLlhoFiKYt?= =?us-ascii?Q?xHsRDUdq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Y2N/UNaqYxQ=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)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:40.8291 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aa3a575c-0bad-4c27-3e7c-08dcfa918c32 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: SN1PEPF0002636C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB9513 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 Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 10 ++- drivers/iommu/amd/iommu.c | 116 ++++++++++++++++++++++++++++ 2 files changed, 125 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..267bd78c6eaa 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -83,12 +83,118 @@ 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 void write_dte_upper128(struct dev_table_entry *ptr, struct dev_tab= le_entry *new) +{ + struct dev_table_entry old =3D {}; + + old.data128[1] =3D READ_ONCE(ptr->data128[1]); + do { + /* + * 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; + + /* Note: try_cmpxchg inherently update &old.data128[1] on failure */ + } while (!try_cmpxchg128(&ptr->data128[1], &old.data128[1], new->data128[= 1])); +} + +static void write_dte_lower128(struct dev_table_entry *ptr, struct dev_tab= le_entry *new) +{ + struct dev_table_entry old =3D {}; + + old.data128[0] =3D READ_ONCE(ptr->data128[0]); + do { + /* Note: try_cmpxchg inherently update &old.data128[0] on failure */ + } while (!try_cmpxchg128(&ptr->data128[0], &old.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) +{ + struct dev_table_entry *dev_table =3D get_dev_table(iommu); + struct dev_table_entry *ptr =3D &dev_table[dev_data->devid]; + + spin_lock(&dev_data->dte_lock); + + 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(&dev_data->dte_lock); +} + static inline bool pdom_is_v2_pgtbl_mode(struct protection_domain *pdom) { return (pdom && (pdom->pd_mode =3D=3D PD_MODE_V2)); @@ -209,6 +315,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 +1368,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 Sun Nov 24 21:19:31 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2051.outbound.protection.outlook.com [40.107.220.51]) (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 6F07F1CCEF0 for ; Fri, 1 Nov 2024 16:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478231; cv=fail; b=huDsTocfI9MbZ60C0f8PIJAo/TjtoLK1m1NuBoyDaVusa2aRmTHBTa0BD8ULPog9LxPMPw3ND20vgvf3GXbaziM6FVoeF4ylTwsN0PVr42gga5xyFvLq+LcDItJV3rc4xx2l7FwyGG/BqSVOWQzMR87yTIpeUBOaDVa6IehHX8w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478231; c=relaxed/simple; bh=CTyNn6UuEsfd/eaMCO+Y8I5utgTiI1c4sxdXu0ln6cg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d5k0LdGFccPY2JHfJHd3gwn8nrcGWJGEkq3HTRnQpgr5E2SvryNsKBYZmI3s3VeGU9+cDZnsO8nwGQFD1YQAxjz7PraMqO0kgVmsXoGkzGPq4iJPrxy49aQuvkJgBhqbyvcYZN0RRv2jaiy0TIKEizhRU84DORXhhYCpaDWThzY= 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=m/nM/uWm; arc=fail smtp.client-ip=40.107.220.51 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="m/nM/uWm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YbnKUhUY7fzQqOUxF8mKXa1gI1qdNVBMFzaQD5ki9R7MZVk+0k2DPaosDZjb9Vzr3c0FLNXq0w52B1KV/iF6kYGtSUtsCfG2iDhB0cogklqE7hMvF3jIptdhXFo0Evdz+5cUrssVEscXPCgOB3nvH1h75vPK+owXSw+O1VX77UySo/wdTt+0xZjD+ry/49xmZHvsk/NPXQpmyF1GmlHIouJXppCve0oLltLEjitV8rsmzBlE8WXf6VDjTvI12kupUP0ABV+BqpmG7FR29HNr3j/JsZujwoPQQ7JXgNcM15nUHd530VfWtvd9FgU/SvvhFj9y9pv0ShP954OdXDZpHg== 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=wwausMUS6exxekzBMafIONb6/OOg/bpaORs8YEY66/0=; b=KL6dLD7FFWdNtnku1YwUdHJ1Qom/oinS3+iZ9RXoXnUXMG8h2vuzoyhEt1CLRiWRQQ/A/ybYZiElkcLnfaVO71THxMnUbYOw3qxOo0loMpMqk6j33yf0H8PowLp/fF4inLqaAMXjlGEll5y1REfCHbGfx3Md9M/aUIodXStkZD+A7KCojSGLMLrQt5jyCb+5YsM8gkIW1ZoAG6/46D1pb7Brx68zPtS1WRi7oFZ55gZ8j2ggHhZj0SsSRS/BheXN3zkK4ExC+rKiost4hTMu7Im6GKGCIJLHtxdBOdi/zKmOfZTUgKoTZKT30/nSBX5M//BNlJuYHxruib3SY8pyYg== 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=wwausMUS6exxekzBMafIONb6/OOg/bpaORs8YEY66/0=; b=m/nM/uWmQbFLvId4xPhzNibB2K38PfEI8V3pyzVWSNYvKJhUBrQzHKvFFhEddougvpFsUsYuazzaCtupo+uKbTxFGJFiudbO+phXwLARKonHoD+9rGEbgW3hlydR3aON3dkZfTm3fCIMjoJWBX6K17r/isbIPoqgpzP4QSuW8Y8= Received: from SA1P222CA0011.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:22c::13) by CYYPR12MB8654.namprd12.prod.outlook.com (2603:10b6:930:c9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Fri, 1 Nov 2024 16:23:45 +0000 Received: from SN1PEPF0002636E.namprd02.prod.outlook.com (2603:10b6:806:22c:cafe::35) by SA1P222CA0011.outlook.office365.com (2603:10b6:806:22c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.23 via Frontend Transport; Fri, 1 Nov 2024 16:23:45 +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 SN1PEPF0002636E.mail.protection.outlook.com (10.167.241.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23:44 +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; Fri, 1 Nov 2024 11:23:40 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v9 06/10] iommu/amd: Modify set_dte_entry() to use 256-bit DTE helpers Date: Fri, 1 Nov 2024 16:23:00 +0000 Message-ID: <20241101162304.4688-7-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636E:EE_|CYYPR12MB8654:EE_ X-MS-Office365-Filtering-Correlation-Id: 49a936ff-7ff6-4141-8d2b-08dcfa918eab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?/IXjuMpk+mRH9sZrLHHcWNLNLCD8x2Cb7dUrB6/hCfVMnRZXvgCrrppANVul?= =?us-ascii?Q?I087Khl/QbFQ/zY0NWN2w/e+8eRYdiq3FxEXUk6U++iQzxPnwMioHPMU0/Zf?= =?us-ascii?Q?HZTJ8brWlv/ZfW2jWb3MFcaf+U8cpy5zmnUPehgXJAAKtrcRsfVnO1oFue1x?= =?us-ascii?Q?ZQlrdU8lScGZ66/PPgnqGkXtXydbevP1U9w14sKceWLiPSvTXKp4jHxlSEs+?= =?us-ascii?Q?+7KhVlDoZYaJ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= =?us-ascii?Q?+s7V4zcjf11cBxtustRgoRdXnvYCFCzyQdtPG/mi3UpIxvWrKOQbIvHKvI4E?= =?us-ascii?Q?3dyrzBNbCoJLms3VxMY9Z6YxJbXDuTJ8G2fqcJG5CfwHQFid8SQSm5mdjfM7?= =?us-ascii?Q?CUDwJvxHzEttlakGRpatw+yYguVsUad+VDLENsKMgbw9Zg3Lm6iZA90u0ZxK?= =?us-ascii?Q?h5C7979jsrXznTm9Jo64EIN425s8g/2npvfT0VypzlWfuxZLWzN/xidoE59b?= =?us-ascii?Q?mgMNCsQfqXDe8MgUmOmBoqzGNAilN4+eA92gTjG9oHT5C92dUA=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)(82310400026)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:44.9639 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 49a936ff-7ff6-4141-8d2b-08dcfa918eab 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: SN1PEPF0002636E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8654 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 267bd78c6eaa..27bda7798f0e 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1937,90 +1937,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 Sun Nov 24 21:19:31 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2049.outbound.protection.outlook.com [40.107.220.49]) (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 DF8651CEAA0 for ; Fri, 1 Nov 2024 16:23:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478235; cv=fail; b=O1H/27oyKaEtBN3peW9anoB/J2HczrAnuy/6RZyGxcT+dZJG46zFPrJhtQzKOpJY3+hMZUKdRedy92LA3/7mlw1LRGh/VPwneqeWXeOqdV1cra9Vu8AVEAZ1OjNQ4fY9k3eIgEA2b8QtyR+sc8IBZeyNWAjN4j54pkxzRgqWheE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478235; c=relaxed/simple; bh=AYR9K5N2AgCVVs/B3EKI65k6IXUb8yeoBi05gs1woq4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Pja+MKxrk3ZCAnQDz/DT8a7nxZyrKF3mO6mWbkWnIfGybvPRoOwzUPItKWJ5tZoIJ5uDxJwOaSvczDUlpTIo6eJ1TDRCgS5M0u1vKOtFkaasTz68F0oAHgj1QKfMDs57vsSERMUYeuUFY1O/ih+vK+KhA4KoKnhm0is9mMh48tk= 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=iC/YmT3h; arc=fail smtp.client-ip=40.107.220.49 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="iC/YmT3h" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oBOUGh/YO83ntpLU+yCYsqsiciUBOd/Auxx+LEXCu/v3H/4HcerYTsZYYqUyZJoN1pXe6OgFTRWcnQZ7+31DVFZl21Yqlukro2iKSefLN4Cyvq1o70j7RP4oN0gkJ/rpCV73zG5ME9w+pfgrvn94MMR9MvDIptKqdys7PPoTsp7o3ZwFiRK6Yx4fA5fgApgB2lbzNLljaJEaEAd3Hx/2nO+L+AGJaocx+SVh1//d3RFk/t0fS4tGXVXB/N9FAHLTkA4nIJ7ycXsApsLqsoZhxSTucT72VmXTozOB0XNFR43cIj/A0QYjh6GRS1ihZk87Gcf9M1DNK/jZTbOZC8qeYQ== 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=wpPwrNHju5DSUGALjPGSnzKUyLP7MYHq/dZto7gcJus=; b=i17KUOOoxtdPM8bR8RVEX1+PtNwR+FAZa1ogrDIrKVfD2w/L1PWWrzh0zmGjPmiJrohEs83pqOLL7oq50iRHXO2KGBiEbrLD6p7hCv+EGAJGJV0BNiXTErzXvotc4bV+uCsdpvr7x+/DGxzS1tvw8evoFvCd1QpRifgEVf4gORdHTm/ujHtX36jFreuyHBPli9yOJEfkEfZMvx0uhKeTTofwcyTjG46ge9LQOmGUx7OZmIRS3N2epfH+e6c/KT9tLTO/I9Z5btFebOXMb9dykpnHt53STMaX/l2Ynz+SioMoegh0YHWNv+I1SNH/Kvvj3WFWvAMOafTFcv9vOVo+Eg== 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=wpPwrNHju5DSUGALjPGSnzKUyLP7MYHq/dZto7gcJus=; b=iC/YmT3he02BjroqkRI3yK0wgLouYx3IZWja+0GgxZZzdQjK8Fgzo+fLWjYMAeefg/lJ5VAYZbn5nrIEMFvdzrmyMRS8JbP1nFghjr7SN57PGDXVxsPxS0FljWDtdNgu5mOTSittsdiz/YTqDREYfAE5OL8711uvRJQVOF5LA5E= Received: from MW4PR03CA0189.namprd03.prod.outlook.com (2603:10b6:303:b8::14) by SA1PR12MB8859.namprd12.prod.outlook.com (2603:10b6:806:37c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.26; Fri, 1 Nov 2024 16:23:49 +0000 Received: from SN1PEPF00026368.namprd02.prod.outlook.com (2603:10b6:303:b8:cafe::63) by MW4PR03CA0189.outlook.office365.com (2603:10b6:303:b8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.35 via Frontend Transport; Fri, 1 Nov 2024 16:23:48 +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 SN1PEPF00026368.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.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23:48 +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; Fri, 1 Nov 2024 11:23:44 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v9 07/10] iommu/amd: Introduce helper function get_dte256() Date: Fri, 1 Nov 2024 16:23:01 +0000 Message-ID: <20241101162304.4688-8-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00026368:EE_|SA1PR12MB8859:EE_ X-MS-Office365-Filtering-Correlation-Id: 0849c8fb-a46a-4f24-fc15-08dcfa9190a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?5J+rx9QTZLmL5aFcZnGvACYXEovzT2pS5lX2otqT4cnx/B++CFQ/L75Ltyxd?= =?us-ascii?Q?AzF97Zb6spb9LkzDQlVozV+n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us-ascii?Q?oy0R1yfGSwuHwM6dpHeCs+a6IibpaDlCMJOvFkODqIc52cv9xsuNbbnqXWps?= =?us-ascii?Q?NHklD0xg9lLTrxWOId0MfJMolO4p7RTISflEZqUXhXZNLB6vGplJIOKGapl0?= =?us-ascii?Q?4ou64kavayQhWCeLA7Jtzq3wqTqj72JUrp1UaiPtaWijFS6Z+GLGUjWVAmTk?= =?us-ascii?Q?t8oqNFMskYlPSnXQmB1cfnSZNvcw3qwfp5X8anxWsUVbEQ6VUnp800xEsrPU?= =?us-ascii?Q?YIjOA3aT3RVNIYHLyWD+CdKECwzEvetBN64mUOEf4a03FpZjjxhoXZhdPRgi?= =?us-ascii?Q?mplsn/djyZDlOSaQq7RB0JO68TVOGXqMDP4a5pMqWZl2HX6OFc795gkd47Bq?= =?us-ascii?Q?bzTtUK0O/cZQNJ9LrMFQOj6oHBpyHmprrOJ+5mYLvwilP1pWI5gJc7T5FYPm?= =?us-ascii?Q?XBfuq1Sa+kR6cG4rkQXlltAUEYv0zCBgU2KZ31NQa+on8IMCGw=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)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:48.2501 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0849c8fb-a46a-4f24-fc15-08dcfa9190a0 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: SN1PEPF00026368.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8859 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 | 61 ++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 27bda7798f0e..4151225b4245 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 @@ -195,6 +197,20 @@ static void update_dte256(struct amd_iommu *iommu, str= uct iommu_dev_data *dev_da spin_unlock(&dev_data->dte_lock); } =20 +static void get_dte256(struct amd_iommu *iommu, struct iommu_dev_data *dev= _data, + struct dev_table_entry *dte) +{ + 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(&dev_data->dte_lock); + dte->data128[0] =3D READ_ONCE(ptr->data128[0]); + dte->data128[1] =3D READ_ONCE(ptr->data128[1]); + spin_unlock(&dev_data->dte_lock); +} + static inline bool pdom_is_v2_pgtbl_mode(struct protection_domain *pdom) { return (pdom && (pdom->pd_mode =3D=3D PD_MODE_V2)); @@ -343,9 +359,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; @@ -354,13 +372,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) @@ -633,6 +665,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 /* @@ -646,8 +684,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 @@ -678,10 +714,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 Sun Nov 24 21:19:31 2024 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2086.outbound.protection.outlook.com [40.107.243.86]) (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 322761CEE84 for ; Fri, 1 Nov 2024 16:23:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478240; cv=fail; b=R9K9x4q8gbogQcMo8/9aAQVKd994XLXlfQ8Vy/lS4PCz4NpAr3PhnXulnQzZ65ygDL+ZKFjXNwEbKZDP/xrMEDYwNQtgpf0mYxMI98NFpHsO2i1KBg6sXYFJ10pZQL8563LLe2lh9Eq0bMDWL4/+LUN+jPigOpc1xTeTxAa3jEI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478240; c=relaxed/simple; bh=p3BCtLShNRmmdDWXsbtOT+jScSArtWp4V+ODmtxuuto=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Piej/yOZ7tMIck3R9RvcoOzvT2d/dr9saymDAf7x21W9fdL6rGcVh4VyIKiUUm/P2NHEF8/OFQ99vq9dWittcAKCARrhQ8p7OELLCvcsksbxFVy/udVu35A6yVrEAkg7WkH3u3xxvJnYx3ygef/wsO3Js36UQfp9rBAP7DlTsXM= 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=4PiQlBeG; arc=fail smtp.client-ip=40.107.243.86 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="4PiQlBeG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fsB7m2DCgh8IKc3Ez6TkkI+jMMKypv1m/8IpOUp5sJ+/H9JPngRNrJkmRJOT4WCaflbZOZ11mcx3OWAgHXg/AIkRManN0CB0uDGZGWaFGQnqqJomHIkmuAew/YQl+6fBWgIe9LA/6a81UpR5xKN6EiobFyUfUEwJgWyV3ZEkgkRMiWKurA+lXk4GQQf/JbQ0jRx5bLqJ9RTFY+izs6/UYXBLmuYrIGMlD7ZlN/MR5EQGazeBA9l4JO0tF85gGdT5vdnwwClX9/9nYwKC+TAgSviiFUGTJCsP/dXUTNpYlT1qohBIKmSK+F9RWrXR/YHL/p7Il1S1ArnTvnS7yUVNgQ== 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=7u8f5rQEZyGNdhnYsRxE4BU9KsFOQkkJi6gz/TmPO9I=; b=RwOb2E6Tsi1VA00YFyEBAsflHowGLGuar/jiINe8FxyAaaXGU9Y95nB6eqm5bQudH47oNSOcfJk77WPDIpEBY5j6+2v2zMzS9sJBs2B7JWqllcUR4to29/DG3G6o1fkvS4PES6XLRaHmFoOvxPPtjJeM2tN/RiiiBWGB9783yxMgt6wTTChek0wUTc41HUbgC4R5OMiKQr5BhjhsGrS7osaW2GAc5ea2Zx5IRTOFT9wFezQ8pa3c9DrKkF3twfn7Ywo3ldHEOx1Se+aomIEGtoBeTOJAam+r7oj12wGTIPin0czQALBmgz7vTKy2gmOKxBd7GxjbT2mFKKLI/kVzMg== 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=7u8f5rQEZyGNdhnYsRxE4BU9KsFOQkkJi6gz/TmPO9I=; b=4PiQlBeGV9uX30BtURI1a3jWKj4g4zWBzDjopZhZk4cXvKcwUV//tjz2NIgg3AHdkVZ50WSEj6uSIHXS9DX/S5bCmSBUJfnB5zZzxozxxrhfvtdspSKD7jU8iyZkpEaM7cKMLIKJa8lC/Rch43rA8eXV8ToD72b06FzrN3+CvGs= Received: from MW4PR03CA0200.namprd03.prod.outlook.com (2603:10b6:303:b8::25) by SJ0PR12MB7036.namprd12.prod.outlook.com (2603:10b6:a03:483::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.23; Fri, 1 Nov 2024 16:23:52 +0000 Received: from SN1PEPF00026368.namprd02.prod.outlook.com (2603:10b6:303:b8:cafe::74) by MW4PR03CA0200.outlook.office365.com (2603:10b6:303:b8::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.36 via Frontend Transport; Fri, 1 Nov 2024 16:23:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00026368.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.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23:52 +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; Fri, 1 Nov 2024 11:23:47 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v9 08/10] iommu/amd: Modify clear_dte_entry() to avoid in-place update Date: Fri, 1 Nov 2024 16:23:02 +0000 Message-ID: <20241101162304.4688-9-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00026368:EE_|SJ0PR12MB7036:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b31bdfd-f368-4c7b-6c0a-08dcfa9192f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pJRDwslLoIevoCiNyNWPiHNjfFGTnmF1CRfDlCmJaI1CSorTGaSKSHWh7muc?= =?us-ascii?Q?t5IGCAW2BBDXucoGJK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ii?Q?ecG1Mvpn0oZ8I2vVKO4w6MMPfEWTVk1zlQGW3Sfm7+mtY3TYfjl8pU9H2r/o?= =?us-ascii?Q?uovai22trvLJHaRUNqhx977Ff6LrCbE8TiAYSpEIL+uP1W8QnFwdGzrxEyp6?= =?us-ascii?Q?0pbYxy64lyher7jK7ClvcYcqVhejujsk+u8YKmiI27GYYCRgUbqJLIKNnRpu?= =?us-ascii?Q?reApNliB3gaKW1qiLBtloWECTK0TDWO6yVpi6nEPZ4YBPXWFEhqPEBI3yLjx?= =?us-ascii?Q?ub26ReWX6MPU1ubt0OceKP0khG+wuc0ztFmF0Hg4jQsKJMzV3uxQm3S5ldlQ?= =?us-ascii?Q?1B8QZXCTIwFo+cUcUXxZ4RQrS0Xvcf7smklBXezUXKV6tuyK+CAaUnAkd+R3?= =?us-ascii?Q?MjCcUivAv3lPTXwN6xlqSI53/sLW14DnwhoqSW8oxQPx5WHP9W8/f2fSZKvq?= =?us-ascii?Q?dSd9cJ9QNelCxmqpS4MceroUsCxpzhS2/+6Qi+hH3nnZ0Jnj5A=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)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:52.1720 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6b31bdfd-f368-4c7b-6c0a-08dcfa9192f7 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: SN1PEPF00026368.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB7036 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 4151225b4245..0a7287c41cf4 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2090,19 +2090,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 */ @@ -2113,7 +2110,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 Sun Nov 24 21:19:31 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2085.outbound.protection.outlook.com [40.107.220.85]) (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 56B611CACEB for ; Fri, 1 Nov 2024 16:23:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478240; cv=fail; b=pIYR4xeKWkknAYUsTJXKi3vy9RGoVnSKHvyGRiXHAjWjx1WoUaFtWm/W5dYNVD0Cr0LOP7M4tiYuyENeLj/fcmUpm9j8DbTM7xZ+N5kW9k7JNBXvOe4PNLyvkT8P63I4537sIIy9do+L0q76BfjH54xvtftsxMd9gwC5n7KQYbM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478240; c=relaxed/simple; bh=FfAzNctd+sDX6/EB3BGFbJYSJWDZTp6Up7+xd79Z1x0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r8PWKyZgqTLMWnJ4wGv1FpigcLA5F6vYdxG/UmIQetsSknUgsEzJ8UgxvUMze1CcYwl7CwZABQnpI4Y56QxUFuywTj9WidLPziQkwps4BXHsi6GncL5izs0uZmQGZClauliC4cVw069U+Pgs+18ZJlcjQSwo3e0zxbKbhYRHct0= 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=YrVzN+Z4; arc=fail smtp.client-ip=40.107.220.85 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="YrVzN+Z4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WtysqdkUKGmfG8pzxXG3glcd6juybjdD+KMxVGoTgqIwgtDKuAigaoT4+vXY0MqYBusterA9iXzhUEoargW+Rl9nHiBrYpcu1LAYKh8VbTU5dICArWRy/KKBm87rNurRZJfFOI09Mk02HjGVbhuoudTsUr1oYtNZ3/hTD5aaF3VeW62sprJY2GgMPQ2bnZrSNxY87GsGI5u6jqiVi3xKM+HoEdQOw8AV8UZTvQDT5XpxhPJ5oiC6FGlrw2fqzlZvJKKVJcdXUsH9SIxjrRTuDwg9AFkkMsRD7O9q4HAlwlp4hi9sjf+5r6UXt7+EV4HtNvvCi/IAz/T1x2xYnS6lMg== 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=KFaYk8skvinWoau3hkwrRvgny9+I159yfwvR9xM6/nU=; b=C44KhMcoaSvSLqEAOaVIOTzZP79l+jGpv+FHG+bsW+1Luyloorp9WRXOdmPRqo9IXzMqBN1+y7xID0bxagk3xwTGJ1yy6zdfesHJPtzImvGL/2VWceTi8YWaKfYWZHlaCdYqmEPjjLT7MX0Z2BtCpImHG2M3sWXDyl1habHIGQ7LmWIqcGtN06XoToYdbfSRu6oHj1IwE1QSV2gh/niUHWHDSOIdi40EdrAt14NurjkbCyEYoYCgfqoi07v5NaLn2TMtNxzjg9Bw+fsEHrZQytjonbkl73LZ2lhlMduMJArBgO5Kqv/YqXZLNM2lg0g5raLWHCE5Dp5b9ub0hJw6ew== 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=KFaYk8skvinWoau3hkwrRvgny9+I159yfwvR9xM6/nU=; b=YrVzN+Z4m6QAeBDjcaDyqdY6Ke3k8hGzok/auvb0SnahcsjiZ+lw8LpC9LrNeGoTJ70KjoDmN/kTYkHtfHlQ/8NWgY04WX21KhGeKPN1UvKYJj46a6kswQx0twxUF5cEeHLJhXiZ1MWdEmLkF3ijPEx+ftUJlQRqovoPG9o+iAw= Received: from MW4PR03CA0188.namprd03.prod.outlook.com (2603:10b6:303:b8::13) by CYXPR12MB9320.namprd12.prod.outlook.com (2603:10b6:930:e6::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Fri, 1 Nov 2024 16:23:55 +0000 Received: from SN1PEPF00026368.namprd02.prod.outlook.com (2603:10b6:303:b8:cafe::b1) by MW4PR03CA0188.outlook.office365.com (2603:10b6:303:b8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32 via Frontend Transport; Fri, 1 Nov 2024 16:23:55 +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 SN1PEPF00026368.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.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23:55 +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; Fri, 1 Nov 2024 11:23:51 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v9 09/10] iommu/amd: Lock DTE before updating the entry with WRITE_ONCE() Date: Fri, 1 Nov 2024 16:23:03 +0000 Message-ID: <20241101162304.4688-10-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00026368:EE_|CYXPR12MB9320:EE_ X-MS-Office365-Filtering-Correlation-Id: a1bb45f1-1d0e-4a01-9244-08dcfa9194e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?e7wQiDAIzwYFpYJPAxxwStNKbYG3oM/EkuTBvUuzsKNOMEWyu6Z6Jb227+UC?= =?us-ascii?Q?IjNmfTUqut195Kde8anD7ALpv/LV4vOhaurR5yD2UfbQVj9uB0fGwYKjsREW?= =?us-ascii?Q?jzu1WuvModWJ3e3EjavXB9bnWDpb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sHD6fRr8b6AK6b75jSkUWU7vL9a4ELiMbfBnkTefhIT2zo7nR8gO?= =?us-ascii?Q?vaIHFnjd5+AtLKiuTCCN0XV4H/IVkz0fERyvWvENtTd8cfrb3wwDCCo9ANSA?= =?us-ascii?Q?rh21wKpDBRV/ypmfuyMVXrZnem276W9xGDu4KIY3h5OvHI9fL9yhSMaYRlFh?= =?us-ascii?Q?28IMuwbMrYSB4uO/CvPprL+z+B7TC0Ewd6YQUbVXWthJcsXZehR+TdVrpuV9?= =?us-ascii?Q?Y9y8E1YuQR+OOdPKtAQlz8jIxx92ConEoC52cwERfA11gJHcH6OBjZ3q4m2i?= =?us-ascii?Q?iu8r/h7iuFJfo136gjpuP7VkFoHRuzhEWbTovLFJ9iCmXDYN0JBy/Rb4yY7G?= =?us-ascii?Q?LeMKmXqC5gRkkHIHbEu2fW49iPPp3M8ZxpGPCZdMHa3WkU6UfQ=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)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:55.3908 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1bb45f1-1d0e-4a01-9244-08dcfa9194e2 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: SN1PEPF00026368.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9320 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 0a7287c41cf4..50b98b62936f 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -339,7 +339,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; @@ -2830,12 +2830,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)) { @@ -2844,16 +2844,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 READ_ONCE(dte->data[0]); + new =3D (enable ? new | DTE_FLAG_HAD : new & ~DTE_FLAG_HAD); + WRITE_ONCE(dte->data[0], 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; } @@ -3120,17 +3119,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 Sun Nov 24 21:19:31 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2048.outbound.protection.outlook.com [40.107.236.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BD021CEEB2 for ; Fri, 1 Nov 2024 16:24:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478244; cv=fail; b=j0Eb3wwJn4UEC1p47VUnyj6XbZcjVtWlaOnEBlxbIC9VpLfgjgYBEPOMYpRmJHKYFeqJHO32K2mE1Wamy831D1Rh6ddoQBiHBDhHuPZAsyQrS0erEK9r//HJzyxeJBRwzhlnAB26ssdZddQ2IKZmAqXIk2anlPVwhqABc4+Fxe8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730478244; c=relaxed/simple; bh=pD3CmY8Vf1E5rTziOoui/AnVhcJWQmAJJ32cDLUAJww=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jYU3KmbxZbEBDbSKWmfgfhP0CVEsFdPRPRLVWVnxD+aTX84Pfp6d2pWLYS3eGZNtW0HtyUGYXJCpngKFnk5vxuVSJakErBqv5IqEIau7HLTM3WLo27M4bzF/ac0ObV3ZXgZtZfhnjvy5NjKi/ty4ckQuhp3u8FpmfdxcKzVAWlY= 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=wpsokaNR; arc=fail smtp.client-ip=40.107.236.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="wpsokaNR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=w2dodd/10wDxc2MVA/NQrUCCUJuMWOsXnkq432zlgZsdParLHJuL3jl+sU1HPvXl9d0SZzeWNi3T+Bi7BBh2zPivcTPf3DYgIHjqZ0tOqB3gBpJ8kLt3QfPtWYlsRf3wdLTNbTtzzPAgY0wFvSI1FliobW75xO9bfAzVT5dL3cJ8uCvm232ouH64xuVJUWBbDVXwKy2zinIddJ7eXBEv6JU7UhuWPOym5jFDHnDIKJciQQAJXojLGXa1vcDRPlJcLz6duNb0e+gd4I2MVUS7nYfq4Tl4ej6Tfl2QX8s2yWS4GI+nKYNjzVy7z+tJf3pUF5s/w5Xznxv997AGtWon6w== 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=lSKpxUanYCWEAen7nHi/6rLaz3C6Za4/BeAouDOZzWp9WdQGAXOXKS+TeeOBtWtFe9qmPfkxBFHHrB2ZySSB3o88+9Rz3ZrOc+Fw5KT3w4BXX4gNHt+GAFEIuJIiq/6fvZ02E+ZsLeCD4Y9EJMVY5fdspTlL+iWDbjZLgpoltXlIyL3xbm/QQSYWECy952U5WarOnWxDTg7kWEW91T3lGDqDzA8sE5+VoUVTm3Zhie9Rvs5vPOkpv07d/50670RfRuNFnDC4VAmJ8vPo98GU7GD8BfyQ8b+jTi+Q8KXjgD7slJH/aPNFOd0cCabiNmKVfTHQr/0yatNR0bWuGmCSYw== 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=wpsokaNRxuieNUyMII0Ynf8m5Qxcs6Ly9APYdhdEXHlaV3ZRsXQoAomv2OZ9wZvBGmRBHaz+6A4FPr2mMRCXtZlUcxVr3k7fMc6vtX2Q92xZNB9DNfaMSOywIoSeETcXsTE5VFF0ORMPuVal/TQGf09VzSSQ7ZHQNnya7uHT/ug= Received: from MW4PR03CA0200.namprd03.prod.outlook.com (2603:10b6:303:b8::25) by BY5PR12MB4177.namprd12.prod.outlook.com (2603:10b6:a03:201::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.26; Fri, 1 Nov 2024 16:23:59 +0000 Received: from SN1PEPF00026368.namprd02.prod.outlook.com (2603:10b6:303:b8:cafe::dc) by MW4PR03CA0200.outlook.office365.com (2603:10b6:303:b8::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.36 via Frontend Transport; Fri, 1 Nov 2024 16:23:59 +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 SN1PEPF00026368.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.8114.16 via Frontend Transport; Fri, 1 Nov 2024 16:23:58 +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; Fri, 1 Nov 2024 11:23:55 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v9 10/10] iommu/amd: Remove amd_iommu_apply_erratum_63() Date: Fri, 1 Nov 2024 16:23:04 +0000 Message-ID: <20241101162304.4688-11-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101162304.4688-1-suravee.suthikulpanit@amd.com> References: <20241101162304.4688-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00026368:EE_|BY5PR12MB4177:EE_ X-MS-Office365-Filtering-Correlation-Id: be0d0904-4f6a-49ab-4060-08dcfa9196f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?hdC/9eVSQ/JTgOXGJccaOuNW6Lz5dVmieQ9ktIVmbzU7MC3RQ8/2C1CkCbhi?= =?us-ascii?Q?+QtTYy57Zz5/gMczPog3ByppidQprZxKnLin4qBfpog1KDxVGT/FcGU3J7sa?= =?us-ascii?Q?F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PliLF9R9/8QO87F?= =?us-ascii?Q?7JLasFG6Wgyh4lhKvd5JCqos4BfnRWj8VuyxLuyLIFzj2ke6C/W0GjiEXwa6?= =?us-ascii?Q?laWsD59Nel262x8lJNITKB20QGVnjHaKzwSnObg1uue9BbczpwLLHdUyB5k2?= =?us-ascii?Q?JJwrb0daLBw2GZSJkQCQbeK360DRAfbqMITHkL6UAcxrVHktB43ekWlzEOk/?= =?us-ascii?Q?rk+HdU2YWnJD+Xkd+ksMoeayIX51EEj9ErAohbYXqKBC5eY/i2JQIU/BRY6R?= =?us-ascii?Q?OwWFY+fT9bEZEhjQRO5gnpn9ywpqlrxD7ssu+6HF6zU8h/AxZlJNGbCneT7M?= =?us-ascii?Q?w9x5e79sDy///qj+z06Wcm5mhP0+ShshI86Am/s+0b3qBv5wYkjMGSTB6xrU?= =?us-ascii?Q?37Z4EKVvR86B6VxdXVKvhUwvVEQ/+HYyXCHAlP4MtnYE41HW2A=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)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 16:23:58.9065 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be0d0904-4f6a-49ab-4060-08dcfa9196f6 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: SN1PEPF00026368.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4177 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