Skip to content

Commit 14c3555

Browse files
arndboupton
authored andcommitted
arm64: kvm: avoid overflow in integer division
The newly added kvm_mmu_split_nr_page_tables() function uses DIV_ROUND_DOWN_ULL() to divide 64-bit addresses, but this requires a 32-bit divisior, and PUD_SIZE may exceed that when 64KB pages are used: arch/arm64/kvm/mmu.c: In function 'kvm_mmu_split_nr_page_tables': include/linux/math.h:42:64: error: conversion from 'long unsigned int' to 'u32' {aka 'unsigned int'} changes value from '68719476736' to '0' [-Werror=overflow] 42 | DIV_ROUND_DOWN_ULL((unsigned long long)(ll) + (d) - 1, (d)) | ^~~ include/linux/math.h:39:47: note: in definition of macro 'DIV_ROUND_DOWN_ULL' 39 | #define DIV_ROUND_DOWN_ULL(ll, d) div_u64(ll, d) | ^ arch/arm64/kvm/mmu.c:95:22: note: in expansion of macro 'DIV_ROUND_UP_ULL' 95 | n += DIV_ROUND_UP_ULL(range, PUD_SIZE); | ^~~~~~~~~~~~~~~~ Since this code is only used on 64-bit targets, DIV_ROUND_UP() can deal with this more easily, as it already takes 64-bit arguments. Fixes: e7bf7a4 ("KVM: arm64: Split huge pages when dirty logging is enabled") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20230517202352.793673-1-arnd@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent a12ab13 commit 14c3555

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

arch/arm64/kvm/mmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ static int kvm_mmu_split_nr_page_tables(u64 range)
9292
int n = 0;
9393

9494
if (KVM_PGTABLE_MIN_BLOCK_LEVEL < 2)
95-
n += DIV_ROUND_UP_ULL(range, PUD_SIZE);
96-
n += DIV_ROUND_UP_ULL(range, PMD_SIZE);
95+
n += DIV_ROUND_UP(range, PUD_SIZE);
96+
n += DIV_ROUND_UP(range, PMD_SIZE);
9797
return n;
9898
}
9999

0 commit comments

Comments
 (0)