From nobody Mon Nov 25 01:56:08 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2077.outbound.protection.outlook.com [40.107.220.77]) (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 72E5B1CB32C for ; Thu, 31 Oct 2024 18:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730400222; cv=fail; b=LGfsUisie1OJmkvFdDsgRWalVImsKJGYxXiNqIvZBpzXcjUWhqs5fTH7jg11Ukwm3WjoIGoJ5JBtIktT2FJWsnYWe2SZbH/wlmdd6XIC709uRrr/2Dq0YY1KDWSEN3GFMfus3n6pZMF0NjzX8xGQBDrOwBEsqz8dqJXNj6kwyfw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730400222; c=relaxed/simple; bh=D0wT/KPOob419H8a7ywwVXAG7CRLLhE+8O3VcZJfVx8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TF2/OF5fkyDgIqPgZk6MEK7ZG8ofyQ5wNS7h1uyk/OUGKAKsYeeBOFN+RLTxSDeC8ZweOKFjvKCg12VAeL158e1uyp6OEXRvx/A+hgdfJp+Skc/GBa3dBQsAj+A11ZypcNIBDio9eDP+m0uwQHyzwqYss9kzu73oonktT72EB4U= 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=gYdrWuHU; arc=fail smtp.client-ip=40.107.220.77 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="gYdrWuHU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sW//lW4JiTaTXTrwrB7QlvKqvnRNrsfT5b2qUzf6dEDLiP23vql7zaBa1a0zdC7m7lPX6xHRBxf/fqYU+24HykDtDibWyqImPF4jy5h1IBMQJ7VapqjpI2bJCNtoyHMht9GRcsjG4BII9O4sxxOzU5hcs8CrFSINR8njPC/3bc5MsISPLMRIGDaR/WRH+E6oTHPeX0UAD4OnZz7Q7x/iFNIqQ3p+4FT0yQjB8JWDfOlKvY1ds9tkAFzJ8pJoz4Lkn9G+EBAYd9WRk4fxUXsyfb45YjlBiknNm0Aweq1jXEFJnW+1RPoF3ojJA87zLEYCH+/xAEqOVfFJky2H52m+uA== 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=RSK8nZP4RcgWxlR8jBJDds4tamPMaiIv9Ra0Rf7BW44=; b=cMVGucVG1RUpeiZRfvH2nm6k5Icp61twUoDrkUSTZ2+3F3UGuLJ+zisYz43qOVEFSYihrDs64n27sNzsuEqWz2JD0K0rA++zzoxfakFTIcHpSftbVndv0CSTE4ANZMksp8/KG3+X1pMK8zlC1jzM+Qyqu+aURTUh99sTVgbGrVJvXfn2IHVjz7NGtLYkGQsAp3BXPpr9kGrAd2kKxV/3LjQPdrD01m0pJ97ND+nvqU/X/ccNqaOL06iA7brkak2aRmK85gJ5E9rsGzxWqCiGC5adkoMfSbqmjolIXLqqoD2sVoYAw5WRo2Vik1wfxDYpakLWXABQwOKBS6ENnn+6Tw== 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=RSK8nZP4RcgWxlR8jBJDds4tamPMaiIv9Ra0Rf7BW44=; b=gYdrWuHUhpwK1z2XKS6KXz0AwNXmHiDsnwuo/oVqYyHBEFvuBCr3KH6/FVji2rDomJl4smk/7pEvqpbqp7IjvtqhMOLPtwQ8rWdm3ImIciCRBjFggq2tZDUDYkmPmQ6Hh/D2/6wJ1lPmeSqTuls8j2P3GVa/rP+9IYi0aFgjW74= Received: from CH0PR07CA0008.namprd07.prod.outlook.com (2603:10b6:610:32::13) by IA0PR12MB8277.namprd12.prod.outlook.com (2603:10b6:208:3de::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.23; Thu, 31 Oct 2024 18:43:38 +0000 Received: from CH2PEPF00000141.namprd02.prod.outlook.com (2603:10b6:610:32:cafe::dd) by CH0PR07CA0008.outlook.office365.com (2603:10b6:610:32::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.22 via Frontend Transport; Thu, 31 Oct 2024 18:43:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF00000141.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Thu, 31 Oct 2024 18:43:37 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 31 Oct 2024 13:43:26 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v8 08/10] iommu/amd: Modify clear_dte_entry() to avoid in-place update Date: Thu, 31 Oct 2024 18:42:41 +0000 Message-ID: <20241031184243.4184-9-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031184243.4184-1-suravee.suthikulpanit@amd.com> References: <20241031184243.4184-1-suravee.suthikulpanit@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000141:EE_|IA0PR12MB8277:EE_ X-MS-Office365-Filtering-Correlation-Id: 4085d3a3-f893-4c75-24e4-08dcf9dbeede X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?4qbFMVfhhhP+GyIhNleYr1heuatzmqPWTZDe6cLt8zkHLHjG11PknLlmiPfu?= =?us-ascii?Q?TPn470KSEiLJO8gWTVsfOoJ5rBpSN6TAI8nlsfj5blDWOGVck4cBVnAxyMaX?= =?us-ascii?Q?0tczMbD9Tg6uwzjsqUr8aqjKYknKR19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us-ascii?Q?AEMhd0W9ezKQXMXTLdxE3z8UIVk5YVKiARM86sC1N8+Ax2WJx5EJggOOpdaN?= =?us-ascii?Q?ljLVlLyDJnNG7Hs01jMpRdl0AA5nYNgsePJZ5K4ZdfBsyhn+yS0buid22Xsj?= =?us-ascii?Q?MbEnPy9L2EzKaNUYfAS0fNkEFdC6g+Ykv5VbCY9Jw6zdjkcZtD9kmF6fZipe?= =?us-ascii?Q?Z2NvWBdSZZVKQR1+1+ihmqNW9ryuxNP82RBHZtLzddSWTVoYAGqgysN4oRL+?= =?us-ascii?Q?+UR18JSMRlS8UwGF17zzHQnGAkhw4R1uDlYGtgp5HyXWDZJKBG9dfoBT17fG?= =?us-ascii?Q?+9UslYgbSPwXTH2/5t4aepbhAtvzethiEOMTZ46hLmI4G5p8mQiecSI1hA0p?= =?us-ascii?Q?QvVrfY3Rwn0AT3BuRNUTNaFbdpNIyS0FfZesepGwo0nW2fjqbw=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)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 18:43:37.9676 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4085d3a3-f893-4c75-24e4-08dcf9dbeede 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: CH2PEPF00000141.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8277 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 1262ea7150f6..f0ae0d7734b5 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2111,19 +2111,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 */ @@ -2134,7 +2131,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