Skip to content

Commit

Permalink
Test the firmware feature in CI
Browse files Browse the repository at this point in the history
Set firmware_class.path after minikube initialization.
Read a dummy firmware in module_init.
Expect the output in the test script.
Collect troubleshooting output as YAML.

Co-Authored-By: Yevgeny Shnaidman <[email protected]>
Co-Authored-By: Constantin Daniel Vultur <[email protected]>
  • Loading branch information
3 people committed Oct 10, 2023
1 parent 95e7c76 commit 8612894
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Install yq
run: sudo snap install yq

- name: Build the image
run: make docker-build-hub HUB_IMG=kmm-hub:local

Expand Down Expand Up @@ -174,7 +177,7 @@ jobs:
if: steps.cache-bin.outputs.cache-hit != 'true'

- name: Run test
run: ${{ matrix.script }}
run: GIT_REF=$GITHUB_REF ${{ matrix.script }}
env:
${{ matrix.env }}

Expand Down
10 changes: 10 additions & 0 deletions ci/install-ci/controller_manager_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
healthProbeBindAddress: :8081
webhookPort: 9443
metrics:
enableAuthnAuthz: true
bindAddress: 0.0.0.0:8443
secureServing: true
worker:
runAsUser: 0
seLinuxType: spc_t
setFirmwareClassPath: /var/lib/firmware
9 changes: 9 additions & 0 deletions ci/install-ci/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ patches:
value: host.minikube.internal:5000/kmm/signimage:local
- name: RELATED_IMAGES_WORKER
value: host.minikube.internal:5000/kmm/worker:local
configMapGenerator:
- behavior: replace
files:
- controller_manager_config.yaml
name: manager-config

generatorOptions:
disableNameSuffixHash: true
10 changes: 9 additions & 1 deletion ci/kmm-kmod-dockerfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ data:
WORKDIR /usr/src/kernel-module-management/ci/kmm-kmod
ARG GIT_REF=main
RUN git fetch origin $GIT_REF
RUN git checkout FETCH_HEAD
RUN KERNEL_SRC_DIR=/usr/src/linux-headers-${KERNEL_VERSION} make all
FROM ubuntu:20.04
Expand All @@ -34,4 +39,7 @@ data:
COPY --from=builder /usr/src/kernel-module-management/ci/kmm-kmod/kmm_ci_a.ko /opt/lib/modules/${KERNEL_VERSION}/
COPY --from=builder /usr/src/kernel-module-management/ci/kmm-kmod/kmm_ci_b.ko /opt/lib/modules/${KERNEL_VERSION}/
RUN depmod -b /opt
RUN ["depmod", "-b", "/opt"]
RUN ["mkdir", "/firmware"]
RUN echo -n 'kmm_ci_firmware validation string' > /firmware/kmm_ci_firmware.bin
3 changes: 3 additions & 0 deletions ci/kmm-kmod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ RUN mkdir -p /opt/lib/modules/${KERNEL_VERSION}/extra
COPY kmm_ci_a.ko kmm_ci_b.ko /opt/lib/modules/${KERNEL_VERSION}/extra/

RUN ["depmod", "-b", "/opt"]

RUN ["mkdir", "/firmware"]
RUN echo -n 'kmm_ci_firmware validation string' > /firmware/kmm_ci_firmware.bin
67 changes: 59 additions & 8 deletions ci/kmm-kmod/kmm_ci_a.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,70 @@
/*
* kmm_ci.c - The simplest kernel module.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/platform_device.h>
#include <linux/firmware.h>
#include <linux/fs.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Quentin Barrand");
MODULE_AUTHOR("Yevgeny Shnaidman");
MODULE_DESCRIPTION("A simple kernel module for KMM CI");
MODULE_VERSION("0.01");

static int __init kmm_ci_init(void) {
printk(KERN_INFO "Hello, World!\n");
return 0;
static int __init kmm_ci_init(void)
{
struct platform_device *pdev;
const char fw_data[] = "kmm_ci_firmware validation string";
const char fw_name[] = "kmm_ci_firmware.bin";
const struct firmware *fw;
int err;

printk(KERN_INFO "Hello world from kmm_ci\n");

pdev = platform_device_register_simple("kmm-ci-1", 0, NULL, 0);
if (IS_ERR(pdev)) {
printk(KERN_ERR "Failed to register device for \"%s\"\n", fw_name);
err = -1;
goto out;
}

err = request_firmware(&fw, fw_name, &pdev->dev);
if (err) {
printk(KERN_ERR "Failed to load image \"%s\" err %d\n", fw_name, err);
goto unregister_platform;
}

if (fw->size != strlen(fw_data)) {
printk(KERN_ERR "The firmware data size is different from what we expect: %ld != %ld\n", strlen(fw_data), fw->size);
err = -1;
goto release_firmware;
}

if (strncmp(fw_data, fw->data, fw->size)) {
printk(KERN_ERR "The firmware data <%s> != the expected data <%s>\n", fw->data, fw_data);
err = -1;
goto release_firmware;
}

printk(KERN_INFO "ALL GOOD WITH FIRMWARE kmm_ci\n");

release_firmware:
release_firmware(fw);
unregister_platform:
platform_device_unregister(pdev);

/*
* A non 0 return means init_module failed; module can't be loaded.
*/
out:
return err;
}

static void __exit kmm_ci_exit(void) {
printk(KERN_INFO "Goodbye, World!\n");
static void __exit kmm_ci_exit(void)
{
printk(KERN_INFO "Goodbye world from kmm_ci.\n");
}

module_init(kmm_ci_init);
Expand Down
1 change: 1 addition & 0 deletions ci/module-kmm-ci-build-sign.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
modprobe:
moduleName: kmm_ci_a
modulesLoadingOrder: [kmm_ci_a, kmm_ci_b]
firmwarePath: /firmware
kernelMappings:
- regexp: '^.+$'
containerImage: host.minikube.internal:5000/$MOD_NAMESPACE/$MOD_NAME:$KERNEL_FULL_VERSION
Expand Down
15 changes: 13 additions & 2 deletions ci/prow/e2e-incluster-build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ check_module_not_loaded () {
fi
}


: "$GIT_REF"

echo "Deploy KMM..."
make deploy

Expand All @@ -29,11 +32,19 @@ kubectl apply -f ci/secret_kmm-kmod-signing.yaml

kubectl wait --for=condition=Available deployment/kmm-operator-controller-manager -n kmm-operator-system

echo "Set the GIT_REF build argument"
yq '
.spec.moduleLoader.container.kernelMappings[select(.regexp == "^.+$")].build.buildArgs = [{"name": "GIT_REF", "value": strenv(GIT_REF)}]
' ci/module-kmm-ci-build-sign.yaml | tee module.replaced.yaml

echo "Add an kmm-ci Module that contains a valid mapping..."
kubectl apply -f ci/module-kmm-ci-build-sign.yaml
kubectl apply -f module.replaced.yaml

echo "Check that the module gets loaded on the node..."
timeout 10m bash -c 'until minikube ssh -- lsmod | grep kmm_ci_a; do sleep 3; done'
timeout 1m bash -c 'until minikube ssh -- lsmod | grep kmm_ci_a; do sleep 3; done'

echo "Check that the module successfully read the firmware"
timeout 1m bash -c 'until dmesg | grep "ALL GOOD WITH FIRMWARE kmm_ci"; do sleep 1; done'

echo "Check that the dependent module is also loaded on the node..."
if ! minikube ssh -- lsmod | grep kmm_ci_b; then
Expand Down
1 change: 0 additions & 1 deletion config/manager/controller_manager_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
healthProbeBindAddress: :8081
metricsBindAddress: 127.0.0.1:8080
webhookPort: 9443
leaderElection:
enabled: true
Expand Down

0 comments on commit 8612894

Please sign in to comment.