xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Bertrand Marquis <Bertrand.Marquis@arm.com>
To: Julien Grall <julien@xen.org>
Cc: "Jan Beulich" <jbeulich@suse.com>,
	Xen-devel <xen-devel@lists.xenproject.org>,
	"Julien Grall" <jgrall@amazon.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"George Dunlap" <george.dunlap@citrix.com>,
	"Ian Jackson" <ian.jackson@eu.citrix.com>, "Wei Liu" <wl@xen.org>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Paul Durrant" <paul@xen.org>,
	"Jun Nakajima" <jun.nakajima@intel.com>,
	"Kevin Tian" <kevin.tian@intel.com>, nd <nd@arm.com>
Subject: Re: [RESEND][PATCH v2 5/7] xen: include xen/guest_access.h rather than asm/guest_access.h
Date: Tue, 18 Aug 2020 09:29:52 +0000	[thread overview]
Message-ID: <226D798C-4F67-408F-A2AE-45B184418D80@arm.com> (raw)
In-Reply-To: <4f2982bb-c352-46a0-da73-58b9db45c28a@xen.org>



> On 18 Aug 2020, at 10:23, Julien Grall <julien@xen.org> wrote:
> 
> 
> 
> On 18/08/2020 10:05, Bertrand Marquis wrote:
>>> On 18 Aug 2020, at 09:58, Julien Grall <julien@xen.org> wrote:
>>> 
>>> 
>>> 
>>> On 18/08/2020 09:50, Jan Beulich wrote:
>>>> On 14.08.2020 21:07, Julien Grall wrote:
>>>>> Hi Jan,
>>>>> 
>>>>> On 31/07/2020 12:36, Jan Beulich wrote:
>>>>>> On 30.07.2020 20:18, Julien Grall wrote:
>>>>>>> From: Julien Grall <jgrall@amazon.com>
>>>>>>> 
>>>>>>> Only a few places are actually including asm/guest_access.h. While this
>>>>>>> is fine today, a follow-up patch will want to move most of the helpers
>>>>>>> from asm/guest_access.h to xen/guest_access.h.
>>>>>>> 
>>>>>>> To prepare the move, everyone should include xen/guest_access.h rather
>>>>>>> than asm/guest_access.h.
>>>>>>> 
>>>>>>> Interestingly, asm-arm/guest_access.h includes xen/guest_access.h. The
>>>>>>> inclusion is now removed as no-one but the latter should include the
>>>>>>> former.
>>>>>>> 
>>>>>>> Signed-off-by: Julien Grall <jgrall@amazon.com>
>>>>>> 
>>>>>> Acked-by: Jan Beulich <jbeulich@suse.com>
>>>>>> 
>>>>>> Is there any chance you could take measures to avoid new inclusions
>>>>>> of asm/guest_access.h to appear?
>>>>> 
>>>>> It should be possible.
>>>>> 
>>>>> How about this:
>>>>> 
>>>>> diff --git a/xen/include/asm-arm/guest_access.h b/xen/include/asm-arm/guest_access.h
>>>>> index b9a89c495527..d8dbc7c973b4 100644
>>>>> --- a/xen/include/asm-arm/guest_access.h
>>>>> +++ b/xen/include/asm-arm/guest_access.h
>>>>> @@ -1,3 +1,7 @@
>>>>> +#ifndef ALLOW_INCLUDE_ASM_GUEST_ACCESS_H
>>>>> +#error "asm/guest_access.h should not be included directly"
>>>>> +#endif
>>>>> +
>>>>>  #ifndef __ASM_ARM_GUEST_ACCESS_H__
>>>>>  #define __ASM_ARM_GUEST_ACCESS_H__
>>>>> 
>>>>> diff --git a/xen/include/asm-x86/guest_access.h b/xen/include/asm-x86/guest_access.h
>>>>> index 369676f31ac3..e665ca3a27af 100644
>>>>> --- a/xen/include/asm-x86/guest_access.h
>>>>> +++ b/xen/include/asm-x86/guest_access.h
>>>>> @@ -4,6 +4,10 @@
>>>>>   * Copyright (c) 2006, K A Fraser
>>>>>   */
>>>>> 
>>>>> +#ifndef ALLOW_INCLUDE_ASM_GUEST_ACCESS_H
>>>>> +#error "asm/guest_access.h should not be included directly"
>>>>> +#endif
>>>>> +
>>>>>  #ifndef __ASM_X86_GUEST_ACCESS_H__
>>>>>  #define __ASM_X86_GUEST_ACCESS_H__
>>>>> 
>>>>> diff --git a/xen/include/xen/guest_access.h b/xen/include/xen/guest_access.h
>>>>> index 75103d30c8be..814e31329de9 100644
>>>>> --- a/xen/include/xen/guest_access.h
>>>>> +++ b/xen/include/xen/guest_access.h
>>>>> @@ -7,7 +7,9 @@
>>>>>  #ifndef __XEN_GUEST_ACCESS_H__
>>>>>  #define __XEN_GUEST_ACCESS_H__
>>>>> 
>>>>> +#define ALLOW_INCLUDE_ASM_GUEST_ACCESS_H
>>>>>  #include <asm/guest_access.h>
>>>>> +#undef ALLOW_INCLUDE_ASM_GUEST_ACCESS_H
>>>>>  #include <xen/types.h>
>>>>>  #include <public/xen.h>
>>>> One option. Personally I'd prefer to avoid introduction of yet another
>>>> constant, by leveraging __XEN_GUEST_ACCESS_H__ instead.
>>> 
>>> I thought about it but it doesn't prevent new inclusions of asm/guest_access.h. For instance, the following would still compile:
>>> 
>>> #include <xen/guest_access.h>
>>> 
>>> [...]
>>> 
>>> #include <asm/guest_access.h>
>>> 
>>> If we want to completely prevent new inclusion, then we need a new temporary constant.
>> I would think that this would not handle all cases but would at least prevent someone from including directly the asm header.
> 
> It is not entirely clear what you mean by "including directly" given that my example above a C file would include <asm/guest_access.h>

Sorry, I meant here including directly the asm one in a C file (without the xen one before) if you test 
only “ifndef __XEN_GUEST_ACCESS_H__” in the asm one.

> 
> To make it more obvious <xen/guest_access.h> may have been included via another header.
> 
> The solution suggested by Jan would only prevent the following case:
> 
> #include <asm/guest_access.h>
> 
> [...]
> 
> #include <xen/guest_access.h>
> 
> But this should never happen given that we request <xen/*> to be before <asm/*>.

But this only enforced by review (not by any magics with ifdefs), why not doing the same for directly inclusion of the asm one ?

> 
>> The solution with the define and undef does not look really nice and headers could become really ugly if we start doing that for
>> all asm headers that should not be included directly.
> 
> It is not but that's the price to pay if we want to enforce the rule.

Then if we want to enforce it with an error during compilation, your solution is the only one working I agree.

Cheers
Bertrand


  reply	other threads:[~2020-08-18  9:30 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-30 18:18 [RESEND][PATCH v2 0/7] xen: Consolidate asm-*/guest_access.h in xen/guest_access.h Julien Grall
2020-07-30 18:18 ` [RESEND][PATCH v2 1/7] xen/guest_access: Add emacs magics Julien Grall
2020-07-31 13:04   ` Bertrand Marquis
2020-08-14 18:36     ` Julien Grall
2020-09-22 10:05   ` Volodymyr Babchuk
2020-07-30 18:18 ` [RESEND][PATCH v2 2/7] xen/arm: kernel: Re-order the includes Julien Grall
2020-07-30 19:36   ` Stefano Stabellini
2020-07-31 12:58   ` Bertrand Marquis
2020-07-30 18:18 ` [RESEND][PATCH v2 3/7] xen/arm: decode: " Julien Grall
2020-07-30 19:37   ` Stefano Stabellini
2020-08-14 18:40     ` Julien Grall
2020-07-30 18:18 ` [RESEND][PATCH v2 4/7] xen/arm: guestcopy: " Julien Grall
2020-07-30 19:37   ` Stefano Stabellini
2020-07-31 12:53   ` Bertrand Marquis
2020-07-31 12:56     ` Bertrand Marquis
2020-08-14 18:50     ` Julien Grall
2020-07-30 18:18 ` [RESEND][PATCH v2 5/7] xen: include xen/guest_access.h rather than asm/guest_access.h Julien Grall
2020-07-30 19:37   ` Stefano Stabellini
2020-07-31 11:36   ` Jan Beulich
2020-08-14 19:07     ` Julien Grall
2020-08-18  8:50       ` Jan Beulich
2020-08-18  8:58         ` Julien Grall
2020-08-18  9:05           ` Bertrand Marquis
2020-08-18  9:23             ` Julien Grall
2020-08-18  9:29               ` Bertrand Marquis [this message]
2020-08-18 11:32           ` Jan Beulich
2020-08-18 13:14             ` Julien Grall
2020-08-18 16:04               ` Jan Beulich
2020-08-18 16:20                 ` Julien Grall
2020-08-18 16:23                   ` Jan Beulich
2020-08-18 16:34                     ` Julien Grall
2020-07-31 12:45   ` Bertrand Marquis
2020-07-31 12:45   ` Bertrand Marquis
2020-09-18 18:39   ` Julien Grall
2020-09-21 15:32   ` Paul Durrant
2020-07-30 18:18 ` [RESEND][PATCH v2 6/7] xen/guest_access: Consolidate guest access helpers in xen/guest_access.h Julien Grall
2020-07-30 19:37   ` Stefano Stabellini
2020-08-14 19:10     ` Julien Grall
2020-07-31 11:45   ` Jan Beulich
2020-08-14 19:14     ` Julien Grall
2020-07-30 18:18 ` [RESEND][PATCH v2 7/7] xen/guest_access: Fix coding style " Julien Grall
2020-07-30 19:38   ` Stefano Stabellini
2020-07-31 11:41   ` Jan Beulich
2020-08-14 19:18     ` Julien Grall
2020-08-18  8:52       ` Jan Beulich
2020-08-18  9:03         ` Julien Grall
2020-07-31 12:46   ` Bertrand Marquis

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=226D798C-4F67-408F-A2AE-45B184418D80@arm.com \
    --to=bertrand.marquis@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jgrall@amazon.com \
    --cc=julien@xen.org \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=nd@arm.com \
    --cc=paul@xen.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).