Peek-before-flush for EVP cached state: is there a real race, and does it help?
https://github.com/openssl/openssl/pull/30739Here's a draft for the updated post. The bracketed parts get filled in from the code review once it finishes, so nothing here claims more than we've checked.
> I'd like feedback from the Academics community on a concurrency pattern for OpenSSL's EVP internal cached state.
>
> The pattern. A caller first does a read-only sweep (a peek) of the cached state. If the cached value is clean, it returns without taking a lock. If the peek finds the state dirty, a flush uses a compare-and-exchange to settle it, so two threads can't overwrite each other's update. Only after a confirmed flush does the caller store the new value. On platforms that fall back to locks, such as NonStop, one write lock covers both the check and the settle, so there's no double-locking.
>
> What it targets. [The specific EVP path, with file and line at a named OpenSSL commit, for example the TLS handshake digest or the EVP fetch cache.] [Whether a lost-update race or measurable lock contention exists there today. If not, I'll say so.]
>
> Evidence so far. [Benchmark results with machine details, or "not measured yet".] [Whether the prototype compiles against current master and is correct on memory ordering.]
>
> Related work. Double-checked locking, seqlocks, RCU, and OpenSSL's own ossl_rcu primitives. I'd especially like to hear how this compares to ossl_rcu for these paths.
>
> Background. I first proposed this as [PR #30739](https://github.com/openssl/openssl/pull/30739), which was closed in April. I'm not asking to reopen it. I'm bringing the idea here as a research question, because I think its value, if it has any, should be judged on evidence.
>
> AI disclosure. [Which AI tools you used and for what, e.g. drafting code, analysis, or writing.]
>
> Critique is very welcome, especially if this turns out to duplicate something OpenSSL already does.
The AI disclosure line needs your own words. The evidence sections will come from the review.