3535#define AMDGPU_BO_LIST_MAX_PRIORITY 32u
3636#define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1)
3737
38- static int amdgpu_bo_list_set (struct amdgpu_device * adev ,
39- struct drm_file * filp ,
40- struct amdgpu_bo_list * list ,
41- struct drm_amdgpu_bo_list_entry * info ,
42- unsigned num_entries );
38+ static void amdgpu_bo_list_free_rcu (struct rcu_head * rcu )
39+ {
40+ struct amdgpu_bo_list * list = container_of (rcu , struct amdgpu_bo_list ,
41+ rhead );
42+
43+ kvfree (list );
44+ }
4345
44- static void amdgpu_bo_list_release_rcu (struct kref * ref )
46+ static void amdgpu_bo_list_free (struct kref * ref )
4547{
4648 struct amdgpu_bo_list * list = container_of (ref , struct amdgpu_bo_list ,
4749 refcount );
@@ -50,67 +52,36 @@ static void amdgpu_bo_list_release_rcu(struct kref *ref)
5052 amdgpu_bo_list_for_each_entry (e , list )
5153 amdgpu_bo_unref (& e -> robj );
5254
53- kvfree (list -> array );
54- kfree_rcu (list , rhead );
55+ call_rcu (& list -> rhead , amdgpu_bo_list_free_rcu );
5556}
5657
57- int amdgpu_bo_list_create (struct amdgpu_device * adev ,
58- struct drm_file * filp ,
59- struct drm_amdgpu_bo_list_entry * info ,
60- unsigned num_entries ,
61- struct amdgpu_bo_list * * list_out )
58+ int amdgpu_bo_list_create (struct amdgpu_device * adev , struct drm_file * filp ,
59+ struct drm_amdgpu_bo_list_entry * info ,
60+ unsigned num_entries , struct amdgpu_bo_list * * result )
6261{
62+ unsigned last_entry = 0 , first_userptr = num_entries ;
63+ struct amdgpu_bo_list_entry * array ;
6364 struct amdgpu_bo_list * list ;
65+ uint64_t total_size = 0 ;
66+ size_t size ;
67+ unsigned i ;
6468 int r ;
6569
70+ if (num_entries > SIZE_MAX / sizeof (struct amdgpu_bo_list_entry ))
71+ return - EINVAL ;
6672
67- list = kzalloc (sizeof (struct amdgpu_bo_list ), GFP_KERNEL );
73+ size = sizeof (struct amdgpu_bo_list );
74+ size += num_entries * sizeof (struct amdgpu_bo_list_entry );
75+ list = kvmalloc (size , GFP_KERNEL );
6876 if (!list )
6977 return - ENOMEM ;
7078
71- /* initialize bo list*/
7279 kref_init (& list -> refcount );
73- r = amdgpu_bo_list_set (adev , filp , list , info , num_entries );
74- if (r ) {
75- kfree (list );
76- return r ;
77- }
78-
79- * list_out = list ;
80- return 0 ;
81- }
82-
83- static void amdgpu_bo_list_destroy (struct amdgpu_fpriv * fpriv , int id )
84- {
85- struct amdgpu_bo_list * list ;
86-
87- mutex_lock (& fpriv -> bo_list_lock );
88- list = idr_remove (& fpriv -> bo_list_handles , id );
89- mutex_unlock (& fpriv -> bo_list_lock );
90- if (list )
91- kref_put (& list -> refcount , amdgpu_bo_list_release_rcu );
92- }
93-
94- static int amdgpu_bo_list_set (struct amdgpu_device * adev ,
95- struct drm_file * filp ,
96- struct amdgpu_bo_list * list ,
97- struct drm_amdgpu_bo_list_entry * info ,
98- unsigned num_entries )
99- {
100- struct amdgpu_bo_list_entry * array ;
101- struct amdgpu_bo * gds_obj = adev -> gds .gds_gfx_bo ;
102- struct amdgpu_bo * gws_obj = adev -> gds .gws_gfx_bo ;
103- struct amdgpu_bo * oa_obj = adev -> gds .oa_gfx_bo ;
104-
105- unsigned last_entry = 0 , first_userptr = num_entries ;
106- struct amdgpu_bo_list_entry * e ;
107- uint64_t total_size = 0 ;
108- unsigned i ;
109- int r ;
80+ list -> gds_obj = adev -> gds .gds_gfx_bo ;
81+ list -> gws_obj = adev -> gds .gws_gfx_bo ;
82+ list -> oa_obj = adev -> gds .oa_gfx_bo ;
11083
111- array = kvmalloc_array (num_entries , sizeof (struct amdgpu_bo_list_entry ), GFP_KERNEL );
112- if (!array )
113- return - ENOMEM ;
84+ array = amdgpu_bo_list_array_entry (list , 0 );
11485 memset (array , 0 , num_entries * sizeof (struct amdgpu_bo_list_entry ));
11586
11687 for (i = 0 ; i < num_entries ; ++ i ) {
@@ -147,36 +118,41 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
147118 entry -> tv .shared = !entry -> robj -> prime_shared_count ;
148119
149120 if (entry -> robj -> preferred_domains == AMDGPU_GEM_DOMAIN_GDS )
150- gds_obj = entry -> robj ;
121+ list -> gds_obj = entry -> robj ;
151122 if (entry -> robj -> preferred_domains == AMDGPU_GEM_DOMAIN_GWS )
152- gws_obj = entry -> robj ;
123+ list -> gws_obj = entry -> robj ;
153124 if (entry -> robj -> preferred_domains == AMDGPU_GEM_DOMAIN_OA )
154- oa_obj = entry -> robj ;
125+ list -> oa_obj = entry -> robj ;
155126
156127 total_size += amdgpu_bo_size (entry -> robj );
157128 trace_amdgpu_bo_list_set (list , entry -> robj );
158129 }
159130
160- amdgpu_bo_list_for_each_entry (e , list )
161- amdgpu_bo_unref (& list -> array [i ].robj );
162-
163- kvfree (list -> array );
164-
165- list -> gds_obj = gds_obj ;
166- list -> gws_obj = gws_obj ;
167- list -> oa_obj = oa_obj ;
168131 list -> first_userptr = first_userptr ;
169- list -> array = array ;
170132 list -> num_entries = num_entries ;
171133
172134 trace_amdgpu_cs_bo_status (list -> num_entries , total_size );
135+
136+ * result = list ;
173137 return 0 ;
174138
175139error_free :
176140 while (i -- )
177141 amdgpu_bo_unref (& array [i ].robj );
178- kvfree (array );
142+ kvfree (list );
179143 return r ;
144+
145+ }
146+
147+ static void amdgpu_bo_list_destroy (struct amdgpu_fpriv * fpriv , int id )
148+ {
149+ struct amdgpu_bo_list * list ;
150+
151+ mutex_lock (& fpriv -> bo_list_lock );
152+ list = idr_remove (& fpriv -> bo_list_handles , id );
153+ mutex_unlock (& fpriv -> bo_list_lock );
154+ if (list )
155+ kref_put (& list -> refcount , amdgpu_bo_list_free );
180156}
181157
182158int amdgpu_bo_list_get (struct amdgpu_fpriv * fpriv , int id ,
@@ -229,7 +205,7 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
229205
230206void amdgpu_bo_list_put (struct amdgpu_bo_list * list )
231207{
232- kref_put (& list -> refcount , amdgpu_bo_list_release_rcu );
208+ kref_put (& list -> refcount , amdgpu_bo_list_free );
233209}
234210
235211int amdgpu_bo_create_list_entry_array (struct drm_amdgpu_bo_list_in * in ,
0 commit comments