pci: fail FLR when reset callback is missing#866
Conversation
tmakatos
left a comment
There was a problem hiding this comment.
This will break virtual NVMe in SPDK, see #461 (comment)
| return call_reset_cb(vfu_ctx, VFU_RESET_PCI_FLR); | ||
| } else { | ||
| vfu_log(vfu_ctx, LOG_ERR, "FLR callback is not implemented"); | ||
| return ERROR_INT(EINVAL); |
There was a problem hiding this comment.
I think the idea was that the device might not have anything to do for FLR, but maybe that's unlikely.
I think we need to document this somewhere if we make this change?
There was a problem hiding this comment.
@jlevon IIUC you're in favour of getting this merged? If we're not planning to work on proper support on SPDK then we should at least add a callback and make it a no-op?
There was a problem hiding this comment.
we do have one, right?
we do, got confused that this callback is specific to FLR but it isn't, we pass the reason
There was a problem hiding this comment.
I think the idea was that the device might not have anything to do for FLR, but maybe that's unlikely.
I think we need to document this somewhere if we make this change?
If the device advertises FLR then it should provide a reset callback, so I think the correct fix should be to fail adding the Device Control capability (pxdc) if a reset callback hasn't been provided. This means we'll have to document that the reset callback must be configured before adding capabilities.
There was a problem hiding this comment.
I'm not sure myself, but perhaps this should be a failure at realize time - so setup can still be in any order.
Wrong, NVMe does provide a reset callback. |
|
Thanks for the feedback — that makes sense to me. Catching this when the capability is added rather than when FLR is actually triggered does seem like the more correct place to enforce it, since it surfaces the misconfiguration at device setup time instead of waiting for a guest to hit it at runtime. I’m fairly new to this codebase, so I don’t have much visibility into how existing consumers structure their setup calls. A couple of things I wanted to check before attempting a rework:
Happy to take a shot at whichever direction makes sense — I just didn’t want to make assumptions given I don’t have the full picture of downstream usage yet. |
Yes it can be folded in this PR.
Our API is technically unstable so it's acceptable to break it in this way.
|
13f4f7c to
dfbd202
Compare
Devices advertising PCIe Function Level Reset (FLR) support must provide a reset callback. Validate this requirement during device realization rather than when the guest first triggers an FLR request, ensuring invalid device configurations fail early. Add a regression test verifying that vfu_realize_ctx() fails with EINVAL when an FLR-capable device does not register a reset callback. Signed-off-by: Siddharth C <siddharthcibi@icloud.com>
dfbd202 to
f2f038d
Compare
|
Updated per review feedback: moved the validation to vfu_realize_ctx() so the check happens during realization rather than when FLR is triggered, and added a regression test for the EINVAL case. |
| struct pxcap *px; | ||
|
|
||
| px = (struct pxcap *)pci_config_space_ptr(vfu_ctx, | ||
| vfu_ctx->pci_cap_exp_off); |
|
@zp78256pxd-ux checks are failing |
|
My current implementation validates this in vfu_realize_ctx(), which causes the samples/lspci example to fail because it advertises FLR support but does not register a reset callback. Would you prefer:
|
this |
|
Updated samples/lspci to register a trivial reset callback when advertising FLR support. This keeps the sample compatible with validation in vfu_realize_ctx() requiring a reset callback when FLR is enabled. Verified locally that samples/lspci builds and runs successfully with the change. My local make pre-push currently fails due to cmocka 2.0.2 deprecation warnings in existing unit tests (expect_check() with -Werror), which appears unrelated to this change |
What this PR does
Return EINVAL when a guest triggers PCI Function Level Reset (FLR) but no reset callback is registered.
Previously the library logged:
"FLR callback is not implemented"
but returned success to the client.
This caused FLR requests to appear successful even though no reset occurred.
Changes
when FLR is requested and reset callback is missing.
no registered reset callback.
Testing
pytest test/py/test_pci_caps.py -k "write_px" -vv