2017-07-13 00:58:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/* Copyright(c) 2016-2018 Intel Corporation. All rights reserved. */
|
2018-10-29 22:52:42 +00:00
|
|
|
#include <linux/memremap.h>
|
2016-05-18 16:15:08 +00:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/pfn_t.h>
|
2016-07-24 22:55:42 +00:00
|
|
|
#include <linux/cdev.h>
|
2016-05-18 16:15:08 +00:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/dax.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mm.h>
|
2018-04-19 20:39:43 +00:00
|
|
|
#include <linux/mman.h>
|
2017-04-07 22:33:36 +00:00
|
|
|
#include "dax-private.h"
|
2017-07-13 00:58:21 +00:00
|
|
|
#include "bus.h"
|
2016-05-18 16:15:08 +00:00
|
|
|
|
2017-01-31 05:43:10 +00:00
|
|
|
static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
|
2016-05-14 19:20:44 +00:00
|
|
|
const char *func)
|
|
|
|
{
|
2017-01-31 05:43:10 +00:00
|
|
|
struct device *dev = &dev_dax->dev;
|
2016-05-14 19:20:44 +00:00
|
|
|
unsigned long mask;
|
|
|
|
|
2017-04-11 16:49:49 +00:00
|
|
|
if (!dax_alive(dev_dax->dax_dev))
|
2016-05-14 19:20:44 +00:00
|
|
|
return -ENXIO;
|
|
|
|
|
2016-11-16 17:00:38 +00:00
|
|
|
/* prevent private mappings from being established */
|
2016-12-07 01:03:35 +00:00
|
|
|
if ((vma->vm_flags & VM_MAYSHARE) != VM_MAYSHARE) {
|
2018-06-27 15:43:58 +00:00
|
|
|
dev_info_ratelimited(dev,
|
|
|
|
"%s: %s: fail, attempted private mapping\n",
|
2016-05-14 19:20:44 +00:00
|
|
|
current->comm, func);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
mask = dev_dax->align - 1;
|
2016-05-14 19:20:44 +00:00
|
|
|
if (vma->vm_start & mask || vma->vm_end & mask) {
|
2018-06-27 15:43:58 +00:00
|
|
|
dev_info_ratelimited(dev,
|
|
|
|
"%s: %s: fail, unaligned vma (%#lx - %#lx, %#lx)\n",
|
2016-05-14 19:20:44 +00:00
|
|
|
current->comm, func, vma->vm_start, vma->vm_end,
|
|
|
|
mask);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vma_is_dax(vma)) {
|
2018-06-27 15:43:58 +00:00
|
|
|
dev_info_ratelimited(dev,
|
|
|
|
"%s: %s: fail, vma is not DAX capable\n",
|
2016-05-14 19:20:44 +00:00
|
|
|
current->comm, func);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-07 22:33:36 +00:00
|
|
|
/* see "strong" declaration in tools/testing/nvdimm/dax-dev.c */
|
2017-05-05 06:38:43 +00:00
|
|
|
__weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff,
|
2016-05-14 19:20:44 +00:00
|
|
|
unsigned long size)
|
|
|
|
{
|
2020-10-13 23:50:39 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < dev_dax->nr_range; i++) {
|
|
|
|
struct dev_dax_range *dax_range = &dev_dax->ranges[i];
|
|
|
|
struct range *range = &dax_range->range;
|
|
|
|
unsigned long long pgoff_end;
|
|
|
|
phys_addr_t phys;
|
|
|
|
|
|
|
|
pgoff_end = dax_range->pgoff + PHYS_PFN(range_len(range)) - 1;
|
|
|
|
if (pgoff < dax_range->pgoff || pgoff > pgoff_end)
|
|
|
|
continue;
|
|
|
|
phys = PFN_PHYS(pgoff - dax_range->pgoff) + range->start;
|
2020-10-13 23:49:43 +00:00
|
|
|
if (phys + size - 1 <= range->end)
|
2016-05-14 19:20:44 +00:00
|
|
|
return phys;
|
2020-10-13 23:50:39 +00:00
|
|
|
break;
|
2016-05-14 19:20:44 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-01-14 22:04:36 +00:00
|
|
|
static void dax_set_mapping(struct vm_fault *vmf, pfn_t pfn,
|
|
|
|
unsigned long fault_size)
|
|
|
|
{
|
|
|
|
unsigned long i, nr_pages = fault_size / PAGE_SIZE;
|
|
|
|
struct file *filp = vmf->vma->vm_file;
|
2022-01-14 22:04:47 +00:00
|
|
|
struct dev_dax *dev_dax = filp->private_data;
|
2022-01-14 22:04:36 +00:00
|
|
|
pgoff_t pgoff;
|
|
|
|
|
2022-01-14 22:04:47 +00:00
|
|
|
/* mapping is only set on the head */
|
|
|
|
if (dev_dax->pgmap->vmemmap_shift)
|
|
|
|
nr_pages = 1;
|
|
|
|
|
2022-01-14 22:04:36 +00:00
|
|
|
pgoff = linear_page_index(vmf->vma,
|
|
|
|
ALIGN(vmf->address, fault_size));
|
|
|
|
|
|
|
|
for (i = 0; i < nr_pages; i++) {
|
|
|
|
struct page *page = pfn_to_page(pfn_t_to_pfn(pfn) + i);
|
|
|
|
|
2022-01-14 22:04:47 +00:00
|
|
|
page = compound_head(page);
|
2022-01-14 22:04:36 +00:00
|
|
|
if (page->mapping)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
page->mapping = filp->f_mapping;
|
|
|
|
page->index = pgoff + i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-14 04:49:34 +00:00
|
|
|
static vm_fault_t __dev_dax_pte_fault(struct dev_dax *dev_dax,
|
2022-01-14 22:04:43 +00:00
|
|
|
struct vm_fault *vmf)
|
2016-05-14 19:20:44 +00:00
|
|
|
{
|
2017-01-31 05:43:10 +00:00
|
|
|
struct device *dev = &dev_dax->dev;
|
2016-05-14 19:20:44 +00:00
|
|
|
phys_addr_t phys;
|
2022-01-14 22:04:43 +00:00
|
|
|
pfn_t pfn;
|
2017-03-10 20:24:22 +00:00
|
|
|
unsigned int fault_size = PAGE_SIZE;
|
2016-05-14 19:20:44 +00:00
|
|
|
|
2017-01-31 05:43:10 +00:00
|
|
|
if (check_vma(dev_dax, vmf->vma, __func__))
|
2016-05-14 19:20:44 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
if (dev_dax->align > PAGE_SIZE) {
|
2018-03-06 00:40:05 +00:00
|
|
|
dev_dbg(dev, "alignment (%#x) > fault size (%#x)\n",
|
2020-10-13 23:50:50 +00:00
|
|
|
dev_dax->align, fault_size);
|
2016-05-14 19:20:44 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
if (fault_size != dev_dax->align)
|
2017-03-10 20:24:22 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
|
2017-05-05 06:38:43 +00:00
|
|
|
phys = dax_pgoff_to_phys(dev_dax, vmf->pgoff, PAGE_SIZE);
|
2016-05-14 19:20:44 +00:00
|
|
|
if (phys == -1) {
|
2018-03-06 00:40:05 +00:00
|
|
|
dev_dbg(dev, "pgoff_to_phys(%#lx) failed\n", vmf->pgoff);
|
2016-05-14 19:20:44 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
|
2022-01-14 22:04:43 +00:00
|
|
|
pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP);
|
2016-05-14 19:20:44 +00:00
|
|
|
|
2022-01-14 22:04:43 +00:00
|
|
|
dax_set_mapping(vmf, pfn, fault_size);
|
2022-01-14 22:04:40 +00:00
|
|
|
|
2022-01-14 22:04:43 +00:00
|
|
|
return vmf_insert_mixed(vmf->vma, vmf->address, pfn);
|
2016-05-14 19:20:44 +00:00
|
|
|
}
|
|
|
|
|
2018-07-14 04:49:34 +00:00
|
|
|
static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax,
|
2022-01-14 22:04:43 +00:00
|
|
|
struct vm_fault *vmf)
|
2016-05-14 19:20:44 +00:00
|
|
|
{
|
2017-02-22 23:40:03 +00:00
|
|
|
unsigned long pmd_addr = vmf->address & PMD_MASK;
|
2017-01-31 05:43:10 +00:00
|
|
|
struct device *dev = &dev_dax->dev;
|
2016-05-14 19:20:44 +00:00
|
|
|
phys_addr_t phys;
|
|
|
|
pgoff_t pgoff;
|
2022-01-14 22:04:43 +00:00
|
|
|
pfn_t pfn;
|
2017-03-10 20:24:22 +00:00
|
|
|
unsigned int fault_size = PMD_SIZE;
|
2016-05-14 19:20:44 +00:00
|
|
|
|
2017-01-31 05:43:10 +00:00
|
|
|
if (check_vma(dev_dax, vmf->vma, __func__))
|
2016-05-14 19:20:44 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
if (dev_dax->align > PMD_SIZE) {
|
2018-03-06 00:40:05 +00:00
|
|
|
dev_dbg(dev, "alignment (%#x) > fault size (%#x)\n",
|
2020-10-13 23:50:50 +00:00
|
|
|
dev_dax->align, fault_size);
|
2016-05-14 19:20:44 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
if (fault_size < dev_dax->align)
|
2017-03-10 20:24:22 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
2020-10-13 23:50:50 +00:00
|
|
|
else if (fault_size > dev_dax->align)
|
2017-03-10 20:24:22 +00:00
|
|
|
return VM_FAULT_FALLBACK;
|
|
|
|
|
|
|
|
/* if we are outside of the VMA */
|
|
|
|
if (pmd_addr < vmf->vma->vm_start ||
|
|
|
|
(pmd_addr + PMD_SIZE) > vmf->vma->vm_end)
|
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
|
2017-02-22 23:40:06 +00:00
|
|
|
pgoff = linear_page_index(vmf->vma, pmd_addr);
|
2017-05-05 06:38:43 +00:00
|
|
|
phys = dax_pgoff_to_phys(dev_dax, pgoff, PMD_SIZE);
|
2016-05-14 19:20:44 +00:00
|
|
|
if (phys == -1) {
|
2018-03-06 00:40:05 +00:00
|
|
|
dev_dbg(dev, "pgoff_to_phys(%#lx) failed\n", pgoff);
|
2016-05-14 19:20:44 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
|
2022-01-14 22:04:43 +00:00
|
|
|
pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP);
|
2016-05-14 19:20:44 +00:00
|
|
|
|
2022-01-14 22:04:43 +00:00
|
|
|
dax_set_mapping(vmf, pfn, fault_size);
|
2022-01-14 22:04:40 +00:00
|
|
|
|
2022-01-14 22:04:43 +00:00
|
|
|
return vmf_insert_pfn_pmd(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE);
|
2016-05-14 19:20:44 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 22:57:05 +00:00
|
|
|
#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
|
2018-07-14 04:49:34 +00:00
|
|
|
static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax,
|
2022-01-14 22:04:43 +00:00
|
|
|
struct vm_fault *vmf)
|
2017-02-24 22:57:05 +00:00
|
|
|
{
|
|
|
|
unsigned long pud_addr = vmf->address & PUD_MASK;
|
2017-01-31 05:43:10 +00:00
|
|
|
struct device *dev = &dev_dax->dev;
|
2017-02-24 22:57:05 +00:00
|
|
|
phys_addr_t phys;
|
|
|
|
pgoff_t pgoff;
|
2022-01-14 22:04:43 +00:00
|
|
|
pfn_t pfn;
|
2017-03-10 20:24:27 +00:00
|
|
|
unsigned int fault_size = PUD_SIZE;
|
|
|
|
|
2017-02-24 22:57:05 +00:00
|
|
|
|
2017-01-31 05:43:10 +00:00
|
|
|
if (check_vma(dev_dax, vmf->vma, __func__))
|
2017-02-24 22:57:05 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
if (dev_dax->align > PUD_SIZE) {
|
2018-03-06 00:40:05 +00:00
|
|
|
dev_dbg(dev, "alignment (%#x) > fault size (%#x)\n",
|
2020-10-13 23:50:50 +00:00
|
|
|
dev_dax->align, fault_size);
|
2017-02-24 22:57:05 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
if (fault_size < dev_dax->align)
|
2017-03-10 20:24:27 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
2020-10-13 23:50:50 +00:00
|
|
|
else if (fault_size > dev_dax->align)
|
2017-03-10 20:24:27 +00:00
|
|
|
return VM_FAULT_FALLBACK;
|
|
|
|
|
|
|
|
/* if we are outside of the VMA */
|
|
|
|
if (pud_addr < vmf->vma->vm_start ||
|
|
|
|
(pud_addr + PUD_SIZE) > vmf->vma->vm_end)
|
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
|
2017-02-24 22:57:05 +00:00
|
|
|
pgoff = linear_page_index(vmf->vma, pud_addr);
|
2017-05-05 06:38:43 +00:00
|
|
|
phys = dax_pgoff_to_phys(dev_dax, pgoff, PUD_SIZE);
|
2017-02-24 22:57:05 +00:00
|
|
|
if (phys == -1) {
|
2018-03-06 00:40:05 +00:00
|
|
|
dev_dbg(dev, "pgoff_to_phys(%#lx) failed\n", pgoff);
|
2017-02-24 22:57:05 +00:00
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
|
2022-01-14 22:04:43 +00:00
|
|
|
pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP);
|
2017-02-24 22:57:05 +00:00
|
|
|
|
2022-01-14 22:04:43 +00:00
|
|
|
dax_set_mapping(vmf, pfn, fault_size);
|
2022-01-14 22:04:40 +00:00
|
|
|
|
2022-01-14 22:04:43 +00:00
|
|
|
return vmf_insert_pfn_pud(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE);
|
2017-02-24 22:57:05 +00:00
|
|
|
}
|
|
|
|
#else
|
2018-07-14 04:49:34 +00:00
|
|
|
static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax,
|
2022-01-14 22:04:43 +00:00
|
|
|
struct vm_fault *vmf)
|
2017-02-24 22:57:05 +00:00
|
|
|
{
|
|
|
|
return VM_FAULT_FALLBACK;
|
|
|
|
}
|
|
|
|
#endif /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */
|
|
|
|
|
2023-08-18 20:23:35 +00:00
|
|
|
static vm_fault_t dev_dax_huge_fault(struct vm_fault *vmf, unsigned int order)
|
2016-05-14 19:20:44 +00:00
|
|
|
{
|
2017-02-22 23:40:06 +00:00
|
|
|
struct file *filp = vmf->vma->vm_file;
|
2018-09-04 22:46:26 +00:00
|
|
|
vm_fault_t rc = VM_FAULT_SIGBUS;
|
|
|
|
int id;
|
2017-01-31 05:43:10 +00:00
|
|
|
struct dev_dax *dev_dax = filp->private_data;
|
2016-05-14 19:20:44 +00:00
|
|
|
|
2023-08-18 20:23:35 +00:00
|
|
|
dev_dbg(&dev_dax->dev, "%s: %s (%#lx - %#lx) order:%d\n", current->comm,
|
2018-03-06 00:40:05 +00:00
|
|
|
(vmf->flags & FAULT_FLAG_WRITE) ? "write" : "read",
|
2023-08-18 20:23:35 +00:00
|
|
|
vmf->vma->vm_start, vmf->vma->vm_end, order);
|
2016-05-14 19:20:44 +00:00
|
|
|
|
2017-04-11 16:49:49 +00:00
|
|
|
id = dax_read_lock();
|
2023-08-18 20:23:35 +00:00
|
|
|
if (order == 0)
|
2022-01-14 22:04:43 +00:00
|
|
|
rc = __dev_dax_pte_fault(dev_dax, vmf);
|
2023-08-18 20:23:35 +00:00
|
|
|
else if (order == PMD_ORDER)
|
2022-01-14 22:04:43 +00:00
|
|
|
rc = __dev_dax_pmd_fault(dev_dax, vmf);
|
2023-08-18 20:23:35 +00:00
|
|
|
else if (order == PUD_ORDER)
|
2022-01-14 22:04:43 +00:00
|
|
|
rc = __dev_dax_pud_fault(dev_dax, vmf);
|
2023-08-18 20:23:35 +00:00
|
|
|
else
|
2017-04-11 16:12:25 +00:00
|
|
|
rc = VM_FAULT_SIGBUS;
|
2018-07-14 04:49:40 +00:00
|
|
|
|
2017-04-11 16:49:49 +00:00
|
|
|
dax_read_unlock(id);
|
2016-05-14 19:20:44 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-07-14 04:49:34 +00:00
|
|
|
static vm_fault_t dev_dax_fault(struct vm_fault *vmf)
|
2017-02-24 22:57:08 +00:00
|
|
|
{
|
2023-08-18 20:23:35 +00:00
|
|
|
return dev_dax_huge_fault(vmf, 0);
|
2017-02-24 22:57:08 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 03:08:17 +00:00
|
|
|
static int dev_dax_may_split(struct vm_area_struct *vma, unsigned long addr)
|
2017-11-30 00:10:32 +00:00
|
|
|
{
|
|
|
|
struct file *filp = vma->vm_file;
|
|
|
|
struct dev_dax *dev_dax = filp->private_data;
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
if (!IS_ALIGNED(addr, dev_dax->align))
|
2017-11-30 00:10:32 +00:00
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-05 23:24:28 +00:00
|
|
|
static unsigned long dev_dax_pagesize(struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct file *filp = vma->vm_file;
|
|
|
|
struct dev_dax *dev_dax = filp->private_data;
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
return dev_dax->align;
|
2018-04-05 23:24:28 +00:00
|
|
|
}
|
|
|
|
|
2017-01-31 05:43:10 +00:00
|
|
|
static const struct vm_operations_struct dax_vm_ops = {
|
|
|
|
.fault = dev_dax_fault,
|
|
|
|
.huge_fault = dev_dax_huge_fault,
|
2020-12-15 03:08:17 +00:00
|
|
|
.may_split = dev_dax_may_split,
|
2018-04-05 23:24:28 +00:00
|
|
|
.pagesize = dev_dax_pagesize,
|
2016-05-14 19:20:44 +00:00
|
|
|
};
|
|
|
|
|
2016-08-11 07:38:03 +00:00
|
|
|
static int dax_mmap(struct file *filp, struct vm_area_struct *vma)
|
2016-05-14 19:20:44 +00:00
|
|
|
{
|
2017-01-31 05:43:10 +00:00
|
|
|
struct dev_dax *dev_dax = filp->private_data;
|
2017-04-11 16:49:49 +00:00
|
|
|
int rc, id;
|
2016-05-14 19:20:44 +00:00
|
|
|
|
2018-03-06 00:40:05 +00:00
|
|
|
dev_dbg(&dev_dax->dev, "trace\n");
|
2016-05-14 19:20:44 +00:00
|
|
|
|
2017-04-11 16:49:49 +00:00
|
|
|
/*
|
|
|
|
* We lock to check dax_dev liveness and will re-check at
|
|
|
|
* fault time.
|
|
|
|
*/
|
|
|
|
id = dax_read_lock();
|
2017-01-31 05:43:10 +00:00
|
|
|
rc = check_vma(dev_dax, vma, __func__);
|
2017-04-11 16:49:49 +00:00
|
|
|
dax_read_unlock(id);
|
2016-05-14 19:20:44 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2017-01-31 05:43:10 +00:00
|
|
|
vma->vm_ops = &dax_vm_ops;
|
2023-01-26 19:37:49 +00:00
|
|
|
vm_flags_set(vma, VM_HUGEPAGE);
|
2016-05-14 19:20:44 +00:00
|
|
|
return 0;
|
2016-08-07 15:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return an unmapped area aligned to the dax region specified alignment */
|
2016-08-11 07:38:03 +00:00
|
|
|
static unsigned long dax_get_unmapped_area(struct file *filp,
|
2016-08-07 15:23:56 +00:00
|
|
|
unsigned long addr, unsigned long len, unsigned long pgoff,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
unsigned long off, off_end, off_align, len_align, addr_align, align;
|
2017-01-31 05:43:10 +00:00
|
|
|
struct dev_dax *dev_dax = filp ? filp->private_data : NULL;
|
2016-08-07 15:23:56 +00:00
|
|
|
|
2017-01-31 05:43:10 +00:00
|
|
|
if (!dev_dax || addr)
|
2016-08-07 15:23:56 +00:00
|
|
|
goto out;
|
|
|
|
|
2020-10-13 23:50:50 +00:00
|
|
|
align = dev_dax->align;
|
2016-08-07 15:23:56 +00:00
|
|
|
off = pgoff << PAGE_SHIFT;
|
|
|
|
off_end = off + len;
|
|
|
|
off_align = round_up(off, align);
|
|
|
|
|
|
|
|
if ((off_end <= off_align) || ((off_end - off_align) < align))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
len_align = len + align;
|
|
|
|
if ((off + len_align) < off)
|
|
|
|
goto out;
|
2016-05-14 19:20:44 +00:00
|
|
|
|
mm: switch mm->get_unmapped_area() to a flag
The mm_struct contains a function pointer *get_unmapped_area(), which is
set to either arch_get_unmapped_area() or arch_get_unmapped_area_topdown()
during the initialization of the mm.
Since the function pointer only ever points to two functions that are
named the same across all arch's, a function pointer is not really
required. In addition future changes will want to add versions of the
functions that take additional arguments. So to save a pointers worth of
bytes in mm_struct, and prevent adding additional function pointers to
mm_struct in future changes, remove it and keep the information about
which get_unmapped_area() to use in a flag.
Add the new flag to MMF_INIT_MASK so it doesn't get clobbered on fork by
mmf_init_flags(). Most MM flags get clobbered on fork. In the
pre-existing behavior mm->get_unmapped_area() would get copied to the new
mm in dup_mm(), so not clobbering the flag preserves the existing behavior
around inheriting the topdown-ness.
Introduce a helper, mm_get_unmapped_area(), to easily convert code that
refers to the old function pointer to instead select and call either
arch_get_unmapped_area() or arch_get_unmapped_area_topdown() based on the
flag. Then drop the mm->get_unmapped_area() function pointer. Leave the
get_unmapped_area() pointer in struct file_operations alone. The main
purpose of this change is to reorganize in preparation for future changes,
but it also converts the calls of mm->get_unmapped_area() from indirect
branches into a direct ones.
The stress-ng bigheap benchmark calls realloc a lot, which calls through
get_unmapped_area() in the kernel. On x86, the change yielded a ~1%
improvement there on a retpoline config.
In testing a few x86 configs, removing the pointer unfortunately didn't
result in any actual size reductions in the compiled layout of mm_struct.
But depending on compiler or arch alignment requirements, the change could
shrink the size of mm_struct.
Link: https://lkml.kernel.org/r/20240326021656.202649-3-rick.p.edgecombe@intel.com
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Deepak Gupta <debug@rivosinc.com>
Cc: Guo Ren <guoren@kernel.org>
Cc: Helge Deller <deller@gmx.de>
Cc: H. Peter Anvin (Intel) <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Naveen N. Rao <naveen.n.rao@linux.ibm.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-03-26 02:16:44 +00:00
|
|
|
addr_align = mm_get_unmapped_area(current->mm, filp, addr, len_align,
|
|
|
|
pgoff, flags);
|
2016-08-07 15:23:56 +00:00
|
|
|
if (!IS_ERR_VALUE(addr_align)) {
|
|
|
|
addr_align += (off - addr_align) & (align - 1);
|
|
|
|
return addr_align;
|
|
|
|
}
|
|
|
|
out:
|
mm: switch mm->get_unmapped_area() to a flag
The mm_struct contains a function pointer *get_unmapped_area(), which is
set to either arch_get_unmapped_area() or arch_get_unmapped_area_topdown()
during the initialization of the mm.
Since the function pointer only ever points to two functions that are
named the same across all arch's, a function pointer is not really
required. In addition future changes will want to add versions of the
functions that take additional arguments. So to save a pointers worth of
bytes in mm_struct, and prevent adding additional function pointers to
mm_struct in future changes, remove it and keep the information about
which get_unmapped_area() to use in a flag.
Add the new flag to MMF_INIT_MASK so it doesn't get clobbered on fork by
mmf_init_flags(). Most MM flags get clobbered on fork. In the
pre-existing behavior mm->get_unmapped_area() would get copied to the new
mm in dup_mm(), so not clobbering the flag preserves the existing behavior
around inheriting the topdown-ness.
Introduce a helper, mm_get_unmapped_area(), to easily convert code that
refers to the old function pointer to instead select and call either
arch_get_unmapped_area() or arch_get_unmapped_area_topdown() based on the
flag. Then drop the mm->get_unmapped_area() function pointer. Leave the
get_unmapped_area() pointer in struct file_operations alone. The main
purpose of this change is to reorganize in preparation for future changes,
but it also converts the calls of mm->get_unmapped_area() from indirect
branches into a direct ones.
The stress-ng bigheap benchmark calls realloc a lot, which calls through
get_unmapped_area() in the kernel. On x86, the change yielded a ~1%
improvement there on a retpoline config.
In testing a few x86 configs, removing the pointer unfortunately didn't
result in any actual size reductions in the compiled layout of mm_struct.
But depending on compiler or arch alignment requirements, the change could
shrink the size of mm_struct.
Link: https://lkml.kernel.org/r/20240326021656.202649-3-rick.p.edgecombe@intel.com
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Deepak Gupta <debug@rivosinc.com>
Cc: Guo Ren <guoren@kernel.org>
Cc: Helge Deller <deller@gmx.de>
Cc: H. Peter Anvin (Intel) <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Naveen N. Rao <naveen.n.rao@linux.ibm.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-03-26 02:16:44 +00:00
|
|
|
return mm_get_unmapped_area(current->mm, filp, addr, len, pgoff, flags);
|
2016-08-07 15:23:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 23:18:29 +00:00
|
|
|
static const struct address_space_operations dev_dax_aops = {
|
2022-02-09 20:22:13 +00:00
|
|
|
.dirty_folio = noop_dirty_folio,
|
2018-09-10 23:18:29 +00:00
|
|
|
};
|
|
|
|
|
2016-08-11 07:38:03 +00:00
|
|
|
static int dax_open(struct inode *inode, struct file *filp)
|
2016-08-07 15:23:56 +00:00
|
|
|
{
|
2017-04-11 16:49:49 +00:00
|
|
|
struct dax_device *dax_dev = inode_dax(inode);
|
|
|
|
struct inode *__dax_inode = dax_inode(dax_dev);
|
|
|
|
struct dev_dax *dev_dax = dax_get_private(dax_dev);
|
2016-08-07 15:23:56 +00:00
|
|
|
|
2018-03-06 00:40:05 +00:00
|
|
|
dev_dbg(&dev_dax->dev, "trace\n");
|
2017-04-11 16:49:49 +00:00
|
|
|
inode->i_mapping = __dax_inode->i_mapping;
|
|
|
|
inode->i_mapping->host = __dax_inode;
|
2018-09-10 23:18:29 +00:00
|
|
|
inode->i_mapping->a_ops = &dev_dax_aops;
|
2016-07-25 04:55:45 +00:00
|
|
|
filp->f_mapping = inode->i_mapping;
|
fs: new infrastructure for writeback error handling and reporting
Most filesystems currently use mapping_set_error and
filemap_check_errors for setting and reporting/clearing writeback errors
at the mapping level. filemap_check_errors is indirectly called from
most of the filemap_fdatawait_* functions and from
filemap_write_and_wait*. These functions are called from all sorts of
contexts to wait on writeback to finish -- e.g. mostly in fsync, but
also in truncate calls, getattr, etc.
The non-fsync callers are problematic. We should be reporting writeback
errors during fsync, but many places spread over the tree clear out
errors before they can be properly reported, or report errors at
nonsensical times.
If I get -EIO on a stat() call, there is no reason for me to assume that
it is because some previous writeback failed. The fact that it also
clears out the error such that a subsequent fsync returns 0 is a bug,
and a nasty one since that's potentially silent data corruption.
This patch adds a small bit of new infrastructure for setting and
reporting errors during address_space writeback. While the above was my
original impetus for adding this, I think it's also the case that
current fsync semantics are just problematic for userland. Most
applications that call fsync do so to ensure that the data they wrote
has hit the backing store.
In the case where there are multiple writers to the file at the same
time, this is really hard to determine. The first one to call fsync will
see any stored error, and the rest get back 0. The processes with open
fds may not be associated with one another in any way. They could even
be in different containers, so ensuring coordination between all fsync
callers is not really an option.
One way to remedy this would be to track what file descriptor was used
to dirty the file, but that's rather cumbersome and would likely be
slow. However, there is a simpler way to improve the semantics here
without incurring too much overhead.
This set adds an errseq_t to struct address_space, and a corresponding
one is added to struct file. Writeback errors are recorded in the
mapping's errseq_t, and the one in struct file is used as the "since"
value.
This changes the semantics of the Linux fsync implementation such that
applications can now use it to determine whether there were any
writeback errors since fsync(fd) was last called (or since the file was
opened in the case of fsync having never been called).
Note that those writeback errors may have occurred when writing data
that was dirtied via an entirely different fd, but that's the case now
with the current mapping_set_error/filemap_check_error infrastructure.
This will at least prevent you from getting a false report of success.
The new behavior is still consistent with the POSIX spec, and is more
reliable for application developers. This patch just adds some basic
infrastructure for doing this, and ensures that the f_wb_err "cursor"
is properly set when a file is opened. Later patches will change the
existing code to use this new infrastructure for reporting errors at
fsync time.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Reviewed-by: Jan Kara <jack@suse.cz>
2017-07-06 11:02:25 +00:00
|
|
|
filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping);
|
vfs: track per-sb writeback errors and report them to syncfs
Patch series "vfs: have syncfs() return error when there are writeback
errors", v6.
Currently, syncfs does not return errors when one of the inodes fails to
be written back. It will return errors based on the legacy AS_EIO and
AS_ENOSPC flags when syncing out the block device fails, but that's not
particularly helpful for filesystems that aren't backed by a blockdev.
It's also possible for a stray sync to lose those errors.
The basic idea in this set is to track writeback errors at the
superblock level, so that we can quickly and easily check whether
something bad happened without having to fsync each file individually.
syncfs is then changed to reliably report writeback errors after they
occur, much in the same fashion as fsync does now.
This patch (of 2):
Usually we suggest that applications call fsync when they want to ensure
that all data written to the file has made it to the backing store, but
that can be inefficient when there are a lot of open files.
Calling syncfs on the filesystem can be more efficient in some
situations, but the error reporting doesn't currently work the way most
people expect. If a single inode on a filesystem reports a writeback
error, syncfs won't necessarily return an error. syncfs only returns an
error if __sync_blockdev fails, and on some filesystems that's a no-op.
It would be better if syncfs reported an error if there were any
writeback failures. Then applications could call syncfs to see if there
are any errors on any open files, and could then call fsync on all of
the other descriptors to figure out which one failed.
This patch adds a new errseq_t to struct super_block, and has
mapping_set_error also record writeback errors there.
To report those errors, we also need to keep an errseq_t in struct file
to act as a cursor. This patch adds a dedicated field for that purpose,
which slots nicely into 4 bytes of padding at the end of struct file on
x86_64.
An earlier version of this patch used an O_PATH file descriptor to cue
the kernel that the open file should track the superblock error and not
the inode's writeback error.
I think that API is just too weird though. This is simpler and should
make syncfs error reporting "just work" even if someone is multiplexing
fsync and syncfs on the same fds.
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Andres Freund <andres@anarazel.de>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: David Howells <dhowells@redhat.com>
Link: http://lkml.kernel.org/r/20200428135155.19223-1-jlayton@kernel.org
Link: http://lkml.kernel.org/r/20200428135155.19223-2-jlayton@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-02 04:45:36 +00:00
|
|
|
filp->f_sb_err = file_sample_sb_err(filp);
|
2017-01-31 05:43:10 +00:00
|
|
|
filp->private_data = dev_dax;
|
2016-08-11 07:41:51 +00:00
|
|
|
inode->i_flags = S_DAX;
|
2016-08-07 15:23:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-05-14 19:20:44 +00:00
|
|
|
|
2016-08-11 07:38:03 +00:00
|
|
|
static int dax_release(struct inode *inode, struct file *filp)
|
2016-08-07 15:23:56 +00:00
|
|
|
{
|
2017-01-31 05:43:10 +00:00
|
|
|
struct dev_dax *dev_dax = filp->private_data;
|
2016-08-07 15:23:56 +00:00
|
|
|
|
2018-03-06 00:40:05 +00:00
|
|
|
dev_dbg(&dev_dax->dev, "trace\n");
|
2016-08-07 15:23:56 +00:00
|
|
|
return 0;
|
2016-05-14 19:20:44 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 16:15:08 +00:00
|
|
|
static const struct file_operations dax_fops = {
|
|
|
|
.llseek = noop_llseek,
|
|
|
|
.owner = THIS_MODULE,
|
2016-08-11 07:38:03 +00:00
|
|
|
.open = dax_open,
|
|
|
|
.release = dax_release,
|
|
|
|
.get_unmapped_area = dax_get_unmapped_area,
|
|
|
|
.mmap = dax_mmap,
|
2024-03-28 12:27:24 +00:00
|
|
|
.fop_flags = FOP_MMAP_SYNC,
|
2016-05-18 16:15:08 +00:00
|
|
|
};
|
|
|
|
|
2017-07-13 00:58:21 +00:00
|
|
|
static void dev_dax_cdev_del(void *cdev)
|
2016-08-07 15:23:56 +00:00
|
|
|
{
|
2017-07-13 00:58:21 +00:00
|
|
|
cdev_del(cdev);
|
|
|
|
}
|
2016-08-07 15:23:56 +00:00
|
|
|
|
2017-07-13 00:58:21 +00:00
|
|
|
static void dev_dax_kill(void *dev_dax)
|
|
|
|
{
|
|
|
|
kill_dev_dax(dev_dax);
|
2016-08-11 07:41:51 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 12:55:09 +00:00
|
|
|
static int dev_dax_probe(struct dev_dax *dev_dax)
|
2016-08-07 15:23:56 +00:00
|
|
|
{
|
2017-07-13 00:58:21 +00:00
|
|
|
struct dax_device *dax_dev = dev_dax->dax_dev;
|
2020-10-13 23:50:08 +00:00
|
|
|
struct device *dev = &dev_dax->dev;
|
2020-10-13 23:49:43 +00:00
|
|
|
struct dev_pagemap *pgmap;
|
2017-04-11 16:49:49 +00:00
|
|
|
struct inode *inode;
|
2016-07-24 22:55:42 +00:00
|
|
|
struct cdev *cdev;
|
2018-10-29 22:52:42 +00:00
|
|
|
void *addr;
|
2020-10-13 23:50:39 +00:00
|
|
|
int rc, i;
|
2018-10-29 22:52:42 +00:00
|
|
|
|
2022-01-14 22:04:33 +00:00
|
|
|
if (static_dev_dax(dev_dax)) {
|
|
|
|
if (dev_dax->nr_range > 1) {
|
|
|
|
dev_warn(dev,
|
|
|
|
"static pgmap / multi-range device conflict\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2020-10-13 23:50:39 +00:00
|
|
|
|
2022-01-14 22:04:33 +00:00
|
|
|
pgmap = dev_dax->pgmap;
|
|
|
|
} else {
|
|
|
|
if (dev_dax->pgmap) {
|
|
|
|
dev_warn(dev,
|
|
|
|
"dynamic-dax with pre-populated page map\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2020-10-13 23:50:39 +00:00
|
|
|
|
2022-01-14 22:04:29 +00:00
|
|
|
pgmap = devm_kzalloc(dev,
|
|
|
|
struct_size(pgmap, ranges, dev_dax->nr_range - 1),
|
|
|
|
GFP_KERNEL);
|
2020-10-13 23:49:43 +00:00
|
|
|
if (!pgmap)
|
|
|
|
return -ENOMEM;
|
2022-01-14 22:04:33 +00:00
|
|
|
|
2020-10-13 23:50:39 +00:00
|
|
|
pgmap->nr_range = dev_dax->nr_range;
|
2022-01-14 22:04:33 +00:00
|
|
|
dev_dax->pgmap = pgmap;
|
|
|
|
|
|
|
|
for (i = 0; i < dev_dax->nr_range; i++) {
|
|
|
|
struct range *range = &dev_dax->ranges[i].range;
|
|
|
|
pgmap->ranges[i] = *range;
|
|
|
|
}
|
2020-10-13 23:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dev_dax->nr_range; i++) {
|
|
|
|
struct range *range = &dev_dax->ranges[i].range;
|
|
|
|
|
|
|
|
if (!devm_request_mem_region(dev, range->start,
|
|
|
|
range_len(range), dev_name(dev))) {
|
|
|
|
dev_warn(dev, "mapping%d: %#llx-%#llx could not reserve range\n",
|
|
|
|
i, range->start, range->end);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2020-10-13 23:49:43 +00:00
|
|
|
}
|
2020-10-13 23:50:39 +00:00
|
|
|
|
2020-10-13 23:49:43 +00:00
|
|
|
pgmap->type = MEMORY_DEVICE_GENERIC;
|
2022-01-14 22:04:47 +00:00
|
|
|
if (dev_dax->align > PAGE_SIZE)
|
|
|
|
pgmap->vmemmap_shift =
|
|
|
|
order_base_2(dev_dax->align >> PAGE_SHIFT);
|
2020-10-13 23:49:43 +00:00
|
|
|
addr = devm_memremap_pages(dev, pgmap);
|
2019-06-13 22:56:33 +00:00
|
|
|
if (IS_ERR(addr))
|
2018-10-29 22:52:42 +00:00
|
|
|
return PTR_ERR(addr);
|
|
|
|
|
2017-04-11 16:49:49 +00:00
|
|
|
inode = dax_inode(dax_dev);
|
|
|
|
cdev = inode->i_cdev;
|
2016-07-24 22:55:42 +00:00
|
|
|
cdev_init(cdev, &dax_fops);
|
2021-11-15 21:20:57 +00:00
|
|
|
cdev->owner = dev->driver->owner;
|
2017-07-13 00:58:21 +00:00
|
|
|
cdev_set_parent(cdev, &dev->kobj);
|
|
|
|
rc = cdev_add(cdev, dev->devt, 1);
|
2016-07-20 00:51:40 +00:00
|
|
|
if (rc)
|
2017-07-13 00:58:21 +00:00
|
|
|
return rc;
|
2016-07-20 00:51:40 +00:00
|
|
|
|
2017-07-13 00:58:21 +00:00
|
|
|
rc = devm_add_action_or_reset(dev, dev_dax_cdev_del, cdev);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2016-08-07 15:23:56 +00:00
|
|
|
|
2017-07-13 00:58:21 +00:00
|
|
|
run_dax(dax_dev);
|
|
|
|
return devm_add_action_or_reset(dev, dev_dax_kill, dev_dax);
|
|
|
|
}
|
2016-08-07 15:23:56 +00:00
|
|
|
|
2018-11-07 23:31:23 +00:00
|
|
|
static struct dax_device_driver device_dax_driver = {
|
2020-10-13 23:50:08 +00:00
|
|
|
.probe = dev_dax_probe,
|
dax: Assign RAM regions to memory-hotplug by default
The default mode for device-dax instances is backwards for RAM-regions
as evidenced by the fact that it tends to catch end users by surprise.
"Where is my memory?". Recall that platforms are increasingly shipping
with performance-differentiated memory pools beyond typical DRAM and
NUMA effects. This includes HBM (high-bandwidth-memory) and CXL (dynamic
interleave, varied media types, and future fabric attached
possibilities).
For this reason the EFI_MEMORY_SP (EFI Special Purpose Memory => Linux
'Soft Reserved') attribute is expected to be applied to all memory-pools
that are not the general purpose pool. This designation gives an
Operating System a chance to defer usage of a memory pool until later in
the boot process where its performance properties can be interrogated
and administrator policy can be applied.
'Soft Reserved' memory can be anything from too limited and precious to
be part of the general purpose pool (HBM), too slow to host hot kernel
data structures (some PMEM media), or anything in between. However, in
the absence of an explicit policy, the memory should at least be made
usable by default. The current device-dax default hides all
non-general-purpose memory behind a device interface.
The expectation is that the distribution of users that want the memory
online by default vs device-dedicated-access by default follows the
Pareto principle. A small number of enlightened users may want to do
userspace memory management through a device, but general users just
want the kernel to make the memory available with an option to get more
advanced later.
Arrange for all device-dax instances not backed by PMEM to default to
attaching to the dax_kmem driver. From there the baseline memory hotplug
policy (CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE / memhp_default_state=)
gates whether the memory comes online or stays offline. Where, if it
stays offline, it can be reliably converted back to device-mode where it
can be partitioned, or fronted by a userspace allocator.
So, if someone wants device-dax instances for their 'Soft Reserved'
memory:
1/ Build a kernel with CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=n or boot
with memhp_default_state=offline, or roll the dice and hope that the
kernel has not pinned a page in that memory before step 2.
2/ Write a udev rule to convert the target dax device(s) from
'system-ram' mode to 'devdax' mode:
daxctl reconfigure-device $dax -m devdax -f
Cc: Michal Hocko <mhocko@suse.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Gregory Price <gregory.price@memverge.com>
Tested-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/167602003336.1924368.6809503401422267885.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-02-10 09:07:13 +00:00
|
|
|
.type = DAXDRV_DEVICE_TYPE,
|
2017-07-13 00:58:21 +00:00
|
|
|
};
|
2016-08-07 15:23:56 +00:00
|
|
|
|
2016-05-18 16:15:08 +00:00
|
|
|
static int __init dax_init(void)
|
|
|
|
{
|
2017-07-13 00:58:21 +00:00
|
|
|
return dax_driver_register(&device_dax_driver);
|
2016-05-18 16:15:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit dax_exit(void)
|
|
|
|
{
|
2018-11-07 23:31:23 +00:00
|
|
|
dax_driver_unregister(&device_dax_driver);
|
2016-05-18 16:15:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Intel Corporation");
|
2024-06-05 17:49:24 +00:00
|
|
|
MODULE_DESCRIPTION("Device DAX: direct access device driver");
|
2016-05-18 16:15:08 +00:00
|
|
|
MODULE_LICENSE("GPL v2");
|
2017-07-13 00:58:21 +00:00
|
|
|
module_init(dax_init);
|
2016-05-18 16:15:08 +00:00
|
|
|
module_exit(dax_exit);
|
2017-07-13 00:58:21 +00:00
|
|
|
MODULE_ALIAS_DAX_DEVICE(0);
|