casaroli opened a new pull request, #21415: URL: https://github.com/apache/nuttx/pull/21415
## Summary Five small fixes of the x86_64 kernel build (`CONFIG_BUILD_KERNEL`). Each commit fixes one bug in one file. With optimization (`CONFIG_DEBUG_FULLOPT`) qemu-intel64:knsh_romfs does not start init on master. - `up_invalid_tlb()`: `invlpg` with an `"m"` operand invalidates the TLB entry of the address of the loop variable (on the stack), not the entry of the page. The disassembly shows `invlpg -0x8(%rbp)`. Now the page address is in a register: `invlpg (%rax)`. - `pgalloc()`: the heap pages went into the address environment of the caller (`addrenv_own`). While `exec()` loads a new program, the address environment of the new program is selected (`addrenv_curr`), so a heap that grows then (a stack larger than the initial heap) is not mapped where the loader writes. Now `addrenv_curr`, as arm64, ARMv7-A and RISC-V do. - `x86_64_create_region()`: each page table (PT) started at the index of the address in the page directory, not in the PT. A region across a 2 MiB boundary replaced the low entries of its PT and left the rest unmapped. Now each PT starts at the index of the address in it, and the loop ends when the whole size is mapped. - `sys_call6()`: the number and the six parameters went into RAX, RDI, RSI, RDX, R10, R8 and R9 with one move each from `"rm"` operands, and these registers were not outputs or clobbers. With optimization one move can overwrite a register that holds a later parameter. Now each value is a register variable and an in/out operand of `syscall`. - `x86_64_syscall_entry()`: with `CONFIG_ARCH_KERNEL_STACK`, RSP was 8 modulo 16 at the call of `x86_64_syscall()`. The SysV ABI wants 16. Aligned SSE moves on the stack (optimized code, the vector register save area of variadic functions) then fault. Now the entry takes 8 more bytes after the push. ## Impact x86_64 only. The `sys_call6()`, `pgalloc()`, region and stack alignment changes are in kernel-build code (`CONFIG_LIB_SYSCALL`, `CONFIG_ARCH_ADDRENV`, `CONFIG_ARCH_KERNEL_STACK`); `up_invalid_tlb()` is in a header that all x86_64 builds include. No common code changes. No API change. No documentation describes this code. ## Testing qemu-intel64:knsh_romfs under QEMU TCG (`-cpu max`, one CPU) with `CONFIG_ARCH_INTEL64_HPET_ALARM=y` and `CONFIG_ARCH_INTEL64_HAVE_PCID=n` (TCG has no TSC deadline timer and no PCID). The applications are built with the steps of the board documentation and are in the ROMFS image. "optimized" is this configuration with `CONFIG_DEBUG_FULLOPT=y` and `CONFIG_ELF_STACKSIZE=2097152` (the 2 MiB heap of a program at 0x8000f0000 crosses a 2 MiB boundary). Test program `x86kfix.c`, case `spawnstack`: `posix_spawn()` of itself with a 1 MiB stack (larger than the initial heap of 160 KiB); the child exits with 42. | Test | master ae2f4f9d87f | this PR | this PR without the commit | |---|---|---|---| | optimized: boot and ostest | init does not start: kernel page fault (write) at 0x8002efff8, the last word of the heap | NSH starts, ostest status 0 | region commit: the same page fault at 0x8002efff8; `sys_call6()` commit: kernel page fault at address 0x27 when init starts | | `x86kfix spawnstack` (-O0) | kernel page fault (write) at 0x800217ff8 in the heap of the new program | PASS | `pgalloc()` commit: the same page fault | | ostest (-O0) | status 0 | status 0 | | The stack alignment commit: a test-only probe in `x86_64_syscall()` counts the calls with a frame pointer that is not 16 byte aligned (-O0, frame pointer = RSP at the call - 16). master: 2000 of 2000 calls misaligned; this PR: 0 of 2000; ostest status 0 in both. Without this commit the optimized boot and ostest still pass: the master kernel has no 16 byte stack local on a system call path that the tests reach. The `up_invalid_tlb()` commit: no test fails today, a stale entry needs a changed mapping that is used again. The disassembly of the old and new forms (x86_64-elf-gcc 16.2, -O0 and -Os): `invlpg -0x8(%rbp)` before, `invlpg (%rax)` / `invlpg (%rdi)` after. Builds with `EXTRAFLAGS="-Wno-cpp -Werror"` (and `-Wno-error=shadow` for a `sinpi` warning in libm of the host compiler, x86_64-elf-gcc 16.2), no new warnings: qemu-intel64:knsh_romfs, knsh_romfs_pci, nsh, nsh_pci, ostest. The tests ran on master ae2f4f9d87f; the branch is rebased on 6569424cfa6 (the new commits touch no x86_64 file). `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
