-
Couldn't load subscription status.
- Fork 114
Flush vcpu when switching and setting domain and prove cur_vcpu_in_cur_domain #918
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
base: master
Are you sure you want to change the base?
Conversation
| "KernelInit_AI" | ||
| "$L4V_ARCH/ArchDetSchedSchedule_AI" | ||
| "$L4V_ARCH/ArchFPU_AI" | ||
| "AInvsToplevel_AI" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the new top-level theory. Having to click through all the single theories has always been annoying and a risk for forgetting one interactively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this. We now have an AI-enhanced toplevel theory :)
| \<comment> \<open>FIXME: trivial helper lemmas for vcpu_flush_integrity_hyp\<close> | ||
| lemma vcpu_invalid_active_arm_current_vcpu_not_Some[wp]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean with the FIXME that these lemmas might not be necessary or that they should be moved elsewhere?
They could go into AInvs, but if I think about fixing the FIXME, I'm not sure I would actually decide to move them if they are not used there currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I forgot about these. I think my intent was that these lemmas were so trivial that it felt like they shouldn't exist and that I should come back to them to try and find a different solution. The first one is an alternative version of vcpu_invalid_active_arm_current_vcpu_None but with a postcondition of _ ≠ Some _ instead of _ = None, and the second is basically an instantiation of hoare_pre_cont.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the first one has been replaced with strengthen None_Some_strg and the second one is now done by using an instantiated hoare_pre_cont directly in the relevant proof. Now that I'm thinking about it again, I'd say that the False precondition was a safe wp lemma but could have caused some serious confusion if that lemma applied unexpectedly elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an aside, while adding that strengthen I thought that it would be nice if it could be added to wpsimp directly instead of needing to do (wpsimp ... | strengthen ...)+. Unfortunately, it looks like strengthen can't be used in Eisbach methods, because it doesn't seem to like the dummy invocation I think it does.
exception CTERM raised (line 149 of "l4v/lib/Monads/Strengthen.thy"):
gather_to_imp
TERM _
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, interesting. I've also wondered a few times about adding strengthen to wpsimp, you got one step further with that than me :-). Maybe we can make Strengthen.thy more robust by catching the exception and defaulting to no_tac if we get one.
| lemma vcpu_invalid_active_arm_current_vcpu_not_Some'[wp]: | ||
| "\<lbrace>\<bottom>\<rbrace> vcpu_invalidate_active \<lbrace>\<lambda>_ s. arm_current_vcpu (arch_state s) = Some (v, b)\<rbrace>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting, I don't think we've done much precondition False yet for wp, but I think it works here. Kinda nice.
| modifyArchState (armHSCurVCPU_update (\<lambda>_. p)) | ||
| od" | ||
| apply (clarsimp simp: modifyArchState_def modify_modify) | ||
| apply (rule ext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried the monad_eq tactic for these? Might not be strong enough, but sometimes it is surprisingly good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the following lemmas were actually just moved from a later file. I'll do the easier cleanup from your suggestions but might leave the more involved changes for another time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries
| \<comment> \<open>FIXME: @{term cur_vcpu} could be reworked so that it could be reused here\<close> | ||
| definition cur_vcpu_tcb :: "'z::state_ext state \<Rightarrow> obj_ref option" where | ||
| "cur_vcpu_tcb s \<equiv> | ||
| case arm_current_vcpu (arch_state s) of | ||
| Some (v, _) \<Rightarrow> vcpu_tcbs_of s v | ||
| | None \<Rightarrow> None" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that FIXME something we actually want to/should do? I think we looked at it in the past, and it doesn't quite work out without changing lots of things. If that is the case, we should probably remove the FIXME, and turn it into a comment that says that we have looked at it, so we don't repeat the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make things more confusing, I think we looked at the similar active_cur_vcpu_of in ArchVCPU_AI. That one has a comment saying (* This is similar to cur_vcpu_2, but not close enough to reuse. *), presumably for exactly the reason you said. This one though is actually similar enough that I think a generalisation would work, although I'm less sure how much benefit that would have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Gerwin here, maybe an issue and fixed in another PR?
| \<comment> \<open>FIXME: generalise to other objects?\<close> | ||
| lemma set_endpoint_vcpus_of[wp]: | ||
| "set_endpoint p ep \<lbrace>\<lambda>s. P (vcpus_of s)\<rbrace>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure these are easy to generalise, they express what type the set_object works on, but anything that describes that and that is not object-level tags has the same kind of quadratic behaviour that we see here. It think the best we can do with these is a proof method (we might already have one for other projections, because it's always the same proof), and potentially some automation for stating the lemmas, given a set of basic functions. Like a crunch for projections.
Stepping away from this for a bit, we do have this pattern a few times: stating the same kind of lemma for a bunch of functions, applying the same proof method to it. Maybe that is something more general that we could actually write. It'd take a term as input that has e.g. an ?f where the function would go, a naming scheme like for crunch, a list of functions, and a proof method. It would then instantiate the pattern with the given functions, and apply the proof method to each. Could of course also be a list of patterns (same generalisation as we did for crunches). I think that might be quite useful and would help with these kinds of patterns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not that I'm suggesting this for this PR, but if people like it, I might give that a go after I finish the current platform proofs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I feel like at least be some sort of generalisation handling set_endpoint and set_notification should be possible, since set_simple_ko asserts that the object previously there was one of those types, but that's small enough that it's probably not worth trying to do.
More generally, your idea does sound pretty good but I think it would be worth doing a rough survey of the proofs first to find examples of these patterns. That would both help us decide a priority for doing this and also guide what it would look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that leads to the more immediate question, should I remove this FIXME or leave it as a signpost for if we do try out your idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the FIXME and put it in an issue (maybe with a pointer to these lemmas as an example). MCS also has a few of these where projections are established, and I remember vaguely thinking about something like this when I did RISCV64 back in the day and again in AARCH64. It never got across the threshold, but if we do it right, it might be a nice tool that can do a lot more than what we're thinking of right now.
| \<comment> \<open>FIXME: Replace earlier lemmas that don't have the Qs. These do have extra preconditions however, | ||
| so updating proofs for this might not be completely trivial.\<close> | ||
| lemma delete_objects_etcb_at': | ||
| "\<lbrace>\<lambda>s. Q (etcb_at P t s) \<and> (t \<notin> {ptr..ptr + 2 ^ bits - 1})\<rbrace> | ||
| delete_objects ptr bits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the more general versions have more preconditions, there would be value in keeping the old ones around. I.e. I'd turn the FIXME into a comment that the precondition is the reason we are keeping the old ones.
spec/abstract/AARCH64/VCPUAcc_A.thy
Outdated
| (*FIXME: find the right place to move this to, ArchTcb_A doesn't work as it is imported by VCPUAcc_A | ||
| and leads to an unresolvable circular dependency*) | ||
| definition arch_prepare_set_domain :: "obj_ref \<Rightarrow> domain \<Rightarrow> (unit,'z::state_ext) s_monad" where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is a problem that the function is here in HYP architectures and in ArchTcb_A in non-HYP architectures. I'd put a comment in the non-HYP architectures that it is in ArchTcb_A, because they don't have the VCPUAcc_A file to explain the discrepancy, and maybe leave comment here that it can't go into ArchTCB_A, because that would lead to a circular dependency. Then we know what's going on and can find things from either direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done. Amazing how those seemingly small invariants can expand into needing changes in 100 files, but that is the way of the proof. Content is good, my only comments are about resolving some of the FIXMEs so our future selves have less despair :-)
Signed-off-by: Corey Lewis <[email protected]>
Signed-off-by: Corey Lewis <[email protected]>
Signed-off-by: Corey Lewis <[email protected]>
Signed-off-by: Corey Lewis <[email protected]>
| all_invs_but_ct_idle_or_in_cur_domain'_def) | ||
| done | ||
|
|
||
| lemma vcpuInvalidateActive_corres[corres]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sanity check: this is moved, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, moved here so that it could be used in vcpuFlush_corres.
| (vcpu_save (Some cvcpu)) (vcpuSave (Some cvcpu))" | ||
| apply (clarsimp simp add: vcpu_save_def vcpuSave_def armvVCPUSave_def) | ||
| apply (cases cvcpu, clarsimp, rename_tac v active) | ||
| "corres dc (none_bot (\<lambda>vcpu. vcpu_at (fst vcpu)) cvcpu) (none_bot (\<lambda>vcpu. vcpu_at' (fst vcpu)) cvcpu and no_0_obj') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's none_bot again? it looks like a quick_print accident, but maybe I'm not familiar with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
none_bot ≡ case_option bot, with various helpful simp rules and automation.
| unfolding vcpu_flush_if_current_def vcpuFlushIfCur_def | ||
| by (corres wp: arch_thread_get_wp archThreadGet_wp) | ||
|
|
||
| crunch vcpu_flush_if_current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, seeing vcpu_flush_if_current and vcpuFlushIfCur side by side, I definitely think the latter should be vcpuFlushIfCurrent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confusingly, I went with vcpu_flush_if_current in the C as well so I'm not sure why I did the Haskell differently. Will change.
| by simp | ||
|
|
||
| lemmas corres_if2 = corres_if[unfolded if_apply_def2] | ||
| lemmas corres_when = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment on AARCH64/Schedule_R
| unfolding valid_objs_def by (auto simp: dom_def) | ||
|
|
||
| \<comment> \<open>This would be a simp rule but too many existing proofs expect valid_obj and break when it is | ||
| preemptively simplified into arch_valid_obj.\<close> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same issue with capMasterCap when arch-splitting, it simplified for the "generic" arch object case but then nothing else would work with it in the generic context. I expect this kind of thing is not uncommon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For proofs that involve things like valid_obj X Y = valid_obj X Y' or something, I'm not sure whether we'd ever want these as simp, otherwise you'd need to simp del them to deal with the generic concept of valid_obj. Hmm. Not sure about this comment in that case.
| for cte_wp_at[wp,Finalise_AI_assms]: "\<lambda>s. P (cte_wp_at P' p s)" | ||
| (simp: crunch_simps assertE_def wp: crunch_wps set_object_cte_at) | ||
|
|
||
| declare arch_post_cap_deletion_cur_thread[Finalise_AI_assms] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unusual place for this? doesn't seem to come out of the above crunches, so is this tagging a fact that was proved in another theory?
| arch_requalify_facts | ||
| resetTimer_device_state_inv | ||
| arch_decode_invocation_inv | ||
| arch_post_cap_deletion_cur_thread |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, converted to interface from a requalify. I approve!
| apply (clarsimp simp: etcb_at_def) | ||
| apply (drule get_tcb_SomeD) | ||
| apply (clarsimp simp: x etcbs_of'_def) | ||
| done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this proof looks a bit old (assumes x, wp+simp vs wpsimp), is it moved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it started as a copy of a old proof, possibly thread_set_no_change_tcb_pred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth a cleanup then?
| assumes prepare_thread_delete_idel_thread[wp] : | ||
| "\<And>t. prepare_thread_delete t \<lbrace>\<lambda>(s:: det_ext state). P (idle_thread s)\<rbrace>" | ||
| assumes prepare_thread_delete_idle_thread[wp]: | ||
| "\<And>P t. prepare_thread_delete t \<lbrace>\<lambda>s::det_state. P (idle_thread s)\<rbrace>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice typo fix. I'm also wondering why you've introduced state_ext here and used it for the stuff you've added, but the other ones use det_state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should have always had a state_ext and been using it where we could, but I think that we were lazy at the time due to most of the DetSched lemmas originally needing to be det_state anyway. This has changed since then and I'm using the ones I've added in other places where them being det_state causes problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a comment on one of the DetSched locales saying something like this and that we could be using state_ext more.
| lemma in_cur_domain_lift_weak_gen: | ||
| assumes a: "\<And>P . f \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace>" | ||
| and b: "\<And>Q. \<lbrace>\<lambda>s. P (etcb_at Q t s) \<and> P' s\<rbrace> f \<lbrace>\<lambda>_ s. P (etcb_at Q t s)\<rbrace>" | ||
| shows "\<lbrace>\<lambda>s. P (in_cur_domain t s) \<and> P' s\<rbrace> f \<lbrace>\<lambda>_ s. P (in_cur_domain t s)\<rbrace>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: I think shows should not be indented this way; it belongs more to lemma than assumes
| "\<lbrace>\<lambda>s::'state_ext state. etcb_at P t s \<and> invs s \<and> st_tcb_at (Not o inactive and Not \<circ> idle) t s \<and> ct_active s \<and> valid_untyped_inv ui s\<rbrace> | ||
| invoke_untyped ui | ||
| \<lbrace>\<lambda>_. etcb_at P t\<rbrace>" | ||
| apply (rule hoare_post_imp[where Q'="\<lambda>_ s. st_tcb_at (Not \<circ> inactive) t s \<and> (st_tcb_at (Not \<circ> inactive) t s \<longrightarrow> etcb_at P t s)"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it not make sense to clobber invoke_untyped_etcb_at?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean get rid of the original lemma? If so, the proofs that were using it are pretty fiddly and expect the implication in the postcondition, while I'm using it in more standard ways that don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, if it's used that way, sure. It ended up being confusing seeing them as additions in AARCH64 AInvs somewhere, and a change here.
| "\<lbrakk>cur_vcpu_at v s; valid_arch_state s\<rbrakk> \<Longrightarrow> | ||
| invs (s\<lparr>arch_state := arch_state s | ||
| \<lparr>arm_current_vcpu := v\<rparr>\<rparr>) = invs s" | ||
| invs (s\<lparr>arch_state := arch_state s \<lparr>arm_current_vcpu := v\<rparr>\<rparr>) = invs s" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while we're here, indentation?
|
|
||
| (* Remove this rule from [wp] here because it is not safe for proofs that involve extended state. It | ||
| is also removed in Deterministic_AI but may have been added back in during a theory merge. *) | ||
| declare dxo_wp_weak[wp del] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still feels weird that it can't be used only in the theories that need it, but leaks out like this instead.
| done | ||
|
|
||
| lemma arch_prepare_set_domain_valid_cur_vcpu[wp]: | ||
| "\<lbrace>\<lambda>s. valid_cur_vcpu s \<and> sym_refs (state_hyp_refs_of s) \<and> in_cur_domain (cur_thread s) s\<rbrace> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost tempting to have an abbreviation for (%s. in_cur_domain (cur_thread s) s) so we can keep using and. probably not worth the bother
|
|
||
| lemma handle_event_valid_cur_vcpu: | ||
| "\<lbrace>valid_cur_vcpu and invs and (\<lambda>s. e \<noteq> Interrupt \<longrightarrow> ct_active s)\<rbrace> | ||
| "\<lbrace>valid_cur_vcpu and einvs and (\<lambda>s. e \<noteq> Interrupt \<longrightarrow> ct_active s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you had a bit of a battle with handle_event... can you say something (here, not as a comment) as to how we can use einvs here, or why, or how you came up with this schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't actually the scene of that specific battle, that's in Syscall_AC. I'm using einvs here for the existing ct_in_cur_domain invariant, which says that if the scheduler action is resume_cur_thread then the current thread is either the idle thread or in the current domain. I use that to resolve the various in_cur_domain (cur_thread s) s preconditions once I'm able to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, this reminds me of the advice I tried to give, related to handle_event. Makes sense, thank you!
| apply (clarsimp simp: ex_nonz_cap_to_def valid_aci_def) | ||
| apply (frule invs_untyped_children) | ||
| apply (clarsimp simp:cte_wp_at_caps_of_state) | ||
| apply (erule_tac ptr="(aa,ba)" in untyped_children_in_mdbE[where P="\<lambda>c. t \<in> zobj_refs c" for t]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved? if not, rename_tac and spaces after :
| by (clarsimp simp: valid_cur_vcpu_def pred_tcb_at_def obj_at_def active_cur_vcpu_of_def) | ||
| lemma thread_set_valid_cur_vcpu_unchanged: | ||
| "\<lbrakk>\<And>tcb. tcb_arch (f tcb) = tcb_arch tcb; \<And>tcb. tcb_domain (f tcb) = tcb_domain tcb\<rbrakk> | ||
| \<Longrightarrow> thread_set f tptr \<lbrace>valid_cur_vcpu\<rbrace>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent on ==>
| "\<lbrace>\<lambda>s. Q (etcb_at P t s) \<and> invs s \<and> st_tcb_at (Not o inactive and Not \<circ> idle) t s \<and> ct_active s \<and> valid_untyped_inv ui s\<rbrace> | ||
| invoke_untyped ui | ||
| \<lbrace>\<lambda>_ s. Q (etcb_at P t s)\<rbrace>" | ||
| apply (rule hoare_post_imp[where Q'="\<lambda>_ s. st_tcb_at (Not \<circ> inactive) t s \<and> (st_tcb_at (Not \<circ> inactive) t s \<longrightarrow> Q (etcb_at P t s))"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feels like I commented on this before, but there the invoke_untyped_etcb_at got a ' only, instead of appearing as an addition... bit confused what happened here
|
|
||
| lemma switch_to_thread_valid_cur_vcpu[wp]: | ||
| "switch_to_thread t \<lbrace>valid_cur_vcpu\<rbrace>" | ||
| "\<lbrace>\<top>\<rbrace> switch_to_thread t \<lbrace>\<lambda>_. valid_cur_vcpu\<rbrace>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
| theory ArchVCPU_AI | ||
| imports AInvs | ||
| imports ArchDetSchedSchedule_AI | ||
| begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless I got confused during review, AARCH64 has an additional ArchVCPUDomain_AI that ARM_HYP does not... any reasons why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I actually meant to mention that when I made this PR, thanks for pointing it out. I have currently only proven cur_vcpu_in_cur_domain for AARCH64, because the way I defined it and its lemmas makes a lot of use of vcpu projections that don't exist in ARM_HYP. Backporting them feels like quite a bit of a project, as does reworking ArchVCPUDomain_AI to not use them.
One of the reasons that we're introducing this invariant is to make use of it in Infoflow and we don't have immediate plans to extend them for ARM_HYP, so I'm hoping that this is sufficient for now and we can leave further work for later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspected it was because ARM_HYP isn't heading for infoflow... but it being hinged on the projections makes sense. I agree, but I think that this should be documented somewhere... my best guess is in the commits, most likely the one that creates ArchVCPUDomain_AI; would it make sense to explain why ARM_HYP doesn't get one there?
| apply (clarsimp simp: ex_nonz_cap_to_def valid_aci_def) | ||
| apply (frule invs_untyped_children) | ||
| apply (clarsimp simp:cte_wp_at_caps_of_state) | ||
| apply (erule_tac ptr="(aa,ba)" in untyped_children_in_mdbE[where P="\<lambda>c. t \<in> zobj_refs c" for t]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments as for ARM_HYP
| by (clarsimp simp: valid_cur_vcpu_def pred_tcb_at_def obj_at_def active_cur_vcpu_of_def) | ||
| lemma thread_set_valid_cur_vcpu_unchanged: | ||
| "\<lbrakk>\<And>tcb. tcb_arch (f tcb) = tcb_arch tcb; \<And>tcb. tcb_domain (f tcb) = tcb_domain tcb\<rbrakk> | ||
| \<Longrightarrow> thread_set f tptr \<lbrace>valid_cur_vcpu\<rbrace>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent on ==>
| definition valid_cur_vcpu :: "'z::state_ext state \<Rightarrow> bool" where | ||
| "valid_cur_vcpu s \<equiv> arch_tcb_at (\<lambda>itcb. itcb_vcpu itcb = active_cur_vcpu_of s) (cur_thread s) s" | ||
| "valid_cur_vcpu s \<equiv> | ||
| in_cur_domain (cur_thread s) s \<or> cur_thread s = idle_thread s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, so we only talk about the current vcpu being valid if the current thread is in the current domain (or idle) ... after a bit of thinking, makes sense
| * | ||
| * SPDX-License-Identifier: GPL-2.0-only | ||
| *) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that this only exists on one architecture (unless I missed something), would be good to have a comment saying what this theory is for
| context Arch begin arch_global_naming | ||
|
|
||
| section \<open>cur_vcpu_in_cur_domain\<close> | ||
| \<comment> \<open>FIXME: @{term cur_vcpu} could be reworked so that it could be reused here\<close> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline above
| \<lbrace>\<lambda>_. cur_vcpu_in_cur_domain\<rbrace>" | ||
| unfolding call_kernel_def | ||
| apply (wpsimp | strengthen invs_valid_objs invs_hyp_sym_refs)+ | ||
| apply (rule hoare_post_imp[where Q'="\<lambda>irq s. irq \<notin> Some ` non_kernel_IRQs \<and> cur_vcpu_in_cur_domain s \<and> valid_sched s \<and> invs s"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is a relevant reasoning step to make the thing work, would be worth a comment... or at least what function this hoare_post_imp applies to
| for arch_tcb_vcpu_at[wp]: "\<lambda>s. (arch_tcb_at (\<lambda>itcb. P (itcb_vcpu itcb)) t s)" | ||
| (simp: crunch_simps wp: crunch_wps) | ||
|
|
||
| lemma vcpu_flush_if_current_arm_current_vcpu_None[wp]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like this isn't a good name, the postcondition is a simplified implies that says "if it's not none, then it's not the current vcpu"
| unfolding arch_perform_invocation_def | ||
| by (wpsimp simp: valid_arch_inv_def) | ||
|
|
||
| \<comment> \<open>FIXME: move (where?)\<close> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bit confused about relationship between ArchVCPUDomain_AI and ArchVCPU_AI... possibly I'd expect it to go into the latter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for the other (where?) above in the file
| "cur_vcpu_in_cur_domain (interrupt_states_update f_interrupt_states s) = cur_vcpu_in_cur_domain s" | ||
| "cur_vcpu_in_cur_domain (is_original_cap_update f_orig_cap s) = cur_vcpu_in_cur_domain s" | ||
| "cur_vcpu_in_cur_domain (arch_state_update (arm_asid_table_update f_asid_table) s) = cur_vcpu_in_cur_domain s" | ||
| "cur_vcpu_in_cur_domain (s\<lparr>arch_state := (arm_asid_table_update f_asid_table) (arch_state s)\<rparr>) = cur_vcpu_in_cur_domain s" \<comment> \<open>FIXME: previous line doesn't work for this, can it be generalised?\<close> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would depend on the underlying term. Nothing obvious springs to mind. Have you looked at it with quick_print on, maybe it shows some of the underlying structure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nitpicks and questions. This turned out to be larger and more complex than we expected. Nicely done.
For this commit, I think I would like more direction:
ainvs: add new AInvsToplevel_AI to AInvs session
In particular, this includes KernelInit along with any files proving extra
arch-specific invariants, such as ArchVCPU_AI and ArchFPU_AI.
The issue I have is that there is a structure without explanation. There is a new AInvsTopLevel_AI which must transitively include all of AInvs theories (for convenience in interactive sessions). Then, you added an extra node to each architecture named ArchAInvsTopLevel_AI which serves a similar role, but only for theories whose existence is related to the architecture, e.g. VCPU proofs. I already commented on these theories not having header comments explaining this, but the commit definitely should.
Test with seL4/seL4#1506