Skip to content

Commit 1cea335

Browse files
Christoph Hellwigdjwong
authored andcommitted
iomap: fix sub-page uptodate handling
bio completions can race when a page spans more than one file system block. Add a spinlock to synchronize marking the page uptodate. Fixes: 9dc55f1 ("iomap: add support for sub-pagesize buffered I/O without buffer heads") Reported-by: Jan Stancek <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 88cfd30 commit 1cea335

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

fs/iomap/buffered-io.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
struct iomap_page {
2929
atomic_t read_count;
3030
atomic_t write_count;
31+
spinlock_t uptodate_lock;
3132
DECLARE_BITMAP(uptodate, PAGE_SIZE / 512);
3233
};
3334

@@ -51,6 +52,7 @@ iomap_page_create(struct inode *inode, struct page *page)
5152
iop = kmalloc(sizeof(*iop), GFP_NOFS | __GFP_NOFAIL);
5253
atomic_set(&iop->read_count, 0);
5354
atomic_set(&iop->write_count, 0);
55+
spin_lock_init(&iop->uptodate_lock);
5456
bitmap_zero(iop->uptodate, PAGE_SIZE / SECTOR_SIZE);
5557

5658
/*
@@ -139,25 +141,38 @@ iomap_adjust_read_range(struct inode *inode, struct iomap_page *iop,
139141
}
140142

141143
static void
142-
iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len)
144+
iomap_iop_set_range_uptodate(struct page *page, unsigned off, unsigned len)
143145
{
144146
struct iomap_page *iop = to_iomap_page(page);
145147
struct inode *inode = page->mapping->host;
146148
unsigned first = off >> inode->i_blkbits;
147149
unsigned last = (off + len - 1) >> inode->i_blkbits;
148-
unsigned int i;
149150
bool uptodate = true;
151+
unsigned long flags;
152+
unsigned int i;
150153

151-
if (iop) {
152-
for (i = 0; i < PAGE_SIZE / i_blocksize(inode); i++) {
153-
if (i >= first && i <= last)
154-
set_bit(i, iop->uptodate);
155-
else if (!test_bit(i, iop->uptodate))
156-
uptodate = false;
157-
}
154+
spin_lock_irqsave(&iop->uptodate_lock, flags);
155+
for (i = 0; i < PAGE_SIZE / i_blocksize(inode); i++) {
156+
if (i >= first && i <= last)
157+
set_bit(i, iop->uptodate);
158+
else if (!test_bit(i, iop->uptodate))
159+
uptodate = false;
158160
}
159161

160-
if (uptodate && !PageError(page))
162+
if (uptodate)
163+
SetPageUptodate(page);
164+
spin_unlock_irqrestore(&iop->uptodate_lock, flags);
165+
}
166+
167+
static void
168+
iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len)
169+
{
170+
if (PageError(page))
171+
return;
172+
173+
if (page_has_private(page))
174+
iomap_iop_set_range_uptodate(page, off, len);
175+
else
161176
SetPageUptodate(page);
162177
}
163178

0 commit comments

Comments
 (0)