From: Andrew Cooper Date: Fri, 17 May 2019 18:30:47 +0000 (+0100) Subject: xen/lib: Introduce printk_once() and replace some opencoded examples X-Git-Tag: archive/raspbian/4.14.0+80-gd101b417b7-1+rpi1^2~63^2~2144 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a5ae5b67a926f34fb369fdaa7327a2f70b1c2c20;p=xen.git xen/lib: Introduce printk_once() and replace some opencoded examples Reflow the ZynqMP message for grepability, and fix the omission of a newline. There is a race condition where multiple cpus could race to set once_ boolean. However, the use of this construct is mainly useful for boot time code, and the only consequence of the race is a repeated print message. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Reviewed-by: Julien Grall --- diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c index 4431b244fd..8904939aca 100644 --- a/xen/arch/arm/cpuerrata.c +++ b/xen/arch/arm/cpuerrata.c @@ -336,18 +336,11 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry) switch ( ssbd_state ) { case ARM_SSBD_FORCE_DISABLE: - { - static bool once = true; - - if ( once ) - printk("%s disabled from command-line\n", entry->desc); - once = false; + printk_once("%s disabled from command-line\n", entry->desc); arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2_FID, 0, NULL); required = false; - break; - } case ARM_SSBD_RUNTIME: if ( required ) @@ -359,18 +352,11 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry) break; case ARM_SSBD_FORCE_ENABLE: - { - static bool once = true; - - if ( once ) - printk("%s forced from command-line\n", entry->desc); - once = false; + printk_once("%s forced from command-line\n", entry->desc); arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2_FID, 1, NULL); required = true; - break; - } default: ASSERT_UNREACHABLE(); diff --git a/xen/arch/arm/platforms/xilinx-zynqmp.c b/xen/arch/arm/platforms/xilinx-zynqmp.c index 08e3e11e1b..3060d79b34 100644 --- a/xen/arch/arm/platforms/xilinx-zynqmp.c +++ b/xen/arch/arm/platforms/xilinx-zynqmp.c @@ -35,14 +35,9 @@ static bool zynqmp_smc(struct cpu_user_regs *regs) */ if ( !cpus_have_const_cap(ARM_SMCCC_1_1) ) { - static bool once = true; + printk_once(XENLOG_WARNING + "ZynqMP firmware Error: no SMCCC 1.1 support. Disabling firmware calls\n"); - if ( once ) - { - printk(XENLOG_WARNING "ZynqMP firmware Error: no SMCCC 1.1 " - "support. Disabling firmware calls."); - once = false; - } return false; } return zynqmp_eemi(regs); diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index 91ed56c703..ce231c5f4f 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -105,6 +105,17 @@ debugtrace_printk(const char *fmt, ...) {} #define _p(_x) ((void *)(unsigned long)(_x)) extern void printk(const char *format, ...) __attribute__ ((format (printf, 1, 2))); + +#define printk_once(fmt, args...) \ +({ \ + static bool __read_mostly once_; \ + if ( unlikely(!once_) ) \ + { \ + once_ = true; \ + printk(fmt, ## args); \ + } \ +}) + extern void guest_printk(const struct domain *d, const char *format, ...) __attribute__ ((format (printf, 2, 3))); extern void noreturn panic(const char *format, ...)