Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9999483ybi; Wed, 24 Jul 2019 13:54:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoBEmIgtnMGXfY07NqPQfEHH98H6WG6PDGMCfSjUKvHyaS0Z5X+mMuDCM0eC7iZo8fRszE X-Received: by 2002:a17:902:1aa:: with SMTP id b39mr39316404plb.333.1564001642782; Wed, 24 Jul 2019 13:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564001642; cv=none; d=google.com; s=arc-20160816; b=yOTV0SWWBqUtvmhwY0V9ZQmL8rI7iIUSuQwsZyKrIe5uahqiDkt0ugprCvGjRDBkfA y1v7/GJ8ufGAGJVk4TXcwXfY+5KOX75MnlarS6V3Ux4RVI4wH+eYQAt7SD8c//d9YVAa Ax9c+43q0HdwRsM+dof/jZu30qn9AaHn9T4FSmcxPPFrVlnMtXnZzkXTqif0fS2Gj/ly 8eB7SMJHfFSoU5wWhZfviSq3nG09sAauQwo0CuYTRlGwtpUek5hUEjkPKWzxqNpELL0g gDSu+4XVO7a6vqUOT9qybGFX2P43B8wr0nYf3JSrPZw/ubF2uNcMsR67AvjJBFv+TeBW NOgA== 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=K5EpkRFFvgeAt0nL+hNBcZ+U2NkFxnbvcSf3cki+3DA=; b=E5fCS+dCvKEJ0tWjLVut52pvs+XUL52FOEiouwlVAbu8sHWW8OBh4DDs9q1UmnpsFH IxrIQ1bIJ65JpDb2vlTXH6xHYxN68OuTKu/xmfEvR1tydQLyShN75VHmjV+JV+Vd21wY ZOCpU5lJTzJfm2w4+W3iym/l0zXuLKOfGuz9d6Cdcad1V+YxCc5CMnPFqITTKsqERYFX +XfB1FVpNkk+lxSbqVYaBdgO7YNXKH5pNYDWScb/OBgbTV1cJXOR7mr43KWL4YatM/XJ ruaGagiQPWLe9AsVipVMG0phLqLPDfVVCJC8z77ofGekJuRb7tPAp0yPVOJdpkKYkCYn fRBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PO7hinLF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j5si17622735pgi.181.2019.07.24.13.53.47; Wed, 24 Jul 2019 13:54:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PO7hinLF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727994AbfGXUxM (ORCPT + 99 others); Wed, 24 Jul 2019 16:53:12 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:43048 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726458AbfGXUxM (ORCPT ); Wed, 24 Jul 2019 16:53:12 -0400 Received: by mail-qk1-f194.google.com with SMTP id m14so9149646qka.10; Wed, 24 Jul 2019 13:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K5EpkRFFvgeAt0nL+hNBcZ+U2NkFxnbvcSf3cki+3DA=; b=PO7hinLFq3VFv+ooVfZfkXHUFKFsUauDMz7qczK0IejHr9Xbvef73lKFG7PUClE09N jpXXO3hwY78SrylxapqREKIH/tXYzqVOzetb7kOm1IkAO2/P4aM3VZcGmZQJUiGj0V2E T6HuDnb5PWbJoDEFvOEqXAVtHNDgEowEluhoZG9zgOlxJXzi4XIlufKYFvm4Y/itVCzv cYPTDkin1sJujrBFaeoFQmCZ9bwanBSYl8ZhtuQJFJ71kiyyi/JnRCKnonYCvABMCemR HFE+RfiZ1P8u3MAxWc7bvaIBjFF6Zh8RY3dQxrm5KSYLKJZpfdIZP8IQyKqtM6uQW/pj 3O5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K5EpkRFFvgeAt0nL+hNBcZ+U2NkFxnbvcSf3cki+3DA=; b=JVievqKYKMMpRmcOWEh9Tb5/SjFeN9o/WIdq+jSQUfzZWNWiX8/ypqHRBwJJ+PnkUg HVYP8WJ5A8jDp4/uSwr1MQzg/SJNKRLsPgv+ftI7t3YW+ht11ATKcF4QRHILm49VBR5g EeFW0NjTfqZ0jLs3yfCMRzZ73bUflvkEMEDDPqVFYJURepDjTGFUCzY5LE0QjLw0KxL8 LFVmfyykwI6IQDsONNnfhKSkACu1Axi+vNgkIZLXiCQ2xp1iBO4UMyUj3zWTZjemoHvY mdiQ7Vf0sd5SKCWWqZKTVdpItTLvcyrJxhmtuao+C3kOSlNiu5w1UEskpg+oAj4yf0tC veOQ== X-Gm-Message-State: APjAAAWkelVgbfqrp7yLbpwG49zWSc7qN8cTQyRSs9ACNK864WgbIKhz KBe/sTJvEEYZ7KH65ETnxsc/RNQBXkufncFsOHpsR5Su X-Received: by 2002:a37:6d85:: with SMTP id i127mr55779207qkc.74.1564001591445; Wed, 24 Jul 2019 13:53:11 -0700 (PDT) MIME-Version: 1.0 References: <20190724165803.87470-1-brianvv@google.com> <20190724165803.87470-2-brianvv@google.com> In-Reply-To: <20190724165803.87470-2-brianvv@google.com> From: Song Liu Date: Wed, 24 Jul 2019 13:53:00 -0700 Message-ID: Subject: Re: [PATCH bpf-next 1/6] bpf: add bpf_map_value_size and bp_map_copy_value helper functions To: Brian Vazquez Cc: Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" , Stanislav Fomichev , Willem de Bruijn , Petar Penkov , open list , Networking , bpf 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 Wed, Jul 24, 2019 at 10:10 AM Brian Vazquez wrote: > > Move reusable code from map_lookup_elem to helper functions to avoid code > duplication in kernel/bpf/syscall.c > > Suggested-by: Stanislav Fomichev > Signed-off-by: Brian Vazquez Acked-by: Song Liu Some very minor nits though. > --- > kernel/bpf/syscall.c | 134 +++++++++++++++++++++++-------------------- > 1 file changed, 73 insertions(+), 61 deletions(-) > > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c > index 5d141f16f6fa9..86cdc2f7bb56e 100644 > --- a/kernel/bpf/syscall.c > +++ b/kernel/bpf/syscall.c > @@ -126,6 +126,76 @@ static struct bpf_map *find_and_alloc_map(union bpf_attr *attr) > return map; > } > > +static u32 bpf_map_value_size(struct bpf_map *map) > +{ > + if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH || > + map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH || > + map->map_type == BPF_MAP_TYPE_PERCPU_ARRAY || > + map->map_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE) > + return round_up(map->value_size, 8) * num_possible_cpus(); > + else if (IS_FD_MAP(map)) > + return sizeof(u32); > + else > + return map->value_size; ^ extra space after return > +} > + > +static int bpf_map_copy_value(struct bpf_map *map, void *key, void *value, > + __u64 flags) > +{ > + void *ptr; > + int err; > + > + if (bpf_map_is_dev_bound(map)) > + return bpf_map_offload_lookup_elem(map, key, value); ^ another extra space after return, did replace? :-) Thanks, Song