From patchwork Tue Dec 21 15:11:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Peng X-Patchwork-Id: 12689869 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 8B52DC433F5 for ; Tue, 21 Dec 2021 15:12:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22F6B6B008A; Tue, 21 Dec 2021 10:12:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E02A6B008C; Tue, 21 Dec 2021 10:12:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A7A36B0092; Tue, 21 Dec 2021 10:12:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0243.hostedemail.com [216.40.44.243]) by kanga.kvack.org (Postfix) with ESMTP id F06686B008A for ; Tue, 21 Dec 2021 10:12:47 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B3A9D181059CF for ; Tue, 21 Dec 2021 15:12:47 +0000 (UTC) X-FDA: 78942143574.06.3C71796 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf12.hostedemail.com (Postfix) with ESMTP id 0652E40049 for ; Tue, 21 Dec 2021 15:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1640099567; x=1671635567; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=6+jEwSaQbRLyJYQpPbesRQbgqxxUkuctrfu8t5OfMl8=; b=WdjMtyUzcA6QjIQKGEZa5y6kLjJ7qSgQl01LXJZaPAFprWHkEXlonuC6 E0i0SZ5E0sfyQlxou10RxI58OdmWOJJo1D6ZjUzVQYzYziABVTVfGpNaK tkfe/lP1scp9bjr3Z4AAUrUeR6nJlxWnp92Ys50nq77EwD7xnr4/R8YU2 OT6jy7pNoHPzTyqnYj8zGQEuxsbtFDC1tsLvGtmgfRaaOUQO7VkBngtjl gafIeVOTgjXek8ACCDZwuYIJ8Qjxx+ARAQnMbyjQO2lcddArr1zbVTh6Y 8debWfrXrG75qeejXSjsrwOi0YngVvXC5Nyah1h/G1ajmPSf2JCxs38Rk g==; X-IronPort-AV: E=McAfee;i="6200,9189,10204"; a="264601343" X-IronPort-AV: E=Sophos;i="5.88,223,1635231600"; d="scan'208";a="264601343" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2021 07:12:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,223,1635231600"; d="scan'208";a="684688364" Received: from chaop.bj.intel.com ([10.240.192.101]) by orsmga005.jf.intel.com with ESMTP; 21 Dec 2021 07:12:33 -0800 From: Chao Peng To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, qemu-devel@nongnu.org Cc: Paolo Bonzini , Jonathan Corbet , Sean Christopherson , 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 , Yu Zhang , Chao Peng , "Kirill A . Shutemov" , luto@kernel.org, john.ji@intel.com, susie.li@intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com Subject: [PATCH v3 04/15] KVM: Extend the memslot to support fd-based private memory Date: Tue, 21 Dec 2021 23:11:14 +0800 Message-Id: <20211221151125.19446-5-chao.p.peng@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211221151125.19446-1-chao.p.peng@linux.intel.com> References: <20211221151125.19446-1-chao.p.peng@linux.intel.com> X-Rspamd-Queue-Id: 0652E40049 X-Stat-Signature: zxo3tcufebx13pyjfcgixbgzga1f6rrw Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=WdjMtyUz; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf12.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.88) smtp.mailfrom=chao.p.peng@linux.intel.com X-Rspamd-Server: rspam11 X-HE-Tag: 1640099549-443815 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: Extend the memslot definition to provide fd-based private memory support by adding two new fields(fd/ofs). The memslot then can maintain memory for both shared and private pages in a single memslot. Shared pages are provided in the existing way by using userspace_addr(hva) field and get_user_pages() while private pages are provided through the new fields(fd/ofs). Since there is no 'hva' concept anymore for private memory we cannot call get_user_pages() to get a pfn, instead we rely on the newly introduced MEMFD_OPS callbacks to do the same job. This new extension is indicated by a new flag KVM_MEM_PRIVATE. Signed-off-by: Yu Zhang Signed-off-by: Chao Peng --- include/linux/kvm_host.h | 9 +++++++++ include/uapi/linux/kvm.h | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 865a677baf52..96e46b288ecd 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -433,8 +433,17 @@ struct kvm_memory_slot { u32 flags; short id; u16 as_id; + struct file *file; + u64 file_ofs; }; +static inline bool kvm_slot_is_private(const struct kvm_memory_slot *slot) +{ + if (slot && (slot->flags & KVM_MEM_PRIVATE)) + return true; + return false; +} + static inline bool kvm_slot_dirty_track_enabled(struct kvm_memory_slot *slot) { return slot->flags & KVM_MEM_LOG_DIRTY_PAGES; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index e3706e574bd2..a2c1fb8c9843 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -103,6 +103,17 @@ struct kvm_userspace_memory_region { __u64 userspace_addr; /* start of the userspace allocated memory */ }; +struct kvm_userspace_memory_region_ext { + __u32 slot; + __u32 flags; + __u64 guest_phys_addr; + __u64 memory_size; /* bytes */ + __u64 userspace_addr; /* hva */ + __u64 ofs; /* offset into fd */ + __u32 fd; + __u32 padding[5]; +}; + /* * The bit 0 ~ bit 15 of kvm_memory_region::flags are visible for userspace, * other bits are reserved for kvm internal use which are defined in @@ -110,6 +121,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) /* for KVM_IRQ_LINE */ struct kvm_irq_level {