Re: [PATCH v2 2/2] perf tools: Put Python bytecode in output directory

From
Ian Rogers <irogers@google.com>
Date
2026-09-21 18:12:38
Also in
linux-perf-users, sashiko-reviews
Reply to
sashiko-bot@kernel.org, 2026-09-21
On Mon, Sep 21, 2026 at 11:05 AM [off-list ref] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: root filesystem pollution or build failure due to stray slash in PYTHONPYCACHEPREFIX
--

commit 3de8bc01d44a9b11e10c327ec26bbff8605926df
Author: Ben Hutchings [off-list ref]

perf tools: Put Python bytecode in output directory

This commit sets the PYTHONPYCACHEPREFIX environment variable to relocate
the Python bytecode cache directory to the output directory during out-of-tree
builds. It also updates the python-clean rule to remove the new cache directory
and perf.pyi.
quoted
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index a0b23d20d005c..50bde95c78a54 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -397,7 +397,8 @@ PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
 PYTHON_EXTBUILD_TMP := $(PYTHON_EXTBUILD)tmp/
 export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP

-python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)python/perf*.so
+# Put Python bytecode in output directory
+export PYTHONPYCACHEPREFIX := $(OUTPUT)/__pycache__
[Severity: Medium]
For in-tree builds where $(OUTPUT) is empty, does the unconditional inclusion
of the slash cause this to evaluate to the absolute path /__pycache__?

When Python 3.8+ runs during the build, it appears it would attempt to write
bytecode files to the root of the filesystem. Could this cause a regression
by breaking the build with permission errors for unprivileged users, or
silently pollute the root filesystem if executed as root?
This is already the behavior. The difference now is that instead of
multiple __pycache__ directories for the directory the python script
is within, there is a single top-level __pycache__ directory that is
handled by the clean step.
[ ... ]
quoted
@@ -919,7 +920,12 @@ $(INSTALL_DOC_TARGETS):
 ### Cleaning rules

 python-clean:
-     $(python-clean)
+     $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)__pycache__ \
[Severity: Medium]
Since $(OUTPUT)__pycache__ would evaluate to __pycache__ in the current
directory during in-tree builds, would this fail to clean the incorrectly
placed bytecode directory at the root of the filesystem?
Same issue; yes, the build would fail but the build would already be
failing if this were a problem.

Thanks,
Ian
quoted
+             $(OUTPUT)python/perf*.so
+     @if [ "$(abspath python/perf.pyi)" != "$(abspath $(OUTPUT)python/perf.pyi)" ]; \
+     then \
+             $(RM) $(OUTPUT)python/perf.pyi; \
+     fi
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260921175719.846883-1-irogers@google.com?part=2
Thread (14 messages) 14 messages, 5 authors, last reply 2026-09-28
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help