Received: by 10.213.65.68 with SMTP id h4csp1753812imn; Mon, 19 Mar 2018 12:19:27 -0700 (PDT) X-Google-Smtp-Source: AG47ELveYCGL+PrUzyPCsSh2syxYR7rIlf9y7qJeUio0Iakc06yr3PajdUWEvv7qqVCBqqrhNwhu X-Received: by 2002:a17:902:b704:: with SMTP id d4-v6mr13775402pls.406.1521487167644; Mon, 19 Mar 2018 12:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521487167; cv=none; d=google.com; s=arc-20160816; b=yTNjSx11C+fzHkzCbjE+kvpCBPl1795xBxHwXXH+WwWmNeoQh44Lez0MNOtFCaAPYL TXSsQhgVK7xSokq6D4yvwoYnG8rvMTi1vZqdXhgVsUCSFqqtChdzSToxmDz2BVeQ6Y0N eIQAKn7ldKOWqmUx/RTQtxRJWqySZz7CDfpxgWZyRfc8a/I0c+yvLAIMzKJWIo8KbVs+ niQYlVIu9A9iOhseUNIPNazVrzWeZVNBh0qkR6o8jvsKKx+/XBVrMMG85JcszKNbK8UK toeKhTMWXPcnlWLryWXmL2kxtJvHtLBrdZlwAXomflL0dtla0jdTVtaOMLybTzc1Jtbn xsgw== 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=u4KqlKwOPy3QjUH9IIOY9EWkzGJDadvVRn9QKkFLOnM=; b=FG02wgbssmc34YtM67HV8kQoPmBwEpOL2gq8RA1nEYkZXND0Aa5MuPCMOTSaNKUh2D jvmyqy7BYy5hqWfWxqHnSlyHWX9nDoaebfDKKCy1QfeQURJXXp3luBd5h6xfGacmx4XQ SF6iNMHZewuSlaTklaosbZFf8vvUaH8+ELc+38zp3H4efMiovYsx9WGk56SexuWUeIdK dxvkrOI2mYto7DHleENJID8R2hFw/WVcfOwgvlFC/+KPe0EJ2yGahfa+poZ3nAyXwW/6 S8X4oT9rYx3nbCH7SEeyQJPHE3vR3ATZcT7hExOsRxaSTQYiLcDWxSnlk1nW2IKXrfSA 2i+g== 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 5-v6si517593plt.371.2018.03.19.12.19.13; Mon, 19 Mar 2018 12:19:27 -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 S969874AbeCSS0L (ORCPT + 99 others); Mon, 19 Mar 2018 14:26:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50636 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S969822AbeCSSZ5 (ORCPT ); Mon, 19 Mar 2018 14:25:57 -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 0CDA4103C; Mon, 19 Mar 2018 18:25:57 +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.9 144/241] perf inject: Copy events when reordering events in pipe mode Date: Mon, 19 Mar 2018 19:06:49 +0100 Message-Id: <20180319180757.148507572@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@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.9-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 @@ -1628,6 +1628,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));