linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
@ 2016-12-19  2:56 Jiandi An
  2016-12-19 12:14 ` Juergen Gross
  0 siblings, 1 reply; 6+ messages in thread
From: Jiandi An @ 2016-12-19  2:56 UTC (permalink / raw)
  To: boris.ostrovsky, jgross, xen-devel, linux-kernel
  Cc: julien.grall, sstabellini, shankerd, shannon.zhao, Jiandi An

Ensure all reserved fields of xatp are zero before making hypervisor
call to XEN in xen_map_device_mmio().  xenmem_add_to_physmap_one() in
XEN fails the mapping request if extra.res reserved field in xatp is
not zero for XENMAPSPACE_dev_mmio request.

Signed-off-by: Jiandi An <anjiandi@codeaurora.org>
---
 drivers/xen/arm-device.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/xen/arm-device.c b/drivers/xen/arm-device.c
index 778acf8..208273b 100644
--- a/drivers/xen/arm-device.c
+++ b/drivers/xen/arm-device.c
@@ -87,6 +87,9 @@ static int xen_map_device_mmio(const struct resource *resources,
 			idxs[j] = XEN_PFN_DOWN(r->start) + j;
 		}
 
+		/* Ensure reserved fields are set to zero */
+		memset(&xatp, 0, sizeof(xatp));
+
 		xatp.domid = DOMID_SELF;
 		xatp.size = nr;
 		xatp.space = XENMAPSPACE_dev_mmio;
-- 
Jiandi An
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
  2016-12-19  2:56 [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call Jiandi An
@ 2016-12-19 12:14 ` Juergen Gross
  2016-12-19 18:49   ` Stefano Stabellini
  0 siblings, 1 reply; 6+ messages in thread
From: Juergen Gross @ 2016-12-19 12:14 UTC (permalink / raw)
  To: Jiandi An, boris.ostrovsky, xen-devel, linux-kernel
  Cc: julien.grall, sstabellini, shankerd, shannon.zhao

On 19/12/16 03:56, Jiandi An wrote:
> Ensure all reserved fields of xatp are zero before making hypervisor
> call to XEN in xen_map_device_mmio().  xenmem_add_to_physmap_one() in
> XEN fails the mapping request if extra.res reserved field in xatp is
> not zero for XENMAPSPACE_dev_mmio request.
> 
> Signed-off-by: Jiandi An <anjiandi@codeaurora.org>
> ---
>  drivers/xen/arm-device.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/xen/arm-device.c b/drivers/xen/arm-device.c
> index 778acf8..208273b 100644
> --- a/drivers/xen/arm-device.c
> +++ b/drivers/xen/arm-device.c
> @@ -87,6 +87,9 @@ static int xen_map_device_mmio(const struct resource *resources,
>  			idxs[j] = XEN_PFN_DOWN(r->start) + j;
>  		}
>  
> +		/* Ensure reserved fields are set to zero */
> +		memset(&xatp, 0, sizeof(xatp));
> +
>  		xatp.domid = DOMID_SELF;
>  		xatp.size = nr;
>  		xatp.space = XENMAPSPACE_dev_mmio;

Instead of setting xatp to 0 in each iteration I'd prefer a static
initialization of .domid and .space:

	struct xen_add_to_physmap_range xatp = {
		.domid = DOMID_SELF,
		.space = XENMAPSPACE_dev_mmio
	};


Juergen

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
  2016-12-19 12:14 ` Juergen Gross
@ 2016-12-19 18:49   ` Stefano Stabellini
  2016-12-20  5:02     ` Jiandi An
  0 siblings, 1 reply; 6+ messages in thread
From: Stefano Stabellini @ 2016-12-19 18:49 UTC (permalink / raw)
  To: Juergen Gross
  Cc: Jiandi An, boris.ostrovsky, xen-devel, linux-kernel,
	julien.grall, sstabellini, shankerd, shannon.zhao

On Mon, 19 Dec 2016, Juergen Gross wrote:
> On 19/12/16 03:56, Jiandi An wrote:
> > Ensure all reserved fields of xatp are zero before making hypervisor
> > call to XEN in xen_map_device_mmio().  xenmem_add_to_physmap_one() in
> > XEN fails the mapping request if extra.res reserved field in xatp is
> > not zero for XENMAPSPACE_dev_mmio request.
> > 
> > Signed-off-by: Jiandi An <anjiandi@codeaurora.org>
> > ---
> >  drivers/xen/arm-device.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/xen/arm-device.c b/drivers/xen/arm-device.c
> > index 778acf8..208273b 100644
> > --- a/drivers/xen/arm-device.c
> > +++ b/drivers/xen/arm-device.c
> > @@ -87,6 +87,9 @@ static int xen_map_device_mmio(const struct resource *resources,
> >  			idxs[j] = XEN_PFN_DOWN(r->start) + j;
> >  		}
> >  
> > +		/* Ensure reserved fields are set to zero */
> > +		memset(&xatp, 0, sizeof(xatp));
> > +
> >  		xatp.domid = DOMID_SELF;
> >  		xatp.size = nr;
> >  		xatp.space = XENMAPSPACE_dev_mmio;
> 
> Instead of setting xatp to 0 in each iteration I'd prefer a static
> initialization of .domid and .space:
> 
> 	struct xen_add_to_physmap_range xatp = {
> 		.domid = DOMID_SELF,
> 		.space = XENMAPSPACE_dev_mmio
> 	};

+1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
  2016-12-19 18:49   ` Stefano Stabellini
@ 2016-12-20  5:02     ` Jiandi An
  2016-12-20  9:57       ` Juergen Gross
  2016-12-20 10:31       ` Julien Grall
  0 siblings, 2 replies; 6+ messages in thread
From: Jiandi An @ 2016-12-20  5:02 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Juergen Gross, boris.ostrovsky, xen-devel, linux-kernel,
	julien.grall, shankerd, shannon.zhao

On 12/19/16 12:49, Stefano Stabellini wrote:
> On Mon, 19 Dec 2016, Juergen Gross wrote:
>> On 19/12/16 03:56, Jiandi An wrote:
>>> Ensure all reserved fields of xatp are zero before making hypervisor
>>> call to XEN in xen_map_device_mmio().  xenmem_add_to_physmap_one() in
>>> XEN fails the mapping request if extra.res reserved field in xatp is
>>> not zero for XENMAPSPACE_dev_mmio request.
>>>
>>> Signed-off-by: Jiandi An <anjiandi@codeaurora.org>
>>> ---
>>>  drivers/xen/arm-device.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/drivers/xen/arm-device.c b/drivers/xen/arm-device.c
>>> index 778acf8..208273b 100644
>>> --- a/drivers/xen/arm-device.c
>>> +++ b/drivers/xen/arm-device.c
>>> @@ -87,6 +87,9 @@ static int xen_map_device_mmio(const struct resource *resources,
>>>  			idxs[j] = XEN_PFN_DOWN(r->start) + j;
>>>  		}
>>>  
>>> +		/* Ensure reserved fields are set to zero */
>>> +		memset(&xatp, 0, sizeof(xatp));
>>> +
>>>  		xatp.domid = DOMID_SELF;
>>>  		xatp.size = nr;
>>>  		xatp.space = XENMAPSPACE_dev_mmio;
>>
>> Instead of setting xatp to 0 in each iteration I'd prefer a static
>> initialization of .domid and .space:
>>
>> 	struct xen_add_to_physmap_range xatp = {
>> 		.domid = DOMID_SELF,
>> 		.space = XENMAPSPACE_dev_mmio
>> 	};
> 
> +1
> 

Hi Juergen,

Thanks for you comments.  xatp is passed to XEN via the hypervisor call in each loop.
XEN touches xatp and returns it back.  For example XEN returns error of underlying mapping call in the err[] array in xatp. (The err[] is not checked after the hypervisor call returns and it's a bug to be addressed in a separate patch)  XEN could theoretically corrupt xatp when it's returned.  And the loop would go on to the next iteration passing in whatever that's in xatp returned by the previous hypervisor call.  Harder to debug in my opinion if xatp get corrupted by XEN somehow when a bug is introduced in XEN.  At first I put the memset of xatp at the beginning outside of the loop.  But I thought it's better to initialize xatp that's passed in each time a hypervisor call is made so we know exactly we set going into the hypervisor call.

-- 
Jiandi An
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
  2016-12-20  5:02     ` Jiandi An
@ 2016-12-20  9:57       ` Juergen Gross
  2016-12-20 10:31       ` Julien Grall
  1 sibling, 0 replies; 6+ messages in thread
From: Juergen Gross @ 2016-12-20  9:57 UTC (permalink / raw)
  To: Jiandi An, Stefano Stabellini
  Cc: boris.ostrovsky, xen-devel, linux-kernel, julien.grall, shankerd,
	shannon.zhao

On 20/12/16 06:02, Jiandi An wrote:
> On 12/19/16 12:49, Stefano Stabellini wrote:
>> On Mon, 19 Dec 2016, Juergen Gross wrote:
>>> On 19/12/16 03:56, Jiandi An wrote:
>>>> Ensure all reserved fields of xatp are zero before making hypervisor
>>>> call to XEN in xen_map_device_mmio().  xenmem_add_to_physmap_one() in
>>>> XEN fails the mapping request if extra.res reserved field in xatp is
>>>> not zero for XENMAPSPACE_dev_mmio request.
>>>>
>>>> Signed-off-by: Jiandi An <anjiandi@codeaurora.org>
>>>> ---
>>>>  drivers/xen/arm-device.c | 3 +++
>>>>  1 file changed, 3 insertions(+)
>>>>
>>>> diff --git a/drivers/xen/arm-device.c b/drivers/xen/arm-device.c
>>>> index 778acf8..208273b 100644
>>>> --- a/drivers/xen/arm-device.c
>>>> +++ b/drivers/xen/arm-device.c
>>>> @@ -87,6 +87,9 @@ static int xen_map_device_mmio(const struct resource *resources,
>>>>  			idxs[j] = XEN_PFN_DOWN(r->start) + j;
>>>>  		}
>>>>  
>>>> +		/* Ensure reserved fields are set to zero */
>>>> +		memset(&xatp, 0, sizeof(xatp));
>>>> +
>>>>  		xatp.domid = DOMID_SELF;
>>>>  		xatp.size = nr;
>>>>  		xatp.space = XENMAPSPACE_dev_mmio;
>>>
>>> Instead of setting xatp to 0 in each iteration I'd prefer a static
>>> initialization of .domid and .space:
>>>
>>> 	struct xen_add_to_physmap_range xatp = {
>>> 		.domid = DOMID_SELF,
>>> 		.space = XENMAPSPACE_dev_mmio
>>> 	};
>>
>> +1
>>
> 
> Hi Juergen,
> 
> Thanks for you comments.  xatp is passed to XEN via the hypervisor call in each loop.
> XEN touches xatp and returns it back.  For example XEN returns error of underlying mapping call in the err[] array in xatp. (The err[] is not checked after the hypervisor call returns and it's a bug to be addressed in a separate patch)  XEN could theoretically corrupt xatp when it's returned.  And the loop would go on to the next iteration passing in whatever that's in xatp returned by the previous hypervisor call.  Harder to debug in my opinion if xatp get corrupted by XEN somehow when a bug is introduced in XEN.  At first I put the memset of xatp at the beginning outside of the loop.  But I thought it's better to initialize xatp that's passed in each time a hypervisor call is made so we know exactly we set going into the hypervisor call.
> 

It is very clearly specified which parameters are IN and which are OUT.
No trusting the hypervisor to follow this interface specification is
weird. Where do you want to stop?


Juergen

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
  2016-12-20  5:02     ` Jiandi An
  2016-12-20  9:57       ` Juergen Gross
@ 2016-12-20 10:31       ` Julien Grall
  1 sibling, 0 replies; 6+ messages in thread
From: Julien Grall @ 2016-12-20 10:31 UTC (permalink / raw)
  To: Jiandi An, Stefano Stabellini
  Cc: Juergen Gross, boris.ostrovsky, xen-devel, linux-kernel,
	shankerd, shannon.zhao

Hi Jiandi,

Please respect the netiquette and wrap line to 70-75 characters.

On 20/12/2016 06:02, Jiandi An wrote:
> On 12/19/16 12:49, Stefano Stabellini wrote:
>> On Mon, 19 Dec 2016, Juergen Gross wrote:
>>> On 19/12/16 03:56, Jiandi An wrote:

> Thanks for you comments.  xatp is passed to XEN via the hypervisor call in each loop.
> XEN touches xatp and returns it back.  For example XEN returns error of underlying mapping call in the err[] array in xatp. (The err[] is not checked after the hypervisor call returns and it's a bug to be addressed in a separate patch)  XEN could theoretically corrupt xatp when it's returned.  And the loop would go on to the next iteration passing in whatever that's in xatp returned by the previous hypervisor call.  Harder to debug in my opinion if xatp get corrupted by XEN somehow when a bug is introduced in XEN.  At first I put the memset of xatp at the beginning outside of the loop.  But I thought it's better to initialize xatp that's passed in each time a hypervisor call is made so we know exactly we set going into the hypervisor call.

If you move struct xen_add_to_physmap_range in the loop, the compiler 
will initialize and zeroed for you the structure at each loop. I.e

for (i = 0; i < count; i++) {
	struct xen_add_to_physmap_range xapt = ....


}

Cheers,

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-20 10:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-19  2:56 [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call Jiandi An
2016-12-19 12:14 ` Juergen Gross
2016-12-19 18:49   ` Stefano Stabellini
2016-12-20  5:02     ` Jiandi An
2016-12-20  9:57       ` Juergen Gross
2016-12-20 10:31       ` Julien Grall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).