Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1544311 > unrolled thread

[PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call

Started byJiandi An <anjiandi@codeaurora.org>
First post2016-12-19 04:00 +0100
Last post2016-12-20 11:40 +0100
Articles 6 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call Jiandi An <anjiandi@codeaurora.org> - 2016-12-19 04:00 +0100
    Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making  hypervisor call Juergen Gross <jgross@suse.com> - 2016-12-19 13:20 +0100
      Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making  hypervisor call Stefano Stabellini <sstabellini@kernel.org> - 2016-12-19 19:50 +0100
        Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making  hypervisor call Jiandi An <anjiandi@codeaurora.org> - 2016-12-20 06:10 +0100
          Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making  hypervisor call Juergen Gross <jgross@suse.com> - 2016-12-20 11:00 +0100
          Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making  hypervisor call Julien Grall <julien.grall@arm.com> - 2016-12-20 11:40 +0100

#1544311 — [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call

FromJiandi An <anjiandi@codeaurora.org>
Date2016-12-19 04:00 +0100
Subject[PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
Message-ID<sPWlc-1Pz-9@gated-at.bofh.it>
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.

[toc] | [next] | [standalone]


#1544490 — Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call

FromJuergen Gross <jgross@suse.com>
Date2016-12-19 13:20 +0100
SubjectRe: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
Message-ID<sQ558-7DY-15@gated-at.bofh.it>
In reply to#1544311
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

[toc] | [prev] | [next] | [standalone]


#1544739 — Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call

FromStefano Stabellini <sstabellini@kernel.org>
Date2016-12-19 19:50 +0100
SubjectRe: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
Message-ID<sQbay-36y-23@gated-at.bofh.it>
In reply to#1544490
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

[toc] | [prev] | [next] | [standalone]


#1544900 — Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call

FromJiandi An <anjiandi@codeaurora.org>
Date2016-12-20 06:10 +0100
SubjectRe: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
Message-ID<sQkQy-12I-3@gated-at.bofh.it>
In reply to#1544739
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.

[toc] | [prev] | [next] | [standalone]


#1545014 — Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call

FromJuergen Gross <jgross@suse.com>
Date2016-12-20 11:00 +0100
SubjectRe: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
Message-ID<sQpnb-3Uc-19@gated-at.bofh.it>
In reply to#1544900
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

[toc] | [prev] | [next] | [standalone]


#1545037 — Re: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call

FromJulien Grall <julien.grall@arm.com>
Date2016-12-20 11:40 +0100
SubjectRe: [PATCH] Xen: ARM: Zero reserved fields of xatp before making hypervisor call
Message-ID<sQpZT-4mH-9@gated-at.bofh.it>
In reply to#1544900
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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web