]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
use consistent values when consuming runtime-changeable parameters
authorJan Beulich <jbeulich@suse.com>
Wed, 31 Oct 2018 16:57:19 +0000 (17:57 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 31 Oct 2018 16:57:19 +0000 (17:57 +0100)
There's no guarantee that e.g. a switch() control expression's memory
operand(s) get(s) read just once. Guard against the compiler producing
"unexpected" code by sprinkling around some ACCESS_ONCE().

I'm leaving alone opt_conswitch[]: It gets accessed in quite a few
places anyway, and an intermediate change won't have any severe effect
afaict.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: George Dunlap <george.dunlap@citrix.com>
xen/arch/x86/pv/domain.c
xen/drivers/char/console.c

index 4c95bf3c2229881b11788a133d5a1724e14e3288..7e84b04082a504d5c226b933cefc2b6243021eea 100644 (file)
@@ -256,7 +256,7 @@ int pv_domain_initialise(struct domain *d)
     d->arch.pv.xpti = is_hardware_domain(d) ? opt_xpti_hwdom : opt_xpti_domu;
 
     if ( !is_pv_32bit_domain(d) && use_invpcid && cpu_has_pcid )
-        switch ( opt_pcid )
+        switch ( ACCESS_ONCE(opt_pcid) )
         {
         case PCID_OFF:
             break;
index 3b75f7a4723a70db99428989fe834d7155b06d9b..5419493dbf045b3418df8027c881c7dbec2aea66 100644 (file)
@@ -630,16 +630,16 @@ static void __putstr(const char *str)
 static int printk_prefix_check(char *p, char **pp)
 {
     int loglvl = -1;
-    int upper_thresh = xenlog_upper_thresh;
-    int lower_thresh = xenlog_lower_thresh;
+    int upper_thresh = ACCESS_ONCE(xenlog_upper_thresh);
+    int lower_thresh = ACCESS_ONCE(xenlog_lower_thresh);
 
     while ( (p[0] == '<') && (p[1] != '\0') && (p[2] == '>') )
     {
         switch ( p[1] )
         {
         case 'G':
-            upper_thresh = xenlog_guest_upper_thresh;
-            lower_thresh = xenlog_guest_lower_thresh;
+            upper_thresh = ACCESS_ONCE(xenlog_guest_upper_thresh);
+            lower_thresh = ACCESS_ONCE(xenlog_guest_lower_thresh);
             if ( loglvl == -1 )
                 loglvl = XENLOG_GUEST_DEFAULT;
             break;
@@ -690,13 +690,14 @@ static int parse_console_timestamps(const char *s)
 
 static void printk_start_of_line(const char *prefix)
 {
+    enum con_timestamp_mode mode = ACCESS_ONCE(opt_con_timestamp_mode);
     struct tm tm;
     char tstr[32];
     uint64_t sec, nsec;
 
     __putstr(prefix);
 
-    switch ( opt_con_timestamp_mode )
+    switch ( mode )
     {
     case TSM_DATE:
     case TSM_DATE_MS:
@@ -704,7 +705,7 @@ static void printk_start_of_line(const char *prefix)
 
         if ( tm.tm_mday == 0 )
             /* nothing */;
-        else if ( opt_con_timestamp_mode == TSM_DATE )
+        else if ( mode == TSM_DATE )
         {
             snprintf(tstr, sizeof(tstr), "[%04u-%02u-%02u %02u:%02u:%02u] ",
                      1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,