diff mbox series

[XEN,for-4.19,v2,2/2] docs/misra: add deviations.rst to document additional deviations.

Message ID ccda90b6be8f6977cff14ae65749ffc7fa429c3c.1696865051.git.nicola.vetrini@bugseng.com (mailing list archive)
State Superseded
Headers show
Series update ecl configurations and deviations | expand

Commit Message

Nicola Vetrini Oct. 9, 2023, 3:44 p.m. UTC
This file contains the deviation that are not marked by
a deviation comment, as specified in
docs/misra/documenting-violations.rst.

Suggested-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 docs/index.rst            |   1 +
 docs/misra/deviations.rst | 240 ++++++++++++++++++++++++++++++++++++++
 docs/misra/rules.rst      |   2 +-
 3 files changed, 242 insertions(+), 1 deletion(-)
 create mode 100644 docs/misra/deviations.rst

--
2.34.1

Comments

Stefano Stabellini Oct. 10, 2023, 1:19 a.m. UTC | #1
+Henry

On Mon, 9 Oct 2023, Nicola Vetrini wrote:
> This file contains the deviation that are not marked by
> a deviation comment, as specified in
> docs/misra/documenting-violations.rst.
> 
> Suggested-by: Stefano Stabellini <sstabellini@kernel.org>
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

This is great! Thank you so much!

I have a few questions below but even as-is it is way better than
nothing. I think we should add this for 4.18


> ---
>  docs/index.rst            |   1 +
>  docs/misra/deviations.rst | 240 ++++++++++++++++++++++++++++++++++++++
>  docs/misra/rules.rst      |   2 +-
>  3 files changed, 242 insertions(+), 1 deletion(-)
>  create mode 100644 docs/misra/deviations.rst
> 
> diff --git a/docs/index.rst b/docs/index.rst
> index 2c47cfa999f2..f3f779f89ce5 100644
> --- a/docs/index.rst
> +++ b/docs/index.rst
> @@ -63,6 +63,7 @@ Xen hypervisor code.
>     :maxdepth: 2
> 
>     misra/rules
> +   misra/deviations
> 
> 
>  Miscellanea
> diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
> new file mode 100644
> index 000000000000..19743e34ce03
> --- /dev/null
> +++ b/docs/misra/deviations.rst
> @@ -0,0 +1,240 @@
> +.. SPDX-License-Identifier: CC-BY-4.0
> +
> +MISRA C deviations for Xen
> +==========================
> +
> +The following is the list of MISRA C:2012 deviations for the Xen codebase that
> +are not covered by a `SAF-x-safe` or `SAF-x-false-positive-<tool>` comment, as
> +specified in docs/misra/documenting-violations.rst; the lack of
> +such comments is usually due to the excessive clutter they would bring to the
> +codebase or the impossibility to express such a deviation (e.g., if it's
> +composed of several conditions).
> +
> +Deviations related to MISRA C:2012 Directives:
> +----------------------------------------------
> +
> +.. list-table::
> +   :header-rows: 1
> +
> +   * - Directive identifier
> +     - Justification
> +     - Notes
> +
> +   * - D4.3
> +     - Accepted for the ARM64 codebase
> +     - Tagged as `disapplied` for ECLAIR on any other violation report.

This mean it has been applied for ARM64 but not x86, right?


> +   * - D4.3
> +     - The inline asm in 'xen/arch/arm/arm64/lib/bitops.c' is tightly coupled
> +       with the surronding C code that acts as a wrapper, so it has been decided
> +       not to add an additional encapsulation layer.
> +     - Tagged as `deliberate` for ECLAIR.
> +
> +Deviations related to MISRA C:2012 Rules:
> +-----------------------------------------
> +
> +.. list-table::
> +   :header-rows: 1
> +
> +   * - Rule identifier
> +     - Justification
> +     - Notes
> +
> +   * - R2.1
> +     - The compiler implementation guarantees that the unreachable code is
> +       removed. Constant expressions and unreachable branches of if and switch
> +       statements are expected.
> +     - Tagged as `safe` for ECLAIR.
> +
> +   * - R2.1
> +     - Some functions are intended not to be referenced.
> +     - Tagged as `deliberate` for ECLAIR.

What does it mean "some functions" in this case? Should we list which
functions?

Other than this, I checked and everything else looks great
Henry Wang Oct. 10, 2023, 1:21 a.m. UTC | #2
Hi Stefano,

> On Oct 10, 2023, at 09:19, Stefano Stabellini <sstabellini@kernel.org> wrote:
> 
> +Henry

Thank you.

> 
> On Mon, 9 Oct 2023, Nicola Vetrini wrote:
>> This file contains the deviation that are not marked by
>> a deviation comment, as specified in
>> docs/misra/documenting-violations.rst.
>> 
>> Suggested-by: Stefano Stabellini <sstabellini@kernel.org>
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> 
> This is great! Thank you so much!
> 
> I have a few questions below but even as-is it is way better than
> nothing. I think we should add this for 4.18

I am fine with that as this patch is purely doc changes.

Release-acked-by: Henry Wang <Henry.Wang@arm.com>

Kind regards,
Henry

> 
> 
>> ---
>> docs/index.rst            |   1 +
>> docs/misra/deviations.rst | 240 ++++++++++++++++++++++++++++++++++++++
>> docs/misra/rules.rst      |   2 +-
>> 3 files changed, 242 insertions(+), 1 deletion(-)
>> create mode 100644 docs/misra/deviations.rst
>> 
>> diff --git a/docs/index.rst b/docs/index.rst
>> index 2c47cfa999f2..f3f779f89ce5 100644
>> --- a/docs/index.rst
>> +++ b/docs/index.rst
>> @@ -63,6 +63,7 @@ Xen hypervisor code.
>>    :maxdepth: 2
>> 
>>    misra/rules
>> +   misra/deviations
>> 
>> 
>> Miscellanea
>> diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
>> new file mode 100644
>> index 000000000000..19743e34ce03
>> --- /dev/null
>> +++ b/docs/misra/deviations.rst
>> @@ -0,0 +1,240 @@
>> +.. SPDX-License-Identifier: CC-BY-4.0
>> +
>> +MISRA C deviations for Xen
>> +==========================
>> +
>> +The following is the list of MISRA C:2012 deviations for the Xen codebase that
>> +are not covered by a `SAF-x-safe` or `SAF-x-false-positive-<tool>` comment, as
>> +specified in docs/misra/documenting-violations.rst; the lack of
>> +such comments is usually due to the excessive clutter they would bring to the
>> +codebase or the impossibility to express such a deviation (e.g., if it's
>> +composed of several conditions).
>> +
>> +Deviations related to MISRA C:2012 Directives:
>> +----------------------------------------------
>> +
>> +.. list-table::
>> +   :header-rows: 1
>> +
>> +   * - Directive identifier
>> +     - Justification
>> +     - Notes
>> +
>> +   * - D4.3
>> +     - Accepted for the ARM64 codebase
>> +     - Tagged as `disapplied` for ECLAIR on any other violation report.
> 
> This mean it has been applied for ARM64 but not x86, right?
> 
> 
>> +   * - D4.3
>> +     - The inline asm in 'xen/arch/arm/arm64/lib/bitops.c' is tightly coupled
>> +       with the surronding C code that acts as a wrapper, so it has been decided
>> +       not to add an additional encapsulation layer.
>> +     - Tagged as `deliberate` for ECLAIR.
>> +
>> +Deviations related to MISRA C:2012 Rules:
>> +-----------------------------------------
>> +
>> +.. list-table::
>> +   :header-rows: 1
>> +
>> +   * - Rule identifier
>> +     - Justification
>> +     - Notes
>> +
>> +   * - R2.1
>> +     - The compiler implementation guarantees that the unreachable code is
>> +       removed. Constant expressions and unreachable branches of if and switch
>> +       statements are expected.
>> +     - Tagged as `safe` for ECLAIR.
>> +
>> +   * - R2.1
>> +     - Some functions are intended not to be referenced.
>> +     - Tagged as `deliberate` for ECLAIR.
> 
> What does it mean "some functions" in this case? Should we list which
> functions?
> 
> Other than this, I checked and everything else looks great
>
Nicola Vetrini Oct. 10, 2023, 8:23 a.m. UTC | #3
On 10/10/2023 03:19, Stefano Stabellini wrote:
> +Henry
> 
> On Mon, 9 Oct 2023, Nicola Vetrini wrote:
>> This file contains the deviation that are not marked by
>> a deviation comment, as specified in
>> docs/misra/documenting-violations.rst.
>> 
>> Suggested-by: Stefano Stabellini <sstabellini@kernel.org>
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> 
> This is great! Thank you so much!
> 
> I have a few questions below but even as-is it is way better than
> nothing. I think we should add this for 4.18
> 
> 
>> ---
>>  docs/index.rst            |   1 +
>>  docs/misra/deviations.rst | 240 
>> ++++++++++++++++++++++++++++++++++++++
>>  docs/misra/rules.rst      |   2 +-
>>  3 files changed, 242 insertions(+), 1 deletion(-)
>>  create mode 100644 docs/misra/deviations.rst
>> 
>> diff --git a/docs/index.rst b/docs/index.rst
>> index 2c47cfa999f2..f3f779f89ce5 100644
>> --- a/docs/index.rst
>> +++ b/docs/index.rst
>> @@ -63,6 +63,7 @@ Xen hypervisor code.
>>     :maxdepth: 2
>> 
>>     misra/rules
>> +   misra/deviations
>> 
>> 
>>  Miscellanea
>> diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
>> new file mode 100644
>> index 000000000000..19743e34ce03
>> --- /dev/null
>> +++ b/docs/misra/deviations.rst
>> @@ -0,0 +1,240 @@
>> +.. SPDX-License-Identifier: CC-BY-4.0
>> +
>> +MISRA C deviations for Xen
>> +==========================
>> +
>> +The following is the list of MISRA C:2012 deviations for the Xen 
>> codebase that
>> +are not covered by a `SAF-x-safe` or `SAF-x-false-positive-<tool>` 
>> comment, as
>> +specified in docs/misra/documenting-violations.rst; the lack of
>> +such comments is usually due to the excessive clutter they would 
>> bring to the
>> +codebase or the impossibility to express such a deviation (e.g., if 
>> it's
>> +composed of several conditions).
>> +
>> +Deviations related to MISRA C:2012 Directives:
>> +----------------------------------------------
>> +
>> +.. list-table::
>> +   :header-rows: 1
>> +
>> +   * - Directive identifier
>> +     - Justification
>> +     - Notes
>> +
>> +   * - D4.3
>> +     - Accepted for the ARM64 codebase
>> +     - Tagged as `disapplied` for ECLAIR on any other violation 
>> report.
> 
> This mean it has been applied for ARM64 but not x86, right?
> 
> 

Yes.

>> +   * - D4.3
>> +     - The inline asm in 'xen/arch/arm/arm64/lib/bitops.c' is tightly 
>> coupled
>> +       with the surronding C code that acts as a wrapper, so it has 
>> been decided
>> +       not to add an additional encapsulation layer.
>> +     - Tagged as `deliberate` for ECLAIR.
>> +
>> +Deviations related to MISRA C:2012 Rules:
>> +-----------------------------------------
>> +
>> +.. list-table::
>> +   :header-rows: 1
>> +
>> +   * - Rule identifier
>> +     - Justification
>> +     - Notes
>> +
>> +   * - R2.1
>> +     - The compiler implementation guarantees that the unreachable 
>> code is
>> +       removed. Constant expressions and unreachable branches of if 
>> and switch
>> +       statements are expected.
>> +     - Tagged as `safe` for ECLAIR.
>> +
>> +   * - R2.1
>> +     - Some functions are intended not to be referenced.
>> +     - Tagged as `deliberate` for ECLAIR.
> 
> What does it mean "some functions" in this case? Should we list which
> functions?
> 

Well, there are a lot, typically resulting from build configurations 
that do not
use them, or because they are used only in asm code. I can mention these 
reasons in the
document, to make it easier to understand.

> Other than this, I checked and everything else looks great
Stefano Stabellini Oct. 10, 2023, 10:27 p.m. UTC | #4
On Tue, 10 Oct 2023, Nicola Vetrini wrote:
> On 10/10/2023 03:19, Stefano Stabellini wrote:
> > +Henry
> > 
> > On Mon, 9 Oct 2023, Nicola Vetrini wrote:
> > > This file contains the deviation that are not marked by
> > > a deviation comment, as specified in
> > > docs/misra/documenting-violations.rst.
> > > 
> > > Suggested-by: Stefano Stabellini <sstabellini@kernel.org>
> > > Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> > 
> > This is great! Thank you so much!
> > 
> > I have a few questions below but even as-is it is way better than
> > nothing. I think we should add this for 4.18
> > 
> > 
> > > ---
> > >  docs/index.rst            |   1 +
> > >  docs/misra/deviations.rst | 240 ++++++++++++++++++++++++++++++++++++++
> > >  docs/misra/rules.rst      |   2 +-
> > >  3 files changed, 242 insertions(+), 1 deletion(-)
> > >  create mode 100644 docs/misra/deviations.rst
> > > 
> > > diff --git a/docs/index.rst b/docs/index.rst
> > > index 2c47cfa999f2..f3f779f89ce5 100644
> > > --- a/docs/index.rst
> > > +++ b/docs/index.rst
> > > @@ -63,6 +63,7 @@ Xen hypervisor code.
> > >     :maxdepth: 2
> > > 
> > >     misra/rules
> > > +   misra/deviations
> > > 
> > > 
> > >  Miscellanea
> > > diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
> > > new file mode 100644
> > > index 000000000000..19743e34ce03
> > > --- /dev/null
> > > +++ b/docs/misra/deviations.rst
> > > @@ -0,0 +1,240 @@
> > > +.. SPDX-License-Identifier: CC-BY-4.0
> > > +
> > > +MISRA C deviations for Xen
> > > +==========================
> > > +
> > > +The following is the list of MISRA C:2012 deviations for the Xen codebase
> > > that
> > > +are not covered by a `SAF-x-safe` or `SAF-x-false-positive-<tool>`
> > > comment, as
> > > +specified in docs/misra/documenting-violations.rst; the lack of
> > > +such comments is usually due to the excessive clutter they would bring to
> > > the
> > > +codebase or the impossibility to express such a deviation (e.g., if it's
> > > +composed of several conditions).
> > > +
> > > +Deviations related to MISRA C:2012 Directives:
> > > +----------------------------------------------
> > > +
> > > +.. list-table::
> > > +   :header-rows: 1
> > > +
> > > +   * - Directive identifier
> > > +     - Justification
> > > +     - Notes
> > > +
> > > +   * - D4.3
> > > +     - Accepted for the ARM64 codebase
> > > +     - Tagged as `disapplied` for ECLAIR on any other violation report.
> > 
> > This mean it has been applied for ARM64 but not x86, right?
> > 
> > 
> 
> Yes.
> 
> > > +   * - D4.3
> > > +     - The inline asm in 'xen/arch/arm/arm64/lib/bitops.c' is tightly
> > > coupled
> > > +       with the surronding C code that acts as a wrapper, so it has been
> > > decided
> > > +       not to add an additional encapsulation layer.
> > > +     - Tagged as `deliberate` for ECLAIR.
> > > +
> > > +Deviations related to MISRA C:2012 Rules:
> > > +-----------------------------------------
> > > +
> > > +.. list-table::
> > > +   :header-rows: 1
> > > +
> > > +   * - Rule identifier
> > > +     - Justification
> > > +     - Notes
> > > +
> > > +   * - R2.1
> > > +     - The compiler implementation guarantees that the unreachable code
> > > is
> > > +       removed. Constant expressions and unreachable branches of if and
> > > switch
> > > +       statements are expected.
> > > +     - Tagged as `safe` for ECLAIR.
> > > +
> > > +   * - R2.1
> > > +     - Some functions are intended not to be referenced.
> > > +     - Tagged as `deliberate` for ECLAIR.
> > 
> > What does it mean "some functions" in this case? Should we list which
> > functions?
> > 
> 
> Well, there are a lot, typically resulting from build configurations that do
> not
> use them, or because they are used only in asm code. I can mention these
> reasons in the
> document, to make it easier to understand.

Yes, I think we need to clarify further this point, because saying "Some
functions" doesn't help the reader understand:
- whether all functions can be not referenced
- which subset of functions can be not referenced

How to distinguish between? How do we know whether a certain patch is
violating the rule or not?

If there is a clear list of functions that can be not referenced, then
we should list them here. If there is a methodology we can use to
distinguish between them (e.g. functions called from asm only) then we
can write the methodology here. Either way it is fine as long as the
criteria to know if it is OK if a function is not referenced is clear.
Julien Grall Oct. 11, 2023, 1:04 p.m. UTC | #5
Hi,

On 10/10/2023 23:27, Stefano Stabellini wrote:
> On Tue, 10 Oct 2023, Nicola Vetrini wrote:
>> On 10/10/2023 03:19, Stefano Stabellini wrote:
>>> +Henry
>>>
>>> On Mon, 9 Oct 2023, Nicola Vetrini wrote:
>>>> This file contains the deviation that are not marked by
>>>> a deviation comment, as specified in
>>>> docs/misra/documenting-violations.rst.
>>>>
>>>> Suggested-by: Stefano Stabellini <sstabellini@kernel.org>
>>>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>>>
>>> This is great! Thank you so much!
>>>
>>> I have a few questions below but even as-is it is way better than
>>> nothing. I think we should add this for 4.18
>>>
>>>
>>>> ---
>>>>   docs/index.rst            |   1 +
>>>>   docs/misra/deviations.rst | 240 ++++++++++++++++++++++++++++++++++++++
>>>>   docs/misra/rules.rst      |   2 +-
>>>>   3 files changed, 242 insertions(+), 1 deletion(-)
>>>>   create mode 100644 docs/misra/deviations.rst
>>>>
>>>> diff --git a/docs/index.rst b/docs/index.rst
>>>> index 2c47cfa999f2..f3f779f89ce5 100644
>>>> --- a/docs/index.rst
>>>> +++ b/docs/index.rst
>>>> @@ -63,6 +63,7 @@ Xen hypervisor code.
>>>>      :maxdepth: 2
>>>>
>>>>      misra/rules
>>>> +   misra/deviations
>>>>
>>>>
>>>>   Miscellanea
>>>> diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
>>>> new file mode 100644
>>>> index 000000000000..19743e34ce03
>>>> --- /dev/null
>>>> +++ b/docs/misra/deviations.rst
>>>> @@ -0,0 +1,240 @@
>>>> +.. SPDX-License-Identifier: CC-BY-4.0
>>>> +
>>>> +MISRA C deviations for Xen
>>>> +==========================
>>>> +
>>>> +The following is the list of MISRA C:2012 deviations for the Xen codebase
>>>> that
>>>> +are not covered by a `SAF-x-safe` or `SAF-x-false-positive-<tool>`
>>>> comment, as
>>>> +specified in docs/misra/documenting-violations.rst; the lack of
>>>> +such comments is usually due to the excessive clutter they would bring to
>>>> the
>>>> +codebase or the impossibility to express such a deviation (e.g., if it's
>>>> +composed of several conditions).
>>>> +
>>>> +Deviations related to MISRA C:2012 Directives:
>>>> +----------------------------------------------
>>>> +
>>>> +.. list-table::
>>>> +   :header-rows: 1
>>>> +
>>>> +   * - Directive identifier
>>>> +     - Justification
>>>> +     - Notes
>>>> +
>>>> +   * - D4.3
>>>> +     - Accepted for the ARM64 codebase
>>>> +     - Tagged as `disapplied` for ECLAIR on any other violation report.
>>>
>>> This mean it has been applied for ARM64 but not x86, right?
>>>
>>>
>>
>> Yes.
>>
>>>> +   * - D4.3
>>>> +     - The inline asm in 'xen/arch/arm/arm64/lib/bitops.c' is tightly
>>>> coupled
>>>> +       with the surronding C code that acts as a wrapper, so it has been
>>>> decided
>>>> +       not to add an additional encapsulation layer.
>>>> +     - Tagged as `deliberate` for ECLAIR.
>>>> +
>>>> +Deviations related to MISRA C:2012 Rules:
>>>> +-----------------------------------------
>>>> +
>>>> +.. list-table::
>>>> +   :header-rows: 1
>>>> +
>>>> +   * - Rule identifier
>>>> +     - Justification
>>>> +     - Notes
>>>> +
>>>> +   * - R2.1
>>>> +     - The compiler implementation guarantees that the unreachable code
>>>> is
>>>> +       removed. Constant expressions and unreachable branches of if and
>>>> switch
>>>> +       statements are expected.
>>>> +     - Tagged as `safe` for ECLAIR.
>>>> +
>>>> +   * - R2.1
>>>> +     - Some functions are intended not to be referenced.
>>>> +     - Tagged as `deliberate` for ECLAIR.
>>>
>>> What does it mean "some functions" in this case? Should we list which
>>> functions?
>>>
>>
>> Well, there are a lot, typically resulting from build configurations that do
>> not
>> use them, or because they are used only in asm code. I can mention these
>> reasons in the
>> document, to make it easier to understand.
> 
> Yes, I think we need to clarify further this point, because saying "Some
> functions" doesn't help the reader understand:
> - whether all functions can be not referenced
> - which subset of functions can be not referenced
> 
> How to distinguish between? How do we know whether a certain patch is
> violating the rule or not?
> 
> If there is a clear list of functions that can be not referenced, then
> we should list them here. If there is a methodology we can use to
> distinguish between them (e.g. functions called from asm only) then we
> can write the methodology here. Either way it is fine as long as the
> criteria to know if it is OK if a function is not referenced is clear.

Aren't they more or less the one we tagged with SAF-1-safe because there 
were no prototype? If so, we could use the same tags.

We could introduce an extra tags for the others. An alternative would be 
to add an attribute (e.g. asmcall) to mark each function used by assembly.

Cheers,
Nicola Vetrini Oct. 11, 2023, 3 p.m. UTC | #6
>>>>> +
>>>>> +   * - R2.1
>>>>> +     - The compiler implementation guarantees that the unreachable 
>>>>> code
>>>>> is
>>>>> +       removed. Constant expressions and unreachable branches of 
>>>>> if and
>>>>> switch
>>>>> +       statements are expected.
>>>>> +     - Tagged as `safe` for ECLAIR.
>>>>> +
>>>>> +   * - R2.1
>>>>> +     - Some functions are intended not to be referenced.
>>>>> +     - Tagged as `deliberate` for ECLAIR.
>>>> 
>>>> What does it mean "some functions" in this case? Should we list 
>>>> which
>>>> functions?
>>>> 
>>> 
>>> Well, there are a lot, typically resulting from build configurations 
>>> that do
>>> not
>>> use them, or because they are used only in asm code. I can mention 
>>> these
>>> reasons in the
>>> document, to make it easier to understand.
>> 
>> Yes, I think we need to clarify further this point, because saying 
>> "Some
>> functions" doesn't help the reader understand:
>> - whether all functions can be not referenced
>> - which subset of functions can be not referenced
>> 
>> How to distinguish between? How do we know whether a certain patch is
>> violating the rule or not?
>> 
>> If there is a clear list of functions that can be not referenced, then
>> we should list them here. If there is a methodology we can use to
>> distinguish between them (e.g. functions called from asm only) then we
>> can write the methodology here. Either way it is fine as long as the
>> criteria to know if it is OK if a function is not referenced is clear.
> 
> Aren't they more or less the one we tagged with SAF-1-safe because
> there were no prototype? If so, we could use the same tags.
> 
> We could introduce an extra tags for the others. An alternative would
> be to add an attribute (e.g. asmcall) to mark each function used by
> assembly.
> 
> Cheers,

Both suggestion do have some value. As it is, it's not distinguishable 
what causes a
function to be unreferenced in a certain analysis config. However:

- functions only used by asm code can be specified in the ECLAIR config 
so that they will
   have an extra fake reference as far as the checker is concerned. I can 
do that on a
   separate patch and list them in deviations.rst. An attribute seems a 
good way to signal the
   intention.
- Functions that have no reference only in the current analysis should 
have their declaration
   #ifdef-ed out in the configurations where they are not used, in an 
ideal world.
- Truly unreferenced functions should be removed, or justified
Nicola Vetrini Oct. 11, 2023, 3:04 p.m. UTC | #7
On 11/10/2023 17:00, Nicola Vetrini wrote:
>>>>>> +
>>>>>> +   * - R2.1
>>>>>> +     - The compiler implementation guarantees that the 
>>>>>> unreachable code
>>>>>> is
>>>>>> +       removed. Constant expressions and unreachable branches of 
>>>>>> if and
>>>>>> switch
>>>>>> +       statements are expected.
>>>>>> +     - Tagged as `safe` for ECLAIR.
>>>>>> +
>>>>>> +   * - R2.1
>>>>>> +     - Some functions are intended not to be referenced.
>>>>>> +     - Tagged as `deliberate` for ECLAIR.
>>>>> 
>>>>> What does it mean "some functions" in this case? Should we list 
>>>>> which
>>>>> functions?
>>>>> 
>>>> 
>>>> Well, there are a lot, typically resulting from build configurations 
>>>> that do
>>>> not
>>>> use them, or because they are used only in asm code. I can mention 
>>>> these
>>>> reasons in the
>>>> document, to make it easier to understand.
>>> 
>>> Yes, I think we need to clarify further this point, because saying 
>>> "Some
>>> functions" doesn't help the reader understand:
>>> - whether all functions can be not referenced
>>> - which subset of functions can be not referenced
>>> 
>>> How to distinguish between? How do we know whether a certain patch is
>>> violating the rule or not?
>>> 
>>> If there is a clear list of functions that can be not referenced, 
>>> then
>>> we should list them here. If there is a methodology we can use to
>>> distinguish between them (e.g. functions called from asm only) then 
>>> we
>>> can write the methodology here. Either way it is fine as long as the
>>> criteria to know if it is OK if a function is not referenced is 
>>> clear.
>> 
>> Aren't they more or less the one we tagged with SAF-1-safe because
>> there were no prototype? If so, we could use the same tags.
>> 
>> We could introduce an extra tags for the others. An alternative would
>> be to add an attribute (e.g. asmcall) to mark each function used by
>> assembly.
>> 
>> Cheers,
> 
> Both suggestion do have some value. As it is, it's not distinguishable
> what causes a
> function to be unreferenced in a certain analysis config. However:
> 
> - functions only used by asm code can be specified in the ECLAIR
> config so that they will
>   have an extra fake reference as far as the checker is concerned. I
> can do that on a
>   separate patch and list them in deviations.rst. An attribute seems a
> good way to signal the
>   intention.
> - Functions that have no reference only in the current analysis should
> have their declaration
>   #ifdef-ed out in the configurations where they are not used, in an
> ideal world.
> - Truly unreferenced functions should be removed, or justified

Especially the last two appear somewhat tricky to disentangle, as they 
do require knowledge of
possible code paths.
Nicola Vetrini Oct. 11, 2023, 4:04 p.m. UTC | #8
Attached is a list of all the unreferenced functions for x86. It's a bit 
rough and does not
distinguish the categories mentioned in my previous reply, but it's a 
starting point for any
further work on this.
Stefano Stabellini Oct. 12, 2023, 11:14 p.m. UTC | #9
On Wed, 11 Oct 2023, Nicola Vetrini wrote:
> On 11/10/2023 17:00, Nicola Vetrini wrote:
> > > > > > > +
> > > > > > > +   * - R2.1
> > > > > > > +     - The compiler implementation guarantees that the
> > > > > > > unreachable code
> > > > > > > is
> > > > > > > +       removed. Constant expressions and unreachable branches of
> > > > > > > if and
> > > > > > > switch
> > > > > > > +       statements are expected.
> > > > > > > +     - Tagged as `safe` for ECLAIR.
> > > > > > > +
> > > > > > > +   * - R2.1
> > > > > > > +     - Some functions are intended not to be referenced.
> > > > > > > +     - Tagged as `deliberate` for ECLAIR.
> > > > > > 
> > > > > > What does it mean "some functions" in this case? Should we list
> > > > > > which
> > > > > > functions?
> > > > > > 
> > > > > 
> > > > > Well, there are a lot, typically resulting from build configurations
> > > > > that do
> > > > > not
> > > > > use them, or because they are used only in asm code. I can mention
> > > > > these
> > > > > reasons in the
> > > > > document, to make it easier to understand.
> > > > 
> > > > Yes, I think we need to clarify further this point, because saying "Some
> > > > functions" doesn't help the reader understand:
> > > > - whether all functions can be not referenced
> > > > - which subset of functions can be not referenced
> > > > 
> > > > How to distinguish between? How do we know whether a certain patch is
> > > > violating the rule or not?
> > > > 
> > > > If there is a clear list of functions that can be not referenced, then
> > > > we should list them here. If there is a methodology we can use to
> > > > distinguish between them (e.g. functions called from asm only) then we
> > > > can write the methodology here. Either way it is fine as long as the
> > > > criteria to know if it is OK if a function is not referenced is clear.
> > > 
> > > Aren't they more or less the one we tagged with SAF-1-safe because
> > > there were no prototype? If so, we could use the same tags.
> > > 
> > > We could introduce an extra tags for the others. An alternative would
> > > be to add an attribute (e.g. asmcall) to mark each function used by
> > > assembly.
> > > 
> > > Cheers,
> > 
> > Both suggestion do have some value. As it is, it's not distinguishable
> > what causes a
> > function to be unreferenced in a certain analysis config. However:
> > 
> > - functions only used by asm code can be specified in the ECLAIR
> > config so that they will
> >   have an extra fake reference as far as the checker is concerned. I
> > can do that on a
> >   separate patch and list them in deviations.rst. An attribute seems a
> > good way to signal the
> >   intention.
> > - Functions that have no reference only in the current analysis should
> > have their declaration
> >   #ifdef-ed out in the configurations where they are not used, in an
> > ideal world.
> > - Truly unreferenced functions should be removed, or justified
> 
> Especially the last two appear somewhat tricky to disentangle, as they do
> require knowledge of
> possible code paths.

First let me premise that if we are unsure on how to proceed on this you
can resend this patch series without this item ("Some functions are
intended not to be referenced"), so at least the rest can go in now.

On this specific point, I think we should only make clear and
unmistakable statements. For instance, I think it is OK to say that all
the functions only used by asm code are exceptions (ideally they would
have a asmcall tag as Julien suggested) because that is deterministic.

Functions that have no references in a specific kconfig configuration
should have their definition #ifdef'ed (not necessarily the
declaration, I think we have already clarified that it is OK to have a
declaration without definition.) 

Truly unreferenced functions should be removed.

In conclusion, I think we should only have "functions only called from
asm code" as a deviation here.
Nicola Vetrini Oct. 13, 2023, 8:26 a.m. UTC | #10
On 13/10/2023 01:14, Stefano Stabellini wrote:
> On Wed, 11 Oct 2023, Nicola Vetrini wrote:
>> On 11/10/2023 17:00, Nicola Vetrini wrote:
>> > > > > > > +
>> > > > > > > +   * - R2.1
>> > > > > > > +     - The compiler implementation guarantees that the
>> > > > > > > unreachable code
>> > > > > > > is
>> > > > > > > +       removed. Constant expressions and unreachable branches of
>> > > > > > > if and
>> > > > > > > switch
>> > > > > > > +       statements are expected.
>> > > > > > > +     - Tagged as `safe` for ECLAIR.
>> > > > > > > +
>> > > > > > > +   * - R2.1
>> > > > > > > +     - Some functions are intended not to be referenced.
>> > > > > > > +     - Tagged as `deliberate` for ECLAIR.
>> > > > > >
>> > > > > > What does it mean "some functions" in this case? Should we list
>> > > > > > which
>> > > > > > functions?
>> > > > > >
>> > > > >
>> > > > > Well, there are a lot, typically resulting from build configurations
>> > > > > that do
>> > > > > not
>> > > > > use them, or because they are used only in asm code. I can mention
>> > > > > these
>> > > > > reasons in the
>> > > > > document, to make it easier to understand.
>> > > >
>> > > > Yes, I think we need to clarify further this point, because saying "Some
>> > > > functions" doesn't help the reader understand:
>> > > > - whether all functions can be not referenced
>> > > > - which subset of functions can be not referenced
>> > > >
>> > > > How to distinguish between? How do we know whether a certain patch is
>> > > > violating the rule or not?
>> > > >
>> > > > If there is a clear list of functions that can be not referenced, then
>> > > > we should list them here. If there is a methodology we can use to
>> > > > distinguish between them (e.g. functions called from asm only) then we
>> > > > can write the methodology here. Either way it is fine as long as the
>> > > > criteria to know if it is OK if a function is not referenced is clear.
>> > >
>> > > Aren't they more or less the one we tagged with SAF-1-safe because
>> > > there were no prototype? If so, we could use the same tags.
>> > >
>> > > We could introduce an extra tags for the others. An alternative would
>> > > be to add an attribute (e.g. asmcall) to mark each function used by
>> > > assembly.
>> > >
>> > > Cheers,
>> >
>> > Both suggestion do have some value. As it is, it's not distinguishable
>> > what causes a
>> > function to be unreferenced in a certain analysis config. However:
>> >
>> > - functions only used by asm code can be specified in the ECLAIR
>> > config so that they will
>> >   have an extra fake reference as far as the checker is concerned. I
>> > can do that on a
>> >   separate patch and list them in deviations.rst. An attribute seems a
>> > good way to signal the
>> >   intention.
>> > - Functions that have no reference only in the current analysis should
>> > have their declaration
>> >   #ifdef-ed out in the configurations where they are not used, in an
>> > ideal world.
>> > - Truly unreferenced functions should be removed, or justified
>> 
>> Especially the last two appear somewhat tricky to disentangle, as they 
>> do
>> require knowledge of
>> possible code paths.
> 
> First let me premise that if we are unsure on how to proceed on this 
> you
> can resend this patch series without this item ("Some functions are
> intended not to be referenced"), so at least the rest can go in now.
> 
> On this specific point, I think we should only make clear and
> unmistakable statements. For instance, I think it is OK to say that all
> the functions only used by asm code are exceptions (ideally they would
> have a asmcall tag as Julien suggested) because that is deterministic.
> 
> Functions that have no references in a specific kconfig configuration
> should have their definition #ifdef'ed (not necessarily the
> declaration, I think we have already clarified that it is OK to have a
> declaration without definition.)
> 
> Truly unreferenced functions should be removed.
> 
> In conclusion, I think we should only have "functions only called from
> asm code" as a deviation here.

I agree on leaving this out of the patch for now.
diff mbox series

Patch

diff --git a/docs/index.rst b/docs/index.rst
index 2c47cfa999f2..f3f779f89ce5 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -63,6 +63,7 @@  Xen hypervisor code.
    :maxdepth: 2

    misra/rules
+   misra/deviations


 Miscellanea
diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
new file mode 100644
index 000000000000..19743e34ce03
--- /dev/null
+++ b/docs/misra/deviations.rst
@@ -0,0 +1,240 @@ 
+.. SPDX-License-Identifier: CC-BY-4.0
+
+MISRA C deviations for Xen
+==========================
+
+The following is the list of MISRA C:2012 deviations for the Xen codebase that
+are not covered by a `SAF-x-safe` or `SAF-x-false-positive-<tool>` comment, as
+specified in docs/misra/documenting-violations.rst; the lack of
+such comments is usually due to the excessive clutter they would bring to the
+codebase or the impossibility to express such a deviation (e.g., if it's
+composed of several conditions).
+
+Deviations related to MISRA C:2012 Directives:
+----------------------------------------------
+
+.. list-table::
+   :header-rows: 1
+
+   * - Directive identifier
+     - Justification
+     - Notes
+
+   * - D4.3
+     - Accepted for the ARM64 codebase
+     - Tagged as `disapplied` for ECLAIR on any other violation report.
+
+   * - D4.3
+     - The inline asm in 'xen/arch/arm/arm64/lib/bitops.c' is tightly coupled
+       with the surronding C code that acts as a wrapper, so it has been decided
+       not to add an additional encapsulation layer.
+     - Tagged as `deliberate` for ECLAIR.
+
+Deviations related to MISRA C:2012 Rules:
+-----------------------------------------
+
+.. list-table::
+   :header-rows: 1
+
+   * - Rule identifier
+     - Justification
+     - Notes
+
+   * - R2.1
+     - The compiler implementation guarantees that the unreachable code is
+       removed. Constant expressions and unreachable branches of if and switch
+       statements are expected.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R2.1
+     - Some functions are intended not to be referenced.
+     - Tagged as `deliberate` for ECLAIR.
+
+   * - R2.1
+     - Unreachability caused by calls to the following functions or macros is
+       deliberate and there is no risk of code being unexpectedly left out.
+     - Tagged as `deliberate` for ECLAIR. Such macros are:
+			 - BUG
+			 - assert_failed
+			 - __builtin_unreachable
+			 - ASSERT_UNREACHABLE
+
+   * - R2.1
+     - Pure declarations, that is, declarations without initializations are not
+       executable, and therefore it is safe for them to be unreachable. The most
+       notable example of such a pattern being used in the codebase is that of
+       a variable declaration that should be available in all the clauses of a
+       switch statement.
+     - ECLAIR has been configured to ignore those statements.
+
+   * - R2.2
+     - Proving compliance with respect to Rule 2.2 is generally impossible:
+       see `<https://arxiv.org/abs/2212.13933>`_ for details. Moreover, peer
+       review gives us confidence that no evidence of errors in the program's
+       logic has been missed due to undetected violations of Rule 2.2, if any.
+       Testing on time behavior gives us confidence on the fact that, should the
+       program contain dead code that is not removed by the compiler, the
+       resulting slowdown is negligible.
+     - Project-wide deviation, tagged as `disapplied` for ECLAIR.
+
+   * - R3.1
+     - Comments starting with '/\*' and containing hyperlinks are safe as they
+       are not instances of commented-out code.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R5.3
+     - As specified in rules.rst, shadowing due to macros being used as macro
+       arguments is allowed, as it's deemed not at risk of causing developer
+       confusion.
+     - Tagged as `safe` for ECLAIR. So far, the following macros are deviated:
+         - READ_SYSREG and WRITE_SYSREG
+         - max_{t}? and min_{t}?
+         - read_[bwlq] and read_[bwlq]_relaxed
+         - per_cpu and this_cpu
+         - __emulate_2op and __emulate_2op_nobyte
+         - read_debugreg and write_debugreg
+
+   * - R7.2
+     - Violations caused by __HYPERVISOR_VIRT_START are related to the
+       particular use of it done in xen_mk_ulong.
+     - Tagged as `deliberate` for ECLAIR.
+
+   * - R7.4
+     - Allow pointers of non-character type as long as the pointee is
+       const-qualified.
+     - ECLAIR has been configured to ignore these assignments.
+
+   * - R8.3
+     - The type ret_t is deliberately used and defined as int or long depending
+       on the architecture.
+     - Tagged as `deliberate` for ECLAIR.
+
+   * - R8.3
+     - Some files are not subject to respect MISRA rules at
+       the moment, but some entity from a file in scope is used; therefore
+       ECLAIR does report a violation, since not all the files involved in the
+       violation are excluded from the analysis.
+     - Tagged as `deliberate` for ECLAIR. Such excluded files are:
+         - xen/arch/x86/time.c
+         - xen/arch/x86/acpi/cpu_idle.c
+         - xen/arch/x86/mpparse.c
+         - xen/common/bunzip2.c
+         - xen/common/unlz4.c
+         - xen/common/unlzma.c
+         - xen/common/unlzo.c
+         - xen/common/unxz.c
+         - xen/common/unzstd.c
+
+   * - R8.4
+     - The definitions present in the files 'asm-offsets.c' for any architecture
+       are used to generate definitions for asm modules, and are not called by
+       C code. Therefore the absence of prior declarations is safe.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R8.4
+     - The functions defined in the file xen/common/coverage/gcov_base.c are
+       meant to be called from gcc-generated code in a non-release build
+       configuration. Therefore, the absence of prior declarations is safe.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R8.6
+     - The following variables are compiled in multiple translation units
+       belonging to different executables and therefore are safe.
+
+       - current_stack_pointer
+       - bsearch
+       - sort
+     - Tagged as `safe` for ECLAIR.
+
+   * - R8.6
+     - Declarations without definitions are allowed (specifically when the
+       definition is compiled-out or optimized-out by the compiler).
+     - Tagged as `deliberate` in ECLAIR.
+
+   * - R8.10
+     - The gnu_inline attribute without static is deliberately allowed.
+     - Tagged as `deliberate` for ECLAIR.
+
+   * - R9.5
+     - The possibility of committing mistakes by specifying an explicit
+       dimension is higher than omitting the dimension, therefore all such
+       instances of violations are deviated.
+     - Project-wide deviation, tagged as `deliberate` for ECLAIR.
+
+   * - R10.1, R10.3, R10.4
+     - The value-preserving conversions of integer constants are safe.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R10.1
+     - Shifting non-negative integers to the right is safe.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R10.1
+     - Shifting non-negative integers to the left is safe if the result is still
+       non-negative.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R10.1
+     - Bitwise logical operations on non-negative integers are safe.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R10.1
+     - The implicit conversion to Boolean for logical operator arguments is
+       well-known to all Xen developers to be a comparison with 0.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R10.1
+     - Xen only supports architectures where signed integers are representend
+       using two's complement and all the Xen developers are aware of this. For
+       this reason, bitwise operations are safe.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R10.1
+     - Given the assumptions on the toolchain detailed in
+       docs/misra/C-language-toolchain.rst and the build flags used by the
+       project, it is deemed safe to use bitwise shift operators.
+       See automation/eclair_analysis/deviations.ecl for the full explanation.
+     - Tagged as `safe` for ECLAIR.
+
+   * - R13.5
+     - All developers and reviewers can be safely assumed to be well aware of
+       the short-circuit evaluation strategy for logical operators.
+     - Project-wide deviation; tagged as `disapplied` for ECLAIR.
+
+   * - R14.2
+     - The severe restrictions imposed by this rule on the use of 'for'
+       statements are not counterbalanced by the presumed facilitation of the
+       peer review activity.
+     - Project-wide deviation; tagged as `disapplied` for ECLAIR.
+
+   * - R14.3
+     - The Xen team relies on the fact that invariant conditions of 'if'
+       statements are deliberate.
+     - Project-wide deviation; tagged as `disapplied` for ECLAIR.
+
+   * - R20.7
+     - Code violating Rule 20.7 is safe when macro parameters are used:
+       (1) as function arguments;
+       (2) as macro arguments;
+       (3) as array indices;
+       (4) as lhs in assignments.
+     - Tagged as `safe` for ECLAIR.
+
+Other deviations:
+-----------------
+
+.. list-table::
+   :header-rows: 1
+
+   * - Deviation
+     - Justification
+
+   * - do-while-0 loops
+     - The do-while-0 is a well-recognized loop idiom used by the Xen community
+       and can therefore be used, even though it would cause a number of
+       violations in some instances.
+
+   * - while-0 and while-1 loops
+     - while-0 and while-1 are well-recognized loop idioms used by the Xen
+       community and can therefore be used, even though they would cause a
+       number of violations in some instances.
diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst
index 3139ca7ae6dd..6efe66195de3 100644
--- a/docs/misra/rules.rst
+++ b/docs/misra/rules.rst
@@ -18,7 +18,7 @@  It is possible that in specific circumstances it is best not to follow a
 rule because it is not possible or because the alternative leads to
 better code quality. Those cases are called "deviations". They are
 permissible as long as they are documented. For details, please refer to
-docs/misra/documenting-violations.rst
+docs/misra/documenting-violations.rst and docs/misra/deviations.rst

 Other documentation mechanisms are work-in-progress.