Up till now, dax_direct_access() is used implicitly for normal access, but for the purpose of recovery write, dax range with poison is requested. To make the interface clear, introduce enum dax_access_mode { DAX_ACCESS, DAX_RECOVERY_WRITE, } where DAX_ACCESS is used for normal dax access, and DAX_RECOVERY_WRITE is used for dax recovery write.
Unified · Split
| @@ -117,6 +117,7 @@ enum dax_device_flags { · 116 unmodified lines | ||
| 117 | 117 | * @dax_dev: a dax_device instance representing the logical memory range |
| 118 | 118 | * @pgoff: offset in pages from the start of the device to translate |
| 119 | 119 | * @nr_pages: number of consecutive pages caller can handle relative to @pfn |
| 120 | + * @mode: indicator on normal access or recovery write | |
| 120 | 121 | * @kaddr: output parameter that returns a virtual address mapping of pfn |
| 121 | 122 | * @pfn: output parameter that returns an absolute pfn translation of @pgoff |
| 122 | 123 | * |
| @@ -124,7 +125,7 @@ enum dax_device_flags { · 1 unmodified line | ||
| 124 | 125 | * pages accessible at the device relative @pgoff. |
| 125 | 126 | */ |
| 126 | 127 | long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages, |
| 127 | − void **kaddr, pfn_t *pfn) | |
| 128 | + enum dax_access_mode mode, void **kaddr, pfn_t *pfn) | |
| 128 | 129 | { |
| 129 | 130 | long avail; |
| 130 | 131 | |
| @@ -138,7 +139,7 @@ long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages, · 7 unmodified lines | ||
| 138 | 139 | return -EINVAL; |
| 139 | 140 | |
| 140 | 141 | avail = dax_dev->ops->direct_access(dax_dev, pgoff, nr_pages, |
| 141 | − kaddr, pfn); | |
| 142 | + mode, kaddr, pfn); | |
| 142 | 143 | if (!avail) |
| 143 | 144 | return -ERANGE; |
| 144 | 145 | return min(avail, nr_pages); |
| @@ -172,11 +172,12 @@ static struct dax_device *linear_dax_pgoff(struct dm_target *ti, pgoff_t *pgoff) · 171 unmodified lines | ||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff, |
| 175 | − long nr_pages, void **kaddr, pfn_t *pfn) | |
| 175 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 176 | + pfn_t *pfn) | |
| 176 | 177 | { |
| 177 | 178 | struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff); |
| 178 | 179 | |
| 179 | − return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn); | |
| 180 | + return dax_direct_access(dax_dev, pgoff, nr_pages, mode, kaddr, pfn); | |
| 180 | 181 | } |
| 181 | 182 | |
| 182 | 183 | static int linear_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff, |
| @@ -889,11 +889,12 @@ static struct dax_device *log_writes_dax_pgoff(struct dm_target *ti, · 888 unmodified lines | ||
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | static long log_writes_dax_direct_access(struct dm_target *ti, pgoff_t pgoff, |
| 892 | − long nr_pages, void **kaddr, pfn_t *pfn) | |
| 892 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 893 | + pfn_t *pfn) | |
| 893 | 894 | { |
| 894 | 895 | struct dax_device *dax_dev = log_writes_dax_pgoff(ti, &pgoff); |
| 895 | 896 | |
| 896 | − return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn); | |
| 897 | + return dax_direct_access(dax_dev, pgoff, nr_pages, mode, kaddr, pfn); | |
| 897 | 898 | } |
| 898 | 899 | |
| 899 | 900 | static int log_writes_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff, |
| @@ -315,11 +315,12 @@ static struct dax_device *stripe_dax_pgoff(struct dm_target *ti, pgoff_t *pgoff) · 314 unmodified lines | ||
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | static long stripe_dax_direct_access(struct dm_target *ti, pgoff_t pgoff, |
| 318 | − long nr_pages, void **kaddr, pfn_t *pfn) | |
| 318 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 319 | + pfn_t *pfn) | |
| 319 | 320 | { |
| 320 | 321 | struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff); |
| 321 | 322 | |
| 322 | − return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn); | |
| 323 | + return dax_direct_access(dax_dev, pgoff, nr_pages, mode, kaddr, pfn); | |
| 323 | 324 | } |
| 324 | 325 | |
| 325 | 326 | static int stripe_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff, |
| @@ -10,6 +10,7 @@ · 9 unmodified lines | ||
| 10 | 10 | #include <linux/init.h> |
| 11 | 11 | #include <linux/kmod.h> |
| 12 | 12 | #include <linux/bio.h> |
| 13 | +#include <linux/dax.h> | |
| 13 | 14 | |
| 14 | 15 | #define DM_MSG_PREFIX "target" |
| 15 | 16 | |
| @@ -142,7 +143,8 @@ static void io_err_release_clone_rq(struct request *clone, · 126 unmodified lines | ||
| 142 | 143 | } |
| 143 | 144 | |
| 144 | 145 | static long io_err_dax_direct_access(struct dm_target *ti, pgoff_t pgoff, |
| 145 | − long nr_pages, void **kaddr, pfn_t *pfn) | |
| 146 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 147 | + pfn_t *pfn) | |
| 146 | 148 | { |
| 147 | 149 | return -EIO; |
| 148 | 150 | } |
| @@ -286,7 +286,8 @@ static int persistent_memory_claim(struct dm_writecache *wc) · 285 unmodified lines | ||
| 286 | 286 | |
| 287 | 287 | id = dax_read_lock(); |
| 288 | 288 | |
| 289 | − da = dax_direct_access(wc->ssd_dev->dax_dev, offset, p, &wc->memory_map, &pfn); | |
| 289 | + da = dax_direct_access(wc->ssd_dev->dax_dev, offset, p, DAX_ACCESS, | |
| 290 | + &wc->memory_map, &pfn); | |
| 290 | 291 | if (da < 0) { |
| 291 | 292 | wc->memory_map = NULL; |
| 292 | 293 | r = da; |
| @@ -308,8 +309,8 @@ static int persistent_memory_claim(struct dm_writecache *wc) · 15 unmodified lines | ||
| 308 | 309 | i = 0; |
| 309 | 310 | do { |
| 310 | 311 | long daa; |
| 311 | − daa = dax_direct_access(wc->ssd_dev->dax_dev, offset + i, p - i, | |
| 312 | − NULL, &pfn); | |
| 312 | + daa = dax_direct_access(wc->ssd_dev->dax_dev, offset + i, | |
| 313 | + p - i, DAX_ACCESS, NULL, &pfn); | |
| 313 | 314 | if (daa <= 0) { |
| 314 | 315 | r = daa ? daa : -EINVAL; |
| 315 | 316 | goto err3; |
| @@ -1093,7 +1093,8 @@ static struct dm_target *dm_dax_get_live_target(struct mapped_device *md, · 1092 unmodified lines | ||
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, |
| 1096 | − long nr_pages, void **kaddr, pfn_t *pfn) | |
| 1096 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 1097 | + pfn_t *pfn) | |
| 1097 | 1098 | { |
| 1098 | 1099 | struct mapped_device *md = dax_get_private(dax_dev); |
| 1099 | 1100 | sector_t sector = pgoff * PAGE_SECTORS; |
| @@ -1111,7 +1112,7 @@ static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, · 11 unmodified lines | ||
| 1111 | 1112 | if (len < 1) |
| 1112 | 1113 | goto out; |
| 1113 | 1114 | nr_pages = min(len, nr_pages); |
| 1114 | − ret = ti->type->direct_access(ti, pgoff, nr_pages, kaddr, pfn); | |
| 1115 | + ret = ti->type->direct_access(ti, pgoff, nr_pages, mode, kaddr, pfn); | |
| 1115 | 1116 | |
| 1116 | 1117 | out: |
| 1117 | 1118 | dm_put_live_table(md, srcu_idx); |
| @@ -239,7 +239,8 @@ static int pmem_rw_page(struct block_device *bdev, sector_t sector, · 238 unmodified lines | ||
| 239 | 239 | |
| 240 | 240 | /* see "strong" declaration in tools/testing/nvdimm/pmem-dax.c */ |
| 241 | 241 | __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, |
| 242 | − long nr_pages, void **kaddr, pfn_t *pfn) | |
| 242 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 243 | + pfn_t *pfn) | |
| 243 | 244 | { |
| 244 | 245 | resource_size_t offset = PFN_PHYS(pgoff) + pmem->data_offset; |
| 245 | 246 | |
| @@ -278,11 +279,12 @@ static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, · 32 unmodified lines | ||
| 278 | 279 | } |
| 279 | 280 | |
| 280 | 281 | static long pmem_dax_direct_access(struct dax_device *dax_dev, |
| 281 | − pgoff_t pgoff, long nr_pages, void **kaddr, pfn_t *pfn) | |
| 282 | + pgoff_t pgoff, long nr_pages, enum dax_access_mode mode, | |
| 283 | + void **kaddr, pfn_t *pfn) | |
| 282 | 284 | { |
| 283 | 285 | struct pmem_device *pmem = dax_get_private(dax_dev); |
| 284 | 286 | |
| 285 | − return __pmem_direct_access(pmem, pgoff, nr_pages, kaddr, pfn); | |
| 287 | + return __pmem_direct_access(pmem, pgoff, nr_pages, mode, kaddr, pfn); | |
| 286 | 288 | } |
| 287 | 289 | |
| 288 | 290 | static const struct dax_operations pmem_dax_ops = { |
| @@ -8,6 +8,8 @@ · 7 unmodified lines | ||
| 8 | 8 | #include <linux/pfn_t.h> |
| 9 | 9 | #include <linux/fs.h> |
| 10 | 10 | |
| 11 | +enum dax_access_mode; | |
| 12 | + | |
| 11 | 13 | /* this definition is in it's own header for tools/testing/nvdimm to consume */ |
| 12 | 14 | struct pmem_device { |
| 13 | 15 | /* One contiguous memory region per device */ |
| @@ -28,7 +30,8 @@ struct pmem_device { · 14 unmodified lines | ||
| 28 | 30 | }; |
| 29 | 31 | |
| 30 | 32 | long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, |
| 31 | − long nr_pages, void **kaddr, pfn_t *pfn); | |
| 33 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 34 | + pfn_t *pfn); | |
| 32 | 35 | |
| 33 | 36 | #ifdef CONFIG_MEMORY_FAILURE |
| 34 | 37 | static inline bool test_and_clear_pmem_poison(struct page *page) |
| @@ -32,7 +32,8 @@ static int dcssblk_open(struct block_device *bdev, fmode_t mode); · 31 unmodified lines | ||
| 32 | 32 | static void dcssblk_release(struct gendisk *disk, fmode_t mode); |
| 33 | 33 | static void dcssblk_submit_bio(struct bio *bio); |
| 34 | 34 | static long dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, |
| 35 | − long nr_pages, void **kaddr, pfn_t *pfn); | |
| 35 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 36 | + pfn_t *pfn); | |
| 36 | 37 | |
| 37 | 38 | static char dcssblk_segments[DCSSBLK_PARM_LEN] = "\0"; |
| 38 | 39 | |
| @@ -50,7 +51,8 @@ static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev, · 11 unmodified lines | ||
| 50 | 51 | long rc; |
| 51 | 52 | void *kaddr; |
| 52 | 53 | |
| 53 | − rc = dax_direct_access(dax_dev, pgoff, nr_pages, &kaddr, NULL); | |
| 54 | + rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_ACCESS, | |
| 55 | + &kaddr, NULL); | |
| 54 | 56 | if (rc < 0) |
| 55 | 57 | return rc; |
| 56 | 58 | memset(kaddr, 0, nr_pages << PAGE_SHIFT); |
| @@ -927,7 +929,8 @@ __dcssblk_direct_access(struct dcssblk_dev_info *dev_info, pgoff_t pgoff, · 870 unmodified lines | ||
| 927 | 929 | |
| 928 | 930 | static long |
| 929 | 931 | dcssblk_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, |
| 930 | − long nr_pages, void **kaddr, pfn_t *pfn) | |
| 932 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 933 | + pfn_t *pfn) | |
| 931 | 934 | { |
| 932 | 935 | struct dcssblk_dev_info *dev_info = dax_get_private(dax_dev); |
| 933 | 936 | |
| @@ -721,7 +721,8 @@ static int copy_cow_page_dax(struct vm_fault *vmf, const struct iomap_iter *iter · 720 unmodified lines | ||
| 721 | 721 | int id; |
| 722 | 722 | |
| 723 | 723 | id = dax_read_lock(); |
| 724 | − rc = dax_direct_access(iter->iomap.dax_dev, pgoff, 1, &kaddr, NULL); | |
| 724 | + rc = dax_direct_access(iter->iomap.dax_dev, pgoff, 1, DAX_ACCESS, | |
| 725 | + &kaddr, NULL); | |
| 725 | 726 | if (rc < 0) { |
| 726 | 727 | dax_read_unlock(id); |
| 727 | 728 | return rc; |
| @@ -1013,7 +1014,7 @@ static int dax_iomap_pfn(const struct iomap *iomap, loff_t pos, size_t size, · 285 unmodified lines | ||
| 1013 | 1014 | |
| 1014 | 1015 | id = dax_read_lock(); |
| 1015 | 1016 | length = dax_direct_access(iomap->dax_dev, pgoff, PHYS_PFN(size), |
| 1016 | − NULL, pfnp); | |
| 1017 | + DAX_ACCESS, NULL, pfnp); | |
| 1017 | 1018 | if (length < 0) { |
| 1018 | 1019 | rc = length; |
| 1019 | 1020 | goto out; |
| @@ -1122,7 +1123,7 @@ static int dax_memzero(struct dax_device *dax_dev, pgoff_t pgoff, · 102 unmodified lines | ||
| 1122 | 1123 | void *kaddr; |
| 1123 | 1124 | long ret; |
| 1124 | 1125 | |
| 1125 | − ret = dax_direct_access(dax_dev, pgoff, 1, &kaddr, NULL); | |
| 1126 | + ret = dax_direct_access(dax_dev, pgoff, 1, DAX_ACCESS, &kaddr, NULL); | |
| 1126 | 1127 | if (ret > 0) { |
| 1127 | 1128 | memset(kaddr + offset, 0, size); |
| 1128 | 1129 | dax_flush(dax_dev, kaddr + offset, size); |
| @@ -1247,7 +1248,7 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi, · 118 unmodified lines | ||
| 1247 | 1248 | } |
| 1248 | 1249 | |
| 1249 | 1250 | map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size), |
| 1250 | − &kaddr, NULL); | |
| 1251 | + DAX_ACCESS, &kaddr, NULL); | |
| 1251 | 1252 | if (map_len < 0) { |
| 1252 | 1253 | ret = map_len; |
| 1253 | 1254 | break; |
| @@ -1241,8 +1241,8 @@ static int fuse_dax_mem_range_init(struct fuse_conn_dax *fcd) · 1240 unmodified lines | ||
| 1241 | 1241 | INIT_DELAYED_WORK(&fcd->free_work, fuse_dax_free_mem_worker); |
| 1242 | 1242 | |
| 1243 | 1243 | id = dax_read_lock(); |
| 1244 | − nr_pages = dax_direct_access(fcd->dev, 0, PHYS_PFN(dax_size), NULL, | |
| 1245 | − NULL); | |
| 1244 | + nr_pages = dax_direct_access(fcd->dev, 0, PHYS_PFN(dax_size), | |
| 1245 | + DAX_ACCESS, NULL, NULL); | |
| 1246 | 1246 | dax_read_unlock(id); |
| 1247 | 1247 | if (nr_pages < 0) { |
| 1248 | 1248 | pr_debug("dax_direct_access() returned %ld\n", nr_pages); |
| @@ -752,7 +752,8 @@ static void virtio_fs_cleanup_vqs(struct virtio_device *vdev, · 751 unmodified lines | ||
| 752 | 752 | * offset. |
| 753 | 753 | */ |
| 754 | 754 | static long virtio_fs_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, |
| 755 | − long nr_pages, void **kaddr, pfn_t *pfn) | |
| 755 | + long nr_pages, enum dax_access_mode mode, | |
| 756 | + void **kaddr, pfn_t *pfn) | |
| 756 | 757 | { |
| 757 | 758 | struct virtio_fs *fs = dax_get_private(dax_dev); |
| 758 | 759 | phys_addr_t offset = PFN_PHYS(pgoff); |
| @@ -772,7 +773,8 @@ static int virtio_fs_zero_page_range(struct dax_device *dax_dev, · 13 unmodified lines | ||
| 772 | 773 | long rc; |
| 773 | 774 | void *kaddr; |
| 774 | 775 | |
| 775 | − rc = dax_direct_access(dax_dev, pgoff, nr_pages, &kaddr, NULL); | |
| 776 | + rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_ACCESS, &kaddr, | |
| 777 | + NULL); | |
| 776 | 778 | if (rc < 0) |
| 777 | 779 | return rc; |
| 778 | 780 | memset(kaddr, 0, nr_pages << PAGE_SHIFT); |
| @@ -14,6 +14,11 @@ struct iomap_ops; · 13 unmodified lines | ||
| 14 | 14 | struct iomap_iter; |
| 15 | 15 | struct iomap; |
| 16 | 16 | |
| 17 | +enum dax_access_mode { | |
| 18 | + DAX_ACCESS, | |
| 19 | + DAX_RECOVERY_WRITE, | |
| 20 | +}; | |
| 21 | + | |
| 17 | 22 | struct dax_operations { |
| 18 | 23 | /* |
| 19 | 24 | * direct_access: translate a device-relative |
| @@ -21,7 +26,7 @@ struct dax_operations { · 1 unmodified line | ||
| 21 | 26 | * number of pages available for DAX at that pfn. |
| 22 | 27 | */ |
| 23 | 28 | long (*direct_access)(struct dax_device *, pgoff_t, long, |
| 24 | − void **, pfn_t *); | |
| 29 | + enum dax_access_mode, void **, pfn_t *); | |
| 25 | 30 | /* |
| 26 | 31 | * Validate whether this device is usable as an fsdax backing |
| 27 | 32 | * device. |
| @@ -178,7 +183,7 @@ static inline void dax_read_unlock(int id) · 150 unmodified lines | ||
| 178 | 183 | bool dax_alive(struct dax_device *dax_dev); |
| 179 | 184 | void *dax_get_private(struct dax_device *dax_dev); |
| 180 | 185 | long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages, |
| 181 | − void **kaddr, pfn_t *pfn); | |
| 186 | + enum dax_access_mode mode, void **kaddr, pfn_t *pfn); | |
| 182 | 187 | size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, |
| 183 | 188 | size_t bytes, struct iov_iter *i); |
| 184 | 189 | size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, |
| @@ -20,6 +20,7 @@ struct dm_table; · 19 unmodified lines | ||
| 20 | 20 | struct dm_report_zones_args; |
| 21 | 21 | struct mapped_device; |
| 22 | 22 | struct bio_vec; |
| 23 | +enum dax_access_mode; | |
| 23 | 24 | |
| 24 | 25 | /* |
| 25 | 26 | * Type of table, mapped_device's mempool and request_queue |
| @@ -146,7 +147,8 @@ typedef int (*dm_busy_fn) (struct dm_target *ti); · 120 unmodified lines | ||
| 146 | 147 | * >= 0 : the number of bytes accessible at the address |
| 147 | 148 | */ |
| 148 | 149 | typedef long (*dm_dax_direct_access_fn) (struct dm_target *ti, pgoff_t pgoff, |
| 149 | − long nr_pages, void **kaddr, pfn_t *pfn); | |
| 150 | + long nr_pages, enum dax_access_mode node, void **kaddr, | |
| 151 | + pfn_t *pfn); | |
| 150 | 152 | typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff, |
| 151 | 153 | size_t nr_pages); |
| 152 | 154 | |
| @@ -4,11 +4,13 @@ · 3 unmodified lines | ||
| 4 | 4 | */ |
| 5 | 5 | #include "test/nfit_test.h" |
| 6 | 6 | #include <linux/blkdev.h> |
| 7 | +#include <linux/dax.h> | |
| 7 | 8 | #include <pmem.h> |
| 8 | 9 | #include <nd.h> |
| 9 | 10 | |
| 10 | 11 | long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, |
| 11 | − long nr_pages, void **kaddr, pfn_t *pfn) | |
| 12 | + long nr_pages, enum dax_access_mode mode, void **kaddr, | |
| 13 | + pfn_t *pfn) | |
| 12 | 14 | { |
| 13 | 15 | resource_size_t offset = PFN_PHYS(pgoff) + pmem->data_offset; |
| 14 | 16 | |