[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z4_F5dNstl3Xzhox@google.com>
Date: Tue, 21 Jan 2025 08:05:57 -0800
From: Sean Christopherson <seanjc@...gle.com>
To: Christoph Schlameuss <schlameuss@...ux.ibm.com>
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
Paolo Bonzini <pbonzini@...hat.com>, Tao Su <tao1.su@...ux.intel.com>,
Claudio Imbrenda <imbrenda@...ux.ibm.com>, Christian Borntraeger <borntraeger@...ibm.com>,
Xiaoyao Li <xiaoyao.li@...el.com>
Subject: Re: [PATCH v2 3/5] KVM: Add a dedicated API for setting KVM-internal memslots
On Mon, Jan 20, 2025, Christoph Schlameuss wrote:
> On Sat Jan 11, 2025 at 1:20 AM CET, Sean Christopherson wrote:
> > Add a dedicated API for setting internal memslots, and have it explicitly
> > disallow setting userspace memslots. Setting a userspace memslots without
> > a direct command from userspace would result in all manner of issues.
> >
> > No functional change intended.
> >
> > Cc: Tao Su <tao1.su@...ux.intel.com>
> > Cc: Claudio Imbrenda <imbrenda@...ux.ibm.com>
> > Cc: Christian Borntraeger <borntraeger@...ibm.com>
> > Signed-off-by: Sean Christopherson <seanjc@...gle.com>
> > ---
> > arch/x86/kvm/x86.c | 2 +-
> > include/linux/kvm_host.h | 4 ++--
> > virt/kvm/kvm_main.c | 15 ++++++++++++---
> > 3 files changed, 15 insertions(+), 6 deletions(-)
>
> [...]
>
> > +int kvm_set_internal_memslot(struct kvm *kvm,
> > + const struct kvm_userspace_memory_region2 *mem)
> > +{
> > + if (WARN_ON_ONCE(mem->slot < KVM_USER_MEM_SLOTS))
> > + return -EINVAL;
> > +
>
> Looking at Claudios changes I found that this is missing to acquire the
> slots_lock here.
>
> guard(mutex)(&kvm->slots_lock);
It's not missing. As of this patch, x86 is the only user of KVM-internal memslots,
and x86 acquires slots_lock outside of kvm_set_internal_memslot() because x86 can
have multiple address spaces (regular vs SMM) and KVM's internal memslots need to
be created for both, i.e. it's desirable to holds slots_lock in the caller.
If it's annoying for s390 to acquire slots_lock, we could add a wrapper, i.e. turn
this into __kvm_set_internal_memslot() and then re-add kvm_set_internal_memslot()
as a version that acquires and releases slots_lock.
Powered by blists - more mailing lists