Direct memory mapping in DIMM

Suppose you have 2 DIMMs inserted in an Intel x86-64 motherboard. All memory interleaving (bank and channel) is disabled.

What I'm trying to do is to reserve the physical memory space of one of these DIMMs from Linux kernel (version 4.11.11 ) and set this physical (reserved) memory space for the application. DIMMs will not be moved in memory channels. How can I do it? What will this process be like? I am new to kernel development and can use the manual.

What I have found so far:

  • To reserve memory from the Linux kernel, you can specify the boot parameter memmap=nn[KMG]$ss[KMG] . This parameter marks a specific memory as a reserved memory area from ss to ss + nn.

  • mmap can be used to establish a mapping between the process address space at pa address for len bytes to the memory object represented by the fildes file descriptor at offset for len bytes.

After the memory is reserved, I assume that a personal device driver is needed to call the reserved memory into the user space application? Thoughts?


Update

It should also be noted that the DIMM to be reserved will have its own dedicated memory channel, and no bank or channel interleaving will be enabled.

+5
source share
1 answer

Displaying /dev/mem is an easy way. I have done this before. View mmap from kernel source :

 static int mmap_mem(struct file *file, struct vm_area_struct *vma) { size_t size = vma->vm_end - vma->vm_start; phys_addr_t offset = (phys_addr_t)vma->vm_pgoff << PAGE_SHIFT; /* It illegal to wrap around the end of the physical address space. */ if (offset + (phys_addr_t)size - 1 < offset) return -EINVAL; if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size)) return -EINVAL; if (!private_mapping_ok(vma)) return -ENOSYS; if (!range_is_allowed(vma->vm_pgoff, size)) return -EPERM; if (!phys_mem_access_prot_allowed(file, vma->vm_pgoff, size, &vma->vm_page_prot)) return -EINVAL; vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, size, vma->vm_page_prot); vma->vm_ops = &mmap_mem_ops; /* Remap-pfn-range will mark the range VM_IO */ if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size, vma->vm_page_prot)) { return -EAGAIN; } return 0; } 

The only thing you need to change is valid_mmap_phys_addr_range(vma->vm_pgoff, size) . Or you can write your own driver version /dev/mem .

0
source

Source: https://habr.com/ru/post/1271406/


All Articles