Skip to content

Commit

Permalink
dax: enable dax fault handler to report VM_FAULT_HWPOISON
Browse files Browse the repository at this point in the history
When multiple processes mmap() a dax file, then at some point,
a process issues a 'load' and consumes a hwpoison, the process
receives a SIGBUS with si_code = BUS_MCEERR_AR and with si_lsb
set for the poison scope. Soon after, any other process issues
a 'load' to the poisoned page (that is unmapped from the kernel
side by memory_failure), it receives a SIGBUS with
si_code = BUS_ADRERR and without valid si_lsb.

This is confusing to user, and is different from page fault due
to poison in RAM memory, also some helpful information is lost.

Channel dax backend driver's poison detection to the filesystem
such that instead of reporting VM_FAULT_SIGBUS, it could report
VM_FAULT_HWPOISON.

If user level block IO syscalls fail due to poison, the errno will
be converted to EIO to maintain block API consistency.

Signed-off-by: Jane Chu <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Dan Williams <[email protected]>
Signed-off-by: Vishal Verma <[email protected]>
  • Loading branch information
jchu314atgithub authored and stellarhopper committed Jun 26, 2023
1 parent 95bf6df commit 1ea7ca1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
5 changes: 4 additions & 1 deletion drivers/dax/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
size_t nr_pages)
{
int ret;

if (!dax_alive(dax_dev))
return -ENXIO;
/*
Expand All @@ -213,7 +215,8 @@ int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
if (nr_pages != 1)
return -EIO;

return dax_dev->ops->zero_page_range(dax_dev, pgoff, nr_pages);
ret = dax_dev->ops->zero_page_range(dax_dev, pgoff, nr_pages);
return dax_mem2blk_err(ret);
}
EXPORT_SYMBOL_GPL(dax_zero_page_range);

Expand Down
2 changes: 1 addition & 1 deletion drivers/nvdimm/pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
long actual_nr;

if (mode != DAX_RECOVERY_WRITE)
return -EIO;
return -EHWPOISON;

/*
* Set the recovery stride is set to kernel page size because
Expand Down
3 changes: 2 additions & 1 deletion drivers/s390/block/dcssblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,
rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_ACCESS,
&kaddr, NULL);
if (rc < 0)
return rc;
return dax_mem2blk_err(rc);

memset(kaddr, 0, nr_pages << PAGE_SHIFT);
dax_flush(dax_dev, kaddr, nr_pages << PAGE_SHIFT);
return 0;
Expand Down
11 changes: 6 additions & 5 deletions fs/dax.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ static int dax_iomap_copy_around(loff_t pos, uint64_t length, size_t align_size,
if (!zero_edge) {
ret = dax_iomap_direct_access(srcmap, pos, size, &saddr, NULL);
if (ret)
return ret;
return dax_mem2blk_err(ret);
}

if (copy_all) {
Expand Down Expand Up @@ -1310,7 +1310,7 @@ static s64 dax_unshare_iter(struct iomap_iter *iter)

out_unlock:
dax_read_unlock(id);
return ret;
return dax_mem2blk_err(ret);
}

int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len,
Expand Down Expand Up @@ -1342,7 +1342,8 @@ static int dax_memzero(struct iomap_iter *iter, loff_t pos, size_t size)
ret = dax_direct_access(iomap->dax_dev, pgoff, 1, DAX_ACCESS, &kaddr,
NULL);
if (ret < 0)
return ret;
return dax_mem2blk_err(ret);

memset(kaddr + offset, 0, size);
if (iomap->flags & IOMAP_F_SHARED)
ret = dax_iomap_copy_around(pos, size, PAGE_SIZE, srcmap,
Expand Down Expand Up @@ -1498,15 +1499,15 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,

map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size),
DAX_ACCESS, &kaddr, NULL);
if (map_len == -EIO && iov_iter_rw(iter) == WRITE) {
if (map_len == -EHWPOISON && iov_iter_rw(iter) == WRITE) {
map_len = dax_direct_access(dax_dev, pgoff,
PHYS_PFN(size), DAX_RECOVERY_WRITE,
&kaddr, NULL);
if (map_len > 0)
recovery = true;
}
if (map_len < 0) {
ret = map_len;
ret = dax_mem2blk_err(map_len);
break;
}

Expand Down
3 changes: 2 additions & 1 deletion fs/fuse/virtio_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,8 @@ static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_ACCESS, &kaddr,
NULL);
if (rc < 0)
return rc;
return dax_mem2blk_err(rc);

memset(kaddr, 0, nr_pages << PAGE_SHIFT);
dax_flush(dax_dev, kaddr, nr_pages << PAGE_SHIFT);
return 0;
Expand Down
13 changes: 13 additions & 0 deletions include/linux/dax.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,19 @@ static inline bool dax_mapping(struct address_space *mapping)
return mapping->host && IS_DAX(mapping->host);
}

/*
* Due to dax's memory and block duo personalities, hwpoison reporting
* takes into consideration which personality is presently visible.
* When dax acts like a block device, such as in block IO, an encounter of
* dax hwpoison is reported as -EIO.
* When dax acts like memory, such as in page fault, a detection of hwpoison
* is reported as -EHWPOISON which leads to VM_FAULT_HWPOISON.
*/
static inline int dax_mem2blk_err(int err)
{
return (err == -EHWPOISON) ? -EIO : err;
}

#ifdef CONFIG_DEV_DAX_HMEM_DEVICES
void hmem_register_resource(int target_nid, struct resource *r);
#else
Expand Down
2 changes: 2 additions & 0 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3342,6 +3342,8 @@ static inline vm_fault_t vmf_error(int err)
{
if (err == -ENOMEM)
return VM_FAULT_OOM;
else if (err == -EHWPOISON)
return VM_FAULT_HWPOISON;
return VM_FAULT_SIGBUS;
}

Expand Down

0 comments on commit 1ea7ca1

Please sign in to comment.