Skip to contentSkip to conversation

drm/amdgpu: fix wrong unit of vf2pf_work delay

PATCH New Sang-Heon Jeon 2 participants 2 messages Nov 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: fix wrong unit of vf2pf_work delay

The delay of schedule_delayed_work() is in jiffies. But amdgpu_virt_update_vf2pf_work_item() reschedules vf2pf_work with vf2pf_update_interval_ms without converting it, so the interval is in milliseconds only if HZ is 1000.

So use msecs_to_jiffies() when rescheduling.

Fixes 519b8b76f0b6 ("drm/amdgpu: Implement new guest side VF2PF message transaction (v2)")

---
I don't have a test environment, so this patch is compile tested only.

 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -1
index 915e2a069baf..f93d5df51528 100644
@@ -797,7 +797,8 @@ static void amdgpu_virt_update_vf2pf_work_item(struct work_struct *work)
 	amdgpu_virt_write_vf2pf_data(adev);
 
 out:
-	schedule_delayed_work(&(adev->virt.vf2pf_work), adev->virt.vf2pf_update_interval_ms);
+	schedule_delayed_work(&(adev->virt.vf2pf_work),
+			      msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));
 }
 
 static int amdgpu_virt_read_exchange_data_from_mem(struct amdgpu_device *adev, uint32_t *pfvf_data)

base-commit: 8dd68a79583aaf6df6fe4feea3ee9e9f26b02993

Signature · 1 line
2.53.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] drm/amdgpu: uncanceled vf2pf_work…

Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] drm/amdgpu: uncanceled vf2pf_work in amdgpu_virt_fini_data_exchange() [1]
--

commit a187e6fa4054f858fa9ab261be0ca76b1509f22d
Author: Sang-Heon Jeon <[email protected]>

drm/amdgpu: fix wrong unit of vf2pf_work delay

This commit converts adev->virt.vf2pf_update_interval_ms to jiffies via msecs_to_jiffies() when rescheduling adev->virt.vf2pf_work in amdgpu_virt_update_vf2pf_work_item().

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
index 915e2a069bafb..f93d5df51528c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c static void amdgpu_virt_update_vf2pf_work_item(struct work_struct *work) · line 804

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -1
@@ -797,7 +797,8 @@ static void amdgpu_virt_update_vf2pf_work_item(struct work_struct *work)
 	amdgpu_virt_write_vf2pf_data(adev);
 
 out:
-	schedule_delayed_work(&(adev->virt.vf2pf_work), adev->virt.vf2pf_update_interval_ms);
+	schedule_delayed_work(&(adev->virt.vf2pf_work),
+			      msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));
 }
 
 static int amdgpu_virt_read_exchange_data_from_mem(struct amdgpu_device *adev, uint32_t *pfvf_data)

[Severity: Critical]
This problem wasn't introduced by this patch, but can [1] leave adev->virt.vf2pf_work running after amdgpu_virt_fini_data_exchange() if amdgpu_virt_read_pf2vf_data() fails?

amdgpu_virt_init_data_exchange() resets adev->virt.vf2pf_update_interval_ms to 0, calls amdgpu_virt_exchange_data() -> amdgpu_virt_read_pf2vf_data() without checking its return value, and schedules adev->virt.vf2pf_work:

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:amdgpu_virt_fini_data_exchange() {
	if (adev->virt.vf2pf_update_interval_ms != 0) {
		dev_info(adev->dev, "clean up the vf2pf work item\n");
		cancel_delayed_work_sync(&adev->virt.vf2pf_work);
		adev->virt.vf2pf_update_interval_ms = 0;
	}
}
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:amdgpu_virt_init_data_exchange() {
    ...
	adev->virt.vf2pf_update_interval_ms = 0;
    ...
	} else if (fw_va || drv_va) {
		/* go through this logic in ip_init and reset to init workqueue*/
		amdgpu_virt_exchange_data(adev);

		schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));
    ...
}

When PF2VF header validation fails in amdgpu_virt_read_pf2vf_data(), vf2pf_update_interval_ms stays 0 while vf2pf_work is scheduled and rescheduled here with a zero delay. Because amdgpu_virt_fini_data_exchange() only cancels vf2pf_work when vf2pf_update_interval_ms is non-zero, teardown leaves the delayed work running in a tight zero-delay loop, leading to accesses to unmapped VRAM and a use-after-free on struct amdgpu_device.

[1] https://sashiko.dev/#/bug/linux-904ad1aa-33f1-44b8-a83c-632c07b49537

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1