kernel: fix hv tools build for arm64 when cross-built
Subsystems (2)
Hello,
While trying to build the LIS daemons for Flatcar Container Linux for ARM64 (https://www.flatcar.org/), as we are doing Gentoo based cross-building from X64 boxes, there was an error while building those daemons, because the cross-compile scenario was not working, as ARCH := $(shell uname -m 2>/dev/null) always returns x86_64.
I have a working patch for the Linux kernel here that was already applied in the Flatcar context and it works:
https://github.com/flatcar/scripts/blob/94b1df1b19449eb5aa967fd48ba4c1f4a6d5f415/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.10/z0008-tools-hv-fix-cross-compilation-for-ARM64.patch
Sorry for the delivery method via github link, but I cannot send proper patches from my work email address currently, as the email server does not support it.
Please let me know if I need to send the patch via the recommended way or if the patch can be used directly.
Also, maybe there is a better way to address the cross-compilation issue, I just wanted to report the bug and also provide a possible fix.
Thank you,
Adrian Vladu
Wei Liu
maintainerQuoted 19 lines · Adrian Vladu
Hello,
While trying to build the LIS daemons for Flatcar Container Linux for ARM64 (https://www.flatcar.org/), as we are doing Gentoo based cross-building from X64 boxes, there was an error while building those daemons, because the cross-compile scenario was not working, as
ARCH := $(shell uname -m 2>/dev/null)always returnsx86_64.I have a working patch for the Linux kernel here that was already applied in the Flatcar context and it works:
https://github.com/flatcar/scripts/blob/94b1df1b19449eb5aa967fd48ba4c1f4a6d5f415/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.10/z0008-tools-hv-fix-cross-compilation-for-ARM64.patchSorry for the delivery method via github link, but I cannot send proper patches from my work email address currently, as the email server does not support it.
Quoted 6 lines
Please let me know if I need to send the patch via the recommended way or if the patch can be used directly.
Also, maybe there is a better way to address the cross-compilation issue, I just wanted to report the bug and also provide a possible fix.
Saurabh added the ARCH variable. He's CCed.
BTW I think your patch can be simplified by using
ARCH ?= $(shell uname -m 2>/dev/null)
instead of the ifeq test in your patch.
I don't think that's correct. ARCH will be set to the correct value by Kbuild.
Saurabh and Adrian, can you test the following patch?
Thanks,
Wei.
From e6a1827887617c08172e2d0ee0d60549f5ccad65 Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Mon, 9 Dec 2024 00:32:50 +0000
Subject: [PATCH] tools/hv: fix cross-compilation issue in hv tools
The Kbuild system sets ARCH to the correct value.
--- tools/hv/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/hv/Makefile +1 -2
@@ -2,7 +2,6 @@ # Makefile for Hyper-V tools include ../scripts/Makefile.include -ARCH := $(shell uname -m 2>/dev/null) sbindir ?= /usr/sbin libexecdir ?= /usr/libexec sharedstatedir ?= /var/lib
@@ -20,7 +19,7 @@ override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include override CFLAGS += -Wno-address-of-packed-member ALL_TARGETS := hv_kvp_daemon hv_vss_daemon -ifneq ($(ARCH), aarch64) +ifneq ($(ARCH), arm64) ALL_TARGETS += hv_fcopy_uio_daemon endif ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
Signature · 1 line
2.45.2
Quoted 27 lines · Wei Liu
Quoted 19 lines · Adrian Vladu
Hello,
While trying to build the LIS daemons for Flatcar Container Linux for ARM64 (https://www.flatcar.org/), as we are doing Gentoo based cross-building from X64 boxes, there was an error while building those daemons, because the cross-compile scenario was not working, as
ARCH := $(shell uname -m 2>/dev/null)always returnsx86_64.I have a working patch for the Linux kernel here that was already applied in the Flatcar context and it works:
https://github.com/flatcar/scripts/blob/94b1df1b19449eb5aa967fd48ba4c1f4a6d5f415/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.10/z0008-tools-hv-fix-cross-compilation-for-ARM64.patchSorry for the delivery method via github link, but I cannot send proper patches from my work email address currently, as the email server does not support it.
Quoted 6 lines
Please let me know if I need to send the patch via the recommended way or if the patch can be used directly.
Also, maybe there is a better way to address the cross-compilation issue, I just wanted to report the bug and also provide a possible fix.
Quoted 5 lines
Saurabh added the ARCH variable. He's CCed.
BTW I think your patch can be simplified by using
ARCH ?= $(shell uname -m 2>/dev/null)
instead of the ifeq test in your patch.
Agree, this is better way to handle it.
Quoted 3 lines
I don't think that's correct. ARCH will be set to the correct value by
Kbuild.
If we build locally on ARM64, there is a chance that ARCH may not be set, leading to build failures for arm64. IMO we should provide a fallback option for local builds when ARCH is not set.
Quoted 31 lines
Saurabh and Adrian, can you test the following patch?
Thanks,
Wei.Quoted 1 line
From
e6a1827887617c08172e2d0ee0d60549f5ccad65Mon Sep 17 00:00:00 2001From: Wei Liu <[email protected]>
Date: Mon, 9 Dec 2024 00:32:50 +0000
Subject: [PATCH]tools/hv: fix cross-compilation issue in hv toolsThe
Kbuildsystem sets ARCH to the correct value.Signed-off-by Wei Liu <[email protected]>--- tools/hv/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)tools/hv/Makefile +0
-1@@ -2,7 +2,6 @@ # Makefile for Hyper-V tools include ../scripts/Makefile.include -ARCH := $(shell uname -m 2>/dev/null) sbindir ?= /usr/sbin libexecdir ?= /usr/libexec sharedstatedir ?= /var/lib
tools/hv/Makefile override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include · line 22
Quoted 5 lines
tools/hv/Makefile +1
-1@@ -20,7 +19,7 @@ override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include override CFLAGS += -Wno-address-of-packed-member ALL_TARGETS := hv_kvp_daemon hv_vss_daemon -ifneq ($(ARCH), aarch64) +ifneq ($(ARCH), arm64)
My understanding is ARCH could be either aarch64 or arm64.
- Saurabh
Wei Liu
maintainerQuoted 37 lines · Saurabh Singh Sengar
Quoted 27 lines · Wei Liu
Quoted 19 lines · Adrian Vladu
Hello,
While trying to build the LIS daemons for Flatcar Container Linux for ARM64 (https://www.flatcar.org/), as we are doing Gentoo based cross-building from X64 boxes, there was an error while building those daemons, because the cross-compile scenario was not working, as
ARCH := $(shell uname -m 2>/dev/null)always returnsx86_64.I have a working patch for the Linux kernel here that was already applied in the Flatcar context and it works:
https://github.com/flatcar/scripts/blob/94b1df1b19449eb5aa967fd48ba4c1f4a6d5f415/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.10/z0008-tools-hv-fix-cross-compilation-for-ARM64.patchSorry for the delivery method via github link, but I cannot send proper patches from my work email address currently, as the email server does not support it.
Quoted 6 lines
Please let me know if I need to send the patch via the recommended way or if the patch can be used directly.
Also, maybe there is a better way to address the cross-compilation issue, I just wanted to report the bug and also provide a possible fix.
Quoted 5 lines
Saurabh added the ARCH variable. He's CCed.
BTW I think your patch can be simplified by using
ARCH ?= $(shell uname -m 2>/dev/null)
instead of the ifeq test in your patch.Agree, this is better way to handle it.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
I don't think that's correct. ARCH will be set to the correct value by
Kbuild.If we build locally on ARM64, there is a chance that ARCH may not be set, leading to build failures for arm64. IMO we should provide a fallback option for local builds when ARCH is not set.
How do you build locally? Even if you build those tools in tools/hv, it still uses the Kbuild system, which sets ARCH to the correct value, right?
Thanks,
Wei.
Quoted 41 lines · Wei Liu
Quoted 40 lines · Saurabh Singh Sengar
Quoted 27 lines · Wei Liu
Quoted 19 lines · Adrian Vladu
Hello,
While trying to build the LIS daemons for Flatcar Container Linux for ARM64 (https://www.flatcar.org/), as we are doing Gentoo based cross-building from X64 boxes, there was an error while building those daemons, because the cross-compile scenario was not working, as
ARCH := $(shell uname -m 2>/dev/null)always returnsx86_64.I have a working patch for the Linux kernel here that was already applied in the Flatcar context and it works:
https://github.com/flatcar/scripts/blob/94b1df1b19449eb5aa967fd48ba4c1f4a6d5f415/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.10/z0008-tools-hv-fix-cross-compilation-for-ARM64.patchSorry for the delivery method via github link, but I cannot send proper patches from my work email address currently, as the email server does not support it.
Quoted 6 lines
Please let me know if I need to send the patch via the recommended way or if the patch can be used directly.
Also, maybe there is a better way to address the cross-compilation issue, I just wanted to report the bug and also provide a possible fix.
Quoted 5 lines
Saurabh added the ARCH variable. He's CCed.
BTW I think your patch can be simplified by using
ARCH ?= $(shell uname -m 2>/dev/null)
instead of the ifeq test in your patch.Agree, this is better way to handle it.
Quoted 3 lines
I don't think that's correct. ARCH will be set to the correct value by
Kbuild.
Quoted 8 lines
Quoted 3 lines
If we build locally on ARM64, there is a chance that ARCH may not be set, leading to build failures for arm64. IMO we should provide a fallback option for local builds when ARCH is not set.
How do you build locally? Even if you build those tools in
tools/hv, it still uses theKbuildsystem, which sets ARCH to the correct value, right?
I have tested your patch in ARM64 VM, can see the build failure. Here's the exact details how I tested:
azureuser@ARM64-ubunutu24:/work/linux-next$ cd tools/hv/
azureuser@ARM64-ubunutu24:/work/linux-next/tools/hv$ make
make[1]: Entering directory '/work/linux-next/tools/hv'
CC hv_kvp_daemon.o
LD hv_kvp_daemon-in.o
make[1]: Leaving directory '/work/linux-next/tools/hv'
LINK hv_kvp_daemon
make[1]: Entering directory '/work/linux-next/tools/hv'
CC hv_vss_daemon.o
LD hv_vss_daemon-in.o
make[1]: Leaving directory '/work/linux-next/tools/hv'
LINK hv_vss_daemon
make[1]: Entering directory '/work/linux-next/tools/hv'
CC hv_fcopy_uio_daemon.o
CC vmbus_bufring.o
vmbus_bufring.c:11:10: fatal error: emmintrin.h: No such file or directory
11 | #include <emmintrin.h>
| ^~~~~~~~~~~~~
compilation terminated.
make[1]: *** [/work/linux-next/tools/build/Makefile.build:106: vmbus_bufring.o] Error 1
make[1]: Leaving directory '/work/linux-next/tools/hv'
make: *** [Makefile:48: hv_fcopy_uio_daemon-in.o] Error 2
azureuser@ARM64-ubunutu24:/work/linux-next/tools/hv$ uname -a
Linux ARM64-ubunutu24 6.12.0-next-20241128+ #12 SMP Fri Nov 29 14:53:06 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux- Saurabh
Wei Liu
maintainerQuoted 65 lines · Saurabh Singh Sengar
Quoted 41 lines · Wei Liu
Quoted 40 lines · Saurabh Singh Sengar
Quoted 27 lines · Wei Liu
Quoted 19 lines · Adrian Vladu
Hello,
While trying to build the LIS daemons for Flatcar Container Linux for ARM64 (https://www.flatcar.org/), as we are doing Gentoo based cross-building from X64 boxes, there was an error while building those daemons, because the cross-compile scenario was not working, as
ARCH := $(shell uname -m 2>/dev/null)always returnsx86_64.I have a working patch for the Linux kernel here that was already applied in the Flatcar context and it works:
https://github.com/flatcar/scripts/blob/94b1df1b19449eb5aa967fd48ba4c1f4a6d5f415/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.10/z0008-tools-hv-fix-cross-compilation-for-ARM64.patchSorry for the delivery method via github link, but I cannot send proper patches from my work email address currently, as the email server does not support it.
Quoted 6 lines
Please let me know if I need to send the patch via the recommended way or if the patch can be used directly.
Also, maybe there is a better way to address the cross-compilation issue, I just wanted to report the bug and also provide a possible fix.
Quoted 5 lines
Saurabh added the ARCH variable. He's CCed.
BTW I think your patch can be simplified by using
ARCH ?= $(shell uname -m 2>/dev/null)
instead of the ifeq test in your patch.Agree, this is better way to handle it.
Quoted 3 lines
I don't think that's correct. ARCH will be set to the correct value by
Kbuild.Quoted 8 lines
Quoted 3 lines
If we build locally on ARM64, there is a chance that ARCH may not be set, leading to build failures for arm64. IMO we should provide a fallback option for local builds when ARCH is not set.
How do you build locally? Even if you build those tools in
tools/hv, it still uses theKbuildsystem, which sets ARCH to the correct value, right?I have tested your patch in ARM64 VM, can see the build failure. Here's the exact details how I tested:
azureuser@ARM64-ubunutu24:/work/linux-next$ cd tools/hv/ azureuser@ARM64-ubunutu24:/work/linux-next/tools/hv$ make make[1]: Entering directory '/work/linux-next/tools/hv' CC hv_kvp_daemon.o LD hv_kvp_daemon-in.o make[1]: Leaving directory '/work/linux-next/tools/hv' LINK hv_kvp_daemon make[1]: Entering directory '/work/linux-next/tools/hv' CC hv_vss_daemon.o LD hv_vss_daemon-in.o
Quoted 8 lines
make[1]: Leaving directory '/work/linux-next/tools/hv'
LINK hv_vss_daemon
make[1]: Entering directory '/work/linux-next/tools/hv'
CC hv_fcopy_uio_daemon.o
CC vmbus_bufring.o
vmbus_bufring.c:11:10: fatal error: emmintrin.h: No such file or directory
11 | #include <emmintrin.h>
| ^~~~~~~~~~~~~I see. I create an arm64 VM and reproduce the issue. The ARCH variable is not set.
That said, the build breaks because emmintrin.h is not available on arm64. It is only needed for _mm_pause(). There is maybe an architecture specific header file we can use to make it build.
Thanks,
Wei.
Quoted 8 lines
compilation terminated.
make[1]: *** [/work/linux-next/tools/build/Makefile.build:106: vmbus_bufring.o] Error 1 make[1]: Leaving directory '/work/linux-next/tools/hv'
make: *** [Makefile:48: hv_fcopy_uio_daemon-in.o] Error 2azureuser@ARM64-ubunutu24:/work/linux-next/tools/hv$ uname -a Linux ARM64-ubunutu24 6.12.0-next-20241128+ #12 SMP Fri Nov 29 14:53:06 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux- Saurabh
Wei Liu
maintainerQuoted 75 lines · Wei Liu
Quoted 65 lines · Saurabh Singh Sengar
Quoted 41 lines · Wei Liu
Quoted 40 lines · Saurabh Singh Sengar
Quoted 27 lines · Wei Liu
Quoted 19 lines · Adrian Vladu
Hello,
While trying to build the LIS daemons for Flatcar Container Linux for ARM64 (https://www.flatcar.org/), as we are doing Gentoo based cross-building from X64 boxes, there was an error while building those daemons, because the cross-compile scenario was not working, as
ARCH := $(shell uname -m 2>/dev/null)always returnsx86_64.I have a working patch for the Linux kernel here that was already applied in the Flatcar context and it works:
https://github.com/flatcar/scripts/blob/94b1df1b19449eb5aa967fd48ba4c1f4a6d5f415/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.10/z0008-tools-hv-fix-cross-compilation-for-ARM64.patchSorry for the delivery method via github link, but I cannot send proper patches from my work email address currently, as the email server does not support it.
Quoted 6 lines
Please let me know if I need to send the patch via the recommended way or if the patch can be used directly.
Also, maybe there is a better way to address the cross-compilation issue, I just wanted to report the bug and also provide a possible fix.
Quoted 5 lines
Saurabh added the ARCH variable. He's CCed.
BTW I think your patch can be simplified by using
ARCH ?= $(shell uname -m 2>/dev/null)
instead of the ifeq test in your patch.Agree, this is better way to handle it.
Quoted 3 lines
I don't think that's correct. ARCH will be set to the correct value by
Kbuild.Quoted 8 lines
Quoted 3 lines
If we build locally on ARM64, there is a chance that ARCH may not be set, leading to build failures for arm64. IMO we should provide a fallback option for local builds when ARCH is not set.
How do you build locally? Even if you build those tools in
tools/hv, it still uses theKbuildsystem, which sets ARCH to the correct value, right?I have tested your patch in ARM64 VM, can see the build failure. Here's the exact details how I tested:
azureuser@ARM64-ubunutu24:/work/linux-next$ cd tools/hv/ azureuser@ARM64-ubunutu24:/work/linux-next/tools/hv$ make make[1]: Entering directory '/work/linux-next/tools/hv' CC hv_kvp_daemon.o LD hv_kvp_daemon-in.o make[1]: Leaving directory '/work/linux-next/tools/hv' LINK hv_kvp_daemon make[1]: Entering directory '/work/linux-next/tools/hv' CC hv_vss_daemon.o LD hv_vss_daemon-in.oQuoted 8 lines
make[1]: Leaving directory '/work/linux-next/tools/hv' LINK hv_vss_daemon make[1]: Entering directory '/work/linux-next/tools/hv' CC hv_fcopy_uio_daemon.o CC vmbus_bufring.o vmbus_bufring.c:11:10: fatal error: emmintrin.h: No such file or directory 11 | #include <emmintrin.h> | ^~~~~~~~~~~~~
Quoted 6 lines
I see. I create an arm64 VM and reproduce the issue. The ARCH variable is not set.
That said, the build breaks because
emmintrin.his not available on arm64. It is only needed for_mm_pause(). There is maybe an architecture specific header file we can use to make it build.
Never mind. There are also open coded x86 assembly code in vmbus_bufring.c. Let's fix the cross-compilation issue first.
Thanks,
Wei.
Quoted 79 lines · Wei Liu
Quoted 78 lines · Wei Liu
Quoted 65 lines · Saurabh Singh Sengar
Quoted 41 lines · Wei Liu
Quoted 40 lines · Saurabh Singh Sengar
Quoted 27 lines · Wei Liu
Quoted 19 lines · Adrian Vladu
Hello,
While trying to build the LIS daemons for Flatcar Container Linux for ARM64 (https://www.flatcar.org/), as we are doing Gentoo based cross-building from X64 boxes, there was an error while building those daemons, because the cross-compile scenario was not working, as
ARCH := $(shell uname -m 2>/dev/null)always returnsx86_64.I have a working patch for the Linux kernel here that was already applied in the Flatcar context and it works:
https://github.com/flatcar/scripts/blob/94b1df1b19449eb5aa967fd48ba4c1f4a6d5f415/sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-sources/files/6.10/z0008-tools-hv-fix-cross-compilation-for-ARM64.patchSorry for the delivery method via github link, but I cannot send proper patches from my work email address currently, as the email server does not support it.
Quoted 6 lines
Please let me know if I need to send the patch via the recommended way or if the patch can be used directly.
Also, maybe there is a better way to address the cross-compilation issue, I just wanted to report the bug and also provide a possible fix.
Quoted 5 lines
Saurabh added the ARCH variable. He's CCed.
BTW I think your patch can be simplified by using
ARCH ?= $(shell uname -m 2>/dev/null)
instead of the ifeq test in your patch.Agree, this is better way to handle it.
Quoted 3 lines
I don't think that's correct. ARCH will be set to the correct value by
Kbuild.Quoted 8 lines
Quoted 3 lines
If we build locally on ARM64, there is a chance that ARCH may not be set, leading to build failures for arm64. IMO we should provide a fallback option for local builds when ARCH is not set.
How do you build locally? Even if you build those tools in
tools/hv, it still uses theKbuildsystem, which sets ARCH to the correct value, right?I have tested your patch in ARM64 VM, can see the build failure. Here's the exact details how I tested:
azureuser@ARM64-ubunutu24:/work/linux-next$ cd tools/hv/ azureuser@ARM64-ubunutu24:/work/linux-next/tools/hv$ make make[1]: Entering directory '/work/linux-next/tools/hv' CC hv_kvp_daemon.o LD hv_kvp_daemon-in.o make[1]: Leaving directory '/work/linux-next/tools/hv' LINK hv_kvp_daemon make[1]: Entering directory '/work/linux-next/tools/hv' CC hv_vss_daemon.o LD hv_vss_daemon-in.oQuoted 8 lines
make[1]: Leaving directory '/work/linux-next/tools/hv' LINK hv_vss_daemon make[1]: Entering directory '/work/linux-next/tools/hv' CC hv_fcopy_uio_daemon.o CC vmbus_bufring.o vmbus_bufring.c:11:10: fatal error: emmintrin.h: No such file or directory 11 | #include <emmintrin.h> | ^~~~~~~~~~~~~I see. I create an arm64 VM and reproduce the issue. The ARCH variable is not set.
Quoted 6 lines
Quoted 3 lines
That said, the build breaks because
emmintrin.his not available on arm64. It is only needed for_mm_pause(). There is maybe an architecture specific header file we can use to make it build.Never mind. There are also open coded x86 assembly code in
vmbus_bufring.c. Let's fix the cross-compilation issue first.
sent a patch for this : https://lkml.org/lkml/2024/12/12/307
- Saurabh
Quoted 3 lines
Thanks,
Wei.