public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Christoph Schlameuss" <schlameuss@linux.ibm.com>
To: "Claudio Imbrenda" <imbrenda@linux.ibm.com>,
	"Sean Christopherson" <seanjc@google.com>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Tao Su" <tao1.su@linux.intel.com>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>,
	"Xiaoyao Li" <xiaoyao.li@intel.com>
Subject: Re: [PATCH v2 3/5] KVM: Add a dedicated API for setting KVM-internal memslots
Date: Tue, 21 Jan 2025 20:40:12 +0100	[thread overview]
Message-ID: <D7808LRDCJ71.L6G17QHODL5Y@linux.ibm.com> (raw)
In-Reply-To: <20250121171756.1e2a2603@p-imbrenda>

On Tue Jan 21, 2025 at 5:17 PM CET, Claudio Imbrenda wrote:
> On Tue, 21 Jan 2025 08:05:57 -0800
> Sean Christopherson <seanjc@google.com> wrote:
>
> > 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@linux.intel.com>
> > > > Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
> > > > Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> > > > Signed-off-by: Sean Christopherson <seanjc@google.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.
>
> I think it's fine as it is, just document that the lock needs to be
> held
>
> I'll add the necessary locking in the s390 code

I see. Thank you for the elaboration, Sean!

  reply	other threads:[~2025-01-21 19:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-11  0:20 [PATCH v2 0/5] KVM: kvm_set_memory_region() cleanups Sean Christopherson
2025-01-11  0:20 ` [PATCH v2 1/5] KVM: Open code kvm_set_memory_region() into its sole caller (ioctl() API) Sean Christopherson
2025-01-11  0:20 ` [PATCH v2 2/5] KVM: Assert slots_lock is held when setting memory regions Sean Christopherson
2025-01-11  0:20 ` [PATCH v2 3/5] KVM: Add a dedicated API for setting KVM-internal memslots Sean Christopherson
2025-01-20 14:44   ` Christoph Schlameuss
2025-01-21 16:05     ` Sean Christopherson
2025-01-21 16:17       ` Claudio Imbrenda
2025-01-21 19:40         ` Christoph Schlameuss [this message]
2025-01-11  0:20 ` [PATCH v2 4/5] KVM: x86: Drop double-underscores from __kvm_set_memory_region() Sean Christopherson
2025-01-11  0:20 ` [PATCH v2 5/5] KVM: Disallow all flags for KVM-internal memslots Sean Christopherson
2025-01-13 11:56 ` [PATCH v2 0/5] KVM: kvm_set_memory_region() cleanups Claudio Imbrenda
2025-01-13 17:30 ` Christoph Schlameuss
2025-01-14  2:09 ` Xiaoyao Li
2025-01-15  2:58 ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D7808LRDCJ71.L6G17QHODL5Y@linux.ibm.com \
    --to=schlameuss@linux.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tao1.su@linux.intel.com \
    --cc=xiaoyao.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox