Mirror memory mapping?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Mirror memory mapping?

Post by Ethin »

So, I've got a couple questions.

1. Is it feasible to "mirror" a mapped region automatically? For example, assume that I want to allocate a shared memory buffer in a userspace process to allow access to hardware. Then assume that that very same buffer needs access by another process. I could change the BARs associated with the device to use an address in physical memory that's associated with the first process, but if I change the BARs for the second process, the first process can no longer access the memory.
2. Is it a good idea to allow a userspace process to have access to, say, the ATA BAR regions if the process in question is an ATA driver in a microkernel? Or should that be conducted through IPC or syscalls?
vvaltchev
Member
Member
Posts: 274
Joined: Fri May 11, 2018 6:51 am

Re: Mirror memory mapping?

Post by vvaltchev »

Ethin wrote:1. Is it feasible to "mirror" a mapped region automatically? For example, assume that I want to allocate a shared memory buffer in a userspace process to allow access to hardware. Then assume that that very same buffer needs access by another process. I could change the BARs associated with the device to use an address in physical memory that's associated with the first process, but if I change the BARs for the second process, the first process can no longer access the memory.
For me, it makes total sense that each process has a separate mapping in its own virtual memory.
Ethin wrote:2. Is it a good idea to allow a userspace process to have access to, say, the ATA BAR regions if the process in question is an ATA driver in a microkernel? Or should that be conducted through IPC or syscalls?
I'm not writing a microkernel so, I might not be the right person to answer this question but, my 2 cents are: yes, in a microkernel it makes sense to have some special userspace processes that can control some hardware devices directly. Doing everything through IPC/syscalls might lead to unacceptable performance issues.
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: Mirror memory mapping?

Post by Octocontrabass »

Ethin wrote:1. Is it feasible to "mirror" a mapped region automatically?
Yes: put the same physical address into your page tables more than once.

I'm not sure why you bring up BARs. Those control the physical addresses of MMIO, not ordinary memory. Why would two userspace programs want to access the same MMIO?
Ethin wrote:2. Is it a good idea to allow a userspace process to have access to, say, the ATA BAR regions if the process in question is an ATA driver in a microkernel?
Yes. Direct access to I/O will always be faster than IPC or syscalls. You can limit a driver to only accessing its own I/O using paging for MMIO and the IOPB in the TSS for port I/O. Note that this doesn't include the PCI configuration space; you don't want drivers to mess with that without going through your kernel.
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: Mirror memory mapping?

Post by Ethin »

Octocontrabass wrote:Yes: put the same physical address into your page tables more than once.

I'm not sure why you bring up BARs. Those control the physical addresses of MMIO, not ordinary memory. Why would two userspace programs want to access the same MMIO?
Fair question, and just a hypothetical scenario. I was thinking about the Unix philosophy when I wrote that.
Post Reply