drm/i915/gvt: Enable guest i915 48bit full ppgtt support
v8 cover drm/i915/gvt: Enable guest i915 48bit full ppgtt support
This patch set is used to enable guest i915 48bit full ppgtt support.
v8:
1) CC intel-gfx on i915 change. (Zhenyu)
v7:
1) Include a new patch for fixing reboot GPU hang issue. (Kechen)
Kechen Lu (1):
drm/i915/gvt: Add shadow context descriptor updating
Tina Zhang (2):
drm/i915/gvt: Fix guest i915 full ppgtt blocking issue drm/i915: Enable guest i915 full ppgtt functionality
drivers/gpu/drm/i915/gvt/execlist.c | 2 ++ drivers/gpu/drm/i915/gvt/gtt.c | 45 ++++++++++++++++++++++-------------- drivers/gpu/drm/i915/gvt/gvt.h | 1 + drivers/gpu/drm/i915/gvt/scheduler.c | 23 ++++++++++++++++++ drivers/gpu/drm/i915/gvt/vgpu.c | 1 + drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem_gtt.c | 14 +++++++---- drivers/gpu/drm/i915/i915_pvinfo.h | 8 ++++++- drivers/gpu/drm/i915/i915_vgpu.c | 7 ++++++ drivers/gpu/drm/i915/i915_vgpu.h | 3 +++ 10 files changed, 83 insertions(+), 22 deletions(-)
Signature · 6 lines
2.7.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 1/3 drm/i915/gvt: Add shadow context descriptor updating
From: Kechen Lu <[email protected]>
The current context logic only updates the descriptor of context when it's being pinned to graphics memory space. But this cannot satisfy the requirement of shadow context. The addressing mode of the pinned shadow context descriptor may be changed according to the guest addressing mode. And this won't be updated, as the already pinned shadow context has no chance to update its descriptor. And this will lead to GPU hang issue, as shadow context is used with wrong descriptor. This patch fixes this issue by letting the pinned shadow context descriptor update its addressing mode on demand.
This patch fixes GPU HANG issue which happends after changing the grub parameter i915.enable_ppgtt form 0x01 to 0x03 or vice versa and then rebooting the guest.
drivers/gpu/drm/i915/gvt/execlist.c +2 -0
@@ -796,6 +796,8 @@ static void clean_workloads(struct intel_vgpu *vgpu, unsigned long engine_mask)list_del_init (&pos->list);free_workload (pos); } + +clear_bit (engine->id, vgpu->shadow_ctx_desc_updated); } }
drivers/gpu/drm/i915/gvt/gvt.h +1 -0
@@ -167,6 +167,7 @@ struct intel_vgpu {atomic_t running_workload_num;DECLARE_BITMAP (tlb_handle_pending,I915_NUM_ENGINES );struct i915_gem_context *shadow_ctx; +DECLARE_BITMAP (shadow_ctx_desc_updated,I915_NUM_ENGINES ); #if IS_ENABLED(CONFIG_DRM_I915_GVT_KVMGT) struct {
drivers/gpu/drm/i915/gvt/scheduler.c +23 -0
@@ -184,6 +184,23 @@ static int shadow_context_status_change(struct notifier_block *nb,return NOTIFY_OK ; } +static void shadow_context_descriptor_update (struct i915_gem_context *ctx, +struct intel_engine_cs *engine) +{ +struct intel_context *ce = &ctx->engine[engine->id]; +u64 desc =0 ; + + desc = ce->lrc_desc; + +/* Update bits 0-11 of the context descriptor which includes flags +* like GEN8_CTX_* cached in desc_template +*/ + desc &=U64_MAX <<12 ; + desc |= ctx->desc_template & ((1ULL <<12 ) -1 ); + + ce->lrc_desc = desc; +} +/** * intel_gvt_scan_and_shadow_workload - audit the workload by scanning and * shadow it as well, include ringbuffer,wa_ctx and ctx.
@@ -210,6 +227,10 @@ int intel_gvt_scan_and_shadow_workload(struct intel_vgpu_workload *workload) shadow_ctx->desc_template |= workload->ctx_desc.addressing_mode <<GEN8_CTX_ADDRESSING_MODE_SHIFT ; +if (!test_and_set_bit (ring_id, vgpu->shadow_ctx_desc_updated)) +shadow_context_descriptor_update (shadow_ctx, + dev_priv->engine[ring_id]); + rq =i915_gem_request_alloc (dev_priv->engine[ring_id], shadow_ctx);if (IS_ERR (rq)) {gvt_vgpu_err ("fail to allocate gem request\n" );
@@ -656,5 +677,7 @@ int intel_vgpu_init_gvt_context(struct intel_vgpu *vgpu) vgpu->shadow_ctx->engine[RCS ].initialised = true; +bitmap_zero (vgpu->shadow_ctx_desc_updated,I915_NUM_ENGINES ); +return 0 ; }
Signature · 6 lines
2.7.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 2/3 drm/i915/gvt: Fix guest i915 full ppgtt blocking issue
In reply to Tina ZhangGuest i915 full ppgtt functionality was blocking by an issue, which would lead to gpu hardware hang. Guest i915 driver may update the ppgtt table just before this workload is going to be submitted to the hardware by device model. This case wasn't handled well by device model before, due to the small time window between removing old ppgtt entry and adding the new one. Errors occur when the workload is executed by hardware during that small time window. This patch is to remove this time window by adding the new ppgtt entry first and then remove the old one.
Changes in v2:
- Move VGT_CAPS_FULL_PPGTT introduction to patch 2/4. (Joonas)
Changes since v2:
- Divide the whole patch set into two separate patch series, with one patch in i915 side to check guest i915 full ppgtt capability and enable it when this capability is supported by the device model, and the other one in gvt side which fixs the blocking issue and enables the device model to provide the capability to guest. And this patch focuses on gvt side. (Joonas)
- Change the title from "reorder the shadow ppgtt update process by adding entry first" to "Fix guest i915 full ppgtt blocking issue". (Tina)
Changes since v3:
- Rebase to the latest branch.
Changes since v4:
- Tested by Tina Zhang.
Changes since v5:
- Rebase to the latest branch.
drivers/gpu/drm/i915/gvt/gtt.c +28 -17
@@ -979,29 +979,26 @@ static int ppgtt_populate_shadow_page(struct intel_vgpu_ppgtt_spt *spt) }static int ppgtt_handle_guest_entry_removal (struct intel_vgpu_guest_page *gpt, -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_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops; -struct intel_gvt_gtt_entry e;int ret; -ppgtt_get_shadow_entry (spt, &e, index); - -trace_gpt_change (spt->vgpu->id,"remove" , spt, sp->type, e.val64, +trace_gpt_change (spt->vgpu->id,"remove" , spt, sp->type, se->val64, index); -if (!ops->test_present (&e)) +if (!ops->test_present (se))return 0 ; -if (ops->get_pfn (&e) == vgpu->gtt.scratch_pt[sp->type].page_mfn) +if (ops->get_pfn (se) == vgpu->gtt.scratch_pt[sp->type].page_mfn)return 0 ; -if (gtt_type_is_pt (get_next_pt_type (e.type))) { +if (gtt_type_is_pt (get_next_pt_type (se->type))) {struct intel_vgpu_ppgtt_spt *s = -ppgtt_find_shadow_page (vgpu, ops->get_pfn (&e)); +ppgtt_find_shadow_page (vgpu, ops->get_pfn (se));if (!s) {gvt_vgpu_err ("fail to find guest page\n" ); ret = -ENXIO ;
@@ -1011,12 +1008,10 @@ static int ppgtt_handle_guest_entry_removal(struct intel_vgpu_guest_page *gpt,if (ret) goto fail; } - ops->set_pfn (&e, vgpu->gtt.scratch_pt[sp->type].page_mfn); -ppgtt_set_shadow_entry (spt, &e, index);return 0 ; fail:gvt_vgpu_err ("fail: shadow page %p guest entry 0x%llx type %d\n" , - spt, e.val64, e.type); + spt, se->val64, se->type);return ret; }
@@ -1236,22 +1231,37 @@ static int ppgtt_handle_guest_write_page_table( {struct intel_vgpu_ppgtt_spt *spt =guest_page_to_ppgtt_spt (gpt);struct intel_vgpu *vgpu = spt->vgpu; +int type = spt->shadow_page.type;struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops; +struct intel_gvt_gtt_entry se;int ret;int new_present; new_present = ops->test_present (we); - ret =ppgtt_handle_guest_entry_removal (gpt, index); -if (ret) - goto fail; +/* +* Adding the new entry first and then removing the old one, that can +* guarantee the ppgtt table is validated during the window between +* adding and removal. +*/ +ppgtt_get_shadow_entry (spt, &se, index);if (new_present) { ret =ppgtt_handle_guest_entry_add (gpt, we, index);if (ret) goto fail; } + + ret =ppgtt_handle_guest_entry_removal (gpt, &se, index); +if (ret) + goto fail; + +if (!new_present) { + ops->set_pfn (&se, vgpu->gtt.scratch_pt[type].page_mfn); +ppgtt_set_shadow_entry (spt, &se, index); + } +return 0 ; fail: gvt_vgpu_err("fail: shadow page %p guest entry 0x%llx type %d.\n",
@@ -1323,7 +1333,7 @@ static int ppgtt_handle_guest_write_page_table_bytes(void *gp,struct intel_vgpu *vgpu = spt->vgpu;struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;const struct intel_gvt_device_info *info = &vgpu->gvt->device_info; -struct intel_gvt_gtt_entry we; +struct intel_gvt_gtt_entry we, se;unsigned long index;int ret;
@@ -1339,7 +1349,8 @@ static int ppgtt_handle_guest_write_page_table_bytes(void *gp,return ret; }else {if (!test_bit (index, spt->post_shadow_bitmap)) { - ret =ppgtt_handle_guest_entry_removal (gpt, index); +ppgtt_get_shadow_entry (spt, &se, index); + ret =ppgtt_handle_guest_entry_removal (gpt, &se, index);if (ret)return ret; }
drivers/gpu/drm/i915/gvt/vgpu.c +1 -0
@@ -43,6 +43,7 @@ void populate_pvinfo_page(struct intel_vgpu *vgpu)vgpu_vreg (vgpu,vgtif_reg (version_minor)) =0 ;vgpu_vreg (vgpu,vgtif_reg (display_ready)) =0 ;vgpu_vreg (vgpu,vgtif_reg (vgt_id)) = vgpu->id; +vgpu_vreg (vgpu,vgtif_reg (vgt_caps)) =VGT_CAPS_FULL_PPGTT_48BIT ;vgpu_vreg (vgpu,vgtif_reg (avail_rs.mappable_gmadr.base)) =vgpu_aperture_gmadr_base (vgpu); vgpu_vreg(vgpu, vgtif_reg(avail_rs.mappable_gmadr.size)) =
Signature · 6 lines
2.7.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 3/3 drm/i915: Enable guest i915 full ppgtt functionality
In reply to Tina ZhangEnable the guest i915 full ppgtt functionality when host can provide this capability. vgt_caps is introduced to guest i915 driver to get the vgpu capabilities from the device model. VGT_CPAS_FULL_PPGTT is one of the capabilities type to let guest i915 dirver know that the guest i915 full ppgtt is supported by device model.
Notice that the minor version of pvinfo isn't bumped because of this vgt_caps introduction, due to older guest would be broken by simply increasing the pvinfo version. Although the pvinfo minor version doesn't increase, the compatibility won't be blocked. The compatibility is ensured by checking the value of caps field in pvinfo. Zero means no full ppgtt support and BIT(2) means this feature is provided.
Changes since v1:
- Use u32 instead of uint32_t (Joonas)
- Move VGT_CAPS_FULL_PPGTT introduction to this patch and use #define instead of enum (Joonas)
- Rewrite the vgpu full ppgtt capability checking logic. (Joonas)
- Some coding style refine. (Joonas)
Changes since v2:
- Divide the whole patch set into two separate patch series, with one patch in i915 side to check guest i915 full ppgtt capability and enable it when this capability is supported by the device model, and the other one in gvt side which fixs the blocking issue and enables the device model to provide the capability to guest. And this patch focuses on guest i915 side. (Joonas)
- Change the title from "introduce vgt_caps to pvinfo" to "Enable guest i915 full ppgtt functionality". (Tina)
Change since v3:
- Add some comments about pvinfo caps and version. (Joonas)
Change since v4:
- Tested by Tina Zhang.
Change since v5:
- Add limitation about supporting 32bit full ppgtt.
Change since v6:
- Change the fallback to 48bit full ppgtt if i915.ppgtt_enable=2. (Zhenyu)
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -1879,6 +1879,7 @@ struct i915_workarounds {struct i915_virtual_gpu {bool active; +u32 caps; };/* used in computing the new watermarks state */
drivers/gpu/drm/i915/i915_gem_gtt.c +10 -4
@@ -141,14 +141,20 @@ int intel_sanitize_enable_ppgtt(struct drm_i915_private *dev_priv, has_aliasing_ppgtt = dev_priv->info.has_aliasing_ppgtt; has_full_ppgtt = dev_priv->info.has_full_ppgtt; - has_full_48bit_ppgtt = dev_priv->info.has_full_48bit_ppgtt;if (intel_vgpu_active (dev_priv)) { -/* emulation is too hard */ - has_full_ppgtt = false; - has_full_48bit_ppgtt = false; + has_full_ppgtt =intel_vgpu_has_full_ppgtt (dev_priv); +/* +* FIXME: There is a limition of vgpu supporting 32bit full +* ppgtt. +*/ +if (enable_ppgtt ==2 ) + enable_ppgtt =3 ; } + has_full_48bit_ppgtt = has_full_ppgtt && + dev_priv->info.has_full_48bit_ppgtt; +if (!has_aliasing_ppgtt)return 0 ;
drivers/gpu/drm/i915/i915_pvinfo.h +7 -1
@@ -49,12 +49,18 @@ enum vgt_g2v_type { VGT_G2V_MAX, }; +/* +* VGT capabilities type +*/ +#define VGT_CAPS_FULL_PPGTT_48BIT BIT(2) +struct vgt_if {u64 magic;/* VGT_MAGIC */ u16 version_major;u16 version_minor;u32 vgt_id;/* ID of vGT instance */ -u32 rsv1[12 ];/* pad to offset 0x40 */ +u32 vgt_caps;/* VGT capabilities */ +u32 rsv1[11 ];/* pad to offset 0x40 */ /* * Data structure to describe the balooning info of resources. * Each VM can only have one portion of continuous area for now.
drivers/gpu/drm/i915/i915_vgpu.c +7 -0
@@ -75,10 +75,17 @@ void i915_check_vgpu(struct drm_i915_private *dev_priv)return ; } + dev_priv->vgpu.caps =__raw_i915_read32 (dev_priv,vgtif_reg (vgt_caps)); + dev_priv->vgpu.active = true;DRM_INFO ("Virtual GPU for Intel GVT-g detected.\n" ); } +bool intel_vgpu_has_full_ppgtt (struct drm_i915_private *dev_priv) +{ +return dev_priv->vgpu.caps &VGT_CAPS_FULL_PPGTT_48BIT ; +} +struct _balloon_info_ {/* * There are up to 2 regions per mappable/unmappable graphic
drivers/gpu/drm/i915/i915_vgpu.h +3 -0
@@ -27,6 +27,9 @@#include "i915_pvinfo.h" void i915_check_vgpu (struct drm_i915_private *dev_priv); + +bool intel_vgpu_has_full_ppgtt (struct drm_i915_private *dev_priv); +int intel_vgt_balloon (struct drm_i915_private *dev_priv);void intel_vgt_deballoon (struct drm_i915_private *dev_priv);
Signature · 6 lines
2.7.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx