[PATCH 2/2] drm/i915/gvt: Initialize intel_gvt_gtt_entry in stack

Zhenyu Wang zhenyuw at linux.intel.com
Mon May 20 05:57:48 UTC 2019


On 2019.05.20 13:36:49 +0800, Tina Zhang wrote:
> In stack, intel_gvt_gtt_entry needs to be initialized before
> being used, as the fields may have some garbage values.
> 
> W/o this patch, set_ggtt_entry prints:
> -------------------------------------
> 274.046840: set_ggtt_entry: vgpu1:set ggtt entry 0x9bed8000ffffe900
> 274.046846: set_ggtt_entry: vgpu1:set ggtt entry 0xe55df001
> 274.046852: set_ggtt_entry: vgpu1:set ggtt entry 0x9bed8000ffffe900
> 
> 0x9bed8000 is the stack grabage.
> 
> W/ this patch, set_ggtt_entry prints:
> ------------------------------------
> 274.046840: set_ggtt_entry: vgpu1:set ggtt entry 0xffffe900
> 274.046846: set_ggtt_entry: vgpu1:set ggtt entry 0xe55df001
> 274.046852: set_ggtt_entry: vgpu1:set ggtt entry 0xffffe900
> 
> Signed-off-by: Tina Zhang <tina.zhang at intel.com>
> ---
>  drivers/gpu/drm/i915/gvt/gtt.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
> index dcc207f04b75..bcb649285707 100644
> --- a/drivers/gpu/drm/i915/gvt/gtt.c
> +++ b/drivers/gpu/drm/i915/gvt/gtt.c
> @@ -2193,7 +2193,7 @@ static int emulate_ggtt_mmio_write(struct intel_vgpu *vgpu, unsigned int off,
>  	/* the VM may configure the whole GM space when ballooning is used */
>  	if (!vgpu_gmadr_is_valid(vgpu, gma))
>  		return 0;
> -
> +	e.val64 = 0;

Could we just initialize it during declaration?

>  	e.type = GTT_TYPE_GGTT_PTE;
>  	memcpy((void *)&e.val64 + (off & (info->gtt_entry_size - 1)), p_data,
>  			bytes);
> @@ -2246,7 +2246,8 @@ static int emulate_ggtt_mmio_write(struct intel_vgpu *vgpu, unsigned int off,
>  
>  	if (!partial_update && (ops->test_present(&e))) {
>  		gfn = ops->get_pfn(&e);
> -		m = e;
> +		m.val64 = e.val64;
> +		m.type = e.type;

Better just memcpy which doesn't depend on struct definition.

>  
>  		/* one PTE update may be issued in multiple writes and the
>  		 * first write may not construct a valid gfn
> @@ -2268,6 +2269,8 @@ static int emulate_ggtt_mmio_write(struct intel_vgpu *vgpu, unsigned int off,
>  		} else
>  			ops->set_pfn(&m, dma_addr >> PAGE_SHIFT);
>  	} else {
> +		m.val64 = 0;
> +		m.type = GTT_TYPE_GGTT_PTE;
>  		ops->set_pfn(&m, gvt->gtt.scratch_mfn);
>  		ops->clear_present(&m);
>  	}
> -- 
> 2.17.1
> 

-- 
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/20190520/53b45cb9/attachment.sig>


More information about the intel-gvt-dev mailing list