Skip to content

Preserve Linux xstate in exception contexts#556

Merged
xrme merged 3 commits into
Clozure:masterfrom
luciusmagn:lho/fix/linux-x86-64-xstate
Jul 20, 2026
Merged

Preserve Linux xstate in exception contexts#556
xrme merged 3 commits into
Clozure:masterfrom
luciusmagn:lho/fix/linux-x86-64-xstate

Conversation

@luciusmagn

Copy link
Copy Markdown
Contributor

Hi guys,

this is my first time contributing to Clozure, so I am not sure if there is a process I am forgetting.

I am submitting a (maybe a little opinionated) small fix for xstate handling.

On x86-64, the interrupted CPU register is carried by signals in a signal frame, and modern CPUs have AVX/other extended register state stored in the XSAVE area (see https://criu.org/Xsave, https://www.kernel.org/doc/html/latest/arch/x86/xstate.html, https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/sigcontext.h).

Atm, when relocating a signal context, CCL copies only the old fixed-size FP/SSE portion of the frame. The copy can still advertise an extended XSAVE area that it does not contain, causing AVX and other extended register state to be discarded on signal return.

This should not break anything, if the extended metadata is missing or invalid, we copy the fp/sse portion and clear the marker so linux treats it as legacy.

I believe this is tangentially related to #85 which shows a bad frame crash as well. This should probably be fixed on x86-32 as well, I can do it if yall want.

Thank you for your time

@luciusmagn

Copy link
Copy Markdown
Contributor Author

I made a small example here: https://github.com/luciusmagn/xsave-failure

@xrme xrme left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please write a comment about the source of magic number words and the purpose of the other constants and then this will be ready to merge

A nice change. If you want to make a similar, separate change for 32-bit x86, I'll be happy to accept that.

Comment thread lisp-kernel/x86-exceptions.c
@luciusmagn
luciusmagn force-pushed the lho/fix/linux-x86-64-xstate branch from 11bfbb9 to ac42534 Compare July 19, 2026 10:34
@luciusmagn

Copy link
Copy Markdown
Contributor Author

Please write a comment about the source of magic number words and the purpose of the other constants and then this will be ready to merge

A nice change. If you want to make a similar, separate change for 32-bit x86, I'll be happy to accept that.

Thanks a lot, I have added support for 32-bit x86, please check it out whenever you can :)

@luciusmagn
luciusmagn requested a review from xrme July 19, 2026 22:20
@xrme
xrme merged commit 91638d1 into Clozure:master Jul 20, 2026
1 of 2 checks passed
@xrme

xrme commented Jul 20, 2026

Copy link
Copy Markdown
Member

Thank you for the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants