linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Sasha Levin <sasha.levin@oracle.com>
Cc: Dave Hansen <dave.hansen@intel.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCH 1/3] mm: generalize VM_BUG_ON() macros
Date: Wed,  1 Oct 2014 14:31:59 +0300	[thread overview]
Message-ID: <1412163121-4295-1-git-send-email-kirill.shutemov@linux.intel.com> (raw)

This patch makes VM_BUG_ON() to accept one to three arguments after the
condition. Any of these arguments can be page, vma or mm. VM_BUG_ON()
will dump info about the argument using appropriate dump_* function.

It's intended to replace separate VM_BUG_ON_PAGE(), VM_BUG_ON_VMA(),
VM_BUG_ON_MM() and allows additional use-cases like:

  VM_BUG_ON(cond, vma, page);
  VM_BUG_ON(cond, vma, src_page, dst_page);
  VM_BUG_ON(cond, mm, src_vma, dst_vma);
  ...

It's possible to extend list of supported data-structures or number of
arguments VM_BUG_ON() can accept.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 include/linux/mmdebug.h | 49 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/include/linux/mmdebug.h b/include/linux/mmdebug.h
index 877ef226f90f..12f304a36b01 100644
--- a/include/linux/mmdebug.h
+++ b/include/linux/mmdebug.h
@@ -14,33 +14,60 @@ void dump_vma(const struct vm_area_struct *vma);
 void dump_mm(const struct mm_struct *mm);
 
 #ifdef CONFIG_DEBUG_VM
-#define VM_BUG_ON(cond) BUG_ON(cond)
-#define VM_BUG_ON_PAGE(cond, page)					\
+#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
+
+#define _VM_DUMP(arg, cond) do {					\
+	if (__builtin_types_compatible_p(typeof(*arg), struct page))	\
+		dump_page((struct page *) arg,				\
+				"VM_BUG_ON(" __stringify(cond)")");	\
+	else if (__builtin_types_compatible_p(typeof(*arg),		\
+				struct vm_area_struct))			\
+		dump_vma((struct vm_area_struct *) arg);		\
+	else if (__builtin_types_compatible_p(typeof(*arg),		\
+				struct mm_struct))			\
+		dump_mm((struct mm_struct *) arg);			\
+	else								\
+		BUILD_BUG();						\
+} while(0)
+
+#define _VM_BUG_ON_ARG1(cond, arg1)					\
 	do {								\
 		if (unlikely(cond)) {					\
-			dump_page(page, "VM_BUG_ON_PAGE(" __stringify(cond)")");\
+			_VM_DUMP(arg1, cond);				\
 			BUG();						\
 		}							\
-	} while (0)
-#define VM_BUG_ON_VMA(cond, vma)					\
+	} while(0)
+#define _VM_BUG_ON_ARG2(cond, arg1, arg2)				\
 	do {								\
 		if (unlikely(cond)) {					\
-			dump_vma(vma);					\
+			_VM_DUMP(arg1, cond);				\
+			_VM_DUMP(arg2, cond);				\
 			BUG();						\
 		}							\
-	} while (0)
-#define VM_BUG_ON_MM(cond, mm)						\
+	} while(0)
+#define _VM_BUG_ON_ARG3(cond, arg1, arg2, arg3)				\
 	do {								\
 		if (unlikely(cond)) {					\
-			dump_mm(mm);					\
+			_VM_DUMP(arg1, cond);				\
+			_VM_DUMP(arg2, cond);				\
+			_VM_DUMP(arg3, cond);				\
 			BUG();						\
 		}							\
-	} while (0)
+	} while(0)
+
+#define VM_BUG_ON(...) GET_MACRO(__VA_ARGS__,				\
+		_VM_BUG_ON_ARG3,					\
+		_VM_BUG_ON_ARG2,					\
+		_VM_BUG_ON_ARG1,					\
+		BUG_ON)(__VA_ARGS__)
+#define VM_BUG_ON_PAGE VM_BUG_ON
+#define VM_BUG_ON_VMA VM_BUG_ON
+#define VM_BUG_ON_MM VM_BUG_ON
 #define VM_WARN_ON(cond) WARN_ON(cond)
 #define VM_WARN_ON_ONCE(cond) WARN_ON_ONCE(cond)
 #define VM_WARN_ONCE(cond, format...) WARN_ONCE(cond, format)
 #else
-#define VM_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
+#define VM_BUG_ON(cond, ...) BUILD_BUG_ON_INVALID(cond)
 #define VM_BUG_ON_PAGE(cond, page) VM_BUG_ON(cond)
 #define VM_BUG_ON_VMA(cond, vma) VM_BUG_ON(cond)
 #define VM_BUG_ON_MM(cond, mm) VM_BUG_ON(cond)
-- 
2.1.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

             reply	other threads:[~2014-10-01 11:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-01 11:31 Kirill A. Shutemov [this message]
2014-10-01 11:32 ` [PATCH 2/3] mm: use VM_BUG_ON instead of VM_BUG_ON_PAGE everywhere Kirill A. Shutemov
2014-10-01 11:32 ` [PATCH 3/3] mm: use VM_BUG_ON() instead of VM_BUG_ON_VMA() and VM_BUG_ON_MM() Kirill A. Shutemov
2014-10-01 11:39 ` [PATCH 1/3] mm: generalize VM_BUG_ON() macros Sasha Levin
2014-10-01 13:18   ` Kirill A. Shutemov
2014-10-01 20:05 ` Andrew Morton
2014-10-02 14:11   ` Kirill A. Shutemov
2014-10-02 17:03   ` Christoph Lameter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1412163121-4295-1-git-send-email-kirill.shutemov@linux.intel.com \
    --to=kirill.shutemov@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sasha.levin@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).