Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5386137imw; Wed, 20 Jul 2022 04:54:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ttzlCMEny6T2LwfvfNDW/voYBHEPwizBLA52hI5S5AgXkedVSG5YFi2rmFfYnFbEopZNj1 X-Received: by 2002:a05:6a00:ac1:b0:52b:5db8:f362 with SMTP id c1-20020a056a000ac100b0052b5db8f362mr20163560pfl.80.1658318064568; Wed, 20 Jul 2022 04:54:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658318064; cv=none; d=google.com; s=arc-20160816; b=sxaApPru7Lz8hX4TOoq4Sk4jyV8DdcrhBSa1Bl/2SF0vHqptVaCtNqNLiymLse7gpb aqHU6clD2i7RxfdpnJOvaWBhcp4a2W9lX0VvLmGSLrwE+wRk2hNXifTjt1I4QsRmhLow ST2NCsGoC/SkkZptcRiAaa1nRcXA1DE8IHRu7mLace9EjQZKGRHQt4RVYXwtkS1KOlS/ fQXuwqx2U5vWOA46v6ZQG9G7N01DlmBDIqAY03h6SmKq6sDkQ3jLoZ8coeXWfa2b942c jYhesmcExu6Wx0bhr6pEAcvo4mazBFbNmdmtCyVfumKNz/Ea8o7GwL2nZ7UTXOQbrQxK 8IwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=z3KFlTHyS29ABxq7E7+mqrxJZKNMmdmSRTF2Gmd+qak=; b=yGroXOnRr8AS402c5qEa8iFvxjaSkUwVYdn5iDx7JIMAdO7X7oiAoysSN2y3+oO/bu SXd/zQZ8G3HaiyBzEV7eewY6r4tYdx1s3xApom+HwEBtFPlJbPxJ7zt5SsUHe2E3VlyD RQHlePKd71E5QhkFH3XWmQGp3e/UnDNh1JODBnAEOZs1/j5qpki9+F1YyxZIxStQk+4S AoXgKjj8O5nRncpoMXNNuTQkwq8mwXUkllhHw4eZeCjgN9eDMtWXnYJ0FQr+7fOtsNfy X1HC1n8c+HIANv4woi8ep8/sBBJOw6nsOf4o/M+6294e26nG3SHhWBsYsELnO4Xvwvu7 bGog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="I68Jc/aA"; 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 t27-20020a63445b000000b003fd2121ace3si21357858pgk.237.2022.07.20.04.54.09; Wed, 20 Jul 2022 04:54:24 -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="I68Jc/aA"; 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 S240822AbiGTLrI (ORCPT + 99 others); Wed, 20 Jul 2022 07:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240751AbiGTLrC (ORCPT ); Wed, 20 Jul 2022 07:47:02 -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 16C4572EC6 for ; Wed, 20 Jul 2022 04:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658317620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=z3KFlTHyS29ABxq7E7+mqrxJZKNMmdmSRTF2Gmd+qak=; b=I68Jc/aAfStXItISmF1tYE7dqMtWbAZLDoyeSicUchwVKnsUDkkRanISvzmAkaufuQQALQ 881qrWPPojPwtt6YnL2brpUGik57pbDKKae6L/DFGXJAAhkp9HZTTYS6UtuayixPrlnvmQ fB7rB88fTNHiuSsP/UuQrLP+KDOCRbM= 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-14-rSDRWVgIOImHt2fqhC-V9g-1; Wed, 20 Jul 2022 07:46:55 -0400 X-MC-Unique: rSDRWVgIOImHt2fqhC-V9g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 66FD7804191; Wed, 20 Jul 2022 11:46:55 +0000 (UTC) Received: from shodan.usersys.redhat.com (unknown [10.43.17.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF4CB2166B26; Wed, 20 Jul 2022 11:46:54 +0000 (UTC) Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id E102B1C029C; Wed, 20 Jul 2022 13:46:53 +0200 (CEST) From: Artem Savkov To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf@vger.kernel.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrea Arcangeli , Daniel Vacek , Jiri Olsa , Song Liu , Artem Savkov Subject: [PATCH bpf-next 0/4] destructive bpf kfuncs (was: bpf_panic) Date: Wed, 20 Jul 2022 13:46:48 +0200 Message-Id: <20220720114652.3020467-1-asavkov@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Spam-Status: No, score=-2.8 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 autolearn=unavailable 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 eBPF is often used for kernel debugging, and one of the widely used and powerful debugging techniques is post-mortem debugging with a full memory dump. Triggering a panic at exactly the right moment allows the user to get such a dump and thus a better view at the system's state. Right now the only way to do this in BPF is to signal userspace to trigger kexec/panic. This is suboptimal as going through userspace requires context changes and adds significant delays taking system further away from "the right moment". On a single-cpu system the situation is even worse because BPF program won't even be able to block the thread of interest. This patchset tries to solve this problem by allowing properly marked tracing bpf programs to call crash_kexec() kernel function. This is a continuation of bpf_panic patchset with initial feedback taken into account. Changes from RFC: - sysctl knob dropped - using crash_kexec() instead of panic() - using kfuncs instead of adding a new helper Artem Savkov (4): bpf: add BPF_F_DESTRUCTIVE flag for BPF_PROG_LOAD bpf: add destructive kfunc set selftests/bpf: add destructive kfunc tests bpf: export crash_kexec() as destructive kfunc include/linux/bpf.h | 1 + include/linux/btf.h | 2 + include/uapi/linux/bpf.h | 6 +++ kernel/bpf/syscall.c | 4 +- kernel/bpf/verifier.c | 12 ++++++ kernel/kexec_core.c | 22 ++++++++++ net/bpf/test_run.c | 12 +++++- tools/include/uapi/linux/bpf.h | 6 +++ .../selftests/bpf/prog_tests/kfunc_call.c | 41 +++++++++++++++++++ .../bpf/progs/kfunc_call_destructive.c | 14 +++++++ 10 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/kfunc_call_destructive.c -- 2.35.3