From patchwork Wed Aug 17 21:04:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12946482 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 51CC4C25B08 for ; Wed, 17 Aug 2022 21:05:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E292C8D000D; Wed, 17 Aug 2022 17:05:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD8608D0002; Wed, 17 Aug 2022 17:05:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C79E58D000D; Wed, 17 Aug 2022 17:05:08 -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 B7D048D0002 for ; Wed, 17 Aug 2022 17:05:08 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9599E1C6F0C for ; Wed, 17 Aug 2022 21:05:08 +0000 (UTC) X-FDA: 79810314654.18.721949F Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf02.hostedemail.com (Postfix) with ESMTP id 2733E801D8 for ; Wed, 17 Aug 2022 21:05:07 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id g18so4599739pju.0 for ; Wed, 17 Aug 2022 14:05:07 -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=WWKi4wI8r69uN3XJ0TC1pEJIpFbczA4APGAcyEcd85IDHK1d0qgmvHQGgGWL29zF80 h6GVEVP662vDxI0f1Ihp9BP9SNsUKr/sAaalCilStw2HtG+V91lr9Y+ThIEzl9CEgiVe x+xHcMTAqaqDqV2aqjtTd/xGI5qKv1LxiJ27F32wwTMARWO03anfgcCy+u55VZcY1QuN zJJh3bmyUuq6wgP3xmlIPUTYPYPUAdYWM0aCL76A31OJ5tFL6pl54wF0Kl9LKhXA9ckl BQmX+AWaxGxV2iGQawz9rTaK9CSK38EjvwR2IDHqzxs54KW9Zub5bvmqUHzoIW7nrDeq g+YA== 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=JYGGkz9Q43n8iPmzNbY4U9YwoghSXq1F2vxZMvopTz6izrwIQekfeC114SKky3gV5Z 8F9MIDMKw1mbW7asJmKRyUSa/5I0JbG4YN19JwObFukF9KLKNWrtyKWF6DuFHo4NggKa FrrJNWUGWBZCUMyq52OIj0dUwP1qUB9TeRR4/D2GoLZa2qlZhjYXWlz7ZqDguDDrN+6r J4dImcVsjJUPW+6u9xwtLFV5/MIFCVAuw9Shp+1KvZ9/6ef6GU6jkoqOnQGYagqD//Rb prriitdBpNU03k+ax2gDrU3RifSQtgESxTAnMwl6z+DL/5DatJnH65gZi1KRYLSvBA35 gHQQ== X-Gm-Message-State: ACgBeo30F02T5pknaiBpYICMBqRUGWAiaOOuOTKlyJhtuVWkNNHV6HxE jM1FqXETJ/HY5QpFE9uKDWM= X-Google-Smtp-Source: AA6agR7gJR7MOvq7/smgPOcBfW8hZe45QZI7aUrmByAEqpEfPv1pIsb0aEpqc9BmPebRsePmQkj86Q== X-Received: by 2002:a17:90b:1b05:b0:1fa:c33e:9137 with SMTP id nu5-20020a17090b1b0500b001fac33e9137mr1728268pjb.59.1660770306969; Wed, 17 Aug 2022 14:05:06 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::1:ccd6]) by smtp.gmail.com with ESMTPSA id 72-20020a62174b000000b005349f259457sm8204082pfx.160.2022.08.17.14.05.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 Aug 2022 14:05:06 -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 v2 bpf-next 12/12] bpf: Remove tracing program restriction on map types Date: Wed, 17 Aug 2022 14:04:19 -0700 Message-Id: <20220817210419.95560-13-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220817210419.95560-1-alexei.starovoitov@gmail.com> References: <20220817210419.95560-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660770308; a=rsa-sha256; cv=none; b=pFz/HDNgfXKA9kLmnZVFr71Yd4SZM8LDdY3aZ7RfHkZZGXlepuk0kC82fNFQWMA1/vBqkg rIiL+yfJ0VopUZqnz3qIBfiYcMIXyK4UVsdwSrD66M2+znqzyGyGoMniFuBx/KC+RVJ/OY UJ0+3JIu12aGzLXg6/BBczvo4AG0Lh4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=WWKi4wI8; spf=pass (imf02.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660770308; 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=B5dlDNXFOn8x9vZdAscwI3ZZ2B09BFTSvPXnYjRHvl8XRVmfVoTtyW3QWjzJ6K4f+Av+4s /0byPmZD0X/dzEG3D0rsytQ0TlWLvXjkHIlZyN63RnyxV7mZ9/Kwfsm5nOKSVO2FJD9ezW 29b+fHhlBdJBaHbbjzBAkwdFig/tE6s= Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=WWKi4wI8; spf=pass (imf02.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: aufjfoornw6ojh5hz4h4hxpdpkig4m4n X-Rspamd-Queue-Id: 2733E801D8 X-HE-Tag: 1660770307-634847 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) {