]> xenbits.xensource.com Git - xen.git/commitdiff
xen/lib: Introduce printk_once() and replace some opencoded examples
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 17 May 2019 18:30:47 +0000 (19:30 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 31 May 2019 18:11:29 +0000 (19:11 +0100)
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 <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Julien Grall <julien.grall@arm.com>
xen/arch/arm/cpuerrata.c
xen/arch/arm/platforms/xilinx-zynqmp.c
xen/include/xen/lib.h

index 4431b244fdeec8796af1a048a25f2fb2b8c822d7..8904939acab1ebd3f7c4096d7db27ab450ca4b80 100644 (file)
@@ -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();
index 08e3e11e1bd9d3f55feb738b19843b1a34c8b38b..3060d79b346763d7bafeec9c2056887f7c710ffe 100644 (file)
@@ -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);
index 91ed56c70374be0b1e21dbd1ed967c4996a9c3db..ce231c5f4f4884f0b58903ce83671332ef64a890 100644 (file)
@@ -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, ...)