mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steffen Eiden <seiden@linux.ibm.com>
To: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-s390@vger.kernel.org, x86@kernel.org,
	Alex Williamson <alex@shazbot.org>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Andreas Grapentin <gra@linux.ibm.com>,
	Borislav Petkov <bp@alien8.de>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Eric Farman <farman@linux.ibm.com>,
	Farhan Ali <alifm@linux.ibm.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Halil Pasic <pasic@linux.ibm.com>,
	Harald Freudenberger <freude@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Holger Dengler <dengler@linux.ibm.com>,
	Ingo Molnar <mingo@redhat.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Jason Herne <jjherne@linux.ibm.com>,
	Matthew Rosato <mjrosato@linux.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Thomas Gleixner <tglx@kernel.org>,
	Tony Krowiak <akrowiak@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>, Jason Gunthorpe <jgg@ziepe.ca>
Subject: Re: [PATCH v2] vfio: Use file-based reference counting for KVM
Date: Fri, 18 Sep 2026 15:45:43 +0200	[thread overview]
Message-ID: <20260918134543.84754-B-seiden@linux.ibm.com> (raw)
In-Reply-To: <apmsZ3j0mtZq4Lp9@google.com>

On Thu, Sep 03, 2026 at 10:20:39AM -0700, Sean Christopherson wrote:
> On Thu, Sep 03, 2026, Steffen Eiden wrote:
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index 65eb26a0520d..34b4c43908b3 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -1314,7 +1314,7 @@ void kvm_get_kvm(struct kvm *kvm)
> >  {
> >  	refcount_inc(&kvm->users_count);
> >  }
> > -EXPORT_SYMBOL_GPL(kvm_get_kvm);
> > +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_get_kvm);
> >  
> >  /*
> >   * Make sure the vm is not during destruction, which is a safe version of
> > @@ -1324,14 +1324,14 @@ bool kvm_get_kvm_safe(struct kvm *kvm)
> >  {
> >  	return refcount_inc_not_zero(&kvm->users_count);
> >  }
> > -EXPORT_SYMBOL_GPL(kvm_get_kvm_safe);
> > +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_get_kvm_safe);
> >  
> >  void kvm_put_kvm(struct kvm *kvm)
> >  {
> >  	if (refcount_dec_and_test(&kvm->users_count))
> >  		kvm_destroy_vm(kvm);
> >  }
> > -EXPORT_SYMBOL_GPL(kvm_put_kvm);
> > +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_put_kvm);
> 
> Please isolate the export changes.  They don't *need* to happen at the same time
> as the VFIO changes, i.e. can be done on top.
> 
> >  /*
> >   * Used to put a reference that was taken on behalf of an object associated
> > @@ -1352,6 +1352,8 @@ static int kvm_vm_release(struct inode *inode, struct file *filp)
> >  
> >  	kvm_irqfd_release(kvm);
> >  
> > +	WRITE_ONCE(kvm->file, NULL);
> 
> Please move tracking the file in "struct kvm" to its own patch as well.
> 
> > +
> >  	kvm_put_kvm(kvm);
> >  	return 0;
> >  }
> > @@ -5496,6 +5498,15 @@ bool file_is_kvm(struct file *file)
> >  }
> >  EXPORT_SYMBOL_FOR_KVM_INTERNAL(file_is_kvm);
> >  
> > +struct kvm *file_to_kvm(struct file *file)
> > +{
> > +	if (!file_is_kvm(file))
> 
> file_is_kvm() should exist at the end of this series.  The only reason to ever
> use file_is_kvm() is in advance of getting at "struct kvm", i.e. this should be
> open coded in file_to_kvm().  Though as I suggested in the other subtread, it
> woudl be kvm_file_to_kvm_fn(), i.e. kvm_file_to_kvm_x86() or kvm_file_to_kvm_s390().
> 
> And those changes can and should be done as prep work, i.e. in separate patches,
> e.g. to end up with something like:
> 
>   1. Add kvm_file_to_kvm_fn() and use it on x86, i.e. replace the use of
>      file_is_kvm() in arch/x86/kvm/svm/sev.c.
>   2. Add kvm->file tracking.
>   3. Switch VFIO to tracking the file.
>   4. s/EXPORT_SYMBOL_GPL/EXPORT_SYMBOL_FOR_KVM_INTERNAL on the get/put APIs.
>   5. Enable kvm_file_to_kvm_fn() on s390 and use kvm_file_to_kvm_s390() in the
>      relevant code to prepare for s390+arm64.


I sent the changes incorporated in the main series[1] in 5 patches:

KVM: Introduce file_to_kvm_<arch>() infrastructure 	- adds the macros
KVM: Add file back-pointer to struct kvm		- adds the file field
KVM: x86: Use file_to_kvm_x86() in SEV
KVM/vfio: Use file-based reference counting for KVM	- the swotch in one go
KVM: Restrict kvm_get_kvm/kvm_put_kvm export to internal KVM modules

I needed to do the switch in one go (i.e. merge 5->3) otherwhise there would be conflicts.

Note, that in addition, I moved the symbol verification makefilestuff to
a shared loaction and reused it for s390 in separate patches in the
series.

	Steffen

[1] https://lore.kernel.org/all/20260918133107.1042730-1-seiden@linux.ibm.com

  reply	other threads:[~2026-09-18 13:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03  8:16 Steffen Eiden
2026-09-03 17:20 ` Sean Christopherson
2026-09-18 13:45   ` Steffen Eiden [this message]
2026-09-18 15:38     ` Jason Gunthorpe

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=20260918134543.84754-B-seiden@linux.ibm.com \
    --to=seiden@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=alex@shazbot.org \
    --cc=alifm@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dengler@linux.ibm.com \
    --cc=farman@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=freude@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=gra@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hpa@zytor.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=jgg@ziepe.ca \
    --cc=jjherne@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=svens@linux.ibm.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®