microkit icon indicating copy to clipboard operation
microkit copied to clipboard

Remove taking the address of local variables

Open isubasinghe opened this issue 1 year ago • 10 comments

This is a change needed to verify the code (see this page on C parser restrictions), instead of taking the address of local variables we should take the address of a global variable and then copy it over to a local variable. This copy itself isn't really needed, but makes the proof somewhat nicer to express.

isubasinghe avatar Jan 17 '24 05:01 isubasinghe

This seem to be a general issue then that other code might also run into. Thus, I wonder if we should provide a version of seL4_ReplyRecv() that returns all both tag an badge then. This might apply for other API then also.

axel-h avatar Jan 17 '24 12:01 axel-h

This seem to be a general issue then that other code might also run into. Thus, I wonder if we should provide a version of seL4_ReplyRecv() that returns all both tag an badge then. This might apply for other API then also.

It would actually be nice to survey libsel4 for those kinds of things. I wonder if returning a tuple (struct) here would also work nicer with the Rust interface. @nspin do you have any input on that? It doesn't seem to me like there'd be any real performance impact since this is just a word.

lsf37 avatar Jan 17 '24 21:01 lsf37

I wonder if returning a tuple (struct) here would also work nicer with the Rust interface. @nspin do you have any input on that?

The Rust bindings already do, e.g https://sel4.github.io/rust-sel4/views/aarch64-microkit/aarch64-sel4-microkit/doc/sel4/struct.LocalCPtr.html#method.reply_recv.

Ivan-Velickovic avatar Jan 17 '24 23:01 Ivan-Velickovic

This seem to be a general issue then that other code might also run into. Thus, I wonder if we should provide a version of seL4_ReplyRecv() that returns all both tag an badge then. This might apply for other API then also.

It would actually be nice to survey libsel4 for those kinds of things. I wonder if returning a tuple (struct) here would also work nicer with the Rust interface. @nspin do you have any input on that? It doesn't seem to me like there'd be any real performance impact since this is just a word.

It would be nice if we can get the code in libsel4 itself in a position where we can pass it off to the C parser. I believe it's really CallWithMRs that is problematic.

This is one thing that somewhat impacts the ability to get verification as a part of the CI pipeline. We can talk more about this tomorrow.

isubasinghe avatar Jan 18 '24 05:01 isubasinghe

These changes make the code no longer thread-safe. Is it meant to be?

wom-bat avatar Feb 28 '24 20:02 wom-bat

These changes make the code no longer thread-safe. Is it meant to be?

All PDs are single-threaded (and I don’t think the code was thread safe to begin with actually)

Ivan-Velickovic avatar Feb 28 '24 22:02 Ivan-Velickovic

Given this is all internal static functions, it seems fine. But I wonder if the variables should be made static at least? What is the state about the approach suggested in https://github.com/seL4/microkit/pull/92#issuecomment-1895669349, to solve this for a wider usage, is there a plan to try this?

axel-h avatar Feb 28 '24 23:02 axel-h

The new globals introduced in this PR can probably be static sure.

Yes, to my knowledge we'd still like to try change libsel4 to return a struct instead. Main focus regarding verification is automating it so that it can be put into CI. Once that is finished I assume @isubasinghe will have more time to return to this.

Ivan-Velickovic avatar Feb 29 '24 00:02 Ivan-Velickovic

Just an update to what I've done regarding verification is that I've kept these changes and changed libsel4 and the python gen tool to emit /* DONT_TRANSLATE */ comments before every libsel4 function.

This was the quickest way to automate the verification process. I have a slight preference to doing what I've done here because it requires little change to libsel4, but happy to make the changes to return structs if there is consensus that that approach is better.

isubasinghe avatar Feb 29 '24 00:02 isubasinghe

make the changes to return structs

It would break the API, so that might be a tough step. If we add a new set of functions with the new interface it might allow a transition for users that care.

axel-h avatar Feb 29 '24 02:02 axel-h

Closing because @isubasinghe won't be pursuing this anymore and we are likely looking at a change to verification tooling that would not need this patch.

If we do need it we can always re-open.

Ivan-Velickovic avatar Jul 02 '24 02:07 Ivan-Velickovic