From patchwork Fri Aug 19 21:42:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12949277 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 30816C32771 for ; Fri, 19 Aug 2022 21:43:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6B988D0003; Fri, 19 Aug 2022 17:43:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF3806B007D; Fri, 19 Aug 2022 17:43:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96D336B0081; Fri, 19 Aug 2022 17:43:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7E2D96B0074 for ; Fri, 19 Aug 2022 17:43:20 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6172781AAE for ; Fri, 19 Aug 2022 21:43:20 +0000 (UTC) X-FDA: 79817668560.12.C0A27D3 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf29.hostedemail.com (Postfix) with ESMTP id 223F2120124 for ; Fri, 19 Aug 2022 21:43:19 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id l64so4677598pge.0 for ; Fri, 19 Aug 2022 14:43:19 -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=ZBI+fwy76bkYY8LVV14e2AjKMWsYkt0VzLIv3m+2oj8=; b=ZrGKkLUP6ZJKXIZPS65dM/dVlcFh5D42Kebha2HBWqrRjunPYa8phJu/LZ6s2Eykhe zMVvKesptbxuK4TjFFxmkfk39Q2PAMttuQLmkIVyZVwXdOsttmDcjpWQ/W51LhcXGeQw eWs5kWF1ymCJ0Pm7jev0AjfgeRp6CncHmEKS6M36J9/jO6HKHg3xJJGwd1ncmyQLvLn4 fWLQPjDGvrHHErxTsPTpIcX5Jbq9U+zBwl0Ebr4ekzakyu8KQKfXOe6Y2KKbZBhp+WD7 XpW6c339wN77gce7pVAqWQ6pOHHYwl15UbBmJpsFeHJxQPYe6SuRGBoJhs8Wv7uQfgzv 3JiQ== 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=ZBI+fwy76bkYY8LVV14e2AjKMWsYkt0VzLIv3m+2oj8=; b=bxodVerItFvCPsnxqZp0w5ddTmt462fXkklQXy2XXnqn/ttmmLvWPRNgFSiKhoD6Sj OVXordjqyKjwHgjruUwFd24R0w5WHfGke/6ptnf3dH5ItMNeGc1K5x3bEb6r0Bzbr1/E epB/R9q3DLg7rxM0JDzIonKrdSdcdgcYEx9kKSuX1cKbBDb7BRCOa966P2ya7cKI709O IHy44dPPe3qtuJ93FqjIeTVBkvrdCD6Xzhc+MSBGJG/SxMi7TET4eK5pVnu2a9OLEUEj +YU5kR8Lffh7LN6KE0+DI5Y96oYhfk3uHHDA5Zfp+MxCuMzqnXVAXb7tf6bj9KXhjxCG NtMA== X-Gm-Message-State: ACgBeo2RBvBHu+C9expPUmgPpZ2M4rghFrRMvdIiObo7agKjExqEfmQ9 v+px5kaJ/jVoasG1DzDJTGg= X-Google-Smtp-Source: AA6agR7oDkmuQzOgW9F0m5UMAkfxkclSWKTAKhyoF1nqkS99BcY1GM7gcN1QX1nxGpw4wZpR9y4iiA== X-Received: by 2002:a05:6a00:1588:b0:52f:a5bb:b992 with SMTP id u8-20020a056a00158800b0052fa5bbb992mr9616631pfk.38.1660945399062; Fri, 19 Aug 2022 14:43:19 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::1:c4b1]) by smtp.gmail.com with ESMTPSA id n14-20020a170903110e00b0016d6963cb12sm3562742plh.304.2022.08.19.14.43.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 19 Aug 2022 14:43:18 -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 v3 bpf-next 12/15] bpf: Remove tracing program restriction on map types Date: Fri, 19 Aug 2022 14:42:29 -0700 Message-Id: <20220819214232.18784-13-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220819214232.18784-1-alexei.starovoitov@gmail.com> References: <20220819214232.18784-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660945400; 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=ZBI+fwy76bkYY8LVV14e2AjKMWsYkt0VzLIv3m+2oj8=; b=GP2Nsoy4Kjo2542lftzLB9jreiewaluBL1v46ew+RiE1XCmT83xBsOux/ejfOlT9NAZbRe 2t+GwR1GWRNlvuJSv0P6qxRblhGuTs2bWiPXM1DWE1jrfFxXuyOYYg/1tj/pA/6y3F10hI q8nc/MtfLIP4fEiUttk76byAjt2cmI0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZrGKkLUP; spf=pass (imf29.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.172 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=1660945400; a=rsa-sha256; cv=none; b=4MChJRPXt7/uAnvPxe/NNPK0/4verps6U9v+imn67tCKdh6pXCDAAU7DvTaYgUkdZAsVx5 nTCD0FCHcC+eAS1OLtN6GE3alY2/EI6CkqClTB+3f6IIENgrgZjdUnWd07R5GBDcj7nLeS cBDoo7L6b8NPdIFkbz32krYMQQVX+mU= Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZrGKkLUP; spf=pass (imf29.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 223F2120124 X-Stat-Signature: x146u6x7x5iwmswtckqo91ezhzawd6pw X-Rspam-User: X-HE-Tag: 1660945399-31270 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. 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 d785f29047d7..a1ada707c57c 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -12599,48 +12599,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) {