From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76D32C433E0 for ; Tue, 26 May 2020 06:16:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 39A8A207CB for ; Tue, 26 May 2020 06:16:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="GcFzir3v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39A8A207CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DC3D68007E; Tue, 26 May 2020 02:16:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D744380061; Tue, 26 May 2020 02:16:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB0758007E; Tue, 26 May 2020 02:16:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0155.hostedemail.com [216.40.44.155]) by kanga.kvack.org (Postfix) with ESMTP id B066180061 for ; Tue, 26 May 2020 02:16:21 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5B6E64DA6 for ; Tue, 26 May 2020 06:16:21 +0000 (UTC) X-FDA: 76857860562.27.chain89_71a66e3cd6c1c X-HE-Tag: chain89_71a66e3cd6c1c X-Filterd-Recvd-Size: 4889 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 26 May 2020 06:16:20 +0000 (UTC) Received: from kernel.org (unknown [87.70.212.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DA1F5207D8; Tue, 26 May 2020 06:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590473780; bh=gpUcruULznsEXcLKKRC5eQF+oxrznq/QzS5NKgeHNYU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GcFzir3vTIFPY79bbVuH9b8AbvS1uA8m3OI44tZqw/MBOGlar8gnomGhlPR736+9t iqlLBronzDmvoOravaNxrcRm2iedky+0gvbZLuE6zUqEJwnmtK+AP5EMiXlqNIS8Lz YTYsY16A+kPjoeRT4Xcxhf1gCFd0iQt2L08pfsY8= Date: Tue, 26 May 2020 09:16:09 +0300 From: Mike Rapoport To: "Kirill A. Shutemov" Cc: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , 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: Re: [RFC 10/16] KVM: x86: Enabled protected memory extension Message-ID: <20200526061609.GE13247@kernel.org> References: <20200522125214.31348-1-kirill.shutemov@linux.intel.com> <20200522125214.31348-11-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200522125214.31348-11-kirill.shutemov@linux.intel.com> 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: On Fri, May 22, 2020 at 03:52:08PM +0300, Kirill A. Shutemov wrote: > Wire up hypercalls for the feature and define VM_KVM_PROTECTED. > > Signed-off-by: Kirill A. Shutemov > --- > arch/x86/Kconfig | 1 + > arch/x86/kvm/cpuid.c | 3 +++ > arch/x86/kvm/x86.c | 9 +++++++++ > include/linux/mm.h | 4 ++++ > 4 files changed, 17 insertions(+) > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig > index 58dd44a1b92f..420e3947f0c6 100644 > --- a/arch/x86/Kconfig > +++ b/arch/x86/Kconfig > @@ -801,6 +801,7 @@ config KVM_GUEST > select ARCH_CPUIDLE_HALTPOLL > select X86_MEM_ENCRYPT_COMMON > select SWIOTLB > + select ARCH_USES_HIGH_VMA_FLAGS > default y > ---help--- > This option enables various optimizations for running under the KVM > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index 901cd1fdecd9..94cc5e45467e 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -714,6 +714,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) > (1 << KVM_FEATURE_POLL_CONTROL) | > (1 << KVM_FEATURE_PV_SCHED_YIELD); > > + if (VM_KVM_PROTECTED) > + entry->eax |=(1 << KVM_FEATURE_MEM_PROTECTED); > + > if (sched_info_on()) > entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index c17e6eb9ad43..acba0ac07f61 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -7598,6 +7598,15 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) > kvm_sched_yield(vcpu->kvm, a0); > ret = 0; > break; > + case KVM_HC_ENABLE_MEM_PROTECTED: > + ret = kvm_protect_all_memory(vcpu->kvm); > + break; > + case KVM_HC_MEM_SHARE: > + ret = kvm_protect_memory(vcpu->kvm, a0, a1, false); > + break; > + case KVM_HC_MEM_UNSHARE: > + ret = kvm_protect_memory(vcpu->kvm, a0, a1, true); > + break; > default: > ret = -KVM_ENOSYS; > break; > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 4f7195365cc0..6eb771c14968 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -329,7 +329,11 @@ extern unsigned int kobjsize(const void *objp); > # define VM_MAPPED_COPY VM_ARCH_1 /* T if mapped copy of data (nommu mmap) */ > #endif > > +#if defined(CONFIG_X86_64) && defined(CONFIG_KVM) This would be better spelled as ARCH_WANTS_PROTECTED_MEMORY, IMHO. > +#define VM_KVM_PROTECTED VM_HIGH_ARCH_4 Maybe this should be VM_HIGH_ARCH_5 so that powerpc could enable this feature eventually? > +#else > #define VM_KVM_PROTECTED 0 > +#endif > > #ifndef VM_GROWSUP > # define VM_GROWSUP VM_NONE > -- > 2.26.2 > > -- Sincerely yours, Mike.