From: "Jason J. Herne" <jjherne@linux.ibm.com>
To: Steffen Eiden <seiden@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Janosch Frank <frankja@linux.ibm.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>,
David Hildenbrand <david@kernel.org>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Farhan Ali <alifm@linux.ibm.com>,
Eric Farman <farman@linux.ibm.com>,
Tony Krowiak <akrowiak@linux.ibm.com>,
Halil Pasic <pasic@linux.ibm.com>,
Harald Freudenberger <freude@linux.ibm.com>,
Holger Dengler <dengler@linux.ibm.com>,
Alex Williamson <alex@shazbot.org>
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
linux-kernel@vger.kernel.org, Jason Gunthorpe <jgg@ziepe.ca>
Subject: Re: [PATCH v3 4/5] KVM/vfio: Use file-based reference counting for KVM
Date: Thu, 24 Sep 2026 08:47:43 -0400 [thread overview]
Message-ID: <0256f343-fda7-492a-b987-91a6aaa4a5b8@linux.ibm.com> (raw)
In-Reply-To: <20260924-vfio-v3-4-4a294307797b@linux.ibm.com>
On 9/24/26 4:58 AM, Steffen Eiden wrote:
> Replace manual module reference counting with file-based reference
> counting for KVM integration. Previously, VFIO used symbol_get() to
> obtain function pointers for kvm_get_kvm_safe() and kvm_put_kvm(),
> then manually tracked module references through these symbols. This
> approach required storing the put_kvm function pointer in each device
> and carefully managing symbol references.
>
> Pass struct file pointers instead of struct kvm pointers throughout the
> VFIO-KVM interface, leveraging the kernel's existing file reference
> counting via get_file()/get_file_active() and fput(). Convert the x86
> page-track API and update s390 vfio to use file_to_kvm_<arch>(). This
> simplifies the code and removes all remaining externally exported
> symbols for KVM which would appear twice for when a second concurrent
> KVM module is introduced.
>
> Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
> Co-developed-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
> arch/s390/include/asm/kvm_host_s390.h | 2 +-
> arch/s390/kvm/s390/pci.c | 9 ++++--
> arch/x86/include/asm/kvm_page_track.h | 8 ++---
> arch/x86/kvm/mmu/page_track.c | 22 +++++++++-----
> drivers/s390/crypto/vfio_ap_ops.c | 20 ++++++++----
> drivers/vfio/group.c | 11 ++++++-
> drivers/vfio/vfio.h | 12 ++++----
> drivers/vfio/vfio_main.c | 57 +++++++++++------------------------
> include/linux/vfio.h | 5 ++-
> virt/kvm/vfio.c | 13 +++++---
> 10 files changed, 85 insertions(+), 74 deletions(-)
> ...
> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
> index 940c0ff668be..556e643244f2 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c
> @@ -1822,17 +1822,27 @@ static const struct attribute_group *vfio_ap_mdev_attr_groups[] = {
>
> /**
> * vfio_ap_mdev_set_kvm - sets all data for @matrix_mdev that are needed
> - * to manage AP resources for the guest whose state is represented by @kvm
> + * to manage AP resources for the guest whose state is represented by
> + * @kvm_file
> *
> * @matrix_mdev: a mediated matrix device
> - * @kvm: reference to KVM instance
> + * @kvm_file: the KVM VM file this vfio device is associated with
> *
> - * Return: 0 if no other mediated matrix device has a reference to @kvm;
> + * Return: 0 if no other mediated matrix device has a reference to the VM;
> * otherwise, returns an -EPERM.
> */
> static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev,
> - struct kvm *kvm)
> + struct file *kvm_file)
> {
> + struct kvm *kvm;
> +
> + if (!kvm_file)
> + return -ENOENT;
> +
> + kvm = file_to_kvm_s390(kvm_file);
> + if (!kvm)
> + return -ENOENT;
> +
> if (kvm->arch.crypto.crycbd) {
> get_update_locks_for_kvm(kvm);
> if (kvm->arch.crypto.pqap_hook) {
> @@ -1841,7 +1851,6 @@ static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev,
> }
> kvm->arch.crypto.pqap_hook = &matrix_mdev->pqap_hook;
>
> - kvm_get_kvm(kvm);
> matrix_mdev->kvm = kvm;
> vfio_ap_mdev_update_guest_apcb(matrix_mdev);
> release_update_locks_for_kvm(kvm);
> @@ -1894,7 +1903,6 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev)
> matrix_mdev->kvm = NULL;
>
> release_update_locks_for_kvm(kvm);
> - kvm_put_kvm(kvm);
> }
> }
>
Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com>
next prev parent reply other threads:[~2026-09-24 12:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 8:58 [PATCH v3 0/5] " Steffen Eiden
2026-09-24 8:58 ` [PATCH v3 1/5] KVM: Introduce file_to_kvm_<arch>() infrastructure Steffen Eiden
2026-09-24 8:58 ` [PATCH v3 2/5] KVM: Add file back-pointer to struct kvm Steffen Eiden
2026-09-24 8:58 ` [PATCH v3 3/5] KVM: x86: Use file_to_kvm_x86() in SEV Steffen Eiden
2026-09-24 8:58 ` [PATCH v3 4/5] KVM/vfio: Use file-based reference counting for KVM Steffen Eiden
2026-09-24 12:47 ` Jason J. Herne [this message]
2026-09-24 8:58 ` [PATCH v3 5/5] KVM: Restrict kvm_get_kvm/kvm_put_kvm export to internal KVM modules Steffen Eiden
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=0256f343-fda7-492a-b987-91a6aaa4a5b8@linux.ibm.com \
--to=jjherne@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=david@kernel.org \
--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=hca@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=imbrenda@linux.ibm.com \
--cc=jgg@ziepe.ca \
--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=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 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®