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
This commit is contained in:
parent
c0873ea614
commit
ad1be94443
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user