git: d0f9b0bd19bf - main - malloc(9): assert wait flags.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 31 Oct 2024 00:41:39 UTC
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=d0f9b0bd19bf5dc4031164fd26c5bbc4bab1cc74 commit d0f9b0bd19bf5dc4031164fd26c5bbc4bab1cc74 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2024-10-31 00:19:48 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2024-10-31 00:19:48 +0000 malloc(9): assert wait flags. The check introduced in d3c11994e1e3 was bogus, combining a non-atomic “once” flag with an equally non-thread-safe ppsratecheck. Rather than fix it, just assert what it attempts to enforce: that the malloc flags must include exactly one of M_WAITOK and M_NOWAIT. Fixes: d3c11994e1e3de7445305abd0d41dce2b8d3e6dc Sponsored by: Klara, Inc. Reviewed by: olce, kevans Differential Revision: https://reviews.freebsd.org/D47309 --- sys/kern/kern_malloc.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 9d7e0464e0f7..b1347b15e651 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -524,27 +524,13 @@ static int malloc_dbg(caddr_t *vap, size_t *sizep, struct malloc_type *mtp, int flags) { -#ifdef INVARIANTS - int indx; - KASSERT(mtp->ks_version == M_VERSION, ("malloc: bad malloc type version")); - /* - * Check that exactly one of M_WAITOK or M_NOWAIT is specified. - */ - indx = flags & (M_WAITOK | M_NOWAIT); - if (indx != M_NOWAIT && indx != M_WAITOK) { - static struct timeval lasterr; - static int curerr, once; - if (once == 0 && ppsratecheck(&lasterr, &curerr, 1)) { - printf("Bad malloc flags: %x\n", indx); - kdb_backtrace(); - flags |= M_WAITOK; - once++; - } - } + KASSERT((flags & (M_WAITOK | M_NOWAIT)) != 0, + ("malloc: flags must include either M_WAITOK or M_NOWAIT")); + KASSERT((flags & (M_WAITOK | M_NOWAIT)) != (M_WAITOK | M_NOWAIT), + ("malloc: flags may not include both M_WAITOK and M_NOWAIT")); KASSERT((flags & M_NEVERFREED) == 0, ("malloc: M_NEVERFREED is for internal use only")); -#endif #ifdef MALLOC_MAKE_FAILURES if ((flags & M_NOWAIT) && (malloc_failure_rate != 0)) { atomic_add_int(&malloc_nowait_count, 1);