From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48A6DC64E7A for ; Tue, 1 Dec 2020 22:01:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E370920870 for ; Tue, 1 Dec 2020 22:01:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="S6YBsLrC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728504AbgLAWBW (ORCPT ); Tue, 1 Dec 2020 17:01:22 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:35620 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390457AbgLAV76 (ORCPT ); Tue, 1 Dec 2020 16:59:58 -0500 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.42/8.16.0.42) with SMTP id 0B1Lnht3006701 for ; Tue, 1 Dec 2020 13:59:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=hlLdQOl7O5R2+aO31pnkoZ3O/8ltB7xcvlY8hk9+rtk=; b=S6YBsLrCv31Krpf3DeJOOI+w6nkl+VYy5Pw3VeTQ0NDCMBzjZxdVdXxMMl8P03GJjWzg Ih/bmXUg9QeYgQ6h5g0wyc+ufE7yBATu7aKmsz9FGh1if3LAU4S4SSc4dx0rOBbdv4lt 5qAs1AP1atUpBsxs+hNrJDJjuMRy+ZoV3uE= Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net with ESMTP id 355pr6kf7w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2020 13:59:16 -0800 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 1 Dec 2020 13:59:09 -0800 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id C409719702D6; Tue, 1 Dec 2020 13:59:06 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v9 28/34] bpf: eliminate rlimit-based memory accounting for sockmap and sockhash maps Date: Tue, 1 Dec 2020 13:58:54 -0800 Message-ID: <20201201215900.3569844-29-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201201215900.3569844-1-guro@fb.com> References: <20201201215900.3569844-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-12-01_11:2020-11-30,2020-12-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 malwarescore=0 priorityscore=1501 suspectscore=38 spamscore=0 adultscore=0 clxscore=1015 mlxlogscore=656 lowpriorityscore=0 mlxscore=0 phishscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010131 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Do not use rlimit-based memory accounting for sockmap and sockhash maps. It has been replaced with the memcg-based memory accounting. Signed-off-by: Roman Gushchin Acked-by: Song Liu --- net/core/sock_map.c | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/net/core/sock_map.c b/net/core/sock_map.c index 153652a582ee..64b5ec14ff50 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -27,8 +27,6 @@ struct bpf_stab { static struct bpf_map *sock_map_alloc(union bpf_attr *attr) { struct bpf_stab *stab; - u64 cost; - int err; =20 if (!capable(CAP_NET_ADMIN)) return ERR_PTR(-EPERM); @@ -46,22 +44,15 @@ static struct bpf_map *sock_map_alloc(union bpf_attr = *attr) bpf_map_init_from_attr(&stab->map, attr); raw_spin_lock_init(&stab->lock); =20 - /* Make sure page count doesn't overflow. */ - cost =3D (u64) stab->map.max_entries * sizeof(struct sock *); - err =3D bpf_map_charge_init(&stab->map.memory, cost); - if (err) - goto free_stab; - stab->sks =3D bpf_map_area_alloc(stab->map.max_entries * sizeof(struct sock *), stab->map.numa_node); - if (stab->sks) - return &stab->map; - err =3D -ENOMEM; - bpf_map_charge_finish(&stab->map.memory); -free_stab: - kfree(stab); - return ERR_PTR(err); + if (!stab->sks) { + kfree(stab); + return ERR_PTR(-ENOMEM); + } + + return &stab->map; } =20 int sock_map_get_from_fd(const union bpf_attr *attr, struct bpf_prog *pr= og) @@ -1104,7 +1095,6 @@ static struct bpf_map *sock_hash_alloc(union bpf_at= tr *attr) { struct bpf_shtab *htab; int i, err; - u64 cost; =20 if (!capable(CAP_NET_ADMIN)) return ERR_PTR(-EPERM); @@ -1132,21 +1122,10 @@ static struct bpf_map *sock_hash_alloc(union bpf_= attr *attr) goto free_htab; } =20 - cost =3D (u64) htab->buckets_num * sizeof(struct bpf_shtab_bucket) + - (u64) htab->elem_size * htab->map.max_entries; - if (cost >=3D U32_MAX - PAGE_SIZE) { - err =3D -EINVAL; - goto free_htab; - } - err =3D bpf_map_charge_init(&htab->map.memory, cost); - if (err) - goto free_htab; - htab->buckets =3D bpf_map_area_alloc(htab->buckets_num * sizeof(struct bpf_shtab_bucket), htab->map.numa_node); if (!htab->buckets) { - bpf_map_charge_finish(&htab->map.memory); err =3D -ENOMEM; goto free_htab; } --=20 2.26.2