From patchwork Tue Apr 18 21:20:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 9686423 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 0DCB4602C2 for ; Tue, 18 Apr 2017 21:24:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3548252D5 for ; Tue, 18 Apr 2017 21:24:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7CA426E4D; Tue, 18 Apr 2017 21:24:22 +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=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 8932A252D5 for ; Tue, 18 Apr 2017 21:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932710AbdDRVUo (ORCPT ); Tue, 18 Apr 2017 17:20:44 -0400 Received: from mail-bn3nam01on0058.outbound.protection.outlook.com ([104.47.33.58]:47712 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758085AbdDRVUj (ORCPT ); Tue, 18 Apr 2017 17:20:39 -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=72U8MKFWKU9fyuZ1pcirGFpNF9mRbhtDXv2fkU+DB6U=; b=sq+z9A2HQigFY/d3Clf3EU8WDRqKyu1vo7BfbaU8h9CEOgiv1zfavaFQlh/+d2NCrADfSvezyb5otyQe7KMyaPnXn5KTH0GBYKuwXJg+nuwsJCMIMmVdzcOdDC1PFgzmRd0viCLkR0riXozC+EUt3HvUUXllmAmmJ1bx6ap++lM= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from tlendack-t1.amdoffice.net (165.204.77.1) by BN6PR12MB1137.namprd12.prod.outlook.com (10.168.226.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.10; Tue, 18 Apr 2017 21:20:23 +0000 From: Tom Lendacky Subject: [PATCH v5 23/32] swiotlb: Add warnings for use of bounce buffers with SME To: , , , , , , , , , CC: Rik van Riel , Radim =?utf-8?b?S3LEjW3DocWZ?= , Toshimitsu Kani , Arnd Bergmann , Jonathan Corbet , Matt Fleming , "Michael S. Tsirkin" , Joerg Roedel , Konrad Rzeszutek Wilk , Paolo Bonzini , Larry Woodman , Brijesh Singh , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , Dave Young , Thomas Gleixner , Dmitry Vyukov Date: Tue, 18 Apr 2017 16:20:19 -0500 Message-ID: <20170418212019.10190.24034.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20170418211612.10190.82788.stgit@tlendack-t1.amdoffice.net> References: <20170418211612.10190.82788.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: BN6PR03CA0059.namprd03.prod.outlook.com (10.173.137.21) To BN6PR12MB1137.namprd12.prod.outlook.com (10.168.226.139) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 19339766-2532-4bc8-9217-08d486a0ba89 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:BN6PR12MB1137; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1137; 3:CW8AI8I5LPn2ocqXH1wvzmQdgeciLGJ5q4Hnqedmuq3CM/masgj2sgZL5aieFF4uV9t5FgX3/9vC+P6JujPk7CTh08L6kSnUvYyiKk1fEvmjviD8zzCfAmht/hwQoAGgf8RX4GrMKaEIplINVVRZHxSJ82wVyxbi8Dnc6KYmcm5I1hngsqb3mCkZFDkcKRS0R2hRZgogfDDSigq9bj4nzUCdBSpGKmfBkzeN+PctKlA43HTtLSq5G0v0SnMV7wYk8O/CertpH0L4g4avLyk6VbzIJEN/qVuxn2+x5c6YuCFzd7w5trsxSFHH/aWLOyZnByAvMZ6CdTXBVwrBrk8P0SbCYRmYput+8b4YrNs6yas=; 25:qZkBMTZVZ6Epjm28cQixKJS6Cx6put1iKev3Y01jZBJxw/VrmdbJLg9uaeuFzVc2LdjRfZ+FUTEftUY2J7+rXm8aczQOf+nPc7SP1O5Ewt7Xs18BVOXz20n5NMjBil8+4xNZyD8LO1wtTOOM5GAQDYaSanTxAF0B/+Wsia6+UbFZETY8KPdFD2Rs7TpBC22+1wB8fr59+CyP8dmdYf81VnS7Dmad7CDj6+nbJzscyXhCFMG6KuAm6eSiYMQAGiwFr93PL2duRfYFairjQ0rwYYJqunF9A0edhshKEwTIZIly1wQj6BTAKU+Z0OlZAcm5cUlYdEn6oTBLd57CrkdmHFtO6bmBirGSss+kUZvXe2Og9QUc30yx2ip0TKfv5v91wDcH7yDwiO3VqDWkuam0ra22f8fIoUOhtu2asFflKBvoyUezXjSP97n9fPo1ASJMznNh1EYgsuo+VLX1ouhsSA== X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1137; 31:r/rn2Ey1xeHoTEVaB5obovWTQK7M/DgEICujIGwwbJ73yRBtBEG1q16fPaDar7ZLVvXAewlM1XqGE6BvLIySx9JrNBzGtYMgmw1T9Dgzm7BLiCTEhaZP6woQ0baMLK2ShcyV7KYxODeUJkjyUrgoqJf08DP5To/uWoUuazhuzuMFTnszAggCg4wQe/Yv8BZLdQXzpRAHmKLOD+HaSW+EvDDMf0bByvlXcMNsCmQd0IE=; 20:ESwKxOksaN1lSHazzitnLq6yvaPU32W3fUfQf+WuM4lkLPrRIs6lQMrx0jfYs5imw42F7M+e6jr0atQ7PYBjvZUeDosucJbDs+kJWOSkKsYPsqoLV1rGmLd4vMxpwHjc5UCb8K9VLCeuPAS2a2d5/6i3bJQv4nk9nr42WQ+m/eGeXBhpTRJs7TYASEEnOngcDoZF7Tgal39rlHTb+TLiT0VMbrR9ISyCxhqTUtZQCpOxb8j5DURvdHlBpwpEWK8CB7DIDbkzG0DtqH2N9SWz4vaJppKXHieeMnEIgvwprNr/GJF4DJYqBJ0uizLbtV/zb4VpF7VKzkUdumdHK0hvLvXW3MkfY8yWeJY3s7gSyI6fhx1O3/p9O6CXSqHfD8JA2zD4osjShEjhk/9oHe9mLeeESIK9Yz4o6yb8DEyrrtS/N7d/YiGcWuux+o350JDt0DmpuxmgBcgv6liMIJ05Yynp1x9HoO0Ghz2NJOyA4BrFxsTWN38NLBGxTtDx+lu3 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123555025)(20161123564025)(6072148); SRVR:BN6PR12MB1137; BCL:0; PCL:0; RULEID:; SRVR:BN6PR12MB1137; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1137; 4:SMxzs8YNpwPYpiIRvaR+avSYZt4Tv9LeVswKptkHp6eRRc82CaJaRhgWOQVSaLak+jyprey7SkDBH0TvSW2zfT7byaDJXCBfMMzV4xPtcAnkowI4NL+tQBP13G3BkZtu2S6cXDAGw5qzIS0qpsdL5fwSs8O5dHwFVjquA/AI+YK45yELcYwsvsIytO1j8k6zCwUcNc1KiKHOYvP1ujGDThn/igZppZK8u2Uq4NUente7vdFtDsU0EoQ0wXMfxFlkBneCdq17recNdjeTqLDEBadd8uxVim0hZpZOpZYRhm9zzcHmI2/k7pLruaSakdGJRkXlWyCSLXqR+oqDLPqGBZdAZmISRfYUS+UtUiDB7tHTQ3DdXIVq+yJrrGvSUa7GIiEuuzuzETQ2oEbx0wJQx8/3q1OKkaJgki5XPFPCti1K1dFJIVivNluUPyTporLhYJeGMlrHmh6JEtC+Tbm8Nxcq3M1yeOc5EjUHPKrtjlPtGdLzYzTpCptBHfUwgtDhv/+kgdgdvBj9pFIcZSroBhOTQeexIa9C2gWAZSarUsVyCmfUNtIPG4wTpaBEpT+l/AUU1arvGb2k5sZDBJ6ym7eI+cP+uPUdgTFeYS8UWwpitjoLhsFOPzKosC8hB0k7ujb+Y+/HRaeS0l3LFcKdRQ57KdQTScHzQExJcZ0cE2b30NhH6nU08lG6bacbMaeObMMWsNUd3n0W3o3SbjIqxgskwN1rzzvNit1nrhgQzU2YTcFgtPX/Ykbxw55b3lOk8TbjYfRiWfJbn1HXQ+wb+A== X-Forefront-PRVS: 028166BF91 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39840400002)(39850400002)(39400400002)(39410400002)(39860400002)(39450400003)(7736002)(7406005)(2201001)(6506006)(7416002)(23676002)(53936002)(86362001)(54906002)(5660300001)(9686003)(83506001)(305945005)(81166006)(8676002)(55016002)(42186005)(2950100002)(53416004)(230700001)(50986999)(6666003)(1076002)(76176999)(103116003)(6116002)(33646002)(97746001)(3846002)(25786009)(47776003)(4001350100001)(50466002)(38730400002)(66066001)(54356999)(2906002)(189998001)(4326008)(921003)(71626007)(1121003)(309714004); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1137; H:tlendack-t1.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WRBHpu8uo2w3u/gVTMLzlt2Ea9tt7ebJW7t+8yz7vpdRsYgkEJL6y32U+Lr2Ijj1GCoWipcdcgt17llZ6G+We0Bw9r6jd7c+jlJMhy+K7wWdCMaLvFOh9YPW/oyHyW1koWZPId5ffYiQBdZbfayQ==; 20:uJwNKnxCL1FgbiPfuu3E6X9H0VoYWq2rfdiWWeiCJtUNYYRYoK3ob9Q7PVv7+aBt7HFA2w5YRRmUQC6qwgRiLFnciFJvBwwTO/4Uezz9isS8jk8KMefBLCJCZFhHFk+qgJrC2zugk/9CXNsy39lbj5xHj0Y0OvA6DmWkR8QCoYoG776shxeMc872qnS2cSisGCexysEeMaV/1iWr06XAj9lwYpl8fEPEmijzkNhxf7NGS8hrsx/lVOrM5jbsF7r/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2017 21:20:23.2046 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1137 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add warnings to let the user know when bounce buffers are being used for DMA when SME is active. Since the bounce buffers are not in encrypted memory, these notifications are to allow the user to determine some appropriate action - if necessary. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/mem_encrypt.h | 11 +++++++++++ include/linux/dma-mapping.h | 11 +++++++++++ include/linux/mem_encrypt.h | 6 ++++++ lib/swiotlb.c | 3 +++ 4 files changed, 31 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 0637b4b..b406df2 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -26,6 +26,11 @@ static inline bool sme_active(void) return !!sme_me_mask; } +static inline u64 sme_dma_mask(void) +{ + return ((u64)sme_me_mask << 1) - 1; +} + void __init sme_early_encrypt(resource_size_t paddr, unsigned long size); void __init sme_early_decrypt(resource_size_t paddr, @@ -50,6 +55,12 @@ static inline bool sme_active(void) { return false; } + +static inline u64 sme_dma_mask(void) +{ + return 0ULL; +} + #endif static inline void __init sme_early_encrypt(resource_size_t paddr, diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 0977317..f825870 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -10,6 +10,7 @@ #include #include #include +#include /** * List of possible attributes associated with a DMA mapping. The semantics @@ -577,6 +578,11 @@ static inline int dma_set_mask(struct device *dev, u64 mask) if (!dev->dma_mask || !dma_supported(dev, mask)) return -EIO; + + if (sme_active() && (mask < sme_dma_mask())) + dev_warn_ratelimited(dev, + "SME is active, device will require DMA bounce buffers\n"); + *dev->dma_mask = mask; return 0; } @@ -596,6 +602,11 @@ static inline int dma_set_coherent_mask(struct device *dev, u64 mask) { if (!dma_supported(dev, mask)) return -EIO; + + if (sme_active() && (mask < sme_dma_mask())) + dev_warn_ratelimited(dev, + "SME is active, device will require DMA bounce buffers\n"); + dev->coherent_dma_mask = mask; return 0; } diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h index 3c384d1..000c430 100644 --- a/include/linux/mem_encrypt.h +++ b/include/linux/mem_encrypt.h @@ -28,6 +28,12 @@ static inline bool sme_active(void) { return false; } + +static inline u64 sme_dma_mask(void) +{ + return 0ULL; +} + #endif #endif /* CONFIG_AMD_MEM_ENCRYPT */ diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 74d6557..af3a268 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -509,6 +509,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"); + WARN_ONCE(sme_active(), + "SME is active and the system is using DMA bounce buffers\n"); + mask = dma_get_seg_boundary(hwdev); tbl_dma_addr &= mask;