2024-06-07 19:10:25

by Fred Griffoul

[permalink] [raw]
Subject: [PATCH v3 0/2] vfio/pci: add msi interrupt affinity support

v4:
- export arm64_mismatched_32bit_el0 to compile the vfio driver as
a kernel module on arm64 if CONFIG_CPUSETS is not defined.
- vfio_pci_ioctl_set_irqs(): free the cpumask_var_t only if data_size
is not zero, otherwise it was not allocated.
- vfio_pci_set_msi_trigger(): call the new function
vfio_pci_set_msi_affinity() later, after the DATA_EVENTFD
processing and the vdev index check.

v3:
- add a first patch to export cpuset_cpus_allowed() to be able to
compile the vfio driver as a kernel module.

v2:
- change the ioctl() interface to use a cpu_set_t in vfio_irq_set
'data' to keep the 'start' and 'count' semantic, as suggested by
David Woodhouse <[email protected]>

v1:

The usual way to configure a device interrupt from userland is to write
the /proc/irq/<irq>/smp_affinity or smp_affinity_list files. When using
vfio to implement a device driver or a virtual machine monitor, this may
not be ideal: the process managing the vfio device interrupts may not be
granted root privilege, for security reasons. Thus it cannot directly
control the interrupt affinity and has to rely on an external command.

This patch extends the VFIO_DEVICE_SET_IRQS ioctl() with a new data flag
to specify the affinity of a vfio pci device interrupt.

The affinity argument must be a subset of the process cpuset, otherwise
an error -EPERM is returned.

The vfio_irq_set argument shall be set-up in the following way:

- the 'flags' field have the new flag VFIO_IRQ_SET_DATA_AFFINITY set
as well as VFIO_IRQ_SET_ACTION_TRIGGER.

- the 'start' field is the device interrupt index. Only one interrupt
can be configured per ioctl().

- the variable-length array consists of one or more CPU index
encoded as __u32, the number of entries in the array is specified in the
'count' field.

Fred Griffoul (2):
cgroup/cpuset: export cpuset_cpus_allowed()
vfio/pci: add msi interrupt affinity support

arch/arm64/kernel/cpufeature.c | 1 +
drivers/vfio/pci/vfio_pci_core.c | 26 +++++++++++++++++----
drivers/vfio/pci/vfio_pci_intrs.c | 39 +++++++++++++++++++++++++++++++
drivers/vfio/vfio_main.c | 13 +++++++----
include/uapi/linux/vfio.h | 10 +++++++-
kernel/cgroup/cpuset.c | 1 +
6 files changed, 81 insertions(+), 9 deletions(-)


base-commit: cbb325e77fbe62a06184175aa98c9eb98736c3e8
--
2.40.1



2024-06-07 19:10:59

by Fred Griffoul

[permalink] [raw]
Subject: [PATCH v4 1/2] cgroup/cpuset: export cpuset_cpus_allowed()

A subsequent patch calls cpuset_cpus_allowed() in the vfio driver pci
code. Export the symbol to be able to build the vfio driver as a kernel
module.

This is not enough, however: when CONFIG_CPUSETS is _not_ defined
cpuset_cpus_allowed() is an inline function returning
task_cpu_possible_mask(). For the arm64 architecture this function is
also inline and checks the arm64_mismatched_32bit_el0 static key. We
thus need to export this symbol as well.

Signed-off-by: Fred Griffoul <[email protected]>
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

Signed-off-by: Fred Griffoul <[email protected]>
---
arch/arm64/kernel/cpufeature.c | 1 +
kernel/cgroup/cpuset.c | 1 +
2 files changed, 2 insertions(+)

diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 56583677c1f2..007fddb07039 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -127,6 +127,7 @@ static bool __read_mostly allow_mismatched_32bit_el0;
* seen at least one CPU capable of 32-bit EL0.
*/
DEFINE_STATIC_KEY_FALSE(arm64_mismatched_32bit_el0);
+EXPORT_SYMBOL_GPL(arm64_mismatched_32bit_el0);

/*
* Mask of CPUs supporting 32-bit EL0.
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 4237c8748715..9fd56222aa4b 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -4764,6 +4764,7 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
rcu_read_unlock();
spin_unlock_irqrestore(&callback_lock, flags);
}
+EXPORT_SYMBOL_GPL(cpuset_cpus_allowed);

/**
* cpuset_cpus_allowed_fallback - final fallback before complete catastrophe.
--
2.40.1


2024-06-07 19:11:11

by Fred Griffoul

[permalink] [raw]
Subject: [PATCH v4 2/2] vfio/pci: add msi interrupt affinity support

The usual way to configure a device interrupt from userland is to write
the /proc/irq/<irq>/smp_affinity or smp_affinity_list files. When using
vfio to implement a device driver or a virtual machine monitor, this may
not be ideal: the process managing the vfio device interrupts may not be
granted root privilege, for security reasons. Thus it cannot directly
control the interrupt affinity and has to rely on an external command.

This patch extends the VFIO_DEVICE_SET_IRQS ioctl() with a new data flag
to specify the affinity of interrupts of a vfio pci device.

The CPU affinity mask argument must be a subset of the process cpuset,
otherwise an error -EPERM is returned.

The vfio_irq_set argument shall be set-up in the following way:

- the 'flags' field have the new flag VFIO_IRQ_SET_DATA_AFFINITY set
as well as VFIO_IRQ_SET_ACTION_TRIGGER.

- the variable-length 'data' field is a cpu_set_t structure, as
for the sched_setaffinity() syscall, the size of which is derived
from 'argsz'.

Signed-off-by: Fred Griffoul <[email protected]>
---
drivers/vfio/pci/vfio_pci_core.c | 26 +++++++++++++++++----
drivers/vfio/pci/vfio_pci_intrs.c | 39 +++++++++++++++++++++++++++++++
drivers/vfio/vfio_main.c | 13 +++++++----
include/uapi/linux/vfio.h | 10 +++++++-
4 files changed, 79 insertions(+), 9 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 80cae87fff36..6a3b1ca95acc 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1192,6 +1192,7 @@ static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev,
{
unsigned long minsz = offsetofend(struct vfio_irq_set, count);
struct vfio_irq_set hdr;
+ cpumask_var_t mask;
u8 *data = NULL;
int max, ret = 0;
size_t data_size = 0;
@@ -1207,9 +1208,21 @@ static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev,
return ret;

if (data_size) {
- data = memdup_user(&arg->data, data_size);
- if (IS_ERR(data))
- return PTR_ERR(data);
+ if (hdr.flags & VFIO_IRQ_SET_DATA_AFFINITY) {
+ if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
+ return -ENOMEM;
+
+ ret = copy_from_user(mask, &arg->data, data_size);
+ if (ret)
+ goto out;
+
+ data = (u8 *)mask;
+
+ } else {
+ data = memdup_user(&arg->data, data_size);
+ if (IS_ERR(data))
+ return PTR_ERR(data);
+ }
}

mutex_lock(&vdev->igate);
@@ -1218,7 +1231,12 @@ static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev,
hdr.count, data);

mutex_unlock(&vdev->igate);
- kfree(data);
+
+out:
+ if (hdr.flags & VFIO_IRQ_SET_DATA_AFFINITY && data_size)
+ free_cpumask_var(mask);
+ else
+ kfree(data);

return ret;
}
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index 8382c5834335..fe01303cf94e 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -19,6 +19,7 @@
#include <linux/vfio.h>
#include <linux/wait.h>
#include <linux/slab.h>
+#include <linux/cpuset.h>

#include "vfio_pci_priv.h"

@@ -675,6 +676,41 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev,
return 0;
}

+static int vfio_pci_set_msi_affinity(struct vfio_pci_core_device *vdev,
+ unsigned int start, unsigned int count,
+ struct cpumask *irq_mask)
+{
+ struct vfio_pci_irq_ctx *ctx;
+ cpumask_var_t allowed_mask;
+ unsigned int i;
+ int err = 0;
+
+ if (!alloc_cpumask_var(&allowed_mask, GFP_KERNEL))
+ return -ENOMEM;
+
+ cpuset_cpus_allowed(current, allowed_mask);
+ if (!cpumask_subset(irq_mask, allowed_mask)) {
+ err = -EPERM;
+ goto finish;
+ }
+
+ for (i = start; i < start + count; i++) {
+ ctx = vfio_irq_ctx_get(vdev, i);
+ if (!ctx) {
+ err = -EINVAL;
+ break;
+ }
+
+ err = irq_set_affinity(ctx->producer.irq, irq_mask);
+ if (err)
+ break;
+ }
+
+finish:
+ free_cpumask_var(allowed_mask);
+ return err;
+}
+
static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev,
unsigned index, unsigned start,
unsigned count, uint32_t flags, void *data)
@@ -713,6 +749,9 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev,
if (!irq_is(vdev, index))
return -EINVAL;

+ if (flags & VFIO_IRQ_SET_DATA_AFFINITY)
+ return vfio_pci_set_msi_affinity(vdev, start, count, data);
+
for (i = start; i < start + count; i++) {
ctx = vfio_irq_ctx_get(vdev, i);
if (!ctx)
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index e97d796a54fb..e87131d45059 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -1505,23 +1505,28 @@ int vfio_set_irqs_validate_and_prepare(struct vfio_irq_set *hdr, int num_irqs,
size = 0;
break;
case VFIO_IRQ_SET_DATA_BOOL:
- size = sizeof(uint8_t);
+ size = hdr->count * sizeof(uint8_t);
break;
case VFIO_IRQ_SET_DATA_EVENTFD:
- size = sizeof(int32_t);
+ size = hdr->count * sizeof(int32_t);
+ break;
+ case VFIO_IRQ_SET_DATA_AFFINITY:
+ size = hdr->argsz - minsz;
+ if (size > cpumask_size())
+ size = cpumask_size();
break;
default:
return -EINVAL;
}

if (size) {
- if (hdr->argsz - minsz < hdr->count * size)
+ if (hdr->argsz - minsz < size)
return -EINVAL;

if (!data_size)
return -EINVAL;

- *data_size = hdr->count * size;
+ *data_size = size;
}

return 0;
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index 2b68e6cdf190..5ba2ca223550 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -580,6 +580,12 @@ struct vfio_irq_info {
*
* Note that ACTION_[UN]MASK specify user->kernel signaling (irqfds) while
* ACTION_TRIGGER specifies kernel->user signaling.
+ *
+ * DATA_AFFINITY specifies the affinity for the range of interrupt vectors.
+ * It must be set with ACTION_TRIGGER in 'flags'. The variable-length 'data'
+ * array is a CPU affinity mask 'cpu_set_t' structure, as for the
+ * sched_setaffinity() syscall argument: the 'argsz' field is used to check
+ * the actual cpu_set_t size.
*/
struct vfio_irq_set {
__u32 argsz;
@@ -587,6 +593,7 @@ struct vfio_irq_set {
#define VFIO_IRQ_SET_DATA_NONE (1 << 0) /* Data not present */
#define VFIO_IRQ_SET_DATA_BOOL (1 << 1) /* Data is bool (u8) */
#define VFIO_IRQ_SET_DATA_EVENTFD (1 << 2) /* Data is eventfd (s32) */
+#define VFIO_IRQ_SET_DATA_AFFINITY (1 << 6) /* Data is cpu_set_t */
#define VFIO_IRQ_SET_ACTION_MASK (1 << 3) /* Mask interrupt */
#define VFIO_IRQ_SET_ACTION_UNMASK (1 << 4) /* Unmask interrupt */
#define VFIO_IRQ_SET_ACTION_TRIGGER (1 << 5) /* Trigger interrupt */
@@ -599,7 +606,8 @@ struct vfio_irq_set {

#define VFIO_IRQ_SET_DATA_TYPE_MASK (VFIO_IRQ_SET_DATA_NONE | \
VFIO_IRQ_SET_DATA_BOOL | \
- VFIO_IRQ_SET_DATA_EVENTFD)
+ VFIO_IRQ_SET_DATA_EVENTFD | \
+ VFIO_IRQ_SET_DATA_AFFINITY)
#define VFIO_IRQ_SET_ACTION_TYPE_MASK (VFIO_IRQ_SET_ACTION_MASK | \
VFIO_IRQ_SET_ACTION_UNMASK | \
VFIO_IRQ_SET_ACTION_TRIGGER)
--
2.40.1


2024-06-09 15:30:15

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] vfio/pci: add msi interrupt affinity support

Hi Fred,

kernel test robot noticed the following build warnings:

url: https://github.com/intel-lab-lkp/linux/commits/Fred-Griffoul/cgroup-cpuset-export-cpuset_cpus_allowed/20240608-031332
base: cbb325e77fbe62a06184175aa98c9eb98736c3e8
patch link: https://lore.kernel.org/r/20240607190955.15376-3-fgriffo%40amazon.co.uk
patch subject: [PATCH v4 2/2] vfio/pci: add msi interrupt affinity support
config: mips-randconfig-r081-20240609 (https://download.01.org/0day-ci/archive/20240609/[email protected]/config)
compiler: mips-linux-gcc (GCC) 13.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

New smatch warnings:
drivers/vfio/pci/vfio_pci_core.c:1241 vfio_pci_ioctl_set_irqs() warn: maybe return -EFAULT instead of the bytes remaining?

vim +1241 drivers/vfio/pci/vfio_pci_core.c

2ecf3b58ed7bc5 drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1190 static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev,
663eab456e072b drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1191 struct vfio_irq_set __user *arg)
2ecf3b58ed7bc5 drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1192 {
2ecf3b58ed7bc5 drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1193 unsigned long minsz = offsetofend(struct vfio_irq_set, count);
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1194 struct vfio_irq_set hdr;
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1195 cpumask_var_t mask;
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1196 u8 *data = NULL;
05692d7005a364 drivers/vfio/pci/vfio_pci.c Vlad Tsyrklevich 2016-10-12 1197 int max, ret = 0;
ef198aaa169c61 drivers/vfio/pci/vfio_pci.c Kirti Wankhede 2016-11-17 1198 size_t data_size = 0;
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1199
663eab456e072b drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1200 if (copy_from_user(&hdr, arg, minsz))
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1201 return -EFAULT;
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1202
05692d7005a364 drivers/vfio/pci/vfio_pci.c Vlad Tsyrklevich 2016-10-12 1203 max = vfio_pci_get_irq_count(vdev, hdr.index);
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1204
ea3fc04d4fad2d drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1205 ret = vfio_set_irqs_validate_and_prepare(&hdr, max, VFIO_PCI_NUM_IRQS,
ea3fc04d4fad2d drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1206 &data_size);
ef198aaa169c61 drivers/vfio/pci/vfio_pci.c Kirti Wankhede 2016-11-17 1207 if (ret)
ef198aaa169c61 drivers/vfio/pci/vfio_pci.c Kirti Wankhede 2016-11-17 1208 return ret;
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1209
ef198aaa169c61 drivers/vfio/pci/vfio_pci.c Kirti Wankhede 2016-11-17 1210 if (data_size) {
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1211 if (hdr.flags & VFIO_IRQ_SET_DATA_AFFINITY) {
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1212 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1213 return -ENOMEM;
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1214
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1215 ret = copy_from_user(mask, &arg->data, data_size);

copy_from_user() returns the number of bytes remaining to be copied.
This should be:

if (copy_from_user(mask, &arg->data, data_size)) {
ret = -EFAULT;
goto out;
}

66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1216 if (ret)
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1217 goto out;
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1218
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1219 data = (u8 *)mask;
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1220
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1221 } else {
663eab456e072b drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1222 data = memdup_user(&arg->data, data_size);
3a1f7041ddd59e drivers/vfio/pci/vfio_pci.c Fengguang Wu 2012-12-07 1223 if (IS_ERR(data))
3a1f7041ddd59e drivers/vfio/pci/vfio_pci.c Fengguang Wu 2012-12-07 1224 return PTR_ERR(data);
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1225 }
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1226 }
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1227
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1228 mutex_lock(&vdev->igate);
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1229
ea3fc04d4fad2d drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1230 ret = vfio_pci_set_irqs_ioctl(vdev, hdr.flags, hdr.index, hdr.start,
ea3fc04d4fad2d drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1231 hdr.count, data);
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1232
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1233 mutex_unlock(&vdev->igate);
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1234
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1235 out:
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1236 if (hdr.flags & VFIO_IRQ_SET_DATA_AFFINITY && data_size)
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1237 free_cpumask_var(mask);
66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1238 else
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1239 kfree(data);
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1240
89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 @1241 return ret;
2ecf3b58ed7bc5 drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1242 }

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


2024-06-09 15:33:28

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] vfio/pci: add msi interrupt affinity support

On Fri, Jun 07, 2024 at 07:09:49PM +0000, Fred Griffoul wrote:
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index e97d796a54fb..e87131d45059 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -1505,23 +1505,28 @@ int vfio_set_irqs_validate_and_prepare(struct vfio_irq_set *hdr, int num_irqs,
> size = 0;
> break;
> case VFIO_IRQ_SET_DATA_BOOL:
> - size = sizeof(uint8_t);
> + size = hdr->count * sizeof(uint8_t);
> break;
> case VFIO_IRQ_SET_DATA_EVENTFD:
> - size = sizeof(int32_t);
> + size = hdr->count * sizeof(int32_t);

Not related to your patch, but this multiply can integer overflow on
32bit systems. Better to use size_mul().

regards,
dan carpenter

> + break;
> + case VFIO_IRQ_SET_DATA_AFFINITY:
> + size = hdr->argsz - minsz;
> + if (size > cpumask_size())
> + size = cpumask_size();
> break;
> default:
> return -EINVAL;
> }
>
> if (size) {
> - if (hdr->argsz - minsz < hdr->count * size)
> + if (hdr->argsz - minsz < size)
> return -EINVAL;
>
> if (!data_size)
> return -EINVAL;
>
> - *data_size = hdr->count * size;
> + *data_size = size;
> }
>
> return 0;


2024-06-10 04:00:00

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] vfio/pci: add msi interrupt affinity support

Hi Fred,

kernel test robot noticed the following build errors:

[auto build test ERROR on cbb325e77fbe62a06184175aa98c9eb98736c3e8]

url: https://github.com/intel-lab-lkp/linux/commits/Fred-Griffoul/cgroup-cpuset-export-cpuset_cpus_allowed/20240608-031332
base: cbb325e77fbe62a06184175aa98c9eb98736c3e8
patch link: https://lore.kernel.org/r/20240607190955.15376-3-fgriffo%40amazon.co.uk
patch subject: [PATCH v4 2/2] vfio/pci: add msi interrupt affinity support
config: arm64-randconfig-001-20240610 (https://download.01.org/0day-ci/archive/20240610/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240610/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8192-imp_iic_wrap.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8192-ipe.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8192-mfg.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8192-mm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8192-msdc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8192-scp_adsp.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8192-vdec.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8365-apmixedsys.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8365.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8365-apu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8365-mm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/mediatek/clk-mt8365-venc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/meson/a1-peripherals.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sunxi-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/suniv-f1c100s-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun20i-d1-r-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun50i-a64-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun50i-a100-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun50i-h6-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun50i-h6-r-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun50i-h616-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun4i-a10-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun8i-a23-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun8i-a83t-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun8i-h3-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun8i-r40-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun8i-v3s-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun9i-a80-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun9i-a80-de-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/sunxi-ng/sun9i-a80-usb-ccu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/versatile/clk-vexpress-osc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/qcom/clk-qcom.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/qcom/gcc-msm8976.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/qcom/videocc-sdm845.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/dma/ti/omap-dma.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/dma/dmatest.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/soc/imx/soc-imx8m.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/soc/amlogic/meson-clk-measure.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pmdomain/amlogic/meson-gx-pwrc-vpu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/xen/xenbus/xenbus_probe_frontend.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/xen/xen-pciback/xen-pciback.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/xen/xen-privcmd.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/regulator/da9121-regulator.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/regulator/max20411-regulator.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/reset/hisilicon/hi6220_reset.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/hw_random/omap-rng.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/hw_random/cavium-rng.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/hw_random/cavium-rng-vf.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/lp.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-slimbus.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-spmi.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-w1.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/misc/fastrpc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mfd/timberdale.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mfd/vexpress-sysreg.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mfd/rt4831.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mfd/qcom-pm8008.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/dax/device_dax.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/dax/dax_cxl.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/cxl/core/cxl_core.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/cxl/cxl_pci.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/cxl/cxl_port.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/scsi/scsi_common.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvme/host/nvme-apple.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/cdrom/cdrom.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/auxdisplay/charlcd.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/auxdisplay/hd44780_common.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/i2c/busses/i2c-ccgx-ucsi.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/i2c/busses/i2c-ali1563.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/i2c/busses/i2c-qup.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/tuners/tda9887.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/rc/rc-core.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/v4l2-core/v4l2-async.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/v4l2-core/v4l2-fwnode.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/media/radio/si470x/radio-si470x-common.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/core/pwrseq_emmc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mmc/host/renesas_sdhi_core.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/ufs/host/ufs-qcom.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/leds/flash/leds-rt4505.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/firmware/meson/meson_sm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/crypto/xilinx/zynqmp-aes-gcm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/crypto/intel/keembay/keembay-ocs-hcu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_performance.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_userspace.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/perf/marvell_cn10k_ddr_pmu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/perf/arm_cspmu/arm_cspmu_module.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/perf/arm_cspmu/nvidia_cspmu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/perf/cxl_pmu.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/interconnect/imx/imx8mm-interconnect.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/interconnect/imx/imx8mq-interconnect.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/interconnect/imx/imx8mp-interconnect.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/parport/parport.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/spmi/spmi-pmic-arb.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/greybus/greybus.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/iio/adc/ingenic-adc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/iio/buffer/kfifo_buf.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-core.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-hub.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-gpio.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-scom.o
>> ERROR: modpost: "system_32bit_el0_cpumask" [drivers/vfio/pci/vfio-pci-core.ko] undefined!

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

2024-06-10 08:22:01

by Frederic Griffoul

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] vfio/pci: add msi interrupt affinity support

Pff. Thanks Dan,

I will post a v5 to address the two issues you mentioned.

Br,

Fred

On Sun, Jun 9, 2024 at 4:29 PM Dan Carpenter <[email protected]> wrote:
>
> Hi Fred,
>
> kernel test robot noticed the following build warnings:
>
> url: https://github.com/intel-lab-lkp/linux/commits/Fred-Griffoul/cgroup-cpuset-export-cpuset_cpus_allowed/20240608-031332
> base: cbb325e77fbe62a06184175aa98c9eb98736c3e8
> patch link: https://lore.kernel.org/r/20240607190955.15376-3-fgriffo%40amazon.co.uk
> patch subject: [PATCH v4 2/2] vfio/pci: add msi interrupt affinity support
> config: mips-randconfig-r081-20240609 (https://download.01.org/0day-ci/archive/20240609/[email protected]/config)
> compiler: mips-linux-gcc (GCC) 13.2.0
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <[email protected]>
> | Reported-by: Dan Carpenter <[email protected]>
> | Closes: https://lore.kernel.org/r/[email protected]/
>
> New smatch warnings:
> drivers/vfio/pci/vfio_pci_core.c:1241 vfio_pci_ioctl_set_irqs() warn: maybe return -EFAULT instead of the bytes remaining?
>
> vim +1241 drivers/vfio/pci/vfio_pci_core.c
>
> 2ecf3b58ed7bc5 drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1190 static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev,
> 663eab456e072b drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1191 struct vfio_irq_set __user *arg)
> 2ecf3b58ed7bc5 drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1192 {
> 2ecf3b58ed7bc5 drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1193 unsigned long minsz = offsetofend(struct vfio_irq_set, count);
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1194 struct vfio_irq_set hdr;
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1195 cpumask_var_t mask;
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1196 u8 *data = NULL;
> 05692d7005a364 drivers/vfio/pci/vfio_pci.c Vlad Tsyrklevich 2016-10-12 1197 int max, ret = 0;
> ef198aaa169c61 drivers/vfio/pci/vfio_pci.c Kirti Wankhede 2016-11-17 1198 size_t data_size = 0;
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1199
> 663eab456e072b drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1200 if (copy_from_user(&hdr, arg, minsz))
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1201 return -EFAULT;
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1202
> 05692d7005a364 drivers/vfio/pci/vfio_pci.c Vlad Tsyrklevich 2016-10-12 1203 max = vfio_pci_get_irq_count(vdev, hdr.index);
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1204
> ea3fc04d4fad2d drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1205 ret = vfio_set_irqs_validate_and_prepare(&hdr, max, VFIO_PCI_NUM_IRQS,
> ea3fc04d4fad2d drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1206 &data_size);
> ef198aaa169c61 drivers/vfio/pci/vfio_pci.c Kirti Wankhede 2016-11-17 1207 if (ret)
> ef198aaa169c61 drivers/vfio/pci/vfio_pci.c Kirti Wankhede 2016-11-17 1208 return ret;
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1209
> ef198aaa169c61 drivers/vfio/pci/vfio_pci.c Kirti Wankhede 2016-11-17 1210 if (data_size) {
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1211 if (hdr.flags & VFIO_IRQ_SET_DATA_AFFINITY) {
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1212 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1213 return -ENOMEM;
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1214
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1215 ret = copy_from_user(mask, &arg->data, data_size);
>
> copy_from_user() returns the number of bytes remaining to be copied.
> This should be:
>
> if (copy_from_user(mask, &arg->data, data_size)) {
> ret = -EFAULT;
> goto out;
> }
>
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1216 if (ret)
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1217 goto out;
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1218
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1219 data = (u8 *)mask;
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1220
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1221 } else {
> 663eab456e072b drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1222 data = memdup_user(&arg->data, data_size);
> 3a1f7041ddd59e drivers/vfio/pci/vfio_pci.c Fengguang Wu 2012-12-07 1223 if (IS_ERR(data))
> 3a1f7041ddd59e drivers/vfio/pci/vfio_pci.c Fengguang Wu 2012-12-07 1224 return PTR_ERR(data);
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1225 }
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1226 }
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1227
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1228 mutex_lock(&vdev->igate);
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1229
> ea3fc04d4fad2d drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1230 ret = vfio_pci_set_irqs_ioctl(vdev, hdr.flags, hdr.index, hdr.start,
> ea3fc04d4fad2d drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1231 hdr.count, data);
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1232
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1233 mutex_unlock(&vdev->igate);
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1234
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1235 out:
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1236 if (hdr.flags & VFIO_IRQ_SET_DATA_AFFINITY && data_size)
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1237 free_cpumask_var(mask);
> 66c926fb7b2507 drivers/vfio/pci/vfio_pci_core.c Fred Griffoul 2024-06-07 1238 else
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1239 kfree(data);
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 1240
> 89e1f7d4c66d85 drivers/vfio/pci/vfio_pci.c Alex Williamson 2012-07-31 @1241 return ret;
> 2ecf3b58ed7bc5 drivers/vfio/pci/vfio_pci_core.c Jason Gunthorpe 2022-08-31 1242 }
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
>