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@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>
This commit is contained in:
Jan Beulich committed 2018-10-31 17:57:19 +01:00
1 parent 8e751ac59c
commit ee91031be2
2 files changed
+8 -7

No files matched your search

+1 -1
View 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;
+7 -6
View 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,
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.