KVM: x86: fix 32 bit build
PATCH 1/1 KVM: x86: fix 32 bit build
Now that kvm->stat.nx_lpage_splits is 64 bit, use DIV_ROUND_UP_ULL when doing division.
--- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -6054,7 +6054,7 @@ static void kvm_recover_nx_lpages(struct kvm *kvm)write_lock (&kvm->mmu_lock); ratio =READ_ONCE (nx_huge_pages_recovery_ratio); - to_zap = ratio ?DIV_ROUND_UP (kvm->stat.nx_lpage_splits, ratio) :0 ; + to_zap = ratio ?DIV_ROUND_UP_ULL (kvm->stat.nx_lpage_splits, ratio) :0 ;for ( ; to_zap; --to_zap) {if (list_empty (&kvm->arch.lpage_disallowed_mmu_pages))break ;
Signature · 1 line
2.26.3
Sean Christopherson
maintainerQuoted 2 lines · Maxim Levitsky
Now that
kvm->stat.nx_lpage_splitsis 64 bit, useDIV_ROUND_UP_ULLwhen doing division.
I went the "cast to an unsigned long" route. I prefer the cast approach because to_zap is also an unsigned long, i.e. using DIV_ROUND_UP_ULL() could look like a truncation bug. In practice, nx_lpage_splits can't be more than an unsigned long so it's largely a moot point, I just like the more explicit "this is doing something odd".
https://lkml.kernel.org/r/[email protected]
Quoted 22 lines
Fixes 7ee093d4f3f5 ("KVM: switch per-VM stats to u64")Signed-off-by Maxim Levitsky <[email protected]>--- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/mmu/mmu.c +1
-1@@ -6054,7 +6054,7 @@ static void kvm_recover_nx_lpages(struct kvm *kvm)write_lock (&kvm->mmu_lock); ratio =READ_ONCE (nx_huge_pages_recovery_ratio); - to_zap = ratio ?DIV_ROUND_UP (kvm->stat.nx_lpage_splits, ratio) :0 ; + to_zap = ratio ?DIV_ROUND_UP_ULL (kvm->stat.nx_lpage_splits, ratio) :0 ;for ( ; to_zap; --to_zap) {if (list_empty (&kvm->arch.lpage_disallowed_mmu_pages))break ;Signature · 1 line
2.26.3
Quoted 25 lines · Sean Christopherson
Quoted 2 lines · Maxim Levitsky
Now that
kvm->stat.nx_lpage_splitsis 64 bit, useDIV_ROUND_UP_ULLwhen doing division.I went the "cast to an unsigned long" route. I prefer the cast approach because
to_zapis also an unsigned long, i.e. usingDIV_ROUND_UP_ULL()could look like a truncation bug. In practice,nx_lpage_splitscan't be more than an unsigned long so it's largely a moot point, I just like the more explicit "this is doing something odd".https://lkml.kernel.org/r/[email protected]
Quoted 13 lines
Fixes 7ee093d4f3f5 ("KVM: switch per-VM stats to u64")Signed-off-by Maxim Levitsky <[email protected]>--- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/mmu/mmu.c +0
-0@@ -6054,7 +6054,7 @@ static void kvm_recover_nx_lpages(struct kvm *kvm)write_lock (&kvm->mmu_lock);
Quoted 9 lines
Quoted 9 lines
arch/x86/kvm/mmu/mmu.c +1
-1ratio =READ_ONCE (nx_huge_pages_recovery_ratio); - to_zap = ratio ?DIV_ROUND_UP (kvm->stat.nx_lpage_splits, ratio) :0 ; + to_zap = ratio ?DIV_ROUND_UP_ULL (kvm->stat.nx_lpage_splits, ratio) :0 ;for ( ; to_zap; --to_zap) {if (list_empty (&kvm->arch.lpage_disallowed_mmu_pages))break ;Signature · 1 line
2.26.3
Cool, makes sense.
I didn't notice your patch (I did look at the list but since the subject didn't mention the build breakage I didn't notice).
I just wanted to send this patch to avoid someone else spending time figuring it out.
Thanks,
Best regards,
Maxim Levitsky