qemu-e2k/hw/i386
Jason Wang ec1a78cee9 intel_iommu: refine iotlb hash calculation
Commit 1b2b12376c ("intel-iommu: PASID support") takes PASID into
account when calculating iotlb hash like:

static guint vtd_iotlb_hash(gconstpointer v)
{
    const struct vtd_iotlb_key *key = v;

    return key->gfn | ((key->sid) << VTD_IOTLB_SID_SHIFT) |
           (key->level) << VTD_IOTLB_LVL_SHIFT |
           (key->pasid) << VTD_IOTLB_PASID_SHIFT;
}

This turns out to be problematic since:

- the shift will lose bits if not converting to uint64_t
- level should be off by one in order to fit into 2 bits
- VTD_IOTLB_PASID_SHIFT is 30 but PASID is 20 bits which will waste
  some bits
- the hash result is uint64_t so we will lose bits when converting to
  guint

So this patch fixes them by

- converting the keys into uint64_t before doing the shift
- off level by one to make it fit into two bits
- change the sid, lvl and pasid shift to 26, 42 and 44 in order to
  take the full width of uint64_t
- perform an XOR to the top 32bit with the bottom 32bit for the final
  result to fit guint

Fixes: Coverity CID 1508100
Fixes: 1b2b12376c ("intel-iommu: PASID support")
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20230412073510.7158-1-jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
2023-04-24 22:56:55 -04:00
..
kvm *: Add missing includes of qemu/error-report.h 2023-03-22 15:06:57 +00:00
xen hw/xen: Rename xen_common.h to xen_native.h 2023-03-07 17:04:30 +00:00
Kconfig xen: add CONFIG_XEN_BUS and CONFIG_XEN_EMU options for Xen emulation 2023-03-01 08:22:49 +00:00
acpi-build.c hw/acpi: limit warning on acpi table size to pc machines older than version 2.3 2023-04-24 22:56:55 -04:00
acpi-build.h hw/acpi/ich9: Enable ACPI PCI hot-plug 2021-07-16 04:33:35 -04:00
acpi-common.c hw/acpi/acpi_dev_interface: Remove unused parameter from AcpiDeviceIfClass::madt_cpu 2023-01-27 11:47:02 -05:00
acpi-common.h misc: Correct relative include path 2021-06-05 21:10:42 +02:00
acpi-microvm.c hw/isa/isa-bus: Turn isa_build_aml() into qbus_build_aml() 2023-01-27 11:47:02 -05:00
acpi-microvm.h microvm/acpi: add minimal acpi support 2020-09-17 14:16:19 +02:00
amd_iommu.c hw/i386/amd_iommu: Factor amdvi_pci_realize out of amdvi_sysbus_realize 2023-04-21 04:25:52 -04:00
amd_iommu.h hw/i386/amd_iommu: Factor amdvi_pci_realize out of amdvi_sysbus_realize 2023-04-21 04:25:52 -04:00
e820_memory_layout.c hw/i386/e820: remove legacy reserved entries for e820 2022-11-02 06:56:31 -04:00
e820_memory_layout.h hw/i386/e820: remove legacy reserved entries for e820 2022-11-02 06:56:31 -04:00
fw_cfg.c hw/i386/e820: remove legacy reserved entries for e820 2022-11-02 06:56:31 -04:00
fw_cfg.h hw/i386/e820: remove legacy reserved entries for e820 2022-11-02 06:56:31 -04:00
generic_event_device_x86.c acpi: ged: add x86 device variant. 2020-09-17 14:16:19 +02:00
intel_iommu.c intel_iommu: refine iotlb hash calculation 2023-04-24 22:56:55 -04:00
intel_iommu_internal.h intel_iommu: refine iotlb hash calculation 2023-04-24 22:56:55 -04:00
kvmvapic.c Do not include cpu.h if it's not really necessary 2021-05-02 17:24:51 +02:00
meson.build microvm: add device tree support. 2021-11-02 17:24:17 +01:00
microvm-dt.c hw/rtc/mc146818rtc: QOM'ify io_base offset 2022-06-11 11:44:50 +02:00
microvm-dt.h microvm: add device tree support. 2021-11-02 17:24:17 +01:00
microvm.c Revert "hw/i386: pass RNG seed via setup_data entry" 2023-03-02 03:10:46 -05:00
multiboot.c bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
multiboot.h target/i386: use DMA-enabled multiboot ROM for new-enough QEMU machine types 2021-11-02 15:57:27 +01:00
pc.c hw/acpi: limit warning on acpi table size to pc machines older than version 2.3 2023-04-24 22:56:55 -04:00
pc_piix.c hw/acpi: limit warning on acpi table size to pc machines older than version 2.3 2023-04-24 22:56:55 -04:00
pc_q35.c hw: Add compat machines for 8.1 2023-04-21 04:25:52 -04:00
pc_sysfw.c i386: factor out x86_firmware_configure() 2022-04-27 07:51:01 +02:00
pc_sysfw_ovmf-stubs.c hw/i386: Introduce X86_FW_OVMF Kconfig symbol 2021-07-14 22:28:58 +02:00
pc_sysfw_ovmf.c hw/i386: Replace magic number with field length calculation 2022-03-06 05:08:23 -05:00
port92.c Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
sgx-epc.c Mark remaining global TypeInfo instances as const 2022-02-21 13:30:20 +00:00
sgx-stub.c numa: Enable numa for SGX EPC sections 2021-12-10 09:47:18 +01:00
sgx.c *: Add missing includes of qemu/error-report.h 2023-03-22 15:06:57 +00:00
trace-events intel-iommu: PASID support 2022-11-07 14:08:17 -05:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
vmmouse.c hw/i386/vmmouse: Require 'i8042' property to be set 2021-12-18 10:57:37 +01:00
vmport.c Do not include cpu.h if it's not really necessary 2021-05-02 17:24:51 +02:00
x86-iommu-stub.c hw/i386/pc: Remove x86_iommu_get_type() 2021-11-01 18:49:10 -04:00
x86-iommu.c hw/i386/pc: Move IOMMU singleton into PCMachineState 2021-11-01 18:49:10 -04:00
x86.c virtio,pc,pci: features, cleanups, fixes 2023-03-03 13:35:54 +00:00