Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Sep 2019 07:26:44 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r352477 - stable/12/sys/compat/linuxkpi/common/src
Message-ID:  <201909180726.x8I7Qirk006274@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Wed Sep 18 07:26:43 2019
New Revision: 352477
URL: https://svnweb.freebsd.org/changeset/base/352477

Log:
  MFC r352206:
  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.
  
  Sponsored by:		Mellanox Technologies

Modified:
  stable/12/sys/compat/linuxkpi/common/src/linux_work.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/compat/linuxkpi/common/src/linux_work.c
==============================================================================
--- stable/12/sys/compat/linuxkpi/common/src/linux_work.c	Wed Sep 18 07:25:56 2019	(r352476)
+++ stable/12/sys/compat/linuxkpi/common/src/linux_work.c	Wed Sep 18 07:26:43 2019	(r352477)
@@ -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?201909180726.x8I7Qirk006274>