Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4fafba2d authored by Zhenyu Wang's avatar Zhenyu Wang
Browse files

drm/i915/gvt: move write protect handler out of mmio emulation function



It's a bit confusing that page write protect handler is live in
mmio emulation handler. This moves it to stand alone gvt ops.

Also remove unnecessary check of write protected page access
in mmio read handler and cleanup handling of failsafe case.

v2: rebase

Reviewed-by: default avatarXiong Zhang <xiong.y.zhang@intel.com>
Signed-off-by: default avatarZhenyu Wang <zhenyuw@linux.intel.com>
parent 90551a12
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -1968,6 +1968,39 @@ int intel_vgpu_emulate_gtt_mmio_write(struct intel_vgpu *vgpu, unsigned int off,
	return ret;
}

int intel_vgpu_write_protect_handler(struct intel_vgpu *vgpu, u64 pa,
				     void *p_data, unsigned int bytes)
{
	struct intel_gvt *gvt = vgpu->gvt;
	int ret = 0;

	if (atomic_read(&vgpu->gtt.n_tracked_guest_page)) {
		struct intel_vgpu_page_track *t;

		mutex_lock(&gvt->lock);

		t = intel_vgpu_find_tracked_page(vgpu, pa >> PAGE_SHIFT);
		if (t) {
			if (unlikely(vgpu->failsafe)) {
				/* remove write protection to prevent furture traps */
				intel_vgpu_clean_page_track(vgpu, t);
			} else {
				ret = t->handler(t, pa, p_data, bytes);
				if (ret) {
					gvt_err("guest page write error %d, "
						"gfn 0x%lx, pa 0x%llx, "
						"var 0x%x, len %d\n",
						ret, t->gfn, pa,
						*(u32 *)p_data, bytes);
				}
			}
		}
		mutex_unlock(&gvt->lock);
	}
	return ret;
}


static int alloc_scratch_pages(struct intel_vgpu *vgpu,
		intel_gvt_gtt_type_t type)
{
+3 −0
Original line number Diff line number Diff line
@@ -308,4 +308,7 @@ int intel_vgpu_emulate_gtt_mmio_read(struct intel_vgpu *vgpu,
int intel_vgpu_emulate_gtt_mmio_write(struct intel_vgpu *vgpu,
	unsigned int off, void *p_data, unsigned int bytes);

int intel_vgpu_write_protect_handler(struct intel_vgpu *vgpu, u64 pa,
				     void *p_data, unsigned int bytes);

#endif /* _GVT_GTT_H_ */
+1 −0
Original line number Diff line number Diff line
@@ -183,6 +183,7 @@ static const struct intel_gvt_ops intel_gvt_ops = {
	.get_gvt_attrs = intel_get_gvt_attrs,
	.vgpu_query_plane = intel_vgpu_query_plane,
	.vgpu_get_dmabuf = intel_vgpu_get_dmabuf,
	.write_protect_handler = intel_vgpu_write_protect_handler,
};

/**
+2 −0
Original line number Diff line number Diff line
@@ -546,6 +546,8 @@ struct intel_gvt_ops {
			struct attribute_group ***intel_vgpu_type_groups);
	int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *);
	int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int);
	int (*write_protect_handler)(struct intel_vgpu *, u64, void *,
				     unsigned int);
};


+2 −2
Original line number Diff line number Diff line
@@ -1360,7 +1360,7 @@ static void kvmgt_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa,
					struct kvmgt_guest_info, track_node);

	if (kvmgt_gfn_is_write_protected(info, gpa_to_gfn(gpa)))
		intel_gvt_ops->emulate_mmio_write(info->vgpu, gpa,
		intel_gvt_ops->write_protect_handler(info->vgpu, gpa,
						     (void *)val, len);
}

Loading