Page MenuHomeFreeBSD

Better handling of nexus and errors for DEV_GET_PATH
ClosedPublic

Authored by kib on Oct 7 2022, 1:32 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 28, 8:16 PM
Unknown Object (File)
Fri, Apr 26, 6:27 AM
Unknown Object (File)
Fri, Apr 26, 6:27 AM
Unknown Object (File)
Fri, Apr 26, 6:27 AM
Unknown Object (File)
Fri, Apr 26, 3:27 AM
Unknown Object (File)
Fri, Apr 26, 3:27 AM
Unknown Object (File)
Thu, Apr 25, 10:32 PM
Unknown Object (File)
Feb 24 2024, 10:02 AM
Subscribers

Details

Summary
commit d59afd47fd1ee3d536d33e0407524ee89b71a765
Author: Konstantin Belousov <kib@FreeBSD.org>
Date:   Thu Oct 6 22:46:30 2022 +0300

    device_get_path(): handle case when dev is root
    
    PR:     266862
    Based on submission by: takawata

commit f356d7d48fbbd94658c2f7c4d7f53d6fcfabdf59
Author: Konstantin Belousov <kib@FreeBSD.org>
Date:   Fri Oct 7 04:25:37 2022 +0300

    device_get_path(): do not drop the error from BUS_GET_DEVICE_PATH()
    
    Later it would silently converted to ENOMEM always, because any error
    was reported as NULL return path.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Oct 7 2022, 1:32 AM
kib created this revision.
sys/kern/subr_bus.c
5330

This could probably use M_NOWAIT since the sbuf_new() above didn't use SB_NOWAIT so uses M_WAITOK internally?

I think this is a good cleanup. We might be better off returning an error for when we have no parent (at the root) and I think we might need to add SB_NOWAIT, unless we can now sleep when probing / attaching driverrs.

sys/kern/subr_bus.c
5319

Could we just return an EINVAL error for root instead?

5330

Likely the above sbuf_new should use SB_NOWAIT and we should return a ENOMEM error there.
This function is called after boot in a sleepable context.
But during boot we can use it to determine if a wired entry matches one of the locators, and we can't sleep then (though in practice, there's a lot of places we are sloppy)

sys/kern/subr_bus.c
5330

Then I wonder if what we don't want to do instead, is change this API to pass down the sbuf pointer directly like we do now for child and location string methods. This lets the caller decide what kind of allocation policy it wants. It also avoids having to do a malloc() + copy in most cases since the caller can use sbuf_data() directly.

sys/kern/subr_bus.c
5330

Then I wonder if what we don't want to do instead, is change this API to pass down the sbuf pointer directly like we do now for child and location string methods. This lets the caller decide what kind of allocation policy it wants. It also avoids having to do a malloc() + copy in most cases since the caller can use sbuf_data() directly.

Oh! I love that idea... For ioctl context, we'd do one thing and in the matching / wiring code another. And I think it would also save at least one malloc. We already have it BUS_GET_DEVICE_PATH which is used here to get the data, and having the callers provide the sb would solve this issue.

I can also code that up as well, if this is getting too far afield for kib.

sys/kern/subr_bus.c
5319

My original patch do just return with error, because the interface does not assume bus device handle the bus device itself. This code will produce "/root0" with "FreeBSD" locator, I think. I think this have to produce "/" instead, if it produce non-error output.

kib marked 6 inline comments as done.Oct 8 2022, 12:11 AM
kib added inline comments.
sys/kern/subr_bus.c
5319

I do not like returning EINVAL, because why? nexus is the device that should be not exceptional for regular API.

Returning "/" would be inconsistent. Note that the bus method is not accumulating, it is supposed to return the full name.

kib marked an inline comment as done.

Make device_get_path() take sbuf pointer.

sys/kern/subr_bus.c
5319
% devctl getpath FreeBSD acpi_wmi0
/nexus0/acpi0/acpi_wmi0
devctl getpath FreeBSD acpi0
/nexus0/acpi0
 % devctl getpath FreeBSD  nexus0
/nexus0

What's next?

sys/kern/subr_bus.c
5319

I do think the FreeBSD path for root0 should be either "" or "/".

5332โ€“5336

I think this is equivalent to:

error = sbuf_error(sb);
if (error == 0 && sbuf_len(sb) <= 1)
    error = EIO;
sys/kern/subr_bus.c
5319

I think it should be "", since we append /$name...

5332โ€“5336

I think so too...

sys/kern/subr_bus.c
5319

Returning empty string for all locator may simplify the issue.

kib marked 6 inline comments as done.

Return "/" for root0.
Simplify error calculation for sbuf.

This revision is now accepted and ready to land.Oct 17 2022, 4:05 AM