Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3574129pxb; Mon, 16 Nov 2020 19:48:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJuGzwwNR9O9AmFN7h/4f2qr4zgtmnm6fPXtTYweTth6geUQs12Dp89rd8aJ8+Nj7mnsyS X-Received: by 2002:a17:906:b003:: with SMTP id v3mr18276800ejy.290.1605584896031; Mon, 16 Nov 2020 19:48:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605584896; cv=none; d=google.com; s=arc-20160816; b=NtctDz0whvogiP5Vvj7F3WX1oGUtqBnc2WyxC9+mVJ3jEZCc1iyvcfSPwkS2emkt2F sG3+U9h18Umll19JM8ICv8KsXXbn8VfynvooEzEhlv381vazX9RhHiqcfzvUbcM2p0JX 8F28E9zBz/0bIOof8aatBJD1AUL15JxQgK6T8vCmrxDqN7eiWZG/SI3bfeZaa/y/ManK HxgLFEZVHDnuTtj9XgxIAbQi1qbYCTMfAnk/Ova2BXb+/pU52DyoUNuKooGC/THQrkNx 6WCeTR1ateG2bolPTNE/AxdC7cZO098QcDN16M1Yk3uXyXy7vpnVlY0o0HGRpxXTNXwe 5Bsg== 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=qdqw2vIRlP2yIbod8BHIh3XnNn0ZSs325Y5RG0+0/sU=; b=k4FTXSjal1OvWruS8vLeEa0Z7UoN1iX4eCix5WCq8eokzubXPgjHPdyd4HLVcgIIWr gGbKUJMH9scnhv+lUTNvNx4c+iydnuOaDCkZ6qv6eD67v5Te2b9Z5P/bMl+7rNLk2XEV 8XELbNeoLIhiKK2dO+iXs5vbwXmScj1yhSvQyJ/o0xrxPvsj4h8ynfLgv96/7K88Iqn7 fez4VOQH4zYvjlLbeTLyH6vtN5VJFXNGb1FlmrVOrFuNwFL5Pc0Ipac261Ti1cH1ZCwt y9jexoznLkk8JoHZ3UKWKL+s8XtLWNg9GFayCquAZTQ98alW9BSBTFIUbemJqQqCujKw BpFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=g1lC1YWS; 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 d12si13999965edn.399.2020.11.16.19.47.53; Mon, 16 Nov 2020 19:48:16 -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=g1lC1YWS; 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 S1728049AbgKQDnW (ORCPT + 99 others); Mon, 16 Nov 2020 22:43:22 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:23558 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727013AbgKQDlS (ORCPT ); Mon, 16 Nov 2020 22:41:18 -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 0AH3cZv7024972 for ; Mon, 16 Nov 2020 19:41: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=qdqw2vIRlP2yIbod8BHIh3XnNn0ZSs325Y5RG0+0/sU=; b=g1lC1YWSbiryDoqP+wY9oOgmikGpRHewX/DGVOQK1EgoqEekmZ2lD8AltCgQB586esiO Ge43fbQPuqf2YPgUoNHa6tY6wKLZr4wU6cUcTH/ccohT+UkSc0Gb9KvWK9OqZgOJUILk Lg/xSatytn3U3XbIVZz8HBKkO8tJV3jg0tc= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net with ESMTP id 34tbssbt8r-15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 16 Nov 2020 19:41:17 -0800 Received: from intmgw003.06.prn3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 16 Nov 2020 19:41:14 -0800 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id 8BEDBC63A8D; Mon, 16 Nov 2020 19:41:10 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v6 27/34] bpf: eliminate rlimit-based memory accounting for bpf ringbuffer Date: Mon, 16 Nov 2020 19:41:01 -0800 Message-ID: <20201117034108.1186569-28-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201117034108.1186569-1-guro@fb.com> References: <20201117034108.1186569-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-17_01:2020-11-13,2020-11-17 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxscore=0 suspectscore=38 impostorscore=0 adultscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 mlxlogscore=744 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011170027 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do not use rlimit-based memory accounting for bpf ringbuffer. It has been replaced with the memcg-based memory accounting. bpf_ringbuf_alloc() can't return anything except ERR_PTR(-ENOMEM) and a valid pointer, so to simplify the code make it return NULL in the first case. This allows to drop a couple of lines in ringbuf_map_alloc() and also makes it look similar to other memory allocating function like kmalloc(). Signed-off-by: Roman Gushchin Acked-by: Song Liu Acked-by: Andrii Nakryiko --- kernel/bpf/ringbuf.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c index ee5f55d9276e..c8892b58501e 100644 --- a/kernel/bpf/ringbuf.c +++ b/kernel/bpf/ringbuf.c @@ -48,7 +48,6 @@ struct bpf_ringbuf { =20 struct bpf_ringbuf_map { struct bpf_map map; - struct bpf_map_memory memory; struct bpf_ringbuf *rb; }; =20 @@ -135,7 +134,7 @@ static struct bpf_ringbuf *bpf_ringbuf_alloc(size_t d= ata_sz, int numa_node) =20 rb =3D bpf_ringbuf_area_alloc(data_sz, numa_node); if (!rb) - return ERR_PTR(-ENOMEM); + return NULL; =20 spin_lock_init(&rb->spinlock); init_waitqueue_head(&rb->waitq); @@ -151,8 +150,6 @@ static struct bpf_ringbuf *bpf_ringbuf_alloc(size_t d= ata_sz, int numa_node) static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr) { struct bpf_ringbuf_map *rb_map; - u64 cost; - int err; =20 if (attr->map_flags & ~RINGBUF_CREATE_FLAG_MASK) return ERR_PTR(-EINVAL); @@ -174,26 +171,13 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_= attr *attr) =20 bpf_map_init_from_attr(&rb_map->map, attr); =20 - cost =3D sizeof(struct bpf_ringbuf_map) + - sizeof(struct bpf_ringbuf) + - attr->max_entries; - err =3D bpf_map_charge_init(&rb_map->map.memory, cost); - if (err) - goto err_free_map; - rb_map->rb =3D bpf_ringbuf_alloc(attr->max_entries, rb_map->map.numa_no= de); - if (IS_ERR(rb_map->rb)) { - err =3D PTR_ERR(rb_map->rb); - goto err_uncharge; + if (!rb_map->rb) { + kfree(rb_map); + return ERR_PTR(-ENOMEM); } =20 return &rb_map->map; - -err_uncharge: - bpf_map_charge_finish(&rb_map->map.memory); -err_free_map: - kfree(rb_map); - return ERR_PTR(err); } =20 static void bpf_ringbuf_free(struct bpf_ringbuf *rb) --=20 2.26.2