angler-fishThe Vulnerability History Project

bpf: rework memlock-based memory accounting for maps

      In order to unify the existing memlock charging code with the
memcg-based memory accounting, which will be added later, let's
rework the current scheme.

Currently the following design is used:
  1) .alloc() callback optionally checks if the allocation will likely
     succeed using bpf_map_precharge_memlock()
  2) .alloc() performs actual allocations
  3) .alloc() callback calculates map cost and sets map.memory.pages
  4) map_create() calls bpf_map_init_memlock() which sets map.memory.user
     and performs actual charging; in case of failure the map is
     destroyed
  <map is in use>
  1) bpf_map_free_deferred() calls bpf_map_release_memlock(), which
     performs uncharge and releases the user
  2) .map_free() callback releases the memory

The scheme can be simplified and made more robust:
  1) .alloc() calculates map cost and calls bpf_map_charge_init()
  2) bpf_map_charge_init() sets map.memory.user and performs actual
    cha
    
commit b936ca643ade11f265fa10e5fb71c20d9c5243f1
+4 -1
+7 -3
+5 -3
+7 -6
+6 -5
+6 -3
+2 -3
+6 -3
+6 -3
+17 -13
+33 -36
+5 -4
+5 -3
+3 -2
expand_less