[PATCH v2 00/14] Make RamDiscardManager work with multiple sources

marcandre.lureau@redhat.com posted 14 patches 1 month, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260225120456.3170057-1-marcandre.lureau@redhat.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Mark Kanda <mark.kanda@oracle.com>, Ben Chaney <bchaney@akamai.com>, David Hildenbrand <david@kernel.org>, "Michael S. Tsirkin" <mst@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
include/hw/vfio/vfio-container.h            |    2 +-
include/hw/vfio/vfio-cpr.h                  |    2 +-
include/hw/virtio/virtio-mem.h              |    3 -
include/system/memory.h                     |  285 +----
include/system/ram-discard-manager.h        |  358 ++++++
include/system/ramblock.h                   |    3 +-
accel/kvm/kvm-all.c                         |    2 +-
hw/vfio/cpr-legacy.c                        |    4 +-
hw/vfio/listener.c                          |   12 +-
hw/virtio/virtio-mem.c                      |  290 +----
migration/ram.c                             |    6 +-
system/memory.c                             |   83 +-
system/memory_mapping.c                     |    4 +-
system/ram-block-attributes.c               |  279 +----
system/ram-discard-manager.c                |  612 +++++++++
tests/unit/test-ram-discard-manager-stubs.c |   48 +
tests/unit/test-ram-discard-manager.c       | 1234 +++++++++++++++++++
system/meson.build                          |    1 +
tests/unit/meson.build                      |    8 +-
19 files changed, 2359 insertions(+), 877 deletions(-)
create mode 100644 include/system/ram-discard-manager.h
create mode 100644 system/ram-discard-manager.c
create mode 100644 tests/unit/test-ram-discard-manager-stubs.c
create mode 100644 tests/unit/test-ram-discard-manager.c
[PATCH v2 00/14] Make RamDiscardManager work with multiple sources
Posted by marcandre.lureau@redhat.com 1 month, 2 weeks ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Hi,

This is an attempt to fix the incompatibility of virtio-mem with confidential
VMs. The solution implements what was discussed earlier with D. Hildenbrand:
https://patchwork.ozlabs.org/project/qemu-devel/patch/20250407074939.18657-5-chenyi.qiang@intel.com/#3502238

The first patches are misc cleanups. Then some code refactoring to have split a
manager/source. And finally, the manager learns to deal with multiple sources.

I haven't done thorough testing. I only launched a SEV guest with a virtio-mem
device. It would be nice to have more tests for those scenarios with
VFIO/virtio-mem/confvm.. In any case, review & testing needed!

(should fix https://issues.redhat.com/browse/RHEL-131968)

v2:
 - drop replay_{populated,discarded} from source, suggested by Peter Xu
 - add extra manager cleanup
 - add r-b tags for preliminary patches

thanks

Marc-André Lureau (14):
  system/rba: use DIV_ROUND_UP
  memory: drop RamDiscardListener::double_discard_supported
  virtio-mem: use warn_report_err_once()
  system/memory: minor doc fix
  kvm: replace RamDicardManager by the RamBlockAttribute
  system/memory: split RamDiscardManager into source and manager
  system/memory: move RamDiscardManager to separate compilation unit
  system/memory: constify section arguments
  system/ram-discard-manager: implement replay via is_populated
    iteration
  virtio-mem: remove replay_populated/replay_discarded implementation
  system/ram-discard-manager: drop replay from source interface
  system/memory: implement RamDiscardManager multi-source aggregation
  system/memory: add RamDiscardManager reference counting and cleanup
  tests: add unit tests for RamDiscardManager multi-source aggregation

 include/hw/vfio/vfio-container.h            |    2 +-
 include/hw/vfio/vfio-cpr.h                  |    2 +-
 include/hw/virtio/virtio-mem.h              |    3 -
 include/system/memory.h                     |  285 +----
 include/system/ram-discard-manager.h        |  358 ++++++
 include/system/ramblock.h                   |    3 +-
 accel/kvm/kvm-all.c                         |    2 +-
 hw/vfio/cpr-legacy.c                        |    4 +-
 hw/vfio/listener.c                          |   12 +-
 hw/virtio/virtio-mem.c                      |  290 +----
 migration/ram.c                             |    6 +-
 system/memory.c                             |   83 +-
 system/memory_mapping.c                     |    4 +-
 system/ram-block-attributes.c               |  279 +----
 system/ram-discard-manager.c                |  612 +++++++++
 tests/unit/test-ram-discard-manager-stubs.c |   48 +
 tests/unit/test-ram-discard-manager.c       | 1234 +++++++++++++++++++
 system/meson.build                          |    1 +
 tests/unit/meson.build                      |    8 +-
 19 files changed, 2359 insertions(+), 877 deletions(-)
 create mode 100644 include/system/ram-discard-manager.h
 create mode 100644 system/ram-discard-manager.c
 create mode 100644 tests/unit/test-ram-discard-manager-stubs.c
 create mode 100644 tests/unit/test-ram-discard-manager.c

-- 
2.53.0


Re: [PATCH v2 00/14] Make RamDiscardManager work with multiple sources
Posted by Cédric Le Goater 1 month, 2 weeks ago
On 2/25/26 13:04, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Hi,
> 
> This is an attempt to fix the incompatibility of virtio-mem with confidential
> VMs. The solution implements what was discussed earlier with D. Hildenbrand:
> https://patchwork.ozlabs.org/project/qemu-devel/patch/20250407074939.18657-5-chenyi.qiang@intel.com/#3502238
> 
> The first patches are misc cleanups. Then some code refactoring to have split a
> manager/source. And finally, the manager learns to deal with multiple sources.
> 
> I haven't done thorough testing. I only launched a SEV guest with a virtio-mem
> device. It would be nice to have more tests for those scenarios with
> VFIO/virtio-mem/confvm.. In any case, review & testing needed!
> 
In a SEV-SNP guest (BIOS) with a VFIO device and virtio-mem device :

   -m 4G,maxmem=24G
   -object '{"size": 4294967296, "id": "mem-vmem0", "qom-type": "memory-backend-ram"}'
   -device '{"id": "pcie-root-port-1", "port": 1, "driver": "pcie-root-port", "bus": "pcie.0", "chassis": 2}'
   -device '{"memdev": "mem-vmem0", "driver": "virtio-mem-pci", "id": "virtio_mem-vmem0", "bus": "pcie-root-port-1", "addr":  "0x0"}'
   -object '{"size": 4294967296, "id": "mem-machine_mem", "qom-type": "memory-backend-ram"}'
   ...

   [    0.663227] Memory Encryption Features active: AMD SEV SEV-ES SEV-SNP
   ...
   [    3.199716] virtio_mem virtio2: start address: 0x180000000
   [    3.200988] virtio_mem virtio2: region size: 0x100000000
   [    3.202217] virtio_mem virtio2: device block size: 0x200000
   [    3.203475] virtio_mem virtio2: nid: 0
   [    3.204384] virtio_mem virtio2: memory block size: 0x8000000
   [    3.205696] virtio_mem virtio2: subblock size: 0x200000
   [    3.207193] virtio_mem virtio2: plugged size: 0x0
   [    3.208282] virtio_mem virtio2: requested size: 0x0

boot is fine.

Powerdown reveals an issue :

   [   25.054116] ACPI: PM: Preparing to enter system sleep state S5
   [   25.055671] reboot: Power down
   **
   ERROR:../system/ram-discard-manager.c:459:ram_discard_manager_finalize: assertion failed: (QLIST_EMPTY(&rdm->source_list))
   Aborted

Thanks,

C.