Re: [PATCH v12 17/45] KVM: guest_memfd: Return early if range already has requested attributes

From: David Hildenbrand (Arm)

Date: Wed Sep 09 2026 - 12:47:07 EST


On 8/31/26 02:25, Ackerley Tng via B4 Relay wrote:
> From: Ackerley Tng <ackerleytng@xxxxxxxxxx>
>
> Provide a function to check that a range has given attributes.
>
> Optimize setting memory attributes by returning early if all pages in the
> requested range already have the requested attributes.
>
> Reviewed-by: Fuad Tabba <tabba@xxxxxxxxxx>
> Tested-by: Shivank Garg <shivankg@xxxxxxx>
> Reviewed-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>
> Reviewed-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
> Signed-off-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
> ---
> virt/kvm/guest_memfd.c | 23 ++++++++++++++++++++++-
> 1 file changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index d14a7024bdc7b..ac8e0c6d6e942 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -98,6 +98,24 @@ static bool kvm_gmem_is_shared_mem(struct inode *inode, pgoff_t index)
> return !kvm_gmem_is_private_mem(inode, index);
> }
>
> +static bool kvm_gmem_range_has_attributes(struct inode *inode,
> + pgoff_t index, size_t nr_pages,
> + u64 attributes)

"has_attributes" could be confused with "has any attributes", not "has exactly
these matching attributes and no others".

Anyhow, I'm out of puff for naming suggestions today and this gets the hob done
;) (kvm_gmem_range_has_matching_attributes is a bit mouthful)

Reviewed-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

--
Cheers,

David