-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
dynamic threads don't work on x86 in some configurations #17893
Comments
This is also a problem on x86_64, and happens quite frequently now that I have userspace working on that, blocking the test case.. |
This doesn't work properly on x86 unless the dynamic thread struct allocated gets lucky and is aligned to 16 bytes. Disabling for now until zephyrproject-rtos#17893 is fixed. Signed-off-by: Andrew Boie <[email protected]>
This doesn't work properly on x86 unless the dynamic thread struct allocated gets lucky and is aligned to 16 bytes. Disabling for now until #17893 is fixed. Signed-off-by: Andrew Boie <[email protected]>
Is this an issue needing to be addressed in Zephyr? The gcc documentation does not specify whether alignment applies to stack variables. However, from reading this issue it seems to me that stack variable alignment smaller than given in the attribute was deemed a bug which was supposedly fixed in gcc 4.6. |
@wobak-j this doesn't have anything to do with the compiler, it's the alignment requirements of memory addresses passed to https://www.felixcloutier.com/x86/fxsave
|
Yes, I understand that the exception is triggered by an |
@wobak-j for build-time defined k_thread, yes, the alignment is correct. But that's not what this bug is about. If you call malloc() or get memory from a memory pool, and cast the returned void * pointer to a k_thread, the alignment is likely not correct. We have no heap in Zephyr where you can specify the alignment in the allocation function. This has nothing to do with GCC or the alignment of stack variables because we are not getting the memory for the k_thread from the stack (and it would be insane to do so, the kernel would explode as soon as the stack memory falls out of scope). Please review the original issue statement:
|
btw, the test currently passes on qemu_x86 and still fails on qemu_x86_64, was looking for a different reason at this test.
|
@nashif are you sure the quoted failure is from qemu_x86_64? note the register names, that is from 32-bit About the original issue: storing in the stack object doesn't work well. It would need to be in memory not accessible by a user thread, and not possible to overwrite in a supervisor stack overflow. Which means it would need to be located before the page-aligned stack buffer, and it would consume a page all by itself, wasting 3584 bytes per thread which is a dealbreaker. I think we need to support aligned thread objects in our dynamic allocations in order to fix this specific issue. Without an aligned allocator, even thread objects that don't require alignment are of limited value since since their corresponding stacks (which must be aligned) cannot be allocated. |
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
Dynamic threads are an optional userspace feature; if CONFIG_DYNAMIC_OBJECTS is enabled, a thread may call
k_object_alloc(K_OBJ_THREAD)
which returns a usablestruct k_thread
pointer. This pointer is no more than 4-byte aligned; Zephyr does not have a heap which allows returning aligned pointers.On x86, thread->arch may have members which require alignment. Currently this happens if CONFIG_EAGER_FP_SHARING or CONFIG_LAZY_FP_SHARING is turned on, as thread->arch will then contain structs requiring alignment because they get passed to x86 CPU instructions to save/restore fp context. Threads that are instantiated statically will be aligned properly, but likely not if allocated dynamically, resulting in a CPU exception when context is attempted to be saved/restored.
A quick survey of arches reveals that only x86 threads have this problem.
We may need to find an alternate storage area. Floating point register stuff could possibly be stored in thread-local area, next to where we put errno; its contents are only significant when the thread is swapped out, and hence a user thread being able to touch this is not of concern.
The text was updated successfully, but these errors were encountered: