Bug 274986

Summary: False positive to unload module dependencies
Product: Base System Reporter: Zhenlei Huang <zlei>
Component: kernAssignee: Zhenlei Huang <zlei>
Status: Closed FIXED    
Severity: Affects Only Me Flags: zlei: mfc-stable14+
zlei: mfc-stable13+
Priority: ---    
Version: 15.0-CURRENT   
Hardware: Any   
OS: Any   
URL: https://reviews.freebsd.org/D42527

Description Zhenlei Huang freebsd_committer freebsd_triage 2023-11-09 09:50:23 UTC
Steps to repeat:

```
# kldload bridgestp
# kldload if_bridge
# kldunload bridgestp && echo OK
OK
```

Try the second time:
```
# kldunload bridgestp
kldunload: can't unload file: Device busy
```

Expected behavior: since bridgestp.ko is dependency of if_bridge.ko , it makes no senses to unload it with **SUCCESS** .
Comment 1 commit-hook freebsd_committer freebsd_triage 2024-03-26 03:57:53 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f43ff3e15c8b4b161ce09c8ab008abc4222db26b

commit f43ff3e15c8b4b161ce09c8ab008abc4222db26b
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2024-03-26 03:55:45 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-03-26 03:55:45 +0000

    kern linker: Do not unload a module if it has dependants

    Despite the name, linker_file_unload() will drop a reference and return
    success when the module file has dependants, i.e. it has more than one
    reference. When user request to unload such modules then the kernel
    should reject unambiguously and immediately.

    PR:             274986
    Reviewed by:    dfr, dab, jhb
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D42527

 sys/kern/kern_linker.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 2 commit-hook freebsd_committer freebsd_triage 2024-04-09 04:11:23 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f1994d1eb215a2b7cb644329797dc623ec883120

commit f1994d1eb215a2b7cb644329797dc623ec883120
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2024-03-26 03:55:45 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-04-09 04:10:07 +0000

    kern linker: Do not unload a module if it has dependants

    Despite the name, linker_file_unload() will drop a reference and return
    success when the module file has dependants, i.e. it has more than one
    reference. When user request to unload such modules then the kernel
    should reject unambiguously and immediately.

    PR:             274986
    Reviewed by:    dfr, dab, jhb
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D42527

    (cherry picked from commit f43ff3e15c8b4b161ce09c8ab008abc4222db26b)

 sys/kern/kern_linker.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 3 commit-hook freebsd_committer freebsd_triage 2024-04-09 04:14:24 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a2f57656620d2ffbb8b79789de34a6fc657286d5

commit a2f57656620d2ffbb8b79789de34a6fc657286d5
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2024-03-26 03:55:45 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-04-09 04:13:08 +0000

    kern linker: Do not unload a module if it has dependants

    Despite the name, linker_file_unload() will drop a reference and return
    success when the module file has dependants, i.e. it has more than one
    reference. When user request to unload such modules then the kernel
    should reject unambiguously and immediately.

    PR:             274986
    Reviewed by:    dfr, dab, jhb
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D42527

    (cherry picked from commit f43ff3e15c8b4b161ce09c8ab008abc4222db26b)
    (cherry picked from commit f1994d1eb215a2b7cb644329797dc623ec883120)

 sys/kern/kern_linker.c | 2 ++
 1 file changed, 2 insertions(+)