drm-core: a driver ioctl matches its number in any direction, as in Linux #19

Merged
toasterson merged 2 commits from x230-driver-ioctl-direction into main 2026-10-05 18:55:48 +00:00
Owner

Driver-private commands matched an entry by value, or by group, number and direction with another size. Linux's drm_ioctl() indexes the driver's table by number and copies the argument in the directions both commands have, and drivers rely on that: i915 lists only DRM_IOCTL_I915_GEM_EXECBUFFER2_WR (_IOWR), while Mesa's crocus and iris submit every batch with DRM_IOCTL_I915_GEM_EXECBUFFER2 (_IOW, the same number).

On a ThinkPad X230 (HD 4000) with i915n attached, crocus created its context (Mesa Intel(R) HD Graphics 4000 (IVB GT2), GL 4.2) and aborted in _crocus_batch_flush at the first submission:

truss: ioctl(6, _IOWN('d', 105, 64), 0x7FFFBFFBF660)   Err#25 ENOTTY

lookup_driver() now falls back to the first entry with the same group and number in any direction, after the exact value and after the same direction with another size, so a table listing several forms keeps each. SizePlan already copies in and out only in the directions both commands have, so an _IOW call of the _IOWR entry is copied in and not back, as in Linux. The core's own and the mode-setting commands keep their stricter rule (another direction is ENOTTY), which the guest tests (drm_r0_test, drm_g6_test) check. Module docs updated; driver_range test updated and driver_write_only_form_of_a_read_write_entry added.

Checks (Mac, 1.97.1): cargo check --locked --workspace --target x86_64-unknown-illumos, clippy -D warnings (same target), fmt, cargo test -p drm-core -p drm-uapi -p drm-facade (161 drm-core), cargo test -p virtio_gpu --no-default-features.

Tested on the X230 (branch x230-test, crocus over GBM/EGL surfaceless on renderD128): glClear + readback 65536/65536 pixels right, 600 clear/readback frames at 3473 frames/s; GLSL 4.20 shaders, full-screen quad with four checked pixels, 2000 frames of 64 triangles with glFinish each at 2847 frames/s; four concurrent clients x 20000 frames (about 100k requests), no GL error, no kernel warning, no hang; 621 MSI interrupts claimed during a 600-frame run.

Driver-private commands matched an entry by value, or by group, number and direction with another size. Linux's `drm_ioctl()` indexes the driver's table by number and copies the argument in the directions both commands have, and drivers rely on that: i915 lists only `DRM_IOCTL_I915_GEM_EXECBUFFER2_WR` (`_IOWR`), while Mesa's crocus and iris submit every batch with `DRM_IOCTL_I915_GEM_EXECBUFFER2` (`_IOW`, the same number). On a ThinkPad X230 (HD 4000) with i915n attached, crocus created its context (`Mesa Intel(R) HD Graphics 4000 (IVB GT2)`, GL 4.2) and aborted in `_crocus_batch_flush` at the first submission: ``` truss: ioctl(6, _IOWN('d', 105, 64), 0x7FFFBFFBF660) Err#25 ENOTTY ``` `lookup_driver()` now falls back to the first entry with the same group and number in any direction, after the exact value and after the same direction with another size, so a table listing several forms keeps each. `SizePlan` already copies in and out only in the directions both commands have, so an `_IOW` call of the `_IOWR` entry is copied in and not back, as in Linux. The core's own and the mode-setting commands keep their stricter rule (another direction is ENOTTY), which the guest tests (`drm_r0_test`, `drm_g6_test`) check. Module docs updated; `driver_range` test updated and `driver_write_only_form_of_a_read_write_entry` added. Checks (Mac, 1.97.1): `cargo check --locked --workspace --target x86_64-unknown-illumos`, clippy `-D warnings` (same target), fmt, `cargo test -p drm-core -p drm-uapi -p drm-facade` (161 drm-core), `cargo test -p virtio_gpu --no-default-features`. **Tested on the X230** (branch `x230-test`, crocus over GBM/EGL surfaceless on `renderD128`): glClear + readback 65536/65536 pixels right, 600 clear/readback frames at 3473 frames/s; GLSL 4.20 shaders, full-screen quad with four checked pixels, 2000 frames of 64 triangles with `glFinish` each at 2847 frames/s; four concurrent clients x 20000 frames (about 100k requests), no GL error, no kernel warning, no hang; 621 MSI interrupts claimed during a 600-frame run.
drm-core: a driver ioctl matches its number in any direction, as in Linux
Some checks failed
ci / check-hosted (pull_request) Has been cancelled
ci / kmod-illumos (pull_request) Has been cancelled
eba855b3a7
Driver-private commands matched an entry by value, or by group, number
and direction with another size. Linux's drm_ioctl() indexes the
driver's table by number and copies the argument in the directions both
commands have, and drivers rely on that: i915 lists only
DRM_IOCTL_I915_GEM_EXECBUFFER2_WR (_IOWR), while Mesa's crocus and iris
submit every batch with DRM_IOCTL_I915_GEM_EXECBUFFER2 (_IOW, the same
number). On a ThinkPad X230 (HD 4000) with i915n, crocus created its
context and then aborted at the first batch: the submission was ENOTTY
(truss: ioctl(6, _IOWN('d', 105, 64)) Err#25 ENOTTY).

lookup_driver() now falls back to the first entry with the same group
and number in any direction, after the exact value and after the same
direction with another size, so that a table listing several forms
keeps each. SizePlan already copies in and out only in the directions
both commands have, so an _IOW call of the _IOWR entry is copied in and
not back, as in Linux. The core's own commands and the mode-setting
commands keep their stricter rule (another direction is ENOTTY), which
the guest tests check.
drm: document the any-direction match of driver ioctls
Some checks failed
ci / check-hosted (pull_request) Successful in 41m31s
ci / kmod-illumos (pull_request) Failing after 52m57s
f9f19e35e7
The driver ioctl contract still described matching by complete value or
by number and direction only, and copying by the command's own
direction. Describe the three stages (complete value; same number and
direction, any size; same number in any direction, as Linux), that the
argument is copied only in the directions both the caller's command and
the entry have, and that a number with no entry is ENOTTY, in
drm_ioctl.h, the Rust driver API docs, device.rs and the README.
drm_illumos_ioctl_user_cmd() can now differ in the direction bits too.

is_driver_nr() uses same_number().
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
illumos/illumos-drm!19
No description provided.