From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AG47ELtbGrUbNLfYOoDT4YRdN/l1fwoCK3TxQEom0XkUCLUpM/08xhoyYxg5WlIFcjrTl8qaIRdl ARC-Seal: i=1; a=rsa-sha256; t=1521483414; cv=none; d=google.com; s=arc-20160816; b=cmwSnILIEgPHxs/kY3hJ6UfvTx+DSloMdVA4Jz/I14s+Qa1g3BJ7c/hjMAg3qPNRKJ UiktYCkEn/+Ott+jJy6/2tkiEtn3G+TdGsAi01C+Ik72c9D/zLhxRvcEhTksRjh5RvhA DYGSp4fvxeubSV3nwGggLE0hgwQ4iHOwnvG3+EGmPApoUpMmNOyItkaxEncySD4b+8Hp UPiim4DRlJxfeiURzmxKkd90c9Holoi2aDYKyfaFl8xdJsuFvfZTDfdDq9UrWIW9pZAb s9AsV3gZcXYq0ra1YrgcyqQ3GmiIjqY4BjSOgTY79Wcqfj4GKh6X1TDiz8c4Zsq19YL3 uXsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=mMbJB9NmQ/DqbVWOiqIVxIgJM54zLlPWrxdNztPhNcY=; b=C7vAzTJm+Co5cCUkWFk4/23Nmkt0HnJZvx/AG9dNubnMRcTAggNqF4RIqNs0Sy9wTN rABoAdc5y7Ig2gKovCWZoZGVaiPhdD5AhAbMTxd6Js5wrcgOC27Ib0hc1vGrilqBp7O2 UVAso34jm83xLKoUm4Hr6jGT1MFM7ngdk3aHL5gD2A0Un7p6fbg3E4nGmfneFWlIxGeZ bSXkZrUtLiZjJ9giTv4QYLUzT0w+efQtUjFOPmxFEnfNI9UBCzI+NMHQNghXAVWRT+JA c7ayg+PGZUPMuYM/3O4M78SFDvPlpd10HRXhtMhw8Ze9G86bJ38W2ZA0dqITC2Xdb3jo Z4qg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.61.202 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.61.202 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Carrillo-Cisneros , Arnaldo Carvalho de Melo , Jiri Olsa , Alexander Shishkin , Andi Kleen , He Kuang , Masami Hiramatsu , Paul Turner , Peter Zijlstra , Simon Que , Stephane Eranian , Wang Nan , Sasha Levin Subject: [PATCH 4.4 071/134] perf inject: Copy events when reordering events in pipe mode Date: Mon, 19 Mar 2018 19:05:54 +0100 Message-Id: <20180319171859.504067912@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1595390625920673495?= X-GMAIL-MSGID: =?utf-8?q?1595390993127940603?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Carrillo-Cisneros [ Upstream commit 1e0d4f0200e4dbdfc38d818f329d8a0955f7c6f5 ] __perf_session__process_pipe_events reuses the same memory buffer to process all events in the pipe. When reordering is needed (e.g. -b option), events are not immediately flushed, but kept around until reordering is possible, causing memory corruption. The problem is usually observed by a "Unknown sample error" output. It can easily be reproduced by: perf record -o - noploop | perf inject -b > output Committer testing: Before: $ perf record -o - stress -t 2 -c 2 | perf inject -b > /dev/null stress: info: [8297] dispatching hogs: 2 cpu, 0 io, 0 vm, 0 hdd stress: info: [8297] successful run completed in 2s [ perf record: Woken up 3 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] Warning: Found 1 unknown events! Is this an older tool processing a perf.data file generated by a more recent tool? If that is not the case, consider reporting to linux-kernel@vger.kernel.org. $ After: $ perf record -o - stress -t 2 -c 2 | perf inject -b > /dev/null stress: info: [9027] dispatching hogs: 2 cpu, 0 io, 0 vm, 0 hdd stress: info: [9027] successful run completed in 2s [ perf record: Woken up 3 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] no symbols found in /usr/bin/stress, maybe install a debug package? no symbols found in /usr/bin/stress, maybe install a debug package? $ Signed-off-by: David Carrillo-Cisneros Tested-by: Arnaldo Carvalho de Melo Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: He Kuang Cc: Masami Hiramatsu Cc: Paul Turner Cc: Peter Zijlstra Cc: Simon Que Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/r/20170410201432.24807-3-davidcc@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/ordered-events.c | 3 ++- tools/perf/util/session.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) --- a/tools/perf/util/ordered-events.c +++ b/tools/perf/util/ordered-events.c @@ -79,7 +79,7 @@ static union perf_event *dup_event(struc static void free_dup_event(struct ordered_events *oe, union perf_event *event) { - if (oe->copy_on_queue) { + if (event && oe->copy_on_queue) { oe->cur_alloc_size -= event->header.size; free(event); } @@ -150,6 +150,7 @@ void ordered_events__delete(struct order list_move(&event->list, &oe->cache); oe->nr_events--; free_dup_event(oe, event->event); + event->event = NULL; } int ordered_events__queue(struct ordered_events *oe, union perf_event *event, --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1437,6 +1437,7 @@ static int __perf_session__process_pipe_ buf = malloc(cur_size); if (!buf) return -errno; + ordered_events__set_copy_on_queue(oe, true); more: event = buf; err = readn(fd, event, sizeof(struct perf_event_header));