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=-11.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 DAC55C4363A for ; Fri, 23 Oct 2020 16:32:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E580722254 for ; Fri, 23 Oct 2020 16:32:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E580722254 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E41C36B005D; Fri, 23 Oct 2020 12:32:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF5BA6B0062; Fri, 23 Oct 2020 12:32:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D07CF6B0068; Fri, 23 Oct 2020 12:32:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id A63F46B005D for ; Fri, 23 Oct 2020 12:32:06 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 46262180AD817 for ; Fri, 23 Oct 2020 16:32:06 +0000 (UTC) X-FDA: 77403732252.12.grain47_3a122c52725b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 1F74918016E90 for ; Fri, 23 Oct 2020 16:32:06 +0000 (UTC) X-HE-Tag: grain47_3a122c52725b X-Filterd-Recvd-Size: 4280 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Fri, 23 Oct 2020 16:32:04 +0000 (UTC) IronPort-SDR: WhmjcjiZ6vHqXx8La2VdIY+NOgGwYilgEkrL2J0DdfTTb076eR2uP8Iw7GUr+1w18bXGkT5oxJ L6w+RAnOSDLQ== X-IronPort-AV: E=McAfee;i="6000,8403,9782"; a="164205375" X-IronPort-AV: E=Sophos;i="5.77,409,1596524400"; d="scan'208";a="164205375" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2020 09:32:02 -0700 IronPort-SDR: 71aJvcrUnpatw20KEuhZ3rsuXf7oGTND3XZXVxTlK40kSHCdl/N440+ISf1WSgAX+bfXg19DUl JcldFVkia1+Q== X-IronPort-AV: E=Sophos;i="5.77,409,1596524400"; d="scan'208";a="524731467" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.160]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2020 09:32:01 -0700 Date: Fri, 23 Oct 2020 09:32:00 -0700 From: Sean Christopherson To: Mike Rapoport Cc: "Kirill A. Shutemov" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , David Rientjes , Andrea Arcangeli , Kees Cook , Will Drewry , "Edgecombe, Rick P" , "Kleen, Andi" , Liran Alon , x86@kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: Re: [RFCv2 15/16] KVM: Unmap protected pages from direct mapping Message-ID: <20201023163158.GB5580@linux.intel.com> References: <20201020061859.18385-1-kirill.shutemov@linux.intel.com> <20201020061859.18385-16-kirill.shutemov@linux.intel.com> <20201023123712.GC392079@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201023123712.GC392079@kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) 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, Oct 23, 2020 at 03:37:12PM +0300, Mike Rapoport wrote: > On Tue, Oct 20, 2020 at 09:18:58AM +0300, Kirill A. Shutemov wrote: > > If the protected memory feature enabled, unmap guest memory from > > kernel's direct mappings. > > > > Migration and KSM is disabled for protected memory as it would require a > > special treatment. > > > > Signed-off-by: Kirill A. Shutemov > > --- > > include/linux/mm.h | 3 +++ > > mm/huge_memory.c | 8 ++++++++ > > mm/ksm.c | 2 ++ > > mm/memory.c | 12 ++++++++++++ > > mm/rmap.c | 4 ++++ > > virt/lib/mem_protected.c | 21 +++++++++++++++++++++ > > 6 files changed, 50 insertions(+) > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index ee274d27e764..74efc51e63f0 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -671,6 +671,9 @@ static inline bool vma_is_kvm_protected(struct vm_area_struct *vma) > > return vma->vm_flags & VM_KVM_PROTECTED; > > } > > > > +void kvm_map_page(struct page *page, int nr_pages); > > +void kvm_unmap_page(struct page *page, int nr_pages); > > This still does not seem right ;-) > > And I still think that map/unmap primitives shoud be a part of the > generic mm rather than exported by KVM. Ya, and going a step further, I suspect it will be cleaner in the long run if the kernel does not automatically map or unmap when converting between private and shared/public memory. Conversions will be rare in a well behaved guest, so exiting to userspace and forcing userspace to do the unmap->map would not be a performance bottleneck. In theory, userspace could also maintain separate pools for private vs. public mappings, though I doubt any VMM will do that in practice.