Skip to content
Snippets Groups Projects
  1. Sep 12, 2023
  2. Sep 11, 2023
    • Stefan Hajnoczi's avatar
      Merge tag 'pull-vfio-20230911' of https://github.com/legoater/qemu into staging · 9ef49775
      Stefan Hajnoczi authored
      vfio queue:
      
      * Small downtime optimisation for VFIO migration
      * P2P support for VFIO migration
      * Introduction of a save_prepare() handler to fail VFIO migration
      * Fix on DMA logging ranges calculation for OVMF enabling dynamic window
      
      # -----BEGIN PGP SIGNATURE-----
      #
      # iQIzBAABCAAdFiEEoPZlSPBIlev+awtgUaNDx8/77KEFAmT+uZQACgkQUaNDx8/7
      # 7KGFSw//UIqSet6MUxZZh/t7yfNFUTnxx6iPdChC3BphBaDDh99FCQrw5mPZ8ImF
      # 4rz0cIwSaHXraugEsC42TDaGjEmcAmYD0Crz+pSpLU21nKtYyWtZy6+9kyYslMNF
      # bUq0UwD0RGTP+ZZi6GBy1hM30y/JbNAGeC6uX8kyJRuK5Korfzoa/X5h+B2XfouW
      # 78G1mARHq5eOkGy91+rAJowdjqtkpKrzkfCJu83330Bb035qAT/PEzGs5LxdfTla
      # ORNqWHy3W+d8ZBicBQ5vwrk6D5JIZWma7vdXJRhs1wGO615cuyt1L8nWLFr8klW5
      # MJl+wM7DZ6UlSODq7r839GtSuWAnQc2j7JKc+iqZuBBk1v9fGXv2tZmtuTGkG2hN
      # nYXSQfuq1igu1nGVdxJv6WorDxsK9wzLNO2ckrOcKTT28RFl8oCDNSPPTKpwmfb5
      # i5RrGreeXXqRXIw0VHhq5EqpROLjAFwE9tkJndO8765Ag154plxssaKTUWo5wm7/
      # kjQVuRuhs5nnMXfL9ixLZkwD1aFn5fWAIaR0psH5vGD0fnB1Pba+Ux9ZzHvxp5D8
      # Kg3H6dKlht6VXdQ/qb0Up1LXCGEa70QM6Th2iO924ydZkkmqrSj+CFwGHvBsINa4
      # 89fYd77nbRbdwWurj3JIznJYVipau2PmfbjZ/jTed4RxjBQ+fPA=
      # =44e0
      # -----END PGP SIGNATURE-----
      # gpg: Signature made Mon 11 Sep 2023 02:54:12 EDT
      # gpg:                using RSA key A0F66548F04895EBFE6B0B6051A343C7CFFBECA1
      # gpg: Good signature from "Cédric Le Goater <clg@redhat.com>" [unknown]
      # gpg:                 aka "Cédric Le Goater <clg@kaod.org>" [unknown]
      # gpg: WARNING: This key is not certified with a trusted signature!
      # gpg:          There is no indication that the signature belongs to the owner.
      # Primary key fingerprint: A0F6 6548 F048 95EB FE6B  0B60 51A3 43C7 CFFB ECA1
      
      * tag 'pull-vfio-20230911' of https://github.com/legoater/qemu
      
      :
        vfio/common: Separate vfio-pci ranges
        vfio/migration: Block VFIO migration with background snapshot
        vfio/migration: Block VFIO migration with postcopy migration
        migration: Add .save_prepare() handler to struct SaveVMHandlers
        migration: Move more initializations to migrate_init()
        vfio/migration: Fail adding device with enable-migration=on and existing blocker
        migration: Add migration prefix to functions in target.c
        vfio/migration: Allow migration of multiple P2P supporting devices
        vfio/migration: Add P2P support for VFIO migration
        vfio/migration: Refactor PRE_COPY and RUNNING state checks
        qdev: Add qdev_add_vm_change_state_handler_full()
        sysemu: Add prepare callback to struct VMChangeStateEntry
        vfio/migration: Move from STOP_COPY to STOP in vfio_save_cleanup()
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      9ef49775
    • Stefan Hajnoczi's avatar
      Merge tag 'pull-riscv-to-apply-20230911' of https://github.com/alistair23/qemu into staging · cb6c406e
      Stefan Hajnoczi authored
      First RISC-V PR for 8.2
      
       * Remove 'host' CPU from TCG
       * riscv_htif Fixup printing on big endian hosts
       * Add zmmul isa string
       * Add smepmp isa string
       * Fix page_check_range use in fault-only-first
       * Use existing lookup tables for MixColumns
       * Add RISC-V vector cryptographic instruction set support
       * Implement WARL behaviour for mcountinhibit/mcounteren
       * Add Zihintntl extension ISA string to DTS
       * Fix zfa fleq.d and fltq.d
       * Fix upper/lower mtime write calculation
       * Make rtc variable names consistent
       * Use abi type for linux-user target_ucontext
       * Add RISC-V KVM AIA Support
       * Fix riscv,pmu DT node path in the virt machine
       * Update CSR bits name for svadu extension
       * Mark zicond non-experimental
       * Fix satp_mode_finalize() when satp_mode.supported = 0
       * Fix non-KVM --enable-debug build
       * Add new extensions to hwprobe
       * Use accelerated helper for AES64KS1I
       * Allocate itrigger timers only once
       * Respect mseccfg.RLB for pmpaddrX changes
       * Align the AIA model to v1.0 ratified spec
       * Don't read the CSR in riscv_csrrw_do64
      
      # -----BEGIN PGP SIGNATURE-----
      #
      # iQIzBAABCAAdFiEEaukCtqfKh31tZZKWr3yVEwxTgBMFAmT+ttMACgkQr3yVEwxT
      # gBN/rg/+KhOvL9xWSNb8pzlIsMQHLvndno0Sq5b9Rb/o5z1ekyYfyg6712N3JJpA
      # TIfZzOIW7oYZV8gHyaBtOt8kIbrjwzGB2rpCh4blhm+yNZv7Ym9Ko6AVVzoUDo7k
      # 2dWkLnC+52/l3SXGeyYMJOlgUUsQMwjD6ykDEr42P6DfVord34fpTH7ftwSasO9K
      # 35qJQqhUCgB3fMzjKTYICN6Rm1UluijTjRNXUZXC0XZlr+UKw2jT/UsybbWVXyNs
      # SmkRtF1MEVGvw+b8XOgA/nG1qVCWglTMcPvKjWMY+cY9WLM6/R9nXAV8OL/JPead
      # v1LvROJNukfjNtDW6AOl5/svOJTRLbIrV5EO7Hlm1E4kftGmE5C+AKZZ/VT4ucUK
      # XgqaHoXh26tFEymVjzbtyFnUHNv0zLuGelTnmc5Ps1byLSe4lT0dBaJy6Zizg0LE
      # DpTR7s3LpyV3qB96Xf9bOMaTPsekUjD3dQI/3X634r36+YovRXapJDEDacN9whbU
      # BSZc20NoM5UxVXFTbELQXolue/X2BRLxpzB+BDG8/cpu/MPgcCNiOZaVrr/pOo33
      # 6rwwrBhLSCfYAXnJ52qTUEBz0Z/FnRPza8AU/uuRYRFk6JhUXIonmO6xkzsoNKuN
      # QNnih/v1J+1XqUyyT2InOoAiTotzHiWgKZKaMfAhomt2j/slz+A=
      # =aqcx
      # -----END PGP SIGNATURE-----
      # gpg: Signature made Mon 11 Sep 2023 02:42:27 EDT
      # gpg:                using RSA key 6AE902B6A7CA877D6D659296AF7C95130C538013
      # gpg: Good signature from "Alistair Francis <alistair@alistair23.me>" [unknown]
      # gpg: WARNING: This key is not certified with a trusted signature!
      # gpg:          There is no indication that the signature belongs to the owner.
      # Primary key fingerprint: 6AE9 02B6 A7CA 877D 6D65  9296 AF7C 9513 0C53 8013
      
      * tag 'pull-riscv-to-apply-20230911' of https://github.com/alistair23/qemu
      
      : (45 commits)
        target/riscv: don't read CSR in riscv_csrrw_do64
        target/riscv: Align the AIA model to v1.0 ratified spec
        target/riscv/pmp.c: respect mseccfg.RLB for pmpaddrX changes
        target/riscv: Allocate itrigger timers only once
        target/riscv: Use accelerated helper for AES64KS1I
        linux-user/riscv: Add new extensions to hwprobe
        hw/intc/riscv_aplic.c fix non-KVM --enable-debug build
        hw/riscv/virt.c: fix non-KVM --enable-debug build
        riscv: zicond: make non-experimental
        target/riscv: fix satp_mode_finalize() when satp_mode.supported = 0
        target/riscv: Update CSR bits name for svadu extension
        hw/riscv: virt: Fix riscv,pmu DT node path
        target/riscv: select KVM AIA in riscv virt machine
        target/riscv: update APLIC and IMSIC to support KVM AIA
        target/riscv: Create an KVM AIA irqchip
        target/riscv: check the in-kernel irqchip support
        target/riscv: support the AIA device emulation with KVM enabled
        linux-user/riscv: Use abi type for target_ucontext
        hw/intc: Make rtc variable names consistent
        hw/intc: Fix upper/lower mtime write calculation
        ...
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      cb6c406e
    • Stefan Hajnoczi's avatar
      Merge tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging · 78f8b6d9
      Stefan Hajnoczi authored
      Block layer patches
      
      - Optimise reqs_lock to make multiqueue actually scale
      - virtio: Drop out of coroutine context in virtio_load()
      - iotests: Fix reference output for some tests after recent changes
      - vpc: Avoid dynamic stack allocation
      - Code cleanup, improved documentation
      
      # -----BEGIN PGP SIGNATURE-----
      #
      # iQJFBAABCAAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmT7VYgRHGt3b2xmQHJl
      # ZGhhdC5jb20ACgkQfwmycsiPL9YfOg/7BoYF6lkB7DF/jH3XLY6f8zoI+OVM7dg1
      # QFEjyVO+uZiJVh0CeBNI9WgnBe7f5vXMbiStyGbWKo3BLUsjnwoQcW/Sxpw61bR2
      # jZYK6UHe0RhFqTQpbt8G1iCmlpRS+sX+Cy+lxcVcbqxcnLRXCOjT6ivyA4bGbYIC
      # q9BHg/9hBmjuM05NTV6Axy8qjqBGVaIWE9ALTnw8H//waBr4/ydJPTl7EWHe3+tO
      # Stm73evgPG7aLHM6W4qdFW4gwAQ8f+f42Q+0NH1YavB/pN3LTN1B6sLQY/51du+0
      # d/JCsXex0IZQXmNPhqv1h01vhOyU9WBmlwpPG2iZv3a06SXk1ys3rQt/L7uIcsZg
      # Z58CpcUJ517FERnkl0BWXzYhsdcW2K+RdlaiL5PX6H1A2B9LT05ouZfD47hh7kKv
      # oX+Ulk05PFr3JRCKQF6QDEejRKXt169bGzInTlns/wXinD/V4sCkUnr9aWQuhoWk
      # KhQm7WMscTTIyHP2FznO4x9kq0ALsoX/NKqBW2wgJUtqRzsd4XxPp5CXEsAir8Vt
      # dpne/DaV5iDI1mGFJrvkctJN545tEoezBtUzC8/9rZGE0cxHAkhvQVZUDo7xVmrq
      # PlGQ1ko9cNui/Gf9B6qDqaJJwSyw0S6vHurGVQJRwbyly57Fi5aisWkr4w7Rc4eA
      # 7u9B1RvwF/Q=
      # =2wGD
      # -----END PGP SIGNATURE-----
      # gpg: Signature made Fri 08 Sep 2023 13:10:32 EDT
      # gpg:                using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6
      # gpg:                issuer "kwolf@redhat.com"
      # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full]
      # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74  56FE 7F09 B272 C88F 2FD6
      
      * tag 'for-upstream' of https://repo.or.cz/qemu/kevin
      
      :
        virtio: Drop out of coroutine context in virtio_load()
        vmstate: Mark VMStateInfo.get/put() coroutine_mixed_fn
        block: Make more BlockDriver definitions static
        block/meson.build: Restore alphabetical order of files
        block: Remove unnecessary variable in bdrv_block_device_info
        block: Remove bdrv_query_block_node_info
        vmdk: Clean up bdrv_open_child() return value check
        qemu-img: Update documentation for compressed images
        block: Be more verbose in create fallback
        block/iscsi: Document why we use raw malloc()
        qemu-img: omit errno value in error message
        block: change reqs_lock to QemuMutex
        block: minimize bs->reqs_lock section in tracked_request_end()
        iotests: adapt test output for new qemu_cleanup() behavior
        block/vpc: Avoid dynamic stack allocation
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      78f8b6d9
    • Stefan Hajnoczi's avatar
      Merge tag 'pull-target-arm-20230908' of... · a7e8e30e
      Stefan Hajnoczi authored
      Merge tag 'pull-target-arm-20230908' of https://git.linaro.org/people/pmaydell/qemu-arm into staging
      
      target-arm queue:
       * New CPU type: cortex-a710
       * Implement new architectural features:
          - FEAT_PACQARMA3
          - FEAT_EPAC
          - FEAT_Pauth2
          - FEAT_FPAC
          - FEAT_FPACCOMBINE
          - FEAT_TIDCP1
       * Xilinx Versal: Model the CFU/CFI
       * Implement RMR_ELx registers
       * Implement handling of HCR_EL2.TIDCP trap bit
       * arm/kvm: Enable support for KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE
       * hw/intc/arm_gicv3_its: Avoid maybe-uninitialized error in get_vte()
       * target/arm: Do not use gen_mte_checkN in trans_STGP
       * arm64: Restore trapless ptimer access
      
      # -----BEGIN PGP SIGNATURE-----
      #
      # iQJNBAABCAA3FiEE4aXFk81BneKOgxXPPCUl7RQ2DN4FAmT7VEkZHHBldGVyLm1h
      # eWRlbGxAbGluYXJvLm9yZwAKCRA8JSXtFDYM3v7BEACENUKCxsFHRQSLmQkoBCT9
      # Lc4SJrGCbVUC6b+4s5ligZSWIoFzp/kY6NPpeRYqFa0DCxozd2T5D81/j7TpSo0C
      # wUFkZfUq1nGFJ4K5arYcDwhdTtJvvc07YrSbUqufBp6uNGqhR4YmDWPECqBfOlaj
      # 7bgJM6axsg7FkJJh5zp4cQ4WEfp14MHWRPQWpVTI+9cxNmNymokSVRBhVFkM0Wen
      # WD4C/nYud8bOxpDfR8GkIqJ+UnUMhUNEhp28QmHdwywgg0zLWOE4ysIxo55cM0+0
      # FL3q45PL2e4S24UUx9dkxDBWnKEZ5qpQpPn9F6EhWzfm3n2dqr4uUnfWAEOg6NAi
      # vnGS9MlL7nZo69OM3h8g7yKDfTKYm2vl9HVZ0ytFA6PLoSnaQyQwli58qnLtiid3
      # 17MWPoNQlq6G8tHUTPkrJjdA8XLz0iNPXe5G2kwhuM/S0Lv7ORzDc2pq4qBYLvIw
      # 9nV0oUWqzyE7zH6bRKxbbPw2sMI7c8qQr9QRyZeLHL7HdcY5ExvX9FH+qii5JDR/
      # fZohi1pBoNNwYYTeSRnxgHiQ7OizYq0xQJhrdqcFF9voytZj1yZEZ0mp6Tq0/CIj
      # YkC/vEyLYBqgrJ2JeUjbV3h1RIzQcVaXxnxwGsyMyceACd6MNMmdbjR7bZk0lNIu
      # kh+aFEdKajPp56UseJiKBQ==
      # =5Shq
      # -----END PGP SIGNATURE-----
      # gpg: Signature made Fri 08 Sep 2023 13:05:13 EDT
      # gpg:                using RSA key E1A5C593CD419DE28E8315CF3C2525ED14360CDE
      # gpg:                issuer "peter.maydell@linaro.org"
      # gpg: Good signature from "Peter Maydell <peter.maydell@linaro.org>" [full]
      # gpg:                 aka "Peter Maydell <pmaydell@gmail.com>" [full]
      # gpg:                 aka "Peter Maydell <pmaydell@chiark.greenend.org.uk>" [full]
      # gpg:                 aka "Peter Maydell <peter@archaic.org.uk>" [unknown]
      # Primary key fingerprint: E1A5 C593 CD41 9DE2 8E83  15CF 3C25 25ED 1436 0CDE
      
      * tag 'pull-target-arm-20230908' of https://git.linaro.org/people/pmaydell/qemu-arm
      
      : (26 commits)
        arm/kvm: Enable support for KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE
        target/arm: Enable SCTLR_EL1.TIDCP for user-only
        target/arm: Implement FEAT_TIDCP1
        target/arm: Implement HCR_EL2.TIDCP
        target/arm: Implement cortex-a710
        target/arm: Implement RMR_ELx
        arm64: Restore trapless ptimer access
        target/arm: Do not use gen_mte_checkN in trans_STGP
        hw/arm/versal: Connect the CFRAME_REG and CFRAME_BCAST_REG
        hw/arm/xlnx-versal: Connect the CFU_APB, CFU_FDRO and CFU_SFR
        hw/misc: Introduce a model of Xilinx Versal's CFRAME_BCAST_REG
        hw/misc: Introduce a model of Xilinx Versal's CFRAME_REG
        hw/misc/xlnx-versal-cfu: Introduce a model of Xilinx Versal's CFU_SFR
        hw/misc/xlnx-versal-cfu: Introduce a model of Xilinx Versal CFU_FDRO
        hw/misc: Introduce a model of Xilinx Versal's CFU_APB
        hw/misc: Introduce the Xilinx CFI interface
        hw/intc/arm_gicv3_its: Avoid maybe-uninitialized error in get_vte()
        target/arm: Implement FEAT_FPAC and FEAT_FPACCOMBINE
        target/arm: Inform helpers whether a PAC instruction is 'combined'
        target/arm: Implement FEAT_Pauth2
        ...
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      a7e8e30e
    • Joao Martins's avatar
      vfio/common: Separate vfio-pci ranges · a31fe5da
      Joao Martins authored
      
      QEMU computes the DMA logging ranges for two predefined ranges: 32-bit
      and 64-bit. In the OVMF case, when the dynamic MMIO window is enabled,
      QEMU includes in the 64-bit range the RAM regions at the lower part
      and vfio-pci device RAM regions which are at the top of the address
      space. This range contains a large gap and the size can be bigger than
      the dirty tracking HW limits of some devices (MLX5 has a 2^42 limit).
      
      To avoid such large ranges, introduce a new PCI range covering the
      vfio-pci device RAM regions, this only if the addresses are above 4GB
      to avoid breaking potential SeaBIOS guests.
      
      [ clg: - wrote commit log
             - fixed overlapping 32-bit and PCI ranges when using SeaBIOS ]
      
      Signed-off-by: default avatarJoao Martins <joao.m.martins@oracle.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      Fixes: 5255bbf4 ("vfio/common: Add device dirty page tracking start/stop")
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      a31fe5da
    • Avihai Horon's avatar
      vfio/migration: Block VFIO migration with background snapshot · 61537976
      Avihai Horon authored
      
      Background snapshot allows creating a snapshot of the VM while it's
      running and keeping it small by not including dirty RAM pages.
      
      The way it works is by first stopping the VM, saving the non-iterable
      devices' state and then starting the VM and saving the RAM while write
      protecting it with UFFD. The resulting snapshot represents the VM state
      at snapshot start.
      
      VFIO migration is not compatible with background snapshot.
      First of all, VFIO device state is not even saved in background snapshot
      because only non-iterable device state is saved. But even if it was
      saved, after starting the VM, a VFIO device could dirty pages without it
      being detected by UFFD write protection. This would corrupt the
      snapshot, as the RAM in it would not represent the RAM at snapshot
      start.
      
      To prevent this, block VFIO migration with background snapshot.
      
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      61537976
    • Avihai Horon's avatar
      vfio/migration: Block VFIO migration with postcopy migration · bf7ef7a2
      Avihai Horon authored
      
      VFIO migration is not compatible with postcopy migration. A VFIO device
      in the destination can't handle page faults for pages that have not been
      sent yet.
      
      Doing such migration will cause the VM to crash in the destination:
      
      qemu-system-x86_64: VFIO_MAP_DMA failed: Bad address
      qemu-system-x86_64: vfio_dma_map(0x55a28c7659d0, 0xc0000, 0xb000, 0x7f1b11a00000) = -14 (Bad address)
      qemu: hardware error: vfio: DMA mapping failed, unable to continue
      
      To prevent this, block VFIO migration with postcopy migration.
      
      Reported-by: default avatarYanghang Liu <yanghliu@redhat.com>
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Tested-by: default avatarYanghang Liu <yanghliu@redhat.com>
      Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      bf7ef7a2
    • Avihai Horon's avatar
      migration: Add .save_prepare() handler to struct SaveVMHandlers · 08fc4cb5
      Avihai Horon authored
      
      Add a new .save_prepare() handler to struct SaveVMHandlers. This handler
      is called early, even before migration starts, and can be used by
      devices to perform early checks.
      
      Refactor migrate_init() to be able to return errors and call
      .save_prepare() from there.
      
      Suggested-by: default avatarPeter Xu <peterx@redhat.com>
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
      Reviewed-by: default avatarCédric Le Goater <clg@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      08fc4cb5
    • Avihai Horon's avatar
      migration: Move more initializations to migrate_init() · f543aa22
      Avihai Horon authored
      
      Initialization of mig_stats, compression_counters and VFIO bytes
      transferred is hard-coded in migration code path and snapshot code path.
      
      Make the code cleaner by initializing them in migrate_init().
      
      Suggested-by: default avatarCédric Le Goater <clg@redhat.com>
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Reviewed-by: default avatarCédric Le Goater <clg@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      f543aa22
    • Avihai Horon's avatar
      vfio/migration: Fail adding device with enable-migration=on and existing blocker · 8118349b
      Avihai Horon authored
      
      If a device with enable-migration=on is added and it causes a migration
      blocker, adding the device should fail with a proper error.
      
      This is not the case with multiple device migration blocker when the
      blocker already exists. If the blocker already exists and a device with
      enable-migration=on is added which causes a migration blocker, adding
      the device will succeed.
      
      Fix it by failing adding the device in such case.
      
      Fixes: 8bbcb64a ("vfio/migration: Make VFIO migration non-experimental")
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Reviewed-by: default avatarCédric Le Goater <clg@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      8118349b
    • Avihai Horon's avatar
      migration: Add migration prefix to functions in target.c · 38c482b4
      Avihai Horon authored
      
      The functions in target.c are not static, yet they don't have a proper
      migration prefix. Add such prefix.
      
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Reviewed-by: default avatarCédric Le Goater <clg@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      38c482b4
    • Avihai Horon's avatar
      vfio/migration: Allow migration of multiple P2P supporting devices · 5c7a4b60
      Avihai Horon authored
      
      Now that P2P support has been added to VFIO migration, allow migration
      of multiple devices if all of them support P2P migration.
      
      Single device migration is allowed regardless of P2P migration support.
      
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Signed-off-by: default avatarJoao Martins <joao.m.martins@oracle.com>
      Reviewed-by: default avatarCédric Le Goater <clg@redhat.com>
      Tested-by: default avatarYangHang Liu <yanghliu@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      5c7a4b60
    • Avihai Horon's avatar
      vfio/migration: Add P2P support for VFIO migration · 94f775e4
      Avihai Horon authored
      
      VFIO migration uAPI defines an optional intermediate P2P quiescent
      state. While in the P2P quiescent state, P2P DMA transactions cannot be
      initiated by the device, but the device can respond to incoming ones.
      Additionally, all outstanding P2P transactions are guaranteed to have
      been completed by the time the device enters this state.
      
      The purpose of this state is to support migration of multiple devices
      that might do P2P transactions between themselves.
      
      Add support for P2P migration by transitioning all the devices to the
      P2P quiescent state before stopping or starting the devices. Use the new
      VMChangeStateHandler prepare_cb to achieve that behavior.
      
      This will allow migration of multiple VFIO devices if all of them
      support P2P migration.
      
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Tested-by: default avatarYangHang Liu <yanghliu@redhat.com>
      Reviewed-by: default avatarCédric Le Goater <clg@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      94f775e4
    • Joao Martins's avatar
      vfio/migration: Refactor PRE_COPY and RUNNING state checks · 3d4d0f0e
      Joao Martins authored
      
      Move the PRE_COPY and RUNNING state checks to helper functions.
      
      This is in preparation for adding P2P VFIO migration support, where
      these helpers will also test for PRE_COPY_P2P and RUNNING_P2P states.
      
      Signed-off-by: default avatarJoao Martins <joao.m.martins@oracle.com>
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Reviewed-by: default avatarCédric Le Goater <clg@redhat.com>
      Tested-by: default avatarYangHang Liu <yanghliu@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      3d4d0f0e
    • Avihai Horon's avatar
      qdev: Add qdev_add_vm_change_state_handler_full() · 02b2e253
      Avihai Horon authored
      
      Add qdev_add_vm_change_state_handler_full() variant that allows setting
      a prepare callback in addition to the main callback.
      
      This will facilitate adding P2P support for VFIO migration in the
      following patches.
      
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Signed-off-by: default avatarJoao Martins <joao.m.martins@oracle.com>
      Reviewed-by: default avatarCédric Le Goater <clg@redhat.com>
      Tested-by: default avatarYangHang Liu <yanghliu@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      02b2e253
    • Avihai Horon's avatar
      sysemu: Add prepare callback to struct VMChangeStateEntry · 9d3103c8
      Avihai Horon authored
      
      Add prepare callback to struct VMChangeStateEntry.
      
      The prepare callback is optional and can be set by the new function
      qemu_add_vm_change_state_handler_prio_full() that allows setting this
      callback in addition to the main callback.
      
      The prepare callbacks and main callbacks are called in two separate
      phases: First all prepare callbacks are called and only then all main
      callbacks are called.
      
      The purpose of the new prepare callback is to allow all devices to run a
      preliminary task before calling the devices' main callbacks.
      
      This will facilitate adding P2P support for VFIO migration where all
      VFIO devices need to be put in an intermediate P2P quiescent state
      before being stopped or started by the main callback.
      
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Reviewed-by: default avatarCédric Le Goater <clg@redhat.com>
      Tested-by: default avatarYangHang Liu <yanghliu@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      9d3103c8
    • Avihai Horon's avatar
      vfio/migration: Move from STOP_COPY to STOP in vfio_save_cleanup() · 5485298c
      Avihai Horon authored
      
      Changing the device state from STOP_COPY to STOP can take time as the
      device may need to free resources and do other operations as part of the
      transition. Currently, this is done in vfio_save_complete_precopy() and
      therefore it is counted in the migration downtime.
      
      To avoid this, change the device state from STOP_COPY to STOP in
      vfio_save_cleanup(), which is called after migration has completed and
      thus is not part of migration downtime.
      
      Signed-off-by: default avatarAvihai Horon <avihaih@nvidia.com>
      Tested-by: default avatarYangHang Liu <yanghliu@redhat.com>
      Signed-off-by: default avatarCédric Le Goater <clg@redhat.com>
      5485298c
    • Nikita Shubin's avatar
      target/riscv: don't read CSR in riscv_csrrw_do64 · e7a03409
      Nikita Shubin authored
      
      As per ISA:
      
      "For CSRRWI, if rd=x0, then the instruction shall not read the CSR and
      shall not cause any of the side effects that might occur on a CSR read."
      
      trans_csrrwi() and trans_csrrw() call do_csrw() if rd=x0, do_csrw() calls
      riscv_csrrw_do64(), via helper_csrw() passing NULL as *ret_value.
      
      Signed-off-by: default avatarNikita Shubin <n.shubin@yadro.com>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Message-ID: <20230808090914.17634-1-nikita.shubin@maquefel.me>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      e7a03409
    • Tommy Wu's avatar
      target/riscv: Align the AIA model to v1.0 ratified spec · 4df28233
      Tommy Wu authored
      
      According to the new spec, when vsiselect has a reserved value, attempts
      from M-mode or HS-mode to access vsireg, or from VS-mode to access
      sireg, should preferably raise an illegal instruction exception.
      
      Signed-off-by: default avatarTommy Wu <tommy.wu@sifive.com>
      Reviewed-by: default avatarFrank Chang <frank.chang@sifive.com>
      Message-ID: <20230816061647.600672-1-tommy.wu@sifive.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      4df28233
    • Leon Schuermann's avatar
      target/riscv/pmp.c: respect mseccfg.RLB for pmpaddrX changes · 4e3adce1
      Leon Schuermann authored
      
      When the rule-lock bypass (RLB) bit is set in the mseccfg CSR, the PMP
      configuration lock bits must not apply. While this behavior is
      implemented for the pmpcfgX CSRs, this bit is not respected for
      changes to the pmpaddrX CSRs. This patch ensures that pmpaddrX CSR
      writes work even on locked regions when the global rule-lock bypass is
      enabled.
      
      Signed-off-by: default avatarLeon Schuermann <leons@opentitan.org>
      Reviewed-by: default avatarMayuresh Chitale <mchitale@ventanamicro.com>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Message-ID: <20230829215046.1430463-1-leon@is.currently.online>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      4e3adce1
    • Akihiko Odaki's avatar
      target/riscv: Allocate itrigger timers only once · a7c272df
      Akihiko Odaki authored
      
      riscv_trigger_init() had been called on reset events that can happen
      several times for a CPU and it allocated timers for itrigger. If old
      timers were present, they were simply overwritten by the new timers,
      resulting in a memory leak.
      
      Divide riscv_trigger_init() into two functions, namely
      riscv_trigger_realize() and riscv_trigger_reset() and call them in
      appropriate timing. The timer allocation will happen only once for a
      CPU in riscv_trigger_realize().
      
      Fixes: 5a4ae64c ("target/riscv: Add itrigger support when icount is enabled")
      Signed-off-by: default avatarAkihiko Odaki <akihiko.odaki@daynix.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      Reviewed-by: default avatarLIU Zhiwei <zhiwei_liu@linux.alibaba.com>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Message-ID: <20230818034059.9146-1-akihiko.odaki@daynix.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      a7c272df
    • Ard Biesheuvel's avatar
      target/riscv: Use accelerated helper for AES64KS1I · 7d496bb5
      Ard Biesheuvel authored
      
      Use the accelerated SubBytes/ShiftRows/AddRoundKey AES helper to
      implement the first half of the key schedule derivation. This does not
      actually involve shifting rows, so clone the same value into all four
      columns of the AES vector to counter that operation.
      
      Cc: Richard Henderson <richard.henderson@linaro.org>
      Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
      Cc: Palmer Dabbelt <palmer@dabbelt.com>
      Cc: Alistair Francis <alistair.francis@wdc.com>
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-ID: <20230831154118.138727-1-ardb@kernel.org>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      7d496bb5
    • Robbin Ehn's avatar
      linux-user/riscv: Add new extensions to hwprobe · bb0a45e9
      Robbin Ehn authored
      
      This patch adds the new extensions in
      linux 6.5 to the hwprobe syscall.
      
      And fixes RVC check to OR with correct value.
      The previous variable contains 0 therefore it
      did work.
      
      Signed-off-by: default avatarRobbin Ehn <rehn@rivosinc.com>
      Acked-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Acked-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Message-ID: <bc82203b72d7efb30f1b4a8f9eb3d94699799dc8.camel@rivosinc.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      bb0a45e9
    • Daniel Henrique Barboza's avatar
      hw/intc/riscv_aplic.c fix non-KVM --enable-debug build · b8156640
      Daniel Henrique Barboza authored
      Commit 6df0b37e2ab breaks a --enable-debug build in a non-KVM
      environment with the following error:
      
      /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_intc_riscv_aplic.c.o: in function `riscv_kvm_aplic_request':
      ./qemu/build/../hw/intc/riscv_aplic.c:486: undefined reference to `kvm_set_irq'
      collect2: error: ld returned 1 exit status
      
      This happens because the debug build will poke into the
      'if (is_kvm_aia(aplic->msimode))' block and fail to find a reference to
      the KVM only function riscv_kvm_aplic_request().
      
      There are multiple solutions to fix this. We'll go with the same
      solution from the previous patch, i.e. add a kvm_enabled() conditional
      to filter out the block. But there's a catch: riscv_kvm_aplic_request()
      is a local function that would end up being used if the compiler crops
      the block, and this won't work. Quoting Richard Henderson's explanation
      in [1]:
      
      "(...) the compiler won't eliminate entire unused functions with -O0"
      
      We'll solve it by moving riscv_kvm_aplic_request() to kvm.c and add its
      declaration in kvm_riscv.h, where all other KVM specific public
      functions are already declared. Other archs handles KVM specific code in
      this manner and we expect to do the same from now on.
      
      [1] https://lore.kernel.org/qemu-riscv/d2f1ad02-eb03-138f-9d08-db676deeed05@linaro.org/
      
      
      
      Signed-off-by: default avatarDaniel Henrique Barboza <dbarboza@ventanamicro.com>
      Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-ID: <20230830133503.711138-3-dbarboza@ventanamicro.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      b8156640
    • Daniel Henrique Barboza's avatar
      hw/riscv/virt.c: fix non-KVM --enable-debug build · a51d4610
      Daniel Henrique Barboza authored
      
      A build with --enable-debug and without KVM will fail as follows:
      
      /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init':
      ./qemu/build/../hw/riscv/virt.c:1465: undefined reference to `kvm_riscv_aia_create'
      
      This happens because the code block with "if virt_use_kvm_aia(s)" isn't
      being ignored by the debug build, resulting in an undefined reference to
      a KVM only function.
      
      Add a 'kvm_enabled()' conditional together with virt_use_kvm_aia() will
      make the compiler crop the kvm_riscv_aia_create() call entirely from a
      non-KVM build. Note that adding the 'kvm_enabled()' conditional inside
      virt_use_kvm_aia() won't fix the build because this function would need
      to be inlined multiple times to make the compiler zero out the entire
      block.
      
      While we're at it, use kvm_enabled() in all instances where
      virt_use_kvm_aia() is checked to allow the compiler to elide these other
      kvm-only instances as well.
      
      Suggested-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Fixes: dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine")
      Signed-off-by: default avatarDaniel Henrique Barboza <dbarboza@ventanamicro.com>
      Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-ID: <20230830133503.711138-2-dbarboza@ventanamicro.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      a51d4610
    • Vineet Gupta's avatar
      riscv: zicond: make non-experimental · c3443f83
      Vineet Gupta authored
      
      zicond is now codegen supported in both llvm and gcc.
      
      This change allows seamless enabling/testing of zicond in downstream
      projects. e.g. currently riscv-gnu-toolchain parses elf attributes
      to create a cmdline for qemu but fails short of enabling it because of
      the "x-" prefix.
      
      Signed-off-by: default avatarVineet Gupta <vineetg@rivosinc.com>
      Message-ID: <20230808181715.436395-1-vineetg@rivosinc.com>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      c3443f83
    • Daniel Henrique Barboza's avatar
      target/riscv: fix satp_mode_finalize() when satp_mode.supported = 0 · 3a2fc235
      Daniel Henrique Barboza authored
      
      In the same emulated RISC-V host, the 'host' KVM CPU takes 4 times
      longer to boot than the 'rv64' KVM CPU.
      
      The reason is an unintended behavior of riscv_cpu_satp_mode_finalize()
      when satp_mode.supported = 0, i.e. when cpu_init() does not set
      satp_mode_max_supported(). satp_mode_max_from_map(map) does:
      
      31 - __builtin_clz(map)
      
      This means that, if satp_mode.supported = 0, satp_mode_supported_max
      wil be '31 - 32'. But this is C, so satp_mode_supported_max will gladly
      set it to UINT_MAX (4294967295). After that, if the user didn't set a
      satp_mode, set_satp_mode_default_map(cpu) will make
      
      cfg.satp_mode.map = cfg.satp_mode.supported
      
      So satp_mode.map = 0. And then satp_mode_map_max will be set to
      satp_mode_max_from_map(cpu->cfg.satp_mode.map), i.e. also UINT_MAX. The
      guard "satp_mode_map_max > satp_mode_supported_max" doesn't protect us
      here since both are UINT_MAX.
      
      And finally we have 2 loops:
      
              for (int i = satp_mode_map_max - 1; i >= 0; --i) {
      
      Which are, in fact, 2 loops from UINT_MAX -1 to -1. This is where the
      extra delay when booting the 'host' CPU is coming from.
      
      Commit 43d1de32 already set a precedence for satp_mode.supported = 0
      in a different manner. We're doing the same here. If supported == 0,
      interpret as 'the CPU wants the OS to handle satp mode alone' and skip
      satp_mode_finalize().
      
      We'll also put a guard in satp_mode_max_from_map() to assert out if map
      is 0 since the function is not ready to deal with it.
      
      Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
      Fixes: 6f23aaeb ("riscv: Allow user to set the satp mode")
      Signed-off-by: default avatarDaniel Henrique Barboza <dbarboza@ventanamicro.com>
      Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
      Message-ID: <20230817152903.694926-1-dbarboza@ventanamicro.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      3a2fc235
    • Weiwei Li's avatar
      target/riscv: Update CSR bits name for svadu extension · ed67d637
      Weiwei Li authored
      
      The Svadu specification updated the name of the *envcfg bit from
      HADE to ADUE.
      
      Signed-off-by: default avatarWeiwei Li <liweiwei@iscas.ac.cn>
      Signed-off-by: default avatarJunqiang Wang <wangjunqiang@iscas.ac.cn>
      Reviewed-by: default avatarDaniel Henrique Barboza <dbarboza@ventanamicro.com>
      Message-ID: <20230816141916.66898-1-liweiwei@iscas.ac.cn>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      ed67d637
    • Conor Dooley's avatar
      hw/riscv: virt: Fix riscv,pmu DT node path · 9ff31406
      Conor Dooley authored
      On a dtb dumped from the virt machine, dt-validate complains:
      soc: pmu: {'riscv,event-to-mhpmcounters': [[1, 1, 524281], [2, 2, 524284], [65561, 65561, 524280], [65563, 65563, 524280], [65569, 65569, 524280]], 'compatible': ['riscv,pmu']} should not be valid under {'type': 'object'}
              from schema $id: http://devicetree.org/schemas/simple-bus.yaml#
      
      
      That's pretty cryptic, but running the dtb back through dtc produces
      something a lot more reasonable:
      Warning (simple_bus_reg): /soc/pmu: missing or empty reg/ranges property
      
      Moving the riscv,pmu node out of the soc bus solves the problem.
      
      Signed-off-by: default avatarConor Dooley <conor.dooley@microchip.com>
      Acked-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Reviewed-by: default avatarDaniel Henrique Barboza <dbarboza@ventanamicro.com>
      Message-ID: <20230727-groom-decline-2c57ce42841c@spud>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      9ff31406
    • Yong-Xuan Wang's avatar
      target/riscv: select KVM AIA in riscv virt machine · 48c2c33c
      Yong-Xuan Wang authored
      
      Select KVM AIA when the host kernel has in-kernel AIA chip support.
      Since KVM AIA only has one APLIC instance, we map the QEMU APLIC
      devices to KVM APLIC.
      
      Signed-off-by: default avatarYong-Xuan Wang <yongxuan.wang@sifive.com>
      Reviewed-by: default avatarJim Shu <jim.shu@sifive.com>
      Reviewed-by: default avatarDaniel Henrique Barboza <dbarboza@ventanamicro.com>
      Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
      Message-ID: <20230727102439.22554-6-yongxuan.wang@sifive.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      48c2c33c
    • Yong-Xuan Wang's avatar
      target/riscv: update APLIC and IMSIC to support KVM AIA · 95a97b3f
      Yong-Xuan Wang authored
      
      KVM AIA can't emulate APLIC only. When "aia=aplic" parameter is passed,
      APLIC devices is emulated by QEMU. For "aia=aplic-imsic", remove the
      mmio operations of APLIC when using KVM AIA and send wired interrupt
      signal via KVM_IRQ_LINE API.
      After KVM AIA enabled, MSI messages are delivered by KVM_SIGNAL_MSI API
      when the IMSICs receive mmio write requests.
      
      Signed-off-by: default avatarYong-Xuan Wang <yongxuan.wang@sifive.com>
      Reviewed-by: default avatarJim Shu <jim.shu@sifive.com>
      Reviewed-by: default avatarDaniel Henrique Barboza <dbarboza@ventanamicro.com>
      Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
      Message-ID: <20230727102439.22554-5-yongxuan.wang@sifive.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      95a97b3f
    • Yong-Xuan Wang's avatar
      target/riscv: Create an KVM AIA irqchip · 9634ef7e
      Yong-Xuan Wang authored
      
      We create a vAIA chip by using the KVM_DEV_TYPE_RISCV_AIA and then set up
      the chip with the KVM_DEV_RISCV_AIA_GRP_* APIs.
      We also extend KVM accelerator to specify the KVM AIA mode. The "riscv-aia"
      parameter is passed along with --accel in QEMU command-line.
      1) "riscv-aia=emul": IMSIC is emulated by hypervisor
      2) "riscv-aia=hwaccel": use hardware guest IMSIC
      3) "riscv-aia=auto": use the hardware guest IMSICs whenever available
                           otherwise we fallback to software emulation.
      
      Signed-off-by: default avatarYong-Xuan Wang <yongxuan.wang@sifive.com>
      Reviewed-by: default avatarJim Shu <jim.shu@sifive.com>
      Reviewed-by: default avatarDaniel Henrique Barboza <dbarboza@ventanamicro.com>
      Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
      Message-ID: <20230727102439.22554-4-yongxuan.wang@sifive.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      9634ef7e
    • Yong-Xuan Wang's avatar
      target/riscv: check the in-kernel irqchip support · 97b9f5ef
      Yong-Xuan Wang authored
      
      We check the in-kernel irqchip support when using KVM acceleration.
      
      Signed-off-by: default avatarYong-Xuan Wang <yongxuan.wang@sifive.com>
      Reviewed-by: default avatarJim Shu <jim.shu@sifive.com>
      Reviewed-by: default avatarDaniel Henrique Barboza <dbarboza@ventanamicro.com>
      Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
      Message-ID: <20230727102439.22554-3-yongxuan.wang@sifive.com>
      Signed-off-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      97b9f5ef
Loading