Skip to content
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

Fix thread pointer calculation, rework TaskTLS #311

Merged
merged 6 commits into from
Dec 4, 2021

Conversation

mkroening
Copy link
Member

@mkroening mkroening commented Dec 2, 2021

Closes hermit-os/hermit-rs#170. 🎉

Replaces #305.

Depends on:

The cause of the issue is the calculation of the thread pointer:

# Current calculation (wrong)
thread_ptr = tls_block_ptr + round(tls_len, 32)

# Correct calculation
thread_ptr = tls_block_ptr + round(tls_len, tls_align)
# round(tls_len, tls_align) is called tls_offset

This is fixed in the first two commits of this PR.

The later commits completely rework the TaskTLS struct. I did this to better understand the problem. The old comments were partly outdated and wrong. Also the code was not very rusty. I replaced manual memory allocations with Boxes and restructured and recommented the code.

@mkroening mkroening self-assigned this Dec 2, 2021
@mkroening mkroening force-pushed the thread-local-align branch 2 times, most recently from 8966d80 to 709eea3 Compare December 2, 2021 22:41
@mkroening mkroening force-pushed the thread-local-align branch 2 times, most recently from 58d1bda to 8ed6cbb Compare December 3, 2021 16:50
bors bot added a commit to hermit-os/uhyve that referenced this pull request Dec 3, 2021
241: BootInfo: Add tls_align r=mkroening a=mkroening

See

* hermit-os/kernel#311

Co-authored-by: Martin Kröning <[email protected]>
@mkroening mkroening force-pushed the thread-local-align branch 2 times, most recently from e5504bc to 7a9119b Compare December 3, 2021 17:46
bors bot added a commit to hermit-os/loader that referenced this pull request Dec 3, 2021
46: BootInfo: Add tls_align r=mkroening a=mkroening

See

* hermit-os/kernel#311

Co-authored-by: Martin Kröning <[email protected]>
@mkroening mkroening force-pushed the thread-local-align branch 2 times, most recently from 11a9160 to 8a5c534 Compare December 4, 2021 11:48
@mkroening mkroening marked this pull request as ready for review December 4, 2021 11:51
@mkroening mkroening changed the title Rework TLS creation Fix thread pointer calculation, rework TaskTLS Dec 4, 2021
bors bot added a commit to hermit-os/uhyve that referenced this pull request Dec 4, 2021
241: BootInfo: Add tls_align r=stlankes a=mkroening

See

* hermit-os/kernel#311

Co-authored-by: Martin Kröning <[email protected]>
bors bot added a commit to hermit-os/uhyve that referenced this pull request Dec 4, 2021
241: BootInfo: Add tls_align r=stlankes a=mkroening

See

* hermit-os/kernel#311

Co-authored-by: Martin Kröning <[email protected]>
bors bot added a commit to hermit-os/uhyve that referenced this pull request Dec 4, 2021
241: BootInfo: Add tls_align r=stlankes a=mkroening

See

* hermit-os/kernel#311

Co-authored-by: Martin Kröning <[email protected]>
bors bot added a commit to hermit-os/uhyve that referenced this pull request Dec 4, 2021
241: BootInfo: Add tls_align r=stlankes a=mkroening

See

* hermit-os/kernel#311

Co-authored-by: Martin Kröning <[email protected]>
@mkroening
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Dec 4, 2021
311: Fix thread pointer calculation, rework TaskTLS r=mkroening a=mkroening

Closes hermit-os/hermit-rs#170. 🎉 

Replaces #305.

Depends on:

* hermit-os/loader#46
* hermit-os/uhyve#241

The cause of the issue is the calculation of the thread pointer:

```python
# Current calculation (wrong)
thread_ptr = tls_block_ptr + round(tls_len, 32)

# Correct calculation
thread_ptr = tls_block_ptr + round(tls_len, tls_align)
# round(tls_len, tls_align) is called tls_offset
```

This is fixed in the first two commits of this PR.

The later commits completely rework the `TaskTLS` struct. I did this to better understand the problem. The old comments were partly outdated and wrong. Also the code was not very rusty. I replaced manual memory allocations with `Box`es and restructured and recommented the code.

Co-authored-by: Martin Kröning <[email protected]>
@bors
Copy link
Contributor

bors bot commented Dec 4, 2021

Build failed:

Separately allocate the TLS block and the thread pointer in Boxes for
easier dropping.
Completely rewrite and comment TLS creation.
@mkroening
Copy link
Member Author

bors retry

@bors
Copy link
Contributor

bors bot commented Dec 4, 2021

@bors bors bot merged commit 73994fd into hermit-os:master Dec 4, 2021
@mkroening mkroening deleted the thread-local-align branch December 4, 2021 21:20
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.

Deadlock on recent nightlies with release profile
1 participant