Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756687AbdGXTMh (ORCPT ); Mon, 24 Jul 2017 15:12:37 -0400 Received: from mail-sn1nam01on0067.outbound.protection.outlook.com ([104.47.32.67]:44920 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756449AbdGXTKS (ORCPT ); Mon, 24 Jul 2017 15:10:18 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-efi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Borislav Petkov , Andy Lutomirski , Tony Luck , Piotr Luc , Tom Lendacky , Fenghua Yu , Lu Baolu , Reza Arbab , David Howells , Matt Fleming , "Kirill A . Shutemov" , Laura Abbott , Ard Biesheuvel , Andrew Morton , Eric Biederman , Benjamin Herrenschmidt , Paul Mackerras , Konrad Rzeszutek Wilk , Jonathan Corbet , Dave Airlie , Kees Cook , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Arnd Bergmann , Tejun Heo , Christoph Lameter , Brijesh Singh Subject: [RFC Part1 PATCH v3 12/17] x86/mm: DMA support for SEV memory encryption Date: Mon, 24 Jul 2017 14:07:52 -0500 Message-Id: <20170724190757.11278-13-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170724190757.11278-1-brijesh.singh@amd.com> References: <20170724190757.11278-1-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: CY4PR04CA0049.namprd04.prod.outlook.com (10.171.243.142) To CY1PR12MB0150.namprd12.prod.outlook.com (10.161.173.20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9480b3b0-8795-4653-59c5-08d4d2c7632a 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:CY1PR12MB0150; X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0150;3:1nw27ZTl97L1HSvqztOSKLwtX/pbltSxpQAJoVQRei5Lamuo9a7fl6bFs8m8v2x4JTxN/JqfJjyOE++edO5gt6G4HaBItfeNqSjyPLQqu5n7qJi2fZdLPIYNkb9qNmj8pDEB+DKezSSj4a9hIUegTtQ9IcoFu96JUCQFye/EbPVYMuZ3SY3+tcsyowhDJ+s2myO9wEbY7qbkPJL2WqRKF1O4orin/SehIzzYUxAQ4zqQl/pxmFt5SUK3eAT3Fh1Yaz2zQZLgO0janQRorJPHOwseyZiWOVHA9Fnm/ckuzuy5vFR4UYkxU/tDqholUAxfTgMJqsE1WGNqFIREeBMxPX4IX2j9DGhC047MkO7sam6Gfa1DJ3qjRfHSlEU97auD5Z6sx9RnrZkga/3m+x4GtBV/GQOGzK1NyJVaufVHQFBRTZtaxAzfP4QNYBx68bGzY5QvC0okvWHH6PzPgoBd1oJgVrqhJo4sEclu1ot3KZ3LxJ8S4yvdETY6GfQtqPVsOXyEc++vjngg+/cMU/gsDqK4X1VGZxDYeqmcMAHhj/vpv96zMtu9dSmfGFK+TIZr4aWKTHhRSQnKj3ri3j1UM+wXt4DMJS4P1tvG5a+Qfb6kdMxcZAICpwsaX7IhPrWd+CYV+qRrzpsCXYga5xNf6DIki31azX/wXLdw+Im+e/VLNeMQcCqw2beGLVFjxlY6EzeJ2DCY2ZOB+7wwrxdMPSyG89qZYAsUWspOqN5Rbmss5tVdJUf+aCtzuDROz222RlZ9RQ6bEQf/RrihGkZBmQ== X-MS-TrafficTypeDiagnostic: CY1PR12MB0150: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tn5QJdbn01cpka20YYoU7NYMwEevMFq0a7+AOfIC7H9M/5AshcfnKq/WecIfVZBvN6vv2pZCkeGd9YmIN4svjiKTIu5KnumnoZty1r+nKECmOe9hO8 X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123564025)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY1PR12MB0150;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY1PR12MB0150; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR12MB0150;4:D6+hiKEhbqm5bzRMYE1fCZXXSbirEfIKg6AIS9cQMi?= =?us-ascii?Q?MVTaH+vU2E2tMqVs6Y2uYXt9fIHy6UNfXwX3Zk/DElGbRe4aELOyshAJu95P?= =?us-ascii?Q?Gyg4eFTrXxiVgVWB5evJEEvtJHJ60JHrLXpbooKVii6f4Iwn5Y84kRRUOM6c?= =?us-ascii?Q?bkU54R3nV3SLX4XPURCMfGD5ccVU1ZS6AdziiXnogtOsne2pZllrI7B7vDt9?= =?us-ascii?Q?QAER0izvlNI93W0tPu7o99wLPFmsD5ilHO426e/nw19CAeflXqYcGmGkSf5E?= =?us-ascii?Q?OZMyPs+nPQrvJEIISItrJe5DIrqLJ9hVNtfRUVkRwQJhy8Htnb9bpoxbNRnb?= =?us-ascii?Q?LvQBbORiFUnFTiRBa/ksbmZdL/yqqkRekylOEfoZG+M7dUVO2EXwhx/p6wzP?= =?us-ascii?Q?+vPO6NscuXA6Ctrj8GntKassRWTPun4JsXAEAFAYHnntpkizeZnSfGzhl7fo?= =?us-ascii?Q?Yj2D9tJYihQmYy+fwwX9EC7HJBnFGw54XadqRr561BtMDO+4jKl4FMB9h2Mp?= =?us-ascii?Q?TT6YvFKNnI237NVSA7YW2jGcfyqA9yjxawYE1+f2H9WYkHTrzF5OVpMAmtaH?= =?us-ascii?Q?IetIxNAEcCqupPM9I+qKNsUNhh+SUOX7i5R5JxP/FlCB+A1HqDTrFVNpgRM5?= =?us-ascii?Q?9PkgxGMpb9Sz4pHQcosUO4jUXfGDcskMn7jMjV8FYacCzcQZ5OUQyhzM2AHT?= =?us-ascii?Q?WZ8VvfmsgQv5yH/F1jIZDlAmI97QgCEaWP/z+YRIMK1RbFpzGNiYT3JeolvP?= =?us-ascii?Q?THDa2fEMWzMYVtvC+91o0i8MaLrUmUoXGgAggMTJy2YyF54pFFUkejXNoXMR?= =?us-ascii?Q?arLEfBvvgDU9/Nh2hQnvGlv1b0+heb0pH+3NjLX60oSq3FhEFu76YTJKETtU?= =?us-ascii?Q?sElqk9qTd+w1juqDwMFdnbeJd6f90aRlhv2VnJpX2n/reKAuoGrj1AxQC/3c?= =?us-ascii?Q?FUk1fV6J2QVejsUzLd90Ohwi7nFqjGwQvyM+bS9ppuB0dFScCVvM1eW2tcZV?= =?us-ascii?Q?ThmFwpe/iUcCaa72MmAW0lvSiBM5aqxb92bFGXH/NciJVzvxOnKGamuejz5x?= =?us-ascii?Q?biBbfqws6ZQUiHZyI5hbNOaa5xvLCG1mm/UPH/TVOS0wxahLEe8FWVDfRPQe?= =?us-ascii?Q?N6sJaWsgYdc4ttGiLZmdPZmvRFlwjBocRV6Bab8OdGoRS5OsfWXgQJgN8BQJ?= =?us-ascii?Q?REJpWPwCN/vFrjT9WchdzZjiGvi251zvF/?= X-Forefront-PRVS: 0378F1E47A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(7370300001)(6009001)(39840400002)(39850400002)(39450400003)(39400400002)(39410400002)(39860400002)(199003)(189002)(4326008)(81156014)(7350300001)(81166006)(50226002)(50466002)(68736007)(36756003)(38730400002)(1076002)(110136004)(53936002)(6116002)(25786009)(48376002)(8676002)(86362001)(305945005)(54906002)(7736002)(2950100002)(6666003)(50986999)(101416001)(47776003)(105586002)(5660300001)(5003940100001)(7416002)(33646002)(106356001)(66066001)(6486002)(7406005)(97736004)(189998001)(3846002)(76176999)(2906002)(53416004)(42186005)(478600001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR12MB0150;H:ubuntu-010236106000.amd.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR12MB0150;23:ecLve+gcQrBArkLBb9g/0B1jQteIHcxEwbWshAz5N?= =?us-ascii?Q?BWHAwT31BmEcl6G3yZyP7DSdVhH6c/tCruCY4r+ZV4aShaddJ/GhgvUBcF26?= =?us-ascii?Q?akHbwN73x52ztuW5F8qUY1KX/UkY5rXu6la7q5jRmfM4+z479X3rmqn7Md9x?= =?us-ascii?Q?Q7t5pkJCZfApZLODMEkkzdrsq0VkiDZx7ngSOtqRdCrBQGoMxQjvsT5hy4lZ?= =?us-ascii?Q?Rypr4NXChR4pgwd34mbYP2CQ/39pIGMbknJu+lHzCwDLyviGf6YE6AckKxMd?= =?us-ascii?Q?KZF27p2ZjySmwyvGpM+yR1Sr+bmFGZCw0keY5E5XQxldbwBfnXmdcNB0MASz?= =?us-ascii?Q?Z1VWjb3liMgAGqKs/iSxFesxWGZ8Yw9mK+VIjs4RNOCn1/RryHsWghDFhv6y?= =?us-ascii?Q?am2nwsBacvqMQgyHr26JhmT1ACVzu+zt201Tx2LDbQV6aTb0JzCkTkmzuhj3?= =?us-ascii?Q?ttfPlSgK2o0jnQanOg89Q0DW+Bj08Ot0xwk7NU91fVv6H5FEEAYmMnMSQL5K?= =?us-ascii?Q?pfKOz2cuUeRCwF3U1XKi3Y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cAt9UT6?= =?us-ascii?Q?ma2nrI36ccN99qaFf1G+TJs5xOjlQAHGWbSVWbEybxrtrDuCTZ3p0HoLI2C6?= =?us-ascii?Q?RzDqt5XSOlCWMK0G/sN0oT?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0150;5:OEHEsRR6BZhbze0V58joIrWjLdq1p5g0k01YAzFy2RC5962buuCM8mLvZKQlupYiUgoXVrka5AElLEiCJHz7A8ghzBSteTaVmLYY7um4ooLQtXSAYz8fR6p0iXdmDkOPjmjv64GzLqXP/VRllWUdPeqOAs1c+m7bjYPl16EKr3WqFbX9ATkpTu+7MAaE8MTnG3Jk2lF+eob/Jft3WIXOUqc4cULPPJiRVC0ClFwze+QskuLCGyVPbpPqw8wTPBl79L13K8uLtCZN7vhmfqY0Te1qGQ8P4ukra00v6Ea93PMANWQIP3jyutqbbETlpFxz/J3qETcVXMse7IT8cgXd3CJNuEhx1dylOnT7HmbWRRFvF3mVYFhVzPqQ8zRJHmtHzhoF76s7EAWIdUEW7Pg5+Q+AOVtTnA0WXxsM+PvuXDfyXuwJcu8CB2Qp8Ct1YSF2o9YkEw8TvWgJwtu0z9oJ6b7Xy286cNE4JhoJSXSXeQbi6wbZBtnF5bUHnf2MIHBS;24:Ry4GojK1A7ws5tpxXtMHF71nODwLP0SWx3AVkETTYR+6rjyGIZJqUwFn1yckWMNvdBX6MdUV4JnTu0ca+Kg1dAB8DPnp8VSruWXTNFb1yEU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0150;7:ipB+fo9XcERFtgZXdnPBu73zafebEB9fybypdAkZf99T0VbFTcqraAVGCuq4c4fQ95Pxak4366j8Hpoo0k7TydVj3GJZLpANTqG/HPT9vMdPuGtvY5or5N79pW+m7iQc8xwtr9lpHoioo3xe4pXtz8yNVyj4Uh2jkyTOkNjcF7byBbk3Ivs3i24hI0X33EWwZYy0cCebdwqouebtxuGiWM057gAW+neW9A97WLzwcSUetQytMRKliVJR5NwMvq1/AMHHUXLLSlyNisaLerVNvbkGXFgC8NyVqbO2HRkyoMrnr0Z2fkW1eSqlTVcUzW6KyaiH6aVjChP44KA7uEV23qwWjaD/a2RNnU1HcyKLpuFwk7QtyTj+LEzBo9cQAGoosPgj5+rUP/wvU2DkXD+Xut4Pc2Dr4DHiQEKQmOH/aK3usGuEETBHsoaBA2P0eOVKXEt85JdWOGf6mCn57vCgsT5IhlN4WG8WQmjIXdun2PgbCX7c5OXX4rG8iCEhXohwK/lW7kkpY93AOY7C9rgEI6tPlM+6Te65ifNAE53DQEbsAl9PJd7F4TWyIbV5P7eN7eIjBuFFy/v8SB5ARC8n8SwjeNBxEgcREQEIEPDYlsBYaHyz89NEIc5DvYpiQQuxKBV7S5EdpAVj0uG05dfcCcbTrOLiqonMwjMUSfFEiAJZ5qX9DWhnQ5zXjeNpIekIMdMcKmQe14ltidSVhf9Y2FAZaqABY1Y0wBQJoVxlfLzvJU5oeXNASvX8TPJKzWWOj/vu6pFCqV3xGn3Dm0uu7DekoO779oSwyetZEnNfQOk= X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0150;20:mMi/4yr3t+ecxEKqPSUuDz8LOf9XZ9EEn6UTgxDdhYqq6HM2qRkw7KXh+u4v6AQf5N6PGxx6VrFJ0fiq80CZN1kVA3NBpPpRJEKj1hXwZaACTyIdvLFesxVsmzArVvaHOU6De+StqFUpqjC6lRKh10cpDmrq4xlJiJaSoP9sqTIx/smqD9XVUw/Lp7l/HBzsEnrxMiMrfsRYAJsCmecVrEGhJGjQ+nD9VV+h62qzG1LzwSE9kHU/QfTaRJ90NtqX X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2017 19:08:35.5596 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0150 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4396 Lines: 138 From: Tom Lendacky DMA access to memory mapped as encrypted while SEV is active can not be encrypted during device write or decrypted during device read. In order for DMA to properly work when SEV is active, the SWIOTLB bounce buffers must be used. Signed-off-by: Tom Lendacky Signed-off-by: Brijesh Singh --- arch/x86/mm/mem_encrypt.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ lib/swiotlb.c | 5 +-- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 1e4643e..5e5d460 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -191,8 +191,86 @@ void __init sme_early_init(void) /* Update the protection map with memory encryption mask */ for (i = 0; i < ARRAY_SIZE(protection_map); i++) protection_map[i] = pgprot_encrypted(protection_map[i]); + + if (sev_active()) + swiotlb_force = SWIOTLB_FORCE; +} + +static void *sme_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, + gfp_t gfp, unsigned long attrs) +{ + unsigned long dma_mask; + unsigned int order; + struct page *page; + void *vaddr = NULL; + + dma_mask = dma_alloc_coherent_mask(dev, gfp); + order = get_order(size); + + /* + * Memory will be memset to zero after marking decrypted, so don't + * bother clearing it before. + */ + gfp &= ~__GFP_ZERO; + + page = alloc_pages_node(dev_to_node(dev), gfp, order); + if (page) { + dma_addr_t addr; + + /* + * Since we will be clearing the encryption bit, check the + * mask with it already cleared. + */ + addr = __sme_clr(phys_to_dma(dev, page_to_phys(page))); + if ((addr + size) > dma_mask) { + __free_pages(page, get_order(size)); + } else { + vaddr = page_address(page); + *dma_handle = addr; + } + } + + if (!vaddr) + vaddr = swiotlb_alloc_coherent(dev, size, dma_handle, gfp); + + if (!vaddr) + return NULL; + + /* Clear the SME encryption bit for DMA use if not swiotlb area */ + if (!is_swiotlb_buffer(dma_to_phys(dev, *dma_handle))) { + set_memory_decrypted((unsigned long)vaddr, 1 << order); + memset(vaddr, 0, PAGE_SIZE << order); + *dma_handle = __sme_clr(*dma_handle); + } + + return vaddr; +} + +static void sme_free(struct device *dev, size_t size, void *vaddr, + dma_addr_t dma_handle, unsigned long attrs) +{ + /* Set the SME encryption bit for re-use if not swiotlb area */ + if (!is_swiotlb_buffer(dma_to_phys(dev, dma_handle))) + set_memory_encrypted((unsigned long)vaddr, + 1 << get_order(size)); + + swiotlb_free_coherent(dev, size, vaddr, dma_handle); } +static const struct dma_map_ops sme_dma_ops = { + .alloc = sme_alloc, + .free = sme_free, + .map_page = swiotlb_map_page, + .unmap_page = swiotlb_unmap_page, + .map_sg = swiotlb_map_sg_attrs, + .unmap_sg = swiotlb_unmap_sg_attrs, + .sync_single_for_cpu = swiotlb_sync_single_for_cpu, + .sync_single_for_device = swiotlb_sync_single_for_device, + .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, + .sync_sg_for_device = swiotlb_sync_sg_for_device, + .mapping_error = swiotlb_dma_mapping_error, +}; + /* Architecture __weak replacement functions */ void __init mem_encrypt_init(void) { @@ -202,6 +280,14 @@ void __init mem_encrypt_init(void) /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ swiotlb_update_mem_attributes(); + /* + * With SEV, DMA operations cannot use encryption. New DMA ops + * are required in order to mark the DMA areas as decrypted or + * to use bounce buffers. + */ + if (sev_active()) + dma_ops = &sme_dma_ops; + pr_info("AMD Secure Memory Encryption (SME) active\n"); } diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 8c6c83e..85fed2f 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -507,8 +507,9 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, if (no_iotlb_memory) panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer"); - if (sme_active()) - pr_warn_once("SME is active and system is using DMA bounce buffers\n"); + if (sme_active() || sev_active()) + pr_warn_once("%s is active and system is using DMA bounce buffers\n", + sme_active() ? "SME" : "SEV"); mask = dma_get_seg_boundary(hwdev); -- 2.9.4