From patchwork Mon Aug 22 22:38:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 9294549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3AEC660574 for ; Mon, 22 Aug 2016 22:56:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 292F9286DA for ; Mon, 22 Aug 2016 22:56:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D2F328AE0; Mon, 22 Aug 2016 22:56:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1817286DA for ; Mon, 22 Aug 2016 22:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932839AbcHVWy0 (ORCPT ); Mon, 22 Aug 2016 18:54:26 -0400 Received: from mail-by2nam03on0056.outbound.protection.outlook.com ([104.47.42.56]:45305 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932828AbcHVWyV (ORCPT ); Mon, 22 Aug 2016 18:54:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=0E+5b32aRf+3b6hdl894j7LGtPEnKzw0lDcXRczpZSc=; b=mNZGtWC72QGzSBNyt2k6DRFcgXND7Hhsr6UFiTmVQ3rHDDbk/oH94KeoXQLrzXy4rO4xIYG2qnJ8EUd1Soq+tfkX+GDkYXDx4Z45S5ADGKxB08UUu+1FDqDVe6Uf+NVwokQsUlLFIeGB9EJJIgsB5m4e4RtWrwu10nO6bhLuhqY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from tlendack-t1.amdoffice.net (165.204.77.1) by BN6PR12MB1138.namprd12.prod.outlook.com (10.168.226.140) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.21; Mon, 22 Aug 2016 22:38:22 +0000 From: Tom Lendacky Subject: [RFC PATCH v2 15/20] 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" , Andrey Ryabinin , Ingo Molnar , Borislav Petkov , "Andy Lutomirski" , "H. Peter Anvin" , "Paolo Bonzini" , Alexander Potapenko , Thomas Gleixner , Dmitry Vyukov Date: Mon, 22 Aug 2016 17:38:20 -0500 Message-ID: <20160822223820.29880.17752.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20160822223529.29880.50884.stgit@tlendack-t1.amdoffice.net> References: <20160822223529.29880.50884.stgit@tlendack-t1.amdoffice.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BLUPR05CA0048.namprd05.prod.outlook.com (10.141.20.18) To BN6PR12MB1138.namprd12.prod.outlook.com (10.168.226.140) X-MS-Office365-Filtering-Correlation-Id: 813d5c8e-5754-429d-d50d-08d3cadd066b X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1138; 2:KyaIDqO66DFpeTS3Bq4it/OjNaDFssmhaDX1NAh9KE1LSeyk6Oq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tbFegxwPH77zqpXUs5PvREsrPidrTahVSy4QOBYnoxwbxNAlHKc/WlhfrHwCG1uMvS64hxGrCi80MHaJ7E9yR0eXAT7xt/f8xS4UbMiJf80AEQLPd5tOw6fSCJyimZTDsqAyaP4xMccGmL7UOPaoX7k+hj2qMKAXhikj4Q2/dCibslfUHLTbhYE5UXh6qpvkmvepbHbBsou/DSI9uVBDA1MP5T8QiQsLvT8Un96N+/j79vvfp8ekV9dyC5vmKwtwC7uROqOeTJLIMY767JzfMnRmhAgpcRJ7mZUsa0ja2C581GHsBI2KKmjesV5mS4yGZazK9AVxTs3J6Zc77w8pNnRUZqPXiwCaMjKMtLj6V+Nb/ea9oOeYtF+uplM1lkry0nm2CIs4+cfkOm5XtKgjCJkK6HSmknwebipfV3BGYdzjPDjfrwTwwSxJ7WGlgOy7lgFNiTqP0QgfKbXUXY5Rqcs35 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:BN6PR12MB1138; BCL:0; PCL:0; RULEID:; SRVR:BN6PR12MB1138; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1138; 4:3BIB+ONzysfnIZtVcyEyQH0NdyN/vBogPVZO/QKVR2gkluqKe/ciQ2mz4zE1L/4UqFYFT0gF45+JjP2XVfdBjlsIvNzwtKwiJHWvJl1UORH/6QfM7qHNtgte2d7avrfJbyjHCefI5Qmn2IYHWldubPUMJe9043Hff0YPHsUs7bvzQtPHVu52y7YrO8dss5ufGZeA8LolMlZS9slDlWl+EkRhsG1Ypah3LU2IamE9qQpP8dX7ODgMpKeDkI4jd8WGHiYk65oEhlurHd0xUXAgBEF3q921TbM+aE3rqSY6+EnoNt8kma+2Z+4hWnoOGb39g6QPsXd62jjdJ+BCdUy6Ai2/fwnCoQu7vti87jzNZP/+vgNEhEtw6EkZl2UKSmE4T4ubtrNgwn0yGUKbSFV5xctWatKUBCNzioZIV6SQMbx/gdA1Pc4sQ07iRFvc2GfX X-Forefront-PRVS: 00429279BA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(199003)(189002)(47776003)(9686002)(68736007)(7846002)(86362001)(19580395003)(7736002)(66066001)(230700001)(6116002)(42186005)(189998001)(103116003)(4326007)(69596002)(2906002)(19580405001)(1076002)(50466002)(305945005)(33646002)(83506001)(5660300001)(229853001)(105586002)(7416002)(54356999)(76176999)(50986999)(97746001)(2201001)(92566002)(8676002)(23676002)(77096005)(81156014)(586003)(3846002)(5001770100001)(4001350100001)(101416001)(53416004)(106356001)(2950100001)(81166006)(97736004)(71626007)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1138; H:tlendack-t1.amdoffice.net; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjEyTUIxMTM4OzIzOm53TzROamtVaG93MENZWG1oVlFQdWRPLzlZ?= =?utf-8?B?T1NsbmpiMjZ1YWp5STBqdlpIMzhManRvOWh5ZWRKdmhrb2VNV2ZGTWdzeDBw?= =?utf-8?B?M2pheWZ5dU4zRUNnNVlnVkowaDd6VjFOYVN6NGd6MWY0WUJuelVRN3VEb1Fr?= =?utf-8?B?bUlidCt5dEVZMGNqL0M1TWhZRDNkN1plYk83cUNUa25DZ28xeDBqdFNCakdR?= =?utf-8?B?d2sxTTNKMjVVRk5lQW5Fa3daVTdLb2YwQiszV1BQRHlqMUNENmo0TTJJRXpu?= =?utf-8?B?T1hETDdaK3BYSlVWMmxnZlhHS3lWTlJwbkYzOHlSclVJNUs2WEtOTVpCRFF5?= =?utf-8?B?NUY3ODErcHdJMlNZZXFkRU5yRHBndnkyU3UwR2VqdzlJSHZ3ajNvUzVVUU8r?= =?utf-8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/H+NCYiUGbAdo9Qd1P8gqbQJUy0g5ZKn662AemRCEwPRMCb0Re9HszA==; 24:zZgARBBorQG+9XuwYfjzjh5PfYwtul9aOCn9rrLseBdQjHi6J9s2C2pnx+bLseIZ5lEX36gJXYFyB5ejoOExEovQWFn/nfUX2EFs5aZE+cg=; 7:bUZcfZmIg8zJlGPhG/OOZM0TIF9b4uqsdyQTJiOFwYLpKroVXFg+tfgyh98t4o9cWePQVGTWAVOLQ9GTyCktt3uwbuPRmCFXnrSMJfpp5EJsbYM0Yz1KUr7SZ1u6PNiFd8AEQFcatT+iw5zCWWQK1riOal5pcbslz8fR7LaIBFBPMSrCZ0vUKlP5bQhWLsDiS8JPmetAeZt6b0NRgc5K17Tk415S5HKRCeBCLdQu1tJ78VD50cj8AE5O+pZ+TWcI SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1138; 20:Y5ZzRLN2U3lBXg/UdEfwRPrGolBLZeK4+5O95EB7orKcjWG5+2Lf2FamPaEDjSzoj8RA0ay7MxZHjin4O22jbktB8/p2JmQDpxpzFLyOj6r+sciGoK/9rzxJOge5b/8gwIkV2IXVL0jnzE4peDhQhvmAJlGHU3/sGh1L+D1CCi9rz8+L2dhcOqN4YKa34yzOR1i0QHIlMxqlrucza8v1coaTKq3cQFCHYlORWQm3Lk2/IA+RaA8ebMD+ed0w402q X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2016 22:38:22.0624 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1138 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 384fdfb..e395729 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -36,6 +36,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 6b2e8bf..2f28d87 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -185,6 +185,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 96de97a..63995e3 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -166,6 +166,15 @@ struct dma_ops_domain { static struct iova_domain reserved_iova_ranges; static struct lock_class_key reserved_rbtree_key; +/* + * 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 @@ -2302,6 +2311,7 @@ static dma_addr_t __map_single(struct device *dev, prot = dir2prot(direction); + paddr |= amd_iommu_get_me_mask(); start = address; for (i = 0; i < pages; ++i) { ret = iommu_map_page(&dma_dom->domain, start, paddr,