Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error handling for einval with lpm trie. #1720

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion map.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,12 @@ func handleMapCreateError(attr sys.MapCreateAttr, spec *MapSpec, err error) erro
if errors.Is(err, unix.EINVAL) && spec.Type == UnspecifiedMap {
return fmt.Errorf("map create: cannot use type %s", UnspecifiedMap)
}
if errors.Is(err, unix.EINVAL) && spec.Flags&sys.BPF_F_NO_PREALLOC > 0 {
// LPM trie key size must be a multiple of 8 and not exceed 2048.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems incorrect according to my experience and the doc https://docs.ebpf.io/linux/map-type/BPF_MAP_TYPE_LPM_TRIE/.

// Ref: https://docs.kernel.org/bpf/map_lpm_trie.html#bpf-map-type-lpm-trie
if errors.Is(err, unix.EINVAL) && spec.Type == LPMTrie && (spec.KeySize%8 != 0 || spec.KeySize > 2048) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is becoming a bit too specific for me. The goal is not to be exhaustive, and the wording here has always been soft on purpose. Could you drop this change?

The actual problem is a false-positive on the error message. I suggest adding the the following to types.go:

func (mt MapType) mustHaveNoPrealloc() bool { }

I'd check the kernel sources for all currently-known cases and make this function return true for LPM, cgroup storage and others that require NO_PREALLOC to be set.

return fmt.Errorf("map create: LPMTrie: invalid key size %d (LPM trie key size must be a multiple of 8 and not exceed 2048)", LPMTrie)
}
if errors.Is(err, unix.EINVAL) && spec.Flags&sys.BPF_F_NO_PREALLOC > 0 && spec.Type != LPMTrie {
return fmt.Errorf("map create: %w (noPrealloc flag may be incompatible with map type %s)", err, spec.Type)
}

Expand Down
Loading