Re: [PATCH] perf kvm stat: Fix build error

From: Leo Yan

Date: Thu Feb 26 2026 - 04:59:41 EST


On Wed, Feb 25, 2026 at 10:36:26PM -0800, Ian Rogers wrote:

[...]

> Hmm.. it looks like something has gone screwy with the include paths.
> The header you've gotten is:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/arch/x86/include/uapi/asm/svm.h#n137
> rather than:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/arch/x86/include/uapi/asm/svm.h#n137
> where the value differs between -1ull and -1.
>
> In Leo's change he has the include path as:
> #include "../../arch/x86/include/uapi/asm/svm.h"
>
> but I think that is off by one and should be:
> #include "../../../arch/x86/include/uapi/asm/svm.h"

Sorry I did not check the header path carefully. A bit thoughts:

The perf build will not include headers in relative paths as we
expected.

It tries to find headers with appending search paths. As Ian said,
I saw .kvm-stat-x86.o.cmd that includes kernel headers:

/home/niayan01/Work/linux/tools/include/../../arch/x86/include/uapi/asm/svm.h \
/home/niayan01/Work/linux/tools/include/../../arch/x86/include/uapi/asm/vmx.h \
/home/niayan01/Work/linux/tools/include/../../arch/x86/include/uapi/asm/kvm.h \

I'd suggest a fix in Makefile as below. The idea is to give priority to
the lower level folders under perf, so that headers in the deeper perf
directories are searched first. This avoids searching any kernel headers.

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index a8dc72cfe48e..47359f672b6a 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -388,8 +388,10 @@ ifeq ($(DEBUG),0)
endif
endif

-INC_FLAGS += -I$(src-perf)/util/include
INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
+INC_FLAGS += -I$(src-perf)/util/include
+INC_FLAGS += -I$(src-perf)/util
+INC_FLAGS += -I$(src-perf)
INC_FLAGS += -I$(srctree)/tools/include/
INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
INC_FLAGS += -I$(srctree)/tools/include/uapi
@@ -403,9 +405,6 @@ INC_FLAGS += -I$(obj-perf)/util
INC_FLAGS += -I$(obj-perf)
endif

-INC_FLAGS += -I$(src-perf)/util
-INC_FLAGS += -I$(src-perf)
-
CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_

As a result, I can get the search paths in .kvm-stat-x86.o.cmd:

/home/niayan01/Work/linux/tools/perf/util/../../arch/x86/include/uapi/asm/svm.h \
/home/niayan01/Work/linux/tools/perf/util/../../arch/x86/include/uapi/asm/vmx.h \
/home/niayan01/Work/linux/tools/perf/util/../../arch/x86/include/uapi/asm/kvm.h \

Please let me know if this makes sense.

Thanks,
Leo