Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dave@treblig.org>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org,
	"Zhenzhong Duan" <zhenzhong.duan@intel.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"David Hildenbrand" <david@kernel.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>,
	qemu-rust@nongnu.org, "Alex Williamson" <alex@shazbot.org>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Mark Kanda" <mark.kanda@oracle.com>,
	"Ben Chaney" <bchaney@akamai.com>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	kvm@vger.kernel.org, "Zhao Liu" <zhao1.liu@intel.com>,
	"Eric Blake" <eblake@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [PATCH v5 12/12] RFC: monitor: add 'info ramblock-attributes' command
Date: Fri, 5 Jun 2026 13:28:13 +0000	[thread overview]
Message-ID: <aiLO7ZQvowWHwK63@gallifrey> (raw)
In-Reply-To: <20260604-rdm5-v5-12-5768e6a0943d@redhat.com>

* Marc-André Lureau (marcandre.lureau@redhat.com) wrote:
> Add a new 'info ramblock-attributes' HMP command and the corresponding
> 'x-query-ramblock-attributes' QMP command to display the shared/private
> memory attributes for ram blocks.
> 
> The QMP command returns structured data (RamBlockAttributesInfo list
> with per-range shared/populated attributes), while HMP formats it for
> human consumption.
> 
> This is useful for debugging confidential guests (TDX, SNP) to inspect
> which memory regions are shared vs private, and their population state
> when a RamDiscardManager is present (e.g. virtio-mem).
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  qapi/machine.json             | 56 ++++++++++++++++++++++++++++++++++
>  include/monitor/hmp.h         |  1 +
>  hw/core/machine-hmp-cmds.c    | 32 +++++++++++++++++++
>  system/ram-block-attributes.c | 71 +++++++++++++++++++++++++++++++++++++++++++
>  hmp-commands-info.hx          | 13 ++++++++
>  5 files changed, 173 insertions(+)
> 

<snip>

For HMP,

Acked-by: Dr. David Alan Gilbert <dave@treblig.org>

however, you might consider whether it would be better to add it
to the existing "info ramblock"

Dave

> +void hmp_info_ramblock_attributes(Monitor *mon, const QDict *qdict)
> +{
> +    Error *err = NULL;
> +    g_autoptr(RamBlockAttributesInfoList) list = NULL;
> +    RamBlockAttributesInfoList *it;
> +
> +    list = qmp_x_query_ramblock_attributes(&err);
> +    if (hmp_handle_error(mon, err)) {
> +        return;
> +    }
> +
> +    for (it = list; it; it = it->next) {
> +        RamBlockAttributesInfo *rba = it->value;
> +        RamBlockAttributeRangeList *r;
> +
> +        monitor_printf(mon, "%s:\n", rba->name);
> +        for (r = rba->ranges; r; r = r->next) {
> +            RamBlockAttributeRange *range = r->value;
> +            const char *shared = range->shared ? "shared" : "private";
> +            const char *pop = range->has_populated ?
> +                (range->populated ? "+populated" : "-populated") : "";
> +
> +            monitor_printf(mon,
> +                           "  0x%016" PRIx64 "-0x%016" PRIx64 " %s%s\n",
> +                           range->start,
> +                           range->start + range->length - 1,
> +                           shared, pop);
> +        }
> +    }
> +}
> diff --git a/system/ram-block-attributes.c b/system/ram-block-attributes.c
> index 59ec7a28eb0..fb657ffca35 100644
> --- a/system/ram-block-attributes.c
> +++ b/system/ram-block-attributes.c
> @@ -11,6 +11,7 @@
>  
>  #include "qemu/osdep.h"
>  #include "qemu/error-report.h"
> +#include "qapi/qapi-commands-machine.h"
>  #include "system/ramblock.h"
>  #include "trace.h"
>  
> @@ -221,3 +222,73 @@ static void ram_block_attributes_class_init(ObjectClass *klass,
>      rdsc->get_min_granularity = ram_block_attributes_rds_get_min_granularity;
>      rdsc->is_populated = ram_block_attributes_rds_is_populated;
>  }
> +
> +RamBlockAttributesInfoList *qmp_x_query_ramblock_attributes(Error **errp)
> +{
> +    RamBlockAttributesInfoList *head = NULL, **tail = &head;
> +    RAMBlock *block;
> +    size_t rba_block_size = ram_block_attributes_get_block_size();
> +
> +    RCU_READ_LOCK_GUARD();
> +
> +    RAMBLOCK_FOREACH(block) {
> +        RamBlockAttributesInfo *rba;
> +        RamBlockAttributeRangeList **range_tail;
> +        RamBlockAttributes *attr = block->attributes;
> +        RamDiscardManager *rdm;
> +        unsigned long pos;
> +
> +        if (!attr) {
> +            continue;
> +        }
> +
> +        rdm = memory_region_get_ram_discard_manager(block->mr);
> +        g_assert(rdm);
> +
> +        rba = g_new0(RamBlockAttributesInfo, 1);
> +        rba->name = g_strdup(block->idstr);
> +        range_tail = &rba->ranges;
> +
> +        pos = 0;
> +        while (pos < attr->bitmap_size) {
> +            bool is_shared = test_bit(pos, attr->bitmap);
> +            unsigned long next;
> +            uint64_t start_offset, length;
> +            RamBlockAttributeRange *range;
> +
> +            if (is_shared) {
> +                next = find_next_zero_bit(attr->bitmap,
> +                                          attr->bitmap_size, pos);
> +            } else {
> +                next = find_next_bit(attr->bitmap,
> +                                     attr->bitmap_size, pos);
> +            }
> +
> +            start_offset = (uint64_t)pos * rba_block_size;
> +            length = (uint64_t)(next - pos) * rba_block_size;
> +
> +            range = g_new0(RamBlockAttributeRange, 1);
> +            range->start = start_offset;
> +            range->length = length;
> +            range->shared = is_shared;
> +
> +            {
> +                MemoryRegionSection section = {
> +                    .mr = block->mr,
> +                    .offset_within_region = start_offset,
> +                    .size = int128_make64(length),
> +                };
> +                range->has_populated = true;
> +                range->populated =
> +                    ram_discard_manager_is_populated(rdm, &section);
> +            }
> +
> +            QAPI_LIST_APPEND(range_tail, range);
> +            pos = next;
> +        }
> +
> +        QAPI_LIST_APPEND(tail, rba);
> +    }
> +
> +    return head;
> +}
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index 82134eb6c21..f119b9cfebc 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -761,6 +761,19 @@ SRST
>      Dump all the ramblocks of the system.
>  ERST
>  
> +    {
> +        .name       = "ramblock-attributes",
> +        .args_type  = "",
> +        .params     = "",
> +        .help       = "Display ramblock shared/private attributes",
> +        .cmd        = hmp_info_ramblock_attributes,
> +    },
> +
> +SRST
> +  ``info ramblock-attributes``
> +    Display the shared/private memory attributes for ram blocks.
> +ERST
> +
>      {
>          .name       = "hotpluggable-cpus",
>          .args_type  = "",
> 
> -- 
> 2.54.0
> 
-- 
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/

  reply	other threads:[~2026-06-05 13:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04 13:43 [PATCH v5 00/12] Make RamDiscardManager work with multiple sources & virtio-mem Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 01/12] system/memory: split RamDiscardManager into source and manager Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 02/12] system/memory: move RamDiscardManager to separate compilation unit Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 03/12] system/memory: constify section arguments Marc-André Lureau
2026-06-05 11:16   ` David Hildenbrand (Arm)
2026-06-08 12:48   ` Maciej S. Szmigiero
2026-06-04 13:43 ` [PATCH v5 04/12] system/ram-discard-manager: implement replay via is_populated iteration Marc-André Lureau
2026-06-05 12:00   ` David Hildenbrand (Arm)
2026-06-04 13:43 ` [PATCH v5 05/12] virtio-mem: remove replay_populated/replay_discarded implementation Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 06/12] system/ram-discard-manager: drop replay from source interface Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 07/12] system/memory: implement RamDiscardManager multi-source aggregation Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 08/12] system/physmem: destroy ram block attributes before RCU-deferred reclaim Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 09/12] system/memory: add RamDiscardManager reference counting and cleanup Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 10/12] tests: add unit tests for RamDiscardManager multi-source aggregation Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 11/12] system/physmem: make ram_block_discard_range() handle guest_memfd Marc-André Lureau
2026-06-04 13:43 ` [PATCH v5 12/12] RFC: monitor: add 'info ramblock-attributes' command Marc-André Lureau
2026-06-05 13:28   ` Dr. David Alan Gilbert [this message]
2026-06-08 13:36     ` Markus Armbruster
2026-06-08 13:30   ` Markus Armbruster

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=aiLO7ZQvowWHwK63@gallifrey \
    --to=dave@treblig.org \
    --cc=alex@shazbot.org \
    --cc=armbru@redhat.com \
    --cc=bchaney@akamai.com \
    --cc=clg@redhat.com \
    --cc=david@kernel.org \
    --cc=eblake@redhat.com \
    --cc=farosas@suse.de \
    --cc=kvm@vger.kernel.org \
    --cc=maciej.szmigiero@oracle.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mark.kanda@oracle.com \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@mailo.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=zhao1.liu@intel.com \
    --cc=zhenzhong.duan@intel.com \
    /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