Commit 2c369d91 authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

perf symbol: Add blocking argument to filename__read_build_id



When synthesizing build-ids, for build ID mmap2 events, they will be
added for data mmaps if -d/--data is specified. The files opened for
their build IDs may block on the open causing perf to hang during
synthesis. There is some robustness in existing calls to
filename__read_build_id by checking the file path is to a regular
file, which unfortunately fails for symlinks. Rather than adding more
is_regular_file calls, switch filename__read_build_id to take a
"block" argument and specify O_NONBLOCK when this is false. The
existing is_regular_file checking callers and the event synthesis
callers are made to pass false and thereby avoiding the hang.

Fixes: 53b00ff3 ("perf record: Make --buildid-mmap the default")
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250823000024.724394-3-irogers@google.com


Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent ba0b7081
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ static int add_dso(const char *fpath, const struct stat *sb __maybe_unused,
	if (typeflag == FTW_D || typeflag == FTW_SL)
		return 0;

	if (filename__read_build_id(fpath, &bid) < 0)
	if (filename__read_build_id(fpath, &bid, /*block=*/true) < 0)
		return 0;

	dso->name = realpath(fpath, NULL);
+4 −4
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
	struct nscookie nsc;

	nsinfo__mountns_enter(nsi, &nsc);
	err = filename__read_build_id(filename, &bid);
	err = filename__read_build_id(filename, &bid, /*block=*/true);
	nsinfo__mountns_exit(&nsc);
	if (err < 0) {
		pr_debug("Couldn't read a build-id in %s\n", filename);
@@ -204,7 +204,7 @@ static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)
	int err;

	nsinfo__mountns_enter(nsi, &nsc);
	err = filename__read_build_id(filename, &bid);
	err = filename__read_build_id(filename, &bid, /*block=*/true);
	nsinfo__mountns_exit(&nsc);
	if (err < 0) {
		pr_debug("Couldn't read a build-id in %s\n", filename);
@@ -280,7 +280,7 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
	if (!dso__build_id_filename(dso, filename, sizeof(filename), false))
		return true;

	if (filename__read_build_id(filename, &bid) == -1) {
	if (filename__read_build_id(filename, &bid, /*block=*/true) == -1) {
		if (errno == ENOENT)
			return false;

@@ -309,7 +309,7 @@ static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi)
	int err;

	nsinfo__mountns_enter(nsi, &nsc);
	err = filename__read_build_id(filename, &bid);
	err = filename__read_build_id(filename, &bid, /*block=*/true);
	nsinfo__mountns_exit(&nsc);
	if (err < 0) {
		pr_debug("Couldn't read a build-id in %s\n", filename);
+2 −2
Original line number Diff line number Diff line
@@ -680,12 +680,12 @@ static int dso__read_build_id(struct dso *dso)

	mutex_lock(dso__lock(dso));
	nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
	if (filename__read_build_id(dso__long_name(dso), &bid) > 0)
	if (filename__read_build_id(dso__long_name(dso), &bid, /*block=*/true) > 0)
		dso__set_build_id(dso, &bid);
	else if (dso__nsinfo(dso)) {
		char *new_name = dso__filename_with_chroot(dso, dso__long_name(dso));

		if (new_name && filename__read_build_id(new_name, &bid) > 0)
		if (new_name && filename__read_build_id(new_name, &bid, /*block=*/true) > 0)
			dso__set_build_id(dso, &bid);
		free(new_name);
	}
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ static int build_id_cache__add_file(const char *filename)
	struct build_id bid = { .size = 0, };
	int err;

	err = filename__read_build_id(filename, &bid);
	err = filename__read_build_id(filename, &bid, /*block=*/true);
	if (err < 0) {
		pr_debug("Failed to read build id of %s\n", filename);
		return err;
+2 −2
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ int filename__snprintf_build_id(const char *pathname, char *sbuild_id, size_t sb
	struct build_id bid = { .size = 0, };
	int ret;

	ret = filename__read_build_id(pathname, &bid);
	ret = filename__read_build_id(pathname, &bid, /*block=*/true);
	if (ret < 0)
		return ret;

@@ -841,7 +841,7 @@ static int filename__read_build_id_ns(const char *filename,
	int ret;

	nsinfo__mountns_enter(nsi, &nsc);
	ret = filename__read_build_id(filename, bid);
	ret = filename__read_build_id(filename, bid, /*block=*/true);
	nsinfo__mountns_exit(&nsc);

	return ret;
Loading