Carve the CPER helper macros out of ghes.c and place them in a private header so they can be shared with upcoming helper files.
Move the vendor record entry declaration and the prototypes for the CPER read and clear helpers along with ghes_new() and ghes_fini() into the same header. This requires dropping their local static visibility in ghes.c. Also synchronize ghes_proc_irq_work during ghes_remove() to avoid a use-after-free. Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Ahmed Tiba <[email protected]> --- drivers/acpi/apei/ghes.c | 95 +++++++++---------------------------------- include/acpi/ghes_cper.h | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 76 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 3236a3ce79d6..c73a316644e8 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -49,6 +49,7 @@ #include <acpi/actbl1.h> #include <acpi/ghes.h> +#include <acpi/ghes_cper.h> #include <acpi/apei.h> #include <asm/fixmap.h> #include <asm/tlbflush.h> @@ -57,40 +58,6 @@ #include "apei-internal.h" -#define GHES_PFX "GHES: " - -#define GHES_ESTATUS_MAX_SIZE 65536 -#define GHES_ESOURCE_PREALLOC_MAX_SIZE 65536 - -#define GHES_ESTATUS_POOL_MIN_ALLOC_ORDER 3 - -/* This is just an estimation for memory pool allocation */ -#define GHES_ESTATUS_CACHE_AVG_SIZE 512 - -#define GHES_ESTATUS_CACHES_SIZE 4 - -#define GHES_ESTATUS_IN_CACHE_MAX_NSEC 10000000000ULL -/* Prevent too many caches are allocated because of RCU */ -#define GHES_ESTATUS_CACHE_ALLOCED_MAX (GHES_ESTATUS_CACHES_SIZE * 3 / 2) - -#define GHES_ESTATUS_CACHE_LEN(estatus_len) \ - (sizeof(struct ghes_estatus_cache) + (estatus_len)) -#define GHES_ESTATUS_FROM_CACHE(estatus_cache) \ - ((struct acpi_hest_generic_status *) \ - ((struct ghes_estatus_cache *)(estatus_cache) + 1)) - -#define GHES_ESTATUS_NODE_LEN(estatus_len) \ - (sizeof(struct ghes_estatus_node) + (estatus_len)) -#define GHES_ESTATUS_FROM_NODE(estatus_node) \ - ((struct acpi_hest_generic_status *) \ - ((struct ghes_estatus_node *)(estatus_node) + 1)) - -#define GHES_VENDOR_ENTRY_LEN(gdata_len) \ - (sizeof(struct ghes_vendor_record_entry) + (gdata_len)) -#define GHES_GDATA_FROM_VENDOR_ENTRY(vendor_entry) \ - ((struct acpi_hest_generic_data *) \ - ((struct ghes_vendor_record_entry *)(vendor_entry) + 1)) - /* * NMI-like notifications vary by architecture, before the compiler can prune * unused static functions it needs a value for these enums. @@ -102,25 +69,6 @@ static ATOMIC_NOTIFIER_HEAD(ghes_report_chain); -static inline bool is_hest_type_generic_v2(struct ghes *ghes) -{ - return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2; -} - -/* - * A platform may describe one error source for the handling of synchronous - * errors (e.g. MCE or SEA), or for handling asynchronous errors (e.g. SCI - * or External Interrupt). On x86, the HEST notifications are always - * asynchronous, so only SEA on ARM is delivered as a synchronous - * notification. - */ -static inline bool is_hest_sync_notify(struct ghes *ghes) -{ - u8 notify_type = ghes->generic->notify.type; - - return notify_type == ACPI_HEST_NOTIFY_SEA; -} - /* * This driver isn't really modular, however for the time being, * continuing to use module_param is the easiest way to remain @@ -165,12 +113,6 @@ static DEFINE_MUTEX(ghes_devs_mutex); */ static DEFINE_SPINLOCK(ghes_notify_lock_irq); -struct ghes_vendor_record_entry { - struct work_struct work; - int error_severity; - char vendor_record[]; -}; - static struct gen_pool *ghes_estatus_pool; static struct ghes_estatus_cache __rcu *ghes_estatus_caches[GHES_ESTATUS_CACHES_SIZE]; @@ -266,7 +208,7 @@ static void ghes_ack_error(struct acpi_hest_generic_v2 *gv2) apei_write(val, &gv2->read_ack_register); } -static struct ghes *ghes_new(struct acpi_hest_generic *generic) +struct ghes *ghes_new(struct acpi_hest_generic *generic) { struct ghes *ghes; unsigned int error_block_length; @@ -313,7 +255,7 @@ static struct ghes *ghes_new(struct acpi_hest_generic *generic) return ERR_PTR(rc); } -static void ghes_fini(struct ghes *ghes) +void ghes_fini(struct ghes *ghes) { kfree(ghes->estatus); apei_unmap_generic_address(&ghes->generic->error_status_address); @@ -363,8 +305,8 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, } /* Check the top-level record header has an appropriate size. */ -static int __ghes_check_estatus(struct ghes *ghes, - struct acpi_hest_generic_status *estatus) +int __ghes_check_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus) { u32 len = cper_estatus_len(estatus); u32 max_len = min(ghes->generic->error_block_length, @@ -389,9 +331,9 @@ static int __ghes_check_estatus(struct ghes *ghes, } /* Read the CPER block, returning its address, and header in estatus. */ -static int __ghes_peek_estatus(struct ghes *ghes, - struct acpi_hest_generic_status *estatus, - u64 *buf_paddr, enum fixed_addresses fixmap_idx) +int __ghes_peek_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr, enum fixed_addresses fixmap_idx) { struct acpi_hest_generic *g = ghes->generic; int rc; @@ -400,7 +342,7 @@ static int __ghes_peek_estatus(struct ghes *ghes, if (rc) { *buf_paddr = 0; pr_warn_ratelimited(FW_WARN GHES_PFX -"Failed to read error status block address for hardware error source: %d.\n", + "Failed to read error status block address for hardware error source: %d.\n", g->header.source_id); return -EIO; } @@ -417,9 +359,9 @@ static int __ghes_peek_estatus(struct ghes *ghes, return 0; } -static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus, - u64 buf_paddr, enum fixed_addresses fixmap_idx, - size_t buf_len) +int __ghes_read_estatus(struct acpi_hest_generic_status *estatus, + u64 buf_paddr, enum fixed_addresses fixmap_idx, + size_t buf_len) { ghes_copy_tofrom_phys(estatus, buf_paddr, buf_len, 1, fixmap_idx); if (cper_estatus_check(estatus)) { @@ -431,9 +373,9 @@ static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus, return 0; } -static int ghes_read_estatus(struct ghes *ghes, - struct acpi_hest_generic_status *estatus, - u64 *buf_paddr, enum fixed_addresses fixmap_idx) +int ghes_read_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr, enum fixed_addresses fixmap_idx) { int rc; @@ -449,9 +391,9 @@ static int ghes_read_estatus(struct ghes *ghes, cper_estatus_len(estatus)); } -static void ghes_clear_estatus(struct ghes *ghes, - struct acpi_hest_generic_status *estatus, - u64 buf_paddr, enum fixed_addresses fixmap_idx) +void ghes_clear_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 buf_paddr, enum fixed_addresses fixmap_idx) { estatus->block_status = 0; @@ -1852,6 +1794,7 @@ static void ghes_remove(struct platform_device *ghes_dev) break; } + irq_work_sync(&ghes_proc_irq_work); ghes_fini(ghes); mutex_lock(&ghes_devs_mutex); diff --git a/include/acpi/ghes_cper.h b/include/acpi/ghes_cper.h new file mode 100644 index 000000000000..4649e3140888 --- /dev/null +++ b/include/acpi/ghes_cper.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * GHES declarations used by both the ACPI APEI GHES driver + * and the firmware-first CPER provider. + * + * These declarations lets GHES and other firmware-first error sources use + * the same helper so the non-ACPI path follows the same + * behavior as GHES instead of carrying a separate copy. + * + * Derived from the ACPI APEI GHES driver. + * + * Copyright 2010,2011 Intel Corp. + * Author: Huang Ying <[email protected]> + */ + +#ifndef ACPI_APEI_GHES_CPER_H +#define ACPI_APEI_GHES_CPER_H + +#include <linux/workqueue.h> + +#include <acpi/ghes.h> +#include <asm/fixmap.h> + +#define GHES_PFX "GHES: " + +#define GHES_ESTATUS_MAX_SIZE 65536 +#define GHES_ESOURCE_PREALLOC_MAX_SIZE 65536 + +#define GHES_ESTATUS_POOL_MIN_ALLOC_ORDER 3 + +/* This is just an estimation for memory pool allocation */ +#define GHES_ESTATUS_CACHE_AVG_SIZE 512 + +#define GHES_ESTATUS_CACHES_SIZE 4 + +#define GHES_ESTATUS_IN_CACHE_MAX_NSEC 10000000000ULL +/* Prevent too many caches are allocated because of RCU */ +#define GHES_ESTATUS_CACHE_ALLOCED_MAX (GHES_ESTATUS_CACHES_SIZE * 3 / 2) + +#define GHES_ESTATUS_CACHE_LEN(estatus_len) \ + (sizeof(struct ghes_estatus_cache) + (estatus_len)) +#define GHES_ESTATUS_FROM_CACHE(estatus_cache) \ + ((struct acpi_hest_generic_status *) \ + ((struct ghes_estatus_cache *)(estatus_cache) + 1)) + +#define GHES_ESTATUS_NODE_LEN(estatus_len) \ + (sizeof(struct ghes_estatus_node) + (estatus_len)) +#define GHES_ESTATUS_FROM_NODE(estatus_node) \ + ((struct acpi_hest_generic_status *) \ + ((struct ghes_estatus_node *)(estatus_node) + 1)) + +#define GHES_VENDOR_ENTRY_LEN(gdata_len) \ + (sizeof(struct ghes_vendor_record_entry) + (gdata_len)) +#define GHES_GDATA_FROM_VENDOR_ENTRY(vendor_entry) \ + ((struct acpi_hest_generic_data *) \ + ((struct ghes_vendor_record_entry *)(vendor_entry) + 1)) + +static inline bool is_hest_type_generic_v2(struct ghes *ghes) +{ + return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2; +} + +/* + * A platform may describe one error source for the handling of synchronous + * errors (e.g. MCE or SEA), or for handling asynchronous errors (e.g. SCI + * or External Interrupt). On x86, the HEST notifications are always + * asynchronous, so only SEA on ARM is delivered as a synchronous + * notification. + */ +static inline bool is_hest_sync_notify(struct ghes *ghes) +{ + u8 notify_type = ghes->generic->notify.type; + + return notify_type == ACPI_HEST_NOTIFY_SEA; +} + +struct ghes_vendor_record_entry { + struct work_struct work; + int error_severity; + char vendor_record[]; +}; + +#ifdef CONFIG_ACPI_APEI +struct ghes *ghes_new(struct acpi_hest_generic *generic); +void ghes_fini(struct ghes *ghes); + +int ghes_read_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr, enum fixed_addresses fixmap_idx); +void ghes_clear_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 buf_paddr, enum fixed_addresses fixmap_idx); +int __ghes_peek_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr, enum fixed_addresses fixmap_idx); +int __ghes_check_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus); +int __ghes_read_estatus(struct acpi_hest_generic_status *estatus, + u64 buf_paddr, enum fixed_addresses fixmap_idx, + size_t buf_len); +#endif + +#endif /* ACPI_APEI_GHES_CPER_H */ -- 2.43.0
