Skip to content

Commit 295764c

Browse files
xiongzhazhenyw
authored andcommitted
drm/i915/gvt: Limit read hw reg to active vgpu
mmio_read_from_hw() let vgpu could read hw reg, if vgpu's workload is running on hw, things is good. Otherwise vgpu will get other vgpu's reg val, it is unsafe. This patch limit such hw access to active vgpu. If vgpu isn't running on hw, the reg read of this vgpu will get the last active val which saved at schedule_out. v2: ring timestamp is walking continuously even if the ring is idle. so read hw directly. (Zhenyu) Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.com> Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
1 parent 5c35258 commit 295764c

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

drivers/gpu/drm/i915/gvt/handlers.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,11 +1471,29 @@ static int skl_lcpll_write(struct intel_vgpu *vgpu, unsigned int offset,
14711471
static int mmio_read_from_hw(struct intel_vgpu *vgpu,
14721472
unsigned int offset, void *p_data, unsigned int bytes)
14731473
{
1474-
struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv;
1474+
struct intel_gvt *gvt = vgpu->gvt;
1475+
struct drm_i915_private *dev_priv = gvt->dev_priv;
1476+
int ring_id;
1477+
u32 ring_base;
1478+
1479+
ring_id = intel_gvt_render_mmio_to_ring_id(gvt, offset);
1480+
/**
1481+
* Read HW reg in following case
1482+
* a. the offset isn't a ring mmio
1483+
* b. the offset's ring is running on hw.
1484+
* c. the offset is ring time stamp mmio
1485+
*/
1486+
if (ring_id >= 0)
1487+
ring_base = dev_priv->engine[ring_id]->mmio_base;
1488+
1489+
if (ring_id < 0 || vgpu == gvt->scheduler.engine_owner[ring_id] ||
1490+
offset == i915_mmio_reg_offset(RING_TIMESTAMP(ring_base)) ||
1491+
offset == i915_mmio_reg_offset(RING_TIMESTAMP_UDW(ring_base))) {
1492+
mmio_hw_access_pre(dev_priv);
1493+
vgpu_vreg(vgpu, offset) = I915_READ(_MMIO(offset));
1494+
mmio_hw_access_post(dev_priv);
1495+
}
14751496

1476-
mmio_hw_access_pre(dev_priv);
1477-
vgpu_vreg(vgpu, offset) = I915_READ(_MMIO(offset));
1478-
mmio_hw_access_post(dev_priv);
14791497
return intel_vgpu_default_mmio_read(vgpu, offset, p_data, bytes);
14801498
}
14811499

drivers/gpu/drm/i915/gvt/scheduler.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ static inline bool is_gvt_request(struct drm_i915_gem_request *req)
131131
return i915_gem_context_force_single_submission(req->ctx);
132132
}
133133

134+
static void save_ring_hw_state(struct intel_vgpu *vgpu, int ring_id)
135+
{
136+
struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv;
137+
u32 ring_base = dev_priv->engine[ring_id]->mmio_base;
138+
i915_reg_t reg;
139+
140+
reg = RING_INSTDONE(ring_base);
141+
vgpu_vreg(vgpu, i915_mmio_reg_offset(reg)) = I915_READ_FW(reg);
142+
reg = RING_ACTHD(ring_base);
143+
vgpu_vreg(vgpu, i915_mmio_reg_offset(reg)) = I915_READ_FW(reg);
144+
reg = RING_ACTHD_UDW(ring_base);
145+
vgpu_vreg(vgpu, i915_mmio_reg_offset(reg)) = I915_READ_FW(reg);
146+
}
147+
134148
static int shadow_context_status_change(struct notifier_block *nb,
135149
unsigned long action, void *data)
136150
{
@@ -175,6 +189,7 @@ static int shadow_context_status_change(struct notifier_block *nb,
175189
break;
176190
case INTEL_CONTEXT_SCHEDULE_OUT:
177191
case INTEL_CONTEXT_SCHEDULE_PREEMPTED:
192+
save_ring_hw_state(workload->vgpu, ring_id);
178193
atomic_set(&workload->shadow_ctx_active, 0);
179194
break;
180195
default:

0 commit comments

Comments
 (0)