Skip to content

TB: Track permissions on the byte-level #4314

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

Merged
merged 2 commits into from
May 30, 2025

Conversation

yoctocell
Copy link

This makes the tracking of permissions on the byte-level, like in Stacked Borrows, which makes the tracking of interior mutable data more fine-grained.

cc @RalfJung @JoJoDeveloping

@JoJoDeveloping
Copy link
Contributor

So, how does adding a new node work (and why do we need to call visit_freeze_sensitive three times:

  • First, you do a read access at the parent node
  • Then, you add the new node. Note that adding a new node is a per-block operation, not per-access
  • Then you set the correct permissions for the new node
  • Then you reset the SIFA thingy (also per-block)
  • Then you call into the data race model

For Stacked Borrows, there are no per-block operations: each stack at each offset its own stack and completely independent from the other ones at different offsets in the same allocation. So there, more (basically everything) can be moved into the per-offset function.

So what do we do for Tree Borrows? One answer is to combine parent reading, permission setting and data race notifying together. This would be somewhat ugly, because you're constructing a node, while also accessing the tree, and this would only be fine because you're careful to not actually add the node into the children array of its parent so that it's not visited when walking the tree.

Should we do this?

@RalfJung
Copy link
Member

Ignoring the SIFA thingy since I already forgot how it works, what I think would make sense is to do a single visit_freeze_sensitive where you

  • do the parent access
  • do the data race access
  • prepare a RangeMap<LocationState> of per-location initial states that will later be passed to Tree::new_child

Does that makes sense or is it too ugly as well?

@JoJoDeveloping
Copy link
Contributor

JoJoDeveloping commented May 12, 2025

That would work. It has to construct an extra RangeMap but presumably this is cheaper than calling visit_freeze_sensitive thrice.
And it requires moving some logic for retags around quite a bit.

@RalfJung
Copy link
Member

presumably this is cheaper than calling visit_freeze_sensitive thrice.

I'm not sure, but that's at least plausible. I also prefer it conceptually.

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

Thanks! This is a lot better.

I don't fully understand the logic around the new perms_map though. It seems like the map is created to cover all the bytes from the beginning of the allocation to the end of the retagged place, which is odd -- it should be either the entire allocation, or just the place. And given that we do not want to actually put anything into the perms map outside the place, I think it should be just the place.

@RalfJung
Copy link
Member

I have pushed a commit with various minor cleanups -- please take a look, I hope they make sense. :)

However, in doing so I stumbled upon a question I could not answer.

@RalfJung RalfJung force-pushed the fine-grained-tracking branch from e705a08 to d518dcf Compare May 23, 2025 09:12
Copy link
Contributor

@JoJoDeveloping JoJoDeveloping left a comment

Choose a reason for hiding this comment

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

There's one more nit about the fact that we use LocationState::new_init even if no initial access happens. (This is one of those cases where init means initialized instead of initial, one that should be renamed presumably)

@yoctocell yoctocell force-pushed the fine-grained-tracking branch from 965ae31 to 575e901 Compare May 27, 2025 16:02
@RalfJung
Copy link
Member

Thanks, I think the logic is all good now! Now it's just fine-tuning comments and names.

Also there is one case where I wonder if we want a test to ensure that this is what we are doing -- if there even could be such a test.

@rustbot author

@rustbot rustbot added the S-waiting-on-author Status: Waiting for the PR author to address review comments label May 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 28, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@yoctocell yoctocell force-pushed the fine-grained-tracking branch from 432ea98 to f2d791b Compare May 30, 2025 08:33
@yoctocell
Copy link
Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels May 30, 2025
@RalfJung
Copy link
Member

RalfJung commented May 30, 2025

All right, I think this is ready. :)
Please squash the commit history so that each commit makes independent sense. If that's too much work you can also squash everything into a single commit. (./miri squash can help you do that.)

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels May 30, 2025
@yoctocell yoctocell force-pushed the fine-grained-tracking branch from 88e78aa to 876f534 Compare May 30, 2025 12:21
@RalfJung
Copy link
Member

Looking at the diff of what you pushed, you removed one line from the comment for new_child...? What happened there?^^

@RalfJung
Copy link
Member

FWIW the comment was outdated, it should say default_perm now.

Xinglu Chen and others added 2 commits May 30, 2025 14:39
@yoctocell
Copy link
Author

Oops, probably an error I made when trying to fix some merge conflict when splitting the commits

@yoctocell yoctocell force-pushed the fine-grained-tracking branch from 876f534 to 5b885ad Compare May 30, 2025 12:44
@RalfJung
Copy link
Member

Now it looks right. :) Great work, let's land this!

@RalfJung RalfJung enabled auto-merge May 30, 2025 13:04
@RalfJung RalfJung added this pull request to the merge queue May 30, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2025
@RalfJung RalfJung added this pull request to the merge queue May 30, 2025
@RalfJung
Copy link
Member

Looks like a timeout, let's try this again...

Merged via the queue into rust-lang:master with commit 46e891c May 30, 2025
8 checks passed
@RalfJung
Copy link
Member

RalfJung commented May 30, 2025

Now that we landed this, I realize... maybe we should put this behind a flag? Or have a flag to turn it off? Some people may wake up soon seeing their CI fail since they were testing with TB and this change affects their code.^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: Waiting for the PR author to address review comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants