From nobody Mon Nov 25 02:51:51 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2062.outbound.protection.outlook.com [40.107.94.62]) (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 D25C019939E for ; Thu, 31 Oct 2024 09:17:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730366239; cv=fail; b=NRIY3cLBnvdFoswXF+24ZDyb8zBHitgritRj6wzICt4JigYFa9wrgVcDQXepJBdHTi2XU4UecH02qmTiCKtg/QUBypwHD8C0r6cWUNueineH7RW6aXG2cDj6HIkY3gRHfFR02s1Wu7ucKT2mzs+rDbDU7EtabnabJVCupXULIME= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730366239; c=relaxed/simple; bh=tZ47vZBh9OhFFaey/i86tdeh0q9vSBPjtbwlWtV9CSE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hlNKwAVzE7DHq5HQXjPHyNfDKHc47xZ3wTAxecuYB+Xn+R7aniVyn5TWtVC3G8IwwdzC8Hh9fibDNmm9JDidjrUofgw/Z7umYyp7Ee6GNJcjWMAl0G7qQOLW5SNXbWcTLTm9VJ0zxnyoRdSFX2kA/dXPRJ/VCLVdmzk8DHO2ttY= 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=CnV4c0Ax; arc=fail smtp.client-ip=40.107.94.62 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="CnV4c0Ax" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Caeabh0Txc5+juAEX8ojdbjZzNP7RTkPojfV/yOWEmrldaS3RHwpCUqmPHRuyk+nrDKbKHQ1x29v971QYtzkhAtLmPQFmYpjdrDMBWuCRaYFzkUH+EwjVh+OQYyKVAdwnZdOJOnG+LHGzLYK3r+rCGmsZqm1gZqSfqjHfUWIzP40FwjXKk0lwhaoi/kyDhQJTkVKK8bcGXVf0YOoIqCDKixUY5EZQIOWAF44TV1oAN1HHORefNrm2LneD0RAquL5KCCc23oPvtC6bmQ+HVVw4DjEk8ApVSJOnreChqfIPig9TC374/bym4a/gqRkqLrX+Yz1ZxVvlB9Laumq0KWEjQ== 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=yFfBhwF42Zs5yWuL7X9+FvccHU8CMdFTLcHr+lNPFhY=; b=YlHcVjmlaIbegfkKVEPKdOZac6QXVabDFDLgHWe6UM9J9LVjX+0YketVamQGQXdOX9rsT9C1s+3R44Vprj+jGUdtWq5xGxWuWQnfFulTokeOflqj7xWoeSv+njxDFDfmRrs6Lw6939tnSmsnkEglsjclWMNxQGgZXqteOFmb0Hz9FI1yxyKLQTKcPsExafW5DYzxalhhtoVtcHSqjU99eGyzGmoiTha9lnZtpA40gczj4Xm1WOuHfdQcVlekSkPZN3c+NAnR+XgEL4r/UhQIULVVQGXY5XA7fWmxGyx3Vh7YjFd4juLpBIPAGRutNUIqJ9rhFoxsjCuBlADgBgdjwg== 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=yFfBhwF42Zs5yWuL7X9+FvccHU8CMdFTLcHr+lNPFhY=; b=CnV4c0AxyjSp1rMz0x4kc2hOMaMNmc2ns9vZkliUxRh5HrirGFaUdnLtXegnO8MuTFI6nIsGj6KXCYgZBfdm3sye0CP5gc5eRuYcPCYXUxg/a0yISsIHFOJr87qYtGUho3InVtPcMUT9CTbsnfwvbh+1ktPQ4fXYrE3APmrXAGM= Received: from MW4PR04CA0087.namprd04.prod.outlook.com (2603:10b6:303:6b::32) by BY5PR12MB4163.namprd12.prod.outlook.com (2603:10b6:a03:202::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Thu, 31 Oct 2024 09:17:14 +0000 Received: from CO1PEPF000042AE.namprd03.prod.outlook.com (2603:10b6:303:6b:cafe::a0) by MW4PR04CA0087.outlook.office365.com (2603:10b6:303:6b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.17 via Frontend Transport; Thu, 31 Oct 2024 09:17:14 +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 CO1PEPF000042AE.mail.protection.outlook.com (10.167.243.43) 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 09:17:14 +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 04:17:07 -0500 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v7 08/10] iommu/amd: Modify clear_dte_entry() to avoid in-place update Date: Thu, 31 Oct 2024 09:16:22 +0000 Message-ID: <20241031091624.4895-9-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031091624.4895-1-suravee.suthikulpanit@amd.com> References: <20241031091624.4895-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: CO1PEPF000042AE:EE_|BY5PR12MB4163:EE_ X-MS-Office365-Filtering-Correlation-Id: 6cecad55-7a2c-42b9-817d-08dcf98ccf0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?hrHNUypCBIlTTFSNLe8M0AFL3Z1/H14eodsOLyLG5zZ2Fp3VZr5Yau0d7D52?= =?us-ascii?Q?E12CJYtRnABWdb005fmjMcpShFEKf9GUYUfqUTMSGk+Fn4hvtonpBkQZwRpx?= =?us-ascii?Q?/xuyKagr4goQWbvAVD0TBjSqB7JW1CPnmgLqvdn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CM+yje9SlsgSItwJ2JElvxi4v6HLl7jh7WR4F4VAwUMAGcdQi?= =?us-ascii?Q?dPoXv41TnIAqdWkwZKgKG2mqFI7y90rVjl7NerVNcTYazgP2KeISsYUQqQ0b?= =?us-ascii?Q?IjJ0Cwb99kJaN2LMaNe3noPhzPzwYD8DvsCvRooPT334S62AEQr0s8Qsoo49?= =?us-ascii?Q?QVwk//qKbw0b2ROOIEiwRcF6SPqOX15LVQ7ayvrR1/gR74mm/iUjtKRsb5ad?= =?us-ascii?Q?8xAvBjhzNr20nEI1LoQxrKcYJU6OHqHb1uoHcWxBmEfWsADv9gmlVOh6LTAc?= =?us-ascii?Q?P3h0hU+z2I18AxTE+qhrPiBJgWfWWNs6hEVMxG4SubFvj5eV0XkOIUPWYk2m?= =?us-ascii?Q?rQvRM+GhW9gt1U5E8+aPBXxGhSGTtCtc+9xauylYagluYPhavw=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 09:17:14.2621 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6cecad55-7a2c-42b9-817d-08dcf98ccf0e 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: CO1PEPF000042AE.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4163 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 c8b0be83ee9b..b71fb22d001a 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