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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84661C433EF for ; Mon, 20 Jun 2022 14:13:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 027806B0073; Mon, 20 Jun 2022 10:13:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F19466B0074; Mon, 20 Jun 2022 10:13:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE2A06B0075; Mon, 20 Jun 2022 10:13:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CEA2A6B0073 for ; Mon, 20 Jun 2022 10:13:15 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 9E9A112018C for ; Mon, 20 Jun 2022 14:13:15 +0000 (UTC) X-FDA: 79598806350.07.B064155 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf03.hostedemail.com (Postfix) with ESMTP id 3D245200A9 for ; Mon, 20 Jun 2022 14:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655734394; x=1687270394; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=Bp9Mlz7Na3xaUAMgzpqbQL8va7PMos3P8wYwM1/XQFY=; b=MYxhyURnL0oJdnbvmYbj0BQV/w9GoiNXsX6fa8gykD1GfCMZOtAGRVDn lW4UO8ivFoFpJXrALvlLASIoiR4UXmLgDHWSUC3z0wkjg1myJe3LjQxx7 uMf7u54B7/1ZFZ3qXjG7mynGjPz+a0kl6hflb4+ImrJXKR82TVnEV8BpV Rrx5Mig4u6MietSo9hGhDlNBsxmMxJ9QQQa3hZYW6npwVh/YS7W5XFCZg 2GnflDFXfSGrHCiZ3g9IpNdusNQuPa3lsQpugxywjhw1qtZwVNScyk5IH Xzaq9UwoBNQwtV8q/ge2pxlYypm0FG0EoqZUfCgpYC3cI6CSfPFc+8Jxe A==; X-IronPort-AV: E=McAfee;i="6400,9594,10380"; a="259727645" X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="259727645" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2022 07:13:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="584912288" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga007.jf.intel.com with ESMTP; 20 Jun 2022 07:13:02 -0700 Date: Mon, 20 Jun 2022 22:09:41 +0800 From: Chao Peng To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com Subject: Re: [PATCH v6 4/8] KVM: Extend the memslot to support fd-based private memory Message-ID: <20220620140941.GB2016793@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220519153713.819591-1-chao.p.peng@linux.intel.com> <20220519153713.819591-5-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655734394; a=rsa-sha256; cv=none; b=2G+aj0/Wa8QsfRANfKC1lCMj1F3xoc1GLCCMrbaC2g+K4OVfb358BryjHAko4uA4HCJqzZ ZsU15LSMOc58cP9ZGxzBetCe/aSHOAGsJ25L6/gcUe2kkCkSLWFuy19Spa94CEyjB4xlH0 uQH9yO5T+fNj8f/g++uJTO7OTnJf9xs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MYxhyURn; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf03.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.136) smtp.mailfrom=chao.p.peng@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655734394; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=R058ihQ7xAz4HUYVURMxMOOG6K+gZA1rE9A5T+FVfO8=; b=ImxSDVugapwPqBVyQNOCCfu6x5nzGaO98DUkJj0Ph99fY6+EjWKwihtuhkiPs2Ey5Xaz3Z DUWAzCuJAJK/W8ix9d5KJ1VZTazOpNmMAiSKO8stpSpYxaI3/5jvGIa0B/Bcy3x+VvXJGB bLjQiItJtO5k4AvhjRJqm5QCGDdMfK0= X-Rspamd-Queue-Id: 3D245200A9 X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MYxhyURn; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf03.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.136) smtp.mailfrom=chao.p.peng@linux.intel.com X-Rspamd-Server: rspam06 X-Stat-Signature: m4kt9zyon3d9ttgwxqs5tgwmgz8msdr7 X-HE-Tag: 1655734393-579089 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, Jun 17, 2022 at 09:27:25PM +0000, Sean Christopherson wrote: > On Fri, Jun 17, 2022, Sean Christopherson wrote: > > > @@ -110,6 +133,7 @@ struct kvm_userspace_memory_region { > > > */ > > > #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0) > > > #define KVM_MEM_READONLY (1UL << 1) > > > +#define KVM_MEM_PRIVATE (1UL << 2) > > > > Hmm, KVM_MEM_PRIVATE is technically wrong now that a "private" memslot maps private > > and/or shared memory. Strictly speaking, we don't actually need a new flag. Valid > > file descriptors must be >=0, so the logic for specifying a memslot that can be > > converted between private and shared could be that "(int)private_fd < 0" means > > "not convertible", i.e. derive the flag from private_fd. > > > > And looking at the two KVM consumers of the flag, via kvm_slot_is_private(), they're > > both wrong. Both kvm_faultin_pfn() and kvm_mmu_max_mapping_level() should operate > > on the _fault_, not the slot. So it would actually be a positive to not have an easy > > way to query if a slot supports conversion. > > I take that back, the usage in kvm_faultin_pfn() is correct, but the names ends > up being confusing because it suggests that it always faults in a private pfn. Make sense, will change the naming, thanks. > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index b6d75016e48c..e1008f00609d 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -4045,7 +4045,7 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > return RET_PF_EMULATE; > } > > - if (fault->is_private) { > + if (kvm_slot_can_be_private(slot)) { > r = kvm_faultin_pfn_private(vcpu, fault); > if (r != RET_PF_CONTINUE) > return r == RET_PF_FIXED ? RET_PF_CONTINUE : r; > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 31f704c83099..c5126190fb71 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -583,9 +583,9 @@ struct kvm_memory_slot { > struct kvm *kvm; > }; > > -static inline bool kvm_slot_is_private(const struct kvm_memory_slot *slot) > +static inline bool kvm_slot_can_be_private(const struct kvm_memory_slot *slot) > { > - return slot && (slot->flags & KVM_MEM_PRIVATE); > + return slot && !!slot->private_file; > } > > static inline bool kvm_slot_dirty_track_enabled(const struct kvm_memory_slot *slot)