hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/kernel/bpf/bpf_lru_list.c
....@@ -41,7 +41,12 @@
4141 /* bpf_lru_node helpers */
4242 static bool bpf_lru_node_is_ref(const struct bpf_lru_node *node)
4343 {
44
- return node->ref;
44
+ return READ_ONCE(node->ref);
45
+}
46
+
47
+static void bpf_lru_node_clear_ref(struct bpf_lru_node *node)
48
+{
49
+ WRITE_ONCE(node->ref, 0);
4550 }
4651
4752 static void bpf_lru_list_count_inc(struct bpf_lru_list *l,
....@@ -89,7 +94,7 @@
8994
9095 bpf_lru_list_count_inc(l, tgt_type);
9196 node->type = tgt_type;
92
- node->ref = 0;
97
+ bpf_lru_node_clear_ref(node);
9398 list_move(&node->list, &l->lists[tgt_type]);
9499 }
95100
....@@ -110,7 +115,7 @@
110115 bpf_lru_list_count_inc(l, tgt_type);
111116 node->type = tgt_type;
112117 }
113
- node->ref = 0;
118
+ bpf_lru_node_clear_ref(node);
114119
115120 /* If the moving node is the next_inactive_rotation candidate,
116121 * move the next_inactive_rotation pointer also.
....@@ -353,7 +358,7 @@
353358 *(u32 *)((void *)node + lru->hash_offset) = hash;
354359 node->cpu = cpu;
355360 node->type = BPF_LRU_LOCAL_LIST_T_PENDING;
356
- node->ref = 0;
361
+ bpf_lru_node_clear_ref(node);
357362 list_add(&node->list, local_pending_list(loc_l));
358363 }
359364
....@@ -419,7 +424,7 @@
419424 if (!list_empty(free_list)) {
420425 node = list_first_entry(free_list, struct bpf_lru_node, list);
421426 *(u32 *)((void *)node + lru->hash_offset) = hash;
422
- node->ref = 0;
427
+ bpf_lru_node_clear_ref(node);
423428 __bpf_lru_node_move(l, node, BPF_LRU_LIST_T_INACTIVE);
424429 }
425430
....@@ -522,7 +527,7 @@
522527 }
523528
524529 node->type = BPF_LRU_LOCAL_LIST_T_FREE;
525
- node->ref = 0;
530
+ bpf_lru_node_clear_ref(node);
526531 list_move(&node->list, local_free_list(loc_l));
527532
528533 raw_spin_unlock_irqrestore(&loc_l->lock, flags);
....@@ -568,7 +573,7 @@
568573
569574 node = (struct bpf_lru_node *)(buf + node_offset);
570575 node->type = BPF_LRU_LIST_T_FREE;
571
- node->ref = 0;
576
+ bpf_lru_node_clear_ref(node);
572577 list_add(&node->list, &l->lists[BPF_LRU_LIST_T_FREE]);
573578 buf += elem_size;
574579 }
....@@ -594,7 +599,7 @@
594599 node = (struct bpf_lru_node *)(buf + node_offset);
595600 node->cpu = cpu;
596601 node->type = BPF_LRU_LIST_T_FREE;
597
- node->ref = 0;
602
+ bpf_lru_node_clear_ref(node);
598603 list_add(&node->list, &l->lists[BPF_LRU_LIST_T_FREE]);
599604 i++;
600605 buf += elem_size;