public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	martin.lau@kernel.org, kernel-team@meta.com
Subject: Re: [PATCH bpf-next] selftests/bpf: make use of PROCMAP_QUERY ioctl if available
Date: Wed, 7 Aug 2024 11:07:48 +0200	[thread overview]
Message-ID: <ZrM5ZKXwjKiWjRk9@krava> (raw)
In-Reply-To: <20240806230319.869734-1-andrii@kernel.org>

On Tue, Aug 06, 2024 at 04:03:19PM -0700, Andrii Nakryiko wrote:

SNIP

>  ssize_t get_uprobe_offset(const void *addr)
>  {
> -	size_t start, end, base;
> -	char buf[256];
> -	bool found = false;
> +	size_t start, base, end;
>  	FILE *f;
> +	char buf[256];
> +	int err, flags;
>  
>  	f = fopen("/proc/self/maps", "r");
>  	if (!f)
>  		return -errno;
>  
> -	while (fscanf(f, "%zx-%zx %s %zx %*[^\n]\n", &start, &end, buf, &base) == 4) {
> -		if (buf[2] == 'x' && (uintptr_t)addr >= start && (uintptr_t)addr < end) {
> -			found = true;
> -			break;
> +	/* requested executable VMA only */
> +	err = procmap_query(fileno(f), addr, PROCMAP_QUERY_VMA_EXECUTABLE, &start, &base, &flags);
> +	if (err == -EOPNOTSUPP) {
> +		bool found = false;
> +
> +		while (fscanf(f, "%zx-%zx %s %zx %*[^\n]\n", &start, &end, buf, &base) == 4) {
> +			if (buf[2] == 'x' && (uintptr_t)addr >= start && (uintptr_t)addr < end) {
> +				found = true;
> +				break;
> +			}
> +		}
> +		if (!found) {
> +			fclose(f);
> +			return -ESRCH;
>  		}
> +	} else if (err) {
> +		fclose(f);
> +		return err;

I feel like I commented on this before, so feel free to ignore me,
but this seems similar to the code below, could be in one function

anyway it's good for follow up

there was another selftest in the original patchset adding benchmark
for the procfs query interface, is it coming in as well?

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

>  	}
> -
>  	fclose(f);
>  
> -	if (!found)
> -		return -ESRCH;
> -
>  #if defined(__powerpc64__) && defined(_CALL_ELF) && _CALL_ELF == 2
>  
>  #define OP_RT_RA_MASK   0xffff0000UL
> @@ -307,15 +371,25 @@ ssize_t get_rel_offset(uintptr_t addr)
>  	size_t start, end, offset;
>  	char buf[256];
>  	FILE *f;
> +	int err, flags;
>  
>  	f = fopen("/proc/self/maps", "r");
>  	if (!f)
>  		return -errno;
>  
> -	while (fscanf(f, "%zx-%zx %s %zx %*[^\n]\n", &start, &end, buf, &offset) == 4) {
> -		if (addr >= start && addr < end) {
> -			fclose(f);
> -			return (size_t)addr - start + offset;
> +	err = procmap_query(fileno(f), (const void *)addr, 0, &start, &offset, &flags);
> +	if (err == 0) {
> +		fclose(f);
> +		return (size_t)addr - start + offset;
> +	} else if (err != -EOPNOTSUPP) {
> +		fclose(f);
> +		return err;
> +	} else if (err) {
> +		while (fscanf(f, "%zx-%zx %s %zx %*[^\n]\n", &start, &end, buf, &offset) == 4) {
> +			if (addr >= start && addr < end) {
> +				fclose(f);
> +				return (size_t)addr - start + offset;
> +			}
>  		}
>  	}
>  
> -- 
> 2.43.5
> 
> 

  reply	other threads:[~2024-08-07  9:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06 23:03 [PATCH bpf-next] selftests/bpf: make use of PROCMAP_QUERY ioctl if available Andrii Nakryiko
2024-08-07  9:07 ` Jiri Olsa [this message]
2024-08-07 15:17   ` Andrii Nakryiko
2024-08-23 14:47     ` Alexei Starovoitov
2024-08-23 16:53       ` Andrii Nakryiko
2024-08-23 21:31         ` Jiri Olsa
2024-08-23 14:50 ` patchwork-bot+netdevbpf

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=ZrM5ZKXwjKiWjRk9@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    /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