Re: [PATCH v5 2/5] x86/umwait: Initialize umwait control values

From: Thomas Gleixner
Date: Sun Jun 23 2019 - 23:01:52 EST

On Wed, 19 Jun 2019, Fenghua Yu wrote:
> +#define MSR_IA32_UMWAIT_CONTROL 0xe1
> +#define MSR_IA32_UMWAIT_CONTROL_MAX_TIME 0xfffffffc

Errm, no! That's not maxtime, that's the time field mask in the
MSR. Throughout the code you use that as a mask, which is not really

> + (((max_time) & MSR_IA32_UMWAIT_CONTROL_MAX_TIME) | \

and later on:


What? How is anyone supposed to understand that?


makes it entirely clear that the value is not allowed to have any bits
outside of the mask set.

> +

The AND is there for maximal confusion of the reader?

> +/*
> + * On resume, set up IA32_UMWAIT_CONTROL MSR on BP which is the only active
> + * CPU at this time. Setting up the MSR on APs when they are re-added later
> + * using CPU hotplug.
> + * The MSR on BP is supposed not to be changed during suspend and thus it's
> + * unnecessary to set it again during resume from suspend. But at this point
> + * we don't know resume is from suspend or hibernation. To simplify the
> + * situation, just set up the MSR on resume from suspend.

We also do not trust any firmware by default whatever it is supposed to do.