Skip to content

Fix the size of the domain_id passed by tick thread to caml_init_domain_self#11550

Merged
xavierleroy merged 1 commit intoocaml:trunkfrom
abbysmal:tick_thread_uintnat_to_int
Sep 21, 2022
Merged

Fix the size of the domain_id passed by tick thread to caml_init_domain_self#11550
xavierleroy merged 1 commit intoocaml:trunkfrom
abbysmal:tick_thread_uintnat_to_int

Conversation

@abbysmal
Copy link
Copy Markdown
Contributor

While investigating the s390x test suite failure at #11385, I found this error I introduced while porting the tick thread to Multicore.

The fix is pretty straightforward, and the deadlock we could see on the precheck run was caused by caml_thread_tick assuming the wrong size for domain_id (uintnat instead of int).
The compiled code would then truncate it with a (64 <- 32) load, meaning that the tick thread would initialise itself to domain 0.
This would not lead to a crash, however the way we request the tick thread to stop is by setting an integer in a domain_id indexed array:

#define Tick_thread_stop tick_thread_stop[Caml_state->id]

So if domain 1 starts up, the tick thread will see itself as being part of domain 0, and will not answer to a termination request, leading to a the main thread waiting on the join forever.

I am sorry for this mishap.

Copy link
Copy Markdown
Contributor

@xavierleroy xavierleroy left a comment

Choose a reason for hiding this comment

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

Obviously correct. Thanks for the detective work.

For those who wonder why this shows up on s390x but not on x86, say: s390x is big-endian, causing the 32-bit int tp end up in the 32 high bits of the 64-bit uintnat, then to be discarded as @Engil described.

@xavierleroy xavierleroy added this to the 5.0 milestone Sep 21, 2022
@xavierleroy xavierleroy merged commit eccc311 into ocaml:trunk Sep 21, 2022
xavierleroy pushed a commit that referenced this pull request Sep 21, 2022
@xavierleroy
Copy link
Copy Markdown
Contributor

Cherry-picked to 5.0 : 69a3e32

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants