Commit e6135df
Alexei Starovoitov
Merge branch 'hashmap_iter_bucket_lock_fix'
Yonghong Song says:
====================
Currently, the bpf hashmap iterator takes a bucket_lock, a spin_lock,
before visiting each element in the bucket. This will cause a deadlock
if a map update/delete operates on an element with the same
bucket id of the visited map.
To avoid the deadlock, let us just use rcu_read_lock instead of
bucket_lock. This may result in visiting stale elements, missing some elements,
or repeating some elements, if concurrent map delete/update happens for the
same map. I think using rcu_read_lock is a reasonable compromise.
For users caring stale/missing/repeating element issues, bpf map batch
access syscall interface can be used.
Note that another approach is during bpf_iter link stage, we check
whether the iter program might be able to do update/delete to the visited
map. If it is, reject the link_create. Verifier needs to record whether
an update/delete operation happens for each map for this approach.
I just feel this checking is too specialized, hence still prefer
rcu_read_lock approach.
Patch #1 has the kernel implementation and Patch #2 added a selftest
which can trigger deadlock without Patch #1.
====================
Signed-off-by: Alexei Starovoitov <ast@kernel.org>File tree
2 files changed
+19
-11
lines changed- kernel/bpf
- tools/testing/selftests/bpf/progs
2 files changed
+19
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1622 | 1622 | | |
1623 | 1623 | | |
1624 | 1624 | | |
1625 | | - | |
1626 | 1625 | | |
1627 | 1626 | | |
1628 | 1627 | | |
| |||
1632 | 1631 | | |
1633 | 1632 | | |
1634 | 1633 | | |
1635 | | - | |
1636 | 1634 | | |
1637 | 1635 | | |
1638 | 1636 | | |
| |||
1656 | 1654 | | |
1657 | 1655 | | |
1658 | 1656 | | |
1659 | | - | |
| 1657 | + | |
1660 | 1658 | | |
1661 | 1659 | | |
1662 | 1660 | | |
1663 | 1661 | | |
1664 | 1662 | | |
1665 | | - | |
| 1663 | + | |
1666 | 1664 | | |
1667 | 1665 | | |
1668 | 1666 | | |
1669 | 1667 | | |
1670 | 1668 | | |
1671 | | - | |
1672 | 1669 | | |
1673 | 1670 | | |
1674 | 1671 | | |
1675 | 1672 | | |
1676 | 1673 | | |
1677 | 1674 | | |
1678 | 1675 | | |
1679 | | - | |
| 1676 | + | |
1680 | 1677 | | |
1681 | 1678 | | |
1682 | 1679 | | |
| |||
1754 | 1751 | | |
1755 | 1752 | | |
1756 | 1753 | | |
1757 | | - | |
1758 | | - | |
1759 | 1754 | | |
1760 | 1755 | | |
1761 | 1756 | | |
1762 | | - | |
1763 | | - | |
1764 | | - | |
| 1757 | + | |
1765 | 1758 | | |
1766 | 1759 | | |
1767 | 1760 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
| 52 | + | |
| 53 | + | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| |||
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
64 | 79 | | |
65 | 80 | | |
66 | 81 | | |
| |||
0 commit comments