From: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx> dax_iomap_cow copies a page before presenting for mmap. Signed-off-by: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx> --- fs/dax.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/fs/dax.c b/fs/dax.c index e254535dd830..21ee3df6f02c 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1269,6 +1269,33 @@ static bool dax_fault_is_synchronous(unsigned long flags, && (iomap->flags & IOMAP_F_DIRTY); } +static int dax_iomap_cow(struct iomap *iomap, loff_t pos, pfn_t *pfn) +{ + void *daddr; + pgoff_t pgoff; + long rc; + int id; + sector_t sector; + + pos = round_down(pos, PAGE_SIZE); + + sector = round_down(iomap->addr + iomap->offset - pos, PAGE_SIZE) >> 9; + rc = bdev_dax_pgoff(iomap->bdev, sector, PAGE_SIZE, &pgoff); + if (rc) + return rc; + + id = dax_read_lock(); + rc = dax_direct_access(iomap->dax_dev, pgoff, 1, &daddr, pfn); + if (rc < 0) + goto out; + + dax_to_dax_copy(iomap, pos, daddr, PAGE_SIZE); + +out: + dax_read_unlock(id); + return rc; +} + static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, int *iomap_errp, const struct iomap_ops *ops) { @@ -1372,7 +1399,11 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, count_memcg_event_mm(vma->vm_mm, PGMAJFAULT); major = VM_FAULT_MAJOR; } - error = dax_iomap_pfn(&iomap, pos, PAGE_SIZE, &pfn); + + if (iomap.flags & IOMAP_F_COW) + error = dax_iomap_cow(&iomap, pos, &pfn); + else + error = dax_iomap_pfn(&iomap, pos, PAGE_SIZE, &pfn); if (error < 0) goto error_finish_iomap; -- 2.16.4