From 3fd63ddfdf3541faea762143365dbc70c16fa49e Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Fri, 5 Feb 2021 11:41:17 +0000 Subject: [PATCH] Limit when we call DELAY from KCSAN on amd64 In some cases the DELAY implementation on amd64 can recurse on a spin mutex in the i8254 early delay code. Detect when this is going to happen and don't call delay in this case. It is safe to not delay here with the only issue being KCSAN may not detect data races. Reviewed by: kib Tested by: arichardson Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D28895 --- sys/amd64/include/csan.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys/amd64/include/csan.h b/sys/amd64/include/csan.h index c886daa12f69..9daf8275492c 100644 --- a/sys/amd64/include/csan.h +++ b/sys/amd64/include/csan.h @@ -31,6 +31,9 @@ * $FreeBSD$ */ +#include + +#include #include #include #include @@ -64,7 +67,14 @@ kcsan_md_enable_intrs(uint64_t *state) static inline void kcsan_md_delay(uint64_t us) { - DELAY(us); + /* + * Only call DELAY if not using the early delay code. The i8254 + * early delay function may cause us to recurse on a spin lock + * leading to a panic. + */ + if ((tsc_is_invariant && tsc_freq != 0) || + timecounter->tc_quality > 0) + DELAY(us); } static void