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

make proofs generic in cacheLineBits #814

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

make proofs generic in cacheLineBits #814

wants to merge 8 commits into from

Conversation

lsf37
Copy link
Member

@lsf37 lsf37 commented Sep 2, 2024

  • import cacheLineBits from config (only used on Arm, defined but unused on RISCV, fixed on x64)
  • check basic properties in Arch_Kernel_Config_Lemmas
  • remove all other unfoldings apart from cacheLineBits_val which is used in ARM and ARM_HYP to fold C values (safe, because the range of values for cacheLineBits is small)
  • the proof updates are similar between ARM and ARM_HYP, and a bit different in AARCH64, where most of it was already generic. They are now all based on the same principles.

There is a bunch of commits. I think they make reasonable sense as logical units, but happy to be persuaded otherwise if people want more squashing.

This changes bring Cortex-A72 into the ARM/ARM_HYP range.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
Use generated CONFIG_L1_CACHE_LINE_SIZE_BITS as source of truth for
the value of cacheLineBits

The requirements for cacheLineBits are numeric: we need more than 1 and
less than or equal to ptBits, which is only available as a constant
after ExecSpec.

1 is excluded, because we want to be able to fold the value of
cacheLineBits inside C cache operations, and 1 is mentioned as index
increment. No other numerals conflict in these functions.

The only observed values for cacheLineBits are 5 and 6 on Arm, but
there is no need to be more restrictive than cacheLineBits_sanity.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
None of the unfoldings of cacheLineBits turn out to be necessary.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
addrFromPPtr_mask and ptrFromPAddr_mask are only needed for masking with
cacheLineBits in CRefine. Move to CRefine where the rest of the
cacheLineBits infrastructure is.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
@lsf37 lsf37 added the platforms making proofs generic in platform and config settings label Sep 2, 2024
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
On AArch64 we have so far only seen cacheLineBits = 6 in the kernel.

To be future-proof, bring AArch64 proofs into line with AArch32 anyway,
rename cacheLineSize to cacheLineBits to stay consistent, and make proof
generic in cacheLineBits.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
apply (simp flip: mask_eqs(7))
done

(* ------------ *)
Copy link
Member

Choose a reason for hiding this comment

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

Not a fan of this. It's not clear what it's for. Is it the end of the cache line bits, the end of the informal abstraction interface, or what.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, what we usually do is error "..." -- I'll use that here as well.

Copy link
Member

Choose a reason for hiding this comment

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

Er, what? Why not remove it like it was previously and have two new lines to the next "section"? I don't think I know what error means in this context.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, my comment somehow went into the wrong box, it was supposed to be an answer to the next one down (the "Overwritten in Isabelle" bit).

For this one, the problem was that the entire configuration section has no end, it just keeps going into abbreviations for notifications etc, which is weird. You're right that the divider is not great either. I guess the proper way to do this would be to find a good name for whatever comes next.

Copy link
Member

Choose a reason for hiding this comment

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

At that point, it makes sense to give it a section/subsection for the configuration part, and/or end it with (* end of Kernel_Config interface section *) or something, then the general chaos can continue afterwards without a good name.

@@ -164,7 +164,7 @@ cacheInvalidateL2RangeCallback _ _ _ = return ()
cacheCleanL2RangeCallback :: Ptr CallbackData -> PAddr -> PAddr -> IO ()
cacheCleanL2RangeCallback _ _ _ = return ()

-- For the ARM1136
-- Overwritten in Isabelle
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 like this phrase. Don't we have an existing one that makes sense already? I'm not sure it's "overwritten in Isabelle", but rather it's clobbered by the abstract spec, or (non-exclusive) it's not imported by the translator.

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe unused by the design/exec spec ...

Copy link
Member

@Xaphiosis Xaphiosis Sep 9, 2024

Choose a reason for hiding this comment

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

Ah, this is what the error comment was about. Yes, might be good to error them out.


(* Folding cacheLineBits_val in C functions only works reliably if cacheLineBits is not 1 and
not too large to conflict with other values used inside cache ops.
12 is ptBits, which is only available after ExecSpec. Anything smaller than ptBits works. *)
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of a worry, since it's a purely syntactic restriction. What is the risk that the proofs will fail in the future due to the appearance of some other number that happens to be the same as cacheLineBits?

not too large to conflict with other values used inside cache ops.
10 is ptBits, which is only available after ExecSpec. Anything smaller than ptBits works. *)
lemma cacheLineBits_sanity:
"cacheLineBits \<in> {2..10}"
Copy link
Member

Choose a reason for hiding this comment

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

would it make sense to say ptBits for these instead of the ..10 or whatever and have a [simplified ptBits_def] or whatever on the lemma statement?

Copy link
Member

Choose a reason for hiding this comment

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

oh right, "which is only available after ExecSpec". Hmm. Nitpick: "anything smaller than" and "not 1" don't gel together well

by (simp add: pageBits_def)

lemma pageBits_leq_pptrBaseOffset_alignment:
"pageBits \<le> pptrBaseOffset_alignment"
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit lost, is pptrBaseOffset_alignment related to cache line size?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it's larger :-)

The relationship is that addrFromPPtr alignment is preserved by anything smaller or equal to pptrBaseOffset_alignment, which is what we need for the .. && mask cacheLineBits = ... lemma


lemma ptBits_leq_pdBits:
"ptBits \<le> pdBits"
by (simp add: pt_bits_def pd_bits_def pde_bits_def pte_bits_def)
Copy link
Member

Choose a reason for hiding this comment

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

it's odd to me that the above two lemmas are in the cacheLineBits interface section

by (simp add: pd_bits_def APIType_capBits_def pde_bits_def)

lemma cacheLineBits_le_PageDirectoryObject_sz:
"cacheLineBits \<le> APIType_capBits PageDirectoryObject us"
Copy link
Member

Choose a reason for hiding this comment

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

what's the intuition behind this constraint?

@@ -3129,18 +3130,13 @@ lemma ccorres_return_void_C':
done

lemma is_aligned_cache_preconds:
"\<lbrakk>is_aligned rva n; n \<ge> 7\<rbrakk> \<Longrightarrow> rva \<le> rva + 0x7F \<and>
addrFromPPtr rva \<le> addrFromPPtr rva + 0x7F \<and> rva && mask 6 = addrFromPPtr rva && mask 6"
"\<lbrakk>is_aligned rva n; n \<ge> 7\<rbrakk> \<Longrightarrow> rva \<le> rva + 0x7F \<and> addrFromPPtr rva \<le> addrFromPPtr rva + 0x7F"
Copy link
Member

Choose a reason for hiding this comment

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

do you happen to know where the 7 and 0x7F come from here? I'm wondering if it's related to cache line size in any way, or from somewhere else

"ccorres dc xfdc
(\<lambda>s. vs \<le> ve \<and> ps \<le> ps + (ve - vs)
\<and> vs && mask cacheLineBits = ps && mask cacheLineBits
\<comment> \<open>ahyp version translates ps into kernel virtual before flushing\<close>
Copy link
Member

Choose a reason for hiding this comment

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

while we're here, could you change ahyp to arm-hyp?

field_simps is_aligned_mask[symmetric] mask_AND_less_0)+
field_simps is_aligned_mask[symmetric] mask_AND_less_0
cacheLineBits_le_PageDirectoryObject_sz[unfolded APIType_capBits_def,
simplified])+
Copy link
Member

Choose a reason for hiding this comment

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

By the way, are you aware of @ from Rule_By_Method? We might be able to abbreviate these kinds of things with [@<simp add: APIType_capBits_def>]

Copy link
Member

Choose a reason for hiding this comment

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

(not needed in this one, but more general observation)

(\<lbrace>\<acute>start = w1\<rbrace> \<inter> \<lbrace>\<acute>end = w2\<rbrace> \<inter> \<lbrace>\<acute>pstart = w3\<rbrace>) []
(doMachineOp (cleanCacheRange_PoU w1 w2 w3))
(Call cleanCacheRange_PoU_'proc)"
apply (rule ccorres_gen_asm)
apply (cinit' lift: start_' end_' pstart_')
apply (fold cacheLineBits_val)
Copy link
Member

Choose a reason for hiding this comment

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

I think some kind of comment on this line (and in other lemmas) would be good, it's the linchpin of this whole exercise.

Copy link
Member

@Xaphiosis Xaphiosis left a comment

Choose a reason for hiding this comment

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

Minor comments and questions, else good. Nice to have these abstractions, updating this was a pain all the times we went 5->6->5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platforms making proofs generic in platform and config settings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants