Re: [PATCH] splice: prevent deadlock when splicing a file to itself
From: Deepanshu Kartikey
Date: Wed Apr 01 2026 - 04:43:22 EST
On Wed, Apr 01, 2026, Jan Kara wrote:
> Hum, I'm probably missing something but I just
> don't see how the proposed deadlock is supposed
> to happen.
You are correct, I apologize for the incorrect
analysis in the patch description.
After looking more carefully at the code, the
actual deadlock involves sendfile() and a
concurrent fallocate() on the same inode:
1. sendfile() write side calls blkdev_write_iter()
which acquires inode_lock_shared().
2. Concurrent fallocate() calls blkdev_fallocate()
which tries inode_lock() (exclusive) and blocks
waiting for the shared lock to be released.
3. sendfile() read side then calls
blkdev_read_iter() which tries
inode_lock_shared() but is blocked because
rwsem prevents new readers when a writer
is waiting.
This creates a circular dependency where nobody
can proceed, causing the hung task.
My original patch was fixing the wrong thing.
I will investigate the correct fix.
Thank you for the careful review!