From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
Xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v4 04/14] x86/boot: Document the ordering dependency of _svm_cpu_up()
Date: Mon, 2 Mar 2026 15:42:14 +0000 [thread overview]
Message-ID: <3e460f2c-9118-4cd1-9d60-bdfa1f502cd2@citrix.com> (raw)
In-Reply-To: <a99ff4bf-1519-4b93-a11e-dd8c2b5c44d6@suse.com>
On 02/03/2026 3:34 pm, Jan Beulich wrote:
> On 02.03.2026 16:20, Andrew Cooper wrote:
>> On 27/02/2026 11:16 pm, Andrew Cooper wrote:
>>> Lets just say this took an unreasoanble amount of time and effort to track
>>> down, when trying to move traps_init() earlier during boot.
>>>
>>> When the SYSCALL linkage MSRs are not configured ahead of _svm_cpu_up() on the
>>> BSP, the first context switch into PV uses svm_load_segs() and clobbers the
>>> later-set-up linkage with the 0's cached here, causing hypercalls issues by
>>> the PV guest to enter at 0 in supervisor mode on the user stack.
>>>
>>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>>> ---
>>> CC: Jan Beulich <JBeulich@suse.com>
>>> CC: Roger Pau Monné <roger.pau@citrix.com>
>>>
>>> v4:
>>> * New
>>>
>>> It occurs to me that it's not actually 0's we cache here. It's whatever
>>> context was left from prior to Xen. We still don't reliably clean unused
>>> MSRs.
> Actually, with this, ...
>
>>> --- a/xen/arch/x86/hvm/svm/svm.c
>>> +++ b/xen/arch/x86/hvm/svm/svm.c
>>> @@ -35,6 +35,7 @@
>>> #include <asm/p2m.h>
>>> #include <asm/paging.h>
>>> #include <asm/processor.h>
>>> +#include <asm/traps.h>
>>> #include <asm/vm_event.h>
>>> #include <asm/x86_emulate.h>
>>>
>>> @@ -1581,6 +1582,21 @@ static int _svm_cpu_up(bool bsp)
>>> /* Initialize OSVW bits to be used by guests */
>>> svm_host_osvw_init();
>>>
>>> + /*
>>> + * VMSAVE writes out the current full FS, GS, LDTR and TR segments, and
>>> + * the GS_SHADOW, SYSENTER and SYSCALL linkage MSRs.
>>> + *
>>> + * The segment data gets modified by the svm_load_segs() optimisation for
>>> + * PV context switches, but all values get reloaded at that point, as well
>>> + * as during context switch from SVM.
>>> + *
>>> + * If PV guests are available (and FRED is not in use), it is critical
>>> + * that the SYSCALL linkage MSRs been configured at this juncture.
>>> + */
>>> + ASSERT(opt_fred >= 0); /* Confirm that FRED-ness has been resolved */
>>> + if ( IS_ENABLED(CONFIG_PV) && !opt_fred )
>>> + ASSERT(rdmsr(MSR_LSTAR));
>> It has occurred to me that this is subtly wrong. While FRED doesn't use
>> LSTAR/SFMASK, it does reuse STAR.
>>
>> So this needs to be:
>>
>> if ( IS_ENABLED(CONFIG_PV) )
>> ASSERT(rdmsr(MSR_STAR));
>>
>> with the include dropped, as the final sentence adjusted to say "even
>> with FRED".
> ... if we inherit a non-zero value, is the assertion of much use this way?
The inherited case is normally when we're KEXEC'd into. That doesn't
happen very much with Xen, and is more of a concern with Linux.
But yes, IMO the assertion is still useful. CI boots from clean, so the
ASSERT() will catch accidental code movement which violates the dependency.
~Andrew
next prev parent reply other threads:[~2026-03-02 15:42 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 23:16 [PATCH v4 00/14] x86: FRED support Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 01/14] x86/pv: Don't assume that INT $imm8 instructions are two bytes long Andrew Cooper
2026-03-02 11:03 ` Jan Beulich
2026-03-02 11:43 ` Andrew Cooper
2026-03-02 12:57 ` Jan Beulich
2026-03-02 16:39 ` Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 02/14] docs/guest-guide: Describe the PV traps and entrypoints ABI Andrew Cooper
2026-03-02 11:19 ` Jan Beulich
2026-03-02 14:47 ` Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 03/14] x86/boot: Move gdt_l1e caching out of traps_init() Andrew Cooper
2026-03-02 11:33 ` Jan Beulich
2026-02-27 23:16 ` [PATCH v4 04/14] x86/boot: Document the ordering dependency of _svm_cpu_up() Andrew Cooper
2026-03-02 11:35 ` Jan Beulich
2026-03-02 15:20 ` Andrew Cooper
2026-03-02 15:34 ` Jan Beulich
2026-03-02 15:42 ` Andrew Cooper [this message]
2026-02-27 23:16 ` [PATCH v4 05/14] x86/traps: Move traps_init() earlier on boot Andrew Cooper
2026-03-02 11:39 ` Jan Beulich
2026-03-02 15:32 ` Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 06/14] x86/traps: Don't configure Supervisor Shadow Stack tokens in FRED mode Andrew Cooper
2026-03-02 14:50 ` Jan Beulich
2026-03-02 15:47 ` Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 07/14] x86/traps: Introduce FRED entrypoints Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 08/14] x86/traps: Enable FRED when requested Andrew Cooper
2026-03-02 16:12 ` Jan Beulich
2026-03-03 13:44 ` Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 09/14] x86/pv: Adjust GS handling for FRED mode Andrew Cooper
2026-03-02 16:24 ` Jan Beulich
2026-03-04 17:18 ` [PATCH v4.1 " Andrew Cooper
2026-03-05 10:00 ` Jan Beulich
2026-02-27 23:16 ` [PATCH v4 10/14] x86/pv: Guest exception handling in " Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 11/14] x86/pv: ERETU error handling Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 12/14] x86/pv: System call handling in FRED mode Andrew Cooper
2026-03-09 22:25 ` Andrew Cooper
2026-03-10 7:16 ` Jan Beulich
2026-02-27 23:16 ` [PATCH v4 13/14] x86: Clamp reserved bits in eflags more aggressively Andrew Cooper
2026-03-02 16:35 ` Jan Beulich
2026-03-11 17:58 ` [PATCH v4.1 13/14] x86: Clamp " Andrew Cooper
2026-03-12 8:15 ` Jan Beulich
2026-03-12 12:36 ` Andrew Cooper
2026-02-27 23:16 ` [PATCH v4 14/14] x86/traps: Use fatal_trap() for #UD and #GP Andrew Cooper
2026-03-02 16:39 ` Jan Beulich
2026-03-02 16:40 ` Jan Beulich
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=3e460f2c-9118-4cd1-9d60-bdfa1f502cd2@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.