All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Steffen Eiden <seiden@linux.ibm.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: Thu, 3 Sep 2026 10:20:39 -0700	[thread overview]
Message-ID: <apmsZ3j0mtZq4Lp9@google.com> (raw)
In-Reply-To: <20260903-vfio-v2-1-ef4cd4190ae7@linux.ibm.com>

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.

      parent reply	other threads:[~2026-09-03 17:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03  8:16 [PATCH v2] vfio: Use file-based reference counting for KVM Steffen Eiden
2026-09-03  8:42 ` sashiko-bot
2026-09-03 17:07   ` Sean Christopherson
2026-09-03 17:20 ` Sean Christopherson [this message]

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=apmsZ3j0mtZq4Lp9@google.com \
    --to=seanjc@google.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=seiden@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.