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

bind minios function virt_to_mfn #4

Merged
merged 1 commit into from
Oct 29, 2018
Merged

Conversation

cfcs
Copy link

@cfcs cfcs commented Mar 16, 2018

This is currently needed for speaking to Qubes GUId, suspect it could be useful for other applications dealing with RPC between Xen domU too.

ping @hannesm who complained this wasn't upstreamed :)

@hannesm
Copy link
Member

hannesm commented Mar 17, 2018

thanks @cfcs. I'm curious about naming (since mfn is not obvious to me, should we rather write its full name?). any other opinions on naming?

@cfcs
Copy link
Author

cfcs commented Mar 18, 2018

It wasn't obvious to me either, but mfn is the Xen term, and virt_to_mfn is the name of the C function bound. This function is only of use if you're doing something Xen-related, in which case you'll go looking for virt_to_mfn - there's no "civilian" use case.

I think it's better to align with Xen and use the upstream terminology (and function names, where we are just wrapping their API).
Doing so makes it easier to reason about code if you know what the C code does, and if you don't know what it does then it's easier to look up information. The PR includes some links in the doc-string, and a brief explanation in the C stub also, for when you're browsing the C code - I feel that should be enough. Again, this function is only used when confronted with the explicit need to communicate MFNs, in which case whatever you're communicating with will also be talking about MFNs.

Copy link
Member

@hannesm hannesm left a comment

Choose a reason for hiding this comment

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

Thanks for the clarification, @cfcs. This is IMHO good to go, but I'd be happy if someone with more C-OCaml knowledge would approve the changes (esp. regarding required allocations).

//cc @djs55 @samoht @yallop @talex5

@cfcs
Copy link
Author

cfcs commented Mar 21, 2018

FWIW I have no idea if it's correct; I've been using it for ~six months without obvious problems, but I have no good way to tell if it is leaking memory, or is potentially returning wrong results. I tried to read the instructions in caml/memory.h, but it made me none the wiser, and doesn't mention the need to free() any of these variables. It is my impression that the CAMLreturn macro takes care of marking stuff for collection, but this is not an empirical assertion.

Looking at the defintions of CAMLreturn and CAMLlocal I wonder if using the local variable is overkill.

I also wonder if Nativeint_val may be wrong - is Nativeint aligned with uintptr_t?
Maybe. See config.h I guess. Is it a problem that intnat is a signed integer? Maybe, probably not, probably depends on the architecture. Thank god Xen doesn't run on that many.
virt_to_mfn(x) seems to end up in a macro casting to (unsigned long)(x) before processing, and it also returns an unsigned long, so that seems fine for all architectures where intnat is long and sizeof(unsigned long) == sizeof(long) == sizeof(intnat).
My guess is that nativeint will fit a pointer on any platform Xen runs on, today, but I have no idea how to confirm it.

These anxieties are kind of the reason for not upstreaming earlier, I've yet to find a guide on how to deal with things like this.

EDIT: Seems like OCaml doesn't use pointers for its values, but uses signed ints instead.s/pointer/sint/g above.

@yallop
Copy link
Member

yallop commented Mar 21, 2018

My guess is that nativeint will fit a pointer on any platform Xen runs on, today, but I have no idea how to confirm it.

Being pointer-width is part of the interface to nativeint. The nativeint documentation says:

This integer type has exactly the same width as that of a pointer type in the C compiler.

@mato
Copy link
Contributor

mato commented Mar 21, 2018

@cfcs I didn't know OCaml had a nativeint, that does indeed look like the correct type to use here. As for whether or not you need the CAMLlocal1; there are places in the Solo5 bindings where I do a direct CAMLreturn(caml_copy_int64(...)) so I guess not.

On a more general note, I realise we don't have any hard guidelines on what goes in OS but I'd be happier if this Xen-specific interface were exposed as OS.Xen.virt_to_mfn rather than going in OS.Heap_pages. See mirage/mirage-solo5@61925cf for an example of a Solo5-specific interface done this way.

@cfcs
Copy link
Author

cfcs commented Mar 21, 2018

@mato I think that makes sense, to have backend-specific modules separate from the rest. Ideally I guess there'd be some kind of common signatures for these shared modules to avoid the different backends growing apart?

@mato
Copy link
Contributor

mato commented Mar 21, 2018 via email

@hannesm
Copy link
Member

hannesm commented Apr 1, 2018

@cfcs could you move the virt_to_mfn functionality into OS.Xen.virt_to_mfn as proposed by @mato -- then we should be good to go! :)

@cfcs cfcs force-pushed the expose_virt_to_mfn branch from ad1ac6e to 4dcdff1 Compare April 4, 2018 15:41
@cfcs
Copy link
Author

cfcs commented Apr 4, 2018

I moved to a new Xen module and force-pushed (IMHO everything Xen-only should have been under a Xen module to begin with, but it doesn't make sense to break everything by moving now, so ... ) .

@hannesm
Copy link
Member

hannesm commented May 1, 2018

@mato since you requested the last change (now known as OS.Xen.virt_to_mfn), do you approve this PR?

@mato
Copy link
Contributor

mato commented May 1, 2018

@hannesm Yes, the change looks fine, however looking at the raw commit, the Author: is Your Name <[email protected]> -- is that OK for committing to MirageOS?

@cfcs
Copy link
Author

cfcs commented May 1, 2018

@mato That's my moniker, what harm could it do?

@mato
Copy link
Contributor

mato commented May 2, 2018

@mato That's my moniker, what harm could it do?

@cfcs I don't mind pseudonyms but the author email goes in the Git history, and I'd prefer that we have a valid-in-good-faith email as a point of contact in case we ever need to contact contributors. I very much doubt that [email protected] is indeed your email address :-)

cfcs pushed a commit to cfcs/mirage-framebuffer that referenced this pull request Jun 13, 2018
@hannesm hannesm merged commit e2b134d into mirage:master Oct 29, 2018
@hannesm
Copy link
Member

hannesm commented Oct 29, 2018

this looks reasonable to me, and has been reviewed by several people. I don't see a reason to require a (valid!?!) email address for maybe contacting contributors -- this is ISC licensed anyways, and email addresses are getting invalid over time (if you leave an organisation / company / university).

@cfcs cfcs deleted the expose_virt_to_mfn branch October 29, 2018 23:16
@mato mato mentioned this pull request Jul 24, 2020
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.

4 participants