[PATCH v2 1/3] drm/i915/gvt: Factor out intel_vgpu_invalidate_mm()

Zhenyu Wang zhenyu.z.wang at intel.com
Tue Nov 7 03:50:35 UTC 2017


On 2017.11.03 00:39:57 +0800, Zhi Wang wrote:
> Factor out intel_vgpu_invalidate_mm() for callers which wants to
> invalidate vGPU mm.
> 
> v2:
> 
> - Keep the intel_vgpu_ prefix. (Zhenyu)
> 
> Signed-off-by: Zhi Wang <zhi.a.wang at intel.com>
> ---
>  drivers/gpu/drm/i915/gvt/gtt.c | 102 +++++++++++++++++++++++------------------
>  drivers/gpu/drm/i915/gvt/gtt.h |   4 +-
>  2 files changed, 60 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
> index 6fa9271..5cff7c5 100644
> --- a/drivers/gpu/drm/i915/gvt/gtt.c
> +++ b/drivers/gpu/drm/i915/gvt/gtt.c
> @@ -1748,6 +1748,62 @@ int intel_vgpu_pin_mm(struct intel_vgpu_mm *mm)
>  	return 0;
>  }
>  
> +static void intel_vgpu_invalidate_ggtt(struct intel_vgpu *vgpu)
> +{
> +	struct intel_gvt *gvt = vgpu->gvt;
> +	struct drm_i915_private *dev_priv = gvt->dev_priv;
> +	struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
> +	u32 index;
> +	u32 offset;
> +	u32 num_entries;
> +	struct intel_gvt_gtt_entry e;
> +
> +	memset(&e, 0, sizeof(struct intel_gvt_gtt_entry));
> +	e.type = GTT_TYPE_GGTT_PTE;
> +	ops->set_pfn(&e, gvt->gtt.scratch_mfn);
> +	e.val64 |= _PAGE_PRESENT;
> +
> +	index = vgpu_aperture_gmadr_base(vgpu) >> PAGE_SHIFT;
> +	num_entries = vgpu_aperture_sz(vgpu) >> PAGE_SHIFT;
> +	for (offset = 0; offset < num_entries; offset++)
> +		ops->set_entry(NULL, &e, index + offset, false, 0, vgpu);
> +
> +	index = vgpu_hidden_gmadr_base(vgpu) >> PAGE_SHIFT;
> +	num_entries = vgpu_hidden_sz(vgpu) >> PAGE_SHIFT;
> +	for (offset = 0; offset < num_entries; offset++)
> +		ops->set_entry(NULL, &e, index + offset, false, 0, vgpu);
> +
> +	gtt_invalidate(dev_priv);
> +}
> +
> +/*
> + * intel_vgpu_invalidate_mm - Invalidate vGPU mm by type
> + * @vgpu: a vGPU
> + * @type: mm type
> + *
> + * This function is used to invalidate mm of specific type
> + *
> + */
> +void intel_vgpu_invalidate_mm(struct intel_vgpu *vgpu, int type)
> +{
> +	struct list_head *pos, *n;
> +	struct intel_vgpu_mm *mm;
> +
> +	if (type == INTEL_GVT_MM_PPGTT) {
> +		intel_vgpu_invalidate_ggtt(vgpu);

Looks you missed my last comment for this typo..

> +		return;
> +	}
> +
> +	list_for_each_safe(pos, n, &vgpu->gtt.mm_list_head) {
> +		mm = container_of(pos, struct intel_vgpu_mm, list);
> +		if (mm->type == INTEL_GVT_MM_PPGTT) {
> +			list_del_init(&mm->lru_list);
> +			if (mm->has_shadow_page_table && mm->shadowed)
> +				invalidate_mm(mm);
> +		}
> +	}
> +}
> +
>  static int reclaim_one_mm(struct intel_gvt *gvt)
>  {
>  	struct intel_vgpu_mm *mm;
> @@ -2107,7 +2163,7 @@ int intel_vgpu_init_gtt(struct intel_vgpu *vgpu)
>  	INIT_LIST_HEAD(&gtt->oos_page_list_head);
>  	INIT_LIST_HEAD(&gtt->post_shadow_list_head);
>  
> -	intel_vgpu_reset_ggtt(vgpu);
> +	intel_vgpu_invalidate_ggtt(vgpu);
>  
>  	ggtt_mm = intel_vgpu_create_mm(vgpu, INTEL_GVT_MM_GGTT,
>  			NULL, 1, 0);
> @@ -2392,42 +2448,6 @@ void intel_gvt_clean_gtt(struct intel_gvt *gvt)
>  }
>  
>  /**
> - * intel_vgpu_reset_ggtt - reset the GGTT entry
> - * @vgpu: a vGPU
> - *
> - * This function is called at the vGPU create stage
> - * to reset all the GGTT entries.
> - *
> - */
> -void intel_vgpu_reset_ggtt(struct intel_vgpu *vgpu)
> -{
> -	struct intel_gvt *gvt = vgpu->gvt;
> -	struct drm_i915_private *dev_priv = gvt->dev_priv;
> -	struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
> -	u32 index;
> -	u32 offset;
> -	u32 num_entries;
> -	struct intel_gvt_gtt_entry e;
> -
> -	memset(&e, 0, sizeof(struct intel_gvt_gtt_entry));
> -	e.type = GTT_TYPE_GGTT_PTE;
> -	ops->set_pfn(&e, gvt->gtt.scratch_mfn);
> -	e.val64 |= _PAGE_PRESENT;
> -
> -	index = vgpu_aperture_gmadr_base(vgpu) >> PAGE_SHIFT;
> -	num_entries = vgpu_aperture_sz(vgpu) >> PAGE_SHIFT;
> -	for (offset = 0; offset < num_entries; offset++)
> -		ops->set_entry(NULL, &e, index + offset, false, 0, vgpu);
> -
> -	index = vgpu_hidden_gmadr_base(vgpu) >> PAGE_SHIFT;
> -	num_entries = vgpu_hidden_sz(vgpu) >> PAGE_SHIFT;
> -	for (offset = 0; offset < num_entries; offset++)
> -		ops->set_entry(NULL, &e, index + offset, false, 0, vgpu);
> -
> -	gtt_invalidate(dev_priv);
> -}
> -
> -/**
>   * intel_vgpu_reset_gtt - reset the all GTT related status
>   * @vgpu: a vGPU
>   *
> @@ -2438,12 +2458,6 @@ void intel_vgpu_reset_ggtt(struct intel_vgpu *vgpu)
>  void intel_vgpu_reset_gtt(struct intel_vgpu *vgpu)
>  {
>  	ppgtt_free_all_shadow_page(vgpu);
> -
> -	/* Shadow pages are only created when there is no page
> -	 * table tracking data, so remove page tracking data after
> -	 * removing the shadow pages.
> -	 */
>  	intel_vgpu_free_mm(vgpu, INTEL_GVT_MM_PPGTT);
> -
> -	intel_vgpu_reset_ggtt(vgpu);
> +	intel_vgpu_invalidate_ggtt(vgpu);
>  }
> diff --git a/drivers/gpu/drm/i915/gvt/gtt.h b/drivers/gpu/drm/i915/gvt/gtt.h
> index 416b2f8..fc04b14 100644
> --- a/drivers/gpu/drm/i915/gvt/gtt.h
> +++ b/drivers/gpu/drm/i915/gvt/gtt.h
> @@ -185,6 +185,7 @@ extern struct intel_vgpu_mm *intel_vgpu_create_mm(struct intel_vgpu *vgpu,
>  		int mm_type, void *virtual_page_table, int page_table_level,
>  		u32 pde_base_index);
>  extern void intel_vgpu_destroy_mm(struct kref *mm_ref);
> +extern void intel_vgpu_invalidate_mm(struct intel_vgpu *vgpu, int type);
>  
>  struct intel_vgpu_guest_page;
>  
> @@ -210,11 +211,10 @@ struct intel_vgpu_gtt {
>  
>  extern int intel_vgpu_init_gtt(struct intel_vgpu *vgpu);
>  extern void intel_vgpu_clean_gtt(struct intel_vgpu *vgpu);
> -void intel_vgpu_reset_ggtt(struct intel_vgpu *vgpu);
>  
>  extern int intel_gvt_init_gtt(struct intel_gvt *gvt);
> -void intel_vgpu_reset_gtt(struct intel_vgpu *vgpu);
>  extern void intel_gvt_clean_gtt(struct intel_gvt *gvt);
> +void intel_vgpu_reset_gtt(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);
> -- 
> 2.7.4
> 
> _______________________________________________
> intel-gvt-dev mailing list
> intel-gvt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/intel-gvt-dev/attachments/20171107/09cbaa14/attachment.sig>


More information about the intel-gvt-dev mailing list