Skip to contentSkip to conversation

MISRA violations in hypercall-defs

DISCUSSION Federico Serafini 4 participants 9 messages Aug 8, 2023 – Aug 9, 2023

lore
Share & tools
lore
#0 lore raw

Hello everyone.

I would like to to ask your opinion about the auto-generated file xen/include/xen/hypercall-defs.h which contains some violations of MISRA C:2012 Rule 8.3:
"All declarations of an object or function shall use the same names and type qualifiers".

Such violations can be seen at the following links
(copy and paste the link on you browser, including also the characters after the '#'):

- arm
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/ARM64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

- x86
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/X86_64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

Some of the violations are due to mismatches on the return types and the use of ret_t.
I see that xen/include/hypercall-defs.c generates the declarations but I am not sure about what might be the best way to modify it so as to address violations with the least amount of changes. Do you have any suggestions?

Regards

Signature · 3 lines
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)
#1 lore raw
Quoted 12 lines · Federico Serafini

Hello everyone.

I would like to to ask your opinion about the auto-generated file xen/include/xen/hypercall-defs.h which contains some violations of MISRA C:2012 Rule 8.3:
"All declarations of an object or function shall use the same names and type qualifiers".

Such violations can be seen at the following links
(copy and paste the link on you browser, including also the characters after the '#'):

Quoted 8 lines

- arm
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/ARM64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

- x86
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/X86_64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

Some of the violations are due to mismatches on the return types and the use of ret_t.

We already said that ret_t will need deviating. For parameter names it ought to be possible to suitably rename, like done elsewhere. Whether that means renaming in the generator script or in the definitions likely again needs judging on a case-by-case basis.

Jan

#2 lore raw
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Federico Serafini

Hello everyone.

I would like to to ask your opinion about the auto-generated file xen/include/xen/hypercall-defs.h which contains some violations of MISRA C:2012 Rule 8.3:
"All declarations of an object or function shall use the same names and type qualifiers".

Such violations can be seen at the following links
(copy and paste the link on you browser, including also the characters after the '#'):

- arm
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/ARM64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

- x86
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/X86_64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

Quoted 7 lines
Quoted 2 lines

Some of the violations are due to mismatches on the return types and the use of ret_t.

We already said that ret_t will need deviating. For parameter names it ought to be possible to suitably rename, like done elsewhere. Whether that means renaming in the generator script or in the definitions likely again needs judging on a case-by-case basis.

Is it the case that ret_t is purposedly defined as 'long' for 64-bit x86 guests and 'int' for 32-bit x86 guests?

I am asking because it looks like we don't use ret_t at all on ARM and on the public interfaces.

#3 lore raw
Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Federico Serafini

Hello everyone.

I would like to to ask your opinion about the auto-generated file xen/include/xen/hypercall-defs.h which contains some violations of MISRA C:2012 Rule 8.3:
"All declarations of an object or function shall use the same names and type qualifiers".

Such violations can be seen at the following links
(copy and paste the link on you browser, including also the characters after the '#'):

- arm
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/ARM64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

- x86
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/X86_64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

Some of the violations are due to mismatches on the return types and the use of ret_t.

Quoted 7 lines
Quoted 4 lines

We already said that ret_t will need deviating. For parameter names it ought to be possible to suitably rename, like done elsewhere. Whether that means renaming in the generator script or in the definitions likely again needs judging on a case-by-case basis.

Is it the case that ret_t is purposedly defined as 'long' for 64-bit x86 guests and 'int' for 32-bit x86 guests?

Yes.

Quoted 2 lines

I am asking because it looks like we don't use ret_t at all on ARM and on the public interfaces.

And I wonder how you get away with this. Aiui hypercall return values are 32-bit on Arm32, so I'd expect you to be at risk of truncation issues in a limited set of cases (see in particular the bottom of compat_memory_op(), where out-of-range values are saturated rather than truncated). But maybe in practice this can't happen?

Jan

#4 lore raw
Quoted 34 lines · Jan Beulich
Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Federico Serafini

Hello everyone.

I would like to to ask your opinion about the auto-generated file xen/include/xen/hypercall-defs.h which contains some violations of MISRA C:2012 Rule 8.3:
"All declarations of an object or function shall use the same names and type qualifiers".

Such violations can be seen at the following links
(copy and paste the link on you browser, including also the characters after the '#'):

- arm
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/ARM64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

- x86
https://saas.eclairit.com:3787/fs/var/local/eclair/XEN.ecdf/ECLAIR_normal/origin/staging/X86_64-Set1/218/PROJECT.ecd;/by_service/MC3R1.R8.3.html#{"select":true,"selection":{"hiddenAreaKinds":[],"hiddenSubareaKinds":[],"show":true,"selector":{"enabled":true,"negated":false,"kind":2,"children":[{"enabled":true,"negated":false,"kind":0,"domain":"file","inputs":[{"enabled":true,"text":"xen/include/xen/hypercall-defs.h"}]}]}}}

Some of the violations are due to mismatches on the return types and the use of ret_t.

Quoted 7 lines
Quoted 4 lines

We already said that ret_t will need deviating. For parameter names it ought to be possible to suitably rename, like done elsewhere. Whether that means renaming in the generator script or in the definitions likely again needs judging on a case-by-case basis.

Is it the case that ret_t is purposedly defined as 'long' for 64-bit x86 guests and 'int' for 32-bit x86 guests?

Yes.

Quoted 8 lines
Quoted 2 lines

I am asking because it looks like we don't use ret_t at all on ARM and on the public interfaces.

And I wonder how you get away with this. Aiui hypercall return values are 32-bit on Arm32, so I'd expect you to be at risk of truncation issues in a limited set of cases (see in particular the bottom of compat_memory_op(), where out-of-range values are saturated rather than truncated). But maybe in practice this can't happen?

Yes I think that must be it. Also consider that mixing 32/64 environments on ARM is rare: the arm32 version of Xen is mostly to run on arm32 targets with only 32-bit guests. The arm64 version of Xen is to run on arm64 targets with mostly (only?) 64-bit guests. Which is a different situation compared to x86.

So the ret_t deviation would only affect the x86 version of the hypervisor.

P.S.
Julien, Bertrand, do you think we should unsupport (in SUPPORT.md, today it is not clarified) 32-bit guests on a 64-bit ARM hypervisor?

#5 lore raw

Hi,

Quoted 3 lines · Stefano Stabellini

P.S.
Julien, Bertrand, do you think we should unsupport (in SUPPORT.md, today it is not clarified) 32-bit guests on a 64-bit ARM hypervisor?

I read your explanation above and I don't really understand why you would want to de-support it. This works pretty well and I am not aware of any issue right now to run 32-bit guest on 64-bit HW.

Cheers,

Signature · 1 line
Julien Grall
#6 lore raw
Quoted 10 lines · Julien Grall

Hi,

Quoted 3 lines · Stefano Stabellini

P.S.
Julien, Bertrand, do you think we should unsupport (in SUPPORT.md, today it is not clarified) 32-bit guests on a 64-bit ARM hypervisor?

I read your explanation above and I don't really understand why you would want to de-support it. This works pretty well and I am not aware of any issue right now to run 32-bit guest on 64-bit HW.

I am happy either way. The reason why I brought it up is that we don't have a specific test for this in gitlab-ci and Jan raised concerns that greater-than 32-bit values as possible as ret from hypercalls on a 64-bit build of Xen.

#7 lore raw

Hi,

Quoted 8 lines · Stefano Stabellini
Quoted 7 lines · Julien Grall

Hi,

Quoted 3 lines · Stefano Stabellini

P.S.
Julien, Bertrand, do you think we should unsupport (in SUPPORT.md, today it is not clarified) 32-bit guests on a 64-bit ARM hypervisor?

Quoted 6 lines
Quoted 3 lines

I read your explanation above and I don't really understand why you would want to de-support it. This works pretty well and I am not aware of any issue right now to run 32-bit guest on 64-bit HW.

I am happy either way. The reason why I brought it up is that we don't have a specific test for this in gitlab-ci

But a gitlab CI test can be added, right? I mean it would seem to be odd to use this as a justification because a lot of features (e.g. passthrough, suspend/resume...) would end up to be de-support it as gitlab CI is still in early stage.

Quoted 3 lines

and Jan raised concerns that
greater-than 32-bit values as possible as ret from hypercalls on a 64-bit build of Xen.

This is a known problem and it was discussed several times on the ML in the past years.

There is a theorical problem because in theory all the hypercalls could return a value that can't fit in 32-bit.

However, AFAIK, only the memory hypercall XENMEM_maximum_gpfn may return a 64-bit value on 64-bit Xen.

It is not a problem for a 32-bit domain issues the hypercall on itself because the guest physical maximum address should never be greater than 40-bit (so 28-bit page frame number) and therefore could fit in 32-bit.

The only problem is if you want to use a 32-bit toolstack on 64-bit. But Jan sent a patch for SUPPORT.md to clarify this is not meant to always work (see [1]).

Please let me know if you are aware of any other truncations.

Cheers,

[1] [email protected]

Signature · 1 line
Julien Grall
#8 lore raw
Quoted 15 lines · Julien Grall
Quoted 14 lines · Stefano Stabellini
Quoted 12 lines · Julien Grall

Hi,

Quoted 3 lines · Stefano Stabellini

P.S.
Julien, Bertrand, do you think we should unsupport (in SUPPORT.md, today it is not clarified) 32-bit guests on a 64-bit ARM hypervisor?

I read your explanation above and I don't really understand why you would want
to de-support it. This works pretty well and I am not aware of any issue right
now to run 32-bit guest on 64-bit HW.

Quoted 7 lines
Quoted 2 lines

I am happy either way. The reason why I brought it up is that we don't have a specific test for this in gitlab-ci

But a gitlab CI test can be added, right? I mean it would seem to be odd to use this as a justification because a lot of features (e.g. passthrough, suspend/resume...) would end up to be de-support it as gitlab CI is still in early stage.

Yes that's fair

Quoted 17 lines
Quoted 3 lines

and Jan raised concerns that
greater-than 32-bit values as possible as ret from hypercalls on a 64-bit build of Xen.

This is a known problem and it was discussed several times on the ML in the past years.

There is a theorical problem because in theory all the hypercalls could return a value that can't fit in 32-bit.

However, AFAIK, only the memory hypercall XENMEM_maximum_gpfn may return a 64-bit value on 64-bit Xen.

It is not a problem for a 32-bit domain issues the hypercall on itself because the guest physical maximum address should never be greater than 40-bit (so 28-bit page frame number) and therefore could fit in 32-bit.

Quoted 5 lines

The only problem is if you want to use a 32-bit toolstack on 64-bit. But Jan sent a patch for SUPPORT.md to clarify this is not meant to always work (see [1]).

Please let me know if you are aware of any other truncations.

No, that's fine. This is exactly what I wanted to know :-)