linux-stable/include
Steven Rostedt (Google) f415e7fa9b tracing/events: Add __vstring() and __assign_vstr() helper macros
[ Upstream commit 0563231f93 ]

There's several places that open code the following logic:

  TP_STRUCT__entry(__dynamic_array(char, msg, MSG_MAX)),
  TP_fast_assign(vsnprintf(__get_str(msg), MSG_MAX, vaf->fmt, *vaf->va);)

To load a string created by variable array va_list.

The main issue with this approach is that "MSG_MAX" usage in the
__dynamic_array() portion. That actually just reserves the MSG_MAX in the
event, and even wastes space because there's dynamic meta data also saved
in the event to denote the offset and size of the dynamic array. It would
have been better to just use a static __array() field.

Instead, create __vstring() and __assign_vstr() that work like __string
and __assign_str() but instead of taking a destination string to copy,
take a format string and a va_list pointer and fill in the values.

It uses the helper:

 #define __trace_event_vstr_len(fmt, va)		\
 ({							\
	va_list __ap;					\
	int __ret;					\
							\
	va_copy(__ap, *(va));				\
	__ret = vsnprintf(NULL, 0, fmt, __ap) + 1;	\
	va_end(__ap);					\
							\
	min(__ret, TRACE_EVENT_STR_MAX);		\
 })

To figure out the length to store the string. It may be slightly slower as
it needs to run the vsnprintf() twice, but it now saves space on the ring
buffer.

Link: https://lkml.kernel.org/r/20220705224749.053570613@goodmis.org

Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Kalle Valo <kvalo@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Arend van Spriel <aspriel@gmail.com>
Cc: Franky Lin <franky.lin@broadcom.com>
Cc: Hante Meuleman <hante.meuleman@broadcom.com>
Cc: Gregory Greenman <gregory.greenman@intel.com>
Cc: Peter Chen <peter.chen@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
Cc: Bin Liu <b-liu@ti.com>
Cc: Marek Lindner <mareklindner@neomailbox.ch>
Cc: Simon Wunderlich <sw@simonwunderlich.de>
Cc: Antonio Quartulli <a@unstable.cc>
Cc: Sven Eckelmann <sven@narfation.org>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-08-17 14:42:23 +02:00
..
acpi ACPI: CPPC: Don't require _OSC if X86_FEATURE_CPPC is supported 2022-07-12 16:42:23 +02:00
asm-generic asm-generic: remove a broken and needless ifdef conditional 2022-08-03 12:05:17 +02:00
clocksource
crypto crypto: blake2s - remove shash module 2022-08-17 14:42:20 +02:00
drm drm/scheduler: Don't kill jobs in interrupt context 2022-07-29 17:27:56 +02:00
dt-bindings clk: qcom: gcc-msm8939: Add missing SYSTEM_MM_NOC_BFDCD_CLK_SRC 2022-08-17 14:41:40 +02:00
keys
kunit
kvm
linux tracing/events: Add __vstring() and __assign_vstr() helper macros 2022-08-17 14:42:23 +02:00
math-emu
media media: uapi: HEVC: Change pic_order_cnt definition in v4l2_hevc_dpb_entry 2022-08-17 14:41:06 +02:00
memory memory: renesas-rpc-if: Fix HF/OSPI data transfer in Manual Mode 2022-04-21 17:00:24 +02:00
misc
net 9p: Add client parameter to p9_req_put() 2022-08-17 14:42:06 +02:00
pcmcia
ras
rdma
scsi scsi: iscsi: Fix session removal on shutdown 2022-08-17 14:41:38 +02:00
soc net: dsa: felix: keep reference on entire tc-taprio config 2022-08-17 14:40:58 +02:00
sound ASoC: cs35l41: Fix an out-of-bounds access in otp_packed_element_t 2022-06-09 10:29:55 +02:00
target
trace tracing/events: Add __vstring() and __assign_vstr() helper macros 2022-08-17 14:42:23 +02:00
uapi netfilter: xtables: Bring SPDX identifier back 2022-08-17 14:41:21 +02:00
vdso
video video: of_display_timing.h: include errno.h 2022-07-12 16:42:17 +02:00
xen