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/
This commit is contained in:
Christian König 2019-08-05 14:24:55 +02:00
Родитель d3c6dd1fb3
Коммит 5d344f58da
2 изменённых файлов: 7 добавлений и 26 удалений

Просмотреть файл

@ -49,12 +49,6 @@
DEFINE_WD_CLASS(reservation_ww_class); DEFINE_WD_CLASS(reservation_ww_class);
EXPORT_SYMBOL(reservation_ww_class); EXPORT_SYMBOL(reservation_ww_class);
struct lock_class_key reservation_seqcount_class;
EXPORT_SYMBOL(reservation_seqcount_class);
const char reservation_seqcount_string[] = "reservation_seqcount";
EXPORT_SYMBOL(reservation_seqcount_string);
/** /**
* reservation_object_list_alloc - allocate fence list * reservation_object_list_alloc - allocate fence list
* @shared_max: number of fences we need space for * @shared_max: number of fences we need space for
@ -103,9 +97,6 @@ static void reservation_object_list_free(struct reservation_object_list *list)
void reservation_object_init(struct reservation_object *obj) void reservation_object_init(struct reservation_object *obj)
{ {
ww_mutex_init(&obj->lock, &reservation_ww_class); ww_mutex_init(&obj->lock, &reservation_ww_class);
__seqcount_init(&obj->seq, reservation_seqcount_string,
&reservation_seqcount_class);
RCU_INIT_POINTER(obj->fence, NULL); RCU_INIT_POINTER(obj->fence, NULL);
RCU_INIT_POINTER(obj->fence_excl, NULL); RCU_INIT_POINTER(obj->fence_excl, NULL);
} }
@ -282,12 +273,10 @@ void reservation_object_add_excl_fence(struct reservation_object *obj,
dma_fence_get(fence); dma_fence_get(fence);
preempt_disable(); preempt_disable();
write_seqcount_begin(&obj->seq); rcu_assign_pointer(obj->fence_excl, fence);
/* write_seqcount_begin provides the necessary memory barrier */ /* pointer update must be visible before we modify the shared_count */
RCU_INIT_POINTER(obj->fence_excl, fence);
if (old) if (old)
old->shared_count = 0; smp_store_mb(old->shared_count, 0);
write_seqcount_end(&obj->seq);
preempt_enable(); preempt_enable();
/* inplace update, no shared fences */ /* inplace update, no shared fences */
@ -368,11 +357,8 @@ retry:
old = reservation_object_get_excl(dst); old = reservation_object_get_excl(dst);
preempt_disable(); preempt_disable();
write_seqcount_begin(&dst->seq); rcu_assign_pointer(dst->fence_excl, new);
/* write_seqcount_begin provides the necessary memory barrier */ rcu_assign_pointer(dst->fence, dst_list);
RCU_INIT_POINTER(dst->fence_excl, new);
RCU_INIT_POINTER(dst->fence, dst_list);
write_seqcount_end(&dst->seq);
preempt_enable(); preempt_enable();
reservation_object_list_free(src_list); reservation_object_list_free(src_list);

Просмотреть файл

@ -46,8 +46,6 @@
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
extern struct ww_class reservation_ww_class; extern struct ww_class reservation_ww_class;
extern struct lock_class_key reservation_seqcount_class;
extern const char reservation_seqcount_string[];
/** /**
* struct reservation_object_list - a list of shared fences * struct reservation_object_list - a list of shared fences
@ -71,7 +69,6 @@ struct reservation_object_list {
*/ */
struct reservation_object { struct reservation_object {
struct ww_mutex lock; struct ww_mutex lock;
seqcount_t seq;
struct dma_fence __rcu *fence_excl; struct dma_fence __rcu *fence_excl;
struct reservation_object_list __rcu *fence; struct reservation_object_list __rcu *fence;
@ -130,14 +127,12 @@ reservation_object_fences(struct reservation_object *obj,
struct reservation_object_list **list, struct reservation_object_list **list,
u32 *shared_count) u32 *shared_count)
{ {
unsigned int seq;
do { do {
seq = read_seqcount_begin(&obj->seq);
*excl = rcu_dereference(obj->fence_excl); *excl = rcu_dereference(obj->fence_excl);
*list = rcu_dereference(obj->fence); *list = rcu_dereference(obj->fence);
*shared_count = *list ? (*list)->shared_count : 0; *shared_count = *list ? (*list)->shared_count : 0;
} while (read_seqcount_retry(&obj->seq, seq)); smp_rmb(); /* See reservation_object_add_excl_fence */
} while (rcu_access_pointer(obj->fence_excl) != *excl);
} }
/** /**