Skip to content

Enabling ssr Inheritance WIP#44

Open
bryanb-h2 wants to merge 8 commits into
masterfrom
bryanb_stmode
Open

Enabling ssr Inheritance WIP#44
bryanb-h2 wants to merge 8 commits into
masterfrom
bryanb_stmode

Conversation

@bryanb-h2

Copy link
Copy Markdown
Contributor

Removed dependence on standalone.

Signed-off-by: Bryan Bayerdorffer <bryanb@qti.qualcomm.com>
@bryanb-h2 bryanb-h2 marked this pull request as draft June 3, 2026 15:10
Comment thread kernel/util/stmode/test/Makefile Outdated
include Makefile.inc
OSLIB=
KERNEL_BUILD_DIR := $(INSTALLPATH)/../build/kernel
CFLAGS += -ffixed-r28 -I$(KERNEL_BUILD_DIR)/include

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, maybe convert: CFLAGS/ASFLAGS -> EXTRA_CFLAGS/EXTRA_ASFLAGS, and move include below these lines.

zbelinsk added 3 commits June 8, 2026 06:15
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>

@bryanb-h2 bryanb-h2 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't request changes since this is my PR.

Comment thread kernel/util/stmode/test/test.c Outdated
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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread kernel/util/stmode/test/test.c Outdated
u32_t tmp;

h2_init(NULL);
#if ARCHV <= 3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a function in kernel/util/hw/hw.h to get ssr.

Comment thread kernel/util/stmode/test/test.c Outdated
any threads. */
static H2K_thread_context extra_contexts[NUM_TEST_THREADS] __attribute__((aligned(32)));

static void stmode_extend_bootvm_contexts(H2K_thread_context *me)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bryanb-h2 bryanb-h2 marked this pull request as ready for review June 8, 2026 16:15
@bryanb-h2 bryanb-h2 changed the title Fix stmode test WIP. Fix stmode test. Jun 8, 2026
@bryanb-h2 bryanb-h2 changed the title Fix stmode test. Fix stmode test Jun 8, 2026
zbelinsk added 4 commits June 9, 2026 00:58
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>
@bryanb-h2 bryanb-h2 added the fail label Jun 10, 2026
@zbelinsk zbelinsk changed the title Fix stmode test Enabling ssr Inheritance Jun 11, 2026
@zbelinsk zbelinsk changed the title Enabling ssr Inheritance Enabling ssr Inheritance WIP Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants