Linux DTrace development list
 help / color / mirror / Atom feed
From: Nick Alcock <nix@esperi.org.uk>
To: Kris Van Hees <kris.van.hees@oracle.com>
Cc: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [PATCH 05/20] btf: stop resolving cyclic type references
Date: Fri, 06 Nov 2026 12:48:40 +0000	[thread overview]
Message-ID: <87v76at9av.fsf@esperi.org.uk> (raw)
In-Reply-To: <62cfb7eb8b923ab975f376f7850c0a83@oracle.com>

On 30 Oct 2026, Kris Van Hees told this:

> --- a/libdtrace/dt_btf.c
> +++ b/libdtrace/dt_btf.c
> @@ -100,8 +100,14 @@ static btf_type_t *
>  dt_btf_real_type_by_id(const dt_btf_t *btf, int32_t id)
>  {
>  	btf_type_t	*type = dt_btf_type_by_id(btf, id);
> +	uint64_t	remaining = 1 + (uint64_t)btf->type_cnt;
>  
> -	while (type != NULL) {
> +	if (btf->parent != NULL)
> +		remaining += btf->parent->type_cnt;
> +
> +	/* A longer chain must revisit a type, so reject cyclic BTF references. */
> +	while (type != NULL && remaining > 0) {
> +		remaining--;
>  		switch (BTF_INFO_KIND(type->info)) {
>  		case BTF_KIND_CONST:
>  		case BTF_KIND_FUNC:

That's a fun approach. Simple and entirely different from what I'm doing
in a yet-to-be-pushed libctf commit :) (which involves a counter which
starts at 1 and is reduced on every lookup, and whenever it hits 0 an
identity-check is done and the counter is reset with an increased
initial value: a tortoise-and-hare-in-O(1) space-and-time algorithm of
Hellman's. Like yours, it has the advantage of being basically free
unless things go wrong.)

Reviewed-by: Nick Alcock <nix@esperi.org.uk>

-- 
NULL && (void)

      reply	other threads:[~2026-11-06 12:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 19:36 [PATCH 05/20] btf: stop resolving cyclic type references Kris Van Hees
2026-11-06 12:48 ` Nick Alcock [this message]

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=87v76at9av.fsf@esperi.org.uk \
    --to=nix@esperi.org.uk \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    --cc=kris.van.hees@oracle.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