Skip to content

Conversation

@kernel-patches-daemon-bpf-rc
Copy link

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

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 2175ccf
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 4effccd
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 5714ca8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 9c1a352
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 9c1a352
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: da4ab5d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: c9c9f6b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: b9da173
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: bbdbed1
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

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]>
@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 46c7676
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1039475
version: 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants