[PATCH v4 00/13] Make RamDiscardManager work with multiple sources & virtio-mem

Marc-André Lureau posted 13 patches 3 weeks, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260504-rdm5-v4-0-bdf61e57c1e1@redhat.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Dr. David Alan Gilbert" <dave@treblig.org>, "Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Mark Kanda <mark.kanda@oracle.com>, Ben Chaney <bchaney@akamai.com>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>, David Hildenbrand <david@kernel.org>, "Michael S. Tsirkin" <mst@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Zhao Liu <zhao1.liu@intel.com>, Marcelo Tosatti <mtosatti@redhat.com>
MAINTAINERS                                 |    4 +
qapi/machine.json                           |   55 ++
include/hw/vfio/vfio-container.h            |    2 +-
include/hw/vfio/vfio-cpr.h                  |    2 +-
include/hw/virtio/virtio-mem.h              |    3 -
include/monitor/hmp.h                       |    1 +
include/system/memory.h                     |  283 +-----
include/system/ram-discard-manager.h        |  358 ++++++++
include/system/ramblock.h                   |    6 +-
accel/kvm/kvm-all.c                         |    5 +-
hw/core/machine-hmp-cmds.c                  |   32 +
hw/vfio/cpr-legacy.c                        |    4 +-
hw/vfio/listener.c                          |   10 +-
hw/virtio/virtio-mem.c                      |  286 ++-----
migration/ram.c                             |    6 +-
system/memory.c                             |   83 +-
system/memory_mapping.c                     |    4 +-
system/physmem.c                            |   27 +-
system/ram-block-attributes.c               |  329 +++----
system/ram-discard-manager.c                |  612 +++++++++++++
target/i386/kvm/tdx.c                       |    2 +-
tests/unit/test-ram-discard-manager-stubs.c |   48 ++
tests/unit/test-ram-discard-manager.c       | 1235 +++++++++++++++++++++++++++
hmp-commands-info.hx                        |   13 +
rust/bindings/system-sys/lib.rs             |    2 +-
system/meson.build                          |    1 +
system/trace-events                         |    2 +-
tests/unit/meson.build                      |    8 +-
28 files changed, 2597 insertions(+), 826 deletions(-)
[PATCH v4 00/13] Make RamDiscardManager work with multiple sources & virtio-mem
Posted by Marc-André Lureau 3 weeks, 5 days ago
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!

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

v4:
 - added "system/physmem: make ram_block_discard_range() handle guest_memfd"
 - added "monitor: add 'info ramblock-attributes' command"
 - added "RFC: hw/virtio: start virtio-mem guest_memfd regions as shared"
 - skip calling source in notify_populate (it may not have updated its
   internal state)
 - rebased, collected trailer tags

v3: issues found by Cédric
 - fix assertion error on shutdown, due to rcu-defer cleanup
 - fix API doc warnings

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

---
Marc-André Lureau (13):
      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/physmem: destroy ram block attributes before RCU-deferred reclaim
      system/memory: add RamDiscardManager reference counting and cleanup
      tests: add unit tests for RamDiscardManager multi-source aggregation
      system/physmem: make ram_block_discard_range() handle guest_memfd
      monitor: add 'info ramblock-attributes' command
      RFC: hw/virtio: start virtio-mem guest_memfd regions as shared

 MAINTAINERS                                 |    4 +
 qapi/machine.json                           |   55 ++
 include/hw/vfio/vfio-container.h            |    2 +-
 include/hw/vfio/vfio-cpr.h                  |    2 +-
 include/hw/virtio/virtio-mem.h              |    3 -
 include/monitor/hmp.h                       |    1 +
 include/system/memory.h                     |  283 +-----
 include/system/ram-discard-manager.h        |  358 ++++++++
 include/system/ramblock.h                   |    6 +-
 accel/kvm/kvm-all.c                         |    5 +-
 hw/core/machine-hmp-cmds.c                  |   32 +
 hw/vfio/cpr-legacy.c                        |    4 +-
 hw/vfio/listener.c                          |   10 +-
 hw/virtio/virtio-mem.c                      |  286 ++-----
 migration/ram.c                             |    6 +-
 system/memory.c                             |   83 +-
 system/memory_mapping.c                     |    4 +-
 system/physmem.c                            |   27 +-
 system/ram-block-attributes.c               |  329 +++----
 system/ram-discard-manager.c                |  612 +++++++++++++
 target/i386/kvm/tdx.c                       |    2 +-
 tests/unit/test-ram-discard-manager-stubs.c |   48 ++
 tests/unit/test-ram-discard-manager.c       | 1235 +++++++++++++++++++++++++++
 hmp-commands-info.hx                        |   13 +
 rust/bindings/system-sys/lib.rs             |    2 +-
 system/meson.build                          |    1 +
 system/trace-events                         |    2 +-
 tests/unit/meson.build                      |    8 +-
 28 files changed, 2597 insertions(+), 826 deletions(-)
---
base-commit: ac0cc20ad2fe0b8df2e5d9458e90a095ac711ab1
change-id: 20260414-rdm5-b6df2366d603

Best regards,
--  
Marc-André Lureau <marcandre.lureau@redhat.com>


Re: [PATCH v4 00/13] Make RamDiscardManager work with multiple sources & virtio-mem
Posted by Peter Xu 2 weeks, 2 days ago
On Mon, May 04, 2026 at 04:30:06PM +0400, Marc-André Lureau wrote:
> 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!
> 
> (help fix https://issues.redhat.com/browse/RHEL-131968)

Copy David for virtio-mem: David, please see if you're OK with virtio-mem
side of things; if you have time look at everything it'll be even better.

Copy Chenyi: would you please check with your environment on whether you
still hit issue with this series?

The whole series can be found here:

https://lore.kernel.org/all/20260504-rdm5-v4-0-bdf61e57c1e1@redhat.com/

Side note: this version still contain quite some "over 80 chars" checkpatch
complains... please consider fixing them when repost.

Thanks,

> 
> v4:
>  - added "system/physmem: make ram_block_discard_range() handle guest_memfd"
>  - added "monitor: add 'info ramblock-attributes' command"
>  - added "RFC: hw/virtio: start virtio-mem guest_memfd regions as shared"
>  - skip calling source in notify_populate (it may not have updated its
>    internal state)
>  - rebased, collected trailer tags
> 
> v3: issues found by Cédric
>  - fix assertion error on shutdown, due to rcu-defer cleanup
>  - fix API doc warnings
> 
> v2:
>  - drop replay_{populated,discarded} from source, suggested by Peter Xu
>  - add extra manager cleanup
>  - add r-b tags for preliminary patches
> 
> ---
> Marc-André Lureau (13):
>       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/physmem: destroy ram block attributes before RCU-deferred reclaim
>       system/memory: add RamDiscardManager reference counting and cleanup
>       tests: add unit tests for RamDiscardManager multi-source aggregation
>       system/physmem: make ram_block_discard_range() handle guest_memfd
>       monitor: add 'info ramblock-attributes' command
>       RFC: hw/virtio: start virtio-mem guest_memfd regions as shared
> 
>  MAINTAINERS                                 |    4 +
>  qapi/machine.json                           |   55 ++
>  include/hw/vfio/vfio-container.h            |    2 +-
>  include/hw/vfio/vfio-cpr.h                  |    2 +-
>  include/hw/virtio/virtio-mem.h              |    3 -
>  include/monitor/hmp.h                       |    1 +
>  include/system/memory.h                     |  283 +-----
>  include/system/ram-discard-manager.h        |  358 ++++++++
>  include/system/ramblock.h                   |    6 +-
>  accel/kvm/kvm-all.c                         |    5 +-
>  hw/core/machine-hmp-cmds.c                  |   32 +
>  hw/vfio/cpr-legacy.c                        |    4 +-
>  hw/vfio/listener.c                          |   10 +-
>  hw/virtio/virtio-mem.c                      |  286 ++-----
>  migration/ram.c                             |    6 +-
>  system/memory.c                             |   83 +-
>  system/memory_mapping.c                     |    4 +-
>  system/physmem.c                            |   27 +-
>  system/ram-block-attributes.c               |  329 +++----
>  system/ram-discard-manager.c                |  612 +++++++++++++
>  target/i386/kvm/tdx.c                       |    2 +-
>  tests/unit/test-ram-discard-manager-stubs.c |   48 ++
>  tests/unit/test-ram-discard-manager.c       | 1235 +++++++++++++++++++++++++++
>  hmp-commands-info.hx                        |   13 +
>  rust/bindings/system-sys/lib.rs             |    2 +-
>  system/meson.build                          |    1 +
>  system/trace-events                         |    2 +-
>  tests/unit/meson.build                      |    8 +-
>  28 files changed, 2597 insertions(+), 826 deletions(-)
> ---
> base-commit: ac0cc20ad2fe0b8df2e5d9458e90a095ac711ab1
> change-id: 20260414-rdm5-b6df2366d603
> 
> Best regards,
> --  
> Marc-André Lureau <marcandre.lureau@redhat.com>
> 

-- 
Peter Xu


Re: [PATCH v4 00/13] Make RamDiscardManager work with multiple sources & virtio-mem
Posted by Chenyi Qiang 2 weeks, 2 days ago

On 5/14/2026 4:53 AM, Peter Xu wrote:
> On Mon, May 04, 2026 at 04:30:06PM +0400, Marc-André Lureau wrote:
>> 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!
>>
>> (help fix https://issues.redhat.com/browse/RHEL-131968)
> 
> Copy David for virtio-mem: David, please see if you're OK with virtio-mem
> side of things; if you have time look at everything it'll be even better.
> 
> Copy Chenyi: would you please check with your environment on whether you
> still hit issue with this series?

With this series along with the ongoing virtio-mem guest change[1], I can
launch the TD guest with a virtio-mem device and do the plug/unplug/replug operations
successfully.

[1] https://lore.kernel.org/lkml/20260401-coco-v1-1-b9c3072e2d9c@redhat.com/