From: David Laight <David.Laight@ACULAB.COM>
To: "'H. Peter Anvin'" <hpa@zytor.com>,
Jules Irenge <jbi.octave@gmail.com>,
"mingo@redhat.com" <mingo@redhat.com>
Cc: "tglx@linutronix.de" <tglx@linutronix.de>,
"bp@alien8.de" <bp@alien8.de>, "x86@kernel.org" <x86@kernel.org>,
"peterz@infradead.org" <peterz@infradead.org>,
"rdunlap@infradead.org" <rdunlap@infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 1/3] x86/tsc: Use div64_ul instead of do_div()
Date: Thu, 2 May 2024 16:30:18 +0000 [thread overview]
Message-ID: <5f30cab9917d4d46b581b06e00b792e9@AcuMS.aculab.com> (raw)
In-Reply-To: <7EE9AB38-3103-4091-A558-BF0DEAF61E1D@zytor.com>
From: H. Peter Anvin
> Sent: 28 April 2024 20:13
>
> On April 28, 2024 10:31:16 AM PDT, Jules Irenge <jbi.octave@gmail.com> wrote:
> >do_div() truncates a u64 divisor to 32 bit.
> >This can lead to non-zero being truncated to zero for division.
> >
> >Fix coccinelle warning
> >WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead
> >
> >Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
> >---
> > arch/x86/kernel/tsc.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> >index 5a69a49acc96..2da37f33dd17 100644
> >--- a/arch/x86/kernel/tsc.c
> >+++ b/arch/x86/kernel/tsc.c
> >@@ -484,7 +484,7 @@ static unsigned long pit_calibrate_tsc(u32 latch, unsigned long ms, int loopmin)
> >
> > /* Calculate the PIT value */
> > delta = t2 - t1;
> >- do_div(delta, ms);
> >+ div64_ul(delta, ms);
> > return delta;
> > }
> >
>
> Are you sure this is not a false positive? This is a *much* more expensive operation on 32 bits.
IIRC do_div() isn't that great either.
Somewhere it changed from being a simple wrapper on the x86 'div' instruction
(ie 64 by 32 giving 32 and 32) to being able to generate a 64bit quotent.
But the patch is entirely broken as well.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2024-05-02 16:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-28 17:31 [PATCH 1/3] x86/tsc: Use div64_ul instead of do_div() Jules Irenge
2024-04-28 19:13 ` H. Peter Anvin
2024-05-02 16:30 ` David Laight [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=5f30cab9917d4d46b581b06e00b792e9@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jbi.octave@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox