From owner-freebsd-current@FreeBSD.ORG Sat Nov 24 03:08:29 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2D86FF96 for ; Sat, 24 Nov 2012 03:08:29 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx1.freebsd.org (Postfix) with ESMTP id D86708FC08 for ; Sat, 24 Nov 2012 03:08:28 +0000 (UTC) Received: by mail-vc0-f182.google.com with SMTP id fo13so13106990vcb.13 for ; Fri, 23 Nov 2012 19:08:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=W/9HoR+xIfMloIZSgbFU47kczgnBqgY79qwyZFMIrLQ=; b=VZgzBXY0D7DqmhZLqnC2kGnIxiBu7uhkC+DoA2skahwATcisqjNyxV94QfTzNCfCEd DQ8i7CZCdMjHfzTvArYy0Qe+9M/NpVZzHVA+ueTlFmFgHuSxHqmOXRwLui1WY6uJkrHq emGPZzeeQgFs3lFHBI9dTyMrbYJu0xbL9DTwVXD5d3JJGVyCDIlXxlpWylQcmO+JSHR5 v4zKkDFY4UxLWG8BNcBf6lBikT5PqcS7ZJhyabcDJ/jUg7rjR3fCvLOyLqRT4s5Ufy8F ek9480DBaFbl3QocONhiN92FfNhLUHPt7m/c9YLshIY/hwOuaqZ/QpI1DzVlDqAYU7xc yVdg== MIME-Version: 1.0 Received: by 10.52.90.241 with SMTP id bz17mr7667411vdb.40.1353726508123; Fri, 23 Nov 2012 19:08:28 -0800 (PST) Received: by 10.58.207.114 with HTTP; Fri, 23 Nov 2012 19:08:28 -0800 (PST) Date: Fri, 23 Nov 2012 22:08:28 -0500 Message-ID: Subject: Spurious witness warning when destroying spin mtx From: Ryan Stone To: FreeBSD Current Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Nov 2012 03:08:29 -0000 Today I saw a spurious witness warning for "acquiring duplicate lock of same type". The root cause is that when running mtx_destroy on a spinlock that is held by the current thread, mtx_destroy calls spinlock_exit() before calling WITNESS_UNLOCK, which opens up a window in which the CPU can be interrupted and attempt to acquire another spinlock of the same type as the one being destroyed. This patch should fix it: diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 2f13863..96f43f8 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -918,16 +918,16 @@ _mtx_destroy(volatile uintptr_t *c) else { MPASS((m->mtx_lock & (MTX_RECURSED|MTX_CONTESTED)) == 0); + lock_profile_release_lock(&m->lock_object); + /* Tell witness this isn't locked to make it happy. */ + WITNESS_UNLOCK(&m->lock_object, LOP_EXCLUSIVE, __FILE__, + __LINE__); + /* Perform the non-mtx related part of mtx_unlock_spin(). */ if (LOCK_CLASS(&m->lock_object) == &lock_class_mtx_spin) spinlock_exit(); else curthread->td_locks--; - - lock_profile_release_lock(&m->lock_object); - /* Tell witness this isn't locked to make it happy. */ - WITNESS_UNLOCK(&m->lock_object, LOP_EXCLUSIVE, __FILE__, - __LINE__); } m->mtx_lock = MTX_DESTROYED