mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Borislav Petkov <bp@alien8.de>, Peter Zijlstra <peterz@infradead.org>
Cc: X86 ML <x86@kernel.org>,
	Kishon VijayAbraham <Kishon.VijayAbraham@amd.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] x86/barrier: Do not serialize MSR accesses on AMD
Date: Fri, 27 Oct 2023 21:09:05 +0100	[thread overview]
Message-ID: <3c56e807-945c-4996-9ac1-3205a23248ab@citrix.com> (raw)
In-Reply-To: <20231027192907.GSZTwPg8v7NF6+Zn0w@fat_crate.local>

On 27/10/2023 8:29 pm, Borislav Petkov wrote:
> On Fri, Oct 27, 2023 at 09:16:33PM +0200, Borislav Petkov wrote:
>> Thus the more conservative approach here.
> And on a second thought, I don't need any of that new stuff - I simply
> need a synthetic flag which says "MSRs need fencing" and set it on
> everything but AMD and Hygon. And we've solved this type of issue
> gazillion times already - why am I reinventing the wheel?!

Quoteth the APM (rev 3.41, June 2023):

16.11.2 WRMSR / RDMSR serialization for x2APIC Register

The WRMSR instruction is used to write the APIC register set in x2APIC
mode. Normally WRMSR is
a serializing instruction, however when accessing x2APIC registers, the
serializing aspect of WRMSR
is relaxed to allow for more efficient access to those registers.
Consequently, a WRMSR write to an
x2APIC register may complete before older store operations are complete
and have become globally
visible. When strong ordering of an x2APIC write access is required with
respect to preceding memory
operations, software can insert a serializing instruction (such as
MFENCE) before the WRMSR
instruction.

So which is right?  This commit message, or the APM?  (and yes, if
you're waiting on an APM update then the commit message should at least
note that one is coming.)


But, to the issue at hand.

There are other non-serialising MSRs on AMD CPUs, including the FS/GS
base MSRs on more modern parts which is enumerated in 8000_0021.eax[1].

So there isn't a boolean "MSRs need fencing, yes/no".  It is vendor
*and* model specific as to whether a particular MSR is serialising or
non-serialising.

*And* it's vendor specific as to what the fencing sequence is.  Intel
require mfence;lfence, while on AMD, mfence suffices.

Most MSR writes don't want to be architecturally serialising, and Intel
are introducing WRMSRNS for this purpose.  But ICR writes *do* need to
be ordered with respect to stores becoming globally visible, and it was
an error for MSR_X2APIC_ICR to be specified as non-serialising.


The only sanity-preserving (pseudo) API for this is something like:

vendor_msr_fence = { mfence;lfence (Intel) | mfence (AMD, Hygon) | ... }

and for each MSR separately, something like:

ALTERNATIVE("", vendor_msr_fence, $VENDOR_NEEDS_MSR_$X_FENCE);

because that's the only one which properly separates "what fence to use"
and "do I need to fence this MSR on the current vendor".

~Andrew

  reply	other threads:[~2023-10-27 20:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-22  9:52 [PATCH] " Borislav Petkov
2023-07-03 12:54 ` Peter Zijlstra
2023-07-04  7:46   ` Borislav Petkov
2023-07-04  9:01     ` Peter Zijlstra
2023-07-04  9:22       ` Borislav Petkov
     [not found]         ` <20231027153327.GKZTvYR3qslaTUjtCT@fat_crate.local>
     [not found]           ` <20231027153418.GLZTvYejCkXb03rArO@fat_crate.local>
2023-10-27 18:11             ` [PATCH 1/2] x86/alternative: Add per-vendor patching Peter Zijlstra
2023-10-27 18:25               ` Borislav Petkov
     [not found]           ` <20231027153458.GMZTvYou1tlK6HD8/Y@fat_crate.local>
2023-10-27 18:56             ` [PATCH 2/2] x86/barrier: Do not serialize MSR accesses on AMD Peter Zijlstra
2023-10-27 19:16               ` Borislav Petkov
2023-10-27 19:29                 ` Borislav Petkov
2023-10-27 20:09                   ` Andrew Cooper [this message]
2023-10-27 20:23                     ` Borislav Petkov
2023-10-29 10:35                       ` [PATCH -v3] " Borislav Petkov
2023-11-02 11:08                     ` [PATCH 2/2] " Borislav Petkov
2023-11-13  8:56 ` [tip: x86/cpu] " tip-bot2 for Borislav Petkov (AMD)
2023-11-13  9:21 ` tip-bot2 for Borislav Petkov (AMD)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3c56e807-945c-4996-9ac1-3205a23248ab@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=Kishon.VijayAbraham@amd.com \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®