From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: linux-rpi-kernel
<linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
"Noralf Trønnes" <noralf-L59+Z2yzLopAfugRpC6u6w@public.gmane.org>,
linux-spi <linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: spi: race in spi_finalize_current_message starting queue_kthread_work before the message is unmapped
Date: Tue, 12 May 2015 14:07:21 +0200 [thread overview]
Message-ID: <5551ECF9.1050006@martin.sperl.org> (raw)
In-Reply-To: <20150512102034.GM2761-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
On 2015-05-12 12:20, Mark Brown wrote:
> We can tell if it's a DMA transfer - if it's a DMA transfer then using
> anything except the SG list is a bit dodgy anyway since you're not
> really supposed to have the CPU look at anything that's mapped for the
> device (though it's generally fine if the device never actually DMAs).
>
>> So unless we have a separate flag to say we only need it for DMA,
>> then we have to keep the the current logic with allocation or we break
>> other drivers.
>
> We essentially have that; anything looking at a DMA mapped transfer had
> better cope.
I believe you miss my point:
a) with SPI_MASTER_MUST_ we will always allocate the buffer - we do not
take the result of can_dma into account when calculating the size.
This means we will allocate memory that is potentially too big for
what we really need (and it can even fail because it is too big
for the system to handle)
b) a driver in PIO mode can run without SPI_MASTER_MUST_XX
but when can_dma returns true it needs a scatter-gather-list and
in that case it needs SPI_MASTER_MUST_ to be set, but the allocation
is not really needed - just a scatter/gather list that does the
transfer - there is no means for the driver to state this
requirement clearly.
That is why I was asking for an additional flag SPI_MASTER_MUST_DMAONLY
to state that requirement.
Then we can extend the if in spi_map_msg to:
if ((master->flags & (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX)) &&
(! (master->flags & SPI_MASTER_MUST_DMAONLY)) {
and we save on the allocation when not needed.
And inside __spi_map_msg we can just add some code to create the simple
scatter-gather mapping using a single preallocated page - so something
along the lines (assuming that either tx_buf or rx_buf must be set):
if ((!xfer->tx_buf) && (master->flags & SPI_MASTER_MUST_TX)) {
ret = spi_map_null(master, tx_dev,
&xfer->tx_sg, &xfer->rx_sg,
DMA_TO_DEVICE);
if (ret != 0) {
spi_unmap_buf(master, rx_dev,
&xfer->rx_sg, DMA_FROM_DEVICE);
return ret;
}
}
if ((!xfer->rx_buf) && (master->flags & SPI_MASTER_MUST_RX)) {
ret = spi_map_null(master, rx_dev,
&xfer->rx_sg, &xfer->tx_sg,
DMA_FROM_DEVICE);
if (ret != 0) {
spi_unmap_buf(master, tx_dev,
&xfer->tx_sg, DMA_TO_DEVICE);
return ret;
}
}
Similarly we could also define 2 flags: SPI_MASTER_MUST_RX_SG and
SPI_MASTER_MUST_TX_SG and be open for more different options for
drivers.
One potentially could merge the functionality of spi_map_msg and
__spi_map_message into one to achive something similar without the
flag, but then this is a subtil change in the functionality which
may break existing drivers with different expectations about what
happens.
I see this last approach as the one with the highest risk of
breaking existing drivers.
So the extra flag seems to be to be a "safer" approach and it also
states more explicitly the needs of the driver.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2015-05-12 12:07 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <8C375B28-1C09-4545-8A5B-78F6CD04102F@martin.sperl.org>
[not found] ` <20150508221309.GK2761@sirena.org.uk>
[not found] ` <20150508221309.GK2761-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-05-09 6:40 ` spi: race in spi_finalize_current_message starting queue_kthread_work before the message is unmapped Martin Sperl
[not found] ` <352560EA-A323-449B-8F37-6066328D2081-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-11 18:00 ` Mark Brown
[not found] ` <20150511180016.GU3458-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-05-11 19:27 ` Martin Sperl
[not found] ` <8F4019F0-7C56-4C9C-9193-A2A23B533165-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-12 10:20 ` Mark Brown
[not found] ` <20150512102034.GM2761-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-05-12 12:07 ` Martin Sperl [this message]
[not found] ` <5551ECF9.1050006-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-12 16:50 ` Mark Brown
[not found] ` <20150512165053.GE3066-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-05-14 9:49 ` Martin Sperl
2015-05-14 9:58 ` [PATCH] spi: SPI_MASTER_MUST_* with scatter-gather only option and avoiding realloc kernel-TqfNSX0MhmxHKSADF0wUEw
[not found] ` <1431597524-7907-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-14 11:19 ` Martin Sperl
2015-05-19 12:46 ` Mark Brown
[not found] ` <20150519124632.GN2761-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-05-19 14:17 ` Martin Sperl
[not found] ` <CA52E701-A9BF-45F1-AE2A-CD3E680CEAFC-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-22 11:34 ` Mark Brown
[not found] ` <20150522113421.GE21391-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-05-22 14:09 ` Martin Sperl
[not found] ` <2B971A09-33E3-42BC-B13D-49B6DD3D2E7A-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-24 9:34 ` [PATCH] spi: add missing cleanup in spi_map_msg on error kernel-TqfNSX0MhmxHKSADF0wUEw
[not found] ` <1432460086-2549-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-25 10:10 ` [PATCH V2] " kernel-TqfNSX0MhmxHKSADF0wUEw
[not found] ` <1432548630-2202-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-25 13:05 ` Mark Brown
2015-05-25 12:44 ` [PATCH 0/4] dma map single page multiple times in sg_list kernel-TqfNSX0MhmxHKSADF0wUEw
[not found] ` <1432557867-2427-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-25 12:44 ` [PATCH 1/4] spi: dma map a single page multiple times in sg_list for rx/tx_buf == NULL kernel-TqfNSX0MhmxHKSADF0wUEw
2015-05-25 12:44 ` [PATCH 2/4] spi: bcm2835: no longer requires SPI_MASTER_MUST_RX/TX kernel-TqfNSX0MhmxHKSADF0wUEw
2015-05-25 12:44 ` [PATCH 3/4] spi: add flags SPI_MASTER_MUST_*_SG to api kernel-TqfNSX0MhmxHKSADF0wUEw
2015-05-25 12:44 ` [PATCH 4/4] spi: bcm2835: set SPI_MASTER_MUST_RX_SG/TX_SG flags kernel-TqfNSX0MhmxHKSADF0wUEw
2015-05-10 7:50 ` [PATCH] spi: fix race freeing dummy_tx/rx before it is unmapped kernel-TqfNSX0MhmxHKSADF0wUEw
[not found] ` <8C375B28-1C09-4545-8A5B-78F6CD04102F-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-09 6:40 ` spi: race in spi_finalize_current_message starting queue_kthread_work before the message " Martin Sperl
[not found] ` <3374181B-61BE-4DAA-9D92-68B43BEF3E1D-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-05-13 7:52 ` Lee Jones
2015-05-13 11:47 ` Mark Brown
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=5551ECF9.1050006@martin.sperl.org \
--to=kernel-tqfnsx0mhmxhksadf0wuew@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=noralf-L59+Z2yzLopAfugRpC6u6w@public.gmane.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;
as well as URLs for NNTP newsgroup(s).