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

gnt: Avoid double unmapping on domain cleanup #5

Merged

Conversation

last-genius
Copy link
Contributor

Oxenstored itself, when cleaning up domains and connections, can call Gnt.unmap transitively several times. Under certain conditions, this can later result in a segfault bringing oxenstored down when it tries to use a freed grant.

Set the mmap_interface pointer to NULL after the first attempt so that it can be detected on the subsequent ones.

Since we are already at it, bring out accesses to OCaml fields out of the critical section.

@last-genius
Copy link
Contributor Author

This resolves the issue I was seeing with PVH unikernels, confirmed in manual testing.

caml_failwith ("Failed to unmap grant");
}
xengnttab_handle* xgt = _G(xgh);
void* start_address = _M(array)->addr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would the code clearer without the alias that we create here for M(array)->addr? So not declaring start_address and using the pointer instead in all places? Because then the NULL-ing becomes more obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_M accesses an OCaml object, so we need some kind of alias anyway to only access C objects inside the critical section

gnt/gnttab_stubs.c Outdated Show resolved Hide resolved
Copy link
Member

@robhoes robhoes left a comment

Choose a reason for hiding this comment

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

While you're here, perhaps do a similar refactor of stub_gnttab_map_fresh?

Oxenstored itself, when cleaning up domains and connections, can call
Gnt.unmap transitively several times. Under certain conditions, this can
later result in a segfault bringing oxenstored down when it tries to use
a freed grant.

Set the mmap_interface pointer to NULL after the first attempt so that it can
be detected on the subsequent ones.

Since we are already at it, bring out accesses to OCaml fields out of the
critical section.

Signed-off-by: Andrii Sultanov <[email protected]>
@last-genius last-genius force-pushed the private/asultanov/double-unmap branch from 013ea17 to 24b70bc Compare January 23, 2025 08:05
@last-genius
Copy link
Contributor Author

Addressed the suggestions, retested - looks good.

@last-genius last-genius merged commit d854ac1 into xapi-project:main Jan 23, 2025
2 checks passed
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.

3 participants