From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v2 2/2] x86/dom0: only disable SMAP for the PV dom0 build
Date: Wed, 31 Jul 2024 16:10:12 +0200 [thread overview]
Message-ID: <ZqpFxHxA0g0KrCC-@macbook> (raw)
In-Reply-To: <e0000e62-5b00-4a00-85fe-8a6c8e7281b9@suse.com>
On Wed, Jul 31, 2024 at 03:39:35PM +0200, Jan Beulich wrote:
> On 31.07.2024 15:25, Roger Pau Monné wrote:
> > On Wed, Jul 31, 2024 at 08:44:46AM +0200, Jan Beulich wrote:
> >> On 30.07.2024 17:28, Roger Pau Monne wrote:
> >>> The PVH dom0 builder doesn't switch page tables and has no need to run with
> >>> SMAP disabled.
> >>>
> >>> Use stac() and clac(), as that's safe to use even if events would hit in the
> >>> middle of the region with SMAP disabled. Nesting stac() and clac() calls is
> >>> not safe, so the stac() call is done strictly after elf_load_binary() because
> >>> that uses raw_{copy_to,clear}_guest() accessors which toggle SMAP.
> >>
> >> And that was the main concern causing the CR4.SMAP override to be used instead,
> >> iirc. While I'm sure you've properly audited all code paths, how can we be sure
> >> there's not going to be another stac() or clac() added somewhere? Or setting of
> >> EFLAGS as a whole, clearing EFLAGS.AC without that being explicit? I think we'd
> >> be better off sticking to the fiddling with CR4.
> >
> > On approach I didn't test would be to add ASSERTs in stac/clac
> > functions to ensure that the state is as intended. IOW: for stac we
> > would assert that the AC flag is not set, while for clac we would do
> > the opposite and assert that it's set before clearing it.
> >
> > That should detect nesting.
>
> Yet it would also refuse non-paired uses which are in principle okay.
While such non-paired uses could be fine, it would seem to point to
other issues, as I would expect stac/clac to always be paired unless
it's a non-return path (a panic or similar).
> Plus is requires respective code paths to be taken for such assertions
> to trigger.
It does. It seems more reliable to me to use stac/clac, rather than
fiddling with %cr4, however there's the nesting issue. I think we
need to reach consensus as to which approach is to be used.
> >>> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> >>
> >> Considering the bug Andrew pointed out on the code you remove from setup.c,
> >> don't we want a Fixes: tag as well?
> >
> > No, I think the current code is correct, it was my change that was
> > incorrect.
>
> Hmm, no I think there was an issue also before, from the cpu_has_smap
> use in the restore-CR4 conditional: We'd enable SMAP there even if on
> the command line there was "smap=hvm". While we clear FEATURE_SMAP
> when "smap=off", we keep the feature available when "smap=hvm". Thus
> we'd pointlessly write CR4 in the first if() and then enable SMAP in
> the second one, even though it wasn't enabled earlier on.
Oh yes, that one. I was thinking about the one related to IST and
cr4_pv32_mask. I will add the fixes tag.
Thanks, Roger.
next prev parent reply other threads:[~2024-07-31 14:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-30 15:28 [PATCH v2 0/2] x86/dom0: miscellaneous fixes for PV dom0 builder Roger Pau Monne
2024-07-30 15:28 ` [PATCH v2 1/2] x86/dom0: fix restoring %cr3 and the mapcache override on PV build error Roger Pau Monne
2024-07-31 6:32 ` Jan Beulich
2024-07-31 7:57 ` Roger Pau Monné
2024-07-31 8:02 ` Jan Beulich
2024-07-30 15:28 ` [PATCH v2 2/2] x86/dom0: only disable SMAP for the PV dom0 build Roger Pau Monne
2024-07-31 6:44 ` Jan Beulich
2024-07-31 13:25 ` Roger Pau Monné
2024-07-31 13:39 ` Jan Beulich
2024-07-31 14:10 ` Roger Pau Monné [this message]
2024-07-31 16:47 ` Andrew Cooper
2024-08-01 7:12 ` 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=ZqpFxHxA0g0KrCC-@macbook \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.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.