Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/parts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ jobs:
# before it is released and not after, when the release has no traceable kernel and no
# ledger (#558). Its own cache tag, written by main as the release kernel's is, keeps
# release.yml's job warm. ~10 min more cold (parts run 45071066129); the version only names
# the bzImage, which nothing here publishes.
# the vmlinux, which nothing here publishes.
- name: Build the traceable kernel
env:
CACHE_EXPORT: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
Expand Down
2 changes: 1 addition & 1 deletion cmd/spin-machine-dev/lab.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func probeNames(probes map[string]lab.Probe) string {
// treeFlags are a tree spec's flags, the same for lab tree and inside a --tree NAME=SPEC.
func treeFlags(fs *pflag.FlagSet, s *lab.TreeSpec) {
fs.StringVar(&s.From, "from", "release", "what the tree starts from: release, release:vYYYYMMDD.NN, or a directory laid out as one (_output)")
fs.StringVar(&s.Kernel, "kernel", "", "the kernel instead: run:N (a parts.yml run), traceable:TAG (the lab-only kernel published beside release TAG, lockdown forced to none) or a bzImage")
fs.StringVar(&s.Kernel, "kernel", "", "the kernel instead: run:N (a parts.yml run), traceable:TAG (the lab-only kernel published beside release TAG, lockdown forced to none), or a vmlinux that randomizes itself or a bzImage")
fs.StringVar(&s.QEMU, "qemu", "", "QEMU and its firmware instead: run:N (a parts.yml run) or a directory with bin/ and qemu/")
fs.StringVar(&s.SpinMachine, "spin-machine", "", "here: built from this checkout; release: built from the commit the --from release was made from, the machine it defined; commit:SHA: built from that commit; left out, the --from tree's own when it has one, else this checkout's (a release ships none)")
fs.StringVar(&s.Append, "append", "", "added to the kernel command line of every boot")
Expand Down
16 changes: 9 additions & 7 deletions cmd/spin-machine-dev/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ func releaseTraceableKernelCmd() *cobra.Command {
Long: `Build the release's kernel (as build kernel does, into _output) and a second one from the same
source and config with lockdown forced to none instead of confidentiality, into _output/traceable,
then hold the second's config to the first's: that one option swapped and every other as the
release has it. Its bzImage is put in _output/release as the release's traceable kernel, to be
signed and published beside the release for the lab's ledger, which reads a scheduler trace that
lockdown takes away (kernel/README.md). It enters no tarball and nothing spin boots.`,
release has it. Its vmlinux, which build verified as the release's (both Xen notes and a filled
.data.reloc), is put in _output/release as the release's traceable kernel, to be signed and
published beside the release for the lab's ledger, which reads a scheduler trace that lockdown
takes away (kernel/README.md), and boots it through PVH as the release boots its own (#697). It
enters no tarball and nothing spin boots.`,
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, _ []string) error {
w, err := open()
Expand All @@ -188,11 +190,11 @@ lockdown takes away (kernel/README.md). It enters no tarball and nothing spin bo
if err := build.TraceableConfig(filepath.Join(o.Out, "kernel", "kernel-config"), filepath.Join(t.Out, "kernel", "kernel-config")); err != nil {
return couldNot(err)
}
to := filepath.Join(w.out, "release", release.TraceableKernel(version))
to := filepath.Join(w.out, "release", release.TraceableVmlinux(version))
if err := os.MkdirAll(filepath.Dir(to), 0o755); err != nil {
return couldNot(fmt.Errorf("making %s: %w", filepath.Dir(to), err))
}
if err := copyFile(filepath.Join(t.Out, "kernel", "bzImage"), to); err != nil {
if err := copyFile(filepath.Join(t.Out, "kernel", "vmlinux"), to); err != nil {
return couldNot(err)
}
say(c, "✓ %s", to)
Expand Down Expand Up @@ -419,7 +421,7 @@ func sign(ctx context.Context, c *cobra.Command, dir, predicate, identity string
"--certificate-identity", identity, "--certificate-oidc-issuer", release.OIDCIssuer)
}
var files []string
for _, g := range []string{"*.tar.gz", "*.tar.gz.sha256", "machine.env", "*.cdx.json", release.TraceableKernel("*")} {
for _, g := range []string{"*.tar.gz", "*.tar.gz.sha256", "machine.env", "*.cdx.json", release.TraceableVmlinux("*")} {
found, _ := filepath.Glob(filepath.Join(dir, g))
files = append(files, found...)
}
Expand Down Expand Up @@ -451,7 +453,7 @@ func sign(ctx context.Context, c *cobra.Command, dir, predicate, identity string
}
for _, g := range []struct{ require, except []string }{
{[]string{"provenance"}, nil},
{[]string{"cdx"}, []string{"*.sha256", "machine.env", "*.cdx.json", release.TraceableKernel("*")}},
{[]string{"cdx"}, []string{"*.sha256", "machine.env", "*.cdx.json", release.TraceableVmlinux("*")}},
} {
missing, err := attestgate.Files(dir, g.require, g.except)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/spin-machine-dev/verbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func printfEscaped(b []byte) string {
func TestTheTraceableKernelIsTheReleaseKernelLessLockdown(t *testing.T) {
dir := checkout(t)
put(t, filepath.Join(dir, "kernel/Dockerfile"), "FROM x", 0o644)
published := filepath.Join(dir, "_output/release", release.TraceableKernel("v1"))
published := filepath.Join(dir, "_output/release", release.TraceableVmlinux("v1"))
calls := fakes(t, map[string]string{"docker": kernelDocker("")})
if _, stderr, status := verb(t, "release", "traceable-kernel", "--version", "v1"); status != 0 {
t.Fatalf("exit %d: %s", status, stderr)
Expand All @@ -238,10 +238,10 @@ func TestTheTraceableKernelIsTheReleaseKernelLessLockdown(t *testing.T) {
if !strings.Contains(got, "KERNEL_LOCKDOWN=confidentiality") || !strings.Contains(got, "KERNEL_LOCKDOWN=none --build-arg KERNEL_NPROC=8 --output type=local,dest="+filepath.Join(dir, "_output/traceable")+" ") {
t.Errorf("docker was not asked for both kernels:\n%s", got)
}
if read(t, published) != read(t, filepath.Join(dir, "_output/traceable/kernel/bzImage")) {
if read(t, published) != read(t, filepath.Join(dir, "_output/traceable/kernel/vmlinux")) {
t.Error("the traceable kernel was not put beside the release")
}
if _, err := os.Stat(filepath.Join(dir, "_output/kernel/bzImage")); err != nil {
if _, err := os.Stat(filepath.Join(dir, "_output/kernel/vmlinux")); err != nil {
t.Errorf("the release kernel was not built: %v", err)
}
_ = os.Remove(published)
Expand Down Expand Up @@ -698,7 +698,7 @@ func TestProvenanceIsRefusedOutsideAWorkflow(t *testing.T) {
func TestSignChecksEveryBundleAndThatNothingIsLeftUnattested(t *testing.T) {
dir := checkout(t)
rel := filepath.Join(dir, "_output/release")
for _, f := range []string{"r.tar.gz", "r.tar.gz.sha256", "machine.env", "r.cdx.json", release.TraceableKernel("v1")} {
for _, f := range []string{"r.tar.gz", "r.tar.gz.sha256", "machine.env", "r.cdx.json", release.TraceableVmlinux("v1")} {
put(t, filepath.Join(rel, f), f, 0o644)
}
// cosign writes each bundle it is asked for.
Expand Down
11 changes: 10 additions & 1 deletion docs/measuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ published beside release TAG, lab-only: the release's source and config with
the release kernel's (#536). Releases before the first one built with it have none. `releases
measure` takes one ledger of each release on it, beside its boot chart, and its record keeps it as
`docs/releases/TAG-ledger.txt`.

**It boots the way the release boots.** A release from #697 on publishes its traceable kernel as
a vmlinux that randomizes itself, verified as the release's is, and the tree boots it through
PVH as the release boots its own. Up to v20261123.07 it was a bzImage, and `traceable:TAG` still
fetches that for those releases. So the ledgers of v20261123.07 and of every release after it
until #697 booted through a decompressor their release no longer ran, and their window before the
kernel's clock reads ~20 ms long. The tree's manifest names the kernel and how the machine
enters it, and the ledger names that window by it.
`--append` takes `lab.LedgerAppend` as it stands in internal/lab/ledgerprobe.go: the scheduler's
tracepoints from the kernel's start, on CLOCK_MONOTONIC, into a 2 MiB buffer that drops what
does not fit rather than the boot.
Expand Down Expand Up @@ -282,7 +290,8 @@ trace lost events. A switch away from a task the CPU was not running counts as a
So the span before the kernel's clock is three parts, which add up to `kernel_zero` by
construction: `before_qemu`, spin-machine to its exec of QEMU; `qemu_start`, QEMU's start and the
held start's monitor to the guest's first instruction; and `guest_to_zero`, the firmware, the
bzImage's decompression and the kernel's setup until its clock runs. A sched offset that puts the
kernel's entry (through PVH, or a bzImage's decompression) and the kernel's setup until its clock
runs. A sched offset that puts the
machine's running before QEMU's exec refuses the ledger, as a journal without the line does.
`kernel_zero` read 97 to 114 ms in six boots, the first the longest (lab 45110630795, bench,
spin's shape, v20261123.04, 2026-11-23):
Expand Down
2 changes: 1 addition & 1 deletion internal/lab/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Compat(here string, tags []string, src Sources, resume func(previous, previ
if err != nil {
return nil, err
}
if !fileExists(filepath.Join(dir, partFiles["kernel"])) {
if !fileExists(filepath.Join(dir, "kernel", "bzImage")) {
rows = append(rows, CompatRow{Release: tag, NoBzImage: true})
break
}
Expand Down
8 changes: 5 additions & 3 deletions internal/lab/lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strconv"
"strings"
"testing"

"github.com/spin-stack/machine/machine"
)

// TestEveryProbeMeasuresATree is the VM lane: every probe once over a tree made from a built
Expand Down Expand Up @@ -135,12 +137,12 @@ func TestTheLabTalksToGitHub(t *testing.T) {
}
// A release's traceable kernel, its signature checked: from the first release built with one.
if tag := os.Getenv("SPIN_LAB_TRACEABLE"); tag != "" {
bz, err := src.traceable(tag)
k, err := src.traceable(tag)
if err != nil {
t.Fatal(err)
}
if err := isBzImage(bz); err != nil {
t.Fatal(err)
if machine.PVH(k) != nil && isBzImage(k) != nil {
t.Fatalf("%s is neither a vmlinux the machine enters through PVH nor a bzImage", k)
}
}
if id := os.Getenv("SPIN_LAB_RUN"); id != "" {
Expand Down
16 changes: 12 additions & 4 deletions internal/lab/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Ledger struct {
FirstLogin float64 `json:"first_login"`
// KernelZero is where the kernel's clock read 0 on the host's, and KernelZeroError half the
// width of the narrowest bracket the trips gave it: before it is QEMU, the firmware and the
// kernel's decompression, which no clock in the guest sees.
// kernel's entry (a bzImage's decompression, or PVH's), which no clock in the guest sees.
KernelZero float64 `json:"kernel_zero"`
KernelZeroError float64 `json:"kernel_zero_error"`
// QEMUExec is where spin-machine exec'd QEMU, and QEMUExecError half the bracket the host's
Expand All @@ -42,9 +42,13 @@ type Ledger struct {
// Running is where the machine went to running and its vCPU ran the guest's first instruction:
// KernelZero less the kvm-clock the kernel read as it made kvm-clock the scheduler's clock, which
// QEMU zeroed at that moment (schedOffset). From QEMUExec to Running is QEMU's start and the held
// start's monitor; from Running to KernelZero, the firmware, the bzImage's decompression and the
// kernel's setup until its clock runs.
// start's monitor; from Running to KernelZero, the firmware, the kernel's entry and its setup
// until its clock runs.
Running float64 `json:"running"`
// PVH is whether the machine entered a vmlinux through PVH, with no decompressor (#645), and not
// a bzImage: what the time from Running to KernelZero holds. A ledger from before #697 has
// none, and booted a bzImage.
PVH bool `json:"pvh,omitempty"`
// LoginEnd is the login's command's exit on the kernel's clock: where the trace's account ends.
LoginEnd float64 `json:"login_end"`
// Residue is FirstLogin less KernelZero and LoginEnd: what the host waited for after the
Expand Down Expand Up @@ -685,7 +689,11 @@ func (l Ledger) Text(title string) string {
fmt.Fprintf(&b, "%8s %8s %8.1f before the kernel's clock (±%.2f)\n", "", "0.0", l.KernelZero, l.KernelZeroError)
fmt.Fprintf(&b, "%26.1f spin-machine, to its exec of QEMU (±%.2f)\n", l.QEMUExec, l.QEMUExecError)
fmt.Fprintf(&b, "%26.1f QEMU's start and the held start, to the guest's first instruction\n", l.Running-l.QEMUExec)
fmt.Fprintf(&b, "%26.1f the firmware, the decompression and the kernel's setup, to the kernel's clock\n", l.KernelZero-l.Running)
entry := "the firmware, the decompression and the kernel's setup, to the kernel's clock"
if l.PVH {
entry = "the firmware, the kernel's PVH entry and its setup, to the kernel's clock"
}
fmt.Fprintf(&b, "%26.1f %s\n", l.KernelZero-l.Running, entry)
for _, w := range l.Windows {
fmt.Fprintf(&b, "%8.1f %8.1f %8.1f %s\n", w.Start, w.End, w.End-w.Start, w.Name)
var rest float64
Expand Down
5 changes: 5 additions & 0 deletions internal/lab/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ func TestTheLedgersTextShowsWhatMatters(t *testing.T) {
if strings.Contains(text, "quiet") || strings.Contains(text, " d 9.6") || strings.Count(text, "others under") != 1 {
t.Errorf("the table shows what it should leave out:\n%s", text)
}
// A boot that entered a vmlinux through PVH ran no decompressor, and the window says so.
l.PVH = true
if pvh := l.Text("t"); !strings.Contains(pvh, " 20.0 the firmware, the kernel's PVH entry and its setup, to the kernel's clock\n") || strings.Contains(pvh, "decompression") {
t.Errorf("a PVH boot's window before the kernel's clock:\n%s", pvh)
}
bare := Ledger{Windows: l.Windows[:1]}.Text("t")
if strings.Contains(bare, "owners from") || strings.Contains(bare, "in the journal") || strings.Contains(bare, "lost events") {
t.Errorf("a ledger of one window, no marks and no breaks:\n%s", bare)
Expand Down
11 changes: 9 additions & 2 deletions internal/lab/ledgerprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"time"

xssh "golang.org/x/crypto/ssh"

"github.com/spin-stack/machine/machine"
)

// ledgerName is the edit a tree carries to be accounted for, and the probe that accounts for it.
Expand Down Expand Up @@ -132,11 +134,11 @@ func (ledgerProbe) Needs(o Options) []Need {
func (ledgerProbe) Metrics() []Metric {
return []Metric{
{"first_login", "ms", "the first login, /usr/bin/true, from the moment before QEMU is exec'd, with the trace running"},
{"kernel_zero", "ms", "where the kernel's clock read 0, from the same moment: QEMU, the firmware and the kernel's decompression"},
{"kernel_zero", "ms", "where the kernel's clock read 0, from the same moment: QEMU, the firmware and the kernel's entry"},
{"kernel_zero_error", "ms", "kernel_zero's uncertainty, half its narrowest bracket"},
{"before_qemu", "ms", "kernel_zero's first part: spin-machine, from the same moment to its exec of QEMU"},
{"qemu_start", "ms", "kernel_zero's second part: QEMU's start and the held start, from its exec to the guest's first instruction"},
{"guest_to_zero", "ms", "kernel_zero's third part: the firmware, the bzImage's decompression and the kernel's setup, to the kernel's clock"},
{"guest_to_zero", "ms", "kernel_zero's third part: the firmware, the kernel's entry (through PVH, or a bzImage's decompression) and its setup, to the kernel's clock"},
{"qemu_exec_error", "ms", "before_qemu's uncertainty, half the bracket the host's polling put QEMU's exec in"},
{"pid1", "ms", "PID 1's exec of init, on the kernel's clock"},
{"handoff", "ms", "spin's handoff as login=spin stands in for it, from its exec as PID 1 to its exec of systemd; 0 on the lane"},
Expand Down Expand Up @@ -165,6 +167,10 @@ func (ledgerProbe) Measure(_ context.Context, m *Measurement) error {
if m.Keep == "" {
return fmt.Errorf("the ledger probe keeps its ledgers, and the experiment names no directory to keep them in")
}
kernel, err := m.Tree.Kernel()
if err != nil {
return err
}
overlay, err := m.Overlay("overlay.qcow2", m.Key.Edits()...)
if err != nil {
return err
Expand Down Expand Up @@ -244,6 +250,7 @@ func (ledgerProbe) Measure(_ context.Context, m *Measurement) error {
if err != nil {
return Miss("no ledger, %d events dropped by the buffer: %v", dropped, err)
}
l.PVH = machine.PVH(kernel) == nil
b, err := json.MarshalIndent(l, "", " ")
if err != nil {
return fmt.Errorf("writing the ledger: %w", err)
Expand Down
Loading