VFIO PCIe BAR写入无法工作。在程序执行完成后,寄存器值会回退。

huangapple go评论69阅读模式
英文:

VFIO PCIe BAR write won't work. Register value falls back when program execution finished

问题

我使用以下代码来通过VFIO_PCI API测试PCIe BAR寄存器的写入。

然而,只有在程序仍在运行时,写入才会生效。在程序执行完成后,该值总是回退。

我已验证这不是因为缓存,因为只要程序仍在运行,我可以在FPGA中看到寄存器值的变化。

我的问题是:我应该怎么做才能使我的写入持久化?

英文:

I am using the following code to test a PCIe BAR register write through VFIO_PCI APIs.


`   struct vfio_group_status group_status = { .argsz = sizeof(group_status) };
    struct vfio_device_info device_info = { .argsz = sizeof(device_info) };
    struct vfio_region_info reg = { .argsz = sizeof(reg) };
    int container = open("/dev/vfio/vfio", O_RDWR);
    int group = open("/dev/vfio/17", O_RDWR);

    /* Add the group to the container */
    ioctl(group, VFIO_GROUP_SET_CONTAINER, &container);
    /* Enable the IOMMU model we want */
    ioctl(container, VFIO_SET_IOMMU, VFIO_TYPE1_IOMMU);

    int dev = ioctl(group, VFIO_GROUP_GET_DEVICE_FD, "0000:02:00.0");

    void* ptr;
    ptr = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, dev, ( 0UL << 40));
    cout << *((unsigned int *)ptr + 0x202) << endl; //this always print out 0
    *((unsigned int *)ptr + 0x202) = 4; //write 4
    cout << *((unsigned int *)ptr + 0x202) << endl;` //this always print out 4

However, the write will take effect only if the program is still running. After the program execution finished, the value always falls back.

I have verified this is not because of cache, because I can see the register value change in the FPGA while the program is still running.

My question is: what can I do to make my write persistent?

答案1

得分: 0

我发现了这个相关帖子。显然,这是一种预期的行为:如果使用VFIO-PCI来控制PCIe设备。 "vfio_pci_try_bus_reset"将在进程完成时被调用。导致设备被重置。如帖子中所述,如果可以添加一个模块参数来绕过重置,那将非常好。但到目前为止,似乎还没有这个参数。

英文:

For any one who might encouter with this in the future.

I found this related post. Apparently, this is an expected behavior: if VFIO-PCI is used to control a PCIe device. "vfio_pci_try_bus_reset" will be called upon a process finished. Causing the device to be reset. As mentioned in the post, it would be nice if a module parameter can be added to by pass the reset. But so far it seems that the parameter is not there yet.

huangapple
  • 本文由 发表于 2023年3月12日 14:51:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75711503.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定