diff --git a/Cargo.lock b/Cargo.lock index 3fb3ba7ae..75c260c50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,7 +118,6 @@ dependencies = [ "kmod", "kmod-5_10-nvidia", "kmod-5_15-nvidia", - "kmod-6_1-neuron", "kmod-6_1-nvidia", "kubernetes-1_24", "kubernetes-1_25", @@ -482,13 +481,6 @@ dependencies = [ "kernel-5_15", ] -[[package]] -name = "kmod-6_1-neuron" -version = "0.1.0" -dependencies = [ - "kernel-6_1", -] - [[package]] name = "kmod-6_1-nvidia" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 1e26fe5ba..aa2cb4255 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,6 @@ members = [ "packages/kmod", "packages/kmod-5.10-nvidia", "packages/kmod-5.15-nvidia", - "packages/kmod-6.1-neuron", "packages/kmod-6.1-nvidia", "packages/kubernetes-1.24", "packages/kubernetes-1.25", diff --git a/kits/bottlerocket-core-kit/Cargo.toml b/kits/bottlerocket-core-kit/Cargo.toml index 0372e0d52..ead068446 100644 --- a/kits/bottlerocket-core-kit/Cargo.toml +++ b/kits/bottlerocket-core-kit/Cargo.toml @@ -58,7 +58,6 @@ keyutils = { path = "../../packages/keyutils" } kmod-5_10-nvidia = { path = "../../packages/kmod-5.10-nvidia" } kmod-5_15-nvidia = { path = "../../packages/kmod-5.15-nvidia" } kmod-6_1-nvidia = { path = "../../packages/kmod-6.1-nvidia" } -kmod-6_1-neuron = { path = "../../packages/kmod-6.1-neuron" } kmod = { path = "../../packages/kmod" } kubernetes-1_24 = { path = "../../packages/kubernetes-1.24" } kubernetes-1_25 = { path = "../../packages/kubernetes-1.25" } diff --git a/packages/kmod-6.1-neuron/.gitignore b/packages/kernel-5.10/.gitignore similarity index 100% rename from packages/kmod-6.1-neuron/.gitignore rename to packages/kernel-5.10/.gitignore diff --git a/packages/kernel-5.10/Cargo.toml b/packages/kernel-5.10/Cargo.toml index ebf20edac..7b617906a 100644 --- a/packages/kernel-5.10/Cargo.toml +++ b/packages/kernel-5.10/Cargo.toml @@ -12,9 +12,14 @@ package-name = "kernel-5.10" path = "../packages.rs" [[package.metadata.build-package.external-files]] -# Use latest-srpm-url.sh to get this. +# Use latest-kernel-srpm-url.sh to get this. url = "https://cdn.amazonlinux.com/blobstore/a9b5c6b9ca0d2a84e4dc3b963a73017a055d602139d2293ff394d33b08111be7/kernel-5.10.227-219.884.amzn2.src.rpm" sha512 = "6729b3ef34c451685d29b736a1a98a6487d158707f503ae35cb0427daf034a442d8768e3cc0db3781bb4b17f316fd53811a211892be52c7f8d2feadf7773611c" +[[package.metadata.build-package.external-files]] +# Use latest-neuron-srpm-url.sh to get this. +url = "https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm" +sha512 = "4ed92e661d0ba368eaf8f60e1a68c202062a26819231fcfd42a5ff05d20ad2f34b82b23359a88e80eea22ee5d0056ad769b6febd5d7e7b161da0e36434ba2579" + [build-dependencies] microcode = { path = "../microcode" } diff --git a/packages/kernel-5.10/kernel-5.10.spec b/packages/kernel-5.10/kernel-5.10.spec index de63d5723..e613c55e6 100644 --- a/packages/kernel-5.10/kernel-5.10.spec +++ b/packages/kernel-5.10/kernel-5.10.spec @@ -6,10 +6,16 @@ Release: 1%{?dist} Summary: The Linux kernel License: GPL-2.0 WITH Linux-syscall-note URL: https://www.kernel.org/ -# Use latest-srpm-url.sh to get this. +# Use latest-kernel-srpm-url.sh to get this. Source0: https://cdn.amazonlinux.com/blobstore/a9b5c6b9ca0d2a84e4dc3b963a73017a055d602139d2293ff394d33b08111be7/kernel-5.10.227-219.884.amzn2.src.rpm +# Use latest-neuron-srpm-url.sh to get this. +Source1: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm Source100: config-bottlerocket +# Neuron-related drop-ins. +Source220: neuron-sysinit.target.drop-in.conf +Source221: modprobe@neuron.service.drop-in.conf + # Help out-of-tree module builds run `make prepare` automatically. Patch1001: 1001-Makefile-add-prepare-target-for-external-modules.patch # Enable INITRAMFS_FORCE config option for our use case. @@ -42,6 +48,11 @@ Requires: %{_cross_os}microcode-licenses Requires: %{name}-modules = %{version}-%{release} Requires: %{name}-devel = %{version}-%{release} +# Pull in platform-dependent modules. +%if "%{_cross_arch}" == "x86_64" +Requires: (%{name}-modules-neuron if (%{_cross_os}variant-platform(aws) without %{_cross_os}variant-flavor(nvidia))) +%endif + # The 5.10 kernel is not FIPS certified. Conflicts: %{_cross_os}image-feature(fips) @@ -72,6 +83,18 @@ Summary: Modules for the Linux kernel %description modules %{summary}. +%if "%{_cross_arch}" == "x86_64" +%package modules-neuron +Summary: Modules for the Linux kernel with Neuron hardware +Requires: %{name} +Requires: %{_cross_os}ghostdog +Requires: %{_cross_os}variant-platform(aws) +Conflicts: %{_cross_os}variant-flavor(nvidia) + +%description modules-neuron +%{summary}. +%endif + %package headers Summary: Header files for the Linux kernel for use by glibc @@ -110,6 +133,13 @@ scripts/kconfig/merge_config.sh \ rm -f ../config-* ../*.patch +%if "%{_cross_arch}" == "x86_64" +cd %{_builddir} +rpm2cpio %{SOURCE1} | cpio -idmu './usr/src/aws-neuronx-*' +find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron \; +rm -r usr +%endif + %global kmake \ make -s\\\ ARCH="%{_cross_karch}"\\\ @@ -125,10 +155,22 @@ make -s\\\ %kmake %{?_smp_mflags} %{_cross_kimage} %kmake %{?_smp_mflags} modules +%if "%{_cross_arch}" == "x86_64" +%kmake %{?_smp_mflags} M=%{_builddir}/neuron +%endif + %install %kmake %{?_smp_mflags} headers_install %kmake %{?_smp_mflags} modules_install +%if "%{_cross_arch}" == "x86_64" +%kmake %{?_smp_mflags} M=%{_builddir}/neuron modules_install V=1 +mv \ + %{buildroot}%{kernel_libdir}/extra/%{_builddir}/neuron/neuron.ko* \ + %{buildroot}%{kernel_libdir}/extra +rm -rf %{buildroot}%{kernel_libdir}/extra/%{_builddir} +%endif + install -d %{buildroot}/boot install -T -m 0755 arch/%{_cross_karch}/boot/%{_cross_kimage} %{buildroot}/boot/vmlinuz install -m 0644 .config %{buildroot}/boot/config @@ -237,6 +279,18 @@ rm -f %{buildroot}%{kernel_libdir}/build %{buildroot}%{kernel_libdir}/source ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/build ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source +# Install a copy of System.map so that module dependencies can be regenerated. +install -p -m 0600 System.map %{buildroot}%{kernel_libdir} + +%if "%{_cross_arch}" == "x86_64" +# Add Neuron-related drop-ins to load the module when the hardware is present. +mkdir -p %{buildroot}%{_cross_unitdir}/sysinit.target.d +install -p -m 0644 %{S:220} %{buildroot}%{_cross_unitdir}/sysinit.target.d/neuron.conf + +mkdir -p %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d +install -p -m 0644 %{S:221} %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf +%endif + %files %license COPYING LICENSES/preferred/GPL-2.0 LICENSES/exceptions/Linux-syscall-note %{_cross_attribution_file} @@ -246,6 +300,14 @@ ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source %files modules %dir %{_cross_libdir}/modules %{_cross_libdir}/modules/* +%exclude %{kernel_libdir}/extra/neuron.ko.gz + +%if "%{_cross_arch}" == "x86_64" +%files modules-neuron +%{kernel_libdir}/extra/neuron.ko.gz +%{_cross_unitdir}/sysinit.target.d/neuron.conf +%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf +%endif %files headers %dir %{_cross_includedir}/asm diff --git a/packages/kernel-5.10/latest-srpm-url.sh b/packages/kernel-5.10/latest-kernel-srpm-url.sh similarity index 100% rename from packages/kernel-5.10/latest-srpm-url.sh rename to packages/kernel-5.10/latest-kernel-srpm-url.sh diff --git a/packages/kmod-6.1-neuron/latest-srpm-url.sh b/packages/kernel-5.10/latest-neuron-srpm-url.sh similarity index 100% rename from packages/kmod-6.1-neuron/latest-srpm-url.sh rename to packages/kernel-5.10/latest-neuron-srpm-url.sh diff --git a/packages/kernel-5.10/modprobe@neuron.service.drop-in.conf b/packages/kernel-5.10/modprobe@neuron.service.drop-in.conf new file mode 100644 index 000000000..e9174355e --- /dev/null +++ b/packages/kernel-5.10/modprobe@neuron.service.drop-in.conf @@ -0,0 +1,7 @@ +[Unit] +ConditionPathExists=!/etc/.neuron-modprobe-done + +[Service] +ExecCondition=/usr/bin/touch /etc/.neuron-modprobe-done +ExecCondition=/usr/bin/ghostdog neuron-present +RemainAfterExit=true diff --git a/packages/kernel-5.10/neuron-sysinit.target.drop-in.conf b/packages/kernel-5.10/neuron-sysinit.target.drop-in.conf new file mode 100644 index 000000000..11c782345 --- /dev/null +++ b/packages/kernel-5.10/neuron-sysinit.target.drop-in.conf @@ -0,0 +1,2 @@ +[Unit] +Wants=modprobe@neuron.service diff --git a/packages/kernel-5.15/.gitignore b/packages/kernel-5.15/.gitignore new file mode 100644 index 000000000..e7a9c1347 --- /dev/null +++ b/packages/kernel-5.15/.gitignore @@ -0,0 +1 @@ +*.rpm diff --git a/packages/kernel-5.15/Cargo.toml b/packages/kernel-5.15/Cargo.toml index bcedef8d9..386865d13 100644 --- a/packages/kernel-5.15/Cargo.toml +++ b/packages/kernel-5.15/Cargo.toml @@ -12,9 +12,14 @@ package-name = "kernel-5.15" path = "../packages.rs" [[package.metadata.build-package.external-files]] -# Use latest-srpm-url.sh to get this. +# Use latest-kernel-srpm-url.sh to get this. url = "https://cdn.amazonlinux.com/blobstore/9cea3dae03703f3c4c78fcb1302eeee5fe4c07ebf53d783cf3aaf7e4f30a6d39/kernel-5.15.168-114.166.amzn2.src.rpm" sha512 = "5b0b0e2640bb04d4868b8820781029d8148c7939802c1b4edcf580533848afe70f7c6372e6e2306dfc017d2b32120a446ada15b105f7b2fe766b9382f83937d3" +[[package.metadata.build-package.external-files]] +# Use latest-neuron-srpm-url.sh to get this. +url = "https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm" +sha512 = "4ed92e661d0ba368eaf8f60e1a68c202062a26819231fcfd42a5ff05d20ad2f34b82b23359a88e80eea22ee5d0056ad769b6febd5d7e7b161da0e36434ba2579" + [build-dependencies] microcode = { path = "../microcode" } diff --git a/packages/kernel-5.15/kernel-5.15.spec b/packages/kernel-5.15/kernel-5.15.spec index d15c59323..2abe2e805 100644 --- a/packages/kernel-5.15/kernel-5.15.spec +++ b/packages/kernel-5.15/kernel-5.15.spec @@ -6,10 +6,16 @@ Release: 1%{?dist} Summary: The Linux kernel License: GPL-2.0 WITH Linux-syscall-note URL: https://www.kernel.org/ -# Use latest-srpm-url.sh to get this. +# Use latest-kernel-srpm-url.sh to get this. Source0: https://cdn.amazonlinux.com/blobstore/9cea3dae03703f3c4c78fcb1302eeee5fe4c07ebf53d783cf3aaf7e4f30a6d39/kernel-5.15.168-114.166.amzn2.src.rpm +# Use latest-neuron-srpm-url.sh to get this. +Source1: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm Source100: config-bottlerocket +# Neuron-related drop-ins. +Source220: neuron-sysinit.target.drop-in.conf +Source221: modprobe@neuron.service.drop-in.conf + # Help out-of-tree module builds run `make prepare` automatically. Patch1001: 1001-Makefile-add-prepare-target-for-external-modules.patch # Expose tools/* targets for out-of-tree module builds. @@ -37,6 +43,11 @@ Requires: %{_cross_os}microcode-licenses Requires: %{name}-modules = %{version}-%{release} Requires: %{name}-devel = %{version}-%{release} +# Pull in platform-dependent modules. +%if "%{_cross_arch}" == "x86_64" +Requires: (%{name}-modules-neuron if (%{_cross_os}variant-platform(aws) without %{_cross_os}variant-flavor(nvidia))) +%endif + # The 5.15 kernel is not FIPS certified. Conflicts: %{_cross_os}image-feature(fips) @@ -67,6 +78,18 @@ Summary: Modules for the Linux kernel %description modules %{summary}. +%if "%{_cross_arch}" == "x86_64" +%package modules-neuron +Summary: Modules for the Linux kernel with Neuron hardware +Requires: %{name} +Requires: %{_cross_os}ghostdog +Requires: %{_cross_os}variant-platform(aws) +Conflicts: %{_cross_os}variant-flavor(nvidia) + +%description modules-neuron +%{summary}. +%endif + %package headers Summary: Header files for the Linux kernel for use by glibc @@ -105,6 +128,13 @@ scripts/kconfig/merge_config.sh \ rm -f ../config-* ../*.patch +%if "%{_cross_arch}" == "x86_64" +cd %{_builddir} +rpm2cpio %{SOURCE1} | cpio -idmu './usr/src/aws-neuronx-*' +find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron \; +rm -r usr +%endif + %global kmake \ make -s\\\ ARCH="%{_cross_karch}"\\\ @@ -120,10 +150,18 @@ make -s\\\ %kmake %{?_smp_mflags} %{_cross_kimage} %kmake %{?_smp_mflags} modules +%if "%{_cross_arch}" == "x86_64" +%kmake %{?_smp_mflags} M=%{_builddir}/neuron +%endif + %install %kmake %{?_smp_mflags} headers_install %kmake %{?_smp_mflags} modules_install +%if "%{_cross_arch}" == "x86_64" +%kmake %{?_smp_mflags} M=%{_builddir}/neuron modules_install +%endif + install -d %{buildroot}/boot install -T -m 0755 arch/%{_cross_karch}/boot/%{_cross_kimage} %{buildroot}/boot/vmlinuz install -m 0644 .config %{buildroot}/boot/config @@ -232,6 +270,18 @@ rm -f %{buildroot}%{kernel_libdir}/build %{buildroot}%{kernel_libdir}/source ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/build ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source +# Install a copy of System.map so that module dependencies can be regenerated. +install -p -m 0600 System.map %{buildroot}%{kernel_libdir} + +%if "%{_cross_arch}" == "x86_64" +# Add Neuron-related drop-ins to load the module when the hardware is present. +mkdir -p %{buildroot}%{_cross_unitdir}/sysinit.target.d +install -p -m 0644 %{S:220} %{buildroot}%{_cross_unitdir}/sysinit.target.d/neuron.conf + +mkdir -p %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d +install -p -m 0644 %{S:221} %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf +%endif + %files %license COPYING LICENSES/preferred/GPL-2.0 LICENSES/exceptions/Linux-syscall-note %{_cross_attribution_file} @@ -241,6 +291,14 @@ ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source %files modules %dir %{_cross_libdir}/modules %{_cross_libdir}/modules/* +%exclude %{kernel_libdir}/extra/neuron.ko.gz + +%if "%{_cross_arch}" == "x86_64" +%files modules-neuron +%{kernel_libdir}/extra/neuron.ko.gz +%{_cross_unitdir}/sysinit.target.d/neuron.conf +%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf +%endif %files headers %dir %{_cross_includedir}/asm diff --git a/packages/kernel-5.15/latest-srpm-url.sh b/packages/kernel-5.15/latest-kernel-srpm-url.sh similarity index 100% rename from packages/kernel-5.15/latest-srpm-url.sh rename to packages/kernel-5.15/latest-kernel-srpm-url.sh diff --git a/packages/kernel-5.15/latest-neuron-srpm-url.sh b/packages/kernel-5.15/latest-neuron-srpm-url.sh new file mode 100755 index 000000000..5bb6c85ec --- /dev/null +++ b/packages/kernel-5.15/latest-neuron-srpm-url.sh @@ -0,0 +1,9 @@ +#!/bin/sh +cmd=" +dnf install -q -y --releasever=latest yum-utils && +dnf download -q --repofrompath neuron,https://yum.repos.neuron.amazonaws.com --repo=neuron --urls aws-neuronx-dkms +" +docker run --rm amazonlinux:2023 bash -c "${cmd}" \ + | grep '^http' \ + | xargs --max-args=1 --no-run-if-empty realpath --canonicalize-missing --relative-to=. \ + | sed 's_:/_://_' diff --git a/packages/kernel-5.15/modprobe@neuron.service.drop-in.conf b/packages/kernel-5.15/modprobe@neuron.service.drop-in.conf new file mode 100644 index 000000000..e9174355e --- /dev/null +++ b/packages/kernel-5.15/modprobe@neuron.service.drop-in.conf @@ -0,0 +1,7 @@ +[Unit] +ConditionPathExists=!/etc/.neuron-modprobe-done + +[Service] +ExecCondition=/usr/bin/touch /etc/.neuron-modprobe-done +ExecCondition=/usr/bin/ghostdog neuron-present +RemainAfterExit=true diff --git a/packages/kernel-5.15/neuron-sysinit.target.drop-in.conf b/packages/kernel-5.15/neuron-sysinit.target.drop-in.conf new file mode 100644 index 000000000..11c782345 --- /dev/null +++ b/packages/kernel-5.15/neuron-sysinit.target.drop-in.conf @@ -0,0 +1,2 @@ +[Unit] +Wants=modprobe@neuron.service diff --git a/packages/kernel-6.1/.gitignore b/packages/kernel-6.1/.gitignore new file mode 100644 index 000000000..e7a9c1347 --- /dev/null +++ b/packages/kernel-6.1/.gitignore @@ -0,0 +1 @@ +*.rpm diff --git a/packages/kernel-6.1/Cargo.toml b/packages/kernel-6.1/Cargo.toml index 28a1943d9..baf1944b4 100644 --- a/packages/kernel-6.1/Cargo.toml +++ b/packages/kernel-6.1/Cargo.toml @@ -12,9 +12,14 @@ package-name = "kernel-6.1" path = "../packages.rs" [[package.metadata.build-package.external-files]] -# Use latest-srpm-url.sh to get this. +# Use latest-kernel-srpm-url.sh to get this. url = "https://cdn.amazonlinux.com/al2023/blobstore/3b0aa0d6cf05ca272d9802ccddfc28201675b2abac6abb307f5c4b8d3ca68d26/kernel-6.1.112-124.190.amzn2023.src.rpm" sha512 = "f7c78716a78d453a0eaaae45f6aaf00a466d7b65e7def0c887f5ff267726b668f725b8a359770a93dbee477313cf297fa6b641580c073aa76dcefda39c19f5c2" +[[package.metadata.build-package.external-files]] +# Use latest-neuron-srpm-url.sh to get this. +url = "https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm" +sha512 = "4ed92e661d0ba368eaf8f60e1a68c202062a26819231fcfd42a5ff05d20ad2f34b82b23359a88e80eea22ee5d0056ad769b6febd5d7e7b161da0e36434ba2579" + [build-dependencies] microcode = { path = "../microcode" } diff --git a/packages/kernel-6.1/kernel-6.1.spec b/packages/kernel-6.1/kernel-6.1.spec index 9084c6804..ea7f8fc95 100644 --- a/packages/kernel-6.1/kernel-6.1.spec +++ b/packages/kernel-6.1/kernel-6.1.spec @@ -6,8 +6,11 @@ Release: 1%{?dist} Summary: The Linux kernel License: GPL-2.0 WITH Linux-syscall-note URL: https://www.kernel.org/ -# Use latest-srpm-url.sh to get this. +# Use latest-kernel-srpm-url.sh to get this. Source0: https://cdn.amazonlinux.com/al2023/blobstore/3b0aa0d6cf05ca272d9802ccddfc28201675b2abac6abb307f5c4b8d3ca68d26/kernel-6.1.112-124.190.amzn2023.src.rpm +# Use latest-neuron-srpm-url.sh to get this. +Source1: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm + Source100: config-bottlerocket # This list of FIPS modules is extracted from /etc/fipsmodules in the initramfs @@ -19,6 +22,10 @@ Source202: fipsmodules-aarch64 # Adjust kernel-devel mount behavior if not squashfs. Source210: var-lib-kernel-devel-lower.mount.drop-in.conf.in +# Neuron-related drop-ins. +Source220: neuron-sysinit.target.drop-in.conf +Source221: modprobe@neuron.service.drop-in.conf + # Bootconfig snippets to adjust the default kernel command line for the platform. Source300: bootconfig-aws.conf Source301: bootconfig-vmware.conf @@ -64,6 +71,9 @@ Requires: (%{name}-bootconfig-metal if %{_cross_os}variant-platform(vmware)) # Pull in platform-dependent modules. Requires: (%{name}-modules-metal if %{_cross_os}variant-platform(metal)) +%if "%{_cross_arch}" == "x86_64" +Requires: (%{name}-modules-neuron if (%{_cross_os}variant-platform(aws) without %{_cross_os}variant-flavor(nvidia))) +%endif # Pull in FIPS-related files if needed. Requires: (%{name}-fips if %{_cross_os}image-feature(fips)) @@ -129,6 +139,22 @@ Summary: Modules for the Linux kernel on bare metal %description modules-metal %{summary}. +%if "%{_cross_arch}" == "x86_64" +%package modules-neuron +Summary: Modules for the Linux kernel with Neuron hardware +Requires: %{name} +Requires: %{_cross_os}ghostdog +Requires: %{_cross_os}variant-platform(aws) +Conflicts: %{_cross_os}variant-flavor(nvidia) + +# Previously the neuron kmod was in a separate package, so provide that +# name for backwards compatibility. +Provides: %{_cross_os}kmod-6.1-neuron + +%description modules-neuron +%{summary}. +%endif + %package headers Summary: Header files for the Linux kernel for use by glibc @@ -175,6 +201,13 @@ scripts/kconfig/merge_config.sh \ rm -f ../config-* ../*.patch +%if "%{_cross_arch}" == "x86_64" +cd %{_builddir} +rpm2cpio %{SOURCE1} | cpio -idmu './usr/src/aws-neuronx-*' +find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron \; +rm -r usr +%endif + %global kmake \ make -s\\\ ARCH="%{_cross_karch}"\\\ @@ -190,10 +223,18 @@ make -s\\\ %kmake %{?_smp_mflags} %{_cross_kimage} %kmake %{?_smp_mflags} modules +%if "%{_cross_arch}" == "x86_64" +%kmake %{?_smp_mflags} M=%{_builddir}/neuron +%endif + %install %kmake %{?_smp_mflags} headers_install %kmake %{?_smp_mflags} modules_install +%if "%{_cross_arch}" == "x86_64" +%kmake %{?_smp_mflags} M=%{_builddir}/neuron modules_install +%endif + install -d %{buildroot}/boot install -T -m 0755 arch/%{_cross_karch}/boot/%{_cross_kimage} %{buildroot}/boot/vmlinuz install -m 0644 .config %{buildroot}/boot/config @@ -328,6 +369,15 @@ mkdir -p %{buildroot}%{_cross_unitdir}/"${LOWERPATH}.mount.d" sed -e 's|PREFIX|%{_cross_prefix}|g' %{S:210} \ > %{buildroot}%{_cross_unitdir}/"${LOWERPATH}.mount.d"/no-squashfs.conf +%if "%{_cross_arch}" == "x86_64" +# Add Neuron-related drop-ins to load the module when the hardware is present. +mkdir -p %{buildroot}%{_cross_unitdir}/sysinit.target.d +install -p -m 0644 %{S:220} %{buildroot}%{_cross_unitdir}/sysinit.target.d/neuron.conf + +mkdir -p %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d +install -p -m 0644 %{S:221} %{buildroot}%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf +%endif + # Install platform-specific bootconfig snippets. install -d %{buildroot}%{_cross_bootconfigdir} install -p -m 0644 %{S:300} %{buildroot}%{_cross_bootconfigdir}/05-aws.conf @@ -1376,4 +1426,11 @@ install -p -m 0644 %{S:302} %{buildroot}%{_cross_bootconfigdir}/05-metal.conf %{_cross_kmoddir}/kernel/drivers/net/mdio.ko.gz %{_cross_kmoddir}/kernel/drivers/scsi/snic/snic.ko.gz +%if "%{_cross_arch}" == "x86_64" +%files modules-neuron +%{_cross_kmoddir}/extra/neuron.ko.gz +%{_cross_unitdir}/sysinit.target.d/neuron.conf +%{_cross_unitdir}/modprobe@neuron.service.d/neuron.conf +%endif + %changelog diff --git a/packages/kernel-6.1/latest-srpm-url.sh b/packages/kernel-6.1/latest-kernel-srpm-url.sh similarity index 100% rename from packages/kernel-6.1/latest-srpm-url.sh rename to packages/kernel-6.1/latest-kernel-srpm-url.sh diff --git a/packages/kernel-6.1/latest-neuron-srpm-url.sh b/packages/kernel-6.1/latest-neuron-srpm-url.sh new file mode 100755 index 000000000..5bb6c85ec --- /dev/null +++ b/packages/kernel-6.1/latest-neuron-srpm-url.sh @@ -0,0 +1,9 @@ +#!/bin/sh +cmd=" +dnf install -q -y --releasever=latest yum-utils && +dnf download -q --repofrompath neuron,https://yum.repos.neuron.amazonaws.com --repo=neuron --urls aws-neuronx-dkms +" +docker run --rm amazonlinux:2023 bash -c "${cmd}" \ + | grep '^http' \ + | xargs --max-args=1 --no-run-if-empty realpath --canonicalize-missing --relative-to=. \ + | sed 's_:/_://_' diff --git a/packages/kernel-6.1/modprobe@neuron.service.drop-in.conf b/packages/kernel-6.1/modprobe@neuron.service.drop-in.conf new file mode 100644 index 000000000..e9174355e --- /dev/null +++ b/packages/kernel-6.1/modprobe@neuron.service.drop-in.conf @@ -0,0 +1,7 @@ +[Unit] +ConditionPathExists=!/etc/.neuron-modprobe-done + +[Service] +ExecCondition=/usr/bin/touch /etc/.neuron-modprobe-done +ExecCondition=/usr/bin/ghostdog neuron-present +RemainAfterExit=true diff --git a/packages/kernel-6.1/neuron-sysinit.target.drop-in.conf b/packages/kernel-6.1/neuron-sysinit.target.drop-in.conf new file mode 100644 index 000000000..11c782345 --- /dev/null +++ b/packages/kernel-6.1/neuron-sysinit.target.drop-in.conf @@ -0,0 +1,2 @@ +[Unit] +Wants=modprobe@neuron.service diff --git a/packages/kmod-6.1-neuron/0001-kbuild-do-not-outline-atomics-for-arm64.patch b/packages/kmod-6.1-neuron/0001-kbuild-do-not-outline-atomics-for-arm64.patch deleted file mode 100644 index c52edefb9..000000000 --- a/packages/kmod-6.1-neuron/0001-kbuild-do-not-outline-atomics-for-arm64.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 5c77e9c0db55dd35f162ec41fa5a62856121f5da Mon Sep 17 00:00:00 2001 -From: Ben Cressey -Date: Fri, 28 Jun 2024 02:06:55 +0000 -Subject: [PATCH] kbuild: do not outline atomics for arm64 - -Signed-off-by: Ben Cressey ---- - usr/src/aws-neuronx-2.18.12.0/Kbuild | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/usr/src/aws-neuronx-2.18.12.0/Kbuild b/usr/src/aws-neuronx-2.18.12.0/Kbuild -index 11f8490..6535608 100644 ---- a/usr/src/aws-neuronx-2.18.12.0/Kbuild -+++ b/usr/src/aws-neuronx-2.18.12.0/Kbuild -@@ -16,3 +16,4 @@ neuron-objs += v3/notific.o v3/neuron_dhal_v3.o - - ccflags-y += -O3 -Wall -Werror -Wno-declaration-after-statement -Wunused-macros -Wunused-local-typedefs - ccflags-y += -I$(src)/ -+ccflags-$(CONFIG_ARM64) += -mno-outline-atomics --- -2.45.1 - diff --git a/packages/kmod-6.1-neuron/Cargo.toml b/packages/kmod-6.1-neuron/Cargo.toml deleted file mode 100644 index 63cb6b0b3..000000000 --- a/packages/kmod-6.1-neuron/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "kmod-6_1-neuron" -version = "0.1.0" -edition = "2021" -publish = false -build = "../build.rs" - -[lib] -path = "../packages.rs" - -[package.metadata.build-package] -package-name = "kmod-6.1-neuron" -releases-url = "https://awsdocs-neuron.readthedocs-hosted.com/en/latest/release-notes/runtime/aws-neuronx-dkms/index.html" - -[[package.metadata.build-package.external-files]] -url = "https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.18.12.0.noarch.rpm" -sha512 = "4ed92e661d0ba368eaf8f60e1a68c202062a26819231fcfd42a5ff05d20ad2f34b82b23359a88e80eea22ee5d0056ad769b6febd5d7e7b161da0e36434ba2579" - -[build-dependencies] -kernel-6_1 = { path = "../kernel-6.1" } diff --git a/packages/kmod-6.1-neuron/kmod-6.1-neuron.spec b/packages/kmod-6.1-neuron/kmod-6.1-neuron.spec deleted file mode 100644 index ab1a72932..000000000 --- a/packages/kmod-6.1-neuron/kmod-6.1-neuron.spec +++ /dev/null @@ -1,77 +0,0 @@ -Name: %{_cross_os}kmod-6.1-neuron -Version: 2.18.12.0 -Release: 1%{?dist} -Epoch: 1 -Summary: Neuron drivers for the 6.1 kernel -License: GPL-2.0-only -URL: https://awsdocs-neuron.readthedocs-hosted.com/en/latest/ - -Source0: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-%{version}.noarch.rpm -Source1: neuron-modules-load.conf -Source2: neuron-systemd-modules-load.drop-in.conf -Patch0001: 0001-kbuild-do-not-outline-atomics-for-arm64.patch - -BuildRequires: %{_cross_os}kernel-6.1-archive - -%description -%{summary}. - -%package devel -Summary: Files for development using the Neuron drivers -Requires: %{name} - -%description devel -%{summary}. - -%prep -rpm2cpio %{SOURCE0} | cpio -idmv -tar -xf %{_cross_datadir}/bottlerocket/kernel-devel.tar.xz -%autopatch -p1 - -%global neuron_sources usr/src/aws-neuronx-%{version} -%global kernel_sources %{_builddir}/kernel-devel - -%build -pushd %{_builddir}/%{neuron_sources} -%make_build \ - -C %{kernel_sources} \ - M=${PWD} \ - ARCH=%{_cross_karch} \ - CROSS_COMPILE=%{_cross_target}- \ - INSTALL_MOD_STRIP=1 \ - %{nil} -gzip -9 neuron.ko -popd - -%install -pushd %{_builddir}/%{neuron_sources} -export KVER="$(cat %{kernel_sources}/include/config/kernel.release)" -export KMODDIR="%{_cross_libdir}/modules/${KVER}/extra" -install -d "%{buildroot}${KMODDIR}" -install -p -m 0644 neuron.ko.gz "%{buildroot}${KMODDIR}" -popd - -# Install modules-load.d drop-in to autoload required kernel modules -install -d %{buildroot}%{_cross_libdir}/modules-load.d -install -p -m 0644 %{S:1} %{buildroot}%{_cross_libdir}/modules-load.d/neuron.conf - -# Install systemd-modules-load drop-in to ensure that depmod runs. -install -d %{buildroot}%{_cross_unitdir}/systemd-modules-load.service.d -install -p -m 0644 %{S:2} %{buildroot}%{_cross_unitdir}/systemd-modules-load.service.d/neuron.conf - -# Install the shared header file -install -d %{buildroot}%{_cross_includedir}/share -install -p -m 0644 %{_builddir}/%{neuron_sources}/share/neuron_driver_shared.h %{buildroot}/%{_cross_includedir}/share/neuron_driver_shared.h -install -p -m 0644 %{_builddir}/%{neuron_sources}/neuron_ioctl.h %{buildroot}/%{_cross_includedir}/neuron_ioctl.h - -%files -%license %{neuron_sources}/LICENSE -%{_cross_attribution_file} -%{_cross_libdir}/modules/*/extra/neuron.ko.gz -%{_cross_libdir}/modules-load.d/neuron.conf -%{_cross_unitdir}/systemd-modules-load.service.d/neuron.conf - -%files devel -%dir %{_cross_includedir}/share/ -%{_cross_includedir}/share/neuron_driver_shared.h -%{_cross_includedir}/neuron_ioctl.h diff --git a/packages/kmod-6.1-neuron/neuron-modules-load.conf b/packages/kmod-6.1-neuron/neuron-modules-load.conf deleted file mode 100644 index aba019c2e..000000000 --- a/packages/kmod-6.1-neuron/neuron-modules-load.conf +++ /dev/null @@ -1 +0,0 @@ -neuron diff --git a/packages/kmod-6.1-neuron/neuron-systemd-modules-load.drop-in.conf b/packages/kmod-6.1-neuron/neuron-systemd-modules-load.drop-in.conf deleted file mode 100644 index 0b1302960..000000000 --- a/packages/kmod-6.1-neuron/neuron-systemd-modules-load.drop-in.conf +++ /dev/null @@ -1,2 +0,0 @@ -[Service] -ExecStartPre=-/usr/bin/depmod diff --git a/sources/Cargo.lock b/sources/Cargo.lock index 8549b6838..9ab6d56a1 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -3556,7 +3556,9 @@ dependencies = [ "bon", "derive-getters", "generate-readme", + "lazy_static", "log", + "maplit", "serde_json", "snafu", "test-case", diff --git a/sources/ghostdog/src/main.rs b/sources/ghostdog/src/main.rs index 8ab463d72..6ef7e10f2 100644 --- a/sources/ghostdog/src/main.rs +++ b/sources/ghostdog/src/main.rs @@ -36,6 +36,7 @@ enum SubCommand { Scan(ScanArgs), EbsDeviceName(EbsDeviceNameArgs), EfaPresent(EfaPresentArgs), + NeuronPresent(NeuronPresentArgs), MatchNvidiaDriver(MatchNvidiaDriverArgs), } @@ -44,6 +45,11 @@ enum SubCommand { /// Detect if EFA devices are attached. struct EfaPresentArgs {} +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand, name = "neuron-present")] +/// Detect if Neuron devices are attached. +struct NeuronPresentArgs {} + #[derive(FromArgs, PartialEq, Debug)] #[argh(subcommand, name = "scan")] /// Scan a device to see if it is an ephemeral disk. @@ -112,6 +118,9 @@ fn run() -> Result<()> { SubCommand::EfaPresent(_) => { is_efa_attached()?; } + SubCommand::NeuronPresent(_) => { + is_neuron_attached()?; + } SubCommand::MatchNvidiaDriver(driver) => { let driver_name = driver.driver_name; nvidia_driver_supported(&driver_name)?; @@ -128,6 +137,14 @@ fn is_efa_attached() -> Result<()> { } } +fn is_neuron_attached() -> Result<()> { + if pciclient::is_neuron_attached().context(error::CheckNeuronFailureSnafu)? { + Ok(()) + } else { + Err(error::Error::NoNeuronPresent) + } +} + /// Find the device type by examining the partition table, if present. fn find_device_type(reader: &mut R) -> Result where @@ -296,8 +313,12 @@ mod error { InvalidDeviceInfo { path: std::path::PathBuf }, #[snafu(display("Failed to check if EFA device is attached: {}", source))] CheckEfaFailure { source: pciclient::PciClientError }, + #[snafu(display("Failed to check if Neuron device is attached: {}", source))] + CheckNeuronFailure { source: pciclient::PciClientError }, #[snafu(display("Did not detect EFA"))] NoEfaPresent, + #[snafu(display("Did not detect Neuron"))] + NoNeuronPresent, #[snafu(display("Failed to open '{}': {}", path.display(), source))] OpenFile { path: std::path::PathBuf, diff --git a/sources/pciclient/Cargo.toml b/sources/pciclient/Cargo.toml index d971b561d..dbbb09d0d 100644 --- a/sources/pciclient/Cargo.toml +++ b/sources/pciclient/Cargo.toml @@ -12,7 +12,9 @@ exclude = ["README.md"] [dependencies] bon.workspace = true derive-getters.workspace = true +lazy_static.workspace = true log.workspace = true +maplit.workspace = true serde_json.workspace = true snafu.workspace = true diff --git a/sources/pciclient/src/lib.rs b/sources/pciclient/src/lib.rs index 5bf55d80d..aafb8f231 100644 --- a/sources/pciclient/src/lib.rs +++ b/sources/pciclient/src/lib.rs @@ -7,7 +7,7 @@ pciclient provides util functions that can: */ mod private; -use private::{call_list_devices, check_efa_attachment, PciClient}; +use private::{call_list_devices, check_efa_attachment, check_neuron_attachment, PciClient}; use bon::Builder; use derive_getters::Getters; @@ -115,6 +115,11 @@ pub fn is_efa_attached() -> Result { check_efa_attachment(PciClient {}) } +/// Call `lspci` and check if there is any Neuron device attached. +pub fn is_neuron_attached() -> Result { + check_neuron_attachment(PciClient {}) +} + mod error { use snafu::Snafu; diff --git a/sources/pciclient/src/private.rs b/sources/pciclient/src/private.rs index bf72c55b6..78c3ee5fa 100644 --- a/sources/pciclient/src/private.rs +++ b/sources/pciclient/src/private.rs @@ -1,6 +1,8 @@ -use std::{ffi::OsStr, process::Command}; - +use lazy_static::lazy_static; +use maplit::hashset; use snafu::{ensure, OptionExt, ResultExt}; +use std::collections::HashSet; +use std::{ffi::OsStr, process::Command}; use crate::{ error::{ @@ -13,6 +15,18 @@ use crate::{ const AMAZON_VENDOR_CODE: &str = "1d0f"; const EFA_KEYWORD: &str = "efa"; +lazy_static! { + static ref NEURON_DEVICES: HashSet<&'static str> = hashset! { + "7064", // inf1 device id 0 + "7065", // inf1 device id 1 + "7066", // inf1 device id 2 + "7067", // inf1 device id 3 + "7164", // trn1 device id 0 + "7264", // inf2 device id 0 + "7364", // trn2 device id 0 + }; +} + const LSPCI_PATH: &str = "/usr/bin/lspci"; pub(crate) trait CommandExecutor { @@ -148,6 +162,19 @@ pub(crate) fn check_efa_attachment(command_executor: T) -> R .any(|device_info| device_info.device.contains(EFA_KEYWORD))) } +/// Call `lspci` and check if there is any Neuron device attached. +/// Internal usage, adding command_executor as parameter allows us to better unit test. +/// For external usage, check [`crate::is_neuron_attached`]. +pub(crate) fn check_neuron_attachment(command_executor: T) -> Result { + let list_devices_param = ListDevicesParam::builder() + .vendor(AMAZON_VENDOR_CODE.to_string()) + .build(); + let list_device_results = call_list_devices(command_executor, list_devices_param)?; + Ok(list_device_results + .iter() + .any(|device_info| NEURON_DEVICES.contains(&device_info.device.as_str()))) +} + /// Internal usage, adding command_executor as parameter allows us to better unit test. /// For external usage, check [`list_devices`]. pub(crate) fn call_list_devices( @@ -167,7 +194,8 @@ mod test { use crate::{ListDevicesOutput, ListDevicesParam, Result}; use super::{ - call_list_devices, check_efa_attachment, parse_list_devices_output, CommandExecutor, + call_list_devices, check_efa_attachment, check_neuron_attachment, + parse_list_devices_output, CommandExecutor, }; struct MockPciClient { @@ -332,4 +360,30 @@ mod test { assert!(check_efa_attachment_result.is_ok()); assert!(!check_efa_attachment_result.unwrap()); } + + #[test] + fn test_is_neuron_attached() { + let mock_pci_client = MockPciClient { + // trn1 device has class code: 0880 for system peripheral, vendor 1d0f for amazon, device code 7164. + // Below is an actual output from lspci for trn1 device. + output: vec![ + r#"00:1e.0 "0880" "1d0f" "7164" -p00 "" """#.to_string(), + r#"00:1e.0 "0302" "10de" "1eb8" -ra1 -p00 "10de" "12a2""#.to_string(), + ], + }; + let check_neuron_attachment_result = check_neuron_attachment(mock_pci_client); + assert!(check_neuron_attachment_result.is_ok()); + assert!(check_neuron_attachment_result.unwrap()); + } + + #[test] + fn test_is_neuron_attached_negative_case() { + let mock_pci_client = MockPciClient { + // Below is an actual output from lspci for ena device (not neuron). + output: vec![r#"00:06.0 "0200" "1d0f" "ec20" -p00 "1d0f" "ec20""#.to_string()], + }; + let check_neuron_attachment_result = check_neuron_attachment(mock_pci_client); + assert!(check_neuron_attachment_result.is_ok()); + assert!(!check_neuron_attachment_result.unwrap()); + } }