[1/1] auto disable cross for kmod build against distro kernels

Message ID 20240118103102.658035-1-felix.moessbauer@siemens.com
State Accepted, archived
Headers show
Series [1/1] auto disable cross for kmod build against distro kernels | expand

Commit Message

MOESSBAUER, Felix Jan. 18, 2024, 10:31 a.m. UTC
Cross compiling kernel modules for distro kernels is not supported in debian.
To simplify downstream kernel module builds, we automatically turn off cross
compilation for a user-provided module when building it for a distro kernel.

This patch further replaces the hard-coded list of distro kernels with
the DISTRO_KERNELS variable to avoid code duplication.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 RECIPE-API-CHANGELOG.md                       |  6 +++++
 .../example-module/example-module.bb          | 22 -------------------
 meta/recipes-kernel/linux-module/module.inc   | 10 +++++++++
 3 files changed, 16 insertions(+), 22 deletions(-)

Comments

Jan Kiszka Jan. 18, 2024, 10:34 a.m. UTC | #1
On 18.01.24 11:31, Felix Moessbauer wrote:
> Cross compiling kernel modules for distro kernels is not supported in debian.
> To simplify downstream kernel module builds, we automatically turn off cross
> compilation for a user-provided module when building it for a distro kernel.
> 
> This patch further replaces the hard-coded list of distro kernels with
> the DISTRO_KERNELS variable to avoid code duplication.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  RECIPE-API-CHANGELOG.md                       |  6 +++++
>  .../example-module/example-module.bb          | 22 -------------------
>  meta/recipes-kernel/linux-module/module.inc   | 10 +++++++++
>  3 files changed, 16 insertions(+), 22 deletions(-)
> 
> diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
> index bea12871..b1e5a5ab 100644
> --- a/RECIPE-API-CHANGELOG.md
> +++ b/RECIPE-API-CHANGELOG.md
> @@ -566,3 +566,9 @@ supported, but a warning is issued when it is used. Future versions will drop
>  When building a custom kernel module, the `KBuild` file might be located in
>  a subdirectory. To support this use-case, set `MODULE_DIR=$(PWD)/subdir` in
>  the module build recipe.
> +
> +### Automatically disable cross for kmod builds against distro kernels
> +
> +Cross compiling kernel modules for distro kernels is not supported in debian.
> +To simplify downstream kernel module builds, we automatically turn of cross
> +compilation for a user-provided module when building it for a distro kernel.
> diff --git a/meta-isar/recipes-kernel/example-module/example-module.bb b/meta-isar/recipes-kernel/example-module/example-module.bb
> index 5ebed102..22f3cc47 100644
> --- a/meta-isar/recipes-kernel/example-module/example-module.bb
> +++ b/meta-isar/recipes-kernel/example-module/example-module.bb
> @@ -5,28 +5,6 @@
>  #
>  # SPDX-License-Identifier: MIT
>  
> -# Cross-compilation is not supported for the default Debian kernels.
> -# For example, package with kernel headers for ARM:
> -#   linux-headers-armmp
> -# has hard dependencies from linux-compiler-gcc-4.8-arm, what
> -# conflicts with the host binaries.
> -python() {
> -    if d.getVar('KERNEL_NAME') in [
> -        'armmp',
> -        'arm64',
> -        'rpi-rpfv',
> -        'amd64',
> -        '686-pae',
> -        '4kc-malta',
> -        'riscv64',
> -        'kernel',
> -        'kernel7',
> -        'kernel7l',
> -        'kernel8',
> -    ]:
> -        d.setVar('ISAR_CROSS_COMPILE', '0')
> -}
> -
>  require recipes-kernel/linux-module/module.inc
>  
>  SRC_URI += "file://src"
> diff --git a/meta/recipes-kernel/linux-module/module.inc b/meta/recipes-kernel/linux-module/module.inc
> index 269da6ae..eddbf177 100644
> --- a/meta/recipes-kernel/linux-module/module.inc
> +++ b/meta/recipes-kernel/linux-module/module.inc
> @@ -28,6 +28,16 @@ SRC_URI += "file://debian/"
>  
>  AUTOLOAD ?= ""
>  
> +# Cross-compilation is not supported for the default Debian kernels.
> +# For example, package with kernel headers for ARM:
> +#   linux-headers-armmp
> +# has hard dependencies from linux-compiler-gcc-4.8-arm, what
> +# conflicts with the host binaries.
> +python() {
> +    if d.getVar('KERNEL_NAME') in d.getVar('DISTRO_KERNELS').split():
> +        d.setVar('ISAR_CROSS_COMPILE', '0')
> +}
> +

What do we do if this changes one day, in trixie e.g? Or is even fixed
for bookworm?

Jan

>  inherit dpkg
>  
>  TEMPLATE_FILES = "debian/control.tmpl \
MOESSBAUER, Felix Jan. 18, 2024, 10:39 a.m. UTC | #2
On Thu, 2024-01-18 at 11:34 +0100, Jan Kiszka wrote:
> On 18.01.24 11:31, Felix Moessbauer wrote:
> > Cross compiling kernel modules for distro kernels is not supported
> > in debian.
> > To simplify downstream kernel module builds, we automatically turn
> > off cross
> > compilation for a user-provided module when building it for a
> > distro kernel.
> > 
> > This patch further replaces the hard-coded list of distro kernels
> > with
> > the DISTRO_KERNELS variable to avoid code duplication.
> > 
> > Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> > ---
> >  RECIPE-API-CHANGELOG.md                       |  6 +++++
> >  .../example-module/example-module.bb          | 22 ---------------
> > ----
> >  meta/recipes-kernel/linux-module/module.inc   | 10 +++++++++
> >  3 files changed, 16 insertions(+), 22 deletions(-)
> > 
> > diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
> > index bea12871..b1e5a5ab 100644
> > --- a/RECIPE-API-CHANGELOG.md
> > +++ b/RECIPE-API-CHANGELOG.md
> > @@ -566,3 +566,9 @@ supported, but a warning is issued when it is
> > used. Future versions will drop
> >  When building a custom kernel module, the `KBuild` file might be
> > located in
> >  a subdirectory. To support this use-case, set
> > `MODULE_DIR=$(PWD)/subdir` in
> >  the module build recipe.
> > +
> > +### Automatically disable cross for kmod builds against distro
> > kernels
> > +
> > +Cross compiling kernel modules for distro kernels is not supported
> > in debian.
> > +To simplify downstream kernel module builds, we automatically turn
> > of cross
> > +compilation for a user-provided module when building it for a
> > distro kernel.
> > diff --git a/meta-isar/recipes-kernel/example-module/example-
> > module.bb b/meta-isar/recipes-kernel/example-module/example-
> > module.bb
> > index 5ebed102..22f3cc47 100644
> > --- a/meta-isar/recipes-kernel/example-module/example-module.bb
> > +++ b/meta-isar/recipes-kernel/example-module/example-module.bb
> > @@ -5,28 +5,6 @@
> >  #
> >  # SPDX-License-Identifier: MIT
> >  
> > -# Cross-compilation is not supported for the default Debian
> > kernels.
> > -# For example, package with kernel headers for ARM:
> > -#   linux-headers-armmp
> > -# has hard dependencies from linux-compiler-gcc-4.8-arm, what
> > -# conflicts with the host binaries.
> > -python() {
> > -    if d.getVar('KERNEL_NAME') in [
> > -        'armmp',
> > -        'arm64',
> > -        'rpi-rpfv',
> > -        'amd64',
> > -        '686-pae',
> > -        '4kc-malta',
> > -        'riscv64',
> > -        'kernel',
> > -        'kernel7',
> > -        'kernel7l',
> > -        'kernel8',
> > -    ]:
> > -        d.setVar('ISAR_CROSS_COMPILE', '0')
> > -}
> > -
> >  require recipes-kernel/linux-module/module.inc
> >  
> >  SRC_URI += "file://src"
> > diff --git a/meta/recipes-kernel/linux-module/module.inc
> > b/meta/recipes-kernel/linux-module/module.inc
> > index 269da6ae..eddbf177 100644
> > --- a/meta/recipes-kernel/linux-module/module.inc
> > +++ b/meta/recipes-kernel/linux-module/module.inc
> > @@ -28,6 +28,16 @@ SRC_URI += "file://debian/"
> >  
> >  AUTOLOAD ?= ""
> >  
> > +# Cross-compilation is not supported for the default Debian
> > kernels.
> > +# For example, package with kernel headers for ARM:
> > +#   linux-headers-armmp
> > +# has hard dependencies from linux-compiler-gcc-4.8-arm, what
> > +# conflicts with the host binaries.
> > +python() {
> > +    if d.getVar('KERNEL_NAME') in
> > d.getVar('DISTRO_KERNELS').split():
> > +        d.setVar('ISAR_CROSS_COMPILE', '0')
> > +}
> > +
> 
> What do we do if this changes one day, in trixie e.g? Or is even
> fixed
> for bookworm?

We can simply add more logic to this python function. As of today, it
is broken for all debian versions. And in general it should not hurt
(except for performance) to emulate the compile.

Well... I know that currently modules for custom kernels MUST be cross
compiled as well if the custom kernel was cross compiled. But this is a
different story and Stefan is working on it.

Felix

> 
> Jan
> 
> >  inherit dpkg
> >  
> >  TEMPLATE_FILES = "debian/control.tmpl \
>
MOESSBAUER, Felix Feb. 1, 2024, 8:38 a.m. UTC | #3
Any news on this? I would consider this a bugfix.

Felix

On Thu, 2024-01-18 at 11:31 +0100, Felix Moessbauer wrote:
> Cross compiling kernel modules for distro kernels is not supported in
> debian.
> To simplify downstream kernel module builds, we automatically turn
> off cross
> compilation for a user-provided module when building it for a distro
> kernel.
> 
> This patch further replaces the hard-coded list of distro kernels
> with
> the DISTRO_KERNELS variable to avoid code duplication.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  RECIPE-API-CHANGELOG.md                       |  6 +++++
>  .../example-module/example-module.bb          | 22 -----------------
> --
>  meta/recipes-kernel/linux-module/module.inc   | 10 +++++++++
>  3 files changed, 16 insertions(+), 22 deletions(-)
> 
> diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
> index bea12871..b1e5a5ab 100644
> --- a/RECIPE-API-CHANGELOG.md
> +++ b/RECIPE-API-CHANGELOG.md
> @@ -566,3 +566,9 @@ supported, but a warning is issued when it is
> used. Future versions will drop
>  When building a custom kernel module, the `KBuild` file might be
> located in
>  a subdirectory. To support this use-case, set
> `MODULE_DIR=$(PWD)/subdir` in
>  the module build recipe.
> +
> +### Automatically disable cross for kmod builds against distro
> kernels
> +
> +Cross compiling kernel modules for distro kernels is not supported
> in debian.
> +To simplify downstream kernel module builds, we automatically turn
> of cross
> +compilation for a user-provided module when building it for a distro
> kernel.
> diff --git a/meta-isar/recipes-kernel/example-module/example-
> module.bb b/meta-isar/recipes-kernel/example-module/example-module.bb
> index 5ebed102..22f3cc47 100644
> --- a/meta-isar/recipes-kernel/example-module/example-module.bb
> +++ b/meta-isar/recipes-kernel/example-module/example-module.bb
> @@ -5,28 +5,6 @@
>  #
>  # SPDX-License-Identifier: MIT
>  
> -# Cross-compilation is not supported for the default Debian kernels.
> -# For example, package with kernel headers for ARM:
> -#   linux-headers-armmp
> -# has hard dependencies from linux-compiler-gcc-4.8-arm, what
> -# conflicts with the host binaries.
> -python() {
> -    if d.getVar('KERNEL_NAME') in [
> -        'armmp',
> -        'arm64',
> -        'rpi-rpfv',
> -        'amd64',
> -        '686-pae',
> -        '4kc-malta',
> -        'riscv64',
> -        'kernel',
> -        'kernel7',
> -        'kernel7l',
> -        'kernel8',
> -    ]:
> -        d.setVar('ISAR_CROSS_COMPILE', '0')
> -}
> -
>  require recipes-kernel/linux-module/module.inc
>  
>  SRC_URI += "file://src"
> diff --git a/meta/recipes-kernel/linux-module/module.inc
> b/meta/recipes-kernel/linux-module/module.inc
> index 269da6ae..eddbf177 100644
> --- a/meta/recipes-kernel/linux-module/module.inc
> +++ b/meta/recipes-kernel/linux-module/module.inc
> @@ -28,6 +28,16 @@ SRC_URI += "file://debian/"
>  
>  AUTOLOAD ?= ""
>  
> +# Cross-compilation is not supported for the default Debian kernels.
> +# For example, package with kernel headers for ARM:
> +#   linux-headers-armmp
> +# has hard dependencies from linux-compiler-gcc-4.8-arm, what
> +# conflicts with the host binaries.
> +python() {
> +    if d.getVar('KERNEL_NAME') in
> d.getVar('DISTRO_KERNELS').split():
> +        d.setVar('ISAR_CROSS_COMPILE', '0')
> +}
> +
>  inherit dpkg
>  
>  TEMPLATE_FILES = "debian/control.tmpl \
MOESSBAUER, Felix March 25, 2024, 2:22 p.m. UTC | #4
Hi,

asking again as the release is now done. Can we get that integrated, or
do I need rework something?

Felix

On Thu, 2024-02-01 at 08:38 +0000, 'MOESSBAUER, Felix' via isar-users
wrote:
> Any news on this? I would consider this a bugfix.
> 
> Felix
> 
> On Thu, 2024-01-18 at 11:31 +0100, Felix Moessbauer wrote:
> > Cross compiling kernel modules for distro kernels is not supported
> > in
> > debian.
> > To simplify downstream kernel module builds, we automatically turn
> > off cross
> > compilation for a user-provided module when building it for a
> > distro
> > kernel.
> > 
> > This patch further replaces the hard-coded list of distro kernels
> > with
> > the DISTRO_KERNELS variable to avoid code duplication.
> > 
> > Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> > ---
> >  RECIPE-API-CHANGELOG.md                       |  6 +++++
> >  .../example-module/example-module.bb          | 22 ---------------
> > --
> > --
> >  meta/recipes-kernel/linux-module/module.inc   | 10 +++++++++
> >  3 files changed, 16 insertions(+), 22 deletions(-)
> > 
> > diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
> > index bea12871..b1e5a5ab 100644
> > --- a/RECIPE-API-CHANGELOG.md
> > +++ b/RECIPE-API-CHANGELOG.md
> > @@ -566,3 +566,9 @@ supported, but a warning is issued when it is
> > used. Future versions will drop
> >  When building a custom kernel module, the `KBuild` file might be
> > located in
> >  a subdirectory. To support this use-case, set
> > `MODULE_DIR=$(PWD)/subdir` in
> >  the module build recipe.
> > +
> > +### Automatically disable cross for kmod builds against distro
> > kernels
> > +
> > +Cross compiling kernel modules for distro kernels is not supported
> > in debian.
> > +To simplify downstream kernel module builds, we automatically turn
> > of cross
> > +compilation for a user-provided module when building it for a
> > distro
> > kernel.
> > diff --git a/meta-isar/recipes-kernel/example-module/example-
> > module.bb b/meta-isar/recipes-kernel/example-module/example-
> > module.bb
> > index 5ebed102..22f3cc47 100644
> > --- a/meta-isar/recipes-kernel/example-module/example-module.bb
> > +++ b/meta-isar/recipes-kernel/example-module/example-module.bb
> > @@ -5,28 +5,6 @@
> >  #
> >  # SPDX-License-Identifier: MIT
> >  
> > -# Cross-compilation is not supported for the default Debian
> > kernels.
> > -# For example, package with kernel headers for ARM:
> > -#   linux-headers-armmp
> > -# has hard dependencies from linux-compiler-gcc-4.8-arm, what
> > -# conflicts with the host binaries.
> > -python() {
> > -    if d.getVar('KERNEL_NAME') in [
> > -        'armmp',
> > -        'arm64',
> > -        'rpi-rpfv',
> > -        'amd64',
> > -        '686-pae',
> > -        '4kc-malta',
> > -        'riscv64',
> > -        'kernel',
> > -        'kernel7',
> > -        'kernel7l',
> > -        'kernel8',
> > -    ]:
> > -        d.setVar('ISAR_CROSS_COMPILE', '0')
> > -}
> > -
> >  require recipes-kernel/linux-module/module.inc
> >  
> >  SRC_URI += "file://src"
> > diff --git a/meta/recipes-kernel/linux-module/module.inc
> > b/meta/recipes-kernel/linux-module/module.inc
> > index 269da6ae..eddbf177 100644
> > --- a/meta/recipes-kernel/linux-module/module.inc
> > +++ b/meta/recipes-kernel/linux-module/module.inc
> > @@ -28,6 +28,16 @@ SRC_URI += "file://debian/"
> >  
> >  AUTOLOAD ?= ""
> >  
> > +# Cross-compilation is not supported for the default Debian
> > kernels.
> > +# For example, package with kernel headers for ARM:
> > +#   linux-headers-armmp
> > +# has hard dependencies from linux-compiler-gcc-4.8-arm, what
> > +# conflicts with the host binaries.
> > +python() {
> > +    if d.getVar('KERNEL_NAME') in
> > d.getVar('DISTRO_KERNELS').split():
> > +        d.setVar('ISAR_CROSS_COMPILE', '0')
> > +}
> > +
> >  inherit dpkg
> >  
> >  TEMPLATE_FILES = "debian/control.tmpl \
> 
> -- 
> Siemens AG, Technology
> Linux Expert Center
> 
>
Uladzimir Bely March 28, 2024, 1:35 p.m. UTC | #5
On Thu, 2024-01-18 at 11:31 +0100, 'Felix Moessbauer' via isar-users
wrote:
> Cross compiling kernel modules for distro kernels is not supported in
> debian.
> To simplify downstream kernel module builds, we automatically turn
> off cross
> compilation for a user-provided module when building it for a distro
> kernel.
> 
> This patch further replaces the hard-coded list of distro kernels
> with
> the DISTRO_KERNELS variable to avoid code duplication.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  RECIPE-API-CHANGELOG.md                       |  6 +++++
>  .../example-module/example-module.bb          | 22 -----------------
> --
>  meta/recipes-kernel/linux-module/module.inc   | 10 +++++++++
>  3 files changed, 16 insertions(+), 22 deletions(-)
> 

Applied to next, thanks.

Patch

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index bea12871..b1e5a5ab 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -566,3 +566,9 @@  supported, but a warning is issued when it is used. Future versions will drop
 When building a custom kernel module, the `KBuild` file might be located in
 a subdirectory. To support this use-case, set `MODULE_DIR=$(PWD)/subdir` in
 the module build recipe.
+
+### Automatically disable cross for kmod builds against distro kernels
+
+Cross compiling kernel modules for distro kernels is not supported in debian.
+To simplify downstream kernel module builds, we automatically turn of cross
+compilation for a user-provided module when building it for a distro kernel.
diff --git a/meta-isar/recipes-kernel/example-module/example-module.bb b/meta-isar/recipes-kernel/example-module/example-module.bb
index 5ebed102..22f3cc47 100644
--- a/meta-isar/recipes-kernel/example-module/example-module.bb
+++ b/meta-isar/recipes-kernel/example-module/example-module.bb
@@ -5,28 +5,6 @@ 
 #
 # SPDX-License-Identifier: MIT
 
-# Cross-compilation is not supported for the default Debian kernels.
-# For example, package with kernel headers for ARM:
-#   linux-headers-armmp
-# has hard dependencies from linux-compiler-gcc-4.8-arm, what
-# conflicts with the host binaries.
-python() {
-    if d.getVar('KERNEL_NAME') in [
-        'armmp',
-        'arm64',
-        'rpi-rpfv',
-        'amd64',
-        '686-pae',
-        '4kc-malta',
-        'riscv64',
-        'kernel',
-        'kernel7',
-        'kernel7l',
-        'kernel8',
-    ]:
-        d.setVar('ISAR_CROSS_COMPILE', '0')
-}
-
 require recipes-kernel/linux-module/module.inc
 
 SRC_URI += "file://src"
diff --git a/meta/recipes-kernel/linux-module/module.inc b/meta/recipes-kernel/linux-module/module.inc
index 269da6ae..eddbf177 100644
--- a/meta/recipes-kernel/linux-module/module.inc
+++ b/meta/recipes-kernel/linux-module/module.inc
@@ -28,6 +28,16 @@  SRC_URI += "file://debian/"
 
 AUTOLOAD ?= ""
 
+# Cross-compilation is not supported for the default Debian kernels.
+# For example, package with kernel headers for ARM:
+#   linux-headers-armmp
+# has hard dependencies from linux-compiler-gcc-4.8-arm, what
+# conflicts with the host binaries.
+python() {
+    if d.getVar('KERNEL_NAME') in d.getVar('DISTRO_KERNELS').split():
+        d.setVar('ISAR_CROSS_COMPILE', '0')
+}
+
 inherit dpkg
 
 TEMPLATE_FILES = "debian/control.tmpl \