Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp55649pxh; Thu, 7 Apr 2022 13:49:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTD1Cn2REW+s9mg1XUheM7NTuRg6iueroWMaDejW6GLvBarsyC3FLet9aTGBYl3rWeRtP+ X-Received: by 2002:a17:90a:d0c5:b0:1c9:ec78:18e5 with SMTP id y5-20020a17090ad0c500b001c9ec7818e5mr17943472pjw.53.1649364584484; Thu, 07 Apr 2022 13:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649364584; cv=none; d=google.com; s=arc-20160816; b=V/LnVRRaL8Tf7s1j1aV1dhEB3SBNuD2+cii6e/qQxfku50sLB0nMpENRpff7n6Xm8C BL5SHbNo6u4Jnk7XE3jJdzAGCG6W7zz8ZP/h7wNAdwp8XzmIwXl/XPVmyzNMb6PAhXb3 zdEJDnygeR7grtI+nzU9M94gBUClhpzpmKDpUnbCyqh/ksc4amXbtPRQ8nrresrG1k/l zWHSIQtNFLiMnqRJnJwSr3wkGGsKDLMxr0xPkJh3sU0CD7dbgEbyNxLzxnG27GgD/1ap w5bk6AOw4hzFmz9OYb5ApGIjutI6ScPKmBdX1ADIq394OAay+M2q2gfO1F2d8Eb6hw2f pKVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=eyzEQI5WafpsISoL+TbuWgHkTeRTUB3yFRqImZRg+t4=; b=ozn7WftvygpvJI66enGMhVM6Sw0VtFDV7lgreTYSkssCTtcB2p1Is46v0zXiXCJLCi +wyoUCk4hklYnFmBkwqQgSnCi7SgGV+jHhzSRWsCC9lsW2nSUKjREPXwDFTF/7nikjVA EqpDf/ruM2GLTuhRMnUZY0+i1pdCwS8ZHFxML8NVeccLdPgrLgoGaHoT4UzODa5ETGGj qdrzuQo4zNGKjl6YzF+M8IGRZ4vIYgY5etA7frgUWUgqgm5pIk6K+V1fzqu/2iHoXUhW hurmjqpfquPdQC5LUVT3DlaYJ3AijEncBM+dpzruiuiGa3Ch+ctFQkLXr4Y/Us4PEmV1 WrUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bzE4SJTz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f184-20020a636ac1000000b003816043eef7si18569203pgc.236.2022.04.07.13.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:49:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bzE4SJTz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 81BD33E7C6B; Thu, 7 Apr 2022 12:56:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343493AbiDGNHV (ORCPT + 99 others); Thu, 7 Apr 2022 09:07:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbiDGNHS (ORCPT ); Thu, 7 Apr 2022 09:07:18 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44BDA48E73; Thu, 7 Apr 2022 06:05:18 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id h5so3954872pgc.7; Thu, 07 Apr 2022 06:05:18 -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:mime-version :content-transfer-encoding; bh=eyzEQI5WafpsISoL+TbuWgHkTeRTUB3yFRqImZRg+t4=; b=bzE4SJTzgtFCRXJ2TFUc7i2rHca5hXZZdPRDM4OBRmn1oFmJOIBXt/EQnH0L7t+GMQ Tec1XYCZXzD2FYZOnoT2R1wd7+FIJqcMlcLu+ABPlZ1hZi0Tgurz9umXAbg9I8V5gM/v lbwldi9lD3QWK/gAlbmzIvqdPlxoFgN2ZKoWovxY410ASjJlzeD8JUBu2RAUO/n3Tuv6 Ik7Dy7afhSZSRXFdnYPK4+yGxEVqRZ9qglMEx/0b3tZTCF5CAPq82JEdRSYbgp/UIn5D QGYNcE/TKvJhJRMg0nUoRZWjAwxylrlYiBVR9iDTKm8TNflInc+EeWmEbOk9UjdnkMT7 pICg== 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:mime-version :content-transfer-encoding; bh=eyzEQI5WafpsISoL+TbuWgHkTeRTUB3yFRqImZRg+t4=; b=EbvXjbiz8LSCOP0kK/67QJTZzlIIOBSSRPJDwJ1vdvpsxnF5r/b+uAXXOQypAbd4Hl U9SLqU2VdDeezkTJjgqEiSGdlS9nJTLp3aF4nqUIDyRAF1SiPSH/k+bExN+IY4j6lqwM zhI+sQp+cW+GsBSpBPLyEo8eu1BQnMEtR9EHSR3+KwcSKCXKF7oMlhMBHZWy6H+jcMJB PytwM97C1E5ZyLWBK2G8/NSXSFXWZG9+znIja4JqBTFuBWvrqsG+TA6cC2HhofimiqR/ dUnmItreJotR1uzqgxGdrpXW6G7aYQYYN8kipl5z2c71FU7aI75IUmPTq7KIbvKYKYja QYXA== X-Gm-Message-State: AOAM532pNog0d88UVW6ATet64bZu6YEgvKl0KYALp8FFBoUnXykcNMm2 uWsxNr2/uhmo+NTbAdsbAac= X-Received: by 2002:a05:6a00:1252:b0:4fa:afcc:7d24 with SMTP id u18-20020a056a00125200b004faafcc7d24mr13960745pfi.85.1649336717708; Thu, 07 Apr 2022 06:05:17 -0700 (PDT) Received: from localhost.localdomain ([43.132.141.3]) by smtp.gmail.com with ESMTPSA id j18-20020a056a00235200b004faabd8d2f2sm22714534pfj.192.2022.04.07.06.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 06:05:16 -0700 (PDT) From: Yuntao Wang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Roman Gushchin , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH bpf-next] bpf: Fix excessive memory allocation in stack_map_alloc() Date: Thu, 7 Apr 2022 21:04:23 +0800 Message-Id: <20220407130423.798386-1-ytcoode@gmail.com> X-Mailer: git-send-email 2.35.0.rc2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The 'n_buckets * (value_size + sizeof(struct stack_map_bucket))' part of the allocated memory for 'smap' is never used, get rid of it. Fixes: b936ca643ade ("bpf: rework memlock-based memory accounting for maps") Signed-off-by: Yuntao Wang --- kernel/bpf/stackmap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index 6131b4a19572..1dd5266fbebb 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -100,7 +100,6 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr) return ERR_PTR(-E2BIG); cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap); - cost += n_buckets * (value_size + sizeof(struct stack_map_bucket)); smap = bpf_map_area_alloc(cost, bpf_map_attr_numa_node(attr)); if (!smap) return ERR_PTR(-ENOMEM); -- 2.35.0.rc2