Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5851977rwr; Mon, 24 Apr 2023 09:49:31 -0700 (PDT) X-Google-Smtp-Source: AKy350Y6qKytVq3F/cCEgoppPUYpNHgBEFz1CdkeLTx2hfzFPPpUQWSr2K1e0spoi8jky9T0WDuI X-Received: by 2002:a05:6a21:3990:b0:ec:fd7a:e827 with SMTP id ad16-20020a056a21399000b000ecfd7ae827mr15086387pzc.32.1682354971631; Mon, 24 Apr 2023 09:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682354971; cv=none; d=google.com; s=arc-20160816; b=BRbAE+yk9Pnwbs7iTSac+HSQsiE8j7etGI2YsglKXKDMmPcqfsbqUI7PTb7t+hF4Nn FDdosnDGmoUEqNO+8x5sWwGBCmaOAh9XZFlqTVrwFGziIo2K4jHB4lsiWHZoONQE4p8C wvWhGNXF4sroza6VEet/64fhQRFPUykL27HsLSlLq7JpOOO4Xcr38Q6KYcb8S/iau8vt bdSji62+jHm/hUOTT3Xpfdeak4FCx0FgCgYPVsOGfO67mzgRXE+rB5bfcZR1KVrBJejB bginpY6iL1Mul0emgYe0ChxC7Vy4e32p2aCB++h/R8NAl/zkhhAAK3k2ay5mkqeqOEDD pAzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=yKXf0cNAKb6gq2MuqWLjiv+ti6kg7FN3aSwzR4hbx2U=; b=SyLnNqJ5UWY1yNrMRkgx+r4G6O1JRq8ZIOXIUu710zBmb1sHXwUf5C2eVeyZvIYyAr o49Rb9IJK/3dlYJnzmYqHKZshr+ABYU1ElTm6B6rPJLhH5ImAtRCzMr19bOljni4IoyW xz9rIQ7gEkzm1ySC5BXSdZEkzgeasvEL7HDM0f62AsPoCzGvUqqZJefS2xCYtwhGFVQx rlMWfWYV2V2nTzd6JPC3OexzW2ZlyLjUHfrntrbqpSgSoEVn+Y3J7K8U4mEoDQWzKO6A 3QPEO3NrVxgTzjVh4ffFCUEK+Bc/v7GNKTFPEqgzdcg7fgwq8s4wJe9suhUQelGdodNS 4BMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=nf6rkWdO; 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 bk13-20020a056a02028d00b00528513d5e9dsi1825278pgb.109.2023.04.24.09.49.16; Mon, 24 Apr 2023 09:49:31 -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=20221208 header.b=nf6rkWdO; 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 S232108AbjDXQoZ (ORCPT + 99 others); Mon, 24 Apr 2023 12:44:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230319AbjDXQoY (ORCPT ); Mon, 24 Apr 2023 12:44:24 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A11844B1; Mon, 24 Apr 2023 09:44:23 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-b980e16b27bso3381109276.2; Mon, 24 Apr 2023 09:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682354662; x=1684946662; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=yKXf0cNAKb6gq2MuqWLjiv+ti6kg7FN3aSwzR4hbx2U=; b=nf6rkWdOPXFKzUX3S+iTvB/fe+NaIdyPTHSVP5LFUd/vkq/C8VDwWT44X2xN+QVl7B Td3HBvRPpFzSQtkYxIFU96dCOeFvARfnvBtbPAzItZUU9ziRdy3gBowHfqyP13YR/Ajj 1JjtgILx0J5ltAKj8hT7hYTxXhUcxWWGxc4SqiLNfvDbABVgN37QR4Rq4MWH4iApf8dz IQIGwfpKoE8gL/3bphhDgkBS1PhYcDeGEPw2otP234DWXCY0MAle5PDlBPpOer94UUp9 gEetm8nVe1k/fqy88yh4uHnXZYP64sVB30yeIJlkL5+zMcAK68T5IiDEjS+DJBIde32P bTkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682354662; x=1684946662; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yKXf0cNAKb6gq2MuqWLjiv+ti6kg7FN3aSwzR4hbx2U=; b=W3zGMlSj845JfudNsRUp3pCu56kLF2Jq7OX4wgJPNJTCaQeB6ezIcNjPAYGLHw2yt/ 9QoPtkevLUiDzrNZkc+Z+ZndP+Dy01nEJM77VwT7EwpITDfWRqzA5IWS6KdXLV64/+a4 65wSSOLyuAgylUEuaqOh+oiTgjmVai3s72Y7r3HlTAd5Il82VQilvC4zDf1+anb9Xnu6 bbxU/0K3QoMpCTzWqqCpTlm0Rg1fDFxmeTbRWCRUQFbtVKxoFCU3oqOzw4QyJToGCbWg Gr+D/dGo2CDI5l5ROlajNvR6wNkWBlcFvfrM0swqmIZvf3emvpvY6X9B67J74yUuv3Xu MJWw== X-Gm-Message-State: AAQBX9e61u2bJAIRtFxo9shzHQUKF0iy9VZgzXGg4SYbteRtlkalU6M1 b2Pol9XFY3Rg6tH4hAHnBhQ= X-Received: by 2002:a25:1885:0:b0:b92:3f59:26e with SMTP id 127-20020a251885000000b00b923f59026emr8625058yby.41.1682354662203; Mon, 24 Apr 2023 09:44:22 -0700 (PDT) Received: from ?IPV6:2600:1700:6cf8:1240:1f41:aa7b:6a04:e9ee? ([2600:1700:6cf8:1240:1f41:aa7b:6a04:e9ee]) by smtp.gmail.com with ESMTPSA id j1-20020a258b81000000b00b923b9e0a82sm2944946ybl.45.2023.04.24.09.44.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Apr 2023 09:44:21 -0700 (PDT) Message-ID: Date: Mon, 24 Apr 2023 09:44:18 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH bpf-next v2] bpftool: Dump map id instead of value for map_of_maps types Content-Language: en-US To: Xueming Feng , Quentin Monnet Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230424090935.52707-1-kuro@kuroa.me> From: Kui-Feng Lee In-Reply-To: <20230424090935.52707-1-kuro@kuroa.me> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, 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 4/24/23 02:09, Xueming Feng wrote: > When using `bpftool map dump` in plain format, it is usually > more convenient to show the inner map id instead of raw value. > Changing this behavior would help with quick debugging with > `bpftool`, without disrupting scripted behavior. Since user > could dump the inner map with id, and need to convert value. > > Signed-off-by: Xueming Feng > --- > Changes in v2: > - Fix commit message grammar. > - Change `print_uint` to only print to stdout, make `arg` const, and rename > `n` to `arg_size`. > - Make `print_uint` able to take any size of argument up to `unsigned long`, > and print it as unsigned decimal. > > Thanks for the review and suggestions! I have changed my patch accordingly. > There is a possibility that `arg_size` is larger than `unsigned long`, > but previous review suggested that it should be up to the caller function to > set `arg_size` correctly. So I didn't add check for that, should I? > > tools/bpf/bpftool/main.c | 15 +++++++++++++++ > tools/bpf/bpftool/main.h | 1 + > tools/bpf/bpftool/map.c | 9 +++++++-- > 3 files changed, 23 insertions(+), 2 deletions(-) > > diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c > index 08d0ac543c67..810c0dc10ecb 100644 > --- a/tools/bpf/bpftool/main.c > +++ b/tools/bpf/bpftool/main.c > @@ -251,6 +251,21 @@ int detect_common_prefix(const char *arg, ...) > return 0; > } > > +void print_uint(const void *arg, unsigned int arg_size) > +{ > + const unsigned char *data = arg; > + unsigned long val = 0ul; > + > + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > + memcpy(&val, data, arg_size); > + #else > + memcpy((unsigned char *)&val + sizeof(val) - arg_size, > + data, arg_size); > + #endif Is it possible that arg_size is bigger than sizeof(val)? > + > + fprintf(stdout, "%lu", val); > +} > + > void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep) > { > unsigned char *data = arg; > diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h > index 0ef373cef4c7..0de671423431 100644 > --- a/tools/bpf/bpftool/main.h > +++ b/tools/bpf/bpftool/main.h > @@ -90,6 +90,7 @@ void __printf(1, 2) p_info(const char *fmt, ...); > > bool is_prefix(const char *pfx, const char *str); > int detect_common_prefix(const char *arg, ...); > +void print_uint(const void *arg, unsigned int arg_size); > void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep); > void usage(void) __noreturn; > > diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c > index aaeb8939e137..f5be4c0564cf 100644 > --- a/tools/bpf/bpftool/map.c > +++ b/tools/bpf/bpftool/map.c > @@ -259,8 +259,13 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, > } > > if (info->value_size) { > - printf("value:%c", break_names ? '\n' : ' '); > - fprint_hex(stdout, value, info->value_size, " "); > + if (map_is_map_of_maps(info->type)) { > + printf("id:%c", break_names ? '\n' : ' '); > + print_uint(value, info->value_size); > + } else { > + printf("value:%c", break_names ? '\n' : ' '); > + fprint_hex(stdout, value, info->value_size, " "); > + } > } > > printf("\n");