Date: Fri, 23 Aug 2019 06:39:40 +0000 (UTC) From: Xin LI <delphij@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351417 - head/sys/kern Message-ID: <201908230639.x7N6defT054208@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: delphij Date: Fri Aug 23 06:39:40 2019 New Revision: 351417 URL: https://svnweb.freebsd.org/changeset/base/351417 Log: INVARIANTS: treat LA_LOCKED as the same of LA_XLOCKED in mtx_assert. The Linux lockdep API assumes LA_LOCKED semantic in lockdep_assert_held(), meaning that either a shared lock or write lock is Ok. On the other hand, the timeout code uses lc_assert() with LA_XLOCKED, and we need both to work. For mutexes, because they can not be shared (this is unique among all lock classes, and it is unlikely that we would add new lock class anytime soon), it is easier to simply extend mtx_assert to handle LA_LOCKED there, despite the change itself can be viewed as a slight abstraction violation. Reviewed by: mjg, cem, jhb MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D21362 Modified: head/sys/kern/kern_mutex.c Modified: head/sys/kern/kern_mutex.c ============================================================================== --- head/sys/kern/kern_mutex.c Fri Aug 23 05:25:21 2019 (r351416) +++ head/sys/kern/kern_mutex.c Fri Aug 23 06:39:40 2019 (r351417) @@ -176,6 +176,21 @@ void assert_mtx(const struct lock_object *lock, int what) { + /* + * Treat LA_LOCKED as if LA_XLOCKED was asserted. + * + * Some callers of lc_assert uses LA_LOCKED to indicate that either + * a shared lock or write lock was held, while other callers uses + * the more strict LA_XLOCKED (used as MA_OWNED). + * + * Mutex is the only lock class that can not be shared, as a result, + * we can reasonably consider the caller really intends to assert + * LA_XLOCKED when they are asserting LA_LOCKED on a mutex object. + */ + if (what & LA_LOCKED) { + what &= ~LA_LOCKED; + what |= LA_XLOCKED; + } mtx_assert((const struct mtx *)lock, what); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201908230639.x7N6defT054208>