svn commit: r344676 - head/sys/kern

Marcin Wojtas mw at FreeBSD.org
Fri Mar 1 01:18:40 UTC 2019


Author: mw
Date: Fri Mar  1 01:18:39 2019
New Revision: 344676
URL: https://svnweb.freebsd.org/changeset/base/344676

Log:
  Prevent detaching driver if the attach is not finished
  
  When the device is in attaching state, detach should return
  EBUSY instead of success. In other case, there could be race
  between attach and detach during the driver unloading.
  
  If driver goes sleep and releases GIANT lock during attaching,
  unloading module could start. In such case when attach continues
  after module unload, page fault "supervisor read instruction,
  page not present" occurred.
  
  This patch works around the real issue, which is a locking
  deficiency of the busses.
  
  Submitted by: Rafal Kozik <rk at semihalf.com>
  Reviewed by: imp
  Obtained from: Semihalf
  MFC after: 2 weeks
  Sponsored by: Amazon, Inc.
  Differential Revision: https://reviews.freebsd.org/D19375

Modified:
  head/sys/kern/subr_bus.c

Modified: head/sys/kern/subr_bus.c
==============================================================================
--- head/sys/kern/subr_bus.c	Thu Feb 28 23:00:47 2019	(r344675)
+++ head/sys/kern/subr_bus.c	Fri Mar  1 01:18:39 2019	(r344676)
@@ -3004,6 +3004,10 @@ device_detach(device_t dev)
 	PDEBUG(("%s", DEVICENAME(dev)));
 	if (dev->state == DS_BUSY)
 		return (EBUSY);
+	if (dev->state == DS_ATTACHING) {
+		device_printf(dev, "device in attaching state! Deferring detach.\n");
+		return (EBUSY);
+	}
 	if (dev->state != DS_ATTACHED)
 		return (0);
 


More information about the svn-src-all mailing list