mmap'd physical memory not updating user virtual

I am writing a user space MAC driver in Linux 2.6.23 hosted on a Arm11 mpcore. A contiguous block of physical memory is allocated and mmap'd to userspace.

/dev/mem with O_SYNC flag is used to mmap so that the user virtual memory is uncached (with no much benefit).

Kernel
------
kptr = kmalloc(sz, GFP_DMA|GFP_KERNEL);
pptr = __pa(kptr);

User
----
fd = open("/dev/mem", O_RDWR|O_SYNC);
uptr = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED,fd, pptr);

The map'd user virtual memory is carved into network buffers and used for DMA.The MAC is successfully able to DMA ethernet frames to the physical memory. From the Rx interrupt handler bh (kernel logical memory) the frames received could be viewed and the cache functions also work fine. However, the mmap'd memory in user space does not reflect the changes.

Why is the physical memory mapped to user virtual does not reflect the chages ?

Or any suggestions on what could be going wrong here ?

thanks,
Deb Rupam Banerjee

P.S: Please note that all buffer alignment's are taken care of.

Hi Deb, How did you solve

dono8's picture

Hi Deb,

How did you solve this issue? I am also facing similar problem with ARM9. I have reserved 4M Bytes of memory at boot time, for using with the DMA and using the following code:

#define DMAMEM_START 0x73C00000

dma_fd = open("/dev/mem", O_RDWR | O_SYNC);
dma_mem = mmap(0, MSP2_DEV_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, dma_fd, DMAMEM_START);

DMA_write(DMAMEM_START, INST_Add, 16);
err = msync(dma_mem, (size_t) 64, MS_SYNC | MS_INVALIDATE);
DMA_read(INST_Add, DMAMEM_START+32, 16);

Using DMA_READ, I can see the data at DMAMEM_START, but sometime it is correct sometime incorrect.

I appreciate your step by step help!

Thanks,
Aa

DEVMEM

debrupam's picture

Mitch,

Thanks for your comments. I was able to solve the problem as follows:

I was using the cache (flush/inv) routines used on the kernel logical address and was able to see the DMA'd data. The same idea I used for the user virtual mapping and the DMA'd data was visible in the user space mapping.

thanks,
Deb

DEVMEM

Mitch Frazier's picture

Presumably mmap() is returning a valid pointer, correct? And you're not seeing any other errors occur, correct? You just never see the data change in the mapped area.

Does your kernel have CONFIG_STRICT_DEVMEM enabled?

Mitch Frazier is an Associate Editor for Linux Journal.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState