如何将从缓存值的一个prevent MMAP? [英] How would one prevent MMAP from caching values?

查看:143
本文介绍了如何将从缓存值的一个prevent MMAP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了ioremaps出口PCI BAR0为特定设备到sysfs的二进制属性允许用户空间来直接控制其Linux驱动程序。

I've written a linux driver that ioremaps exports PCI BAR0 for a particular device to a sysfs binary attribute allowing userspace to directly control it.

当我尝试MMAP对属性的顶部直接访问的内存位(从用户级程序)问题抚养。读取成功就好了,返回预期值,但是当我写内存这似乎是内核和内存,并不会传递到GMCH根联合体(因此设备)之间的某处缓存。我想要做的是在每次访问之后,隐式写内存屏障。

The problem rears when I attempt to MMAP on top of the attribute to directly access that bit of memory (from a userland program). Reads succeed just fine and return expected values, though when I write to that memory it appears to be cached somewhere between the kernel and memory and not delivered to the GMCH root complex (and therefore the device). What I'd like to do is have an implicit write memory barrier after each access.


  • 有什么办法prevent从缓存内核写入到内存的MMAP-ED位?

请按照UPS:


  • 呼吁则msync()后,每访问接受的方式来做到这一点?

  • Is calling msync() after every access the "accepted" way to do this?

推荐答案

要继续前进,回答这个问题我自己和我的解决方案。

Going to go ahead and answer this one myself with my solution.

在从我的sysfs MMAP功能的内核驱动程序,存在一个/include/asm/pgtable.h宏设置适当的标志为nocache'd PFN重映射。它看起来是这样的:

In the Kernel driver from my sysfs mmap function, there is a macro in /include/asm/pgtable.h that sets the proper flags for a nocache'd pfn remap. It looks like this:

vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
               vma->vm_end - vma->vm_start,
               vma->vm_page_prot))
    return -EAGAIN;

此外,在用户态mmap的,我用了MAP_SHARED标志,在标志的mmap参数。

Additionally, in the userland mmap, I used the MAP_SHARED flag in the mmap flags argument.

两者的结合最终奏效了。

The combination of the two ultimately did the trick.

这篇关于如何将从缓存值的一个prevent MMAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆