Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751841AbbEYJ0U (ORCPT ); Mon, 25 May 2015 05:26:20 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:58311 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750923AbbEYJ0T (ORCPT ); Mon, 25 May 2015 05:26:19 -0400 Message-ID: <5562EA2A.2000901@huawei.com> Date: Mon, 25 May 2015 17:23:54 +0800 From: "Wangnan (F)" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Alexei Starovoitov , , , , , , , , , , CC: , , Subject: Re: [RFC PATCH v3 21/37] bpf tools: Create eBPF maps defined in an object file References: <1431860222-61636-1-git-send-email-wangnan0@huawei.com> <1431860222-61636-22-git-send-email-wangnan0@huawei.com> <555A3419.4040207@plumgrid.com> In-Reply-To: <555A3419.4040207@plumgrid.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.111.66.109] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.5562EA9D.00AB,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 34ccac4cdd7f72711b5709ca1cedd3f7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2374 Lines: 70 On 2015/5/19 2:48, Alexei Starovoitov wrote: > On 5/17/15 3:56 AM, Wang Nan wrote: >> This patch creates maps based on 'map' section in object file using >> bpf_create_map(), and store the fds into an array in >> 'struct bpf_object'. Since the byte order of the object may differ >> from the host, swap map definition before processing. >> >> This is the first patch in 'loading' phase. Previous patches parse ELF >> object file and create needed data structure, but doesnnt play with >> kernel. They belong to 'opening' phase. >> >> Signed-off-by: Wang Nan > ... >> + for (j = 0; j < i; j++) { >> + close(obj->maps_fds[j]); >> + obj->maps_fds[j] = -1; > > this line is unnecessary, since you're freeing the whole array > at the line below: > >> + } >> + free(obj->maps_fds); >> + obj->maps_fds = NULL; > > ... > >> void bpf_close_object(struct bpf_object *obj) >> { >> if (!obj) >> return; >> >> bpf_obj_clear_elf(obj); >> + bpf_unload_object(obj); > > just realized that this API keeps elf file open for the whole > life time. I think that should be split up. > bpf_open_object() can do elf parsing, creation of maps and > bpf loading. > bpf_close_object() can unload programs, maps. That's fine, > but closing of elf file and freeing memory associated > with parsing sections should be a separate call. > Looks like I didn't describe the API of libbpf very clearly in patch 0/37. There are two phases of the API: opening and loading. Opening phase does ELF parsing, and records all related information info 'struct bpf_object'. After that, ELF file itself is closed by bpf_obj_elf_finish(). See patch 19/37. After that, caller will have a chance to adjust programs and maps (currently not implemented). Caller should call bpf_load_object() to do real useful things with kernel. bpf_unload_object() remove map and programs in the object from kernel. It also calls bpf_obj_elf_finish(). However, if it has been called once, the 2nd call doesn't take effect at all. Just in case. Thank you. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/