⬢ DragonFlyBSD Kernel Audit
DF-5672 / fix.diff
← back to finding ↓ download raw
--- a/sys/platform/pc64/x86_64/ipl_funcs.c
+++ b/sys/platform/pc64/x86_64/ipl_funcs.c
@@ -36,12 +36,17 @@
 #include <machine/globaldata.h>
 
 /*
- * Bits in the spending bitmap variable must be set atomically because
- * spending may be manipulated by interrupts or other cpu's without holding
- * any locks.
+ * gd_spending / gd_sdelayed are STRICTLY per-CPU.  Every manipulation of
+ * CPU n's words executes on CPU n: the functions below resolve gd = mdcpu
+ * (the calling CPU), and the unpend side clears them via PCPU(spending)
+ * in doreti_soft/splz_soft (exception.S/ipl.s).  No cross-CPU accessor
+ * exists; do not add one.
  *
- * Note: setbits uses a locked or, making simple cases MP safe.
+ * The or to gd_spending is intentionally NON-locked (a single-instruction
+ * RMW cannot tear against same-CPU interrupt handlers), while the
+ * gd_reqflags store is locked as belt-and-braces.  DO NOT rely on the
+ * spending store being MP-safe: it is not.  (pc64 twin of DF-5671.)
  */
 #define DO_SETBITS(name, var, bits) 					\
 void									\