All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ryan Roberts" <ryan.roberts@arm.com>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
	devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
	robh@kernel.org, conor+dt@kernel.org,
	"Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [RFC PATCH v2 15/15] misc/arm-cla: Add vfio-mdev user interface
Date: Thu, 15 Oct 2026 14:49:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-172994@kernel.org> (raw)
In-Reply-To: <20261015142552.4128028-16-ryan.roberts@arm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] sysfs: NULL pointer dereference in cpu_show() during mdev probe
- [Low] kconfig: ARM_CLA_MDEV linkage error when VFIO or KVM are modules
- [Low] char: cla_mdev_ioctl() returns -EINVAL instead of -ENOTTY for unknown ioctls
--

commit dd12438e45e5acb03e5d810526fd148e9b134169
Author: Jean-Philippe Brucker <jpb@kernel.org>

misc/arm-cla: Add vfio-mdev user interface

This commit implements an interface to assign CLA devices to KVM guests
using the VFIO mediated device framework. It sets up the stage-2 MTC for
the assigned VMs and exposes a sysfs interface for device discovery.

> diff --git a/drivers/misc/arm-cla/Kconfig b/drivers/misc/arm-cla/Kconfig
> index f8436a12c1e64..5def727b7a342 100644
> --- a/drivers/misc/arm-cla/Kconfig
> +++ b/drivers/misc/arm-cla/Kconfig
> @@ -8,3 +8,19 @@ config ARM_CLA
>  	  accelerators. It is only accessible from its associated CPU.
>  
>  	  If unsure, say N.
> +
> +config ARM_CLA_MDEV
> +	bool "Mediated device for Arm CLA"
> +	default y
> +	depends on KVM
> +	depends on VFIO

[Severity: Low]
Will this cause linker errors if ARM_CLA is built-in but KVM or VFIO
are built as modules?

Because ARM_CLA_MDEV is a bool depending on tristate symbols (KVM, VFIO),
it evaluates to y even when KVM or VFIO are m. If ARM_CLA=y, cla-mdev.o
is compiled into the kernel. Since cla-mdev.c references module symbols
from vfio and kvm, this can result in undefined reference errors during
the kernel build.

Should the Kconfig dependencies enforce that if ARM_CLA is built-in, its
tristate dependencies must also be built-in?

> diff --git a/drivers/misc/arm-cla/cla-mdev.c b/drivers/misc/arm-cla/cla-mdev.c
> new file mode 100644
> index 0000000000000..66c5dd197542e
> --- /dev/null
> +++ b/drivers/misc/arm-cla/cla-mdev.c

[ ... ]

> +static ssize_t cpu_show(struct device *dev, struct device_attribute *attr,
> +			char *buf)
> +{
> +	struct cla_mdev *mdev = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", mdev->dev->cpu);

[Severity: High]
Can this result in a NULL pointer dereference during device probe?

The cla_mdev_driver defines dev_groups = cla_mdev_sysfs_groups, meaning
the sysfs core creates the cpu file before cla_mdev_probe() is called.
If userspace reads the newly created file concurrently, cpu_show() executes
before the drvdata is set later in cla_mdev_probe():

static int cla_mdev_probe(struct mdev_device *mdev)
{
    ...
    dev_set_drvdata(&mdev->dev, cla_mdev);

This would cause dev_get_drvdata() to return NULL, leading to a crash
when accessing mdev->dev->cpu.

[ ... ]

> +static long cla_mdev_ioctl(struct vfio_device *vdev, unsigned int cmd,
> +			       unsigned long arg)
> +{
> +	struct cla_mdev *mdev =
> +		container_of(vdev, struct cla_mdev, vdev);
> +	unsigned long minsz;
> +
> +	switch (cmd) {
> +	case VFIO_DEVICE_GET_INFO:
> +	{

[ ... ]

> +	}
> +	case VFIO_DEVICE_RESET:
> +		return cla_mdev_reset(mdev);
> +	case VFIO_DEVICE_GET_IRQ_INFO:
> +	case VFIO_DEVICE_SET_IRQS:
> +	default:
> +		return -EINVAL;
> +	}
> +	return -ENOTTY;

[Severity: Low]
Does this ioctl handler incorrectly return -EINVAL instead of -ENOTTY for
unknown commands?

The default case catches all unknown ioctls and returns -EINVAL, which
makes the final return -ENOTTY unreachable. Userspace applications probing
for features often rely on -ENOTTY to properly detect unsupported
commands. Returning -EINVAL could mislead them into thinking the command
is supported but their arguments are invalid.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015142552.4128028-1-ryan.roberts@arm.com?part=15

  reply	other threads:[~2026-10-15 14:49 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 14:25 [RFC PATCH v2 00/15] Arm Core Local Accelerator Driver Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 01/15] misc/arm-cla: Add driver skeleton and documentation Ryan Roberts
2026-10-15 14:35   ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 02/15] misc/arm-cla: Add launch operation helpers Ryan Roberts
2026-10-15 14:42   ` sashiko-bot
2026-10-15 16:17   ` Greg Kroah-Hartman
2026-10-15 16:32     ` Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 03/15] dt-bindings: misc: Add Arm Core Local Accelerator Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 04/15] misc/arm-cla: Probe firmware-described devices Ryan Roberts
2026-10-15 14:37   ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 05/15] misc/arm-cla: Initialize devices on CPU bringup Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 06/15] misc/arm-cla: Accelerator context save and restore Ryan Roberts
2026-10-15 14:41   ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 07/15] misc/arm-cla: Set up memory translation context Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 08/15] misc/arm-cla: Manage domain contexts Ryan Roberts
2026-10-15 14:38   ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 09/15] misc/arm-cla: Add userspace interface Ryan Roberts
2026-10-15 14:47   ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 10/15] KVM: arm64: Introduce support to pin VMIDs Ryan Roberts
2026-10-15 14:38   ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 11/15] KVM: arm64: Export stage-2 MMU config Ryan Roberts
2026-10-15 14:43   ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 12/15] vfio: Support VFIO devices that access the CPU MMU Ryan Roberts
2026-10-15 14:44   ` sashiko-bot
2026-10-15 16:44   ` Jason Gunthorpe
2026-10-15 14:25 ` [RFC PATCH v2 13/15] misc/arm-cla: Add stage-2 MTC and VM context switch Ryan Roberts
2026-10-15 14:40   ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 14/15] misc/arm-cla: Support exclusive context assignment Ryan Roberts
2026-10-15 14:41   ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 15/15] misc/arm-cla: Add vfio-mdev user interface Ryan Roberts
2026-10-15 14:49   ` sashiko-bot [this message]
2026-10-15 16:41   ` 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=sashiko-outbox-172994@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=robh@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.