Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map_pci_memory: workaround for kernel race condition #1476

Merged
merged 3 commits into from
Jul 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/lib/hardware/pci.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,19 @@ end

function map_pci_memory (f)
local st = assert(f:stat())
local mem = assert(f:mmap(nil, st.size, "read, write", "shared", 0))
local mem, err = f:mmap(nil, st.size, "read, write", "shared", 0)
-- mmap() returns EINVAL on Linux >= 4.5 if the device is still
-- claimed by the kernel driver. We assume that
-- unbind_device_from_linux() has already been called but it may take
-- some time for the driver to release the device.
if not mem and err.INVAL then
lib.waitfor2("mmap of "..filepath,
function ()
mem, err = f:mmap(nil, st.size, "read, write", "shared", 0)
return mem ~= nil or not err.INVAL
end, 5, 1000000)
end
assert(mem, err)
return ffi.cast("uint32_t *", mem)
end

Expand Down