Skip to content

Commit 8336b8e

Browse files
madhu-pillaijlebon
andcommitted
Set up CEX device on s390x builder
Add a new systemd unit that sets up a CEX device for use by kola tests. The device is associated with a UUID. This UUID is passed to kola via an environment variable for now. See also: coreos/coreos-assembler#3828 Co-authored-by: Jonathan Lebon <[email protected]>
1 parent 3d66eef commit 8336b8e

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ streams:
2323

2424
additional_arches: [aarch64, ppc64le, s390x]
2525

26+
env:
27+
# This matches the UUID in multi-arch-builders/create-cex-device.sh
28+
# Ideally, we'd pass this a cleaner way. See also:
29+
# https://github.com/coreos/coreos-assembler/pull/3828#discussion_r1669010741
30+
KOLA_CEX_UUID: "68cd2d83-3eef-4e45-b22c-534f90b16cb9"
31+
2632
source_config:
2733
url: https://github.com/coreos/fedora-coreos-config
2834

multi-arch-builders/coreos-s390x-rhcos-builder.bu

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ systemd:
2929
ExecStart=/usr/local/bin/create-secex-data.sh
3030
[Install]
3131
WantedBy=multi-user.target
32+
- name: cex-config.service
33+
enabled: true
34+
contents: |
35+
[Unit]
36+
Description=Create IBM CEX mediate device
37+
[Service]
38+
Type=oneshot
39+
RemainAfterExit=yes
40+
ExecStart=/usr/local/bin/create-cex-device.sh
41+
[Install]
42+
WantedBy=multi-user.target
3243
storage:
3344
files:
3445
- path: /usr/local/bin/create-secex-data.sh
@@ -91,3 +102,12 @@ storage:
91102

92103
echo "Importing tarball into volume"
93104
sudo -u builder -H /bin/bash -c "cd /var/home/builder; podman volume import secex-data /var/home/builder/${TARBALL}"
105+
106+
- path: /usr/local/bin/create-cex-device.sh
107+
mode: 0755
108+
user:
109+
name: root
110+
group:
111+
name: root
112+
contents:
113+
local: create-cex-device.sh
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Reference document for the cex configuration in zKVM
5+
# https://www.ibm.com/docs/en/linux-on-systems?topic=management-configuring-crypto-express-adapters-kvm-guests
6+
7+
modprobe vfio_ap
8+
9+
# Hardcoded the UUID for the quick verification of mediated device.
10+
# This UUID is passed to kola via the KOLA_CEX_UUID env var in the pipecfg.
11+
UUID='68cd2d83-3eef-4e45-b22c-534f90b16cb9'
12+
if ls /sys/devices/vfio_ap/matrix | grep -q "${UUID}"; then
13+
echo "${UUID}"
14+
exit 1
15+
fi
16+
17+
cards=$(ls /sys/bus/ap/devices | grep -E 'card[0-9]{2}')
18+
if [ -z "${cards}" ]; then
19+
echo "cex device not found."
20+
exit 1
21+
fi
22+
23+
# if more than one card picks the first available cca controller
24+
for card in $cards; do
25+
if $(grep -q cca /sys/bus/ap/devices/${card}/uevent); then
26+
card=${card}
27+
card_domain=$(ls /sys/bus/ap/devices/$card/ | grep -E '[0-9a-f]{2}.[0-9a-f]{4}')
28+
break
29+
fi
30+
done
31+
32+
# Validating the card and domain
33+
if [ -z "${card}" ] || [ -z "${card_domain}"]; then
34+
echo "couldn't find card with CCA controller"
35+
exit 1
36+
fi
37+
38+
echo "Freeing adapter and domain."
39+
echo 0x0 > /sys/bus/ap/apmask
40+
echo 0x0 > /sys/bus/ap/aqmask
41+
echo ${UUID} > /sys/devices/vfio_ap/matrix/mdev_supported_types/vfio_ap-passthrough/create
42+
if [ $? != 0 ]; then
43+
echo "failed creating mediated device."
44+
exit 1
45+
fi
46+
47+
echo "Configuring the adapter and domain."
48+
card_no=$(echo ${card_domain} | cut -f1 -d.)
49+
domain_no=$(echo ${card_domain} | cut -f2 -d.)
50+
echo 0x${card_no} > /sys/devices/vfio_ap/matrix/${UUID}/assign_adapter
51+
echo 0x${domain_no} > /sys/devices/vfio_ap/matrix/${UUID}/assign_domain
52+
53+
echo "Validating the domains."
54+
validate_dom=$(cat /sys/devices/vfio_ap/matrix/${UUID}/matrix)
55+
if [[ "${card_no}.${domain_no}" != ${validate_dom} ]]; then
56+
echo -e "Mismatched card number. \n"
57+
exit 1
58+
fi

0 commit comments

Comments
 (0)