Re: [PATCH bpf-next v8 04/10] bpf: hold module for bpf_struct_ops_map.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 10/30/23 18:21, Martin KaFai Lau wrote:
On 10/30/23 12:28 PM, thinker.li@xxxxxxxxx wrote:
@@ -681,9 +697,17 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)
      if (!st_ops_desc)
          return ERR_PTR(-ENOTSUPP);
+    if (st_ops_desc->btf != btf_vmlinux) {
+        mod = btf_try_get_module(st_ops_desc->btf);
+        if (!mod)
+            return ERR_PTR(-EINVAL);
+    }
+
      vt = st_ops_desc->value_type;
-    if (attr->value_size != vt->size)
-        return ERR_PTR(-EINVAL);
+    if (attr->value_size != vt->size) {
+        ret = -EINVAL;
+        goto errout;
+    }
      t = st_ops_desc->type;
@@ -694,17 +718,17 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)
          (vt->size - sizeof(struct bpf_struct_ops_value));
      st_map = bpf_map_area_alloc(st_map_size, NUMA_NO_NODE);
-    if (!st_map)
-        return ERR_PTR(-ENOMEM);
+    if (!st_map) {
+        ret = -ENOMEM;
+        goto errout;
+    }
      st_map->st_ops_desc = st_ops_desc;
      map = &st_map->map;
      ret = bpf_jit_charge_modmem(PAGE_SIZE);
-    if (ret) {
-        __bpf_struct_ops_map_free(map);
-        return ERR_PTR(ret);
-    }
+    if (ret)
+        goto errout_free;
      st_map->image = bpf_jit_alloc_exec(PAGE_SIZE);
      if (!st_map->image) {
@@ -713,23 +737,32 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)
           * here.
           */
          bpf_jit_uncharge_modmem(PAGE_SIZE);
-        __bpf_struct_ops_map_free(map);
-        return ERR_PTR(-ENOMEM);
+        ret = -ENOMEM;
+        goto errout_free;
      }
      st_map->uvalue = bpf_map_area_alloc(vt->size, NUMA_NO_NODE);
      st_map->links =
          bpf_map_area_alloc(btf_type_vlen(t) * sizeof(struct bpf_links *),
                     NUMA_NO_NODE);
      if (!st_map->uvalue || !st_map->links) {
-        __bpf_struct_ops_map_free(map);
-        return ERR_PTR(-ENOMEM);
+        ret = -ENOMEM;
+        goto errout_free;
      }
      mutex_init(&st_map->lock);
      set_vm_flush_reset_perms(st_map->image);
      bpf_map_init_from_attr(map, attr);
+    module_put(mod);
+
      return map;
+
+errout_free:
+    __bpf_struct_ops_map_free(map);
+    btf = NULL;        /* has been released */

btf is not defined. I don't think this patch compiles.
Something from a latter patch?

Yes, it is defined in the next patch. I will fix it.


+errout:
+    module_put(mod);
+    return ERR_PTR(ret);
  }





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux