[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen staging] use consistent values when consuming runtime-changeable parameters



commit ee91031be2852b9e132fddbc00a6eee38e6e23fc
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Wed Oct 31 17:57:19 2018 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Oct 31 17:57:19 2018 +0100

    use consistent values when consuming runtime-changeable parameters
    
    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@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Acked-by: George Dunlap <george.dunlap@xxxxxxxxxx>
---
 xen/arch/x86/pv/domain.c   |  2 +-
 xen/drivers/char/console.c | 13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 4c95bf3c22..7e84b04082 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -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;
diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 3b75f7a472..5419493dbf 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -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,
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.