]> git.baikalelectronics.ru Git - kernel.git/commit
dma-debug: improve search for partial syncs
authorRobin Murphy <robin.murphy@arm.com>
Mon, 15 Aug 2022 19:28:40 +0000 (20:28 +0100)
committerChristoph Hellwig <hch@lst.de>
Wed, 7 Sep 2022 08:38:16 +0000 (10:38 +0200)
commit2e9c169f68d81b95fefbe2057ca5aac35b47072f
tree76fe9a7aa5cc776516fdc5d3754fe8a240f3bbc8
parent5e6e7bed228af148bab4983d1ba8e146ab7f35eb
dma-debug: improve search for partial syncs

When bucket_find_contains() tries to find the original entry for a
partial sync, it manages to constrain its search in a way that is both
too restrictive and not restrictive enough. A driver which only uses
single mappings rather than scatterlists might not set max_seg_size, but
could still technically perform a partial sync at an offset of more than
64KB into a sufficiently large mapping, so we could stop searching too
early before reaching a legitimate entry. Conversely, if no valid entry
is present and max_range is large enough, we can pointlessly search
buckets that we've already searched, or that represent an impossible
wrapping around the bottom of the address space. At worst, the
(legitimate) case of max_seg_size == UINT_MAX can make the loop
infinite.

Replace the fragile and frankly hard-to-follow "range" logic with a
simple counted loop for the number of possible hash buckets below the
given address.

Reported-by: Yunfei Wang <yf.wang@mediatek.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
kernel/dma/debug.c