From: Borislav Petkov <bp@alien8.de>
To: Linux regressions mailing list <regressions@lists.linux.dev>
Cc: lukas.bulwahn@gmail.com, dave.hansen@linux.intel.com,
hpa@zytor.com, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org, mingo@redhat.com,
tglx@linutronix.de, x86@kernel.org, initramfs@vger.kernel.org
Subject: [PATCH] x86: Add a "x86" ELF note namespace
Date: Wed, 22 Nov 2023 14:24:43 +0100 [thread overview]
Message-ID: <20231122132419.GBZV4BA399sG2JRFAJ@fat_crate.local> (raw)
In-Reply-To: <20231122115826.GAZV3s4krKXI002KQ0@fat_crate.local>
On Wed, Nov 22, 2023 at 12:58:26PM +0100, Borislav Petkov wrote:
> On Wed, Nov 22, 2023 at 10:15:42AM +0100, Linux regression tracking (Thorsten Leemhuis) wrote:
> > [1] unless you fiddle with things obviously internal; not sure if this
> > case would qualify for him, but somehow I doubt it -- but I might be
> > wrong there.
>
> Well, think about it - by that logic, if CONFIG_* items are an ABI, we
> will never ever be able to change any of them. Now that would be awful.
>
> > Any progress on this?
>
> We're thinking...
Turns out this is easier than I think and people have solved this
problem already - all I need to do is use it. Wonderful.
Lemme Cc initramfs@vger.kernel.org as an FYI and see whether dracut
folks would have any comments about this.
---
From: "Borislav Petkov (AMD)" <bp@alien8.de>
Date: Wed, 22 Nov 2023 13:59:40 +0100
Add a "x86" ELF note namespace to put ELF note structures with which to
communicate in a ABI-compliant manner what a kernel image supports.
Also, add the first note type of this - X86_ELFNOTE_MICROCODE - which
denotes that microcode support is built into the kernel image and thus
initrd-generating tools like dracut can parse the ELF .notes section for
this.
$ readelf -n vmlinux
Displaying notes found in: .notes
Owner Data size Description
...
x86 0x00000004 Unknown note type: (0x00000000)
description data: 01 00 00 00
^^^^^^^^^^^^^^
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
---
arch/x86/include/uapi/elfnote.h | 18 ++++++++++++++++++
arch/x86/kernel/cpu/microcode/core.c | 5 +++++
2 files changed, 23 insertions(+)
create mode 100644 arch/x86/include/uapi/elfnote.h
diff --git a/arch/x86/include/uapi/elfnote.h b/arch/x86/include/uapi/elfnote.h
new file mode 100644
index 000000000000..bef26c4944e8
--- /dev/null
+++ b/arch/x86/include/uapi/elfnote.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _X86_UAPI_ELFNOTE_H_
+#define _X86_UAPI_ELFNOTE_H_
+
+/*
+ * "x86" namespaced ELF note structures to communicate features
+ * supported by the kernel binary to external utilities which need that
+ * info in order to do additional preparatory work based on the target
+ * kernel image.
+ */
+
+/*
+ * Used by the microcode loader to communicate support to external
+ * initrd generators like dracut.
+ */
+#define X86_ELFNOTE_MICROCODE 0
+
+#endif /* _X86_UAPI_ELFNOTE_H_ */
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index 232026a239a6..f35444bafbbc 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -24,6 +24,7 @@
#include <linux/capability.h>
#include <linux/firmware.h>
#include <linux/cpumask.h>
+#include <linux/elfnote.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/mutex.h>
@@ -32,6 +33,8 @@
#include <linux/fs.h>
#include <linux/mm.h>
+#include <uapi/elfnote.h>
+
#include <asm/apic.h>
#include <asm/cpu_device_id.h>
#include <asm/perf_event.h>
@@ -859,3 +862,5 @@ static int __init microcode_init(void)
}
late_initcall(microcode_init);
+
+ELFNOTE32("x86", X86_ELFNOTE_MICROCODE, CONFIG_MICROCODE);
--
2.42.0.rc0.25.ga82fb66fed25
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2023-11-22 13:25 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230825141226.13566-1-lukas.bulwahn@gmail.com>
2023-11-12 15:03 ` [regression] microcode files missing in initramfs imgages from dracut (was Re: [PATCH] x86: Clean up remaining references to CONFIG_MICROCODE_AMD) Linux regression tracking (Thorsten Leemhuis)
2023-11-12 18:10 ` Borislav Petkov
2023-11-22 9:15 ` Linux regression tracking (Thorsten Leemhuis)
2023-11-22 11:58 ` Borislav Petkov
2023-11-22 13:24 ` Borislav Petkov [this message]
2023-11-22 14:07 ` [PATCH] x86: Add a "x86" ELF note namespace Borislav Petkov
2023-11-22 15:34 ` [regression] microcode files missing in initramfs imgages from dracut (was Re: [PATCH] x86: Clean up remaining references to CONFIG_MICROCODE_AMD) Linux regression tracking (Thorsten Leemhuis)
2023-11-22 15:57 ` Borislav Petkov
2023-11-22 20:35 ` Linus Torvalds
2023-11-22 20:51 ` Borislav Petkov
2023-11-22 21:08 ` Linus Torvalds
2023-11-22 21:35 ` Borislav Petkov
2023-11-23 11:20 ` Borislav Petkov
2023-11-24 8:49 ` Antonio Feijoo
2023-11-24 12:15 ` Borislav Petkov
2023-11-24 13:15 ` Antonio Feijoo
2023-11-24 13:33 ` Borislav Petkov
2023-11-28 13:17 ` Borislav Petkov
2023-11-22 13:45 ` Lukas Bulwahn
2023-11-23 4:07 ` Linux regression tracking #update (Thorsten Leemhuis)
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=20231122132419.GBZV4BA399sG2JRFAJ@fat_crate.local \
--to=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=initramfs@vger.kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
--cc=mingo@redhat.com \
--cc=regressions@lists.linux.dev \
--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;
as well as URLs for NNTP newsgroup(s).