[PATCH 1/4] update-linux-headers: fix forwarding to asm-generic headers

Paolo Bonzini posted 4 patches 5 months, 3 weeks ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
[PATCH 1/4] update-linux-headers: fix forwarding to asm-generic headers
Posted by Paolo Bonzini 5 months, 3 weeks ago
Afer commit 3efc75ad9d9 ("scripts/update-linux-headers.sh: Remove
temporary directory inbetween", 2024-05-29), updating linux-headers/
results in errors such as

   cp: cannot stat '/tmp/tmp.1A1Eejh1UE/headers/include/asm/bitsperlong.h': No such file or directory

because Loongarch does not have an asm/bitsperlong.h file and uses the
generic version.  Before commit 3efc75ad9d9, the missing file would
incorrectly cause stale files to be included in linux-headers/.  The files
were never committed to qemu.git, but were wrong nevertheless. The build
would just use the system version of the files, which is opposite to
the idea of importing Linux header files into QEMU's tree.

Create forwarding headers, resembling the ones that are generated during a
kernel build by scripts/Makefile.asm-generic, if a file is only installed
under include/asm-generic/.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/update-linux-headers.sh | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index 23afe8c08ad..ae34d18572b 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -118,7 +118,14 @@ for arch in $ARCHLIST; do
     rm -rf "$output/linux-headers/asm-$arch"
     mkdir -p "$output/linux-headers/asm-$arch"
     for header in kvm.h unistd.h bitsperlong.h mman.h; do
-        cp "$hdrdir/include/asm/$header" "$output/linux-headers/asm-$arch"
+        if test -f "$hdrdir/include/asm/$header"; then
+            cp "$hdrdir/include/asm/$header" "$output/linux-headers/asm-$arch"
+        elif test -f "$hdrdir/include/asm-generic/$header"; then
+            # not installed as <asm/bitsperlong.h>, but used as such in kernel sources
+            cat <<EOF >$output/linux-headers/asm-$arch/$header
+#include <asm-generic/$header>
+EOF
+        fi
     done
 
     if [ $arch = mips ]; then
-- 
2.45.1
Re: [PATCH 1/4] update-linux-headers: fix forwarding to asm-generic headers
Posted by Thomas Huth 5 months, 3 weeks ago
On 03/06/2024 15.11, Paolo Bonzini wrote:
> Afer commit 3efc75ad9d9 ("scripts/update-linux-headers.sh: Remove
> temporary directory inbetween", 2024-05-29), updating linux-headers/
> results in errors such as
> 
>     cp: cannot stat '/tmp/tmp.1A1Eejh1UE/headers/include/asm/bitsperlong.h': No such file or directory

Oops, sorry, I was pretty sure the update was working for me when I tested 
the patch ... maybe I was on an older branch that didn't have loongarch 
support yet.

> diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
> index 23afe8c08ad..ae34d18572b 100755
> --- a/scripts/update-linux-headers.sh
> +++ b/scripts/update-linux-headers.sh
> @@ -118,7 +118,14 @@ for arch in $ARCHLIST; do
>       rm -rf "$output/linux-headers/asm-$arch"
>       mkdir -p "$output/linux-headers/asm-$arch"
>       for header in kvm.h unistd.h bitsperlong.h mman.h; do
> -        cp "$hdrdir/include/asm/$header" "$output/linux-headers/asm-$arch"
> +        if test -f "$hdrdir/include/asm/$header"; then
> +            cp "$hdrdir/include/asm/$header" "$output/linux-headers/asm-$arch"
> +        elif test -f "$hdrdir/include/asm-generic/$header"; then
> +            # not installed as <asm/bitsperlong.h>, but used as such in kernel sources

Maybe change the comment to talk about <asm/$header> instead of 
<asm/bitsperlong.h> ?

> +            cat <<EOF >$output/linux-headers/asm-$arch/$header
> +#include <asm-generic/$header>
> +EOF
> +        fi
>       done
>   
>       if [ $arch = mips ]; then

Reviewed-by: Thomas Huth <thuth@redhat.com>