Commit graph

103 commits

Author SHA1 Message Date
Changyuan Lyu
3c241aa63e chore: bump version to 0.2.0
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-24 13:56:06 -07:00
Changyuan Lyu
82e2167873 fix(net): set dev feature bits based on the tap
TUN_F_USO4/TUN_F_USO6 were added in Linux 6.2.

There is no easy way to query the supported features from the tap
device, so similar to QEMU (tap_fd_set_offload() in net/tap-linux.c),
we try tun_set_offload() until success.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-24 13:46:01 -07:00
Changyuan Lyu
3571e91452 fix(kvm): use old KVM_GET_SREGS/KVM_SET_SREGS
For now we do not need the new features of
KVM_GET_SREGS2/KVM_SET_SREGS2. Use the old ioctls for better
compatibility.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-24 13:46:01 -07:00
Changyuan Lyu
17f33e6b68 feat(kvm)!: allow specifying char dev file paths
This enables Alioth to work in environments where the devtmpfs
is not mounted at /dev.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-24 13:46:01 -07:00
Changyuan Lyu
f88f290ab9 docs(sev): boot AMD-SEV guests with Oak/Stage0
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
5ad2ea658c feat(virtio): enable ACCESS_PLATFORM bits
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
04f01b350e feat(sev): add a flag for launching SEV guests
With all the preparation, SEV guests are ready to go,

* SEV guests: --coco sev,policy=0x1
* SEV-ES guests: --coco sev,policy=0x5

We still need to make virtio devices work with SEV guests.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
f968fcb0a8 feat(sev): set up AP registers for SEV-ES guests
This includes

* parse the firmware blob to get the AP EIP value
* set up AP registers based on the parsed EIP
* call sev_launch_update_vmsa before booting CPUs

Ref:
[1] QEMU hw/i386/pc_sysfw_ovmf.c
[2] QEMU docs/specs/sev-guest-firmware.rst
[3] https://github.com/project-oak/oak snp_measurement/src/stage0.rs

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
709829beb7 feat(sev): set up CPUID bits for SEV guests
For now PhysAddrReduction and CbitPosition is hardcoded to 1 and 51,
which is good for milan CPUs.

Ref: AMD64 Architecture Programmer's Manual Vol. 3, section E.4.17.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
d14a30be31 feat(sev): call SEV launch OPs in BSP thread
This includes

* sev_launch_start,
* sev_launch_update_data (called in firmware setup)
* sev_launch_measure,
* sev_launch_finish.

Ref:
[1] QEMU target/i386/sev.c
[2] AMD Secure Encrypted Virtualization API 0.24, 1.3 Guest Lifecycle

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
c8d9fb0833 feat(sev): update the firmware bytes with AMD PSP
This allows the guest to see the correct firmware blob instead
of some random bytes.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
9458fce313 feat(sev): register fw and RAM as encrypted
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
34135d3c43 feat(sev): add wrappers for SEV-related KVM ops
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
1dd5849d30 feat(sev)!: initialize SEV for confidential guest
This includes opening the sev char device file and issuing
KVM_SEV_INIT or KVM_SEV_ES_INIT command.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
ac106e00ff feat(sev): add AMD-SEV related bindings
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 23:10:49 -07:00
Changyuan Lyu
b091f5afd7 fix(net): add alias and default to param fields
This gives us the backward compatibility for command line options
like `--net if=test-tap,mac=aa:bb:cc:dd:ee:ff,mtu=1500`.

Fixes: 6a66b2d299 ("feat(cli)!: use serde-aco to parse cli options")

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 18:36:40 -07:00
Changyuan Lyu
6a66b2d299 feat(cli)!: use serde-aco to parse cli options
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 00:00:14 -07:00
Changyuan Lyu
6e97023603 feat(cli): add a new crate for parsing cli opts
`serde-aco` is for parsing complex data structures from command line.
Nested structures can be expressed by multiple key-value pair
strings.

This crate is inspired by QEMU's `-object` flag.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-22 00:00:14 -07:00
Changyuan Lyu
275ee66800 fix(pci): handle PCI BAR reprogramming
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-20 22:41:21 -07:00
Changyuan Lyu
f9ab67372b fix(pci): handle IO/MEM bits of config command
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-20 22:41:21 -07:00
dependabot[bot]
68c2688e4b ci: Bump actions/checkout from 4.1.5 to 4.1.6
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.5 to 4.1.6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](44c2b7a8a4...a5ac7e51b4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-17 08:38:40 -07:00
Changyuan Lyu
b3fef9c53d fix(serial): set the OPOST flag in termios attr
QEMU sets this flag in qemu_chr_set_echo_stdio() of
chardev/char-stdio.c.

With this bit set, the line breaks of the outputs from stage0 work
as expected.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-11 16:54:26 -07:00
Changyuan Lyu
50049516d6 feat(loader): support boot from stage0 firmware
Alioth is able to boot a Linux ELF kernel along with the stage0 [1]
firmware by

target/x86_64-unknown-linux-gnu/release/alioth \
    --log-to-file \
    run \
    --num-cpu 2 \
    --mem-size 1G \
    -f $HOME/data/oak_stage0.bin \
    --fw-cfg opt/stage0/elf_kernel,file=$HOME/data/vmlinuz-6.6.17.bin \
    --fw-cfg opt/stage0/initramfs,file=$HOME/data/initramfs.linux_amd64.cpio \
    --fw-cfg opt/stage0/cmdline,string="console=ttyS0"

[1] https://github.com/project-oak/oak/tree/main/stage0_bin

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-11 16:54:26 -07:00
Changyuan Lyu
8c63a87da5 feat(fw_cfg): plug the fw_cfg device into the VM
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-11 16:54:26 -07:00
Changyuan Lyu
f0e4524872 feat(fw_cfg): implement ACPI table loaders
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-11 16:54:26 -07:00
Changyuan Lyu
01ff8cf33f feat(dev): implement QEMU's fw_cfg device
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-11 16:54:26 -07:00
Changyuan Lyu
8a73625287 feat(acpi)!: create relocatable ACPI tables
Inspired by QEMU(hw/acpi/bios-linker-loader.c), build a relocatable
ACPI table. The `relocate()` method can update the checksums and
pointers in the table bytes.

This commit is a preparation for reusing the ACPI module in a future
QEMU fw_cfg device.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-11 16:54:26 -07:00
Changyuan Lyu
592f643ba8 fix(kvm): handle the pthread_t definition in musl
`pthread_t` is defined as `struct __pthread *` in musl[1] and
`unsigned long int` in glibc[2]. Use `as _` to let rust compiler do
the conversion.

[1] http://git.musl-libc.org/cgit/musl/tree/include/alltypes.h.in
[2] https://elixir.bootlin.com/glibc/latest/source/sysdeps/nptl/bits/pthreadtypes.h#L27

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-11 11:00:01 -07:00
Changyuan Lyu
981631841c fix(ioctl): use u32 as the type of request codes
From Linux doc[1]

> While this can be any 32-bit number that uniquely identifies an
> action for a particular driver, ...

However, the `ioctl` function is `int ioctl(int, unsigned long, ...)`
in glibc and `int ioctl(int, int, ...)` in musl libc.

This commit changes the type of request codes to `u32`, and when it
is passed to `ioctl`, use `as _` to let rust compiler do the
conversion.

[1] https://docs.kernel.org/driver-api/ioctl.html#command-number-definitions

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-11 11:00:01 -07:00
Changyuan Lyu
1b2829a0d0 feat(net): use a tun/tap interface as a backend
The current virtio-net implementation assumes the tap device path is
referring to a macvtap or ipvtap. This commit allows using a tun/tap
interface pre-created by `ip tuntap add mode tap $IF_NAME` as a
backend.

Usage:

```
--net if=$IF_NAME,mac=$IF_MAC,mtu=$IF_MTU
```

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-09 23:39:38 -07:00
dependabot[bot]
69d3d5d6d4 ci: Bump actions/checkout from 4.1.4 to 4.1.5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.4 to 4.1.5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](0ad4b8fada...44c2b7a8a4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-07 08:26:06 -07:00
Changyuan Lyu
01f5cac223 feat(block): impl raw file backed virtio-block dev
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
7f14a74c8b feat(virtio): impl tap-based net device
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
b3568fa1db feat(virtio): plug the entropy device into the VM
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
27a5d8bc90 feat(virtio): implement a virtio entropy device
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
7b2d918e9d fix(virtio/pci): wake up device on queue notify
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
064f237d58 feat(virtio/pci): impl a general virtio pci device
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
50b5ec55ca feat(pci): emulate read/write to MSI-X tables
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
391e5ec733 feat(mmio): impl Mmio for readonly zerocopy types
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
438fcfda5d feat(virtio/pci): handle device status init/reset
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
f8b6f9ca7f feat(virtio/pci): mmio of queue/config msix vector
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
21211f459a feat(virtio): forward data from reader / to writer
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
bd56123919 feat(virtio): implement split queue operations
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
3aa60e2d32 fix(mem)!: remove redundant Result of lock_layout
Fixes: b44bb87b87 ("feat!: use RwLock and Mutex from parking_lot")

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
b4b9dc07aa feat(virtio): skeleton of a general virtio device
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
2d346d3820 feat(virtio): skeleton of a split queue
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
b905804d66 feat(virtio): MSI-X based IRQ sender
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
488e47f0b1 feat(kvm): inject interrupts by KVM_SIGNAL_MSI
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
3178e57a64 feat(virtio): mmio to virtio PCI capabilities
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00
Changyuan Lyu
a18f19d8a2 feat(virtio): traits for virtio devices and queues
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2024-05-06 00:25:28 -07:00