Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp69620pxu; Tue, 24 Nov 2020 19:06:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJybHpnHitTG+NoP+p8sNZCnI/A4dynxDYzwB4vG9l1Jq2N6utRELN7kk0N2kcni5N11GFwO X-Received: by 2002:a17:906:138c:: with SMTP id f12mr1412844ejc.108.1606273571854; Tue, 24 Nov 2020 19:06:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606273571; cv=none; d=google.com; s=arc-20160816; b=bfZGh6IZtvAsQwJjnLBAHzL1eY/lJYvnqyI39ZBZSD/WSyZ3ihcDoAxkPBywK4h4iN J7GnQOtRIKkdRuMAaJ9hC/PO3H3lGFv+iIEnNvVn33dd27jHhX8MSLk7QD2qDHvtV1V/ dtXAgULsY93jnLZ6lQUZnCx8O3kHXhNE7moKFHzFDzrKM/QTb0HMD1w7+hasd8PCb2dB esXkKfm2mjx17/DAHtAxmd2XdzXL1eraLWmWu0QkjDr2nYv2l2/ep7QCas4vqT/LWUji wCpQZY1glLbjnK0DgFudzXyAcTOo2Nqbnt24kCY/8rDDzLn6qwf2K0hFIiguSlj96dk2 +l7g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5881LDsie8spgc0CJnGPZKzfQ93H94+qiosPyw2APzw=; b=Skh4Gzlq7pe184Tw/mQwyzH90frH3TJb66L8qn/r4zZNuEZ5pjIOYO2oScL+pMD/qP mBYA323OYhC6LKvZMLWGAMX1m5uWYmikQq7RSFkuEuEcx8Yzdd+J4ZEd8fXS3qZGSPbZ 5p6LvA/Zd2NrEFXSbMkSB//28BlxmxHBSdjLQnyUw0hF5Cxb8yEuXe+Ef2PLHsfQq4lw Lw//sumo0by06iNoTDd2BYB+lCY44jJ8a7CRRdrJVQkYQLh/7wN6uF2eFb5A1RUoZ+eO ICZNjxZ/ktu8hoNvRoIOvhvG9aSv4rGTAB9EyNee7ipvbJfKzGZqWCLyjfahgXOcEFHO x6zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=Fjyyog1e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si404207edj.143.2020.11.24.19.05.49; Tue, 24 Nov 2020 19:06:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=Fjyyog1e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728482AbgKYDDK (ORCPT + 99 others); Tue, 24 Nov 2020 22:03:10 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:64052 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727374AbgKYDBb (ORCPT ); Tue, 24 Nov 2020 22:01:31 -0500 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.42/8.16.0.42) with SMTP id 0AP2s9FA020697 for ; Tue, 24 Nov 2020 19:01:30 -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=5881LDsie8spgc0CJnGPZKzfQ93H94+qiosPyw2APzw=; b=Fjyyog1eLS4A+tZ77eRTE1SC3tfEHwHYu5rY9mZpyFJqgFaxvMIEot4uO7fpeDAj4D2t zjrLWSZm4i3oiOsF+hWCHNjGX5XUUpF4cLIQYO0eyKvm0lY7Bn0AJc84cG4WJ7piSGsx NDgu5h7x8jlj5uBTFXgpbTeofK88m7l8ChA= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net with ESMTP id 34yx1t31xu-11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 24 Nov 2020 19:01:30 -0800 Received: from intmgw001.41.prn1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 24 Nov 2020 19:01:27 -0800 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id 6DCFB16A18B9; Tue, 24 Nov 2020 19:01:22 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v8 28/34] bpf: eliminate rlimit-based memory accounting for sockmap and sockhash maps Date: Tue, 24 Nov 2020 19:01:13 -0800 Message-ID: <20201125030119.2864302-29-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201125030119.2864302-1-guro@fb.com> References: <20201125030119.2864302-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-11-24_11:2020-11-24,2020-11-24 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 phishscore=0 adultscore=0 bulkscore=0 suspectscore=38 spamscore=0 mlxlogscore=685 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011250018 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 3ff635af737a..310e57f65a00 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