From patchwork Thu Sep 1 16:15:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12962897 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 CEBD0ECAAD8 for ; Thu, 1 Sep 2022 16:16:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67ABB6B00AB; Thu, 1 Sep 2022 12:16:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 605978000C; Thu, 1 Sep 2022 12:16:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 455D48000B; Thu, 1 Sep 2022 12:16:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 34E406B00AB for ; Thu, 1 Sep 2022 12:16:45 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0BB4A140FD7 for ; Thu, 1 Sep 2022 16:16:45 +0000 (UTC) X-FDA: 79864019970.16.95CD729 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf09.hostedemail.com (Postfix) with ESMTP id A35FE14005D for ; Thu, 1 Sep 2022 16:16:44 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id bh13so16831928pgb.4 for ; Thu, 01 Sep 2022 09:16:44 -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=nsaRt32bGU9db3oBvsXD1o3WCeCEvT2VQ8VQ0NN+DuQ=; b=AjGkvzQarWREX80MYqd521cobbbisB71tXVBt1zkuUzMMblPgBytWVeffcjAsKO3Xz WjwHNd3YDPp3J5q6qPDwlmeM7rj8rI7Sh0TXuIycZXCgX0enJAZapcMD0ckYYFoQtFVy ZtUUiel+e5KqtE4NKw1sk8BkdxyYUIRt2NAQCGtdB22vxAkOWkVs/0YZ9kWoUVPB2jQc DsESX8cCxppTmRJnxVkf1ZtWD59gamB4XwYvrnCwQA6COoa5Y8sOqtmOMyJy64A5wHkW SXih0ASCqSYrA41JsmYRpK3MaOHJ3wtX4QOhvV8JapSVB9XMI9FlSg4dSP5Vx5qe/bbF o05g== 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=nsaRt32bGU9db3oBvsXD1o3WCeCEvT2VQ8VQ0NN+DuQ=; b=PsBwVMDFIZVOCY47jMtVMnQFZrESW5lVGKVW76kBny+aT1uEw25/6lpHsIhMAeke2J uk7lw3H2Fk5NuC7Qee4x0aFYSqVwCaCHNFOr8s34aRkUglWhjFhDkVWBEeFTa43VXjVi zHazV0QGtA25W57k5uE6G82sX3grS73Iz9WZ+hvs6+BmLBieA8IUE+QHn4lH86V8YTZ+ 77OeluYskhmscXpggmYMyXYZsJJ7LuuBA1cTlmSAtmg3Zmb17N7T5Zgk4L/PyurzWhUl RtN2M8/FQbWrdw3GNoI/qJa+Qwt1Wj+ZASDYyEQdOLMRqrLTswe4XFB5EKQ2oYjFsnPf A/PQ== X-Gm-Message-State: ACgBeo3cLfBE4f93A1/PoCLygIK0DSGPU1SnngywTgN2kyGmVSpKGONi jvFmNLuUWmiAt2m/il/eNfc= X-Google-Smtp-Source: AA6agR5fl5WH3XWfSQxaOYgWoidwKTZaD/1MGsZn98/okbXbZF5fM8ZiNCbJW1FLOk6IwQZCyO5jDQ== X-Received: by 2002:a63:6cc7:0:b0:42b:7d8f:7136 with SMTP id h190-20020a636cc7000000b0042b7d8f7136mr25223605pgc.15.1662049003655; Thu, 01 Sep 2022 09:16:43 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::3:4dc5]) by smtp.gmail.com with ESMTPSA id a9-20020a637f09000000b004215af667cdsm5537666pgd.41.2022.09.01.09.16.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 01 Sep 2022 09:16:43 -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 14/15] bpf: Remove prealloc-only restriction for sleepable bpf programs. Date: Thu, 1 Sep 2022 09:15:46 -0700 Message-Id: <20220901161547.57722-15-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=1662049004; a=rsa-sha256; cv=none; b=HzJYsoXtRqshG92vNcYL4cvKOMhAkaj8VqTBvlw//kPnT5GFDsmnIoz1YruRXkvcblaPCi V95q4ShtsAe86IJjE4qiJZbwKovrYxht2yynJHXXoCtyOYzEf1hGoSo2B0LBmQETRD87ae dpk4q7PzClz3FPxSbCLdJ6ySBdafd70= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AjGkvzQa; spf=pass (imf09.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.173 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=1662049004; 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=nsaRt32bGU9db3oBvsXD1o3WCeCEvT2VQ8VQ0NN+DuQ=; b=RR/pyPZkeRYX7Phcn4xZKjDiZV57rFl+RCNseyf+Nz/CrKL77ILQAuDalOFFpNp7v5x042 hqxI8igHXvLyT6sJFlSC7vcc9JRc2OHPz5Uummo8V3JSJ7fCLv4tw5YvhR44MWIuc2Gpfi ImjGr1g6ajTCLgxoaO4M8mS/gn0cVh8= Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AjGkvzQa; spf=pass (imf09.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A35FE14005D X-Stat-Signature: m3c48tefdpfkgcg96izj93t6fgt3ncea X-HE-Tag: 1662049004-368293 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 Since hash map is now converted to bpf_mem_alloc and it's waiting for rcu and rcu_tasks_trace GPs before freeing elements into global memory slabs it's safe to use dynamically allocated hash maps in sleepable bpf programs. Acked-by: Kumar Kartikeya Dwivedi Acked-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov --- kernel/bpf/verifier.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 57ec06b1d09d..068b20ed34d2 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -12586,14 +12586,6 @@ static int check_pseudo_btf_id(struct bpf_verifier_env *env, return err; } -static int check_map_prealloc(struct bpf_map *map) -{ - return (map->map_type != BPF_MAP_TYPE_HASH && - map->map_type != BPF_MAP_TYPE_PERCPU_HASH && - map->map_type != BPF_MAP_TYPE_HASH_OF_MAPS) || - !(map->map_flags & BPF_F_NO_PREALLOC); -} - static bool is_tracing_prog_type(enum bpf_prog_type type) { switch (type) { @@ -12608,15 +12600,6 @@ static bool is_tracing_prog_type(enum bpf_prog_type type) } } -static bool is_preallocated_map(struct bpf_map *map) -{ - if (!check_map_prealloc(map)) - return false; - if (map->inner_map_meta && !check_map_prealloc(map->inner_map_meta)) - return false; - return true; -} - static int check_map_prog_compatibility(struct bpf_verifier_env *env, struct bpf_map *map, struct bpf_prog *prog) @@ -12669,12 +12652,6 @@ static int check_map_prog_compatibility(struct bpf_verifier_env *env, case BPF_MAP_TYPE_LRU_PERCPU_HASH: case BPF_MAP_TYPE_ARRAY_OF_MAPS: case BPF_MAP_TYPE_HASH_OF_MAPS: - if (!is_preallocated_map(map)) { - verbose(env, - "Sleepable programs can only use preallocated maps\n"); - return -EINVAL; - } - break; case BPF_MAP_TYPE_RINGBUF: case BPF_MAP_TYPE_INODE_STORAGE: case BPF_MAP_TYPE_SK_STORAGE: