From: Elliot Berman <quic_eberman@quicinc.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Fuad Tabba <tabba@google.com>,
David Hildenbrand <david@redhat.com>,
Patrick Roy <roypat@amazon.co.uk>, <qperret@google.com>,
Ackerley Tng <ackerleytng@google.com>,
Mike Rapoport <rppt@kernel.org>, <x86@kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
<kvm@vger.kernel.org>, <linux-coco@lists.linux.dev>,
<linux-arm-msm@vger.kernel.org>,
Elliot Berman <quic_eberman@quicinc.com>
Subject: [PATCH RFC v2 0/5] mm: Introduce guest_memfd library
Date: Thu, 29 Aug 2024 15:24:08 -0700 [thread overview]
Message-ID: <20240829-guest-memfd-lib-v2-0-b9afc1ff3656@quicinc.com> (raw)
In preparation for adding more features to KVM's guest_memfd, refactor
and introduce a library which abstracts some of the core-mm decisions
about managing folios associated with the file. The goal of the refactor
serves two purposes:
1. Provide an easier way to reason about memory in guest_memfd. With KVM
supporting multiple confidentiality models (TDX, SEV-SNP, pKVM, ARM
CCA), and coming support for allowing kernel and userspace to access
this memory, it seems necessary to create a stronger abstraction between
core-mm concerns and hypervisor concerns.
2. Provide a common implementation for other hypervisors (Gunyah) to use.
To create a guest_memfd, the owner provides operations to attempt to
unmap the folio and check whether a folio is accessible to the host. The
owner can call guest_memfd_make_inaccessible() to ensure Linux doesn't
have the folio mapped.
The series first introduces a guest_memfd library based on the current
KVM (next) implementation, then adds few features needed for Gunyah and
arm64 pKVM. The Gunyah usage of the series will be posted separately
shortly after sending this series. I'll work with Fuad on using the
guest_memfd library for arm64 pKVM based on the feedback received.
There are a few TODOs still pending.
- The KVM patch isn't tested. I don't have access a SEV-SNP setup to be
able to test.
- I've not yet investigated deeply whether having the guest_memfd
library helps live migration. I'd appreciate any input on that part.
- We should consider consolidating the adjust_direct_map() in
arch/x86/virt/svm/sev.c so guest_memfd can take care of it.
- There's a race possibility where the folio ref count is incremented
and about to also increment the safe counter, but waiting for the
folio lock to be released. The owner of folio_lock will see mismatched
counter values and not be able to convert to (in)accessible, even
though it should be okay to do so.
I'd appreciate any feedback, especially on the direction I'm taking for
tracking the (in)accessible state.
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Changes in v2:
- Significantly reworked to introduce "accessible" and "safe" reference
counters
- Link to v1:
https://lore.kernel.org/r/20240805-guest-memfd-lib-v1-0-e5a29a4ff5d7@quicinc.com
---
Elliot Berman (5):
mm: Introduce guest_memfd
mm: guest_memfd: Allow folios to be accessible to host
kvm: Convert to use guest_memfd library
mm: guest_memfd: Add ability for userspace to mmap pages
mm: guest_memfd: Add option to remove inaccessible memory from direct map
arch/x86/kvm/svm/sev.c | 3 +-
include/linux/guest_memfd.h | 49 ++++
mm/Kconfig | 3 +
mm/Makefile | 1 +
mm/guest_memfd.c | 667 ++++++++++++++++++++++++++++++++++++++++++++
virt/kvm/Kconfig | 1 +
virt/kvm/guest_memfd.c | 371 +++++-------------------
virt/kvm/kvm_main.c | 2 -
virt/kvm/kvm_mm.h | 6 -
9 files changed, 797 insertions(+), 306 deletions(-)
---
base-commit: 5be63fc19fcaa4c236b307420483578a56986a37
change-id: 20240722-guest-memfd-lib-455f24115d46
Best regards,
--
Elliot Berman <quic_eberman@quicinc.com>
next reply other threads:[~2024-08-29 22:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 22:24 Elliot Berman [this message]
2024-08-29 22:24 ` [PATCH RFC v2 1/5] mm: Introduce guest_memfd Elliot Berman
2024-08-29 22:24 ` [PATCH RFC v2 2/5] mm: guest_memfd: Allow folios to be accessible to host Elliot Berman
2024-10-09 20:14 ` Vishal Annapurve
2024-08-29 22:24 ` [PATCH RFC v2 3/5] kvm: Convert to use guest_memfd library Elliot Berman
2024-10-23 1:18 ` Mike Day
2024-08-29 22:24 ` [PATCH RFC v2 4/5] mm: guest_memfd: Add ability for userspace to mmap pages Elliot Berman
2024-08-29 22:24 ` [PATCH RFC v2 5/5] mm: guest_memfd: Add option to remove inaccessible memory from direct map Elliot Berman
2024-10-10 13:04 ` [PATCH RFC v2 0/5] mm: Introduce guest_memfd library Paolo Bonzini
2024-10-10 21:20 ` Elliot Berman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240829-guest-memfd-lib-v2-0-b9afc1ff3656@quicinc.com \
--to=quic_eberman@quicinc.com \
--cc=ackerleytng@google.com \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qperret@google.com \
--cc=roypat@amazon.co.uk \
--cc=rppt@kernel.org \
--cc=seanjc@google.com \
--cc=tabba@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox