Page MenuHomeFreeBSD

Use syscall_helper_register() rather than syscall_register().
ClosedPublic

Authored by brooks on Feb 6 2018, 6:59 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, May 4, 8:09 PM
Unknown Object (File)
Tue, Apr 30, 12:50 AM
Unknown Object (File)
Mar 17 2024, 2:14 AM
Unknown Object (File)
Mar 17 2024, 2:14 AM
Unknown Object (File)
Mar 17 2024, 2:14 AM
Unknown Object (File)
Mar 17 2024, 2:14 AM
Unknown Object (File)
Mar 17 2024, 2:14 AM
Unknown Object (File)
Mar 14 2024, 9:09 AM
Subscribers

Details

Summary

The usage is simpler and more common.

Obtained from: CheriBSD
Sponsored by: DARPA, AFRL

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I looked for a manual page for syscall_helper_register but it didn't exist :-(.

The conversion looks good to me.

This revision is now accepted and ready to land.Feb 6 2018, 7:39 PM
  • Per @jhb's comment on D14232 let MOD_UNLOAD handle the failure case.
This revision now requires review to proceed.Feb 8 2018, 8:18 PM

Huh, it surprises me that MOD_UNLOAD gets invoked if MOD_LOAD returns an error. But I can see it in module_register_init().

Since MOD_UNLOAD is not allowed and just fails, I don't see a reason
to call kgss_unload() and get rid of the syscalls.

The old code just left the module loaded and usable.
(Most of the NFS related modules cannot be safely unloaded,
since there is no way to know if no process/thread is executing
within them. The nfsd.ko is the main exception and can be
safely unloaded, since it only uses its own threads and it knows
if these still exist.)

Again, since I know nothing about the interface, I'll take myself off
the review.

In D14227#299184, @cem wrote:

Huh, it surprises me that MOD_UNLOAD gets invoked if MOD_LOAD returns an error. But I can see it in module_register_init().

I also found this surprising FWIW.

Since MOD_UNLOAD is not allowed and just fails, I don't see a reason
to call kgss_unload() and get rid of the syscalls.

The old code just left the module loaded and usable.
(Most of the NFS related modules cannot be safely unloaded,
since there is no way to know if no process/thread is executing
within them. The nfsd.ko is the main exception and can be
safely unloaded, since it only uses its own threads and it knows
if these still exist.)

Again, since I know nothing about the interface, I'll take myself off
the review.

FWIW, the syscall_register/unregister stuff does its own thread counter now to handle this race for you. Once syscall_unregister() returns, no thread is currently in that syscall and no new thread can enter the syscall. Thus, if system calls are the only places threads can enter the system taht you are worried about, then syscall_helper_unregister() should be sufficient to permit you to unload. (You will still need to ensure you cleanup global variables such as locks, etc.)

sys/kgssapi/gss_impl.c
290 ↗(On Diff #39061)

I think it's best to register syscalls last after data structures are initialized, not first.

320 ↗(On Diff #39061)

That means you could also safely mtx_destroy(&kgss_gssd_lock) here since it would always be initialized even if MOD_LOAD failed due to kgss_load() failing.

I'm sure there's a way to add this to the above comment box,
but I don't know how to do it.

  • W.r.t. the syscall_helper() maintaining a counter of caller threads...

---> For the NFS/Krpc modules it isn't normally syscall threads.

 Usually they are called through the VFS or via a set of function
 pointers or...
- There really isn't any reason to unload any of these as far as I know.
  • Register syscalls last in the load process.
cem added inline comments.
sys/kgssapi/gss_impl.c
84 ↗(On Diff #39123)

theoretically this returns an error value that should be propagated up.

practically, that value is always 0 (success).

This revision is now accepted and ready to land.Feb 10 2018, 7:33 PM
This revision was automatically updated to reflect the committed changes.