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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions gnt/gnttab_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,26 @@ stub_gnttab_unmap (value xgh, value array)
{
CAMLparam2 (xgh, array);
int result;

caml_enter_blocking_section ();
result = xengnttab_unmap (_G (xgh), _M (array)->addr,
_M (array)->len >> XEN_PAGE_SHIFT);
caml_leave_blocking_section ();

if (result != 0)
{
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

uint32_t count = _M(array)->len >> XEN_PAGE_SHIFT;
char s[64];

/* Check if this grant hasn't already been unmapped before */
if (start_address) {
caml_enter_blocking_section ();
result = xengnttab_unmap (xgt, start_address, count);
caml_leave_blocking_section ();
/* Avoid double unmapping by NULL-ing the pointer */
_M(array)->addr = NULL;
_M(array)->len = 0;

if (result != 0)
{
int r = snprintf(s, 64, "Failed to unmap grant (errno %d, rc %d)", errno, result);
caml_failwith(s);
}
}

CAMLreturn (Val_unit);
}
Expand All @@ -94,12 +104,13 @@ stub_gnttab_map_fresh (value xgh,
CAMLparam4 (xgh, reference, domid, writable);
CAMLlocal1 (contents);
void *map;
xengnttab_handle* xgt = _G(xgh);
uint32_t domid_c = Int_val(domid);
uint32_t ref = Int_val(reference);
int prot = Bool_val (writable) ? PROT_READ | PROT_WRITE : PROT_READ;

caml_enter_blocking_section ();
map = xengnttab_map_grant_ref (_G (xgh), Int_val (domid),
Int_val (reference),
Bool_val (writable) ? PROT_READ |
PROT_WRITE : PROT_READ);
map = xengnttab_map_grant_ref (xgt, domid_c, ref, prot);
caml_leave_blocking_section ();

if (map == NULL)
Expand Down
Loading