tools: PAGE_SIZE mmap fallback for CONFIG_IO_STRICT_DEVMEM kernels#172
Merged
Conversation
mem_reg() always mmap()s a 64 KiB window so consecutive register reads in the same SoC block hit a cache. On kernels built with CONFIG_IO_STRICT_DEVMEM=y (the kernel default since v4.6, and what the OpenIPC hi3516cv6xx defconfig currently ships) any /dev/mem mapping whose range overlaps a page already claimed by a driver via request_mem_region() is rejected with EPERM, even for root. On Hi3516CV608 the very first probe touches SCSYSID at 0x11020EE0. The 64 KiB window [0x11020000..0x1102FFFF] covers 0x11029000, claimed by the PWM driver, so mmap fails and ipctool aborts before printing the chip name -- even though the SYSCTRL page itself is unclaimed and readable. When EPERM is observed, retry the mmap with a single PAGE_SIZE window aligned to the requested address. That unblocks chip-ID, HPM, DDR PHY and any other register block whose own page isn't kernel-claimed. Pages that *are* claimed (CRG/clocks, I2C, SPI, GPIO, UART) still need the kernel-side companion fix in the OpenIPC firmware defconfig. Cache invalidation is rewritten to track the actual loaded window range instead of comparing against a fixed 64 KiB offset, so the fallback path's smaller window still benefits from the read-side cache for adjacent registers in the same page. Verified on OpenIPC hi3516cv6xx (kernel 5.10.221, CONFIG_STRICT_DEVMEM and CONFIG_IO_STRICT_DEVMEM both =y): before the patch ipctool exited with "read_mem_reg mmap error: Operation not permitted (1)"; after, it correctly identifies model 3516CV608 and emits NOR/RAM/firmware sections of the YAML report. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mem_reg()mmaps a 64 KiB window per call. OnCONFIG_IO_STRICT_DEVMEM=ykernels, the kernel rejects any/dev/memmapping whose range overlaps a driver-claimed page — even for root.0x11020EE0) opens a window[0x11020000..0x1102FFFF]that covers PWM @0x11029000, so the mmap fails withEPERMand ipctool aborts before printing the chip name.EPERM, retry with a single PAGE_SIZE window aligned to the requested address. The cache-invalidation logic is reworked to compare against the actual loaded window range, so reads of adjacent registers in the same page still hit the cache after a fallback.Validation
Tested on OpenIPC
hi3516cv6xx(kernel 5.10.221 armv7, dual A7) at 10.216.128.115 with stock OpenIPC defconfig (bothCONFIG_STRICT_DEVMEM=yandCONFIG_IO_STRICT_DEVMEM=y).Before:
After:
Three
EPERMs remain on register blocks whose pages really are kernel-claimed (0x11010000CRG/clocks,0x11060000I2C,0x1109xxxxGPIO). Those need the kernel-side companion fix (dropCONFIG_IO_STRICT_DEVMEMfromhi3516cv6xx.generic.config— separate firmware PR).Test plan
arm-openipc-linux-musleabi.cmaketoolchain fileEPERM)🤖 Generated with Claude Code