Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp393308ybt; Wed, 24 Jun 2020 01:47:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt6gta/L2SVV3FXl0aeY4bZqYt2EXW0ZmYh4/LnF+YYafEqTkQTJpoy99MSS1rrPDnaG9C X-Received: by 2002:a17:907:42d2:: with SMTP id ng2mr23458908ejb.301.1592988447264; Wed, 24 Jun 2020 01:47:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592988447; cv=none; d=google.com; s=arc-20160816; b=ngcbtQaKPhHnhmEb0td7geznrVu+FoZ2jOhu5/CL3egCXUmxzB13I95XzeLHIlOW1P 9H4dxi3D8CSXvF8RxVd9aKAYnL6CNlZB16Ru8pH5FGVp3yTCH71n4YEQdSjz8HKFE6EO Dl+Dk3i87tTisneGbDwDXgeFAYpX4W4mCuDvb9GBcwKDWbYtzNmEG3923nL6K2POxdrk VDQo10OsQC7CSMm3WiQFoMvT1OEGZSChEReLIcgTkGPRx31NPCSRB//FhIMHmlgQeaj+ De95JV6YEuLUcKTe7pyEycUW6S5VLowX2Swy4mRrs7+KIXl+twuqPrxyN8OX1sITyf2z J0Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=bcZNan/6AB/vkv3UghrQGStc0hQezRyCXEFFFLVApbU=; b=gNsHYW2nZUf0CshNqJGkiJhqCAjRyBPzplKaosDt4tQ6qw+NP2L8vRrlwuWTeor/tG lwcXqnDtmd4SiSyF4V6J1AxNedKxv/jgyQ+qiLlhd8d2ZnJeQImJIeDh0bicK46GZeYX Q+nFxU6FMIIBB5BsFUFoWGgHV49iTarpO2ESH62gGa1pqSZXDR4+ZfrcGrYAYclJrjFe nTbcB6fJzFzrCoKcU4pZmxzI3DA1Uvt4mjD5N+dqdgWKp2zY4/ymsGwP6qS2YUGnpuau 55YpgzySHYPKuxmf6edrlL5IUJSPOo4IypAUoPWIV3DluZG6xEz8H4FBxmuph2nG6qxd KFWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KzYEL5ei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y12si13095112edt.9.2020.06.24.01.47.04; Wed, 24 Jun 2020 01:47:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KzYEL5ei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388685AbgFXIpj (ORCPT + 99 others); Wed, 24 Jun 2020 04:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388624AbgFXIph (ORCPT ); Wed, 24 Jun 2020 04:45:37 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D6A0C061573 for ; Wed, 24 Jun 2020 01:45:37 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id h185so874681pfg.2 for ; Wed, 24 Jun 2020 01:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bcZNan/6AB/vkv3UghrQGStc0hQezRyCXEFFFLVApbU=; b=KzYEL5eiqFmI8xNDQbUVTPfw8BDN1Miyy92qy14LK5hNTHIUnPpKf1Wgr5G08a5jKc Sb+MkospilCJiPugr2/MAXO/SHai2vmKqJ56yQNANXYYZc36Y15qNKuEXGYoiSPF8lZZ TkAF3FtdlwUNOIclEovXph93py6BwmYGWMMew= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bcZNan/6AB/vkv3UghrQGStc0hQezRyCXEFFFLVApbU=; b=VSiaxS2q8pyj7viWkJxzOZzADLWABWjNOqq8xMD4iDaTssmWPEp8sFyGxSNIYcEN+L 9EVTSwrHO+UYHg8Wx0vgQ7pluJC5//Y0jfuSOG1m7/9rbamR6jQWIHomfWQpQvCm/weY MbtiO/XNxZq29vfxoTdwPBw9fCVPLVWnP29oPmVpYzhzJMkzRaUarCeRuuk/t9yOPN4y DD0leLaJVtlsL33ONLe9cjYHPWiKpNbz3gncBnOWBmshhiE8Xc9JU3jegY1uySywS0Z8 WyNI9g9ZbfKwhO7GDqlXESfITvYh7hDylMuc4IU8SVN4CLFa7qTo82AXr95mAf3QkeC2 gNMg== X-Gm-Message-State: AOAM532N1Ccz1BNv9I+8cyNW5FJfofAUULccVXBhKKSxddBBoLF7O076 8M5rkRgUpzGLJx+dm5P1QDQXQ+YBIVmlNA== X-Received: by 2002:a63:1549:: with SMTP id 9mr20619084pgv.408.1592988336346; Wed, 24 Jun 2020 01:45:36 -0700 (PDT) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:d8b7:33af:adcb:b648]) by smtp.gmail.com with ESMTPSA id q16sm19404841pfg.49.2020.06.24.01.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 01:45:35 -0700 (PDT) From: Nicolas Boichat To: linux-kernel@vger.kernel.org Cc: Steven Rostedt , Ingo Molnar , Andrew Morton , Kees Cook , Jason Gunthorpe , Daniel Vetter , Peter Zijlstra , Vinod Koul , Andy Shevchenko , Alexey Dobriyan , Tiezhu Yang , Nicolas Boichat , Thomas Gleixner , "Guilherme G . Piccoli" , Will Deacon , dianders@chromium.org, groeck@chromium.org Subject: [PATCH] kernel/trace: Add TRACING_ALLOW_PRINTK config option Date: Wed, 24 Jun 2020 16:45:24 +0800 Message-Id: <20200624084524.259560-1-drinkcat@chromium.org> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org trace_printk is only meant as a debugging tool, and should never be compiled into production code without source code changes, as indicated by the warning that shows up on boot if any trace_printk is called: ** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE ** ** ** ** trace_printk() being used. Allocating extra memory. ** ** ** ** This means that this is a DEBUG kernel and it is ** ** unsafe for production use. ** If this option is set to n, the kernel will generate a build-time error if trace_printk is used. Signed-off-by: Nicolas Boichat --- include/linux/kernel.h | 17 ++++++++++++++++- kernel/trace/Kconfig | 9 +++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 196607aaf653082..b6addc6ba669e85 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -721,10 +721,15 @@ do { \ #define trace_printk(fmt, ...) \ do { \ char _______STR[] = __stringify((__VA_ARGS__)); \ + \ + __static_assert( \ + IS_ENABLED(CONFIG_TRACING_ALLOW_PRINTK),\ + "trace_printk called, please enable CONFIG_TRACING_ALLOW_PRINTK."); \ + \ if (sizeof(_______STR) > 3) \ do_trace_printk(fmt, ##__VA_ARGS__); \ else \ - trace_puts(fmt); \ + do_trace_puts(fmt); \ } while (0) #define do_trace_printk(fmt, args...) \ @@ -773,6 +778,13 @@ int __trace_printk(unsigned long ip, const char *fmt, ...); */ #define trace_puts(str) ({ \ + __static_assert( \ + IS_ENABLED(CONFIG_TRACING_ALLOW_PRINTK), \ + "trace_puts called, please enable CONFIG_TRACING_ALLOW_PRINTK."); \ + do_trace_puts(str); \ +}) + +#define do_trace_puts(str) ({ \ static const char *trace_printk_fmt __used \ __attribute__((section("__trace_printk_fmt"))) = \ __builtin_constant_p(str) ? str : NULL; \ @@ -794,6 +806,9 @@ extern void trace_dump_stack(int skip); */ #define ftrace_vprintk(fmt, vargs) \ do { \ + __static_assert( \ + IS_ENABLED(CONFIG_TRACING_ALLOW_PRINTK), \ + "ftrace_vprintk called, please enable CONFIG_TRACING_ALLOW_PRINTK."); \ if (__builtin_constant_p(fmt)) { \ static const char *trace_printk_fmt __used \ __attribute__((section("__trace_printk_fmt"))) = \ diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index a4020c0b4508c99..89ffddebe1864aa 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -111,6 +111,15 @@ config GENERIC_TRACER bool select TRACING +config TRACING_ALLOW_PRINTK + bool "Allow trace_printk" + default y if DEBUG_KERNEL + depends on TRACING + help + trace_printk is only meant as a debugging tool. If this option is + set to n, the kernel will generate a build-time error if trace_printk + is used. + # # Minimum requirements an architecture has to meet for us to # be able to offer generic tracing facilities: -- 2.27.0.111.gc72c7da667-goog