x86/mcheck: allow varying bank counts per CPU
PATCH 1/1 x86/mcheck: allow varying bank counts per CPU
In mca_cap_init function,the mcabanks_alloc allocates and initializes an mca_banks structure for managing MCA banks, setting up a bank map and storing the specified or default number of banks.
After this we will call mcabanks_set(i, mca_allbanks); The mcabanks_set function sets a specific bit in the bank_map of an mca_banks structure, provided the structure, its bank_map, and the bit index are valid.
At the end, we will call mcabanks_free(xchg(&mca_allbanks, all));
This function is thread safe and does below:
1. Atomically exchanges the value of "mca_allbanks" with "all"
2. Returns the old value that was previously in "mca_allbanks"
So, when we will call mcabanks_free , that will free the memory.
The problem is that mcabanks_set(i, mca_allbanks) function is updating mca_allbanks which will be freed via mcabanks_free later. This means new mca_allbanks instance("all") will never get chance to update it's bank_map.
Due to this when we will collect log from mcheck_mca_logout function , the condition "if ( !mcabanks_test(i, bankmask) )" will always fails and MCA logs will not be collected for any bank.
The fix is to solve this problem.
--- xen/arch/x86/cpu/mcheck/mce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/cpu/mcheck/mce.c +1 -1
@@ -663,7 +663,7 @@ static int mca_cap_init(void)if ( !all )return -ENOMEM ;for ( i =0 ; i < nr; i++ ) -mcabanks_set (i, mca_allbanks); +mcabanks_set (i, all);mcabanks_free (xchg (&mca_allbanks, all)); }
Signature · 1 line
2.17.1
Quoted 22 lines · Soham Dandapat
In
mca_cap_initfunction,themcabanks_allocallocates and initializes anmca_banksstructure for managing MCA banks, setting up a bank map and storing the specified or default number of banks.After this we will call
mcabanks_set(i, mca_allbanks); Themcabanks_setfunction sets a specific bit in thebank_mapof anmca_banksstructure, provided the structure, itsbank_map, and the bit index are valid.At the end, we will call
mcabanks_free(xchg(&mca_allbanks, all));
This function is thread safe and does below:
1. Atomically exchanges the value of "mca_allbanks" with "all"
2. Returns the old value that was previously in "mca_allbanks"
So, when we will callmcabanks_free, that will free the memory.The problem is that
mcabanks_set(i, mca_allbanks)function is updatingmca_allbankswhich will be freed viamcabanks_freelater. This means newmca_allbanksinstance("all")will never get chance to update it'sbank_map.
Quoted 8 lines
Due to this when we will collect log from
mcheck_mca_logoutfunction , the condition "if ( !mcabanks_test(i, bankmask) )" will always fails and MCA logs will not be collected for any bank.The fix is to solve this problem.
Fixes 560cf418c845 ("x86/mcheck: allow varying bank counts per CPU")Signed-off-by Soham Dandapat <[email protected]>
Maybe the patch subject should be "x86/mcheck: Fix mca bank initialization" to differentiate from the Fixes commit?
Thanks,
Jason
Jan Beulich
Reviewed-byQuoted 31 lines · Jason Andryuk
Quoted 28 lines · Soham Dandapat
In
mca_cap_initfunction,themcabanks_allocallocates and initializes anmca_banksstructure for managing MCA banks, setting up a bank map and storing the specified or default number of banks.After this we will call
mcabanks_set(i, mca_allbanks); Themcabanks_setfunction sets a specific bit in thebank_mapof anmca_banksstructure, provided the structure, itsbank_map, and the bit index are valid.At the end, we will call
mcabanks_free(xchg(&mca_allbanks, all));
This function is thread safe and does below:
1. Atomically exchanges the value of "mca_allbanks" with "all"
2. Returns the old value that was previously in "mca_allbanks"
So, when we will callmcabanks_free, that will free the memory.The problem is that
mcabanks_set(i, mca_allbanks)function is updatingmca_allbankswhich will be freed viamcabanks_freelater. This means newmca_allbanksinstance("all")will never get chance to update it'sbank_map.Due to this when we will collect log from
mcheck_mca_logoutfunction , the condition "if ( !mcabanks_test(i, bankmask) )" will always fails and MCA logs will not be collected for any bank.The fix is to solve this problem.
Quoted 7 lines
Quoted 2 lines
Fixes 560cf418c845 ("x86/mcheck: allow varying bank counts per CPU")Signed-off-by Soham Dandapat <[email protected]>Reviewed-by Jason Andryuk <[email protected]>Maybe the patch subject should be "x86/mcheck: Fix mca bank initialization" to differentiate from the Fixes commit?
That's still more generic than wanted. How about "x86/mcheck: fix mca_allbanks updating"? With a more concise title (which can be adjusted while committing, so long as there's agreement):
Jan
Quoted 37 lines · Jan Beulich
Quoted 36 lines · Jason Andryuk
Quoted 22 lines · Soham Dandapat
In
mca_cap_initfunction,themcabanks_allocallocates and initializes anmca_banksstructure for managing MCA banks, setting up a bank map and storing the specified or default number of banks.After this we will call
mcabanks_set(i, mca_allbanks); Themcabanks_setfunction sets a specific bit in thebank_mapof anmca_banksstructure, provided the structure, itsbank_map, and the bit index are valid.At the end, we will call
mcabanks_free(xchg(&mca_allbanks, all));
This function is thread safe and does below:
1. Atomically exchanges the value of "mca_allbanks" with "all"
2. Returns the old value that was previously in "mca_allbanks"
So, when we will callmcabanks_free, that will free the memory.The problem is that
mcabanks_set(i, mca_allbanks)function is updatingmca_allbankswhich will be freed viamcabanks_freelater. This means newmca_allbanksinstance("all")will never get chance to update it'sbank_map.Quoted 8 lines
Due to this when we will collect log from
mcheck_mca_logoutfunction , the condition "if ( !mcabanks_test(i, bankmask) )" will always fails and MCA logs will not be collected for any bank.The fix is to solve this problem.
Fixes 560cf418c845 ("x86/mcheck: allow varying bank counts per CPU")Signed-off-by Soham Dandapat <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
Quoted 7 lines
Quoted 2 lines
Maybe the patch subject should be "x86/mcheck: Fix mca bank initialization" to differentiate from the Fixes commit?
That's still more generic than wanted. How about "x86/mcheck: fix
mca_allbanksupdating"? With a more concise title (which can be adjusted while committing, so long as there's agreement):Reviewed-by Jan Beulich <[email protected]>
Your suggestion sounds good to me.
Thanks,
Jason
[Public]
Hi Jan , Jason ,
Suggestion sounds good to me . I am ok with that .
Thanks,
Soham
-----Original Message-----
From: Jason Andryuk <[email protected]>
Sent: Monday, September 8, 2025 7:10 PM
To: Jan Beulich <[email protected]>; Dandapat, Soham <[email protected]>
Cc: Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; [email protected]
Subject: Re: [PATCH] x86/mcheck: allow varying bank counts per CPU
Quoted 37 lines · Jan Beulich
Quoted 36 lines · Jason Andryuk
Quoted 25 lines · Soham Dandapat
In
mca_cap_initfunction,themcabanks_allocallocates and initializes anmca_banksstructure for managing MCA banks, setting up a bank map and storing the specified or default number of banks.After this we will call
mcabanks_set(i, mca_allbanks); Themcabanks_setfunction sets a specific bit in thebank_mapof anmca_banksstructure, provided the structure, itsbank_map, and the bit index are valid.At the end, we will call
mcabanks_free(xchg(&mca_allbanks, all)); This function is thread safe and does below:
1. Atomically exchanges the value of "mca_allbanks" with "all"
2. Returns the old value that was previously in "mca_allbanks"
So, when we will callmcabanks_free, that will free the memory.The problem is that
mcabanks_set(i, mca_allbanks)function is updatingmca_allbankswhich will be freed viamcabanks_freelater. This means newmca_allbanksinstance("all")will never get chance to update it'sbank_map.Due to this when we will collect log from
mcheck_mca_logoutfunction , the condition "if ( !mcabanks_test(i, bankmask) )" will always fails and MCA logs will not be collected for any bank.Quoted 5 lines
The fix is to solve this problem.
Fixes 560cf418c845 ("x86/mcheck: allow varying bank counts perCPU")
Signed-off-by Soham Dandapat <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
Quoted 7 lines
Quoted 2 lines
Maybe the patch subject should be "x86/mcheck: Fix mca bank initialization" to differentiate from the Fixes commit?
That's still more generic than wanted. How about "x86/mcheck: fix
mca_allbanksupdating"? With a more concise title (which can be adjusted while committing, so long as there's agreement):Reviewed-by Jan Beulich <[email protected]>
Your suggestion sounds good to me.
Thanks,
Jason