On Tue, 17 Nov 2026 12:10:11 +0100
Pierre Gondois <[email protected]> wrote:

> Prepare for reporting CPER Memory Error Section 2 records through MCE
> by extracting apei_mce_report_mem_error_common().
> 
> No functional change.
> 
> Signed-off-by: Pierre Gondois <[email protected]>
One curious question + trivial comment inline.

Otherwise, this is a simple refactor and seems clean to me.
Reviewed-by: Jonathan Cameron <[email protected]>

> ---
>  arch/x86/kernel/cpu/mce/apei.c | 31 +++++++++++++++++--------------
>  1 file changed, 17 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/mce/apei.c b/arch/x86/kernel/cpu/mce/apei.c
> index 0a89947e47bc8..b993ac78a3b36 100644
> --- a/arch/x86/kernel/cpu/mce/apei.c
> +++ b/arch/x86/kernel/cpu/mce/apei.c
> @@ -26,24 +26,15 @@
>  
>  #include "internal.h"
>  
> -void apei_mce_report_mem_error(int severity, struct cper_sec_mem_err 
> *mem_err)
> +static void apei_mce_report_mem_error_common(int severity, u64 physical_addr,
> +                                          u64 physical_addr_mask)
>  {
>       struct mce_hw_err err;
>       struct mce *m;
>       int lsb;
>  
> -     if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
> -             return;
> -
> -     /*
> -      * Even if the ->validation_bits are set for address mask,
> -      * to be extra safe, check and reject an error radius '0',
> -      * and fall back to the default page size.
> -      */
> -     if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK)
> -             lsb = find_first_bit((void *)&mem_err->physical_addr_mask, 
> PAGE_SHIFT);
> -     else
> -             lsb = PAGE_SHIFT;
> +     /* Missing or zero masks default to page granularity. */
> +     lsb = find_first_bit((void *)&physical_addr_mask, PAGE_SHIFT);

Silly question.  What stops it being bigger than a page?  I appreciate you
aren't changing what is already here but it made me curious.  It's 8 bytes
so limiting it to page size seems odd.

That larger usecase came up last year for how to handle error injection
into a VM that was running smaller pages than the host.

I guess on x86 it simply isn't ever bigger than one page?


>  
>       mce_prep_record(&err);
>       m = &err.m;
> @@ -60,9 +51,21 @@ void apei_mce_report_mem_error(int severity, struct 
> cper_sec_mem_err *mem_err)
>               m->tsc = rdtsc();
>       }
>  
> -     m->addr = mem_err->physical_addr;
> +     m->addr = physical_addr;
>       mce_log(&err);
>  }
> +
> +void apei_mce_report_mem_error(int severity, struct cper_sec_mem_err 
> *mem_err)
> +{
> +     u64 mask = 0;
> +
> +     if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
> +             return;

I'd add a blank line here given that return is a mite hard to spot.

> +     if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK)
> +             mask = mem_err->physical_addr_mask;
> +
> +     apei_mce_report_mem_error_common(severity, mem_err->physical_addr, 
> mask);
> +}
>  EXPORT_SYMBOL_GPL(apei_mce_report_mem_error);
>  
>  int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 
> lapic_id)


Reply via email to