Skip to content

Commit 13dd4e0

Browse files
iridesakpm00
authored andcommitted
fsdax: unshare: zero destination if srcmap is HOLE or UNWRITTEN
unshare copies data from source to destination. But if the source is HOLE or UNWRITTEN extents, we should zero the destination, otherwise the HOLE or UNWRITTEN part will be user-visible old data of the new allocated extent. Found by running generic/649 while mounting with -o dax=always on pmem. Link: https://lkml.kernel.org/r/1679483469-2-1-git-send-email-ruansy.fnst@fujitsu.com Fixes: d984648 ("fsdax,xfs: port unshare to fsdax") Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Darrick J. Wong <djwong@kernel.org> Cc: Jan Kara <jack@suse.cz> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Alistair Popple <apopple@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: John Hubbard <jhubbard@nvidia.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f478b99 commit 13dd4e0

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

fs/dax.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,15 +1258,20 @@ static s64 dax_unshare_iter(struct iomap_iter *iter)
12581258
/* don't bother with blocks that are not shared to start with */
12591259
if (!(iomap->flags & IOMAP_F_SHARED))
12601260
return length;
1261-
/* don't bother with holes or unwritten extents */
1262-
if (srcmap->type == IOMAP_HOLE || srcmap->type == IOMAP_UNWRITTEN)
1263-
return length;
12641261

12651262
id = dax_read_lock();
12661263
ret = dax_iomap_direct_access(iomap, pos, length, &daddr, NULL);
12671264
if (ret < 0)
12681265
goto out_unlock;
12691266

1267+
/* zero the distance if srcmap is HOLE or UNWRITTEN */
1268+
if (srcmap->flags & IOMAP_F_SHARED || srcmap->type == IOMAP_UNWRITTEN) {
1269+
memset(daddr, 0, length);
1270+
dax_flush(iomap->dax_dev, daddr, length);
1271+
ret = length;
1272+
goto out_unlock;
1273+
}
1274+
12701275
ret = dax_iomap_direct_access(srcmap, pos, length, &saddr, NULL);
12711276
if (ret < 0)
12721277
goto out_unlock;

0 commit comments

Comments
 (0)