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

arm+arm-hyp spec+proofs: use UserContext datatype like other arches #757

Merged
merged 1 commit into from
May 30, 2024

Conversation

Xaphiosis
Copy link
Member

This reduces the diff to other architectures and FPU versions by having a UserContext datatype that contains the register state, instead of assuming the context is only the state of the registers.

Some of this touches old proofs and fitting in with style is wonky. Thoughts welcome.
This will break the FPU Arm platform port proofs, but once fixed the diff will be smaller.
Will squash commits to the above commit message (and same header as this PR) once people are ok with the changes.

@Xaphiosis Xaphiosis added cleanup proof engineering nicer, shorter, more maintainable etc proofs labels May 27, 2024
@Xaphiosis Xaphiosis requested review from lsf37 and corlewis May 27, 2024 01:14
Copy link
Member

@lsf37 lsf37 left a comment

Choose a reason for hiding this comment

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

Nice, this is a step in the right direction for making things more generic.

Comment on lines +5244 to +5248
(* FIXME MOVE *)
lemma all_Not_False[simp]:
"All Not = False"
by blast

Copy link
Member

Choose a reason for hiding this comment

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

Have you tried if moving this to somewhere in Lib breaks stuff? It looks like a generally useful thing we should always have in scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to do that now. Since I can't access pcr I'll use the PR check to see if/where it fails.

Copy link
Member Author

Choose a reason for hiding this comment

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

This causes a bunch of failure, might want to do it separately.

@@ -1220,7 +1220,10 @@ lemma getSyscallArg_ccorres_foo:
apply (simp add: word_less_nat_alt split: if_split)
apply (rule ccorres_add_return2)
apply (rule ccorres_symb_exec_l)
apply (rule_tac P="\<lambda>s. n < unat (scast n_msgRegisters :: word32) \<and> obj_at' (\<lambda>tcb. atcbContextGet (tcbArch tcb) (ARM_HYP_H.msgRegisters!n) = x!n) (ksCurThread s) s"
apply (rule_tac P="\<lambda>s. n < unat (scast n_msgRegisters :: word32)
Copy link
Member

Choose a reason for hiding this comment

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

Should this one be word32 or machine_word?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea. It's casting n_msgRegisters which is an int due to being an enumeration, so that's 32 signed word ... then it's trying to do a unat, so it's casting the signed away with scast, so technically that's to 32 word or whatever we call it on other arches (int_len word?), which is 32 even on 64 bit arches? Then again machine_word is a suitably large word to carry it, so it seems arbitrary in this case. Since you pointed it out, what do you think? :)

Copy link
Member

@lsf37 lsf37 May 30, 2024

Choose a reason for hiding this comment

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

I was mostly checking if you had thought about it. If it's not really tied to machine_word it's fine to leave as is. We'll get to think properly about this bit when we attempt splitting in CRefine

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, will leave it for now

Comment on lines -220 to +221
"getRegister r = (\<lambda>con. ({(con r, con)}, False))"
"getRegister r = (\<lambda>con. ({(user_regs con r, con)}, False))"
Copy link
Member

Choose a reason for hiding this comment

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

Had forgotten that we did these monad unfoldings here. Those are going to bite when we move to the concurrency monad, but that's a problem for future us. Nothing to do with this PR in any case.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know anything about how they're used but I don't think that it will be hard to write a similar unfolding for the trace monad. It would be a bit fiddly if we couldn't make the function atomic but even that shouldn't be too bad.

@@ -1186,7 +1187,10 @@ lemma getSyscallArg_ccorres_foo:
apply (simp add: word_less_nat_alt split: if_split)
apply (rule ccorres_add_return2)
apply (rule ccorres_symb_exec_l)
apply (rule_tac P="\<lambda>s. n < unat (scast n_msgRegisters :: word32) \<and> obj_at' (\<lambda>tcb. atcbContextGet (tcbArch tcb) (ARM_H.msgRegisters!n) = x!n) (ksCurThread s) s"
apply (rule_tac P="\<lambda>s. n < unat (scast n_msgRegisters :: word32)
Copy link
Member

Choose a reason for hiding this comment

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

machine_word? (same as on ARM_HYP)

proof/crefine/ARM/ADT_C.thy Show resolved Hide resolved
Copy link
Member

@corlewis corlewis left a comment

Choose a reason for hiding this comment

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

Very nice, definitely good to see more consistency!

setRegister :: "register \<Rightarrow> machine_word \<Rightarrow> unit user_monad"
where
"setRegister r v \<equiv> modify (\<lambda>uc. uc (r := v))"
"modify_registers f uc \<equiv> UserContext (f (user_regs uc))"
Copy link
Member

Choose a reason for hiding this comment

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

A very minor style question; do we want to explicitly state the type here like we do for getRegister and setRegister?

Copy link
Member Author

Choose a reason for hiding this comment

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

will fix

Copy link
Member Author

Choose a reason for hiding this comment

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

done

proof/refine/ARM/KHeap_R.thy Show resolved Hide resolved
proof/refine/ARM/TcbAcc_R.thy Outdated Show resolved Hide resolved
proof/refine/ARM_HYP/TcbAcc_R.thy Outdated Show resolved Hide resolved
proof/crefine/ARM/IsolatedThreadAction.thy Outdated Show resolved Hide resolved
proof/crefine/ARM/IsolatedThreadAction.thy Outdated Show resolved Hide resolved
Comment on lines -220 to +221
"getRegister r = (\<lambda>con. ({(con r, con)}, False))"
"getRegister r = (\<lambda>con. ({(user_regs con r, con)}, False))"
Copy link
Member

Choose a reason for hiding this comment

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

I don't know anything about how they're used but I don't think that it will be hard to write a similar unfolding for the trace monad. It would be a bit fiddly if we couldn't make the function atomic but even that shouldn't be too bad.

proof/drefine/Schedule_DR.thy Outdated Show resolved Hide resolved
@Xaphiosis Xaphiosis force-pushed the arm_user_context branch 3 times, most recently from 25c3ef8 to c1843c6 Compare May 30, 2024 05:12
This reduces the diff to other architectures and FPU versions by having
a UserContext datatype that contains the register state, instead of
assuming the context is only the state of the registers.

Signed-off-by: Rafal Kolanski <[email protected]>
@Xaphiosis
Copy link
Member Author

Squashed commits down to 1 and hopefully addressed all PR feedback. Will now wait for tests to make sure I didn't mess something up.

@Xaphiosis Xaphiosis merged commit 53953e7 into seL4:master May 30, 2024
13 checks passed
@Xaphiosis Xaphiosis deleted the arm_user_context branch May 30, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup proof engineering nicer, shorter, more maintainable etc proofs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants