lkml.org 
[lkml]   [2023]   [Nov]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v13 13/35] KVM: Introduce per-page memory attributes
Date
On Thu, 2023-11-02 at 11:32 +0100, Paolo Bonzini wrote:
> > > +#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES
> > > +static inline unsigned long kvm_get_memory_attributes(struct kvm *kvm, gfn_t gfn)
> > > +{
> > > + return xa_to_value(xa_load(&kvm->mem_attr_array, gfn));
> > > +}
> >
> > Only call xa_to_value() when xa_load() returns !NULL?
>
> This xarray does not store a pointer, therefore xa_load() actually
> returns an integer that is tagged with 1 in the low bit:
>
> static inline unsigned long xa_to_value(const void *entry)
> {
>          return (unsigned long)entry >> 1;
> }
>
> Returning zero for an empty entry is okay, so the result of xa_load()
> can be used directly.

Thanks for explaining. I was thinking perhaps it's better to do:

void *entry = xa_load(...);

return xa_is_value(entry) ? xa_to_value(entry) : 0;

But "NULL (0) >> 1" is still 0, so yes we can use directly.
\
 
 \ /
  Last update: 2023-11-02 11:57    [W:0.124 / U:1.544 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site