Skip to content

Commit 03f2891

Browse files
committed
Revert "Launch Katana asynchronously via VM control channel"
This reverts commit a2bc333.
1 parent a2bc333 commit 03f2891

File tree

3 files changed

+68
-341
lines changed

3 files changed

+68
-341
lines changed

misc/AMDSEV/README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ If `--katana` is not provided, `build.sh` prompts for confirmation (`y/N`) befor
4040
| `build-kernel.sh` | Downloads and extracts Ubuntu kernel (`vmlinuz`) |
4141
| `build-initrd.sh` | Creates minimal initrd with busybox, SEV-SNP modules, and katana |
4242
| `build-config` | Pinned versions and checksums for reproducible builds |
43-
| `start-vm.sh` | Starts a TEE VM with SEV-SNP and launches Katana asynchronously |
43+
| `start-vm.sh` | Starts a TEE VM with SEV-SNP enabled using QEMU |
4444

4545
## SNP Tools
4646

@@ -93,11 +93,8 @@ qemu-system-x86_64 \
9393
# Initial ramdisk containing katana (measured when kernel-hashes=on)
9494
-initrd output/qemu/initrd.img \
9595
# Kernel command line (measured when kernel-hashes=on)
96-
-append "console=ttyS0" \
97-
# Katana control channel (used to start Katana asynchronously after boot)
98-
-device virtio-serial-pci,id=virtio-serial0 \
99-
-chardev socket,id=katanactl,path=/tmp/katana-control.sock,server=on,wait=off \
100-
-device virtserialport,chardev=katanactl,name=org.katana.control.0 \
96+
# katana.args passes arguments to katana via init script
97+
-append "console=ttyS0 katana.args=--http.addr,0.0.0.0,--http.port,5050,--tee.provider,sev-snp" \
10198
..
10299
```
103100

@@ -111,16 +108,11 @@ sudo ./misc/AMDSEV/start-vm.sh
111108

112109
# Or specify a custom boot components directory
113110
sudo ./misc/AMDSEV/start-vm.sh /path/to/boot-components
114-
115-
# Or customize Katana runtime flags (comma-separated)
116-
sudo ./misc/AMDSEV/start-vm.sh --katana-args "--http.addr,0.0.0.0,--http.port,5050,--tee.provider,sev-snp,--dev"
117111
```
118112

119113
The script:
120114
- Starts QEMU with SEV-SNP confidential computing enabled
121115
- Uses direct kernel boot with kernel-hashes=on for attestation
122-
- Keeps kernel cmdline stable (`console=ttyS0`) for deterministic measurement
123-
- Starts Katana asynchronously via virtio-serial control channel
124116
- Forwards RPC port 5050 to host port 15051
125117
- Outputs serial log to a temp file and follows it
126118

@@ -137,7 +129,7 @@ cargo build -p snp-tools
137129
--ovmf output/qemu/OVMF.fd \
138130
--kernel output/qemu/vmlinuz \
139131
--initrd output/qemu/initrd.img \
140-
--append "console=ttyS0" \
132+
--append "console=ttyS0 katana.args=--http.addr,0.0.0.0,--http.port,5050,--tee.provider,sev-snp" \
141133
--vcpus 1 \
142134
--cpu epyc-v4 \
143135
--vmm qemu \

misc/AMDSEV/build-initrd.sh

Lines changed: 23 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,6 @@ log() { echo "[init] $*"; }
293293
KATANA_PID=""
294294
KATANA_DB_DIR="/mnt/data/katana-db"
295295
SHUTTING_DOWN=0
296-
KATANA_EXIT_CODE="never"
297-
CONTROL_PORT_NAME="org.katana.control.0"
298-
CONTROL_PORT_LINK="/dev/virtio-ports/org.katana.control.0"
299296
300297
fatal_boot() {
301298
log "ERROR: $*"
@@ -306,90 +303,6 @@ fatal_boot() {
306303
done
307304
}
308305
309-
refresh_katana_state() {
310-
if [ -n "$KATANA_PID" ] && ! kill -0 "$KATANA_PID" 2>/dev/null; then
311-
if wait "$KATANA_PID"; then
312-
KATANA_EXIT_CODE=0
313-
else
314-
KATANA_EXIT_CODE=$?
315-
fi
316-
log "Katana exited with code $KATANA_EXIT_CODE"
317-
KATANA_PID=""
318-
fi
319-
}
320-
321-
respond_control() {
322-
printf '%s\n' "$1" >&3 2>/dev/null || true
323-
}
324-
325-
resolve_control_port() {
326-
mkdir -p /dev/virtio-ports
327-
for name_file in /sys/class/virtio-ports/*/name; do
328-
[ -f "$name_file" ] || continue
329-
330-
PORT_NAME_VALUE="$(cat "$name_file" 2>/dev/null || true)"
331-
if [ "$PORT_NAME_VALUE" != "$CONTROL_PORT_NAME" ]; then
332-
continue
333-
fi
334-
335-
PORT_DIR="${name_file%/name}"
336-
PORT_DEV="/dev/${PORT_DIR##*/}"
337-
if [ -e "$PORT_DEV" ]; then
338-
ln -sf "$PORT_DEV" "$CONTROL_PORT_LINK"
339-
echo "$CONTROL_PORT_LINK"
340-
return 0
341-
fi
342-
done
343-
return 1
344-
}
345-
346-
handle_control_command() {
347-
RAW_CMD="$1"
348-
CMD="${RAW_CMD%% *}"
349-
CMD_PAYLOAD=""
350-
if [ "$CMD" != "$RAW_CMD" ]; then
351-
CMD_PAYLOAD="${RAW_CMD#* }"
352-
fi
353-
354-
case "$CMD" in
355-
start)
356-
refresh_katana_state
357-
if [ -n "$KATANA_PID" ] && kill -0 "$KATANA_PID" 2>/dev/null; then
358-
respond_control "err already-running pid=$KATANA_PID"
359-
return 0
360-
fi
361-
362-
KATANA_ARGS=""
363-
if [ -n "$CMD_PAYLOAD" ]; then
364-
KATANA_ARGS="$(echo "$CMD_PAYLOAD" | tr ',' ' ')"
365-
fi
366-
367-
log "Starting katana asynchronously..."
368-
# shellcheck disable=SC2086
369-
/bin/katana --db-dir="$KATANA_DB_DIR" $KATANA_ARGS &
370-
KATANA_PID=$!
371-
KATANA_EXIT_CODE="running"
372-
respond_control "ok started pid=$KATANA_PID"
373-
;;
374-
375-
status)
376-
refresh_katana_state
377-
if [ -n "$KATANA_PID" ] && kill -0 "$KATANA_PID" 2>/dev/null; then
378-
respond_control "running pid=$KATANA_PID"
379-
else
380-
respond_control "stopped exit=$KATANA_EXIT_CODE"
381-
fi
382-
;;
383-
384-
"")
385-
;;
386-
387-
*)
388-
respond_control "err unknown-command"
389-
;;
390-
esac
391-
}
392-
393306
shutdown_handler() {
394307
if [ "$SHUTTING_DOWN" -eq 1 ]; then
395308
return 0
@@ -491,6 +404,15 @@ else
491404
log "WARNING: eth0 interface not found; skipping static network setup"
492405
fi
493406
407+
# Parse katana args from cmdline
408+
CMDLINE="$(cat /proc/cmdline 2>/dev/null || true)"
409+
KATANA_ARGS=""
410+
for tok in $CMDLINE; do
411+
case "$tok" in
412+
katana.args=*) KATANA_ARGS="$(echo "${tok#katana.args=}" | tr ',' ' ')" ;;
413+
esac
414+
done
415+
494416
# Require persistent storage at /dev/sda
495417
if [ ! -b /dev/sda ]; then
496418
fatal_boot "required storage device /dev/sda not found"
@@ -504,30 +426,22 @@ fi
504426
mkdir -p "$KATANA_DB_DIR"
505427
log "Storage mounted at /mnt/data"
506428
507-
# Start async control loop for Katana startup/status commands.
508-
log "Waiting for control channel ($CONTROL_PORT_NAME)..."
509-
CONTROL_PORT=""
510-
while [ -z "$CONTROL_PORT" ]; do
511-
CONTROL_PORT="$(resolve_control_port || true)"
512-
[ -n "$CONTROL_PORT" ] || sleep 1
513-
done
514-
log "Control channel ready: $CONTROL_PORT"
515-
516-
while true; do
517-
refresh_katana_state
429+
log "Starting katana..."
430+
# shellcheck disable=SC2086
431+
/bin/katana --db-dir="$KATANA_DB_DIR" $KATANA_ARGS &
432+
KATANA_PID=$!
433+
log "Katana started with PID $KATANA_PID"
518434
519-
if ! exec 3<>"$CONTROL_PORT"; then
520-
log "WARNING: failed to open control channel, retrying..."
521-
sleep 1
522-
continue
523-
fi
524-
525-
while IFS= read -r CONTROL_CMD <&3; do
526-
handle_control_command "$CONTROL_CMD"
527-
done
435+
if wait "$KATANA_PID"; then
436+
EXIT_CODE=0
437+
else
438+
EXIT_CODE=$?
439+
fi
440+
log "Katana exited with code $EXIT_CODE"
528441
529-
exec 3>&- 3<&-
530-
sleep 1
442+
# PID 1 must stay alive unless explicitly powered off.
443+
while true; do
444+
sleep 60
531445
done
532446
INIT_EOF
533447

0 commit comments

Comments
 (0)