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
This commit is contained in:
Andrew Turner 2021-02-05 11:41:17 +00:00
parent 59f6ddb2bc
commit 3fd63ddfdf

View File

@ -31,6 +31,9 @@
* $FreeBSD$
*/
#include <sys/timetc.h>
#include <machine/clock.h>
#include <machine/cpufunc.h>
#include <machine/stack.h>
#include <machine/vmparam.h>
@ -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