From: Jan Beulich <jbeulich@suse.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>,
Xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v4.1 13/14] x86: Clamp bits in eflags more aggressively
Date: Thu, 12 Mar 2026 09:15:38 +0100 [thread overview]
Message-ID: <2f006ef9-8a2e-4059-83ed-65dbe50ea9bb@suse.com> (raw)
In-Reply-To: <20260311175838.573925-1-andrew.cooper3@citrix.com>
On 11.03.2026 18:58, Andrew Cooper wrote:
> In FRED mode, ERET is stricter than IRET about flags. Notably this means:
>
> * The vm86 bit (bit 17) and IOPL (bits 12,13) must be clear.
> * The sticky-1 reserved bit (bit 2) must be set, so dom0_construct() needs to
> set X86_EFLAGS_MBS in order for a PV dom0 to start.
> * All other reserved bits must be clear.
>
> Xen has been overly lax with reserved bit handling. Adjust
> arch_set_info_guest*() and hypercall_iret() which consume flags to clamp the
> reserved bits for all guest types.
>
> This is a minor ABI change, but by the same argument as commit
> 9f892f84c279 ("x86/domctl: Stop using XLAT_cpu_user_regs()"); the reserved
> bits would get clamped like this naturally by hardware when the vCPU is run.
>
> The handling of vm86 is also different. Guests under 32bit Xen really could
> use vm86 mode, but Long Mode disallows vm86 mode and IRET simply ignores the
> bit. Xen's behaviour for a PV32 guest trying to use vm86 mode under a 64bit
> Xen is to arrange to deliver #GP at the target of the IRET, rather than to
> fail the IRET itself.
>
> However there's no filter filtering in arch_set_info_guest() itself, and it
Nit: Excess "filter"?
> can't arrange to queue a #GP at the target, so do the next best thing and fail
> the hypercall. This is not expected to create an issue for PV guests, as the
> result of such an arch_set_info_guest() previously would be to run supposedly
> Real Mode code as Protected Mode code.
>
> This allows PV guests to start when Xen is using FRED mode.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Nevertheless, a largely unrelated remark and two suggestions:
> --- a/xen/arch/x86/domain.c
> +++ b/xen/arch/x86/domain.c
> @@ -1193,6 +1193,14 @@ int arch_set_info_guest(
>
> if ( !__addr_ok(c.nat->ldt_base) )
> return -EINVAL;
Seeing this still in context: I had some trouble locating the position where
you're making the change, as in my local tree this is long gone. Is there
any chance we could make progress on "x86/PV: consolidate LDT checks" [1]?
> +
> + /*
> + * IRET in Long Mode discards EFLAGS.VM, but in FRED mode ERET
> + * cares that it is zero.
> + *
> + * Guests can't see FRED, so emulate IRET behaviour.
> + */
> + c.nat->user_regs.rflags &= ~X86_EFLAGS_VM;
> }
> #ifdef CONFIG_COMPAT
> else
> @@ -1205,6 +1213,18 @@ int arch_set_info_guest(
>
> for ( i = 0; i < ARRAY_SIZE(c.cmp->trap_ctxt); i++ )
> fixup_guest_code_selector(d, c.cmp->trap_ctxt[i].cs);
> +
> + /*
> + * Under 32bit Xen, PV guests could really use vm86 mode. Under
> + * 64bit Xen, vm86 mode can't be entered even by PV32 guests.
> + *
> + * For backwards compatibility, compat HYPERCALL_iret will arrange
> + * to deliver #GP at the target of the IRET rather than to fail
> + * the IRET itself, but we can't arrange for the same behaviour
> + * here. Reject the hypercall as the next best option.
> + */
> + if ( c.cmp->user_regs.eflags & X86_EFLAGS_VM )
> + return -EINVAL;
Technically we could support VM86 mode, by fully emulating things. Hence I
think -EOPNOTSUPP would be more appropriate.
> }
> #endif
Having all of the EFLAGS handling together would be nice. IOPL and IF handling
sit further down. Could I talk you into moving these additions down there? Yes,
there are downsides to that: It looks to need another "compat" conditional, and
it would further the mix of state updates and error checks. Yet I still think
having all of the EFLAGS stuff together is a benefit.
Jan
[1] https://lists.xen.org/archives/html/xen-devel/2023-09/msg00157.html
next prev parent reply other threads:[~2026-03-12 8:16 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
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 [this message]
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=2f006ef9-8a2e-4059-83ed-65dbe50ea9bb@suse.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.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.