On Sat, Jun 4, 2022 at 1:27 AM Martin KaFai Lau <kafai@xxxxxx> wrote: > > On Fri, Jun 03, 2022 at 11:11:58PM -0700, Martin KaFai Lau wrote: > > > @@ -549,9 +655,15 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp, > > > bpf_cgroup_storages_assign(pl->storage, storage); > > > cgrp->bpf.flags[atype] = saved_flags; > > > > > > + if (type == BPF_LSM_CGROUP && !old_prog) { > > hmm... I think this "!old_prog" test should not be here. > > > > In allow_multi, old_prog can be NULL but it still needs > > to bump the shim_link's refcnt by calling > > bpf_trampoline_link_cgroup_shim(). > > > > This is a bit tricky. Does it make sense ? > I think I read the "!"old_prog upside-down. I think I got the > intention here now after reading some latter patches. > It is to save a bpf_trampoline_link_cgroup_shim() and unlink > for the replace case ? I would prefer not to do this. > It is quite confusing to read and does not save much. Ok, let me try to drop it! > > > + err = bpf_trampoline_link_cgroup_shim(new_prog, &tgt_info, atype); > > > + if (err) > > > + goto cleanup; > > > + } > > > + > > > err = update_effective_progs(cgrp, atype); > > > if (err) > > > - goto cleanup; > > > + goto cleanup_trampoline; > > > > > > if (old_prog) > > Then it needs a bpf_trampoline_unlink_cgroup_shim(old_prog) here. > > > > > bpf_prog_put(old_prog); > > > @@ -560,6 +672,10 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp, > > > bpf_cgroup_storages_link(new_storage, cgrp, type); > > > return 0; > > > > > > +cleanup_trampoline: > > > + if (type == BPF_LSM_CGROUP && !old_prog) > > The "!old_prog" test should also be removed. > > > > > + bpf_trampoline_unlink_cgroup_shim(new_prog); > > > + > > > cleanup: > > > if (old_prog) { > > > pl->prog = old_prog;