Page MenuHomeFreeBSD

linuxkpi: Accept NULL as a value in `linux_xarray`
ClosedPublic

Authored by dumbbell on Feb 12 2023, 10:09 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Jan 1, 3:24 PM
Unknown Object (File)
Oct 28 2024, 8:01 PM
Unknown Object (File)
Oct 9 2024, 12:05 PM
Unknown Object (File)
Sep 30 2024, 1:39 PM
Unknown Object (File)
Sep 28 2024, 7:15 PM
Unknown Object (File)
Sep 20 2024, 4:29 PM
Unknown Object (File)
Sep 19 2024, 5:12 PM
Unknown Object (File)
Sep 19 2024, 11:36 AM

Details

Summary

Linux' XArray allows to store a NULL pointer as a value. xa_load() would return NULL for both an unused index and an index set to NULL. But it impacts xa_alloc() which needs to find the next available index.

However, our implementation relies on a radix tree (see linux_radix.c) which does not accept NULL pointers as values. I'm not sure if this is a limitation or a feature, so to work around this, a NULL value is replaced by NULL_VALUE, an unlikely address, when we pass it to linux_radix.

This is part of the update of the DRM drivers to Linux 5.15.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

manu added a subscriber: hselasky.

Maybe wait for @hselasky comment

This revision is now accepted and ready to land.Feb 13 2023, 11:40 AM

Looks like an acceptable solution, thank you for the detailed comment describing the situation.

markj added inline comments.
sys/compat/linuxkpi/common/src/linux_xarray.c
250–252

Should we assert that the passed-in value for ptr isn't equal to NULL_VALUE?

sys/compat/linuxkpi/common/src/linux_xarray.c
250–252

Good idea, I will prepare another patch. Thanks!