From patchwork Wed Jan 31 19:24:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 194914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp2112377dyb; Wed, 31 Jan 2024 11:24:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfgCDzZlQY0HLXW3+jNxn6w/2Q1IDaFGHlgYFgSD1fsNdvklEYB16jEYBsAbZXIMhTk9AU X-Received: by 2002:a05:6402:31ae:b0:55f:4602:bf93 with SMTP id dj14-20020a05640231ae00b0055f4602bf93mr1711723edb.26.1706729096189; Wed, 31 Jan 2024 11:24:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706729096; cv=pass; d=google.com; s=arc-20160816; b=XUpN6hvGwByflBk/4pEB2yP9pZMK9eSV+c8bZKgCAlj1yw3D6hTcM/ZEkvYJRGWdza 3nw9XXA2mm82EMVPIux0QVPKuGdLeAKtsx5u+yD5jkNROhPbfitxB3BxXyKBNp6U6XDQ XDSH212IfYi1cPw0EPNvxb4bwSmaSpDsXGAgz1TTiR+QYNMCz3SENgK2s+zz4h9JrMj1 0U6OV++wVvttkM9tOr4/MKLV3iLg/fR9kt2ljoC0IWgP1TzQ/NPz7wYeDKCtUt5a8tV0 6M/k5v6DgIEGJ9k4oaaJPHgCSjRu4gXba/Dfi2Io7EoiFJISXSnBukOs3xDVXPpG/wUw uoCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:organization:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature; bh=l0Fv5gqXzLNCHN6a1jWMGf5aQ22RiicyXuvdUNytQu0=; fh=NUVbVUQIC/hMXXZ2av1mkJrcWWGeaVtY9g8aV4liS6I=; b=j/zwwY3HFxsAfw8oArwVV/XR8Jf42fzIV1cW7s43Er7p0YE9OgGDoGkfwfLg2PnK4k SjfkoCYIsJexS9Xr4lqKQpYQmhvGUR9GJPfGeaRcIsdMGW3I7wnUCgJdx/wfdnJRU8AY 1ITPS0oMiIsb+2ocMwkyh72geB0J7b79he+I7EE/4O5RuWFiahBkJ1MPE2nTGcVlZFg4 G28NGvrfHfGogt+PDryl/wuORibo7mqocqeAPOqWMLrap4BsvpkNB2YaYfX7+4yY4A5o OD+W7txNiuY8aRHOlGSWfxxiQ2dqwkcyhm+iLBUoGsPTkA2MI+8fddyHWwUnyptiyMxc 4OEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="QK4rhbG/"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-47012-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47012-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWyL3ywuLV8qPzVLzT8menWyk6rNe44cMoAJMpTxhqWh+XN833IbeqdDPBQR14xErQ2VVJNZwyKTHGVkOzDOZruw1HQdA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fk5-20020a056402398500b0055cf4ac3414si5775412edb.62.2024.01.31.11.24.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 11:24:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47012-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="QK4rhbG/"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-47012-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47012-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 am.mirrors.kernel.org (Postfix) with ESMTPS id CB2CD1F25B92 for ; Wed, 31 Jan 2024 19:24:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51AC53B287; Wed, 31 Jan 2024 19:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QK4rhbG/" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A3633610A; Wed, 31 Jan 2024 19:24:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706729075; cv=none; b=t2bD7clOuO2ZAy09jpgUOJdn7XyMuSaob/7ogoRwOHAJNvx4Gv0RXpJcVbTUGBnoAz8pZGdRkGOHmHtPEyMpZKHnAMs6W8D27O6NQ+Y8ZKq2HC0aYfJLK24+mdHlwUKkLqi5FFUEkuP9J8COhD4QReooVvuOXnbuFMXvzqASg20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706729075; c=relaxed/simple; bh=T8MDEuGVKv/mgfa9CO6cBEqeOvKSrL1fjA0wmbjS61A=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=a4mT32vJR0b91kVIfB1t0nLSiEx8PSRsozsa/S6CPe0TcRDQbuKiB0M/PooaCKskTTgEQnHEnMsbSNCE+GudkFJwTWFJDJULcYO0zSIrrEwziYQ0BUlth7BmS5rugZPQ+J7GF94Qgjle6157OEr1hmNQlBQecItt0HMx8Y2jR6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QK4rhbG/; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706729074; x=1738265074; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=T8MDEuGVKv/mgfa9CO6cBEqeOvKSrL1fjA0wmbjS61A=; b=QK4rhbG/vLXfdUU0iUVa1lthr4DQgqJh2KvRplk0d6hTXSbBM5ARm+a8 +qftyjtI4Q3oIkwWw9R13B8890BIweCgsESRrwVsiL4YQ6gIeZl/tVgOC 5UhQU+Qh2e+nBvQE+sA/CUn8v5gVdUi2rHqxnUbPtCmNlJ5p5AXqC0hCY B32FHQUzrQalC5H+ZSueJNyzJFbQJrK6Vz+DXqz68So6iimGJC7hQm9m1 Q0O5sw+maEkn/WGwg0Nc/mLy58MHWZc8cyqLR8cspWuC092UDBtPBEyiS PbuR+wv+DSv62UZKD383V9PpKvyUfJ80ssS2+zeLOmFVrr2/qPNPNTcMY A==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3562151" X-IronPort-AV: E=Sophos;i="6.05,233,1701158400"; d="scan'208";a="3562151" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 11:24:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,233,1701158400"; d="scan'208";a="4269805" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.251.217.93]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 11:24:30 -0800 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH] perf test: Enable Symbols test to work with a current module dso Date: Wed, 31 Jan 2024 21:24:16 +0200 Message-Id: <20240131192416.16387-1-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789635168422626127 X-GMAIL-MSGID: 1789635168422626127 The test needs a struct machine and creates one for the current host, but a side-effect is that struct machine has set up kernel maps including module maps. If the 'Symbols' test --dso option specifies a current kernel module, it will already be present as a kernel dso, and a map with kmaps needs to be used otherwise there will be a segfault - see below. For that case, find the existing map and use that. In that case also, the dso is split by section into multiple dsos, so test those dsos also. That in turn, shows up that those dsos have not had overlapping symbols removed, so the test fails. Example: Before: $ perf test -F -v Symbols --dso /lib/modules/$(uname -r)/kernel/arch/x86/kvm/kvm-intel.ko 70: Symbols : --- start --- Testing /lib/modules/6.7.2-local/kernel/arch/x86/kvm/kvm-intel.ko Segmentation fault (core dumped) After: $ perf test -F -v Symbols --dso /lib/modules/$(uname -r)/kernel/arch/x86/kvm/kvm-intel.ko 70: Symbols : --- start --- Testing /lib/modules/6.7.2-local/kernel/arch/x86/kvm/kvm-intel.ko Overlapping symbols: 41d30-41fbb l vmx_init 41d30-41fbb g init_module ---- end ---- Symbols: FAILED! Signed-off-by: Adrian Hunter --- tools/perf/tests/symbols.c | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tools/perf/tests/symbols.c b/tools/perf/tests/symbols.c index 16e1c5502b09..2fed6d67f50f 100644 --- a/tools/perf/tests/symbols.c +++ b/tools/perf/tests/symbols.c @@ -41,6 +41,30 @@ static void exit_test_info(struct test_info *ti) machine__delete(ti->machine); } +struct dso_map { + struct dso *dso; + struct map *map; +}; + +static int find_map_cb(struct map *map, void *d) +{ + struct dso_map *data = d; + + if (map__dso(map) != data->dso) + return 0; + data->map = map; + return 1; +} + +static struct map *find_module_map(struct machine *machine, struct dso *dso) +{ + struct dso_map data = { .dso = dso }; + + machine__for_each_kernel_map(machine, find_map_cb, &data); + + return data.map; +} + static void get_test_dso_filename(char *filename, size_t max_sz) { if (dso_to_test) @@ -51,6 +75,26 @@ static void get_test_dso_filename(char *filename, size_t max_sz) static int create_map(struct test_info *ti, char *filename, struct map **map_p) { + struct dso *dso = machine__findnew_dso(ti->machine, filename); + + /* + * If 'filename' matches a current kernel module, must use a kernel + * map. Find the one that already exists. + */ + if (dso && dso->kernel) { + *map_p = find_module_map(ti->machine, dso); + dso__put(dso); + if (!*map_p) { + pr_debug("Failed to find map for curent kernel module %s", + filename); + return TEST_FAIL; + } + map__get(*map_p); + return TEST_OK; + } + + dso__put(dso); + /* Create a dummy map at 0x100000 */ *map_p = map__new(ti->machine, 0x100000, 0xffffffff, 0, NULL, PROT_EXEC, 0, NULL, filename, ti->thread); @@ -97,6 +141,26 @@ static int test_dso(struct dso *dso) return ret; } +static int subdivided_dso_cb(struct dso *dso, struct machine *machine __maybe_unused, void *d) +{ + struct dso *text_dso = d; + + if (dso != text_dso && strstarts(dso->short_name, text_dso->short_name)) + if (test_dso(dso) != TEST_OK) + return -1; + + return 0; +} + +static int process_subdivided_dso(struct machine *machine, struct dso *dso) +{ + int ret; + + ret = machine__for_each_dso(machine, subdivided_dso_cb, dso); + + return ret < 0 ? TEST_FAIL : TEST_OK; +} + static int test_file(struct test_info *ti, char *filename) { struct map *map = NULL; @@ -124,6 +188,10 @@ static int test_file(struct test_info *ti, char *filename) } ret = test_dso(dso); + + /* Module dso is split into many dsos by section */ + if (ret == TEST_OK && dso->kernel) + ret = process_subdivided_dso(ti->machine, dso); out_put: map__put(map);