Xen: ARM: Zero reserved fields of xatp before making hypervisor call
PATCH 1/1 Xen: ARM: Zero reserved fields of xatp before making hypervisor call
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.
--- drivers/xen/arm-device.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/xen/arm-device.c +3 -0
@@ -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;
Signature · 3 lines
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.
Juergen Gross
maintainerQuoted 15 lines · 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 forXENMAPSPACE_dev_mmiorequest.Signed-off-by Jiandi An <[email protected]>--- drivers/xen/arm-device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/xen/arm-device.c +0
-0
drivers/xen/arm-device.c static int xen_map_device_mmio(const struct resource *resources, · line 95
Quoted 9 lines
drivers/xen/arm-device.c +3
-0@@ -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
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Juergen Gross
maintainerQuoted 15 lines · 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 forXENMAPSPACE_dev_mmiorequest.Signed-off-by Jiandi An <[email protected]>--- drivers/xen/arm-device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/xen/arm-device.c +0
-0
drivers/xen/arm-device.c static int xen_map_device_mmio(const struct resource *resources, · line 95
Quoted 9 lines
drivers/xen/arm-device.c +3
-0@@ -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
Stefano Stabellini
maintainerQuoted 29 lines · Juergen Gross
Quoted 15 lines · 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 forXENMAPSPACE_dev_mmiorequest.Signed-off-by Jiandi An <[email protected]>--- drivers/xen/arm-device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/xen/arm-device.c +0
-0drivers/xen/arm-device.c static int xen_map_device_mmio(const struct resource *resources, · line 95
Quoted 9 lines
drivers/xen/arm-device.c +3
-0@@ -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:
Quoted 4 lines
struct xen_add_to_physmap_range xatp = {
.domid = DOMID_SELF,
.space = XENMAPSPACE_dev_mmio
};+1
Quoted 30 lines · Stefano Stabellini
Quoted 29 lines · Juergen Gross
Quoted 15 lines · 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 forXENMAPSPACE_dev_mmiorequest.Signed-off-by Jiandi An <[email protected]>--- drivers/xen/arm-device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/xen/arm-device.c +0
-0drivers/xen/arm-device.c static int xen_map_device_mmio(const struct resource *resources, · line 95
Quoted 9 lines
drivers/xen/arm-device.c +3
-0@@ -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:
Quoted 7 lines
Quoted 4 lines
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.
Signature · 3 lines
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.
Juergen Gross
maintainerQuoted 36 lines · Jiandi An
Quoted 35 lines · Stefano Stabellini
Quoted 33 lines · Juergen Gross
Quoted 15 lines · 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 forXENMAPSPACE_dev_mmiorequest.Signed-off-by Jiandi An <[email protected]>--- drivers/xen/arm-device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/xen/arm-device.c +0
-0drivers/xen/arm-device.c static int xen_map_device_mmio(const struct resource *resources, · line 95
Quoted 9 lines
drivers/xen/arm-device.c +3
-0@@ -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 };
Quoted 8 lines
Quoted 2 lines
+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
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Juergen Gross
maintainerQuoted 36 lines · Jiandi An
Quoted 35 lines · Stefano Stabellini
Quoted 33 lines · Juergen Gross
Quoted 15 lines · 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 forXENMAPSPACE_dev_mmiorequest.Signed-off-by Jiandi An <[email protected]>--- drivers/xen/arm-device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/xen/arm-device.c +0
-0drivers/xen/arm-device.c static int xen_map_device_mmio(const struct resource *resources, · line 95
Quoted 9 lines
drivers/xen/arm-device.c +3
-0@@ -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 };
Quoted 8 lines
Quoted 2 lines
+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
Hi Jiandi,
Please respect the netiquette and wrap line to 70-75 characters.
Quoted 6 lines · Jiandi An
Quoted 2 lines · Stefano Stabellini
Quoted 1 line · Juergen Gross
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,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Hi Jiandi,
Please respect the netiquette and wrap line to 70-75 characters.
Quoted 6 lines · Jiandi An
Quoted 2 lines · Stefano Stabellini
Quoted 1 line · Juergen Gross
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,
Signature · 1 line
Julien Grall
Quoted 30 lines · Stefano Stabellini
Quoted 29 lines · Juergen Gross
Quoted 15 lines · 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 forXENMAPSPACE_dev_mmiorequest.Signed-off-by Jiandi An <[email protected]>--- drivers/xen/arm-device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/xen/arm-device.c +0
-0drivers/xen/arm-device.c static int xen_map_device_mmio(const struct resource *resources, · line 95
Quoted 9 lines
drivers/xen/arm-device.c +3
-0@@ -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:
Quoted 7 lines
Quoted 4 lines
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.
Signature · 8 lines
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. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Stefano Stabellini
maintainerQuoted 29 lines · Juergen Gross
Quoted 15 lines · 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 forXENMAPSPACE_dev_mmiorequest.Signed-off-by Jiandi An <[email protected]>--- drivers/xen/arm-device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/xen/arm-device.c +0
-0drivers/xen/arm-device.c static int xen_map_device_mmio(const struct resource *resources, · line 95
Quoted 9 lines
drivers/xen/arm-device.c +3
-0@@ -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:
Quoted 4 lines
struct xen_add_to_physmap_range xatp = {
.domid = DOMID_SELF,
.space = XENMAPSPACE_dev_mmio
};+1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel