Bug Summary

File:dev/pci/drm/i915/gt/intel_gt_buffer_pool.c
Warning:line 245, column 31
Value stored to 'pool' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name intel_gt_buffer_pool.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -ffreestanding -mcmodel=kernel -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -target-feature -sse2 -target-feature -sse -target-feature -3dnow -target-feature -mmx -target-feature +save-args -disable-red-zone -no-implicit-float -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -nostdsysteminc -nobuiltininc -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/sys -I /usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -I /usr/src/sys/arch -I /usr/src/sys/dev/pci/drm/include -I /usr/src/sys/dev/pci/drm/include/uapi -I /usr/src/sys/dev/pci/drm/amd/include/asic_reg -I /usr/src/sys/dev/pci/drm/amd/include -I /usr/src/sys/dev/pci/drm/amd/amdgpu -I /usr/src/sys/dev/pci/drm/amd/display -I /usr/src/sys/dev/pci/drm/amd/display/include -I /usr/src/sys/dev/pci/drm/amd/display/dc -I /usr/src/sys/dev/pci/drm/amd/display/amdgpu_dm -I /usr/src/sys/dev/pci/drm/amd/pm/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu11 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu12 -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/hwmgr -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/smumgr -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc/hw -I /usr/src/sys/dev/pci/drm/amd/display/dc/clk_mgr -I /usr/src/sys/dev/pci/drm/amd/display/modules/inc -I /usr/src/sys/dev/pci/drm/amd/display/modules/hdcp -I /usr/src/sys/dev/pci/drm/amd/display/dmub/inc -I /usr/src/sys/dev/pci/drm/i915 -D DDB -D DIAGNOSTIC -D KTRACE -D ACCOUNTING -D KMEMSTATS -D PTRACE -D POOL_DEBUG -D CRYPTO -D SYSVMSG -D SYSVSEM -D SYSVSHM -D UVM_SWAP_ENCRYPT -D FFS -D FFS2 -D FFS_SOFTUPDATES -D UFS_DIRHASH -D QUOTA -D EXT2FS -D MFS -D NFSCLIENT -D NFSSERVER -D CD9660 -D UDF -D MSDOSFS -D FIFO -D FUSE -D SOCKET_SPLICE -D TCP_ECN -D TCP_SIGNATURE -D INET6 -D IPSEC -D PPP_BSDCOMP -D PPP_DEFLATE -D PIPEX -D MROUTING -D MPLS -D BOOT_CONFIG -D USER_PCICONF -D APERTURE -D MTRR -D NTFS -D HIBERNATE -D PCIVERBOSE -D USBVERBOSE -D WSDISPLAY_COMPAT_USL -D WSDISPLAY_COMPAT_RAWKBD -D WSDISPLAY_DEFAULTSCREENS=6 -D X86EMU -D ONEWIREVERBOSE -D MULTIPROCESSOR -D MAXUSERS=80 -D _KERNEL -D CONFIG_DRM_AMD_DC_DCN3_0 -O2 -Wno-pointer-sign -Wno-address-of-packed-member -Wno-constant-conversion -Wno-unused-but-set-variable -Wno-gnu-folding-constant -fdebug-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -o /usr/obj/sys/arch/amd64/compile/GENERIC.MP/scan-build/2022-01-12-131800-47421-1 -x c /usr/src/sys/dev/pci/drm/i915/gt/intel_gt_buffer_pool.c
1// SPDX-License-Identifier: MIT
2/*
3 * Copyright © 2014-2018 Intel Corporation
4 */
5
6#include "gem/i915_gem_object.h"
7
8#include "i915_drv.h"
9#include "intel_engine_pm.h"
10#include "intel_gt_buffer_pool.h"
11
12static struct intel_gt *to_gt(struct intel_gt_buffer_pool *pool)
13{
14 return container_of(pool, struct intel_gt, buffer_pool)({ const __typeof( ((struct intel_gt *)0)->buffer_pool ) *
__mptr = (pool); (struct intel_gt *)( (char *)__mptr - __builtin_offsetof
(struct intel_gt, buffer_pool) );})
;
15}
16
17static struct list_head *
18bucket_for_size(struct intel_gt_buffer_pool *pool, size_t sz)
19{
20 int n;
21
22 /*
23 * Compute a power-of-two bucket, but throw everything greater than
24 * 16KiB into the same bucket: i.e. the buckets hold objects of
25 * (1 page, 2 pages, 4 pages, 8+ pages).
26 */
27 n = fls(sz >> PAGE_SHIFT12) - 1;
28 if (n >= ARRAY_SIZE(pool->cache_list)(sizeof((pool->cache_list)) / sizeof((pool->cache_list)
[0]))
)
29 n = ARRAY_SIZE(pool->cache_list)(sizeof((pool->cache_list)) / sizeof((pool->cache_list)
[0]))
- 1;
30
31 return &pool->cache_list[n];
32}
33
34static void node_free(struct intel_gt_buffer_pool_node *node)
35{
36 i915_gem_object_put(node->obj);
37 i915_active_fini(&node->active);
38 kfree_rcu(node, rcu)do { free((void *)node, 145, 0); } while(0);
39}
40
41static bool_Bool pool_free_older_than(struct intel_gt_buffer_pool *pool, long keep)
42{
43 struct intel_gt_buffer_pool_node *node, *stale = NULL((void *)0);
44 bool_Bool active = false0;
45 int n;
46
47 /* Free buffers that have not been used in the past second */
48 for (n = 0; n < ARRAY_SIZE(pool->cache_list)(sizeof((pool->cache_list)) / sizeof((pool->cache_list)
[0]))
; n++) {
49 struct list_head *list = &pool->cache_list[n];
50
51 if (list_empty(list))
52 continue;
53
54 if (spin_trylock_irq(&pool->lock)mtx_enter_try(&pool->lock)) {
55 struct list_head *pos;
56
57 /* Most recent at head; oldest at tail */
58 list_for_each_prev(pos, list)for (pos = (list)->prev; pos != (list); pos = pos->prev
)
{
59 unsigned long age;
60
61 node = list_entry(pos, typeof(*node), link)({ const __typeof( ((typeof(*node) *)0)->link ) *__mptr = (
pos); (typeof(*node) *)( (char *)__mptr - __builtin_offsetof(
typeof(*node), link) );})
;
62
63 age = READ_ONCE(node->age)({ typeof(node->age) __tmp = *(volatile typeof(node->age
) *)&(node->age); membar_datadep_consumer(); __tmp; })
;
64 if (!age || jiffies - age < keep)
65 break;
66
67 /* Check we are the first to claim this node */
68 if (!xchg(&node->age, 0)__sync_lock_test_and_set(&node->age, 0))
69 break;
70
71 node->free = stale;
72 stale = node;
73 }
74 if (!list_is_last(pos, list))
75 __list_del_many(pos, list);
76
77 spin_unlock_irq(&pool->lock)mtx_leave(&pool->lock);
78 }
79
80 active |= !list_empty(list);
81 }
82
83 while ((node = stale)) {
84 stale = stale->free;
85 node_free(node);
86 }
87
88 return active;
89}
90
91static void pool_free_work(struct work_struct *wrk)
92{
93 struct intel_gt_buffer_pool *pool =
94 container_of(wrk, typeof(*pool), work.work)({ const __typeof( ((typeof(*pool) *)0)->work.work ) *__mptr
= (wrk); (typeof(*pool) *)( (char *)__mptr - __builtin_offsetof
(typeof(*pool), work.work) );})
;
95
96 if (pool_free_older_than(pool, HZhz))
97 schedule_delayed_work(&pool->work,
98 round_jiffies_up_relative(HZhz));
99}
100
101static int pool_active(struct i915_active *ref)
102{
103 struct intel_gt_buffer_pool_node *node =
104 container_of(ref, typeof(*node), active)({ const __typeof( ((typeof(*node) *)0)->active ) *__mptr =
(ref); (typeof(*node) *)( (char *)__mptr - __builtin_offsetof
(typeof(*node), active) );})
;
105 struct dma_resv *resv = node->obj->base.resv;
106 int err;
107
108 if (dma_resv_trylock(resv)) {
109 dma_resv_add_excl_fence(resv, NULL((void *)0));
110 dma_resv_unlock(resv);
111 }
112
113 err = i915_gem_object_pin_pages(node->obj);
114 if (err)
115 return err;
116
117 /* Hide this pinned object from the shrinker until retired */
118 i915_gem_object_make_unshrinkable(node->obj);
119
120 return 0;
121}
122
123__i915_active_call__attribute__((__aligned__(4)))
124static void pool_retire(struct i915_active *ref)
125{
126 struct intel_gt_buffer_pool_node *node =
127 container_of(ref, typeof(*node), active)({ const __typeof( ((typeof(*node) *)0)->active ) *__mptr =
(ref); (typeof(*node) *)( (char *)__mptr - __builtin_offsetof
(typeof(*node), active) );})
;
128 struct intel_gt_buffer_pool *pool = node->pool;
129 struct list_head *list = bucket_for_size(pool, node->obj->base.size);
130 unsigned long flags;
131
132 i915_gem_object_unpin_pages(node->obj);
133
134 /* Return this object to the shrinker pool */
135 i915_gem_object_make_purgeable(node->obj);
136
137 GEM_BUG_ON(node->age)((void)0);
138 spin_lock_irqsave(&pool->lock, flags)do { flags = 0; mtx_enter(&pool->lock); } while (0);
139 list_add_rcu(&node->link, list)list_add(&node->link, list);
140 WRITE_ONCE(node->age, jiffies ?: 1)({ typeof(node->age) __tmp = (jiffies ?: 1); *(volatile typeof
(node->age) *)&(node->age) = __tmp; __tmp; })
; /* 0 reserved for active nodes */
141 spin_unlock_irqrestore(&pool->lock, flags)do { (void)(flags); mtx_leave(&pool->lock); } while (0
)
;
142
143 schedule_delayed_work(&pool->work,
144 round_jiffies_up_relative(HZhz));
145}
146
147static struct intel_gt_buffer_pool_node *
148node_create(struct intel_gt_buffer_pool *pool, size_t sz)
149{
150 struct intel_gt *gt = to_gt(pool);
151 struct intel_gt_buffer_pool_node *node;
152 struct drm_i915_gem_object *obj;
153
154 node = kmalloc(sizeof(*node),
155 GFP_KERNEL(0x0001 | 0x0004) | __GFP_RETRY_MAYFAIL0 | __GFP_NOWARN0);
156 if (!node)
157 return ERR_PTR(-ENOMEM12);
158
159 node->age = 0;
160 node->pool = pool;
161 i915_active_init(&node->active, pool_active, pool_retire)do { static struct lock_class_key __mkey; static struct lock_class_key
__wkey; __i915_active_init(&node->active, pool_active
, pool_retire, &__mkey, &__wkey); } while (0)
;
162
163 obj = i915_gem_object_create_internal(gt->i915, sz);
164 if (IS_ERR(obj)) {
165 i915_active_fini(&node->active);
166 kfree(node);
167 return ERR_CAST(obj);
168 }
169
170 i915_gem_object_set_readonly(obj);
171
172 node->obj = obj;
173 return node;
174}
175
176struct intel_gt_buffer_pool_node *
177intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size)
178{
179 struct intel_gt_buffer_pool *pool = &gt->buffer_pool;
180 struct intel_gt_buffer_pool_node *node;
181 struct list_head *list;
182 int ret;
183
184 size = PAGE_ALIGN(size)(((size) + ((1 << 12) - 1)) & ~((1 << 12) - 1
))
;
185 list = bucket_for_size(pool, size);
186
187 rcu_read_lock();
188 list_for_each_entry_rcu(node, list, link)for (node = ({ const __typeof( ((__typeof(*node) *)0)->link
) *__mptr = ((list)->next); (__typeof(*node) *)( (char *)
__mptr - __builtin_offsetof(__typeof(*node), link) );}); &
node->link != (list); node = ({ const __typeof( ((__typeof
(*node) *)0)->link ) *__mptr = (node->link.next); (__typeof
(*node) *)( (char *)__mptr - __builtin_offsetof(__typeof(*node
), link) );}))
{
189 unsigned long age;
190
191 if (node->obj->base.size < size)
192 continue;
193
194 age = READ_ONCE(node->age)({ typeof(node->age) __tmp = *(volatile typeof(node->age
) *)&(node->age); membar_datadep_consumer(); __tmp; })
;
195 if (!age)
196 continue;
197
198 if (cmpxchg(&node->age, age, 0)__sync_val_compare_and_swap(&node->age, age, 0) == age) {
199 spin_lock_irq(&pool->lock)mtx_enter(&pool->lock);
200 list_del_rcu(&node->link)list_del(&node->link);
201 spin_unlock_irq(&pool->lock)mtx_leave(&pool->lock);
202 break;
203 }
204 }
205 rcu_read_unlock();
206
207 if (&node->link == list) {
208 node = node_create(pool, size);
209 if (IS_ERR(node))
210 return node;
211 }
212
213 ret = i915_active_acquire(&node->active);
214 if (ret) {
215 node_free(node);
216 return ERR_PTR(ret);
217 }
218
219 return node;
220}
221
222void intel_gt_init_buffer_pool(struct intel_gt *gt)
223{
224 struct intel_gt_buffer_pool *pool = &gt->buffer_pool;
225 int n;
226
227 mtx_init(&pool->lock, IPL_TTY)do { (void)(((void *)0)); (void)(0); __mtx_init((&pool->
lock), ((((0x9)) > 0x0 && ((0x9)) < 0x9) ? 0x9 :
((0x9)))); } while (0)
;
228 for (n = 0; n < ARRAY_SIZE(pool->cache_list)(sizeof((pool->cache_list)) / sizeof((pool->cache_list)
[0]))
; n++)
229 INIT_LIST_HEAD(&pool->cache_list[n]);
230 INIT_DELAYED_WORK(&pool->work, pool_free_work);
231}
232
233void intel_gt_flush_buffer_pool(struct intel_gt *gt)
234{
235 struct intel_gt_buffer_pool *pool = &gt->buffer_pool;
236
237 do {
238 while (pool_free_older_than(pool, 0))
239 ;
240 } while (cancel_delayed_work_sync(&pool->work));
241}
242
243void intel_gt_fini_buffer_pool(struct intel_gt *gt)
244{
245 struct intel_gt_buffer_pool *pool = &gt->buffer_pool;
Value stored to 'pool' during its initialization is never read
246 int n;
247
248 intel_gt_flush_buffer_pool(gt);
249
250 for (n = 0; n < ARRAY_SIZE(pool->cache_list)(sizeof((pool->cache_list)) / sizeof((pool->cache_list)
[0]))
; n++)
251 GEM_BUG_ON(!list_empty(&pool->cache_list[n]))((void)0);
252}