public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Corey Minyard <corey@minyard.net>
To: stable@vger.kernel.org
Cc: Corey Minyard <corey@minyard.net>
Subject: [PATCH 5.15.y] ipmi:ssif: Fix a thread shutdown issue
Date: Fri,  1 May 2026 11:11:41 -0500	[thread overview]
Message-ID: <20260501161407.1106914-1-corey@minyard.net> (raw)
In-Reply-To: <2026050148-politely-tabloid-3059@gregkh>

The kthread used by ssif had a shutdown issue that was fixed by
6bd0eb6d759b ("ipmi:ssif: Fix a shutdown race").  That was backported to
an older kernel in the process of fixing another issue,
2105b70be84d ("ipmi:ssif: Clean up kthread on errors") as it would
not have worked correctly without the shutdown race fix.

Kernel version 6.1 has a fix to kthread stop to cause interruptible
waits to return -ERESTARTSYS on a stop.  This has not been backported
to older kernels, and that would probably be a bad idea.  But not
having this means that the completion in the SSIF driver will
not wake up on kthread_stop(), thus the driver hangs on unload.

We can't cause the interrupt before calling kthread_stop() because
the task stop bit need to be set before causing the interrupt.

So re-introduce the code removed by 6bd0eb6d759b ("ipmi:ssif: Fix a
shutdown race") but add a wait at the end of the thread so it
doesn't exit until kthread_should_stop() is set.

Fixes: 6bd0eb6d759b ("ipmi:ssif: Fix a shutdown race")
Signed-off-by: Corey Minyard <corey@minyard.net>
---
I realized I hadn't done an unload test on this on the older kernels.
But why wouldn't that work?  Well, it didn't.  One more patch for this
on top of the previous two.  Sorry :(.


 drivers/char/ipmi/ipmi_ssif.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index ce0f20cac88d..b884bfae7fa6 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -487,6 +487,8 @@ static int ipmi_ssif_thread(void *data)
 		/* Wait for something to do */
 		result = wait_for_completion_interruptible(
 						&ssif_info->wake_thread);
+		if (ssif_info->stopping)
+			break;
 		if (result == -ERESTARTSYS)
 			continue;
 		init_completion(&ssif_info->wake_thread);
@@ -511,6 +513,16 @@ static int ipmi_ssif_thread(void *data)
 		}
 	}
 
+	/*
+	 * The thread can break out of the loop if stopping is set,
+	 * and this can be before kthread_stop() gets called and thus
+	 * kthread_should_stop() will not be set.  This can cause
+	 * spinning calling this function and other bad things.  So
+	 * wait for kthread_should_stop() to be set.
+	 */
+	while (!kthread_should_stop())
+		msleep_interruptible(1);
+
 	return 0;
 }
 
@@ -1278,6 +1290,7 @@ static void shutdown_ssif(void *send_info)
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
 	if (ssif_info->thread) {
+		complete(&ssif_info->wake_thread);
 		kthread_stop(ssif_info->thread);
 		ssif_info->thread = NULL;
 	}
@@ -1916,6 +1929,8 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		 * it to NULL.  Otherwise it must be freed here.
 		 */
 		if (ssif_info->thread) {
+			ssif_info->stopping = true;
+			complete(&ssif_info->wake_thread);
 			kthread_stop(ssif_info->thread);
 			ssif_info->thread = NULL;
 		}
-- 
2.43.0


  parent reply	other threads:[~2026-05-01 16:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.15-stable tree gregkh
2026-05-01 14:27 ` [PATCH 5.15.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 14:27   ` [PATCH 5.15.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-01 16:11 ` Corey Minyard [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.10-stable tree gregkh
2026-05-01 14:54 ` [PATCH 5.10.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 14:54   ` [PATCH 5.10.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-01 16:20 ` [PATCH 5.10.y] ipmi:ssif: Fix a thread shutdown issue Corey Minyard
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.1-stable tree gregkh
2026-05-01 14:19 ` [PATCH 6.1.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 14:19   ` [PATCH 6.1.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.6-stable tree gregkh
2026-05-01 14:06 ` [PATCH 6.6.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 14:06   ` [PATCH 6.6.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.12-stable tree gregkh
2026-05-01 13:56 ` [PATCH 6.12.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 13:56   ` [PATCH 6.12.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-03 18:19   ` [PATCH 6.12.y/6.6.y/6.1.y/5.15.y/5.10.y 1-2/2] ipmi:ssif: shutdown race + kthread cleanup Sasha Levin
2026-05-04 11:04     ` Corey Minyard

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=20260501161407.1106914-1-corey@minyard.net \
    --to=corey@minyard.net \
    --cc=stable@vger.kernel.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