From patchwork Fri Sep 2 21:10:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12964690 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 A13FBC6FA82 for ; Fri, 2 Sep 2022 21:11:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D31F80139; Fri, 2 Sep 2022 17:11:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35AC480120; Fri, 2 Sep 2022 17:11:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AE1280139; Fri, 2 Sep 2022 17:11:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0480080120 for ; Fri, 2 Sep 2022 17:11:48 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E13371A0822 for ; Fri, 2 Sep 2022 21:11:47 +0000 (UTC) X-FDA: 79868392254.19.F9C821D Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf03.hostedemail.com (Postfix) with ESMTP id 89F6A20052 for ; Fri, 2 Sep 2022 21:11:47 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id w139so3041790pfc.13 for ; Fri, 02 Sep 2022 14:11:47 -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:subject:date; bh=0fGyRfQR7wXSaL6USjScrGPvvIFh66CwdJrIvv58a5g=; b=f9ZJGOxbwYCUfS699Y4HA7lWPPB3p8DS5HVSKmOcLRQUl8OIe8Hlunu6jAN/iqOW/N QhCKvfG0MsvcA17ghHoZEnsfnrA6kgsmKMLwXWVJ+wzu6nGWnUs44ny1WHxEPloYRiqP GS+Y+HPYHsLEeFDiEauG/g38ktmMlyQizGE6PiWPYuz/DDbbMQI6UvLCL+Ctb9Ieyly0 l1V60K6e11KsUkpS4iskN8qgaySrb4A7plkOJ8oOl15OKzlcFxMv7+mvVjaeSr7KRaJz KLfhEYUuFMSGr+0ZwK1/K05S7YWXkqvIwHxjJ87arj7aDQCAj32CZOoDbiDdK0RB1jdD HOXg== 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 :subject:date; bh=0fGyRfQR7wXSaL6USjScrGPvvIFh66CwdJrIvv58a5g=; b=JIL72xkEmtjP3rO8ZT2/DcKP6Mc19nJRmK4MNyF1EOchV0fW5oVGqhvST87CdgH4j5 D/jpiM/qmwiZbTjeVE3K0mLxK6l62oWpgu+O7kJpdCY74t24xMWVCSrtORzHLtKbghQl 8D/lmm41Km261vJh910UapWICnaRiXuIiM9Ob9HSqTi7vmfAhQrl7F3EuMBwmzVZ9zAO AQPXJ4FhDeOvTjbvg/wAV1cARC/do2SVnEO1Xpwqu0QQ1hGpURxHLzUOimyma+E6vN7z 7QcuvsdoSdNELkQ/Dgxv0KMgPpfR5TQKKkMzAxjRgx44K5rNHFiErERnua9V1OSAvvmY 9H0A== X-Gm-Message-State: ACgBeo0QnP46ZLfI2s2NqJuwQcaKIu0Zoi/kelQvXRfrC8uBeZISTCx2 SW4vSRMy6xgtZNXNlaI353zIqnTbMZ0= X-Google-Smtp-Source: AA6agR7Y0ntmo6WJN5i54Frl+0Q0pJs+/U+OuU5sDJJjsDGmYEEAIe/z6DKl8Pf1q40IiYJfNKDOGQ== X-Received: by 2002:a63:451f:0:b0:42c:5a26:d7cc with SMTP id s31-20020a63451f000000b0042c5a26d7ccmr19825722pga.199.1662153106479; Fri, 02 Sep 2022 14:11:46 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::c978]) by smtp.gmail.com with ESMTPSA id iw5-20020a170903044500b0016d1f6d1b99sm2075753plb.49.2022.09.02.14.11.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 02 Sep 2022 14:11:46 -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 v6 bpf-next 12/16] bpf: Remove tracing program restriction on map types Date: Fri, 2 Sep 2022 14:10:54 -0700 Message-Id: <20220902211058.60789-13-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220902211058.60789-1-alexei.starovoitov@gmail.com> References: <20220902211058.60789-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=f9ZJGOxb; spf=pass (imf03.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662153107; a=rsa-sha256; cv=none; b=xPNHJt8iup0aJOD1gyn4d4Kq4I80di0JzrjFzBEPqPFIGJSgaoMjwye8mfncI3GEhpHYvJ EOXCpHbXGt8ilMXNIvqsrndrFtwOKmzf5VTNyTYM6XItS2roH6CwI1SB7f2EoYUDDd74ef BcPxaW+NeAuTgaDMrGiLJ3ehKIjkxnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662153107; 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=Y14hXWeEkIikKMCjwtfxRdxIhcYfKRN+8IcnOzzvlU8GVzwz4SMeauGoSkcFtSFuNOHWvu ABTaML99jhrTtyz7GPNqe+fxS36+TiBI7ZbS3RaYpnCuNRDmhdgA8Bo7aip9RSrq+MTvfU 0k+bu2eLgYqHbXH4chCbwQ/oJ/M7naQ= X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 89F6A20052 X-Stat-Signature: 8pwwfowgqp3hyyk3cz95tueag1mizjiu Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=f9ZJGOxb; spf=pass (imf03.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1662153107-178220 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) {