Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp1589277rwb; Fri, 5 Aug 2022 04:50:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR4owKT8IgKcMPvJDBMS5r/wQsVqVe0+gtXj6enb9r9Q1VcgA6c9QpvuoIK/21bYlg3jfm47 X-Received: by 2002:a17:902:e805:b0:16f:4a25:b5bd with SMTP id u5-20020a170902e80500b0016f4a25b5bdmr6374688plg.85.1659700202091; Fri, 05 Aug 2022 04:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659700202; cv=none; d=google.com; s=arc-20160816; b=UvfRfgFT58gPZjQE6+ySpWGWOlTVNgjirJpHW4cXy+3/d/iEc0jqUcfuNcSJMhdcZd ElKsguIHeFFlFVw3yvWdF4MEi1YTePQARZd0ziIbM+E/DuhpXFB4wSl4mQz/th/RGEGe ndMKbTTazHrODT6nzM35KNVktEV992TJBMalKelk8jrocuIMSrFe5ocnWgNEPHtUkSef f/7v2PD1uBGdF7vkf17LaMRhel4MeF3PmO6WxkIXJJLi3h28yiJzz6FpohAVahwDl2oo pNQIgCu12JNu3uAVbtQQ3ZOrGEwiQLQ3tToqcVA3NWiM+mQrHYV1Hw/4/xtP8Bm/V4Gh 5eJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=iJ2vojdH8FtOr3UJApDg2Ea8FrlKufBhz/SYWXyGjZg=; b=XvRBHrNWRj8MQnmeDHtBEeZPDUeEK+RpfqOgTdJOhjS4Zi/k18pekB8V0b1Le5iS3A V+qHdnx56bfnfJdIbQ7YvndpCTXIGgNTnssdKNiD5o4Qy52NdrP9nH0dc+LzpxUiLAtW jwIgKdgNb93xzrm9UAzRaaEc0crM1uZqrlEX+r6xBriu6jQTeZiRhWxU6B1iNBaoN/3Q n7MGPfi8JBHAC/XgKfrcn3tYFpcaCh/yQTzMTpJ1TWaxLE9H+eGPi0GJ6T8U6Mx7i8M4 aNDDv+9JI1xxkUUJWvEYrOywCRY035TYnJx8HNF6+WFO4ls9fFCOjArs//1/t50XzY5u MK3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DJTPjypq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c6-20020a655a86000000b0041c89ac3658si3022351pgt.822.2022.08.05.04.49.47; Fri, 05 Aug 2022 04:50:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DJTPjypq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235108AbiHELbY (ORCPT + 99 others); Fri, 5 Aug 2022 07:31:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232378AbiHELbX (ORCPT ); Fri, 5 Aug 2022 07:31:23 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C46C81A808 for ; Fri, 5 Aug 2022 04:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659699080; 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: in-reply-to:in-reply-to:references:references; bh=iJ2vojdH8FtOr3UJApDg2Ea8FrlKufBhz/SYWXyGjZg=; b=DJTPjypqfpO//WJIGt+b8qUF89Clj6wf7+9Cnl5eYtjd4SFwVqCUqVNG/QQHLy+5drpGlf E8JyCwd6sfrHnWIeLIgeChF8y9/fzjFgBx2sHwUCmPlZdWx9srql8NVuvqRcSivYQHw7Yu LNWQxSLLS8hdgVpYzOCfHVzeZNsfsLU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-38-msbGWBtKM9GAzByWCUYbKg-1; Fri, 05 Aug 2022 07:31:19 -0400 X-MC-Unique: msbGWBtKM9GAzByWCUYbKg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D74DA108C19D; Fri, 5 Aug 2022 11:31:18 +0000 (UTC) Received: from samus.usersys.redhat.com (unknown [10.43.17.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 242A618EB7; Fri, 5 Aug 2022 11:31:17 +0000 (UTC) Date: Fri, 5 Aug 2022 13:31:15 +0200 From: Artem Savkov To: Alexei Starovoitov Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf , Network Development , LKML , Andrea Arcangeli , Daniel Vacek , Jiri Olsa , Song Liu , Daniel Xu Subject: Re: [PATCH bpf-next v2 2/3] bpf: export crash_kexec() as destructive kfunc Message-ID: Mail-Followup-To: Alexei Starovoitov , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf , Network Development , LKML , Andrea Arcangeli , Daniel Vacek , Jiri Olsa , Song Liu , Daniel Xu References: <20220802091030.3742334-1-asavkov@redhat.com> <20220802091030.3742334-3-asavkov@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 04, 2022 at 01:41:53PM -0700, Alexei Starovoitov wrote: > On Tue, Aug 2, 2022 at 2:10 AM Artem Savkov wrote: > > > > Allow properly marked bpf programs to call crash_kexec(). > > > > Signed-off-by: Artem Savkov > > --- > > kernel/kexec_core.c | 21 +++++++++++++++++++++ > > 1 file changed, 21 insertions(+) > > > > diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c > > index 4d34c78334ce..9259ea3bd693 100644 > > --- a/kernel/kexec_core.c > > +++ b/kernel/kexec_core.c > > @@ -39,6 +39,8 @@ > > #include > > #include > > #include > > +#include > > +#include > > > > #include > > #include > > @@ -1238,3 +1240,22 @@ void __weak arch_kexec_protect_crashkres(void) > > > > void __weak arch_kexec_unprotect_crashkres(void) > > {} > > + > > +#ifdef CONFIG_DEBUG_INFO_BTF_MODULES > > +BTF_SET8_START(kexec_btf_ids) > > +BTF_ID_FLAGS(func, crash_kexec, KF_DESTRUCTIVE) > > +BTF_SET8_END(kexec_btf_ids) > > + > > +static const struct btf_kfunc_id_set kexec_kfunc_set = { > > + .owner = THIS_MODULE, > > + .set = &kexec_btf_ids, > > +}; > > + > > +static int __init crash_kfunc_init(void) > > +{ > > + register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &kexec_kfunc_set); > > + return 0; > > +} > > + > > +subsys_initcall(crash_kfunc_init); > > +#endif > > It feels there will be a bunch of such boiler plate code > in different .c files in many places in the kernel > if we go with this approach. > > Maybe we should do one call: > register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING > from kernel/bpf/helper.c > to register all tracing kfuncs ? > > And gate > BTF_ID_FLAGS(func, crash_kexec, KF_DESTRUCTIVE) > with #ifdef CONFIG_KEXEC_CORE. > > We have such a pattern in verifier.c already. Good idea, thanks for the pointers. I'll do that in next version. -- Artem