freebsd-dev/sys/dev/ipmi
Chuck Silvers f0f3e3e961 ipmi: use a queue for kcs driver requests when possible
The ipmi watchdog pretimeout action can trigger unintentionally in
certain rare, complicated situations.  What we have seen at Netflix
is that the BMC can sometimes be sent a continuous stream of
writes to port 0x80, and due to what is a bug or misconfiguration
in the BMC software, this results in the BMC running out of memory,
becoming very slow to respond to KCS requests, and eventually being
rebooted by its own internal watchdog.  While that is going on in
the BMC, back in the host OS, a number of requests are pending in
the ipmi request queue, and the kcs_loop thread is working on
processing these requests.  All of the KCS accesses to process
those requests are timing out and eventually failing because the
BMC is responding very slowly or not at all, and the kcs_loop thread
is holding the IPMI_IO_LOCK the whole time that is going on.
Meanwhile the watchdogd process in the host is trying to pat the
BMC watchdog, and this process is sleeping waiting to get the
IPMI_IO_LOCK.  It's not entirely clear why the watchdogd process
is sleeping for this lock, because the intention is that a thread
holding the IPMI_IO_LOCK should not sleep and thus any thread
that wants the lock should just spin to wait for it.  My best guess
is that the kcs_loop thread is spinning waiting for the BMC to
respond for so long that it is eventually preempted, and during
the brief interval when the kcs_loop thread is not running,
the watchdogd thread notices that the lock holder is not running
and sleeps.  When the kcs_loop thread eventually finishes processing
one request, it drops the IPMI_IO_LOCK and then immediately takes the
lock again so it can process the next request in the queue.
Because the watchdogd thread is sleeping at this point, the kcs_loop
always wins the race to acquire the IPMI_IO_LOCK, thus starving
the watchdogd thread.  The callout for the watchdog pretimeout
would be reset by the watchdogd thread after its request to the BMC
watchdog completes, but since that request never processed, the
pretimeout callout eventually fires, even though there is nothing
actually wrong with the host.

To prevent this saga from unfolding:

 - when kcs_driver_request() is called in a context where it can sleep,
   queue the request and let the worker thread process it rather than
   trying to process in the original thread.
 - add a new high-priority queue for driver requests, so that the
   watchdog patting requests will be processed as quickly as possible
   even if lots of application requests have already been queued.

With these two changes, the watchdog pretimeout action does not trigger
even if the BMC is completely out to lunch for long periods of time
(as long as the watchdogd check command does not also get stuck).

Sponsored by:	Netflix
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D36555
2022-11-01 10:55:14 -07:00
..
ipmi_acpi.c ipmi: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 12:22:02 -07:00
ipmi_isa.c impi(4): Fix two typos in source code comments 2022-09-03 14:52:44 +02:00
ipmi_kcs.c ipmi: use a queue for kcs driver requests when possible 2022-11-01 10:55:14 -07:00
ipmi_linux.c
ipmi_opal.c ipmi: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 12:22:02 -07:00
ipmi_pci.c ipmi: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 12:22:02 -07:00
ipmi_smbios.c pmap_unmapdev/bios: Accept a pointer instead of a vm_offset_t. 2022-09-22 15:08:52 -07:00
ipmi_smbus.c ipmi: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 12:22:02 -07:00
ipmi_smic.c
ipmi_ssif.c ipmi_ssif: Fix inverted for the end of multi-part reads 2021-02-18 15:48:01 +00:00
ipmi.c ipmi: use a queue for kcs driver requests when possible 2022-11-01 10:55:14 -07:00
ipmivars.h ipmi: use a queue for kcs driver requests when possible 2022-11-01 10:55:14 -07:00