Skip to contentSkip to conversation

drm/amdgpu: fix the ioctl direction for DRM_IOCTL_AMDGPU_GEM_VA

PATCH In review Masatake YAMATO 2 participants 3 messages Aug 6, 2024 – Aug 7, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: fix the ioctl direction for DRM_IOCTL_AMDGPU_GEM_VA

Though drmCommandWriteRead() is used in libdrm [1], DRM_IOCTL_AMDGPU_GEM_VA uses DRM_IOW for encoding.

[1] https://gitlab.freedesktop.org/mesa/drm/-/blob/main/amdgpu/amdgpu_bo.c?ref_type=heads

---
 include/uapi/drm/amdgpu_drm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/drm/amdgpu_drm.h +1 -1
index efe5de6ce208..7325390798bc 100644
@@ -63,7 +63,7 @@ extern "C" {
 #define DRM_IOCTL_AMDGPU_INFO		DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_INFO, struct drm_amdgpu_info)
 #define DRM_IOCTL_AMDGPU_GEM_METADATA	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_METADATA, struct drm_amdgpu_gem_metadata)
 #define DRM_IOCTL_AMDGPU_GEM_WAIT_IDLE	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_WAIT_IDLE, union drm_amdgpu_gem_wait_idle)
-#define DRM_IOCTL_AMDGPU_GEM_VA		DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_VA, struct drm_amdgpu_gem_va)
+#define DRM_IOCTL_AMDGPU_GEM_VA		DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_VA, struct drm_amdgpu_gem_va)
 #define DRM_IOCTL_AMDGPU_WAIT_CS	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_CS, union drm_amdgpu_wait_cs)
 #define DRM_IOCTL_AMDGPU_GEM_OP		DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_OP, struct drm_amdgpu_gem_op)
 #define DRM_IOCTL_AMDGPU_GEM_USERPTR	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_USERPTR, struct drm_amdgpu_gem_userptr)
Signature · 1 line
2.45.2
#1 lore raw

Hi Yamato-san,

Quoted 4 lines · Masatake YAMATO

Though drmCommandWriteRead() is used in libdrm [1], DRM_IOCTL_AMDGPU_GEM_VA uses DRM_IOW for encoding.

[1] https://gitlab.freedesktop.org/mesa/drm/-/blob/main/amdgpu/amdgpu_bo.c?ref_type=heads

AFAICT libdrm doesn't read from the struct drm_amdgpu_gem_va it passes to the ioctl after the latter returns though.

Also, while amdgpu_gem_va_ioctl (the ioctl implementation in the kernel) modifies the struct:

	args->va_address &= AMDGPU_GMC_HOLE_MASK;

that looks like an implementation detail which could be avoided if necessary, and shouldn't be propagated back to user space.

I'd suggest fixing libdrm to use drmCommandWrite instead.

Signature · 2 lines
Earthling Michel Dänzer       \        GNOME / Xwayland / Mesa developer
https://redhat.com             \               Libre software enthusiast
#2 lore raw

Hi,

Quoted 12 lines

Hi Yamato-san,

Quoted 4 lines · Masatake YAMATO

Though drmCommandWriteRead() is used in libdrm [1], DRM_IOCTL_AMDGPU_GEM_VA uses DRM_IOW for encoding.

[1] https://gitlab.freedesktop.org/mesa/drm/-/blob/main/amdgpu/amdgpu_bo.c?ref_type=heads

AFAICT libdrm doesn't read from the struct drm_amdgpu_gem_va it passes to the ioctl after the latter returns though.

Quoted 8 lines

Also, while amdgpu_gem_va_ioctl (the ioctl implementation in the kernel) modifies the struct:

	args->va_address &= AMDGPU_GMC_HOLE_MASK;

that looks like an implementation detail which could be avoided if necessary, and shouldn't be propagated back to user space.

I'd suggest fixing libdrm to use drmCommandWrite instead.

Thank you.

After reading this mail, I inspected drm_ioctl.c.
I was surprised that drm_ioctl() uses only the offset from DRM_COMMAND_BASE when choosing the real handler for a cmd. Therefore we can switch from drmCommandWriteRead to drmCommandWrite without breaking applications using the library.

Masatake YAMATO

Quoted 5 lines
Signature · 3 lines
-- 
Earthling Michel Dänzer       \        GNOME / Xwayland / Mesa developer
https://redhat.com             \               Libre software enthusiast