Received: by 10.213.65.68 with SMTP id h4csp1784919imn; Mon, 19 Mar 2018 13:11:41 -0700 (PDT) X-Google-Smtp-Source: AG47ELt2sFBSwwMyOoeLujUbszjlDkBdfEjYNZ2ZmnmR60CiqKT4TkE512Gn9JkO/y2q+9EXlF1R X-Received: by 10.98.97.1 with SMTP id v1mr11420010pfb.119.1521490301378; Mon, 19 Mar 2018 13:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521490301; cv=none; d=google.com; s=arc-20160816; b=agNHUVBiCZOfoh52y1HTOAmE4wWnVuBMT18u1TCbVYoKbmAXbY4iV2QZcO26MwZ2lB q5OwybIz+ENwsigedwUoTBesEEs9QSOxmxeS3OlKCnSXidkDtcv1XtBgpP5Rxux4vZq4 2H2Iq2W2vlLIWjr2ENge9xwhTcJhhn9JWpxFghYwrYm8yZJg5ULDVKN4NpHl5MjcBhtI cDbIntsEDw3JKVmsLyKNbWiqaVfJeyUuPfYB+3YSIQaRM7IhurAGUHiiXG0JYw7AUsRH azkXFyRsH6iXXtfxEK41FgnoVGIfQAk9oAAc72XWDcx5rDZRIEzYKEoF7WQyNjDA1UTP 6UGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=mMbJB9NmQ/DqbVWOiqIVxIgJM54zLlPWrxdNztPhNcY=; b=sPuMD8N0f49dqwwj1sns1BM5ah0VbFhzKMRv/3Qw1MTa46brcec2RjRLR+TrRCI1rc EPOQAz4/6/k5F2PTHXPex2jkjPO2q/ogAd75TKSTuHj0BtkgBzLa+BydsFVb/qsARqOQ utrQiDInf3pWZayf03a7bSW8LDwDL07FogodTlKdgKLZ4CHbM1jsmbVL3XCvLHQHtgxt P93dBbI4bz1BUW5qO4oLeuLEDbVofdsNko0WHzmXmyJvoaR5+kyp5xoS7i0yXHeJn/J6 3v/4oeee8tty1mbYlET14J+J7nc7wLsyzsWEh5ckrsLSKY7SU5H4rl4f5NIf+l4Cazva wdqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o10si154pgp.607.2018.03.19.13.11.27; Mon, 19 Mar 2018 13:11:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S971117AbeCSUKA (ORCPT + 99 others); Mon, 19 Mar 2018 16:10:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45374 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030907AbeCSSQz (ORCPT ); Mon, 19 Mar 2018 14:16:55 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 329D51165; Mon, 19 Mar 2018 18:16:54 +0000 (UTC) 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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));