From patchwork Fri Aug 26 02:44:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12955504 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 359AAECAAA2 for ; Fri, 26 Aug 2022 02:45:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C032D8000F; Thu, 25 Aug 2022 22:45:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB2D480007; Thu, 25 Aug 2022 22:45:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A53C28000F; Thu, 25 Aug 2022 22:45:22 -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 95DC880007 for ; Thu, 25 Aug 2022 22:45:22 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5C05080547 for ; Fri, 26 Aug 2022 02:45:22 +0000 (UTC) X-FDA: 79840202484.02.8280EE2 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf09.hostedemail.com (Postfix) with ESMTP id 221C214000C for ; Fri, 26 Aug 2022 02:45:21 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id 72so307841pfx.9 for ; Thu, 25 Aug 2022 19:45:21 -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=npiETgRwDYegJeQPkgRCmw8CYHFlORx1B2gGnaepqcQ=; b=e+bSbZkl7envlVYZAFYCewLjpcre0KiJcKaFhi7xoVHKhCWc0njTaLRrXpeVFZSH+R vsaeoPXH0MEWU5tzVg3/VfJTcqZ1MGqmuMRfSlihRYhiz2lvscCrABVy3CVUVyfwUs74 Uezxt8PpEomaEhfEyZD0h7ZhXuS3FzQwPWOGzcmhfHHdeisZH55JPNPcQeMChpC5wfZJ z9OWknA1te3hX8a6YuCheJ3sYjkIkzCwn6QyNzb2JEWhBB2RxieeBZEa7mUbrSH6TlXo wapvrbiOPg5Juf9JqnN7d+2n7Ax2yEl3enbdNQfCSBSBFUmOrHD0sbcywSKOaqffYx0e z/QQ== 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=npiETgRwDYegJeQPkgRCmw8CYHFlORx1B2gGnaepqcQ=; b=e0hF5ez36rcoCH9h41gry5ByBYn0Z9/HeFZ2TinareyvFEyTAiVLv+rsG3/6wDyICZ lb0BkYxKtnrsSXzjXLRe1Qgo37wtGBCTTWmjTglsBRCYtQ+m7OFBgZLTWPyB0F0ay8fR Eo3mYn2Kl+6I6Z76ldYehFY6vYr0wPFTHQCO01cQG2n+Ep6VC9dKH4Jfph3hHntXw2yP XZm8uzIcx8huVAKULr7s4tbbDPVUDcKYIRRJrIFFQBzMWYOEtZUnrYYH8NPzXF+79ybz 9MZqbPPS3QH3Xg5W6dc/mUiXJ7c3z11ap00AqjDDtmzFAFOuoVUWLeIALBx9dN8dcmfx 9b9g== X-Gm-Message-State: ACgBeo1Auv1nhlzYi1WaJn9CmqH5tk8B0XURRp7r0tlfmMFAMqtUp7Iy KuJzrZkatmRUzFIQtlTPGWuZZqigFoI= X-Google-Smtp-Source: AA6agR5mEmWR70rsohsYXBBkwh25jznbtxJMxn5NHJGfQXVbDlt9394v2MZchWx42S0yKImnG+fpug== X-Received: by 2002:a65:6c07:0:b0:41d:9ddd:4266 with SMTP id y7-20020a656c07000000b0041d9ddd4266mr1595015pgu.326.1661481921144; Thu, 25 Aug 2022 19:45:21 -0700 (PDT) Received: from macbook-pro-3.dhcp.thefacebook.com ([2620:10d:c090:400::5:15dc]) by smtp.gmail.com with ESMTPSA id w188-20020a6262c5000000b0052c456eafe1sm365074pfb.176.2022.08.25.19.45.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 25 Aug 2022 19:45:20 -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 v4 bpf-next 12/15] bpf: Remove tracing program restriction on map types Date: Thu, 25 Aug 2022 19:44:27 -0700 Message-Id: <20220826024430.84565-13-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220826024430.84565-1-alexei.starovoitov@gmail.com> References: <20220826024430.84565-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661481922; a=rsa-sha256; cv=none; b=uOi6hTvPuPf8Kog9l3GVtvn+bJ1eF6q/lRi4ydj8NCCskVZjw2KNK0/EmwISSQnBnoxwke q+ST+IoZHA+d+Q4QrcnNveA9jK0C4iIPhrG1yoUMSSGlSjZT84T6EAv6biPwppV46JQZfe hBckJWOhg3O24CHaNU//mDX6dS9lsD0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=e+bSbZkl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.174 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=1661481922; 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=npiETgRwDYegJeQPkgRCmw8CYHFlORx1B2gGnaepqcQ=; b=DWOV7f+k08MNVxHDPcZv7/O9/WtLW9+gVzEr81K8t5WFJP1OXztYJ4XrXB1tRfXV5v+WIe T3NoDT3cmcxXL1CJrbOcQmhWudmtPGXtUZh5w8VzzF/87nB4HhmqwQD1s1XqeDdqIopO0Y jbqoVI6oKhrMCKgL7bRecb/cnyRjFmA= Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=e+bSbZkl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-Rspam-User: X-Rspamd-Queue-Id: 221C214000C X-Rspamd-Server: rspam08 X-Stat-Signature: 583ixy4jbqhh6p6gzu9mk9yjrohb7sxn X-HE-Tag: 1661481921-902751 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 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) {