From: Jason Gunthorpe <jgg@nvidia.com>
To: Yan Zhao <yan.y.zhao@intel.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
alex.williamson@redhat.com, kevin.tian@intel.com,
peterx@redhat.com, ajones@ventanamicro.com
Subject: Re: [PATCH] vfio: Reuse file f_inode as vfio device inode
Date: Wed, 26 Jun 2024 10:35:28 -0300 [thread overview]
Message-ID: <20240626133528.GE2494510@nvidia.com> (raw)
In-Reply-To: <20240617095332.30543-1-yan.y.zhao@intel.com>
On Mon, Jun 17, 2024 at 05:53:32PM +0800, Yan Zhao wrote:
> Reuse file f_inode as vfio device inode and associate pseudo path file
> directly to inode allocated in vfio fs.
>
> Currently, vfio device is opened via 2 ways:
> 1) via cdev open
> vfio device is opened with a cdev device with file f_inode and address
> space associated with a cdev inode;
> 2) via VFIO_GROUP_GET_DEVICE_FD ioctl
> vfio device is opened via a pseudo path file with file f_inode and
> address space associated with an inode in anon_inode_fs.
>
> In commit b7c5e64fecfa ("vfio: Create vfio_fs_type with inode per device"),
> an inode in vfio fs is allocated for each vfio device. However, this inode
> in vfio fs is only used to assign its address space to that of a file
> associated with another cdev inode or an inode in anon_inode_fs.
>
> This patch
> - reuses cdev device inode as the vfio device inode when it's opened via
> cdev way;
> - allocates an inode in vfio fs, associate it to the pseudo path file,
> and save it as the vfio device inode when the vfio device is opened via
> VFIO_GROUP_GET_DEVICE_FD ioctl.
>
> File address space will then point automatically to the address space of
> the vfio device inode. Tools like unmap_mapping_range() can then zap all
> vmas associated with the vfio device.
>
> Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
> ---
> drivers/vfio/device_cdev.c | 9 ++++---
> drivers/vfio/group.c | 21 ++--------------
> drivers/vfio/vfio.h | 2 ++
> drivers/vfio/vfio_main.c | 49 +++++++++++++++++++++++++++-----------
> 4 files changed, 43 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/vfio/device_cdev.c b/drivers/vfio/device_cdev.c
> index bb1817bd4ff3..a4eec8e88f5c 100644
> --- a/drivers/vfio/device_cdev.c
> +++ b/drivers/vfio/device_cdev.c
> @@ -40,12 +40,11 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep)
> filep->private_data = df;
>
> /*
> - * Use the pseudo fs inode on the device to link all mmaps
> - * to the same address space, allowing us to unmap all vmas
> - * associated to this device using unmap_mapping_range().
> + * mmaps are linked to the address space of the inode of device cdev.
> + * Save the inode of device cdev in device->inode to allow
> + * unmap_mapping_range() to unmap all vmas.
> */
> - filep->f_mapping = device->inode->i_mapping;
> -
> + device->inode = inode;
This doesn't seem right.. There is only one device but multiple file
can be opened on that device.
We expect every open file to have a unique inode otherwise the
unmap_mapping_range() will not function properly.
Jason
next prev parent reply other threads:[~2024-06-26 13:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-17 9:53 [PATCH] vfio: Reuse file f_inode as vfio device inode Yan Zhao
2024-06-20 10:14 ` Yan Zhao
2024-06-26 8:36 ` Tian, Kevin
2024-06-26 9:11 ` Yan Zhao
2024-06-26 13:35 ` Jason Gunthorpe [this message]
2024-06-26 23:55 ` Tian, Kevin
2024-06-27 12:26 ` Jason Gunthorpe
2024-06-27 0:17 ` Tian, Kevin
2024-06-27 9:51 ` Yan Zhao
2024-06-27 12:42 ` Jason Gunthorpe
2024-06-28 5:21 ` Yan Zhao
2024-06-28 9:48 ` Yi Liu
2024-06-28 15:28 ` Yan Zhao
2024-06-30 7:06 ` Yi Liu
2024-07-01 1:47 ` Yan Zhao
2024-07-01 5:44 ` Yi Liu
2024-07-01 5:48 ` Yan Zhao
2024-07-10 14:40 ` Jason Gunthorpe
2024-07-12 5:19 ` Yan Zhao
2024-07-12 6:14 ` Yi Liu
2024-07-01 7:54 ` Yi Liu
2024-07-01 11:29 ` Yan Zhao
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=20240626133528.GE2494510@nvidia.com \
--to=jgg@nvidia.com \
--cc=ajones@ventanamicro.com \
--cc=alex.williamson@redhat.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=yan.y.zhao@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.