From 59710ebf5f5752f8d85a551f15d7847f2d55f035 Mon Sep 17 00:00:00 2001 From: wangxiao65 Date: Tue, 24 Sep 2024 03:54:07 +0000 Subject: [PATCH] backport upstream patches --- ...e-skip-check_cpu_map-with-pipe-input.patch | 40 +++++++++++++ ...orrectly-sized-memset-in-check_cpu_m.patch | 35 ++++++++++++ ...en-BLKTRACESETUP-fails-and-o-is-used.patch | 57 +++++++++++++++++++ blktrace.spec | 11 +++- 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 0020-blkparse-skip-check_cpu_map-with-pipe-input.patch create mode 100644 0021-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch create mode 100644 0022-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch diff --git a/0020-blkparse-skip-check_cpu_map-with-pipe-input.patch b/0020-blkparse-skip-check_cpu_map-with-pipe-input.patch new file mode 100644 index 0000000..edac2e6 --- /dev/null +++ b/0020-blkparse-skip-check_cpu_map-with-pipe-input.patch @@ -0,0 +1,40 @@ +From ac416ab67cd7add0089c3bc668427e6b909eb59e Mon Sep 17 00:00:00 2001 +From: Jeff Mahoney +Date: Thu, 21 Oct 2021 10:16:19 -0400 +Subject: [PATCH] blkparse: skip check_cpu_map with pipe input + +When we're using pipe input, we don't track online CPUs and don't have a +cpu_map. When we start to show entries, check_sequence will be invoked. +If the first entry isn't sequence 1 (perhaps it's been dropped?), we'll +proceed to check_cpu_map. Since we haven't tracked online CPUs, +pdi->cpu_map_max will be 0 and we'll do a malloc(0). Then we'll start +setting bits corresponding to CPU numbers in memory we don't own. Since +there's nothing to check here, let's skip it on pipe input. + +Signed-off-by: Jeff Mahoney +Signed-off-by: Jens Axboe + +Conflict: no +Reference: https://git.kernel.dk/cgit/blktrace/commit/?id=ac416ab67cd7add0089c3bc668427e6b909eb59e +--- + blkparse.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/blkparse.c b/blkparse.c +index f88204a..498857c 100644 +--- a/blkparse.c ++++ b/blkparse.c +@@ -2229,6 +2229,10 @@ static int check_cpu_map(struct per_dev_info *pdi) + unsigned int i; + int ret, cpu; + ++ /* Pipe input doesn't do CPU online tracking. */ ++ if (!pdi->cpu_map_max) ++ return 0; ++ + /* + * create a map of the cpus we have traces for + */ +-- +2.33.0 + diff --git a/0021-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch b/0021-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch new file mode 100644 index 0000000..6ea9b3f --- /dev/null +++ b/0021-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch @@ -0,0 +1,35 @@ +From 7f5d2c5173d72018aa29c583c9291ef10abaf8df Mon Sep 17 00:00:00 2001 +From: Jeff Mahoney +Date: Thu, 21 Oct 2021 10:16:20 -0400 +Subject: [PATCH] blkparse: fix incorrectly sized memset in check_cpu_map + +The memset call in check_cpu_map always clears sizeof(unsigned long *) +regardless of what size was allocated. Use calloc instead to allocate +the map so it's zeroed properly regardless of the size requested. + +Signed-off-by: Jeff Mahoney +Signed-off-by: Jens Axboe + +Conflict: no +Reference: https://git.kernel.dk/cgit/blktrace/commit/?id=7f5d2c5173d72018aa29c583c9291ef10abaf8df +--- + blkparse.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/blkparse.c b/blkparse.c +index 498857c..9d2029a 100644 +--- a/blkparse.c ++++ b/blkparse.c +@@ -2236,8 +2236,7 @@ static int check_cpu_map(struct per_dev_info *pdi) + /* + * create a map of the cpus we have traces for + */ +- cpu_map = malloc(pdi->cpu_map_max / sizeof(long)); +- memset(cpu_map, 0, sizeof(*cpu_map)); ++ cpu_map = calloc(1, pdi->cpu_map_max / sizeof(long)); + n = rb_first(&rb_sort_root); + while (n) { + __t = rb_entry(n, struct trace, rb_node); +-- +2.33.0 + diff --git a/0022-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch b/0022-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch new file mode 100644 index 0000000..1aa9199 --- /dev/null +++ b/0022-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch @@ -0,0 +1,57 @@ +From 1836be5d99c9362f1e2b39206c95270f19cb7faa Mon Sep 17 00:00:00 2001 +From: Eric Sandeen +Date: Wed, 5 Jun 2024 23:07:27 -0500 +Subject: [PATCH] fix hang when BLKTRACESETUP fails and "-o -" is used + +# blktrace -o - /dev/sda /dev/sdb /dev/sdc + +has to be SIGKILLed if BLKTRACESETUP fails for any or all of the devices +listed. (I simulated this by just catching one of the devices in +setup_buts(), skipping the ioctl, and doing ret++). + +This seems to be because with "-o -" on the command line, use_tracer_devpaths() +sees piped_output set, so we call process_trace_bufs which ends up waiting on +(!done) and "done" is never set. i.e. + +atexit(exit_tracing) + wait_tracers + if (use_tracer_devpaths()) // true because "-o -" + process_trace_bufs + while (wait_empty_entries()) + wait_empty_entries + while (!done ... ) + + +I think this can be avoided by just setting "done = 1" before returning +when setup_buts() fails in run_tracers(). + +Signed-off-by: Eric Sandeen +Reviewed-by: Jeff Moyer +Link: https://lore.kernel.org/r/f3204c9d-1384-40b5-a5fb-3bb967ca2bec@redhat.com +Signed-off-by: Jens Axboe + +Conflict: no +Reference: https://git.kernel.dk/cgit/blktrace/commit/?id=1836be5d99c9362f1e2b39206c95270f19cb7faa +--- + blktrace.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/blktrace.c b/blktrace.c +index 3444fbb..038b2cb 100644 +--- a/blktrace.c ++++ b/blktrace.c +@@ -2684,8 +2684,10 @@ static int run_tracers(void) + if (net_mode == Net_client) + printf("blktrace: connecting to %s\n", hostname); + +- if (setup_buts()) ++ if (setup_buts()) { ++ done = 1; + return 1; ++ } + + if (use_tracer_devpaths()) { + if (setup_tracer_devpaths()) +-- +2.33.0 + diff --git a/blktrace.spec b/blktrace.spec index 3480f56..03645e1 100644 --- a/blktrace.spec +++ b/blktrace.spec @@ -1,6 +1,6 @@ Name: blktrace Version: 1.2.0 -Release: 26 +Release: 27 Summary: Block IO tracer in the Linux kernel License: GPLv2+ Source: http://brick.kernel.dk/snaps/blktrace-%{version}.tar.bz2 @@ -30,6 +30,9 @@ Patch16: blktrace-fix-exit-directly-when-nthreads-running.patch Patch17: 0017-blktrace-Makefile-add-fstack-protector-strong-flag.patch Patch18: 0018-fix-parallel-build-failures.patch Patch19: 0019-fix-parallel-build-of-btt-and-blkiomon.patch +Patch20: 0020-blkparse-skip-check_cpu_map-with-pipe-input.patch +Patch21: 0021-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch +Patch22: 0022-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch %description blktrace is a block layer IO tracing mechanism which provides detailed @@ -64,6 +67,12 @@ make dest=%{buildroot} prefix=%{buildroot}/%{_prefix} mandir=%{buildroot}/%{_man %{_mandir}/man8/* %changelog +* Tue Sep 24 2024 wangxiao - 1.2.0-27 +- DESC: backport upstream patches + blkparse skip check_cpu_map with pipe input + blkparse fix incorrectly sized memset in check_cpu_map + fix hang when BLKTRACESETUP fails and "-o -" is used + * Sat Oct 09 2021 zhanchengbin - 1.2.0-26 - Fixed the issue of modifying parallel compilation -- Gitee