From: Paolo Bonzini <pbonzini@redhat.com>
To: cgel.zte@gmail.com
Cc: seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com,
jmattson@google.com, joro@8bytes.org, tglx@linutronix.de,
mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
x86@kernel.org, hpa@zytor.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Changcheng Deng <deng.changcheng@zte.com.cn>,
Zeal Robot <zealci@zte.com.cn>
Subject: Re: [PATCH] KVM: x86: Use div64_ul instead of do_div
Date: Fri, 17 Dec 2021 09:44:55 +0100 [thread overview]
Message-ID: <afacee89-4edb-f4fb-156d-7b6c8dd0bb3b@redhat.com> (raw)
In-Reply-To: <20211217084155.452262-1-deng.changcheng@zte.com.cn>
On 12/17/21 09:41, cgel.zte@gmail.com wrote:
> From: Changcheng Deng <deng.changcheng@zte.com.cn>
>
> do_div() does a 64-by-32 division. Here the divisor is an unsigned long
> which on some platforms is 64 bit wide. So use div64_ul instead of do_div
> to avoid a possible truncation.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
> ---
> 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 c5028e6b0f96..3b629870632c 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1707,7 +1707,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);
> + ns = div64_ul(ns, this_tsc_khz);
>
> if (likely(tscdeadline > guest_tsc) &&
> likely(ns > apic->lapic_timer.timer_advance_ns)) {
>
You could change this_tsc_khz to u32 instead, it's assigned from a
32-bit value.
Using div64_ul would be unnecessary and less efficient.
Paolo
prev parent reply other threads:[~2021-12-17 8:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-17 8:41 cgel.zte
2021-12-17 8:44 ` Paolo Bonzini [this message]
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=afacee89-4edb-f4fb-156d-7b6c8dd0bb3b@redhat.com \
--to=pbonzini@redhat.com \
--cc=bp@alien8.de \
--cc=cgel.zte@gmail.com \
--cc=dave.hansen@linux.intel.com \
--cc=deng.changcheng@zte.com.cn \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
--cc=zealci@zte.com.cn \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®