-
Notifications
You must be signed in to change notification settings - Fork 5
bpf: lru: Fix unintended eviction when updating lru hash maps #6629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bpf-next_base
Are you sure you want to change the base?
bpf: lru: Fix unintended eviction when updating lru hash maps #6629
Conversation
|
Upstream branch: 2175ccf |
c2ec379 to
1ca2f98
Compare
|
Upstream branch: 4effccd |
96f659f to
ca4f479
Compare
1ca2f98 to
e66bead
Compare
|
Upstream branch: 5714ca8 |
ca4f479 to
82ac249
Compare
e66bead to
4e52ed6
Compare
|
Upstream branch: 9c1a352 |
82ac249 to
7049f54
Compare
4e52ed6 to
a222f37
Compare
|
Upstream branch: 9c1a352 |
7049f54 to
103835b
Compare
a222f37 to
3b9ba08
Compare
|
Upstream branch: da4ab5d |
103835b to
b5c59f4
Compare
3b9ba08 to
63c1fef
Compare
|
Upstream branch: c9c9f6b |
b5c59f4 to
b7565d8
Compare
63c1fef to
e72af2a
Compare
|
Upstream branch: b9da173 |
b7565d8 to
d0044a6
Compare
e72af2a to
f626d31
Compare
|
Upstream branch: bbdbed1 |
d0044a6 to
475be85
Compare
f626d31 to
ebd9b12
Compare
The hash field is not used by the LRU list itself. Setting hash while manipulating the LRU list also obscures the intent of the code and makes it harder to follow. Tidy this up by moving the hash assignment to prealloc_lru_pop(), where the element is prepared for insertion into the hash table. Signed-off-by: Leon Hwang <[email protected]>
Introduce the helper bpf_lru_node_reset_state to set type and clear ref. No functional change intended. Signed-off-by: Leon Hwang <[email protected]>
It's to update the 'next_inactive_rotation' for extra node case using the helper. No functional change intended. Signed-off-by: Leon Hwang <[email protected]>
When updating an existing element in lru_[percpu_,]hash maps, the current implementation always calls prealloc_lru_pop() to get a new node before checking if the key already exists. If the map is full, this triggers LRU eviction and removes an existing element, even though the update operation only needs to modify the value of an existing key in-place. This is problematic because: 1. Users may unexpectedly lose entries when doing simple value updates 2. The eviction overhead is unnecessary for existing key updates Fix this by first checking if the key exists before allocating a new node. If the key is found, update the value using the extra lru node without triggering any eviction. Fixes: 29ba732 ("bpf: Add BPF_MAP_TYPE_LRU_HASH") Fixes: 8f84493 ("bpf: Add BPF_MAP_TYPE_LRU_PERCPU_HASH") Signed-off-by: Leon Hwang <[email protected]>
…ng lru_[percpu_,]hash maps Add four tests to verify that updating an existing element in LRU hash maps does not cause unintended eviction of other elements. The test creates lru_hash/lru_percpu_hash maps with max_entries slots and populates all of them. It then updates an existing key and verifies that: 1. The update succeeds without error 2. The updated key has the new value 3. All other keys still exist with their original values This validates the fix that prevents unnecessary LRU eviction when updating existing elements in full LRU hash maps. Signed-off-by: Leon Hwang <[email protected]>
|
Upstream branch: 46c7676 |
475be85 to
c2480c8
Compare
Pull request for series with
subject: bpf: lru: Fix unintended eviction when updating lru hash maps
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475