[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/10] vfio/spapr: Fix page size calculation
From: |
David Gibson |
Subject: |
[PULL 02/10] vfio/spapr: Fix page size calculation |
Date: |
Tue, 7 Apr 2020 14:35:58 +1000 |
From: Alexey Kardashevskiy <address@hidden>
Coverity detected an issue (CID 1421903) with potential call of clz64(0)
which returns 64 which make it do "<<" with a negative number.
This checks the mask and avoids undefined behaviour.
In practice pgsizes and memory_region_iommu_get_min_page_size() always
have some common page sizes and even if they did not, the resulting page
size would be 0x8000.0000.0000.0000 (gcc 9.2) and
ioctl(VFIO_IOMMU_SPAPR_TCE_CREATE) would fail anyway.
Signed-off-by: Alexey Kardashevskiy <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Greg Kurz <address@hidden>
Signed-off-by: David Gibson <address@hidden>
---
hw/vfio/spapr.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
index 33692fc86f..2900bd1941 100644
--- a/hw/vfio/spapr.c
+++ b/hw/vfio/spapr.c
@@ -147,7 +147,7 @@ int vfio_spapr_create_window(VFIOContainer *container,
{
int ret = 0;
IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
- uint64_t pagesize = memory_region_iommu_get_min_page_size(iommu_mr);
+ uint64_t pagesize = memory_region_iommu_get_min_page_size(iommu_mr),
pgmask;
unsigned entries, bits_total, bits_per_level, max_levels;
struct vfio_iommu_spapr_tce_create create = { .argsz = sizeof(create) };
long rampagesize = qemu_minrampagesize();
@@ -159,8 +159,8 @@ int vfio_spapr_create_window(VFIOContainer *container,
if (pagesize > rampagesize) {
pagesize = rampagesize;
}
- pagesize = 1ULL << (63 - clz64(container->pgsizes &
- (pagesize | (pagesize - 1))));
+ pgmask = container->pgsizes & (pagesize | (pagesize - 1));
+ pagesize = pgmask ? (1ULL << (63 - clz64(pgmask))) : 0;
if (!pagesize) {
error_report("Host doesn't support page size 0x%"PRIx64
", the supported mask is 0x%lx",
--
2.25.2
- [PULL 00/10] ppc-for-5.0 queue 20200407, David Gibson, 2020/04/07
- [PULL 01/10] hw/ppc/e500.c: Handle qemu_find_file() failure, David Gibson, 2020/04/07
- [PULL 03/10] ppc/spapr: KVM FWNMI should not be enabled until guest requests it, David Gibson, 2020/04/07
- [PULL 02/10] vfio/spapr: Fix page size calculation,
David Gibson <=
- [PULL 04/10] ppc/spapr: Improve FWNMI machine check delivery corner case comments, David Gibson, 2020/04/07
- [PULL 08/10] hw/ppc/ppc440_uc.c: Remove incorrect iothread locking from dcr_write_pcie(), David Gibson, 2020/04/07
- [PULL 05/10] ppc/spapr: Add FWNMI machine check delivery warnings, David Gibson, 2020/04/07
- [PULL 06/10] ppc/spapr: Don't kill the guest if a recovered FWNMI machine check delivery fails, David Gibson, 2020/04/07
- [PULL 10/10] ppc/pnv: Create BMC devices only when defaults are enabled, David Gibson, 2020/04/07
- [PULL 09/10] pseries: Update SLOF firmware image, David Gibson, 2020/04/07
- [PULL 07/10] spapr: Fix failure path for attempting to hot unplug PCI bridges, David Gibson, 2020/04/07
- Re: [PULL 00/10] ppc-for-5.0 queue 20200407, Peter Maydell, 2020/04/07