kernel: fix hv tools build for arm64 when cross-built

2024-10-23 Thread 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 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

Raw patch link here: 
https://raw.githubusercontent.com/flatcar/scripts/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


Re: [PATCH] tools: hv: Fix cross-compilation

2024-12-14 Thread Adrian Vladu
Thanks for the refined patch, much appreciated.
For Flatcar Container Linux, we would like to use 6.12 kernel, would be great 
to have this fix backported to the stable branch 6.12.


From: Roman Kisel 
Sent: Friday, December 13, 2024 8:11 PM
To: Saurabh Sengar ; k...@microsoft.com 
; haiya...@microsoft.com ; 
wei@kernel.org ; de...@microsoft.com 
; linux-hyperv@vger.kernel.org 
; linux-ker...@vger.kernel.org 

Cc: ssen...@microsoft.com ; Adrian Vladu 

Subject: Re: [PATCH] tools: hv: Fix cross-compilation
 
Thanks, LGTM!

Reviewed-by: Roman Kisel 

On 12/12/2024 12:28 AM, Saurabh Sengar wrote:
> Use the native ARCH only incase it is not set, this will allow
> the cross complilation where ARCH is explicitly set. Add few
> info prints as well to know what arch and toolchain is getting
> used to build it.
>
> Additionally, simplify the check for ARCH so that fcopy daemon
> is build only for x86_64.
>
> Fixes: 82b0945ce2c2 ("tools: hv: Add new fcopy application based on uio 
> driver")
> Reported-by: Adrian Vladu 
> Closes: 
> https://lore.kernel.org/linux-hyperv/Z1Y9ZkAt9GPjQsGi@liuwe-devbox-debian-v2/
> Signed-off-by: Saurabh Sengar 
> ---
>   tools/hv/Makefile | 14 +++---
>   1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/tools/hv/Makefile b/tools/hv/Makefile
> index 34ffcec264ab..d29e6be6309b 100644
> --- a/tools/hv/Makefile
> +++ b/tools/hv/Makefile
> @@ -2,7 +2,7 @@
>   # Makefile for Hyper-V tools
>   include ../scripts/Makefile.include
>  
> -ARCH := $(shell uname -m 2>/dev/null)
> +ARCH ?= $(shell uname -m 2>/dev/null)
>   sbindir ?= /usr/sbin
>   libexecdir ?= /usr/libexec
>   sharedstatedir ?= /var/lib
> @@ -20,18 +20,26 @@ 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)
> +ifeq ($(ARCH), x86_64)
>   ALL_TARGETS += hv_fcopy_uio_daemon
>   endif
>   ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
>  
>   ALL_SCRIPTS := hv_get_dhcp_info.sh hv_get_dns_info.sh hv_set_ifconfig.sh
>  
> -all: $(ALL_PROGRAMS)
> +all: info $(ALL_PROGRAMS)
>  
>   export srctree OUTPUT CC LD CFLAGS
>   include $(srctree)/tools/build/Makefile.include
>  
> +info:
> + @echo "-"
> + @echo "Building for:"
> + @echo "CC $(CC)"
> + @echo "LD $(LD)"
> + @echo "ARCH $(ARCH)"
> + @echo "-"
> +
>   HV_KVP_DAEMON_IN := $(OUTPUT)hv_kvp_daemon-in.o
>   $(HV_KVP_DAEMON_IN): FORCE
>    $(Q)$(MAKE) $(build)=hv_kvp_daemon

--
Thank you,
Roman