* Re: [PATCH] fs/proc/task_mmu: return -ENOTTY for unknown pagemap ioctls
2026-10-23 18:13 [PATCH] fs/proc/task_mmu: return -ENOTTY for unknown pagemap ioctls Hengyu Liang
@ 2026-10-23 18:24 ` Andrew Morton
2026-10-25 10:56 ` David Hildenbrand (Arm)
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-10-23 18:24 UTC (permalink / raw)
To: Hengyu Liang
Cc: linux-mm, liam, ljs, vbabka, jannh, pfalcato, usama.anjum,
avagin, mirq-linux, arnd, linux-fsdevel, linux-kernel, stable
On Fri, 23 Oct 2026 14:13:00 -0400 Hengyu Liang <hengyul@cs.unc.edu> wrote:
> Commit 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and
> optionally clear info about PTEs") made do_pagemap_cmd() the ioctl
> handler of /proc/<pid>/pagemap.
>
> However, do_pagemap_cmd() returns -EINVAL for every command other than
> PAGEMAP_SCAN. Before that commit, pagemap had no ioctl handler, and
> the VFS returned -ENOTTY for these commands. As of now, they fail with
> EINVAL, so tcgetattr() and isatty() on pagemap report EINVAL instead
> of ENOTTY.
>
> The issue can be reproduced with a simple C program:
>
> #include <fcntl.h>
> #include <stdio.h>
> #include <termios.h>
>
> int main(void)
> {
> struct termios t;
> int fd = open("/proc/self/pagemap", O_RDONLY);
>
> if (tcgetattr(fd, &t) < 0)
> perror("tcgetattr");
> return 0;
> }
>
> Before that commit, the result is:
>
> tcgetattr: Inappropriate ioctl for device
>
> After that commit, the result is:
>
> tcgetattr: Invalid argument
>
> This patch will return -ENOIOCTLCMD for unknown commands, as
> procfs_procmap_ioctl() in the same file does, so that the VFS turns it
> into -ENOTTY.
OK, thanks, annoying.
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
Three years ago. So if anyone had to update their userspace code
because we altered this, they will now need to unupdate it. It's hard
to believe that this will cause significant harm - perhaps there are
correctness test suites which will be surprised (again).
> Cc: stable@vger.kernel.org
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
> ---
> Unknown commands should fail with ENOTTY: Documentation/driver-api/
> ioctl.rst says so and calls -EINVAL wrong, and POSIX requires
> tcgetattr() to fail with ENOTTY on a file that is not a terminal.
>
> I found no user space that relies on EINVAL here: Wine and the mm and
> kvm selftests only use PAGEMAP_SCAN on pagemap, whose results do not
> change, and CRIU and LTP only read the file.
Good info, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] fs/proc/task_mmu: return -ENOTTY for unknown pagemap ioctls
2026-10-23 18:13 [PATCH] fs/proc/task_mmu: return -ENOTTY for unknown pagemap ioctls Hengyu Liang
2026-10-23 18:24 ` Andrew Morton
@ 2026-10-25 10:56 ` David Hildenbrand (Arm)
2026-10-26 13:23 ` Pedro Falcato
2026-10-26 13:53 ` Lorenzo Stoakes (ARM)
3 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-10-25 10:56 UTC (permalink / raw)
To: Hengyu Liang, akpm, linux-mm
Cc: liam, ljs, vbabka, jannh, pfalcato, usama.anjum, avagin,
mirq-linux, arnd, linux-fsdevel, linux-kernel, stable
On 10/23/26 20:13, Hengyu Liang wrote:
> Commit 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and
> optionally clear info about PTEs") made do_pagemap_cmd() the ioctl
> handler of /proc/<pid>/pagemap.
>
> However, do_pagemap_cmd() returns -EINVAL for every command other than
> PAGEMAP_SCAN. Before that commit, pagemap had no ioctl handler, and
> the VFS returned -ENOTTY for these commands. As of now, they fail with
> EINVAL, so tcgetattr() and isatty() on pagemap report EINVAL instead
> of ENOTTY.
>
> The issue can be reproduced with a simple C program:
>
> #include <fcntl.h>
> #include <stdio.h>
> #include <termios.h>
>
> int main(void)
> {
> struct termios t;
> int fd = open("/proc/self/pagemap", O_RDONLY);
>
> if (tcgetattr(fd, &t) < 0)
> perror("tcgetattr");
> return 0;
> }
>
> Before that commit, the result is:
>
> tcgetattr: Inappropriate ioctl for device
>
> After that commit, the result is:
>
> tcgetattr: Invalid argument
>
> This patch will return -ENOIOCTLCMD for unknown commands, as
> procfs_procmap_ioctl() in the same file does, so that the VFS turns it
> into -ENOTTY.
>
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] fs/proc/task_mmu: return -ENOTTY for unknown pagemap ioctls
2026-10-23 18:13 [PATCH] fs/proc/task_mmu: return -ENOTTY for unknown pagemap ioctls Hengyu Liang
2026-10-23 18:24 ` Andrew Morton
2026-10-25 10:56 ` David Hildenbrand (Arm)
@ 2026-10-26 13:23 ` Pedro Falcato
2026-10-26 13:53 ` Lorenzo Stoakes (ARM)
3 siblings, 0 replies; 5+ messages in thread
From: Pedro Falcato @ 2026-10-26 13:23 UTC (permalink / raw)
To: Hengyu Liang
Cc: akpm, linux-mm, liam, ljs, vbabka, jannh, usama.anjum, avagin,
mirq-linux, arnd, linux-fsdevel, linux-kernel, stable
On Fri, Oct 23, 2026 at 02:13:00PM -0400, Hengyu Liang wrote:
> Commit 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and
> optionally clear info about PTEs") made do_pagemap_cmd() the ioctl
> handler of /proc/<pid>/pagemap.
>
> However, do_pagemap_cmd() returns -EINVAL for every command other than
> PAGEMAP_SCAN. Before that commit, pagemap had no ioctl handler, and
> the VFS returned -ENOTTY for these commands. As of now, they fail with
> EINVAL, so tcgetattr() and isatty() on pagemap report EINVAL instead
> of ENOTTY.
>
> The issue can be reproduced with a simple C program:
>
> #include <fcntl.h>
> #include <stdio.h>
> #include <termios.h>
>
> int main(void)
> {
> struct termios t;
> int fd = open("/proc/self/pagemap", O_RDONLY);
>
> if (tcgetattr(fd, &t) < 0)
> perror("tcgetattr");
> return 0;
> }
>
> Before that commit, the result is:
>
> tcgetattr: Inappropriate ioctl for device
>
> After that commit, the result is:
>
> tcgetattr: Invalid argument
>
> This patch will return -ENOIOCTLCMD for unknown commands, as
> procfs_procmap_ioctl() in the same file does, so that the VFS turns it
> into -ENOTTY.
>
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
I would generally be scared of applying this change, but since this is a
niche API, and there are no other ioctls for it, this should be fine.
--
Pedro
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] fs/proc/task_mmu: return -ENOTTY for unknown pagemap ioctls
2026-10-23 18:13 [PATCH] fs/proc/task_mmu: return -ENOTTY for unknown pagemap ioctls Hengyu Liang
` (2 preceding siblings ...)
2026-10-26 13:23 ` Pedro Falcato
@ 2026-10-26 13:53 ` Lorenzo Stoakes (ARM)
3 siblings, 0 replies; 5+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-10-26 13:53 UTC (permalink / raw)
To: Hengyu Liang
Cc: akpm, linux-mm, liam, vbabka, jannh, pfalcato, usama.anjum,
avagin, mirq-linux, arnd, linux-fsdevel, linux-kernel, stable
On Fri, Oct 23, 2026 at 02:13:00PM -0400, Hengyu Liang wrote:
> Commit 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and
> optionally clear info about PTEs") made do_pagemap_cmd() the ioctl
> handler of /proc/<pid>/pagemap.
>
> However, do_pagemap_cmd() returns -EINVAL for every command other than
> PAGEMAP_SCAN. Before that commit, pagemap had no ioctl handler, and
> the VFS returned -ENOTTY for these commands. As of now, they fail with
> EINVAL, so tcgetattr() and isatty() on pagemap report EINVAL instead
> of ENOTTY.
>
> The issue can be reproduced with a simple C program:
>
> #include <fcntl.h>
> #include <stdio.h>
> #include <termios.h>
>
> int main(void)
> {
> struct termios t;
> int fd = open("/proc/self/pagemap", O_RDONLY);
>
> if (tcgetattr(fd, &t) < 0)
> perror("tcgetattr");
> return 0;
> }
>
> Before that commit, the result is:
>
> tcgetattr: Inappropriate ioctl for device
>
> After that commit, the result is:
>
> tcgetattr: Invalid argument
>
> This patch will return -ENOIOCTLCMD for unknown commands, as
> procfs_procmap_ioctl() in the same file does, so that the VFS turns it
> into -ENOTTY.
>
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Seems reasonable, though I doubt any sane user is relying on this.
Confirmed the conversion from -ENOIOCTLCMD (first time I saw that :) to -ENOTTY also.
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 5+ messages in thread