From patchwork Fri Aug 19 21:42:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12949282 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 0217DC32771 for ; Fri, 19 Aug 2022 21:45:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D2F36B0073; Fri, 19 Aug 2022 17:45:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 882998D0005; Fri, 19 Aug 2022 17:45:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7239E8D0003; Fri, 19 Aug 2022 17:45:23 -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 611B16B0073 for ; Fri, 19 Aug 2022 17:45:23 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3670B81AB3 for ; Fri, 19 Aug 2022 21:45:23 +0000 (UTC) X-FDA: 79817673726.17.5D675BB Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf06.hostedemail.com (Postfix) with ESMTP id 2565418002C for ; Fri, 19 Aug 2022 21:43:26 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id 2so5186917pll.0 for ; Fri, 19 Aug 2022 14:43:26 -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=bW5ocW6PzISfaCgKiPdCkbtq/RA2U8OKQTKMdTGnVOA=; b=QL0G/EHoJfksQ4p6mh6jETpl0vwiWZswZj/MQI0CXx3GQ3XVocxIglIesp1mjt6wig liFF8jPt0KXoJ+PurPcIH41o7V+QkbIadjk4Okh9eyYvPwKeN2XF0bHWtiHpL1MKxE7P C+ePoBtSmYEBPgR/F159rvLFaFgWqmrHo47CKrrYjAlH+WEPNOb3DdMvOn6m4kjqltc7 iD9zOt6GSKu1/Bu2Ld5wdUAS/2exFqYpqD3DLVdb4K9K446n4ZPAdmO8B4ZYdubYD6C5 NUVTtVRkpKRUm8k1SelZZIDYmuadXTy+z0Bk3bHXaqzkOhAZg8nc0nglkMGRxm6bub6P JJxA== 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=bW5ocW6PzISfaCgKiPdCkbtq/RA2U8OKQTKMdTGnVOA=; b=1PLUmDISL5Mo2f9jIk3mQ/SpHd0WTE5UrNb2J46idrh6ep8OU9mjBCt2KKETN6+upy JaxVnC/ogCpe2wFPI0t9juqqPzBPYvP/sJbBipKLMeCHEIjQ7LVPQWfmXa5QveBzzcQB KeoHcMkQn0YAexwrhv5G6zACSX7JffXlOdxYVhjf+4nJBYS0A8s7epOutba/ERgv+Yu8 fGJpF9ljUfO79hGMjkkUocpriSKlgGfCNfytQXprgm9gv8F6fq6DsUqtBnL6YlcSvfV9 tNzhrYRVWBQf/k2FMQ0vH/FYa34bcParz+JCymU0MLsX7JpApjGC+HQFsIYWLH//49rs JF6w== X-Gm-Message-State: ACgBeo1WsU9KZnLJacEf5Df+i2WmCDilDWIgumfHYCn3UjytfUdDCqPb ayyunFG3eYAjOF5Uid5NGNc= X-Google-Smtp-Source: AA6agR56faXSMcH0PAhNAx9r0g5F4js3qHybSTN70KIu5Hh8X5AOPg7E/K1Wj532E/7UrKfXAIftFw== X-Received: by 2002:a17:90b:4a4d:b0:1f5:431c:54fa with SMTP id lb13-20020a17090b4a4d00b001f5431c54famr10378826pjb.199.1660945406270; Fri, 19 Aug 2022 14:43:26 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::1:c4b1]) by smtp.gmail.com with ESMTPSA id y23-20020a17090264d700b0016b81679c1fsm3587099pli.216.2022.08.19.14.43.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 19 Aug 2022 14:43:25 -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 14/15] bpf: Remove prealloc-only restriction for sleepable bpf programs. Date: Fri, 19 Aug 2022 14:42:31 -0700 Message-Id: <20220819214232.18784-15-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=1660945407; 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=bW5ocW6PzISfaCgKiPdCkbtq/RA2U8OKQTKMdTGnVOA=; b=cd4X3YErsh4iddgF3zpsDh+K8jF5Xx7LXY+aoBN6X7/kKrJA2rKOsHMqzjQ4LqsGTgNTcV RnL4l+qsFIuZ+CZ4nfhR++6laq5U2218JhUIcR5r53sTxRCjF1hfr9ggPIXK8mgMCAEZJf ovMvWX3EEesJ/+QZ0Kh9mc65ZulDTTQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="QL0G/EHo"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660945407; a=rsa-sha256; cv=none; b=BP7IjdVB7YS0ECPL9aJpUlqQf2CVTvSnlyf6yH3b8aqzjx/lmNjX4NzahgSfffh1xQrK7b FOlh/F9j3u+5Ss9yODfkkrUzOxEMXvKDJc4q/q+2B6C8aYWICno032UN1sZXg5XuOhAV3d bY5MUM3egaOsr20femVNNcRbTI4SXRw= X-Rspamd-Queue-Id: 2565418002C X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="QL0G/EHo"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-Rspamd-Server: rspam04 X-Stat-Signature: fjt5xaanzfokk9ekoaiqfwammpasgu3e X-HE-Tag: 1660945406-266201 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. 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 a1ada707c57c..dcbcf876b886 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -12562,14 +12562,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) { @@ -12584,15 +12576,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) @@ -12645,12 +12628,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: