hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/kernel/bpf/bpf_lru_list.c
....@@ -1,8 +1,5 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* Copyright (c) 2016 Facebook
2
- *
3
- * This program is free software; you can redistribute it and/or
4
- * modify it under the terms of version 2 of the GNU General Public
5
- * License as published by the Free Software Foundation.
63 */
74 #include <linux/cpumask.h>
85 #include <linux/spinlock.h>
....@@ -44,7 +41,12 @@
4441 /* bpf_lru_node helpers */
4542 static bool bpf_lru_node_is_ref(const struct bpf_lru_node *node)
4643 {
47
- 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);
4850 }
4951
5052 static void bpf_lru_list_count_inc(struct bpf_lru_list *l,
....@@ -92,7 +94,7 @@
9294
9395 bpf_lru_list_count_inc(l, tgt_type);
9496 node->type = tgt_type;
95
- node->ref = 0;
97
+ bpf_lru_node_clear_ref(node);
9698 list_move(&node->list, &l->lists[tgt_type]);
9799 }
98100
....@@ -113,7 +115,7 @@
113115 bpf_lru_list_count_inc(l, tgt_type);
114116 node->type = tgt_type;
115117 }
116
- node->ref = 0;
118
+ bpf_lru_node_clear_ref(node);
117119
118120 /* If the moving node is the next_inactive_rotation candidate,
119121 * move the next_inactive_rotation pointer also.
....@@ -356,7 +358,7 @@
356358 *(u32 *)((void *)node + lru->hash_offset) = hash;
357359 node->cpu = cpu;
358360 node->type = BPF_LRU_LOCAL_LIST_T_PENDING;
359
- node->ref = 0;
361
+ bpf_lru_node_clear_ref(node);
360362 list_add(&node->list, local_pending_list(loc_l));
361363 }
362364
....@@ -422,7 +424,7 @@
422424 if (!list_empty(free_list)) {
423425 node = list_first_entry(free_list, struct bpf_lru_node, list);
424426 *(u32 *)((void *)node + lru->hash_offset) = hash;
425
- node->ref = 0;
427
+ bpf_lru_node_clear_ref(node);
426428 __bpf_lru_node_move(l, node, BPF_LRU_LIST_T_INACTIVE);
427429 }
428430
....@@ -525,7 +527,7 @@
525527 }
526528
527529 node->type = BPF_LRU_LOCAL_LIST_T_FREE;
528
- node->ref = 0;
530
+ bpf_lru_node_clear_ref(node);
529531 list_move(&node->list, local_free_list(loc_l));
530532
531533 raw_spin_unlock_irqrestore(&loc_l->lock, flags);
....@@ -571,7 +573,7 @@
571573
572574 node = (struct bpf_lru_node *)(buf + node_offset);
573575 node->type = BPF_LRU_LIST_T_FREE;
574
- node->ref = 0;
576
+ bpf_lru_node_clear_ref(node);
575577 list_add(&node->list, &l->lists[BPF_LRU_LIST_T_FREE]);
576578 buf += elem_size;
577579 }
....@@ -597,7 +599,7 @@
597599 node = (struct bpf_lru_node *)(buf + node_offset);
598600 node->cpu = cpu;
599601 node->type = BPF_LRU_LIST_T_FREE;
600
- node->ref = 0;
602
+ bpf_lru_node_clear_ref(node);
601603 list_add(&node->list, &l->lists[BPF_LRU_LIST_T_FREE]);
602604 i++;
603605 buf += elem_size;