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 CA5A0C433FE for ; Thu, 23 Dec 2021 18:34:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D6986B0072; Thu, 23 Dec 2021 13:34:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2861D6B0073; Thu, 23 Dec 2021 13:34:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 126A66B0074; Thu, 23 Dec 2021 13:34:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id F37A46B0072 for ; Thu, 23 Dec 2021 13:34:27 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id AD725181AC9C6 for ; Thu, 23 Dec 2021 18:34:27 +0000 (UTC) X-FDA: 78949909374.06.04BF6C8 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf16.hostedemail.com (Postfix) with ESMTP id 484FB180040 for ; Thu, 23 Dec 2021 18:34:27 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id j6-20020a17090a588600b001a78a5ce46aso9520718pji.0 for ; Thu, 23 Dec 2021 10:34:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=wgoegRi5bG9RfU6sMp0VEJxN3NnOXgdV/DTIFT/FP9s=; b=L+zXpuXCNgLWcMvoCH32XVHU3LmaAvryhek/ia9zaFUu0ZSn7rADevGixqyB2soisL lb8sy3eZ0Qb13+uIbTieaElB9/eNeY1LdDq+a6B1I4SCMgjk8KynVB6mC3VxCjS62dVR shouleL8Xc9cW4Wz78SXSVxVyqQLoN4F0NG+DvAR8pOfjTfWeQzVKxXB0o9Pq4oNeD2u D/l3mjhlcj2MVLlMZngH+SksfEZR9/1Wk/yngiydrBqbgLH3qAIjqS5gEc7eeKDfOTuB avLlOIlX+XDpMaVWp30QaJoxFQY/I8sNhRtyyMDPfKjd8Jl1YaMQ7pZgNNA9C4UmrgVB 9akA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wgoegRi5bG9RfU6sMp0VEJxN3NnOXgdV/DTIFT/FP9s=; b=yYv/Exy6qHhskvhWnULYDKQYgXAA83xjfAFW3NAEWrb3obyiqKUJr7LLe10xhIRrtm Mx7h6Dz0ZEYJunK3d+Jr+FfNPcMnqUwdDokmMvq5Zgf+dxHoSb/lzG95ajvIWeTvt9ox bRuqOCH6KnT2L4/hJl8MFYbJTff2zD/u4EcHfJM7grVwiJHPDsOMghbHxajc9ocm+coG zaa887X66pSdXd30BtKvZoX83GYqd2+UFRJotNqsrna9dD8W44nUA0UgYEYTLmUbey4q ssV4KNHbT19Z+aNA3mfiELK23l8ou3SZi0/pcc0+0Z8K/SmbIhBIkZA5MNck1SoU2BMH d8OA== X-Gm-Message-State: AOAM53305p5hrUKw+WQ1n5F3fCQvVDuPH4+vmqFkgzezigLOAwkc0r4i dKzczndM+QoIk9FbpMZdtS9Z9w== X-Google-Smtp-Source: ABdhPJymsNE7J9ptKr2BtgChAzAfQEzAGp2WzRVvToHDYcXxBbfV5GZE58CrgE/W67Py/7kxVbiHvg== X-Received: by 2002:a17:90a:c58f:: with SMTP id l15mr3967558pjt.227.1640284466086; Thu, 23 Dec 2021 10:34:26 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id k6sm6898801pff.17.2021.12.23.10.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Dec 2021 10:34:25 -0800 (PST) Date: Thu, 23 Dec 2021 18:34:22 +0000 From: Sean Christopherson To: Chao Peng Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@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 , Yu Zhang , "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: Re: [PATCH v3 kvm/queue 06/16] KVM: Implement fd-based memory using MEMFD_OPS interfaces Message-ID: References: <20211223123011.41044-1-chao.p.peng@linux.intel.com> <20211223123011.41044-7-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211223123011.41044-7-chao.p.peng@linux.intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 484FB180040 X-Stat-Signature: pjjfmawm1j9ghkobp3squzwx4hujjbuw Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=L+zXpuXC; spf=pass (imf16.hostedemail.com: domain of seanjc@google.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1640284467-580542 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 Thu, Dec 23, 2021, Chao Peng wrote: > diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig > index 03b2ce34e7f4..86655cd660ca 100644 > --- a/arch/x86/kvm/Kconfig > +++ b/arch/x86/kvm/Kconfig > @@ -46,6 +46,7 @@ config KVM > select SRCU > select INTERVAL_TREE > select HAVE_KVM_PM_NOTIFIER if PM > + select MEMFD_OPS MEMFD_OPS is a weird Kconfig name given that it's not just memfd() that can implement the ops. > help > Support hosting fully virtualized guest machines using hardware > virtualization extensions. You will need a fairly recent > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 3bd875f9669f..21f8b1880723 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -806,6 +806,12 @@ static inline void kvm_irqfd_exit(void) > { > } > #endif > + > +int kvm_memfd_register(struct kvm *kvm, struct kvm_memory_slot *slot); > +void kvm_memfd_unregister(struct kvm_memory_slot *slot); > +long kvm_memfd_get_pfn(struct kvm_memory_slot *slot, gfn_t gfn, int *order); > +void kvm_memfd_put_pfn(kvm_pfn_t pfn); > + > int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, > struct module *module); > void kvm_exit(void); > diff --git a/virt/kvm/Makefile.kvm b/virt/kvm/Makefile.kvm > index ffdcad3cc97a..8842128d8429 100644 > --- a/virt/kvm/Makefile.kvm > +++ b/virt/kvm/Makefile.kvm > @@ -5,7 +5,7 @@ > > KVM ?= ../../../virt/kvm > > -kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o > +kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o $(KVM)/memfd.o This should be kvm-$(CONFIG_MEMFD_OPS) += $(KVM)/memfd.o with stubs provided in a header file as needed. I also really dislike naming KVM's file memfd.c, though I don't have a good alternative off the top of my head. > kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o > kvm-$(CONFIG_KVM_MMIO) += $(KVM)/coalesced_mmio.o > kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o > +#ifdef CONFIG_MEMFD_OPS > +static const struct memfd_pfn_ops *memfd_ops; memfd_ops needs to be associated with the slot, e.g. userspace should be able to map multiple types of a backing stores into a single VM. This doesn't even allow that for multiple VMs, and there are all kinds of ordering issues. > +void kvm_memfd_unregister(struct kvm_memory_slot *slot) > +{ > +#ifdef CONFIG_MEMFD_OPS > + if (slot->file) { > + fput(slot->file); Needs to actually unregister. > + slot->file = NULL; > + } > +#endif > +} > -- > 2.17.1 >