From: Tony Luck <tony.luck@intel.com>
To: Borislav Petkov <bp@alien8.de>
Cc: "Naik, Avadhut" <avadnaik@amd.com>,
"Mehta, Sohil" <sohil.mehta@intel.com>,
"Yazen Ghannam" <yazen.ghannam@amd.com>,
x86@kernel.org, linux-edac@vger.kernel.org,
linux-kernel@vger.kernel.org, Tony Luck <tony.luck@intel.com>
Subject: [PATCH v2] x86/mce: Dynamically size space for machine check records
Date: Wed, 6 Mar 2024 16:02:56 -0800 [thread overview]
Message-ID: <20240307000256.34352-1-tony.luck@intel.com> (raw)
Systems with a large number of CPUs may generate a large
number of machine check records when things go seriously
wrong. But Linux has a fixed buffer that can only capture
a few dozen errors.
Allocate space based on the number of CPUs (with a minimum
value based on the historical fixed buffer that could store
80 records).
Signed-off-by: Tony Luck <tony.luck@intel.com>
---
Changes since v1: Link: https://lore.kernel.org/all/Zd--PJp-NbXGrb39@agluck-desk3/
Sohil:
Group declaration of "order" with other int's in mce_gen_pool_create()
Use #define MCE_MIN_ENTRIES instead of hard-coded inline "80"
Missed kfree(mce_pool) in error path.
Yazen:
Use order_base_2() instead of ilog2() as rounded up size of
structure is needed.
Avadhut:
Allocate 2 records per CPU
Me:
Add a #define MCE_PER_CPU for number of records per CPU
arch/x86/kernel/cpu/mce/genpool.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kernel/cpu/mce/genpool.c b/arch/x86/kernel/cpu/mce/genpool.c
index fbe8b61c3413..42ce3dc97ca8 100644
--- a/arch/x86/kernel/cpu/mce/genpool.c
+++ b/arch/x86/kernel/cpu/mce/genpool.c
@@ -16,14 +16,14 @@
* used to save error information organized in a lock-less list.
*
* This memory pool is only to be used to save MCE records in MCE context.
- * MCE events are rare, so a fixed size memory pool should be enough. Use
- * 2 pages to save MCE events for now (~80 MCE records at most).
+ * MCE events are rare, so a fixed size memory pool should be enough.
+ * Allocate on a sliding scale based on number of CPUs.
*/
-#define MCE_POOLSZ (2 * PAGE_SIZE)
+#define MCE_MIN_ENTRIES 80
+#define MCE_PER_CPU 2
static struct gen_pool *mce_evt_pool;
static LLIST_HEAD(mce_event_llist);
-static char gen_pool_buf[MCE_POOLSZ];
/*
* Compare the record "t" with each of the records on list "l" to see if
@@ -118,16 +118,27 @@ int mce_gen_pool_add(struct mce *mce)
static int mce_gen_pool_create(void)
{
+ int mce_numrecords, mce_poolsz, order;
struct gen_pool *tmpp;
int ret = -ENOMEM;
+ void *mce_pool;
- tmpp = gen_pool_create(ilog2(sizeof(struct mce_evt_llist)), -1);
+ order = order_base_2(sizeof(struct mce_evt_llist));
+ tmpp = gen_pool_create(order, -1);
if (!tmpp)
goto out;
- ret = gen_pool_add(tmpp, (unsigned long)gen_pool_buf, MCE_POOLSZ, -1);
+ mce_numrecords = max(MCE_MIN_ENTRIES, num_possible_cpus() * MCE_PER_CPU);
+ mce_poolsz = mce_numrecords * (1 << order);
+ mce_pool = kmalloc(mce_poolsz, GFP_KERNEL);
+ if (!mce_pool) {
+ gen_pool_destroy(tmpp);
+ goto out;
+ }
+ ret = gen_pool_add(tmpp, (unsigned long)mce_pool, mce_poolsz, -1);
if (ret) {
gen_pool_destroy(tmpp);
+ kfree(mce_pool);
goto out;
}
base-commit: d206a76d7d2726f3b096037f2079ce0bd3ba329b
--
2.43.0
next reply other threads:[~2024-03-07 0:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 0:02 Tony Luck [this message]
2024-03-07 12:16 ` [PATCH v2] x86/mce: Dynamically size space for machine check records Borislav Petkov
2024-03-07 16:59 ` Sohil Mehta
2024-03-07 17:09 ` Borislav Petkov
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=20240307000256.34352-1-tony.luck@intel.com \
--to=tony.luck@intel.com \
--cc=avadnaik@amd.com \
--cc=bp@alien8.de \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sohil.mehta@intel.com \
--cc=x86@kernel.org \
--cc=yazen.ghannam@amd.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).