Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1064340ybl; Wed, 14 Aug 2019 10:08:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmMPzAljZo6UWDIBhAp/NPKZbHX1QIvrbaIAmOBNal1PTI4Udkc1qkiWR5e25n52nRUTQF X-Received: by 2002:a17:902:e311:: with SMTP id cg17mr369843plb.183.1565802489174; Wed, 14 Aug 2019 10:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802489; cv=none; d=google.com; s=arc-20160816; b=jEjR3KNSXkF80MrKjdYz5wJ7dX7tyKPbBPeQLVeT9h19FOIsgR0uKVfi5KE0ezrE/+ zrthorBMtIpSh+KGyqRELVyI48EFlEN1VbGqs0u0GMO6NOxbR36uqXtoSAsU1zu5irJ6 GNZFr28tiJ0DlXEToJLt8XDVk2HXAyYBxIA55Ao9X3OPYeZ+FxRG1YqUqEayz+9PjP1i +hHlzib10B6kA4m3/T+Pyiv79XYGnIb4tYNycjV2ZtH7Jnrh3DIMhSFLbkJpY+e0VNew AYDgxcpzAaDM0rSHAIsk/6rz/OJ9A+yN+ude5ONZtR2RZZtcT+MNlXh5g32m4ZUBPQJA xFGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=m+5I+JxKGF9vl7PgjuCuF2C2NxsSMQcpDmXwjAka3zg=; b=BVnT20udHZXkpweVaKKFyLfopp87G6hAuzDNfXzpz+Oh0zYaNR4KdxwU17nyKUCxz9 yFXup92UasCy64WZiy+gXyZFUe4+e1CNBX4QkTrIXI8FtNDvCdgakl9ov/XO+5r74XGQ pO2RB90nWH0H735xvZpC7Rznqj/fAvs/M9Zn4K2XZxD4zzE5tzpV2qhlOMIChYVrf/zJ bwpVmzdiZd9P1r8OgGqYeffypcJ1N4lspwjmNY7N+kkjiYHIZ3A87twifVJl1l5xVtxB CI99h/cP9Hvxx/AAgEH1TKOdKdBsv5M/sxEmeLoZfzCeGSeOwfCljyLluverBKAtKq2a lOag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UrW6tIg0; 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 x6si171173pgq.473.2019.08.14.10.07.53; Wed, 14 Aug 2019 10:08:09 -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; dkim=pass header.i=@kernel.org header.s=default header.b=UrW6tIg0; 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 S1729607AbfHNRGM (ORCPT + 99 others); Wed, 14 Aug 2019 13:06:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:55222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729137AbfHNRGJ (ORCPT ); Wed, 14 Aug 2019 13:06:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BDAB021721; Wed, 14 Aug 2019 17:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802368; bh=/2Wd/frythSl97MX/OTUSLUYw7DWSem4ThyOhhXUykA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UrW6tIg0Kw0GFEGSuV8PwqGHkYx0rDD1xB1VTCdwq2WnsXz10QLSMUbwKncPsl7Fr T2peTPgM/DiWSFJduknzbkWIrsZO3DPDpuhoR7I7f3t/FJqGmesL2sGco+0oRp+9Oa /6dNFYIfxRdN0Zy/xID1678+Krl6bMUxhDrlStpM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Budankov , Jiri Olsa , Alexander Shishkin , Andi Kleen , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.2 099/144] perf session: Fix loading of compressed data split across adjacent records Date: Wed, 14 Aug 2019 19:00:55 +0200 Message-Id: <20190814165804.025278784@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165759.466811854@linuxfoundation.org> References: <20190814165759.466811854@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 872c8ee8f0f47222f7b10da96eea84d0486540a3 ] Fix decompression failure found during the loading of compressed trace collected on larger scale systems (>48 cores). The error happened due to lack of decompression space for a mmaped buffer data chunk split across adjacent PERF_RECORD_COMPRESSED records. $ perf report -i bt.16384.data --stats failed to decompress (B): 63869 -> 0 : Destination buffer is too small user stack dump failure Can't parse sample, err = -14 0x2637e436 [0x4080]: failed to process type: 9 Error: failed to process sample $ perf test 71 71: Zstd perf.data compression/decompression : Ok Signed-off-by: Alexey Budankov Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/4d839e1b-9c48-89c4-9702-a12217420611@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/session.c | 22 ++++++++++++++-------- tools/perf/util/session.h | 1 + tools/perf/util/zstd.c | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 2e61dd6a3574e..d789840960444 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -36,10 +36,16 @@ static int perf_session__process_compressed_event(struct perf_session *session, void *src; size_t decomp_size, src_size; u64 decomp_last_rem = 0; - size_t decomp_len = session->header.env.comp_mmap_len; + size_t mmap_len, decomp_len = session->header.env.comp_mmap_len; struct decomp *decomp, *decomp_last = session->decomp_last; - decomp = mmap(NULL, sizeof(struct decomp) + decomp_len, PROT_READ|PROT_WRITE, + if (decomp_last) { + decomp_last_rem = decomp_last->size - decomp_last->head; + decomp_len += decomp_last_rem; + } + + mmap_len = sizeof(struct decomp) + decomp_len; + decomp = mmap(NULL, mmap_len, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (decomp == MAP_FAILED) { pr_err("Couldn't allocate memory for decompression\n"); @@ -47,10 +53,10 @@ static int perf_session__process_compressed_event(struct perf_session *session, } decomp->file_pos = file_offset; + decomp->mmap_len = mmap_len; decomp->head = 0; - if (decomp_last) { - decomp_last_rem = decomp_last->size - decomp_last->head; + if (decomp_last_rem) { memcpy(decomp->data, &(decomp_last->data[decomp_last->head]), decomp_last_rem); decomp->size = decomp_last_rem; } @@ -61,7 +67,7 @@ static int perf_session__process_compressed_event(struct perf_session *session, decomp_size = zstd_decompress_stream(&(session->zstd_data), src, src_size, &(decomp->data[decomp_last_rem]), decomp_len - decomp_last_rem); if (!decomp_size) { - munmap(decomp, sizeof(struct decomp) + decomp_len); + munmap(decomp, mmap_len); pr_err("Couldn't decompress data\n"); return -1; } @@ -255,15 +261,15 @@ static void perf_session__delete_threads(struct perf_session *session) static void perf_session__release_decomp_events(struct perf_session *session) { struct decomp *next, *decomp; - size_t decomp_len; + size_t mmap_len; next = session->decomp; - decomp_len = session->header.env.comp_mmap_len; do { decomp = next; if (decomp == NULL) break; next = decomp->next; - munmap(decomp, decomp_len + sizeof(struct decomp)); + mmap_len = decomp->mmap_len; + munmap(decomp, mmap_len); } while (1); } diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index dd8920b745bce..863dbad878496 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -46,6 +46,7 @@ struct perf_session { struct decomp { struct decomp *next; u64 file_pos; + size_t mmap_len; u64 head; size_t size; char data[]; diff --git a/tools/perf/util/zstd.c b/tools/perf/util/zstd.c index 23bdb98845760..d2202392ffdbb 100644 --- a/tools/perf/util/zstd.c +++ b/tools/perf/util/zstd.c @@ -99,8 +99,8 @@ size_t zstd_decompress_stream(struct zstd_data *data, void *src, size_t src_size while (input.pos < input.size) { ret = ZSTD_decompressStream(data->dstream, &output, &input); if (ZSTD_isError(ret)) { - pr_err("failed to decompress (B): %ld -> %ld : %s\n", - src_size, output.size, ZSTD_getErrorName(ret)); + pr_err("failed to decompress (B): %ld -> %ld, dst_size %ld : %s\n", + src_size, output.size, dst_size, ZSTD_getErrorName(ret)); break; } output.dst = dst + output.pos; -- 2.20.1