NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

PR/57870 CVS commit: src/sys/dev/sdmmc



The following reply was made to PR kern/57870; it has been noted by GNATS.

From: "Taylor R Campbell" <riastradh%netbsd.org@localhost>
To: gnats-bugs%gnats.NetBSD.org@localhost
Cc: 
Subject: PR/57870 CVS commit: src/sys/dev/sdmmc
Date: Tue, 23 Jan 2024 23:13:05 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Jan 23 23:13:05 UTC 2024
 
 Modified Files:
 	src/sys/dev/sdmmc: ld_sdmmc.c
 
 Log Message:
 ld@sdmmc(4): Hack around deadlock in cache sync on detach.
 
 Yanking a card triggers the sdmmc discovery task, which runs in the
 sdmmc task thread, to detach any attached child devices.
 
 Detaching ld@sdmmc triggers a cache flush (via ldbegindetach ->
 disk_begindetach -> ld_lastclose -> ld_flush -> ioctl DIOCCACHESYNC),
 which is implemented by scheduling a task to do sdmmc_mem_flush_cache
 and then waiting for it to complete.
 
 The sdmmc_mem_cache_flush is done by an sdmmc task so it happens
 after all previously scheduled I/O operations -- that way the cache
 flush doesn't complete until the previously scheduled I/O operations
 are complete.
 
 However, when the cache flush task is issued from the discovery task,
 this doesn't work, because the cache flush task can't start until the
 discovery task has returned -- but the discovery task won't return
 until the cache flush task has completed.
 
 To work around this deadlock, which usually happens only when the
 device has been yanked anyway so further I/O would be lost anyway,
 just do the cache flush synchronously in DIOCCACHESYNC if we're
 running in the task thread.
 
 This isn't quite right -- implementation details of the task thread
 shouldn't bleed into ld@sdmmc, and running the cache sync _before_
 any subsequently scheduled I/O tasks is asking for trouble -- but it
 should serve to avoid the deadlock in PR kern/57870 until we can fix
 a host of concurrency bugs in sdmmc by fixing the locking scheme and
 running discovery in a separate thread from tasks.
 
 XXX pullup-10
 
 
 To generate a diff of this commit:
 cvs rdiff -u -r1.42 -r1.43 src/sys/dev/sdmmc/ld_sdmmc.c
 
 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.
 


Home | Main Index | Thread Index | Old Index