Commit 44b46733 authored by Changbin Du's avatar Changbin Du Committed by Zhenyu Wang

drm/i915/gvt: Rework shadow page management code

This is a another big one and the GVT shadow page management code is
heavily refined.

The new code only use struct intel_vgpu_ppgtt_spt to represent a vgpu
shadow page table - w/ or wo/ a guest page associated with. A pure shadow
page (no guest page associated) will be used to shadow splited 2M huge
gtt. In this case, the spt.guest_page.gfn should be a zero.

To search a existed shadow page table, we have two new interfaces:
 - intel_vgpu_find_spt_by_gfn(), find a spt by guest gfn. It must not
   be a pure spt.
 - intel_vgpu_find_spt_by_mfn, Find the spt using shadow page mfn in
   shadowed PTE.

The oos_page management is remained as what is was.

v2: Split some changes into small standalone patches.
Signed-off-by: default avatarChangbin Du <changbin.du@intel.com>
Signed-off-by: default avatarZhenyu Wang <zhenyuw@linux.intel.com>
parent 72f03d7e
...@@ -593,11 +593,11 @@ static inline int ppgtt_spt_set_entry( ...@@ -593,11 +593,11 @@ static inline int ppgtt_spt_set_entry(
#define ppgtt_get_guest_entry(spt, e, index) \ #define ppgtt_get_guest_entry(spt, e, index) \
ppgtt_spt_get_entry(spt, NULL, \ ppgtt_spt_get_entry(spt, NULL, \
spt->guest_page_type, e, index, true) spt->guest_page.type, e, index, true)
#define ppgtt_set_guest_entry(spt, e, index) \ #define ppgtt_set_guest_entry(spt, e, index) \
ppgtt_spt_set_entry(spt, NULL, \ ppgtt_spt_set_entry(spt, NULL, \
spt->guest_page_type, e, index, true) spt->guest_page.type, e, index, true)
#define ppgtt_get_shadow_entry(spt, e, index) \ #define ppgtt_get_shadow_entry(spt, e, index) \
ppgtt_spt_get_entry(spt, spt->shadow_page.vaddr, \ ppgtt_spt_get_entry(spt, spt->shadow_page.vaddr, \
...@@ -607,52 +607,29 @@ static inline int ppgtt_spt_set_entry( ...@@ -607,52 +607,29 @@ static inline int ppgtt_spt_set_entry(
ppgtt_spt_set_entry(spt, spt->shadow_page.vaddr, \ ppgtt_spt_set_entry(spt, spt->shadow_page.vaddr, \
spt->shadow_page.type, e, index, false) spt->shadow_page.type, e, index, false)
/** #define page_track_to_ppgtt_spt(ptr) \
* intel_vgpu_init_page_track - init a page track data structure container_of(ptr, struct intel_vgpu_ppgtt_spt, guest_page.track)
* @vgpu: a vGPU
* @t: a page track data structure static void *alloc_spt(gfp_t gfp_mask)
* @gfn: guest memory page frame number
* @handler: the function will be called when target guest memory page has
* been modified.
*
* This function is called when a user wants to prepare a page track data
* structure to track a guest memory page.
*
* Returns:
* Zero on success, negative error code if failed.
*/
int intel_vgpu_init_page_track(struct intel_vgpu *vgpu,
struct intel_vgpu_page_track *t,
unsigned long gfn,
int (*handler)(void *, u64, void *, int),
void *data)
{ {
INIT_HLIST_NODE(&t->node); struct intel_vgpu_ppgtt_spt *spt;
t->tracked = false; spt = kzalloc(sizeof(*spt), gfp_mask);
t->gfn = gfn; if (!spt)
t->handler = handler; return NULL;
t->data = data;
hash_add(vgpu->gtt.tracked_guest_page_hash_table, &t->node, t->gfn); spt->shadow_page.page = alloc_page(gfp_mask);
return 0; if (!spt->shadow_page.page) {
kfree(spt);
return NULL;
}
return spt;
} }
/** static void free_spt(struct intel_vgpu_ppgtt_spt *spt)
* intel_vgpu_clean_page_track - release a page track data structure
* @vgpu: a vGPU
* @t: a page track data structure
*
* This function is called before a user frees a page track data structure.
*/
void intel_vgpu_clean_page_track(struct intel_vgpu *vgpu,
struct intel_vgpu_page_track *t)
{ {
if (!hlist_unhashed(&t->node)) __free_page(spt->shadow_page.page);
hash_del(&t->node); kfree(spt);
if (t->tracked)
intel_gvt_hypervisor_disable_page_track(vgpu, t);
} }
/** /**
...@@ -679,139 +656,53 @@ struct intel_vgpu_page_track *intel_vgpu_find_tracked_page( ...@@ -679,139 +656,53 @@ struct intel_vgpu_page_track *intel_vgpu_find_tracked_page(
return NULL; return NULL;
} }
static int init_guest_page(struct intel_vgpu *vgpu,
struct intel_vgpu_guest_page *p,
unsigned long gfn,
int (*handler)(void *, u64, void *, int),
void *data)
{
p->oos_page = NULL;
p->write_cnt = 0;
return intel_vgpu_init_page_track(vgpu, &p->track, gfn, handler, data);
}
static int detach_oos_page(struct intel_vgpu *vgpu, static int detach_oos_page(struct intel_vgpu *vgpu,
struct intel_vgpu_oos_page *oos_page); struct intel_vgpu_oos_page *oos_page);
static void clean_guest_page(struct intel_vgpu *vgpu, static void ppgtt_free_shadow_page(struct intel_vgpu_ppgtt_spt *spt)
struct intel_vgpu_guest_page *p)
{
if (p->oos_page)
detach_oos_page(vgpu, p->oos_page);
intel_vgpu_clean_page_track(vgpu, &p->track);
}
static inline int init_shadow_page(struct intel_vgpu *vgpu,
struct intel_vgpu_shadow_page *p, int type, bool hash)
{ {
struct device *kdev = &vgpu->gvt->dev_priv->drm.pdev->dev; struct device *kdev = &spt->vgpu->gvt->dev_priv->drm.pdev->dev;
dma_addr_t daddr;
daddr = dma_map_page(kdev, p->page, 0, 4096, PCI_DMA_BIDIRECTIONAL);
if (dma_mapping_error(kdev, daddr)) {
gvt_vgpu_err("fail to map dma addr\n");
return -EINVAL;
}
p->vaddr = page_address(p->page); trace_spt_free(spt->vgpu->id, spt, spt->guest_page.type);
p->type = type;
INIT_HLIST_NODE(&p->node); dma_unmap_page(kdev, spt->shadow_page.mfn << I915_GTT_PAGE_SHIFT, 4096,
p->mfn = daddr >> I915_GTT_PAGE_SHIFT;
if (hash)
hash_add(vgpu->gtt.shadow_page_hash_table, &p->node, p->mfn);
return 0;
}
static inline void clean_shadow_page(struct intel_vgpu *vgpu,
struct intel_vgpu_shadow_page *p)
{
struct device *kdev = &vgpu->gvt->dev_priv->drm.pdev->dev;
dma_unmap_page(kdev, p->mfn << I915_GTT_PAGE_SHIFT, 4096,
PCI_DMA_BIDIRECTIONAL); PCI_DMA_BIDIRECTIONAL);
if (!hlist_unhashed(&spt->node))
hash_del(&spt->node);
if (!hlist_unhashed(&p->node)) if (spt->guest_page.oos_page)
hash_del(&p->node); detach_oos_page(spt->vgpu, spt->guest_page.oos_page);
}
static inline struct intel_vgpu_shadow_page *find_shadow_page(
struct intel_vgpu *vgpu, unsigned long mfn)
{
struct intel_vgpu_shadow_page *p;
hash_for_each_possible(vgpu->gtt.shadow_page_hash_table,
p, node, mfn) {
if (p->mfn == mfn)
return p;
}
return NULL;
}
#define page_track_to_guest_page(ptr) \
container_of(ptr, struct intel_vgpu_guest_page, track)
#define guest_page_to_ppgtt_spt(ptr) \
container_of(ptr, struct intel_vgpu_ppgtt_spt, guest_page)
#define shadow_page_to_ppgtt_spt(ptr) \
container_of(ptr, struct intel_vgpu_ppgtt_spt, shadow_page)
static void *alloc_spt(gfp_t gfp_mask)
{
struct intel_vgpu_ppgtt_spt *spt;
spt = kzalloc(sizeof(*spt), gfp_mask);
if (!spt)
return NULL;
spt->shadow_page.page = alloc_page(gfp_mask);
if (!spt->shadow_page.page) {
kfree(spt);
return NULL;
}
return spt;
}
static void free_spt(struct intel_vgpu_ppgtt_spt *spt) if (!hlist_unhashed(&spt->guest_page.track.node))
{ hash_del(&spt->guest_page.track.node);
__free_page(spt->shadow_page.page);
kfree(spt);
}
static void ppgtt_free_shadow_page(struct intel_vgpu_ppgtt_spt *spt) if (spt->guest_page.track.tracked)
{ intel_gvt_hypervisor_disable_page_track(spt->vgpu,
trace_spt_free(spt->vgpu->id, spt, spt->shadow_page.type); &spt->guest_page.track);
clean_shadow_page(spt->vgpu, &spt->shadow_page);
clean_guest_page(spt->vgpu, &spt->guest_page);
list_del_init(&spt->post_shadow_list); list_del_init(&spt->post_shadow_list);
free_spt(spt); free_spt(spt);
} }
static void ppgtt_free_all_shadow_page(struct intel_vgpu *vgpu) static void ppgtt_free_all_shadow_page(struct intel_vgpu *vgpu)
{ {
struct hlist_node *n; struct hlist_node *n;
struct intel_vgpu_shadow_page *sp; struct intel_vgpu_ppgtt_spt *spt;
int i; int i;
hash_for_each_safe(vgpu->gtt.shadow_page_hash_table, i, n, sp, node) hash_for_each_safe(vgpu->gtt.shadow_page_hash_table, i, n, spt, node)
ppgtt_free_shadow_page(shadow_page_to_ppgtt_spt(sp)); ppgtt_free_shadow_page(spt);
} }
static int ppgtt_handle_guest_write_page_table_bytes( static int ppgtt_handle_guest_write_page_table_bytes(
struct intel_vgpu_guest_page *gpt, struct intel_vgpu_ppgtt_spt *spt,
u64 pa, void *p_data, int bytes); u64 pa, void *p_data, int bytes);
static int ppgtt_write_protection_handler(void *data, u64 pa, static int ppgtt_write_protection_handler(void *data, u64 pa,
void *p_data, int bytes) void *p_data, int bytes)
{ {
struct intel_vgpu_page_track *t = data; struct intel_vgpu_page_track *t = data;
struct intel_vgpu_guest_page *p = page_track_to_guest_page(t); struct intel_vgpu_ppgtt_spt *spt = page_track_to_ppgtt_spt(t);
int ret; int ret;
if (bytes != 4 && bytes != 8) if (bytes != 4 && bytes != 8)
...@@ -820,20 +711,47 @@ static int ppgtt_write_protection_handler(void *data, u64 pa, ...@@ -820,20 +711,47 @@ static int ppgtt_write_protection_handler(void *data, u64 pa,
if (!t->tracked) if (!t->tracked)
return -EINVAL; return -EINVAL;
ret = ppgtt_handle_guest_write_page_table_bytes(p, ret = ppgtt_handle_guest_write_page_table_bytes(spt,
pa, p_data, bytes); pa, p_data, bytes);
if (ret) if (ret)
return ret; return ret;
return ret; return ret;
} }
/* Find a spt by guest gfn. */
static struct intel_vgpu_ppgtt_spt *intel_vgpu_find_spt_by_gfn(
struct intel_vgpu *vgpu, unsigned long gfn)
{
struct intel_vgpu_page_track *track;
track = intel_vgpu_find_tracked_page(vgpu, gfn);
if (track)
return page_track_to_ppgtt_spt(track);
return NULL;
}
/* Find the spt by shadow page mfn. */
static struct intel_vgpu_ppgtt_spt *intel_vgpu_find_spt_by_mfn(
struct intel_vgpu *vgpu, unsigned long mfn)
{
struct intel_vgpu_ppgtt_spt *spt;
hash_for_each_possible(vgpu->gtt.shadow_page_hash_table, spt, node, mfn) {
if (spt->shadow_page.mfn == mfn)
return spt;
}
return NULL;
}
static int reclaim_one_ppgtt_mm(struct intel_gvt *gvt); static int reclaim_one_ppgtt_mm(struct intel_gvt *gvt);
static struct intel_vgpu_ppgtt_spt *ppgtt_alloc_shadow_page( static struct intel_vgpu_ppgtt_spt *ppgtt_alloc_shadow_page(
struct intel_vgpu *vgpu, int type, unsigned long gfn) struct intel_vgpu *vgpu, int type, unsigned long gfn)
{ {
struct device *kdev = &vgpu->gvt->dev_priv->drm.pdev->dev;
struct intel_vgpu_ppgtt_spt *spt = NULL; struct intel_vgpu_ppgtt_spt *spt = NULL;
int ret; dma_addr_t daddr;
retry: retry:
spt = alloc_spt(GFP_KERNEL | __GFP_ZERO); spt = alloc_spt(GFP_KERNEL | __GFP_ZERO);
...@@ -846,44 +764,39 @@ static struct intel_vgpu_ppgtt_spt *ppgtt_alloc_shadow_page( ...@@ -846,44 +764,39 @@ static struct intel_vgpu_ppgtt_spt *ppgtt_alloc_shadow_page(
} }
spt->vgpu = vgpu; spt->vgpu = vgpu;
spt->guest_page_type = type;
atomic_set(&spt->refcount, 1); atomic_set(&spt->refcount, 1);
INIT_LIST_HEAD(&spt->post_shadow_list); INIT_LIST_HEAD(&spt->post_shadow_list);
/* /*
* TODO: guest page type may be different with shadow page type, * Init shadow_page.
* when we support PSE page in future.
*/ */
ret = init_shadow_page(vgpu, &spt->shadow_page, type, true); spt->shadow_page.type = type;
if (ret) { daddr = dma_map_page(kdev, spt->shadow_page.page,
gvt_vgpu_err("fail to initialize shadow page for spt\n"); 0, 4096, PCI_DMA_BIDIRECTIONAL);
goto err; if (dma_mapping_error(kdev, daddr)) {
} gvt_vgpu_err("fail to map dma addr\n");
free_spt(spt);
ret = init_guest_page(vgpu, &spt->guest_page, return ERR_PTR(-EINVAL);
gfn, ppgtt_write_protection_handler, NULL);
if (ret) {
gvt_vgpu_err("fail to initialize guest page for spt\n");
goto err;
} }
spt->shadow_page.vaddr = page_address(spt->shadow_page.page);
spt->shadow_page.mfn = daddr >> I915_GTT_PAGE_SHIFT;
trace_spt_alloc(vgpu->id, spt, type, spt->shadow_page.mfn, gfn); /*
return spt; * Init guest_page.
err: */
ppgtt_free_shadow_page(spt); spt->guest_page.type = type;
return ERR_PTR(ret); spt->guest_page.gfn = gfn;
}
static struct intel_vgpu_ppgtt_spt *ppgtt_find_shadow_page( spt->guest_page.track.gfn = gfn;
struct intel_vgpu *vgpu, unsigned long mfn) spt->guest_page.track.handler = ppgtt_write_protection_handler;
{ hash_add(vgpu->gtt.tracked_guest_page_hash_table,
struct intel_vgpu_shadow_page *p = find_shadow_page(vgpu, mfn); &spt->guest_page.track.node, gfn);
if (p) INIT_HLIST_NODE(&spt->node);
return shadow_page_to_ppgtt_spt(p); hash_add(vgpu->gtt.shadow_page_hash_table, &spt->node, spt->shadow_page.mfn);
gvt_vgpu_err("fail to find ppgtt shadow page: 0x%lx\n", mfn); trace_spt_alloc(vgpu->id, spt, type, spt->shadow_page.mfn, gfn);
return NULL; return spt;
} }
#define pt_entry_size_shift(spt) \ #define pt_entry_size_shift(spt) \
...@@ -929,7 +842,7 @@ static int ppgtt_invalidate_shadow_page_by_shadow_entry(struct intel_vgpu *vgpu, ...@@ -929,7 +842,7 @@ static int ppgtt_invalidate_shadow_page_by_shadow_entry(struct intel_vgpu *vgpu,
vgpu->gtt.scratch_pt[cur_pt_type].page_mfn) vgpu->gtt.scratch_pt[cur_pt_type].page_mfn)
return 0; return 0;
} }
s = ppgtt_find_shadow_page(vgpu, ops->get_pfn(e)); s = intel_vgpu_find_spt_by_mfn(vgpu, ops->get_pfn(e));
if (!s) { if (!s) {
gvt_vgpu_err("fail to find shadow page: mfn: 0x%lx\n", gvt_vgpu_err("fail to find shadow page: mfn: 0x%lx\n",
ops->get_pfn(e)); ops->get_pfn(e));
...@@ -947,7 +860,7 @@ static int ppgtt_invalidate_shadow_page(struct intel_vgpu_ppgtt_spt *spt) ...@@ -947,7 +860,7 @@ static int ppgtt_invalidate_shadow_page(struct intel_vgpu_ppgtt_spt *spt)
int v = atomic_read(&spt->refcount); int v = atomic_read(&spt->refcount);
trace_spt_change(spt->vgpu->id, "die", spt, trace_spt_change(spt->vgpu->id, "die", spt,
spt->guest_page.track.gfn, spt->shadow_page.type); spt->guest_page.gfn, spt->shadow_page.type);
trace_spt_refcount(spt->vgpu->id, "dec", spt, v, (v - 1)); trace_spt_refcount(spt->vgpu->id, "dec", spt, v, (v - 1));
...@@ -981,7 +894,7 @@ static int ppgtt_invalidate_shadow_page(struct intel_vgpu_ppgtt_spt *spt) ...@@ -981,7 +894,7 @@ static int ppgtt_invalidate_shadow_page(struct intel_vgpu_ppgtt_spt *spt)
} }
release: release:
trace_spt_change(spt->vgpu->id, "release", spt, trace_spt_change(spt->vgpu->id, "release", spt,
spt->guest_page.track.gfn, spt->shadow_page.type); spt->guest_page.gfn, spt->shadow_page.type);
ppgtt_free_shadow_page(spt); ppgtt_free_shadow_page(spt);
return 0; return 0;
fail: fail:
...@@ -996,43 +909,38 @@ static struct intel_vgpu_ppgtt_spt *ppgtt_populate_shadow_page_by_guest_entry( ...@@ -996,43 +909,38 @@ static struct intel_vgpu_ppgtt_spt *ppgtt_populate_shadow_page_by_guest_entry(
struct intel_vgpu *vgpu, struct intel_gvt_gtt_entry *we) struct intel_vgpu *vgpu, struct intel_gvt_gtt_entry *we)
{ {
struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops; struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
struct intel_vgpu_ppgtt_spt *s = NULL; struct intel_vgpu_ppgtt_spt *spt = NULL;
struct intel_vgpu_guest_page *g;
struct intel_vgpu_page_track *t;
int ret; int ret;
GEM_BUG_ON(!gtt_type_is_pt(get_next_pt_type(we->type))); GEM_BUG_ON(!gtt_type_is_pt(get_next_pt_type(we->type)));
t = intel_vgpu_find_tracked_page(vgpu, ops->get_pfn(we)); spt = intel_vgpu_find_spt_by_gfn(vgpu, ops->get_pfn(we));
if (t) { if (spt)
g = page_track_to_guest_page(t); ppgtt_get_shadow_page(spt);
s = guest_page_to_ppgtt_spt(g); else {
ppgtt_get_shadow_page(s);
} else {
int type = get_next_pt_type(we->type); int type = get_next_pt_type(we->type);
s = ppgtt_alloc_shadow_page(vgpu, type, ops->get_pfn(we)); spt = ppgtt_alloc_shadow_page(vgpu, type, ops->get_pfn(we));
if (IS_ERR(s)) { if (IS_ERR(spt)) {
ret = PTR_ERR(s); ret = PTR_ERR(spt);
goto fail; goto fail;
} }
ret = intel_gvt_hypervisor_enable_page_track(vgpu, ret = intel_gvt_hypervisor_enable_page_track(vgpu, &spt->guest_page.track);
&s->guest_page.track);
if (ret) if (ret)
goto fail; goto fail;
ret = ppgtt_populate_shadow_page(s); ret = ppgtt_populate_shadow_page(spt);
if (ret) if (ret)
goto fail; goto fail;
trace_spt_change(vgpu->id, "new", s, s->guest_page.track.gfn, trace_spt_change(vgpu->id, "new", spt, spt->guest_page.gfn,
s->shadow_page.type); spt->shadow_page.type);
} }
return s; return spt;
fail: fail:
gvt_vgpu_err("fail: shadow page %p guest entry 0x%llx type %d\n", gvt_vgpu_err("fail: shadow page %p guest entry 0x%llx type %d\n",
s, we->val64, we->type); spt, we->val64, we->type);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -1097,8 +1005,7 @@ static int ppgtt_populate_shadow_page(struct intel_vgpu_ppgtt_spt *spt) ...@@ -1097,8 +1005,7 @@ static int ppgtt_populate_shadow_page(struct intel_vgpu_ppgtt_spt *spt)
for_each_present_guest_entry(spt, &ge, i) { for_each_present_guest_entry(spt, &ge, i) {
if (gtt_type_is_pt(get_next_pt_type(ge.type))) { if (gtt_type_is_pt(get_next_pt_type(ge.type))) {
s = ppgtt_populate_shadow_page_by_guest_entry(vgpu, s = ppgtt_populate_shadow_page_by_guest_entry(vgpu, &ge);
&ge);
if (IS_ERR(s)) { if (IS_ERR(s)) {
ret = PTR_ERR(s); ret = PTR_ERR(s);
goto fail; goto fail;
...@@ -1126,17 +1033,15 @@ static int ppgtt_populate_shadow_page(struct intel_vgpu_ppgtt_spt *spt) ...@@ -1126,17 +1033,15 @@ static int ppgtt_populate_shadow_page(struct intel_vgpu_ppgtt_spt *spt)
return ret; return ret;
} }
static int ppgtt_handle_guest_entry_removal(struct intel_vgpu_guest_page *gpt, static int ppgtt_handle_guest_entry_removal(struct intel_vgpu_ppgtt_spt *spt,
struct intel_gvt_gtt_entry *se, unsigned long index) struct intel_gvt_gtt_entry *se, unsigned long index)
{ {
struct intel_vgpu_ppgtt_spt *spt = guest_page_to_ppgtt_spt(gpt);
struct intel_vgpu_shadow_page *sp = &spt->shadow_page;
struct intel_vgpu *vgpu = spt->vgpu; struct intel_vgpu *vgpu = spt->vgpu;
struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops; struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
int ret; int ret;
trace_gpt_change(spt->vgpu->id, "remove", spt, sp->type, se->val64, trace_spt_guest_change(spt->vgpu->id, "remove", spt,
index); spt->shadow_page.type, se->val64, index);
gvt_vdbg_mm("destroy old shadow entry, type %d, index %lu, value %llx\n", gvt_vdbg_mm("destroy old shadow entry, type %d, index %lu, value %llx\n",
se->type, index, se->val64); se->type, index, se->val64);
...@@ -1144,12 +1049,13 @@ static int ppgtt_handle_guest_entry_removal(struct intel_vgpu_guest_page *gpt, ...@@ -1144,12 +1049,13 @@ static int ppgtt_handle_guest_entry_removal(struct intel_vgpu_guest_page *gpt,
if (!ops->test_present(se)) if (!ops->test_present(se))
return 0; return 0;
if (ops->get_pfn(se) == vgpu->gtt.scratch_pt[sp->type].page_mfn) if (ops->get_pfn(se) ==
vgpu->gtt.scratch_pt[spt->shadow_page.type].page_mfn)
return 0; return 0;
if (gtt_type_is_pt(get_next_pt_type(se->type))) { if (gtt_type_is_pt(get_next_pt_type(se->type))) {
struct intel_vgpu_ppgtt_spt *s = struct intel_vgpu_ppgtt_spt *s =
ppgtt_find_shadow_page(vgpu, ops->get_pfn(se)); intel_vgpu_find_spt_by_mfn(vgpu, ops->get_pfn(se));
if (!s) { if (!s) {
gvt_vgpu_err("fail to find guest page\n"); gvt_vgpu_err("fail to find guest page\n");
ret = -ENXIO; ret = -ENXIO;
...@@ -1166,17 +1072,15 @@ static int ppgtt_handle_guest_entry_removal(struct intel_vgpu_guest_page *gpt, ...@@ -1166,17 +1072,15 @@ static int ppgtt_handle_guest_entry_removal(struct intel_vgpu_guest_page *gpt,
return ret; return ret;
} }
static int ppgtt_handle_guest_entry_add(struct intel_vgpu_guest_page *gpt, static int ppgtt_handle_guest_entry_add(struct intel_vgpu_ppgtt_spt *spt,
struct intel_gvt_gtt_entry *we, unsigned long index) struct intel_gvt_gtt_entry *we, unsigned long index)
{ {
struct intel_vgpu_ppgtt_spt *spt = guest_page_to_ppgtt_spt(gpt);
struct intel_vgpu_shadow_page *sp = &spt->shadow_page;
struct intel_vgpu *vgpu = spt->vgpu; struct intel_vgpu *vgpu = spt->vgpu;
struct intel_gvt_gtt_entry m; struct intel_gvt_gtt_entry m;
struct intel_vgpu_ppgtt_spt *s; struct intel_vgpu_ppgtt_spt *s;
int ret; int ret;
trace_gpt_change(spt->vgpu->id, "add", spt, sp->type, trace_spt_guest_change(spt->vgpu->id, "add", spt, spt->shadow_page.type,
we->val64, index); we->val64, index);
gvt_vdbg_mm("add shadow entry: type %d, index %lu, value %llx\n", gvt_vdbg_mm("add shadow entry: type %d, index %lu, value %llx\n",
...@@ -1209,30 +1113,29 @@ static int sync_oos_page(struct intel_vgpu *vgpu, ...@@ -1209,30 +1113,29 @@ static int sync_oos_page(struct intel_vgpu *vgpu,
const struct intel_gvt_device_info *info = &vgpu->gvt->device_info; const struct intel_gvt_device_info *info = &vgpu->gvt->device_info;
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
struct intel_gvt_gtt_pte_ops *ops = gvt->gtt.pte_ops; struct intel_gvt_gtt_pte_ops *ops = gvt->gtt.pte_ops;
struct intel_vgpu_ppgtt_spt *spt = struct intel_vgpu_ppgtt_spt *spt = oos_page->spt;
guest_page_to_ppgtt_spt(oos_page->guest_page);
struct intel_gvt_gtt_entry old, new; struct intel_gvt_gtt_entry old, new;
int index; int index;
int ret; int ret;
trace_oos_change(vgpu->id, "sync", oos_page->id, trace_oos_change(vgpu->id, "sync", oos_page->id,
oos_page->guest_page, spt->guest_page_type); spt, spt->guest_page.type);
old.type = new.type = get_entry_type(spt->guest_page_type); old.type = new.type = get_entry_type(spt->guest_page.type);
old.val64 = new.val64 = 0; old.val64 = new.val64 = 0;
for (index = 0; index < (I915_GTT_PAGE_SIZE >> for (index = 0; index < (I915_GTT_PAGE_SIZE >>
info->gtt_entry_size_shift); index++) { info->gtt_entry_size_shift); index++) {
ops->get_entry(oos_page->mem, &old, index, false, 0, vgpu); ops->get_entry(oos_page->mem, &old, index, false, 0, vgpu);
ops->get_entry(NULL, &new, index, true, ops->get_entry(NULL, &new, index, true,
oos_page->guest_page->track.gfn << PAGE_SHIFT, vgpu); spt->guest_page.gfn << PAGE_SHIFT, vgpu);
if (old.val64 == new.val64 if (old.val64 == new.val64
&& !test_and_clear_bit(index, spt->post_shadow_bitmap)) && !test_and_clear_bit(index, spt->post_shadow_bitmap))
continue; continue;
trace_oos_sync(vgpu->id, oos_page->id, trace_oos_sync(vgpu->id, oos_page->id,
oos_page->guest_page, spt->guest_page_type, spt, spt->guest_page.type,
new.val64, index); new.val64, index);
ret = ppgtt_populate_shadow_entry(vgpu, spt, index, &new); ret = ppgtt_populate_shadow_entry(vgpu, spt, index, &new);
...@@ -1242,7 +1145,7 @@ static int sync_oos_page(struct intel_vgpu *vgpu, ...@@ -1242,7 +1145,7 @@ static int sync_oos_page(struct intel_vgpu *vgpu,
ops->set_entry(oos_page->mem, &new, index, false, 0, vgpu); ops->set_entry(oos_page->mem, &new, index, false, 0, vgpu);
} }
oos_page->guest_page->write_cnt = 0; spt->guest_page.write_cnt = 0;
list_del_init(&spt->post_shadow_list); list_del_init(&spt->post_shadow_list);
return 0; return 0;
} }
...@@ -1251,15 +1154,14 @@ static int detach_oos_page(struct intel_vgpu *vgpu, ...@@ -1251,15 +1154,14 @@ static int detach_oos_page(struct intel_vgpu *vgpu,
struct intel_vgpu_oos_page *oos_page) struct intel_vgpu_oos_page *oos_page)
{ {
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
struct intel_vgpu_ppgtt_spt *spt = struct intel_vgpu_ppgtt_spt *spt = oos_page->spt;
guest_page_to_ppgtt_spt(oos_page->guest_page);
trace_oos_change(vgpu->id, "detach", oos_page->id, trace_oos_change(vgpu->id, "detach", oos_page->id,
oos_page->guest_page, spt->guest_page_type); spt, spt->guest_page.type);
oos_page->guest_page->write_cnt = 0; spt->guest_page.write_cnt = 0;
oos_page->guest_page->oos_page = NULL; spt->guest_page.oos_page = NULL;
oos_page->guest_page = NULL; oos_page->spt = NULL;
list_del_init(&oos_page->vm_list); list_del_init(&oos_page->vm_list);
list_move_tail(&oos_page->list, &gvt->gtt.oos_page_free_list_head); list_move_tail(&oos_page->list, &gvt->gtt.oos_page_free_list_head);
...@@ -1267,51 +1169,49 @@ static int detach_oos_page(struct intel_vgpu *vgpu, ...@@ -1267,51 +1169,49 @@ static int detach_oos_page(struct intel_vgpu *vgpu,
return 0; return 0;
} }
static int attach_oos_page(struct intel_vgpu *vgpu, static int attach_oos_page(struct intel_vgpu_oos_page *oos_page,
struct intel_vgpu_oos_page *oos_page, struct intel_vgpu_ppgtt_spt *spt)
struct intel_vgpu_guest_page *gpt)
{ {
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = spt->vgpu->gvt;
int ret; int ret;
ret = intel_gvt_hypervisor_read_gpa(vgpu, ret = intel_gvt_hypervisor_read_gpa(spt->vgpu,
gpt->track.gfn << I915_GTT_PAGE_SHIFT, spt->guest_page.gfn << I915_GTT_PAGE_SHIFT,
oos_page->mem, I915_GTT_PAGE_SIZE); oos_page->mem, I915_GTT_PAGE_SIZE);
if (ret) if (ret)
return ret; return ret;
oos_page->guest_page = gpt; oos_page->spt = spt;
gpt->oos_page = oos_page; spt->guest_page.oos_page = oos_page;
list_move_tail(&oos_page->list, &gvt->gtt.oos_page_use_list_head); list_move_tail(&oos_page->list, &gvt->gtt.oos_page_use_list_head);
trace_oos_change(vgpu->id, "attach", gpt->oos_page->id, trace_oos_change(spt->vgpu->id, "attach", oos_page->id,
gpt, guest_page_to_ppgtt_spt(gpt)->guest_page_type); spt, spt->guest_page.type);
return 0; return 0;
} }
static int ppgtt_set_guest_page_sync(struct intel_vgpu *vgpu, static int ppgtt_set_guest_page_sync(struct intel_vgpu_ppgtt_spt *spt)
struct intel_vgpu_guest_page *gpt)
{ {
struct intel_vgpu_oos_page *oos_page = spt->guest_page.oos_page;
int ret; int ret;
ret = intel_gvt_hypervisor_enable_page_track(vgpu, &gpt->track); ret = intel_gvt_hypervisor_enable_page_track(spt->vgpu, &spt->guest_page.track);
if (ret) if (ret)
return ret; return ret;
trace_oos_change(vgpu->id, "set page sync", gpt->oos_page->id, trace_oos_change(spt->vgpu->id, "set page sync", oos_page->id,
gpt, guest_page_to_ppgtt_spt(gpt)->guest_page_type); spt, spt->guest_page.type);
list_del_init(&gpt->oos_page->vm_list); list_del_init(&oos_page->vm_list);
return sync_oos_page(vgpu, gpt->oos_page); return sync_oos_page(spt->vgpu, oos_page);
} }
static int ppgtt_allocate_oos_page(struct intel_vgpu *vgpu, static int ppgtt_allocate_oos_page(struct intel_vgpu_ppgtt_spt *spt)
struct intel_vgpu_guest_page *gpt)
{ {
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = spt->vgpu->gvt;
struct intel_gvt_gtt *gtt = &gvt->gtt; struct intel_gvt_gtt *gtt = &gvt->gtt;
struct intel_vgpu_oos_page *oos_page = gpt->oos_page; struct intel_vgpu_oos_page *oos_page = spt->guest_page.oos_page;
int ret; int ret;
WARN(oos_page, "shadow PPGTT page has already has a oos page\n"); WARN(oos_page, "shadow PPGTT page has already has a oos page\n");
...@@ -1319,31 +1219,30 @@ static int ppgtt_allocate_oos_page(struct intel_vgpu *vgpu, ...@@ -1319,31 +1219,30 @@ static int ppgtt_allocate_oos_page(struct intel_vgpu *vgpu,
if (list_empty(&gtt->oos_page_free_list_head)) { if (list_empty(&gtt->oos_page_free_list_head)) {
oos_page = container_of(gtt->oos_page_use_list_head.next, oos_page = container_of(gtt->oos_page_use_list_head.next,
struct intel_vgpu_oos_page, list); struct intel_vgpu_oos_page, list);
ret = ppgtt_set_guest_page_sync(vgpu, oos_page->guest_page); ret = ppgtt_set_guest_page_sync(oos_page->spt);
if (ret) if (ret)
return ret; return ret;
ret = detach_oos_page(vgpu, oos_page); ret = detach_oos_page(spt->vgpu, oos_page);
if (ret) if (ret)
return ret; return ret;
} else } else
oos_page = container_of(gtt->oos_page_free_list_head.next, oos_page = container_of(gtt->oos_page_free_list_head.next,
struct intel_vgpu_oos_page, list); struct intel_vgpu_oos_page, list);
return attach_oos_page(vgpu, oos_page, gpt); return attach_oos_page(oos_page, spt);
} }
static int ppgtt_set_guest_page_oos(struct intel_vgpu *vgpu, static int ppgtt_set_guest_page_oos(struct intel_vgpu_ppgtt_spt *spt)
struct intel_vgpu_guest_page *gpt)
{ {
struct intel_vgpu_oos_page *oos_page = gpt->oos_page; struct intel_vgpu_oos_page *oos_page = spt->guest_page.oos_page;
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;
trace_oos_change(vgpu->id, "set page out of sync", gpt->oos_page->id, trace_oos_change(spt->vgpu->id, "set page out of sync", oos_page->id,
gpt, guest_page_to_ppgtt_spt(gpt)->guest_page_type); spt, spt->guest_page.type);
list_add_tail(&oos_page->vm_list, &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(vgpu, &gpt->track); return intel_gvt_hypervisor_disable_page_track(spt->vgpu, &spt->guest_page.track);
} }
/** /**
...@@ -1368,7 +1267,7 @@ int intel_vgpu_sync_oos_pages(struct intel_vgpu *vgpu) ...@@ -1368,7 +1267,7 @@ int intel_vgpu_sync_oos_pages(struct intel_vgpu *vgpu)
list_for_each_safe(pos, n, &vgpu->gtt.oos_page_list_head) { list_for_each_safe(pos, n, &vgpu->gtt.oos_page_list_head) {
oos_page = container_of(pos, oos_page = container_of(pos,
struct intel_vgpu_oos_page, vm_list); struct intel_vgpu_oos_page, vm_list);
ret = ppgtt_set_guest_page_sync(vgpu, oos_page->guest_page); ret = ppgtt_set_guest_page_sync(oos_page->spt);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -1379,10 +1278,9 @@ int intel_vgpu_sync_oos_pages(struct intel_vgpu *vgpu) ...@@ -1379,10 +1278,9 @@ int intel_vgpu_sync_oos_pages(struct intel_vgpu *vgpu)
* The heart of PPGTT shadow page table. * The heart of PPGTT shadow page table.
*/ */
static int ppgtt_handle_guest_write_page_table( static int ppgtt_handle_guest_write_page_table(
struct intel_vgpu_guest_page *gpt, struct intel_vgpu_ppgtt_spt *spt,
struct intel_gvt_gtt_entry *we, unsigned long index) struct intel_gvt_gtt_entry *we, unsigned long index)
{ {
struct intel_vgpu_ppgtt_spt *spt = guest_page_to_ppgtt_spt(gpt);
struct intel_vgpu *vgpu = spt->vgpu; struct intel_vgpu *vgpu = spt->vgpu;
int type = spt->shadow_page.type; int type = spt->shadow_page.type;
struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops; struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
...@@ -1400,12 +1298,12 @@ static int ppgtt_handle_guest_write_page_table( ...@@ -1400,12 +1298,12 @@ static int ppgtt_handle_guest_write_page_table(
ppgtt_get_shadow_entry(spt, &old_se, index); ppgtt_get_shadow_entry(spt, &old_se, index);
if (new_present) { if (new_present) {
ret = ppgtt_handle_guest_entry_add(gpt, we, index); ret = ppgtt_handle_guest_entry_add(spt, we, index);
if (ret) if (ret)
goto fail; goto fail;
} }
ret = ppgtt_handle_guest_entry_removal(gpt, &old_se, index); ret = ppgtt_handle_guest_entry_removal(spt, &old_se, index);
if (ret) if (ret)
goto fail; goto fail;
...@@ -1423,12 +1321,11 @@ static int ppgtt_handle_guest_write_page_table( ...@@ -1423,12 +1321,11 @@ static int ppgtt_handle_guest_write_page_table(
static inline bool can_do_out_of_sync(struct intel_vgpu_guest_page *gpt) static inline bool can_do_out_of_sync(struct intel_vgpu_ppgtt_spt *spt)
{ {
return enable_out_of_sync return enable_out_of_sync
&& gtt_type_is_pte_pt( && gtt_type_is_pte_pt(spt->guest_page.type)
guest_page_to_ppgtt_spt(gpt)->guest_page_type) && spt->guest_page.write_cnt >= 2;
&& gpt->write_cnt >= 2;
} }
static void ppgtt_set_post_shadow(struct intel_vgpu_ppgtt_spt *spt, static void ppgtt_set_post_shadow(struct intel_vgpu_ppgtt_spt *spt,
...@@ -1468,8 +1365,8 @@ int intel_vgpu_flush_post_shadow(struct intel_vgpu *vgpu) ...@@ -1468,8 +1365,8 @@ int intel_vgpu_flush_post_shadow(struct intel_vgpu *vgpu)
GTT_ENTRY_NUM_IN_ONE_PAGE) { GTT_ENTRY_NUM_IN_ONE_PAGE) {
ppgtt_get_guest_entry(spt, &ge, index); ppgtt_get_guest_entry(spt, &ge, index);
ret = ppgtt_handle_guest_write_page_table( ret = ppgtt_handle_guest_write_page_table(spt,
&spt->guest_page, &ge, index); &ge, index);
if (ret) if (ret)
return ret; return ret;
clear_bit(index, spt->post_shadow_bitmap); clear_bit(index, spt->post_shadow_bitmap);
...@@ -1480,10 +1377,9 @@ int intel_vgpu_flush_post_shadow(struct intel_vgpu *vgpu) ...@@ -1480,10 +1377,9 @@ int intel_vgpu_flush_post_shadow(struct intel_vgpu *vgpu)
} }
static int ppgtt_handle_guest_write_page_table_bytes( static int ppgtt_handle_guest_write_page_table_bytes(
struct intel_vgpu_guest_page *gpt, struct intel_vgpu_ppgtt_spt *spt,
u64 pa, void *p_data, int bytes) u64 pa, void *p_data, int bytes)
{ {
struct intel_vgpu_ppgtt_spt *spt = guest_page_to_ppgtt_spt(gpt);
struct intel_vgpu *vgpu = spt->vgpu; struct intel_vgpu *vgpu = spt->vgpu;
struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops; struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
const struct intel_gvt_device_info *info = &vgpu->gvt->device_info; const struct intel_gvt_device_info *info = &vgpu->gvt->device_info;
...@@ -1498,7 +1394,7 @@ static int ppgtt_handle_guest_write_page_table_bytes( ...@@ -1498,7 +1394,7 @@ static int ppgtt_handle_guest_write_page_table_bytes(
ops->test_pse(&we); ops->test_pse(&we);
if (bytes == info->gtt_entry_size) { if (bytes == info->gtt_entry_size) {
ret = ppgtt_handle_guest_write_page_table(gpt, &we, index); ret = ppgtt_handle_guest_write_page_table(spt, &we, index);
if (ret) if (ret)
return ret; return ret;
} else { } else {
...@@ -1506,7 +1402,7 @@ static int ppgtt_handle_guest_write_page_table_bytes( ...@@ -1506,7 +1402,7 @@ static int ppgtt_handle_guest_write_page_table_bytes(
int type = spt->shadow_page.type; int type = spt->shadow_page.type;
ppgtt_get_shadow_entry(spt, &se, index); ppgtt_get_shadow_entry(spt, &se, index);
ret = ppgtt_handle_guest_entry_removal(gpt, &se, index); ret = ppgtt_handle_guest_entry_removal(spt, &se, index);
if (ret) if (ret)
return ret; return ret;
ops->set_pfn(&se, vgpu->gtt.scratch_pt[type].page_mfn); ops->set_pfn(&se, vgpu->gtt.scratch_pt[type].page_mfn);
...@@ -1518,17 +1414,17 @@ static int ppgtt_handle_guest_write_page_table_bytes( ...@@ -1518,17 +1414,17 @@ static int ppgtt_handle_guest_write_page_table_bytes(
if (!enable_out_of_sync) if (!enable_out_of_sync)
return 0; return 0;
gpt->write_cnt++; spt->guest_page.write_cnt++;
if (gpt->oos_page) if (spt->guest_page.oos_page)
ops->set_entry(gpt->oos_page->mem, &we, index, ops->set_entry(spt->guest_page.oos_page->mem, &we, index,
false, 0, vgpu); false, 0, vgpu);
if (can_do_out_of_sync(gpt)) { if (can_do_out_of_sync(spt)) {
if (!gpt->oos_page) if (!spt->guest_page.oos_page)
ppgtt_allocate_oos_page(vgpu, gpt); ppgtt_allocate_oos_page(spt);
ret = ppgtt_set_guest_page_oos(vgpu, gpt); ret = ppgtt_set_guest_page_oos(spt);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -1557,7 +1453,7 @@ static void invalidate_ppgtt_mm(struct intel_vgpu_mm *mm) ...@@ -1557,7 +1453,7 @@ static void invalidate_ppgtt_mm(struct intel_vgpu_mm *mm)
se.val64 = 0; se.val64 = 0;
ppgtt_set_shadow_root_entry(mm, &se, index); ppgtt_set_shadow_root_entry(mm, &se, index);
trace_gpt_change(vgpu->id, "destroy root pointer", trace_spt_guest_change(vgpu->id, "destroy root pointer",
NULL, se.type, se.val64, index); NULL, se.type, se.val64, index);
} }
...@@ -1586,7 +1482,7 @@ static int shadow_ppgtt_mm(struct intel_vgpu_mm *mm) ...@@ -1586,7 +1482,7 @@ static int shadow_ppgtt_mm(struct intel_vgpu_mm *mm)
if (!ops->test_present(&ge)) if (!ops->test_present(&ge))
continue; continue;
trace_gpt_change(vgpu->id, __func__, NULL, trace_spt_guest_change(vgpu->id, __func__, NULL,
ge.type, ge.val64, index); ge.type, ge.val64, index);
spt = ppgtt_populate_shadow_page_by_guest_entry(vgpu, &ge); spt = ppgtt_populate_shadow_page_by_guest_entry(vgpu, &ge);
...@@ -1598,7 +1494,7 @@ static int shadow_ppgtt_mm(struct intel_vgpu_mm *mm) ...@@ -1598,7 +1494,7 @@ static int shadow_ppgtt_mm(struct intel_vgpu_mm *mm)
ppgtt_generate_shadow_entry(&se, spt, &ge); ppgtt_generate_shadow_entry(&se, spt, &ge);
ppgtt_set_shadow_root_entry(mm, &se, index); ppgtt_set_shadow_root_entry(mm, &se, index);
trace_gpt_change(vgpu->id, "populate root pointer", trace_spt_guest_change(vgpu->id, "populate root pointer",
NULL, se.type, se.val64, index); NULL, se.type, se.val64, index);
} }
...@@ -1793,7 +1689,7 @@ static inline int ppgtt_get_next_level_entry(struct intel_vgpu_mm *mm, ...@@ -1793,7 +1689,7 @@ static inline int ppgtt_get_next_level_entry(struct intel_vgpu_mm *mm,
struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops; struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
struct intel_vgpu_ppgtt_spt *s; struct intel_vgpu_ppgtt_spt *s;
s = ppgtt_find_shadow_page(vgpu, ops->get_pfn(e)); s = intel_vgpu_find_spt_by_mfn(vgpu, ops->get_pfn(e));
if (!s) if (!s)
return -ENXIO; return -ENXIO;
...@@ -2030,7 +1926,7 @@ int intel_vgpu_write_protect_handler(struct intel_vgpu *vgpu, u64 pa, ...@@ -2030,7 +1926,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_vgpu_clean_page_track(vgpu, t); intel_gvt_hypervisor_disable_page_track(vgpu, t);
} else { } else {
ret = t->handler(t, pa, p_data, bytes); ret = t->handler(t, pa, p_data, bytes);
if (ret) { if (ret) {
......
...@@ -205,16 +205,6 @@ extern void intel_gvt_clean_gtt(struct intel_gvt *gvt); ...@@ -205,16 +205,6 @@ extern void intel_gvt_clean_gtt(struct intel_gvt *gvt);
extern struct intel_vgpu_mm *intel_gvt_find_ppgtt_mm(struct intel_vgpu *vgpu, extern struct intel_vgpu_mm *intel_gvt_find_ppgtt_mm(struct intel_vgpu *vgpu,
int page_table_level, void *root_entry); int page_table_level, void *root_entry);
struct intel_vgpu_oos_page;
struct intel_vgpu_shadow_page {
void *vaddr;
struct page *page;
int type;
struct hlist_node node;
unsigned long mfn;
};
struct intel_vgpu_page_track { struct intel_vgpu_page_track {
struct hlist_node node; struct hlist_node node;
bool tracked; bool tracked;
...@@ -223,14 +213,8 @@ struct intel_vgpu_page_track { ...@@ -223,14 +213,8 @@ struct intel_vgpu_page_track {
void *data; void *data;
}; };
struct intel_vgpu_guest_page {
struct intel_vgpu_page_track track;
unsigned long write_cnt;
struct intel_vgpu_oos_page *oos_page;
};
struct intel_vgpu_oos_page { struct intel_vgpu_oos_page {
struct intel_vgpu_guest_page *guest_page; struct intel_vgpu_ppgtt_spt *spt;
struct list_head list; struct list_head list;
struct list_head vm_list; struct list_head vm_list;
int id; int id;
...@@ -239,27 +223,30 @@ struct intel_vgpu_oos_page { ...@@ -239,27 +223,30 @@ struct intel_vgpu_oos_page {
#define GTT_ENTRY_NUM_IN_ONE_PAGE 512 #define GTT_ENTRY_NUM_IN_ONE_PAGE 512
/* Represent a vgpu shadow page table. */
struct intel_vgpu_ppgtt_spt { struct intel_vgpu_ppgtt_spt {
struct intel_vgpu_shadow_page shadow_page;
struct intel_vgpu_guest_page guest_page;
int guest_page_type;
atomic_t refcount; atomic_t refcount;
struct intel_vgpu *vgpu; struct intel_vgpu *vgpu;
DECLARE_BITMAP(post_shadow_bitmap, GTT_ENTRY_NUM_IN_ONE_PAGE); struct hlist_node node;
struct list_head post_shadow_list;
};
int intel_vgpu_init_page_track(struct intel_vgpu *vgpu, struct {
struct intel_vgpu_page_track *t, intel_gvt_gtt_type_t type;
unsigned long gfn, void *vaddr;
int (*handler)(void *gp, u64, void *, int), struct page *page;
void *data); unsigned long mfn;
} shadow_page;
void intel_vgpu_clean_page_track(struct intel_vgpu *vgpu, struct {
struct intel_vgpu_page_track *t); intel_gvt_gtt_type_t type;
unsigned long gfn;
unsigned long write_cnt;
struct intel_vgpu_page_track track;
struct intel_vgpu_oos_page *oos_page;
} guest_page;
struct intel_vgpu_page_track *intel_vgpu_find_tracked_page( DECLARE_BITMAP(post_shadow_bitmap, GTT_ENTRY_NUM_IN_ONE_PAGE);
struct intel_vgpu *vgpu, unsigned long gfn); struct list_head post_shadow_list;
};
int intel_vgpu_sync_oos_pages(struct intel_vgpu *vgpu); int intel_vgpu_sync_oos_pages(struct intel_vgpu *vgpu);
......
...@@ -168,7 +168,7 @@ TRACE_EVENT(spt_change, ...@@ -168,7 +168,7 @@ TRACE_EVENT(spt_change,
TP_printk("%s", __entry->buf) TP_printk("%s", __entry->buf)
); );
TRACE_EVENT(gpt_change, TRACE_EVENT(spt_guest_change,
TP_PROTO(int id, const char *tag, void *spt, int type, u64 v, TP_PROTO(int id, const char *tag, void *spt, int type, u64 v,
unsigned long index), unsigned long index),
......
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