From patchwork Fri Aug 26 02:44: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: 12955506 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 53EDDECAAA3 for ; Fri, 26 Aug 2022 02:45:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD7F080011; Thu, 25 Aug 2022 22:45:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D87AA80007; Thu, 25 Aug 2022 22:45:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C28D580011; Thu, 25 Aug 2022 22:45:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B058080007 for ; Thu, 25 Aug 2022 22:45:30 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9387E12069F for ; Fri, 26 Aug 2022 02:45:30 +0000 (UTC) X-FDA: 79840202820.13.0518B80 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf31.hostedemail.com (Postfix) with ESMTP id 54C1C20012 for ; Fri, 26 Aug 2022 02:45:30 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id ds12-20020a17090b08cc00b001fae6343d9fso6905166pjb.0 for ; Thu, 25 Aug 2022 19:45:30 -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=uV2iJKt1r8T4/kLPE+0S1a5qg1z9UcPmTn8EI+FbVTo=; b=gtEwsy4x+ddZbQwM7VlCCFDOxzrhgFhLglupjaRgCD3AJZlTMpit1vdMX5v8Bni/HA vDa71MrVWUlvn5LpFBMWOWVw6vMcrOCd/fUEeM1UMXpCTra44xMBlSb+iMsNNFy3CH7m 4JXWN4MlEX3rJMhhnlxU7n+Od+4H1MZVHWvG1TMSziWe03JZKAfH5asgRhyi32or0QX0 tqkGfCdKrOVoFtOXf/ySkKi1evQRMdtWo0NRmE31kSGsSO0hc3jVAukkBFPjftA40wXx onIV8UusP66eO+hVTj1a5Htqwo3bXAk8c727wkzss96LrUc2Gdsf0oPeoaQWnjVAOM9W SIHw== 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=uV2iJKt1r8T4/kLPE+0S1a5qg1z9UcPmTn8EI+FbVTo=; b=iHoUXEBM0Z6YFiHQ7Xli07CL4qFf8pHtOP4z+Caqhv0tHUNQ161e5xCQrkZrhyCl+9 ReN8tAVbH2G0Ao5gDHNhnFpZ8ADbK+EVWDsAxbL+cYxQ1YCAGZdVuAnOeBDppr530Xmj bcsZZNFhYmBlfKQA/SEBS7jZEe9XeWxbYswc/C39rVLgj5v+xgB/K7/IUuS1D7/YUQeo mVut3eYAREfdb2d0PwubMWioJJQj8huz0Fa8h4sP+eut2L7Gd7rmxD0h5Io5VcnOn5+r QiuTwSqW5ehfgJeOlZxPtCjlLWxN9scFDk+qtQ/LjVLkISK3X4+jFWOIFDMXIZSQG4e+ 8Y+w== X-Gm-Message-State: ACgBeo3Srtfq6NgUaQo9DgPPPjy3Rf29TvUS3+9Me7Kb4SW/12JZ0JO1 NnLcMEMEhu6Yqmuwv1fiW4o= X-Google-Smtp-Source: AA6agR6cxdfOqJFcJA44Y7BdIgBjd3RcuOdJYy4wgdgAkiQKPwJQN8WC3FxYM1NwvpDrniv6z1pgVQ== X-Received: by 2002:a17:90a:1d0:b0:1fa:c551:5e83 with SMTP id 16-20020a17090a01d000b001fac5515e83mr2116468pjd.106.1661481929024; Thu, 25 Aug 2022 19:45:29 -0700 (PDT) Received: from macbook-pro-3.dhcp.thefacebook.com ([2620:10d:c090:400::5:15dc]) by smtp.gmail.com with ESMTPSA id p9-20020a1709027ec900b00172c7d6badcsm259849plb.251.2022.08.25.19.45.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 25 Aug 2022 19:45:28 -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 14/15] bpf: Remove prealloc-only restriction for sleepable bpf programs. Date: Thu, 25 Aug 2022 19:44:29 -0700 Message-Id: <20220826024430.84565-15-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-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gtEwsy4x; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf31.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661481930; a=rsa-sha256; cv=none; b=oLDNXGNP5wrY/RL7opFZZD1r+HyETAK9IQPpDxquhwkZayk2mZjZyDEX8p/rIdla2pseo8 lRyRaO33RucmlPjXVic+lDcH89tWDpCN7PQ3Uyl+9gezc4r/iE+wrNwonezFaLgyObiFzY rOQ4HIssGNX1tIvBG3kyBb3aqTr17dE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661481930; 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=uV2iJKt1r8T4/kLPE+0S1a5qg1z9UcPmTn8EI+FbVTo=; b=vxKyCostc3anWLLf1AiV7V0caqab+1s86KyMH6geIgSwqZHpzx5l+hmnseJQ4/I+Z7KWqt DeyfXHtT8dWMN8vUImwHgZOfaLwd5n3lCTd8Wn7phm4syM7KRUouNRa1eB35yquk/yqt7G 7gkurcF9BDe7DKBYmxFIkXUzpyT1QaI= X-Stat-Signature: faxsfjxpdscktzsaztzwwn63mjbw7smg Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gtEwsy4x; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf31.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 54C1C20012 X-Rspam-User: X-HE-Tag: 1661481930-310084 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 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: