Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753320AbcDZW6n (ORCPT ); Tue, 26 Apr 2016 18:58:43 -0400 Received: from mail-bl2on0091.outbound.protection.outlook.com ([65.55.169.91]:30608 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752082AbcDZW6h (ORCPT ); Tue, 26 Apr 2016 18:58:37 -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: [RFC PATCH v1 14/18] iommu/amd: AMD IOMMU support for memory encryption To: , , , , , , , , CC: Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , "Konrad Rzeszutek Wilk" , Paolo Bonzini , "Ingo Molnar" , Borislav Petkov , "H. Peter Anvin" , Andrey Ryabinin , "Alexander Potapenko" , Thomas Gleixner , "Dmitry Vyukov" Date: Tue, 26 Apr 2016 17:58:24 -0500 Message-ID: <20160426225824.13567.79822.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20160426225553.13567.19459.stgit@tlendack-t1.amdoffice.net> References: <20160426225553.13567.19459.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: SN1PR0701CA0018.namprd07.prod.outlook.com (10.162.96.28) To CY1PR1201MB1114.namprd12.prod.outlook.com (10.169.19.18) X-MS-Office365-Filtering-Correlation-Id: b2850ee7-5a5e-458a-af14-08d36e2647d9 X-Microsoft-Exchange-Diagnostics: 1;CY1PR1201MB1114;2:3FxmjRwVMa/FMLicI0JmCkoRMX/IL9V3QtoO6XvBLI5aNlHt8EN5TnHpX7HSDD5M3EpwhC+NmhxUi/qboayKB/pwMXXq5HOLvOSLVIRXKlW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EQiZyK1QQ6NCz115VqQGRCSCgYY/DVpIU2jP8GD5F0WFkzLPlc3enVlMD6cJiJAt4dLRu7kpUeQmz+Ve3Oxl3DHX8L;4:xbkwLBx2UWZlLQIeypk0JVlQQIq3QN6fN/KdLhwAvwQUOPAHPw83IkME/V4xCHZBeS3vlH4XMdizSmbrmQnYk+37q3/DF6Zrfp9ngd7JhX6sjgdUe3r3dQ6pNfupgieXdNlXl/SVOicNTABhoQ1QXYdthOW+NoiPK+PIU9YNKC9fhtl4H1l8mn9aKLN7SpZd4tNU2txqb2JJPoAJ95g5AwX+Bzu9BTBlX1uKcmJ67JmDJcCJwVL8x1zHZ1gTGjcne4BqHhj6RYVQ32cly/a8sV3nzZjbldQwENdt+sAck3QKYsEe1NaTR5lwEviOborc9+7puVzeTHBjjZfkimzz2m7wuRAF/PKXlaqlf+tsKdmGO4bBOMHwXvtizeD5op5cMGRatgUI//T/P3DLTAqG/Wu+aXKrtM4P/F0umcn/XPY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521072)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026);SRVR:CY1PR1201MB1114;BCL:0;PCL:0;RULEID:;SRVR:CY1PR1201MB1114; X-Forefront-PRVS: 0924C6A0D5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(2201001)(92566002)(2906002)(5001770100001)(97746001)(81166005)(33646002)(66066001)(230700001)(4001350100001)(47776003)(54356999)(50986999)(50466002)(23676002)(76176999)(86362001)(229853001)(9686002)(5008740100001)(189998001)(53416004)(4326007)(6116002)(1096002)(103116003)(42186005)(1076002)(5004730100002)(19580405001)(77096005)(2950100001)(19580395003)(586003)(71626007)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR1201MB1114;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exch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0ZKePR6FM5QH2x2T4RPsMCrX+laGPRIfCYNyoGMMeyrCSSdLYkqo5JpRwp/pcfDc=;20:UVuNEiyp4DWYTSsnrGJcFabbL7Es6g7BSlp6uUNbiaSI1kXdDsPWUT8/H+w1FP00Ka0gnt49mKCAN/yUqYG9WR899Dp+Jj+N/FMK+b9pWvK92KbMIGtsCTNMFWNc462DrGhTeg8KqNJqX5elVHB8l75t2M/lucHM3XzgtrBc94f3+40sdS3yWEROBbqJRBPjTcGzXRHnoxt4J/N1x88fNGt/W2Ey4sUKnt07glPXubsQuTqNwbyPV5gifC0pjZJm X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2016 22:58:27.2163 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR1201MB1114 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2067 Lines: 67 Add support to the AMD IOMMU driver to set the memory encryption mask if memory encryption is enabled. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/mem_encrypt.h | 2 ++ arch/x86/mm/mem_encrypt.c | 5 +++++ drivers/iommu/amd_iommu.c | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index d17d8cf..55163e4 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -39,6 +39,8 @@ void __init sme_early_init(void); /* Architecture __weak replacement functions */ void __init mem_encrypt_init(void); +unsigned long amd_iommu_get_me_mask(void); + unsigned long swiotlb_get_me_mask(void); void swiotlb_set_mem_dec(void *vaddr, unsigned long size); diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 594dc65..6efceb8 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -179,6 +179,11 @@ void __init mem_encrypt_init(void) swiotlb_clear_encryption(); } +unsigned long amd_iommu_get_me_mask(void) +{ + return sme_me_mask; +} + unsigned long swiotlb_get_me_mask(void) { return sme_me_mask; diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 5efadad..5dc8f52 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -156,6 +156,15 @@ struct dma_ops_domain { struct aperture_range *aperture[APERTURE_MAX_RANGES]; }; +/* + * Support for memory encryption. If memory encryption is supported, then an + * override to this function will be provided. + */ +unsigned long __weak amd_iommu_get_me_mask(void) +{ + return 0; +} + /**************************************************************************** * * Helper functions @@ -2612,6 +2621,7 @@ static dma_addr_t __map_single(struct device *dev, if (address == DMA_ERROR_CODE) goto out; + paddr |= amd_iommu_get_me_mask(); start = address; for (i = 0; i < pages; ++i) { ret = dma_ops_domain_map(dma_dom, start, paddr, dir);