All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: alex.williamson@redhat.com, jgg@nvidia.com
Cc: kevin.tian@intel.com, eric.auger@redhat.com, cohuck@redhat.com,
	nicolinc@nvidia.com, yi.y.sun@linux.intel.com,
	chao.p.peng@linux.intel.com, mjrosato@linux.ibm.com,
	kvm@vger.kernel.org, yi.l.liu@intel.com
Subject: [RFC 03/10] vfio: Wrap group codes to be helpers for __vfio_register_dev() and unregister
Date: Wed, 23 Nov 2022 07:01:06 -0800	[thread overview]
Message-ID: <20221123150113.670399-4-yi.l.liu@intel.com> (raw)
In-Reply-To: <20221123150113.670399-1-yi.l.liu@intel.com>

This avoids to decode group fields in the common functions used by
vfio_device registration, and prepares for further moving vfio group
specific code into separate file.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/vfio/vfio_main.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index bd45b8907311..f4af3afcb26f 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -517,6 +517,20 @@ static struct vfio_group *vfio_group_find_or_alloc(struct device *dev)
 	return group;
 }
 
+static void vfio_device_group_register(struct vfio_device *device)
+{
+	mutex_lock(&device->group->device_lock);
+	list_add(&device->group_next, &device->group->device_list);
+	mutex_unlock(&device->group->device_lock);
+}
+
+static void vfio_device_group_unregister(struct vfio_device *device)
+{
+	mutex_lock(&device->group->device_lock);
+	list_del(&device->group_next);
+	mutex_unlock(&device->group->device_lock);
+}
+
 static int __vfio_register_dev(struct vfio_device *device,
 		struct vfio_group *group)
 {
@@ -555,9 +569,7 @@ static int __vfio_register_dev(struct vfio_device *device,
 	/* Refcounting can't start until the driver calls register */
 	refcount_set(&device->refcount, 1);
 
-	mutex_lock(&group->device_lock);
-	list_add(&device->group_next, &group->device_list);
-	mutex_unlock(&group->device_lock);
+	vfio_device_group_register(device);
 
 	return 0;
 err_out:
@@ -617,7 +629,6 @@ static struct vfio_device *vfio_device_get_from_name(struct vfio_group *group,
  * removed.  Open file descriptors for the device... */
 void vfio_unregister_group_dev(struct vfio_device *device)
 {
-	struct vfio_group *group = device->group;
 	unsigned int i = 0;
 	bool interrupted = false;
 	long rc;
@@ -645,9 +656,7 @@ void vfio_unregister_group_dev(struct vfio_device *device)
 		}
 	}
 
-	mutex_lock(&group->device_lock);
-	list_del(&device->group_next);
-	mutex_unlock(&group->device_lock);
+	vfio_device_group_unregister(device);
 
 	/* Balances device_add in register path */
 	device_del(&device->device);
-- 
2.34.1


  parent reply	other threads:[~2022-11-23 15:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 15:01 [RFC 00/10] Move group specific code into group.c Yi Liu
2022-11-23 15:01 ` [RFC 01/10] vfio: Simplify vfio_create_group() Yi Liu
2022-11-23 15:01 ` [RFC 02/10] vfio: Move the sanity check of the group to vfio_create_group() Yi Liu
2022-11-23 15:01 ` Yi Liu [this message]
2022-11-23 15:01 ` [RFC 04/10] vfio: Make vfio_device_open() group agnostic Yi Liu
2022-11-23 15:01 ` [RFC 05/10] vfio: Move device open/close code to be helpfers Yi Liu
2022-11-23 15:01 ` [RFC 06/10] vfio: Swap order of vfio_device_container_register() and open_device() Yi Liu
2022-11-23 15:01 ` [RFC 07/10] vfio: Refactor vfio_device_first_open() and _last_close() Yi Liu
2022-11-23 15:01 ` [RFC 08/10] vfio: Wrap vfio group module init/clean code into helpers Yi Liu
2022-11-23 15:01 ` [RFC 09/10] vfio: Refactor dma APIs for emulated devices Yi Liu
2022-11-23 16:51   ` Jason Gunthorpe
2022-11-24  3:05     ` Yi Liu
2022-11-23 15:01 ` [RFC 10/10] vfio: Move vfio group specific code into group.c Yi Liu
2022-11-23 18:37   ` Jason Gunthorpe
2022-11-24  3:06     ` Yi Liu
2022-11-23 18:41 ` [RFC 00/10] Move " Jason Gunthorpe
2022-11-24  3:15   ` Yi Liu

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=20221123150113.670399-4-yi.l.liu@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=cohuck@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=nicolinc@nvidia.com \
    --cc=yi.y.sun@linux.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 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.