Skip to contentSkip to conversation

dma-buf: insert memory barrier before updating num_fences

PATCH In review Jay Wang 2 participants 2 messages Aug 8, 2025 – Aug 9, 2025 Stable branch

lore
Share & tools
lore

Jay Wang

author
#0 lore raw

PATCH 1/1 dma-buf: insert memory barrier before updating num_fences

From: Hyejeong Choi <[email protected]>

commit 72c7d62583ebce7baeb61acce6057c361f73be4a upstream.

smp_store_mb() inserts memory barrier after storing operation. It is different with what the comment is originally aiming so Null pointer dereference can be happened if memory update is reordered.

Fixes a590d0fdbaa5 ("dma-buf: Update reservation shared_count after adding the new fence")
[Conflict resolved by applying changes from dma_resv_add_fence() in the original fix to dma_resv_add_shared_fence() in current code base]
---
 drivers/dma-buf/dma-resv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dma-buf/dma-resv.c +3 -2
index 789f72db097f..16eb0b389e08 100644
@@ -291,8 +291,9 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence)
 
 replace:
 	RCU_INIT_POINTER(fobj->shared[i], fence);
-	/* pointer update must be visible before we extend the shared_count */
-	smp_store_mb(fobj->shared_count, count);
+	/* fence update must be visible before we extend the shared_count */
+	smp_wmb();
+	fobj->shared_count = count;
 
 	write_seqcount_end(&obj->seq);
 	dma_fence_put(old);
Signature · 1 line
2.47.3
maintainer
#1 lore raw

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected. No action required from the submitter.

The upstream commit SHA1 provided is correct: 72c7d62583ebce7baeb61acce6057c361f73be4a

WARNING: Author mismatch between patch and upstream commit:
Backport author: Jay Wang <[email protected]> Commit author: Hyejeong Choi <[email protected]>

Status in newer kernel trees:
6.15.y | Present (exact SHA1)
6.12.y | Present (different SHA1: fe1bebd0edb2) 6.6.y | Present (different SHA1: c9d2b9a80d06) 6.1.y | Present (different SHA1: 3becc659f9cb) 5.15.y | Not found

Note: The patch differs from the upstream commit:
---

1:  72c7d62583eb < -:  ------------ dma-buf: insert memory barrier before updating num_fences
-:  ------------ > 1:  eb3b4ab80d5e dma-buf: insert memory barrier before updating num_fences

---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| origin/linux-5.10.y       | Success     | Success    |