mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V1] accel/amdxdna: Fully initialize map structure before registering notifier
@ 2026-09-11 16:39 Lizhi Hou
  2026-09-11 17:11 ` Max Zhen
  0 siblings, 1 reply; 3+ messages in thread
From: Lizhi Hou @ 2026-09-11 16:39 UTC (permalink / raw)
  To: ogabbay, quic_jhugo, mario.limonciello, karol.wachowski,
	dri-devel, max.zhen
  Cc: Lizhi Hou, linux-kernel, sonal.santan

The map structure is currently only partially initialized when the
notifier is registered. Although holding mmap_write_lock() prevents
the notifier callback from running before the remaining initialization
is complete, the ordering can be confusing during code review.

Fully initialize the map structure before registering the notifier so
that the structure is completely constructed before it is published.

Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
 drivers/accel/amdxdna/amdxdna_gem.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
index 5a1a2ee261b7..e861db6f9369 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.c
+++ b/drivers/accel/amdxdna/amdxdna_gem.c
@@ -415,6 +415,15 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,
 		goto free_map;
 	}
 
+	mapp->range.notifier = &mapp->notifier;
+	mapp->range.start = vma->vm_start;
+	mapp->range.end = vma->vm_end;
+	mapp->range.default_flags = HMM_PFN_REQ_FAULT;
+	mapp->abo = abo;
+	kref_init(&mapp->refcnt);
+
+	INIT_WORK(&mapp->hmm_unreg_work, amdxdna_hmm_unreg_work);
+
 	ret = mmu_interval_notifier_insert_locked(&mapp->notifier,
 						  current->mm,
 						  addr,
@@ -425,15 +434,6 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,
 		goto free_pfns;
 	}
 
-	mapp->range.notifier = &mapp->notifier;
-	mapp->range.start = vma->vm_start;
-	mapp->range.end = vma->vm_end;
-	mapp->range.default_flags = HMM_PFN_REQ_FAULT;
-	mapp->abo = abo;
-	kref_init(&mapp->refcnt);
-
-	INIT_WORK(&mapp->hmm_unreg_work, amdxdna_hmm_unreg_work);
-
 	down_write(&xdna->notifier_lock);
 	if (list_empty(&abo->mem.umap_list))
 		abo->mem.uva = addr;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V1] accel/amdxdna: Fully initialize map structure before registering notifier
  2026-09-11 16:39 [PATCH V1] accel/amdxdna: Fully initialize map structure before registering notifier Lizhi Hou
@ 2026-09-11 17:11 ` Max Zhen
  2026-09-17 16:14   ` Lizhi Hou
  0 siblings, 1 reply; 3+ messages in thread
From: Max Zhen @ 2026-09-11 17:11 UTC (permalink / raw)
  To: Lizhi Hou, ogabbay, quic_jhugo, mario.limonciello,
	karol.wachowski, dri-devel
  Cc: linux-kernel, sonal.santan



On 9/11/2026 Fri 09:39, Lizhi Hou wrote:
> The map structure is currently only partially initialized when the
> notifier is registered. Although holding mmap_write_lock() prevents
> the notifier callback from running before the remaining initialization
> is complete, the ordering can be confusing during code review.
> 
> Fully initialize the map structure before registering the notifier so
> that the structure is completely constructed before it is published.
> 
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Reviewed-by: Max Zhen <max.zhen@amd.com>
> ---
>   drivers/accel/amdxdna/amdxdna_gem.c | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
> index 5a1a2ee261b7..e861db6f9369 100644
> --- a/drivers/accel/amdxdna/amdxdna_gem.c
> +++ b/drivers/accel/amdxdna/amdxdna_gem.c
> @@ -415,6 +415,15 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,
>   		goto free_map;
>   	}
>   
> +	mapp->range.notifier = &mapp->notifier;
> +	mapp->range.start = vma->vm_start;
> +	mapp->range.end = vma->vm_end;
> +	mapp->range.default_flags = HMM_PFN_REQ_FAULT;
> +	mapp->abo = abo;
> +	kref_init(&mapp->refcnt);
> +
> +	INIT_WORK(&mapp->hmm_unreg_work, amdxdna_hmm_unreg_work);
> +
>   	ret = mmu_interval_notifier_insert_locked(&mapp->notifier,
>   						  current->mm,
>   						  addr,
> @@ -425,15 +434,6 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,
>   		goto free_pfns;
>   	}
>   
> -	mapp->range.notifier = &mapp->notifier;
> -	mapp->range.start = vma->vm_start;
> -	mapp->range.end = vma->vm_end;
> -	mapp->range.default_flags = HMM_PFN_REQ_FAULT;
> -	mapp->abo = abo;
> -	kref_init(&mapp->refcnt);
> -
> -	INIT_WORK(&mapp->hmm_unreg_work, amdxdna_hmm_unreg_work);
> -
>   	down_write(&xdna->notifier_lock);
>   	if (list_empty(&abo->mem.umap_list))
>   		abo->mem.uva = addr;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V1] accel/amdxdna: Fully initialize map structure before registering notifier
  2026-09-11 17:11 ` Max Zhen
@ 2026-09-17 16:14   ` Lizhi Hou
  0 siblings, 0 replies; 3+ messages in thread
From: Lizhi Hou @ 2026-09-17 16:14 UTC (permalink / raw)
  To: Max Zhen, ogabbay, quic_jhugo, mario.limonciello,
	karol.wachowski, dri-devel
  Cc: linux-kernel, sonal.santan

Applied to drm-misc-next

On 9/11/26 10:11, Max Zhen wrote:
>
>
> On 9/11/2026 Fri 09:39, Lizhi Hou wrote:
>> The map structure is currently only partially initialized when the
>> notifier is registered. Although holding mmap_write_lock() prevents
>> the notifier callback from running before the remaining initialization
>> is complete, the ordering can be confusing during code review.
>>
>> Fully initialize the map structure before registering the notifier so
>> that the structure is completely constructed before it is published.
>>
>> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
> Reviewed-by: Max Zhen <max.zhen@amd.com>
>> ---
>>   drivers/accel/amdxdna/amdxdna_gem.c | 18 +++++++++---------
>>   1 file changed, 9 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/accel/amdxdna/amdxdna_gem.c 
>> b/drivers/accel/amdxdna/amdxdna_gem.c
>> index 5a1a2ee261b7..e861db6f9369 100644
>> --- a/drivers/accel/amdxdna/amdxdna_gem.c
>> +++ b/drivers/accel/amdxdna/amdxdna_gem.c
>> @@ -415,6 +415,15 @@ static int amdxdna_hmm_register(struct 
>> amdxdna_gem_obj *abo,
>>           goto free_map;
>>       }
>>   +    mapp->range.notifier = &mapp->notifier;
>> +    mapp->range.start = vma->vm_start;
>> +    mapp->range.end = vma->vm_end;
>> +    mapp->range.default_flags = HMM_PFN_REQ_FAULT;
>> +    mapp->abo = abo;
>> +    kref_init(&mapp->refcnt);
>> +
>> +    INIT_WORK(&mapp->hmm_unreg_work, amdxdna_hmm_unreg_work);
>> +
>>       ret = mmu_interval_notifier_insert_locked(&mapp->notifier,
>>                             current->mm,
>>                             addr,
>> @@ -425,15 +434,6 @@ static int amdxdna_hmm_register(struct 
>> amdxdna_gem_obj *abo,
>>           goto free_pfns;
>>       }
>>   -    mapp->range.notifier = &mapp->notifier;
>> -    mapp->range.start = vma->vm_start;
>> -    mapp->range.end = vma->vm_end;
>> -    mapp->range.default_flags = HMM_PFN_REQ_FAULT;
>> -    mapp->abo = abo;
>> -    kref_init(&mapp->refcnt);
>> -
>> -    INIT_WORK(&mapp->hmm_unreg_work, amdxdna_hmm_unreg_work);
>> -
>>       down_write(&xdna->notifier_lock);
>>       if (list_empty(&abo->mem.umap_list))
>>           abo->mem.uva = addr;
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-17 16:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 16:39 [PATCH V1] accel/amdxdna: Fully initialize map structure before registering notifier Lizhi Hou
2026-09-11 17:11 ` Max Zhen
2026-09-17 16:14   ` Lizhi Hou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®