]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
drm/panfrost: Simplify lock_region calculation
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 24 Aug 2021 17:30:25 +0000 (13:30 -0400)
committerKelsey Skunberg <kelsey.skunberg@canonical.com>
Tue, 12 Oct 2021 22:31:40 +0000 (16:31 -0600)
commit2e21faf2662f0c4167cc1a8aab04e07b485f3a14
treea4f0ce55f122cafebdb0630cb75bc87dc90ed3e0
parent6463945cb41736adef4ffbfedfeae56d62be83fd
drm/panfrost: Simplify lock_region calculation

BugLink: https://bugs.launchpad.net/bugs/1946802
commit b5fab345654c603c07525100d744498f28786929 upstream.

In lock_region, simplify the calculation of the region_width parameter.
This field is the size, but encoded as ceil(log2(size)) - 1.
ceil(log2(size)) may be computed directly as fls(size - 1). However, we
want to use the 64-bit versions as the amount to lock can exceed
32-bits.

This avoids undefined (and completely wrong) behaviour when locking all
memory (size ~0). In this case, the old code would "round up" ~0 to the
nearest page, overflowing to 0. Since fls(0) == 0, this would calculate
a region width of 10 + 0 = 10. But then the code would shift by
(region_width - 11) = -1. As shifting by a negative number is undefined,
UBSAN flags the bug. Of course, even if it were defined the behaviour is
wrong, instead of locking all memory almost none would get locked.

The new form of the calculation corrects this special case and avoids
the undefined behaviour.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reported-and-tested-by: Chris Morgan <macromorgan@hotmail.com>
Fixes: f3ba91228e8e ("drm/panfrost: Add initial panfrost driver")
Cc: <stable@vger.kernel.org>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Steven Price <steven.price@arm.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210824173028.7528-2-alyssa.rosenzweig@collabora.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
drivers/gpu/drm/panfrost/panfrost_mmu.c