@nosana/node 1.1.94-rc → 1.1.95-rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/.env +1 -1
  2. package/dist/package.json +1 -1
  3. package/dist/packages/vm-orchestrator/src/VmSpec.d.ts +2 -0
  4. package/dist/packages/vm-orchestrator/src/buildQemuArgs.d.ts +4 -3
  5. package/dist/packages/vm-orchestrator/src/buildQemuArgs.js +66 -19
  6. package/dist/packages/vm-orchestrator/src/hostAccess/VmHostAccess.d.ts +1 -0
  7. package/dist/packages/vm-orchestrator/src/hostAccess/VmHostAccess.js +2 -1
  8. package/dist/packages/vm-orchestrator/src/hostAccess/deviceProblems.d.ts +2 -0
  9. package/dist/packages/vm-orchestrator/src/hostAccess/deviceProblems.js +7 -0
  10. package/dist/packages/vm-orchestrator/src/hostAccess/findVmHostAccessProblems.d.ts +3 -2
  11. package/dist/packages/vm-orchestrator/src/hostAccess/findVmHostAccessProblems.js +11 -4
  12. package/dist/packages/vm-orchestrator/src/hostDevices.d.ts +2 -0
  13. package/dist/packages/vm-orchestrator/src/hostDevices.js +2 -0
  14. package/dist/packages/vm-orchestrator/src/hostTools.d.ts +5 -0
  15. package/dist/packages/vm-orchestrator/src/hostTools.js +22 -0
  16. package/dist/packages/vm-orchestrator/src/index.d.ts +4 -2
  17. package/dist/packages/vm-orchestrator/src/index.js +4 -2
  18. package/dist/packages/vm-orchestrator/src/sevSnp.d.ts +9 -0
  19. package/dist/packages/vm-orchestrator/src/sevSnp.js +15 -0
  20. package/dist/src/NodeManager/node/job/selectJobRuntimeEnvironment.d.ts +11 -3
  21. package/dist/src/NodeManager/node/job/selectJobRuntimeEnvironment.js +29 -5
  22. package/dist/src/NodeManager/provider/vmHost/setup/PrepareVmHostSystem.d.ts +2 -0
  23. package/dist/src/NodeManager/provider/vmHost/setup/PrepareVmHostSystem.js +2 -1
  24. package/dist/src/NodeManager/provider/vmHost/setup/prepareVmHost.d.ts +5 -4
  25. package/dist/src/NodeManager/provider/vmHost/setup/prepareVmHost.js +8 -4
  26. package/dist/src/cli/commands/run/command.js +2 -1
  27. package/dist/src/cli/commands/sharedOptions/--environment.d.ts +5 -0
  28. package/dist/src/cli/commands/sharedOptions/--environment.js +5 -0
  29. package/dist/src/cli/commands/start/command.js +2 -1
  30. package/npm-shrinkwrap.json +2 -2
  31. package/package.json +1 -1
package/dist/.env CHANGED
@@ -1,6 +1,6 @@
1
1
  BACKEND_SOLANA_ADDRESS=7rFPFnxjXHC2sfDy3qrDa9pEb4j49oivMuV7e8sYDPmB
2
2
  FRP_SERVER_IMAGE=registry.hub.docker.com/nosana/frpc:v1.0.45
3
- JOB_RUNTIME_IMAGE="nosana/job-runtime:v0.3.5"
3
+ JOB_RUNTIME_IMAGE="nosana/job-runtime:v0.3.6"
4
4
  GOLDEN_VM_IMAGE=https://models.nosana.io/golden-vm/cuda13-580-dev-2/golden-vm-cuda13-580-dev-2.qcow2
5
5
  RESOURCE_MANAGER_IMAGE=registry.hub.docker.com/nosana/resource-manager:v1.1.19
6
6
  FRP_SERVER_PORT=7000
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.1.94-rc",
3
+ "version": "1.1.95-rc",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "nosana-node": "./dist/src/index.js"
@@ -11,6 +11,8 @@ export interface VmSpec {
11
11
  gpus: string[];
12
12
  /** The disk size in MiB, capped by the space free; undefined: sized from the free space. */
13
13
  diskMiB?: number;
14
+ /** Booted as an AMD SEV-SNP guest, its memory encrypted (`--cvm`); a plain VM otherwise. */
15
+ confidential?: boolean;
14
16
  }
15
17
  /**
16
18
  * Parse a memory/disk size into MiB. A bare number is already MiB; a string may
@@ -22,12 +22,13 @@ export interface QemuOptions {
22
22
  apiHostPort?: number;
23
23
  /** Guest CID of a virtio-vsock device, the guest's `host.sock` channel; none when omitted. */
24
24
  guestCid?: number;
25
- /** OVMF/UEFI firmware, booted only when GPUs are passed through (see firmwareArgs). */
25
+ /** OVMF/UEFI firmware, booted by a confidential VM or one with GPUs (see firmwareArgs). */
26
26
  biosPath?: string;
27
27
  }
28
28
  /**
29
29
  * The `qemu-system-x86_64` argument vector for a {@link VmSpec}, its GPUs attached as VFIO
30
- * passthrough devices. Pure, so the whole QEMU command surface is unit-testable; the
31
- * hypervisor picks the binary and applies NUMA pinning at spawn.
30
+ * passthrough devices, as an AMD SEV-SNP guest when the spec is confidential. Pure, so the
31
+ * whole QEMU command surface is unit-testable; the hypervisor picks the binary and applies
32
+ * NUMA pinning at spawn. Throws for a confidential VM without firmware: it can only boot OVMF.
32
33
  */
33
34
  export declare function buildQemuArgs(spec: VmSpec, paths: QemuPaths, opts?: QemuOptions): string[];
@@ -6,20 +6,36 @@ export const DEFAULT_ACCEL = 'kvm';
6
6
  const MACHINE = 'q35';
7
7
  /** CPU model. 'host' passes the host CPU through (needed under KVM). */
8
8
  const CPU_MODEL = 'host';
9
+ /**
10
+ * The SEV-SNP launch of a confidential VM. Every SNP-capable EPYC (Zen 3 and later) puts the
11
+ * memory-encryption bit at 51 and reduces the physical address width by 1; the policy is SNP's
12
+ * required bit 17 with SMT allowed (bit 16), 0x30000.
13
+ */
14
+ const SEV_SNP_GUEST = `sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1,policy=${0x30000}`;
15
+ /**
16
+ * A confidential guest's memory is private by default, and a virtio device may only DMA into
17
+ * pages the guest shared: `iommu_platform=on` routes its DMA through the guest's DMA API, which
18
+ * shares them, `disable-legacy=on` makes it a modern virtio device and `romfile=` drops its
19
+ * option ROM. Without them a confidential VM with a GPU passed through aborts at boot ("Failed
20
+ * to notify the listener the state change to shared").
21
+ */
22
+ const CONFIDENTIAL_VIRTIO_PROPS = ',iommu_platform=on,disable-legacy=on,romfile=';
9
23
  /**
10
24
  * The `qemu-system-x86_64` argument vector for a {@link VmSpec}, its GPUs attached as VFIO
11
- * passthrough devices. Pure, so the whole QEMU command surface is unit-testable; the
12
- * hypervisor picks the binary and applies NUMA pinning at spawn.
25
+ * passthrough devices, as an AMD SEV-SNP guest when the spec is confidential. Pure, so the
26
+ * whole QEMU command surface is unit-testable; the hypervisor picks the binary and applies
27
+ * NUMA pinning at spawn. Throws for a confidential VM without firmware: it can only boot OVMF.
13
28
  */
14
29
  export function buildQemuArgs(spec, paths, opts = {}) {
15
30
  const { accel = DEFAULT_ACCEL, apiHostPort, guestCid, biosPath } = opts;
31
+ const virtioProps = spec.confidential ? CONFIDENTIAL_VIRTIO_PROPS : '';
16
32
  return [
17
33
  ...machineArgs(spec, accel),
18
- ...firmwareArgs(biosPath, spec.gpus),
19
- ...diskArgs(paths),
20
- ...networkArgs(apiHostPort),
34
+ ...firmwareArgs(biosPath, spec),
35
+ ...diskArgs(paths, virtioProps),
36
+ ...networkArgs(apiHostPort, virtioProps),
21
37
  ...consoleArgs(paths),
22
- ...vsockArgs(guestCid),
38
+ ...vsockArgs(guestCid, virtioProps),
23
39
  ...vfioArgs(spec.gpus),
24
40
  ];
25
41
  }
@@ -27,12 +43,17 @@ export function buildQemuArgs(spec, paths, opts = {}) {
27
43
  * Machine, CPU and memory, headless: `-display none` with the console on a
28
44
  * socket (see consoleArgs) rather than `-nographic`, which would multiplex
29
45
  * serial and monitor onto stdio. `-no-reboot` makes a guest `poweroff` exit
30
- * QEMU instead of rebooting.
46
+ * QEMU instead of rebooting. A confidential VM's machine is backed by the
47
+ * SEV-SNP launch object.
31
48
  */
32
49
  function machineArgs(spec, accel) {
50
+ const machine = spec.confidential
51
+ ? `${MACHINE},accel=${accel},confidential-guest-support=sev0`
52
+ : `${MACHINE},accel=${accel}`;
53
+ const confidentialGuest = spec.confidential ? ['-object', SEV_SNP_GUEST] : [];
33
54
  return [
34
55
  '-machine',
35
- `${MACHINE},accel=${accel}`,
56
+ machine,
36
57
  '-cpu',
37
58
  CPU_MODEL,
38
59
  '-smp',
@@ -42,30 +63,51 @@ function machineArgs(spec, accel) {
42
63
  '-display',
43
64
  'none',
44
65
  '-no-reboot',
66
+ ...confidentialGuest,
45
67
  ];
46
68
  }
47
69
  /**
48
70
  * A GPU VM boots UEFI (OVMF): the q35 default (SeaBIOS) can't place several
49
71
  * large 64-bit GPU BARs, so only ~2 of N GPUs initialise, while OVMF sizes the
50
- * 64-bit MMIO window to fit them all. A VM without GPUs keeps the default
72
+ * 64-bit MMIO window to fit them all. A confidential VM boots OVMF, which runs
73
+ * the SEV-SNP launch, with or without GPUs. Any other VM keeps the default
51
74
  * firmware, so a BIOS-only image boots as before.
52
75
  */
53
- function firmwareArgs(biosPath, gpus) {
54
- if (!biosPath || gpus.length === 0)
76
+ function firmwareArgs(biosPath, spec) {
77
+ if (spec.confidential) {
78
+ if (!biosPath)
79
+ throw new Error('a confidential VM boots OVMF firmware, and this host has none');
80
+ return ['-bios', biosPath];
81
+ }
82
+ if (!biosPath || spec.gpus.length === 0)
55
83
  return [];
56
84
  return ['-bios', biosPath];
57
85
  }
58
86
  /**
59
87
  * The root disk and the cloud-init seed. The overlay bypasses the host page
60
88
  * cache (cache=none): the guest already caches its own disk, and a host copy
61
- * of every guest write only competes with guest RAM for memory.
89
+ * of every guest write only competes with guest RAM for memory. A confidential
90
+ * VM's disks carry `virtioProps`, which the `if=virtio` shorthand cannot, so
91
+ * they are spelled out as a drive and its virtio-blk device.
62
92
  */
63
- function diskArgs(paths) {
93
+ function diskArgs(paths, virtioProps) {
94
+ if (!virtioProps) {
95
+ return [
96
+ '-drive',
97
+ `file=${paths.overlay},if=virtio,format=qcow2,cache=none`,
98
+ '-drive',
99
+ `file=${paths.seedIso},if=virtio,format=raw,readonly=on`,
100
+ ];
101
+ }
64
102
  return [
65
103
  '-drive',
66
- `file=${paths.overlay},if=virtio,format=qcow2,cache=none`,
104
+ `file=${paths.overlay},if=none,id=disk0,format=qcow2,cache=none`,
105
+ '-device',
106
+ `virtio-blk-pci,drive=disk0${virtioProps}`,
67
107
  '-drive',
68
- `file=${paths.seedIso},if=virtio,format=raw,readonly=on`,
108
+ `file=${paths.seedIso},if=none,id=seed,format=raw,readonly=on`,
109
+ '-device',
110
+ `virtio-blk-pci,drive=seed${virtioProps}`,
69
111
  ];
70
112
  }
71
113
  /**
@@ -75,11 +117,16 @@ function diskArgs(paths) {
75
117
  * nowhere on an IPv4-only host, so a lookup that returns only AAAA fails as
76
118
  * "network is unreachable" instead of using IPv4.
77
119
  */
78
- function networkArgs(apiHostPort) {
120
+ function networkArgs(apiHostPort, virtioProps) {
79
121
  const hostfwd = apiHostPort === undefined
80
122
  ? ''
81
123
  : `,hostfwd=tcp:127.0.0.1:${apiHostPort}-:${JOB_RUNTIME_GUEST_PORT}`;
82
- return ['-netdev', `user,id=net0,ipv6=off${hostfwd}`, '-device', 'virtio-net-pci,netdev=net0'];
124
+ return [
125
+ '-netdev',
126
+ `user,id=net0,ipv6=off${hostfwd}`,
127
+ '-device',
128
+ `virtio-net-pci,netdev=net0${virtioProps}`,
129
+ ];
83
130
  }
84
131
  /** The guest serial console on the socket VmStateManager streams, and the QMP socket. */
85
132
  function consoleArgs(paths) {
@@ -93,10 +140,10 @@ function consoleArgs(paths) {
93
140
  ];
94
141
  }
95
142
  /** virtio-vsock: the guest bridges its `host.sock` out to the host (CID 2), no network involved. */
96
- function vsockArgs(guestCid) {
143
+ function vsockArgs(guestCid, virtioProps) {
97
144
  if (guestCid === undefined)
98
145
  return [];
99
- return ['-device', `vhost-vsock-pci,guest-cid=${guestCid}`];
146
+ return ['-device', `vhost-vsock-pci,guest-cid=${guestCid}${virtioProps}`];
100
147
  }
101
148
  /**
102
149
  * GPU passthrough via the iommufd backend: one shared iommufd object, then a
@@ -7,6 +7,7 @@ export interface VmHostAccess {
7
7
  kvmDevice: string;
8
8
  vsockDevice: string;
9
9
  iommufdDevice: string;
10
+ sevDevice: string;
10
11
  /** Where the kernel puts each vfio-pci device's node (`/dev/vfio/devices`). */
11
12
  vfioDevicesDir: string;
12
13
  /** Whether the node's user may access `file` in `mode` (fs.constants R_OK, W_OK, X_OK). */
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs';
2
- import { IOMMUFD_DEVICE, KVM_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from '../hostDevices.js';
2
+ import { IOMMUFD_DEVICE, KVM_DEVICE, SEV_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from '../hostDevices.js';
3
3
  import { readMemlockLimit } from '../memlockLimit.js';
4
4
  /** The real host, as the node's user. */
5
5
  export function defaultVmHostAccess() {
@@ -9,6 +9,7 @@ export function defaultVmHostAccess() {
9
9
  kvmDevice: KVM_DEVICE,
10
10
  vsockDevice: VSOCK_DEVICE,
11
11
  iommufdDevice: IOMMUFD_DEVICE,
12
+ sevDevice: SEV_DEVICE,
12
13
  vfioDevicesDir: VFIO_DEVICES_DIR,
13
14
  canAccess,
14
15
  memlockLimitBytes: () => readMemlockLimit(),
@@ -1,3 +1,5 @@
1
1
  import { type VmHostAccess } from './VmHostAccess.js';
2
2
  /** What stops the user from opening the devices every VM needs: KVM and vhost-vsock. */
3
3
  export declare function deviceProblems(host: VmHostAccess): string[];
4
+ /** What stops the user from opening the SEV device a confidential VM's launch needs. */
5
+ export declare function sevDeviceProblems(host: VmHostAccess): string[];
@@ -15,3 +15,10 @@ export function deviceProblems(host) {
15
15
  }
16
16
  return problems;
17
17
  }
18
+ /** What stops the user from opening the SEV device a confidential VM's launch needs. */
19
+ export function sevDeviceProblems(host) {
20
+ if (!fs.existsSync(host.sevDevice)) {
21
+ return [`${host.sevDevice} is missing: load kvm_amd with SEV-SNP enabled`];
22
+ }
23
+ return canOpen(host, host.sevDevice) ? [] : [cannotOpenMessage(host.sevDevice)];
24
+ }
@@ -3,7 +3,8 @@ import { type VmHostAccess } from './VmHostAccess.js';
3
3
  /**
4
4
  * What stops the node's user from booting VMs of `spec` under `workRoot`, one line each; none
5
5
  * when it can. Root may do anything here but find a device missing; a user needs the devices
6
- * QEMU opens, GPUs already on vfio-pci (binding them needs root), a locked-memory limit that
7
- * holds the guest's RAM, and to own what an earlier run left in the work root.
6
+ * QEMU opens (the SEV device too for a confidential VM), GPUs already on vfio-pci (binding them
7
+ * needs root), a locked-memory limit that holds the guest's RAM, and to own what an earlier run
8
+ * left in the work root.
8
9
  */
9
10
  export declare function findVmHostAccessProblems(spec: VmSpec, workRoot: string, host?: VmHostAccess): string[];
@@ -1,4 +1,4 @@
1
- import { deviceProblems } from './deviceProblems.js';
1
+ import { deviceProblems, sevDeviceProblems } from './deviceProblems.js';
2
2
  import { gpuProblems } from './gpuProblems.js';
3
3
  import { memlockProblems } from './memlockProblems.js';
4
4
  import { defaultVmHostAccess } from './VmHostAccess.js';
@@ -6,12 +6,19 @@ import { workRootProblems } from './workRootProblems.js';
6
6
  /**
7
7
  * What stops the node's user from booting VMs of `spec` under `workRoot`, one line each; none
8
8
  * when it can. Root may do anything here but find a device missing; a user needs the devices
9
- * QEMU opens, GPUs already on vfio-pci (binding them needs root), a locked-memory limit that
10
- * holds the guest's RAM, and to own what an earlier run left in the work root.
9
+ * QEMU opens (the SEV device too for a confidential VM), GPUs already on vfio-pci (binding them
10
+ * needs root), a locked-memory limit that holds the guest's RAM, and to own what an earlier run
11
+ * left in the work root.
11
12
  */
12
13
  export function findVmHostAccessProblems(spec, workRoot, host = defaultVmHostAccess()) {
13
14
  const gpuVmProblems = spec.gpus.length > 0
14
15
  ? [...gpuProblems(spec.gpus, host), ...memlockProblems(spec.memoryMiB, host)]
15
16
  : [];
16
- return [...deviceProblems(host), ...gpuVmProblems, ...workRootProblems(workRoot, host)];
17
+ const confidentialVmProblems = spec.confidential ? sevDeviceProblems(host) : [];
18
+ return [
19
+ ...deviceProblems(host),
20
+ ...confidentialVmProblems,
21
+ ...gpuVmProblems,
22
+ ...workRootProblems(workRoot, host),
23
+ ];
17
24
  }
@@ -4,6 +4,8 @@ export declare const SYSFS_PCI_ROOT = "/sys/bus/pci";
4
4
  export declare const KVM_DEVICE = "/dev/kvm";
5
5
  /** The vhost-vsock device behind the guest's vsock (see buildQemuArgs). */
6
6
  export declare const VSOCK_DEVICE = "/dev/vhost-vsock";
7
+ /** The AMD SEV device QEMU opens to launch a confidential (SEV-SNP) VM. */
8
+ export declare const SEV_DEVICE = "/dev/sev";
7
9
  /** The iommufd device QEMU's GPU passthrough opens (see buildQemuArgs). */
8
10
  export declare const IOMMUFD_DEVICE = "/dev/iommu";
9
11
  /** Where the kernel puts each vfio-pci device's node, which iommufd passthrough opens. */
@@ -4,6 +4,8 @@ export const SYSFS_PCI_ROOT = '/sys/bus/pci';
4
4
  export const KVM_DEVICE = '/dev/kvm';
5
5
  /** The vhost-vsock device behind the guest's vsock (see buildQemuArgs). */
6
6
  export const VSOCK_DEVICE = '/dev/vhost-vsock';
7
+ /** The AMD SEV device QEMU opens to launch a confidential (SEV-SNP) VM. */
8
+ export const SEV_DEVICE = '/dev/sev';
7
9
  /** The iommufd device QEMU's GPU passthrough opens (see buildQemuArgs). */
8
10
  export const IOMMUFD_DEVICE = '/dev/iommu';
9
11
  /** Where the kernel puts each vfio-pci device's node, which iommufd passthrough opens. */
@@ -23,3 +23,8 @@ export type RunSync = (command: string, args: string[]) => string;
23
23
  * run.
24
24
  */
25
25
  export declare function qemuSupportsIommufd(run?: RunSync): boolean;
26
+ /**
27
+ * Whether the host's QEMU can boot the confidential VMs: SEV-SNP with VFIO passthrough needs
28
+ * QEMU 9.2 or newer, read from `--version`. False when QEMU cannot run or names no version.
29
+ */
30
+ export declare function qemuSupportsSevSnp(run?: RunSync): boolean;
@@ -34,6 +34,28 @@ export function qemuSupportsIommufd(run = runSync) {
34
34
  return false;
35
35
  }
36
36
  }
37
+ /** The oldest QEMU that boots an SEV-SNP guest with a GPU passed through by VFIO. */
38
+ const MIN_SEV_SNP_QEMU = { major: 9, minor: 2 };
39
+ /**
40
+ * Whether the host's QEMU can boot the confidential VMs: SEV-SNP with VFIO passthrough needs
41
+ * QEMU 9.2 or newer, read from `--version`. False when QEMU cannot run or names no version.
42
+ */
43
+ export function qemuSupportsSevSnp(run = runSync) {
44
+ let banner;
45
+ try {
46
+ banner = run(QEMU_BINARY, ['--version']);
47
+ }
48
+ catch {
49
+ return false;
50
+ }
51
+ const match = /version (\d+)\.(\d+)/.exec(banner);
52
+ if (!match)
53
+ return false;
54
+ const [major, minor] = [Number(match[1]), Number(match[2])];
55
+ if (major !== MIN_SEV_SNP_QEMU.major)
56
+ return major > MIN_SEV_SNP_QEMU.major;
57
+ return minor >= MIN_SEV_SNP_QEMU.minor;
58
+ }
37
59
  function runSync(command, args) {
38
60
  return execFileSync(command, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
39
61
  }
@@ -3,10 +3,12 @@ export type { QemuHypervisorConfig, QemuHypervisorOptions, QemuHypervisorSystem,
3
3
  export { VmNotRunningError } from './Hypervisor.js';
4
4
  export type { Hypervisor, VmInstance, VmRecord, BootOptions } from './Hypervisor.js';
5
5
  export { HOST_VSOCK_PORT_BASE } from './vsockBridge.js';
6
- export { qemuSupportsIommufd, requiredHostTools } from './hostTools.js';
6
+ export { qemuSupportsIommufd, qemuSupportsSevSnp, requiredHostTools } from './hostTools.js';
7
+ export { hostHasSevSnp } from './sevSnp.js';
8
+ export { discoverUefiBios } from './firmware.js';
7
9
  export { findVmHostAccessProblems } from './hostAccess/index.js';
8
10
  export { bindGpusToVfio } from './vfioBinding.js';
9
- export { IOMMUFD_DEVICE, KVM_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from './hostDevices.js';
11
+ export { IOMMUFD_DEVICE, KVM_DEVICE, SEV_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from './hostDevices.js';
10
12
  export { missingVfioNodeMessage, readVfioDeviceNodes } from './pciSysfs.js';
11
13
  export { removeWorkDir, WORK_DIR_PREFIX, OVERLAY_FILE, VM_CONSOLE_LOG } from './workDirs.js';
12
14
  export { JOB_RUNTIME_GUEST_PORT } from './buildQemuArgs.js';
@@ -1,10 +1,12 @@
1
1
  export { QemuHypervisor } from './QemuHypervisor.js';
2
2
  export { VmNotRunningError } from './Hypervisor.js';
3
3
  export { HOST_VSOCK_PORT_BASE } from './vsockBridge.js';
4
- export { qemuSupportsIommufd, requiredHostTools } from './hostTools.js';
4
+ export { qemuSupportsIommufd, qemuSupportsSevSnp, requiredHostTools } from './hostTools.js';
5
+ export { hostHasSevSnp } from './sevSnp.js';
6
+ export { discoverUefiBios } from './firmware.js';
5
7
  export { findVmHostAccessProblems } from './hostAccess/index.js';
6
8
  export { bindGpusToVfio } from './vfioBinding.js';
7
- export { IOMMUFD_DEVICE, KVM_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from './hostDevices.js';
9
+ export { IOMMUFD_DEVICE, KVM_DEVICE, SEV_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from './hostDevices.js';
8
10
  export { missingVfioNodeMessage, readVfioDeviceNodes } from './pciSysfs.js';
9
11
  export { removeWorkDir, WORK_DIR_PREFIX, OVERLAY_FILE, VM_CONSOLE_LOG } from './workDirs.js';
10
12
  export { JOB_RUNTIME_GUEST_PORT } from './buildQemuArgs.js';
@@ -0,0 +1,9 @@
1
+ /** The kvm_amd parameter that reads `Y` while the host kernel runs SEV-SNP. */
2
+ export declare const SEV_SNP_PARAMETER = "/sys/module/kvm_amd/parameters/sev_snp";
3
+ /** Reads a file's text; throws when it cannot. */
4
+ export type ReadText = (file: string) => string;
5
+ /**
6
+ * Whether the host kernel runs AMD SEV-SNP, so it can launch confidential VMs: false on any
7
+ * other host (Intel, kvm_amd not loaded, SNP off in the BIOS or the kernel).
8
+ */
9
+ export declare function hostHasSevSnp(readText?: ReadText): boolean;
@@ -0,0 +1,15 @@
1
+ import { readFileSync } from 'fs';
2
+ /** The kvm_amd parameter that reads `Y` while the host kernel runs SEV-SNP. */
3
+ export const SEV_SNP_PARAMETER = '/sys/module/kvm_amd/parameters/sev_snp';
4
+ /**
5
+ * Whether the host kernel runs AMD SEV-SNP, so it can launch confidential VMs: false on any
6
+ * other host (Intel, kvm_amd not loaded, SNP off in the BIOS or the kernel).
7
+ */
8
+ export function hostHasSevSnp(readText = (file) => readFileSync(file, 'utf8')) {
9
+ try {
10
+ return readText(SEV_SNP_PARAMETER).trim() === 'Y';
11
+ }
12
+ catch {
13
+ return false;
14
+ }
15
+ }
@@ -8,6 +8,8 @@ import type { JobRuntimeEnvironment } from './JobRuntimeEnvironment.js';
8
8
  export interface JobRuntimeEnvironmentOptions extends VmNodeOptions {
9
9
  /** Run each job's runtime in a VM (`--vm`), not a container beside the node. */
10
10
  vm?: boolean;
11
+ /** Boot those VMs as confidential (AMD SEV-SNP) guests (`--cvm`, which sets `vm` too). */
12
+ cvm?: boolean;
11
13
  /** Power cap in watts the guest applies to each GPU (`--gpu-power-limit`). */
12
14
  gpuPowerLimit?: number;
13
15
  }
@@ -21,6 +23,12 @@ export interface VmHostSystem {
21
23
  isOnPath: (binary: string) => boolean;
22
24
  /** Whether the host's QEMU can pass GPUs through (its iommufd backend, QEMU 9.0 or newer). */
23
25
  canPassGpus: () => boolean;
26
+ /** Whether the host kernel runs AMD SEV-SNP. */
27
+ hasSevSnp: () => boolean;
28
+ /** Whether the host's QEMU boots SEV-SNP guests with GPUs (QEMU 9.2 or newer). */
29
+ canBootSevSnp: () => boolean;
30
+ /** The OVMF firmware a confidential VM boots; undefined when the host has none. */
31
+ findUefiFirmware: () => string | undefined;
24
32
  /** Reads the VM every job boots from the node's limits and the host. */
25
33
  readVmSpec: typeof readVmSpec;
26
34
  /** What stops the node's user from booting the VMs under the work root; none when it can. */
@@ -43,8 +51,8 @@ export interface JobRuntimeEnvironmentDeps {
43
51
  }
44
52
  /**
45
53
  * Where this node runs its jobs' runtimes: a sidecar container beside the node by default, a
46
- * golden VM per job with `--vm`. Both composition roots (the node, `nosana node run`) choose
47
- * here. A `--vm` host that cannot boot a VM is refused now, with what it lacks, rather than at
48
- * its first job.
54
+ * golden VM per job with `--vm`, a confidential one with `--cvm`. Both composition roots (the
55
+ * node, `nosana node run`) choose here. A host that cannot boot those VMs is refused now, with
56
+ * what it lacks, rather than at its first job.
49
57
  */
50
58
  export declare function selectJobRuntimeEnvironment(options: JobRuntimeEnvironmentOptions, deps: JobRuntimeEnvironmentDeps): JobRuntimeEnvironment;
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { createVmImageResolver, findVmHostAccessProblems, KVM_DEVICE, QemuHypervisor, qemuSupportsIommufd, requiredHostTools, VM_IMAGE_CACHE_DIR, } from '../../../../packages/vm-orchestrator/src/index.js';
3
+ import { createVmImageResolver, discoverUefiBios, findVmHostAccessProblems, hostHasSevSnp, KVM_DEVICE, QemuHypervisor, qemuSupportsIommufd, qemuSupportsSevSnp, requiredHostTools, VM_IMAGE_CACHE_DIR, } from '../../../../packages/vm-orchestrator/src/index.js';
4
4
  import { configs } from '../../configs/configs.js';
5
5
  import { hasPciAddress, makeVmWorkRoot, readVmSpec, } from '../../provider/vmHost/index.js';
6
6
  import { getKit, nodeAddress } from '../../sdk/index.js';
@@ -9,9 +9,9 @@ import { ContainerJobRuntime } from './ContainerJobRuntime.js';
9
9
  import { VmJobRuntime } from './VmJobRuntime.js';
10
10
  /**
11
11
  * Where this node runs its jobs' runtimes: a sidecar container beside the node by default, a
12
- * golden VM per job with `--vm`. Both composition roots (the node, `nosana node run`) choose
13
- * here. A `--vm` host that cannot boot a VM is refused now, with what it lacks, rather than at
14
- * its first job.
12
+ * golden VM per job with `--vm`, a confidential one with `--cvm`. Both composition roots (the
13
+ * node, `nosana node run`) choose here. A host that cannot boot those VMs is refused now, with
14
+ * what it lacks, rather than at its first job.
15
15
  */
16
16
  export function selectJobRuntimeEnvironment(options, deps) {
17
17
  const { containerOrchestration, resourceManager } = deps;
@@ -26,6 +26,9 @@ export function selectJobRuntimeEnvironment(options, deps) {
26
26
  exists: fs.existsSync,
27
27
  isOnPath,
28
28
  canPassGpus: qemuSupportsIommufd,
29
+ hasSevSnp: () => hostHasSevSnp(),
30
+ canBootSevSnp: () => qemuSupportsSevSnp(),
31
+ findUefiFirmware: () => discoverUefiBios(),
29
32
  readVmSpec,
30
33
  findAccessProblems: findVmHostAccessProblems,
31
34
  makeVmWorkRoot,
@@ -36,9 +39,11 @@ export function selectJobRuntimeEnvironment(options, deps) {
36
39
  if (!settings.vm.image) {
37
40
  throw new Error('--vm needs GOLDEN_VM_IMAGE in .env: the golden image each job’s VM boots');
38
41
  }
39
- const spec = system.readVmSpec(options);
42
+ const nodeSpec = system.readVmSpec(options);
43
+ const spec = options.cvm ? { ...nodeSpec, confidential: true } : nodeSpec;
40
44
  assertVmToolsOnPath(spec, system);
41
45
  assertQemuCanPassGpus(spec, system);
46
+ assertCanLaunchConfidentialVms(spec, system);
42
47
  const workRoot = system.makeVmWorkRoot(deps.dataDir);
43
48
  assertCanBootVms(spec, workRoot, system);
44
49
  const host = { spec, workRoot, gpuPowerLimitWatts: options.gpuPowerLimit };
@@ -79,6 +84,25 @@ function assertQemuCanPassGpus(spec, system) {
79
84
  throw new Error('--vm needs QEMU 9.0 or newer to pass GPUs through (its iommufd backend); this host’s ' +
80
85
  'qemu-system-x86_64 has no iommufd: upgrade QEMU');
81
86
  }
87
+ /**
88
+ * A confidential VM needs a host kernel running SEV-SNP, the OVMF firmware that launches it, and
89
+ * a QEMU that boots it with GPUs passed through. Every gap is named at once.
90
+ */
91
+ function assertCanLaunchConfidentialVms(spec, system) {
92
+ if (!spec.confidential)
93
+ return;
94
+ const problems = [
95
+ ...(system.hasSevSnp()
96
+ ? []
97
+ : ['AMD SEV-SNP in the host kernel: enable it in the BIOS and in kvm_amd (sev_snp=Y)']),
98
+ ...(system.findUefiFirmware() ? [] : ['OVMF firmware: install the ovmf package']),
99
+ ...(system.canBootSevSnp() ? [] : ['QEMU 9.2 or newer: upgrade qemu-system-x86_64']),
100
+ ];
101
+ if (problems.length === 0)
102
+ return;
103
+ throw new Error('--cvm cannot launch confidential VMs on this host; it needs:\n' +
104
+ problems.map((problem) => ` - ${problem}`).join('\n'));
105
+ }
82
106
  /**
83
107
  * The node's user must be able to boot the VMs: open QEMU's devices, use GPUs already on
84
108
  * vfio-pci, lock the guest's RAM, and write the work root. Every gap is named at once.
@@ -18,6 +18,8 @@ export interface PrepareVmHostSystem {
18
18
  pciRoot: string;
19
19
  vsockDevice: string;
20
20
  iommufdDevice: string;
21
+ /** The SEV device a confidential VM's launch opens; present only on an SEV host. */
22
+ sevDevice: string;
21
23
  /** Where the kernel puts each vfio-pci device's node (`/dev/vfio/devices`). */
22
24
  vfioDevicesDir: string;
23
25
  /** The pam_limits file the user's memlock limit is written to. */
@@ -1,6 +1,6 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import fs from 'node:fs';
3
- import { bindGpusToVfio, IOMMUFD_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from '../../../../../packages/vm-orchestrator/src/index.js';
3
+ import { bindGpusToVfio, IOMMUFD_DEVICE, SEV_DEVICE, SYSFS_PCI_ROOT, VFIO_DEVICES_DIR, VSOCK_DEVICE, } from '../../../../../packages/vm-orchestrator/src/index.js';
4
4
  import { lookupGroupId, lookupUser } from './hostUser.js';
5
5
  import { MEMLOCK_LIMITS_FILE } from './memlockLimits.js';
6
6
  import { findSudoCaller } from './sudoCaller.js';
@@ -19,6 +19,7 @@ export function defaultPrepareVmHostSystem() {
19
19
  pciRoot: SYSFS_PCI_ROOT,
20
20
  vsockDevice: VSOCK_DEVICE,
21
21
  iommufdDevice: IOMMUFD_DEVICE,
22
+ sevDevice: SEV_DEVICE,
22
23
  vfioDevicesDir: VFIO_DEVICES_DIR,
23
24
  limitsFile: MEMLOCK_LIMITS_FILE,
24
25
  };
@@ -8,10 +8,11 @@ export interface PrepareVmHostOptions {
8
8
  configDir: string;
9
9
  }
10
10
  /**
11
- * Prepares the host, as root, for a `--vm` node run by `user`: puts the user in the kvm
12
- * group, moves the GPUs to vfio-pci, gives the kvm group QEMU's devices (vhost-vsock, iommufd,
13
- * the GPUs' VFIO nodes), lifts the user's locked-memory limit (VFIO pins the guest's RAM) and
14
- * hands the user the VM work root an earlier root run left. The binding and the devices'
11
+ * Prepares the host, as root, for a `--vm` or `--cvm` node run by `user`: puts the user in the
12
+ * kvm group, moves the GPUs to vfio-pci, gives the kvm group QEMU's devices (vhost-vsock,
13
+ * iommufd, the GPUs' VFIO nodes, and on an SEV host the SEV device), lifts the user's
14
+ * locked-memory limit (VFIO pins the guest's RAM) and hands the user the VM work root an
15
+ * earlier root run left. The binding and the devices'
15
16
  * modes last until reboot. Answers what it did, one line each.
16
17
  */
17
18
  export declare function prepareVmHost({ user, gpus, configDir }: PrepareVmHostOptions, system?: PrepareVmHostSystem): Promise<string[]>;
@@ -8,10 +8,11 @@ import { defaultPrepareVmHostSystem } from './PrepareVmHostSystem.js';
8
8
  /** The group given QEMU's devices; a user in it may boot VMs. */
9
9
  const KVM_GROUP = 'kvm';
10
10
  /**
11
- * Prepares the host, as root, for a `--vm` node run by `user`: puts the user in the kvm
12
- * group, moves the GPUs to vfio-pci, gives the kvm group QEMU's devices (vhost-vsock, iommufd,
13
- * the GPUs' VFIO nodes), lifts the user's locked-memory limit (VFIO pins the guest's RAM) and
14
- * hands the user the VM work root an earlier root run left. The binding and the devices'
11
+ * Prepares the host, as root, for a `--vm` or `--cvm` node run by `user`: puts the user in the
12
+ * kvm group, moves the GPUs to vfio-pci, gives the kvm group QEMU's devices (vhost-vsock,
13
+ * iommufd, the GPUs' VFIO nodes, and on an SEV host the SEV device), lifts the user's
14
+ * locked-memory limit (VFIO pins the guest's RAM) and hands the user the VM work root an
15
+ * earlier root run left. The binding and the devices'
15
16
  * modes last until reboot. Answers what it did, one line each.
16
17
  */
17
18
  export async function prepareVmHost({ user, gpus, configDir }, system = defaultPrepareVmHostSystem()) {
@@ -32,6 +33,9 @@ export async function prepareVmHost({ user, gpus, configDir }, system = defaultP
32
33
  done.push(...(await bindGpus(gpus, system)), ...liftMemlockLimit(account, system));
33
34
  devices.push(system.iommufdDevice, ...vfioNodes(gpus, system));
34
35
  }
36
+ // On an SEV host the user's node may launch confidential VMs (`--cvm`).
37
+ if (fs.existsSync(system.sevDevice))
38
+ devices.push(system.sevDevice);
35
39
  done.push(...grantDevices(devices, kvmGid, system));
36
40
  done.push(...handOverWorkRoot(account, configDir, system));
37
41
  return done;
@@ -1,6 +1,6 @@
1
1
  import { Argument, Command, Option } from 'commander';
2
2
  import { runJob } from './action.js';
3
- import { configOption, gpuOption, verboseOption, walletOption, coresOption, ramOption, diskOption, gpuPowerLimitOption, vmOption, } from '../sharedOptions/index.js';
3
+ import { configOption, gpuOption, verboseOption, walletOption, coresOption, ramOption, diskOption, gpuPowerLimitOption, vmOption, cvmOption, } from '../sharedOptions/index.js';
4
4
  export * from './action.js';
5
5
  export const runNodeCommand = new Command('run')
6
6
  .description('Run Job Definition File')
@@ -15,5 +15,6 @@ export const runNodeCommand = new Command('run')
15
15
  .addOption(diskOption)
16
16
  .addOption(gpuPowerLimitOption)
17
17
  .addOption(vmOption)
18
+ .addOption(cvmOption)
18
19
  .addOption(verboseOption)
19
20
  .action(runJob);
@@ -4,3 +4,8 @@ import { Option } from 'commander';
4
4
  * the job. Without it each job's runtime runs as a container on the host; with it, in a golden VM.
5
5
  */
6
6
  export declare const vmOption: Option;
7
+ /**
8
+ * `--cvm`: `--vm` with each job's golden VM booted as a confidential (AMD SEV-SNP) guest, its
9
+ * memory encrypted. A host that cannot launch one is refused at start.
10
+ */
11
+ export declare const cvmOption: Option;
@@ -4,3 +4,8 @@ import { Option } from 'commander';
4
4
  * the job. Without it each job's runtime runs as a container on the host; with it, in a golden VM.
5
5
  */
6
6
  export const vmOption = new Option('--vm', 'run this node’s jobs inside a golden VM');
7
+ /**
8
+ * `--cvm`: `--vm` with each job's golden VM booted as a confidential (AMD SEV-SNP) guest, its
9
+ * memory encrypted. A host that cannot launch one is refused at start.
10
+ */
11
+ export const cvmOption = new Option('--cvm', 'run this node’s jobs inside a confidential (AMD SEV-SNP) golden VM').implies({ vm: true });
@@ -1,6 +1,6 @@
1
1
  import { Command, Option } from 'commander';
2
2
  import { startNode } from './action.js';
3
- import { configOption, networkOption, portOption, rpcOption, walletOption, verboseOption, gpuOption, teeRuntimeOption, coresOption, ramOption, diskOption, gpuPowerLimitOption, vmOption, } from '../sharedOptions/index.js';
3
+ import { configOption, networkOption, portOption, rpcOption, walletOption, verboseOption, gpuOption, teeRuntimeOption, coresOption, ramOption, diskOption, gpuPowerLimitOption, vmOption, cvmOption, } from '../sharedOptions/index.js';
4
4
  export * from './action.js';
5
5
  export const startNodeCommand = new Command('start')
6
6
  .description('Start Nosana Node')
@@ -17,6 +17,7 @@ export const startNodeCommand = new Command('start')
17
17
  .addOption(diskOption)
18
18
  .addOption(gpuPowerLimitOption)
19
19
  .addOption(vmOption)
20
+ .addOption(cvmOption)
20
21
  .addOption(portOption)
21
22
  .addOption(verboseOption)
22
23
  .action(startNode);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.1.94-rc",
3
+ "version": "1.1.95-rc",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@nosana/node",
9
- "version": "1.1.94-rc",
9
+ "version": "1.1.95-rc",
10
10
  "license": "ISC",
11
11
  "workspaces": [
12
12
  "packages/*"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.1.94-rc",
3
+ "version": "1.1.95-rc",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "nosana-node": "./dist/src/index.js"