[PATCH 03/21] drm/xe/eudebug: Introduce eudebug support

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Mon Aug 12 12:02:29 UTC 2024


On Fri, Jul 26, 2024 at 05:08:00PM +0300, Mika Kuoppala wrote:

<cut>

> +static long xe_eudebug_read_event(struct xe_eudebug *d,
> +				  const u64 arg,
> +				  const bool wait)
> +{
> +	struct xe_device *xe = d->xe;
> +	struct drm_xe_eudebug_event __user * const user_orig =
> +		u64_to_user_ptr(arg);
> +	struct drm_xe_eudebug_event user_event;
> +	struct xe_eudebug_event *event;
> +	long ret = 0;
> +
> +	if (XE_IOCTL_DBG(xe, copy_from_user(&user_event, user_orig, sizeof(user_event))))
> +		return -EFAULT;
> +
> +	if (XE_IOCTL_DBG(xe, !user_event.type))
> +		return -EINVAL;
> +
> +	if (XE_IOCTL_DBG(xe, user_event.type > DRM_XE_EUDEBUG_EVENT_MAX_EVENT))
> +		return -EINVAL;
> +
> +	if (XE_IOCTL_DBG(xe, user_event.type != DRM_XE_EUDEBUG_EVENT_READ))
> +		return -EINVAL;
> +
> +	if (XE_IOCTL_DBG(xe, user_event.len < sizeof(*user_orig)))
> +		return -EINVAL;
> +
> +	if (XE_IOCTL_DBG(xe, user_event.flags))
> +		return -EINVAL;
> +
> +	if (XE_IOCTL_DBG(xe, user_event.reserved))
> +		return -EINVAL;
> +
> +	/* XXX: define wait time in connect arguments ? */
> +	if (wait) {
> +		ret = wait_event_interruptible_timeout(d->events.write_done,
> +						       event_fifo_has_events(d),
> +						       msecs_to_jiffies(5 * 1000));
> +
> +		if (XE_IOCTL_DBG(xe, ret < 0))
> +			return ret;
> +	}
> +
> +	ret = 0;
> +	spin_lock(&d->events.lock);
> +	event = event_fifo_pending(d);
> +	if (event) {
> +		if (user_event.len < event->len) {
> +			ret = -EMSGSIZE;

Maybe it is worth to copy event->len to user_orig? I wonder how
userspace guesses the size of the buffer to allocate for the event.

--
Zbigniew



More information about the Intel-xe mailing list