From patchwork Mon Jul 17 21:10:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 9846145 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 D31E560386 for ; Mon, 17 Jul 2017 21:12:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 171002621B for ; Mon, 17 Jul 2017 21:12:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B794274D0; Mon, 17 Jul 2017 21:12:42 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham 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 BD54C2621B for ; Mon, 17 Jul 2017 21:12:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751556AbdGQVMh (ORCPT ); Mon, 17 Jul 2017 17:12:37 -0400 Received: from mail-bn3nam01on0054.outbound.protection.outlook.com ([104.47.33.54]:47168 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752013AbdGQVM3 (ORCPT ); Mon, 17 Jul 2017 17:12:29 -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=b+yNg43OAft2Yr6wkxk12Uyn6Gq6iY2ZPCzlU7AR4sw=; b=bPDP7i66eoDkRQahq45mUEGLnLV34ES8S7fFT3rmwp2WHdG+YSzyyic62fRPXertUsmHmbKLLhIJf7fRoI5Ljtu2KTaMAsOaeCdHOqQhNpTfDx1Wz3wqJ/KWUw5mxG18HkZGem1IO4h5uKq3wZEqbNc/ajmqZZXBmTRjGbEllns= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none; kernel.org; dmarc=none action=none header.from=amd.com; Received: from tlendack-t1.amdoffice.net (165.204.77.1) by MWHPR12MB1151.namprd12.prod.outlook.com (10.169.204.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.13; Mon, 17 Jul 2017 21:12:22 +0000 From: Tom Lendacky To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kasan-dev@googlegroups.com Cc: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Konrad Rzeszutek Wilk , Andrey Ryabinin , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , Paolo Bonzini , Alexander Potapenko , Thomas Gleixner , Dmitry Vyukov , Rik van Riel , Larry Woodman , Dave Young , Toshimitsu Kani , "Michael S. Tsirkin" , Brijesh Singh Subject: [PATCH v10 24/38] x86, swiotlb: Add memory encryption support Date: Mon, 17 Jul 2017 16:10:21 -0500 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR03CA0008.namprd03.prod.outlook.com (10.168.230.146) To MWHPR12MB1151.namprd12.prod.outlook.com (10.169.204.15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6d067b19-14eb-41a7-1d52-08d4cd58865f 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:MWHPR12MB1151; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1151; 3:Lk7Ev29Xw5U0/DLdUZZAVIBzyzlRkk4Amw9lHz/SgNscDecTgcv48NQ4djW+w9C96UgRRa8dlaW3tonv0lSr7xv4BT0KWa/8iP+iUhDKPunoMEEJog78R/ZzkIR0dC5PQxazzDAxjBEGYef5xn1WrFT1Vy1qpnDN9Q5/MHKeZLon0aXQs+h5tLhlW5RnCIDN54tM2K2XaeWB7chVsCYTw9x7JXcsibb2DJxZH0+7kC+V0NEB0yPot0ranWF4n3rsgwnu4w8Hl7tdF9W7sl7MSmZpNOMTyPUrdEEKj4G1ZRg9Xheltk/7IUCS5CvVjEo47JoI9kLxc5etDu4RZ+nkfYrJT1iulSRKa2FXQNkpufNxC6aiVFXP6/dMerQ7Vac3a9UOIhlglXMwW96YlPksAPySkxcmOL1sw0C2JmxIswRfN6ZwkV1dhEML+c9sYT3fJJ0Q7iGDJgOZgtz8k4RfV1mFCLdX6x4XO2WEgFRSZM2F/o5Cl4UH9TvRbw9aE6zSY0PiK7yHhzxA7QdqqFSu/keFxJEsXHK5hgSxfsl3fQWgjjoUMUVu69GdT1kDWbUobwXULYMOuyTUPk1qNjbCtjz0hWCVeRPQModzWqvxTFqw+7z1PhTwYIxi1tiNFQ3/0FNgJZoKLq6RRENz+OnF2kuwXPljHbYs0utgpCsVRrmyN7iBriyUyCNfq1s0S4Y/HdlIYh8pm8gSZNdP9yA3pgjSsT+TMoI1kwYd8Vk/oqS6WIvRzlTcGEPIOxmsQWWITwsgOjsvp1AbozgVmrr6iw== X-MS-TrafficTypeDiagnostic: MWHPR12MB1151: X-Microsoft-Exchange-Diagnostics: 1; MWHP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u7nD8KQwzeMjHSblxq7LbR85MNwjSbwN1rEdHvBSQNJtVl+TjQ+rP84x9x9atGVSO1IkfCwYsbsjkEr2Nsk41bIF5kri62N4pPwBwWd4w0yUXLlMJOpvcxOQ X-Exchange-Antispam-Report-Test: UriScan:(133145235818549)(236129657087228)(767451399110)(167848164394848); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(2017060910075)(5005006)(8121501046)(100000703101)(100105400095)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123558100)(20161123555025)(20161123562025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:MWHPR12MB1151; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:MWHPR12MB1151; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1151; 4:Ax9OW2gPuojbdfvGY4HCqNJT7NkR2CDy+F7Tl6mufW?= =?us-ascii?Q?9dJfGS0gN5TOru8Zg6cEBrHitWqRhdxQOYZFfsfCNRQCrAKnvkwr1dbTeITW?= =?us-ascii?Q?qbtSvVXaWngy7LNP8XbGDE4W2LwiYBv4ba9peRkBJiDi+Yv3XDyTG6ypg4a5?= =?us-ascii?Q?l32X/uWjoQzY32rCGJJ/Hv6RA8YRhHvhjsKpKRuycJahigPpxLyyMf8ze2fy?= =?us-ascii?Q?NgmY5UbFgiuetfmxPm3AHKcdhvJZHXW5nnj3pw/W7KBZCIkxSwBgZDiTZrdX?= =?us-ascii?Q?sOaadoJuvcLqiHdbILujSFyGWFErpU202GqMWZ64oWWl7rLhhBTtdhRf0jWz?= =?us-ascii?Q?mH+WaMLFLe/LeV7Zs53rZmN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us-ascii?Q?nctgRhpL4Xy9ZL+bai3mWlX+S1vVCKW1xmwokOLRxkGUsfuPdRqcZbTJcDcX?= =?us-ascii?Q?Xda/jnyIqZOd9F0vj15+mVx0X5F8EGv2hCZq9JkZzU?= X-Forefront-PRVS: 0371762FE7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(39410400002)(39850400002)(39840400002)(39860400002)(39400400002)(39450400003)(25786009)(6506006)(33646002)(54906002)(7416002)(76176999)(478600001)(8676002)(50986999)(6486002)(47776003)(5660300001)(189998001)(42186005)(38730400002)(305945005)(72206003)(53416004)(66066001)(50466002)(48376002)(110136004)(118296001)(2950100002)(81166006)(5003940100001)(3846002)(36756003)(53936002)(7350300001)(6512007)(2906002)(7736002)(6116002)(86362001)(4326008)(50226002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1151; H:tlendack-t1.amdoffice.net; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1151; 23:mfdrxs/K4iLxa7h4XHBk3G09qY+/eQ7PEOTuE2DQ8?= =?us-ascii?Q?Jij9pyfbLwgGaAtePWeuh5eCxjGS9O+t131hG5XXloBABFzNRnsKbMDlJefK?= =?us-ascii?Q?IR1sf30dkvk5+R6q1/5PhSEodtUJ7+wZX7LSJLaavj479iTQlZ6g0caCumNu?= =?us-ascii?Q?XdNUzqxtL1mrxUVW/PwQTHEss2Az168EIimsIlr2fOpZBIMgnpm8vRqFo0Hx?= =?us-ascii?Q?Z/RVJKkBDhlnWiDPkERRHzBfNCPD18Bf0EkWyfpP3QwcEIi8YRAImUeGwcZJ?= =?us-ascii?Q?NPZBJpPxzCAM7ffofrf+3nbjvJpNvoJZPtEoA5w13nqXI7glupaIrxh/Bqx0?= =?us-ascii?Q?AQkEfQ7eSzCvC4Ig8soPgnF6hwwu97e9bsDmdJfsncYHQ0ksN3A5wlxkiYSo?= =?us-ascii?Q?guirAISYzVc5P+s2QwZshQIAuTzd01ZoneCS/1twrNGpmYenhKlh8dDcJyXO?= =?us-ascii?Q?h+xFNXYcc89Cl9kMbmJZdABEX/Dx0KC+MlshiTawTBC41Y3BOWYc/LEUbC3A?= =?us-ascii?Q?w1hUALb4MA0pj0Ltp3xxEuR0onkj5sq39Qr8LKeXKRdLw7PLlTpIIe97A++8?= =?us-ascii?Q?yzoZxm8RpcM+Q8ixry72vyJq7hA4EzkoH1R3e195L762KKtCazXs1RB0F5H6?= =?us-ascii?Q?1xyISXcwO21SqaP7a3E4xmU17HEP7iZ2sX7yTkR/8p4+v7GDbzjGfF5xRtla?= =?us-ascii?Q?yreNlvLq2p8flypDxqjO5NjVbP6WMkrI6yGuO4f5B2s6v7YFlON06KLmo4Yn?= =?us-ascii?Q?C7odbaKHjhZS1w5W+YcbUFfKmMHKAuJf+8d3p7Lu9hP/mDFNAOGbJIjR9Ac5?= =?us-ascii?Q?hPfYBClXeMYXqr3H7eFsaA0Uk6BTBenKzdAue+uozKMof1zkmOkrXhat+wri?= =?us-ascii?Q?nUb65Fcuvk8ocDYRX/TVRxcZsCO38fKp9pynhA0eo/TjyqvtSlZiNVC2vDku?= =?us-ascii?Q?895VmEyspFjmjF9Xx6jcHxpgiKi3x4yNT+C9yqHptNeapcxkxMJ+klLR/m/S?= =?us-ascii?Q?MaZvWtYvx8QFB4r/Ycwv4PKvT091Uo+pgPMvfOm7TGS4/8BwNseWVjHkB+XZ?= =?us-ascii?Q?91IUtFNNzwgx3aIFlebKEsR85Tl3vwkmlIwqCx6S+oIRToSYqRoarSc0qHwT?= =?us-ascii?Q?55GQKVGdvUetH5xWdOuVPDi3fNSNUuzVXe5q8JAQk9pNu+nFbxcA/BMU37w3?= =?us-ascii?Q?L7hrJcZoHhy5yw=3D?= X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1151; 6:1ZdYeaoh7QX1frcRMiI7lgnFYV7dcEwFR1wLWFr8Dx?= =?us-ascii?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DDvCjWfQtee418EGumxhWAFpi6FEn+R6RniwTCKuAXwRkpgzfLd/nw7U9pdFzg4C5ZGuZCmjmYYV6P3bKZrAdVAuAAmVQEI5GuY9+MQv2UpJzkgQpatfSY/bEo90Wo0L+VH4q1a02YI+tqinRngmqec1LlUPQK8hW4u057QlhQ7kCGwwMwhWCx8o/cPhtWA5yZiuC9diPBKWtC8h+apxdpcK+Epj8fowW1lC0QWSdCpAjGcUlUrFVAAohmcHY9DeqUn6+WPPy5XCcxEpJZi47wPX7fD3QjKdYWfdo/p17F53CvxwRx7pc90EmLzHmkUNG5UPOC0YS5XS4R/ePkzyAHI+Cy1FhsXZnmLSCcbu0cxoX2aE3lx6JV1arPEhTRKEwJ2eGAca49DQIsGnYYx/TI47GgBYCdLZdm60CfGIFRgvl+9nMfzLxVJo74c5heRN5qU0iHNAIQQ6GaTmM/1J9wmjywtnT9WUo8mEilCXwssBjYS3ECnMLMtzHiCGdklMJbjqkehXcn44vUMwXD+9zk0Avmd+gUf9hqmneT0HPGaCjDIAh4rZ1SYS98WzG+OvEcmAFl3gRtbiVOVt34LMPcYb1MJAFzmXIOxqGIHI= X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1151; 20:eyyU65d3ZpR1U8aGyMkepyOMulhl+es/iWNtSUSc8m2kggOgQKE++8byMBOzTjpjkIV/ai2AM2RVPrV2NJU3/BdVWaXgB9X2PYh6K8uXilO+mLfj+ofz+P/OQ+mnyVwgMTncrLiKVvhZORe+TnFQ2zflEO/B2RoWYaLtUROLQJD+tuucq0Qf6ICx068CA96uZv3BWfT9yC8UXDH06xDOJwj/EBfsEXPbmGYmDoC4Am02KQ5AGVxjrt8hg8gWVuZH X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2017 21:12:22.5639 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1151 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since DMA addresses will effectively look like 48-bit addresses when the memory encryption mask is set, SWIOTLB is needed if the DMA mask of the device performing the DMA does not support 48-bits. SWIOTLB will be initialized to create decrypted bounce buffers for use by these devices. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/dma-mapping.h | 5 ++-- arch/x86/include/asm/mem_encrypt.h | 5 ++++ arch/x86/kernel/pci-dma.c | 11 +++++--- arch/x86/kernel/pci-nommu.c | 2 +- arch/x86/kernel/pci-swiotlb.c | 15 +++++++++-- arch/x86/mm/mem_encrypt.c | 22 ++++++++++++++++ include/linux/swiotlb.h | 1 + init/main.c | 10 +++++++ lib/swiotlb.c | 54 ++++++++++++++++++++++++++++++++------ 9 files changed, 108 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h index 398c798..1387daf 100644 --- a/arch/x86/include/asm/dma-mapping.h +++ b/arch/x86/include/asm/dma-mapping.h @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_ISA # define ISA_DMA_BIT_MASK DMA_BIT_MASK(24) @@ -57,12 +58,12 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) { - return paddr; + return __sme_set(paddr); } static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr) { - return daddr; + return __sme_clr(daddr); } #endif /* CONFIG_X86_DMA_REMAP */ diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index ab1fe77..70e55f6 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -34,6 +34,11 @@ void __init sme_early_decrypt(resource_size_t paddr, void __init sme_encrypt_kernel(void); void __init sme_enable(void); +/* Architecture __weak replacement functions */ +void __init mem_encrypt_init(void); + +void swiotlb_set_mem_attributes(void *vaddr, unsigned long size); + #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define sme_me_mask 0UL diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index 5e16d3f..0accc24 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -93,9 +93,12 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, if (gfpflags_allow_blocking(flag)) { page = dma_alloc_from_contiguous(dev, count, get_order(size), flag); - if (page && page_to_phys(page) + size > dma_mask) { - dma_release_from_contiguous(dev, page, count); - page = NULL; + if (page) { + addr = phys_to_dma(dev, page_to_phys(page)); + if (addr + size > dma_mask) { + dma_release_from_contiguous(dev, page, count); + page = NULL; + } } } /* fallback */ @@ -104,7 +107,7 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, if (!page) return NULL; - addr = page_to_phys(page); + addr = phys_to_dma(dev, page_to_phys(page)); if (addr + size > dma_mask) { __free_pages(page, get_order(size)); diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c index a6d4040..4fc3cb6 100644 --- a/arch/x86/kernel/pci-nommu.c +++ b/arch/x86/kernel/pci-nommu.c @@ -32,7 +32,7 @@ static dma_addr_t nommu_map_page(struct device *dev, struct page *page, enum dma_data_direction dir, unsigned long attrs) { - dma_addr_t bus = page_to_phys(page) + offset; + dma_addr_t bus = phys_to_dma(dev, page_to_phys(page)) + offset; WARN_ON(size == 0); if (!check_addr("map_single", dev, bus, size)) return NOMMU_MAPPING_ERROR; diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c index 1e23577..6770775 100644 --- a/arch/x86/kernel/pci-swiotlb.c +++ b/arch/x86/kernel/pci-swiotlb.c @@ -6,12 +6,14 @@ #include #include #include +#include #include #include #include #include #include + int swiotlb __read_mostly; void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size, @@ -79,8 +81,8 @@ int __init pci_swiotlb_detect_override(void) pci_swiotlb_late_init); /* - * if 4GB or more detected (and iommu=off not set) return 1 - * and set swiotlb to 1. + * If 4GB or more detected (and iommu=off not set) or if SME is active + * then set swiotlb to 1 and return 1. */ int __init pci_swiotlb_detect_4gb(void) { @@ -89,6 +91,15 @@ int __init pci_swiotlb_detect_4gb(void) if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN) swiotlb = 1; #endif + + /* + * If SME is active then swiotlb will be set to 1 so that bounce + * buffers are allocated and used for devices that do not support + * the addressing range required for the encryption mask. + */ + if (sme_active()) + swiotlb = 1; + return swiotlb; } IOMMU_INIT(pci_swiotlb_detect_4gb, diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 0843d02..a7400ec 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -13,11 +13,14 @@ #include #include #include +#include +#include #include #include #include #include +#include /* * Since SME related variables are set early in the boot process they must @@ -177,6 +180,25 @@ void __init sme_early_init(void) protection_map[i] = pgprot_encrypted(protection_map[i]); } +/* Architecture __weak replacement functions */ +void __init mem_encrypt_init(void) +{ + if (!sme_me_mask) + return; + + /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ + swiotlb_update_mem_attributes(); +} + +void swiotlb_set_mem_attributes(void *vaddr, unsigned long size) +{ + WARN(PAGE_ALIGN(size) != size, + "size is not page-aligned (%#lx)\n", size); + + /* Make the SWIOTLB buffer area decrypted */ + set_memory_decrypted((unsigned long)vaddr, size >> PAGE_SHIFT); +} + void __init sme_encrypt_kernel(void) { } diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 4ee479f..15e7160 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -35,6 +35,7 @@ enum swiotlb_force { extern unsigned long swiotlb_nr_tbl(void); unsigned long swiotlb_size_or_default(void); extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs); +extern void __init swiotlb_update_mem_attributes(void); /* * Enumeration for sync targets diff --git a/init/main.c b/init/main.c index 052481f..9789ab7 100644 --- a/init/main.c +++ b/init/main.c @@ -488,6 +488,8 @@ void __init __weak thread_stack_cache_init(void) } #endif +void __init __weak mem_encrypt_init(void) { } + /* * Set up kernel memory allocators */ @@ -641,6 +643,14 @@ asmlinkage __visible void __init start_kernel(void) */ locking_selftest(); + /* + * This needs to be called before any devices perform DMA + * operations that might use the SWIOTLB bounce buffers. It will + * mark the bounce buffers as decrypted so that their usage will + * not cause "plain-text" data to be decrypted when accessed. + */ + mem_encrypt_init(); + #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start && !initrd_below_start_ok && page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) { diff --git a/lib/swiotlb.c b/lib/swiotlb.c index a8d74a7..04ac91a 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -155,6 +156,15 @@ unsigned long swiotlb_size_or_default(void) return size ? size : (IO_TLB_DEFAULT_SIZE); } +void __weak swiotlb_set_mem_attributes(void *vaddr, unsigned long size) { } + +/* For swiotlb, clear memory encryption mask from dma addresses */ +static dma_addr_t swiotlb_phys_to_dma(struct device *hwdev, + phys_addr_t address) +{ + return __sme_clr(phys_to_dma(hwdev, address)); +} + /* Note that this doesn't work with highmem page */ static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev, volatile void *address) @@ -183,6 +193,31 @@ void swiotlb_print_info(void) bytes >> 20, vstart, vend - 1); } +/* + * Early SWIOTLB allocation may be too early to allow an architecture to + * perform the desired operations. This function allows the architecture to + * call SWIOTLB when the operations are possible. It needs to be called + * before the SWIOTLB memory is used. + */ +void __init swiotlb_update_mem_attributes(void) +{ + void *vaddr; + unsigned long bytes; + + if (no_iotlb_memory || late_alloc) + return; + + vaddr = phys_to_virt(io_tlb_start); + bytes = PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT); + swiotlb_set_mem_attributes(vaddr, bytes); + memset(vaddr, 0, bytes); + + vaddr = phys_to_virt(io_tlb_overflow_buffer); + bytes = PAGE_ALIGN(io_tlb_overflow); + swiotlb_set_mem_attributes(vaddr, bytes); + memset(vaddr, 0, bytes); +} + int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) { void *v_overflow_buffer; @@ -320,6 +355,7 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) io_tlb_start = virt_to_phys(tlb); io_tlb_end = io_tlb_start + bytes; + swiotlb_set_mem_attributes(tlb, bytes); memset(tlb, 0, bytes); /* @@ -330,6 +366,8 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) if (!v_overflow_buffer) goto cleanup2; + swiotlb_set_mem_attributes(v_overflow_buffer, io_tlb_overflow); + memset(v_overflow_buffer, 0, io_tlb_overflow); io_tlb_overflow_buffer = virt_to_phys(v_overflow_buffer); /* @@ -581,7 +619,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, return SWIOTLB_MAP_ERROR; } - start_dma_addr = phys_to_dma(hwdev, io_tlb_start); + start_dma_addr = swiotlb_phys_to_dma(hwdev, io_tlb_start); return swiotlb_tbl_map_single(hwdev, start_dma_addr, phys, size, dir, attrs); } @@ -702,7 +740,7 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, goto err_warn; ret = phys_to_virt(paddr); - dev_addr = phys_to_dma(hwdev, paddr); + dev_addr = swiotlb_phys_to_dma(hwdev, paddr); /* Confirm address can be DMA'd by device */ if (dev_addr + size - 1 > dma_mask) { @@ -812,10 +850,10 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, map = map_single(dev, phys, size, dir, attrs); if (map == SWIOTLB_MAP_ERROR) { swiotlb_full(dev, size, dir, 1); - return phys_to_dma(dev, io_tlb_overflow_buffer); + return swiotlb_phys_to_dma(dev, io_tlb_overflow_buffer); } - dev_addr = phys_to_dma(dev, map); + dev_addr = swiotlb_phys_to_dma(dev, map); /* Ensure that the address returned is DMA'ble */ if (dma_capable(dev, dev_addr, size)) @@ -824,7 +862,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, attrs |= DMA_ATTR_SKIP_CPU_SYNC; swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); - return phys_to_dma(dev, io_tlb_overflow_buffer); + return swiotlb_phys_to_dma(dev, io_tlb_overflow_buffer); } EXPORT_SYMBOL_GPL(swiotlb_map_page); @@ -958,7 +996,7 @@ void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, sg_dma_len(sgl) = 0; return 0; } - sg->dma_address = phys_to_dma(hwdev, map); + sg->dma_address = swiotlb_phys_to_dma(hwdev, map); } else sg->dma_address = dev_addr; sg_dma_len(sg) = sg->length; @@ -1026,7 +1064,7 @@ void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, int swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr) { - return (dma_addr == phys_to_dma(hwdev, io_tlb_overflow_buffer)); + return (dma_addr == swiotlb_phys_to_dma(hwdev, io_tlb_overflow_buffer)); } EXPORT_SYMBOL(swiotlb_dma_mapping_error); @@ -1039,6 +1077,6 @@ void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, int swiotlb_dma_supported(struct device *hwdev, u64 mask) { - return phys_to_dma(hwdev, io_tlb_end - 1) <= mask; + return swiotlb_phys_to_dma(hwdev, io_tlb_end - 1) <= mask; } EXPORT_SYMBOL(swiotlb_dma_supported);