From: Vincent Pelletier <plr.vincent@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org,
Florian Fainelli <f.fainelli@gmail.com>,
Ray Jui <rjui@broadcom.com>,
Scott Branden <sbranden@broadcom.com>,
Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
linux-rpi-kernel@lists.infradead.org,
Tudor Ambarus <tudor.ambarus@microchip.com>
Subject: Re: 5.11.0-rc1+: "Division by zero in kernel." when writing to spidev
Date: Fri, 8 Jan 2021 01:10:44 +0000 [thread overview]
Message-ID: <20210108011044.5780aa96@gmail.com> (raw)
In-Reply-To: <20210107153546.GD4726@sirena.org.uk>
[-- Attachment #1: Type: text/plain, Size: 3038 bytes --]
On Thu, 7 Jan 2021 15:35:46 +0000, Mark Brown <broonie@kernel.org> wrote:
> Copying in a bunch of people for that driver.
Thanks.
I added Tudor Ambarus as well as my debugging points in the direction
of:
commit 9326e4f1e5dd1a4410c429638d3c412b6fc17040 (spi/for-5.10)
Author: Tudor Ambarus <tudor.ambarus@microchip.com>
Date: Wed Dec 9 19:35:14 2020 +0200
spi: Limit the spi device max speed to controller's max speed
Make sure the max_speed_hz of spi_device does not override
the max_speed_hz of controller.
> I'd not expect this to be required with a polled path, it's only needed
> if the transfer function returns a positive value indicating that the
> transfer is still in progress which shouldn't be the case when things
> are polled.
Oh, indeed. And the driver is indeed returning 0 in this case.
> > I'll continue poking around later (especially checking computed timeout values),
> > should I submit patches for s/complete/spi_finalize_current_transfer/ ?
Reverting
spi: Limit the spi device max speed to controller's max speed
fixes the timeout.
Which brings be back to devicetree:
- the controller node does not define the max clock rate
- the device I add in my overlay does define one
So spi->max_speed_hz is initially non-zero, but
spi->controller->max_speed_hz is zero, then:
- if (!spi->max_speed_hz)
+ if (!spi->max_speed_hz ||
+ spi->max_speed_hz > spi->controller->max_speed_hz)
spi->max_speed_hz = spi->controller->max_speed_hz;
it becomes zero in 5.11.
Then, because I do not specify a transfer speed in my userland code:
if (!xfer->speed_hz)
xfer->speed_hz = spi->max_speed_hz;
it gets zero instead of the (as of 5.10) 4MHz, which led to my original
division-by-zero issue.
What would be the correct fix ?
- declare controller max clock ?
If so, I think spi.c should warn about this missing value.
- do not cap transfer speed to controller speed when the latter is
zero ?
- both ?
My working out, for whatever it's worth:
I ran my userland code under "strace -tt -T" and get:
00:31:21.449837 write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4000) = -1 ETIMEDOUT (Connection timed out) <0.885552>
Given the previous divide-by-zero issue, spi.c is now assuming 100kHz,
which for this 4000 bytes buffer means:
>>> ((8*1000*4000)/100000) * 2 + 200
844.96
milliseconds, which roughly matches the call duration measured by
strace.
But this device is declared in my DT as supporting transfer rates up to
4MHz (so period of 250ns), which would mean an actual transfer duration
of:
>>> 4000*8*250e-9
0.008
assuming bytes being sent back-to-back (which I believe is the case for
SPI, but worst case I do not expect this to multiply the transfer time
by 100...). So there is something wrong with the transfer speed.
> Probably send the completion patch, yes.
Done.
Regards,
--
Vincent Pelletier
[-- Attachment #2: Signature digitale OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-01-08 1:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-06 12:55 5.11.0-rc1+: "Division by zero in kernel." when writing to spidev Vincent Pelletier
2021-01-06 13:00 ` Mark Brown
2021-01-06 15:06 ` Vincent Pelletier
2021-01-06 17:37 ` Mark Brown
2021-01-07 0:57 ` Vincent Pelletier
2021-01-07 15:35 ` Mark Brown
2021-01-08 1:10 ` Vincent Pelletier [this message]
2021-01-08 1:53 ` Fabio Estevam
2021-01-08 11:55 ` Vincent Pelletier
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=20210108011044.5780aa96@gmail.com \
--to=plr.vincent@gmail.com \
--cc=broonie@kernel.org \
--cc=f.fainelli@gmail.com \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=nsaenzjulienne@suse.de \
--cc=rjui@broadcom.com \
--cc=sbranden@broadcom.com \
--cc=tudor.ambarus@microchip.com \
/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).