Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752214AbdLDTxF (ORCPT ); Mon, 4 Dec 2017 14:53:05 -0500 Received: from mail-co1nam03on0060.outbound.protection.outlook.com ([104.47.40.60]:42121 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751862AbdLDTw7 (ORCPT ); Mon, 4 Dec 2017 14:52:59 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Subject: [PATCH] iommu/amd - Set the device table entry PPR bit for IOMMU V2 devices From: Gary R Hook To: iommu@lists.linux-foundation.org Cc: joro@8bytes.org, linux-kernel@vger.kernel.org Date: Mon, 04 Dec 2017 13:52:52 -0600 Message-ID: <151241717281.31129.11796268388010226384.stgit@sosxen2.amd.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM5PR1101CA0017.namprd11.prod.outlook.com (10.174.246.27) To BN6PR12MB1202.namprd12.prod.outlook.com (10.168.227.12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a20192ba-a9a3-4a04-dd46-08d53b509cfb X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603286);SRVR:BN6PR12MB1202; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1202;3:nC3Umk1VPNFGdrNzk4TUPw5hkLZeoS2qUGbK+7DbO/rf6tghVEaFvylJ+zaY+Jkv129T+tNF+t2HVYcdLJj7Goi3swxWVwENlfEnPyzId3l/ZfFLwvQgG33qqKyYDXzJyoHZtyC+1XHS2rLAxhw1F+m+pyF/gx5yQ/PlIefwDd0l4G2i7i9GEcKFtf5iqsg9KGJtscs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zsRW3fe/311LykSMrT6/y7J4iznLmxM/nstkaXTLa/WbhhxKQAoALrQkcsQGaDxkDMQwzkG+RahZKEn4GMCe9oy0g4Z5WU1+ZYUo9J7/D7fVgwkKrMb1CXMBGj04yRq/74FqHx78IMigmmMaN0EAq;4:Vbfxi+bX8BSYKtbr4mZwHmzJdXc6uq2tx96Fwl3zwmGL3me3J10LFPLbWhVYTlKjrM2UBOsE7CHdTKRfe2hSYmwjuPZrwAHDIIpr1uBSJaY96290GBLIJ9rcwZsrBaLN2MsZeA3YC7IkCIjDNfVI6Pjmtz+3jxV+Ky3SuDhi/JCf7fj0TvvOeh9JDLdM6yD4zHNqrXtoszjcb/S78XhKOvo+Yeql1f5P0xFvJZhlaIUjgBPee0RR+F78irk7MeiH2wJVR/Lo5PjPKR8FvRh5EEt/K5ccapfSILKbh+67Qez39+17D99YD/xaWPqE7KXh X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231022)(93006095)(93001095)(6055026)(6041248)(20161123562025)(20161123560025)(20161123555025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(201708071742011);SRVR:BN6PR12MB1202;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:BN6PR12MB1202; X-Forefront-PRVS: 051158ECBB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(376002)(366004)(346002)(39860400002)(189002)(199003)(3846002)(6116002)(25786009)(230700001)(81156014)(66066001)(81166006)(8676002)(8936002)(58126008)(5660300001)(316002)(33646002)(6306002)(103116003)(6666003)(53936002)(83506002)(101416001)(478600001)(2351001)(106356001)(2361001)(50466002)(7736002)(72206003)(305945005)(6916009)(4326008)(966005)(2906002)(54356011)(105586002)(86362001)(16526018)(55016002)(53416004)(47776003)(52116002)(2486003)(5890100001)(189998001)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WliYysyenB4ZmFBS2tobHhyOXRSZlI3RjUyT0tPTkV3PT0=?= X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1202;6:ASejgq8KyktdqVn2x3TAb7qrv2ABlipq7nC62PpaEpuq1padWQf5YFSHvDmNx9hf8zh26EMYDXzH/rJHuL+ArSsz6l1fW7UXwPcjdwlDOxWLt28ntGDsem8JHYPBvca9dae1kleyHsSLOeOIKDkcXnjADiUtGMvXIOJY+fJwkHY2B6xfwH4k+NPt7DToSgFo7G88yVNAa98InDxG3qKYOqdt4YK4STnrQMCdrd41M8RR8a3jH8rA9mrF/f2TWwz6PV3jn6gdzO5bOAsNI6OSRpC5wFRBYcYoHWJnTO/ahkbleApdOEsmm9IAykXdac+6di01hDVTbQT+R+Bd+whPH/Hg+VBunolI7nxNDyrqkUE=;5:C4+bxy3ROlphhdvR0KsfKqvwucJtQhDsjM1zyzSefFthaZpbB/zFvUW49uN4nqzYrV/vtywdwjjVMTxgX2W6n+dwoh2duiWTST00LAFnMvnWSJcRANk7xY9KQJyiOZxylR1maUpsULmGs9VuUNxSFWHBiBOgfcb3aRXEqmKtyes=;24:yysT8WQak0l/NIkB4rmhYadk6tPYNr/GMfOfFc7m0ACA4Whr/Yc/mWKIjoqXcbry+5lF5n6HkiEZQbW7oxQBAUaPxmb0y4QqHKVMpZmqOzI=;7:C/DgCf0HiVOpu8ts79x1k+Lr9iPogcUV2wVOynvMjA547NPzXoAuK1fZcHNrF/pc+lJCCp9x3jTKmfBZI90+95Dbmp5sSxCcDW4Z2tg6CMM4NxeuaTh/SYoC1CVQCWOQl5JIb80IKe9aiCA31VV2KUY7Q0V7PHB3xlRRn4AhTri63DWk3xyYPy89e9LBhfrEddYPBggR7HDqWOnYw2vwe23MFwQuv86UtbL5TxNZljEbG+W8YLCzcTdVkQTl5ETv SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1202;20:gkFAQ6KqRbLgF9kLmYVXPU7djKh/nqY/8wFmuIntqNPG13le4oOKrCDeoCLlI3dhuDt3iyZ9ZPoIVGmrP2wN/FSNGs58Q5arBjt2GwHlPB2B2UFB2dOpZOkOnc4W3xXqSPRZH9A/HXiSTvuLmgOL46BKt3UIn6LV7JWKZwQeudVWHoxAc5n1C6K/x9ItWG/S12MzAlj9XJ3Otw1LnCcfM2iLwjz4na6OJdBFiMas/MDomoyJrpqCAxy3bI0jitNu X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2017 19:52:55.5280 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a20192ba-a9a3-4a04-dd46-08d53b509cfb X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1202 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3413 Lines: 95 The AMD IOMMU specification Rev 3.00 (December 2016) introduces a new Enhanced PPR Handling Support (EPHSup) bit in the MMIO register offset 0030h (IOMMU Extended Feature Register). When EPHSup=1, the IOMMU hardware requires the PPR bit of the device table entry (DTE) to be set in order to support PPR for a particular endpoint device. Please see https://support.amd.com/TechDocs/48882_IOMMU.pdf for this revision of the AMD IOMMU specification. Signed-off-by: Gary R Hook --- drivers/iommu/amd_iommu.c | 20 +++++++++++++++----- drivers/iommu/amd_iommu_types.h | 2 ++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index cb78933ef53f..329940ffb8c1 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1818,7 +1818,8 @@ static bool dma_ops_domain(struct protection_domain *domain) return domain->flags & PD_DMA_OPS_MASK; } -static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats) +static void set_dte_entry(u16 devid, struct protection_domain *domain, + bool ats, bool ppr) { u64 pte_root = 0; u64 flags = 0; @@ -1835,6 +1836,13 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats) if (ats) flags |= DTE_FLAG_IOTLB; + if (ppr) { + struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; + + if (iommu_feature(iommu, FEATURE_EPHSUP)) + pte_root |= DEV_ENTRY_PPR; + } + if (domain->flags & PD_IOMMUV2_MASK) { u64 gcr3 = iommu_virt_to_phys(domain->gcr3_tbl); u64 glx = domain->glx; @@ -1897,9 +1905,9 @@ static void do_attach(struct iommu_dev_data *dev_data, domain->dev_cnt += 1; /* Update device table */ - set_dte_entry(dev_data->devid, domain, ats); + set_dte_entry(dev_data->devid, domain, ats, dev_data->iommu_v2); if (alias != dev_data->devid) - set_dte_entry(alias, domain, ats); + set_dte_entry(alias, domain, ats, dev_data->iommu_v2); device_flush_dte(dev_data); } @@ -2278,13 +2286,15 @@ static void update_device_table(struct protection_domain *domain) struct iommu_dev_data *dev_data; list_for_each_entry(dev_data, &domain->dev_list, list) { - set_dte_entry(dev_data->devid, domain, dev_data->ats.enabled); + set_dte_entry(dev_data->devid, domain, dev_data->ats.enabled, + dev_data->iommu_v2); if (dev_data->devid == dev_data->alias) continue; /* There is an alias, update device table entry for it */ - set_dte_entry(dev_data->alias, domain, dev_data->ats.enabled); + set_dte_entry(dev_data->alias, domain, dev_data->ats.enabled, + dev_data->iommu_v2); } } diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index f6b24c7d8b70..6a877ebd058b 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -98,6 +98,7 @@ #define FEATURE_HE (1ULL<<8) #define FEATURE_PC (1ULL<<9) #define FEATURE_GAM_VAPIC (1ULL<<21) +#define FEATURE_EPHSUP (1ULL<<50) #define FEATURE_PASID_SHIFT 32 #define FEATURE_PASID_MASK (0x1fULL << FEATURE_PASID_SHIFT) @@ -192,6 +193,7 @@ /* macros and definitions for device table entries */ #define DEV_ENTRY_VALID 0x00 #define DEV_ENTRY_TRANSLATION 0x01 +#define DEV_ENTRY_PPR 0x34 #define DEV_ENTRY_IR 0x3d #define DEV_ENTRY_IW 0x3e #define DEV_ENTRY_NO_PAGE_FAULT 0x62