-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memory protection for x86 dependent on XIP #18956
Comments
@andrewboie There are 50-odd tests in sanitycheck that fail when XIP is deselected. I assume they're all related, and will share one (trivial) solution. As far as I can tell this problem existed before the recent implementation of per-thread page tables. I'll be looking into this - it's valuable to me as an exercise in getting to know the gritty details of the x86 userspace implementation - but I wanted to draw this to your attention in case you know of an obvious "whoopie" here. |
I agree this probably has a single, fairly trivial fix. QEMU had XIP turned on by default for a long time (years) so it seems a matter of the non-XIP scenario never having been tested. Can you post the error log with the console output? |
|
The crash is in the code that constructs page tables for new user threads. On further analysis, DT_PHYS_RAM_ADDR is being set wrong for qemu_x86 if CONFIG_XIP is turned off, it had a value of 0x500000. But with XIP turned off, RAM spans from 0x100000 - 0x4FFFFF. The below code works for me, although tests/kernel/xip unsurprisingly crashes. The rest pass. Below code snippet is not a fix, it warns about overlapping the "flash" region.
I think we need to move some policy out of ia32.dtsi. There shouldn't be a flash0 region defined there at all, and sram0 should start at 1MB. If qemu_x86 wants to test flash and xip this stuff needs to be moved qemu_x86's dts and not in the main ia32 one. Still looking into this to find the best fix. |
So this is definitely a DTS/board config problem and not a userspace one. I'm working on a PR which does the following:
This will have the effect of testing both XIP and non-XIP on qemu_x86 to ensure it doesn't bit-rot, with qemu's default being non-XIP. |
Just FYI, that page allocator I mentioned last week will be submitted this afternoon. The "SRAM" information from DTS is going to be a "default" memory map, which can be overridden by a memory map obtained at runtime (from EFI/ACPI/multiboot, or whatever). There's going to be some overlap here, and to be complete, will probably require some minor changes to the early MMU setup (since the memory map isn't necessarily defined by constants like DT_PHYS_RAM_ADDR anymore) and newlib's heap stuff. All minor details though that I think won't collide with what you're doing here. |
XIP support in x86 was something of a mess. This patch does the following: - Generic ia32 SOC no longer defines a "flash" region as generic X86 devices don't have a microcontroller- like concept of flash. The same has been done for apollo_lake. - Generic ia32 and apollo_lake SOCs starts memory at 1MB. - Generic ia32 SOC may optionally have CONFIG_XIP enabled. The board definition must provide a flash region definition that gets exposed as DT_PHYS_LOAD_ADDR. - Fixed definitions for RAM/ROM source addresses in ia32's linker.ld when XIP is turned off. - Support for enabling XIP on apollo_lake SOC removed, there's no use-case. - acrn and gpmrb boards have flash and XIP related definitions removed. - qemu_x86 has a fake flash region added, immediately after system RAM, for use when XIP is enabled. This used to be in the ia32 SOC. However, the default for qemu_x86 is to now have XIP disabled. - Fixed tests/kernel/xip to run by default on boards that enable XIP by default, plus an additional test to exercise XIP on qemu_x86 (which supports it but has XIP switched off by default) The overall effect of this patch is to: - Remove XIP configuration for SOC/boards where it does not make any sense to have it - Support testing XIP on qemu_x86 via tests/kernel/xip, but leave it off by default for other tests, to ensure it doesn't bit-rot and that the system works in both scenarios. - XIP remains an available feature for boards that need it. Fixes: zephyrproject-rtos#18956 Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
XIP support in x86 was something of a mess. This patch does the following: - Generic ia32 SOC no longer defines a "flash" region as generic X86 devices don't have a microcontroller- like concept of flash. The same has been done for apollo_lake. - Generic ia32 and apollo_lake SOCs starts memory at 1MB. - Generic ia32 SOC may optionally have CONFIG_XIP enabled. The board definition must provide a flash region definition that gets exposed as DT_PHYS_LOAD_ADDR. - Fixed definitions for RAM/ROM source addresses in ia32's linker.ld when XIP is turned off. - Support for enabling XIP on apollo_lake SOC removed, there's no use-case. - acrn and gpmrb boards have flash and XIP related definitions removed. - qemu_x86 has a fake flash region added, immediately after system RAM, for use when XIP is enabled. This used to be in the ia32 SOC. However, the default for qemu_x86 is to now have XIP disabled. - Fixed tests/kernel/xip to run by default on boards that enable XIP by default, plus an additional test to exercise XIP on qemu_x86 (which supports it but has XIP switched off by default) The overall effect of this patch is to: - Remove XIP configuration for SOC/boards where it does not make any sense to have it - Support testing XIP on qemu_x86 via tests/kernel/xip, but leave it off by default for other tests, to ensure it doesn't bit-rot and that the system works in both scenarios. - XIP remains an available feature for boards that need it. Fixes: #18956 Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
If you disable CONFIG_XIP for x86, userspace/memory protection tests begin to fail.
Out of the box:
charles@cyouse-desk1:~/zephyr/zephyr$ sanitycheck -p qemu_x86 -T samples/userspace/shared_mem
JOBS: 6
Cleaning output directory /home/charles/zephyr/zephyr/sanity-out
Building testcase defconfigs...
Filtering test cases...
1 tests selected, 196 tests discarded due to filters
total complete: 1/ 1 100% failed: 0
1 of 1 tests passed with 0 warnings in 9 seconds
Modify the
boards/x86/qemu_x86/Kconfig.board
to comment outselect XIP
and then re-run:$ vi boards/x86/qemu_x86/Kconfig.board
$ sanitycheck -p qemu_x86 -T samples/userspace/shared_mem
JOBS: 6
Cleaning output directory /home/charles/zephyr/zephyr/sanity-out
Building testcase defconfigs...
Filtering test cases...
1 tests selected, 196 tests discarded due to filters
total complete: 0/ 1 0% failed: 0
qemu_x86 samples/userspace/shared_mem/sample.kernel.memory_protection.shared_mem FAILED: handler_crash
see: sanity-out/qemu_x86/samples/userspace/shared_mem/sample.kernel.memory_protection.shared_mem/handler.log
total complete: 1/ 1 100% failed: 1
0 of 1 tests passed with 0 warnings in 5 seconds
The text was updated successfully, but these errors were encountered: