Skip to content

Commit 8e2fa7c

Browse files
committed
kernel-6.12: Add additional Neuron module
Add a second neuron module so that we can choose the appropriate driver based upon the detected hardware. This provides both neuron_2_21 and neuron_latest in the data directory which is not discoverable by depmod. The mechanism for loading the driver is driverdog link and load modules for neuron. There is now two scripts for checking the neuron driver, one for 2.21.* and one for latest. Signed-off-by: Matthew Yeazel <[email protected]>
1 parent 0fe171f commit 8e2fa7c

10 files changed

+119
-27
lines changed

packages/kernel-6.12/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ sha512 = "ca7fc22f52e6d0c29d02ed2d51636a63e460d4ec5f2ac49a2cd0ad901af1031ff5741f
1818
force-upstream = true
1919

2020
[[package.metadata.build-package.external-files]]
21-
# Use latest-neuron-srpm-url.sh to get this.
21+
# Use latest-2.21-neuron-srpm-url.sh to get this.
2222
url = "https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.21.37.0.noarch.rpm"
2323
sha512 = "4bdb01d846f12a04bdbe6902c3008ebadbcb50d4d94e8f81b524c02a4e94da7041cdb5e94fd564e1d9898f52a8cbd960a6a65435b90ba7d7839c807e7ca8736d"
2424

25+
[[package.metadata.build-package.external-files]]
26+
# Use latest-neuron-srpm.url.sh to get this.
27+
url = "https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.24.7.0.noarch.rpm"
28+
sha512 = "2892ad1c6c4ff670d8e4aa0151af57b2b437f647a58ffa58901377b2ddeb504a9e4cce6c148643f8340e1ede8bb26ab66039b0a6bbb184bf5d647c6c71720186"
29+
2530
[build-dependencies]
2631
microcode = { path = "../microcode" }

packages/kernel-6.12/kernel-6.12.spec

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ URL: https://www.kernel.org/
1212
# Use latest-kernel-srpm-url.sh to get this.
1313
Source0: https://cdn.amazonlinux.com/al2023/blobstore/90e970acea5d658008c0707a6c4953b0e877f85b122cd967525bfecb043af96b/kernel6.12-6.12.46-66.121.amzn2023.src.rpm
1414
Source1: gpgkey-B21C50FA44A99720EAA72F7FE951904AD832C631.asc
15-
# Use latest-neuron-srpm-url.sh to get this.
15+
# Use latest-2.21-neuron-srpm-url.sh to get this.
1616
Source2: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.21.37.0.noarch.rpm
17-
Source3: gpgkey-00FA2C1079260870A76D2C285749CAD8646D9185.asc
17+
# Use latest-neuron-srpm-url.sh to get this.
18+
Source3: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.24.7.0.noarch.rpm
19+
Source4: gpgkey-00FA2C1079260870A76D2C285749CAD8646D9185.asc
1820

1921
# Custom Bottlerocket kernel configurations.
2022
Source100: config-bottlerocket
@@ -33,9 +35,12 @@ Source202: fipsmodules-aarch64
3335
# Adjust kernel-devel mount behavior if not squashfs.
3436
Source210: var-lib-kernel-devel-lower.mount.drop-in.conf.in
3537

36-
# Neuron-related drop-ins.
37-
Source220: neuron-sysinit.target.drop-in.conf
38-
38+
# Neuron-related configuration and unit files
39+
Source220: neuron-tmpfiles.conf
40+
Source221: neuron-inf1.toml
41+
Source222: neuron-latest.toml
42+
Source223: load-neuron-inf1-modules.service
43+
Source224: load-neuron-latest-modules.service
3944

4045
# Bootconfig snippets to adjust the default kernel command line for the platform.
4146
Source300: bootconfig-aws.conf
@@ -228,11 +233,20 @@ rm -f ../config-* ../*.patch
228233

229234
%if "%{_cross_arch}" == "x86_64"
230235
cd %{_builddir}
231-
rpmkeys --import %{S:3} --dbpath "${PWD}/rpmdb"
236+
# 2.21 for inf1 support
237+
rpmkeys --import %{S:4} --dbpath "${PWD}/rpmdb"
232238
rpmkeys --checksig %{S:2} --dbpath "${PWD}/rpmdb"
233239
rm -rf "${PWD}/rpmdb"
234240
rpm2cpio %{S:2} | cpio -idmu './usr/src/aws-neuronx-*'
235-
find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron \;
241+
find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron_2_21 \;
242+
rm -r usr
243+
244+
# latest neuron driver
245+
rpmkeys --import %{S:4} --dbpath "${PWD}/rpmdb"
246+
rpmkeys --checksig %{S:3} --dbpath "${PWD}/rpmdb"
247+
rm -rf "${PWD}/rpmdb"
248+
rpm2cpio %{S:3} | cpio -idmu './usr/src/aws-neuronx-*'
249+
find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron_latest \;
236250
rm -r usr
237251
%endif
238252

@@ -252,7 +266,8 @@ make -s\\\
252266
%kmake %{?_smp_mflags} modules
253267

254268
%if "%{_cross_arch}" == "x86_64"
255-
%kmake %{?_smp_mflags} M=%{_builddir}/neuron
269+
%kmake %{?_smp_mflags} M=%{_builddir}/neuron_2_21
270+
%kmake %{?_smp_mflags} M=%{_builddir}/neuron_latest
256271
%endif
257272

258273
make -C tools/bpf/bpftool bootstrap
@@ -263,7 +278,12 @@ make -C tools/bpf/bpftool bootstrap
263278
%kmake %{?_smp_mflags} modules_install
264279

265280
%if "%{_cross_arch}" == "x86_64"
266-
%kmake %{?_smp_mflags} M=%{_builddir}/neuron modules_install
281+
install -d %{buildroot}%{_cross_libexecdir}/neuron/neuron_2_21/
282+
install -d %{buildroot}%{_cross_libexecdir}/neuron/neuron_latest/
283+
%kmake %{?_smp_mflags} INSTALL_MOD_DIR=neuron_2_21 M=%{_builddir}/neuron_2_21 modules_install
284+
%kmake %{?_smp_mflags} INSTALL_MOD_DIR=neuron_latest M=%{_builddir}/neuron_latest modules_install
285+
mv %{buildroot}%{_cross_kmoddir}/neuron_2_21/neuron.%{_ko} %{buildroot}%{_cross_libexecdir}/neuron/neuron_2_21/
286+
mv %{buildroot}%{_cross_kmoddir}/neuron_latest/neuron.%{_ko} %{buildroot}%{_cross_libexecdir}/neuron/neuron_latest/
267287
%endif
268288

269289
install -d %{buildroot}/boot
@@ -387,12 +407,23 @@ mkdir -p %{buildroot}%{_cross_datadir}/xfsprogs/mkfs
387407
ln -s lts_6.12.conf %{buildroot}%{_cross_datadir}/xfsprogs/mkfs/default.conf
388408

389409
%if "%{_cross_arch}" == "x86_64"
390-
# Add Neuron-related drop-ins to load the module when the hardware is present.
391-
mkdir -p %{buildroot}%{_cross_unitdir}/sysinit.target.d
392-
install -p -m 0644 %{S:220} %{buildroot}%{_cross_unitdir}/sysinit.target.d/neuron.conf
410+
# Add Neuron-related configuration files to load the module when the hardware is present.
411+
install -d 0644 %{buildroot}%{_cross_tmpfilesdir}
412+
sed \
413+
-e "s|__KERNEL_VERSION__|%{kmajor}|" \
414+
-e "s|__PREFIX__|%{_cross_prefix}|" %{S:220} > neuron.conf
415+
install -p -m 0644 neuron.conf %{buildroot}%{_cross_tmpfilesdir}/
416+
install -d 0644 %{buildroot}%{_cross_factorydir}%{_cross_sysconfdir}/drivers
417+
# inf1
418+
sed -e 's|__NEURON_MODULES__|%{_cross_datadir}/neuron|' %{S:221} > \
419+
neuron-inf1.toml
420+
install -m 0644 neuron-inf1.toml %{buildroot}%{_cross_factorydir}%{_cross_sysconfdir}/drivers
421+
# latest
422+
sed -e 's|__NEURON_MODULES__|%{_cross_datadir}/neuron|' %{S:222} > \
423+
neuron-latest.toml
424+
install -m 0644 neuron-latest.toml %{buildroot}%{_cross_factorydir}%{_cross_sysconfdir}/drivers
425+
install -p -m 0644 %{S:223} %{S:224} %{buildroot}%{_cross_unitdir}
393426

394-
mkdir -p %{buildroot}%{_cross_unitdir}/[email protected]
395-
install -p -m 0644 %{S:221} %{buildroot}%{_cross_unitdir}/[email protected]/neuron.conf
396427
%endif
397428

398429
# Install platform-specific bootconfig snippets.
@@ -1412,9 +1443,13 @@ install -p -m 0644 %{S:301} %{buildroot}%{_cross_bootconfigdir}/05-vmware.conf
14121443

14131444
%if "%{_cross_arch}" == "x86_64"
14141445
%files modules-neuron
1415-
%{_cross_kmoddir}/updates/neuron.%{_ko}
1416-
%{_cross_unitdir}/sysinit.target.d/neuron.conf
1417-
%{_cross_unitdir}/[email protected]/neuron.conf
1446+
%{_cross_libexecdir}/neuron/neuron_2_21/neuron.%{_ko}
1447+
%{_cross_libexecdir}/neuron/neuron_latest/neuron.%{_ko}
1448+
%{_cross_tmpfilesdir}/neuron.conf
1449+
%{_cross_unitdir}/load-neuron-inf1-modules.service
1450+
%{_cross_unitdir}/load-neuron-latest-modules.service
1451+
%{_cross_factorydir}%{_cross_sysconfdir}/drivers/neuron-inf1.toml
1452+
%{_cross_factorydir}%{_cross_sysconfdir}/drivers/neuron-latest.toml
14181453
%endif
14191454

14201455
%changelog
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
cmd="
3+
dnf install -q -y --releasever=latest yum-utils &&
4+
dnf download -q --repofrompath neuron,https://yum.repos.neuron.amazonaws.com --repo=neuron --urls aws-neuronx-dkms-2.21*
5+
"
6+
docker run --rm public.ecr.aws/amazonlinux/amazonlinux:2023 sh -c "${cmd}" \
7+
| grep '^http' \
8+
| xargs --max-args=1 --no-run-if-empty realpath --canonicalize-missing --relative-to=. \
9+
| sed 's_:/_://_'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
Description=Load Neuron Inf1 modules
3+
After=local-fs.target
4+
Requires=local-fs.target
5+
# Disable manual restarts to prevent loading kernel modules
6+
# that weren't linked by the running system
7+
RefuseManualStart=true
8+
RefuseManualStop=true
9+
10+
[Service]
11+
Type=oneshot
12+
ExecCondition=/usr/bin/ghostdog match-driver neuron inf1
13+
ExecStart=/usr/bin/driverdog --modules-set neuron-inf1 link-modules
14+
ExecStart=/usr/bin/driverdog --modules-set neuron-inf1 load-modules
15+
RemainAfterExit=true
16+
StandardError=journal+console
17+
18+
[Install]
19+
RequiredBy=drivers.target
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
Description=Load Neuron Latest modules
3+
After=local-fs.target
4+
Requires=local-fs.target
5+
# Disable manual restarts to prevent loading kernel modules
6+
# that weren't linked by the running system
7+
RefuseManualStart=true
8+
RefuseManualStop=true
9+
10+
[Service]
11+
Type=oneshot
12+
ExecCondition=/usr/bin/ghostdog match-driver neuron latest
13+
ExecStart=/usr/bin/driverdog --modules-set neuron-latest link-modules
14+
ExecStart=/usr/bin/driverdog --modules-set neuron-latest load-modules
15+
RemainAfterExit=true
16+
StandardError=journal+console
17+
18+
[Install]
19+
RequiredBy=drivers.target

packages/kernel-6.12/[email protected]

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[neuron-inf1]
2+
lib-modules-path = "kernel/drivers/neuron"
3+
4+
[neuron-inf1.kernel-modules."neuron.ko"]
5+
copy-source = "__NEURON_MODULES__/neuron_2_21"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[neuron-latest]
2+
lib-modules-path = "kernel/drivers/neuron"
3+
4+
[neuron-latest.kernel-modules."neuron.ko"]
5+
copy-source = "__NEURON_MODULES__/neuron_latest"

packages/kernel-6.12/neuron-sysinit.target.drop-in.conf

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
C /etc/drivers/neuron-inf1.toml
2+
C /etc/drivers/neuron-latest.toml
3+
R __PREFIX__/lib/modules/__KERNEL_VERSION__/kernel/drivers/neuron - - - - -
4+
d __PREFIX__/lib/modules/__KERNEL_VERSION__/kernel/drivers/neuron 0755 root root - -

0 commit comments

Comments
 (0)