public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Corey Minyard <cminyard@mvista.com>,
	Bodo Stroesser <bstroesser@ts.fujitsu.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 3.10 015/103] ipmi: Fix a race restarting the timer
Date: Wed,  4 Jun 2014 16:24:38 -0700	[thread overview]
Message-ID: <20140604232547.316867017@linuxfoundation.org> (raw)
In-Reply-To: <20140604232546.704156131@linuxfoundation.org>

3.10-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Bodo Stroesser <bstroesser@ts.fujitsu.com>

commit 48e8ac2979920ffa39117e2d725afa3a749bfe8d upstream.

With recent changes it is possible for the timer handler to detect an
idle interface and not start the timer, but the thread to start an
operation at the same time.  The thread will not start the timer in that
instance, resulting in the timer not running.

Instead, move all timer operations under the lock and start the timer in
the thread if it detect non-idle and the timer is not already running.
Moving under locks allows the last timeout to be set in both the thread
and the timer.  'Timer is not running' means that the timer is not
pending and smi_timeout() is not running.  So we need a flag to detect
this correctly.

Also fix a few other timeout bugs: setting the last timeout when the
interrupt has to be disabled and the timer started, and setting the last
timeout in check_start_timer_thread possibly racing with the timer

Signed-off-by: Corey Minyard <cminyard@mvista.com>
Signed-off-by: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/char/ipmi/ipmi_si_intf.c |   46 +++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 18 deletions(-)

--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -244,6 +244,9 @@ struct smi_info {
 	/* The timer for this si. */
 	struct timer_list   si_timer;
 
+	/* This flag is set, if the timer is running (timer_pending() isn't enough) */
+	bool		    timer_running;
+
 	/* The time (in jiffies) the last timeout occurred at. */
 	unsigned long       last_timeout_jiffies;
 
@@ -427,6 +430,13 @@ static void start_clear_flags(struct smi
 	smi_info->si_state = SI_CLEARING_FLAGS;
 }
 
+static void smi_mod_timer(struct smi_info *smi_info, unsigned long new_val)
+{
+	smi_info->last_timeout_jiffies = jiffies;
+	mod_timer(&smi_info->si_timer, new_val);
+	smi_info->timer_running = true;
+}
+
 /*
  * When we have a situtaion where we run out of memory and cannot
  * allocate messages, we just leave them in the BMC and run the system
@@ -439,8 +449,7 @@ static inline void disable_si_irq(struct
 		start_disable_irq(smi_info);
 		smi_info->interrupt_disabled = 1;
 		if (!atomic_read(&smi_info->stop_operation))
-			mod_timer(&smi_info->si_timer,
-				  jiffies + SI_TIMEOUT_JIFFIES);
+			smi_mod_timer(smi_info, jiffies + SI_TIMEOUT_JIFFIES);
 	}
 }
 
@@ -900,15 +909,7 @@ static void sender(void                *
 		list_add_tail(&msg->link, &smi_info->xmit_msgs);
 
 	if (smi_info->si_state == SI_NORMAL && smi_info->curr_msg == NULL) {
-		/*
-		 * last_timeout_jiffies is updated here to avoid
-		 * smi_timeout() handler passing very large time_diff
-		 * value to smi_event_handler() that causes
-		 * the send command to abort.
-		 */
-		smi_info->last_timeout_jiffies = jiffies;
-
-		mod_timer(&smi_info->si_timer, jiffies + SI_TIMEOUT_JIFFIES);
+		smi_mod_timer(smi_info, jiffies + SI_TIMEOUT_JIFFIES);
 
 		if (smi_info->thread)
 			wake_up_process(smi_info->thread);
@@ -997,6 +998,17 @@ static int ipmi_thread(void *data)
 
 		spin_lock_irqsave(&(smi_info->si_lock), flags);
 		smi_result = smi_event_handler(smi_info, 0);
+
+		/*
+		 * If the driver is doing something, there is a possible
+		 * race with the timer.  If the timer handler see idle,
+		 * and the thread here sees something else, the timer
+		 * handler won't restart the timer even though it is
+		 * required.  So start it here if necessary.
+		 */
+		if (smi_result != SI_SM_IDLE && !smi_info->timer_running)
+			smi_mod_timer(smi_info, jiffies + SI_TIMEOUT_JIFFIES);
+
 		spin_unlock_irqrestore(&(smi_info->si_lock), flags);
 		busy_wait = ipmi_thread_busy_wait(smi_result, smi_info,
 						  &busy_until);
@@ -1066,10 +1078,6 @@ static void smi_timeout(unsigned long da
 		     * SI_USEC_PER_JIFFY);
 	smi_result = smi_event_handler(smi_info, time_diff);
 
-	spin_unlock_irqrestore(&(smi_info->si_lock), flags);
-
-	smi_info->last_timeout_jiffies = jiffies_now;
-
 	if ((smi_info->irq) && (!smi_info->interrupt_disabled)) {
 		/* Running with interrupts, only do long timeouts. */
 		timeout = jiffies + SI_TIMEOUT_JIFFIES;
@@ -1091,7 +1099,10 @@ static void smi_timeout(unsigned long da
 
  do_mod_timer:
 	if (smi_result != SI_SM_IDLE)
-		mod_timer(&(smi_info->si_timer), timeout);
+		smi_mod_timer(smi_info, timeout);
+	else
+		smi_info->timer_running = false;
+	spin_unlock_irqrestore(&(smi_info->si_lock), flags);
 }
 
 static irqreturn_t si_irq_handler(int irq, void *data)
@@ -1139,8 +1150,7 @@ static int smi_start_processing(void
 
 	/* Set up the timer that drives the interface. */
 	setup_timer(&new_smi->si_timer, smi_timeout, (long)new_smi);
-	new_smi->last_timeout_jiffies = jiffies;
-	mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES);
+	smi_mod_timer(new_smi, jiffies + SI_TIMEOUT_JIFFIES);
 
 	/*
 	 * Check if the user forcefully enabled the daemon.



  parent reply	other threads:[~2014-06-04 23:49 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-04 23:24 [PATCH 3.10 000/103] 3.10.42-stable review Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 001/103] futex: Add another early deadlock detection check Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 002/103] futex: Prevent attaching to kernel threads Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 003/103] mips: dts: Fix missing device_type="memory" property in memory nodes Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 004/103] ftrace/module: Hardcode ftrace_module_init() call into load_module() Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 008/103] pata_at91: fix ata_host_activate() failure handling Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 010/103] mm: make fixup_user_fault() check the vma access rights too Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 011/103] serial: 8250: Fix thread unsafe __dma_tx_complete function Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 012/103] 8250_core: Fix unwanted TX chars write Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 013/103] gpu: host1x: handle the correct # of syncpt regs Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 014/103] timer: Prevent overflow in apply_slack Greg Kroah-Hartman
2014-06-04 23:24 ` Greg Kroah-Hartman [this message]
2014-06-04 23:24 ` [PATCH 3.10 016/103] ipmi: Reset the KCS timeout when starting error recovery Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 017/103] mac80211: fix suspend vs. authentication race Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 018/103] mm, thp: close race between mremap() and split_huge_page() Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 019/103] x86, mm, hugetlb: Add missing TLB page invalidation for hugetlb_cow() Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 020/103] hwpoison, hugetlb: lock_page/unlock_page does not match for handling a free hugepage Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 021/103] mac80211: fix on-channel remain-on-channel Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 022/103] hwmon: (emc1403) fix inverted store_hyst() Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 023/103] hwmon: (emc1403) Support full range of known chip revision numbers Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 024/103] drivercore: deferral race condition fix Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 025/103] hrtimer: Prevent all reprogramming if hang detected Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 026/103] hrtimer: Prevent remote enqueue of leftmost timers Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 027/103] hrtimer: Set expiry time before switch_hrtimer_base() Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 028/103] md: avoid possible spinning md thread at shutdown Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 029/103] drm/i915: Break encoder->crtc link separately in intel_sanitize_crtc() Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 032/103] drm/tegra: Remove gratuitous pad field Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 033/103] iio:imu:mpu6050: Fixed segfault in Invensens MPU driver due to null dereference Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 034/103] fsl-usb: do not test for PHY_CLK_VALID bit on controller version 1.6 Greg Kroah-Hartman
2014-06-04 23:24 ` [PATCH 3.10 035/103] usb: gadget: at91-udc: fix irq and iomem resource retrieval Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 038/103] usb: storage: shuttle_usbat: fix discs being detected twice Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 039/103] USB: Nokia 305 should be treated as unusual dev Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 040/103] USB: Nokia 5300 " Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 041/103] rt2x00: fix beaconing on USB Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 042/103] ALSA: usb-audio: work around corrupted TEAC UD-H01 feedback data Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 043/103] Bluetooth: Fix triggering BR/EDR L2CAP Connect too early Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 044/103] Bluetooth: Fix redundant encryption request for reauthentication Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 045/103] Bluetooth: Add support for Lite-on [04ca:3007] Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 046/103] posix_acl: handle NULL ACL in posix_acl_equiv_mode Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 047/103] [media] omap3isp: Defer probe when the IOMMU is not available Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 048/103] ARM: dts: i.MX53: Fix ipu register space size Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 049/103] ARM: 8012/1: kdump: Avoid overflow when converting pfn to physaddr Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 050/103] rtl8192cu: Fix unbalanced irq enable in error path of rtl92cu_hw_init() Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 051/103] drm/nouveau/acpi: allow non-optimus setups to load vbios from acpi Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 053/103] leds: leds-pwm: properly clean up after probe failure Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 054/103] brcmsmac: fix deadlock on missing firmware Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 055/103] Documentation: Update stable address in Chinese and Japanese translations Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 056/103] crypto: crypto_wq - Fix late crypto work queue initialization Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 057/103] clk: vexpress: NULL dereference on error path Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 059/103] i2c: i801: Add Device IDs for Intel Wildcat Point-LP PCH Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 060/103] i2c: i801: enable Intel BayTrail SMBUS Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 061/103] Drivers: hv: vmbus: Negotiate version 3.0 when running on ws2012r2 hosts Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 062/103] trace: module: Maintain a valid user count Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 063/103] Input: atkbd - fix keyboard not working on some LG laptops Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 064/103] Input: elantech - fix touchpad initialization on Gigabyte U2442 Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 065/103] Input: synaptics - add min/max quirk for the ThinkPad W540 Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 066/103] Input: synaptics - T540p - unify with other LEN0034 models Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 067/103] ALSA: hda - Fix onboard audio on Intel H97/Z97 chipsets Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 068/103] NFSd: Move default initialisers from create_client() to alloc_client() Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 069/103] NFSd: call rpc_destroy_wait_queue() from free_client() Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 070/103] NFSD: Call ->set_acl with a NULL ACL structure if no entries Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 071/103] nfsd4: warn on finding lockowner without stateids Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 072/103] nfsd4: remove lockowner when removing lock stateid Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 073/103] workqueue: fix bugs in wq_update_unbound_numa() failure path Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 074/103] workqueue: fix a possible race condition between rescuer and pwq-release Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 075/103] workqueue: make rescuer_thread() empty wq->maydays list before exiting Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 076/103] bus: mvebu-mbus: allow several windows with the same target/attribute Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 077/103] percpu: make pcpu_alloc_chunk() use pcpu_mem_free() instead of kfree() Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 080/103] ASoC: wm8962: Update register CLASS_D_CONTROL_1 to be non-volatile Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 081/103] metag: fix memory barriers Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 082/103] metag: Reduce maximum stack size to 256MB Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 083/103] x86-64, modify_ldt: Make support for 16-bit segments a runtime option Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 084/103] genirq: Provide irq_force_affinity fallback for non-SMP Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 085/103] PCI: shpchp: Check bridges secondary (not primary) bus speed Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 086/103] Target/iser: Fix wrong connection requests list addition Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 087/103] Target/iser: Fix iscsit_accept_np and rdma_cm racy flow Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 088/103] target: Dont allow setting WC emulation if device doesnt support Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 089/103] powerpc/tm: Fix crash when forking inside a transaction Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 090/103] dm crypt: fix cpu hotplug crash by removing per-cpu structure Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 091/103] libata: clean up ZPODD when a port is detached Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 092/103] ACPI / blacklist: Add dmi_enable_osi_linux quirk for Asus EEE PC 1015PX Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 093/103] i2c: rcar: bail out on zero length transfers Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 094/103] i2c: designware: Mask all interrupts during i2c controller enable Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 095/103] i2c: s3c2410: resume race fix Greg Kroah-Hartman
2014-06-04 23:25 ` [PATCH 3.10 096/103] crypto: caam - add allocation failure handling in SPRINTFCAT macro Greg Kroah-Hartman
2014-06-04 23:26 ` [PATCH 3.10 097/103] crypto: s390 - fix aes,des ctr mode concurrency finding Greg Kroah-Hartman
2014-06-04 23:26 ` [PATCH 3.10 098/103] powerpc: Fix 64 bit builds with binutils 2.24 Greg Kroah-Hartman
2014-06-04 23:26 ` [PATCH 3.10 099/103] libceph: fix corruption when using page_count 0 page in rbd Greg Kroah-Hartman
2014-06-04 23:26 ` [PATCH 3.10 100/103] iommu/amd: Fix interrupt remapping for aliased devices Greg Kroah-Hartman
2014-06-04 23:26 ` [PATCH 3.10 101/103] media: fc2580: fix tuning failure on 32-bit arch Greg Kroah-Hartman
2014-06-04 23:26 ` [PATCH 3.10 102/103] media: V4L2: ov7670: fix a wrong index, potentially Oopsing the kernel from user-space Greg Kroah-Hartman
2014-06-04 23:26 ` [PATCH 3.10 103/103] media: V4L2: fix VIDIOC_CREATE_BUFS in 64- / 32-bit compatibility mode Greg Kroah-Hartman
     [not found] ` <20140604232547.006861681@linuxfoundation.org>
2014-06-05 16:05   ` [PATCH 3.10 005/103] irqchip: Gic: Support forced affinity setting Mark Rutland
2014-06-05 18:05     ` Greg Kroah-Hartman
2014-06-05 18:10       ` Mark Rutland
2014-06-23 11:17       ` Mark Brown
2014-06-05 17:15 ` [PATCH 3.10 000/103] 3.10.42-stable review Guenter Roeck
2014-06-05 17:55 ` Shuah Khan
2014-06-05 23:20 ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140604232547.316867017@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=bstroesser@ts.fujitsu.com \
    --cc=cminyard@mvista.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox