Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp978985imw; Fri, 8 Jul 2022 15:45:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u4Jnnf4sMPLqK7yv9jroP23PKrKXQ0T9tQHupX7kLy7z7m5UcsmeKpnIgAY3LUq4mFypY4 X-Received: by 2002:a17:907:7607:b0:72b:1c8a:da9b with SMTP id jx7-20020a170907760700b0072b1c8ada9bmr6069123ejc.108.1657320358995; Fri, 08 Jul 2022 15:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657320358; cv=none; d=google.com; s=arc-20160816; b=gKBZJkn3OQGYEtAeDLZ+skqbxmVgmOn1RSUiFdVq31Sw+MjdbyEsJjafT6vIiyDwV0 6q8RiCFprdpuHUgbH2qJno6rtPoP1LLMglHDJklJS333TdpLo8ezfr5o7c6+F2GTZHz9 DDXg+jCZOnWqWZCZil9ctVU6Q7GfwkuaJy7113PtZssXJ+k2HpWUzvC7M963fcLphzBj TzDJ1Z2ZwzYjZPN+YWAtG2SvNkkCgVKHwvwOt5nbHw73X37Jir9Tg3n0Nzlxsz+H4qAD gVtrrTQk10eoUsc/sXsJTwX13yUkYGS66Y4dj10C8REMhIh+ggHE5ELNYRhEu6iKG+h1 1OXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vtYNlUjFPBorTja/ZZdAiqkuVJixHxyN2XSNBOycbUI=; b=zZGhpSIqjojkLvWLmfnyFr+bgzYVPxiBT9mOWN3+VeVA4HMSGvDJJU4SUMnX7hXBps lMqsF0SQsrfPPFvUXZpXqVmSNjmReMoA1PG23xhmiBIr121yUto0X8uPm8GcrDc600Gm 3iPk7uXe1gypMHG0jV0zZV5T7Li+RkFHI/cVRiCQx2Z5TVgwTxZ0JkOD4mREK6W2kWho JcSxGkoSRSYTPrBtn1gXIMY5+U1mL88Ie3XQw8CiDD1i2K2nCTLFJWLHYOLmljfy8+Ob UPKAwofySz5DsYb/kkaaGKDaxEFcPrtioy2r7u0F1O6T1vwmPO2U7fqdwNSIE/WU6gXa /InA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DM5Hj2oO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p8-20020a056402074800b0043a56c0dbaesi20647077edy.167.2022.07.08.15.45.34; Fri, 08 Jul 2022 15:45:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DM5Hj2oO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239055AbiGHWbL (ORCPT + 99 others); Fri, 8 Jul 2022 18:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238977AbiGHWbH (ORCPT ); Fri, 8 Jul 2022 18:31:07 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71EF713B462; Fri, 8 Jul 2022 15:31:06 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id dn9so34614724ejc.7; Fri, 08 Jul 2022 15:31:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vtYNlUjFPBorTja/ZZdAiqkuVJixHxyN2XSNBOycbUI=; b=DM5Hj2oOBlL+l9CByJUKOaJ1vh4HJDKbEohe9/mUhrJgEyABIdmO+clfDNX8z4r0VE nO3YJTw4Dj43d+Ay0VD9VuWxZn3DTEQTUbM/kbJ4S7meIbQXRsDrq4PSBKwlvTLCj8f9 tD8hIcQzA2JxTza2YBdsVregDQcn+tgrrmRuWeGW3NN7zkdUaRumuuPDsb2LiQ4IEpL2 yOB9FFMy/0wpprM4LnpZ15p3wwuLPUGpmHLxXl+xf4tVLMXyDpm0lFf8gM4V5edxrtIH dT5HHV32Z9hMD4BpMZAoV+EXhfLeV/u5UTsBdsa2+Mhyg4FmR8s2R/IH4LJzCBGxetst aOjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vtYNlUjFPBorTja/ZZdAiqkuVJixHxyN2XSNBOycbUI=; b=2pkBIjiTDRMMB3g1QnJ8GbohCKVvdGipWFX8BajFFa1xn+cDdkOlQ/Hy8sz+zI1S8F mF4Tj6E56EXa23pp81oKNoAI+8wj6WVRl6XPnK+CSN/+hnTdU3B0YugSsDjiJ1HdqpSx jdKOE2bpFqSz2Do//GVGybBelByVh/ABj6wqZ0mMbIW/EDhHZA6LVvxy6lFsmrtaaVti YziRUD7LcTS+taTSl9zidjiCqb8VCi8vKWIyExUjRBk6X5f0ECxgLhHq1Z+pVR1wi062 KxjHzDefCP3U6zsKaMtxHcbE0ZvA+niiCnfD6hXZ5F/U9wC+rwhz0/Ab7R+uu5cOO0WH s3VQ== X-Gm-Message-State: AJIora/6k9UjF2P0Gfeb6bAUz6iUTHEo5542x0DCVqostOO7IRKn7WsX ZjZsiBruBC+2p7Or7isfD9rrp49dajIMBy27apw= X-Received: by 2002:a17:906:a3ca:b0:726:2bd2:87bc with SMTP id ca10-20020a170906a3ca00b007262bd287bcmr5799290ejb.226.1657319464980; Fri, 08 Jul 2022 15:31:04 -0700 (PDT) MIME-Version: 1.0 References: <20220530092815.1112406-1-pulehui@huawei.com> <20220530092815.1112406-5-pulehui@huawei.com> <38a59b80-f64a-0913-73e4-29e4ee4149c5@huawei.com> In-Reply-To: <38a59b80-f64a-0913-73e4-29e4ee4149c5@huawei.com> From: Andrii Nakryiko Date: Fri, 8 Jul 2022 15:30:53 -0700 Message-ID: Subject: Re: [PATCH bpf-next v3 4/6] libbpf: Unify memory address casting operation style To: Pu Lehui Cc: Daniel Borkmann , bpf , linux-riscv@lists.infradead.org, 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > > 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 > > . > >