Move the CXL CPER handling paths out of ghes.c and into ghes_cper.c so the helpers can be reused. Update the public prototypes so GHES continues to call the relocated implementation.
Preserve the existing CXL record validation, FIFO handling, and locking unchanged. Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Ahmed Tiba <[email protected]> --- drivers/acpi/apei/ghes.c | 152 ----------------------------------------- drivers/acpi/apei/ghes_cper.c | 155 ++++++++++++++++++++++++++++++++++++++++++ include/acpi/ghes_cper.h | 11 +++ 3 files changed, 166 insertions(+), 152 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 2369bfcbfe88..7b460d6fa0d2 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -401,158 +401,6 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) #endif } -/* Room for 8 entries */ -#define CXL_CPER_PROT_ERR_FIFO_DEPTH 8 -static DEFINE_KFIFO(cxl_cper_prot_err_fifo, struct cxl_cper_prot_err_work_data, - CXL_CPER_PROT_ERR_FIFO_DEPTH); - -/* Synchronize schedule_work() with cxl_cper_prot_err_work changes */ -static DEFINE_RAW_SPINLOCK(cxl_cper_prot_err_work_lock); -struct work_struct *cxl_cper_prot_err_work; - -void cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err *prot_err, - int severity, u32 len) -{ -#ifdef CONFIG_ACPI_APEI_PCIEAER - struct cxl_cper_prot_err_work_data wd; - - if (cxl_cper_sec_prot_err_valid(prot_err, len)) - return; - - guard(raw_spinlock_irqsave)(&cxl_cper_prot_err_work_lock); - - if (!cxl_cper_prot_err_work) - return; - - if (cxl_cper_setup_prot_err_work_data(&wd, prot_err, severity)) - return; - - if (!kfifo_put(&cxl_cper_prot_err_fifo, wd)) { - pr_err_ratelimited("CXL CPER kfifo overflow\n"); - return; - } - - schedule_work(cxl_cper_prot_err_work); -#endif -} -EXPORT_SYMBOL_FOR_MODULES(cxl_cper_post_prot_err, "acpi_extlog"); - -void cxl_cper_register_prot_err_work(struct work_struct *work) -{ - guard(raw_spinlock_irqsave)(&cxl_cper_prot_err_work_lock); - - if (WARN_ONCE(cxl_cper_prot_err_work, - "CPER-CXL kfifo consumer already registered\n")) - return; - cxl_cper_prot_err_work = work; -} -EXPORT_SYMBOL_FOR_MODULES(cxl_cper_register_prot_err_work, "cxl_core"); - -void cxl_cper_unregister_prot_err_work(void) -{ - struct work_struct *old; - - scoped_guard(raw_spinlock_irqsave, &cxl_cper_prot_err_work_lock) { - WARN_ONCE(!cxl_cper_prot_err_work, - "CPER-CXL kfifo consumer not registered on unregister\n"); - old = cxl_cper_prot_err_work; - cxl_cper_prot_err_work = NULL; - } - - if (old) - cancel_work_sync(old); - - /* Discard stale entries so they are not replayed on next module load */ - kfifo_reset(&cxl_cper_prot_err_fifo); -} -EXPORT_SYMBOL_FOR_MODULES(cxl_cper_unregister_prot_err_work, "cxl_core"); - -int cxl_cper_prot_err_kfifo_get(struct cxl_cper_prot_err_work_data *wd) -{ - return kfifo_get(&cxl_cper_prot_err_fifo, wd); -} -EXPORT_SYMBOL_FOR_MODULES(cxl_cper_prot_err_kfifo_get, "cxl_core"); - -/* Room for 8 entries for each of the 4 event log queues */ -#define CXL_CPER_FIFO_DEPTH 32 -DEFINE_KFIFO(cxl_cper_fifo, struct cxl_cper_work_data, CXL_CPER_FIFO_DEPTH); - -/* Synchronize schedule_work() with cxl_cper_work changes */ -static DEFINE_RAW_SPINLOCK(cxl_cper_work_lock); -struct work_struct *cxl_cper_work; - -static void cxl_cper_post_event(enum cxl_event_type event_type, - struct cxl_cper_event_rec *rec, u32 len) -{ - struct cxl_cper_work_data wd; - - if (len < sizeof(*rec)) { - pr_err(FW_WARN "CXL CPER section too small (%u)\n", len); - return; - } - - if (rec->hdr.length <= sizeof(rec->hdr) || - rec->hdr.length > sizeof(*rec)) { - pr_err(FW_WARN "CXL CPER Invalid section length (%u)\n", - rec->hdr.length); - return; - } - - if (!(rec->hdr.validation_bits & CPER_CXL_COMP_EVENT_LOG_VALID)) { - pr_err(FW_WARN "CXL CPER invalid event\n"); - return; - } - - guard(raw_spinlock_irqsave)(&cxl_cper_work_lock); - - if (!cxl_cper_work) - return; - - wd.event_type = event_type; - memcpy(&wd.rec, rec, sizeof(wd.rec)); - - if (!kfifo_put(&cxl_cper_fifo, wd)) { - pr_err_ratelimited("CXL CPER kfifo overflow\n"); - return; - } - - schedule_work(cxl_cper_work); -} - -int cxl_cper_register_work(struct work_struct *work) -{ - guard(raw_spinlock_irqsave)(&cxl_cper_work_lock); - if (WARN_ONCE(cxl_cper_work, - "CXL CPER kfifo consumer already registered\n")) - return -EINVAL; - - cxl_cper_work = work; - return 0; -} -EXPORT_SYMBOL_NS_GPL(cxl_cper_register_work, "CXL"); - -void cxl_cper_unregister_work(struct work_struct *work) -{ - scoped_guard(raw_spinlock_irqsave, &cxl_cper_work_lock) { - if (WARN_ONCE(cxl_cper_work != work, - "CXL CPER kfifo consumer mismatch on unregister\n")) - return; - cxl_cper_work = NULL; - } - - cancel_work_sync(work); - - /* Discard stale entries so they are not replayed on next module load */ - kfifo_reset(&cxl_cper_fifo); -} -EXPORT_SYMBOL_NS_GPL(cxl_cper_unregister_work, "CXL"); - -int cxl_cper_kfifo_get(struct cxl_cper_work_data *wd) -{ - return kfifo_get(&cxl_cper_fifo, wd); -} -EXPORT_SYMBOL_NS_GPL(cxl_cper_kfifo_get, "CXL"); - static void ghes_log_hwerr(int sev, guid_t *sec_type) { if (sev != GHES_SEV_RECOVERABLE) diff --git a/drivers/acpi/apei/ghes_cper.c b/drivers/acpi/apei/ghes_cper.c index 20826d9fb13e..2037046d9be8 100644 --- a/drivers/acpi/apei/ghes_cper.c +++ b/drivers/acpi/apei/ghes_cper.c @@ -12,9 +12,12 @@ * Author: Huang Ying <[email protected]> */ +#include <linux/aer.h> +#include <linux/cleanup.h> #include <linux/err.h> #include <linux/genalloc.h> #include <linux/io.h> +#include <linux/kfifo.h> #include <linux/kernel.h> #include <linux/math64.h> #include <linux/mm.h> @@ -350,6 +353,158 @@ void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata, schedule_work(&entry->work); } +/* Room for 8 entries */ +#define CXL_CPER_PROT_ERR_FIFO_DEPTH 8 +static DEFINE_KFIFO(cxl_cper_prot_err_fifo, struct cxl_cper_prot_err_work_data, + CXL_CPER_PROT_ERR_FIFO_DEPTH); + +/* Synchronize schedule_work() with cxl_cper_prot_err_work changes */ +static DEFINE_RAW_SPINLOCK(cxl_cper_prot_err_work_lock); +struct work_struct *cxl_cper_prot_err_work; + +void cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err *prot_err, + int severity, u32 len) +{ +#ifdef CONFIG_ACPI_APEI_PCIEAER + struct cxl_cper_prot_err_work_data wd; + + if (cxl_cper_sec_prot_err_valid(prot_err, len)) + return; + + guard(raw_spinlock_irqsave)(&cxl_cper_prot_err_work_lock); + + if (!cxl_cper_prot_err_work) + return; + + if (cxl_cper_setup_prot_err_work_data(&wd, prot_err, severity)) + return; + + if (!kfifo_put(&cxl_cper_prot_err_fifo, wd)) { + pr_err_ratelimited("CXL CPER kfifo overflow\n"); + return; + } + + schedule_work(cxl_cper_prot_err_work); +#endif +} +EXPORT_SYMBOL_FOR_MODULES(cxl_cper_post_prot_err, "acpi_extlog"); + +void cxl_cper_register_prot_err_work(struct work_struct *work) +{ + guard(raw_spinlock_irqsave)(&cxl_cper_prot_err_work_lock); + + if (WARN_ONCE(cxl_cper_prot_err_work, + "CPER-CXL kfifo consumer already registered\n")) + return; + cxl_cper_prot_err_work = work; +} +EXPORT_SYMBOL_FOR_MODULES(cxl_cper_register_prot_err_work, "cxl_core"); + +void cxl_cper_unregister_prot_err_work(void) +{ + struct work_struct *old; + + scoped_guard(raw_spinlock_irqsave, &cxl_cper_prot_err_work_lock) { + WARN_ONCE(!cxl_cper_prot_err_work, + "CPER-CXL kfifo consumer not registered on unregister\n"); + old = cxl_cper_prot_err_work; + cxl_cper_prot_err_work = NULL; + } + + if (old) + cancel_work_sync(old); + + /* Discard stale entries so they are not replayed on next module load */ + kfifo_reset(&cxl_cper_prot_err_fifo); +} +EXPORT_SYMBOL_FOR_MODULES(cxl_cper_unregister_prot_err_work, "cxl_core"); + +int cxl_cper_prot_err_kfifo_get(struct cxl_cper_prot_err_work_data *wd) +{ + return kfifo_get(&cxl_cper_prot_err_fifo, wd); +} +EXPORT_SYMBOL_FOR_MODULES(cxl_cper_prot_err_kfifo_get, "cxl_core"); + +/* Room for 8 entries for each of the 4 event log queues */ +#define CXL_CPER_FIFO_DEPTH 32 +DEFINE_KFIFO(cxl_cper_fifo, struct cxl_cper_work_data, CXL_CPER_FIFO_DEPTH); + +/* Synchronize schedule_work() with cxl_cper_work changes */ +static DEFINE_RAW_SPINLOCK(cxl_cper_work_lock); +struct work_struct *cxl_cper_work; + +void cxl_cper_post_event(enum cxl_event_type event_type, + struct cxl_cper_event_rec *rec, u32 len) +{ + struct cxl_cper_work_data wd; + + if (len < sizeof(*rec)) { + pr_err(FW_WARN "CXL CPER section too small (%u)\n", len); + return; + } + + if (rec->hdr.length <= sizeof(rec->hdr) || + rec->hdr.length > sizeof(*rec)) { + pr_err(FW_WARN "CXL CPER Invalid section length (%u)\n", + rec->hdr.length); + return; + } + + if (!(rec->hdr.validation_bits & CPER_CXL_COMP_EVENT_LOG_VALID)) { + pr_err(FW_WARN "CXL CPER invalid event\n"); + return; + } + + guard(raw_spinlock_irqsave)(&cxl_cper_work_lock); + + if (!cxl_cper_work) + return; + + wd.event_type = event_type; + memcpy(&wd.rec, rec, sizeof(wd.rec)); + + if (!kfifo_put(&cxl_cper_fifo, wd)) { + pr_err_ratelimited("CXL CPER kfifo overflow\n"); + return; + } + + schedule_work(cxl_cper_work); +} + +int cxl_cper_register_work(struct work_struct *work) +{ + guard(raw_spinlock_irqsave)(&cxl_cper_work_lock); + if (WARN_ONCE(cxl_cper_work, + "CXL CPER kfifo consumer already registered\n")) + return -EINVAL; + + cxl_cper_work = work; + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_cper_register_work, "CXL"); + +void cxl_cper_unregister_work(struct work_struct *work) +{ + scoped_guard(raw_spinlock_irqsave, &cxl_cper_work_lock) { + if (WARN_ONCE(cxl_cper_work != work, + "CXL CPER kfifo consumer mismatch on unregister\n")) + return; + cxl_cper_work = NULL; + } + + cancel_work_sync(work); + + /* Discard stale entries so they are not replayed on next module load */ + kfifo_reset(&cxl_cper_fifo); +} +EXPORT_SYMBOL_NS_GPL(cxl_cper_unregister_work, "CXL"); + +int cxl_cper_kfifo_get(struct cxl_cper_work_data *wd) +{ + return kfifo_get(&cxl_cper_fifo, wd); +} +EXPORT_SYMBOL_NS_GPL(cxl_cper_kfifo_get, "CXL"); + /* * GHES error status reporting throttle, to report more kinds of * errors, instead of just most frequently occurred errors. diff --git a/include/acpi/ghes_cper.h b/include/acpi/ghes_cper.h index 38f8e0782b9e..5821eca46d63 100644 --- a/include/acpi/ghes_cper.h +++ b/include/acpi/ghes_cper.h @@ -20,6 +20,7 @@ #include <acpi/ghes.h> #include <asm/fixmap.h> +#include <cxl/event.h> #define GHES_PFX "GHES: " @@ -106,5 +107,15 @@ void ghes_estatus_cache_add(struct acpi_hest_generic *generic, struct acpi_hest_generic_status *estatus); void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata, int sev); +void cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err *prot_err, + int severity, u32 len); +void cxl_cper_register_prot_err_work(struct work_struct *work); +void cxl_cper_unregister_prot_err_work(void); +int cxl_cper_prot_err_kfifo_get(struct cxl_cper_prot_err_work_data *wd); +void cxl_cper_post_event(enum cxl_event_type event_type, + struct cxl_cper_event_rec *rec, u32 len); +int cxl_cper_register_work(struct work_struct *work); +void cxl_cper_unregister_work(struct work_struct *work); +int cxl_cper_kfifo_get(struct cxl_cper_work_data *wd); #endif /* ACPI_APEI_GHES_CPER_H */ -- 2.43.0
