All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson via Linux-kernel-mentees <linux-kernel-mentees@lists.linuxfoundation.org>
To: "José Pekkarinen" <jose.pekkarinen@foxhound.fi>
Cc: x86@kernel.org, hpa@zytor.com, kvm@vger.kernel.org,
	dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org,
	mingo@redhat.com, bp@alien8.de, pbonzini@redhat.com,
	tglx@linutronix.de,
	linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [PATCH] KVM: x86: replace do_div with div64_ul
Date: Mon, 30 Oct 2023 09:12:53 -0700	[thread overview]
Message-ID: <ZT_WBanoip8zhxis@google.com> (raw)
In-Reply-To: <20231029093928.138570-1-jose.pekkarinen@foxhound.fi>

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;
 

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

WARNING: multiple messages have this Message-ID (diff)
From: Sean Christopherson <seanjc@google.com>
To: "José Pekkarinen" <jose.pekkarinen@foxhound.fi>
Cc: pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com,
	bp@alien8.de,  dave.hansen@linux.intel.com,
	skhan@linuxfoundation.org, x86@kernel.org,  hpa@zytor.com,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [PATCH] KVM: x86: replace do_div with div64_ul
Date: Mon, 30 Oct 2023 09:12:53 -0700	[thread overview]
Message-ID: <ZT_WBanoip8zhxis@google.com> (raw)
In-Reply-To: <20231029093928.138570-1-jose.pekkarinen@foxhound.fi>

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;
 


  reply	other threads:[~2023-10-30 16:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-29  9:39 [PATCH] KVM: x86: replace do_div with div64_ul José Pekkarinen
2023-10-29  9:39 ` José Pekkarinen
2023-10-30 16:12 ` Sean Christopherson via Linux-kernel-mentees [this message]
2023-10-30 16:12   ` Sean Christopherson
2023-10-31  9:35 ` David Laight
2023-10-31  9:35   ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZT_WBanoip8zhxis@google.com \
    --to=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jose.pekkarinen@foxhound.fi \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.