From patchwork Tue Mar 8 13:10:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12773795 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 E6F2BC433FE for ; Tue, 8 Mar 2022 13:11:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71F7E8D000C; Tue, 8 Mar 2022 08:11:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A47C8D0001; Tue, 8 Mar 2022 08:11:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 543C08D000C; Tue, 8 Mar 2022 08:11:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 459E98D0001 for ; Tue, 8 Mar 2022 08:11:28 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0A4E41A8F for ; Tue, 8 Mar 2022 13:11:28 +0000 (UTC) X-FDA: 79221255456.13.FF8DF4A Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf28.hostedemail.com (Postfix) with ESMTP id 6E6BAC0007 for ; Tue, 8 Mar 2022 13:11:27 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id s11so17253130pfu.13 for ; Tue, 08 Mar 2022 05:11:27 -0800 (PST) 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=3y4pmtErmcUQqTEOzusAX2pzTuUiyQeDCSeMBuC6VMQ=; b=SiVmiDuO/2M2Xzol8AGb7jc3+OznGw2J3+JiAFGq0IgPtRBs+B5WCzg555zf8AFxw/ SvYvYKlfzqYxdYqt6HLWTZDy8hkMR7VnTuVpC45UG+9hWjGQT82Z1lZGXZz5u5ZkI1Sb T8wWUD1Ign+8sEYvUjXqv3kCkXpo2pRUaADUOJC50otN7MQwMr6DhUs3+5lXu5EZyZlv 2hNDqCxhpUMTgCqyUWHe6LD6wxoxG2PbB4oUB14AjukT5kPNQVRsOtgTr1FmYzxJeIYq pq7ceeU7QUXEBoLpCRr4f2m0Wt8L3ogseVrdawWE9L5U3W4JXEjIhDfPwNpqxZEx+Kkp TdMg== 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=3y4pmtErmcUQqTEOzusAX2pzTuUiyQeDCSeMBuC6VMQ=; b=a48vnQ3q8tAwJQY6uQnWYi/CoEugIrEurnX9ijFT4aosgje1EA9wCa2uN26oIs9DkK 3T9085xM3+kbCCMby2tCHnpNVhEYAANU3CgNupynvsQc2A4221lrAb9arsaqa02nD7TQ Iso6QbY8KY8AOJt9Od3N1RD3H59l9s7+ny/qAD07hOwKDbl3GM+ocjMoHnfYEbfEzHK1 UXlRGF5W8USaDG3PvF9Fz+OsjKS5P21UYmjdFrSORgh7FWMM5tqU6vIeScy8hGYztIGG rTPBB9S8Ig4dInnVKRLKnwR64c8NRdAABEOvwtwqz8FWJpHhCTlJjPGpcQXHLcb0T/JI 2T5w== X-Gm-Message-State: AOAM532640hbIMa8hV+rEIENy5vlKWQQvwWuE6rQyxI2Kefc6gbwD8tS +fWaUX4Db70EIsvn7qXDNWk= X-Google-Smtp-Source: ABdhPJxozHq59VkUFv288fl2mix6RMNdONpReM8rlehkbq7w0YTK49AhZHAdBosK85EByFXP+tX5JQ== X-Received: by 2002:a63:d253:0:b0:380:3aee:8437 with SMTP id t19-20020a63d253000000b003803aee8437mr9002618pgi.382.1646745084332; Tue, 08 Mar 2022 05:11:24 -0800 (PST) Received: from vultr.guest ([149.248.19.67]) by smtp.gmail.com with ESMTPSA id s20-20020a056a00179400b004f709998d13sm7378598pfg.10.2022.03.08.05.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 05:11:23 -0800 (PST) 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, akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, guro@fb.com Cc: linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Yafang Shao Subject: [PATCH RFC 7/9] bpf: add BPF_MAP_RECHARGE syscall Date: Tue, 8 Mar 2022 13:10:54 +0000 Message-Id: <20220308131056.6732-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220308131056.6732-1-laoar.shao@gmail.com> References: <20220308131056.6732-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6E6BAC0007 X-Stat-Signature: 3njedn16p6g5ndx96ez1r1749kyuxdss Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SiVmiDuO; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-HE-Tag: 1646745087-473895 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: This patch adds a new bpf syscall BPF_MAP_RECHARGE, which means to recharge the allocated memory of a bpf map from an offline memcg to the current memcg. The recharge methord for each map will be implemented in the follow-up patches. Signed-off-by: Yafang Shao --- include/linux/bpf.h | 2 ++ include/uapi/linux/bpf.h | 9 +++++++++ kernel/bpf/syscall.c | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 88449fb..fca274e 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -147,6 +147,8 @@ struct bpf_map_ops { bpf_callback_t callback_fn, void *callback_ctx, u64 flags); + bool (*map_recharge_memcg)(struct bpf_map *map); + /* BTF name and id of struct allocated by map_alloc */ const char * const map_btf_name; int *map_btf_id; diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index a448b06..290ea67 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -821,6 +821,14 @@ struct bpf_cgroup_storage_key { * Returns zero on success. On error, -1 is returned and *errno* * is set appropriately. * + * BPF_MAP_RECHARGE + * Description + * Recharge bpf memory from an offline memcg + * + * Return + * Returns zero on success. On error, -1 is returned and *errno* + * is set appropriately. + * * NOTES * eBPF objects (maps and programs) can be shared between processes. * @@ -875,6 +883,7 @@ enum bpf_cmd { BPF_ITER_CREATE, BPF_LINK_DETACH, BPF_PROG_BIND_MAP, + BPF_MAP_RECHARGE, }; enum bpf_map_type { diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 68fea3b..85456f1 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1128,7 +1128,6 @@ static int map_lookup_elem(union bpf_attr *attr) return err; } - #define BPF_MAP_UPDATE_ELEM_LAST_FIELD flags static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr) @@ -4621,6 +4620,21 @@ static int bpf_prog_bind_map(union bpf_attr *attr) return ret; } +static int map_recharge_elem(union bpf_attr *attr) +{ + int id = attr->map_id; + struct bpf_map *map; + + map = bpf_map_idr_find(id); + if (IS_ERR(map)) + return PTR_ERR(map); + + if (map->ops->map_recharge_memcg) + map->ops->map_recharge_memcg(map); + + return 0; +} + static int __sys_bpf(int cmd, bpfptr_t uattr, unsigned int size) { union bpf_attr attr; @@ -4757,6 +4771,9 @@ static int __sys_bpf(int cmd, bpfptr_t uattr, unsigned int size) case BPF_PROG_BIND_MAP: err = bpf_prog_bind_map(&attr); break; + case BPF_MAP_RECHARGE: + err = map_recharge_elem(&attr); + break; default: err = -EINVAL; break;