From: Anthony DeRossi <ajderossi@gmail.com>
To: kvm@vger.kernel.org
Cc: alex.williamson@redhat.com, cohuck@redhat.com, jgg@ziepe.ca,
kevin.tian@intel.com, abhsahu@nvidia.com, yishaih@nvidia.com
Subject: [PATCH v4 2/3] vfio: Add an open counter to vfio_device_set
Date: Fri, 4 Nov 2022 12:57:26 -0700 [thread overview]
Message-ID: <20221104195727.4629-3-ajderossi@gmail.com> (raw)
In-Reply-To: <20221104195727.4629-1-ajderossi@gmail.com>
open_count is incremented before open_device() and decremented after
close_device() for each device in the set. This allows devices to
determine whether shared resources are in use without tracking them
manually or accessing the private open_count in vfio_device.
Signed-off-by: Anthony DeRossi <ajderossi@gmail.com>
---
drivers/vfio/vfio_main.c | 3 +++
include/linux/vfio.h | 1 +
2 files changed, 4 insertions(+)
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 9a4af880e941..6c65418fc7e3 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -761,6 +761,7 @@ static struct file *vfio_device_open(struct vfio_device *device)
mutex_lock(&device->group->group_lock);
device->kvm = device->group->kvm;
+ device->dev_set->open_count++;
if (device->ops->open_device) {
ret = device->ops->open_device(device);
if (ret)
@@ -809,6 +810,7 @@ static struct file *vfio_device_open(struct vfio_device *device)
}
err_undo_count:
mutex_unlock(&device->group->group_lock);
+ device->dev_set->open_count--;
device->open_count--;
if (device->open_count == 0 && device->kvm)
device->kvm = NULL;
@@ -1023,6 +1025,7 @@ static int vfio_device_fops_release(struct inode *inode, struct file *filep)
device->ops->close_device(device);
vfio_device_container_unregister(device);
+ device->dev_set->open_count--;
}
mutex_unlock(&device->group->group_lock);
device->open_count--;
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index e7cebeb875dd..5becdcdf4ba2 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -28,6 +28,7 @@ struct vfio_device_set {
struct mutex lock;
struct list_head device_list;
unsigned int device_count;
+ unsigned int open_count;
};
struct vfio_device {
--
2.37.4
next prev parent reply other threads:[~2022-11-04 20:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-04 19:57 [PATCH v4 0/3] vfio/pci: Check the device set open_count on reset Anthony DeRossi
2022-11-04 19:57 ` [PATCH v4 1/3] vfio: Fix container device registration life cycle Anthony DeRossi
2022-11-04 20:59 ` Alex Williamson
2022-11-09 0:51 ` Jason Gunthorpe
2022-11-09 0:58 ` Alex Williamson
2022-11-09 1:00 ` Jason Gunthorpe
2022-11-04 19:57 ` Anthony DeRossi [this message]
2022-11-04 20:59 ` [PATCH v4 2/3] vfio: Add an open counter to vfio_device_set Alex Williamson
2022-11-05 22:56 ` Anthony DeRossi
2022-11-04 19:57 ` [PATCH v4 3/3] vfio/pci: Check the device set open_count on reset Anthony DeRossi
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=20221104195727.4629-3-ajderossi@gmail.com \
--to=ajderossi@gmail.com \
--cc=abhsahu@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=jgg@ziepe.ca \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=yishaih@nvidia.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;
as well as URLs for NNTP newsgroup(s).