Mark dma buffer readonly
Saket Sinha
saket.sinha89 at gmail.com
Wed Jan 31 09:19:29 EST 2018
Hi,
This is regarding dma memory usage in my kernel driver on arm64 processor.
I have a structure in my kernel driver as shown below-
struct dummy_dc_dmabuf {
struct dma_buf *buf;
struct dma_buf_attachment *attach;
struct sg_table *sgt;
};
For this I am able to get memory allocated like below
void pin_window(struct dummy_dmabuf **dum_buf, int fd, struct device *dev)
{
struct dummy_dmabuf *dum_dmabuf;
dma_addr_t dma_addr;
dum_dmabuf = kzalloc(sizeof(*dum_dmabuf), GFP_KERNEL);
if (!dum_dmabuf)
return -ENOMEM;
dum_dmabuf->buf = dma_buf_get(fd);
dum_dmabuf->attach = dma_buf_attach(dum_dmabuf->buf, dev->parent);
dum_dmabuf->sgt = dma_buf_map_attachment(dum_dmabuf->attach,
DMA_TO_DEVICE);
*dum_buf = dum_dmabuf;
}
As per ldd3 , Chapter 15 - "The DMA controller is a shared resource,
and confusion could arise if more than one
processor attempts to program it simultaneously. For that reason, the
controller is protected by a spinlock, called dma_spin_lock. Drivers
should not manipulate the
lock directly;"
However, I am using this in kthreads and I want to protect it without
using mutex/spilock.
Apart from protecting it with spinlock or mutex, is their anyway to
mark this dma buffer as read-only so that other threads(after
concerned thread has accessed it) cannot access the dma buffer.
Regards,
Saket Sinha
More information about the Kernelnewbies
mailing list