Skip to contentSkip to conversation

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

PATCH Applied Danish Khateeb 2 participants 2 messages Sep 29 – Oct 31

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

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

counter_fops has no .compat_ioctl, so COUNTER_ADD_WATCH_IOCTL, COUNTER_ENABLE_EVENTS_IOCTL and COUNTER_DISABLE_EVENTS_IOCTL fail with -ENOTTY for 32-bit tasks on a 64-bit kernel, e.g. armhf userspace on arm64. Without a watch, such a task gets no events from /dev/counterN.

struct counter_watch has the same layout for 32-bit and 64-bit tasks, and the other two ioctls take no argument, so compat_ptr_ioctl() is enough. struct counter_event, which read() returns, has the same layout too.

Fixes b6c50affda59 ("counter: Add character device interface")
Assisted-by LLM

---

Notes:
Tested on x86_64 in QEMU (counter-fixes plus this patch, KASAN and lockdep) with interrupt-cnt on a gpio-sim line, toggling the line five times per run:

- before: tools/counter/counter_watch_events built with -m32 fails with "Error adding watches[0]: Inappropriate ioctl for device", and so do the enable and disable ioctls; the 64-bit build gets all five events
- after: the -m32 build gets the same five events and the same errors for an invalid watch and a bad pointer as the 64-bit build

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

 drivers/counter/counter-chrdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/counter/counter-chrdev.c +1 -0
index 61451ba74ca1..f5bf8e40096b 100644
@@ -457,6 +457,7 @@ static const struct file_operations counter_fops = {
 	.read = counter_chrdev_read,
 	.poll = counter_chrdev_poll,
 	.unlocked_ioctl = counter_chrdev_ioctl,
+	.compat_ioctl = compat_ptr_ioctl,
 	.open = counter_chrdev_open,
 	.release = counter_chrdev_release,
 };

base-commit: fd73f4a6659897191fa0d40695fe370925dd3780

Signature · 1 line
2.55.0
maintainer Applied
#1 lore raw
Quoted 11 lines · Danish Khateeb

counter_fops has no .compat_ioctl, so COUNTER_ADD_WATCH_IOCTL, COUNTER_ENABLE_EVENTS_IOCTL and COUNTER_DISABLE_EVENTS_IOCTL fail with -ENOTTY for 32-bit tasks on a 64-bit kernel, e.g. armhf userspace on arm64. Without a watch, such a task gets no events from /dev/counterN.

struct counter_watch has the same layout for 32-bit and 64-bit tasks, and the other two ioctls take no argument, so compat_ptr_ioctl() is enough. struct counter_event, which read() returns, has the same layout too.

[...]

I don't believe this warrants a backport to the stable trees, so I've dropped the respective Cc tag.

Applied, thanks!

[1/1] counter: Allow 32-bit tasks to use the character device

      commit: d722f879730c766ed9347352f4b5855a4841125d

Best regards,

Signature · 1 line
William Breathitt Gray <[email protected]>