From patchwork Thu Sep 1 16:15:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12962895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62546ECAAD3 for ; Thu, 1 Sep 2022 16:16:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 039C06B00A7; Thu, 1 Sep 2022 12:16:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2B1E8000C; Thu, 1 Sep 2022 12:16:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA4E78000B; Thu, 1 Sep 2022 12:16:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C53186B00A7 for ; Thu, 1 Sep 2022 12:16:37 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9BFABAAF62 for ; Thu, 1 Sep 2022 16:16:37 +0000 (UTC) X-FDA: 79864019634.07.9E21463 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf10.hostedemail.com (Postfix) with ESMTP id 53CAAC004B for ; Thu, 1 Sep 2022 16:16:37 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id y127so17940974pfy.5 for ; Thu, 01 Sep 2022 09:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=0fGyRfQR7wXSaL6USjScrGPvvIFh66CwdJrIvv58a5g=; b=moJ3QGwNSKtYu6wWQdRUAqn5vj/OGKF7dCZIO4PjfQTweG7WVmeKw0iOVyYrtXJiDx l9BwYgFNLwLHikDnkkSagE0/FIh2cyXKDA+EPfE+BEaD8B7kq4ahMptMml1suYP9ycH3 HAzsZJhAf+DFN15Ykj/1O8MFENQrBh1KNA5N4AStyIOHaEYlOtwf3QJhqNdRbnagLlj4 Mufw7a3+axZD0NZXcGG6Y+tlD7hjAw7hA0khvYK35msgOJXpFagZF6t1lMAZtEDEpF5Y qUr4/1Nvwb7kTr/M3DhZdxgalroISYL0M/ViOhOtkbpvi0bt0vsX5MY4s2TkDuEcHl9L WJqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=0fGyRfQR7wXSaL6USjScrGPvvIFh66CwdJrIvv58a5g=; b=Mm6rDSpvnuvei39VYPeBY5zv9yIgxpySkR9jP0WcU6Hi/eltiuWHwCnWz6ItXCVRM4 wvtphmqm8lXB4LG/Vv3kOvdf7x3pyzvm11FWNFvk5vSdj2Ul6tJAK0w+v+xw9QVxIIBf x2kZeRfugrp5yqd89xvf4vyhQuJDk1khJUVIO3g9Fu83W88bDV834V19caveK+n8olml ZFd+GtlJoyLgqJ5AAa7nTgo3XrgieP2dlnzq6uonT+kLk1hiFQZPsxS2RkorA61KvQeQ zgfxo/M0qoslX7kMxVFjVazTy5K6vDYByMljEodz/PvXmkJSSCKifox0tKQ+cC2+/PAG leAA== X-Gm-Message-State: ACgBeo0sFpyEooto43iQdbZLiD1ohiSUQwfqE9ppJAaMWvQOrlfBb5zZ 0g5GPo+rGGTrsjqxKtacZbc= X-Google-Smtp-Source: AA6agR7LjjuE3wBIwKQp/cjDicVkre1L5Fbr8voVsdCnosFf0RhuKL47jGob3bHkfRIqJC/40s3vEw== X-Received: by 2002:a63:450:0:b0:42b:c914:a0fc with SMTP id 77-20020a630450000000b0042bc914a0fcmr20695445pge.317.1662048996291; Thu, 01 Sep 2022 09:16:36 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::3:4dc5]) by smtp.gmail.com with ESMTPSA id d2-20020a170902f14200b00173368e9dedsm10798175plb.252.2022.09.01.09.16.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 01 Sep 2022 09:16:35 -0700 (PDT) From: Alexei Starovoitov To: davem@davemloft.net Cc: daniel@iogearbox.net, andrii@kernel.org, tj@kernel.org, memxor@gmail.com, delyank@fb.com, linux-mm@kvack.org, bpf@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v5 bpf-next 12/15] bpf: Remove tracing program restriction on map types Date: Thu, 1 Sep 2022 09:15:44 -0700 Message-Id: <20220901161547.57722-13-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220901161547.57722-1-alexei.starovoitov@gmail.com> References: <20220901161547.57722-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662048997; a=rsa-sha256; cv=none; b=4ksLGozJa4pwIBRhnpTGogj5kGsuMNrbi7GV6KGi2mLJdhGutYYWES3ynXiIQGhs6IALxD sLJq787q8pzi4aWWydpELry6qhbT77T5UFAi2pXPcc97lD81usP4SBz8jKD2dmHO66lEFS JWUKclJLiXWbn9Lf30TTAmJrs8zpdgE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=moJ3QGwN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662048997; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0fGyRfQR7wXSaL6USjScrGPvvIFh66CwdJrIvv58a5g=; b=dlEsLzkoaQsRaF+mqX+ZPtO50kMA85uly4qhsIu4ZwghYGG/TmtKx2wEndb4MnZKMs+wQ7 jJe9DHuOX+1KByjQQrUgylgetDPQHQ12H1BXnL6cFMfcl9f+FpO0A0w6rlYCwsX2UJQNQ3 SfH276mlVe/l9i7GW3431dk/WruMTvM= X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 53CAAC004B X-Stat-Signature: 4hsrgk5qgfp6tsgi1u8w1ehhq1q8bydg Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=moJ3QGwN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-HE-Tag: 1662048997-687345 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Alexei Starovoitov The hash map is now fully converted to bpf_mem_alloc. Its implementation is not allocating synchronously and not calling call_rcu() directly. It's now safe to use non-preallocated hash maps in all types of tracing programs including BPF_PROG_TYPE_PERF_EVENT that runs out of NMI context. Acked-by: Kumar Kartikeya Dwivedi Acked-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov --- kernel/bpf/verifier.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 3dce3166855f..57ec06b1d09d 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -12623,48 +12623,6 @@ static int check_map_prog_compatibility(struct bpf_verifier_env *env, { enum bpf_prog_type prog_type = resolve_prog_type(prog); - /* - * Validate that trace type programs use preallocated hash maps. - * - * For programs attached to PERF events this is mandatory as the - * perf NMI can hit any arbitrary code sequence. - * - * All other trace types using non-preallocated per-cpu hash maps are - * unsafe as well because tracepoint or kprobes can be inside locked - * regions of the per-cpu memory allocator or at a place where a - * recursion into the per-cpu memory allocator would see inconsistent - * state. Non per-cpu hash maps are using bpf_mem_alloc-tor which is - * safe to use from kprobe/fentry and in RT. - * - * On RT enabled kernels run-time allocation of all trace type - * programs is strictly prohibited due to lock type constraints. On - * !RT kernels it is allowed for backwards compatibility reasons for - * now, but warnings are emitted so developers are made aware of - * the unsafety and can fix their programs before this is enforced. - */ - if (is_tracing_prog_type(prog_type) && !is_preallocated_map(map)) { - if (prog_type == BPF_PROG_TYPE_PERF_EVENT) { - /* perf_event bpf progs have to use preallocated hash maps - * because non-prealloc is still relying on call_rcu to free - * elements. - */ - verbose(env, "perf_event programs can only use preallocated hash map\n"); - return -EINVAL; - } - if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH || - (map->inner_map_meta && - map->inner_map_meta->map_type == BPF_MAP_TYPE_PERCPU_HASH)) { - if (IS_ENABLED(CONFIG_PREEMPT_RT)) { - verbose(env, - "trace type programs can only use preallocated per-cpu hash map\n"); - return -EINVAL; - } - WARN_ONCE(1, "trace type BPF program uses run-time allocation\n"); - verbose(env, - "trace type programs with run-time allocated per-cpu hash maps are unsafe." - " Switch to preallocated hash maps.\n"); - } - } if (map_value_has_spin_lock(map)) { if (prog_type == BPF_PROG_TYPE_SOCKET_FILTER) {