From patchwork Fri May 22 12:52:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 11565553 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47AC0159A for ; Fri, 22 May 2020 12:52:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1691B20759 for ; Fri, 22 May 2020 12:52:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="T5hCoobM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1691B20759 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7BDCA8000A; Fri, 22 May 2020 08:52:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 793D280008; Fri, 22 May 2020 08:52:21 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F3938000A; Fri, 22 May 2020 08:52:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id 3FD6080008 for ; Fri, 22 May 2020 08:52:21 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E97ED824CA0B for ; Fri, 22 May 2020 12:52:20 +0000 (UTC) X-FDA: 76844343240.02.fear53_88e2346c9d960 X-Spam-Summary: 2,0,0,fc9db9a1cf8d68ba,d41d8cd98f00b204,kirill@shutemov.name,,RULES_HIT:41:69:355:379:541:960:966:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1543:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2895:2897:3138:3139:3140:3141:3142:3354:3622:3865:3867:3868:3871:3874:4118:4250:4321:4385:4605:5007:6119:6120:6261:6653:6742:7901:8568:8660:9592:10004:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12895:12986:13141:13148:13230:13894:14181:14721:21080:21444:21451:21627:21939:21990:30054:30070,0,RBL:209.85.208.195:@shutemov.name:.lbl8.mailshell.net-62.8.0.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: fear53_88e2346c9d960 X-Filterd-Recvd-Size: 7481 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 May 2020 12:52:20 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id v16so12502555ljc.8 for ; Fri, 22 May 2020 05:52:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QDGQlabqNdXWT8KYXiZwEeKnt25k8ILFDWxwAiuz/rs=; b=T5hCoobMWtJ7Xzo20ohRf6NdcQ3ttgHexOKNzdWduVQbkLxApAPl+W+t7qaQWvvPaL szS1ESDyCBl8nxotiDX/fMAWiyPnn53Y573QSOYSRIKxkWL0hFikT7PbX/xhc6GpbupH Jx3l5SbaTAsfUfZ10CSxgW0gxp6Cm2E9v82GsvCLwFYiFiZkeS2r0a/IwAaNcT0g776C 7W0DJCCofxJ5gED2yaCZ/LqHet1TQUSlADKixI+VvxGE2mHgUd5Dkn1QmrHHAhn68P+f a2mkP4+qpHJmX+8ZpqpZJ8eyw6wwk1TMtgSBnlxvgDuZ5J/XSH61k5FXpKubBlHpB7A+ tHsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QDGQlabqNdXWT8KYXiZwEeKnt25k8ILFDWxwAiuz/rs=; b=d84sBkfOmY0eOcc+l1lglVjeDOXPmS24bNew2/jA3BjIJ4fkz8b4fKzej6RM0UZnEd kXK0NbfkvPWkFeVRCreg+gYtrC0p85ycMqdkLQ6UJ1F1NKgh3ZTGV5QzhxNyM4DFooq+ QSiQr2cVCWCa3uGnlCfy72tvcdMWhHEn+ROxDmKhd7obA8sqS2Mi4vGpHc9c5b0gQG8Y V4+qDW5YQ3nbXnVR2oJpNIaVNZspFTozWos7dGhvrRgTPBhHASG7tOzeg7EOEcWALXOi CDpiv/4rCjwoBSAHjismUaDw1rBrbMeMA3xMs+G6+mnmsyLNpnaiTDaZWCUl/H78AN2D qjuw== X-Gm-Message-State: AOAM533txgNCR5MwZMZsT0MTeWYzbSpHAI/t4WISIaSPH75nIuTZ0ljA 6pI/K3zXaBntvN+TkmqdIXPZmg== X-Google-Smtp-Source: ABdhPJzbEgynOtDCfmMokHSL9w+mx6+aIeiKdBvwClE9qAMTx107s9z4ayxTSo/aYXpRjHq4p8yErA== X-Received: by 2002:a2e:9ada:: with SMTP id p26mr7407068ljj.14.1590151939171; Fri, 22 May 2020 05:52:19 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id e18sm343134lja.55.2020.05.22.05.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 05:52:17 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id B92F7102051; Fri, 22 May 2020 15:52:19 +0300 (+03) To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Cc: David Rientjes , Andrea Arcangeli , Kees Cook , Will Drewry , "Edgecombe, Rick P" , "Kleen, Andi" , x86@kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [RFC 04/16] x86/kvm: Use bounce buffers for KVM memory protection Date: Fri, 22 May 2020 15:52:02 +0300 Message-Id: <20200522125214.31348-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200522125214.31348-1-kirill.shutemov@linux.intel.com> References: <20200522125214.31348-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Mirror SEV, use SWIOTLB always if KVM memory protection is enabled. Signed-off-by: Kirill A. Shutemov --- arch/x86/Kconfig | 1 + arch/x86/kernel/kvm.c | 2 ++ arch/x86/kernel/pci-swiotlb.c | 3 ++- arch/x86/mm/mem_encrypt.c | 20 -------------------- arch/x86/mm/mem_encrypt_common.c | 23 +++++++++++++++++++++++ 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 86c012582f51..58dd44a1b92f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -800,6 +800,7 @@ config KVM_GUEST select PARAVIRT_CLOCK select ARCH_CPUIDLE_HALTPOLL select X86_MEM_ENCRYPT_COMMON + select SWIOTLB default y ---help--- This option enables various optimizations for running under the KVM diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index bda761ca0d26..f50d65df4412 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -742,6 +743,7 @@ static void __init kvm_init_platform(void) } mem_protected = true; + swiotlb_force = SWIOTLB_FORCE; } } diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c index c2cfa5e7c152..814060a6ceb0 100644 --- a/arch/x86/kernel/pci-swiotlb.c +++ b/arch/x86/kernel/pci-swiotlb.c @@ -13,6 +13,7 @@ #include #include #include +#include int swiotlb __read_mostly; @@ -49,7 +50,7 @@ int __init pci_swiotlb_detect_4gb(void) * buffers are allocated and used for devices that do not support * the addressing range required for the encryption mask. */ - if (sme_active()) + if (sme_active() || kvm_mem_protected()) swiotlb = 1; return swiotlb; diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 112304a706f3..35c748ee3fcb 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -370,23 +370,3 @@ void __init mem_encrypt_free_decrypted_mem(void) free_init_pages("unused decrypted", vaddr, vaddr_end); } - -void __init mem_encrypt_init(void) -{ - if (!sme_me_mask) - return; - - /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ - swiotlb_update_mem_attributes(); - - /* - * With SEV, we need to unroll the rep string I/O instructions. - */ - if (sev_active()) - static_branch_enable(&sev_enable_key); - - pr_info("AMD %s active\n", - sev_active() ? "Secure Encrypted Virtualization (SEV)" - : "Secure Memory Encryption (SME)"); -} - diff --git a/arch/x86/mm/mem_encrypt_common.c b/arch/x86/mm/mem_encrypt_common.c index a878e7f246d5..7900f3788010 100644 --- a/arch/x86/mm/mem_encrypt_common.c +++ b/arch/x86/mm/mem_encrypt_common.c @@ -37,3 +37,26 @@ bool force_dma_unencrypted(struct device *dev) return false; } + +void __init mem_encrypt_init(void) +{ + if (!sme_me_mask && !kvm_mem_protected()) + return; + + /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ + swiotlb_update_mem_attributes(); + + /* + * With SEV, we need to unroll the rep string I/O instructions. + */ + if (sev_active()) + static_branch_enable(&sev_enable_key); + + if (sme_me_mask) { + pr_info("AMD %s active\n", + sev_active() ? "Secure Encrypted Virtualization (SEV)" + : "Secure Memory Encryption (SME)"); + } else { + pr_info("KVM memory protection enabled\n"); + } +}