From patchwork Fri Jul 29 15:23:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12932544 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 AAE00C00144 for ; Fri, 29 Jul 2022 15:23:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 419926B0087; Fri, 29 Jul 2022 11:23:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CA706B0088; Fri, 29 Jul 2022 11:23:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21B406B0089; Fri, 29 Jul 2022 11:23:52 -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 141B96B0087 for ; Fri, 29 Jul 2022 11:23:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E6194C1133 for ; Fri, 29 Jul 2022 15:23:51 +0000 (UTC) X-FDA: 79740507462.15.1E09E6B Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf20.hostedemail.com (Postfix) with ESMTP id 8E4FC1C000B for ; Fri, 29 Jul 2022 15:23:51 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id v16-20020a17090abb9000b001f25244c65dso8716330pjr.2 for ; Fri, 29 Jul 2022 08:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vYnEy8nKJWMROwA3MmvoCcmRLFYdVgR55TwlItJ2+GU=; b=Mkrl04Y5bR3wO1T3rRf4pjfQ6zW0Au+4rSRFHRqhmyLikvX+6Mhx2b47cSG2rgEaCW XPCcWAbWgbq/cxdH/xP1L7oWnHwfbF3+SmoqM4Y0/peTnhwEjmCVKDBmISQceZn7IKy9 4lfLn41fhG7TI/xqGA3YRfVmEJm9MsyqXXoZx5tdaye0L+S/j5TIrnsFXlcDu95kwb41 TGYhUGnPF1jX3PWn0L6lRgwISXK/D3AJat0IY1I5m3UfRy8hYosZNVkHJnVdWd63sEqv /nmRZxOjXyPAdnEfbjEmIkT4HHGTyNMGVyLGhY2EoIaQ7L/HS5meKFFLAGP+s+knjQHL iKAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vYnEy8nKJWMROwA3MmvoCcmRLFYdVgR55TwlItJ2+GU=; b=yvXQTRYbVHeq3jVaB3yPHGK6zBpCQzDkALPme7swFKZgs53rDWl4kI9qgsl2KzBKtp XbryT72CJ+GIp3IIwQyffyYst2QjwxRXahH6BYvzCUwisCUFXN4LWDaPHxkGRbIYJZK7 h9vhPgcQwjVGl0s0qS7ys+D1Qld9XG7Mz7cnMqXTsEbEcbTDbRPtxeEPA7Am8DURx4xl 6BFX4mrk4ACK45xVj4EPHJtYUWCLzpa85pd29IzPiDdWNfYJKys7SWF2IkSfnhWfZlw1 X/OHFLkLk8+dGAuxxHvZlOM+N01pFrfWNTGCgulTl4JKxEC/k+1HICGtjt79+CLyzRpV 097w== X-Gm-Message-State: ACgBeo2d5U3BwfSUe0f9bX+cuIPrK4Ulwh3rmd5JDkFBp0iFEk14fqba jCY2mC2uI7BCkMj5PBH5Dbg= X-Google-Smtp-Source: AA6agR5/5myi/pHhqOGN+umenk6xWAgqpqvDsItrls1rKZv/ueQaUf6O4B1azHULpfbNK/hwB1PyTg== X-Received: by 2002:a17:902:d48a:b0:16d:30f4:ca5a with SMTP id c10-20020a170902d48a00b0016d30f4ca5amr4369743plg.50.1659108230655; Fri, 29 Jul 2022 08:23:50 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:2912:5400:4ff:fe16:4344]) by smtp.gmail.com with ESMTPSA id b12-20020a1709027e0c00b0016d3a354cffsm3714219plm.89.2022.07.29.08.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 08:23:49 -0700 (PDT) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, songmuchun@bytedance.com, akpm@linux-foundation.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-mm@kvack.org, Yafang Shao Subject: [RFC PATCH bpf-next 14/15] bpf: Add new map flag BPF_F_SELECTABLE_MEMCG Date: Fri, 29 Jul 2022 15:23:15 +0000 Message-Id: <20220729152316.58205-15-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220729152316.58205-1-laoar.shao@gmail.com> References: <20220729152316.58205-1-laoar.shao@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659108231; 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=vYnEy8nKJWMROwA3MmvoCcmRLFYdVgR55TwlItJ2+GU=; b=hUcJ3tESvwC8VsdxSjve/3duFcqKuquRIZ6OK77DqZ73FvtZVhqEwPY9Gqnkh/EoAYsV9x Z2zQ7SIy7bAxH8rU3G++KOh6Bg4BeFxGHc8Q20Q0ke7o1va9eAAprgtcBHfQiaYFTSFAQz FAfkQFz35nbxj/t+RGScyJiQQC7Qfdo= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Mkrl04Y5; spf=pass (imf20.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659108231; a=rsa-sha256; cv=none; b=SvnHGzI/BFn387rFYD0KUXaf53J925LKBwQCl23EapGYiSM/OjI/boCku2SYgeg4Dp3I78 fyQkwpml6Qcl3qNkwmf/0HydAJNbD+5kpvIBUgN3tNYmAMWOCs/DUskmGPC/FfGjSXBjth 5GiojLAlT7HDd4mYkqJSJDrsGCIrf24= X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8E4FC1C000B X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Mkrl04Y5; spf=pass (imf20.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: rt69tsrxd9hq4wchkfuw36118c4j3s5g X-HE-Tag: 1659108231-748199 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: Introduce new map flag BPF_F_SELECTABLE_MEMCG for map creation. This flag is supported for all bpf maps. This is a preparation for followup patch. Signed-off-by: Yafang Shao --- include/uapi/linux/bpf.h | 3 +++ kernel/bpf/arraymap.c | 2 +- kernel/bpf/bloom_filter.c | 4 ++-- kernel/bpf/bpf_local_storage.c | 3 ++- kernel/bpf/bpf_struct_ops.c | 5 ++++- kernel/bpf/devmap.c | 4 ++-- kernel/bpf/hashtab.c | 2 +- kernel/bpf/local_storage.c | 2 +- kernel/bpf/queue_stack_maps.c | 2 +- kernel/bpf/ringbuf.c | 2 +- kernel/bpf/stackmap.c | 2 +- net/core/sock_map.c | 4 ++-- tools/include/uapi/linux/bpf.h | 3 +++ 13 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 59a217ca2dfd..d5fc1ea70b59 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1227,6 +1227,9 @@ enum { /* Create a map that is suitable to be an inner map with dynamic max entries */ BPF_F_INNER_MAP = (1U << 12), + +/* Selectable memcg */ + BPF_F_SELECTABLE_MEMCG = (1U << 13), }; /* Flags for BPF_PROG_QUERY. */ diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 883905c6c845..eb8deac529ac 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -17,7 +17,7 @@ #define ARRAY_CREATE_FLAG_MASK \ (BPF_F_NUMA_NODE | BPF_F_MMAPABLE | BPF_F_ACCESS_MASK | \ - BPF_F_PRESERVE_ELEMS | BPF_F_INNER_MAP) + BPF_F_PRESERVE_ELEMS | BPF_F_INNER_MAP | BPF_F_SELECTABLE_MEMCG) static void bpf_array_free_percpu(struct bpf_array *array) { diff --git a/kernel/bpf/bloom_filter.c b/kernel/bpf/bloom_filter.c index 9fe3c6774c40..3714aebc9ed6 100644 --- a/kernel/bpf/bloom_filter.c +++ b/kernel/bpf/bloom_filter.c @@ -9,8 +9,8 @@ #include #include -#define BLOOM_CREATE_FLAG_MASK \ - (BPF_F_NUMA_NODE | BPF_F_ZERO_SEED | BPF_F_ACCESS_MASK) +#define BLOOM_CREATE_FLAG_MASK (BPF_F_NUMA_NODE | \ + BPF_F_ZERO_SEED | BPF_F_ACCESS_MASK | BPF_F_SELECTABLE_MEMCG) struct bpf_bloom_filter { struct bpf_map map; diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c index e12891dcf2a9..7798235f311e 100644 --- a/kernel/bpf/bpf_local_storage.c +++ b/kernel/bpf/bpf_local_storage.c @@ -15,7 +15,8 @@ #include #include -#define BPF_LOCAL_STORAGE_CREATE_FLAG_MASK (BPF_F_NO_PREALLOC | BPF_F_CLONE) +#define BPF_LOCAL_STORAGE_CREATE_FLAG_MASK \ + (BPF_F_NO_PREALLOC | BPF_F_CLONE | BPF_F_SELECTABLE_MEMCG) static struct bpf_local_storage_map_bucket * select_bucket(struct bpf_local_storage_map *smap, diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index 51b7ce9902a8..208d593e6a44 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -12,6 +12,8 @@ #include #include +#define STRUCT_OPS_CREATE_FLAG_MASK (BPF_F_SELECTABLE_MEMCG) + enum bpf_struct_ops_state { BPF_STRUCT_OPS_STATE_INIT, BPF_STRUCT_OPS_STATE_INUSE, @@ -586,7 +588,8 @@ static void bpf_struct_ops_map_free(struct bpf_map *map) static int bpf_struct_ops_map_alloc_check(union bpf_attr *attr) { if (attr->key_size != sizeof(unsigned int) || attr->max_entries != 1 || - attr->map_flags || !attr->btf_vmlinux_value_type_id) + (attr->map_flags & ~STRUCT_OPS_CREATE_FLAG_MASK) || + !attr->btf_vmlinux_value_type_id) return -EINVAL; return 0; } diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index 11c7b8411b03..52858963373c 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c @@ -50,8 +50,8 @@ #include #include -#define DEV_CREATE_FLAG_MASK \ - (BPF_F_NUMA_NODE | BPF_F_RDONLY | BPF_F_WRONLY) +#define DEV_CREATE_FLAG_MASK (BPF_F_NUMA_NODE | \ + BPF_F_RDONLY | BPF_F_WRONLY | BPF_F_SELECTABLE_MEMCG) struct xdp_dev_bulk_queue { struct xdp_frame *q[DEV_MAP_BULK_SIZE]; diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 3cb9486eb313..532c8ee89d58 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -17,7 +17,7 @@ #define HTAB_CREATE_FLAG_MASK \ (BPF_F_NO_PREALLOC | BPF_F_NO_COMMON_LRU | BPF_F_NUMA_NODE | \ - BPF_F_ACCESS_MASK | BPF_F_ZERO_SEED) + BPF_F_ACCESS_MASK | BPF_F_ZERO_SEED | BPF_F_SELECTABLE_MEMCG) #define BATCH_OPS(_name) \ .map_lookup_batch = \ diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c index b2bd031aba79..009d6f43a099 100644 --- a/kernel/bpf/local_storage.c +++ b/kernel/bpf/local_storage.c @@ -16,7 +16,7 @@ #include "../cgroup/cgroup-internal.h" #define LOCAL_STORAGE_CREATE_FLAG_MASK \ - (BPF_F_NUMA_NODE | BPF_F_ACCESS_MASK) + (BPF_F_NUMA_NODE | BPF_F_ACCESS_MASK | BPF_F_SELECTABLE_MEMCG) struct bpf_cgroup_storage_map { struct bpf_map map; diff --git a/kernel/bpf/queue_stack_maps.c b/kernel/bpf/queue_stack_maps.c index 9425df0695ac..c4aab43198ad 100644 --- a/kernel/bpf/queue_stack_maps.c +++ b/kernel/bpf/queue_stack_maps.c @@ -12,7 +12,7 @@ #include "percpu_freelist.h" #define QUEUE_STACK_CREATE_FLAG_MASK \ - (BPF_F_NUMA_NODE | BPF_F_ACCESS_MASK) + (BPF_F_NUMA_NODE | BPF_F_ACCESS_MASK | BPF_F_SELECTABLE_MEMCG) struct bpf_queue_stack { struct bpf_map map; diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c index 3be472fd55da..53a7eb8db257 100644 --- a/kernel/bpf/ringbuf.c +++ b/kernel/bpf/ringbuf.c @@ -12,7 +12,7 @@ #include #include -#define RINGBUF_CREATE_FLAG_MASK (BPF_F_NUMA_NODE) +#define RINGBUF_CREATE_FLAG_MASK (BPF_F_NUMA_NODE | BPF_F_SELECTABLE_MEMCG) /* non-mmap()'able part of bpf_ringbuf (everything up to consumer page) */ #define RINGBUF_PGOFF \ diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index c952c7547279..007b10d2da7d 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -14,7 +14,7 @@ #define STACK_CREATE_FLAG_MASK \ (BPF_F_NUMA_NODE | BPF_F_RDONLY | BPF_F_WRONLY | \ - BPF_F_STACK_BUILD_ID) + BPF_F_STACK_BUILD_ID | BPF_F_SELECTABLE_MEMCG) struct stack_map_bucket { struct pcpu_freelist_node fnode; diff --git a/net/core/sock_map.c b/net/core/sock_map.c index 4d9b730aa27f..0310b00e19b8 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -21,8 +21,8 @@ struct bpf_stab { raw_spinlock_t lock; }; -#define SOCK_CREATE_FLAG_MASK \ - (BPF_F_NUMA_NODE | BPF_F_RDONLY | BPF_F_WRONLY) +#define SOCK_CREATE_FLAG_MASK (BPF_F_NUMA_NODE | \ + BPF_F_RDONLY | BPF_F_WRONLY | BPF_F_SELECTABLE_MEMCG) static int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog, struct bpf_prog *old, u32 which); diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 59a217ca2dfd..d5fc1ea70b59 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1227,6 +1227,9 @@ enum { /* Create a map that is suitable to be an inner map with dynamic max entries */ BPF_F_INNER_MAP = (1U << 12), + +/* Selectable memcg */ + BPF_F_SELECTABLE_MEMCG = (1U << 13), }; /* Flags for BPF_PROG_QUERY. */