From patchwork Sun Jun 19 15:50:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12886761 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 40C5BC43334 for ; Sun, 19 Jun 2022 15:51:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD3588D000E; Sun, 19 Jun 2022 11:51:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5C418D0006; Sun, 19 Jun 2022 11:51:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAEF48D000E; Sun, 19 Jun 2022 11:51:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 98BD08D0006 for ; Sun, 19 Jun 2022 11:51:02 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 736F03461F for ; Sun, 19 Jun 2022 15:51:02 +0000 (UTC) X-FDA: 79595423964.24.6EF6508 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf26.hostedemail.com (Postfix) with ESMTP id 1E935140096 for ; Sun, 19 Jun 2022 15:51:01 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id k5-20020a17090a404500b001e8875e6242so8109923pjg.5 for ; Sun, 19 Jun 2022 08:51:01 -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=cwCrlHiRqBK3TQXbqbFOzQOTzh9qCJzbmrIFhJw7nPY=; b=gG5XX7PqlXa2X73375TmgCa4Z4pHjtha1wTFLorvCMGCCG36m1IsgvAHVnj/+kxo0i bWjyjchH3NmfZsW8qb5crT1xlS7txgjFZBq6XHUtzm5v7+d5b1Jfe7SBqP3xa2NivqE3 F7nM5p8L3hCk7zsN+8OlXjO49kBQox6Pjc22I8Nfqgo9hUW/SzxD8+SCypdijeEFIQcz 9zyiIDcWGRXH1RgYtszLyCKiIQZRixcRQZs+NkJIGA8ynrZxUXI3prYBc1yQQlqwKI3v sYHP1GcXC93i3jEvjKVjPrOrB8b6Ukbxq90/8tq+kV1wG7hFeFgZ7l+K62H6HbTNaP9u PXdg== 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=cwCrlHiRqBK3TQXbqbFOzQOTzh9qCJzbmrIFhJw7nPY=; b=IxL4/oJAOv59e8CGcemNUszGPYN6S2g57GIE67sIJxxEdUKcKht13cmffHmwEyUxT6 CnEdeh2g9sJaxsyCer3mNisK6HfGZVZf2Kk/lqSMpO+uukGOyaaHgrjgCt7i403iwdPN mVBa0M9MFIoy+7JQuLIxRVR901g/E9Mfb9sIIt7nAdfOZjv1EMJpAKPWxyoUSffRV62w 3vgiS4K+bUibKQXGyWXV+LqCVQ9VyB+9ARXPGW4Uw9ADXOMmZm7Ulg1lfsKArs5FM25m PRGI5O7xL6edUd/m5XvIc6F3JZgy7k7gEV0/mokJU7mlia6vuQO2L1YrNran52tkXl6Y Ibrw== X-Gm-Message-State: AJIora/2UZC2NOX1sNdrI/Iq27NS9CNAOtaDeTRKVSxz9rcsZB1s6+qY x3pbTngbSFTPS4gywZyqox4= X-Google-Smtp-Source: AGRyM1vAxtpulJ0ehxCQm0vNdQXfcu7UMbEBF0DvHPLPdUMcTffedr4blykuzh6+o2/NsoGPcNcR7w== X-Received: by 2002:a17:90a:408f:b0:1d1:d1ba:2abb with SMTP id l15-20020a17090a408f00b001d1d1ba2abbmr32595817pjg.152.1655653861217; Sun, 19 Jun 2022 08:51:01 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:2b24:5400:4ff:fe09:b144]) by smtp.gmail.com with ESMTPSA id z10-20020a1709027e8a00b001690a7df347sm6381761pla.96.2022.06.19.08.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jun 2022 08:51:00 -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, quentin@isovalent.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, songmuchun@bytedance.com, akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz Cc: linux-mm@kvack.org, bpf@vger.kernel.org, Yafang Shao Subject: [RFC PATCH bpf-next 09/10] bpf: Make bpf_map_{save, release}_memcg public Date: Sun, 19 Jun 2022 15:50:31 +0000 Message-Id: <20220619155032.32515-10-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220619155032.32515-1-laoar.shao@gmail.com> References: <20220619155032.32515-1-laoar.shao@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655653862; a=rsa-sha256; cv=none; b=PWkHdgYOB+aJv9IfHMz9IV01bNftexWLXC16wVymtKVVHk1pQ4M55vgIGb6TkWgZvwbgoB XhVGbNK5Tpcy34BdwhYYYx1gfvD1aR+EpDrLQ0eVpJAUZq0+SCLCpzY1GHuPCJ+UzVqgoF iO3a3/anpdZLBhAUWdBJCGo9++FhBL8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gG5XX7Pq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655653862; 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=cwCrlHiRqBK3TQXbqbFOzQOTzh9qCJzbmrIFhJw7nPY=; b=klgpj4sxmrtKwfA4pxylJWvlrm8J3ltazW7HAXZZEwpD6bZjGh1fu9FKwlgwoDI/+ewvUL rDS/r5jF86P6Y13VvwxM0axe71YiRdxZc7i5HSQ51pjRM9uFW+ZvwthoGqFmN4f1fMQIN3 WRxgctBLrRygq12ycLOgF6NPb3Zs9LM= X-Rspamd-Queue-Id: 1E935140096 X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gG5XX7Pq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-Rspamd-Server: rspam06 X-Stat-Signature: ndjdtq8ia4eaa5u7kmcjawepsubpxj64 X-HE-Tag: 1655653861-184825 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: These two helpers will be used in map specific files later. Signed-off-by: Yafang Shao --- include/linux/bpf.h | 21 +++++++++++++++++++++ kernel/bpf/syscall.c | 19 ------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index b18a30e70507..a0f21d4382ff 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -27,6 +27,7 @@ #include #include #include +#include struct bpf_verifier_env; struct bpf_verifier_log; @@ -248,6 +249,26 @@ struct bpf_map { bool frozen; /* write-once; write-protected by freeze_mutex */ }; +#ifdef CONFIG_MEMCG_KMEM +static inline void bpf_map_save_memcg(struct bpf_map *map) +{ + map->memcg = get_mem_cgroup_from_mm(current->mm); +} + +static inline void bpf_map_release_memcg(struct bpf_map *map) +{ + mem_cgroup_put(map->memcg); +} +#else +static inline void bpf_map_save_memcg(struct bpf_map *map) +{ +} + +static inline void bpf_map_release_memcg(struct bpf_map *map) +{ +} +#endif + static inline bool map_value_has_spin_lock(const struct bpf_map *map) { return map->spin_lock_off >= 0; diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 8817c40275f3..5159b97d1064 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -417,16 +417,6 @@ void bpf_map_free_id(struct bpf_map *map, bool do_idr_lock) } #ifdef CONFIG_MEMCG_KMEM -static void bpf_map_save_memcg(struct bpf_map *map) -{ - map->memcg = get_mem_cgroup_from_mm(current->mm); -} - -static void bpf_map_release_memcg(struct bpf_map *map) -{ - mem_cgroup_put(map->memcg); -} - void *bpf_map_kmalloc_node(const struct bpf_map *map, size_t size, gfp_t flags, int node) { @@ -464,15 +454,6 @@ void __percpu *bpf_map_alloc_percpu(const struct bpf_map *map, size_t size, return ptr; } - -#else -static void bpf_map_save_memcg(struct bpf_map *map) -{ -} - -static void bpf_map_release_memcg(struct bpf_map *map) -{ -} #endif static int bpf_map_kptr_off_cmp(const void *a, const void *b)