* [PATCH] KVM: x86: replace do_div with div64_ul
@ 2023-10-29 9:39 José Pekkarinen
2023-10-30 16:12 ` Sean Christopherson
2023-10-31 9:35 ` David Laight
0 siblings, 2 replies; 3+ messages in thread
From: José Pekkarinen @ 2023-10-29 9:39 UTC (permalink / raw)
To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, skhan
Cc: José Pekkarinen, x86, hpa, kvm, linux-kernel,
linux-kernel-mentees
Reported by coccinelle, there is a do_div call that does
64-by-32 divisions even in 64bit platforms, this patch will
move it to div64_ul macro that will decide the correct
division function for the platform underneath. The output
the warning follows:
arch/x86/kvm/lapic.c:1948:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead.
Signed-off-by: José Pekkarinen <jose.pekkarinen@foxhound.fi>
---
arch/x86/kvm/lapic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 3e977dbbf993..0b90c6ad5091 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1945,7 +1945,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic)
guest_tsc = kvm_read_l1_tsc(vcpu, rdtsc());
ns = (tscdeadline - guest_tsc) * 1000000ULL;
- do_div(ns, this_tsc_khz);
+ div64_ul(ns, this_tsc_khz);
if (likely(tscdeadline > guest_tsc) &&
likely(ns > apic->lapic_timer.timer_advance_ns)) {
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] KVM: x86: replace do_div with div64_ul
2023-10-29 9:39 [PATCH] KVM: x86: replace do_div with div64_ul José Pekkarinen
@ 2023-10-30 16:12 ` Sean Christopherson
2023-10-31 9:35 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2023-10-30 16:12 UTC (permalink / raw)
To: José Pekkarinen
Cc: pbonzini, tglx, mingo, bp, dave.hansen, skhan, x86, hpa, kvm,
linux-kernel, linux-kernel-mentees
On Sun, Oct 29, 2023, José Pekkarinen wrote:
> Reported by coccinelle, there is a do_div call that does
> 64-by-32 divisions even in 64bit platforms, this patch will
> move it to div64_ul macro that will decide the correct
> division function for the platform underneath. The output
> the warning follows:
>
> arch/x86/kvm/lapic.c:1948:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead.
>
> Signed-off-by: José Pekkarinen <jose.pekkarinen@foxhound.fi>
> ---
> arch/x86/kvm/lapic.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 3e977dbbf993..0b90c6ad5091 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1945,7 +1945,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic)
> guest_tsc = kvm_read_l1_tsc(vcpu, rdtsc());
>
> ns = (tscdeadline - guest_tsc) * 1000000ULL;
> - do_div(ns, this_tsc_khz);
> + div64_ul(ns, this_tsc_khz);
Well this is silly, virtual_tsc_khz is a u32.
unsigned long this_tsc_khz = vcpu->arch.virtual_tsc_khz;
struct kvm_vcpu_arch {
...
u32 virtual_tsc_khz;
}
I assume this will make coccinelle happy?
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 245b20973cae..31e9c84b8791 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1932,7 +1932,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic)
u64 ns = 0;
ktime_t expire;
struct kvm_vcpu *vcpu = apic->vcpu;
- unsigned long this_tsc_khz = vcpu->arch.virtual_tsc_khz;
+ u32 this_tsc_khz = vcpu->arch.virtual_tsc_khz;
unsigned long flags;
ktime_t now;
^ permalink raw reply related [flat|nested] 3+ messages in thread* RE: [PATCH] KVM: x86: replace do_div with div64_ul
2023-10-29 9:39 [PATCH] KVM: x86: replace do_div with div64_ul José Pekkarinen
2023-10-30 16:12 ` Sean Christopherson
@ 2023-10-31 9:35 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2023-10-31 9:35 UTC (permalink / raw)
To: 'José Pekkarinen', seanjc@google.com,
pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com,
skhan@linuxfoundation.org
Cc: x86@kernel.org, hpa@zytor.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org
From: José Pekkarinen
> Sent: 29 October 2023 09:39
>
> Reported by coccinelle, there is a do_div call that does
> 64-by-32 divisions even in 64bit platforms, this patch will
> move it to div64_ul macro that will decide the correct
> division function for the platform underneath. The output
> the warning follows:
>
> arch/x86/kvm/lapic.c:1948:1-7: WARNING: do_div() does a 64-by-32 division, please consider using
> div64_ul instead.
That is about the worst message from the coccinelle scripts.
It really ought to ask you to check the domain on the values.
>
> Signed-off-by: José Pekkarinen <jose.pekkarinen@foxhound.fi>
> ---
> arch/x86/kvm/lapic.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 3e977dbbf993..0b90c6ad5091 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1945,7 +1945,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic)
> guest_tsc = kvm_read_l1_tsc(vcpu, rdtsc());
>
> ns = (tscdeadline - guest_tsc) * 1000000ULL;
> - do_div(ns, this_tsc_khz);
> + div64_ul(ns, this_tsc_khz);
Did you test this?
Hint - you didn't.
David
>
> if (likely(tscdeadline > guest_tsc) &&
> likely(ns > apic->lapic_timer.timer_advance_ns)) {
> --
> 2.39.2
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-31 9:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-29 9:39 [PATCH] KVM: x86: replace do_div with div64_ul José Pekkarinen
2023-10-30 16:12 ` Sean Christopherson
2023-10-31 9:35 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox