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=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 0ACD6CA9EC0 for ; Mon, 28 Oct 2019 17:55:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8B6D214E0 for ; Mon, 28 Oct 2019 17:55:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="oSy+4rOh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731262AbfJ1RzN (ORCPT ); Mon, 28 Oct 2019 13:55:13 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42691 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730978AbfJ1RzN (ORCPT ); Mon, 28 Oct 2019 13:55:13 -0400 Received: by mail-pg1-f193.google.com with SMTP id f14so7376808pgi.9 for ; Mon, 28 Oct 2019 10:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=XzpTan8+i3B861bOkzCgxWVBcpdZyq9MdPABjYUZBgQ=; b=oSy+4rOh8KWTH/gIyqSaytcg7to4HP8L8rh7yGFyrKygpn7vuTWG1Y4quilc3aX4dW Quq+GiHWZ1SiV3QId+vN6XMHjSJsmTnwsvdsvp/zAPO9ELfFpHyj6yZZpJNSfym+NVgw HzSvO5YaC9G6UiBFjUsIQ6dw70Ujc+c8gGusIZp94sB4exmhtoOb9URSq1Dx/RfOPFEs a9bD12RsLVBhYkRmFwEyZDi6xkiwKshdO5lYIhI7SmGlL7S/NahyCgXZF0EzZ9F71L3q oWqiDkaVJUtS9jf6otdaODvMAhqRD3INHQ8qey5joUdm8UfFYeu3t3TpgYlcKoKImkjU KaRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=XzpTan8+i3B861bOkzCgxWVBcpdZyq9MdPABjYUZBgQ=; b=TP8N9r+onJI/SHNNg6pigQ5roCP+5hu0VsBpGTXT8Hj5CRlr0pX/q6+nrDzkqo3Ped salgwhDJHNLzUrpoNUnfTlAVCmaVZvhGawFp270onxOXh4zJA25s0ExE5MN52n62/nTW as7qWITnF9ioTNB0cs1rdO7YdD/gGc74RA97swnGZPCecYhlSdXKe975fEfGgdld8OQH GhR0NnI9q8xW7k+VteiA/prFhEHNAVBZ9jqbGWSkDHITs0XUrkhcwiuEnnYlpekZ9+LY HY36egb40+uNFyFQbI6Ga+Dnbnk703M/+Y/hLwRGLQPS7I76W522AjV1r3QZCu6aJXNy TkOg== X-Gm-Message-State: APjAAAVCWwS7mXfagTm38+dZ2NvqN5Tx9r7L8pkZjGelCIlDIh4Ir7cc XgLLIWOXlfq1NXjOnp6fG7nvvQ== X-Google-Smtp-Source: APXvYqw9h0io44UIDPb6BEpXUzgy/w877Ppb+p+ryUkh+wd7UWlExOeW5pyTQArXeU2xjBzv2aqfKQ== X-Received: by 2002:aa7:9295:: with SMTP id j21mr22355815pfa.223.1572285312139; Mon, 28 Oct 2019 10:55:12 -0700 (PDT) Received: from cakuba.hsd1.ca.comcast.net ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id w27sm9763868pgc.20.2019.10.28.10.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 10:55:11 -0700 (PDT) Date: Mon, 28 Oct 2019 10:55:08 -0700 From: Jakub Kicinski To: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= Cc: netdev@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , bpf@vger.kernel.org, magnus.karlsson@gmail.com, magnus.karlsson@intel.com, maciej.fijalkowski@intel.com, toke@redhat.com Subject: Re: [PATCH bpf-next v2 1/2] xsk: store struct xdp_sock as a flexible array member of the XSKMAP Message-ID: <20191028105508.4173bf8b@cakuba.hsd1.ca.comcast.net> In-Reply-To: <20191025071842.7724-2-bjorn.topel@gmail.com> References: <20191025071842.7724-1-bjorn.topel@gmail.com> <20191025071842.7724-2-bjorn.topel@gmail.com> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Fri, 25 Oct 2019 09:18:40 +0200, Bj=C3=B6rn T=C3=B6pel wrote: > From: Bj=C3=B6rn T=C3=B6pel >=20 > Prior this commit, the array storing XDP socket instances were stored > in a separate allocated array of the XSKMAP. Now, we store the sockets > as a flexible array member in a similar fashion as the arraymap. Doing > so, we do less pointer chasing in the lookup. >=20 > Signed-off-by: Bj=C3=B6rn T=C3=B6pel Thanks for the re-spin. > diff --git a/kernel/bpf/xskmap.c b/kernel/bpf/xskmap.c > index 82a1ffe15dfa..a83e92fe2971 100644 > --- a/kernel/bpf/xskmap.c > +++ b/kernel/bpf/xskmap.c > @@ -92,44 +93,35 @@ static struct bpf_map *xsk_map_alloc(union bpf_attr *= attr) > attr->map_flags & ~(BPF_F_NUMA_NODE | BPF_F_RDONLY | BPF_F_WRONLY)) > return ERR_PTR(-EINVAL); > =20 > - m =3D kzalloc(sizeof(*m), GFP_USER); > - if (!m) > + numa_node =3D bpf_map_attr_numa_node(attr); > + size =3D struct_size(m, xsk_map, attr->max_entries); > + cost =3D size + array_size(sizeof(*m->flush_list), num_possible_cpus()); Now we didn't use array_size() previously because the sum here may overflow. We could use __ab_c_size() here, the name is probably too ugly to use directly and IDK what we'd have to name such a accumulation helper... So maybe just make cost and size a u64 and we should be in the clear. > + err =3D bpf_map_charge_init(&mem, cost); > + if (err < 0) > + return ERR_PTR(err); > + > + m =3D bpf_map_area_alloc(size, numa_node); > + if (!m) { > + bpf_map_charge_finish(&mem); > return ERR_PTR(-ENOMEM); > + } > =20 > bpf_map_init_from_attr(&m->map, attr); > + bpf_map_charge_move(&m->map.memory, &mem); > spin_lock_init(&m->lock); > =20 > - cost =3D (u64)m->map.max_entries * sizeof(struct xdp_sock *); > - cost +=3D sizeof(struct list_head) * num_possible_cpus(); > - > - /* Notice returns -EPERM on if map size is larger than memlock limit */ > - err =3D bpf_map_charge_init(&m->map.memory, cost); > - if (err) > - goto free_m; > - > - err =3D -ENOMEM; > - > m->flush_list =3D alloc_percpu(struct list_head); > - if (!m->flush_list) > - goto free_charge; > + if (!m->flush_list) { > + bpf_map_charge_finish(&m->map.memory); > + bpf_map_area_free(m); > + return ERR_PTR(-ENOMEM); > + } > =20 > for_each_possible_cpu(cpu) > INIT_LIST_HEAD(per_cpu_ptr(m->flush_list, cpu)); > =20 > - m->xsk_map =3D bpf_map_area_alloc(m->map.max_entries * > - sizeof(struct xdp_sock *), > - m->map.numa_node); > - if (!m->xsk_map) > - goto free_percpu; > return &m->map; > - > -free_percpu: > - free_percpu(m->flush_list); > -free_charge: > - bpf_map_charge_finish(&m->map.memory); > -free_m: > - kfree(m); > - return ERR_PTR(err); > } > =20 > static void xsk_map_free(struct bpf_map *map)