linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Printbufs v6
@ 2022-08-15 17:26 Kent Overstreet
  2022-08-15 17:26 ` [PATCH 01/11] mm/memcontrol.c: Convert to printbuf Kent Overstreet
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

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



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 01/11] mm/memcontrol.c: Convert to printbuf
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:26 ` [PATCH 02/11] clk: tegra: bpmp: " Kent Overstreet
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm
  Cc: linux-kernel, Kent Overstreet, Johannes Weiner, Michal Hocko,
	Roman Gushchin, Michal Hocko

From: Kent Overstreet <kent.overstreet@gmail.com>

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.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Michal Hocko <mhocko@suse.com>
---
 mm/memcontrol.c | 54 ++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b69979c9ce..54897e4ac4 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -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
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 02/11] clk: tegra: bpmp: Convert to printbuf
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
  2022-08-15 17:26 ` [PATCH 01/11] mm/memcontrol.c: Convert to printbuf Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:26 ` [PATCH 03/11] tools/testing/nvdimm: " Kent Overstreet
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Kent Overstreet, linux-tegra

From: Kent Overstreet <kent.overstreet@gmail.com>

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.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: linux-tegra@vger.kernel.org
---
 drivers/clk/tegra/clk-bpmp.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
index 3748a39dae..7e3b48ed9d 100644
--- a/drivers/clk/tegra/clk-bpmp.c
+++ b/drivers/clk/tegra/clk-bpmp.c
@@ -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,
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 03/11] tools/testing/nvdimm: Convert to printbuf
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
  2022-08-15 17:26 ` [PATCH 01/11] mm/memcontrol.c: Convert to printbuf Kent Overstreet
  2022-08-15 17:26 ` [PATCH 02/11] clk: tegra: bpmp: " Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:26 ` [PATCH 04/11] powerpc: " Kent Overstreet
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm
  Cc: linux-kernel, Kent Overstreet, Dan Williams, Dave Hansen, nvdimm,
	Shivaprasad G Bhat

From: Kent Overstreet <kent.overstreet@gmail.com>

This converts from seq_buf to printbuf. Here we're using printbuf with
an external buffer, meaning it's a direct conversion.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: nvdimm@lists.linux.dev
Acked-by: Dan Williams <dan.j.williams@intel.com>
Tested-By: Shivaprasad G Bhat <sbhat@linux.ibm.com>
---
 tools/testing/nvdimm/test/ndtest.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
index 4d1a947367..a2097955da 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -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);
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 04/11] powerpc: Convert to printbuf
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
                   ` (2 preceding siblings ...)
  2022-08-15 17:26 ` [PATCH 03/11] tools/testing/nvdimm: " Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:26 ` [PATCH 05/11] x86/resctrl: " Kent Overstreet
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Kent Overstreet, linuxppc-dev

From: Kent Overstreet <kent.overstreet@gmail.com>

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.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: linuxppc-dev@lists.ozlabs.org
---
 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(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 0fbda89cd1..05654dbeb2 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -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);
 	}
 }
 
diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c
index d96fd14bd7..b34de62e65 100644
--- a/arch/powerpc/kernel/security.c
+++ b/arch/powerpc/kernel/security.c
@@ -10,7 +10,7 @@
 #include <linux/memblock.h>
 #include <linux/nospec.h>
 #include <linux/prctl.h>
-#include <linux/seq_buf.h>
+#include <linux/printbuf.h>
 #include <linux/debugfs.h>
 
 #include <asm/asm-prototypes.h>
@@ -144,31 +144,28 @@ void __init setup_spectre_v2(void)
 #ifdef CONFIG_PPC_BOOK3S_64
 ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf)
 {
+	struct printbuf s = PRINTBUF_EXTERN(buf, PAGE_SIZE);
 	bool thread_priv;
 
 	thread_priv = security_ftr_enabled(SEC_FTR_L1D_THREAD_PRIV);
 
 	if (rfi_flush) {
-		struct seq_buf s;
-		seq_buf_init(&s, buf, PAGE_SIZE - 1);
 
-		seq_buf_printf(&s, "Mitigation: RFI Flush");
+		prt_printf(&s, "Mitigation: RFI Flush");
 		if (thread_priv)
-			seq_buf_printf(&s, ", L1D private per thread");
-
-		seq_buf_printf(&s, "\n");
-
-		return s.len;
+			prt_printf(&s, ", L1D private per thread");
+
+		prt_printf(&s, "\n");
+	} else if (thread_priv) {
+		prt_printf(&s, "Vulnerable: L1D private per thread\n");
+	} else if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) &&
+		   !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR)) {
+		prt_printf(&s, "Not affected\n");
+	} else {
+		prt_printf(&s, "Vulnerable\n");
 	}
 
-	if (thread_priv)
-		return sprintf(buf, "Vulnerable: L1D private per thread\n");
-
-	if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) &&
-	    !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR))
-		return sprintf(buf, "Not affected\n");
-
-	return sprintf(buf, "Vulnerable\n");
+	return printbuf_written(&s);
 }
 
 ssize_t cpu_show_l1tf(struct device *dev, struct device_attribute *attr, char *buf)
@@ -179,70 +176,66 @@ ssize_t cpu_show_l1tf(struct device *dev, struct device_attribute *attr, char *b
 
 ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	struct seq_buf s;
-
-	seq_buf_init(&s, buf, PAGE_SIZE - 1);
+	struct printbuf s = PRINTBUF_EXTERN(buf, PAGE_SIZE);
 
 	if (security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR)) {
 		if (barrier_nospec_enabled)
-			seq_buf_printf(&s, "Mitigation: __user pointer sanitization");
+			prt_printf(&s, "Mitigation: __user pointer sanitization");
 		else
-			seq_buf_printf(&s, "Vulnerable");
+			prt_printf(&s, "Vulnerable");
 
 		if (security_ftr_enabled(SEC_FTR_SPEC_BAR_ORI31))
-			seq_buf_printf(&s, ", ori31 speculation barrier enabled");
+			prt_printf(&s, ", ori31 speculation barrier enabled");
 
-		seq_buf_printf(&s, "\n");
+		prt_printf(&s, "\n");
 	} else
-		seq_buf_printf(&s, "Not affected\n");
+		prt_printf(&s, "Not affected\n");
 
-	return s.len;
+	return printbuf_written(&s);
 }
 
 ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	struct seq_buf s;
+	struct printbuf s = PRINTBUF_EXTERN(buf, PAGE_SIZE);
 	bool bcs, ccd;
 
-	seq_buf_init(&s, buf, PAGE_SIZE - 1);
-
 	bcs = security_ftr_enabled(SEC_FTR_BCCTRL_SERIALISED);
 	ccd = security_ftr_enabled(SEC_FTR_COUNT_CACHE_DISABLED);
 
 	if (bcs || ccd) {
-		seq_buf_printf(&s, "Mitigation: ");
+		prt_printf(&s, "Mitigation: ");
 
 		if (bcs)
-			seq_buf_printf(&s, "Indirect branch serialisation (kernel only)");
+			prt_printf(&s, "Indirect branch serialisation (kernel only)");
 
 		if (bcs && ccd)
-			seq_buf_printf(&s, ", ");
+			prt_printf(&s, ", ");
 
 		if (ccd)
-			seq_buf_printf(&s, "Indirect branch cache disabled");
+			prt_printf(&s, "Indirect branch cache disabled");
 
 	} else if (count_cache_flush_type != BRANCH_CACHE_FLUSH_NONE) {
-		seq_buf_printf(&s, "Mitigation: Software count cache flush");
+		prt_printf(&s, "Mitigation: Software count cache flush");
 
 		if (count_cache_flush_type == BRANCH_CACHE_FLUSH_HW)
-			seq_buf_printf(&s, " (hardware accelerated)");
+			prt_printf(&s, " (hardware accelerated)");
 
 	} else if (btb_flush_enabled) {
-		seq_buf_printf(&s, "Mitigation: Branch predictor state flush");
+		prt_printf(&s, "Mitigation: Branch predictor state flush");
 	} else {
-		seq_buf_printf(&s, "Vulnerable");
+		prt_printf(&s, "Vulnerable");
 	}
 
 	if (bcs || ccd || count_cache_flush_type != BRANCH_CACHE_FLUSH_NONE) {
 		if (link_stack_flush_type != BRANCH_CACHE_FLUSH_NONE)
-			seq_buf_printf(&s, ", Software link stack flush");
+			prt_printf(&s, ", Software link stack flush");
 		if (link_stack_flush_type == BRANCH_CACHE_FLUSH_HW)
-			seq_buf_printf(&s, " (hardware accelerated)");
+			prt_printf(&s, " (hardware accelerated)");
 	}
 
-	seq_buf_printf(&s, "\n");
+	prt_printf(&s, "\n");
 
-	return s.len;
+	return printbuf_written(&s);
 }
 
 #ifdef CONFIG_PPC_BOOK3S_64
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 20f6ed813b..a1fd25243c 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -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);
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 05/11] x86/resctrl: Convert to printbuf
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
                   ` (3 preceding siblings ...)
  2022-08-15 17:26 ` [PATCH 04/11] powerpc: " Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:26 ` [PATCH 06/11] PCI/P2PDMA: " Kent Overstreet
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Kent Overstreet, x86

From: Kent Overstreet <kent.overstreet@gmail.com>

This converts from seq_buf to printbuf. We're using printbuf in external
buffer mode so it's a trivial direct conversion.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: x86@kernel.org
---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index f276aff521..50c12711a2 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -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)
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 06/11] PCI/P2PDMA: Convert to printbuf
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
                   ` (4 preceding siblings ...)
  2022-08-15 17:26 ` [PATCH 05/11] x86/resctrl: " Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:26 ` [PATCH 07/11] tracing: trace_events_synth: " Kent Overstreet
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Kent Overstreet, linux-pci

From: Kent Overstreet <kent.overstreet@gmail.com>

This converts from seq_buf to printbuf. We're using printbuf in external
buffer mode so this is a direct conversion.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: linux-pci@vger.kernel.org
---
 drivers/pci/p2pdma.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index 4496a7c5c4..8e29e7caba 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -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;
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 07/11] tracing: trace_events_synth: Convert to printbuf
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
                   ` (5 preceding siblings ...)
  2022-08-15 17:26 ` [PATCH 06/11] PCI/P2PDMA: " Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:43   ` Steven Rostedt
  2022-08-15 17:26 ` [PATCH 08/11] d_path: prt_path() Kent Overstreet
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Kent Overstreet, Steven Rostedt, Ingo Molnar

From: Kent Overstreet <kent.overstreet@gmail.com>

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.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
---
 kernel/trace/trace_events_synth.c | 51 ++++++++++---------------------
 1 file changed, 16 insertions(+), 35 deletions(-)

diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index 5e8c07aef0..720c75429c 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -5,13 +5,14 @@
  * Copyright (C) 2015, 2020 Tom Zanussi <tom.zanussi@linux.intel.com>
  */
 
-#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);
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 08/11] d_path: prt_path()
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
                   ` (6 preceding siblings ...)
  2022-08-15 17:26 ` [PATCH 07/11] tracing: trace_events_synth: " Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:26 ` [PATCH 09/11] ACPI/APEI: Add missing include Kent Overstreet
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Kent Overstreet, Alexander Viro

From: Kent Overstreet <kent.overstreet@gmail.com>

This implements a new printbuf version of d_path()/mangle_path(), which
will replace the seq_buf version.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
---
 fs/d_path.c            | 35 +++++++++++++++++++++++++++++++++++
 include/linux/dcache.h |  1 +
 2 files changed, 36 insertions(+)

diff --git a/fs/d_path.c b/fs/d_path.c
index e4e0ebad1f..1bd9e85f2f 100644
--- a/fs/d_path.c
+++ b/fs/d_path.c
@@ -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
  */
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index c73e5e327e..bdd5940aa7 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -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.. */
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 09/11] ACPI/APEI: Add missing include
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
                   ` (7 preceding siblings ...)
  2022-08-15 17:26 ` [PATCH 08/11] d_path: prt_path() Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:26 ` [PATCH 10/11] seq_buf: Move to kernel/tracing Kent Overstreet
  2022-08-15 17:26 ` [PATCH 11/11] MAINTAINERS: Add entry for printbufs Kent Overstreet
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Kent Overstreet, linux-acpi, Rafael J . Wysocki

From: Kent Overstreet <kent.overstreet@gmail.com>

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.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: linux-acpi@vger.kernel.org
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/apei/erst-dbg.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/acpi/apei/erst-dbg.c b/drivers/acpi/apei/erst-dbg.c
index 8bc71cdc22..370993c9c3 100644
--- a/drivers/acpi/apei/erst-dbg.c
+++ b/drivers/acpi/apei/erst-dbg.c
@@ -11,6 +11,7 @@
  *   Author: Huang Ying <ying.huang@intel.com>
  */
 
+#include <linux/fs.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/uaccess.h>
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 10/11] seq_buf: Move to kernel/tracing
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
                   ` (8 preceding siblings ...)
  2022-08-15 17:26 ` [PATCH 09/11] ACPI/APEI: Add missing include Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  2022-08-15 17:26 ` [PATCH 11/11] MAINTAINERS: Add entry for printbufs Kent Overstreet
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Kent Overstreet, Steven Rostedt

From: Kent Overstreet <kent.overstreet@gmail.com>

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.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
---
 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%)

diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index c6651e16b5..03ad4d8c27 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -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
diff --git a/lib/seq_buf.c b/kernel/trace/seq_buf.c
similarity index 100%
rename from lib/seq_buf.c
rename to kernel/trace/seq_buf.c
diff --git a/lib/Makefile b/lib/Makefile
index d44f8d03d6..9ed57a1f9f 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -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
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 11/11] MAINTAINERS: Add entry for printbufs
  2022-08-15 17:26 Printbufs v6 Kent Overstreet
                   ` (9 preceding siblings ...)
  2022-08-15 17:26 ` [PATCH 10/11] seq_buf: Move to kernel/tracing Kent Overstreet
@ 2022-08-15 17:26 ` Kent Overstreet
  10 siblings, 0 replies; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Kent Overstreet

From: Kent Overstreet <kent.overstreet@gmail.com>

Printbufs are a new string building library; adding myself as the author
of this code.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b7deb6e92a..d954af7a84 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16365,6 +16365,12 @@ S:	Maintained
 F:	include/linux/psi*
 F:	kernel/sched/psi.c
 
+PRINTBUF
+M:	Kent Overstreet <kent.overstreet@linux.dev>
+S:	Maintained
+F:	include/linux/printbuf.h
+F:	lib/printbuf.c
+
 PRINTK
 M:	Petr Mladek <pmladek@suse.com>
 M:	Sergey Senozhatsky <senozhatsky@chromium.org>
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 07/11] tracing: trace_events_synth: Convert to printbuf
  2022-08-15 17:26 ` [PATCH 07/11] tracing: trace_events_synth: " Kent Overstreet
@ 2022-08-15 17:43   ` Steven Rostedt
  2022-08-15 17:58     ` Kent Overstreet
  0 siblings, 1 reply; 15+ messages in thread
From: Steven Rostedt @ 2022-08-15 17:43 UTC (permalink / raw)
  To: Kent Overstreet; +Cc: akpm, linux-kernel, Kent Overstreet, Ingo Molnar

On Mon, 15 Aug 2022 13:26:09 -0400
Kent Overstreet <kent.overstreet@linux.dev> wrote:

> From: Kent Overstreet <kent.overstreet@gmail.com>
> 
> 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).

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.

> 
> 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


> Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> ---
>  kernel/trace/trace_events_synth.c | 51 ++++++++++---------------------
>  1 file changed, 16 insertions(+), 35 deletions(-)
> 
> diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
> index 5e8c07aef0..720c75429c 100644
> --- a/kernel/trace/trace_events_synth.c
> +++ b/kernel/trace/trace_events_synth.c
> @@ -5,13 +5,14 @@
>   * Copyright (C) 2015, 2020 Tom Zanussi <tom.zanussi@linux.intel.com>
>   */
>  
> -#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);


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 07/11] tracing: trace_events_synth: Convert to printbuf
  2022-08-15 17:43   ` Steven Rostedt
@ 2022-08-15 17:58     ` Kent Overstreet
  2022-08-15 18:28       ` Steven Rostedt
  0 siblings, 1 reply; 15+ messages in thread
From: Kent Overstreet @ 2022-08-15 17:58 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: akpm, linux-kernel, Kent Overstreet, Ingo Molnar

On Mon, Aug 15, 2022 at 01:43:14PM -0400, Steven Rostedt wrote:
> On Mon, 15 Aug 2022 13:26:09 -0400
> Kent Overstreet <kent.overstreet@linux.dev> wrote:
> 
> > From: Kent Overstreet <kent.overstreet@gmail.com>
> > 
> > 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).
> 
> As I stated before. I'll look into converting the seq_bufs to 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.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 07/11] tracing: trace_events_synth: Convert to printbuf
  2022-08-15 17:58     ` Kent Overstreet
@ 2022-08-15 18:28       ` Steven Rostedt
  0 siblings, 0 replies; 15+ messages in thread
From: Steven Rostedt @ 2022-08-15 18:28 UTC (permalink / raw)
  To: Kent Overstreet; +Cc: akpm, linux-kernel, Kent Overstreet, Ingo Molnar

On Mon, 15 Aug 2022 13:58:30 -0400
Kent Overstreet <kent.overstreet@linux.dev> wrote:

> 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.

> 
> Andrew, I just reran the tracing tests with this patch dropped - you can just
> drop it, no other fixups are required.

Thanks,

-- Steve

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-08-15 18:51 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15 17:26 Printbufs v6 Kent Overstreet
2022-08-15 17:26 ` [PATCH 01/11] mm/memcontrol.c: Convert to printbuf Kent Overstreet
2022-08-15 17:26 ` [PATCH 02/11] clk: tegra: bpmp: " Kent Overstreet
2022-08-15 17:26 ` [PATCH 03/11] tools/testing/nvdimm: " Kent Overstreet
2022-08-15 17:26 ` [PATCH 04/11] powerpc: " Kent Overstreet
2022-08-15 17:26 ` [PATCH 05/11] x86/resctrl: " Kent Overstreet
2022-08-15 17:26 ` [PATCH 06/11] PCI/P2PDMA: " Kent Overstreet
2022-08-15 17:26 ` [PATCH 07/11] tracing: trace_events_synth: " Kent Overstreet
2022-08-15 17:43   ` Steven Rostedt
2022-08-15 17:58     ` Kent Overstreet
2022-08-15 18:28       ` Steven Rostedt
2022-08-15 17:26 ` [PATCH 08/11] d_path: prt_path() Kent Overstreet
2022-08-15 17:26 ` [PATCH 09/11] ACPI/APEI: Add missing include Kent Overstreet
2022-08-15 17:26 ` [PATCH 10/11] seq_buf: Move to kernel/tracing Kent Overstreet
2022-08-15 17:26 ` [PATCH 11/11] MAINTAINERS: Add entry for printbufs Kent Overstreet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).