perf record: Ensure space for lost samples
Previous allocation didn't account for sample ID written after the lost samples event. Switch from malloc/free to a stack allocation. Reported-by: Milian Wolff <milian.wolff@kdab.com> Closes: https://lore.kernel.org/linux-perf-users/23879991.0LEYPuXRzz@milian-workstation/ Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20240611050626.1223155-1-irogers@google.com
This commit is contained in:
parent
6828d6929b
commit
6c1785cd75
@ -77,6 +77,12 @@ struct perf_record_lost_samples {
|
|||||||
__u64 lost;
|
__u64 lost;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define MAX_ID_HDR_ENTRIES 6
|
||||||
|
struct perf_record_lost_samples_and_ids {
|
||||||
|
struct perf_record_lost_samples lost;
|
||||||
|
__u64 sample_ids[MAX_ID_HDR_ENTRIES];
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID | PERF_FORMAT_LOST
|
* PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID | PERF_FORMAT_LOST
|
||||||
*/
|
*/
|
||||||
|
@ -1926,7 +1926,7 @@ static void __record__save_lost_samples(struct record *rec, struct evsel *evsel,
|
|||||||
static void record__read_lost_samples(struct record *rec)
|
static void record__read_lost_samples(struct record *rec)
|
||||||
{
|
{
|
||||||
struct perf_session *session = rec->session;
|
struct perf_session *session = rec->session;
|
||||||
struct perf_record_lost_samples *lost = NULL;
|
struct perf_record_lost_samples_and_ids lost;
|
||||||
struct evsel *evsel;
|
struct evsel *evsel;
|
||||||
|
|
||||||
/* there was an error during record__open */
|
/* there was an error during record__open */
|
||||||
@ -1951,20 +1951,13 @@ static void record__read_lost_samples(struct record *rec)
|
|||||||
|
|
||||||
if (perf_evsel__read(&evsel->core, x, y, &count) < 0) {
|
if (perf_evsel__read(&evsel->core, x, y, &count) < 0) {
|
||||||
pr_debug("read LOST count failed\n");
|
pr_debug("read LOST count failed\n");
|
||||||
goto out;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count.lost) {
|
if (count.lost) {
|
||||||
if (!lost) {
|
memset(&lost.lost, 0, sizeof(lost));
|
||||||
lost = zalloc(sizeof(*lost) +
|
lost.lost.header.type = PERF_RECORD_LOST_SAMPLES;
|
||||||
session->machines.host.id_hdr_size);
|
__record__save_lost_samples(rec, evsel, &lost.lost,
|
||||||
if (!lost) {
|
|
||||||
pr_debug("Memory allocation failed\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lost->header.type = PERF_RECORD_LOST_SAMPLES;
|
|
||||||
}
|
|
||||||
__record__save_lost_samples(rec, evsel, lost,
|
|
||||||
x, y, count.lost, 0);
|
x, y, count.lost, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1972,21 +1965,12 @@ static void record__read_lost_samples(struct record *rec)
|
|||||||
|
|
||||||
lost_count = perf_bpf_filter__lost_count(evsel);
|
lost_count = perf_bpf_filter__lost_count(evsel);
|
||||||
if (lost_count) {
|
if (lost_count) {
|
||||||
if (!lost) {
|
memset(&lost.lost, 0, sizeof(lost));
|
||||||
lost = zalloc(sizeof(*lost) +
|
lost.lost.header.type = PERF_RECORD_LOST_SAMPLES;
|
||||||
session->machines.host.id_hdr_size);
|
__record__save_lost_samples(rec, evsel, &lost.lost, 0, 0, lost_count,
|
||||||
if (!lost) {
|
|
||||||
pr_debug("Memory allocation failed\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lost->header.type = PERF_RECORD_LOST_SAMPLES;
|
|
||||||
}
|
|
||||||
__record__save_lost_samples(rec, evsel, lost, 0, 0, lost_count,
|
|
||||||
PERF_RECORD_MISC_LOST_SAMPLES_BPF);
|
PERF_RECORD_MISC_LOST_SAMPLES_BPF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
|
||||||
free(lost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static volatile sig_atomic_t workload_exec_errno;
|
static volatile sig_atomic_t workload_exec_errno;
|
||||||
@ -3198,7 +3182,7 @@ static int switch_output_setup(struct record *rec)
|
|||||||
unsigned long val;
|
unsigned long val;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're using --switch-output-events, then we imply its
|
* If we're using --switch-output-events, then we imply its
|
||||||
* --switch-output=signal, as we'll send a SIGUSR2 from the side band
|
* --switch-output=signal, as we'll send a SIGUSR2 from the side band
|
||||||
* thread to its parent.
|
* thread to its parent.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user