Commit 6f04d664 authored by Adrian Hunter's avatar Adrian Hunter Committed by Namhyung Kim

perf test: Enable Symbols test to work with a current module dso

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: default avatarAdrian Hunter <adrian.hunter@intel.com>
Reviewed-by: default avatarIan Rogers <irogers@google.com>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240131192416.16387-1-adrian.hunter@intel.com
parent 81901fc0
...@@ -41,6 +41,30 @@ static void exit_test_info(struct test_info *ti) ...@@ -41,6 +41,30 @@ static void exit_test_info(struct test_info *ti)
machine__delete(ti->machine); 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) static void get_test_dso_filename(char *filename, size_t max_sz)
{ {
if (dso_to_test) if (dso_to_test)
...@@ -51,6 +75,26 @@ static void get_test_dso_filename(char *filename, size_t max_sz) ...@@ -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) 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 */ /* Create a dummy map at 0x100000 */
*map_p = map__new(ti->machine, 0x100000, 0xffffffff, 0, NULL, *map_p = map__new(ti->machine, 0x100000, 0xffffffff, 0, NULL,
PROT_EXEC, 0, NULL, filename, ti->thread); PROT_EXEC, 0, NULL, filename, ti->thread);
...@@ -97,6 +141,26 @@ static int test_dso(struct dso *dso) ...@@ -97,6 +141,26 @@ static int test_dso(struct dso *dso)
return ret; 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) static int test_file(struct test_info *ti, char *filename)
{ {
struct map *map = NULL; struct map *map = NULL;
...@@ -124,6 +188,10 @@ static int test_file(struct test_info *ti, char *filename) ...@@ -124,6 +188,10 @@ static int test_file(struct test_info *ti, char *filename)
} }
ret = test_dso(dso); 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: out_put:
map__put(map); map__put(map);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment