From: Jani Nikula <jani.nikula@linux.intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
David Airlie <airlied@gmail.com>,
Alex Williamson <alex.williamson@redhat.com>,
Ankit Agrawal <ankita@nvidia.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Brett Creeley <brett.creeley@amd.com>,
dri-devel@lists.freedesktop.org,
Eric Auger <eric.auger@redhat.com>,
Eric Farman <farman@linux.ibm.com>,
Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
intel-gfx@lists.freedesktop.org,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Kevin Tian <kevin.tian@intel.com>,
kvm@vger.kernel.org, Kirti Wankhede <kwankhede@nvidia.com>,
linux-s390@vger.kernel.org, Longfang Liu <liulongfang@huawei.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Nikhil Agarwal <nikhil.agarwal@amd.com>,
Nipun Gupta <nipun.gupta@amd.com>,
Peter Oberparleiter <oberpar@linux.ibm.com>,
Halil Pasic <pasic@linux.ibm.com>,
Pranjal Shrivastava <praan@google.com>,
qat-linux@intel.com, Rodrigo Vivi <rodrigo.vivi@intel.com>,
Simona Vetter <simona@ffwll.ch>,
Shameer Kolothum <skolothumtho@nvidia.com>,
Mostafa Saleh <smostafa@google.com>,
Sven Schnelle <svens@linux.ibm.com>,
Tvrtko Ursulin <tursulin@ursulin.net>,
virtualization@lists.linux.dev,
Vineeth Vijayan <vneethv@linux.ibm.com>,
Yishai Hadas <yishaih@nvidia.com>,
Zhenyu Wang <zhenyuw.linux@gmail.com>,
Zhi Wang <zhi.wang.linux@gmail.com>
Cc: patches@lists.linux.dev
Subject: Re: [PATCH 13/22] vfio/gvt: Provide a get_region_info op
Date: Fri, 24 Oct 2025 13:12:28 +0300 [thread overview]
Message-ID: <c30b38456cc11ced5b74d9d38900cf8544a1978e@intel.com> (raw)
In-Reply-To: <13-v1-679a6fa27d31+209-vfio_get_region_info_op_jgg@nvidia.com>
On Thu, 23 Oct 2025, Jason Gunthorpe <jgg@nvidia.com> wrote:
> Move it out of intel_vgpu_ioctl() and re-indent it.
Not a huge deal, but this will conflict with 69b4d367fff6
("drm/i915/gvt: Simplify case switch in intel_vgpu_ioctl") in
drm-intel-next.
BR,
Jani.
>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> drivers/gpu/drm/i915/gvt/kvmgt.c | 301 +++++++++++++++----------------
> 1 file changed, 150 insertions(+), 151 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 69830a5c49d3fd..6b47e33078eb52 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -1140,6 +1140,155 @@ static int intel_vgpu_set_irqs(struct intel_vgpu *vgpu, u32 flags,
> return func(vgpu, index, start, count, flags, data);
> }
>
> +static int intel_vgpu_get_region_info(struct vfio_device *vfio_dev,
> + struct vfio_region_info __user *arg)
> +{
> + struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
> + struct vfio_region_info_cap_sparse_mmap *sparse = NULL;
> + struct intel_vgpu *vgpu = vfio_dev_to_vgpu(vfio_dev);
> + struct vfio_region_info info;
> + unsigned long minsz;
> + int nr_areas = 1;
> + int cap_type_id;
> + unsigned int i;
> + int ret;
> +
> + minsz = offsetofend(struct vfio_region_info, offset);
> +
> + if (copy_from_user(&info, arg, minsz))
> + return -EFAULT;
> +
> + if (info.argsz < minsz)
> + return -EINVAL;
> +
> + switch (info.index) {
> + case VFIO_PCI_CONFIG_REGION_INDEX:
> + info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> + info.size = vgpu->gvt->device_info.cfg_space_size;
> + info.flags = VFIO_REGION_INFO_FLAG_READ |
> + VFIO_REGION_INFO_FLAG_WRITE;
> + break;
> + case VFIO_PCI_BAR0_REGION_INDEX:
> + info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> + info.size = vgpu->cfg_space.bar[info.index].size;
> + if (!info.size) {
> + info.flags = 0;
> + break;
> + }
> +
> + info.flags = VFIO_REGION_INFO_FLAG_READ |
> + VFIO_REGION_INFO_FLAG_WRITE;
> + break;
> + case VFIO_PCI_BAR1_REGION_INDEX:
> + info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> + info.size = 0;
> + info.flags = 0;
> + break;
> + case VFIO_PCI_BAR2_REGION_INDEX:
> + info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> + info.flags = VFIO_REGION_INFO_FLAG_CAPS |
> + VFIO_REGION_INFO_FLAG_MMAP |
> + VFIO_REGION_INFO_FLAG_READ |
> + VFIO_REGION_INFO_FLAG_WRITE;
> + info.size = gvt_aperture_sz(vgpu->gvt);
> +
> + sparse = kzalloc(struct_size(sparse, areas, nr_areas),
> + GFP_KERNEL);
> + if (!sparse)
> + return -ENOMEM;
> +
> + sparse->header.id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
> + sparse->header.version = 1;
> + sparse->nr_areas = nr_areas;
> + cap_type_id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
> + sparse->areas[0].offset =
> + PAGE_ALIGN(vgpu_aperture_offset(vgpu));
> + sparse->areas[0].size = vgpu_aperture_sz(vgpu);
> + break;
> +
> + case VFIO_PCI_BAR3_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
> + info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> + info.size = 0;
> + info.flags = 0;
> +
> + gvt_dbg_core("get region info bar:%d\n", info.index);
> + break;
> +
> + case VFIO_PCI_ROM_REGION_INDEX:
> + case VFIO_PCI_VGA_REGION_INDEX:
> + info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> + info.size = 0;
> + info.flags = 0;
> +
> + gvt_dbg_core("get region info index:%d\n", info.index);
> + break;
> + default: {
> + struct vfio_region_info_cap_type cap_type = {
> + .header.id = VFIO_REGION_INFO_CAP_TYPE,
> + .header.version = 1
> + };
> +
> + if (info.index >= VFIO_PCI_NUM_REGIONS + vgpu->num_regions)
> + return -EINVAL;
> + info.index = array_index_nospec(
> + info.index, VFIO_PCI_NUM_REGIONS + vgpu->num_regions);
> +
> + i = info.index - VFIO_PCI_NUM_REGIONS;
> +
> + info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> + info.size = vgpu->region[i].size;
> + info.flags = vgpu->region[i].flags;
> +
> + cap_type.type = vgpu->region[i].type;
> + cap_type.subtype = vgpu->region[i].subtype;
> +
> + ret = vfio_info_add_capability(&caps, &cap_type.header,
> + sizeof(cap_type));
> + if (ret)
> + return ret;
> + }
> + }
> +
> + if ((info.flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) {
> + switch (cap_type_id) {
> + case VFIO_REGION_INFO_CAP_SPARSE_MMAP:
> + ret = vfio_info_add_capability(
> + &caps, &sparse->header,
> + struct_size(sparse, areas, sparse->nr_areas));
> + if (ret) {
> + kfree(sparse);
> + return ret;
> + }
> + break;
> + default:
> + kfree(sparse);
> + return -EINVAL;
> + }
> + }
> +
> + if (caps.size) {
> + info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
> + if (info.argsz < sizeof(info) + caps.size) {
> + info.argsz = sizeof(info) + caps.size;
> + info.cap_offset = 0;
> + } else {
> + vfio_info_cap_shift(&caps, sizeof(info));
> + if (copy_to_user((void __user *)arg + sizeof(info),
> + caps.buf, caps.size)) {
> + kfree(caps.buf);
> + kfree(sparse);
> + return -EFAULT;
> + }
> + info.cap_offset = sizeof(info);
> + }
> +
> + kfree(caps.buf);
> + }
> +
> + kfree(sparse);
> + return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
> +}
> +
> static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,
> unsigned long arg)
> {
> @@ -1168,157 +1317,6 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,
> return copy_to_user((void __user *)arg, &info, minsz) ?
> -EFAULT : 0;
>
> - } else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
> - struct vfio_region_info info;
> - struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
> - unsigned int i;
> - int ret;
> - struct vfio_region_info_cap_sparse_mmap *sparse = NULL;
> - int nr_areas = 1;
> - int cap_type_id;
> -
> - minsz = offsetofend(struct vfio_region_info, offset);
> -
> - if (copy_from_user(&info, (void __user *)arg, minsz))
> - return -EFAULT;
> -
> - if (info.argsz < minsz)
> - return -EINVAL;
> -
> - switch (info.index) {
> - case VFIO_PCI_CONFIG_REGION_INDEX:
> - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> - info.size = vgpu->gvt->device_info.cfg_space_size;
> - info.flags = VFIO_REGION_INFO_FLAG_READ |
> - VFIO_REGION_INFO_FLAG_WRITE;
> - break;
> - case VFIO_PCI_BAR0_REGION_INDEX:
> - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> - info.size = vgpu->cfg_space.bar[info.index].size;
> - if (!info.size) {
> - info.flags = 0;
> - break;
> - }
> -
> - info.flags = VFIO_REGION_INFO_FLAG_READ |
> - VFIO_REGION_INFO_FLAG_WRITE;
> - break;
> - case VFIO_PCI_BAR1_REGION_INDEX:
> - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> - info.size = 0;
> - info.flags = 0;
> - break;
> - case VFIO_PCI_BAR2_REGION_INDEX:
> - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> - info.flags = VFIO_REGION_INFO_FLAG_CAPS |
> - VFIO_REGION_INFO_FLAG_MMAP |
> - VFIO_REGION_INFO_FLAG_READ |
> - VFIO_REGION_INFO_FLAG_WRITE;
> - info.size = gvt_aperture_sz(vgpu->gvt);
> -
> - sparse = kzalloc(struct_size(sparse, areas, nr_areas),
> - GFP_KERNEL);
> - if (!sparse)
> - return -ENOMEM;
> -
> - sparse->header.id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
> - sparse->header.version = 1;
> - sparse->nr_areas = nr_areas;
> - cap_type_id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
> - sparse->areas[0].offset =
> - PAGE_ALIGN(vgpu_aperture_offset(vgpu));
> - sparse->areas[0].size = vgpu_aperture_sz(vgpu);
> - break;
> -
> - case VFIO_PCI_BAR3_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
> - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> - info.size = 0;
> - info.flags = 0;
> -
> - gvt_dbg_core("get region info bar:%d\n", info.index);
> - break;
> -
> - case VFIO_PCI_ROM_REGION_INDEX:
> - case VFIO_PCI_VGA_REGION_INDEX:
> - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> - info.size = 0;
> - info.flags = 0;
> -
> - gvt_dbg_core("get region info index:%d\n", info.index);
> - break;
> - default:
> - {
> - struct vfio_region_info_cap_type cap_type = {
> - .header.id = VFIO_REGION_INFO_CAP_TYPE,
> - .header.version = 1 };
> -
> - if (info.index >= VFIO_PCI_NUM_REGIONS +
> - vgpu->num_regions)
> - return -EINVAL;
> - info.index =
> - array_index_nospec(info.index,
> - VFIO_PCI_NUM_REGIONS +
> - vgpu->num_regions);
> -
> - i = info.index - VFIO_PCI_NUM_REGIONS;
> -
> - info.offset =
> - VFIO_PCI_INDEX_TO_OFFSET(info.index);
> - info.size = vgpu->region[i].size;
> - info.flags = vgpu->region[i].flags;
> -
> - cap_type.type = vgpu->region[i].type;
> - cap_type.subtype = vgpu->region[i].subtype;
> -
> - ret = vfio_info_add_capability(&caps,
> - &cap_type.header,
> - sizeof(cap_type));
> - if (ret)
> - return ret;
> - }
> - }
> -
> - if ((info.flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) {
> - switch (cap_type_id) {
> - case VFIO_REGION_INFO_CAP_SPARSE_MMAP:
> - ret = vfio_info_add_capability(&caps,
> - &sparse->header,
> - struct_size(sparse, areas,
> - sparse->nr_areas));
> - if (ret) {
> - kfree(sparse);
> - return ret;
> - }
> - break;
> - default:
> - kfree(sparse);
> - return -EINVAL;
> - }
> - }
> -
> - if (caps.size) {
> - info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
> - if (info.argsz < sizeof(info) + caps.size) {
> - info.argsz = sizeof(info) + caps.size;
> - info.cap_offset = 0;
> - } else {
> - vfio_info_cap_shift(&caps, sizeof(info));
> - if (copy_to_user((void __user *)arg +
> - sizeof(info), caps.buf,
> - caps.size)) {
> - kfree(caps.buf);
> - kfree(sparse);
> - return -EFAULT;
> - }
> - info.cap_offset = sizeof(info);
> - }
> -
> - kfree(caps.buf);
> - }
> -
> - kfree(sparse);
> - return copy_to_user((void __user *)arg, &info, minsz) ?
> - -EFAULT : 0;
> } else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) {
> struct vfio_irq_info info;
>
> @@ -1475,6 +1473,7 @@ static const struct vfio_device_ops intel_vgpu_dev_ops = {
> .write = intel_vgpu_write,
> .mmap = intel_vgpu_mmap,
> .ioctl = intel_vgpu_ioctl,
> + .get_region_info = intel_vgpu_get_region_info,
> .dma_unmap = intel_vgpu_dma_unmap,
> .bind_iommufd = vfio_iommufd_emulated_bind,
> .unbind_iommufd = vfio_iommufd_emulated_unbind,
--
Jani Nikula, Intel
next prev parent reply other threads:[~2025-10-24 10:12 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 01/22] vfio: Provide a get_region_info op Jason Gunthorpe
2025-11-03 5:57 ` Pranjal Shrivastava
2025-11-03 14:17 ` Eric Auger
2025-10-23 23:09 ` [PATCH 02/22] vfio/hisi: Convert to the " Jason Gunthorpe
2025-10-28 1:55 ` liulongfang
2025-10-28 7:07 ` Tian, Kevin
2025-11-03 6:06 ` Pranjal Shrivastava
2025-11-03 13:31 ` Jason Gunthorpe
2025-11-07 1:29 ` liulongfang
2025-10-23 23:09 ` [PATCH 03/22] vfio/virtio: " Jason Gunthorpe
2025-11-03 6:21 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 04/22] vfio/nvgrace: " Jason Gunthorpe
2025-11-03 6:41 ` Pranjal Shrivastava
2025-11-03 13:35 ` Ankit Agrawal
2025-10-23 23:09 ` [PATCH 05/22] vfio/pci: Fill in the missing get_region_info ops Jason Gunthorpe
2025-11-03 6:43 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 06/22] vfio/mtty: Provide a get_region_info op Jason Gunthorpe
2025-11-03 7:17 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 07/22] vfio/mdpy: " Jason Gunthorpe
2025-11-03 7:18 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 08/22] vfio/mbochs: " Jason Gunthorpe
2025-11-03 7:19 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 09/22] vfio/platform: " Jason Gunthorpe
2025-11-03 7:14 ` Pranjal Shrivastava
2025-11-03 9:53 ` Mostafa Saleh
2025-11-03 13:59 ` Eric Auger
2025-11-03 14:27 ` Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 10/22] vfio/fsl: " Jason Gunthorpe
2025-11-03 7:30 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 11/22] vfio/cdx: " Jason Gunthorpe
2025-11-03 7:31 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 12/22] vfio/ccw: " Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 13/22] vfio/gvt: " Jason Gunthorpe
2025-10-24 10:12 ` Jani Nikula [this message]
2025-10-23 23:09 ` [PATCH 14/22] vfio: Require drivers to implement get_region_info Jason Gunthorpe
2025-11-03 7:39 ` Pranjal Shrivastava
2025-11-05 20:48 ` Alex Williamson
2025-11-05 20:56 ` Jason Gunthorpe
2025-11-05 21:19 ` Pranjal Shrivastava
2025-11-03 9:55 ` Mostafa Saleh
2025-10-23 23:09 ` [PATCH 15/22] vfio: Add get_region_info_caps op Jason Gunthorpe
2025-11-03 10:16 ` Pranjal Shrivastava
2025-11-03 11:03 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 16/22] vfio/mbochs: Convert mbochs to use vfio_info_add_capability() Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 17/22] vfio/gvt: Convert to get_region_info_caps Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 18/22] vfio/ccw: " Jason Gunthorpe
2025-10-28 7:09 ` Tian, Kevin
2025-10-23 23:09 ` [PATCH 19/22] vfio/pci: Convert all PCI drivers " Jason Gunthorpe
2025-10-28 17:08 ` Brett Creeley
2025-11-03 10:25 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 20/22] vfio/platform: Convert " Jason Gunthorpe
2025-11-03 9:57 ` Mostafa Saleh
2025-11-03 10:21 ` Pranjal Shrivastava
2025-11-03 14:20 ` Eric Auger
2025-11-07 1:05 ` Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 21/22] vfio: Move the remaining drivers " Jason Gunthorpe
2025-11-03 10:29 ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 22/22] vfio: Remove the get_region_info op Jason Gunthorpe
2025-11-03 10:52 ` Pranjal Shrivastava
2025-11-07 0:43 ` Jason Gunthorpe
2025-10-28 7:10 ` [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Tian, Kevin
2025-11-03 9:53 ` Mostafa Saleh
2025-11-05 20:58 ` Alex Williamson
2025-11-06 20:37 ` 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=c30b38456cc11ced5b74d9d38900cf8544a1978e@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=agordeev@linux.ibm.com \
--cc=airlied@gmail.com \
--cc=alex.williamson@redhat.com \
--cc=ankita@nvidia.com \
--cc=borntraeger@linux.ibm.com \
--cc=brett.creeley@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=eric.auger@redhat.com \
--cc=farman@linux.ibm.com \
--cc=giovanni.cabiddu@intel.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jgg@nvidia.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=linux-s390@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=mjrosato@linux.ibm.com \
--cc=nikhil.agarwal@amd.com \
--cc=nipun.gupta@amd.com \
--cc=oberpar@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=patches@lists.linux.dev \
--cc=praan@google.com \
--cc=qat-linux@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=skolothumtho@nvidia.com \
--cc=smostafa@google.com \
--cc=svens@linux.ibm.com \
--cc=tursulin@ursulin.net \
--cc=virtualization@lists.linux.dev \
--cc=vneethv@linux.ibm.com \
--cc=yishaih@nvidia.com \
--cc=zhenyuw.linux@gmail.com \
--cc=zhi.wang.linux@gmail.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