LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Leo Yan <leo.yan@linaro.org>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next 4/5] samples/bpf: Refine printing symbol for sampleip
Date: Thu, 19 Apr 2018 13:12:49 +0800	[thread overview]
Message-ID: <20180419051249.GA27295@leoy-ThinkPad-X240s> (raw)
In-Reply-To: <20180419044743.srjhqegvir5exub5@ast-mbp>

On Wed, Apr 18, 2018 at 09:47:45PM -0700, Alexei Starovoitov wrote:
> On Thu, Apr 19, 2018 at 09:34:05AM +0800, Leo Yan wrote:
> > The code defines macro 'PAGE_OFFSET' and uses it to decide if the
> > address is in kernel space or not.  But different architecture has
> > different 'PAGE_OFFSET' so this program cannot be used for all
> > platforms.
> > 
> > This commit changes to check returned pointer from ksym_search() to
> > judge if the address falls into kernel space or not, and removes
> > macro 'PAGE_OFFSET' as it isn't used anymore.  As result, this program
> > has no architecture dependency.
> > 
> > Signed-off-by: Leo Yan <leo.yan@linaro.org>
> > ---
> >  samples/bpf/sampleip_user.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/samples/bpf/sampleip_user.c b/samples/bpf/sampleip_user.c
> > index 4ed690b..0eea1b3 100644
> > --- a/samples/bpf/sampleip_user.c
> > +++ b/samples/bpf/sampleip_user.c
> > @@ -26,7 +26,6 @@
> >  #define DEFAULT_FREQ	99
> >  #define DEFAULT_SECS	5
> >  #define MAX_IPS		8192
> > -#define PAGE_OFFSET	0xffff880000000000
> >  
> >  static int nr_cpus;
> >  
> > @@ -107,14 +106,13 @@ static void print_ip_map(int fd)
> >  	/* sort and print */
> >  	qsort(counts, max, sizeof(struct ipcount), count_cmp);
> >  	for (i = 0; i < max; i++) {
> > -		if (counts[i].ip > PAGE_OFFSET) {
> > -			sym = ksym_search(counts[i].ip);
> 
> yes. it is x64 specific, since it's a sample code,
> but simply removing it is not a fix.
> It makes this sampleip code behaving incorrectly.
> To do such 'cleanup of ksym' please refactor it in the true generic way,
> so these ksym* helpers can work on all archs and put this new
> functionality into selftests.

Just want to check, are you suggesting to create a standalone
testing for kallsyms (like a folder tools/testing/selftests/ksym) or
do you mean to place the generic code into folder
tools/testing/selftests/bpf/?

> If you can convert these examples into proper self-checking tests
> that run out of selftests that would be awesome.

Thank you for suggestions, Alexei.

> Thanks!
> 

  reply	other threads:[~2018-04-19  5:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19  1:34 [PATCH bpf-next 0/5] samples/bpf: Minor fixes and cleanup Leo Yan
2018-04-19  1:34 ` [PATCH bpf-next 1/5] samples/bpf: Fix typo in comment Leo Yan
2018-04-20 12:10   ` Jesper Dangaard Brouer
2018-04-20 13:21     ` Daniel Thompson
2018-04-20 13:52       ` Jesper Dangaard Brouer
2018-04-25 10:01         ` Leo Yan
2018-04-19  1:34 ` [PATCH bpf-next 2/5] samples/bpf: Dynamically allocate structure 'syms' Leo Yan
2018-04-19  1:34 ` [PATCH bpf-next 3/5] samples/bpf: Use NULL for failed to find symbol Leo Yan
2018-04-19  1:34 ` [PATCH bpf-next 4/5] samples/bpf: Refine printing symbol for sampleip Leo Yan
2018-04-19  4:47   ` Alexei Starovoitov
2018-04-19  5:12     ` Leo Yan [this message]
2018-04-19  5:21       ` Alexei Starovoitov
2018-04-19  5:33         ` Leo Yan
2018-04-19  1:34 ` [PATCH bpf-next 5/5] samples/bpf: Handle NULL pointer returned by ksym_search() Leo Yan

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=20180419051249.GA27295@leoy-ThinkPad-X240s \
    --to=leo.yan@linaro.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --subject='Re: [PATCH bpf-next 4/5] samples/bpf: Refine printing symbol for sampleip' \
    /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

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).