Skip to content

fix : add enum support for resolve#4800

Open
tdaudi wants to merge 3 commits intocilium:mainfrom
tdaudi:pr/tdaudi/fix-resolve-enum
Open

fix : add enum support for resolve#4800
tdaudi wants to merge 3 commits intocilium:mainfrom
tdaudi:pr/tdaudi/fix-resolve-enum

Conversation

@tdaudi
Copy link
Copy Markdown
Contributor

@tdaudi tdaudi commented Mar 26, 2026

Fixes #4799

Description

Enums are uint32. Currently, because of the way integer are handled on BPF, we need to add an extra dereferencing in the resolve algo to have it working properly. For this reason I did not add tests as this little hack won't be necessary after a fix will be done.

[11] ENUM 'test_enum' encoding=UNSIGNED size=4 vlen=3

@tdaudi tdaudi requested a review from a team as a code owner March 26, 2026 15:36
@andrewstrohman andrewstrohman added the release-note/minor This PR introduces a minor user-visible change label Mar 27, 2026
@andrewstrohman
Copy link
Copy Markdown
Contributor

andrewstrohman commented Mar 27, 2026

Enums are uint32.

I don't think this is always true. I think they can be other integer types too. I think that's why the definition of Enum specifies Size and Signed:

// Enum lists possible values.
type Enum struct {
	Name string
	// Size of the enum value in bytes.
	Size uint32
	// True if the values should be interpreted as signed integers.
	Signed bool
	Values []EnumValue
}

But given your debug output:

[11] ENUM 'test_enum' encoding=UNSIGNED size=4 vlen=3

I agree the user would configure the type as uint32 in their policy for this case. I'm just pointing out that the correct type to configure in the policy seems to be situational.

Copy link
Copy Markdown
Contributor

@olsajiri olsajiri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks

Copy link
Copy Markdown
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enums are uint32. Currently, because of the way integer are handled on
BPF, we need to add an extra dereferencing in the resolve algo to have
it working properly.

That's the most common case, but it's not universal as Andy pointed out.

sudo bpftool btf dump file /sys/kernel/btf/vmlinux | grep 'ENUM ' | grep -v 'size=4'
[1148] ENUM 'rw_hint' encoding=UNSIGNED size=1 vlen=6
[2359] ENUM 'blk_integrity_checksum' encoding=UNSIGNED size=1 vlen=4
[4871] ENUM '_cache_table_type' encoding=UNSIGNED size=1 vlen=4
[4872] ENUM '_tlb_table_type' encoding=UNSIGNED size=1 vlen=15
[23364] ENUM 'scsi_cmnd_submitter' encoding=UNSIGNED size=1 vlen=3
[115702] ENUM 'hub_led_mode' encoding=UNSIGNED size=1 vlen=8

Shouldn't we check the enum size and act appropriately?

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 4, 2026

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit e1aa561
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/69d16abc6fa47f0008e50845
😎 Deploy Preview https://deploy-preview-4800--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@tdaudi
Copy link
Copy Markdown
Contributor Author

tdaudi commented Apr 4, 2026

Thank you for your clarifications. I think it's better this way indeed.

Changes includes :

  • One commit for the type: transformation when lastBTFType is an *btf.Enum. (I give details in the commit message)
  • I "recycle" the v32 field in TestUprobeResolve to validate the enum with uint32 format.

@tdaudi tdaudi requested review from andrewstrohman and kkourt April 4, 2026 21:03
Copy link
Copy Markdown
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but can you please rephrase the first commit message that still mentions:

Enums are uint32.

tdaudi added 3 commits April 8, 2026 20:44
Enums are integers. Currently, because of the way integer are handled on
BPF side, we need to add an extra dereferencing in the resolve algo to have
it working properly.

```
sudo bpftool btf dump file /sys/kernel/btf/vmlinux | grep 'ENUM '
[1148] ENUM 'rw_hint' encoding=UNSIGNED size=1 vlen=6
```

Or with custom uprobe we can have something like
```
[11] ENUM 'test_enum' encoding=UNSIGNED size=4 vlen=3
```

Signed-off-by: Tristan d'Audibert <tdaudibe@isovalent.com>
Enum can have different size. To prevent from user misconfiguration, we
calculate the correct type for the enum and return the appropriate one.
Like this, if the user set the `type` with something wrong (e.g. `file`)
it will be replaced by this new value silently.

```yaml
type: file
resolve: my_enum
type: uint32
resolve: my_enum
```

Example enum format displayed with `bpftool`.

```
[11] ENUM 'test_enum' encoding=UNSIGNED size=4 vlen=3
[1148] ENUM 'rw_hint' encoding=UNSIGNED size=1 vlen=6
```

Signed-off-by: Tristan d'Audibert <tdaudibe@isovalent.com>
Signed-off-by: Tristan d'Audibert <tdaudibe@isovalent.com>
@tdaudi tdaudi force-pushed the pr/tdaudi/fix-resolve-enum branch from e1aa561 to f0314f7 Compare April 8, 2026 18:44
@tdaudi
Copy link
Copy Markdown
Contributor Author

tdaudi commented Apr 8, 2026

Sorry, it should be better now. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/minor This PR introduces a minor user-visible change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enum support for uprobe resolve

5 participants