Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp748636imj; Thu, 7 Feb 2019 11:12:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IZsmyuKHAIBYGvmIHaIhPkXssFoBNYwDOV++5WlRR5ExfpqSVm9ocwBSWPzPlcSx4Xf4sLu X-Received: by 2002:a17:902:161:: with SMTP id 88mr18505894plb.306.1549566727589; Thu, 07 Feb 2019 11:12:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549566727; cv=none; d=google.com; s=arc-20160816; b=pDquINK8hf0ZiAwEu2pwxGHOtY11G9Zg7+GMwDk+aOqOXaRIucHnOTzAaZAPA/celm k+SAI+jCkvr5TzThxRqzbRFs96cDclwY1snZJiMu7iOPBlvonr6+JEb3OrZi64il4fO4 p/t6jyj6X1ewj7EwQ1y/NcERrYCMhkcZwcXsjd75ZlO0k8g5lDpBPH78F2SdkUtwv+Ri R3hKtu7VA0/f9w9zs8+ZpA8iv5Zj+eAIkiNTqSgSLxDm3yh+y5+ohpdMg9I5o/rt2LIM J02XXN39FxGBtWF1IxUQPdCSUR2ioN3uiN9/gwvD0aEUZlZ+L8kLMBoFun453Ttv9j3U TKPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=dLfZctGyg88KHjIe54x7L54U6/5OMOtg0xRo1izFf48=; b=RlOibFroRyKnVw8z/+2N7bMEXXRCZtjlffGmADbzWbcxN8zXBSZPuhwixPRgdYc0o3 J9JHuKXbJyGzhxt18vIz/pLNgo1qCYjey1ktNiyYngxo3eBNTxjKr/2uhZo2AlPPIRUn 4yFM2NSdmO2tl925XPmxIvx+SyNaTI8nDbqwOFW1Z3TgqXzE8P81rtANwHLpfNCS0c1G x0NRL4aRgLHNaCrQFT/xqhTtV/kH+M85x2oymuLX5CSda7pXMX/xedpCZEvWmiiywYMs z7NeEplqk2AOUfwnBSeiA4EDZ/TFV1L2JsLxUgIjv5Riby5oiKzcwpxw2CjZLeA8LqPM V1tg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q2si9635769pll.343.2019.02.07.11.11.43; Thu, 07 Feb 2019 11:12:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727330AbfBGTJg (ORCPT + 99 others); Thu, 7 Feb 2019 14:09:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59906 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726791AbfBGTJe (ORCPT ); Thu, 7 Feb 2019 14:09:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DCCF488E52; Thu, 7 Feb 2019 19:09:33 +0000 (UTC) Received: from llong.com (dhcp-17-35.bos.redhat.com [10.18.17.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B1361693B; Thu, 7 Feb 2019 19:09:28 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-arch@vger.kernel.org, x86@kernel.org, Arnd Bergmann , Borislav Petkov , "H. Peter Anvin" , Davidlohr Bueso , Linus Torvalds , Andrew Morton , Tim Chen , Waiman Long Subject: [PATCH-tip 09/22] locking/rwsem: Enhance DEBUG_RWSEMS_WARN_ON() macro Date: Thu, 7 Feb 2019 14:07:13 -0500 Message-Id: <1549566446-27967-10-git-send-email-longman@redhat.com> In-Reply-To: <1549566446-27967-1-git-send-email-longman@redhat.com> References: <1549566446-27967-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 07 Feb 2019 19:09:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the DEBUG_RWSEMS_WARN_ON() macro just dumps a stack trace when the rwsem isn't in the right state. It does not show the actual states of the rwsem. This may not be that helpful in the debugging process. Enhance the DEBUG_RWSEMS_WARN_ON() macro to also show the current content of the rwsem count and owner fields to give more information about what is wrong with the rwsem. Signed-off-by: Waiman Long --- kernel/locking/rwsem-xadd.h | 19 ++++++++++++------- kernel/locking/rwsem.c | 5 +++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/kernel/locking/rwsem-xadd.h b/kernel/locking/rwsem-xadd.h index 77151c3..6d2478c 100644 --- a/kernel/locking/rwsem-xadd.h +++ b/kernel/locking/rwsem-xadd.h @@ -27,9 +27,13 @@ #define RWSEM_ANONYMOUSLY_OWNED (1UL << 1) #ifdef CONFIG_DEBUG_RWSEMS -# define DEBUG_RWSEMS_WARN_ON(c) DEBUG_LOCKS_WARN_ON(c) +# define DEBUG_RWSEMS_WARN_ON(c, sem) \ + WARN_ONCE(c, "DEBUG_RWSEMS_WARN_ON(%s): count = 0x%lx, owner = 0x%lx, curr 0x%lx, list %sempty\n",\ + #c, atomic_long_read(&(sem)->count), \ + (long)((sem)->owner), (long)current, \ + list_empty(&(sem)->wait_list) ? "" : "not ") #else -# define DEBUG_RWSEMS_WARN_ON(c) +# define DEBUG_RWSEMS_WARN_ON(c, sem) #endif /* @@ -168,7 +172,7 @@ static inline void __down_read(struct rw_semaphore *sem) if (unlikely(atomic_long_inc_return_acquire(&sem->count) <= 0)) { rwsem_down_read_failed(sem); DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & - RWSEM_READER_OWNED)); + RWSEM_READER_OWNED), sem); } else { rwsem_set_reader_owned(sem); } @@ -180,7 +184,7 @@ static inline int __down_read_killable(struct rw_semaphore *sem) if (IS_ERR(rwsem_down_read_failed_killable(sem))) return -EINTR; DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & - RWSEM_READER_OWNED)); + RWSEM_READER_OWNED), sem); } else { rwsem_set_reader_owned(sem); } @@ -248,7 +252,8 @@ static inline void __up_read(struct rw_semaphore *sem) { long tmp; - DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & RWSEM_READER_OWNED)); + DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & RWSEM_READER_OWNED), + sem); rwsem_clear_reader_owned(sem); tmp = atomic_long_dec_return_release(&sem->count); if (unlikely(tmp < -1 && (tmp & RWSEM_ACTIVE_MASK) == 0)) @@ -260,7 +265,7 @@ static inline void __up_read(struct rw_semaphore *sem) */ static inline void __up_write(struct rw_semaphore *sem) { - DEBUG_RWSEMS_WARN_ON(sem->owner != current); + DEBUG_RWSEMS_WARN_ON(sem->owner != current, sem); rwsem_clear_owner(sem); if (unlikely(atomic_long_sub_return_release(RWSEM_ACTIVE_WRITE_BIAS, &sem->count) < 0)) @@ -281,7 +286,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem) * read-locked region is ok to be re-ordered into the * write side. As such, rely on RELEASE semantics. */ - DEBUG_RWSEMS_WARN_ON(sem->owner != current); + DEBUG_RWSEMS_WARN_ON(sem->owner != current, sem); tmp = atomic_long_add_return_release(-RWSEM_WAITING_BIAS, &sem->count); rwsem_set_reader_owned(sem); if (tmp < 0) diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index 598fc7c..bdfca7c 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -17,7 +17,7 @@ #include "rwsem-xadd.h" #else #define __rwsem_set_reader_owned(a, b) -#define DEBUG_RWSEMS_WARN_ON(a) +#define DEBUG_RWSEMS_WARN_ON(a, b) #endif /* @@ -203,7 +203,8 @@ int __sched down_write_killable_nested(struct rw_semaphore *sem, int subclass) void up_read_non_owner(struct rw_semaphore *sem) { - DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & RWSEM_READER_OWNED)); + DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & RWSEM_READER_OWNED), + sem); __up_read(sem); } -- 1.8.3.1