Commit 09475728 authored by Changbin Du's avatar Changbin Du Committed by Zhenyu Wang

drm/i915/gvt: Don't extend page_track to mpt layer

Don't extend page_track to mpt layer. Keep MPT simple and clean.
Meanwhile remove gtt.n_tracked_guest_page which doesn't make much
sense.

v2: clean up gtt.n_tracked_guest_page.
Signed-off-by: default avatarChangbin Du <changbin.du@intel.com>
Signed-off-by: default avatarZhenyu Wang <zhenyuw@linux.intel.com>
parent f66e5ff7
...@@ -678,7 +678,7 @@ static void ppgtt_free_spt(struct intel_vgpu_ppgtt_spt *spt) ...@@ -678,7 +678,7 @@ static void ppgtt_free_spt(struct intel_vgpu_ppgtt_spt *spt)
if (spt->guest_page.track.tracked) if (spt->guest_page.track.tracked)
intel_gvt_hypervisor_disable_page_track(spt->vgpu, intel_gvt_hypervisor_disable_page_track(spt->vgpu,
&spt->guest_page.track); spt->guest_page.track.gfn);
list_del_init(&spt->post_shadow_list); list_del_init(&spt->post_shadow_list);
free_spt(spt); free_spt(spt);
...@@ -926,10 +926,11 @@ static struct intel_vgpu_ppgtt_spt *ppgtt_populate_spt_by_guest_entry( ...@@ -926,10 +926,11 @@ static struct intel_vgpu_ppgtt_spt *ppgtt_populate_spt_by_guest_entry(
goto fail; goto fail;
} }
ret = intel_gvt_hypervisor_enable_page_track(vgpu, &spt->guest_page.track); ret = intel_gvt_hypervisor_enable_page_track(vgpu, spt->guest_page.track.gfn);
if (ret) if (ret)
goto fail; goto fail;
spt->guest_page.track.tracked = true;
ret = ppgtt_populate_spt(spt); ret = ppgtt_populate_spt(spt);
if (ret) if (ret)
goto fail; goto fail;
...@@ -1196,9 +1197,10 @@ static int ppgtt_set_guest_page_sync(struct intel_vgpu_ppgtt_spt *spt) ...@@ -1196,9 +1197,10 @@ static int ppgtt_set_guest_page_sync(struct intel_vgpu_ppgtt_spt *spt)
struct intel_vgpu_oos_page *oos_page = spt->guest_page.oos_page; struct intel_vgpu_oos_page *oos_page = spt->guest_page.oos_page;
int ret; int ret;
ret = intel_gvt_hypervisor_enable_page_track(spt->vgpu, &spt->guest_page.track); ret = intel_gvt_hypervisor_enable_page_track(spt->vgpu, spt->guest_page.track.gfn);
if (ret) if (ret)
return ret; return ret;
spt->guest_page.track.tracked = true;
trace_oos_change(spt->vgpu->id, "set page sync", oos_page->id, trace_oos_change(spt->vgpu->id, "set page sync", oos_page->id,
spt, spt->guest_page.type); spt, spt->guest_page.type);
...@@ -1234,6 +1236,7 @@ static int ppgtt_allocate_oos_page(struct intel_vgpu_ppgtt_spt *spt) ...@@ -1234,6 +1236,7 @@ static int ppgtt_allocate_oos_page(struct intel_vgpu_ppgtt_spt *spt)
static int ppgtt_set_guest_page_oos(struct intel_vgpu_ppgtt_spt *spt) static int ppgtt_set_guest_page_oos(struct intel_vgpu_ppgtt_spt *spt)
{ {
struct intel_vgpu_oos_page *oos_page = spt->guest_page.oos_page; struct intel_vgpu_oos_page *oos_page = spt->guest_page.oos_page;
int ret;
if (WARN(!oos_page, "shadow PPGTT page should have a oos page\n")) if (WARN(!oos_page, "shadow PPGTT page should have a oos page\n"))
return -EINVAL; return -EINVAL;
...@@ -1242,7 +1245,11 @@ static int ppgtt_set_guest_page_oos(struct intel_vgpu_ppgtt_spt *spt) ...@@ -1242,7 +1245,11 @@ static int ppgtt_set_guest_page_oos(struct intel_vgpu_ppgtt_spt *spt)
spt, spt->guest_page.type); spt, spt->guest_page.type);
list_add_tail(&oos_page->vm_list, &spt->vgpu->gtt.oos_page_list_head); list_add_tail(&oos_page->vm_list, &spt->vgpu->gtt.oos_page_list_head);
return intel_gvt_hypervisor_disable_page_track(spt->vgpu, &spt->guest_page.track); ret = intel_gvt_hypervisor_disable_page_track(spt->vgpu, spt->guest_page.track.gfn);
if (ret)
return ret;
spt->guest_page.track.tracked = false;
return 0;
} }
/** /**
...@@ -1917,7 +1924,6 @@ int intel_vgpu_write_protect_handler(struct intel_vgpu *vgpu, u64 pa, ...@@ -1917,7 +1924,6 @@ int intel_vgpu_write_protect_handler(struct intel_vgpu *vgpu, u64 pa,
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
int ret = 0; int ret = 0;
if (atomic_read(&vgpu->gtt.n_tracked_guest_page)) {
struct intel_vgpu_page_track *t; struct intel_vgpu_page_track *t;
mutex_lock(&gvt->lock); mutex_lock(&gvt->lock);
...@@ -1926,7 +1932,7 @@ int intel_vgpu_write_protect_handler(struct intel_vgpu *vgpu, u64 pa, ...@@ -1926,7 +1932,7 @@ int intel_vgpu_write_protect_handler(struct intel_vgpu *vgpu, u64 pa,
if (t) { if (t) {
if (unlikely(vgpu->failsafe)) { if (unlikely(vgpu->failsafe)) {
/* remove write protection to prevent furture traps */ /* remove write protection to prevent furture traps */
intel_gvt_hypervisor_disable_page_track(vgpu, t); intel_gvt_hypervisor_disable_page_track(vgpu, t->gfn);
} else { } else {
ret = t->handler(t, pa, p_data, bytes); ret = t->handler(t, pa, p_data, bytes);
if (ret) { if (ret) {
...@@ -1939,7 +1945,7 @@ int intel_vgpu_write_protect_handler(struct intel_vgpu *vgpu, u64 pa, ...@@ -1939,7 +1945,7 @@ int intel_vgpu_write_protect_handler(struct intel_vgpu *vgpu, u64 pa,
} }
} }
mutex_unlock(&gvt->lock); mutex_unlock(&gvt->lock);
}
return ret; return ret;
} }
......
...@@ -156,51 +156,29 @@ static inline unsigned long intel_gvt_hypervisor_virt_to_mfn(void *p) ...@@ -156,51 +156,29 @@ static inline unsigned long intel_gvt_hypervisor_virt_to_mfn(void *p)
/** /**
* intel_gvt_hypervisor_enable_page_track - track a guest page * intel_gvt_hypervisor_enable_page_track - track a guest page
* @vgpu: a vGPU * @vgpu: a vGPU
* @t: page track data structure * @gfn: the gfn of guest
* *
* Returns: * Returns:
* Zero on success, negative error code if failed. * Zero on success, negative error code if failed.
*/ */
static inline int intel_gvt_hypervisor_enable_page_track( static inline int intel_gvt_hypervisor_enable_page_track(
struct intel_vgpu *vgpu, struct intel_vgpu *vgpu, unsigned long gfn)
struct intel_vgpu_page_track *t)
{ {
int ret; return intel_gvt_host.mpt->enable_page_track(vgpu->handle, gfn);
if (t->tracked)
return 0;
ret = intel_gvt_host.mpt->enable_page_track(vgpu->handle, t->gfn);
if (ret)
return ret;
t->tracked = true;
atomic_inc(&vgpu->gtt.n_tracked_guest_page);
return 0;
} }
/** /**
* intel_gvt_hypervisor_disable_page_track - untrack a guest page * intel_gvt_hypervisor_disable_page_track - untrack a guest page
* @vgpu: a vGPU * @vgpu: a vGPU
* @t: page track data structure * @gfn: the gfn of guest
* *
* Returns: * Returns:
* Zero on success, negative error code if failed. * Zero on success, negative error code if failed.
*/ */
static inline int intel_gvt_hypervisor_disable_page_track( static inline int intel_gvt_hypervisor_disable_page_track(
struct intel_vgpu *vgpu, struct intel_vgpu *vgpu, unsigned long gfn)
struct intel_vgpu_page_track *t)
{ {
int ret; return intel_gvt_host.mpt->disable_page_track(vgpu->handle, gfn);
if (!t->tracked)
return 0;
ret = intel_gvt_host.mpt->disable_page_track(vgpu->handle, t->gfn);
if (ret)
return ret;
t->tracked = false;
atomic_dec(&vgpu->gtt.n_tracked_guest_page);
return 0;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment