lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdVfoQ-vW3VeO8vDVALNREBV1afaSnwnc0jnkoXmvw6xhQ@mail.gmail.com>
Date:   Tue, 15 Sep 2020 15:35:00 +0200
From:   Geert Uytterhoeven <geert@...ux-m68k.org>
To:     "Daniel W. S. Almeida" <dwlsalmeida@...il.com>
Cc:     "mchehab+huawei@...nel.org" <mchehab+huawei@...nel.org>,
        "r.verdejo@...sung.com" <r.verdejo@...sung.com>,
        "nicolas@...fresne.ca" <nicolas@...fresne.ca>,
        "linux-media@...r.kernel.org" <linux-media@...r.kernel.org>,
        "skhan@...uxfoundation.org" <skhan@...uxfoundation.org>,
        "linux-kernel-mentees@...ts.linuxfoundation.org" 
        <linux-kernel-mentees@...ts.linuxfoundation.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [v10 3/4] media: vidtv: add a bridge driver

Hi Daniel,

On Tue, Sep 15, 2020 at 3:26 PM Daniel W. S. Almeida
<dwlsalmeida@...il.com> wrote:
> >> +    u32 nbytes = 0;  /* the number of bytes written by this function */
> >> +
> >> +    u64 nbytes_expected; /* the number of bytes we should have written */
> >> +    u64 nbytes_streamed; /* the number of bytes we actually wrote */
> >> +    u32 num_null_pkts; /* number of null packets to bridge the gap */
> >> +
> >> +    u64 elapsed_time_msecs = jiffies_to_usecs(m->timing.current_jiffies -
> >> +                                              m->timing.past_jiffies);
> >> +
> >> +    elapsed_time_msecs = min(elapsed_time_msecs,
> >> (u64)VIDTV_MAX_SLEEP_USECS / 1000);
> >> +    nbytes_expected = div64_u64(m->mux_rate_kbytes_sec * 1000, MSEC_PER_SEC);
> >
> > Seriously?!?
> >
> > You multiply by 1000 first, followed by a division by 1000 using an
> > expensive 64-by-64 division?
>
> This entire function is broken and needs a do-over :)
>
> > using an expensive 64-by-64 division?
>
> I am new to kernel development. I wasn't even aware that this was
> expensive, to be honest.

All divisions involving 64-bit data are expensive, especially on 32-bit
platforms.  That's why we have the helpers in <linux/math.h>.  Most
of them implement simplified variants, which are less expensive.

> >> +    if (nbytes_streamed < nbytes_expected) {
> >> +            /* can't write half a packet: roundup to a 188 multiple */
> >> +            nbytes_expected  = roundup(nbytes_expected - nbytes_streamed, TS_PACKET_LEN);
> >
> > drivers/media/test-drivers/vidtv/vidtv_mux.o: In function `vidtv_mux_tick':
> > vidtv_mux.c:(.text+0x788): undefined reference to `__udivdi3'
> >
> > This is a 64-by-32 division, hence it should use a helper from
> > <linux/math64.h>.
> >
> > However, I'm wondering if "nbytes_expected - nbytes_streamed" is
> > guaranteed to be a "small" number, hence a 32-by-32 division would be
> > sufficient?
>
> I think so.
>
> I will send a patch to address the things you pointed out in this email.

Thanks, looking forward to it!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ