[PATCH 28/46] mm/mmu_notifier: set ->mm only after mmgrab()
Lorenzo Stoakes (ARM)
ljs at kernel.org
Tue Oct 27 01:50:46 PDT 2026
On Tue, Oct 27, 2026 at 12:17:48AM +0100, David Hildenbrand (Arm) wrote:
> From: Chris Mason <mason at kernel.org>
>
> 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: 3506ff69c3ec ("drm/radeon: use mmu_interval_notifier_insert")
> Cc: stable at vger.kernel.org
> Signed-off-by: Chris Mason <mason at kernel.org>
> [ david: simplify description ]
> Signed-off-by: David Hildenbrand (Arm) <david at kernel.org>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs at kernel.org>
> ---
> mm/mmu_notifier.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c
> index 2e20f88e162d7..a7bae5de5fedc 100644
> --- a/mm/mmu_notifier.c
> +++ b/mm/mmu_notifier.c
> @@ -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
>
> --
> 2.43.0
>
--
Cheers, Lorenzo
More information about the kexec
mailing list