All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] x86/mce: Dynamically size space for machine check records
@ 2024-03-07 19:27 Tony Luck
  2024-03-11  5:38 ` Naik, Avadhut
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tony Luck @ 2024-03-07 19:27 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Naik, Avadhut, Mehta, Sohil, Yazen Ghannam, x86, linux-edac,
	linux-kernel, Tony Luck

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>
Reviewed-by: Sohil Mehta <sohil.mehta@intel.com>
---

Changes since V2; Link: https://lore.kernel.org/all/20240307000256.34352-1-tony.luck@intel.com/

Boris: Eliminate "out:" label in mce_gen_pool_create()

Sohil: Added Reviewed-by tag

 arch/x86/kernel/cpu/mce/genpool.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/cpu/mce/genpool.c b/arch/x86/kernel/cpu/mce/genpool.c
index fbe8b61c3413..cadf28662a70 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,22 +118,32 @@ 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;
+		return ret;
 
-	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);
+		return ret;
+	}
+	ret = gen_pool_add(tmpp, (unsigned long)mce_pool, mce_poolsz, -1);
 	if (ret) {
 		gen_pool_destroy(tmpp);
-		goto out;
+		kfree(mce_pool);
+		return ret;
 	}
 
 	mce_evt_pool = tmpp;
 
-out:
 	return ret;
 }
 

base-commit: d206a76d7d2726f3b096037f2079ce0bd3ba329b
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] x86/mce: Dynamically size space for machine check records
  2024-03-07 19:27 [PATCH v3] x86/mce: Dynamically size space for machine check records Tony Luck
@ 2024-03-11  5:38 ` Naik, Avadhut
  2024-03-26 11:49 ` Borislav Petkov
  2024-03-26 12:35 ` [tip: ras/core] " tip-bot2 for Tony Luck
  2 siblings, 0 replies; 4+ messages in thread
From: Naik, Avadhut @ 2024-03-11  5:38 UTC (permalink / raw)
  To: Tony Luck, Borislav Petkov
  Cc: Mehta, Sohil, Yazen Ghannam, x86, linux-edac, linux-kernel



On 3/7/2024 13:27, Tony Luck wrote:
> 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>
> Reviewed-by: Sohil Mehta <sohil.mehta@intel.com>
> ---
> 
> Changes since V2; Link: https://lore.kernel.org/all/20240307000256.34352-1-tony.luck@intel.com/
> 
> Boris: Eliminate "out:" label in mce_gen_pool_create()
> 
> Sohil: Added Reviewed-by tag
> 
>  arch/x86/kernel/cpu/mce/genpool.c | 28 +++++++++++++++++++---------
>  1 file changed, 19 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/mce/genpool.c b/arch/x86/kernel/cpu/mce/genpool.c
> index fbe8b61c3413..cadf28662a70 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,22 +118,32 @@ 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;
> +		return ret;
>  
> -	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);
> +		return ret;
> +	}
> +	ret = gen_pool_add(tmpp, (unsigned long)mce_pool, mce_poolsz, -1);
>  	if (ret) {
>  		gen_pool_destroy(tmpp);
> -		goto out;
> +		kfree(mce_pool);
> +		return ret;
>  	}
>  
>  	mce_evt_pool = tmpp;
>  
> -out:
>  	return ret;
>  }
>  
> 
> base-commit: d206a76d7d2726f3b096037f2079ce0bd3ba329b

LGTM!

Reviewed-by: Avadhut Naik <avadhut.naik@amd.com>

-- 
Thanks,
Avadhut Naik

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] x86/mce: Dynamically size space for machine check records
  2024-03-07 19:27 [PATCH v3] x86/mce: Dynamically size space for machine check records Tony Luck
  2024-03-11  5:38 ` Naik, Avadhut
@ 2024-03-26 11:49 ` Borislav Petkov
  2024-03-26 12:35 ` [tip: ras/core] " tip-bot2 for Tony Luck
  2 siblings, 0 replies; 4+ messages in thread
From: Borislav Petkov @ 2024-03-26 11:49 UTC (permalink / raw)
  To: Tony Luck
  Cc: Naik, Avadhut, Mehta, Sohil, Yazen Ghannam, x86, linux-edac,
	linux-kernel

On Thu, Mar 07, 2024 at 11:27:04AM -0800, Tony Luck wrote:
> -	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);

So, on a big fat machine with 8K CPUs that's, what

	8192 * 2 * (1 << 8) = ~4M

buffer?

Well, if you have a fat machine, you get fat buffers too.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: ras/core] x86/mce: Dynamically size space for machine check records
  2024-03-07 19:27 [PATCH v3] x86/mce: Dynamically size space for machine check records Tony Luck
  2024-03-11  5:38 ` Naik, Avadhut
  2024-03-26 11:49 ` Borislav Petkov
@ 2024-03-26 12:35 ` tip-bot2 for Tony Luck
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Tony Luck @ 2024-03-26 12:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Tony Luck, Borislav Petkov (AMD),
	Sohil Mehta, Avadhut Naik, x86, linux-kernel

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     108c6494bdf1dfeaefc0a506e2f471aa92fafdd6
Gitweb:        https://git.kernel.org/tip/108c6494bdf1dfeaefc0a506e2f471aa92fafdd6
Author:        Tony Luck <tony.luck@intel.com>
AuthorDate:    Thu, 07 Mar 2024 11:27:04 -08:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Tue, 26 Mar 2024 12:40:42 +01:00

x86/mce: Dynamically size space for machine check records

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-size 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).

  [ bp: Rename local var from tmpp to something more telling: gpool. ]

Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Sohil Mehta <sohil.mehta@intel.com>
Reviewed-by: Avadhut Naik <avadhut.naik@amd.com>
Link: https://lore.kernel.org/r/20240307192704.37213-1-tony.luck@intel.com
---
 arch/x86/kernel/cpu/mce/genpool.c | 40 ++++++++++++++++++------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/arch/x86/kernel/cpu/mce/genpool.c b/arch/x86/kernel/cpu/mce/genpool.c
index fbe8b61..4284749 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,22 +118,32 @@ int mce_gen_pool_add(struct mce *mce)
 
 static int mce_gen_pool_create(void)
 {
-	struct gen_pool *tmpp;
+	int mce_numrecords, mce_poolsz, order;
+	struct gen_pool *gpool;
 	int ret = -ENOMEM;
-
-	tmpp = gen_pool_create(ilog2(sizeof(struct mce_evt_llist)), -1);
-	if (!tmpp)
-		goto out;
-
-	ret = gen_pool_add(tmpp, (unsigned long)gen_pool_buf, MCE_POOLSZ, -1);
+	void *mce_pool;
+
+	order = order_base_2(sizeof(struct mce_evt_llist));
+	gpool = gen_pool_create(order, -1);
+	if (!gpool)
+		return ret;
+
+	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(gpool);
+		return ret;
+	}
+	ret = gen_pool_add(gpool, (unsigned long)mce_pool, mce_poolsz, -1);
 	if (ret) {
-		gen_pool_destroy(tmpp);
-		goto out;
+		gen_pool_destroy(gpool);
+		kfree(mce_pool);
+		return ret;
 	}
 
-	mce_evt_pool = tmpp;
+	mce_evt_pool = gpool;
 
-out:
 	return ret;
 }
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-26 12:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-07 19:27 [PATCH v3] x86/mce: Dynamically size space for machine check records Tony Luck
2024-03-11  5:38 ` Naik, Avadhut
2024-03-26 11:49 ` Borislav Petkov
2024-03-26 12:35 ` [tip: ras/core] " tip-bot2 for Tony Luck

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.