Skip to content

Commit fa128e6

Browse files
Alexei Starovoitovdavem330
Alexei Starovoitov
authored andcommitted
perf: pad raw data samples automatically
Instead of WARN_ON in perf_event_output() on unpaded raw samples, pad them automatically. Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 63b11e7 commit fa128e6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

kernel/events/core.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -5286,9 +5286,15 @@ void perf_output_sample(struct perf_output_handle *handle,
52865286

52875287
if (sample_type & PERF_SAMPLE_RAW) {
52885288
if (data->raw) {
5289-
perf_output_put(handle, data->raw->size);
5290-
__output_copy(handle, data->raw->data,
5291-
data->raw->size);
5289+
u32 raw_size = data->raw->size;
5290+
u32 real_size = round_up(raw_size + sizeof(u32),
5291+
sizeof(u64)) - sizeof(u32);
5292+
u64 zero = 0;
5293+
5294+
perf_output_put(handle, real_size);
5295+
__output_copy(handle, data->raw->data, raw_size);
5296+
if (real_size - raw_size)
5297+
__output_copy(handle, &zero, real_size - raw_size);
52925298
} else {
52935299
struct {
52945300
u32 size;
@@ -5420,8 +5426,7 @@ void perf_prepare_sample(struct perf_event_header *header,
54205426
else
54215427
size += sizeof(u32);
54225428

5423-
WARN_ON_ONCE(size & (sizeof(u64)-1));
5424-
header->size += size;
5429+
header->size += round_up(size, sizeof(u64));
54255430
}
54265431

54275432
if (sample_type & PERF_SAMPLE_BRANCH_STACK) {

0 commit comments

Comments
 (0)