Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "vdso.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "dso.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <internal/lib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "symbol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "machine.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "thread.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "linux/string.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/zalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * Include definition of find_map() also used in perf-read-vdso.c for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * building perf-read-vdso32 and perf-read-vdsox32.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "find-map.c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct vdso_file {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	bool found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	bool error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	char temp_file_name[sizeof(VDSO__TEMP_FILE_NAME)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	const char *dso_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	const char *read_prog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) struct vdso_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct vdso_file vdso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct vdso_file vdso32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct vdso_file vdsox32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct vdso_info *vdso_info__new(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	static const struct vdso_info vdso_info_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		.vdso    = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			.temp_file_name = VDSO__TEMP_FILE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			.dso_name = DSO__NAME_VDSO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		.vdso32  = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			.temp_file_name = VDSO__TEMP_FILE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			.dso_name = DSO__NAME_VDSO32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			.read_prog = "perf-read-vdso32",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		.vdsox32  = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			.temp_file_name = VDSO__TEMP_FILE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			.dso_name = DSO__NAME_VDSOX32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			.read_prog = "perf-read-vdsox32",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return memdup(&vdso_info_init, sizeof(vdso_info_init));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static char *get_file(struct vdso_file *vdso_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	char *vdso = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	char *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	void *start, *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (vdso_file->found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return vdso_file->temp_file_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (vdso_file->error || find_map(&start, &end, VDSO__MAP_NAME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	size = end - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	buf = memdup(start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	fd = mkstemp(vdso_file->temp_file_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (fd < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (size == (size_t) write(fd, buf, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		vdso = vdso_file->temp_file_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	free(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	vdso_file->found = (vdso != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	vdso_file->error = !vdso_file->found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return vdso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void machine__exit_vdso(struct machine *machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct vdso_info *vdso_info = machine->vdso_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (!vdso_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (vdso_info->vdso.found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		unlink(vdso_info->vdso.temp_file_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (vdso_info->vdso32.found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		unlink(vdso_info->vdso32.temp_file_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (vdso_info->vdsox32.found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		unlink(vdso_info->vdsox32.temp_file_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	zfree(&machine->vdso_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static struct dso *__machine__addnew_vdso(struct machine *machine, const char *short_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 					  const char *long_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct dso *dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	dso = dso__new(short_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (dso != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		__dsos__add(&machine->dsos, dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		dso__set_long_name(dso, long_name, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		/* Put dso here because __dsos_add already got it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		dso__put(dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static enum dso_type machine__thread_dso_type(struct machine *machine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 					      struct thread *thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	enum dso_type dso_type = DSO__TYPE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	maps__for_each_entry(thread->maps, map) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		struct dso *dso = map->dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		if (!dso || dso->long_name[0] != '/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		dso_type = dso__type(dso, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (dso_type != DSO__TYPE_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return dso_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int vdso__do_copy_compat(FILE *f, int fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	char buf[4096];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	size_t count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		count = fread(buf, 1, sizeof(buf), f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		if (ferror(f))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		if (feof(f))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		if (count && writen(fd, buf, count) != (ssize_t)count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int vdso__copy_compat(const char *prog, int fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	FILE *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	f = popen(prog, "r");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (!f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	err = vdso__do_copy_compat(f, fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (pclose(f) == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static int vdso__create_compat_file(const char *prog, char *temp_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	int fd, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	fd = mkstemp(temp_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (fd < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	err = vdso__copy_compat(prog, fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (close(fd) == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static const char *vdso__get_compat_file(struct vdso_file *vdso_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (vdso_file->found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return vdso_file->temp_file_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (vdso_file->error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	err = vdso__create_compat_file(vdso_file->read_prog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				       vdso_file->temp_file_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		pr_err("%s failed, error %d\n", vdso_file->read_prog, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		vdso_file->error = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	vdso_file->found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return vdso_file->temp_file_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static struct dso *__machine__findnew_compat(struct machine *machine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 					     struct vdso_file *vdso_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	const char *file_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct dso *dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	dso = __dsos__find(&machine->dsos, vdso_file->dso_name, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	file_name = vdso__get_compat_file(vdso_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (!file_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	dso = __machine__addnew_vdso(machine, vdso_file->dso_name, file_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int __machine__findnew_vdso_compat(struct machine *machine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 					  struct thread *thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 					  struct vdso_info *vdso_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 					  struct dso **dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	enum dso_type dso_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	dso_type = machine__thread_dso_type(machine, thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #ifndef HAVE_PERF_READ_VDSO32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (dso_type == DSO__TYPE_32BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #ifndef HAVE_PERF_READ_VDSOX32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (dso_type == DSO__TYPE_X32BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	switch (dso_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	case DSO__TYPE_32BIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		*dso = __machine__findnew_compat(machine, &vdso_info->vdso32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	case DSO__TYPE_X32BIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		*dso = __machine__findnew_compat(machine, &vdso_info->vdsox32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	case DSO__TYPE_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	case DSO__TYPE_64BIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static struct dso *machine__find_vdso(struct machine *machine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 				      struct thread *thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct dso *dso = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	enum dso_type dso_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	dso_type = machine__thread_dso_type(machine, thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	switch (dso_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	case DSO__TYPE_32BIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		dso = __dsos__find(&machine->dsos, DSO__NAME_VDSO32, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		if (!dso) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			dso = __dsos__find(&machine->dsos, DSO__NAME_VDSO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 					   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			if (dso && dso_type != dso__type(dso, machine))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 				dso = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	case DSO__TYPE_X32BIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		dso = __dsos__find(&machine->dsos, DSO__NAME_VDSOX32, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	case DSO__TYPE_64BIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	case DSO__TYPE_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		dso = __dsos__find(&machine->dsos, DSO__NAME_VDSO, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	return dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct dso *machine__findnew_vdso(struct machine *machine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 				  struct thread *thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	struct vdso_info *vdso_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	struct dso *dso = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	down_write(&machine->dsos.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (!machine->vdso_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		machine->vdso_info = vdso_info__new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	vdso_info = machine->vdso_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (!vdso_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	dso = machine__find_vdso(machine, thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	if (__machine__findnew_vdso_compat(machine, thread, vdso_info, &dso))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	dso = __dsos__find(&machine->dsos, DSO__NAME_VDSO, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	if (!dso) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		char *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		file = get_file(&vdso_info->vdso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		if (file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			dso = __machine__addnew_vdso(machine, DSO__NAME_VDSO, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	dso__get(dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	up_write(&machine->dsos.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	return dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) bool dso__is_vdso(struct dso *dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	return !strcmp(dso->short_name, DSO__NAME_VDSO) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	       !strcmp(dso->short_name, DSO__NAME_VDSO32) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	       !strcmp(dso->short_name, DSO__NAME_VDSOX32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }