Skip to content
Snippets Groups Projects
  1. Mar 23, 2021
  2. Mar 22, 2021
    • Marian Postevca's avatar
      acpi: Move setters/getters of oem fields to X86MachineState · d07b2286
      Marian Postevca authored
      
      The code that sets/gets oem fields is duplicated in both PC and MICROVM
      variants. This commit moves it to X86MachineState so that all x86
      variants can use it and duplication is removed.
      
      Signed-off-by: default avatarMarian Postevca <posteuca@mutex.one>
      Message-Id: <20210221001737.24499-2-posteuca@mutex.one>
      Reviewed-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      d07b2286
    • David Hildenbrand's avatar
      acpi: Set proper maximum size for "etc/acpi/rsdp" blob · 50337286
      David Hildenbrand authored
      
      Let's also set a maximum size for "etc/acpi/rsdp", so the maximum
      size doesn't get implicitly set based on the initial table size. In my
      experiments, the table size was in the range of 22 bytes, so a single
      page (== what we used until now) seems to be good enough.
      
      Now that we have defined maximum sizes for all currently used table types,
      let's assert that we catch usage with new tables that need a proper maximum
      size definition.
      
      Also assert that our initial size does not exceed the maximum size; while
      qemu_ram_alloc_internal() properly asserts that the initial RAMBlock size
      is <= its maximum size, the result might differ when the host page size
      is bigger than 4k.
      
      Suggested-by: default avatarLaszlo Ersek <lersek@redhat.com>
      Cc: Alistair Francis <alistair.francis@xilinx.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Igor Mammedov <imammedo@redhat.com>
      Cc: Peter Maydell <peter.maydell@linaro.org>
      Cc: Shannon Zhao <shannon.zhaosl@gmail.com>
      Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Richard Henderson <richard.henderson@linaro.org>
      Cc: Laszlo Ersek <lersek@redhat.com>
      Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Message-Id: <20210304105554.121674-5-david@redhat.com>
      Reviewed-by: default avatarLaszlo Ersek <lersek@redhat.com>
      Reviewed-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      50337286
    • David Hildenbrand's avatar
      acpi: Move maximum size logic into acpi_add_rom_blob() · 6930ba0d
      David Hildenbrand authored
      
      We want to have safety margins for all tables based on the table type.
      Let's move the maximum size logic into acpi_add_rom_blob() and make it
      dependent on the table name, so we don't have to replicate for each and
      every instance that creates such tables.
      
      Suggested-by: default avatarLaszlo Ersek <lersek@redhat.com>
      Cc: Alistair Francis <alistair.francis@xilinx.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Igor Mammedov <imammedo@redhat.com>
      Cc: Peter Maydell <peter.maydell@linaro.org>
      Cc: Shannon Zhao <shannon.zhaosl@gmail.com>
      Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Richard Henderson <richard.henderson@linaro.org>
      Cc: Laszlo Ersek <lersek@redhat.com>
      Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Message-Id: <20210304105554.121674-4-david@redhat.com>
      Reviewed-by: default avatarLaszlo Ersek <lersek@redhat.com>
      Reviewed-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      6930ba0d
    • David Hildenbrand's avatar
      microvm: Don't open-code "etc/table-loader" · 2a3bdc5c
      David Hildenbrand authored
      
      Let's just reuse ACPI_BUILD_LOADER_FILE.
      
      Cc: Alistair Francis <alistair.francis@xilinx.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Igor Mammedov <imammedo@redhat.com>
      Cc: Peter Maydell <peter.maydell@linaro.org>
      Cc: Shannon Zhao <shannon.zhaosl@gmail.com>
      Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Richard Henderson <richard.henderson@linaro.org>
      Cc: Laszlo Ersek <lersek@redhat.com>
      Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Message-Id: <20210304105554.121674-3-david@redhat.com>
      Reviewed-by: default avatarLaszlo Ersek <lersek@redhat.com>
      Reviewed-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      2a3bdc5c
    • David Hildenbrand's avatar
      acpi: Set proper maximum size for "etc/table-loader" blob · 6c2b24d1
      David Hildenbrand authored
      
      The resizeable memory region / RAMBlock that is created for the cmd blob
      has a maximum size of whole host pages (e.g., 4k), because RAMBlocks
      work on full host pages. In addition, in i386 ACPI code:
        acpi_align_size(tables->linker->cmd_blob, ACPI_BUILD_ALIGN_SIZE);
      makes sure to align to multiples of 4k, padding with 0.
      
      For example, if our cmd_blob is created with a size of 2k, the maximum
      size is 4k - we cannot grow beyond that. Growing might be required
      due to guest action when rebuilding the tables, but also on incoming
      migration.
      
      This automatic generation of the maximum size used to be sufficient,
      however, there are cases where we cross host pages now when growing at
      runtime: we exceed the maximum size of the RAMBlock and can crash QEMU when
      trying to resize the resizeable memory region / RAMBlock:
        $ build/qemu-system-x86_64 --enable-kvm \
            -machine q35,nvdimm=on \
            -smp 1 \
            -cpu host \
            -m size=2G,slots=8,maxmem=4G \
            -object memory-backend-file,id=mem0,mem-path=/tmp/nvdimm,size=256M \
            -device nvdimm,label-size=131072,memdev=mem0,id=nvdimm0,slot=1 \
            -nodefaults \
            -device vmgenid \
            -device intel-iommu
      
      Results in:
        Unexpected error in qemu_ram_resize() at ../softmmu/physmem.c:1850:
        qemu-system-x86_64: Size too large: /rom@etc/table-loader:
          0x2000 > 0x1000: Invalid argument
      
      In this configuration, we consume exactly 4k (32 entries, 128 bytes each)
      when creating the VM. However, once the guest boots up and maps the MCFG,
      we also create the MCFG table and end up consuming 2 additional entries
      (pointer + checksum) -- which is where we try resizing the memory region
      / RAMBlock, however, the maximum size does not allow for it.
      
      Currently, we get the following maximum sizes for our different
      mutable tables based on behavior of resizeable RAMBlock:
      
        hw       table                max_size
        -------  ---------------------------------------------------------
      
        virt     "etc/acpi/tables"    ACPI_BUILD_TABLE_MAX_SIZE (0x200000)
        virt     "etc/table-loader"   HOST_PAGE_ALIGN(initial_size)
        virt     "etc/acpi/rsdp"      HOST_PAGE_ALIGN(initial_size)
      
        i386     "etc/acpi/tables"    ACPI_BUILD_TABLE_MAX_SIZE (0x200000)
        i386     "etc/table-loader"   HOST_PAGE_ALIGN(initial_size)
        i386     "etc/acpi/rsdp"      HOST_PAGE_ALIGN(initial_size)
      
        microvm  "etc/acpi/tables"    ACPI_BUILD_TABLE_MAX_SIZE (0x200000)
        microvm  "etc/table-loader"   HOST_PAGE_ALIGN(initial_size)
        microvm  "etc/acpi/rsdp"      HOST_PAGE_ALIGN(initial_size)
      
      Let's set the maximum table size for "etc/table-loader" to 64k, so we
      can properly grow at runtime, which should be good enough for the future.
      
      Migration is not concerned with the maximum size of a RAMBlock, only
      with the used size - so existing setups are not affected. Of course, we
      cannot migrate a VM that would have crash when started on older QEMU from
      new QEMU to older QEMU without failing early on the destination when
      synchronizing the RAM state:
          qemu-system-x86_64: Size too large: /rom@etc/table-loader: 0x2000 > 0x1000: Invalid argument
          qemu-system-x86_64: error while loading state for instance 0x0 of device 'ram'
          qemu-system-x86_64: load of migration failed: Invalid argument
      
      We'll refactor the code next, to make sure we get rid of this implicit
      behavior for "etc/acpi/rsdp" as well and to make the code easier to
      grasp.
      
      Reviewed-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Cc: Alistair Francis <alistair.francis@xilinx.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Igor Mammedov <imammedo@redhat.com>
      Cc: Peter Maydell <peter.maydell@linaro.org>
      Cc: Shannon Zhao <shannon.zhaosl@gmail.com>
      Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Richard Henderson <richard.henderson@linaro.org>
      Cc: Laszlo Ersek <lersek@redhat.com>
      Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Message-Id: <20210304105554.121674-2-david@redhat.com>
      Reviewed-by: default avatarLaszlo Ersek <lersek@redhat.com>
      Reviewed-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      6c2b24d1
Loading