drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling
PATCH v2 1/1 drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling
Add error handling for the following VFIO_DEVICE_SET_IRQS cases with respect to the hdr struct:
- More than one VFIO_IRQ_DATA_TYPE_MASK flag is set in hdr.flags
- More than one VFIO_IRQ_ACTION_TYPE_MASK flag is set in hdr.flags
- hdr.count is not specified
Note that since hdr.count != 0, data_size != 0 is guaranteed unless vfio_set_irqs_validate_and_prepare fails and returns an error. So, we no longer need to check data_size before running memdup_user because checking the return value of the function is sufficient.
v2: Use correct name for mask
--- drivers/gpu/drm/i915/gvt/kvmgt.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/gvt/kvmgt.c +12 -6
@@ -1361,21 +1361,27 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; +if (hweight32 (hdr.flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) !=1 || +hweight32 (hdr.flags &VFIO_IRQ_SET_ACTION_TYPE_MASK ) !=1 ) +return -EINVAL ; +if (!(hdr.flags &VFIO_IRQ_SET_DATA_NONE )) {int max =intel_vgpu_get_irq_count (vgpu, hdr.index); +if (!hdr.count) +return -EINVAL ; + ret =vfio_set_irqs_validate_and_prepare (&hdr, max,VFIO_PCI_NUM_IRQS , &data_size);if (ret) {gvt_vgpu_err ("intel:vfio_set_irqs_validate_and_prepare failed\n" );return -EINVAL ; } -if (data_size) { - data =memdup_user ((void __user *)(arg + minsz), - data_size); -if (IS_ERR (data)) -return PTR_ERR (data); - } + + data =memdup_user ((void __user *)(arg + minsz), + data_size); +if (IS_ERR (data)) +return PTR_ERR (data); } ret = intel_vgpu_set_irqs(vgpu, hdr.flags, hdr.index,
Signature · 1 line
2.43.0
Patchwork
CI✗ i915.CI.BAT: failure for drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling (rev2)
== Series Details ==
== Series Details ==
Series: drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling (rev2)
URL : https://patchwork.freedesktop.org/series/154798/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_17244 -> Patchwork_154798v2
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with Patchwork_154798v2 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes
introduced in Patchwork_154798v2, please notify your bug team ([email protected]) to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/index.html
Participating hosts (43 -> 42)
------------------------------
Missing (1): fi-snb-2520m
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in Patchwork_154798v2:
### IGT changes ###
#### Possible regressions ####
* igt@i915_selftest@live@objects:
- bat-arlh-3: [PASS][1] -> [INCOMPLETE][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_17244/bat-arlh-3/igt@i915_selftest@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/bat-arlh-3/igt@i915_selftest@[email protected]
Known issues
------------
Here are the changes found in Patchwork_154798v2 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@i915_selftest@live@requests:
- bat-atsm-1: [PASS][3] -> [INCOMPLETE][4] ([i915#14564])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_17244/bat-atsm-1/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/bat-atsm-1/igt@i915_selftest@[email protected]
#### Possible fixes ####
* igt@i915_selftest@live@guc_multi_lrc:
- bat-dg2-8: [ABORT][5] ([i915#14201]) -> [PASS][6] +1 other test pass
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_17244/bat-dg2-8/igt@i915_selftest@live@guc_multi_lrc.html
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/bat-dg2-8/igt@i915_selftest@live@guc_multi_lrc.html
* igt@i915_selftest@live@workarounds:
- bat-arlh-3: [DMESG-FAIL][7] ([i915#12061]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_17244/bat-arlh-3/igt@i915_selftest@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/bat-arlh-3/igt@i915_selftest@[email protected]
- bat-arls-5: [DMESG-FAIL][9] ([i915#12061]) -> [PASS][10] +1 other test pass
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_17244/bat-arls-5/igt@i915_selftest@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/bat-arls-5/igt@i915_selftest@[email protected]
- bat-dg2-11: [DMESG-FAIL][11] ([i915#12061]) -> [PASS][12] +1 other test pass
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_17244/bat-dg2-11/igt@i915_selftest@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/bat-dg2-11/igt@i915_selftest@[email protected]
#### Warnings ####
* igt@i915_selftest@live:
- bat-arlh-3: [DMESG-FAIL][13] ([i915#12061]) -> [INCOMPLETE][14] ([i915#14764] / [i915#14837])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_17244/bat-arlh-3/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/bat-arlh-3/igt@[email protected]
- bat-atsm-1: [DMESG-FAIL][15] ([i915#12061] / [i915#13929]) -> [INCOMPLETE][16] ([i915#12061] / [i915#14564])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_17244/bat-atsm-1/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/bat-atsm-1/igt@[email protected]
[i915#12061]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/12061
[i915#13929]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13929
[i915#14201]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14201
[i915#14564]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14564
[i915#14764]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14764
[i915#14837]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14837
Build changes
-------------
* Linux: CI_DRM_17244 -> Patchwork_154798v2
CI-20190529: 20190529
CI_DRM_17244: 6279a928fb7ed7a69e44171637abf2bf50668a9c @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_8544: b7d758d47000f2092226f4bf68e9299883cf02de @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_154798v2: 6279a928fb7ed7a69e44171637abf2bf50668a9c @ git://anongit.freedesktop.org/gfx-ci/linux
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_154798v2/index.html
Quoted 25 lines · Jonathan Cavitt
Add error handling for the following
VFIO_DEVICE_SET_IRQScases with respect to the hdr struct:- More than one
VFIO_IRQ_DATA_TYPE_MASKflag is set in hdr.flags
- More than oneVFIO_IRQ_ACTION_TYPE_MASKflag is set in hdr.flags
- hdr.count is not specifiedNote that since hdr.count != 0,
data_size!= 0 is guaranteed unlessvfio_set_irqs_validate_and_preparefails and returns an error. So, we no longer need to checkdata_sizebefore runningmemdup_userbecause checking the return value of the function is sufficient.v2: Use correct name for mask
Signed-off-by Jonathan Cavitt <[email protected]>Cc Andi Shyti <[email protected]>--- drivers/gpu/drm/i915/gvt/kvmgt.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0
drivers/gpu/drm/i915/gvt/kvmgt.c static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd, · line 1367
Quoted 7 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +4
-0@@ -1361,21 +1361,27 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; +if (hweight32 (hdr.flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) !=1 || +hweight32 (hdr.flags &VFIO_IRQ_SET_ACTION_TYPE_MASK ) !=1 ) +return -EINVAL ; +
Possible to move this into general vfio code? Clearly vfio can't set mutiple types of data or action on same series of data, so maybe good to check in general. But enough for gvt of coz.
Quoted 29 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +8
-6if (!(hdr.flags &VFIO_IRQ_SET_DATA_NONE )) {int max =intel_vgpu_get_irq_count (vgpu, hdr.index); +if (!hdr.count) +return -EINVAL ; + ret =vfio_set_irqs_validate_and_prepare (&hdr, max,VFIO_PCI_NUM_IRQS , &data_size);if (ret) {gvt_vgpu_err ("intel:vfio_set_irqs_validate_and_prepare failed\n" );return -EINVAL ; } -if (data_size) { - data =memdup_user ((void __user *)(arg + minsz), - data_size); -if (IS_ERR (data)) -return PTR_ERR (data); - } + + data =memdup_user ((void __user *)(arg + minsz), + data_size); +if (IS_ERR (data)) +return PTR_ERR (data); } ret = intel_vgpu_set_irqs(vgpu, hdr.flags, hdr.index,Signature · 1 line
2.43.0
Hi Jonathan,
...
drivers/gpu/drm/i915/gvt/kvmgt.c static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd, · line 1365
Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +2
-0@@ -1361,21 +1361,27 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; +if (hweight32 (hdr.flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) !=1 || +hweight32 (hdr.flags &VFIO_IRQ_SET_ACTION_TYPE_MASK ) !=1 )
How about using:
if (!is_power_of_2(...) ||
!is_power_of_2(...))The rest looks good.
Andi
Quoted 1 line
(quoted diff) +1
-0+ return -EINVAL;
-----Original Message-----
From: Andi Shyti <[email protected]>
Sent: Tuesday, September 23, 2025 2:00 PM
To: Cavitt, Jonathan <[email protected]>
Cc: [email protected]; Gupta, saurabhg <[email protected]>; Zuo, Alex <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling
Quoted 14 lines
Hi Jonathan,
...
drivers/gpu/drm/i915/gvt/kvmgt.c static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd, · line 1365
Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +2
-0@@ -1361,21 +1361,27 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; +if (hweight32 (hdr.flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) !=1 || +hweight32 (hdr.flags &VFIO_IRQ_SET_ACTION_TYPE_MASK ) !=1 )How about using:
Quoted 4 lines
if (!is_power_of_2(...) || !is_power_of_2(...))The rest looks good.
Hmm... Yeah, looking at it, that does seem a bit more efficient than what I have here. I don't know if it's worth spinning another revision of the patch over, though. Perhaps if it's considered worthwhile enough we could just add it in at merge time?
Thoughts?
-Jonathan Cavitt
Quoted 5 lines
Andi
Quoted 1 line
(quoted diff) +1
-0+ return -EINVAL;
-----Original Message-----
From: Cavitt, Jonathan
Sent: Tuesday, September 23, 2025 2:11 PM
To: Andi Shyti <[email protected]>
Cc: [email protected]; Gupta, saurabhg <[email protected]>; Zuo, Alex <[email protected]>; [email protected]
Subject: RE: [PATCH v2] drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling
Quoted 26 lines
-----Original Message-----
From: Andi Shyti <[email protected]>
Sent: Tuesday, September 23, 2025 2:00 PM
To: Cavitt, Jonathan <[email protected]>
Cc: [email protected]; Gupta, saurabhg <[email protected]>; Zuo, Alex <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/i915/gvt: Improveintel_vgpu_ioctlhdr error handlingQuoted 14 lines
Hi Jonathan,
...
drivers/gpu/drm/i915/gvt/kvmgt.c static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd, · line 1365
Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +2
-0@@ -1361,21 +1361,27 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; +if (hweight32 (hdr.flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) !=1 || +hweight32 (hdr.flags &VFIO_IRQ_SET_ACTION_TYPE_MASK ) !=1 )How about using:
Quoted 4 lines
if (!is_power_of_2(...) || !is_power_of_2(...))The rest looks good.
Quoted 7 lines
Hmm... Yeah, looking at it, that does seem a bit more efficient than what I have here. I don't know if it's worth spinning another revision of the patch over, though. Perhaps if it's considered worthwhile enough we could just add it in at merge time?
Thoughts?
-Jonathan Cavitt
EDIT: Never mind. I'll send a new revision anyways: it's easy enough for me to accomplish regardless, and the suggestion is just more efficient than what was being used prior.
-Jonathan Cavitt
Quoted 7 lines
Quoted 6 lines
Andi
Quoted 1 line
(quoted diff) +1
-0+ return -EINVAL;