ebpf icon indicating copy to clipboard operation
ebpf copied to clipboard

Better error for BPF_MAP_TYPE_LRU_HASH creation fail due to bpf_spin_lock field

Open incfly opened this issue 4 months ago • 0 comments

When a map value contains a bpf_spin_lock field, the map could not be declared as BPF_MAP_TYPE_LRU_HASH.

struct value {
  struct bpf_spin_lock semaphore;
  // other fields
}

This is a eBPF its own requirement. But currently I see the error message is a generic map create: operation not supported. I see we have similar effort before on refining error message, https://github.com/cilium/ebpf/issues/1072

And in map.go map loader would try to provide more information

func handleMapCreateError(attr sys.MapCreateAttr, spec *MapSpec, err error) error {
	if errors.Is(err, unix.EPERM) {
		return fmt.Errorf("map create: %w (MEMLOCK may be too low, consider rlimit.RemoveMemlock)", err)
	}
	if errors.Is(err, unix.EINVAL) && spec.MaxEntries == 0 {
		return fmt.Errorf("map create: %w (MaxEntries may be incorrectly set to zero)", err)
	}
	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 {
		return fmt.Errorf("map create: %w (noPrealloc flag may be incompatible with map type %s)", err, spec.Type)
	}

It would be great to indicate this type of error as well.

Version: 0.17.3

incfly avatar Jun 19 '25 00:06 incfly