lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1336570043.2527.38.camel@twins>
Date:	Wed, 09 May 2012 15:27:23 +0200
From:	Peter Zijlstra <peterz@...radead.org>
To:	Igor Mammedov <imammedo@...hat.com>
Cc:	Jiang Liu <liuj97@...il.com>, linux-kernel@...r.kernel.org,
	mingo@...nel.org, pjt@...gle.com, tglx@...utronix.de,
	seto.hidetoshi@...fujitsu.com,
	Andrew Morton <akpm@...ux-foundation.org>,
	Linus Torvalds <torvalds@...ux-foundation.org>
Subject: [RFC][PATCH] printk: Add %pb to print bitmaps

On Wed, 2012-05-09 at 14:30 +0200, Peter Zijlstra wrote:
> on a related note, we should add a printk-%p modifier for cpulist,
> this cpulist_scnprintf() stuff gets annoying. 

Something like so I guess.. I'll try and convert some of the sched_debug
code to test it..

---
 lib/vsprintf.c |   36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index abbabec..90bfcd1 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -25,6 +25,9 @@
 #include <linux/kallsyms.h>
 #include <linux/uaccess.h>
 #include <linux/ioport.h>
+#include <linux/bitmap.h>
+#include <linux/cpumask.h>
+#include <linux/numa.h>
 #include <net/addrconf.h>
 
 #include <asm/page.h>		/* for PAGE_SIZE */
@@ -857,15 +860,19 @@ int kptr_restrict __read_mostly;
  *       correctness of the format string and va_list arguments.
  * - 'K' For a kernel pointer that should be hidden from unprivileged users
  * - 'NF' For a netdev_features_t
+ * - 'b' For a bitmap, consumes 2 args, second is int
+ * - 'bc' For a cpumask
+ * - 'bn' For a nodemask
  *
  * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
  * function pointers are really function descriptors, which contain a
  * pointer to the real address.
  */
-static noinline_for_stack
-char *pointer(const char *fmt, char *buf, char *end, void *ptr,
-	      struct printf_spec spec)
+static noinline_for_stack 
+char *pointer(const char *fmt, char *buf, char *end, va_list args, struct printf_spec spec)
 {
+	void *ptr = va_arg(args, void *);
+
 	if (!ptr && *fmt != 'K') {
 		/*
 		 * Print (null) with the same width as a pointer so it makes
@@ -941,6 +948,26 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 			return netdev_feature_string(buf, end, ptr, spec);
 		}
 		break;
+	case 'b':
+		{
+			int bits, len;
+
+			switch (fmt[1]) {
+			case 'c':
+				bits = nr_cpumask_bits;
+				break;
+			case 'n':
+				bits = MAX_NUMNODES;
+				break;
+			default:
+				bits = va_arg(args, int);
+				break;
+			}
+		       
+			len = bitmap_scnlistprintf(buf, end - buf, ptr, bits);
+
+			return buf + len;
+		}
 	}
 	spec.flags |= SMALL;
 	if (spec.field_width == -1) {
@@ -1261,8 +1288,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 			break;
 
 		case FORMAT_TYPE_PTR:
-			str = pointer(fmt+1, str, end, va_arg(args, void *),
-				      spec);
+			str = pointer(fmt+1, str, end, args, spec);
 			while (isalnum(*fmt))
 				fmt++;
 			break;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ