From patchwork Mon Dec 12 00:37:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13070700 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 88951C4332F for ; Mon, 12 Dec 2022 00:38:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25B528E0002; Sun, 11 Dec 2022 19:38:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E303940007; Sun, 11 Dec 2022 19:38:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AA438E000A; Sun, 11 Dec 2022 19:38:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EF29C8E0002 for ; Sun, 11 Dec 2022 19:38:14 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C2931407CA for ; Mon, 12 Dec 2022 00:38:14 +0000 (UTC) X-FDA: 80231792508.02.C194F79 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf16.hostedemail.com (Postfix) with ESMTP id 27274180003 for ; Mon, 12 Dec 2022 00:38:12 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TWn91mBr; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.180 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=1670805493; 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=+Gn9WpBDEDaKUZZ8QU8b0wRBxnaqWXKyRBa/KIthXAc=; b=zDlhaf199X8IB0Sj/E9tmwV9Q3ahoZOVZr3LuAkKAv4ujVIXIwKVYozFP7ymxcbY5qdGUb UkE2ikvqM7LnI9nTq+8m6IsXPbwYdF0nA9E81hR46itdZIT4pKAC/mLDpiPZwc0J64FiXh EX45QHuKLd9nA5XSQ9KIDVym43PFu/I= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TWn91mBr; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670805493; a=rsa-sha256; cv=none; b=Yh7Mn97gi35dn4N+rxwnc8U/vCdU5VlQq0OpCGO3tCPFC0c/p+/jTtsibf0deWwJqVx0gi WQjJg22REjZKBjv9dQiH0C0Eh68Npdd3PmXmIkuNj2VZDh+8ZUIA/ROfuwKMBsulN4fhKA tDw5d9C0H/M6VUiNhm7i1M/Dlcs/B0w= Received: by mail-pl1-f180.google.com with SMTP id g10so10410712plo.11 for ; Sun, 11 Dec 2022 16:38:12 -0800 (PST) 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:subject:date :message-id:reply-to; bh=+Gn9WpBDEDaKUZZ8QU8b0wRBxnaqWXKyRBa/KIthXAc=; b=TWn91mBr7aKw/ejdDKR8YL7ViEiJcmwoPO13rsfGRzSRZE90vZVGrc6m64SxoME0rZ E9fh4oE0UPZADwjceaLGA4JaZzdz/IgvhYVJ9gkZbU1JRYUvBeN0VVWTtH9Aj110I2Tr 4fM0+PLVoB0u4oFlIsTnJqhY6GjykrCYTJW1LQaZ754Nr8tOqlv2pMi6C+kKF2+EIKno kHiEl3JnREg8e5EjK8s+1wLeoI9rT4QwKporT6WDsvXLGG3UZoLK8SJnszfUYecDX4VX kEpaWZ1S1SrCVl8ShKGHFUKaEAiSFq6nWM/byd0bd7dRnm2NTps4eMiA3pf3enuIC8qT 4edQ== 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 :subject:date:message-id:reply-to; bh=+Gn9WpBDEDaKUZZ8QU8b0wRBxnaqWXKyRBa/KIthXAc=; b=Ro7nnWFieWSjG8C9PcCmWBaQJLXYePYDuyESBePQ6s6PQ5Y4UnxNeCB4MkORCxFZG+ 3RvJ8oTvoYU93gdbzfPVBwtmRPCYuR7OMUw+W9fcoPWDZPjoyz0ZOdFsaKRSWnSeHiBT yfzgNnqT2g/HX/htVzNgTm8NhGmgsfEW396CZ3QYm/rGSrz4X+u1qZ4bGVQKkRX5YFLE ecyknSkhu2Rb9Bk+OoM6DIJYMiZmqX3Dqe5hrIVldhlw3l5OC40Est0jOqyjkBK5afdJ XpGNfvFND+NY2IZvbfF1v/pRjCyVmAizfFj7zSN8BBCdglzUTV8A0+vFmlMa7YTu2MrL Qj9w== X-Gm-Message-State: ANoB5plMpvUOHPdpPksCLiWwVcboyJ5gByGh0x8agNE9QVP1wRYyNHBA 6jjsYiPH8/YbNvenWOlOnw0= X-Google-Smtp-Source: AA0mqf4aXVqdAlSTQEp8cHa2whCkSMepIO+xNKgkOlasHFVjqEnA9uC4JbLlGFLM9jtxp3TZIyO5fg== X-Received: by 2002:a17:902:ed85:b0:185:441e:2d9f with SMTP id e5-20020a170902ed8500b00185441e2d9fmr12716619plj.54.1670805492169; Sun, 11 Dec 2022 16:38:12 -0800 (PST) Received: from vultr.guest ([2001:19f0:7002:8c7:5400:4ff:fe3d:656a]) by smtp.gmail.com with ESMTPSA id w9-20020a170902e88900b00177fb862a87sm4895960plg.20.2022.12.11.16.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Dec 2022 16:38:11 -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, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tj@kernel.org, dennis@kernel.org, cl@linux.com, akpm@linux-foundation.org, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com Cc: linux-mm@kvack.org, bpf@vger.kernel.org, Yafang Shao Subject: [RFC PATCH bpf-next 7/9] bpf: Use bpf_map_kzalloc in arraymap Date: Mon, 12 Dec 2022 00:37:09 +0000 Message-Id: <20221212003711.24977-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221212003711.24977-1-laoar.shao@gmail.com> References: <20221212003711.24977-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 27274180003 X-Stat-Signature: 31hatixqc859xtaurgm5ts3gcno4dct4 X-HE-Tag: 1670805492-658246 X-HE-Meta: U2FsdGVkX1/6fD3OZw5MltfqIY1mOy9TWZFdIj/JNIYFwZDiZdF9S6g9xdKKy9hbn+JR0I0qDZTVN2/oN3UIWDVkqEiY7vtkLuXdrHaQIDQkxwff6Rm71E4mKWdVP+pFbQwTzfTq6s3L9wRiWHAVsYsXnxkpXQ0mCwviD+5kpFY8TUAIdidqKS4SgITIrASytaErwsuU/PqTDuJC8UVmc+mGgOrigokNLdTJqGMEP9+BDZ0iYUkiMxhIyKTYo7XyoFBi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 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Allocates memory after map creation, then we can use the generic helper bpf_map_kzalloc() instead of the open-coded kzalloc(). Signed-off-by: Yafang Shao --- kernel/bpf/arraymap.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 484706959556..e64a4178d92d 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -1102,20 +1102,20 @@ static struct bpf_map *prog_array_map_alloc(union bpf_attr *attr) struct bpf_array_aux *aux; struct bpf_map *map; - aux = kzalloc(sizeof(*aux), GFP_KERNEL_ACCOUNT); - if (!aux) + map = array_map_alloc(attr); + if (IS_ERR(map)) return ERR_PTR(-ENOMEM); + aux = bpf_map_kzalloc(map, sizeof(*aux), GFP_KERNEL); + if (!aux) { + array_map_free(map); + return ERR_PTR(-ENOMEM); + } + INIT_WORK(&aux->work, prog_array_map_clear_deferred); INIT_LIST_HEAD(&aux->poke_progs); mutex_init(&aux->poke_mutex); - map = array_map_alloc(attr); - if (IS_ERR(map)) { - kfree(aux); - return map; - } - container_of(map, struct bpf_array, map)->aux = aux; aux->map = map;