From: Jan Beulich <jbeulich@suse.com>
To: Roberto Bagnara <roberto.bagnara@bugseng.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>, "Wei Liu" <wl@xen.org>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Julien Grall" <julien@xen.org>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
"Bertrand Marquis" <bertrand.marquis@arm.com>,
Xen-devel <xen-devel@lists.xenproject.org>,
"Andrew Cooper" <andrew.cooper3@citrix.com>
Subject: Re: [PATCH 1/3] x86/p2m.h: Add include guards
Date: Wed, 18 May 2022 08:26:04 +0200 [thread overview]
Message-ID: <c655c9c1-2d16-6358-38cc-df860341cee9@suse.com> (raw)
In-Reply-To: <e6e6c211-3915-af72-d077-0bf77b6a6a9e@bugseng.com>
On 17.05.2022 20:42, Roberto Bagnara wrote:
> On 17/05/22 17:38, Jan Beulich wrote:
>> On 09.05.2022 14:24, Andrew Cooper wrote:
>>> Spotted by Eclair MISRA scanner.
>>
>> I'm sorry, but what exactly was it that the scanner spotted? It was
>> actually deliberate to introduce this file without guards. I'm of
>> the general opinion that (private) headers not to be included by
>> other headers (but only by .c files) are not in need of guards. If
>> it is project-wide consensus that _all_ header files should have
>> guards, then I'll try to keep this in mind (in "x86emul: a few
>> small steps towards disintegration" for example I introduce
>> another such instance), but then it should also be put down in
>> ./CODING_STYLE.
>
> The rationale of this rule is as follows:
>
> - With a complex hierarchy of nested header files, it is possible
> for a header file to be included more than once.
>
> - This can bring to circular references of header files, which
> can result in undefined behavior and/or be difficult to debug.
This, in particular, is known to happen in our and other source
bases despite the use of guards, hence I view this point as at
best partly related. Nevertheless I agree with and understand the
reasons for using guards _where they are needed_. I do not agree
that guards need to be there for no specific reason.
Jan
> - If multiple inclusion leads to multiple or conflicting definitions,
> then this can result in undefined or erroneous behavior.
>
> - Compilation and analysis time is needlessly increased.
>
> There has been a period (which lasted until the end of the '70s
> or the beginning of the '80s, I would have to dig up to be
> more precise) when the solution was thought to be "headers
> shall not to be included by other headers but only by .c files."
> Experience then showed that, in medium to large projects,
> each .c file had to begin with a long list of #include
> directives; such lists needed to be ordered to accommodate
> the dependencies between header files; in some cases the
> lists were so long that:
>
> a) it was a kind of black magic to find out the right
> inclusion order, one that would work in any of
> possibly many project configurations;
> b) the lists of #include directives often contained duplicates,
> possibly because the desperate programmers where trying
> to find the right order.
>
> In the end, the software engineering community converged
> on the idea that guards against multiple inclusion are
> a much better alternative.
>
> Of course there are valid reasons to deviate the rule:
> some header files might be conceived to be included
> multiple times. A one-line configuration for ECLAIR
> will do the trick to make sure such header files are
> not reported.
>
> Kind regards,
>
> Roberto
>
>>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>>> ---
>>> CC: Jan Beulich <JBeulich@suse.com>
>>> CC: Roger Pau Monné <roger.pau@citrix.com>
>>> CC: Wei Liu <wl@xen.org>
>>> CC: Stefano Stabellini <sstabellini@kernel.org>
>>> CC: Julien Grall <julien@xen.org>
>>> CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
>>> CC: Bertrand Marquis <bertrand.marquis@arm.com>
>>> ---
>>> xen/arch/x86/mm/p2m.h | 5 +++++
>>> 1 file changed, 5 insertions(+)
>>>
>>> diff --git a/xen/arch/x86/mm/p2m.h b/xen/arch/x86/mm/p2m.h
>>> index cc0f6766e4df..dc706b8e4799 100644
>>> --- a/xen/arch/x86/mm/p2m.h
>>> +++ b/xen/arch/x86/mm/p2m.h
>>> @@ -15,6 +15,9 @@
>>> * along with this program; If not, see <http://www.gnu.org/licenses/>.
>>> */
>>>
>>> +#ifndef __ARCH_MM_P2M_H__
>>> +#define __ARCH_MM_P2M_H__
>>> +
>>> struct p2m_domain *p2m_init_one(struct domain *d);
>>> void p2m_free_one(struct p2m_domain *p2m);
>>>
>>> @@ -39,6 +42,8 @@ int ept_p2m_init(struct p2m_domain *p2m);
>>> void ept_p2m_uninit(struct p2m_domain *p2m);
>>> void p2m_init_altp2m_ept(struct domain *d, unsigned int i);
>>>
>>> +#endif /* __ARCH_MM_P2M_H__ */
>>> +
>>> /*
>>> * Local variables:
>>> * mode: C
>>
>>
>
next prev parent reply other threads:[~2022-05-18 6:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-09 12:24 [PATCH 0/3] xen: Trivial MISRA fixes Andrew Cooper
2022-05-09 12:24 ` [PATCH 1/3] x86/p2m.h: Add include guards Andrew Cooper
2022-05-09 12:32 ` Bertrand Marquis
2022-05-09 13:18 ` Roger Pau Monné
2022-05-09 13:23 ` Andrew Cooper
2022-05-17 15:38 ` Jan Beulich
2022-05-17 18:42 ` Roberto Bagnara
2022-05-18 6:26 ` Jan Beulich [this message]
2022-05-09 12:24 ` [PATCH 2/3] x86/shadow: Don't use signed bitfield in sh_emulate_ctxt Andrew Cooper
2022-05-09 12:40 ` Bertrand Marquis
2022-05-09 13:19 ` Roger Pau Monné
2022-05-09 12:24 ` [PATCH 3/3] common/spinlock: Drop inline from _spin_lock_cb() Andrew Cooper
2022-05-09 12:34 ` Bertrand Marquis
2022-05-09 13:53 ` Roger Pau Monné
2022-05-17 15:42 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c655c9c1-2d16-6358-38cc-df860341cee9@suse.com \
--to=jbeulich@suse.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=bertrand.marquis@arm.com \
--cc=julien@xen.org \
--cc=roberto.bagnara@bugseng.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.