[PATCH] physmem: use PR_SET_VMA_ANON_NAME to set ram block name

Eiichi Tsukata posted 1 patch 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230411041158.66728-1-eiichi.tsukata@nutanix.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>
meson.build       | 2 ++
softmmu/physmem.c | 9 +++++++++
2 files changed, 11 insertions(+)
[PATCH] physmem: use PR_SET_VMA_ANON_NAME to set ram block name
Posted by Eiichi Tsukata 1 year ago
Use linux specific PR_SET_VMA_ANON_NAME (introduced in v5.17) to set ram
block name in the kernel. This makes each ram block distinguishable and
can help debugging and inspection. The names of ram blocks are shown in
/proc/pid/maps like this:

  7f00e9400000-7f00f1400000 rw-p 00000000 00:00 0      [anon:pc.ram]
  7f0115200000-7f0115201000 rw-p 00000000 00:00 0      [anon:/rom@etc/acpi/rsdp]
  7f0115400000-7f0115410000 rw-p 00000000 00:00 0      [anon:/rom@etc/table-loader]
  7f0115600000-7f0115800000 rw-p 00000000 00:00 0      [anon:/rom@etc/acpi/tables]
  7f0115a00000-7f0115a40000 rw-p 00000000 00:00 0      [anon:e1000.rom]
  ...

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
---
 meson.build       | 2 ++
 softmmu/physmem.c | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/meson.build b/meson.build
index 29f8644d6d..aca889f5f0 100644
--- a/meson.build
+++ b/meson.build
@@ -2040,6 +2040,8 @@ config_host_data.set('HAVE_OPTRESET',
                      cc.has_header_symbol('getopt.h', 'optreset'))
 config_host_data.set('HAVE_IPPROTO_MPTCP',
                      cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP'))
+config_host_data.set('CONFIG_PRCTL_PR_SET_VMA_ANON_NAME',
+                     cc.has_header_symbol('sys/prctl.h', 'PR_SET_VMA_ANON_NAME'))
 
 # has_member
 config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID',
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index e35061bba4..4fe3e14193 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -80,6 +80,10 @@
 #include <daxctl/libdaxctl.h>
 #endif
 
+#ifdef CONFIG_PRCTL_PR_SET_VMA_ANON_NAME
+#include <sys/prctl.h>
+#endif
+
 //#define DEBUG_SUBPAGE
 
 /* ram_list is read under rcu_read_lock()/rcu_read_unlock().  Writes
@@ -1810,6 +1814,11 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
                 return;
             }
             memory_try_enable_merging(new_block->host, new_block->max_length);
+#ifdef CONFIG_PRCTL_PR_SET_VMA_ANON_NAME
+            prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME,
+                  (unsigned long) new_block->host, new_block->max_length,
+                  (unsigned long) new_block->mr->name);
+#endif
         }
     }
 
-- 
2.39.2
Re: [PATCH] physmem: use PR_SET_VMA_ANON_NAME to set ram block name
Posted by Peter Xu 1 year ago
On Tue, Apr 11, 2023 at 04:11:58AM +0000, Eiichi Tsukata wrote:
> Use linux specific PR_SET_VMA_ANON_NAME (introduced in v5.17) to set ram
> block name in the kernel. This makes each ram block distinguishable and
> can help debugging and inspection. The names of ram blocks are shown in
> /proc/pid/maps like this:
> 
>   7f00e9400000-7f00f1400000 rw-p 00000000 00:00 0      [anon:pc.ram]
>   7f0115200000-7f0115201000 rw-p 00000000 00:00 0      [anon:/rom@etc/acpi/rsdp]
>   7f0115400000-7f0115410000 rw-p 00000000 00:00 0      [anon:/rom@etc/table-loader]
>   7f0115600000-7f0115800000 rw-p 00000000 00:00 0      [anon:/rom@etc/acpi/tables]
>   7f0115a00000-7f0115a40000 rw-p 00000000 00:00 0      [anon:e1000.rom]
>   ...
> 
> Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>

Acked-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu
Re: [PATCH] physmem: use PR_SET_VMA_ANON_NAME to set ram block name
Posted by David Hildenbrand 1 year ago
On 11.04.23 06:11, Eiichi Tsukata wrote:
> Use linux specific PR_SET_VMA_ANON_NAME (introduced in v5.17) to set ram
> block name in the kernel. This makes each ram block distinguishable and
> can help debugging and inspection. The names of ram blocks are shown in
> /proc/pid/maps like this:
> 
>    7f00e9400000-7f00f1400000 rw-p 00000000 00:00 0      [anon:pc.ram]
>    7f0115200000-7f0115201000 rw-p 00000000 00:00 0      [anon:/rom@etc/acpi/rsdp]
>    7f0115400000-7f0115410000 rw-p 00000000 00:00 0      [anon:/rom@etc/table-loader]
>    7f0115600000-7f0115800000 rw-p 00000000 00:00 0      [anon:/rom@etc/acpi/tables]
>    7f0115a00000-7f0115a40000 rw-p 00000000 00:00 0      [anon:e1000.rom]
>    ...
> 
> Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
> ---
>   meson.build       | 2 ++
>   softmmu/physmem.c | 9 +++++++++
>   2 files changed, 11 insertions(+)
> 
> diff --git a/meson.build b/meson.build
> index 29f8644d6d..aca889f5f0 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2040,6 +2040,8 @@ config_host_data.set('HAVE_OPTRESET',
>                        cc.has_header_symbol('getopt.h', 'optreset'))
>   config_host_data.set('HAVE_IPPROTO_MPTCP',
>                        cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP'))
> +config_host_data.set('CONFIG_PRCTL_PR_SET_VMA_ANON_NAME',
> +                     cc.has_header_symbol('sys/prctl.h', 'PR_SET_VMA_ANON_NAME'))

Nit: I'd suggest placing that directly next to the 
CONFIG_PRCTL_PR_SET_TIMERSLACK check.

>   
>   # has_member
>   config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID',
> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
> index e35061bba4..4fe3e14193 100644
> --- a/softmmu/physmem.c
> +++ b/softmmu/physmem.c
> @@ -80,6 +80,10 @@
>   #include <daxctl/libdaxctl.h>
>   #endif
>   
> +#ifdef CONFIG_PRCTL_PR_SET_VMA_ANON_NAME
> +#include <sys/prctl.h>
> +#endif
> +
>   //#define DEBUG_SUBPAGE
>   
>   /* ram_list is read under rcu_read_lock()/rcu_read_unlock().  Writes
> @@ -1810,6 +1814,11 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
>                   return;
>               }
>               memory_try_enable_merging(new_block->host, new_block->max_length);
> +#ifdef CONFIG_PRCTL_PR_SET_VMA_ANON_NAME
> +            prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME,
> +                  (unsigned long) new_block->host, new_block->max_length,
> +                  (unsigned long) new_block->mr->name);

We might not have anon memory. I assume that we expect that the prctl 
will simply silently fail (maybe worth a comment) in case we have !anon 
memory.

I assume new_block->mr->name should be set in all cases we care about, 
so LGTM.

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb