From: Josh Poimboeuf <jpoimboe@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Breno Leitao <leitao@debian.org>,
tglx@linutronix.de, bp@alien8.de, Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
leit@meta.com,
"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4] x86/bugs: Add a separate config for each mitigation
Date: Tue, 17 Oct 2023 10:15:05 -0700 [thread overview]
Message-ID: <20231017171505.6bsecux7vjuluhp2@treble> (raw)
In-Reply-To: <ZS0GQoEsG/20IvnE@gmail.com>
On Mon, Oct 16, 2023 at 11:45:38AM +0200, Ingo Molnar wrote:
> * Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> > On Fri, Oct 13, 2023 at 12:50:59PM +0200, Ingo Molnar wrote:
> > > * Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> > > > On Thu, Oct 12, 2023 at 08:51:24PM +0200, Ingo Molnar wrote:
> > > > > > Another way to avoid ifdeffery:
> > > > > >
> > > > > > static enum retbleed_mitigation_cmd retbleed_cmd __ro_after_init =
> > > > > > IS_ENABLED(CONFIG_MITIGATION_RETBLEED) ? RETBLEED_CMD_AUTO : RETBLEED_CMD_OFF;
> > > > >
> > > > > I think we could make it a simple:
> > > > >
> > > > > static enum retbleed_mitigation_cmd retbleed_cmd __ro_after_init = IS_ENABLED(CONFIG_MITIGATION_RETBLEED);
> > > > >
> > > > > Because RETBLEED_CMD_AUTO && RETBLEED_CMD_OFF maps naturally to 1 and 0.
> > > > > Maybe add a comment to the enum to maintain this property in the future
> > > > > too.
> > > >
> > > > Hm, that both obfuscates the default and makes it fragile. The fact
> > > > that it would need a comment to try to prevent breaking it in the future
> > > > is a clue that maybe we shouldn't do it ;-)
> > >
> > > Can be enforced with BUILD_BUG_ON().
> >
> > That replaces fragility with brittleness. If we change a default then
> > we have to go rearrange the corresponding enum, and update the
> > BUILD_BUG_ONs.
>
> How realistic is that? A world in which an enum named '*_OFF' isn't zero
> and the most obvious second enum isn't 'auto' would be unconditionally sad
> IMO...
I'm glad you asked ;-)
Not only is it realistic, it already seems to be the case for the
majority of the enums which are used for defaults:
enum l1tf_mitigations {
L1TF_MITIGATION_OFF,
L1TF_MITIGATION_FLUSH_NOWARN,
L1TF_MITIGATION_FLUSH, /* default */
L1TF_MITIGATION_FLUSH_NOSMT,
L1TF_MITIGATION_FULL,
L1TF_MITIGATION_FULL_FORCE
};
enum taa_mitigations {
TAA_MITIGATION_OFF,
TAA_MITIGATION_UCODE_NEEDED,
TAA_MITIGATION_VERW, /* default */
TAA_MITIGATION_TSX_DISABLED,
};
enum mmio_mitigations {
MMIO_MITIGATION_OFF,
MMIO_MITIGATION_UCODE_NEEDED,
MMIO_MITIGATION_VERW, /* default */
};
enum srbds_mitigations {
SRBDS_MITIGATION_OFF,
SRBDS_MITIGATION_UCODE_NEEDED,
SRBDS_MITIGATION_FULL, /* default */
SRBDS_MITIGATION_TSX_OFF,
SRBDS_MITIGATION_HYPERVISOR,
};
enum l1d_flush_mitigations {
L1D_FLUSH_OFF = 0, / * default */
L1D_FLUSH_ON,
};
enum gds_mitigations {
GDS_MITIGATION_OFF,
GDS_MITIGATION_UCODE_NEEDED,
GDS_MITIGATION_FORCE,
GDS_MITIGATION_FULL, /* default */
GDS_MITIGATION_FULL_LOCKED,
GDS_MITIGATION_HYPERVISOR,
};
enum srso_mitigation_cmd {
SRSO_CMD_OFF,
SRSO_CMD_MICROCODE,
SRSO_CMD_SAFE_RET, /* default */
SRSO_CMD_IBPB,
SRSO_CMD_IBPB_ON_VMEXIT,
};
It's dangerous (and in fact antithetical to the concept of enums!) to
make assumptions about enum values, for both existing and future code.
> > More importantly, it's still less readable because the reader now has to
> > go read the enum values to cross-reference the hard-coded values of 0 and
> > 1 with the enums which are used everywhere else.
>
> They'd have to do that anyway, to make sense of the enum jungle.
Why? The enum values are completely opaque to the code as far as I can
tell. Changing that will just make the code even more obtuse.
I don't see any benefit in hard-coding them. What's the point?
--
Josh
prev parent reply other threads:[~2023-10-17 17:15 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-10 10:30 Breno Leitao
2023-10-11 4:42 ` Josh Poimboeuf
2023-10-11 12:20 ` Breno Leitao
2023-10-11 16:49 ` Josh Poimboeuf
2023-10-11 19:03 ` Borislav Petkov
2023-10-11 22:03 ` Josh Poimboeuf
2023-10-12 7:29 ` Borislav Petkov
2023-10-12 16:48 ` Josh Poimboeuf
2023-10-15 15:06 ` Borislav Petkov
2023-10-16 10:07 ` Ingo Molnar
2023-10-16 12:46 ` Borislav Petkov
2023-10-17 15:08 ` Breno Leitao
2023-10-11 21:59 ` Ingo Molnar
2023-10-12 13:02 ` Breno Leitao
2023-10-12 17:05 ` Josh Poimboeuf
2023-10-12 18:51 ` Ingo Molnar
2023-10-12 20:43 ` Josh Poimboeuf
2023-10-13 10:50 ` Ingo Molnar
2023-10-15 14:11 ` Josh Poimboeuf
2023-10-16 9:45 ` Ingo Molnar
2023-10-17 17:15 ` Josh Poimboeuf [this message]
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=20231017171505.6bsecux7vjuluhp2@treble \
--to=jpoimboe@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=leit@meta.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--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®