Printbufs v6
Subsystems (16)
Hey Andrew - here's the rest of the patch series. My brand new email account was suspended halfway through because it thought I was sending spam... subtle commentary on the contents, perhaps?
Cheers
PATCH 1/11 mm/memcontrol.c: Convert to printbuf
From: Kent Overstreet <[email protected]>
This converts memory_stat_format() from seq_buf to printbuf. Printbuf is simalar to seq_buf except that it heap allocates the string buffer:
here, we were already heap allocating the buffer with kmalloc() so the conversion is trivial.
--- mm/memcontrol.c | 54 ++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-)
mm/memcontrol.c +27 -27
@@ -62,7 +62,7 @@#include <linux/file.h> #include <linux/resume_user_mode.h> #include <linux/psi.h> -#include <linux/seq_buf.h> +#include <linux/printbuf.h> #include "internal.h" #include <net/sock.h> #include <net/ip.h>
@@ -1490,13 +1490,10 @@ static const unsigned int memcg_vm_event_stat[] = {#endif }; -static void memory_stat_format (struct mem_cgroup *memcg,char *buf,int bufsize) +static void memory_stat_format (struct printbuf *out,struct mem_cgroup *memcg) { -struct seq_buf s;int i; -seq_buf_init (&s, buf, bufsize); -/* * Provide statistics on the state of the memory subsystem as * well as cumulative event counters that show past behavior.
@@ -1513,30 +1510,30 @@ static void memory_stat_format(struct mem_cgroup *memcg, char *buf, int bufsize)u64 size; size =memcg_page_state_output (memcg, memory_stats[i].idx); -seq_buf_printf (&s,"%s %llu\n" , memory_stats[i].name, size); +prt_printf (out,"%s %llu\n" , memory_stats[i].name, size);if (unlikely (memory_stats[i].idx ==NR_SLAB_UNRECLAIMABLE_B )) { size +=memcg_page_state_output (memcg,NR_SLAB_RECLAIMABLE_B ); -seq_buf_printf (&s,"slab %llu\n" , size); +prt_printf (out,"slab %llu\n" , size); } }/* Accumulated memory events */ -seq_buf_printf (&s,"pgscan %lu\n" , -memcg_events (memcg,PGSCAN_KSWAPD ) + -memcg_events (memcg,PGSCAN_DIRECT )); -seq_buf_printf (&s,"pgsteal %lu\n" , -memcg_events (memcg,PGSTEAL_KSWAPD ) + -memcg_events (memcg,PGSTEAL_DIRECT )); +prt_printf (out,"pgscan %lu\n" , +memcg_events (memcg,PGSCAN_KSWAPD ) + +memcg_events (memcg,PGSCAN_DIRECT )); +prt_printf (out,"pgsteal %lu\n" , +memcg_events (memcg,PGSTEAL_KSWAPD ) + +memcg_events (memcg,PGSTEAL_DIRECT ));for (i =0 ; i <ARRAY_SIZE (memcg_vm_event_stat); i++) -seq_buf_printf (&s,"%s %lu\n" , -vm_event_name (memcg_vm_event_stat[i]), -memcg_events (memcg, memcg_vm_event_stat[i])); +prt_printf (out,"%s %lu\n" , +vm_event_name (memcg_vm_event_stat[i]), +memcg_events (memcg, memcg_vm_event_stat[i]));/* The above should easily fit into one page */ -WARN_ON_ONCE (seq_buf_has_overflowed (&s)); +WARN_ON_ONCE (!printbuf_remaining (out)); }#define K (x) ((x) << (PAGE_SHIFT-10))
@@ -1573,7 +1570,8 @@ void mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *void mem_cgroup_print_oom_meminfo (struct mem_cgroup *memcg) {/* Use static buffer, for the caller is holding oom_lock. */ -static char buf[PAGE_SIZE ]; +static char _buf[PAGE_SIZE ]; +struct printbuf buf =PRINTBUF_EXTERN (_buf,sizeof (_buf));lockdep_assert_held (&oom_lock);
@@ -1596,8 +1594,8 @@ void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg)pr_info ("Memory cgroup stats for " );pr_cont_cgroup_path (memcg->css.cgroup);pr_cont (":" ); -memory_stat_format (memcg, buf,sizeof (buf)); -pr_info ("%s" , buf); +memory_stat_format (&buf, memcg); +pr_info ("%s" , buf.buf); }/*
@@ -6401,14 +6399,16 @@ static int memory_events_local_show(struct seq_file *m, void *v)static int memory_stat_show (struct seq_file *m,void *v) {struct mem_cgroup *memcg =mem_cgroup_from_seq (m); -char *buf =kmalloc (PAGE_SIZE ,GFP_KERNEL ); +struct printbuf buf =PRINTBUF ; +int ret; -if (!buf) -return -ENOMEM ; -memory_stat_format (memcg, buf,PAGE_SIZE ); -seq_puts (m, buf); -kfree (buf); -return 0 ; +memory_stat_format (&buf, memcg); + ret = buf.allocation_failure ? -ENOMEM :0 ; +if (!ret) +seq_puts (m, buf.buf); + +printbuf_exit (&buf); +return ret; }#ifdef CONFIG_NUMA
Signature · 1 line
2.36.1
PATCH 2/11 clk: tegra: bpmp: Convert to printbuf
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
This converts from seq_buf to printbuf, which is similar but heap allocates the string buffer.
Previously in this code the string buffer was allocated on the stack; this means we've added a new potential memory allocation failure. This is fine though since it's only for a dev_printk() message.
Memory allocation context: printbuf doesn't take gfp flags, instead we prefer the new memalloc_no*_(save|restore) interfaces to be used. Here the surrounding code is already allocating with GFP_KERNEL, so everything is fine.
--- drivers/clk/tegra/clk-bpmp.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/clk/tegra/clk-bpmp.c +10 -11
@@ -5,7 +5,7 @@#include <linux/clk-provider.h> #include <linux/device.h> -#include <linux/seq_buf.h> +#include <linux/printbuf.h> #include <linux/slab.h> #include <soc/tegra/bpmp.h>
@@ -365,39 +365,38 @@ static void tegra_bpmp_clk_info_dump(struct tegra_bpmp *bpmp, const struct tegra_bpmp_clk_info *info) {const char *prefix ="" ; -struct seq_buf buf; +struct printbuf buf =PRINTBUF ;unsigned int i; -char flags[64 ]; - -seq_buf_init (&buf, flags,sizeof (flags));if (info->flags) -seq_buf_printf (&buf,"(" ); +prt_printf (&buf,"(" );if (info->flags &TEGRA_BPMP_CLK_HAS_MUX ) { -seq_buf_printf (&buf,"%smux" , prefix); +prt_printf (&buf,"%smux" , prefix); prefix =", " ; }if ((info->flags &TEGRA_BPMP_CLK_HAS_SET_RATE ) ==0 ) { -seq_buf_printf (&buf,"%sfixed" , prefix); +prt_printf (&buf,"%sfixed" , prefix); prefix =", " ; }if (info->flags &TEGRA_BPMP_CLK_IS_ROOT ) { -seq_buf_printf (&buf,"%sroot" , prefix); +prt_printf (&buf,"%sroot" , prefix); prefix =", " ; }if (info->flags) -seq_buf_printf (&buf,")" ); +prt_printf (&buf,")" );dev_printk (level, bpmp->dev,"%03u: %s\n" , info->id, info->name); -dev_printk (level, bpmp->dev," flags: %lx %s\n" , info->flags, flags); +dev_printk (level, bpmp->dev," flags: %lx %s\n" , info->flags,printbuf_str (&buf));dev_printk (level, bpmp->dev," parents: %u\n" , info->num_parents);for (i =0 ; i < info->num_parents; i++)dev_printk (level, bpmp->dev," %03u\n" , info->parents[i]); + +printbuf_exit (&buf); } static int tegra_bpmp_probe_clocks(struct tegra_bpmp *bpmp,
Signature · 1 line
2.36.1
PATCH 3/11 tools/testing/nvdimm: Convert to printbuf
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
This converts from seq_buf to printbuf. Here we're using printbuf with an external buffer, meaning it's a direct conversion.
--- tools/testing/nvdimm/test/ndtest.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
tools/testing/nvdimm/test/ndtest.c +10 -12
@@ -12,7 +12,7 @@#include <linux/ndctl.h> #include <nd-core.h> #include <linux/printk.h> -#include <linux/seq_buf.h> +#include <linux/printbuf.h> #include "../watermark.h" #include "nfit_test.h"
@@ -740,32 +740,30 @@ static ssize_t flags_show(struct device *dev, {struct nvdimm *nvdimm =to_nvdimm (dev);struct ndtest_dimm *dimm =nvdimm_provider_data (nvdimm); -struct seq_buf s; +struct printbuf s =PRINTBUF_EXTERN (buf,PAGE_SIZE );u64 flags; flags = dimm->flags; -seq_buf_init (&s, buf,PAGE_SIZE );if (flags &PAPR_PMEM_UNARMED_MASK ) -seq_buf_printf (&s,"not_armed " ); +prt_printf (&s,"not_armed " );if (flags &PAPR_PMEM_BAD_SHUTDOWN_MASK ) -seq_buf_printf (&s,"flush_fail " ); +prt_printf (&s,"flush_fail " );if (flags &PAPR_PMEM_BAD_RESTORE_MASK ) -seq_buf_printf (&s,"restore_fail " ); +prt_printf (&s,"restore_fail " );if (flags &PAPR_PMEM_SAVE_MASK ) -seq_buf_printf (&s,"save_fail " ); +prt_printf (&s,"save_fail " );if (flags &PAPR_PMEM_SMART_EVENT_MASK ) -seq_buf_printf (&s,"smart_notify " ); +prt_printf (&s,"smart_notify " ); +if (printbuf_written (&s)) +prt_printf (&s,"\n" ); -if (seq_buf_used (&s)) -seq_buf_printf (&s,"\n" ); - -return seq_buf_used (&s); +return printbuf_written (&s); }static DEVICE_ATTR_RO (flags);
Signature · 1 line
2.36.1
PATCH 4/11 powerpc: Convert to printbuf
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
This converts from seq_buf to printbuf. We're using printbuf in external buffer mode, so it's a direct conversion, aside from some trivial refactoring in cpu_show_meltdown() to make the code more consistent.
--- arch/powerpc/kernel/process.c | 16 +++-- arch/powerpc/kernel/security.c | 75 ++++++++++------------- arch/powerpc/platforms/pseries/papr_scm.c | 34 +++++----- 3 files changed, 57 insertions(+), 68 deletions(-)
arch/powerpc/kernel/process.c +7 -9
@@ -37,7 +37,7 @@#include <linux/hw_breakpoint.h> #include <linux/uaccess.h> #include <linux/pkeys.h> -#include <linux/seq_buf.h> +#include <linux/printbuf.h> #include <asm/interrupt.h> #include <asm/io.h>
@@ -1396,32 +1396,30 @@ void show_user_instructions(struct pt_regs *regs) {unsigned long pc;int n =NR_INSN_TO_PRINT ; -struct seq_buf s;char buf[96 ];/* enough for 8 times 9 + 2 chars */ +struct printbuf s =PRINTBUF_EXTERN (buf,sizeof (buf)); pc = regs->nip - (NR_INSN_TO_PRINT *3 /4 *sizeof (int )); -seq_buf_init (&s, buf,sizeof (buf)); -while (n) {int i; -seq_buf_clear (&s); +printbuf_reset (&s);for (i =0 ; i <8 && n; i++, n--, pc +=sizeof (int )) {int instr;if (copy_from_user_nofault (&instr, (void __user *)pc,sizeof (instr))) { -seq_buf_printf (&s,"XXXXXXXX " ); +prt_printf (&s,"XXXXXXXX " );continue ; } -seq_buf_printf (&s, regs->nip == pc ?"<%08x> " :"%08x " , instr); +prt_printf (&s, regs->nip == pc ?"<%08x> " :"%08x " , instr); } -if (!seq_buf_has_overflowed (&s)) +if (printbuf_remaining (&s))pr_info ("%s[%d]: code: %s\n" , current->comm, - current->pid, s.buffer); + current->pid, s.buf); } }
arch/powerpc/kernel/security.c +34 -41
142 lines not on this page · raw message
arch/powerpc/platforms/pseries/papr_scm.c +16 -18
@@ -12,7 +12,7 @@#include <linux/libnvdimm.h> #include <linux/platform_device.h> #include <linux/delay.h> -#include <linux/seq_buf.h> +#include <linux/printbuf.h> #include <linux/nd.h> #include <asm/plpar_wrappers.h>
@@ -1142,7 +1142,7 @@ static ssize_t perf_stats_show(struct device *dev, {int index;ssize_t rc; -struct seq_buf s; +struct printbuf s =PRINTBUF_EXTERN (buf,PAGE_SIZE );struct papr_scm_perf_stat *stat;struct papr_scm_perf_stats *stats;struct nvdimm *dimm =to_nvdimm (dev);
@@ -1165,18 +1165,17 @@ static ssize_t perf_stats_show(struct device *dev,* values. Since stat_id is essentially a char string of * 8 bytes, simply use the string format specifier to print it. */ -seq_buf_init (&s, buf,PAGE_SIZE );for (index =0 , stat = stats->scm_statistic; index <be32_to_cpu (stats->num_statistics); ++index, ++stat) { -seq_buf_printf (&s,"%.8s = 0x%016llX\n" , - stat->stat_id, -be64_to_cpu (stat->stat_val)); +prt_printf (&s,"%.8s = 0x%016llX\n" , + stat->stat_id, +be64_to_cpu (stat->stat_val)); } free_stats:kfree (stats); -return rc ? rc : (ssize_t )seq_buf_used (&s); +return rc ?:printbuf_written (&s); }static DEVICE_ATTR_ADMIN_RO (perf_stats);
@@ -1185,7 +1184,7 @@ static ssize_t flags_show(struct device *dev, {struct nvdimm *dimm =to_nvdimm (dev);struct papr_scm_priv *p =nvdimm_provider_data (dimm); -struct seq_buf s; +struct printbuf s =PRINTBUF_EXTERN (buf,PAGE_SIZE );u64 health;int rc;
@@ -1196,29 +1195,28 @@ static ssize_t flags_show(struct device *dev,/* Copy health_bitmap locally, check masks & update out buffer */ health =READ_ONCE (p->health_bitmap); -seq_buf_init (&s, buf,PAGE_SIZE );if (health &PAPR_PMEM_UNARMED_MASK ) -seq_buf_printf (&s,"not_armed " ); +prt_printf (&s,"not_armed " );if (health &PAPR_PMEM_BAD_SHUTDOWN_MASK ) -seq_buf_printf (&s,"flush_fail " ); +prt_printf (&s,"flush_fail " );if (health &PAPR_PMEM_BAD_RESTORE_MASK ) -seq_buf_printf (&s,"restore_fail " ); +prt_printf (&s,"restore_fail " );if (health &PAPR_PMEM_ENCRYPTED ) -seq_buf_printf (&s,"encrypted " ); +prt_printf (&s,"encrypted " );if (health &PAPR_PMEM_SMART_EVENT_MASK ) -seq_buf_printf (&s,"smart_notify " ); +prt_printf (&s,"smart_notify " );if (health &PAPR_PMEM_SCRUBBED_AND_LOCKED ) -seq_buf_printf (&s,"scrubbed locked " ); +prt_printf (&s,"scrubbed locked " ); -if (seq_buf_used (&s)) -seq_buf_printf (&s,"\n" ); +if (printbuf_written (&s)) +prt_printf (&s,"\n" ); -return seq_buf_used (&s); +return printbuf_written (&s); }DEVICE_ATTR_RO (flags);
Signature · 1 line
2.36.1
PATCH 5/11 x86/resctrl: Convert to printbuf
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
This converts from seq_buf to printbuf. We're using printbuf in external buffer mode so it's a trivial direct conversion.
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8 -8
@@ -19,7 +19,7 @@#include <linux/fs_parser.h> #include <linux/sysfs.h> #include <linux/kernfs.h> -#include <linux/seq_buf.h> +#include <linux/printbuf.h> #include <linux/seq_file.h> #include <linux/sched/signal.h> #include <linux/sched/task.h>
@@ -51,7 +51,7 @@ static struct kernfs_node *kn_mongrp;/* Kernel fs node for "mon_data" directory under root */ static struct kernfs_node *kn_mondata; -static struct seq_buf last_cmd_status; +static struct printbuf last_cmd_status;static char last_cmd_status_buf[512 ];struct dentry *debugfs_resctrl;
@@ -59,13 +59,13 @@ struct dentry *debugfs_resctrl;void rdt_last_cmd_clear (void ) {lockdep_assert_held (&rdtgroup_mutex); -seq_buf_clear (&last_cmd_status); +printbuf_reset (&last_cmd_status); }void rdt_last_cmd_puts (const char *s) {lockdep_assert_held (&rdtgroup_mutex); -seq_buf_puts (&last_cmd_status, s); +prt_str (&last_cmd_status, s); }void rdt_last_cmd_printf (const char *fmt, ...)
@@ -74,7 +74,7 @@ void rdt_last_cmd_printf(const char *fmt, ...)va_start (ap, fmt);lockdep_assert_held (&rdtgroup_mutex); -seq_buf_vprintf (&last_cmd_status, fmt, ap); +prt_vprintf (&last_cmd_status, fmt, ap);va_end (ap); }
@@ -833,7 +833,7 @@ static int rdt_last_cmd_status_show(struct kernfs_open_file *of,int len;mutex_lock (&rdtgroup_mutex); - len =seq_buf_used (&last_cmd_status); + len =printbuf_written (&last_cmd_status);if (len)seq_printf (seq,"%.*s" , len, last_cmd_status_buf);else
@@ -3248,8 +3248,8 @@ int __init rdtgroup_init(void) {int ret =0 ; -seq_buf_init (&last_cmd_status, last_cmd_status_buf, -sizeof (last_cmd_status_buf)); + last_cmd_status =PRINTBUF_EXTERN (last_cmd_status_buf, +sizeof (last_cmd_status_buf)); ret =rdtgroup_setup_root ();if (ret)
Signature · 1 line
2.36.1
PATCH 6/11 PCI/P2PDMA: Convert to printbuf
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
This converts from seq_buf to printbuf. We're using printbuf in external buffer mode so this is a direct conversion.
--- drivers/pci/p2pdma.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/pci/p2pdma.c +8 -13
@@ -18,7 +18,7 @@#include <linux/memremap.h> #include <linux/percpu-refcount.h> #include <linux/random.h> -#include <linux/seq_buf.h> +#include <linux/printbuf.h> #include <linux/xarray.h> struct pci_p2pdma {
@@ -275,12 +275,9 @@ static int pci_bridge_has_acs_redir(struct pci_dev *pdev)return 0 ; } -static void seq_buf_print_bus_devfn (struct seq_buf *buf,struct pci_dev *pdev) +static void prt_bus_devfn (struct printbuf *buf,struct pci_dev *pdev) { -if (!buf) -return ; - -seq_buf_printf (buf,"%s;" ,pci_name (pdev)); +prt_printf (buf,"%s;" ,pci_name (pdev)); }static bool cpu_supports_p2pdma (void )
@@ -454,13 +451,11 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client,struct pci_dev *a = provider, *b = client, *bb;bool acs_redirects = false;struct pci_p2pdma *p2pdma; -struct seq_buf acs_list;int acs_cnt =0 ;int dist_a =0 ;int dist_b =0 ;char buf[128 ]; - -seq_buf_init (&acs_list, buf,sizeof (buf)); +struct printbuf acs_list =PRINTBUF_EXTERN (buf,sizeof (buf));/* * Note, we don't need to take references to devices returned by
@@ -471,7 +466,7 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client, dist_b =0 ;if (pci_bridge_has_acs_redir (a)) { -seq_buf_print_bus_devfn (&acs_list, a); +prt_bus_devfn (&acs_list, a); acs_cnt++; }
@@ -500,7 +495,7 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client,break ;if (pci_bridge_has_acs_redir (bb)) { -seq_buf_print_bus_devfn (&acs_list, bb); +prt_bus_devfn (&acs_list, bb); acs_cnt++; }
@@ -515,11 +510,11 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client, }if (verbose) { - acs_list.buffer[acs_list.len-1 ] =0 ;/* drop final semicolon */ + acs_list.buf[acs_list.pos-1 ] =0 ;/* drop final semicolon */ pci_warn (client,"ACS redirect is set between the client and provider (%s)\n" ,pci_name (provider));pci_warn (client,"to disable ACS redirect for this path, add the kernel parameter: pci=disable_acs_redir=%s\n" , - acs_list.buffer); + acs_list.buf); } acs_redirects = true;
Signature · 1 line
2.36.1
PATCH 7/11 tracing: trace_events_synth: Convert to printbuf
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
This converts from seq_buf to printbuf.
This code was using seq_buf for building up dynamically allocated strings; the conversion uses printbuf's heap allocation functionality to simplify things (no longer need to calculate size of the output string).
Also, alphabetize the #includes.
--- kernel/trace/trace_events_synth.c | 51 ++++++++++--------------------- 1 file changed, 16 insertions(+), 35 deletions(-)
kernel/trace/trace_events_synth.c +16 -35
@@ -5,13 +5,14 @@* Copyright (C) 2015, 2020 Tom Zanussi <[email protected]> */ -#include <linux/module.h> #include <linux/kallsyms.h> -#include <linux/security.h> +#include <linux/module.h> #include <linux/mutex.h> +#include <linux/printbuf.h> +#include <linux/rculist.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/stacktrace.h> -#include <linux/rculist.h> #include <linux/tracefs.h> /* for gfp flag names */
@@ -611,7 +612,7 @@ static struct synth_field *parse_synth_field(int argc, char **argv,const char *prefix =NULL , *field_type = argv[0 ], *field_name, *array;struct synth_field *field;int len, ret = -ENOMEM ; -struct seq_buf s; +struct printbuf buf;ssize_t size;if (!strcmp (field_type,"unsigned" )) {
@@ -654,28 +655,16 @@ static struct synth_field *parse_synth_field(int argc, char **argv, goto free; } - len =strlen (field_type) +1 ; - -if (array) - len +=strlen (array); - -if (prefix) - len +=strlen (prefix); - - field->type =kzalloc (len,GFP_KERNEL ); -if (!field->type) - goto free; - -seq_buf_init (&s, field->type, len); + buf =PRINTBUF ;if (prefix) -seq_buf_puts (&s, prefix); -seq_buf_puts (&s, field_type); +prt_str (&buf, prefix); +prt_str (&buf, field_type);if (array) -seq_buf_puts (&s, array); -if (WARN_ON_ONCE (!seq_buf_buffer_left (&s))) +prt_str (&buf, array); +if (buf.allocation_failure) goto free; - s.buffer[s.len] ='\0' ; + field->type = buf.buf; size =synth_field_size (field->type);if (size <0 ) {
@@ -687,23 +676,15 @@ static struct synth_field *parse_synth_field(int argc, char **argv, goto free; }else if (size ==0 ) {if (synth_field_is_string (field->type)) { -char *type; - - len =sizeof ("__data_loc " ) +strlen (field->type) +1 ; - type =kzalloc (len,GFP_KERNEL ); -if (!type) - goto free; - -seq_buf_init (&s, type, len); -seq_buf_puts (&s,"__data_loc " ); -seq_buf_puts (&s, field->type); + buf =PRINTBUF ; +prt_str (&buf,"__data_loc " ); +prt_str (&buf, field->type); -if (WARN_ON_ONCE (!seq_buf_buffer_left (&s))) +if (buf.allocation_failure) goto free; - s.buffer[s.len] ='\0' ;kfree (field->type); - field->type = type; + field->type = buf.buf; field->is_dynamic = true; size =sizeof (u64);
Signature · 1 line
2.36.1
Steven Rostedt
maintainerRe: [PATCH 07/11] tracing: trace_events_synth: Convert to printbuf
Quoted 7 lines · On Mon, 15 Aug 2022 13:26:09 -0400 Kent Overstreet <[email protected]>…
From: Kent Overstreet <[email protected]>
This converts from
seq_bufto printbuf.This code was using
seq_buffor building up dynamically allocated strings; the conversion uses printbuf's heap allocation functionality to simplify things (no longer need to calculate size of the output string).
As I stated before. I'll look into converting the seq_bufs to printbuf for tracing at a later date. That includes this file.
Please remove this patch from the series.
Quoted 3 lines
Also, alphabetize the #includes.
And although the #includes are not in the order the tracing directory prefers, that order is upside-down x-mas tree, not alphabetical.
Thanks,
-- Steve
Quoted 102 lines
Signed-off-by Kent Overstreet <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ingo Molnar <[email protected]>--- kernel/trace/trace_events_synth.c | 51 ++++++++++--------------------- 1 file changed, 16 insertions(+), 35 deletions(-)kernel/trace/trace_events_synth.c +16
-35@@ -5,13 +5,14 @@* Copyright (C) 2015, 2020 Tom Zanussi <[email protected]> */ -#include <linux/module.h> #include <linux/kallsyms.h> -#include <linux/security.h> +#include <linux/module.h> #include <linux/mutex.h> +#include <linux/printbuf.h> +#include <linux/rculist.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/stacktrace.h> -#include <linux/rculist.h> #include <linux/tracefs.h> /* for gfp flag names */ @@ -611,7 +612,7 @@ static struct synth_field *parse_synth_field(int argc, char **argv,const char *prefix =NULL , *field_type = argv[0 ], *field_name, *array;struct synth_field *field;int len, ret = -ENOMEM ; -struct seq_buf s; +struct printbuf buf;ssize_t size;if (!strcmp (field_type,"unsigned" )) {@@ -654,28 +655,16 @@ static struct synth_field *parse_synth_field(int argc, char **argv, goto free; } - len =strlen (field_type) +1 ; - -if (array) - len +=strlen (array); - -if (prefix) - len +=strlen (prefix); - - field->type =kzalloc (len,GFP_KERNEL ); -if (!field->type) - goto free; - -seq_buf_init (&s, field->type, len); + buf =PRINTBUF ;if (prefix) -seq_buf_puts (&s, prefix); -seq_buf_puts (&s, field_type); +prt_str (&buf, prefix); +prt_str (&buf, field_type);if (array) -seq_buf_puts (&s, array); -if (WARN_ON_ONCE (!seq_buf_buffer_left (&s))) +prt_str (&buf, array); +if (buf.allocation_failure) goto free; - s.buffer[s.len] ='\0' ; + field->type = buf.buf; size =synth_field_size (field->type);if (size <0 ) {@@ -687,23 +676,15 @@ static struct synth_field *parse_synth_field(int argc, char **argv, goto free; }else if (size ==0 ) {if (synth_field_is_string (field->type)) { -char *type; - - len =sizeof ("__data_loc " ) +strlen (field->type) +1 ; - type =kzalloc (len,GFP_KERNEL ); -if (!type) - goto free; - -seq_buf_init (&s, type, len); -seq_buf_puts (&s,"__data_loc " ); -seq_buf_puts (&s, field->type); + buf =PRINTBUF ; +prt_str (&buf,"__data_loc " ); +prt_str (&buf, field->type); -if (WARN_ON_ONCE (!seq_buf_buffer_left (&s))) +if (buf.allocation_failure) goto free; - s.buffer[s.len] ='\0' ;kfree (field->type); - field->type = type; + field->type = buf.buf; field->is_dynamic = true; size =sizeof (u64);
Re: [PATCH 07/11] tracing: trace_events_synth: Convert to printbuf
Quoted 5 lines · Steven Rostedt
Quoted 2 lines · On Mon, 15 Aug 2022 13:26:09 -0400 Kent Overstreet <[email protected]>…
From: Kent Overstreet <[email protected]>
Quoted 8 lines
Quoted 5 lines
This converts from
seq_bufto printbuf.This code was using
seq_buffor building up dynamically allocated strings; the conversion uses printbuf's heap allocation functionality to simplify things (no longer need to calculate size of the output string).As I stated before. I'll look into converting the
seq_bufsto printbuf for tracing at a later date. That includes this file.
You specified the other tracing patch, you did not specify this one.
Andrew, I just reran the tracing tests with this patch dropped - you can just drop it, no other fixups are required.
Steven Rostedt
maintainerRe: [PATCH 07/11] tracing: trace_events_synth: Convert to printbuf
Quoted 1 line · On Mon, 15 Aug 2022 13:58:30 -0400 Kent Overstreet <[email protected]>…
You specified the other tracing patch, you did not specify this one.
I said: "As I said. Feel free to move seq_buf.c back into the tracing directory (but
still need to keep seq_buf.h in include/linux), and feel free to convert all the other users besides tracing, to printbuf."
This is one of the tracing patches.
Quoted 3 lines
Andrew, I just reran the tracing tests with this patch dropped - you can just drop it, no other fixups are required.
Thanks,
-- Steve
PATCH 8/11 d_path: prt_path()
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
This implements a new printbuf version of d_path()/mangle_path(), which will replace the seq_buf version.
--- fs/d_path.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/dcache.h | 1 + 2 files changed, 36 insertions(+)
fs/d_path.c +35 -0
@@ -5,6 +5,7 @@#include <linux/fs_struct.h> #include <linux/fs.h> #include <linux/slab.h> +#include <linux/printbuf.h> #include <linux/prefetch.h> #include "mount.h"
@@ -294,6 +295,40 @@ char *d_path(const struct path *path, char *buf, int buflen) }EXPORT_SYMBOL (d_path); +/** +* prt_path - format a path for output +* @out: printbuf to output to +* @path: path to write into the sequence buffer. +* @esc: set of characters to escape in the output +* +* Write a path name into the sequence buffer. +* +* Returns 0 on success, or error code from d_path +*/ +int prt_path (struct printbuf *out,const struct path *path,const char *esc) +{ +char *p, *buf; +size_t size; +again: + buf = out->buf + out->pos; + size =printbuf_remaining_size (out); + + p =d_path (path, buf, size); +if (IS_ERR (p)) { +printbuf_make_room (out,max_t (size_t,64 , size *2 )); +if (printbuf_remaining_size (out) > size) + goto again; + +return PTR_ERR (p); + } + + p =mangle_path (buf, p, esc); +if (p) + out->pos += p - buf; +return 0 ; +} +EXPORT_SYMBOL (prt_path); +/* * Helper function for dentry_operations.d_dname() members */
include/linux/dcache.h +1 -0
@@ -293,6 +293,7 @@ extern char *d_absolute_path(const struct path *, char *, int);extern char *d_path (const struct path *,char *,int );extern char *dentry_path_raw (const struct dentry *,char *,int );extern char *dentry_path (const struct dentry *,char *,int ); +extern int prt_path (struct printbuf *,const struct path *,const char *);/* Allocation counts.. */
Signature · 1 line
2.36.1
PATCH 9/11 ACPI/APEI: Add missing include
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
The upcoming patch to switch tracing from seq_buf to printbuf means we're no longer pulling in headers that we used to; this adds a missing include so things don't break.
--- drivers/acpi/apei/erst-dbg.c | 1 + 1 file changed, 1 insertion(+)
drivers/acpi/apei/erst-dbg.c +1 -0
@@ -11,6 +11,7 @@* Author: Huang Ying <[email protected]> */ +#include <linux/fs.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/uaccess.h>
Signature · 1 line
2.36.1
PATCH 10/11 seq_buf: Move to kernel/tracing
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
Tracing is the last user of seq_buf, which has been replaced by printbufs elsewhere; move out of lib/ since it's no longer the standard API.
---
kernel/trace/Makefile | 1 +
{lib => kernel/trace}/seq_buf.c | 0
lib/Makefile | 2 +-
3 files changed, 2 insertions(+), 1 deletion(-)
rename {lib => kernel/trace}/seq_buf.c (100%)kernel/trace/Makefile +1 -0
@@ -52,6 +52,7 @@ obj-$(CONFIG_TRACING) += trace_seq.o obj-$(CONFIG_TRACING) += trace_stat.o obj-$(CONFIG_TRACING) += trace_printk.o obj-$(CONFIG_TRACING) += pid_list.o +obj-$(CONFIG_TRACING) += seq_buf.o obj-$(CONFIG_TRACING_MAP) += tracing_map.o obj-$(CONFIG_PREEMPTIRQ_DELAY_TEST) += preemptirq_delay_test.o obj-$(CONFIG_SYNTH_EVENT_GEN_TEST) += synth_event_gen_test.o
kernel/trace/seq_buf.c renamed from lib/seq_buf.c +0 -0
lib/Makefile +1 -1
@@ -32,7 +32,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ idr.o extable.o irq_regs.o argv_split.o \ flex_proportions.o ratelimit.o show_mem.o \ is_single_threaded.o plist.o decompress.o kobject_uevent.o \ - earlycpio.o seq_buf.o siphash.o dec_and_lock.o \ + earlycpio.o siphash.o dec_and_lock.o \ nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \ buildid.o cpumask.o printbuf.o
Signature · 1 line
2.36.1
PATCH 11/11 MAINTAINERS: Add entry for printbufs
In reply to Kent OverstreetFrom: Kent Overstreet <[email protected]>
Printbufs are a new string building library; adding myself as the author of this code.
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -16365,6 +16365,12 @@ S: Maintained F: include/linux/psi* F: kernel/sched/psi.c +PRINTBUF +M: Kent Overstreet <[email protected]> +S: Maintained +F: include/linux/printbuf.h +F: lib/printbuf.c + PRINTK M: Petr Mladek <[email protected]> M: Sergey Senozhatsky <[email protected]>
Signature · 1 line
2.36.1