lkml.org 
[lkml]   [2023]   [Feb]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    SubjectRe: [PATCH v10 2/9] KVM: Introduce per-page memory attributes
    From
    On Mon, Feb 13, 2023, Isaku Yamahata wrote:
    > On Fri, Feb 10, 2023 at 12:35:30AM +0000,
    > Sean Christopherson <seanjc@google.com> wrote:
    >
    > > On Wed, Feb 08, 2023, Isaku Yamahata wrote:
    > > > On Fri, Dec 02, 2022 at 02:13:40PM +0800,
    > > > Chao Peng <chao.p.peng@linux.intel.com> wrote:
    > > >
    > > > > +static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm,
    > > > > + struct kvm_memory_attributes *attrs)
    > > > > +{
    > > > > + gfn_t start, end;
    > > > > + unsigned long i;
    > > > > + void *entry;
    > > > > + u64 supported_attrs = kvm_supported_mem_attributes(kvm);
    > > > > +
    > > > > + /* flags is currently not used. */
    > > > > + if (attrs->flags)
    > > > > + return -EINVAL;
    > > > > + if (attrs->attributes & ~supported_attrs)
    > > > > + return -EINVAL;
    > > > > + if (attrs->size == 0 || attrs->address + attrs->size < attrs->address)
    > > > > + return -EINVAL;
    > > > > + if (!PAGE_ALIGNED(attrs->address) || !PAGE_ALIGNED(attrs->size))
    > > > > + return -EINVAL;
    > > > > +
    > > > > + start = attrs->address >> PAGE_SHIFT;
    > > > > + end = (attrs->address + attrs->size - 1 + PAGE_SIZE) >> PAGE_SHIFT;
    > > > > +
    > > > > + entry = attrs->attributes ? xa_mk_value(attrs->attributes) : NULL;
    > > > > +
    > > > > + mutex_lock(&kvm->lock);
    > > > > + for (i = start; i < end; i++)
    > > > > + if (xa_err(xa_store(&kvm->mem_attr_array, i, entry,
    > > > > + GFP_KERNEL_ACCOUNT)))
    > > > > + break;
    > > > > + mutex_unlock(&kvm->lock);
    > > > > +
    > > > > + attrs->address = i << PAGE_SHIFT;
    > > > > + attrs->size = (end - i) << PAGE_SHIFT;
    > > > > +
    > > > > + return 0;
    > > > > +}
    > > > > +#endif /* CONFIG_HAVE_KVM_MEMORY_ATTRIBUTES */
    > > > > +
    > > >
    > > > If memslot isn't private, it should return error if private attribute is set.
    > >
    > > Why? I'd rather keep the two things separate. If we enforce this sort of thing
    > > at KVM_SET_MEMORY_ATTRIBUTES, then we also have to enforce it at
    > > KVM_SET_USER_MEMORY_REGION.
    >
    > For device assignment via shared GPA, non-private memory slot needs to be
    > allowed.

    That doesn't say anything about why setting attributes needs to poke into the
    memslot. The page fault path already kicks out to userspace if there's a
    discrepancy between the attributes and the memslot, why is that insufficient?

    \
     
     \ /
      Last update: 2023-03-27 00:23    [W:4.221 / U:0.212 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site