Re: [PATCH v3 7/9] rust: vfio: add PCI variant driver abstractions

From: Danilo Krummrich

Date: Thu Nov 26 2026 - 18:12:28 EST


(Cc: Rafael)

On Thu Nov 26, 2026 at 4:01 PM CET, Simon Song wrote:
> On 11/25/2026 3:51 PM, Danilo Krummrich wrote:
>
>>> +impl RuntimeActive {
>>> + fn new(dev: &device::Device<device::Bound>) -> Result<Self> {
>>> + // SAFETY: `dev` is a valid device. This is `pm_runtime_get_sync()`, which takes a usage
>>> + // reference even if it fails.
>>> + #[cfg(CONFIG_PM)]
>>> + let ret =
>>> + unsafe { bindings::__pm_runtime_resume(dev.as_raw(), bindings::RPM_GET_PUT as c_int) };
>>> + #[cfg(not(CONFIG_PM))]
>>> + let ret = 0;
>>> + // INVARIANT: `this` owns the usage reference, and drops it if the resume failed.
>>> + let this = Self(dev.into());
>>> + to_result(ret)?;
>>> + Ok(this)
>>> + }
>>> +}
>>> +
>>> +impl Drop for RuntimeActive {
>>> + fn drop(&mut self) {
>>> + // SAFETY: `self.0` is a valid device, and `new()` took the usage reference dropped
>>> + // here. This is `pm_runtime_put()`.
>>> + #[cfg(CONFIG_PM)]
>>> + unsafe {
>>> + bindings::__pm_runtime_idle(
>>> + self.0.as_raw(),
>>> + (bindings::RPM_GET_PUT | bindings::RPM_ASYNC) as c_int,
>>> + )
>>> + };
>>> + }
>>> +}
>>
>> This seems reasonable, but doesn't belong into VFIO core code. This should e.g.
>> go under rust/kernel/device/pm.rs.
>>
>> However, it would become dead code once we land the runtime PM stuff and enable
>> it for PCI, right? I think an alternative could be to just make nova-vgpu depend
>> on !PM.
>>
>
> Right, this goes away once driver has runtime PM callbacks, I tried !PM and it
> works, but CONFIG_PM is set in x86_64_defconfig and allmodconfig, so driver
> won't be built there with default option for x86, would you rather keep
> RuntimeActive and moved it to pm.rs or prefer to depend on the CONFIG_PM until
> the runtime PM for PCI lands?

Right, in this case I'd just inline the call to __pm_runtime_resume() into
Registration::new() and the call to __pm_runtime_idle() into
Registration::drop() to keep it as local as possible.

We can then replace it with the proper bus PM handling once the core PM code
lands; I will send the corresponding PCI changes soon.

Rafael, please let me know if you have any concerns.

Thanks,
Danilo