简体   繁体   English

为什么我对虚拟内存的写入在虚拟设备驱动程序中不可见?

[英]Why is my write to virtual memory not visible in Virtual Device Driver?

I have a custom driver that I've written meant to facilitate a custom mapping of exact hardware ram memory addresses into user land. 我有一个自定义驱动程序,我写的是为了便于将精确硬件RAM内存地址自定义映射到用户区。 I am trying to test that common memory mmap'd as shared between two processes to the same hardware address facilitates visible memory operations that each side can see. 我试图测试两个进程之间共享到同一硬件地址的公共内存mmap,这有助于每一方都能看到的可见内存操作。

My code is approximately something like this: 我的代码大概是这样的:

  //placement: in a mmap callback to a file_operations facilitated
  //    character device
  //phys_addr - a variable that I will ioremap for a virtual addr
  virtaddr = ioremap(phys_addr, size);
  if (!virtaddr) {
    printk(KERN_INFO "could not remap page!");
    goto out;
  } else { 
    printk(KERN_INFO "attempting write");
    *((int *)virtaddr) = 0xdeadbeef;
    //wmb(); <--- I haven't tried this yet
  }

As it so turns out, I thought maybe the issue was the lack of a write barrier to force the cache to flush to ram. 事实证明,我认为问题可能是缺少强制缓存刷新ram的写屏障。 I have to boot the test on some special hardware due to OS specifics that are outside the scope of this question. 由于操作系统的具体内容超出了本问题的范围,我必须在某些特殊硬件上启动测试。 I don't think that write barriers apply to main memory or ram quite like it does for device registers or device memory (ex: cache on a SSD or something). 我不认为写入障碍适用于主存储器或ram,就像它对设备寄存器或设备存储器一样(例如:SSD上的缓存等)。 So, I haven't tested wmb, but I just wanted to get my question out there. 所以,我没有测试过wmb,但我只想在那里提出我的问题。 I've searched around some as well through the Linux Device Drivers 3 book, and I've executed my code; 我通过Linux设备驱动程序3一书搜索了一些,我已经执行了我的代码; the fragment from which I am pulling is in fact executing and I know it because I can see the printk. 从我拉片段其实在执行我知道这是因为我能看到的printk。 The driver executes the code, but then just appears to keep on going. 驱动程序执行代码,但后来似乎继续。 Lastly, there's an analogous piece of code that performs on ioremap on a common piece of hardware memory, which it then tries to read from. 最后,有一段类似的代码片段在ioremap上执行一个共同的硬件内存,然后尝试从中读取。 That read doesn't contain the value that I wrote to it. 该读取不包含我写给它的值。

Why? 为什么?

Can you please tell exactly what you mean by this statement "hardware ram memory addresses into user land". 你能否准确地告诉你这句话“硬件ram内存地址进入用户域”是什么意思。

What type of device you are simulating [PCIe, USB etc] 您正在模拟哪种类型的设备[PCIe,USB等]

This all depends upon your CPU routing and as hardware is not connected then the translation will not cause fault instead it will send data over bus protocol which will just like fake packed generation from bus controller to device. 这一切都取决于您的CPU路由,并且由于硬件没有连接,因此转换不会导致故障,而是通过总线协议发送数据,这就像从总线控制器到设备的假包装生成一样。

To verify you can check bus transactions and in case of IO port mapping you can check using signals coming from specific port address/bits. 要验证您是否可以检查总线事务,并且在IO端口映射的情况下,您可以使用来自特定端口地址/位的信号进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM