linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm64/cpufeatures: Enforce inline/const properties of cpus_have_const_cap
Date: Thu, 19 Jan 2017 14:37:04 +0000	[thread overview]
Message-ID: <20170119143703.GB31594@arm.com> (raw)
In-Reply-To: <1484740725-24776-1-git-send-email-marc.zyngier@arm.com>

On Wed, Jan 18, 2017 at 11:58:45AM +0000, Marc Zyngier wrote:
> Despite being flagged "inline", cpus_have_const_cap may end-up being
> placed out of line if the compiler decides so. This would be unfortunate,
> as we want to be able to use this function in HYP, where we need to
> be 100% sure of what is mapped there. __always_inline seems to be a
> better choice given the constraint.
> 
> Also, be a lot tougher on non-const or out-of-range capability values
> (a non-const cap value shouldn't be used here, and the semantic of an
> OOR value is at best ill defined). In those two case, BUILD_BUG_ON is
> what you get.
> 
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
>  arch/arm64/include/asm/cpufeature.h | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
> index b4989df..4710469 100644
> --- a/arch/arm64/include/asm/cpufeature.h
> +++ b/arch/arm64/include/asm/cpufeature.h
> @@ -105,10 +105,11 @@ static inline bool cpu_have_feature(unsigned int num)
>  }
>  
>  /* System capability check for constant caps */
> -static inline bool cpus_have_const_cap(int num)
> +static __always_inline bool cpus_have_const_cap(int num)
>  {
> -	if (num >= ARM64_NCAPS)
> -		return false;
> +	BUILD_BUG_ON(!__builtin_constant_p(num));
> +	BUILD_BUG_ON(num >= ARM64_NCAPS);

This gives different behaviour to cpus_have_const_cap when compared to
cpus_have_cap, which I really don't like. What is the current behaviour
if you pass a non-constant num parameter? Does the kernel actually build?

Maybe it's best to spin a separate patch that makes cpus_have_cap and
cpus_have_const_cap both use __always_inline, then we can debate the merit
of the BUILD_BUG_ONs separately.

Will

  reply	other threads:[~2017-01-19 14:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 11:58 [PATCH] arm64/cpufeatures: Enforce inline/const properties of cpus_have_const_cap Marc Zyngier
2017-01-19 14:37 ` Will Deacon [this message]
2017-01-19 14:42   ` Marc Zyngier
2017-01-19 14:48     ` Will Deacon

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=20170119143703.GB31594@arm.com \
    --to=will.deacon@arm.com \
    --cc=linux-arm-kernel@lists.infradead.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).