Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp46714lqj; Wed, 10 Apr 2024 03:38:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUQ3Tg9kHIQU6GJuY0Yz7lagJO79NkmEOUASOQ2zpqr5s0lAAUxICxusQBBLumJQ4qDWj0+bFy371gm4SOzdtB8NtInc6ie9RZsdkqH8A== X-Google-Smtp-Source: AGHT+IHXBNG+kbKRkefQgEj94rZaohaCaQKzb+XB8qN9Uf2j5hW7PBphYMCVE63wz0/zDov7ODa3 X-Received: by 2002:a05:6a00:b54:b0:6ea:ad5e:f4b3 with SMTP id p20-20020a056a000b5400b006eaad5ef4b3mr2734437pfo.23.1712745516701; Wed, 10 Apr 2024 03:38:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712745516; cv=pass; d=google.com; s=arc-20160816; b=dVqugxFX0ozXVcrqM8Y3BJqI9QXd/i3aYBNdox08B8VTrokSvRDwRWm3Lwe2G2fYLy 5cgyX3VcaopBp8Mquyj2Y2Pmq/KMJAHStA71cptwdgLnOY0C4qHpCsbJtBIXZzDCZZL6 fCt9ABbov90JccOUKu7b8aZd1WWpn16qfyibEsWvyxRfY2Xs6VVErWPVVRjp7EhXVMnF v2nYkyYWZVpvl5powBiRspI7IyTwywipPHFNwTgLt+32fBTKY2gbLYa0MUJIWdlmurRM WVTy2Dm1aXnGrAyeNaXZGfRAKHMUQ0RJOjEFMUk+cC1WnNW1LhhV2sJlQnEly6r66mM4 Q5lA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=2B+Gt/KAr8t7f+jbMGjB13Te+/LBSkRQRyRMTlg82cE=; fh=Nx34APoIcnJ0+S23bfWBcqFDEk6NNmFHNRxZpQVNwlY=; b=XaE8Gzw+zjB5lQx/RQPZSHETSNSdZNhSiV+S/YZe3ibuFcV5gAF36KuUV/todhYVmL k3SkKVeWbYo9rdMv/mLdhhjukunNNGIkrVta/spLNhmjnwl1a1NgO7PDvPce+zmBfW+5 uVEKeZ8OD8uUkdXy7JFg98QchIOED7z1qFZLG4RndVmaDhVeuLqnFqMGgbB4ugzS/0Mr 2oOYf7Oh3gI2VFQiVhq2AN2GWcOvPcPfYkJEMQrvZE7S2yYgTyMxTjoO36qvLsmfN+o3 41J9v1zLIGkox+wVAzB9a0amrU4AUpE+ab+l5nahcWQEytnR1EWNB1QNEPQUhcly66rv sCeQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-138336-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138336-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d4-20020a056a0010c400b006e628dd06efsi7189025pfu.260.2024.04.10.03.38.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 03:38:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138336-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-138336-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138336-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7226DB21723 for ; Wed, 10 Apr 2024 10:36:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26D7615991C; Wed, 10 Apr 2024 10:35:38 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 255DD159566; Wed, 10 Apr 2024 10:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712745337; cv=none; b=Rm+IyYd1d2aHqxws33385p91PfhtoLSVhugEBpw+xbMgM7PezH1/tl8BnWHXxmZobvYe4lF8mWRF7Uh+8N0nAKK2dvn6CFhKo2x2oYOcftJH1DH0OX+HykusEWWmbhQxpMOgC/GdrOx6PPcQffJ1WwjtNtsRKxDgEJPDYjcjek0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712745337; c=relaxed/simple; bh=ypMirJBQln4cahP5+iyf5ns4VS6WkKkpnbUKpCIXRMM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r5SCfGFAWixfFpfFPGS23j2SYO3JUW9QnhdbW95O5ZbjAfRJ86CNnSC80+Iz5CLqFD9H5tnryVzGS2e5Gsrk+6NNQ5Keo9llUemiEwGySxv1ltTwG0NErSzr6QPE811D/RGUomnz3wxFd52U+U4S1TGyfc9WjBj+sItPW8fKufw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6F50B139F; Wed, 10 Apr 2024 03:36:05 -0700 (PDT) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 278903F6C4; Wed, 10 Apr 2024 03:35:33 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com, namhyung@kernel.org Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , "Liang, Kan" , Athira Rajeev , Spoorthy S , Leo Yan , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] perf map: Remove kernel map before updating start and end addresses Date: Wed, 10 Apr 2024 11:34:54 +0100 Message-Id: <20240410103458.813656-4-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240410103458.813656-1-james.clark@arm.com> References: <20240410103458.813656-1-james.clark@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In a debug build there is validation that mmap lists are sorted when taking a lock. In machine__update_kernel_mmap() the start and end addresses are updated resulting in an unsorted list before the map is removed from the list. When the map is removed, the lock is taken which triggers the validation and the failure: $ perf test "object code reading" --- start --- perf: util/maps.c:88: check_invariants: Assertion `map__start(prev) <= map__start(map)' failed. Aborted Fix it by updating the addresses after removal, but before insertion. The bug depends on the ordering and type of debug info on the system and doesn't reproduce everywhere. Fixes: 659ad3492b91 ("perf maps: Switch from rbtree to lazily sorted array for addresses") Signed-off-by: James Clark --- tools/perf/util/machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 5eb9044bc223..a26c8bea58d0 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1549,8 +1549,8 @@ static int machine__update_kernel_mmap(struct machine *machine, updated = map__get(orig); machine->vmlinux_map = updated; - machine__set_kernel_mmap(machine, start, end); maps__remove(machine__kernel_maps(machine), orig); + machine__set_kernel_mmap(machine, start, end); err = maps__insert(machine__kernel_maps(machine), updated); map__put(orig); -- 2.34.1