Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp3057255rdb; Mon, 4 Dec 2023 15:51:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJDfYHveWRzKF7fPeIEHnDedsV/WQi+7F4GPCg5Qu/SZqolElDCfYzH6uTzq2EnMBdiFHC X-Received: by 2002:a05:6808:191c:b0:3b8:b063:adfa with SMTP id bf28-20020a056808191c00b003b8b063adfamr6332155oib.87.1701733867618; Mon, 04 Dec 2023 15:51:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701733867; cv=none; d=google.com; s=arc-20160816; b=UspPAbG1nX3MFKEpTwlRQL80AvBFDer05M9j+X8yo95Ar2wBaREwsqpm3QrWJbLRJT OUOPq3lvTYJ4GjH7vvJo1Bm3zHNLCUXbj5jg7YIWN8BQb3s62WRRKihThZDh7JFQiAbu r5b1nOkSj/Vcm66lS4LslbOwE6A01zSvkqAvlDfZk/7HDI2MivTRDox3xw+GPg2J0a0O hJjAY+xywWeKam9Z1wkdg3Gb2b5u26gGGKQ5MIkdIOdKXGH8pRHQ+4ozVQehl9SbFQH+ ZDCwiHdO7L06HwVR82Ns6YB5B/QYQ9Sxr+wEUqXsczG57sA0NXdHV3Sth/aOjGAu0OFx P7Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=Qbmoe8XJrscbWZkndPgZP+BUk7qNyGvRmvX9Fko36GE=; fh=aWa9tyepd0GWyBFjkZa5ys7uNwpZ1AjfSj0Mu1iuQbE=; b=CN4F0/vvOhTyObkVEUIILXK7VBrzZHirbmJkOLmnIWyZAgGPK1pyvSubhfA8UEMv7f T473/ophCULHU9UWesvgWmIvnyviWa3EW0UWcQOW4XtRfllrUF5V1/mRgwPcWVHIviWv bGA/cY+8TezIMRY8L/aAtj8dJD9pXiU6CeB1FUi0LlTCHWzgcIAeGl4efUVx5gfdpIOY yEBfJq8uwLBDdZrz1rBl06HQ17ODhyNIaM8gaW8+zGGAMA+zVl/nLEV2OvIz0QfNjNPe EaVb+6Mgp8TRnjjxcafDNzl1PiwIUTSAA0wXM+CGwSyDsBbx0I7hVArumqwAMVdd3WNR QVQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id 23-20020a630f57000000b005b915369810si3426388pgp.590.2023.12.04.15.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 15:51:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id AF1A880320ED; Mon, 4 Dec 2023 15:50:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235395AbjLDXuf convert rfc822-to-8bit (ORCPT + 99 others); Mon, 4 Dec 2023 18:50:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234924AbjLDXuI (ORCPT ); Mon, 4 Dec 2023 18:50:08 -0500 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B39710E7; Mon, 4 Dec 2023 15:49:57 -0800 (PST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6ce5a0c384fso1068730b3a.1; Mon, 04 Dec 2023 15:49:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701733796; x=1702338596; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sRrhfsrD/bMKdqj5ETo8Mo1h2Igm/9o0AxAk0uXBBOw=; b=GiGriiPSW0/GA6JpJa/Fl/NDAw7y9mru03e3XBqGjBrr4sj0jsmQYSwl4ghfsz2U/+ osXuTB6z5NWReOcexEIBi0Gz8MnWrS09P9Dw4YMEOJg1EhCWR7AORkyFW/XBm5AYIo5C zyFa4gdVYvrJnHSEzGcFnuyuwFHGsHG8O7JCVedx+ZJ5CzvXl8mgNyhhF/476eY8MW39 z4Kiop4sQ5aIVrMMbdZYnw9quSCVrhglCL0hVahXPeSVAupztLjpjrizNa67LO1+qxSc 6Rnoykr8HnwbEu2SKUa5Le7KQGaLAXmcYE2RireYmmnBqVTxc9Sr4hOGtImq5Ox7kloO j4Gw== X-Gm-Message-State: AOJu0Ywx6Mhow/uy3srg74PSDAMEdAdaHmt33aXNPkC4fkgPDWvPRm71 +wcoai9IuaMXetnya+fuiZRdnw7v2Duh5qzYgCc= X-Received: by 2002:a05:6a20:9f96:b0:18f:97c:ba1a with SMTP id mm22-20020a056a209f9600b0018f097cba1amr4697963pzb.116.1701733796435; Mon, 04 Dec 2023 15:49:56 -0800 (PST) MIME-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> <20231127220902.1315692-17-irogers@google.com> In-Reply-To: <20231127220902.1315692-17-irogers@google.com> From: Namhyung Kim Date: Mon, 4 Dec 2023 15:49:45 -0800 Message-ID: Subject: Re: [PATCH v5 16/50] perf maps: Add remove maps function to remove a map based on callback To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 04 Dec 2023 15:50:57 -0800 (PST) On Mon, Nov 27, 2023 at 2:10 PM Ian Rogers wrote: > > Removing maps wasn't being done under the write lock. Similar to > maps__for_each_map, iterate the entries but in this case remove the > entry based on the result of the callback. If an entry was removed > then maps_by_name also needs updating, so add missed flush. > > In dso__load_kcore, the test of map to save would always be false with > REFCNT_CHECKING because of a missing RC_CHK_ACCESS. > > Signed-off-by: Ian Rogers Acked-by: Namhyung Kim A nitpick below, > --- [SNIP] > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c > index 72f03b875478..30da8a405d11 100644 > --- a/tools/perf/util/symbol.c > +++ b/tools/perf/util/symbol.c > @@ -1239,13 +1239,23 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data) > return 0; > } > > +static bool remove_old_maps(struct map *map, void *data) > +{ > + const struct map *map_to_save = data; > + > + /* > + * We need to preserve eBPF maps even if they are covered by kcore, > + * because we need to access eBPF dso for source data. > + */ > + return RC_CHK_ACCESS(map) != RC_CHK_ACCESS(map_to_save) && !__map__is_bpf_prog(map); RC_CHK_EQUAL(map, map_to_save) ? Thanks, Namhyung > +} > + > static int dso__load_kcore(struct dso *dso, struct map *map, > const char *kallsyms_filename) > { > struct maps *kmaps = map__kmaps(map); > struct kcore_mapfn_data md; > struct map *replacement_map = NULL; > - struct map_rb_node *old_node, *next; > struct machine *machine; > bool is_64_bit; > int err, fd; > @@ -1292,17 +1302,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map, > } > > /* Remove old maps */ > - maps__for_each_entry_safe(kmaps, old_node, next) { > - struct map *old_map = old_node->map; > - > - /* > - * We need to preserve eBPF maps even if they are > - * covered by kcore, because we need to access > - * eBPF dso for source data. > - */ > - if (old_map != map && !__map__is_bpf_prog(old_map)) > - maps__remove(kmaps, old_map); > - } > + maps__remove_maps(kmaps, remove_old_maps, map); > machine->trampolines_mapped = false; > > /* Find the kernel map using the '_stext' symbol */ > -- > 2.43.0.rc1.413.gea7ed67945-goog >