Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Sep 2019 08:20:13 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r352206 - head/sys/compat/linuxkpi/common/src
Message-ID:  <201909110820.x8B8KD57080569@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Wed Sep 11 08:20:13 2019
New Revision: 352206
URL: https://svnweb.freebsd.org/changeset/base/352206

Log:
  Fix synchronous work drain issue in the LinuxKPI.
  
  A work callback may restart itself. Loop in the drain function to see if the
  work has been rescheduled and stop the subsequent reschedules, if any.
  
  MFC after:		1 week
  Sponsored by:		Mellanox Technologies

Modified:
  head/sys/compat/linuxkpi/common/src/linux_work.c

Modified: head/sys/compat/linuxkpi/common/src/linux_work.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_work.c	Wed Sep 11 07:53:49 2019	(r352205)
+++ head/sys/compat/linuxkpi/common/src/linux_work.c	Wed Sep 11 08:20:13 2019	(r352206)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2017 Hans Petter Selasky
+ * Copyright (c) 2017-2019 Hans Petter Selasky
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -323,24 +323,26 @@ linux_cancel_work_sync(struct work_struct *work)
 		[WORK_ST_CANCEL] = WORK_ST_IDLE,	/* cancel and drain */
 	};
 	struct taskqueue *tq;
+	bool retval = false;
 
 	WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
 	    "linux_cancel_work_sync() might sleep");
-
+retry:
 	switch (linux_update_state(&work->state, states)) {
 	case WORK_ST_IDLE:
 	case WORK_ST_TIMER:
-		return (0);
+		return (retval);
 	case WORK_ST_EXEC:
 		tq = work->work_queue->taskqueue;
 		if (taskqueue_cancel(tq, &work->work_task, NULL) != 0)
 			taskqueue_drain(tq, &work->work_task);
-		return (0);
+		goto retry;	/* work may have restarted itself */
 	default:
 		tq = work->work_queue->taskqueue;
 		if (taskqueue_cancel(tq, &work->work_task, NULL) != 0)
 			taskqueue_drain(tq, &work->work_task);
-		return (1);
+		retval = true;
+		goto retry;
 	}
 }
 
@@ -421,18 +423,19 @@ linux_cancel_delayed_work_sync(struct delayed_work *dw
 		[WORK_ST_CANCEL] = WORK_ST_IDLE,	/* cancel and drain */
 	};
 	struct taskqueue *tq;
+	bool retval = false;
 
 	WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
 	    "linux_cancel_delayed_work_sync() might sleep");
-
+retry:
 	switch (linux_update_state(&dwork->work.state, states)) {
 	case WORK_ST_IDLE:
-		return (0);
+		return (retval);
 	case WORK_ST_EXEC:
 		tq = dwork->work.work_queue->taskqueue;
 		if (taskqueue_cancel(tq, &dwork->work.work_task, NULL) != 0)
 			taskqueue_drain(tq, &dwork->work.work_task);
-		return (0);
+		goto retry;	/* work may have restarted itself */
 	case WORK_ST_TIMER:
 	case WORK_ST_CANCEL:
 		if (linux_cancel_timer(dwork, 1)) {
@@ -442,14 +445,16 @@ linux_cancel_delayed_work_sync(struct delayed_work *dw
 			 */
 			tq = dwork->work.work_queue->taskqueue;
 			taskqueue_drain(tq, &dwork->work.work_task);
-			return (1);
+			retval = true;
+			goto retry;
 		}
 		/* FALLTHROUGH */
 	default:
 		tq = dwork->work.work_queue->taskqueue;
 		if (taskqueue_cancel(tq, &dwork->work.work_task, NULL) != 0)
 			taskqueue_drain(tq, &dwork->work.work_task);
-		return (1);
+		retval = true;
+		goto retry;
 	}
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909110820.x8B8KD57080569>