Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kmsan: expose KMSAN_WARN_ON()

KMSAN_WARN_ON() is required for implementing s390-specific KMSAN
functions, but right now it's available only to the KMSAN internal
functions. Expose it to subsystems through <linux/kmsan.h>.

Link: https://lkml.kernel.org/r/20240621113706.315500-17-iii@linux.ibm.com
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: <kasan-dev@googlegroups.com>
Cc: Marco Elver <elver@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ilya Leoshkevich and committed by
Andrew Morton
e6553e2f d1dac751

+26 -23
+25
include/linux/kmsan.h
··· 268 268 return __memset(s, c, n); 269 269 } 270 270 271 + extern bool kmsan_enabled; 272 + extern int panic_on_kmsan; 273 + 274 + /* 275 + * KMSAN performs a lot of consistency checks that are currently enabled by 276 + * default. BUG_ON is normally discouraged in the kernel, unless used for 277 + * debugging, but KMSAN itself is a debugging tool, so it makes little sense to 278 + * recover if something goes wrong. 279 + */ 280 + #define KMSAN_WARN_ON(cond) \ 281 + ({ \ 282 + const bool __cond = WARN_ON(cond); \ 283 + if (unlikely(__cond)) { \ 284 + WRITE_ONCE(kmsan_enabled, false); \ 285 + if (panic_on_kmsan) { \ 286 + /* Can't call panic() here because */ \ 287 + /* of uaccess checks. */ \ 288 + BUG(); \ 289 + } \ 290 + } \ 291 + __cond; \ 292 + }) 293 + 271 294 #else 272 295 273 296 static inline void kmsan_init_shadow(void) ··· 402 379 { 403 380 return memset(s, c, n); 404 381 } 382 + 383 + #define KMSAN_WARN_ON WARN_ON 405 384 406 385 #endif 407 386
+1 -23
mm/kmsan/kmsan.h
··· 11 11 #define __MM_KMSAN_KMSAN_H 12 12 13 13 #include <linux/irqflags.h> 14 + #include <linux/kmsan.h> 14 15 #include <linux/mm.h> 15 16 #include <linux/nmi.h> 16 17 #include <linux/pgtable.h> ··· 34 33 35 34 #define KMSAN_META_SHADOW (false) 36 35 #define KMSAN_META_ORIGIN (true) 37 - 38 - extern bool kmsan_enabled; 39 - extern int panic_on_kmsan; 40 - 41 - /* 42 - * KMSAN performs a lot of consistency checks that are currently enabled by 43 - * default. BUG_ON is normally discouraged in the kernel, unless used for 44 - * debugging, but KMSAN itself is a debugging tool, so it makes little sense to 45 - * recover if something goes wrong. 46 - */ 47 - #define KMSAN_WARN_ON(cond) \ 48 - ({ \ 49 - const bool __cond = WARN_ON(cond); \ 50 - if (unlikely(__cond)) { \ 51 - WRITE_ONCE(kmsan_enabled, false); \ 52 - if (panic_on_kmsan) { \ 53 - /* Can't call panic() here because */ \ 54 - /* of uaccess checks. */ \ 55 - BUG(); \ 56 - } \ 57 - } \ 58 - __cond; \ 59 - }) 60 36 61 37 /* 62 38 * A pair of metadata pointers to be returned by the instrumentation functions.