• Mark Rutland's avatar
    arm64: Add cpucap_is_possible() · de66cb37
    Mark Rutland authored
    Many cpucaps can only be set when certain CONFIG_* options are selected,
    and we need to check the CONFIG_* option before the cap in order to
    avoid generating redundant code. Due to this, we have a growing number
    of helpers in <asm/cpufeature.h> of the form:
    
    | static __always_inline bool system_supports_foo(void)
    | {
    |         return IS_ENABLED(CONFIG_ARM64_FOO) &&
    |                 cpus_have_const_cap(ARM64_HAS_FOO);
    | }
    
    This is unfortunate as it forces us to use cpus_have_const_cap()
    unnecessarily, resulting in redundant code being generated by the
    compiler. In the vast majority of cases, we only require that feature
    checks indicate the presence of a feature after cpucaps have been
    finalized, and so it would be sufficient to use alternative_has_cap_*().
    However some code needs to handle a feature before alternatives have
    been patched, and must test the system_cpucaps bitmap via
    cpus_have_const_cap(). In other cases we'd like to check for
    unintentional usage of a cpucap before alternatives are patched, and so
    it would be preferable to use cpus_have_final_cap().
    
    Placing the IS_ENABLED() checks in each callsite is tedious and
    error-prone, and the same applies for writing wrappers for each
    comination of cpucap and alternative_has_cap_*() / cpus_have_cap() /
    cpus_have_final_cap(). It would be nicer if we could centralize the
    knowledge of which cpucaps are possible, and have
    alternative_has_cap_*(), cpus_have_cap(), and cpus_have_final_cap()
    handle this automatically.
    
    This patch adds a new cpucap_is_possible() function which will be
    responsible for checking the CONFIG_* option, and updates the low-level
    cpucap checks to use this. The existing CONFIG_* checks in
    <asm/cpufeature.h> are moved over to cpucap_is_possible(), but the (now
    trival) wrapper functions are retained for now.
    
    There should be no functional change as a result of this patch alone.
    Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
    Cc: Marc Zyngier <maz@kernel.org>
    Cc: Mark Brown <broonie@kernel.org>
    Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
    Cc: Will Deacon <will@kernel.org>
    Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
    de66cb37
alternative-macros.h 6.39 KB