Skip to content

Commit 5d344f5

Browse files
dma-buf: nuke reservation_object seq number
The only remaining use for this is to protect against setting a new exclusive fence while we grab both exclusive and shared. That can also be archived by looking if the exclusive fence has changed or not after completing the operation. v2: switch setting excl fence to rcu_assign_pointer Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Link: https://patchwork.freedesktop.org/patch/322380/
1 parent d3c6dd1 commit 5d344f5

2 files changed

Lines changed: 7 additions & 26 deletions

File tree

‎drivers/dma-buf/reservation.c‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@
4949
DEFINE_WD_CLASS(reservation_ww_class);
5050
EXPORT_SYMBOL(reservation_ww_class);
5151

52-
struct lock_class_key reservation_seqcount_class;
53-
EXPORT_SYMBOL(reservation_seqcount_class);
54-
55-
const char reservation_seqcount_string[] = "reservation_seqcount";
56-
EXPORT_SYMBOL(reservation_seqcount_string);
57-
5852
/**
5953
* reservation_object_list_alloc - allocate fence list
6054
* @shared_max: number of fences we need space for
@@ -103,9 +97,6 @@ static void reservation_object_list_free(struct reservation_object_list *list)
10397
void reservation_object_init(struct reservation_object *obj)
10498
{
10599
ww_mutex_init(&obj->lock, &reservation_ww_class);
106-
107-
__seqcount_init(&obj->seq, reservation_seqcount_string,
108-
&reservation_seqcount_class);
109100
RCU_INIT_POINTER(obj->fence, NULL);
110101
RCU_INIT_POINTER(obj->fence_excl, NULL);
111102
}
@@ -282,12 +273,10 @@ void reservation_object_add_excl_fence(struct reservation_object *obj,
282273
dma_fence_get(fence);
283274

284275
preempt_disable();
285-
write_seqcount_begin(&obj->seq);
286-
/* write_seqcount_begin provides the necessary memory barrier */
287-
RCU_INIT_POINTER(obj->fence_excl, fence);
276+
rcu_assign_pointer(obj->fence_excl, fence);
277+
/* pointer update must be visible before we modify the shared_count */
288278
if (old)
289-
old->shared_count = 0;
290-
write_seqcount_end(&obj->seq);
279+
smp_store_mb(old->shared_count, 0);
291280
preempt_enable();
292281

293282
/* inplace update, no shared fences */
@@ -368,11 +357,8 @@ int reservation_object_copy_fences(struct reservation_object *dst,
368357
old = reservation_object_get_excl(dst);
369358

370359
preempt_disable();
371-
write_seqcount_begin(&dst->seq);
372-
/* write_seqcount_begin provides the necessary memory barrier */
373-
RCU_INIT_POINTER(dst->fence_excl, new);
374-
RCU_INIT_POINTER(dst->fence, dst_list);
375-
write_seqcount_end(&dst->seq);
360+
rcu_assign_pointer(dst->fence_excl, new);
361+
rcu_assign_pointer(dst->fence, dst_list);
376362
preempt_enable();
377363

378364
reservation_object_list_free(src_list);

‎include/linux/reservation.h‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
#include <linux/rcupdate.h>
4747

4848
extern struct ww_class reservation_ww_class;
49-
extern struct lock_class_key reservation_seqcount_class;
50-
extern const char reservation_seqcount_string[];
5149

5250
/**
5351
* struct reservation_object_list - a list of shared fences
@@ -71,7 +69,6 @@ struct reservation_object_list {
7169
*/
7270
struct reservation_object {
7371
struct ww_mutex lock;
74-
seqcount_t seq;
7572

7673
struct dma_fence __rcu *fence_excl;
7774
struct reservation_object_list __rcu *fence;
@@ -130,14 +127,12 @@ reservation_object_fences(struct reservation_object *obj,
130127
struct reservation_object_list **list,
131128
u32 *shared_count)
132129
{
133-
unsigned int seq;
134-
135130
do {
136-
seq = read_seqcount_begin(&obj->seq);
137131
*excl = rcu_dereference(obj->fence_excl);
138132
*list = rcu_dereference(obj->fence);
139133
*shared_count = *list ? (*list)->shared_count : 0;
140-
} while (read_seqcount_retry(&obj->seq, seq));
134+
smp_rmb(); /* See reservation_object_add_excl_fence */
135+
} while (rcu_access_pointer(obj->fence_excl) != *excl);
141136
}
142137

143138
/**

0 commit comments

Comments
 (0)