From patchwork Thu Jan 12 15:53:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13098272 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 6E46FC54EBD for ; Thu, 12 Jan 2023 15:53:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C79E68E000A; Thu, 12 Jan 2023 10:53:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB5B08E0001; Thu, 12 Jan 2023 10:53:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B9398E000A; Thu, 12 Jan 2023 10:53:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8127C8E0001 for ; Thu, 12 Jan 2023 10:53:47 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 39716160305 for ; Thu, 12 Jan 2023 15:53:47 +0000 (UTC) X-FDA: 80346592494.26.84ACF71 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by imf10.hostedemail.com (Postfix) with ESMTP id 86B32C000F for ; Thu, 12 Jan 2023 15:53:45 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=aU2Esvnu; spf=pass (imf10.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673538825; 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=E3K14TM0boLxDmRFoAT7RRQ6Ph6mAKiCi/aS411tfbA=; b=ofNO37a2GVKbTpW0obykx5eG5GnYVacAisLcarhSb/fEo/VJD6SNHrV5/AMa/GTNOFo3Zx lKtqdjRpiiDiqFLzJxkW0/PWI5smS3E2bosY1Rlvei5CAqSmo1jtayqt2G5jeaWi76hYnG Ed330DCjp9qKm2Ss20UC78qAFSvT2cc= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=aU2Esvnu; spf=pass (imf10.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.160.171 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=1673538825; a=rsa-sha256; cv=none; b=Qmy8m7fJhQn9FrBsg9/1se9B0j/gpWI2uV4wo3CPSk6iDJ4W2MAkK4ImL+nbTA/fxDawJ9 k8BgmM614xxvxcrDO6eqRZmmQTj9RpC4Jc1VIfqhQkXcArNCGd/iYCRfQEjby30W2Ozlc8 vFfKDHtvi+BBd4OMlp8oX0O7dt7EXdE= Received: by mail-qt1-f171.google.com with SMTP id x7so6685460qtv.13 for ; Thu, 12 Jan 2023 07:53:45 -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=E3K14TM0boLxDmRFoAT7RRQ6Ph6mAKiCi/aS411tfbA=; b=aU2EsvnuuPe3ZSnD50zuV9E4JG6cC0vrWHgi5vg4ikr91yqv2ZGfpwHTgtuioVbpBM yyzQKV9/BjIWz7exRjSTq4RarPTJ/Rlay11Cq2e4N063c8OsXOEaMwQ+s4OEoF4KoPch oWIcu/UkJwCVTSCFUjbild5uruartTUjGA2B+vrw7cJgwLrO1u6b2EFAn8IJTkNBc5OO UlJE64nia/i0LkkrFI92NE/BnSEWTF9cfEphiDZKIJzaE3S1HPXo98teauQs5sn57MMQ ceIE7gIKfpLLQKA7fWNK1yOatwIAlDmcEH49jqOD3eVtCUdCrdcwfOk8ScblBs3TJux0 xs7g== 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=E3K14TM0boLxDmRFoAT7RRQ6Ph6mAKiCi/aS411tfbA=; b=7S1FLAWmTMt2DTfscuDly3Ebe3GxHDP5kZHixUfdpzLmPefh8hvensAkWORtMOV3h3 LNM7HZ2HWeS568cVASimX3IM1yr/K3zenorla5nTESGX6Sp4PLQ20DNH5cmEQlLjIAJP 0etGORjW1+nCS7aNXwb7tl59XpJO8K8lo04hUyUzerN7Rlmjs3yg19+397C9FkirPlJv 4YbvUM38yHpeIN7pLjutFgK03fIkHW7d6fVpjzsi+0ulub/wMSqFwplPvWe0699u/5eB SuMa3LOWGWyyKyLpWDGsSNyHp+sYO1xT7Kly7uS2qJVMkpHA1n8wg6Tl533DscIJSevL eTAA== X-Gm-Message-State: AFqh2koyiaupbnx643LAM1IKsupZvxGUXPpagsukrFaAFoTDutD2LfCz zE1TtgLQqRu/OgyMhwMBDq4= X-Google-Smtp-Source: AMrXdXvViXPTwmFpafLglW8xYZpT4nbyGcr8EcVCNuoHszbaRFi7jBpgklWOBB6m5tYn5p20XICckQ== X-Received: by 2002:ac8:528c:0:b0:395:396f:a519 with SMTP id s12-20020ac8528c000000b00395396fa519mr101217124qtn.0.1673538824580; Thu, 12 Jan 2023 07:53:44 -0800 (PST) Received: from vultr.guest ([173.199.122.241]) by smtp.gmail.com with ESMTPSA id l17-20020ac848d1000000b003ab43dabfb1sm9280836qtr.55.2023.01.12.07.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 07:53:43 -0800 (PST) From: Yafang Shao To: 42.hyeyoo@gmail.com, vbabka@suse.cz, 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, roman.gushchin@linux.dev Cc: linux-mm@kvack.org, bpf@vger.kernel.org, Yafang Shao Subject: [RFC PATCH bpf-next v2 08/11] bpf: use bpf_map_kzalloc in arraymap Date: Thu, 12 Jan 2023 15:53:23 +0000 Message-Id: <20230112155326.26902-9-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230112155326.26902-1-laoar.shao@gmail.com> References: <20230112155326.26902-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 86B32C000F X-Stat-Signature: pzkitboj5oc5xogabuzp9cxaspbdrrbb X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1673538825-776751 X-HE-Meta: U2FsdGVkX1/9oxY/dZZvBIcxhu3f46J4CDXO4qW8oywsvZpqFRMYTz+tFJhJ1KfJRFb94mFv/ox4q5Sf1lm/i18d29R7qJ5MbrNW3r4kGZwcZD+61HCJD4bkyEsqKAAW2pd7L4O9ATw2EoJEu1ojYUKfBVrmIwa+FRcBK+RjZ4z+ZKwIgj1ZkLAu237g1R0pfwvAGgL6HDqDzuNcHlLa7zioQzL87ZirEmhCOjLIwBcYOcD05EIF9D88m1eUJslIw4gHq5kYBeWaGAsDFNmXnnOnhpUU6pUpqwXe6sCZwnccizhQL+1RlN8SmVfBjUuDCE7NeJgfr79liFlxnLv4EesrdHoKV1+I3FGb/2CYccIxSbKY8nVRfp56Xk/sEA7U8LPrlJFYLCqIkrbx0l08o3p5VgtF6SzbzmfST5yUT/TIFUWqAJyxDTfcgWeFTEmI18KC37MwdWZWSARzOsIRyfS9Rlh15MjtnUUbGLsPL3mEUEmRsJ5ZYl/qSVXA1SSen/Ax/1vxeuHO54Eohx7V/Vt9v5oAUrOaRwsN2W5oy8NDpgGqJ+rvOCO6mLVsARVzFXdDSlAKaXwJerZuzG0V4/mtrWd2MOpKrr4budTtxk/DChNTa6iGmCBUx1aWjGeRU5ZLEX4paSEtRTVbdzWocNUHR4BtfwkcdMWhPe0dgZIkrYuyjMsxJ8CCarFsO5wQOtPyMOY98FQAhiRL7hJYavw13aXzBpZ+pxPaJhg2HphZKO3eLqO9aIGjiP8K8+m6ekkTlfxMJvEIFxcgjLdyvQLR0XhsaiSbnVC0XIIKQ/pNPHqccxJlngGZBljQpu9hzbnw61rLtXRXqzecIWJ+xu2eDwzNMyO2ZyjX6yMru/u8AEwbE55DA3Z8fwK9+pBH9t5EyzbMk3dbdinf1OSSZtXkUhc6YTc03pQzIbuQVTguZNfp2Mx6SYVyhDaHv0CPs5TXStfCv3VqsMyW06G nUTU/Rku 2OxnXN9/NHiN7/xlmvfRAX/dIomvjn2VgpHau7nu2vbob4/fVM+8kJFmdysDgTa807K/8WSL9I8Lbx08jmNnKFXUM90Wz1VDD/HcE+BxBdohRuO10ZUhsAACTq5JgdTcSyHcjH3P+dWblfRiP3orZ7hYQKvpj6JuHu1g48yTzn0+gy8Yh37E8Povg6GTlECtjKMvMc+DU7Ne/fbh7ACAzlHen9EdphPGnQ41OjDJgxmYFenj+DxUK4A2uS51Aqn98wDRJEjx6IW//AodA9Enq2tp6k5trV1BDBd27 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: 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 4847069..e64a417 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;