Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp392013pxu; Tue, 1 Dec 2020 14:03:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJxEecLmevIkpBR4NAqKbSE75+xFL6joJQD8o+FOo8dYdWKmpTuTk+GvF8GHiaqJoLx4vkvu X-Received: by 2002:a05:6402:1593:: with SMTP id c19mr5402997edv.269.1606860212492; Tue, 01 Dec 2020 14:03:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606860212; cv=none; d=google.com; s=arc-20160816; b=jp1tMyNjmvtLnXwhQVGekUNaByHm2r+Cz1IPVaM/QPivfgGsikvIzRSuMmKnAWKqnL kUhluuuHEtGYkH1xRByOkdqIHCRnvYKcTIoiMR3gFQ28D0idSajgx4xEfEdFV97htogb zlK6vl2TIErvt2cfnIqgTY3aEvGeDO45vdVHrkDnRrISNC7RNQnxGGZr+MThMrLyjfsn O5cX88UIdruUEpNic7rlmvG467VGmDAK71WhWz/5s5TpcctREmOug5nb1bLHpfK+YkXA 2kiE3bE38IN69h4jOmHeygLeJV1fBc87ldan4SMQQ45UCEZy7quRUaTFtfTBV1VASjyS q1CQ== 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=uCllWrpna2fyGfEQPGgVF85fW7DA3k55lJW1gO0QKWU=; b=ZR77xeQCPQpL12zcFsbIAf9V2FsVkrMYCW9QNquFywIXR9jPu2BCFfqc0o2ofRCKzu TNi9KfjXPw32iErt3n5pL5MdUnUxyI7xLc/b2wgvGM43Bbe6G+abOZlsKZAVB9tbeoPf UFDZUXMAXM7BD3KcMpItCLSJwiSiEGJueaOUwGNvD6UUHjlmspCiU4OsTqBSK4V9yytz z1eMTTVGA70atR0GxB5MZ0XqEH9qI7cbjJK6i0CsBsG+1+K8nS4F/tM9W5FEsO2KVMfo hm41XIanMY0hh9uNdlOMCn/LCjvDeLh7woWETk9kwR6+vjTs5w/NfUbUtz7z70Xo9TFn rV1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=rFkRdYlE; 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 pg28si769967ejb.614.2020.12.01.14.03.09; Tue, 01 Dec 2020 14:03:32 -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=rFkRdYlE; 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 S2390956AbgLAWAC (ORCPT + 99 others); Tue, 1 Dec 2020 17:00:02 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:41216 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390304AbgLAV77 (ORCPT ); Tue, 1 Dec 2020 16:59:59 -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 0B1LnhbO006717 for ; Tue, 1 Dec 2020 13:59:18 -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=uCllWrpna2fyGfEQPGgVF85fW7DA3k55lJW1gO0QKWU=; b=rFkRdYlE+Y+8qvR1Tp5ML3LZgMOTpnNAha6eus+6oJqDZdoYmra3rUfBgSeeodhRgqf2 gxolWGQ4lhNdapjzwoqL8MRZIQ7DE5EzgYNAQyijqahFnCqsHJRsVaatKkigFnI5J8aw 7zMbf6xjtigAAwSecSoOuTyh8rR4ewqZF5Y= Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net with ESMTP id 355pr6kf7g-17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2020 13:59:18 -0800 Received: from intmgw001.41.prn1.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:21d::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:11 -0800 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id BEF8019702D4; Tue, 1 Dec 2020 13:59:06 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v9 27/34] bpf: eliminate rlimit-based memory accounting for bpf ringbuffer Date: Tue, 1 Dec 2020 13:58:53 -0800 Message-ID: <20201201215900.3569844-28-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=742 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: 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 8983a46f6580..f25b719ac786 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 @@ -131,7 +130,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); @@ -147,8 +146,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); @@ -170,26 +167,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