Commit Graph

10 Commits

Author SHA1 Message Date
Isaku Yamahata
6e8132e3ab memfd_restricted: Allow any memory backend for HostMemoryBackend
For large page support, it's convenient to be able to use any backend as
shared memory for memory-backend-memfd-private.  Add shmemdev property to
specify memory backend.

Example:
-object memory-backend-memfd,id=ramhuge,size=6144M,hugetlb=on,hugetlbsize=2M
-object memory-backend-memfd-private,id=ram1,size=6144M,hugetlb=on,hugetlbsize=2M,shmemdev=ramhuge
-machine memory-backend=ram1

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
2023-11-28 17:14:57 +02:00
Isaku Yamahata
cf015bf13b hostmem: Make HostMemoryBackend::mr pointer
Make HostMemoryBackend::mr pointer and add pointee to HostMemoryBackend.
Initialize mr in host_memory_backend_memory_complete().
For restricted memfd memory backend to be able to use any host memory
backend.

No functional change, just add one pointer as indirection.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
2023-11-28 17:14:57 +02:00
Isaku Yamahata
c159594a2f memfd_restricted: Allow memfd_restricted to specify path for mount point
Property for tmpfs can be utilized.  It's needed for large page support.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
2023-11-28 17:14:57 +02:00
Isaku Yamahata
70b6bc1f21 memfd_restricted: Update for memfd_restricted
memfd has a patch to specify mountpoint for properties of tmpfs.
This patch catches up memfd_restricted for the change.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
Link: https://lore.kernel.org/r/592ebd9e33a906ba026d56dc68f42d691706f865.1680306489.git.ackerleytng@google.com
2023-11-28 17:14:57 +02:00
Chenyi Qiang
1ecc52f24e Revert "hostmem: Add RamDiscardManager interface in private memfd backend"
This reverts commit 3ef892bf16ce0e6a888ce2c519249fee7561d865.
2023-11-28 17:14:56 +02:00
Chenyi Qiang
0ab7f737e4 Revert "hostmem: Add the placeholder for some live migration callbacks"
This reverts commit 52b69740ceaac136b4fe01171e588665825e63b5.
2023-11-28 17:14:55 +02:00
Chenyi Qiang
b1afb83cc4 hostmem: Add the placeholder for some live migration callbacks
Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
2023-11-28 17:14:55 +02:00
Chenyi Qiang
db86d2719e hostmem: Add RamDiscardManager interface in private memfd backend
RamDiscardManager is firstly introduced for some special RAM memory
regions (managed by virtio-mem). This interface can coordinate which
parts of specific memory regions are currently populated to be used by
the VM, notifying after parts were discarded and before parts will be
populated.

It is required by VFIO because VFIO tries to register the whole region
with the kernel and pin all pages, which is incompatible with discarding
of RAM. With RamDiscardManager, VFIO can require proper coordination to
only map the currently populated parts, to hinder parts that are
expected to remain discarded from silently getting populated and
consuming memory.

This interface also applies to the private memfd backend, which can
represent two types of memory (shared and private). Shared memory is
accessiable by host VMM and can be mapped in IOMMU page tables. Private
memory is inaccessible and can't be DMA-mapped. So the memory regions
backed by private memfd can coordinate to only ap the shared parts,
update eh mapping when notified about page attribute conversion between
shared and private.

Introduce the RamDiscardManager interface in private memfd backend and
utilize the existing VFIORamDiscardListener (registered in
vfio_register_ram_discard_listener()). The users can call
priv_memfd_backend_state_change() notifier to DMA map the shared parts
and unmap the private parts.

There are some notes in current implementation.
- VFIO has registerd the population ram discard listener which will DMA
  map in minimun granularity (i.e. block_size in virtio-mem and private
  memfd). The block_size of private memfd is set to host page size
  because the conversion size can be as small as one page.
- Current VFIO do the map/unmap with minimal pranularity each time,
  which can avoid partial unmap request from TD guest.

Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
2023-11-28 17:14:55 +02:00
Wei Wang
35bb3ae328 softmmu/physmem: add cgs_bitmap
Add a per-RAMBlock bitmap (named cgs_bmap) to record if a guest-physical
address is private/shared. The bitmap is allocated only when the guest is
a confidential guest, so it's allocated in the private memory backend.

By default, bits are 0 in the bitmap to indicate all the guest pages are
private pages. When the guest changes a private page to share or shared
page to private later, it exits to QEMU with the KVM_EXIT_MEMORY_FAULT
reason and the cgs_bmap will be updated accordingly.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:53 +02:00
Chao Peng
f42710517a memfd: Add private memfd host memory backend
This new object is similar to existing 'memory-backend-memfd' object
which provides host memory with linux memfd_create API but differs in
that this new object will have two memfds, one is for share memory which
can be mmaped, the other is for private memory which is restricted memfd
and can not be accessed from userspace.

Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
2023-11-28 17:14:50 +02:00