Skip to contentSkip to conversation

dma-buf: add new dma_fence_chain container v6

PATCH In review Chunming Zhou 6 participants 16 messages Mar 20, 2019 – Mar 22, 2019 5 messages not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/9 dma-buf: add new dma_fence_chain container v6

From: Christian König <[email protected]>

Lockless container implementation similar to a dma_fence_array, but with only two elements per node and automatic garbage collection.

v2: properly document dma_fence_chain_for_each, add dma_fence_chain_find_seqno,
drop prev reference during garbage collection if it's not a chain fence.
v3: use head and iterator for dma_fence_chain_for_each
v4: fix reference count in dma_fence_chain_enable_signaling
v5: fix iteration when walking each chain node
v6: add __rcu for member 'prev' of struct chain node

Cc Lionel Landwerlin <[email protected]>
---
 drivers/dma-buf/Makefile          |   3 +-
 drivers/dma-buf/dma-fence-chain.c | 241 ++++++++++++++++++++++++++++++
 include/linux/dma-fence-chain.h   |  81 ++++++++++
 3 files changed, 324 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma-buf/dma-fence-chain.c
 create mode 100644 include/linux/dma-fence-chain.h
drivers/dma-buf/Makefile +2 -1
index 0913a6ccab5a..1f006e083eb9 100644
@@ -1,4 +1,5 @@
-obj-y := dma-buf.o dma-fence.o dma-fence-array.o reservation.o seqno-fence.o
+obj-y := dma-buf.o dma-fence.o dma-fence-array.o dma-fence-chain.o \
+	 reservation.o seqno-fence.o
 obj-$(CONFIG_SYNC_FILE)		+= sync_file.o
 obj-$(CONFIG_SW_SYNC)		+= sw_sync.o sync_debug.o
 obj-$(CONFIG_UDMABUF)		+= udmabuf.o
drivers/dma-buf/dma-fence-chain.c new file +241 -0

241 lines not on this page · raw message

include/linux/dma-fence-chain.h new file +81 -0

81 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 2/9 drm/syncobj: add new drm_syncobj_add_point interface v4

From: Christian König <[email protected]>

Use the dma_fence_chain object to create a timeline of fence objects instead of just replacing the existing fence.

v2: rebase and cleanup
v3: fix garbage collection parameters
v4: add unorder point check, print a warn calltrace

Cc Lionel Landwerlin <[email protected]>
---
 drivers/gpu/drm/drm_syncobj.c | 39 +++++++++++++++++++++++++++++++++++
 include/drm/drm_syncobj.h     |  5 +++++
 2 files changed, 44 insertions(+)
drivers/gpu/drm/drm_syncobj.c +39 -0
index 5329e66598c6..19a9ce638119 100644
@@ -122,6 +122,45 @@ static void drm_syncobj_remove_wait(struct drm_syncobj *syncobj,
 	spin_unlock(&syncobj->lock);
 }
 
+/**
+ * drm_syncobj_add_point - add new timeline point to the syncobj
+ * @syncobj: sync object to add timeline point do
+ * @chain: chain node to use to add the point
+ * @fence: fence to encapsulate in the chain node
+ * @point: sequence number to use for the point
+ *
+ * Add the chain node as new timeline point to the syncobj.
+ */
+void drm_syncobj_add_point(struct drm_syncobj *syncobj,
+			   struct dma_fence_chain *chain,
+			   struct dma_fence *fence,
+			   uint64_t point)
+{
+	struct syncobj_wait_entry *cur, *tmp;
+	struct dma_fence *prev;
+
+	dma_fence_get(fence);
+
+	spin_lock(&syncobj->lock);
+
+	prev = drm_syncobj_fence_get(syncobj);
+	/* You are adding an unorder point to timeline, which could cause payload returned from query_ioctl is 0! */
+	WARN_ON_ONCE(prev && prev->seqno >= point);
+	dma_fence_chain_init(chain, prev, fence, point);
+	rcu_assign_pointer(syncobj->fence, &chain->base);
+
+	list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) {
+		list_del_init(&cur->node);
+		syncobj_wait_syncobj_func(syncobj, cur);
+	}
+	spin_unlock(&syncobj->lock);
+
+	/* Walk the chain once to trigger garbage collection */
+	dma_fence_chain_for_each(fence, prev);
+	dma_fence_put(prev);
+}
+EXPORT_SYMBOL(drm_syncobj_add_point);
+
 /**
  * drm_syncobj_replace_fence - replace fence in a sync object.
  * @syncobj: Sync object to replace fence in
include/drm/drm_syncobj.h +5 -0
index 0311c9fdbd2f..6cf7243a1dc5 100644
@@ -27,6 +27,7 @@
 #define __DRM_SYNCOBJ_H__
 
 #include <linux/dma-fence.h>
+#include <linux/dma-fence-chain.h>
 
 struct drm_file;
 
@@ -112,6 +113,10 @@ drm_syncobj_fence_get(struct drm_syncobj *syncobj)
 
 struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
 				     u32 handle);
+void drm_syncobj_add_point(struct drm_syncobj *syncobj,
+			   struct dma_fence_chain *chain,
+			   struct dma_fence *fence,
+			   uint64_t point);
 void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
 			       struct dma_fence *fence);
 int drm_syncobj_find_fence(struct drm_file *file_private,
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#3 lore raw

PATCH 3/9 drm/syncobj: add support for timeline point wait v8

In reply to a message not in the archive

points array is one-to-one match with syncobjs array. v2:
add seperate ioctl for timeline point wait, otherwise break uapi. v3:
userspace can specify two kinds waits::
a. Wait for time point to be completed.
b. and wait for time point to become available
v4:
rebase
v5:
add comment for xxx_WAIT_AVAILABLE
v6: rebase and rework on new container
v7: drop _WAIT_COMPLETED, it is the default anyway
v8: correctly handle garbage collected fences

Cc Tobias Hector <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc Dave Airlie <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Lionel Landwerlin <[email protected]>
---
 drivers/gpu/drm/drm_internal.h |   2 +
 drivers/gpu/drm/drm_ioctl.c    |   2 +
 drivers/gpu/drm/drm_syncobj.c  | 153 ++++++++++++++++++++++++++-------
 include/uapi/drm/drm.h         |  15 ++++
 4 files changed, 143 insertions(+), 29 deletions(-)
drivers/gpu/drm/drm_internal.h +2 -0
index 251d67e04c2d..331ac6225b58 100644
@@ -182,6 +182,8 @@ int drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
 				   struct drm_file *file_private);
 int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
 			   struct drm_file *file_private);
+int drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
+				    struct drm_file *file_private);
 int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file_private);
 int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/drm_ioctl.c +2 -0
index 687943df58e1..c984654646fa 100644
@@ -688,6 +688,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_WAIT, drm_syncobj_wait_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT, drm_syncobj_timeline_wait_ioctl,
+		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_RESET, drm_syncobj_reset_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl,
drivers/gpu/drm/drm_syncobj.c +124 -29

253 lines not on this page · raw message

include/uapi/drm/drm.h +15 -0
index 300f336633f2..44ebcdd9bd1d 100644
@@ -737,6 +737,7 @@ struct drm_syncobj_handle {
 
 #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)
 #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)
+#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2) /* wait for time point to become available */
 struct drm_syncobj_wait {
 	__u64 handles;
 	/* absolute timeout */
@@ -747,6 +748,19 @@ struct drm_syncobj_wait {
 	__u32 pad;
 };
 
+struct drm_syncobj_timeline_wait {
+	__u64 handles;
+	/* wait on specific timeline point for every handles*/
+	__u64 points;
+	/* absolute timeout */
+	__s64 timeout_nsec;
+	__u32 count_handles;
+	__u32 flags;
+	__u32 first_signaled; /* only valid when not waiting all */
+	__u32 pad;
+};
+
+
 struct drm_syncobj_array {
 	__u64 handles;
 	__u32 count_handles;
@@ -909,6 +923,7 @@ extern "C" {
 #define DRM_IOCTL_MODE_GET_LEASE	DRM_IOWR(0xC8, struct drm_mode_get_lease)
 #define DRM_IOCTL_MODE_REVOKE_LEASE	DRM_IOWR(0xC9, struct drm_mode_revoke_lease)
 
+#define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT	DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait)
 /**
  * Device specific ioctls should only be in their respective headers
  * The device specific ioctl range is from 0x40 to 0x9f.
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#4 lore raw

PATCH 4/9 drm/syncobj: add timeline payload query ioctl v6

In reply to a message not in the archive

user mode can query timeline payload.
v2: check return value of copy_to_user
v3: handle querying entry by entry
v4: rebase on new chain container, simplify interface
v5: query last signaled timeline point, not last point.
v6: add unorder point check

Cc Tobias Hector <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc Dave Airlie <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Lionel Landwerlin <[email protected]>
---
 drivers/gpu/drm/drm_internal.h |  2 ++
 drivers/gpu/drm/drm_ioctl.c    |  2 ++
 drivers/gpu/drm/drm_syncobj.c  | 62 ++++++++++++++++++++++++++++++++++
 include/uapi/drm/drm.h         | 10 ++++++
 4 files changed, 76 insertions(+)
drivers/gpu/drm/drm_internal.h +2 -0
index 331ac6225b58..695179bb88dc 100644
@@ -188,6 +188,8 @@ int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file_private);
 int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
 			     struct drm_file *file_private);
+int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
+			    struct drm_file *file_private);
 
 /* drm_framebuffer.c */
 void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
drivers/gpu/drm/drm_ioctl.c +2 -0
index c984654646fa..7a534c184e52 100644
@@ -694,6 +694,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_QUERY, drm_syncobj_query_ioctl,
+		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_CRTC_GET_SEQUENCE, drm_crtc_get_sequence_ioctl, DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_CRTC_QUEUE_SEQUENCE, drm_crtc_queue_sequence_ioctl, DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER|DRM_UNLOCKED),
drivers/gpu/drm/drm_syncobj.c +62 -0

65 lines not on this page · raw message

include/uapi/drm/drm.h +10 -0
index 44ebcdd9bd1d..c62be0840ba5 100644
@@ -767,6 +767,14 @@ struct drm_syncobj_array {
 	__u32 pad;
 };
 
+struct drm_syncobj_timeline_array {
+	__u64 handles;
+	__u64 points;
+	__u32 count_handles;
+	__u32 pad;
+};
+
+
 /* Query current scanout sequence number */
 struct drm_crtc_get_sequence {
 	__u32 crtc_id;		/* requested crtc_id */
@@ -924,6 +932,8 @@ extern "C" {
 #define DRM_IOCTL_MODE_REVOKE_LEASE	DRM_IOWR(0xC9, struct drm_mode_revoke_lease)
 
 #define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT	DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait)
+#define DRM_IOCTL_SYNCOBJ_QUERY		DRM_IOWR(0xCB, struct drm_syncobj_timeline_array)
+
 /**
  * Device specific ioctls should only be in their respective headers
  * The device specific ioctl range is from 0x40 to 0x9f.
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#5 lore raw

PATCH 6/9 drm/amdgpu: add timeline support in amdgpu CS v3

In reply to a message not in the archive

syncobj wait/signal operation is appending in command submission.
v2: separate to two kinds in/out_deps functions
v3: fix checking for timeline syncobj

Cc Tobias Hector <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc Dave Airlie <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Lionel Landwerlin <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 152 +++++++++++++++++++++----
 include/uapi/drm/amdgpu_drm.h          |   8 ++
 3 files changed, 144 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +8 -2
index 8d0d7f3dd5fb..deec2c796253 100644
@@ -433,6 +433,12 @@ struct amdgpu_cs_chunk {
 	void			*kdata;
 };
 
+struct amdgpu_cs_post_dep {
+	struct drm_syncobj *syncobj;
+	struct dma_fence_chain *chain;
+	u64 point;
+};
+
 struct amdgpu_cs_parser {
 	struct amdgpu_device	*adev;
 	struct drm_file		*filp;
@@ -462,8 +468,8 @@ struct amdgpu_cs_parser {
 	/* user fence */
 	struct amdgpu_bo_list_entry	uf_entry;
 
-	unsigned num_post_dep_syncobjs;
-	struct drm_syncobj **post_dep_syncobjs;
+	unsigned			num_post_deps;
+	struct amdgpu_cs_post_dep	*post_deps;
 };
 
 static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +128 -24

229 lines not on this page · raw message

include/uapi/drm/amdgpu_drm.h +8 -0
index 4a53f6cfa034..e928760c4c1a 100644
@@ -525,6 +525,8 @@ struct drm_amdgpu_gem_va {
 #define AMDGPU_CHUNK_ID_SYNCOBJ_OUT     0x05
 #define AMDGPU_CHUNK_ID_BO_HANDLES      0x06
 #define AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES	0x07
+#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT    0x08
+#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL  0x09
 
 struct drm_amdgpu_cs_chunk {
 	__u32		chunk_id;
@@ -605,6 +607,12 @@ struct drm_amdgpu_cs_chunk_sem {
 	__u32 handle;
 };
 
+struct drm_amdgpu_cs_chunk_syncobj {
+       __u32 handle;
+       __u32 flags;
+       __u64 point;
+};
+
 #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ	0
 #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD	1
 #define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD	2
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#6 lore raw

PATCH 7/9 drm/syncobj: add transition iotcls between binary and timeline v2

In reply to a message not in the archive

we need to import/export timeline point.

v2: unify to one transfer ioctl

Cc Lionel Landwerlin <[email protected]>
---
 drivers/gpu/drm/drm_internal.h |  2 +
 drivers/gpu/drm/drm_ioctl.c    |  2 +
 drivers/gpu/drm/drm_syncobj.c  | 74 ++++++++++++++++++++++++++++++++++
 include/uapi/drm/drm.h         | 10 +++++
 4 files changed, 88 insertions(+)
drivers/gpu/drm/drm_internal.h +2 -0
index 695179bb88dc..dd11ae5f1eef 100644
@@ -180,6 +180,8 @@ int drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,
 				   struct drm_file *file_private);
 int drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
 				   struct drm_file *file_private);
+int drm_syncobj_transfer_ioctl(struct drm_device *dev, void *data,
+			       struct drm_file *file_private);
 int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
 			   struct drm_file *file_private);
 int drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/drm_ioctl.c +2 -0
index 7a534c184e52..92b3b7b2fd81 100644
@@ -686,6 +686,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, drm_syncobj_fd_to_handle_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TRANSFER, drm_syncobj_transfer_ioctl,
+		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_WAIT, drm_syncobj_wait_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT, drm_syncobj_timeline_wait_ioctl,
drivers/gpu/drm/drm_syncobj.c +74 -0

80 lines not on this page · raw message

include/uapi/drm/drm.h +10 -0
index c62be0840ba5..e8d0d6b51875 100644
@@ -735,6 +735,15 @@ struct drm_syncobj_handle {
 	__u32 pad;
 };
 
+struct drm_syncobj_transfer {
+	__u32 src_handle;
+	__u32 dst_handle;
+	__u64 src_point;
+	__u64 dst_point;
+	__u32 flags;
+	__u32 pad;
+};
+
 #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)
 #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)
 #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2) /* wait for time point to become available */
@@ -933,6 +942,7 @@ extern "C" {
 
 #define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT	DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait)
 #define DRM_IOCTL_SYNCOBJ_QUERY		DRM_IOWR(0xCB, struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_TRANSFER	DRM_IOWR(0xCC, struct drm_syncobj_transfer)
 
 /**
  * Device specific ioctls should only be in their respective headers
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#7 lore raw

PATCH 8/9 drm/syncobj: add timeline signal ioctl for syncobj v4

In reply to a message not in the archive

v2: individually allocate chain array, since chain node is free independently.
v3: all existing points must be already signaled before cpu perform signal operation,
so add check condition for that.
v4: remove v3 change and add checking to prevent out-of-order

Cc Tobias Hector <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc Dave Airlie <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Lionel Landwerlin <[email protected]>
---
 drivers/gpu/drm/drm_internal.h |  2 +
 drivers/gpu/drm/drm_ioctl.c    |  2 +
 drivers/gpu/drm/drm_syncobj.c  | 93 ++++++++++++++++++++++++++++++++++
 include/uapi/drm/drm.h         |  1 +
 4 files changed, 98 insertions(+)
drivers/gpu/drm/drm_internal.h +2 -0
index dd11ae5f1eef..d9a483a5fce0 100644
@@ -190,6 +190,8 @@ int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file_private);
 int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
 			     struct drm_file *file_private);
+int drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
+				      struct drm_file *file_private);
 int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file_private);
 
drivers/gpu/drm/drm_ioctl.c +2 -0
index 92b3b7b2fd81..d337f161909c 100644
@@ -696,6 +696,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL, drm_syncobj_timeline_signal_ioctl,
+		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_QUERY, drm_syncobj_query_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_CRTC_GET_SEQUENCE, drm_crtc_get_sequence_ioctl, DRM_UNLOCKED),
drivers/gpu/drm/drm_syncobj.c +93 -0

99 lines not on this page · raw message

include/uapi/drm/drm.h +1 -0
index e8d0d6b51875..236b01a1fabf 100644
@@ -943,6 +943,7 @@ extern "C" {
 #define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT	DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait)
 #define DRM_IOCTL_SYNCOBJ_QUERY		DRM_IOWR(0xCB, struct drm_syncobj_timeline_array)
 #define DRM_IOCTL_SYNCOBJ_TRANSFER	DRM_IOWR(0xCC, struct drm_syncobj_transfer)
+#define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL	DRM_IOWR(0xCD, struct drm_syncobj_timeline_array)
 
 /**
  * Device specific ioctls should only be in their respective headers
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#8 lore raw

PATCH 9/9 drm/amdgpu: update version for timeline syncobj support in amdgpu

In reply to a message not in the archive
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
index 8a0732088640..4d8db87048d3 100644
@@ -74,9 +74,10 @@
  * - 3.28.0 - Add AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES
  * - 3.29.0 - Add AMDGPU_IB_FLAG_RESET_GDS_MAX_WAVE_ID
  * - 3.30.0 - Add AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE.
+ * - 3.31.0 - Add syncobj timeline support to AMDGPU_CS.
  */
 #define KMS_DRIVER_MAJOR	3
-#define KMS_DRIVER_MINOR	30
+#define KMS_DRIVER_MINOR	31
 #define KMS_DRIVER_PATCHLEVEL	0
 
 int amdgpu_vram_limit = 0;
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#9 lore raw

PATCH 5/9 drm/syncobj: use the timeline point in drm_syncobj_find_fence v4

In reply to Chunming Zhou

From: Christian König <[email protected]>

Implement finding the right timeline point in drm_syncobj_find_fence.

v2: return -EINVAL when the point is not submitted yet.
v3: fix reference counting bug, add flags handling as well
v4: add timeout for find fence

Cc Lionel Landwerlin <[email protected]>
---
 drivers/gpu/drm/drm_syncobj.c | 50 ++++++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_syncobj.c +47 -3
index 0e62a793c8dd..087fd4e7eaf3 100644
@@ -213,6 +213,8 @@ static void drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
 	dma_fence_put(fence);
 }
 
+/* 5s default for wait submission */
+#define DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT 5000000000ULL
 /**
  * drm_syncobj_find_fence - lookup and reference the fence in a sync object
  * @file_private: drm file private pointer
@@ -233,16 +235,58 @@ int drm_syncobj_find_fence(struct drm_file *file_private,
 			   struct dma_fence **fence)
 {
 	struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle);
-	int ret = 0;
+	struct syncobj_wait_entry wait;
+	u64 timeout = nsecs_to_jiffies64(DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT);
+	int ret;
 
 	if (!syncobj)
 		return -ENOENT;
 
 	*fence = drm_syncobj_fence_get(syncobj);
-	if (!*fence) {
+	drm_syncobj_put(syncobj);
+
+	if (*fence) {
+		ret = dma_fence_chain_find_seqno(fence, point);
+		if (!ret)
+			return 0;
+		dma_fence_put(*fence);
+	} else {
 		ret = -EINVAL;
 	}
-	drm_syncobj_put(syncobj);
+
+	if (!(flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT))
+		return ret;
+
+	memset(&wait, 0, sizeof(wait));
+	wait.task = current;
+	wait.point = point;
+	drm_syncobj_fence_add_wait(syncobj, &wait);
+
+	do {
+		set_current_state(TASK_INTERRUPTIBLE);
+		if (wait.fence) {
+			ret = 0;
+			break;
+		}
+                if (timeout == 0) {
+                        ret = -ETIME;
+                        break;
+                }
+
+		if (signal_pending(current)) {
+			ret = -ERESTARTSYS;
+			break;
+		}
+
+                timeout = schedule_timeout(timeout);
+	} while (1);
+
+	__set_current_state(TASK_RUNNING);
+	*fence = wait.fence;
+
+	if (wait.node.next)
+		drm_syncobj_remove_wait(syncobj, &wait);
+
 	return ret;
 }
 EXPORT_SYMBOL(drm_syncobj_find_fence);
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw
In reply to Chunming Zhou
I love your patch! Perhaps something to improve:

Hi Chunming,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.1-rc1 next-20190320]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Chunming-Zhou/dma-buf-add-new-dma_fence_chain-container-v6/20190320-223607
reproduce:

        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

sparse warnings: (new ones prefixed by >>)

>> drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__old @@    got  dma_fence [noderef] <asn:4>*__old @@
   drivers/dma-buf/dma-fence-chain.c:73:23:    expected struct dma_fence [noderef] <asn:4>*__old
   drivers/dma-buf/dma-fence-chain.c:73:23:    got struct dma_fence *[assigned] prev
>> drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__new @@    got  dma_fence [noderef] <asn:4>*__new @@
   drivers/dma-buf/dma-fence-chain.c:73:23:    expected struct dma_fence [noderef] <asn:4>*__new
   drivers/dma-buf/dma-fence-chain.c:73:23:    got struct dma_fence *[assigned] replacement
>> drivers/dma-buf/dma-fence-chain.c:73:21: sparse: incorrect type in assignment (different address spaces) @@    expected struct dma_fence *tmp @@    got struct dma_fence [noderef] <struct dma_fence *tmp @@
   drivers/dma-buf/dma-fence-chain.c:73:21:    expected struct dma_fence *tmp
   drivers/dma-buf/dma-fence-chain.c:73:21:    got struct dma_fence [noderef] <asn:4>*[assigned] __ret
>> drivers/dma-buf/dma-fence-chain.c:190:28: sparse: incorrect type in argument 1 (different address spaces) @@    expected struct dma_fence *fence @@    got struct dma_fence struct dma_fence *fence @@
   drivers/dma-buf/dma-fence-chain.c:190:28:    expected struct dma_fence *fence
   drivers/dma-buf/dma-fence-chain.c:190:28:    got struct dma_fence [noderef] <asn:4>*prev
>> drivers/dma-buf/dma-fence-chain.c:222:21: sparse: incorrect type in assignment (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*prev @@    got [noderef] <asn:4>*prev @@

drivers/dma-buf/dma-fence-chain.c:222:21: expected struct dma_fence [noderef] <asn:4>*prev
drivers/dma-buf/dma-fence-chain.c:222:21: got struct dma_fence *prev
drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void) drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void)

vim +73 drivers/dma-buf/dma-fence-chain.c

    38	
    39	/**
    40	 * dma_fence_chain_walk - chain walking function
    41	 * @fence: current chain node
    42	 *
    43	 * Walk the chain to the next node. Returns the next fence or NULL if we are at
    44	 * the end of the chain. Garbage collects chain nodes which are already
    45	 * signaled.
    46	 */
    47	struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence)
    48	{
    49		struct dma_fence_chain *chain, *prev_chain;
    50		struct dma_fence *prev, *replacement, *tmp;
    51	
    52		chain = to_dma_fence_chain(fence);
    53		if (!chain) {
    54			dma_fence_put(fence);
    55			return NULL;
    56		}
    57	
    58		while ((prev = dma_fence_chain_get_prev(chain))) {
    59	
    60			prev_chain = to_dma_fence_chain(prev);
    61			if (prev_chain) {
    62				if (!dma_fence_is_signaled(prev_chain->fence))
    63					break;
    64	
    65				replacement = dma_fence_chain_get_prev(prev_chain);
    66			} else {
    67				if (!dma_fence_is_signaled(prev))
    68					break;
    69	
    70				replacement = NULL;
    71			}
    72	
  > 73			tmp = cmpxchg(&chain->prev, prev, replacement);
    74			if (tmp == prev)
    75				dma_fence_put(tmp);
    76			else
    77				dma_fence_put(replacement);
    78			dma_fence_put(prev);
    79		}
    80	
    81		dma_fence_put(fence);
    82		return prev;
    83	}
    84	EXPORT_SYMBOL(dma_fence_chain_walk);
    85	
    86	/**
    87	 * dma_fence_chain_find_seqno - find fence chain node by seqno
    88	 * @pfence: pointer to the chain node where to start
    89	 * @seqno: the sequence number to search for
    90	 *
    91	 * Advance the fence pointer to the chain node which will signal this sequence
    92	 * number. If no sequence number is provided then this is a no-op.
    93	 *
    94	 * Returns EINVAL if the fence is not a chain node or the sequence number has
    95	 * not yet advanced far enough.
    96	 */
    97	int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno)
    98	{
    99		struct dma_fence_chain *chain;
   100	
   101		if (!seqno)
   102			return 0;
   103	
   104		chain = to_dma_fence_chain(*pfence);
   105		if (!chain || chain->base.seqno < seqno)
   106			return -EINVAL;
   107	
   108		dma_fence_chain_for_each(*pfence, &chain->base) {
   109			if ((*pfence)->context != chain->base.context ||
   110			    to_dma_fence_chain(*pfence)->prev_seqno < seqno)
   111				break;
   112		}
   113		dma_fence_put(&chain->base);
   114	
   115		return 0;
   116	}
   117	EXPORT_SYMBOL(dma_fence_chain_find_seqno);
   118	
   119	static const char *dma_fence_chain_get_driver_name(struct dma_fence *fence)
   120	{
   121	        return "dma_fence_chain";
   122	}
   123	
   124	static const char *dma_fence_chain_get_timeline_name(struct dma_fence *fence)
   125	{
   126	        return "unbound";
   127	}
   128	
   129	static void dma_fence_chain_irq_work(struct irq_work *work)
   130	{
   131		struct dma_fence_chain *chain;
   132	
   133		chain = container_of(work, typeof(*chain), work);
   134	
   135		/* Try to rearm the callback */
   136		if (!dma_fence_chain_enable_signaling(&chain->base))
   137			/* Ok, we are done. No more unsignaled fences left */
   138			dma_fence_signal(&chain->base);
   139		dma_fence_put(&chain->base);
   140	}
   141	
   142	static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb)
   143	{
   144		struct dma_fence_chain *chain;
   145	
   146		chain = container_of(cb, typeof(*chain), cb);
   147		irq_work_queue(&chain->work);
   148		dma_fence_put(f);
   149	}
   150	
   151	static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
   152	{
   153		struct dma_fence_chain *head = to_dma_fence_chain(fence);
   154	
   155		dma_fence_get(&head->base);
   156		dma_fence_chain_for_each(fence, &head->base) {
   157			struct dma_fence_chain *chain = to_dma_fence_chain(fence);
   158			struct dma_fence *f = chain ? chain->fence : fence;
   159	
   160			dma_fence_get(f);
   161			if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) {
   162				dma_fence_put(fence);
   163				return true;
   164			}
   165			dma_fence_put(f);
   166		}
   167		dma_fence_put(&head->base);
   168		return false;
   169	}
   170	
   171	static bool dma_fence_chain_signaled(struct dma_fence *fence)
   172	{
   173		dma_fence_chain_for_each(fence, fence) {
   174			struct dma_fence_chain *chain = to_dma_fence_chain(fence);
   175			struct dma_fence *f = chain ? chain->fence : fence;
   176	
   177			if (!dma_fence_is_signaled(f)) {
   178				dma_fence_put(fence);
   179				return false;
   180			}
   181		}
   182	
   183		return true;
   184	}
   185	
   186	static void dma_fence_chain_release(struct dma_fence *fence)
   187	{
   188		struct dma_fence_chain *chain = to_dma_fence_chain(fence);
   189	
 > 190		dma_fence_put(chain->prev);
   191		dma_fence_put(chain->fence);
   192		dma_fence_free(fence);
   193	}
   194	
   195	const struct dma_fence_ops dma_fence_chain_ops = {
   196		.get_driver_name = dma_fence_chain_get_driver_name,
   197		.get_timeline_name = dma_fence_chain_get_timeline_name,
   198		.enable_signaling = dma_fence_chain_enable_signaling,
   199		.signaled = dma_fence_chain_signaled,
   200		.release = dma_fence_chain_release,
   201	};
   202	EXPORT_SYMBOL(dma_fence_chain_ops);
   203	
   204	/**
   205	 * dma_fence_chain_init - initialize a fence chain
   206	 * @chain: the chain node to initialize
   207	 * @prev: the previous fence
   208	 * @fence: the current fence
   209	 *
   210	 * Initialize a new chain node and either start a new chain or add the node to
   211	 * the existing chain of the previous fence.
   212	 */
   213	void dma_fence_chain_init(struct dma_fence_chain *chain,
   214				  struct dma_fence *prev,
   215				  struct dma_fence *fence,
   216				  uint64_t seqno)
   217	{
   218		struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
   219		uint64_t context;
   220	
   221		spin_lock_init(&chain->lock);
 > 222		chain->prev = prev;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 201903210813.K5uuPgyD%[email protected]

#12 lore raw

Hi Lionel and Christian,

Below is robot report for chain->prev, which was added __rcu as you suggested.

How to fix this line "tmp = cmpxchg(&chain->prev, prev, replacement); "? I checked kernel header file, seems it has no cmpxchg for rcu.

Any suggestion to fix this robot report?

Thanks,
-David

Quoted 221 lines · kbuild test robot

Hi Chunming,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.1-rc1 next-20190320]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Chunming-Zhou/dma-buf-add-new-dma_fence_chain-container-v6/20190320-223607
reproduce:

         # apt-get install sparse
         make ARCH=x86_64 allmodconfig
         make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

sparse warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@ expected struct dma_fence [noderef] <asn:4>*__old @@ got dma_fence [noderef] <asn:4>*__old @@

drivers/dma-buf/dma-fence-chain.c:73:23: expected struct dma_fence [noderef] <asn:4>*__old
drivers/dma-buf/dma-fence-chain.c:73:23: got struct dma_fence *[assigned] prev

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@ expected struct dma_fence [noderef] <asn:4>*__new @@ got dma_fence [noderef] <asn:4>*__new @@

drivers/dma-buf/dma-fence-chain.c:73:23: expected struct dma_fence [noderef] <asn:4>*__new
drivers/dma-buf/dma-fence-chain.c:73:23: got struct dma_fence *[assigned] replacement

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:73:21: sparse: incorrect type in assignment (different address spaces) @@ expected struct dma_fence *tmp @@ got struct dma_fence [noderef] <struct dma_fence *tmp @@

drivers/dma-buf/dma-fence-chain.c:73:21: expected struct dma_fence *tmp
drivers/dma-buf/dma-fence-chain.c:73:21: got struct dma_fence [noderef] <asn:4>*[assigned] __ret

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:190:28: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct dma_fence *fence @@ got struct dma_fence struct dma_fence *fence @@

drivers/dma-buf/dma-fence-chain.c:190:28: expected struct dma_fence *fence
drivers/dma-buf/dma-fence-chain.c:190:28: got struct dma_fence [noderef] <asn:4>*prev

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:222:21: sparse: incorrect type in assignment (different address spaces) @@ expected struct dma_fence [noderef] <asn:4>*prev @@ got [noderef] <asn:4>*prev @@

drivers/dma-buf/dma-fence-chain.c:222:21: expected struct dma_fence [noderef] <asn:4>*prev
drivers/dma-buf/dma-fence-chain.c:222:21: got struct dma_fence *prev
drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void) drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void)

vim +73 drivers/dma-buf/dma-fence-chain.c

     38	
     39	/**
     40	 * dma_fence_chain_walk - chain walking function
     41	 * @fence: current chain node
     42	 *
     43	 * Walk the chain to the next node. Returns the next fence or NULL if we are at
     44	 * the end of the chain. Garbage collects chain nodes which are already
     45	 * signaled.
     46	 */
     47	struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence)
     48	{
     49		struct dma_fence_chain *chain, *prev_chain;
     50		struct dma_fence *prev, *replacement, *tmp;
     51	
     52		chain = to_dma_fence_chain(fence);
     53		if (!chain) {
     54			dma_fence_put(fence);
     55			return NULL;
     56		}
     57	
     58		while ((prev = dma_fence_chain_get_prev(chain))) {
     59	
     60			prev_chain = to_dma_fence_chain(prev);
     61			if (prev_chain) {
     62				if (!dma_fence_is_signaled(prev_chain->fence))
     63					break;
     64	
     65				replacement = dma_fence_chain_get_prev(prev_chain);
     66			} else {
     67				if (!dma_fence_is_signaled(prev))
     68					break;
     69	
     70				replacement = NULL;
     71			}
     72	
Quoted 1 line

73 tmp = cmpxchg(&chain->prev, prev, replacement);

     74			if (tmp == prev)
     75				dma_fence_put(tmp);
     76			else
     77				dma_fence_put(replacement);
     78			dma_fence_put(prev);
     79		}
     80	
     81		dma_fence_put(fence);
     82		return prev;
     83	}
     84	EXPORT_SYMBOL(dma_fence_chain_walk);
     85	
     86	/**
     87	 * dma_fence_chain_find_seqno - find fence chain node by seqno
     88	 * @pfence: pointer to the chain node where to start
     89	 * @seqno: the sequence number to search for
     90	 *
     91	 * Advance the fence pointer to the chain node which will signal this sequence
     92	 * number. If no sequence number is provided then this is a no-op.
     93	 *
     94	 * Returns EINVAL if the fence is not a chain node or the sequence number has
     95	 * not yet advanced far enough.
     96	 */
     97	int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno)
     98	{
     99		struct dma_fence_chain *chain;
    100	
    101		if (!seqno)
    102			return 0;
    103	
    104		chain = to_dma_fence_chain(*pfence);
    105		if (!chain || chain->base.seqno < seqno)
    106			return -EINVAL;
    107	
    108		dma_fence_chain_for_each(*pfence, &chain->base) {
    109			if ((*pfence)->context != chain->base.context ||
    110			    to_dma_fence_chain(*pfence)->prev_seqno < seqno)
    111				break;
    112		}
    113		dma_fence_put(&chain->base);
    114	
    115		return 0;
    116	}
    117	EXPORT_SYMBOL(dma_fence_chain_find_seqno);
    118	
    119	static const char *dma_fence_chain_get_driver_name(struct dma_fence *fence)
    120	{
    121	        return "dma_fence_chain";
    122	}
    123	
    124	static const char *dma_fence_chain_get_timeline_name(struct dma_fence *fence)
    125	{
    126	        return "unbound";
    127	}
    128	
    129	static void dma_fence_chain_irq_work(struct irq_work *work)
    130	{
    131		struct dma_fence_chain *chain;
    132	
    133		chain = container_of(work, typeof(*chain), work);
    134	
    135		/* Try to rearm the callback */
    136		if (!dma_fence_chain_enable_signaling(&chain->base))
    137			/* Ok, we are done. No more unsignaled fences left */
    138			dma_fence_signal(&chain->base);
    139		dma_fence_put(&chain->base);
    140	}
    141	
    142	static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb)
    143	{
    144		struct dma_fence_chain *chain;
    145	
    146		chain = container_of(cb, typeof(*chain), cb);
    147		irq_work_queue(&chain->work);
    148		dma_fence_put(f);
    149	}
    150	
    151	static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
    152	{
    153		struct dma_fence_chain *head = to_dma_fence_chain(fence);
    154	
    155		dma_fence_get(&head->base);
    156		dma_fence_chain_for_each(fence, &head->base) {
    157			struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    158			struct dma_fence *f = chain ? chain->fence : fence;
    159	
    160			dma_fence_get(f);
    161			if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) {
    162				dma_fence_put(fence);
    163				return true;
    164			}
    165			dma_fence_put(f);
    166		}
    167		dma_fence_put(&head->base);
    168		return false;
    169	}
    170	
    171	static bool dma_fence_chain_signaled(struct dma_fence *fence)
    172	{
    173		dma_fence_chain_for_each(fence, fence) {
    174			struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    175			struct dma_fence *f = chain ? chain->fence : fence;
    176	
    177			if (!dma_fence_is_signaled(f)) {
    178				dma_fence_put(fence);
    179				return false;
    180			}
    181		}
    182	
    183		return true;
    184	}
    185	
    186	static void dma_fence_chain_release(struct dma_fence *fence)
    187	{
    188		struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    189	
Quoted 1 line

190 dma_fence_put(chain->prev);

    191		dma_fence_put(chain->fence);
    192		dma_fence_free(fence);
    193	}
    194	
    195	const struct dma_fence_ops dma_fence_chain_ops = {
    196		.get_driver_name = dma_fence_chain_get_driver_name,
    197		.get_timeline_name = dma_fence_chain_get_timeline_name,
    198		.enable_signaling = dma_fence_chain_enable_signaling,
    199		.signaled = dma_fence_chain_signaled,
    200		.release = dma_fence_chain_release,
    201	};
    202	EXPORT_SYMBOL(dma_fence_chain_ops);
    203	
    204	/**
    205	 * dma_fence_chain_init - initialize a fence chain
    206	 * @chain: the chain node to initialize
    207	 * @prev: the previous fence
    208	 * @fence: the current fence
    209	 *
    210	 * Initialize a new chain node and either start a new chain or add the node to
    211	 * the existing chain of the previous fence.
    212	 */
    213	void dma_fence_chain_init(struct dma_fence_chain *chain,
    214				  struct dma_fence *prev,
    215				  struct dma_fence *fence,
    216				  uint64_t seqno)
    217	{
    218		struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
    219		uint64_t context;
    220	
    221		spin_lock_init(&chain->lock);
Quoted 5 lines
Quoted 1 line

222 chain->prev = prev;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#13 lore raw

Hi David,

For the cmpxchg() case I of hand don't know either. Looks like so far nobody has used cmpxchg() with rcu protected structures.

The other cases should be replaced by RCU_INIT_POINTER() or rcu_dereference_protected(.., true);

Regards,
Christian.

Am 21.03.19 um 07:34 schrieb zhoucm1:

Quoted 7 lines

Hi Lionel and Christian,

Below is robot report for chain->prev, which was added __rcu as you suggested.

How to fix this line "tmp = cmpxchg(&chain->prev, prev, replacement); "? I checked kernel header file, seems it has no cmpxchg for rcu.

Quoted 233 lines

Any suggestion to fix this robot report?

Thanks,
-David

Quoted 226 lines · kbuild test robot

Hi Chunming,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.1-rc1 next-20190320]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Chunming-Zhou/dma-buf-add-new-dma_fence_chain-container-v6/20190320-223607
reproduce:

         # apt-get install sparse
         make ARCH=x86_64 allmodconfig
         make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

sparse warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__old @@    got  dma_fence [noderef] <asn:4>*__old @@

    drivers/dma-buf/dma-fence-chain.c:73:23:    expected struct dma_fence [noderef] <asn:4>*__old drivers/dma-buf/dma-fence-chain.c:73:23:    got struct dma_fence *[assigned] prev

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__new @@    got  dma_fence [noderef] <asn:4>*__new @@

    drivers/dma-buf/dma-fence-chain.c:73:23:    expected struct dma_fence [noderef] <asn:4>*__new drivers/dma-buf/dma-fence-chain.c:73:23:    got struct dma_fence *[assigned] replacement

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:73:21: sparse: incorrect type in assignment (different address spaces) @@    expected struct dma_fence *tmp @@    got struct dma_fence [noderef] <struct dma_fence *tmp @@

    drivers/dma-buf/dma-fence-chain.c:73:21:    expected struct dma_fence *tmp drivers/dma-buf/dma-fence-chain.c:73:21:    got struct dma_fence [noderef] <asn:4>*[assigned] __ret

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:190:28: sparse: incorrect type in argument 1 (different address spaces) @@    expected struct dma_fence *fence @@    got struct dma_fence struct dma_fence *fence @@

    drivers/dma-buf/dma-fence-chain.c:190:28:    expected struct dma_fence *fence drivers/dma-buf/dma-fence-chain.c:190:28:    got struct dma_fence [noderef] <asn:4>*prev

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:222:21: sparse: incorrect type in assignment (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*prev @@    got [noderef] <asn:4>*prev @@

    drivers/dma-buf/dma-fence-chain.c:222:21:    expected struct dma_fence [noderef] <asn:4>*prev drivers/dma-buf/dma-fence-chain.c:222:21:    got struct dma_fence *prev drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void) drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void)

vim +73 drivers/dma-buf/dma-fence-chain.c

     38
     39    /**
     40     * dma_fence_chain_walk - chain walking function
     41     * @fence: current chain node
     42     *
     43     * Walk the chain to the next node. Returns the next fence or NULL if we are at 44     * the end of the chain. Garbage collects chain nodes which are already 45     * signaled.
     46     */
     47    struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence) 48    {
     49        struct dma_fence_chain *chain, *prev_chain;
     50        struct dma_fence *prev, *replacement, *tmp;
     51
     52        chain = to_dma_fence_chain(fence);
     53        if (!chain) {
     54            dma_fence_put(fence);
     55            return NULL;
     56        }
     57
     58        while ((prev = dma_fence_chain_get_prev(chain))) {
     59
     60            prev_chain = to_dma_fence_chain(prev);
     61            if (prev_chain) {
     62                if (!dma_fence_is_signaled(prev_chain->fence))
     63                    break;
     64
     65                replacement = dma_fence_chain_get_prev(prev_chain); 66            } else {
     67                if (!dma_fence_is_signaled(prev))
     68                    break;
     69
     70                replacement = NULL;
     71            }
     72
   > 73            tmp = cmpxchg(&chain->prev, prev, replacement);
     74            if (tmp == prev)
     75                dma_fence_put(tmp);
     76            else
     77                dma_fence_put(replacement);
     78            dma_fence_put(prev);
     79        }
     80
     81        dma_fence_put(fence);
     82        return prev;
     83    }
     84    EXPORT_SYMBOL(dma_fence_chain_walk);
     85
     86    /**
     87     * dma_fence_chain_find_seqno - find fence chain node by seqno 88     * @pfence: pointer to the chain node where to start
     89     * @seqno: the sequence number to search for
     90     *
     91     * Advance the fence pointer to the chain node which will signal this sequence 92     * number. If no sequence number is provided then this is a no-op. 93     *
     94     * Returns EINVAL if the fence is not a chain node or the sequence number has 95     * not yet advanced far enough.
     96     */
     97    int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno) 98    {
     99        struct dma_fence_chain *chain;
    100
    101        if (!seqno)
    102            return 0;
    103
    104        chain = to_dma_fence_chain(*pfence);
    105        if (!chain || chain->base.seqno < seqno)
    106            return -EINVAL;
    107
    108        dma_fence_chain_for_each(*pfence, &chain->base) {
    109            if ((*pfence)->context != chain->base.context ||
    110 to_dma_fence_chain(*pfence)->prev_seqno < seqno)
    111                break;
    112        }
    113        dma_fence_put(&chain->base);
    114
    115        return 0;
    116    }
    117    EXPORT_SYMBOL(dma_fence_chain_find_seqno);
    118
    119    static const char *dma_fence_chain_get_driver_name(struct dma_fence *fence) 120    {
    121            return "dma_fence_chain";
    122    }
    123
    124    static const char *dma_fence_chain_get_timeline_name(struct dma_fence *fence) 125    {
    126            return "unbound";
    127    }
    128
    129    static void dma_fence_chain_irq_work(struct irq_work *work)
    130    {
    131        struct dma_fence_chain *chain;
    132
    133        chain = container_of(work, typeof(*chain), work);
    134
    135        /* Try to rearm the callback */
    136        if (!dma_fence_chain_enable_signaling(&chain->base))
    137            /* Ok, we are done. No more unsignaled fences left */ 138            dma_fence_signal(&chain->base);
    139        dma_fence_put(&chain->base);
    140    }
    141
    142    static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb) 143    {
    144        struct dma_fence_chain *chain;
    145
    146        chain = container_of(cb, typeof(*chain), cb);
    147        irq_work_queue(&chain->work);
    148        dma_fence_put(f);
    149    }
    150
    151    static bool dma_fence_chain_enable_signaling(struct dma_fence *fence) 152    {
    153        struct dma_fence_chain *head = to_dma_fence_chain(fence); 154
    155        dma_fence_get(&head->base);
    156        dma_fence_chain_for_each(fence, &head->base) {
    157            struct dma_fence_chain *chain = to_dma_fence_chain(fence); 158            struct dma_fence *f = chain ? chain->fence : fence;
    159
    160            dma_fence_get(f);
    161            if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) { 162                dma_fence_put(fence);
    163                return true;
    164            }
    165            dma_fence_put(f);
    166        }
    167        dma_fence_put(&head->base);
    168        return false;
    169    }
    170
    171    static bool dma_fence_chain_signaled(struct dma_fence *fence) 172    {
    173        dma_fence_chain_for_each(fence, fence) {
    174            struct dma_fence_chain *chain = to_dma_fence_chain(fence); 175            struct dma_fence *f = chain ? chain->fence : fence;
    176
    177            if (!dma_fence_is_signaled(f)) {
    178                dma_fence_put(fence);
    179                return false;
    180            }
    181        }
    182
    183        return true;
    184    }
    185
    186    static void dma_fence_chain_release(struct dma_fence *fence)
    187    {
    188        struct dma_fence_chain *chain = to_dma_fence_chain(fence); 189
  > 190        dma_fence_put(chain->prev);
    191        dma_fence_put(chain->fence);
    192        dma_fence_free(fence);
    193    }
    194
    195    const struct dma_fence_ops dma_fence_chain_ops = {
    196        .get_driver_name = dma_fence_chain_get_driver_name,
    197        .get_timeline_name = dma_fence_chain_get_timeline_name,
    198        .enable_signaling = dma_fence_chain_enable_signaling,
    199        .signaled = dma_fence_chain_signaled,
    200        .release = dma_fence_chain_release,
    201    };
    202    EXPORT_SYMBOL(dma_fence_chain_ops);
    203
    204    /**
    205     * dma_fence_chain_init - initialize a fence chain
    206     * @chain: the chain node to initialize
    207     * @prev: the previous fence
    208     * @fence: the current fence
    209     *
    210     * Initialize a new chain node and either start a new chain or add the node to 211     * the existing chain of the previous fence.
    212     */
    213    void dma_fence_chain_init(struct dma_fence_chain *chain,
    214                  struct dma_fence *prev,
    215                  struct dma_fence *fence,
    216                  uint64_t seqno)
    217    {
    218        struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev); 219        uint64_t context;
    220
    221        spin_lock_init(&chain->lock);
  > 222        chain->prev = prev;

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#14 lore raw

cmpxchg be replaced by some simple c sentance?
otherwise we have to remove __rcu of chian->prev.

-David

-------- Original Message --------
Subject: Re: [PATCH 1/9] dma-buf: add new dma_fence_chain container v6
From: Christian König
To: "Zhou, David(ChunMing)" ,kbuild test robot ,"Zhou, David(ChunMing)"
CC: [email protected],[email protected],[email protected],[email protected],[email protected],"Koenig, Christian" ,"Hector, Tobias"

Hi David,

For the cmpxchg() case I of hand don't know either. Looks like so far nobody has used cmpxchg() with rcu protected structures.

The other cases should be replaced by RCU_INIT_POINTER() or rcu_dereference_protected(.., true);

Regards,
Christian.

Am 21.03.19 um 07:34 schrieb zhoucm1:

Quoted 8 lines

Hi Lionel and Christian,

Below is robot report for chain->prev, which was added __rcu as you suggested.

How to fix this line "tmp = cmpxchg(&chain->prev, prev, replacement); "? I checked kernel header file, seems it has no cmpxchg for rcu.

Quoted 280 lines

Any suggestion to fix this robot report?

Thanks,
-David

Quoted 273 lines · kbuild test robot

Hi Chunming,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.1-rc1 next-20190320]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:
https://github.com/0day-ci/linux/commits/Chunming-Zhou/dma-buf-add-new-dma_fence_chain-container-v6/20190320-223607
reproduce:

         # apt-get install sparse
         make ARCH=x86_64 allmodconfig
         make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

sparse warnings: (new ones prefixed by >>)

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in
initializer (different address spaces) @@ expected struct
dma_fence [noderef] <asn:4>*__old @@ got dma_fence [noderef]
<asn:4>*__old @@

drivers/dma-buf/dma-fence-chain.c:73:23: expected struct
dma_fence [noderef] <asn:4>*__old
drivers/dma-buf/dma-fence-chain.c:73:23: got struct dma_fence
*[assigned] prev

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in
initializer (different address spaces) @@ expected struct
dma_fence [noderef] <asn:4>*__new @@ got dma_fence [noderef]
<asn:4>*__new @@

drivers/dma-buf/dma-fence-chain.c:73:23: expected struct
dma_fence [noderef] <asn:4>*__new
drivers/dma-buf/dma-fence-chain.c:73:23: got struct dma_fence
*[assigned] replacement

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:21: sparse: incorrect type in
assignment (different address spaces) @@ expected struct
dma_fence *tmp @@ got struct dma_fence [noderef] <struct
dma_fence *tmp @@

drivers/dma-buf/dma-fence-chain.c:73:21: expected struct
dma_fence *tmp
drivers/dma-buf/dma-fence-chain.c:73:21: got struct dma_fence
[noderef] <asn:4>*[assigned] __ret

Quoted 3 lines
Quoted 3 lines

drivers/dma-buf/dma-fence-chain.c:190:28: sparse: incorrect type in
argument 1 (different address spaces) @@ expected struct
dma_fence *fence @@ got struct dma_fence struct dma_fence *fence @@

drivers/dma-buf/dma-fence-chain.c:190:28: expected struct
dma_fence *fence
drivers/dma-buf/dma-fence-chain.c:190:28: got struct dma_fence
[noderef] <asn:4>*prev

Quoted 3 lines
Quoted 3 lines

drivers/dma-buf/dma-fence-chain.c:222:21: sparse: incorrect type in
assignment (different address spaces) @@ expected struct
dma_fence [noderef] <asn:4>*prev @@ got [noderef] <asn:4>*prev @@

drivers/dma-buf/dma-fence-chain.c:222:21: expected struct
dma_fence [noderef] <asn:4>*prev
drivers/dma-buf/dma-fence-chain.c:222:21: got struct dma_fence
*prev
drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression
using sizeof(void)
drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression
using sizeof(void)

vim +73 drivers/dma-buf/dma-fence-chain.c

38
39 /**
40 * dma_fence_chain_walk - chain walking function
41 * @fence: current chain node
42 *
43 * Walk the chain to the next node. Returns the next fence
or NULL if we are at
44 * the end of the chain. Garbage collects chain nodes
which are already
45 * signaled.
46 */
47 struct dma_fence *dma_fence_chain_walk(struct dma_fence
*fence)

     48    {
     49        struct dma_fence_chain *chain, *prev_chain;
     50        struct dma_fence *prev, *replacement, *tmp;
     51
     52        chain = to_dma_fence_chain(fence);
     53        if (!chain) {
     54            dma_fence_put(fence);
     55            return NULL;
     56        }
     57
     58        while ((prev = dma_fence_chain_get_prev(chain))) {
     59
     60            prev_chain = to_dma_fence_chain(prev);
     61            if (prev_chain) {
     62                if (!dma_fence_is_signaled(prev_chain->fence))
     63                    break;
     64
     65                replacement =
dma_fence_chain_get_prev(prev_chain);
     66            } else {
     67                if (!dma_fence_is_signaled(prev))
     68                    break;
     69
     70                replacement = NULL;
     71            }
     72
Quoted 1 line

73 tmp = cmpxchg(&chain->prev, prev, replacement);

     74            if (tmp == prev)
     75                dma_fence_put(tmp);
     76            else
     77                dma_fence_put(replacement);
     78            dma_fence_put(prev);
     79        }
     80
     81        dma_fence_put(fence);
     82        return prev;
     83    }
     84    EXPORT_SYMBOL(dma_fence_chain_walk);
     85
     86    /**
     87     * dma_fence_chain_find_seqno - find fence chain node by
seqno
     88     * @pfence: pointer to the chain node where to start
     89     * @seqno: the sequence number to search for
     90     *
     91     * Advance the fence pointer to the chain node which will

signal this sequence
92 * number. If no sequence number is provided then this is
a no-op.
93 *
94 * Returns EINVAL if the fence is not a chain node or the
sequence number has
95 * not yet advanced far enough.
96 */
97 int dma_fence_chain_find_seqno(struct dma_fence **pfence,
uint64_t seqno)

     98    {
     99        struct dma_fence_chain *chain;
    100
    101        if (!seqno)
    102            return 0;
    103
    104        chain = to_dma_fence_chain(*pfence);
    105        if (!chain || chain->base.seqno < seqno)
    106            return -EINVAL;
    107
    108        dma_fence_chain_for_each(*pfence, &chain->base) {
    109            if ((*pfence)->context != chain->base.context ||
    110 to_dma_fence_chain(*pfence)->prev_seqno < seqno)
    111                break;
    112        }
    113        dma_fence_put(&chain->base);
    114
    115        return 0;
    116    }
    117    EXPORT_SYMBOL(dma_fence_chain_find_seqno);
    118
    119    static const char *dma_fence_chain_get_driver_name(struct
dma_fence *fence)
    120    {
    121            return "dma_fence_chain";
    122    }
    123
    124    static const char
*dma_fence_chain_get_timeline_name(struct dma_fence *fence)
    125    {
    126            return "unbound";
    127    }
    128
    129    static void dma_fence_chain_irq_work(struct irq_work *work)
    130    {
    131        struct dma_fence_chain *chain;
    132
    133        chain = container_of(work, typeof(*chain), work);
    134
    135        /* Try to rearm the callback */
    136        if (!dma_fence_chain_enable_signaling(&chain->base))
    137            /* Ok, we are done. No more unsignaled fences left */
    138            dma_fence_signal(&chain->base);
    139        dma_fence_put(&chain->base);
    140    }
    141
    142    static void dma_fence_chain_cb(struct dma_fence *f, struct
dma_fence_cb *cb)
    143    {
    144        struct dma_fence_chain *chain;
    145
    146        chain = container_of(cb, typeof(*chain), cb);
    147        irq_work_queue(&chain->work);
    148        dma_fence_put(f);
    149    }
    150
    151    static bool dma_fence_chain_enable_signaling(struct
dma_fence *fence)
    152    {
    153        struct dma_fence_chain *head = to_dma_fence_chain(fence);
    154
    155        dma_fence_get(&head->base);
    156        dma_fence_chain_for_each(fence, &head->base) {
    157            struct dma_fence_chain *chain =
to_dma_fence_chain(fence);
    158            struct dma_fence *f = chain ? chain->fence : fence;
    159
    160            dma_fence_get(f);
    161            if (!dma_fence_add_callback(f, &head->cb,
dma_fence_chain_cb)) {
    162                dma_fence_put(fence);
    163                return true;
    164            }
    165            dma_fence_put(f);
    166        }
    167        dma_fence_put(&head->base);
    168        return false;
    169    }
    170
    171    static bool dma_fence_chain_signaled(struct dma_fence *fence)
    172    {
    173        dma_fence_chain_for_each(fence, fence) {
    174            struct dma_fence_chain *chain =
to_dma_fence_chain(fence);
    175            struct dma_fence *f = chain ? chain->fence : fence;
    176
    177            if (!dma_fence_is_signaled(f)) {
    178                dma_fence_put(fence);
    179                return false;
    180            }
    181        }
    182
    183        return true;
    184    }
    185
    186    static void dma_fence_chain_release(struct dma_fence *fence)
    187    {
    188        struct dma_fence_chain *chain =
to_dma_fence_chain(fence);
    189
Quoted 1 line

190 dma_fence_put(chain->prev);

191 dma_fence_put(chain->fence);
192 dma_fence_free(fence);
193 }
194
195 const struct dma_fence_ops dma_fence_chain_ops = {
196 .get_driver_name = dma_fence_chain_get_driver_name,
197 .get_timeline_name = dma_fence_chain_get_timeline_name,
198 .enable_signaling = dma_fence_chain_enable_signaling,
199 .signaled = dma_fence_chain_signaled,
200 .release = dma_fence_chain_release,
201 };
202 EXPORT_SYMBOL(dma_fence_chain_ops);
203
204 /**
205 * dma_fence_chain_init - initialize a fence chain
206 * @chain: the chain node to initialize
207 * @prev: the previous fence
208 * @fence: the current fence
209 *
210 * Initialize a new chain node and either start a new
chain or add the node to
211 * the existing chain of the previous fence.
212 */
213 void dma_fence_chain_init(struct dma_fence_chain *chain,
214 struct dma_fence *prev,
215 struct dma_fence *fence,
216 uint64_t seqno)
217 {
218 struct dma_fence_chain *prev_chain =

to_dma_fence_chain(prev);
    219        uint64_t context;
    220
    221        spin_lock_init(&chain->lock);
Quoted 1 line

222 chain->prev = prev;

---
0-DAY kernel test infrastructure Open Source
Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 2q1nzdv6akhy5260mi-2nbzia-ttsfc8-dz76ft-4ifnnm-oz4kfp-uezs6vwoq2oq-wd0h34-v7m6m7-cd3muc-v4wzqd-yktmtp-2338r6riorqe-ez3yxk-8jr766yyjh0ob0v5e8-33h712k31w5b1ntkih.1553177522341-2ueSQiBKiTY7tOexoI0I+QC/[email protected]

#16 lore raw

No, atomic cmpxchg is a hardware operation. If you want to replace that you need a lock again.

Maybe just add a comment and use an explicit cast to void* ? Not sure if that silences the warning.

Christian.

Am 21.03.19 um 15:13 schrieb Zhou, David(ChunMing):

Quoted 318 lines

cmpxchg be replaced by some simple c sentance?
otherwise we have to remove __rcu of chian->prev.

-David

-------- Original Message --------
Subject: Re: [PATCH 1/9] dma-buf: add new dma_fence_chain container v6
From: Christian König
To: "Zhou, David(ChunMing)" ,kbuild test robot ,"Zhou, David(ChunMing)"
CC: [email protected],[email protected],[email protected],[email protected],jason-fQELhIk9awXprZlt/[email protected],"Koenig, Christian" ,"Hector, Tobias"

Hi David,

For the cmpxchg() case I of hand don't know either. Looks like so far nobody has used cmpxchg() with rcu protected structures.

The other cases should be replaced by RCU_INIT_POINTER() or rcu_dereference_protected(.., true);

Regards,
Christian.

Am 21.03.19 um 07:34 schrieb zhoucm1:

Quoted 8 lines

Hi Lionel and Christian,

Below is robot report for chain->prev, which was added __rcu as you suggested.

How to fix this line "tmp = cmpxchg(&chain->prev, prev, replacement); "? I checked kernel header file, seems it has no cmpxchg for rcu.

Quoted 17 lines

Any suggestion to fix this robot report?

Thanks,
-David

Quoted 11 lines · kbuild test robot

Hi Chunming,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.1-rc1 next-20190320]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:

https://github.com/0day-ci/linux/commits/Chunming-Zhou/dma-buf-add-new-dma_fence_chain-container-v6/20190320-223607

Quoted 28 lines
Quoted 28 lines

reproduce:

         # apt-get install sparse
         make ARCH=x86_64 allmodconfig
         make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

sparse warnings: (new ones prefixed by >>)

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__old @@    got  dma_fence [noderef] <asn:4>*__old @@

    drivers/dma-buf/dma-fence-chain.c:73:23: expected struct dma_fence [noderef] <asn:4>*__old drivers/dma-buf/dma-fence-chain.c:73:23:    got struct dma_fence *[assigned] prev

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__new @@    got  dma_fence [noderef] <asn:4>*__new @@

    drivers/dma-buf/dma-fence-chain.c:73:23: expected struct dma_fence [noderef] <asn:4>*__new drivers/dma-buf/dma-fence-chain.c:73:23:    got struct dma_fence *[assigned] replacement

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:21: sparse: incorrect type in assignment (different address spaces) @@ expected struct dma_fence *tmp @@    got struct dma_fence [noderef] <struct dma_fence *tmp @@

Quoted 7 lines
Quoted 7 lines

    drivers/dma-buf/dma-fence-chain.c:73:21: expected struct dma_fence *tmp
    drivers/dma-buf/dma-fence-chain.c:73:21:    got struct dma_fence [noderef] <asn:4>*[assigned] __ret

Quoted 3 lines
Quoted 3 lines

drivers/dma-buf/dma-fence-chain.c:190:28: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct dma_fence *fence @@    got struct dma_fence struct dma_fence

*fence @@

Quoted 121 lines
Quoted 121 lines

    drivers/dma-buf/dma-fence-chain.c:190:28: expected struct dma_fence *fence drivers/dma-buf/dma-fence-chain.c:190:28: got struct dma_fence [noderef] <asn:4>*prev

Quoted 3 lines
Quoted 3 lines

drivers/dma-buf/dma-fence-chain.c:222:21: sparse: incorrect type in assignment (different address spaces) @@ expected struct dma_fence [noderef] <asn:4>*prev @@    got [noderef] <asn:4>*prev @@

    drivers/dma-buf/dma-fence-chain.c:222:21: expected struct dma_fence [noderef] <asn:4>*prev drivers/dma-buf/dma-fence-chain.c:222:21: got struct dma_fence *prev
    drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void) drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void)

vim +73 drivers/dma-buf/dma-fence-chain.c

     38
     39    /**
     40     * dma_fence_chain_walk - chain walking function 41     * @fence: current chain node
     42     *
     43     * Walk the chain to the next node. Returns the next fence or NULL if we are at
     44     * the end of the chain. Garbage collects chain nodes which are already
     45     * signaled.
     46     */
     47    struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence)
     48    {
     49        struct dma_fence_chain *chain, *prev_chain; 50        struct dma_fence *prev, *replacement, *tmp; 51
     52        chain = to_dma_fence_chain(fence);
     53        if (!chain) {
     54            dma_fence_put(fence);
     55            return NULL;
     56        }
     57
     58        while ((prev = dma_fence_chain_get_prev(chain))) { 59
     60            prev_chain = to_dma_fence_chain(prev); 61            if (prev_chain) {
     62                if (!dma_fence_is_signaled(prev_chain->fence)) 63                    break;
     64
     65                replacement = dma_fence_chain_get_prev(prev_chain);
     66            } else {
     67                if (!dma_fence_is_signaled(prev))
     68                    break;
     69
     70                replacement = NULL;
     71            }
     72
   > 73            tmp = cmpxchg(&chain->prev, prev, replacement); 74            if (tmp == prev)
     75                dma_fence_put(tmp);
     76            else
     77                dma_fence_put(replacement);
     78            dma_fence_put(prev);
     79        }
     80
     81        dma_fence_put(fence);
     82        return prev;
     83    }
     84    EXPORT_SYMBOL(dma_fence_chain_walk);
     85
     86    /**
     87     * dma_fence_chain_find_seqno - find fence chain node by seqno
     88     * @pfence: pointer to the chain node where to start 89     * @seqno: the sequence number to search for
     90     *
     91     * Advance the fence pointer to the chain node which will signal this sequence
     92     * number. If no sequence number is provided then this is a no-op.
     93     *
     94     * Returns EINVAL if the fence is not a chain node or the sequence number has
     95     * not yet advanced far enough.
     96     */
     97    int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno)
     98    {
     99        struct dma_fence_chain *chain;
    100
    101        if (!seqno)
    102            return 0;
    103
    104        chain = to_dma_fence_chain(*pfence);
    105        if (!chain || chain->base.seqno < seqno)
    106            return -EINVAL;
    107
    108        dma_fence_chain_for_each(*pfence, &chain->base) { 109            if ((*pfence)->context != chain->base.context || 110 to_dma_fence_chain(*pfence)->prev_seqno < seqno) 111                break;
    112        }
    113        dma_fence_put(&chain->base);
    114
    115        return 0;
    116    }
    117 EXPORT_SYMBOL(dma_fence_chain_find_seqno);
    118
    119    static const char *dma_fence_chain_get_driver_name(struct dma_fence *fence)
    120    {
    121            return "dma_fence_chain";
    122    }
    123
    124    static const char *dma_fence_chain_get_timeline_name(struct dma_fence *fence) 125    {
    126            return "unbound";
    127    }
    128
    129    static void dma_fence_chain_irq_work(struct irq_work *work)

Quoted 8 lines
Quoted 8 lines

    130    {
    131        struct dma_fence_chain *chain;
    132
    133        chain = container_of(work, typeof(*chain), work); 134
    135        /* Try to rearm the callback */
    136        if (!dma_fence_chain_enable_signaling(&chain->base)) 137            /* Ok, we are done. No more unsignaled fences

left */

Quoted 10 lines
Quoted 10 lines

    138 dma_fence_signal(&chain->base);
    139        dma_fence_put(&chain->base);
    140    }
    141
    142    static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb)
    143    {
    144        struct dma_fence_chain *chain;
    145
    146        chain = container_of(cb, typeof(*chain), cb);

Quoted 8 lines
Quoted 8 lines

    147        irq_work_queue(&chain->work);
    148        dma_fence_put(f);
    149    }
    150
    151    static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
    152    {
    153        struct dma_fence_chain *head =

to_dma_fence_chain(fence);

Quoted 12 lines
Quoted 12 lines

    154
    155        dma_fence_get(&head->base);
    156        dma_fence_chain_for_each(fence, &head->base) { 157            struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    158            struct dma_fence *f = chain ? chain->fence : fence; 159
    160            dma_fence_get(f);
    161            if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) {
    162                dma_fence_put(fence);
    163                return true;

Quoted 8 lines
Quoted 8 lines

    164            }
    165            dma_fence_put(f);
    166        }
    167        dma_fence_put(&head->base);
    168        return false;
    169    }
    170
    171    static bool dma_fence_chain_signaled(struct dma_fence

*fence)

Quoted 56 lines
Quoted 56 lines

    172    {
    173        dma_fence_chain_for_each(fence, fence) {
    174            struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    175            struct dma_fence *f = chain ? chain->fence : fence; 176
    177            if (!dma_fence_is_signaled(f)) {
    178                dma_fence_put(fence);
    179                return false;
    180            }
    181        }
    182
    183        return true;
    184    }
    185
    186    static void dma_fence_chain_release(struct dma_fence *fence) 187    {
    188        struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    189
  > 190        dma_fence_put(chain->prev);
    191        dma_fence_put(chain->fence);
    192        dma_fence_free(fence);
    193    }
    194
    195    const struct dma_fence_ops dma_fence_chain_ops = { 196        .get_driver_name = dma_fence_chain_get_driver_name, 197        .get_timeline_name = dma_fence_chain_get_timeline_name, 198        .enable_signaling = dma_fence_chain_enable_signaling, 199        .signaled = dma_fence_chain_signaled,
    200        .release = dma_fence_chain_release,
    201    };
    202    EXPORT_SYMBOL(dma_fence_chain_ops);
    203
    204    /**
    205     * dma_fence_chain_init - initialize a fence chain 206     * @chain: the chain node to initialize
    207     * @prev: the previous fence
    208     * @fence: the current fence
    209     *
    210     * Initialize a new chain node and either start a new chain or add the node to
    211     * the existing chain of the previous fence.
    212     */
    213    void dma_fence_chain_init(struct dma_fence_chain *chain, 214                  struct dma_fence *prev,
    215                  struct dma_fence *fence,
    216                  uint64_t seqno)
    217    {
    218        struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
    219        uint64_t context;
    220
    221        spin_lock_init(&chain->lock);
  > 222        chain->prev = prev;

Quoted 5 lines
Quoted 4 lines

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

Quoted 4 lines

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 6bd1f7e6-965b-3bd5-e4e0-f3b04e0638fd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#18 lore raw

how about the attached?

If ok, I will merge to pathc#1.

-David

Quoted 327 lines · Christian König

No, atomic cmpxchg is a hardware operation. If you want to replace that you need a lock again.

Maybe just add a comment and use an explicit cast to void* ? Not sure if that silences the warning.

Christian.

Am 21.03.19 um 15:13 schrieb Zhou, David(ChunMing):

Quoted 320 lines

cmpxchg be replaced by some simple c sentance?
otherwise we have to remove __rcu of chian->prev.

-David

-------- Original Message --------
Subject: Re: [PATCH 1/9] dma-buf: add new dma_fence_chain container v6
From: Christian König
To: "Zhou, David(ChunMing)" ,kbuild test robot ,"Zhou, David(ChunMing)"
CC: [email protected],[email protected],[email protected],[email protected],jason-fQELhIk9awXprZlt/[email protected],"Koenig, Christian" ,"Hector, Tobias"

Hi David,

For the cmpxchg() case I of hand don't know either. Looks like so far nobody has used cmpxchg() with rcu protected structures.

The other cases should be replaced by RCU_INIT_POINTER() or rcu_dereference_protected(.., true);

Regards,
Christian.

Am 21.03.19 um 07:34 schrieb zhoucm1:

Quoted 6 lines

Hi Lionel and Christian,

Below is robot report for chain->prev, which was added __rcu as you suggested.

How to fix this line "tmp = cmpxchg(&chain->prev, prev,

replacement); "?

Quoted 19 lines

I checked kernel header file, seems it has no cmpxchg for rcu.

Any suggestion to fix this robot report?

Thanks,
-David

Quoted 11 lines · kbuild test robot

Hi Chunming,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.1-rc1 next-20190320]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:

https://github.com/0day-ci/linux/commits/Chunming-Zhou/dma-buf-add-new-dma_fence_chain-container-v6/20190320-223607

Quoted 28 lines
Quoted 28 lines

reproduce:

         # apt-get install sparse
         make ARCH=x86_64 allmodconfig
         make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

sparse warnings: (new ones prefixed by >>)

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__old @@    got  dma_fence [noderef] <asn:4>*__old @@

    drivers/dma-buf/dma-fence-chain.c:73:23: expected struct dma_fence [noderef] <asn:4>*__old drivers/dma-buf/dma-fence-chain.c:73:23: got struct dma_fence *[assigned] prev

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__new @@    got  dma_fence [noderef] <asn:4>*__new @@

    drivers/dma-buf/dma-fence-chain.c:73:23: expected struct dma_fence [noderef] <asn:4>*__new drivers/dma-buf/dma-fence-chain.c:73:23: got struct dma_fence *[assigned] replacement

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:21: sparse: incorrect type in assignment (different address spaces) @@    expected struct dma_fence *tmp @@    got struct dma_fence [noderef] <struct dma_fence *tmp @@

Quoted 7 lines
Quoted 7 lines

    drivers/dma-buf/dma-fence-chain.c:73:21: expected struct dma_fence *tmp
    drivers/dma-buf/dma-fence-chain.c:73:21: got struct dma_fence [noderef] <asn:4>*[assigned] __ret

Quoted 3 lines
Quoted 3 lines

drivers/dma-buf/dma-fence-chain.c:190:28: sparse: incorrect type in argument 1 (different address spaces) @@    expected struct dma_fence *fence @@    got struct dma_fence struct dma_fence

*fence @@

Quoted 121 lines
Quoted 121 lines

    drivers/dma-buf/dma-fence-chain.c:190:28: expected struct dma_fence *fence drivers/dma-buf/dma-fence-chain.c:190:28: got struct dma_fence [noderef] <asn:4>*prev

Quoted 3 lines
Quoted 3 lines

drivers/dma-buf/dma-fence-chain.c:222:21: sparse: incorrect type in assignment (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*prev @@    got [noderef] <asn:4>*prev @@

    drivers/dma-buf/dma-fence-chain.c:222:21: expected struct dma_fence [noderef] <asn:4>*prev drivers/dma-buf/dma-fence-chain.c:222:21: got struct dma_fence *prev
    drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void) drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void)

vim +73 drivers/dma-buf/dma-fence-chain.c

     38
     39    /**
     40     * dma_fence_chain_walk - chain walking function 41     * @fence: current chain node
     42     *
     43     * Walk the chain to the next node. Returns the next fence or NULL if we are at
     44     * the end of the chain. Garbage collects chain nodes which are already
     45     * signaled.
     46     */
     47    struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence)
     48    {
     49        struct dma_fence_chain *chain, *prev_chain; 50        struct dma_fence *prev, *replacement, *tmp; 51
     52        chain = to_dma_fence_chain(fence);
     53        if (!chain) {
     54            dma_fence_put(fence);
     55            return NULL;
     56        }
     57
     58        while ((prev = dma_fence_chain_get_prev(chain))) { 59
     60            prev_chain = to_dma_fence_chain(prev); 61            if (prev_chain) {
     62                if (!dma_fence_is_signaled(prev_chain->fence)) 63                    break;
     64
     65                replacement = dma_fence_chain_get_prev(prev_chain);
     66            } else {
     67                if (!dma_fence_is_signaled(prev))
     68                    break;
     69
     70                replacement = NULL;
     71            }
     72
   > 73            tmp = cmpxchg(&chain->prev, prev, replacement); 74            if (tmp == prev)
     75                dma_fence_put(tmp);
     76            else
     77 dma_fence_put(replacement);
     78            dma_fence_put(prev);
     79        }
     80
     81        dma_fence_put(fence);
     82        return prev;
     83    }
     84    EXPORT_SYMBOL(dma_fence_chain_walk);
     85
     86    /**
     87     * dma_fence_chain_find_seqno - find fence chain node by seqno
     88     * @pfence: pointer to the chain node where to start 89     * @seqno: the sequence number to search for
     90     *
     91     * Advance the fence pointer to the chain node which will signal this sequence
     92     * number. If no sequence number is provided then this is a no-op.
     93     *
     94     * Returns EINVAL if the fence is not a chain node or the sequence number has
     95     * not yet advanced far enough.
     96     */
     97    int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno)
     98    {
     99        struct dma_fence_chain *chain;
    100
    101        if (!seqno)
    102            return 0;
    103
    104        chain = to_dma_fence_chain(*pfence);
    105        if (!chain || chain->base.seqno < seqno)
    106            return -EINVAL;
    107
    108        dma_fence_chain_for_each(*pfence, &chain->base) { 109            if ((*pfence)->context != chain->base.context || 110 to_dma_fence_chain(*pfence)->prev_seqno < seqno) 111                break;
    112        }
    113 dma_fence_put(&chain->base);
    114
    115        return 0;
    116    }
    117 EXPORT_SYMBOL(dma_fence_chain_find_seqno);
    118
    119    static const char *dma_fence_chain_get_driver_name(struct dma_fence *fence)
    120    {
    121            return "dma_fence_chain";
    122    }
    123
    124    static const char *dma_fence_chain_get_timeline_name(struct dma_fence *fence) 125    {
    126            return "unbound";
    127    }
    128
    129    static void dma_fence_chain_irq_work(struct irq_work *work)

Quoted 8 lines
Quoted 8 lines

    130    {
    131        struct dma_fence_chain *chain;
    132
    133        chain = container_of(work, typeof(*chain), work); 134
    135        /* Try to rearm the callback */
    136        if (!dma_fence_chain_enable_signaling(&chain->base)) 137            /* Ok, we are done. No more unsignaled fences

left */

Quoted 10 lines
Quoted 10 lines

    138 dma_fence_signal(&chain->base);
    139 dma_fence_put(&chain->base);
    140    }
    141
    142    static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb)
    143    {
    144        struct dma_fence_chain *chain;
    145
    146        chain = container_of(cb, typeof(*chain), cb);

Quoted 8 lines
Quoted 8 lines

    147 irq_work_queue(&chain->work);
    148        dma_fence_put(f);
    149    }
    150
    151    static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
    152    {
    153        struct dma_fence_chain *head =

to_dma_fence_chain(fence);

Quoted 12 lines
Quoted 12 lines

    154
    155        dma_fence_get(&head->base);
    156        dma_fence_chain_for_each(fence, &head->base) { 157            struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    158            struct dma_fence *f = chain ? chain->fence : fence; 159
    160            dma_fence_get(f);
    161            if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) {
    162                dma_fence_put(fence);
    163                return true;

Quoted 8 lines
Quoted 8 lines

    164            }
    165            dma_fence_put(f);
    166        }
    167        dma_fence_put(&head->base);
    168        return false;
    169    }
    170
    171    static bool dma_fence_chain_signaled(struct dma_fence

*fence)

Quoted 8 lines
Quoted 8 lines

    172    {
    173        dma_fence_chain_for_each(fence, fence) {
    174            struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    175            struct dma_fence *f = chain ? chain->fence : fence; 176
    177            if (!dma_fence_is_signaled(f)) {
    178                dma_fence_put(fence);

Quoted 8 lines
Quoted 8 lines

    179                return false;
    180            }
    181        }
    182
    183        return true;
    184    }
    185
    186    static void dma_fence_chain_release(struct dma_fence

*fence)

Quoted 45 lines
Quoted 44 lines

    187    {
    188        struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    189
  > 190        dma_fence_put(chain->prev);
    191        dma_fence_put(chain->fence);
    192        dma_fence_free(fence);
    193    }
    194
    195    const struct dma_fence_ops dma_fence_chain_ops = { 196        .get_driver_name = dma_fence_chain_get_driver_name, 197        .get_timeline_name = dma_fence_chain_get_timeline_name, 198        .enable_signaling = dma_fence_chain_enable_signaling, 199        .signaled = dma_fence_chain_signaled,
    200        .release = dma_fence_chain_release,
    201    };
    202    EXPORT_SYMBOL(dma_fence_chain_ops);
    203
    204    /**
    205     * dma_fence_chain_init - initialize a fence chain 206     * @chain: the chain node to initialize
    207     * @prev: the previous fence
    208     * @fence: the current fence
    209     *
    210     * Initialize a new chain node and either start a new chain or add the node to
    211     * the existing chain of the previous fence.
    212     */
    213    void dma_fence_chain_init(struct dma_fence_chain *chain, 214                  struct dma_fence *prev,
    215                  struct dma_fence *fence,
    216                  uint64_t seqno)
    217    {
    218        struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
    219        uint64_t context;
    220
    221 spin_lock_init(&chain->lock);
  > 222        chain->prev = prev;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

Quoted 7 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

From 0cb7171b2a99b425323a8e02a968c9488de29608 Mon Sep 17 00:00:00 2001

From: Chunming Zhou <[email protected]>
Date: Fri, 22 Mar 2019 15:33:01 +0800
Subject: [PATCH] fix rcu warning from kernel robot

---
 drivers/dma-buf/dma-fence-chain.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/dma-buf/dma-fence-chain.c +3 -3
index 0c5e3c902fa0..c729f98a7bd3 100644
@@ -70,7 +70,7 @@ struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence)
 			replacement = NULL;
 		}
 
-		tmp = cmpxchg(&chain->prev, prev, replacement);
+		tmp = cmpxchg((void **)&chain->prev, (void *)prev, (void *)replacement);
 		if (tmp == prev)
 			dma_fence_put(tmp);
 		else
@@ -187,7 +187,7 @@ static void dma_fence_chain_release(struct dma_fence *fence)
 {
 	struct dma_fence_chain *chain = to_dma_fence_chain(fence);
 
-	dma_fence_put(chain->prev);
+	dma_fence_put(rcu_dereference_protected(chain->prev, true));
 	dma_fence_put(chain->fence);
 	dma_fence_free(fence);
 }
@@ -219,7 +219,7 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
 	uint64_t context;
 
 	spin_lock_init(&chain->lock);
-	chain->prev = prev;
+	rcu_assign_pointer(chain->prev, prev);
 	chain->fence = fence;
 	chain->prev_seqno = 0;
 	init_irq_work(&chain->work, dma_fence_chain_irq_work);
Signature · 1 line
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 5cb29811-a383-f473-5443-25e9d968c516-5C7GfCeVMHo@public.gmane.org

#20 lore raw

Yeah, that should work.

Christian.

Am 22.03.19 um 08:34 schrieb zhoucm1:

Quoted 353 lines

how about the attached?

If ok, I will merge to pathc#1.

-David

Quoted 341 lines · Christian König

No, atomic cmpxchg is a hardware operation. If you want to replace that you need a lock again.

Maybe just add a comment and use an explicit cast to void* ? Not sure if that silences the warning.

Christian.

Am 21.03.19 um 15:13 schrieb Zhou, David(ChunMing):

Quoted 333 lines

cmpxchg be replaced by some simple c sentance?
otherwise we have to remove __rcu of chian->prev.

-David

-------- Original Message --------
Subject: Re: [PATCH 1/9] dma-buf: add new dma_fence_chain container v6
From: Christian König
To: "Zhou, David(ChunMing)" ,kbuild test robot ,"Zhou, David(ChunMing)"
CC: [email protected],[email protected],[email protected],[email protected],jason-fQELhIk9awXprZlt/[email protected],"Koenig, Christian" ,"Hector, Tobias"

Hi David,

For the cmpxchg() case I of hand don't know either. Looks like so far nobody has used cmpxchg() with rcu protected structures.

The other cases should be replaced by RCU_INIT_POINTER() or rcu_dereference_protected(.., true);

Regards,
Christian.

Am 21.03.19 um 07:34 schrieb zhoucm1:

Quoted 6 lines

Hi Lionel and Christian,

Below is robot report for chain->prev, which was added __rcu as you suggested.

How to fix this line "tmp = cmpxchg(&chain->prev, prev,

replacement); "?

Quoted 19 lines

I checked kernel header file, seems it has no cmpxchg for rcu.

Any suggestion to fix this robot report?

Thanks,
-David

Quoted 11 lines · kbuild test robot

Hi Chunming,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.1-rc1 next-20190320]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:

https://github.com/0day-ci/linux/commits/Chunming-Zhou/dma-buf-add-new-dma_fence_chain-container-v6/20190320-223607

Quoted 28 lines
Quoted 28 lines

reproduce:

         # apt-get install sparse
         make ARCH=x86_64 allmodconfig
         make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

sparse warnings: (new ones prefixed by >>)

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__old @@    got  dma_fence [noderef] <asn:4>*__old @@

    drivers/dma-buf/dma-fence-chain.c:73:23: expected struct dma_fence [noderef] <asn:4>*__old drivers/dma-buf/dma-fence-chain.c:73:23: got struct dma_fence *[assigned] prev

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:23: sparse: incorrect type in initializer (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*__new @@    got  dma_fence [noderef] <asn:4>*__new @@

    drivers/dma-buf/dma-fence-chain.c:73:23: expected struct dma_fence [noderef] <asn:4>*__new drivers/dma-buf/dma-fence-chain.c:73:23: got struct dma_fence *[assigned] replacement

Quoted 4 lines
Quoted 4 lines

drivers/dma-buf/dma-fence-chain.c:73:21: sparse: incorrect type in assignment (different address spaces) @@    expected struct dma_fence *tmp @@    got struct dma_fence [noderef] <struct dma_fence *tmp @@

Quoted 5 lines
Quoted 5 lines

    drivers/dma-buf/dma-fence-chain.c:73:21: expected struct dma_fence *tmp
    drivers/dma-buf/dma-fence-chain.c:73:21: got struct dma_fence [noderef] <asn:4>*[assigned] __ret

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:190:28: sparse: incorrect

type in

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

argument 1 (different address spaces) @@    expected struct dma_fence *fence @@    got struct dma_fence struct dma_fence

*fence @@

Quoted 5 lines
Quoted 5 lines

drivers/dma-buf/dma-fence-chain.c:190:28:    expected struct dma_fence *fence drivers/dma-buf/dma-fence-chain.c:190:28:    got struct dma_fence [noderef] <asn:4>*prev

Quoted 1 line
Quoted 1 line

drivers/dma-buf/dma-fence-chain.c:222:21: sparse: incorrect

type in

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

assignment (different address spaces) @@    expected struct dma_fence [noderef] <asn:4>*prev @@    got [noderef]

<asn:4>*prev @@

Quoted 9 lines
Quoted 9 lines

drivers/dma-buf/dma-fence-chain.c:222:21:    expected struct dma_fence [noderef] <asn:4>*prev drivers/dma-buf/dma-fence-chain.c:222:21:    got struct dma_fence *prev
    drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void) drivers/dma-buf/dma-fence-chain.c:235:33: sparse: expression using sizeof(void)

Quoted 8 lines
Quoted 8 lines

vim +73 drivers/dma-buf/dma-fence-chain.c

     38
     39    /**
     40     * dma_fence_chain_walk - chain walking function 41     * @fence: current chain node
     42     *
     43     * Walk the chain to the next node. Returns the next

fence

Quoted 89 lines
Quoted 89 lines

or NULL if we are at
     44     * the end of the chain. Garbage collects chain nodes which are already
     45     * signaled.
     46     */
     47    struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence)
     48    {
     49        struct dma_fence_chain *chain, *prev_chain; 50        struct dma_fence *prev, *replacement, *tmp; 51
     52        chain = to_dma_fence_chain(fence);
     53        if (!chain) {
     54            dma_fence_put(fence);
     55            return NULL;
     56        }
     57
     58        while ((prev = dma_fence_chain_get_prev(chain))) { 59
     60            prev_chain = to_dma_fence_chain(prev); 61            if (prev_chain) {
     62                if (!dma_fence_is_signaled(prev_chain->fence)) 63                    break;
     64
     65                replacement = dma_fence_chain_get_prev(prev_chain);
     66            } else {
     67                if (!dma_fence_is_signaled(prev)) 68                    break;
     69
     70                replacement = NULL;
     71            }
     72
   > 73            tmp = cmpxchg(&chain->prev, prev, replacement); 74            if (tmp == prev)
     75                dma_fence_put(tmp);
     76            else
     77 dma_fence_put(replacement);
     78            dma_fence_put(prev);
     79        }
     80
     81        dma_fence_put(fence);
     82        return prev;
     83    }
     84    EXPORT_SYMBOL(dma_fence_chain_walk);
     85
     86    /**
     87     * dma_fence_chain_find_seqno - find fence chain node by seqno
     88     * @pfence: pointer to the chain node where to start 89     * @seqno: the sequence number to search for
     90     *
     91     * Advance the fence pointer to the chain node which will signal this sequence
     92     * number. If no sequence number is provided then this is a no-op.
     93     *
     94     * Returns EINVAL if the fence is not a chain node or the sequence number has
     95     * not yet advanced far enough.
     96     */
     97    int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno)
     98    {
     99        struct dma_fence_chain *chain;
    100
    101        if (!seqno)
    102            return 0;
    103
    104        chain = to_dma_fence_chain(*pfence);
    105        if (!chain || chain->base.seqno < seqno) 106            return -EINVAL;
    107
    108 dma_fence_chain_for_each(*pfence, &chain->base) { 109            if ((*pfence)->context != chain->base.context || 110 to_dma_fence_chain(*pfence)->prev_seqno < seqno) 111                break;
    112        }
    113 dma_fence_put(&chain->base);
    114
    115        return 0;
    116    }
    117 EXPORT_SYMBOL(dma_fence_chain_find_seqno);
    118
    119    static const char *dma_fence_chain_get_driver_name(struct dma_fence *fence)
    120    {
    121            return "dma_fence_chain";
    122    }

Quoted 8 lines
Quoted 8 lines

    123
    124    static const char *dma_fence_chain_get_timeline_name(struct dma_fence *fence) 125    {
    126            return "unbound";
    127    }
    128
    129    static void dma_fence_chain_irq_work(struct irq_work

*work)

Quoted 8 lines
Quoted 8 lines

    130    {
    131        struct dma_fence_chain *chain;
    132
    133        chain = container_of(work, typeof(*chain), work); 134
    135        /* Try to rearm the callback */
    136        if (!dma_fence_chain_enable_signaling(&chain->base)) 137            /* Ok, we are done. No more unsignaled fences

left */

Quoted 5 lines
Quoted 5 lines

    138 dma_fence_signal(&chain->base);
    139 dma_fence_put(&chain->base);
    140    }
    141
    142    static void dma_fence_chain_cb(struct dma_fence *f,

struct

Quoted 5 lines
Quoted 5 lines

dma_fence_cb *cb)
    143    {
    144        struct dma_fence_chain *chain;
    145
    146        chain = container_of(cb, typeof(*chain), cb);

Quoted 8 lines
Quoted 8 lines

    147 irq_work_queue(&chain->work);
    148        dma_fence_put(f);
    149    }
    150
    151    static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
    152    {
    153        struct dma_fence_chain *head =

to_dma_fence_chain(fence);

Quoted 6 lines
Quoted 6 lines

    154
    155 dma_fence_get(&head->base);
    156        dma_fence_chain_for_each(fence, &head->base) { 157            struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    158            struct dma_fence *f = chain ? chain->fence :

fence;

Quoted 6 lines
Quoted 6 lines

    159
    160            dma_fence_get(f);
    161            if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) {
    162                dma_fence_put(fence);
    163                return true;

Quoted 8 lines
Quoted 8 lines

    164            }
    165            dma_fence_put(f);
    166        }
    167 dma_fence_put(&head->base);
    168        return false;
    169    }
    170
    171    static bool dma_fence_chain_signaled(struct dma_fence

*fence)

Quoted 5 lines
Quoted 5 lines

    172    {
    173        dma_fence_chain_for_each(fence, fence) { 174            struct dma_fence_chain *chain = to_dma_fence_chain(fence);
    175            struct dma_fence *f = chain ? chain->fence :

fence;

Quoted 11 lines
Quoted 11 lines

    176
    177            if (!dma_fence_is_signaled(f)) { 178                dma_fence_put(fence);
    179                return false;
    180            }
    181        }
    182
    183        return true;
    184    }
    185
    186    static void dma_fence_chain_release(struct dma_fence

*fence)

Quoted 4 lines
Quoted 4 lines

    187    {
    188        struct dma_fence_chain *chain =
to_dma_fence_chain(fence);
    189

Quoted 8 lines
Quoted 8 lines

  > 190 dma_fence_put(chain->prev);
    191        dma_fence_put(chain->fence);
    192        dma_fence_free(fence);
    193    }
    194
    195    const struct dma_fence_ops dma_fence_chain_ops = { 196        .get_driver_name = dma_fence_chain_get_driver_name, 197        .get_timeline_name =

dma_fence_chain_get_timeline_name,

Quoted 28 lines
Quoted 28 lines

    198        .enable_signaling = dma_fence_chain_enable_signaling, 199        .signaled = dma_fence_chain_signaled,
    200        .release = dma_fence_chain_release,
    201    };
    202    EXPORT_SYMBOL(dma_fence_chain_ops);
    203
    204    /**
    205     * dma_fence_chain_init - initialize a fence chain 206     * @chain: the chain node to initialize
    207     * @prev: the previous fence
    208     * @fence: the current fence
    209     *
    210     * Initialize a new chain node and either start a new chain or add the node to
    211     * the existing chain of the previous fence. 212     */
    213    void dma_fence_chain_init(struct dma_fence_chain *chain, 214                  struct dma_fence *prev,
    215                  struct dma_fence *fence,
    216                  uint64_t seqno)
    217    {
    218        struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
    219        uint64_t context;
    220
    221 spin_lock_init(&chain->lock);
  > 222        chain->prev = prev;

Quoted 5 lines
Quoted 4 lines

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx