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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D2F9C43334 for ; Sat, 9 Jul 2022 01:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbiGIBco (ORCPT ); Fri, 8 Jul 2022 21:32:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiGIBcn (ORCPT ); Fri, 8 Jul 2022 21:32:43 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47E83709A8; Fri, 8 Jul 2022 18:32:40 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Lfsyn1T0kz1L8dD; Sat, 9 Jul 2022 09:30:09 +0800 (CST) Received: from dggpemm500019.china.huawei.com (7.185.36.180) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 9 Jul 2022 09:32:38 +0800 Received: from [10.67.109.184] (10.67.109.184) by dggpemm500019.china.huawei.com (7.185.36.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 9 Jul 2022 09:32:37 +0800 Subject: Re: [PATCH bpf-next v3 4/6] libbpf: Unify memory address casting operation style To: Andrii Nakryiko CC: Daniel Borkmann , bpf , , Networking , "open list" , Alexei Starovoitov , Andrii Nakryiko , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Luke Nelson , Xi Wang , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Paul Walmsley , Palmer Dabbelt , Albert Ou References: <20220530092815.1112406-1-pulehui@huawei.com> <20220530092815.1112406-5-pulehui@huawei.com> <38a59b80-f64a-0913-73e4-29e4ee4149c5@huawei.com> From: Pu Lehui Message-ID: <0355b933-c47b-d3d3-587a-50b38f192d54@huawei.com> Date: Sat, 9 Jul 2022 09:32:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.109.184] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500019.china.huawei.com (7.185.36.180) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/7/9 6:30, Andrii Nakryiko wrote: > On Thu, Jul 7, 2022 at 5:23 AM Pu Lehui wrote: >> >> >> >> On 2022/6/4 5:03, Andrii Nakryiko wrote: >>> On Mon, May 30, 2022 at 2:03 PM Daniel Borkmann wrote: >>>> >>>> On 5/30/22 11:28 AM, Pu Lehui wrote: >>>>> The members of bpf_prog_info, which are line_info, jited_line_info, >>>>> jited_ksyms and jited_func_lens, store u64 address pointed to the >>>>> corresponding memory regions. Memory addresses are conceptually >>>>> unsigned, (unsigned long) casting makes more sense, so let's make >>>>> a change for conceptual uniformity. >>>>> >>>>> Signed-off-by: Pu Lehui >>>>> --- >>>>> tools/lib/bpf/bpf_prog_linfo.c | 9 +++++---- >>>>> 1 file changed, 5 insertions(+), 4 deletions(-) >>>>> >>>>> diff --git a/tools/lib/bpf/bpf_prog_linfo.c b/tools/lib/bpf/bpf_prog_linfo.c >>>>> index 5c503096ef43..7beb060d0671 100644 >>>>> --- a/tools/lib/bpf/bpf_prog_linfo.c >>>>> +++ b/tools/lib/bpf/bpf_prog_linfo.c >>>>> @@ -127,7 +127,8 @@ struct bpf_prog_linfo *bpf_prog_linfo__new(const struct bpf_prog_info *info) >>>>> prog_linfo->raw_linfo = malloc(data_sz); >>>>> if (!prog_linfo->raw_linfo) >>>>> goto err_free; >>>>> - memcpy(prog_linfo->raw_linfo, (void *)(long)info->line_info, data_sz); >>>>> + memcpy(prog_linfo->raw_linfo, (void *)(unsigned long)info->line_info, >>>>> + data_sz); >>>> >>>> Took in patch 1-3, lgtm, thanks! My question around the cleanups in patch 4-6 ... >>>> there are various other such cases e.g. in libbpf, perhaps makes sense to clean all >>>> of them up at once and not just the 4 locations in here. >>> >>> if (void *)(long) pattern is wrong, then I guess the best replacement >>> should be (void *)(uintptr_t) ? >>> >> >> I also think that (void *)(uintptr_t) would be the best replacement. I >> applied the changes to kernel/bpf and samples/bpf, and it worked fine. >> But in selftests/bpf, the following similar error occur at compile time: >> >> progs/test_cls_redirect.c:504:11: error: cast to 'uint8_t *' (aka >> 'unsigned char *') from smaller integer type 'uintptr_t' (aka 'unsigned >> int') [-Werror,-Wint-to-pointer-cast] >> .head = (uint8_t *)(uintptr_t)skb->data, > > this is BPF-side code so using system's uintptr_t definition won't > work correctly here. Just do (unsigned long) instead? > It is fine by me, and for this cleanup >> >> I take clang to compile with the front and back end separation, like >> samples/bpf, and it works. It seems that the all-in-one clang has >> problems handling the uintptr_t. >> >>>> >>>> Thanks, >>>> Daniel >>> . >>> > . >