linux/drivers/char/ipmi
Masamitsu Yamazaki 4f7f5551a7 ipmi: Stop timers before cleaning up the module
System may crash after unloading ipmi_si.ko module
because a timer may remain and fire after the module cleaned up resources.

cleanup_one_si() contains the following processing.

        /*
         * Make sure that interrupts, the timer and the thread are
         * stopped and will not run again.
         */
        if (to_clean->irq_cleanup)
                to_clean->irq_cleanup(to_clean);
        wait_for_timer_and_thread(to_clean);

        /*
         * Timeouts are stopped, now make sure the interrupts are off
         * in the BMC.  Note that timers and CPU interrupts are off,
         * so no need for locks.
         */
        while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
                poll(to_clean);
                schedule_timeout_uninterruptible(1);
        }

si_state changes as following in the while loop calling poll(to_clean).

  SI_GETTING_MESSAGES
    => SI_CHECKING_ENABLES
     => SI_SETTING_ENABLES
      => SI_GETTING_EVENTS
       => SI_NORMAL

As written in the code comments above,
timers are expected to stop before the polling loop and not to run again.
But the timer is set again in the following process
when si_state becomes SI_SETTING_ENABLES.

  => poll
     => smi_event_handler
       => handle_transaction_done
          // smi_info->si_state == SI_SETTING_ENABLES
         => start_getting_events
           => start_new_msg
            => smi_mod_timer
              => mod_timer

As a result, before the timer set in start_new_msg() expires,
the polling loop may see si_state becoming SI_NORMAL
and the module clean-up finishes.

For example, hard LOCKUP and panic occurred as following.
smi_timeout was called after smi_event_handler,
kcs_event and hangs at port_inb()
trying to access I/O port after release.

    [exception RIP: port_inb+19]
    RIP: ffffffffc0473053  RSP: ffff88069fdc3d80  RFLAGS: 00000006
    RAX: ffff8806800f8e00  RBX: ffff880682bd9400  RCX: 0000000000000000
    RDX: 0000000000000ca3  RSI: 0000000000000ca3  RDI: ffff8806800f8e40
    RBP: ffff88069fdc3d80   R8: ffffffff81d86dfc   R9: ffffffff81e36426
    R10: 00000000000509f0  R11: 0000000000100000  R12: 0000000000]:000000
    R13: 0000000000000000  R14: 0000000000000246  R15: ffff8806800f8e00
    ORIG_RAX: ffffffffffffffff  CS: 0010  SS: 0000
 --- <NMI exception stack> ---

To fix the problem I defined a flag, timer_can_start,
as member of struct smi_info.
The flag is enabled immediately after initializing the timer
and disabled immediately before waiting for timer deletion.

Fixes: 0cfec916e8 ("ipmi: Start the timer and thread on internal msgs")
Signed-off-by: Yamazaki Masamitsu <m-yamazaki@ah.jp.nec.com>
[Adjusted for recent changes in the driver.]
Signed-off-by: Corey Minyard <cminyard@mvista.com>
2017-12-06 07:13:03 -06:00
..
Kconfig ipmi: Make the IPMI proc interface configurable 2017-09-28 12:26:03 -05:00
Makefile IPMI updates for 4.15 2017-11-15 15:12:28 -08:00
bt-bmc.c ipmi: bt-bmc: Add ast2500 compatible string 2017-04-07 12:25:38 -05:00
ipmi_bt_sm.c ipmi: Make some data const that was only read 2015-09-03 15:02:27 -05:00
ipmi_devintf.c ipmi: get rid of field-by-field __get_user() 2017-06-26 17:02:54 -04:00
ipmi_dmi.c IPMI updates for 4.15 2017-11-15 15:12:28 -08:00
ipmi_dmi.h IPMI updates for 4.15 2017-11-15 15:12:28 -08:00
ipmi_kcs_sm.c ipmi: Make some data const that was only read 2015-09-03 15:02:27 -05:00
ipmi_msghandler.c ipmi: remove redundant initialization of bmc 2017-09-28 12:29:44 -05:00
ipmi_powernv.c ipmi: Remove the device id from ipmi_register_smi() 2017-09-27 16:03:45 -05:00
ipmi_poweroff.c Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux into for-next 2017-11-02 11:19:15 -05:00
ipmi_si.h ipmi_si: Move port and mem I/O handling to their own files 2017-09-28 12:26:00 -05:00
ipmi_si_hardcode.c ipmi_si: Move hardcode handling to a separate file. 2017-09-27 16:03:45 -05:00
ipmi_si_hotmod.c Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux into for-next 2017-11-02 11:19:15 -05:00
ipmi_si_intf.c ipmi: Stop timers before cleaning up the module 2017-12-06 07:13:03 -06:00
ipmi_si_mem_io.c ipmi_si: Move port and mem I/O handling to their own files 2017-09-28 12:26:00 -05:00
ipmi_si_parisc.c ipmi_si: Move PARISC handling to another file 2017-09-28 12:25:58 -05:00
ipmi_si_pci.c ipmi_si: Move PCI setup to another file 2017-09-28 12:25:50 -05:00
ipmi_si_platform.c ipmi: Make the DMI probe into a generic platform probe 2017-09-28 12:26:03 -05:00
ipmi_si_port_io.c ipmi_si: Move port and mem I/O handling to their own files 2017-09-28 12:26:00 -05:00
ipmi_si_sm.h ipmi: Make the DMI probe into a generic platform probe 2017-09-28 12:26:03 -05:00
ipmi_smic_sm.c ipmi: Make some data const that was only read 2015-09-03 15:02:27 -05:00
ipmi_ssif.c ipmi: Make the DMI probe into a generic platform probe 2017-09-28 12:26:03 -05:00
ipmi_watchdog.c ipmi: Get the device id through a function 2017-09-27 16:03:45 -05:00