Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Mar 2019 01:18:40 +0000 (UTC)
From:      Marcin Wojtas <mw@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r344676 - head/sys/kern
Message-ID:  <201903010118.x211IeVj027670@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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@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);
 



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