Re: [PATCH v2 1/5] x86/speculation: Provide a debugfs file to dump SPEC_CTRL MSRs

From: Waiman Long
Date: Wed Jun 21 2023 - 09:48:32 EST



On 6/21/23 03:41, Peter Zijlstra wrote:
On Tue, Jun 20, 2023 at 10:06:21AM -0400, Waiman Long wrote:
Sometimes it is useful to know the states the SPEC_CTRL MSRs to see what
mitigations are enabled at run time. Provide a new x86/spec_ctrl_msrs
debugfs file to dump the cached versions of the current SPEC_CTRL MSRs.

Pff, clearly I can't even read email anymore..

We don't do this for any of the other MSRs, so why start now?

That is true since most of the MSRs are static. IOW, they don't change once they are set. The current way to read the content of the MSRs is via the /dev/cpu/<n>/msr files. There are user space tools to do that.

SPEC_CTRL, however, can be subjected to frequent changes especially when X86_FEATURE_KERNEL_IBRS is set. As a result, the current way of reading MSRs from /dev/cpu/<n>/msr doesn't quite work for SPEC_CTRL as the IBRS bit is always set due to the fact that the reading is done internally via an IPI in kernel space. That is the main reason that I add this debugfs file to get a good snapshot of the current set of cached SPEC_CTRL MSR values without the need to disturb what the CPUs are currently doing at that point in time.

This patch is not central to the main purpose of this patch series, but it does enable me to quickly verify the other patches are working correctly. I can take it out if people don't think it is a good idea.

Cheers,
Longman