Module Name: src Committed By: riastradh Date: Thu Feb 23 02:58:41 UTC 2023
Modified Files: src/sys/kern: kern_descrip.c Log Message: kern_descrip.c: Use atomic_store_relaxed/release for ff->ff_file. 1. atomic_store_relaxed in fd_close avoids the appearance of race in sanitizers (minor bug). 2. atomic_store_release in fd_affix is necessary because the lock activity was not, in fact, enough to guarantee ordering (real bug some architectures like aarch64). The premise appears to have been that the mutex_enter/exit earlier in fd_affix is enough to guarantee that initialization of fp (A) happens before use of fp by a user once fp is published (B): fp->f_... = ...; // A /* fd_affix */ mutex_enter(&fp->f_lock); fp->f_count++; mutex_exit(&fp->f_lock); ... ff->ff_file = fp; // B But actually mutex_enter/exit allow the following reordering by the CPU: mutex_enter(&fp->f_lock); ff->ff_file = fp; // B fp->f_count++; fp->f_... = ...; // A mutex_exit(&fp->f_lock); The only constraints they imply are: 1. fp->f_count++ and B cannot precede mutex_enter 2. mutex_exit cannot precede A and fp->f_count++ They imply no constraint on the relative ordering of A, B, and fp->f_count++ amongst each other, however. This affects any architecture that has a native load-acquire or store-release operation in mutex_enter/exit, like aarch64, instead of explicit load-before-load/store and load/store-before-store barrier. No need for atomic_store_* in fd_copy or fd_free because we have exclusive access to ff as is. XXX pullup-9 XXX pullup-10 To generate a diff of this commit: cvs rdiff -u -r1.252 -r1.253 src/sys/kern/kern_descrip.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.