Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753187AbdGGNn3 (ORCPT ); Fri, 7 Jul 2017 09:43:29 -0400 Received: from mail-cys01nam02on0055.outbound.protection.outlook.com ([104.47.37.55]:58144 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752734AbdGGNnT (ORCPT ); Fri, 7 Jul 2017 09:43:19 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; From: Tom Lendacky Subject: [PATCH v9 27/38] iommu/amd: Allow the AMD IOMMU to work with memory encryption To: linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, xen-devel@lists.xen.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Brijesh Singh , Toshimitsu Kani , Radim =?utf-8?b?S3LEjW3DocWZ?= , Matt Fleming , Alexander Potapenko , "H. Peter Anvin" , Larry Woodman , Jonathan Corbet , Joerg Roedel , "Michael S. Tsirkin" , Ingo Molnar , Andrey Ryabinin , Dave Young , Rik van Riel , Arnd Bergmann , Konrad Rzeszutek Wilk , Borislav Petkov , Andy Lutomirski , Boris Ostrovsky , Dmitry Vyukov , Juergen Gross , Thomas Gleixner , Paolo Bonzini Date: Fri, 07 Jul 2017 08:43:08 -0500 Message-ID: <20170707134308.29711.87493.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20170707133804.29711.1616.stgit@tlendack-t1.amdoffice.net> References: <20170707133804.29711.1616.stgit@tlendack-t1.amdoffice.net> 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.77.1] X-ClientProxiedBy: MWHPR13CA0019.namprd13.prod.outlook.com (10.169.208.29) To DM5PR12MB1147.namprd12.prod.outlook.com (10.168.236.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 25128425-5033-4cbe-5e2b-08d4c53e1e83 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(48565401081)(300000503095)(300135400095)(201703131423075)(201703031133081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DM5PR12MB1147; X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1147;3:kQHaS/sIDL5OMDWvnc4G+HehN7Qk767MNKFJOnRXc4Rx62xtm95ZIHY21FDdC5JJhdLvl6pZKd4jPBU1SiBUfn/lA/a75UN7Vzs1I1LNyNomkqOXmYTFjYf8nKaSP49DXcQJ0VBHa9csj+xlgMcjcmvJSQ/WJS7pfUdH3xmngjjTEWsNMZCrJKbPt7XTBk6FInJFQyX3b2StvT4umQM6VqI0qA1LRwe91pnZ8n19zp036iF22CxbAnMxkADNWiN776NrRbj3FKdIPyO49xCtKpoehmMuyzztZnkrjjDd4TIafzW2YmjFanHRvqPbZaZp/WRKszv/KzZfUd5M4st3vEipZApGm1c6gA7FBwu73J4pfYRU2VLRkNhU5o+GLOzlVLgosfGxCyGkGrexGqyl/kIiB4BhQi6+En98NMRBY1fT+xIsvmGfUWmrtUn5FL42O5qt1kFMwpkNrB2zN6CSRhJuaIqHoaFpG8cIcqhq+Xjf5nVBKY9y6USPV+ku147WFjNJyI9UGD/znZG4ptbC9/UmaFKz6U9BPb+lMQOF+w5XF2j9AUh03ImAJASb5sxrNdD0B8zJPoqzkxwttB1pia8m1CpeO3fgwDNXlTEmhtWo32av/tWCBPb7bl93Xl/WHyGstwwhn6mrXBu3iAjadYuQzOvjKWli6GOj9iNWLXdP0MrHrwKhguL5BnYFzgswMA1UbKckCQ6FufCad3pZv3MbQwTY6eipGhNULuyN+d5kyE7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jhzwBUBFagQ9j/UVPSGHjQ1m4MFFaq0pIKc+Lt4UZ7XvNUMM8+7F2hnUpZem8hfEw8TKqrnwcr5p/esJa81wREYtnonoRK5zETVfb5VUYUBP5vp4Yn4zqhdK4HJlZn1AJaKqUtjwrnQxUYxffYG3VPc75KcThqcc2zR2nDoto5iPu X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(133145235818549)(236129657087228)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(2017060910064)(5005006)(8121501046)(100000703101)(100105400095)(10201501046)(93006095)(93001095)(3002001)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DM5PR12MB1147;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DM5PR12MB1147; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxMTQ3OzQ6T1d6dGNCR3pRTjd4cHJKZUk2c0p2d01LbmhM?= =?utf-8?B?OHVaTjFrN09oK3B4Sjdpc0hyV0VoTStLM1hWMmhnSVAxNXA1eEg3RExNWkxn?= =?utf-8?B?eHJaam54aFN6Y2JGUW1SaTdxNS9hNVppS2pjM2RhbG9kVEErMHJGV0tGMENS?= =?utf-8?B?SVBHby9pSXI5RkhwOXIrZWlMQ3k2Q2ZsOFZmRGdNTGdTbFlkeDBMYVV5M3Np?= =?utf-8?B?NG5kNlRaZnNqVVZ6MVV2NXRNNnhsR1lPM3lPN21CUWlNREtqSWN0bWZXVzBp?= =?utf-8?B?UjZyQVFwZDRmUzQ1THBYUG1QU1FLV3hxLzFmOE8vMy94WDVGZTlEaGV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ng3MVljWDNP?= =?utf-8?B?a2FGd0NjU2ZHRUFiUDN3TDlrQWtJVUY3VUl0K0V0RFU0bFdmOWFUTkVIbG1y?= =?utf-8?B?QjJCUWlxeHpGYmpCZXBXTktiMmdFR3RRQmdFd1NJNlhxR0s2M1YxRG1ZQlNK?= =?utf-8?B?V1d1Skl2QnlhZjBGNHJSQXRsSGxFeldBTjZzUWNhcEw5NWNidnBVOFVvdEtB?= =?utf-8?B?b3VUbGVaREtnMVdZS2pMaklGcHZmazFocW9nSlljT2k5V3RnSDFteTdCY2Zt?= =?utf-8?B?b295Y1RpOHFpVHlYcVJsUFdIU3F3T0tMdUlGZTJqYlZHVm05MFg3V0dabSsy?= =?utf-8?B?cmxsdTd3TnRjMUtITmMvNVhKT3RzVzBKWUtpRHI0N3FJR1hkM0p0c3BaLzNL?= =?utf-8?B?akRRY0Vxcmk3S1c0MFBodGdFcFJwbE5zYStGTmIwZUpFMWZFZ0ptcTdjWGdv?= =?utf-8?B?b21TcThmeFBBVG54NUZ4dnRhV1JBcEdFaE5UTktYOEsxWnRJdFYxeWUzdEFZ?= =?utf-8?Q?6LECNLHe+v9aAjz3b8FEKt6pT0iNoWS3lofM=3D?= X-Forefront-PRVS: 0361212EA8 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39450400003)(39860400002)(39850400002)(39400400002)(39410400002)(39840400002)(189998001)(6666003)(2950100002)(1076002)(4326008)(6116002)(53936002)(478600001)(103116003)(7406005)(72206003)(7416002)(47776003)(81166006)(25786009)(97746001)(8676002)(83506001)(86362001)(575784001)(50466002)(76176999)(54356999)(38730400002)(50986999)(5660300001)(23676002)(42186005)(305945005)(110136004)(2906002)(53416004)(6506006)(66066001)(3846002)(7736002)(54906002)(9686003)(33646002)(55016002)(230700001)(921003)(217873001)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1147;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft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LTH1Lc= X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1147;20:7e5Yc0qDOTxARrKfQ6Il5BPnkmlvCbDQiro58P/1A7fFI7q0xT9QlHzzayHUmq25sYRMVCHYdl/3amcetXA9j/2LudYWZibvtLzQfyUdGmCQvoR8nasoCSEFLDBVUShcFsOmljbrjV3wVDrbcRvfCnazU56kLmb5LWDuey/9uTosiXJmRDI9XsXw4tqyEM/mu7se1T09DTU9R4SRILFl/sbnPjz8d2jDtNRrn0vWidBrhwEPqj13jEhgFCJzzTp4 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2017 13:43:12.3735 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1147 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9195 Lines: 266 The IOMMU is programmed with physical addresses for the various tables and buffers that are used to communicate between the device and the driver. When the driver allocates this memory it is encrypted. In order for the IOMMU to access the memory as encrypted the encryption mask needs to be included in these physical addresses during configuration. The PTE entries created by the IOMMU should also include the encryption mask so that when the device behind the IOMMU performs a DMA, the DMA will be performed to encrypted memory. Acked-by: Joerg Roedel Reviewed-by: Borislav Petkov Signed-off-by: Tom Lendacky --- drivers/iommu/amd_iommu.c | 30 ++++++++++++++++-------------- drivers/iommu/amd_iommu_init.c | 34 ++++++++++++++++++++++++++++------ drivers/iommu/amd_iommu_proto.h | 10 ++++++++++ drivers/iommu/amd_iommu_types.h | 2 +- 4 files changed, 55 insertions(+), 21 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 5c9759e..a0a39f6 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -544,7 +544,7 @@ static void dump_dte_entry(u16 devid) static void dump_command(unsigned long phys_addr) { - struct iommu_cmd *cmd = phys_to_virt(phys_addr); + struct iommu_cmd *cmd = iommu_phys_to_virt(phys_addr); int i; for (i = 0; i < 4; ++i) @@ -865,11 +865,13 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu, static void build_completion_wait(struct iommu_cmd *cmd, u64 address) { + u64 paddr = iommu_virt_to_phys((void *)address); + WARN_ON(address & 0x7ULL); memset(cmd, 0, sizeof(*cmd)); - cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK; - cmd->data[1] = upper_32_bits(__pa(address)); + cmd->data[0] = lower_32_bits(paddr) | CMD_COMPL_WAIT_STORE_MASK; + cmd->data[1] = upper_32_bits(paddr); cmd->data[2] = 1; CMD_SET_TYPE(cmd, CMD_COMPL_WAIT); } @@ -1328,7 +1330,7 @@ static bool increase_address_space(struct protection_domain *domain, return false; *pte = PM_LEVEL_PDE(domain->mode, - virt_to_phys(domain->pt_root)); + iommu_virt_to_phys(domain->pt_root)); domain->pt_root = pte; domain->mode += 1; domain->updated = true; @@ -1365,7 +1367,7 @@ static u64 *alloc_pte(struct protection_domain *domain, if (!page) return NULL; - __npte = PM_LEVEL_PDE(level, virt_to_phys(page)); + __npte = PM_LEVEL_PDE(level, iommu_virt_to_phys(page)); /* pte could have been changed somewhere. */ if (cmpxchg64(pte, __pte, __npte) != __pte) { @@ -1481,10 +1483,10 @@ static int iommu_map_page(struct protection_domain *dom, return -EBUSY; if (count > 1) { - __pte = PAGE_SIZE_PTE(phys_addr, page_size); + __pte = PAGE_SIZE_PTE(__sme_set(phys_addr), page_size); __pte |= PM_LEVEL_ENC(7) | IOMMU_PTE_P | IOMMU_PTE_FC; } else - __pte = phys_addr | IOMMU_PTE_P | IOMMU_PTE_FC; + __pte = __sme_set(phys_addr) | IOMMU_PTE_P | IOMMU_PTE_FC; if (prot & IOMMU_PROT_IR) __pte |= IOMMU_PTE_IR; @@ -1700,7 +1702,7 @@ static void free_gcr3_tbl_level1(u64 *tbl) if (!(tbl[i] & GCR3_VALID)) continue; - ptr = __va(tbl[i] & PAGE_MASK); + ptr = iommu_phys_to_virt(tbl[i] & PAGE_MASK); free_page((unsigned long)ptr); } @@ -1715,7 +1717,7 @@ static void free_gcr3_tbl_level2(u64 *tbl) if (!(tbl[i] & GCR3_VALID)) continue; - ptr = __va(tbl[i] & PAGE_MASK); + ptr = iommu_phys_to_virt(tbl[i] & PAGE_MASK); free_gcr3_tbl_level1(ptr); } @@ -1807,7 +1809,7 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats) u64 flags = 0; if (domain->mode != PAGE_MODE_NONE) - pte_root = virt_to_phys(domain->pt_root); + pte_root = iommu_virt_to_phys(domain->pt_root); pte_root |= (domain->mode & DEV_ENTRY_MODE_MASK) << DEV_ENTRY_MODE_SHIFT; @@ -1819,7 +1821,7 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats) flags |= DTE_FLAG_IOTLB; if (domain->flags & PD_IOMMUV2_MASK) { - u64 gcr3 = __pa(domain->gcr3_tbl); + u64 gcr3 = iommu_virt_to_phys(domain->gcr3_tbl); u64 glx = domain->glx; u64 tmp; @@ -3470,10 +3472,10 @@ static u64 *__get_gcr3_pte(u64 *root, int level, int pasid, bool alloc) if (root == NULL) return NULL; - *pte = __pa(root) | GCR3_VALID; + *pte = iommu_virt_to_phys(root) | GCR3_VALID; } - root = __va(*pte & PAGE_MASK); + root = iommu_phys_to_virt(*pte & PAGE_MASK); level -= 1; } @@ -3652,7 +3654,7 @@ static void set_dte_irq_entry(u16 devid, struct irq_remap_table *table) dte = amd_iommu_dev_table[devid].data[2]; dte &= ~DTE_IRQ_PHYS_ADDR_MASK; - dte |= virt_to_phys(table->table); + dte |= iommu_virt_to_phys(table->table); dte |= DTE_IRQ_REMAP_INTCTL; dte |= DTE_IRQ_TABLE_LEN; dte |= DTE_IRQ_REMAP_ENABLE; diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 5a11328..096538c 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -346,7 +347,7 @@ static void iommu_set_device_table(struct amd_iommu *iommu) BUG_ON(iommu->mmio_base == NULL); - entry = virt_to_phys(amd_iommu_dev_table); + entry = iommu_virt_to_phys(amd_iommu_dev_table); entry |= (dev_table_size >> 12) - 1; memcpy_toio(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET, &entry, sizeof(entry)); @@ -602,7 +603,7 @@ static void iommu_enable_command_buffer(struct amd_iommu *iommu) BUG_ON(iommu->cmd_buf == NULL); - entry = (u64)virt_to_phys(iommu->cmd_buf); + entry = iommu_virt_to_phys(iommu->cmd_buf); entry |= MMIO_CMD_SIZE_512; memcpy_toio(iommu->mmio_base + MMIO_CMD_BUF_OFFSET, @@ -631,7 +632,7 @@ static void iommu_enable_event_buffer(struct amd_iommu *iommu) BUG_ON(iommu->evt_buf == NULL); - entry = (u64)virt_to_phys(iommu->evt_buf) | EVT_LEN_MASK; + entry = iommu_virt_to_phys(iommu->evt_buf) | EVT_LEN_MASK; memcpy_toio(iommu->mmio_base + MMIO_EVT_BUF_OFFSET, &entry, sizeof(entry)); @@ -664,7 +665,7 @@ static void iommu_enable_ppr_log(struct amd_iommu *iommu) if (iommu->ppr_log == NULL) return; - entry = (u64)virt_to_phys(iommu->ppr_log) | PPR_LOG_SIZE_512; + entry = iommu_virt_to_phys(iommu->ppr_log) | PPR_LOG_SIZE_512; memcpy_toio(iommu->mmio_base + MMIO_PPR_LOG_OFFSET, &entry, sizeof(entry)); @@ -744,10 +745,10 @@ static int iommu_init_ga_log(struct amd_iommu *iommu) if (!iommu->ga_log_tail) goto err_out; - entry = (u64)virt_to_phys(iommu->ga_log) | GA_LOG_SIZE_512; + entry = iommu_virt_to_phys(iommu->ga_log) | GA_LOG_SIZE_512; memcpy_toio(iommu->mmio_base + MMIO_GA_LOG_BASE_OFFSET, &entry, sizeof(entry)); - entry = ((u64)virt_to_phys(iommu->ga_log) & 0xFFFFFFFFFFFFFULL) & ~7ULL; + entry = (iommu_virt_to_phys(iommu->ga_log) & 0xFFFFFFFFFFFFFULL) & ~7ULL; memcpy_toio(iommu->mmio_base + MMIO_GA_LOG_TAIL_OFFSET, &entry, sizeof(entry)); writel(0x00, iommu->mmio_base + MMIO_GA_HEAD_OFFSET); @@ -2535,6 +2536,24 @@ static int __init amd_iommu_init(void) return ret; } +static bool amd_iommu_sme_check(void) +{ + if (!sme_active() || (boot_cpu_data.x86 != 0x17)) + return true; + + /* For Fam17h, a specific level of support is required */ + if (boot_cpu_data.microcode >= 0x08001205) + return true; + + if ((boot_cpu_data.microcode >= 0x08001126) && + (boot_cpu_data.microcode <= 0x080011ff)) + return true; + + pr_notice("AMD-Vi: IOMMU not currently supported when SME is active\n"); + + return false; +} + /**************************************************************************** * * Early detect code. This code runs at IOMMU detection time in the DMA @@ -2552,6 +2571,9 @@ int __init amd_iommu_detect(void) if (amd_iommu_disabled) return -ENODEV; + if (!amd_iommu_sme_check()) + return -ENODEV; + ret = iommu_go_to_state(IOMMU_IVRS_DETECTED); if (ret) return ret; diff --git a/drivers/iommu/amd_iommu_proto.h b/drivers/iommu/amd_iommu_proto.h index 466260f..3f12fb2 100644 --- a/drivers/iommu/amd_iommu_proto.h +++ b/drivers/iommu/amd_iommu_proto.h @@ -87,4 +87,14 @@ static inline bool iommu_feature(struct amd_iommu *iommu, u64 f) return !!(iommu->features & f); } +static inline u64 iommu_virt_to_phys(void *vaddr) +{ + return (u64)__sme_set(virt_to_phys(vaddr)); +} + +static inline void *iommu_phys_to_virt(unsigned long paddr) +{ + return phys_to_virt(__sme_clr(paddr)); +} + #endif /* _ASM_X86_AMD_IOMMU_PROTO_H */ diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index 4de8f41..3ce587d 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -343,7 +343,7 @@ #define IOMMU_PAGE_MASK (((1ULL << 52) - 1) & ~0xfffULL) #define IOMMU_PTE_PRESENT(pte) ((pte) & IOMMU_PTE_P) -#define IOMMU_PTE_PAGE(pte) (phys_to_virt((pte) & IOMMU_PAGE_MASK)) +#define IOMMU_PTE_PAGE(pte) (iommu_phys_to_virt((pte) & IOMMU_PAGE_MASK)) #define IOMMU_PTE_MODE(pte) (((pte) >> 9) & 0x07) #define IOMMU_PROT_MASK 0x03