Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp37618ybg; Mon, 27 Jul 2020 22:38:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEMFgbY2ecqbMEziGvYh3hpZuVd+YVWNHirR5pqMkgWOSefKt+lSxbh0f+XDriox28JNXC X-Received: by 2002:a05:6402:1606:: with SMTP id f6mr5199515edv.328.1595914739062; Mon, 27 Jul 2020 22:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595914739; cv=none; d=google.com; s=arc-20160816; b=xGdpkpnq8zugH6vc7JzE0BBbqTMg4ZX4gixVSF1ModzTcpHpzuHOUlbNP+K0dfmKG6 stmSavtUXwiuHgIKKiFRo3JKoEaHURZgXtSSn+h7k18l2tZhKnRQHZ8Sgk25xxF9wXAD RNzwPag+YjMSynPy3/Fp8cNuxuj87rK7pCzuBvP3y0O2atHtptW9Htn2Xyif/kohWkpc Z5XlChqVQzTfCa8ZiLfvtYfgQuF9r03rpvVokFdwV2xf4rnAIwkuUqwpY7e0SRgp/mzB b/fVEC+JBGzuRxPU5xluAf9xts53t27Tlerypr8dVrhnb8YvzgY3aMpaxKPSDWJyb/4W 9f2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=k2Tkfd29QnTLRN0GMwxIk/E19sPFaLjLLzMQZciShAI=; b=e959AuFiXJR7PTviSfQuDN2Utw1LKzuJpgOhde8E2/zbTmtqtnJ2a4Cl1nw16uYwQA 7/0GjyCLUlRkQnMWsGfqy01zpn9w0+fajsrNI+ZkcWqikJ81O9RI4VRbYz7nKU6Mr0NE jPJk5ytM24sLfsP+6SuKowW+F+VRsjIRerYgqVT9HMzUfc7V0Cl8YBoLcnsIkP8ujG9h HSRTPmsDHyqQL/GqXSbBFJmwOyrdpZrsNX57aNbSNyXB5AEGyuHk8C0ILo9x3U12AgrL rksiKzjfSuSNukka/VGtTc7rSlTvp3Tgv54zwCLWAcCoUWl+jx3JXQltuFwVxvy0eSJ2 bRQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tcuyzm+2; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si3863429ejs.414.2020.07.27.22.38.37; Mon, 27 Jul 2020 22:38:59 -0700 (PDT) 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=@kernel.org header.s=default header.b=Tcuyzm+2; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgG1FiN (ORCPT + 99 others); Tue, 28 Jul 2020 01:38:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:44498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726251AbgG1FiM (ORCPT ); Tue, 28 Jul 2020 01:38:12 -0400 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6D07C21883; Tue, 28 Jul 2020 05:38:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595914691; bh=zQfvL6mXPDvArmEZLKk1wPWEFI4+SrGpgZSDfVmZNFs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Tcuyzm+2cHo8cqzgn5IkjaRedCAa+xOOR37u2+WM4RzbRDE15DgjXIFXKTcAMSwbk 0qT5pZkgRi6oftYCYDhCjzLK9BlDa3lZnHMDgLDaWE3w9+7qBgQM7M5DYXsdMOu24y 3GadVfWBSnrowvG6sBN+LbnUvEB3ivgJJveMv1t8= Received: by mail-lj1-f179.google.com with SMTP id g6so7140451ljn.11; Mon, 27 Jul 2020 22:38:11 -0700 (PDT) X-Gm-Message-State: AOAM5329Bnz9KAXPT1LS4BWXV2P9tOQIW4dhm10FozQSDE+AVsAMHzH5 6hDFUgwi3gKdLhKlYKiRE0kK9MQV1nKtGNEaYWA= X-Received: by 2002:a05:651c:1349:: with SMTP id j9mr4580894ljb.392.1595914689684; Mon, 27 Jul 2020 22:38:09 -0700 (PDT) MIME-Version: 1.0 References: <20200727184506.2279656-1-guro@fb.com> <20200727184506.2279656-24-guro@fb.com> In-Reply-To: <20200727184506.2279656-24-guro@fb.com> From: Song Liu Date: Mon, 27 Jul 2020 22:37:58 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v2 23/35] bpf: eliminate rlimit-based memory accounting for sockmap and sockhash maps To: Roman Gushchin Cc: bpf , Networking , Alexei Starovoitov , Daniel Borkmann , Kernel Team , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 27, 2020 at 12:21 PM Roman Gushchin wrote: > > 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 bc797adca44c..07c90baf8db1 100644 > --- a/net/core/sock_map.c > +++ b/net/core/sock_map.c > @@ -26,8 +26,6 @@ struct bpf_stab { > static struct bpf_map *sock_map_alloc(union bpf_attr *attr) > { > struct bpf_stab *stab; > - u64 cost; > - int err; > > if (!capable(CAP_NET_ADMIN)) > return ERR_PTR(-EPERM); > @@ -45,22 +43,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); > > - /* Make sure page count doesn't overflow. */ > - cost = (u64) stab->map.max_entries * sizeof(struct sock *); > - err = bpf_map_charge_init(&stab->map.memory, cost); > - if (err) > - goto free_stab; > - > stab->sks = bpf_map_area_alloc(stab->map.max_entries * > sizeof(struct sock *), > stab->map.numa_node); > - if (stab->sks) > - return &stab->map; > - err = -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; > } > > int sock_map_get_from_fd(const union bpf_attr *attr, struct bpf_prog *prog) > @@ -999,7 +990,6 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr) > { > struct bpf_shtab *htab; > int i, err; > - u64 cost; > > if (!capable(CAP_NET_ADMIN)) > return ERR_PTR(-EPERM); > @@ -1027,21 +1017,10 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr) > goto free_htab; > } > > - cost = (u64) htab->buckets_num * sizeof(struct bpf_shtab_bucket) + > - (u64) htab->elem_size * htab->map.max_entries; > - if (cost >= U32_MAX - PAGE_SIZE) { > - err = -EINVAL; > - goto free_htab; > - } > - err = bpf_map_charge_init(&htab->map.memory, cost); > - if (err) > - goto free_htab; > - > htab->buckets = 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 = -ENOMEM; > goto free_htab; > } > -- > 2.26.2 >