Enabling ssr Inheritance WIP#44
Conversation
Signed-off-by: Bryan Bayerdorffer <bryanb@qti.qualcomm.com>
| include Makefile.inc | ||
| OSLIB= | ||
| KERNEL_BUILD_DIR := $(INSTALLPATH)/../build/kernel | ||
| CFLAGS += -ffixed-r28 -I$(KERNEL_BUILD_DIR)/include |
There was a problem hiding this comment.
For readability, maybe convert: CFLAGS/ASFLAGS -> EXTRA_CFLAGS/EXTRA_ASFLAGS, and move include below these lines.
h2_thread_create() hardcodes ssr_um=1 (guest-user mode) for created threads, but this test runs in monitor space (no BOOT/booter) where code pages are supervisor-execute-only. Guest-user threads fault with Hexagon cause 0x11 (user/guest execute to page with no execute permission) at their first instruction. Fix by providing a local override of H2K_thread_create_no_squash that inherits ssr_guest/ssr_um from the caller (main runs ssr_um=0, ssr_guest=1) instead of hardcoding 1. Add linking flag --allow-multiple-definition so the linker picks test.o over libh2kernel.a for this symbol. Also: - Add stmode_extend_bootvm_contexts() to pre-allocate NUM_TEST_THREADS extra H2K_thread_context slots into the boot VM free list, so the test is self-contained and does not require MAX_BOOT_CONTEXTS=3 at kernel build time. - Add wait_for_threads_to_sleep() using MODECTL_W_BITS to quiesce all hw threads into WAIT after h2_hwconfig_hwthreads_mask(-1) before calling stmode_begin(); without this, stmode_begin races threads coming online and spuriously reports >1 active thread. - Add MODECTL_E_MASK/MODECTL_W_BITS/MODECTL_W_MASK to max.h. Signed-off-by: Zeev Belinsky <zbelinsk@qti.qualcomm.com>
Signed-off-by: zbelinsk <zbelinsk@qti.qualcomm.com>
Signed-off-by: zbelinsk <zbelinsk@qti.qualcomm.com>
Bryan Bayerdorffer (bryanb-h2)
left a comment
There was a problem hiding this comment.
Can't request changes since this is my PR.
| This is needed because this test runs in monitor space (no BOOT/booter), so pages | ||
| are supervisor-execute-only. Created threads must run at the same privilege as | ||
| main (ssr_um=0, ssr_guest=1) to be able to execute them without cause-0x11. */ | ||
| IN_SECTION(".text.misc.create") s32_t H2K_thread_create_no_squash(u32_t pc, u32_t sp, u32_t arg1, u32_t prio, H2K_vmblock_t *vmblock, H2K_thread_context *me) |
There was a problem hiding this comment.
Instead of doing all this I think it would actually be ok to just change to 'tmp->ssr_um = me->ssr_um' in the real function. ssr_guest doesn't matter for the test because that is only significant when um == 1. Anything in the normal execution flow that calls thread_create via a trap will have me->ssr_um == 1, so it's safe.
We should document this behavior in kernel/thread/create/create/spec though.
| u32_t tmp; | ||
|
|
||
| h2_init(NULL); | ||
| #if ARCHV <= 3 |
There was a problem hiding this comment.
Add a function in kernel/util/hw/hw.h to get ssr.
| any threads. */ | ||
| static H2K_thread_context extra_contexts[NUM_TEST_THREADS] __attribute__((aligned(32))); | ||
|
|
||
| static void stmode_extend_bootvm_contexts(H2K_thread_context *me) |
There was a problem hiding this comment.
inline?
| H2K_stmode_end(); | ||
| if ((H2K_get_syscfg() & 0x10) == 0) FAIL("stmode_end didn't ensable gie"); | ||
|
|
||
| h2_thread_create(test1, &stack1[STACK_SIZE], (void *)1, 0); |
There was a problem hiding this comment.
Arguably this should just call H2K_thread_create_no_squash() directly to simplify the test. We can do this here since the test runs in monitor. Makes debugging the test easier.
Add H2K_get_sgp() to kernel/util/hw/hw.h to return the current thread context pointer from sgp/sgp0. Also make stmode_extend_bootvm_contexts(), wait_for_threads_to_sleep() static inlines. Signed-off-by: Zeev Belinsky <zbelinsk@qti.qualcomm.com>
Add hwconfig trap handlers and user-facing wrappers for registers that booter was accessing directly via H2K_* kernel functions: CCR, SYSCFG, livelock (s35), turkey (s61), duck (s62), chicken (s63), rgdr (s60). Replace all H2K_get_*/H2K_set_* calls in booter/booter.c with the new h2_hwconfig_* trap wrappers. Remove include of hw.h from booter since it no longer needs kernel-internal register access. Add SSR_UM_BIT (bit 16) to max.h as a named constant. Simplify stmode test: remove local H2K_thread_create_no_squash override and --allow-multiple-definition now that create.ref.c inherits ssr_um from the caller. Use H2K_get_sgp() instead of raw sgp0 asm. Replace h2_hwconfig_hwthreads_mask() with H2K_trap_hwconfig_hwthreads_mask(). Signed-off-by: Zeev Belinsky <zbelinsk@qti.qualcomm.com>
H2K_thread_create_no_squash: change tmp->ssr_um from hardcoded 1 to me->ssr_um so created threads inherit the caller's user mode bit. Set SSR_UM_BIT in BOOT_THREAD_SSR so the booter boot thread starts as guest-user (ssr_um=1), which is required for the inheritance to work correctly for booter-created VMs. NOTE: h2_compat/error test is currently failing - needs adaptation. Signed-off-by: Zeev Belinsky <zbelinsk@qti.qualcomm.com>
Signed-off-by: zbelinsk <zbelinsk@qti.qualcomm.com>
Signed-off-by: zbelinsk <zbelinsk@qti.qualcomm.com>
The real issue this test exposed: the booter runs as supervisor guest (ssr_um=0, gm=1), so threads it creates inherit ssr_um=0. This causes these instructions to have unexpected behaviour: - SSR read: works cleanly - syscfg write: hangs The correct long-term fix is to make BOOT_THREAD_SSR include SSR_UM_BIT so the booter and its guest VMs run as true user-mode guests. However: - Kernel-level tests (e.g. kernel/util/stmode/test) run at monitor privilege reusing BOOT_THREAD_SSR, and would hang before reaching main() with ssr_um=1. For now, use trap1(#7) which unconditionally routes to H2K_vmtrap_bad -> H2K_vm_event(cause=0x1B) regardless of ssr_um, fixing the test. Signed-off-by: Zeev Belinsky <zbelinsk@qti.qualcomm.com>
|
Update: |
There's really no such thing as 'supervisor guest'. Supervisor mode (or monitor mode as it's called in Hexagon) is (ssr.ex==1 || ssr.um ==0). If neither of those is true (i.e. ssr.ex==0 && ssr.um==1) then ssr.gm determines if the mode is guest or user. To put it another way, in monitor mode the processor ignores the guest bit. What does syscfg write hanging mean? In monitor mode you can write syscfg, but the core must be in single-thread mode. |
Removed dependence on standalone.