[PATCH v2 4/9] memory: Rename memory_region_has_guest_memfd() to *_private()

Peter Xu posted 9 patches 2 months, 3 weeks ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, David Hildenbrand <david@kernel.org>, Igor Mammedov <imammedo@redhat.com>, Peter Xu <peterx@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>
There is a newer version of this series
[PATCH v2 4/9] memory: Rename memory_region_has_guest_memfd() to *_private()
Posted by Peter Xu 2 months, 3 weeks ago
Rename the function with "_private" suffix, to show that it returns true
only if it has an internal guest-memfd to back private pages (rather than
in-place guest-memfd).

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/system/memory.h | 6 +++---
 accel/kvm/kvm-all.c     | 6 +++---
 system/memory.c         | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/system/memory.h b/include/system/memory.h
index 2c1a5e06b4..4428701a9f 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -1823,14 +1823,14 @@ static inline bool memory_region_is_romd(MemoryRegion *mr)
 bool memory_region_is_protected(MemoryRegion *mr);
 
 /**
- * memory_region_has_guest_memfd: check whether a memory region has guest_memfd
- *     associated
+ * memory_region_has_guest_memfd_private: check whether a memory region has
+ *     guest_memfd associated
  *
  * Returns %true if a memory region's ram_block has valid guest_memfd assigned.
  *
  * @mr: the memory region being queried
  */
-bool memory_region_has_guest_memfd(MemoryRegion *mr);
+bool memory_region_has_guest_memfd_private(MemoryRegion *mr);
 
 /**
  * memory_region_get_iommu: check whether a memory region is an iommu
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index f477014126..320315f50c 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -666,7 +666,7 @@ static int kvm_mem_flags(MemoryRegion *mr)
     if (readonly && kvm_readonly_mem_allowed) {
         flags |= KVM_MEM_READONLY;
     }
-    if (memory_region_has_guest_memfd(mr)) {
+    if (memory_region_has_guest_memfd_private(mr)) {
         assert(kvm_guest_memfd_supported);
         flags |= KVM_MEM_GUEST_MEMFD;
     }
@@ -1615,7 +1615,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
             abort();
         }
 
-        if (memory_region_has_guest_memfd(mr)) {
+        if (memory_region_has_guest_memfd_private(mr)) {
             err = kvm_set_memory_attributes_private(start_addr, slot_size);
             if (err) {
                 error_report("%s: failed to set memory attribute private: %s",
@@ -3101,7 +3101,7 @@ int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private)
         return ret;
     }
 
-    if (!memory_region_has_guest_memfd(mr)) {
+    if (!memory_region_has_guest_memfd_private(mr)) {
         /*
          * Because vMMIO region must be shared, guest TD may convert vMMIO
          * region to shared explicitly.  Don't complain such case.  See
diff --git a/system/memory.c b/system/memory.c
index 81b7bff42d..15964160ee 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1897,7 +1897,7 @@ bool memory_region_is_protected(MemoryRegion *mr)
     return mr->ram && (mr->ram_block->flags & RAM_PROTECTED);
 }
 
-bool memory_region_has_guest_memfd(MemoryRegion *mr)
+bool memory_region_has_guest_memfd_private(MemoryRegion *mr)
 {
     return mr->ram_block && mr->ram_block->guest_memfd >= 0;
 }
-- 
2.50.1
Re: [PATCH v2 4/9] memory: Rename memory_region_has_guest_memfd() to *_private()
Posted by Xiaoyao Li 1 month, 4 weeks ago
On 11/20/2025 1:29 AM, Peter Xu wrote:
> Rename the function with "_private" suffix, to show that it returns true
> only if it has an internal guest-memfd to back private pages (rather than
> in-place guest-memfd).
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>   include/system/memory.h | 6 +++---
>   accel/kvm/kvm-all.c     | 6 +++---
>   system/memory.c         | 2 +-
>   3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/include/system/memory.h b/include/system/memory.h
> index 2c1a5e06b4..4428701a9f 100644
> --- a/include/system/memory.h
> +++ b/include/system/memory.h
> @@ -1823,14 +1823,14 @@ static inline bool memory_region_is_romd(MemoryRegion *mr)
>   bool memory_region_is_protected(MemoryRegion *mr);
>   
>   /**
> - * memory_region_has_guest_memfd: check whether a memory region has guest_memfd
> - *     associated
> + * memory_region_has_guest_memfd_private: check whether a memory region has
> + *     guest_memfd associated

Nit: maybe change it to "guest_memfd_private associated", and maybe put 
this patch after patch 5?

Otherwise,

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>

>    *
>    * Returns %true if a memory region's ram_block has valid guest_memfd assigned.
>    *
>    * @mr: the memory region being queried
>    */
> -bool memory_region_has_guest_memfd(MemoryRegion *mr);
> +bool memory_region_has_guest_memfd_private(MemoryRegion *mr);
>   
>   /**
>    * memory_region_get_iommu: check whether a memory region is an iommu
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index f477014126..320315f50c 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -666,7 +666,7 @@ static int kvm_mem_flags(MemoryRegion *mr)
>       if (readonly && kvm_readonly_mem_allowed) {
>           flags |= KVM_MEM_READONLY;
>       }
> -    if (memory_region_has_guest_memfd(mr)) {
> +    if (memory_region_has_guest_memfd_private(mr)) {
>           assert(kvm_guest_memfd_supported);
>           flags |= KVM_MEM_GUEST_MEMFD;
>       }
> @@ -1615,7 +1615,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
>               abort();
>           }
>   
> -        if (memory_region_has_guest_memfd(mr)) {
> +        if (memory_region_has_guest_memfd_private(mr)) {
>               err = kvm_set_memory_attributes_private(start_addr, slot_size);
>               if (err) {
>                   error_report("%s: failed to set memory attribute private: %s",
> @@ -3101,7 +3101,7 @@ int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private)
>           return ret;
>       }
>   
> -    if (!memory_region_has_guest_memfd(mr)) {
> +    if (!memory_region_has_guest_memfd_private(mr)) {
>           /*
>            * Because vMMIO region must be shared, guest TD may convert vMMIO
>            * region to shared explicitly.  Don't complain such case.  See
> diff --git a/system/memory.c b/system/memory.c
> index 81b7bff42d..15964160ee 100644
> --- a/system/memory.c
> +++ b/system/memory.c
> @@ -1897,7 +1897,7 @@ bool memory_region_is_protected(MemoryRegion *mr)
>       return mr->ram && (mr->ram_block->flags & RAM_PROTECTED);
>   }
>   
> -bool memory_region_has_guest_memfd(MemoryRegion *mr)
> +bool memory_region_has_guest_memfd_private(MemoryRegion *mr)
>   {
>       return mr->ram_block && mr->ram_block->guest_memfd >= 0;
>   }
Re: [PATCH v2 4/9] memory: Rename memory_region_has_guest_memfd() to *_private()
Posted by Peter Xu 1 month, 4 weeks ago
On Thu, Dec 11, 2025 at 03:10:24PM +0800, Xiaoyao Li wrote:
> On 11/20/2025 1:29 AM, Peter Xu wrote:
> > Rename the function with "_private" suffix, to show that it returns true
> > only if it has an internal guest-memfd to back private pages (rather than
> > in-place guest-memfd).

PS: I forgot to update here, I'll use "fully shared" to replace "in-place".

> > 
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >   include/system/memory.h | 6 +++---
> >   accel/kvm/kvm-all.c     | 6 +++---
> >   system/memory.c         | 2 +-
> >   3 files changed, 7 insertions(+), 7 deletions(-)
> > 
> > diff --git a/include/system/memory.h b/include/system/memory.h
> > index 2c1a5e06b4..4428701a9f 100644
> > --- a/include/system/memory.h
> > +++ b/include/system/memory.h
> > @@ -1823,14 +1823,14 @@ static inline bool memory_region_is_romd(MemoryRegion *mr)
> >   bool memory_region_is_protected(MemoryRegion *mr);
> >   /**
> > - * memory_region_has_guest_memfd: check whether a memory region has guest_memfd
> > - *     associated
> > + * memory_region_has_guest_memfd_private: check whether a memory region has
> > + *     guest_memfd associated
> 
> Nit: maybe change it to "guest_memfd_private associated", and maybe put this
> patch after patch 5?

Agree, though maybe I should do this change in the other ramblock patch
(and move that one before this)?

> 
> Otherwise,
> 
> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>

Thanks,

-- 
Peter Xu