From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB10DC43460 for ; Wed, 14 Apr 2021 11:01:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B69D161249 for ; Wed, 14 Apr 2021 11:01:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235458AbhDNLCA (ORCPT ); Wed, 14 Apr 2021 07:02:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35895 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235355AbhDNLBz (ORCPT ); Wed, 14 Apr 2021 07:01:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618398094; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0gFg/Ogt8TyIcva+R8+ipOzwiflVs6gLc+fuZSdSw3U=; b=DwMZNlQbt89DcC/gGPIhibzEm6hdxWHk2XrFFL8H032q3UXgsJlz9ny/UAjgXOxe8RMJs+ AIU03t5kUHTCRIMnweqAkKDdlijR5bXDVR+Fc3jOQedqeLWf96vIKJ9cN/z95j3cL1FKWS KMcbCp+e3Ms1kn864fhu6HAK9FJ2IfQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-582-gn4_252DML2TR_mudGNHvQ-1; Wed, 14 Apr 2021 07:01:29 -0400 X-MC-Unique: gn4_252DML2TR_mudGNHvQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 159C35F9FB; Wed, 14 Apr 2021 11:01:28 +0000 (UTC) Received: from krava (unknown [10.40.196.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 145A3610F3; Wed, 14 Apr 2021 11:01:12 +0000 (UTC) Date: Wed, 14 Apr 2021 13:01:12 +0200 From: Jiri Olsa To: Andrii Nakryiko Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , kernel test robot , Julia Lawall , Toke =?iso-8859-1?Q?H=F8iland-J=F8rgensen?= , Networking , bpf , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Julia Lawall Subject: Re: [PATCHv4 bpf-next 1/5] bpf: Allow trampoline re-attach for tracing and lsm programs Message-ID: References: <20210412162502.1417018-1-jolsa@kernel.org> <20210412162502.1417018-2-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Apr 13, 2021 at 03:03:27PM -0700, Andrii Nakryiko wrote: > On Mon, Apr 12, 2021 at 9:28 AM Jiri Olsa wrote: > > > > Currently we don't allow re-attaching of trampolines. Once > > it's detached, it can't be re-attach even when the program > > is still loaded. > > > > Adding the possibility to re-attach the loaded tracing and > > lsm programs. > > > > Fixing missing unlock with proper cleanup goto jump reported > > by Julia. > > > > Reported-by: kernel test robot > > Reported-by: Julia Lawall > > Acked-by: Toke Høiland-Jørgensen > > Signed-off-by: Jiri Olsa > > --- > > kernel/bpf/syscall.c | 23 +++++++++++++++++------ > > kernel/bpf/trampoline.c | 2 +- > > 2 files changed, 18 insertions(+), 7 deletions(-) > > > > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c > > index 6428634da57e..f02c6a871b4f 100644 > > --- a/kernel/bpf/syscall.c > > +++ b/kernel/bpf/syscall.c > > @@ -2645,14 +2645,25 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, > > * target_btf_id using the link_create API. > > * > > * - if tgt_prog == NULL when this function was called using the old > > - * raw_tracepoint_open API, and we need a target from prog->aux > > - * > > - * The combination of no saved target in prog->aux, and no target > > - * specified on load is illegal, and we reject that here. > > + * raw_tracepoint_open API, and we need a target from prog->aux > > + * > > + * - if prog->aux->dst_trampoline and tgt_prog is NULL, the program > > + * was detached and is going for re-attachment. > > */ > > if (!prog->aux->dst_trampoline && !tgt_prog) { > > - err = -ENOENT; > > - goto out_unlock; > > + /* > > + * Allow re-attach for TRACING and LSM programs. If it's > > + * currently linked, bpf_trampoline_link_prog will fail. > > + * EXT programs need to specify tgt_prog_fd, so they > > + * re-attach in separate code path. > > + */ > > + if (prog->type != BPF_PROG_TYPE_TRACING && > > + prog->type != BPF_PROG_TYPE_LSM) { > > + err = -EINVAL; > > + goto out_unlock; > > + } > > + btf_id = prog->aux->attach_btf_id; > > + key = bpf_trampoline_compute_key(NULL, prog->aux->attach_btf, btf_id); > > } > > > > if (!prog->aux->dst_trampoline || > > diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c > > index 1f3a4be4b175..48b8b9916aa2 100644 > > --- a/kernel/bpf/trampoline.c > > +++ b/kernel/bpf/trampoline.c > > @@ -437,7 +437,7 @@ int bpf_trampoline_unlink_prog(struct bpf_prog *prog, struct bpf_trampoline *tr) > > tr->extension_prog = NULL; > > goto out; > > } > > - hlist_del(&prog->aux->tramp_hlist); > > + hlist_del_init(&prog->aux->tramp_hlist); > > there is another hlist_del few lines above in error handling path of > bpf_trampoline_link_prog(), it should probably be also updated to > hlist_del_init(), no? ugh, that one is missing.. will fix thanks, jirka > > > tr->progs_cnt[kind]--; > > err = bpf_trampoline_update(tr); > > out: > > -- > > 2.30.2 > > >