mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
mm/mmu_notifier: set ->mm only after mmgrab()
Radeon uses a non-NULL notifier->mm to decide whether to call
mmu_interval_notifier_remove() when freeing a buffer object.
__mmu_interval_notifier_insert() sets ->mm before validating the range,
so a wrapping userptr range can leave ->mm set after insertion fails.
Cleanup then tries to remove an unregistered notifier for which no mm
reference was acquired.
Set ->mm only after mmgrab(), once insertion can no longer fail. While
we could fix radeon's code instead, setting ->mm on success only makes
the code more robust.
Fix generated by an LLM and sent by Chris Mason in private.
Fixes: 3506ff69c3 ("drm/radeon: use mmu_interval_notifier_insert")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ david: simplify description ]
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Tested-by: Muhammad Usama Anjum <usama.anjum@arm.com>
Link: https://patch.msgid.link/20261031-fixes_core-v3-29-d6437171ecc3@kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
This commit is contained in:
parent
6d65925777
commit
5ad9e4b0f1
|
|
@ -947,7 +947,6 @@ static int __mmu_interval_notifier_insert(
|
|||
struct mmu_notifier_subscriptions *subscriptions, unsigned long start,
|
||||
unsigned long length, const struct mmu_interval_notifier_ops *ops)
|
||||
{
|
||||
interval_sub->mm = mm;
|
||||
interval_sub->ops = ops;
|
||||
RB_CLEAR_NODE(&interval_sub->interval_tree.rb);
|
||||
interval_sub->interval_tree.start = start;
|
||||
|
|
@ -964,8 +963,12 @@ static int __mmu_interval_notifier_insert(
|
|||
if (WARN_ON(atomic_read(&mm->mm_users) <= 0))
|
||||
return -EINVAL;
|
||||
|
||||
/* pairs with mmdrop in mmu_interval_notifier_remove() */
|
||||
/*
|
||||
* Pairs with mmdrop in mmu_interval_notifier_remove(). Drivers take a
|
||||
* non-NULL ->mm for "registered", so set it only with the reference.
|
||||
*/
|
||||
mmgrab(mm);
|
||||
interval_sub->mm = mm;
|
||||
|
||||
/*
|
||||
* If some invalidate_range_start/end region is going on in parallel
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user