Dan Williams | 51cf784 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* Copyright(c) 2016-2018 Intel Corporation. All rights reserved. */ |
Dan Williams | 89ec9f2 | 2018-10-29 15:52:42 -0700 | [diff] [blame] | 3 | #include <linux/memremap.h> |
Dan Williams | ab68f26 | 2016-05-18 09:15:08 -0700 | [diff] [blame] | 4 | #include <linux/pagemap.h> |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/device.h> |
| 7 | #include <linux/pfn_t.h> |
Dan Williams | ba09c01 | 2016-07-24 15:55:42 -0700 | [diff] [blame] | 8 | #include <linux/cdev.h> |
Dan Williams | ab68f26 | 2016-05-18 09:15:08 -0700 | [diff] [blame] | 9 | #include <linux/slab.h> |
| 10 | #include <linux/dax.h> |
| 11 | #include <linux/fs.h> |
| 12 | #include <linux/mm.h> |
Dave Jiang | ef84230 | 2018-04-19 13:39:43 -0700 | [diff] [blame] | 13 | #include <linux/mman.h> |
Dan Williams | 7361636 | 2017-05-04 23:38:43 -0700 | [diff] [blame] | 14 | #include "dax-private.h" |
Dan Williams | 51cf784 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 15 | #include "bus.h" |
Dan Williams | ab68f26 | 2016-05-18 09:15:08 -0700 | [diff] [blame] | 16 | |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 17 | static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma, |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 18 | const char *func) |
| 19 | { |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 20 | struct device *dev = &dev_dax->dev; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 21 | unsigned long mask; |
| 22 | |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 23 | if (!dax_alive(dev_dax->dax_dev)) |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 24 | return -ENXIO; |
| 25 | |
Dan Williams | 4cb1935 | 2016-11-16 09:00:38 -0800 | [diff] [blame] | 26 | /* prevent private mappings from being established */ |
Dan Williams | 325896f | 2016-12-06 17:03:35 -0800 | [diff] [blame] | 27 | if ((vma->vm_flags & VM_MAYSHARE) != VM_MAYSHARE) { |
Jeff Moyer | 5a14e91 | 2018-06-27 11:43:58 -0400 | [diff] [blame] | 28 | dev_info_ratelimited(dev, |
| 29 | "%s: %s: fail, attempted private mapping\n", |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 30 | current->comm, func); |
| 31 | return -EINVAL; |
| 32 | } |
| 33 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 34 | mask = dev_dax->align - 1; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 35 | if (vma->vm_start & mask || vma->vm_end & mask) { |
Jeff Moyer | 5a14e91 | 2018-06-27 11:43:58 -0400 | [diff] [blame] | 36 | dev_info_ratelimited(dev, |
| 37 | "%s: %s: fail, unaligned vma (%#lx - %#lx, %#lx)\n", |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 38 | current->comm, func, vma->vm_start, vma->vm_end, |
| 39 | mask); |
| 40 | return -EINVAL; |
| 41 | } |
| 42 | |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 43 | if (!vma_is_dax(vma)) { |
Jeff Moyer | 5a14e91 | 2018-06-27 11:43:58 -0400 | [diff] [blame] | 44 | dev_info_ratelimited(dev, |
| 45 | "%s: %s: fail, vma is not DAX capable\n", |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 46 | current->comm, func); |
| 47 | return -EINVAL; |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Dan Williams | 7361636 | 2017-05-04 23:38:43 -0700 | [diff] [blame] | 53 | /* see "strong" declaration in tools/testing/nvdimm/dax-dev.c */ |
| 54 | __weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 55 | unsigned long size) |
| 56 | { |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 57 | int i; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 58 | |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 59 | for (i = 0; i < dev_dax->nr_range; i++) { |
| 60 | struct dev_dax_range *dax_range = &dev_dax->ranges[i]; |
| 61 | struct range *range = &dax_range->range; |
| 62 | unsigned long long pgoff_end; |
| 63 | phys_addr_t phys; |
| 64 | |
| 65 | pgoff_end = dax_range->pgoff + PHYS_PFN(range_len(range)) - 1; |
| 66 | if (pgoff < dax_range->pgoff || pgoff > pgoff_end) |
| 67 | continue; |
| 68 | phys = PFN_PHYS(pgoff - dax_range->pgoff) + range->start; |
Dan Williams | f5516ec | 2020-10-13 16:49:43 -0700 | [diff] [blame] | 69 | if (phys + size - 1 <= range->end) |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 70 | return phys; |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 71 | break; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 72 | } |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 73 | return -1; |
| 74 | } |
| 75 | |
Joao Martins | a0fb038 | 2022-01-14 14:04:36 -0800 | [diff] [blame] | 76 | static void dax_set_mapping(struct vm_fault *vmf, pfn_t pfn, |
| 77 | unsigned long fault_size) |
| 78 | { |
| 79 | unsigned long i, nr_pages = fault_size / PAGE_SIZE; |
| 80 | struct file *filp = vmf->vma->vm_file; |
Joao Martins | 1460600 | 2022-01-14 14:04:47 -0800 | [diff] [blame] | 81 | struct dev_dax *dev_dax = filp->private_data; |
Joao Martins | a0fb038 | 2022-01-14 14:04:36 -0800 | [diff] [blame] | 82 | pgoff_t pgoff; |
| 83 | |
Joao Martins | 1460600 | 2022-01-14 14:04:47 -0800 | [diff] [blame] | 84 | /* mapping is only set on the head */ |
| 85 | if (dev_dax->pgmap->vmemmap_shift) |
| 86 | nr_pages = 1; |
| 87 | |
Joao Martins | a0fb038 | 2022-01-14 14:04:36 -0800 | [diff] [blame] | 88 | pgoff = linear_page_index(vmf->vma, |
| 89 | ALIGN(vmf->address, fault_size)); |
| 90 | |
| 91 | for (i = 0; i < nr_pages; i++) { |
| 92 | struct page *page = pfn_to_page(pfn_t_to_pfn(pfn) + i); |
| 93 | |
Joao Martins | 1460600 | 2022-01-14 14:04:47 -0800 | [diff] [blame] | 94 | page = compound_head(page); |
Joao Martins | a0fb038 | 2022-01-14 14:04:36 -0800 | [diff] [blame] | 95 | if (page->mapping) |
| 96 | continue; |
| 97 | |
| 98 | page->mapping = filp->f_mapping; |
| 99 | page->index = pgoff + i; |
| 100 | } |
| 101 | } |
| 102 | |
Dan Williams | 226ab56 | 2018-07-13 21:49:34 -0700 | [diff] [blame] | 103 | static vm_fault_t __dev_dax_pte_fault(struct dev_dax *dev_dax, |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 104 | struct vm_fault *vmf) |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 105 | { |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 106 | struct device *dev = &dev_dax->dev; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 107 | phys_addr_t phys; |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 108 | pfn_t pfn; |
Dave Jiang | 0134ed4 | 2017-03-10 13:24:22 -0700 | [diff] [blame] | 109 | unsigned int fault_size = PAGE_SIZE; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 110 | |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 111 | if (check_vma(dev_dax, vmf->vma, __func__)) |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 112 | return VM_FAULT_SIGBUS; |
| 113 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 114 | if (dev_dax->align > PAGE_SIZE) { |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 115 | dev_dbg(dev, "alignment (%#x) > fault size (%#x)\n", |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 116 | dev_dax->align, fault_size); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 117 | return VM_FAULT_SIGBUS; |
| 118 | } |
| 119 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 120 | if (fault_size != dev_dax->align) |
Dave Jiang | 0134ed4 | 2017-03-10 13:24:22 -0700 | [diff] [blame] | 121 | return VM_FAULT_SIGBUS; |
| 122 | |
Dan Williams | 7361636 | 2017-05-04 23:38:43 -0700 | [diff] [blame] | 123 | phys = dax_pgoff_to_phys(dev_dax, vmf->pgoff, PAGE_SIZE); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 124 | if (phys == -1) { |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 125 | dev_dbg(dev, "pgoff_to_phys(%#lx) failed\n", vmf->pgoff); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 126 | return VM_FAULT_SIGBUS; |
| 127 | } |
| 128 | |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 129 | pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 130 | |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 131 | dax_set_mapping(vmf, pfn, fault_size); |
Joao Martins | 0e7325f | 2022-01-14 14:04:40 -0800 | [diff] [blame] | 132 | |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 133 | return vmf_insert_mixed(vmf->vma, vmf->address, pfn); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Dan Williams | 226ab56 | 2018-07-13 21:49:34 -0700 | [diff] [blame] | 136 | static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax, |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 137 | struct vm_fault *vmf) |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 138 | { |
Dave Jiang | d8a849e | 2017-02-22 15:40:03 -0800 | [diff] [blame] | 139 | unsigned long pmd_addr = vmf->address & PMD_MASK; |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 140 | struct device *dev = &dev_dax->dev; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 141 | phys_addr_t phys; |
| 142 | pgoff_t pgoff; |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 143 | pfn_t pfn; |
Dave Jiang | 0134ed4 | 2017-03-10 13:24:22 -0700 | [diff] [blame] | 144 | unsigned int fault_size = PMD_SIZE; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 145 | |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 146 | if (check_vma(dev_dax, vmf->vma, __func__)) |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 147 | return VM_FAULT_SIGBUS; |
| 148 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 149 | if (dev_dax->align > PMD_SIZE) { |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 150 | dev_dbg(dev, "alignment (%#x) > fault size (%#x)\n", |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 151 | dev_dax->align, fault_size); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 152 | return VM_FAULT_SIGBUS; |
| 153 | } |
| 154 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 155 | if (fault_size < dev_dax->align) |
Dave Jiang | 0134ed4 | 2017-03-10 13:24:22 -0700 | [diff] [blame] | 156 | return VM_FAULT_SIGBUS; |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 157 | else if (fault_size > dev_dax->align) |
Dave Jiang | 0134ed4 | 2017-03-10 13:24:22 -0700 | [diff] [blame] | 158 | return VM_FAULT_FALLBACK; |
| 159 | |
| 160 | /* if we are outside of the VMA */ |
| 161 | if (pmd_addr < vmf->vma->vm_start || |
| 162 | (pmd_addr + PMD_SIZE) > vmf->vma->vm_end) |
| 163 | return VM_FAULT_SIGBUS; |
| 164 | |
Dave Jiang | f420039 | 2017-02-22 15:40:06 -0800 | [diff] [blame] | 165 | pgoff = linear_page_index(vmf->vma, pmd_addr); |
Dan Williams | 7361636 | 2017-05-04 23:38:43 -0700 | [diff] [blame] | 166 | phys = dax_pgoff_to_phys(dev_dax, pgoff, PMD_SIZE); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 167 | if (phys == -1) { |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 168 | dev_dbg(dev, "pgoff_to_phys(%#lx) failed\n", pgoff); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 169 | return VM_FAULT_SIGBUS; |
| 170 | } |
| 171 | |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 172 | pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 173 | |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 174 | dax_set_mapping(vmf, pfn, fault_size); |
Joao Martins | 0e7325f | 2022-01-14 14:04:40 -0800 | [diff] [blame] | 175 | |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 176 | return vmf_insert_pfn_pmd(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 179 | #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD |
Dan Williams | 226ab56 | 2018-07-13 21:49:34 -0700 | [diff] [blame] | 180 | static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 181 | struct vm_fault *vmf) |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 182 | { |
| 183 | unsigned long pud_addr = vmf->address & PUD_MASK; |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 184 | struct device *dev = &dev_dax->dev; |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 185 | phys_addr_t phys; |
| 186 | pgoff_t pgoff; |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 187 | pfn_t pfn; |
Dave Jiang | 70b085b | 2017-03-10 13:24:27 -0700 | [diff] [blame] | 188 | unsigned int fault_size = PUD_SIZE; |
| 189 | |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 190 | |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 191 | if (check_vma(dev_dax, vmf->vma, __func__)) |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 192 | return VM_FAULT_SIGBUS; |
| 193 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 194 | if (dev_dax->align > PUD_SIZE) { |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 195 | dev_dbg(dev, "alignment (%#x) > fault size (%#x)\n", |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 196 | dev_dax->align, fault_size); |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 197 | return VM_FAULT_SIGBUS; |
| 198 | } |
| 199 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 200 | if (fault_size < dev_dax->align) |
Dave Jiang | 70b085b | 2017-03-10 13:24:27 -0700 | [diff] [blame] | 201 | return VM_FAULT_SIGBUS; |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 202 | else if (fault_size > dev_dax->align) |
Dave Jiang | 70b085b | 2017-03-10 13:24:27 -0700 | [diff] [blame] | 203 | return VM_FAULT_FALLBACK; |
| 204 | |
| 205 | /* if we are outside of the VMA */ |
| 206 | if (pud_addr < vmf->vma->vm_start || |
| 207 | (pud_addr + PUD_SIZE) > vmf->vma->vm_end) |
| 208 | return VM_FAULT_SIGBUS; |
| 209 | |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 210 | pgoff = linear_page_index(vmf->vma, pud_addr); |
Dan Williams | 7361636 | 2017-05-04 23:38:43 -0700 | [diff] [blame] | 211 | phys = dax_pgoff_to_phys(dev_dax, pgoff, PUD_SIZE); |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 212 | if (phys == -1) { |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 213 | dev_dbg(dev, "pgoff_to_phys(%#lx) failed\n", pgoff); |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 214 | return VM_FAULT_SIGBUS; |
| 215 | } |
| 216 | |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 217 | pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 218 | |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 219 | dax_set_mapping(vmf, pfn, fault_size); |
Joao Martins | 0e7325f | 2022-01-14 14:04:40 -0800 | [diff] [blame] | 220 | |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 221 | return vmf_insert_pfn_pud(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 222 | } |
| 223 | #else |
Dan Williams | 226ab56 | 2018-07-13 21:49:34 -0700 | [diff] [blame] | 224 | static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 225 | struct vm_fault *vmf) |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 226 | { |
| 227 | return VM_FAULT_FALLBACK; |
| 228 | } |
| 229 | #endif /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ |
| 230 | |
Dan Williams | 226ab56 | 2018-07-13 21:49:34 -0700 | [diff] [blame] | 231 | static vm_fault_t dev_dax_huge_fault(struct vm_fault *vmf, |
Dave Jiang | c791ace | 2017-02-24 14:57:08 -0800 | [diff] [blame] | 232 | enum page_entry_size pe_size) |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 233 | { |
Dave Jiang | f420039 | 2017-02-22 15:40:06 -0800 | [diff] [blame] | 234 | struct file *filp = vmf->vma->vm_file; |
Souptick Joarder | 36bdac1 | 2018-09-04 15:46:26 -0700 | [diff] [blame] | 235 | vm_fault_t rc = VM_FAULT_SIGBUS; |
| 236 | int id; |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 237 | struct dev_dax *dev_dax = filp->private_data; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 238 | |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 239 | dev_dbg(&dev_dax->dev, "%s: %s (%#lx - %#lx) size = %d\n", current->comm, |
| 240 | (vmf->flags & FAULT_FLAG_WRITE) ? "write" : "read", |
Oliver O'Halloran | 7620262 | 2017-04-12 01:59:36 +1000 | [diff] [blame] | 241 | vmf->vma->vm_start, vmf->vma->vm_end, pe_size); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 242 | |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 243 | id = dax_read_lock(); |
Dave Jiang | c791ace | 2017-02-24 14:57:08 -0800 | [diff] [blame] | 244 | switch (pe_size) { |
| 245 | case PE_SIZE_PTE: |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 246 | rc = __dev_dax_pte_fault(dev_dax, vmf); |
Dave Jiang | a2d5816 | 2017-02-24 14:56:59 -0800 | [diff] [blame] | 247 | break; |
Dave Jiang | c791ace | 2017-02-24 14:57:08 -0800 | [diff] [blame] | 248 | case PE_SIZE_PMD: |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 249 | rc = __dev_dax_pmd_fault(dev_dax, vmf); |
Dave Jiang | a2d5816 | 2017-02-24 14:56:59 -0800 | [diff] [blame] | 250 | break; |
Dave Jiang | c791ace | 2017-02-24 14:57:08 -0800 | [diff] [blame] | 251 | case PE_SIZE_PUD: |
Joao Martins | 6ec228b | 2022-01-14 14:04:43 -0800 | [diff] [blame] | 252 | rc = __dev_dax_pud_fault(dev_dax, vmf); |
Dave Jiang | 9557fee | 2017-02-24 14:57:05 -0800 | [diff] [blame] | 253 | break; |
Dave Jiang | a2d5816 | 2017-02-24 14:56:59 -0800 | [diff] [blame] | 254 | default: |
Pushkar Jambhlekar | 54eafcc | 2017-04-11 09:12:25 -0700 | [diff] [blame] | 255 | rc = VM_FAULT_SIGBUS; |
Dave Jiang | a2d5816 | 2017-02-24 14:56:59 -0800 | [diff] [blame] | 256 | } |
Dan Williams | 2232c63 | 2018-07-13 21:49:40 -0700 | [diff] [blame] | 257 | |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 258 | dax_read_unlock(id); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 259 | |
| 260 | return rc; |
| 261 | } |
| 262 | |
Dan Williams | 226ab56 | 2018-07-13 21:49:34 -0700 | [diff] [blame] | 263 | static vm_fault_t dev_dax_fault(struct vm_fault *vmf) |
Dave Jiang | c791ace | 2017-02-24 14:57:08 -0800 | [diff] [blame] | 264 | { |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 265 | return dev_dax_huge_fault(vmf, PE_SIZE_PTE); |
Dave Jiang | c791ace | 2017-02-24 14:57:08 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Dmitry Safonov | dd3b614 | 2020-12-14 19:08:17 -0800 | [diff] [blame] | 268 | static int dev_dax_may_split(struct vm_area_struct *vma, unsigned long addr) |
Dan Williams | 9702cff | 2017-11-29 16:10:32 -0800 | [diff] [blame] | 269 | { |
| 270 | struct file *filp = vma->vm_file; |
| 271 | struct dev_dax *dev_dax = filp->private_data; |
Dan Williams | 9702cff | 2017-11-29 16:10:32 -0800 | [diff] [blame] | 272 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 273 | if (!IS_ALIGNED(addr, dev_dax->align)) |
Dan Williams | 9702cff | 2017-11-29 16:10:32 -0800 | [diff] [blame] | 274 | return -EINVAL; |
| 275 | return 0; |
| 276 | } |
| 277 | |
Dan Williams | c1d53b9 | 2018-04-05 16:24:28 -0700 | [diff] [blame] | 278 | static unsigned long dev_dax_pagesize(struct vm_area_struct *vma) |
| 279 | { |
| 280 | struct file *filp = vma->vm_file; |
| 281 | struct dev_dax *dev_dax = filp->private_data; |
Dan Williams | c1d53b9 | 2018-04-05 16:24:28 -0700 | [diff] [blame] | 282 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 283 | return dev_dax->align; |
Dan Williams | c1d53b9 | 2018-04-05 16:24:28 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 286 | static const struct vm_operations_struct dax_vm_ops = { |
| 287 | .fault = dev_dax_fault, |
| 288 | .huge_fault = dev_dax_huge_fault, |
Dmitry Safonov | dd3b614 | 2020-12-14 19:08:17 -0800 | [diff] [blame] | 289 | .may_split = dev_dax_may_split, |
Dan Williams | c1d53b9 | 2018-04-05 16:24:28 -0700 | [diff] [blame] | 290 | .pagesize = dev_dax_pagesize, |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
Dan Williams | af69f51 | 2016-08-11 00:38:03 -0700 | [diff] [blame] | 293 | static int dax_mmap(struct file *filp, struct vm_area_struct *vma) |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 294 | { |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 295 | struct dev_dax *dev_dax = filp->private_data; |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 296 | int rc, id; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 297 | |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 298 | dev_dbg(&dev_dax->dev, "trace\n"); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 299 | |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 300 | /* |
| 301 | * We lock to check dax_dev liveness and will re-check at |
| 302 | * fault time. |
| 303 | */ |
| 304 | id = dax_read_lock(); |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 305 | rc = check_vma(dev_dax, vma, __func__); |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 306 | dax_read_unlock(id); |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 307 | if (rc) |
| 308 | return rc; |
| 309 | |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 310 | vma->vm_ops = &dax_vm_ops; |
Dave Jiang | e1fb4a0 | 2018-08-17 15:43:40 -0700 | [diff] [blame] | 311 | vma->vm_flags |= VM_HUGEPAGE; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 312 | return 0; |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 313 | } |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 314 | |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 315 | /* return an unmapped area aligned to the dax region specified alignment */ |
Dan Williams | af69f51 | 2016-08-11 00:38:03 -0700 | [diff] [blame] | 316 | static unsigned long dax_get_unmapped_area(struct file *filp, |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 317 | unsigned long addr, unsigned long len, unsigned long pgoff, |
| 318 | unsigned long flags) |
| 319 | { |
| 320 | unsigned long off, off_end, off_align, len_align, addr_align, align; |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 321 | struct dev_dax *dev_dax = filp ? filp->private_data : NULL; |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 322 | |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 323 | if (!dev_dax || addr) |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 324 | goto out; |
| 325 | |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 326 | align = dev_dax->align; |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 327 | off = pgoff << PAGE_SHIFT; |
| 328 | off_end = off + len; |
| 329 | off_align = round_up(off, align); |
| 330 | |
| 331 | if ((off_end <= off_align) || ((off_end - off_align) < align)) |
| 332 | goto out; |
| 333 | |
| 334 | len_align = len + align; |
| 335 | if ((off + len_align) < off) |
| 336 | goto out; |
| 337 | |
| 338 | addr_align = current->mm->get_unmapped_area(filp, addr, len_align, |
| 339 | pgoff, flags); |
| 340 | if (!IS_ERR_VALUE(addr_align)) { |
| 341 | addr_align += (off - addr_align) & (align - 1); |
| 342 | return addr_align; |
| 343 | } |
| 344 | out: |
| 345 | return current->mm->get_unmapped_area(filp, addr, len, pgoff, flags); |
| 346 | } |
| 347 | |
Dave Jiang | 41c9b1b | 2018-09-10 16:18:29 -0700 | [diff] [blame] | 348 | static const struct address_space_operations dev_dax_aops = { |
Matthew Wilcox (Oracle) | b82a96c | 2021-06-28 19:36:27 -0700 | [diff] [blame] | 349 | .set_page_dirty = __set_page_dirty_no_writeback, |
Dave Jiang | 41c9b1b | 2018-09-10 16:18:29 -0700 | [diff] [blame] | 350 | .invalidatepage = noop_invalidatepage, |
| 351 | }; |
| 352 | |
Dan Williams | af69f51 | 2016-08-11 00:38:03 -0700 | [diff] [blame] | 353 | static int dax_open(struct inode *inode, struct file *filp) |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 354 | { |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 355 | struct dax_device *dax_dev = inode_dax(inode); |
| 356 | struct inode *__dax_inode = dax_inode(dax_dev); |
| 357 | struct dev_dax *dev_dax = dax_get_private(dax_dev); |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 358 | |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 359 | dev_dbg(&dev_dax->dev, "trace\n"); |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 360 | inode->i_mapping = __dax_inode->i_mapping; |
| 361 | inode->i_mapping->host = __dax_inode; |
Dave Jiang | 41c9b1b | 2018-09-10 16:18:29 -0700 | [diff] [blame] | 362 | inode->i_mapping->a_ops = &dev_dax_aops; |
Dan Williams | 3bc52c4 | 2016-07-24 21:55:45 -0700 | [diff] [blame] | 363 | filp->f_mapping = inode->i_mapping; |
Jeff Layton | 5660e13 | 2017-07-06 07:02:25 -0400 | [diff] [blame] | 364 | filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); |
Jeff Layton | 735e4ae | 2020-06-01 21:45:36 -0700 | [diff] [blame] | 365 | filp->f_sb_err = file_sample_sb_err(filp); |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 366 | filp->private_data = dev_dax; |
Dan Williams | ebd84d7 | 2016-08-11 00:41:51 -0700 | [diff] [blame] | 367 | inode->i_flags = S_DAX; |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 368 | |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
Dan Williams | af69f51 | 2016-08-11 00:38:03 -0700 | [diff] [blame] | 372 | static int dax_release(struct inode *inode, struct file *filp) |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 373 | { |
Dan Williams | 5f0694b | 2017-01-30 21:43:10 -0800 | [diff] [blame] | 374 | struct dev_dax *dev_dax = filp->private_data; |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 375 | |
Dan Williams | 6daaca5 | 2018-03-05 16:40:05 -0800 | [diff] [blame] | 376 | dev_dbg(&dev_dax->dev, "trace\n"); |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 377 | return 0; |
Dan Williams | dee4107 | 2016-05-14 12:20:44 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Dan Williams | ab68f26 | 2016-05-18 09:15:08 -0700 | [diff] [blame] | 380 | static const struct file_operations dax_fops = { |
| 381 | .llseek = noop_llseek, |
| 382 | .owner = THIS_MODULE, |
Dan Williams | af69f51 | 2016-08-11 00:38:03 -0700 | [diff] [blame] | 383 | .open = dax_open, |
| 384 | .release = dax_release, |
| 385 | .get_unmapped_area = dax_get_unmapped_area, |
| 386 | .mmap = dax_mmap, |
Dave Jiang | ef84230 | 2018-04-19 13:39:43 -0700 | [diff] [blame] | 387 | .mmap_supported_flags = MAP_SYNC, |
Dan Williams | ab68f26 | 2016-05-18 09:15:08 -0700 | [diff] [blame] | 388 | }; |
| 389 | |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 390 | static void dev_dax_cdev_del(void *cdev) |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 391 | { |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 392 | cdev_del(cdev); |
Dan Williams | ebd84d7 | 2016-08-11 00:41:51 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 395 | static void dev_dax_kill(void *dev_dax) |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 396 | { |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 397 | kill_dev_dax(dev_dax); |
| 398 | } |
| 399 | |
Dan Williams | f11cf81 | 2020-10-13 16:50:08 -0700 | [diff] [blame] | 400 | int dev_dax_probe(struct dev_dax *dev_dax) |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 401 | { |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 402 | struct dax_device *dax_dev = dev_dax->dax_dev; |
Dan Williams | f11cf81 | 2020-10-13 16:50:08 -0700 | [diff] [blame] | 403 | struct device *dev = &dev_dax->dev; |
Dan Williams | f5516ec | 2020-10-13 16:49:43 -0700 | [diff] [blame] | 404 | struct dev_pagemap *pgmap; |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 405 | struct inode *inode; |
Dan Williams | ba09c01 | 2016-07-24 15:55:42 -0700 | [diff] [blame] | 406 | struct cdev *cdev; |
Dan Williams | 89ec9f2 | 2018-10-29 15:52:42 -0700 | [diff] [blame] | 407 | void *addr; |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 408 | int rc, i; |
Dan Williams | 89ec9f2 | 2018-10-29 15:52:42 -0700 | [diff] [blame] | 409 | |
Joao Martins | fc65c4e | 2022-01-14 14:04:33 -0800 | [diff] [blame] | 410 | if (static_dev_dax(dev_dax)) { |
| 411 | if (dev_dax->nr_range > 1) { |
| 412 | dev_warn(dev, |
| 413 | "static pgmap / multi-range device conflict\n"); |
| 414 | return -EINVAL; |
| 415 | } |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 416 | |
Joao Martins | fc65c4e | 2022-01-14 14:04:33 -0800 | [diff] [blame] | 417 | pgmap = dev_dax->pgmap; |
| 418 | } else { |
| 419 | if (dev_dax->pgmap) { |
| 420 | dev_warn(dev, |
| 421 | "dynamic-dax with pre-populated page map\n"); |
| 422 | return -EINVAL; |
| 423 | } |
| 424 | |
Joao Martins | 09b8013 | 2022-01-14 14:04:29 -0800 | [diff] [blame] | 425 | pgmap = devm_kzalloc(dev, |
| 426 | struct_size(pgmap, ranges, dev_dax->nr_range - 1), |
| 427 | GFP_KERNEL); |
Dan Williams | f5516ec | 2020-10-13 16:49:43 -0700 | [diff] [blame] | 428 | if (!pgmap) |
| 429 | return -ENOMEM; |
Joao Martins | fc65c4e | 2022-01-14 14:04:33 -0800 | [diff] [blame] | 430 | |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 431 | pgmap->nr_range = dev_dax->nr_range; |
Joao Martins | fc65c4e | 2022-01-14 14:04:33 -0800 | [diff] [blame] | 432 | dev_dax->pgmap = pgmap; |
| 433 | |
| 434 | for (i = 0; i < dev_dax->nr_range; i++) { |
| 435 | struct range *range = &dev_dax->ranges[i].range; |
| 436 | pgmap->ranges[i] = *range; |
| 437 | } |
Dan Williams | f5516ec | 2020-10-13 16:49:43 -0700 | [diff] [blame] | 438 | } |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 439 | |
| 440 | for (i = 0; i < dev_dax->nr_range; i++) { |
| 441 | struct range *range = &dev_dax->ranges[i].range; |
| 442 | |
| 443 | if (!devm_request_mem_region(dev, range->start, |
| 444 | range_len(range), dev_name(dev))) { |
| 445 | dev_warn(dev, "mapping%d: %#llx-%#llx could not reserve range\n", |
| 446 | i, range->start, range->end); |
| 447 | return -EBUSY; |
| 448 | } |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Dan Williams | f5516ec | 2020-10-13 16:49:43 -0700 | [diff] [blame] | 451 | pgmap->type = MEMORY_DEVICE_GENERIC; |
Joao Martins | 1460600 | 2022-01-14 14:04:47 -0800 | [diff] [blame] | 452 | if (dev_dax->align > PAGE_SIZE) |
| 453 | pgmap->vmemmap_shift = |
| 454 | order_base_2(dev_dax->align >> PAGE_SHIFT); |
Dan Williams | f5516ec | 2020-10-13 16:49:43 -0700 | [diff] [blame] | 455 | addr = devm_memremap_pages(dev, pgmap); |
Dan Williams | 50f44ee | 2019-06-13 15:56:33 -0700 | [diff] [blame] | 456 | if (IS_ERR(addr)) |
Dan Williams | 89ec9f2 | 2018-10-29 15:52:42 -0700 | [diff] [blame] | 457 | return PTR_ERR(addr); |
Dan Williams | 89ec9f2 | 2018-10-29 15:52:42 -0700 | [diff] [blame] | 458 | |
Dan Williams | 7b6be84 | 2017-04-11 09:49:49 -0700 | [diff] [blame] | 459 | inode = dax_inode(dax_dev); |
| 460 | cdev = inode->i_cdev; |
Dan Williams | ba09c01 | 2016-07-24 15:55:42 -0700 | [diff] [blame] | 461 | cdev_init(cdev, &dax_fops); |
Dan Williams | 83762cb | 2021-11-15 13:20:57 -0800 | [diff] [blame] | 462 | cdev->owner = dev->driver->owner; |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 463 | cdev_set_parent(cdev, &dev->kobj); |
| 464 | rc = cdev_add(cdev, dev->devt, 1); |
Dan Williams | d76911e | 2016-07-19 17:51:40 -0700 | [diff] [blame] | 465 | if (rc) |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 466 | return rc; |
Dan Williams | d76911e | 2016-07-19 17:51:40 -0700 | [diff] [blame] | 467 | |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 468 | rc = devm_add_action_or_reset(dev, dev_dax_cdev_del, cdev); |
| 469 | if (rc) |
| 470 | return rc; |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 471 | |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 472 | run_dax(dax_dev); |
| 473 | return devm_add_action_or_reset(dev, dev_dax_kill, dev_dax); |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 474 | } |
Dan Williams | 730926c | 2017-07-16 13:51:53 -0700 | [diff] [blame] | 475 | EXPORT_SYMBOL_GPL(dev_dax_probe); |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 476 | |
Dan Williams | d200781 | 2018-11-07 15:31:23 -0800 | [diff] [blame] | 477 | static struct dax_device_driver device_dax_driver = { |
Dan Williams | f11cf81 | 2020-10-13 16:50:08 -0700 | [diff] [blame] | 478 | .probe = dev_dax_probe, |
Uwe Kleine-König | c80b532 | 2021-02-05 23:28:41 +0100 | [diff] [blame] | 479 | /* all probe actions are unwound by devm, so .remove isn't necessary */ |
Dan Williams | d200781 | 2018-11-07 15:31:23 -0800 | [diff] [blame] | 480 | .match_always = 1, |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 481 | }; |
Dan Williams | 043a925 | 2016-08-07 08:23:56 -0700 | [diff] [blame] | 482 | |
Dan Williams | ab68f26 | 2016-05-18 09:15:08 -0700 | [diff] [blame] | 483 | static int __init dax_init(void) |
| 484 | { |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 485 | return dax_driver_register(&device_dax_driver); |
Dan Williams | ab68f26 | 2016-05-18 09:15:08 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static void __exit dax_exit(void) |
| 489 | { |
Dan Williams | d200781 | 2018-11-07 15:31:23 -0800 | [diff] [blame] | 490 | dax_driver_unregister(&device_dax_driver); |
Dan Williams | ab68f26 | 2016-05-18 09:15:08 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | MODULE_AUTHOR("Intel Corporation"); |
| 494 | MODULE_LICENSE("GPL v2"); |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 495 | module_init(dax_init); |
Dan Williams | ab68f26 | 2016-05-18 09:15:08 -0700 | [diff] [blame] | 496 | module_exit(dax_exit); |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 497 | MODULE_ALIAS_DAX_DEVICE(0); |