linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Nicolin Chen <nicolinc@nvidia.com>
Cc: kevin.tian@intel.com, corbet@lwn.net, will@kernel.org,
	joro@8bytes.org, suravee.suthikulpanit@amd.com,
	robin.murphy@arm.com, dwmw2@infradead.org,
	baolu.lu@linux.intel.com, shuah@kernel.org,
	linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org,
	eric.auger@redhat.com, jean-philippe@linaro.org, mdf@kernel.org,
	mshavit@google.com, shameerali.kolothum.thodi@huawei.com,
	smostafa@google.com, ddutile@redhat.com, yi.l.liu@intel.com,
	patches@lists.linux.dev
Subject: Re: [PATCH v5 04/14] iommufd: Abstract an iommufd_eventq from iommufd_fault
Date: Fri, 10 Jan 2025 13:26:37 -0400	[thread overview]
Message-ID: <20250110172637.GF396083@nvidia.com> (raw)
In-Reply-To: <a6490048ab3df78f648e3ef0d217a90b7213d47c.1736237481.git.nicolinc@nvidia.com>

On Tue, Jan 07, 2025 at 09:10:07AM -0800, Nicolin Chen wrote:

> @@ -433,32 +434,35 @@ void iopt_remove_access(struct io_pagetable *iopt,
>  			u32 iopt_access_list_id);
>  void iommufd_access_destroy_object(struct iommufd_object *obj);
>  
> -/*
> - * An iommufd_fault object represents an interface to deliver I/O page faults
> - * to the user space. These objects are created/destroyed by the user space and
> - * associated with hardware page table objects during page-table allocation.
> - */
> -struct iommufd_fault {
> +struct iommufd_eventq_ops {
> +	ssize_t (*read)(struct iommufd_eventq *eventq, char __user *buf,
> +			size_t count, loff_t *ppos); /* Mandatory op */
> +	ssize_t (*write)(struct iommufd_eventq *eventq, const char __user *buf,
> +			 size_t count, loff_t *ppos); /* Optional op */
> +};

I think I recommend to avoid this, more like this:

diff --git a/drivers/iommu/iommufd/eventq.c b/drivers/iommu/iommufd/eventq.c
index b5be629f38eda7..73f5e8a6b17f54 100644
--- a/drivers/iommu/iommufd/eventq.c
+++ b/drivers/iommu/iommufd/eventq.c
@@ -341,11 +341,6 @@ static ssize_t iommufd_fault_fops_write(struct iommufd_eventq *eventq,
 	return done == 0 ? rc : done;
 }
 
-static const struct iommufd_eventq_ops iommufd_fault_ops = {
-	.read = &iommufd_fault_fops_read,
-	.write = &iommufd_fault_fops_write,
-};
-
 /* IOMMUFD_OBJ_VEVENTQ Functions */
 
 void iommufd_veventq_abort(struct iommufd_object *obj)
@@ -409,31 +404,8 @@ static ssize_t iommufd_veventq_fops_read(struct iommufd_eventq *eventq,
 	return done == 0 ? rc : done;
 }
 
-static const struct iommufd_eventq_ops iommufd_veventq_ops = {
-	.read = &iommufd_veventq_fops_read,
-};
-
 /* Common Event Queue Functions */
 
-static ssize_t iommufd_eventq_fops_read(struct file *filep, char __user *buf,
-					size_t count, loff_t *ppos)
-{
-	struct iommufd_eventq *eventq = filep->private_data;
-
-	return eventq->ops->read(eventq, buf, count, ppos);
-}
-
-static ssize_t iommufd_eventq_fops_write(struct file *filep,
-					 const char __user *buf, size_t count,
-					 loff_t *ppos)
-{
-	struct iommufd_eventq *eventq = filep->private_data;
-
-	if (!eventq->ops->write)
-		return -EOPNOTSUPP;
-	return eventq->ops->write(eventq, buf, count, ppos);
-}
-
 static __poll_t iommufd_eventq_fops_poll(struct file *filep,
 					 struct poll_table_struct *wait)
 {
@@ -458,34 +430,31 @@ static int iommufd_eventq_fops_release(struct inode *inode, struct file *filep)
 	return 0;
 }
 
-static const struct file_operations iommufd_eventq_fops = {
-	.owner		= THIS_MODULE,
-	.open		= nonseekable_open,
-	.read		= iommufd_eventq_fops_read,
-	.write		= iommufd_eventq_fops_write,
-	.poll		= iommufd_eventq_fops_poll,
-	.release	= iommufd_eventq_fops_release,
-};
+#define INIT_EVENTQ_FOPS(read_op, write_op)                     \
+	(struct file_operations){                               \
+		.owner = THIS_MODULE,                           \
+		.open = nonseekable_open,                       \
+		.read = read_op,                                \
+		.write = write_op,                              \
+		.poll = iommufd_eventq_fops_poll,               \
+		.release = iommufd_eventq_fops_release,         \
+	}
 
 static int iommufd_eventq_init(struct iommufd_eventq *eventq, char *name,
 			       struct iommufd_ctx *ictx,
-			       const struct iommufd_eventq_ops *ops)
+			       const struct file_operations *fops)
 {
 	struct file *filep;
 	int fdno;
 
-	if (WARN_ON_ONCE(!ops || !ops->read))
-		return -EINVAL;
-
 	mutex_init(&eventq->mutex);
 	INIT_LIST_HEAD(&eventq->deliver);
 	init_waitqueue_head(&eventq->wait_queue);
 
-	filep = anon_inode_getfile(name, &iommufd_eventq_fops, eventq, O_RDWR);
+	filep = anon_inode_getfile(name, fops, eventq, O_RDWR);
 	if (IS_ERR(filep))
 		return PTR_ERR(filep);
 
-	eventq->ops = ops;
 	eventq->ictx = ictx;
 	iommufd_ctx_get(eventq->ictx);
 	refcount_inc(&eventq->obj.users);
@@ -497,6 +466,9 @@ static int iommufd_eventq_init(struct iommufd_eventq *eventq, char *name,
 	return fdno;
 }
 
+static const struct file_operations iommufd_pgfault_fops =
+	INIT_EVENTQ_FOPS(iommufd_fault_fops_read, iommufd_fault_fops_write);
+
 int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
 {
 	struct iommu_fault_alloc *cmd = ucmd->cmd;
@@ -515,7 +487,7 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
 	xa_init_flags(&fault->response, XA_FLAGS_ALLOC1);
 
 	fdno = iommufd_eventq_init(&fault->common, "[iommufd-pgfault]",
-				   ucmd->ictx, &iommufd_fault_ops);
+				   ucmd->ictx, &iommufd_pgfault_fops);
 	if (fdno < 0) {
 		rc = fdno;
 		goto out_abort;
@@ -541,6 +513,9 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
 	return rc;
 }
 
+static const struct file_operations iommufd_viommu_fops =
+	INIT_EVENTQ_FOPS(iommufd_veventq_fops_read, NULL);
+
 int iommufd_veventq_alloc(struct iommufd_ucmd *ucmd)
 {
 	struct iommu_veventq_alloc *cmd = ucmd->cmd;
@@ -580,7 +555,7 @@ int iommufd_veventq_alloc(struct iommufd_ucmd *ucmd)
 	list_add_tail(&veventq->node, &viommu->veventqs);
 
 	fdno = iommufd_eventq_init(&veventq->common, "[iommufd-viommu-event]",
-				   ucmd->ictx, &iommufd_veventq_ops);
+				   ucmd->ictx, &iommufd_viommu_fops);
 	if (fdno < 0) {
 		rc = fdno;
 		goto out_abort;
diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h
index 3c0374154a94d3..6c23d5b58901af 100644
--- a/drivers/iommu/iommufd/iommufd_private.h
+++ b/drivers/iommu/iommufd/iommufd_private.h
@@ -434,20 +434,11 @@ void iopt_remove_access(struct io_pagetable *iopt,
 			u32 iopt_access_list_id);
 void iommufd_access_destroy_object(struct iommufd_object *obj);
 
-struct iommufd_eventq_ops {
-	ssize_t (*read)(struct iommufd_eventq *eventq, char __user *buf,
-			size_t count, loff_t *ppos); /* Mandatory op */
-	ssize_t (*write)(struct iommufd_eventq *eventq, const char __user *buf,
-			 size_t count, loff_t *ppos); /* Optional op */
-};
-
 struct iommufd_eventq {
 	struct iommufd_object obj;
 	struct iommufd_ctx *ictx;
 	struct file *filep;
 
-	const struct iommufd_eventq_ops *ops;
-
 	/* The lists of outstanding events protected by below mutex. */
 	struct mutex mutex;
 	struct list_head deliver;


  parent reply	other threads:[~2025-01-10 17:32 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 17:10 [PATCH v5 00/14] iommufd: Add vIOMMU infrastructure (Part-3: vEVENTQ) Nicolin Chen
2025-01-07 17:10 ` [PATCH v5 01/14] iommufd: Keep OBJ/IOCTL lists in an alphabetical order Nicolin Chen
2025-01-10  6:26   ` Tian, Kevin
2025-01-10 17:25   ` Jason Gunthorpe
2025-01-14 19:29   ` Jason Gunthorpe
2025-01-07 17:10 ` [PATCH v5 02/14] iommufd/fault: Add an iommufd_fault_init() helper Nicolin Chen
2025-01-10 17:25   ` Jason Gunthorpe
2025-01-07 17:10 ` [PATCH v5 03/14] iommufd/fault: Move iommufd_fault_iopf_handler() to header Nicolin Chen
2025-01-10 17:25   ` Jason Gunthorpe
2025-01-07 17:10 ` [PATCH v5 04/14] iommufd: Abstract an iommufd_eventq from iommufd_fault Nicolin Chen
2025-01-10  6:26   ` Tian, Kevin
2025-01-10 17:26   ` Jason Gunthorpe [this message]
2025-01-10 20:49     ` Nicolin Chen
2025-01-07 17:10 ` [PATCH v5 05/14] iommufd: Rename fault.c to eventq.c Nicolin Chen
2025-01-10 17:27   ` Jason Gunthorpe
2025-01-07 17:10 ` [PATCH v5 06/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC Nicolin Chen
2025-01-10  7:06   ` Tian, Kevin
2025-01-10 21:29     ` Nicolin Chen
2025-01-13  2:52       ` Tian, Kevin
2025-01-13  4:51         ` Nicolin Chen
2025-01-13  8:17           ` Tian, Kevin
2025-01-13 19:10           ` Jason Gunthorpe
2025-01-10 17:48   ` Jason Gunthorpe
2025-01-10 19:27     ` Nicolin Chen
2025-01-10 19:49       ` Jason Gunthorpe
2025-01-10 21:58         ` Nicolin Chen
2025-01-13 19:12           ` Jason Gunthorpe
2025-01-13 19:18             ` Nicolin Chen
2025-01-07 17:10 ` [PATCH v5 07/14] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper Nicolin Chen
2025-01-10  7:07   ` Tian, Kevin
2025-01-10 21:35     ` Nicolin Chen
2025-01-07 17:10 ` [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper Nicolin Chen
2025-01-10  7:12   ` Tian, Kevin
2025-01-10 14:51     ` Jason Gunthorpe
2025-01-10 18:40       ` Nicolin Chen
2025-01-10 17:41   ` Jason Gunthorpe
2025-01-10 18:38     ` Nicolin Chen
2025-01-10 19:51       ` Jason Gunthorpe
2025-01-10 19:56         ` Nicolin Chen
2025-01-13  5:37         ` Nicolin Chen
2025-01-13 19:21           ` Jason Gunthorpe
2025-01-13 19:47             ` Nicolin Chen
2025-01-13 19:54               ` Jason Gunthorpe
2025-01-13 20:44                 ` Nicolin Chen
2025-01-14 13:41                   ` Jason Gunthorpe
2025-01-17 22:11                     ` Nicolin Chen
2025-01-20 18:18                       ` Jason Gunthorpe
2025-01-20 20:52                         ` Nicolin Chen
2025-01-21 18:36                           ` Jason Gunthorpe
2025-01-21 19:55                             ` Nicolin Chen
2025-01-21 20:09                               ` Jason Gunthorpe
2025-01-21 21:02                                 ` Nicolin Chen
2025-01-21 21:14                                   ` Jason Gunthorpe
2025-01-21 21:40                                     ` Nicolin Chen
2025-01-22  0:21                                       ` Jason Gunthorpe
2025-01-22  7:15                                         ` Nicolin Chen
2025-01-22  9:33                                           ` Tian, Kevin
2025-01-22 19:54                                             ` Nicolin Chen
2025-01-23 13:42                                               ` Jason Gunthorpe
2025-01-22  8:05                                       ` Nicolin Chen
2025-01-22 18:02                                         ` Nicolin Chen
2025-01-23  7:02                                           ` Nicolin Chen
2025-01-23 13:43                                             ` Jason Gunthorpe
2025-01-07 17:10 ` [PATCH v5 09/14] iommufd/selftest: Require vdev_id when attaching to a nested domain Nicolin Chen
2025-01-07 17:10 ` [PATCH v5 10/14] iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_VEVENT for vEVENTQ coverage Nicolin Chen
2025-01-07 17:10 ` [PATCH v5 11/14] iommufd/selftest: Add IOMMU_VEVENTQ_ALLOC test coverage Nicolin Chen
2025-01-07 17:10 ` [PATCH v5 12/14] Documentation: userspace-api: iommufd: Update FAULT and VEVENTQ Nicolin Chen
2025-01-10  7:13   ` Tian, Kevin
2025-01-07 17:10 ` [PATCH v5 13/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster Nicolin Chen
2025-01-13 19:29   ` Jason Gunthorpe
2025-01-13 19:52     ` Nicolin Chen
2025-01-07 17:10 ` [PATCH v5 14/14] iommu/arm-smmu-v3: Report events that belong to devices attached to vIOMMU Nicolin Chen
2025-01-09 11:04   ` kernel test robot
2025-01-13 19:01     ` Nicolin Chen
2025-01-13 19:06       ` Jason Gunthorpe
2025-01-13 19:15         ` Nicolin Chen
2025-01-13 19:18           ` 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=20250110172637.GF396083@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=ddutile@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=eric.auger@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jean-philippe@linaro.org \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mdf@kernel.org \
    --cc=mshavit@google.com \
    --cc=nicolinc@nvidia.com \
    --cc=patches@lists.linux.dev \
    --cc=robin.murphy@arm.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=shuah@kernel.org \
    --cc=smostafa@google.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=will@kernel.org \
    --cc=yi.l.liu@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 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).