Commit 3745834
bpf: switch task_vma iterator from mmap_lock to per-VMA locks
[ Upstream commit bee9ef4 ]
The open-coded task_vma iterator holds mmap_lock for the entire duration
of iteration, increasing contention on this highly contended lock.
Switch to per-VMA locking. Find the next VMA via an RCU-protected maple
tree walk and lock it with lock_vma_under_rcu(). lock_next_vma() is not
used because its fallback takes mmap_read_lock(), and the iterator must
work in non-sleepable contexts.
lock_vma_under_rcu() is a point lookup (mas_walk) that finds the VMA
containing a given address but cannot iterate across gaps. An
RCU-protected vma_next() walk (mas_find) first locates the next VMA's
vm_start to pass to lock_vma_under_rcu().
Between the RCU walk and the lock, the VMA may be removed, shrunk, or
write-locked. On failure, advance past it using vm_end from the RCU
walk. Because the VMA slab is SLAB_TYPESAFE_BY_RCU, vm_end may be
stale; fall back to PAGE_SIZE advancement when it does not make forward
progress. Concurrent VMA insertions at addresses already passed by the
iterator are not detected.
CONFIG_PER_VMA_LOCK is required; return -EOPNOTSUPP without it.
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Link: https://lore.kernel.org/r/20260408154539.3832150-3-puranjay@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Stable-dep-of: 4cbee02 ("bpf: return VMA snapshot from task_vma iterator")
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent d0862de commit 3745834
1 file changed
Lines changed: 73 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
807 | 808 | | |
808 | 809 | | |
809 | 810 | | |
810 | | - | |
811 | | - | |
| 811 | + | |
| 812 | + | |
812 | 813 | | |
813 | 814 | | |
814 | 815 | | |
| |||
829 | 830 | | |
830 | 831 | | |
831 | 832 | | |
832 | | - | |
833 | 833 | | |
834 | 834 | | |
835 | 835 | | |
836 | 836 | | |
837 | 837 | | |
838 | | - | |
839 | | - | |
| 838 | + | |
840 | 839 | | |
841 | 840 | | |
842 | 841 | | |
843 | 842 | | |
844 | 843 | | |
845 | 844 | | |
846 | | - | |
| 845 | + | |
847 | 846 | | |
848 | 847 | | |
849 | 848 | | |
| |||
886 | 885 | | |
887 | 886 | | |
888 | 887 | | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
| 888 | + | |
| 889 | + | |
897 | 890 | | |
898 | 891 | | |
899 | | - | |
900 | | - | |
901 | 892 | | |
902 | 893 | | |
903 | 894 | | |
| |||
906 | 897 | | |
907 | 898 | | |
908 | 899 | | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
909 | 950 | | |
910 | 951 | | |
911 | 952 | | |
| 953 | + | |
912 | 954 | | |
913 | 955 | | |
914 | 956 | | |
915 | | - | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
916 | 970 | | |
917 | 971 | | |
918 | 972 | | |
919 | 973 | | |
920 | 974 | | |
921 | 975 | | |
922 | 976 | | |
923 | | - | |
| 977 | + | |
| 978 | + | |
924 | 979 | | |
925 | 980 | | |
926 | 981 | | |
| |||
0 commit comments