Skip to content

Don't derive kernel granularities from getpagesize()

Wake Liu via ltp ltp 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 1 replyIn review
  2. v14 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- fcntl35: Use the pipe buffer size for the unprivileged case too, as suggested by Kalesh. pipe-max-size can't be lower than a single pipe buffer, so with 16K kernel pages and a 4K page size reported to userspace, setting it to getpagesize() still allowed 16K pipes.
- Rebased on current master.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4epoll_wait06, fcntl35: Don't assume a pipe buffer is getpagesize()testcases/kernel/syscalls/epoll_wait/epoll_wait06.c testcases/kernel/syscalls/fcntl/fcntl35.c+30 -61 reply
2/4memcg, userfaultfd07: Populate whole pages instead of single bytestestcases/kernel/controllers/memcg/control/mem_process.c testcases/kernel/controllers/memcg/memcontrol02.c testcases/kernel/syscalls/userfaultfd/userfaultfd07.c+22 -130 replies
3/4ioctl10: Compare vma_page_size with KernelPageSize from smapstestcases/kernel/syscalls/ioctl/ioctl10.c+33 -10 replies
4/4signal06: Allocate the alternate signal stack with mmap()testcases/kernel/syscalls/signal/signal06.c+11 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [LTP] [PATCH v2 0/4] Don't derive kernel granularities from getpagesize()

Hi,

Several tests derive kernel internal granularities from getpagesize():
the size of a pipe buffer, the granularity memory is faulted in and cached with, or the page size reported by PROCMAP_QUERY. On mainline kernels all of these are the same value, so the assumption never shows.

Android runs LTP on x86_64 emulators that boot a 4K kernel with the page size emulation of the Android Common Kernels [1], enabled by page_shift=14 on the kernel command line. It is not part of mainline. The kernel reports a 16K page size to userspace through AT_PAGESZ and enforces 16K alignment for mmap() and friends, while it keeps using 4K pages internally. Interfaces that userspace commonly relies on, such as mincore() and /proc/pid/pagemap, are emulated as well, but pipe buffers, page fault, page cache and memcg accounting granularity, and the KernelPageSize reported in smaps and by PROCMAP_QUERY keep reflecting the real 4K kernel page size.

Android has carried local workarounds for these tests so far. This series instead makes the tests rely on what the kernel reports, or populate memory independently of the page size, so that Android can run them unmodified. The patches are grouped by the assumption they remove. None of them alters the behavior on kernels where both page sizes are equal, and none adds emulation specific code to the tests.

Changes in v2:
- fcntl35: Use the pipe buffer size for the unprivileged case too, as suggested by Kalesh. pipe-max-size can't be lower than a single pipe buffer, so with 16K kernel pages and a 4K page size reported to userspace, setting it to getpagesize() still allowed 16K pipes.
- Rebased on current master.

Tested on:
- x86_64 with a 4K page size (Debian, 7.1 kernel), where epoll_wait06, ioctl10 and signal06 pass before and after the series, and all changed tests compile without warnings with gcc and clang.
- An Android x86_64 emulator with a 4K page size (6.6 kernel), where the results are the same before and after the series.
- An Android x86_64 Cuttlefish device running 6.18.32-android17 with page_shift=14, where all of the patched tests fail without the series and pass with it.

For v2, fcntl35 and epoll_wait06 were also run as root on the same Cuttlefish device with getpagesize() and sysconf(_SC_PAGESIZE) wrapped to return 1K, to mimic kernel pages that are larger than the page size reported to userspace. Both fail there without the series, v1 still fails the unprivileged case of fcntl35, and v2 passes. epoll_wait06, ioctl10 and signal06 also pass with the series on the 4K x86_64 host with getpagesize() interposed to return 1K or 16K.

v1: https://lore.kernel.org/ltp/[email protected]/

[1] https://source.android.com/docs/core/architecture/16kb-page-size/getting-started-cf-x86-64-pgagnostic

Wake Liu (4):
epoll_wait06, fcntl35: Don't assume a pipe buffer is getpagesize() memcg, userfaultfd07: Populate whole pages instead of single bytes
ioctl10: Compare vma_page_size with KernelPageSize from smaps
signal06: Allocate the alternate signal stack with mmap()

 .../controllers/memcg/control/mem_process.c   | 11 +++---
 .../kernel/controllers/memcg/memcontrol02.c   | 13 +++----
 .../kernel/syscalls/epoll_wait/epoll_wait06.c | 15 +++++---
 testcases/kernel/syscalls/fcntl/fcntl35.c     | 21 +++++++++++-
 testcases/kernel/syscalls/ioctl/ioctl10.c     | 34 ++++++++++++++++++-
 testcases/kernel/syscalls/signal/signal06.c   | 15 +++++---
 .../syscalls/userfaultfd/userfaultfd07.c      | 11 ++++--
 7 files changed, 96 insertions(+), 24 deletions(-)

base-commit: c4be3107083cd11e4732884c4c8c5e9c6665e729

Signature · 5 lines
2.56.0.611.g1030f0b940-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp