linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Josh Boyer <jwboyer@redhat.com>,
	One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
Subject: Re: [PATCH] ktime: Fix ktime_divns to do signed division
Date: Fri, 1 May 2015 17:00:09 -0700	[thread overview]
Message-ID: <CALAqxLXK9tTE_+6JVz6s0iPSa5vEiawdZNnezDBrEmh7BWexaQ@mail.gmail.com> (raw)
In-Reply-To: <alpine.LFD.2.11.1505011939060.7750@knanqh.ubzr>

On Fri, May 1, 2015 at 4:54 PM, Nicolas Pitre <nicolas.pitre@linaro.org> wrote:
> On Fri, 1 May 2015, John Stultz wrote:
>
>> It was noted that the 32bit implementation of ktime_divns
>> was doing unsgined division adn didn't properly handle
>> negative values.
>>
>> This patch fixes the problem by checking and preserving
>> the sign bit, and then reapplying it if appropriate
>> after the division.
>>
>> Unfortunately there is some duplication since we have
>> the optimized version for constant 32bit divider. I
>> was considering reworkign the __ktime_divns helper
>> to simplify the sign-handling logic, but then it
>> would likely just be a s64/s64 divide, and probably
>> should be more generic.
>>
>> Thoughts?
>
> Wouldn't it be better to simply forbid negative time altogether?  Given
> it's been broken for quite a while, there must not be that many
> instances of such usage and fixing them would avoid the useless sign
> handling overhead to 99.9% of the cases.

Well, ktime is basically an s64 and timespecs can be negative as well.
So I'm not sure its reasonable to disqualify negative time intervals
from using this function.  Especially since on 64bit systems,
ktime_divns handles negative intervals just fine.


>> Nicolas also notes that the ktime_divns() function
>> breaks if someone passes in a negative divisor as
>> well. This patch doesn't yet address that issue.
>
> GRanted, a negative divisor here would be even weirder and should
> definitely be rejected.  Maybe the infinite loop is a good thing in that
> case, probably better than producing wrong numbers.

Yea. I'm thinking a WARN_ON or a BUG would be good to have in both
32bit and 64bit cases so we avoid folks testing on 64bit and thinking
it works generally.

thanks
-john

  reply	other threads:[~2015-05-02  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-01 22:41 [PATCH] ktime: Fix ktime_divns to do signed division John Stultz
2015-05-01 22:43 ` John Stultz
2015-05-01 23:54 ` Nicolas Pitre
2015-05-02  0:00   ` John Stultz [this message]
2015-05-02  0:14 ` Nicolas Pitre
2015-05-02  8:31 ` Trevor Cordes

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=CALAqxLXK9tTE_+6JVz6s0iPSa5vEiawdZNnezDBrEmh7BWexaQ@mail.gmail.com \
    --to=john.stultz@linaro.org \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=jwboyer@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.pitre@linaro.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).