Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp296730rdb; Thu, 30 Nov 2023 05:16:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXw3vksQlZat1O0Zcef7oKMA6+riuo4tr5YSMJan0PPYBMJ/9Urb8RanVAjQO0Sxp8dVUv X-Received: by 2002:a17:902:e843:b0:1cf:d24c:7b6c with SMTP id t3-20020a170902e84300b001cfd24c7b6cmr13310833plg.59.1701350160163; Thu, 30 Nov 2023 05:16:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701350160; cv=none; d=google.com; s=arc-20160816; b=FJd7TMKoSb7FAKPeL7Iiw7r3Qk5LEIu2kUzUH+k3A1T1No3YRdOQ2Hex67DA+IoGEi DLje6TnXDIU5jOPKnzvewjqumr2uP09FCQdzeU4O+/SYAl2DNzfX6eetGPEprLhWq+ot /2jN85qSqOZqQ+H7rVUEnDZl9fAkK8AtFte6fk83Yd7KVRANpq75CqQ/gPUtomgRDN+f iElNGf7S8Zv2+GIb92BoyDheFl8DaVdOmOsWsBGLxJdiViuBh3uQ5cg2JTrF9bR+yvKs GaW0mhX8Q6rDDWD6pKjbyvtbNeNhoKr8GX/12wY9W9l0y2HoOD1iScs6iD2ZBXU6hCYQ OaEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Kx8Avm3tHD4n1ScPDMqANl7SbXbFToA+kCUNolS0ar0=; fh=qIobCfX76lsQY4tPHmFabU/v7o/CpMmoYC6lNgko6fI=; b=efN3m504c/xVz74ohFnk6BZeyTE7+HgnNRMakl//RccUyfaVzitF98naA9LuaS/JYI gWIxbmMTpeV+W4LpQL6093DF5nXSep5iyXZVX0lTNhmvnQTKqSWTISXeziPmTUQWjjFT EypNFtk66QUFjdtAvjK4eJJ7TyokC8ymrhCK8hl5Mntv/C8OkH7KsAGqI85dEsMixgE2 xyh6Xi4S5L58oqAlGCdpiTJYOhxH8Yw7HixWPOwTGWxGlBVKLVkTW94pm2z/EyymoUfp q2KO8xGmMC4HHOVGmeB8DTtL+7cac791L91V017An52jeeBQKuWPplSTkOQZw1MygTtQ ry+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BfDBPr8f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id g2-20020a170902740200b001cfd6baa008si1182693pll.511.2023.11.30.05.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:16:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BfDBPr8f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 1CB6D802158E; Thu, 30 Nov 2023 05:15:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232107AbjK3NPl (ORCPT + 99 others); Thu, 30 Nov 2023 08:15:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231990AbjK3NPj (ORCPT ); Thu, 30 Nov 2023 08:15:39 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9303D6C for ; Thu, 30 Nov 2023 05:15:45 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E9CCC433C8; Thu, 30 Nov 2023 13:15:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701350145; bh=ESm2XXf+f9FWS1yFlh8OmKYXTJZxIwuCreSBi7nmY00=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BfDBPr8fn0WoNKCpDTDlL374d6/n0Vh5pSkf88RafdnaRhwVotRG1gVzSgfUfMnUr FnnGbWOHMSre9aDBVg64y3N8n50e+vkNiLNsLk/fSC6KIOVV0cixMVjQeVRu48jNTZ VLfEY1Yafvf4nAOMyFKxPv7ydsO00A173dW3KphDPMie9GHH9/S9gBbaGrzJaSAvNS wn+ISUZ23eruuJlQRrJXWjrk3uPQGmjC0iw/t3VoiVZ4XSwwI8IdU3Ar1IX/XL/OTv rakfqB4dPjcYqcTFCMyhw10buFsGUMKGYcoprxGQ0d+8cndqwbSsPnFWyeCRLWv0l2 SW9Mu6EeOPdDg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 1BF0840094; Thu, 30 Nov 2023 10:15:43 -0300 (-03) Date: Thu, 30 Nov 2023 10:15:43 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio Subject: Re: [PATCH v5 02/50] libperf: Lazily allocate/size mmap event copy Message-ID: References: <20231127220902.1315692-1-irogers@google.com> <20231127220902.1315692-3-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231127220902.1315692-3-irogers@google.com> X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 30 Nov 2023 05:15:56 -0800 (PST) Em Mon, Nov 27, 2023 at 02:08:14PM -0800, Ian Rogers escreveu: > The event copy in the mmap is used to have storage to read an > event. Not all users of mmaps read the events, such as perf > record. The amount of buffer was also statically set to > PERF_SAMPLE_MAX_SIZE rather than the amount necessary from the > header's event size. Switch to a model where the event_copy is > reallocated if too small to the event's size. This adds the potential > for the event to move, so if a copy of the event pointer were stored > it could be broken. All the current users do: > > while(event = perf_mmap__read_event()) { ... } > > and so they would be broken due to the event being overwritten if they > had stored the pointer. Manual inspection and address sanitizer > testing also shows the event pointer not being stored. > > Signed-off-by: Ian Rogers > --- > tools/lib/perf/include/internal/mmap.h | 3 ++- > tools/lib/perf/mmap.c | 21 ++++++++++++++++++--- > 2 files changed, 20 insertions(+), 4 deletions(-) > > diff --git a/tools/lib/perf/include/internal/mmap.h b/tools/lib/perf/include/internal/mmap.h > index 5a062af8e9d8..5f08cab61ece 100644 > --- a/tools/lib/perf/include/internal/mmap.h > +++ b/tools/lib/perf/include/internal/mmap.h > @@ -33,7 +33,8 @@ struct perf_mmap { > bool overwrite; > u64 flush; > libperf_unmap_cb_t unmap_cb; > - char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8); > + void *event_copy; > + size_t event_copy_sz; > struct perf_mmap *next; > }; > > diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c > index 2184814b37dd..c829db7bf1fa 100644 > --- a/tools/lib/perf/mmap.c > +++ b/tools/lib/perf/mmap.c > @@ -19,6 +19,7 @@ > void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev, > bool overwrite, libperf_unmap_cb_t unmap_cb) > { > + /* Assume fields were zero initialized. */ > map->fd = -1; > map->overwrite = overwrite; > map->unmap_cb = unmap_cb; > @@ -51,13 +52,19 @@ int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, > > void perf_mmap__munmap(struct perf_mmap *map) > { > - if (map && map->base != NULL) { > + if (!map) > + return; > + > + free(map->event_copy); > + map->event_copy = NULL; I?m converting this to: zfree(&map->event_copy); Hopefully we'll find some tool to flag these before submitting patches, does clang-tidy do these kinds of things? Also, applied: b4 am -P2,4-7 -ctsl --cc-trailers 20231127220902.1315692-1-irogers@google.com The ones that Namhyung acked and that applied cleanly in order. The first one, as Namhyung noted, is already merged. - Arnaldo