Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4602838ybc; Fri, 15 Nov 2019 07:14:44 -0800 (PST) X-Google-Smtp-Source: APXvYqxzijrzo4TWa3OF++p6AzE+VtjfPbhp/VMczhJf7YLOE7ZwL0bg2S7JKbmDzvU4PpXAKqVl X-Received: by 2002:a1c:16:: with SMTP id 22mr16220379wma.0.1573830884201; Fri, 15 Nov 2019 07:14:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573830884; cv=none; d=google.com; s=arc-20160816; b=xpwlzlKqTRgM4cdWCbBmBXo2n955Ue8AqR+dHN/KajJo91299BA5UXzyw1pV7/rGKS toIzz4wk4lGmO2SapEWujIpBl/yWpBD4iArgK+8Ia5kDVZucRz6jCFPR5YbXJOmGPg/6 UnPxnz566BFMFyE+bnTrZufUCNRrN94s6k77Q5ppS1oVjcKWwenKSwnOnjQAZID52Hid +/fUg+COhmKSt0OUZXRXlH+pd3Hew/wLBquIjqF174xeR5LfgOeWbM2oRPRk44m4nVGk 8C/vI1qpuzwU/X78WCzar2tWHuZhgAnXhSvL7kCImA7onN0Gw0G29oPAgYmFFLQCyojO kqQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:user-agent:in-reply-to:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VPXP6F+mV8JIBN1eHnEpmeTZOZyHrGdWMdr7mXYpyO8=; b=cjPfsRSeNhtCFmT5ewjkOzyUV2Tk5LQj5/2gCH74j1oJkm3u/fm68PgZrKSc2LR7CK a9m+1k7uVbc+4CaQ3CCrOHyCg0/7wETbEL3lhomQWsTxb6GAzubyqXV+XFOY38bffrnM IZLrPpvc2cYI+ykYhYe0uSdHw/jmc67Si7RXSBfgfCPIRUEl0qOcAARg3IIKZsFaMANq Khi1KZNKiTQPWs24vFubjNkfRrUOOLjsDFSAH9bCTlGPMTFD42zrQt2VyLPsW4NrgWet ZSkzphbrQ7eWiOnCY4aQb99EoNhS+mEoqP/aXhaGOSSriwlDoAb/ax32MNQ7ko2ptECL WxAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VKr2vO4m; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l47si7170889edb.111.2019.11.15.07.14.17; Fri, 15 Nov 2019 07:14:44 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=VKr2vO4m; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727630AbfKOPLc (ORCPT + 99 others); Fri, 15 Nov 2019 10:11:32 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:30451 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727380AbfKOPLc (ORCPT ); Fri, 15 Nov 2019 10:11:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573830691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VPXP6F+mV8JIBN1eHnEpmeTZOZyHrGdWMdr7mXYpyO8=; b=VKr2vO4mQVXU7bOFHrzwTguxnmw7XH9r4pMva8bm8PWDmEuaA4jYnLyHdA0oeYkETtBBpo sb0l1XQNt2NdLTsAwK/sQMSQfqqEwPZDswHMlbJL7IKMpAVenY3UV47pl2Ch9+/TWd4Ay5 YwnU9tOH9pxL0hmloqqE3hgkMFHehCk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-182-9wMylUw0MIi5PyyvYa4yQQ-1; Fri, 15 Nov 2019 10:11:28 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0EED31005500; Fri, 15 Nov 2019 15:11:27 +0000 (UTC) Received: from krava (unknown [10.43.17.48]) by smtp.corp.redhat.com (Postfix) with SMTP id 3B9455C1B0; Fri, 15 Nov 2019 15:11:25 +0000 (UTC) Date: Fri, 15 Nov 2019 16:11:24 +0100 From: Jiri Olsa To: Alexey Budankov Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Peter Zijlstra , Alexander Shishkin , Ingo Molnar , Andi Kleen , linux-kernel Subject: Re: [PATCH v1] perf session: fix decompression of PERF_RECORD_COMPRESSED records Message-ID: <20191115151124.GA25246@krava> References: <237222f1-9765-dce1-601c-60530a7fc844@linux.intel.com> MIME-Version: 1.0 In-Reply-To: <237222f1-9765-dce1-601c-60530a7fc844@linux.intel.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 9wMylUw0MIi5PyyvYa4yQQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 15, 2019 at 12:05:14PM +0300, Alexey Budankov wrote: >=20 > Avoid termination of trace loading in case the last record in=20 > the decompressed buffer partly resides in the following=20 > mmaped PERF_RECORD_COMPRESSED record. In this case NULL value > returned by fetch_mmaped_event() means to proceed to the next=20 > mmaped record then decompress it and load compressed events.=20 >=20 > The issue can be reproduced like this: >=20 > $ perf record -z -- some_long_running_workload > $ perf report --stdio -vv > decomp (B): 44519 to 163000 > decomp (B): 48119 to 174800 > decomp (B): 65527 to 131072 > fetch_mmaped_event: head=3D0x1ffe0 event->header_size=3D0x28, mmap_size= =3D0x20000: fuzzed perf.data? > Error: > failed to process sample > ... >=20 > Testing: > 71: Zstd perf.data compression/decompression : Ok >=20 > Fixes: 57fc032ad643 ("perf session: Avoid infinite loop when seeing inval= id header.size") > Link: https://marc.info/?l=3Dlinux-kernel&m=3D156580812427554&w=3D2 > Co-developed-by: Jiri Olsa > Signed-off-by: Alexey Budankov > --- > tools/perf/util/session.c | 47 +++++++++++++++++++++++++++++++++--------= ------ > 1 file changed, 33 insertions(+), 14 deletions(-) >=20 > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c > index f07b8ecb91bc..3f6f812ec4ed 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -1957,9 +1957,31 @@ static int __perf_session__process_pipe_events(str= uct perf_session *session) > =09return err; > } > =20 > +static union perf_event * > +prefetch_event(char *buf, u64 head, size_t mmap_size, > +=09 bool needs_swap, union perf_event *ret); why not move prefetch_event definition in here? I don't see any need for the static declaration.. > + > static union perf_event * > fetch_mmaped_event(struct perf_session *session, > =09=09 u64 head, size_t mmap_size, char *buf) > +{ > +=09return prefetch_event(buf, head, mmap_size, > +=09=09=09 session->header.needs_swap, > +=09=09=09 ERR_PTR(-EINVAL)); > +} > + > +static union perf_event * > +fetch_decomp_event(struct perf_session *session, > +=09=09 u64 head, size_t mmap_size, char *buf) > +{ if this is decomp specific, it could take 'struct decomp*' as argument > +=09return prefetch_event(buf, head, mmap_size, > +=09=09=09 session->header.needs_swap, > +=09=09=09 NULL); > +} > + > +static union perf_event * > +prefetch_event(char *buf, u64 head, size_t mmap_size, > +=09 bool needs_swap, union perf_event *ret) > { 'error' might be more suitable then ret in here thanks, jirka