[Qemu-devel] [PATCH 0/4] Introduce the microvm machine type

Sergio Lopez posted 4 patches 4 years, 11 months ago
Test checkpatch failed
Test s390x failed
Test asan passed
Test docker-mingw@fedora passed
Test FreeBSD passed
Test docker-clang@ubuntu passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20190628115349.60293-1-slp@redhat.com
Maintainers: Eduardo Habkost <ehabkost@redhat.com>, Richard Henderson <rth@twiddle.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
There is a newer version of this series
default-configs/i386-softmmu.mak            |   1 +
hw/i386/Kconfig                             |   4 +
hw/i386/Makefile.objs                       |   2 +
hw/i386/cpu.c                               | 174 +++++++
hw/i386/microvm.c                           | 518 ++++++++++++++++++++
hw/i386/mptable.c                           | 157 ++++++
hw/i386/pc.c                                | 151 +-----
hw/i386/pc_piix.c                           |   3 +-
hw/i386/pc_q35.c                            |   3 +-
hw/virtio/virtio-mmio.c                     |  35 +-
hw/virtio/virtio-mmio.h                     |  60 +++
include/hw/i386/apic.h                      |   1 +
include/hw/i386/cpu-internal.h              |  32 ++
include/hw/i386/microvm.h                   |  85 ++++
include/hw/i386/mptable.h                   |  37 ++
include/standard-headers/linux/mpspec_def.h | 182 +++++++
16 files changed, 1264 insertions(+), 181 deletions(-)
create mode 100644 hw/i386/cpu.c
create mode 100644 hw/i386/microvm.c
create mode 100644 hw/i386/mptable.c
create mode 100644 hw/virtio/virtio-mmio.h
create mode 100644 include/hw/i386/cpu-internal.h
create mode 100644 include/hw/i386/microvm.h
create mode 100644 include/hw/i386/mptable.h
create mode 100644 include/standard-headers/linux/mpspec_def.h
[Qemu-devel] [PATCH 0/4] Introduce the microvm machine type
Posted by Sergio Lopez 4 years, 11 months ago
Microvm is a machine type inspired by both NEMU and Firecracker, and
constructed after the machine model implemented by the latter.

It's main purpose is providing users a KVM-only machine type with fast
boot times, minimal attack surface (measured as the number of IO ports
and MMIO regions exposed to the Guest) and small footprint (specially
when combined with the ongoing QEMU modularization effort).

Normally, other than the device support provided by KVM itself,
microvm only supports virtio-mmio devices. Microvm also includes a
legacy mode, which adds an ISA bus with a 16550A serial port, useful
for being able to see the early boot kernel messages.

This is the list of the exposed IO ports and MMIO regions when running
in non-legacy mode:

address-space: memory
    00000000d0000000-00000000d00001ff (prio 0, i/o): virtio-mmio
    00000000d0000200-00000000d00003ff (prio 0, i/o): virtio-mmio
    00000000d0000400-00000000d00005ff (prio 0, i/o): virtio-mmio
    00000000d0000600-00000000d00007ff (prio 0, i/o): virtio-mmio
    00000000d0000800-00000000d00009ff (prio 0, i/o): virtio-mmio
    00000000d0000a00-00000000d0000bff (prio 0, i/o): virtio-mmio
    00000000d0000c00-00000000d0000dff (prio 0, i/o): virtio-mmio
    00000000d0000e00-00000000d0000fff (prio 0, i/o): virtio-mmio
    00000000fee00000-00000000feefffff (prio 4096, i/o): kvm-apic-msi

address-space: I/O
  0000000000000000-000000000000ffff (prio 0, i/o): io
    0000000000000020-0000000000000021 (prio 0, i/o): kvm-pic
    0000000000000040-0000000000000043 (prio 0, i/o): kvm-pit
    000000000000007e-000000000000007f (prio 0, i/o): kvmvapic
    00000000000000a0-00000000000000a1 (prio 0, i/o): kvm-pic
    00000000000004d0-00000000000004d0 (prio 0, i/o): kvm-elcr
    00000000000004d1-00000000000004d1 (prio 0, i/o): kvm-elcr

A QEMU instance with the microvm machine type can be invoked this way:

 - Normal mode:

qemu-system-x86_64 -M microvm -m 512m -smp 2 \
 -kernel vmlinux -append "console=hvc0 root=/dev/vda" \
 -nodefaults -no-user-config \
 -chardev pty,id=virtiocon0,server \
 -device virtio-serial-device \
 -device virtconsole,chardev=virtiocon0 \
 -drive id=test,file=test.img,format=raw,if=none \
 -device virtio-blk-device,drive=test \
 -netdev tap,id=tap0,script=no,downscript=no \
 -device virtio-net-device,netdev=tap0

 - Legacy mode:

qemu-system-x86_64 -M microvm,legacy -m 512m -smp 2 \
 -kernel vmlinux -append "console=ttyS0 root=/dev/vda" \
 -nodefaults -no-user-config \
 -drive id=test,file=test.img,format=raw,if=none \
 -device virtio-blk-device,drive=test \
 -netdev tap,id=tap0,script=no,downscript=no \
 -device virtio-net-device,netdev=tap0 \
 -serial stdio


Sergio Lopez (4):
  hw/i386: Factorize CPU routine
  hw/virtio: Factorize virtio-mmio headers
  hw/i386: Add an Intel MPTable generator
  hw/i386: Introduce the microvm machine type

 default-configs/i386-softmmu.mak            |   1 +
 hw/i386/Kconfig                             |   4 +
 hw/i386/Makefile.objs                       |   2 +
 hw/i386/cpu.c                               | 174 +++++++
 hw/i386/microvm.c                           | 518 ++++++++++++++++++++
 hw/i386/mptable.c                           | 157 ++++++
 hw/i386/pc.c                                | 151 +-----
 hw/i386/pc_piix.c                           |   3 +-
 hw/i386/pc_q35.c                            |   3 +-
 hw/virtio/virtio-mmio.c                     |  35 +-
 hw/virtio/virtio-mmio.h                     |  60 +++
 include/hw/i386/apic.h                      |   1 +
 include/hw/i386/cpu-internal.h              |  32 ++
 include/hw/i386/microvm.h                   |  85 ++++
 include/hw/i386/mptable.h                   |  37 ++
 include/standard-headers/linux/mpspec_def.h | 182 +++++++
 16 files changed, 1264 insertions(+), 181 deletions(-)
 create mode 100644 hw/i386/cpu.c
 create mode 100644 hw/i386/microvm.c
 create mode 100644 hw/i386/mptable.c
 create mode 100644 hw/virtio/virtio-mmio.h
 create mode 100644 include/hw/i386/cpu-internal.h
 create mode 100644 include/hw/i386/microvm.h
 create mode 100644 include/hw/i386/mptable.h
 create mode 100644 include/standard-headers/linux/mpspec_def.h

--
2.21.0

Re: [Qemu-devel] [PATCH 0/4] Introduce the microvm machine type
Posted by Paolo Bonzini 4 years, 11 months ago
On 28/06/19 13:53, Sergio Lopez wrote:
> qemu-system-x86_64 -M microvm,legacy -m 512m -smp 2 \
>  -kernel vmlinux -append "console=ttyS0 root=/dev/vda" \
>  -nodefaults -no-user-config \
>  -drive id=test,file=test.img,format=raw,if=none \
>  -device virtio-blk-device,drive=test \
>  -netdev tap,id=tap0,script=no,downscript=no \
>  -device virtio-net-device,netdev=tap0 \
>  -serial stdio

I think the "non-legacy" mode can be obtained from the "legacy" one just
with -nodefaults (which all sane management should be using anyway), so
legacy=on can actually be the default. :)

I think this is interesting.  I'd love to have it optionally provide a
device tree as well.  It's not very common on x86 and most distro
kernels don't support device tree, but it would provide a more
out-of-the-box experience and it may even be a drop-in replacement for
q35 or pc as far as Kata is concerned.

Paolo

Re: [Qemu-devel] [PATCH 0/4] Introduce the microvm machine type
Posted by Sergio Lopez 4 years, 11 months ago
Paolo Bonzini <pbonzini@redhat.com> writes:

> On 28/06/19 13:53, Sergio Lopez wrote:
>> qemu-system-x86_64 -M microvm,legacy -m 512m -smp 2 \
>>  -kernel vmlinux -append "console=ttyS0 root=/dev/vda" \
>>  -nodefaults -no-user-config \
>>  -drive id=test,file=test.img,format=raw,if=none \
>>  -device virtio-blk-device,drive=test \
>>  -netdev tap,id=tap0,script=no,downscript=no \
>>  -device virtio-net-device,netdev=tap0 \
>>  -serial stdio
>
> I think the "non-legacy" mode can be obtained from the "legacy" one just
> with -nodefaults (which all sane management should be using anyway), so
> legacy=on can actually be the default. :)

I'm a bit confused here. The "legacy" boolean property in the microvm
machine type is used to indicate that QEMU should instantiate an i8259
PIC and an ISA bus (mainly to have easy access to "isa-serial"), instead
of relying on KVM's LAPIC+IOAPIC exclusively.

> I think this is interesting.  I'd love to have it optionally provide a
> device tree as well.  It's not very common on x86 and most distro
> kernels don't support device tree, but it would provide a more
> out-of-the-box experience and it may even be a drop-in replacement for
> q35 or pc as far as Kata is concerned.

I guess generating a dtb and having the kernel parse it will eat some
valuable microseconds but, as you say, it may be a good idea adding it
in the future, as long it's optional.

Sergio.
Re: [Qemu-devel] [PATCH 0/4] Introduce the microvm machine type
Posted by no-reply@patchew.org 4 years, 11 months ago
Patchew URL: https://patchew.org/QEMU/20190628115349.60293-1-slp@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190628115349.60293-1-slp@redhat.com
Type: series
Subject: [Qemu-devel] [PATCH 0/4] Introduce the microvm machine type

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Switched to a new branch 'test'
7ea633c hw/i386: Introduce the microvm machine type
df613e2 hw/i386: Add an Intel MPTable generator
a4046b8 hw/virtio: Factorize virtio-mmio headers
6fc3cc5 hw/i386: Factorize CPU routine

=== OUTPUT BEGIN ===
1/4 Checking commit 6fc3cc5db6b1 (hw/i386: Factorize CPU routine)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#51: 
new file mode 100644

WARNING: Block comments use a leading /* on a separate line
#102: FILE: hw/i386/cpu.c:47:
+/* Calculates initial APIC ID for a specific CPU index

WARNING: Block comments should align the * on each line
#155: FILE: hw/i386/cpu.c:100:
+         * -smp hasn't been parsed after it
+        */

ERROR: line over 90 characters
#168: FILE: hw/i386/cpu.c:113:
+        ms->possible_cpus->cpus[i].arch_id = cpu_apicid_from_index(i, compat_apic_id_mode);

WARNING: Block comments use a leading /* on a separate line
#214: FILE: hw/i386/cpu.c:159:
+    /* Calculates the limit to CPU APIC ID values

total: 1 errors, 4 warnings, 438 lines checked

Patch 1/4 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/4 Checking commit a4046b824588 (hw/virtio: Factorize virtio-mmio headers)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#66: 
new file mode 100644

total: 0 errors, 1 warnings, 105 lines checked

Patch 2/4 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/4 Checking commit df613e2dbf51 (hw/i386: Add an Intel MPTable generator)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#16: 
new file mode 100644

total: 0 errors, 1 warnings, 376 lines checked

Patch 3/4 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
4/4 Checking commit 7ea633c1e39e (hw/i386: Introduce the microvm machine type)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#60: 
new file mode 100644

WARNING: line over 80 characters
#198: FILE: hw/i386/microvm.c:134:
+    object_property_add_child(qdev_get_machine(), "ioapic", OBJECT(ioapic_dev), NULL);

WARNING: line over 80 characters
#208: FILE: hw/i386/microvm.c:144:
+    mms->gsi = qemu_allocate_irqs(microvm_gsi_handler, ioapic_irq, IOAPIC_NUM_PINS);

ERROR: consider using qemu_strtol in preference to strtol
#300: FILE: hw/i386/microvm.c:236:
+    index = strtol(separator + 1, NULL, 10);

ERROR: line over 90 characters
#318: FILE: hw/i386/microvm.c:254:
+static void microvm_setup_bootparams(MicrovmMachineState *mms, const gchar *kernel_cmdline)

WARNING: line over 80 characters
#344: FILE: hw/i386/microvm.c:280:
+                gchar *mmio_cmdline = microvm_get_virtio_mmio_cmdline(mmio_bus->name);

ERROR: that open brace { should be on the previous line
#414: FILE: hw/i386/microvm.c:350:
+    struct SegmentCache seg_code =
+        { .selector = 0x8, .base = 0x0, .limit = 0xfffff, .flags = 0xa09b00 };

ERROR: that open brace { should be on the previous line
#416: FILE: hw/i386/microvm.c:352:
+    struct SegmentCache seg_data =
+        { .selector = 0x10, .base = 0x0, .limit = 0xfffff, .flags = 0xc09300 };

ERROR: that open brace { should be on the previous line
#418: FILE: hw/i386/microvm.c:354:
+    struct SegmentCache seg_tr =
+        { .selector = 0x18, .base = 0x0, .limit = 0xfffff, .flags = 0x808b00 };

WARNING: Block comments use a leading /* on a separate line
#487: FILE: hw/i386/microvm.c:423:
+        /* Reset APIC after devices have been reset to cancel

ERROR: space prohibited between function name and open parenthesis '('
#567: FILE: hw/i386/microvm.c:503:
+    mc->default_cpu_type = X86_CPU_TYPE_NAME ("host");

total: 6 errors, 5 warnings, 624 lines checked

Patch 4/4 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190628115349.60293-1-slp@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
Re: [Qemu-devel] [PATCH 0/4] Introduce the microvm machine type
Posted by no-reply@patchew.org 4 years, 11 months ago
Patchew URL: https://patchew.org/QEMU/20190628115349.60293-1-slp@redhat.com/



Hi,

This series failed build test on s390x host. Please find the details below.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with
# HEAD pointing to a commit that has the patches applied on top of "base"
# branch
set -e

echo
echo "=== ENV ==="
env

echo
echo "=== PACKAGES ==="
rpm -qa

echo
echo "=== UNAME ==="
uname -a

CC=$HOME/bin/cc
INSTALL=$PWD/install
BUILD=$PWD/build
mkdir -p $BUILD $INSTALL
SRC=$PWD
cd $BUILD
$SRC/configure --cc=$CC --prefix=$INSTALL
make -j4
# XXX: we need reliable clean up
# make check -j4 V=1
make install
=== TEST SCRIPT END ===

  CC      i386-softmmu/hw/i386/microvm.o
  CC      aarch64-softmmu/hw/misc/exynos4210_rng.o
  CC      lm32-softmmu/gdbstub.o
/var/tmp/patchew-tester-tmp-kt7629bk/src/hw/i386/microvm.c:43:10: fatal error: asm/bootparam.h: No such file or directory
   43 | #include <asm/bootparam.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.


The full log is available at
http://patchew.org/logs/20190628115349.60293-1-slp@redhat.com/testing.s390x/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com