Skip to content

Commit f7c03c4

Browse files
committed
kernel-6.1: 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 8e2fa7c commit f7c03c4

11 files changed

+121
-30
lines changed

packages/kernel-6.1/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ sha512 = "395940a92892d92612c51edc566e9bd7bb59432048a796e9e4934246f20aca8f7cef95
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.1/kernel-6.1.spec

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ URL: https://www.kernel.org/
99
# Use latest-kernel-srpm-url.sh to get this.
1010
Source0: https://cdn.amazonlinux.com/al2023/blobstore/f3b09a804dce910af99d51994144a9e73322ac17d13feb47547b70b7833fa40a/kernel-6.1.155-176.282.amzn2023.src.rpm
1111
Source1: gpgkey-B21C50FA44A99720EAA72F7FE951904AD832C631.asc
12-
# Use latest-neuron-srpm-url.sh to get this.
12+
# Use latest-2.21-neuron-srpm-url.sh to get this.
1313
Source2: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.21.37.0.noarch.rpm
14-
Source3: gpgkey-00FA2C1079260870A76D2C285749CAD8646D9185.asc
14+
# Use latest-neuron-srpm-url.sh to get this.
15+
Source3: https://yum.repos.neuron.amazonaws.com/aws-neuronx-dkms-2.24.7.0.noarch.rpm
16+
Source4: gpgkey-00FA2C1079260870A76D2C285749CAD8646D9185.asc
1517

1618
# Custom Bottlerocket kernel configurations.
1719
Source100: config-bottlerocket
@@ -30,9 +32,12 @@ Source202: fipsmodules-aarch64
3032
# Adjust kernel-devel mount behavior if not squashfs.
3133
Source210: var-lib-kernel-devel-lower.mount.drop-in.conf.in
3234

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

3742
# Bootconfig snippets to adjust the default kernel command line for the platform.
3843
Source300: bootconfig-aws.conf
@@ -252,11 +257,20 @@ rm -f ../config-* ../*.patch
252257

253258
%if "%{_cross_arch}" == "x86_64"
254259
cd %{_builddir}
255-
rpmkeys --import %{S:3} --dbpath "${PWD}/rpmdb"
260+
# 2.21 for inf1 support
261+
rpmkeys --import %{S:4} --dbpath "${PWD}/rpmdb"
256262
rpmkeys --checksig %{S:2} --dbpath "${PWD}/rpmdb"
257263
rm -rf "${PWD}/rpmdb"
258264
rpm2cpio %{S:2} | cpio -idmu './usr/src/aws-neuronx-*'
259-
find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron \;
265+
find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron_2_21 \;
266+
rm -r usr
267+
268+
# latest neuron driver
269+
rpmkeys --import %{S:4} --dbpath "${PWD}/rpmdb"
270+
rpmkeys --checksig %{S:3} --dbpath "${PWD}/rpmdb"
271+
rm -rf "${PWD}/rpmdb"
272+
rpm2cpio %{S:3} | cpio -idmu './usr/src/aws-neuronx-*'
273+
find usr/src/ -mindepth 1 -maxdepth 1 -type d -exec mv {} neuron_latest \;
260274
rm -r usr
261275
%endif
262276

@@ -276,15 +290,21 @@ make -s\\\
276290
%kmake %{?_smp_mflags} modules
277291

278292
%if "%{_cross_arch}" == "x86_64"
279-
%kmake %{?_smp_mflags} M=%{_builddir}/neuron
293+
%kmake %{?_smp_mflags} M=%{_builddir}/neuron_2_21
294+
%kmake %{?_smp_mflags} M=%{_builddir}/neuron_latest
280295
%endif
281296

282297
%install
283298
%kmake %{?_smp_mflags} headers_install
284299
%kmake %{?_smp_mflags} modules_install
285300

286301
%if "%{_cross_arch}" == "x86_64"
287-
%kmake %{?_smp_mflags} M=%{_builddir}/neuron modules_install
302+
install -d %{buildroot}%{_cross_libexecdir}/neuron/neuron_2_21/
303+
install -d %{buildroot}%{_cross_libexecdir}/neuron/neuron_latest/
304+
%kmake %{?_smp_mflags} INSTALL_MOD_DIR=neuron_2_21 M=%{_builddir}/neuron_2_21 modules_install
305+
%kmake %{?_smp_mflags} INSTALL_MOD_DIR=neuron_latest M=%{_builddir}/neuron_latest modules_install
306+
mv %{buildroot}%{_cross_kmoddir}/neuron_2_21/neuron.ko.gz %{buildroot}%{_cross_libexecdir}/neuron/neuron_2_21/
307+
mv %{buildroot}%{_cross_kmoddir}/neuron_latest/neuron.ko.gz %{buildroot}%{_cross_libexecdir}/neuron/neuron_latest/
288308
%endif
289309

290310
install -d %{buildroot}/boot
@@ -426,12 +446,22 @@ sed -e 's|PREFIX|%{_cross_prefix}|g' %{S:210} \
426446
> %{buildroot}%{_cross_unitdir}/"${LOWERPATH}.mount.d"/no-squashfs.conf
427447

428448
%if "%{_cross_arch}" == "x86_64"
429-
# Add Neuron-related drop-ins to load the module when the hardware is present.
430-
mkdir -p %{buildroot}%{_cross_unitdir}/sysinit.target.d
431-
install -p -m 0644 %{S:220} %{buildroot}%{_cross_unitdir}/sysinit.target.d/neuron.conf
432-
433-
mkdir -p %{buildroot}%{_cross_unitdir}/[email protected]
434-
install -p -m 0644 %{S:221} %{buildroot}%{_cross_unitdir}/[email protected]/neuron.conf
449+
# Add Neuron-related configuration files to load the module when the hardware is present.
450+
install -d 0644 %{buildroot}%{_cross_tmpfilesdir}
451+
sed \
452+
-e "s|__KERNEL_VERSION__|%{version}|" \
453+
-e "s|__PREFIX__|%{_cross_prefix}|" %{S:220} > neuron.conf
454+
install -p -m 0644 neuron.conf %{buildroot}%{_cross_tmpfilesdir}/
455+
install -d 0644 %{buildroot}%{_cross_factorydir}%{_cross_sysconfdir}/drivers
456+
# inf1
457+
sed -e 's|__NEURON_MODULES__|%{_cross_libexecdir}/neuron|' %{S:221} > \
458+
neuron-inf1.toml
459+
install -m 0644 neuron-inf1.toml %{buildroot}%{_cross_factorydir}%{_cross_sysconfdir}/drivers
460+
# latest
461+
sed -e 's|__NEURON_MODULES__|%{_cross_libexecdir}/neuron|' %{S:222} > \
462+
neuron-latest.toml
463+
install -m 0644 neuron-latest.toml %{buildroot}%{_cross_factorydir}%{_cross_sysconfdir}/drivers
464+
install -p -m 0644 %{S:223} %{S:224} %{buildroot}%{_cross_unitdir}
435465
%endif
436466

437467
# Install platform-specific bootconfig snippets.
@@ -1501,9 +1531,13 @@ install -p -m 0644 %{S:302} %{buildroot}%{_cross_bootconfigdir}/05-metal.conf
15011531

15021532
%if "%{_cross_arch}" == "x86_64"
15031533
%files modules-neuron
1504-
%{_cross_kmoddir}/extra/neuron.ko.gz
1505-
%{_cross_unitdir}/sysinit.target.d/neuron.conf
1506-
%{_cross_unitdir}/[email protected]/neuron.conf
1534+
%{_cross_libexecdir}/neuron/neuron_2_21/neuron.ko.gz
1535+
%{_cross_libexecdir}/neuron/neuron_latest/neuron.ko.gz
1536+
%{_cross_tmpfilesdir}/neuron.conf
1537+
%{_cross_unitdir}/load-neuron-inf1-modules.service
1538+
%{_cross_unitdir}/load-neuron-latest-modules.service
1539+
%{_cross_factorydir}%{_cross_sysconfdir}/drivers/neuron-inf1.toml
1540+
%{_cross_factorydir}%{_cross_sysconfdir}/drivers/neuron-latest.toml
15071541
%endif
15081542

15091543
%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.1/[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.gz"]
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.gz"]
5+
copy-source = "__NEURON_MODULES__/neuron_latest"

packages/kernel-6.1/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)