Bug 267869 - iwlwifi cannot kldunload after device is attached
Summary: iwlwifi cannot kldunload after device is attached
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: wireless (show other bugs)
Version: 13.1-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Bjoern A. Zeeb
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-19 21:12 UTC by Peter Much
Modified: 2022-11-28 17:30 UTC (History)
3 users (show)

See Also:
bz: mfc-stable13?
bz: mfc-stable12-


Attachments
wait for completion without resetting condition (579 bytes, patch)
2022-11-19 21:12 UTC, Peter Much
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Much 2022-11-19 21:12:42 UTC
Created attachment 238184 [details]
wait for completion without resetting condition

When trying to kldunload if_iwlwifi, the command will not succeed and neither fail. It will instead hang forever in the "completi" wchan.

The exact location is in the first line of iwl-drv.c:iwl_drv_stop():
    wait_for_completion(&drv->request_firmware_complete);

This behaviour was introduced by change f808c43ad9234670 
    "iwlwifi: enforce FreeBSD specific (expected) behaviour" 
which now does another wait_for_completion() already in iwl_drv_start().

The problem is that wait_for_completion() apparently does not only wait for the condition, but also reset the condition, and so the now second invocation in iwl_drv_stop does wait forever for a condition that will not appear again.

I created a quick workaround patch - without bothering to understand the intended use of the completion, or the use of the sleepq, so this should be rewritten more nicely - but it works for now so we can focus on the other issues.
Comment 1 Bjoern A. Zeeb freebsd_committer freebsd_triage 2022-11-21 19:53:26 UTC
Can you try this one:
https://people.freebsd.org/~bz/tmp/20221121-01-iwlwifi-completion.diff
Comment 2 Peter Much 2022-11-21 21:19:44 UTC
Ah, torch relay ;)
Thank You. Installed, and did work thru a couple of unload/load.
Comment 3 Bjoern A. Zeeb freebsd_committer freebsd_triage 2022-11-21 21:56:24 UTC
(In reply to Peter Much from comment #2)

Thanks a lot for reporting and testing!

I'll commit this tomorrow and then I can go back and looking into the other teardown issues as well.  I found at least two problems so far.  But more about the elsewhere.
Comment 4 commit-hook freebsd_committer freebsd_triage 2022-11-22 17:46:21 UTC
A commit in branch main references this bug:

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

commit bee60c98974593d25aa18743f9413a78e0d57dc9
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-11-22 17:29:41 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-11-22 17:29:41 +0000

    iwlwifi: fix hang on unloading driver

    f808c43ad9234670770601ba32a7426b00bbf528 introduced a FreeBSD specific
    behaviour to wait for firmware load completion before returning from
    loading the driver.  This does no longer allow iwl_drv_stop to detect
    that startup has completed and it will wait indefinitely for a
    completion event that will not happen.
    We could change the complete() call to a complete_all() but to avoid
    confusion, future side effects, and for simplicity daisy-chain two
    complete events in FreeBSD.

    PR:             267869
    Reported by:    Peter Much (pmc citylink.dinoex.sub.org)
    Tested by:      Peter Much (pmc citylink.dinoex.sub.org)
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days

 sys/contrib/dev/iwlwifi/iwl-drv.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Comment 5 commit-hook freebsd_committer freebsd_triage 2022-11-28 17:27:58 UTC
A commit in branch stable/13 references this bug:

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

commit 46c09d766d265a886a7fd11ee5dd88bb17e9a0af
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-11-22 17:29:41 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-11-28 16:34:46 +0000

    iwlwifi: fix hang on unloading driver

    f808c43ad9234670770601ba32a7426b00bbf528 introduced a FreeBSD specific
    behaviour to wait for firmware load completion before returning from
    loading the driver.  This does no longer allow iwl_drv_stop to detect
    that startup has completed and it will wait indefinitely for a
    completion event that will not happen.
    We could change the complete() call to a complete_all() but to avoid
    confusion, future side effects, and for simplicity daisy-chain two
    complete events in FreeBSD.

    PR:             267869
    Reported by:    Peter Much (pmc citylink.dinoex.sub.org)
    Tested by:      Peter Much (pmc citylink.dinoex.sub.org)
    Sponsored by:   The FreeBSD Foundation

    (cherry picked from commit bee60c98974593d25aa18743f9413a78e0d57dc9)

 sys/contrib/dev/iwlwifi/iwl-drv.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Comment 6 Bjoern A. Zeeb freebsd_committer freebsd_triage 2022-11-28 17:30:13 UTC
Now also merged to stable/13.
Thanks a lot again for reporting and testing the change!