linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: Okash Khawaja <osk@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <kafai@fb.com>,
	Alexei Starovoitov <ast@kernel.org>, Yonghong Song <yhs@fb.com>,
	Quentin Monnet <quentin.monnet@netronome.com>,
	"David S. Miller" <davem@davemloft.net>, <netdev@vger.kernel.org>,
	<kernel-team@fb.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next v4 2/3] bpf: btf: add btf print functionality
Date: Wed, 11 Jul 2018 12:10:15 -0700	[thread overview]
Message-ID: <20180711121015.42873aff@cakuba.lan> (raw)
In-Reply-To: <20180711032557.728015225@fb.com>

Thank you for all the changes made so far.

On Tue, 10 Jul 2018 20:21:10 -0700, Okash Khawaja wrote:
> --- /dev/null
> +++ b/tools/bpf/bpftool/btf_dumper.c
> @@ -0,0 +1,248 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2018 Facebook */
> +
> +#include <linux/btf.h>
> +#include <linux/err.h>
> +#include <stdio.h> /* for (FILE *) used by json_writer */
> +#include <linux/bitops.h>
> +#include <string.h>
> +#include <ctype.h>

Again, please sort the headers the way I suggested.  Otherwise as the
list of includes grows it's hard to know what's already there.

> +#include "btf.h"
> +#include "json_writer.h"
> +#include "main.h"
> +
> +#define BITS_PER_BYTE_MASK (BITS_PER_BYTE - 1)
> +#define BITS_PER_BYTE_MASKED(bits) ((bits) & BITS_PER_BYTE_MASK)
> +#define BITS_ROUNDDOWN_BYTES(bits) ((bits) >> 3)
> +#define BITS_ROUNDUP_BYTES(bits) \
> +	(BITS_ROUNDDOWN_BYTES(bits) + !!BITS_PER_BYTE_MASKED(bits))
> +
> +static int btf_dumper_do_type(const struct btf_dumper *d, __u32 type_id,
> +			      __u8 bit_offset, const void *data);
> +
> +static void btf_dumper_ptr(const void *data, json_writer_t *jw,
> +			   bool is_plain_text)
> +{
> +	if (is_plain_text)
> +		jsonw_printf(jw, "%p", *((unsigned long *)data));
> +	else
> +		jsonw_printf(jw, "%u", *((unsigned long *)data));

Again, please drop the extraneous parens. 

> +}
> +

> +static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
> +				const void *data, json_writer_t *jw,
> +				bool is_plain_text)
> +{
> +	int left_shift_bits, right_shift_bits;
> +	int nr_bits = BTF_INT_BITS(int_type);
> +	int total_bits_offset;
> +	int bytes_to_copy;
> +	int bits_to_copy;
> +	__u64 print_num;
> +
> +	total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type);
> +	data += BITS_ROUNDDOWN_BYTES(total_bits_offset);
> +	bit_offset = BITS_PER_BYTE_MASKED(total_bits_offset);
> +	bits_to_copy = bit_offset + nr_bits;
> +	bytes_to_copy = BITS_ROUNDUP_BYTES(bits_to_copy);
> +
> +	print_num = 0;
> +	memcpy(&print_num, data, bytes_to_copy);
> +#ifdef __BIG_ENDIAN_BITFIELD
> +	left_shift_bits = bit_offset;
> +#else
> +	left_shift_bits = 64 - bits_to_copy;
> +#endif
> +	right_shift_bits = 64 - nr_bits;

Please include <asm/byteorder.h> as I suggested to you previously.
This is dead code right now, look:

$ git diff
diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
index c64465094b92..045add07b721 100644
--- a/tools/bpf/bpftool/btf_dumper.c
+++ b/tools/bpf/bpftool/btf_dumper.c
@@ -91,7 +91,8 @@ static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
 
        print_num = 0;
        memcpy(&print_num, data, bytes_to_copy);
-#ifdef __BIG_ENDIAN_BITFIELD
+#ifndef __LITTLE_ENDIAN_BITFIELD
+#error "abc"
        left_shift_bits = bit_offset;
 #else
        left_shift_bits = 64 - bits_to_copy;

$ make -C tools/bpf/bpftool/ CC=gcc-8
make: Entering directory '/home/jkicinski/devel/linux/tools/bpf/bpftool'
  CC       btf_dumper.o
btf_dumper.c: In function ‘btf_dumper_int_bits’:
btf_dumper.c:95:2: error: #error "abc"
 #error "abc"
  ^~~~~
Makefile:96: recipe for target 'btf_dumper.o' failed
make: *** [btf_dumper.o] Error 1
make: Leaving directory '/home/jkicinski/devel/linux/tools/bpf/bpftool'

  reply	other threads:[~2018-07-11 19:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-11  3:21 [PATCH bpf-next v4 0/3] bpf: btf: print bpftool map data with btf Okash Khawaja
2018-07-11  3:21 ` [PATCH bpf-next v4 2/3] bpf: btf: add btf print functionality Okash Khawaja
2018-07-11 19:10   ` Jakub Kicinski [this message]
2018-07-11 20:08     ` Daniel Borkmann
2018-07-11 21:20       ` Okash Khawaja
2018-07-11 21:18     ` Okash Khawaja
2018-07-11  3:21 ` [PATCH bpf-next v4 3/3] bpf: btf: print map dump and lookup with btf info Okash Khawaja
2018-07-11 20:04   ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180711121015.42873aff@cakuba.lan \
    --to=jakub.kicinski@netronome.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=osk@fb.com \
    --cc=quentin.monnet@netronome.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).