From 3bb0852c74e50ae83a11b2c93a376a81655266d0 Mon Sep 17 00:00:00 2001 From: foolstrong Date: Wed, 31 Jul 2024 11:33:40 +0800 Subject: [PATCH] backport bugfix patches from upstream --- ...e-skip-check_cpu_map-with-pipe-input.patch | 37 +++++++++++++ ...orrectly-sized-memset-in-check_cpu_m.patch | 32 +++++++++++ ...en-BLKTRACESETUP-fails-and-o-is-used.patch | 54 +++++++++++++++++++ blktrace.spec | 8 ++- 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 0004-blkparse-skip-check_cpu_map-with-pipe-input.patch create mode 100644 0005-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch create mode 100644 0006-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch diff --git a/0004-blkparse-skip-check_cpu_map-with-pipe-input.patch b/0004-blkparse-skip-check_cpu_map-with-pipe-input.patch new file mode 100644 index 0000000..c9afa5f --- /dev/null +++ b/0004-blkparse-skip-check_cpu_map-with-pipe-input.patch @@ -0,0 +1,37 @@ +From ac416ab67cd7add0089c3bc668427e6b909eb59e Mon Sep 17 00:00:00 2001 +From: Jeff Mahoney +Date: Thu, 21 Oct 2021 10:16:19 -0400 +Subject: [PATCH 2/5] 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 +--- + 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/0005-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch b/0005-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch new file mode 100644 index 0000000..685dc2e --- /dev/null +++ b/0005-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch @@ -0,0 +1,32 @@ +From 7f5d2c5173d72018aa29c583c9291ef10abaf8df Mon Sep 17 00:00:00 2001 +From: Jeff Mahoney +Date: Thu, 21 Oct 2021 10:16:20 -0400 +Subject: [PATCH 3/5] 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 +--- + 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/0006-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch b/0006-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch new file mode 100644 index 0000000..6750796 --- /dev/null +++ b/0006-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch @@ -0,0 +1,54 @@ +From 1836be5d99c9362f1e2b39206c95270f19cb7faa Mon Sep 17 00:00:00 2001 +From: Eric Sandeen +Date: Wed, 5 Jun 2024 23:07:27 -0500 +Subject: [PATCH 5/5] 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 +--- + 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 ab9569d..740f8b0 100644 --- a/blktrace.spec +++ b/blktrace.spec @@ -1,6 +1,6 @@ Name: blktrace Version: 1.3.0 -Release: 2 +Release: 3 Summary: Block IO tracer in the Linux kernel License: GPLv2+ Source: http://brick.kernel.dk/snaps/blktrace-%{version}.tar.bz2 @@ -14,6 +14,9 @@ Requires: python3 Patch1: 0001-blktrace-remove-python2-dedpendency.patch Patch2: 0002-blktrace-Makefile-add-fstack-protector-strong-flag.patch Patch3: 0003-blktrace-fix-exit-directly-when-nthreads-running.patch +Patch4: 0004-blkparse-skip-check_cpu_map-with-pipe-input.patch +Patch5: 0005-blkparse-fix-incorrectly-sized-memset-in-check_cpu_m.patch +Patch6: 0006-fix-hang-when-BLKTRACESETUP-fails-and-o-is-used.patch %description blktrace is a block layer IO tracing mechanism which provides detailed @@ -50,6 +53,9 @@ make dest=%{buildroot} prefix=%{buildroot}/%{_prefix} mandir=%{buildroot}/%{_man %changelog +* Wed Jul 31 2024 wangzhiqiang - 1.3.0-3 +- backport bugfix patches from upstream + * Mon May 16 2022 Li Jinlin - 1.3.0-2 - provide iowatcher via Provides -- Gitee