Skip to contentSkip to conversation

pwm: Allow 32-bit tasks to use the character device

PATCH In review Danish Khateeb 2 participants 2 messages Sep 28 – Sep 29

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

PATCH 1/1 pwm: Allow 32-bit tasks to use the character device

pwm_cdev_fileops has no .compat_ioctl, so every ioctl on /dev/pwmchipN fails with -ENOTTY for 32-bit tasks on a 64-bit kernel, e.g. armhf userspace on arm64.

struct pwmchip_waveform has the same layout for 32-bit and 64-bit tasks, so compat_ptr_ioctl() is enough. PWM_IOCTL_REQUEST and PWM_IOCTL_FREE take an integer rather than a pointer, which is fine too: compat_ptr() only changed the value on s390, which dropped compat support in v6.19.

Fixes 9c06f26ba5f5 ("pwm: Add support for pwmchip devices for faster and easier userspace access")
Assisted-by LLM

---

Notes:
Tested on x86_64 in QEMU (pwm/for-next 17dbb6938d3a plus this patch, KASAN and lockdep) with a PCA9685 instantiated on i2c-stub, which gets /dev/pwmchip0. A test program runs all six ioctls, including the error cases (hwpwm out of range or not requested, __pad != 0, use after FREE, SETEXACTWF returning -EDOM):

- before: every ioctl from the -m32 build fails with -ENOTTY, while the 64-bit build works
- after: the -m32 output matches the 64-bit output line for line

No splats. W=1 builds are clean for arm64 (COMPAT=y, LLVM=1) and for i386 (no COMPAT).

 drivers/pwm/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pwm/core.c +1 -0
index 2a050ff4608b..4c6d716e5fde 100644
@@ -2389,6 +2389,7 @@ static const struct file_operations pwm_cdev_fileops = {
 	.release = pwm_cdev_release,
 	.owner = THIS_MODULE,
 	.unlocked_ioctl = pwm_cdev_ioctl,
+	.compat_ioctl = compat_ptr_ioctl,
 };
 
 static dev_t pwm_devt;

base-commit: 17dbb6938d3ab444cd6be1c95506450595a8800d

Signature · 1 line
2.55.0
#1 lore raw

Hello,

Quoted 37 lines · Danish Khateeb

pwm_cdev_fileops has no .compat_ioctl, so every ioctl on /dev/pwmchipN fails with -ENOTTY for 32-bit tasks on a 64-bit kernel, e.g. armhf userspace on arm64.

struct pwmchip_waveform has the same layout for 32-bit and 64-bit tasks, so compat_ptr_ioctl() is enough. PWM_IOCTL_REQUEST and PWM_IOCTL_FREE take an integer rather than a pointer, which is fine too: compat_ptr() only changed the value on s390, which dropped compat support in v6.19.

Fixes 9c06f26ba5f5 ("pwm: Add support for pwmchip devices for faster and easier userspace access")
Assisted-by LLM

---

Notes:
Tested on x86_64 in QEMU (pwm/for-next 17dbb6938d3a plus this patch, KASAN and lockdep) with a PCA9685 instantiated on i2c-stub, which gets /dev/pwmchip0. A test program runs all six ioctls, including the error cases (hwpwm out of range or not requested, __pad != 0, use after FREE, SETEXACTWF returning -EDOM):

- before: every ioctl from the -m32 build fails with -ENOTTY, while the 64-bit build works
- after: the -m32 output matches the 64-bit output line for line

No splats. W=1 builds are clean for arm64 (COMPAT=y, LLVM=1) and for i386 (no COMPAT).

 drivers/pwm/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pwm/core.c +0 -0
index 2a050ff4608b..4c6d716e5fde 100644

drivers/pwm/core.c static const struct file_operations pwm_cdev_fileops = { · line 2393

Quoted 5 lines
drivers/pwm/core.c +1 -0
@@ -2389,6 +2389,7 @@ static const struct file_operations pwm_cdev_fileops = {
 	.release = pwm_cdev_release,
 	.owner = THIS_MODULE,
 	.unlocked_ioctl = pwm_cdev_ioctl,
+	.compat_ioctl = compat_ptr_ioctl,
 };

Not entirely sure about the stable backport, but the change looks fine.

Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next but dropped the Cc:.

Thanks
Uwe