Skip to content

Commit 671a794

Browse files
weiny2djbw
authored andcommitted
acpi/ghes: Process CXL Component Events
BIOS can configure memory devices as firmware first. This will send CXL events to the firmware instead of the OS. The firmware can then send these events to the OS via UEFI. UEFI v2.10 section N.2.14 defines a Common Platform Error Record (CPER) format for CXL Component Events. The format is mostly the same as the CXL Common Event Record Format. The difference is the use of a GUID in the Section Type rather than a UUID as part of the event itself. Add GHES support to detect CXL CPER records and call a registered callback with the event. A notifier chain was considered for the callback but the complexity did not justify the use case as only the CXL subsystem requires this event. Enforce that only one callback can be registered at any time. Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Rafael J. Wysocki <rafael@kernel.org> Signed-off-by: Ira Weiny <ira.weiny@intel.com> Link: https://lore.kernel.org/r/20231220-cxl-cper-v5-7-1bb8a4ca2c7a@intel.com [djbw: fixup checkpatch errors] Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Acked-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent f9c6833 commit 671a794

2 files changed

Lines changed: 139 additions & 0 deletions

File tree

drivers/acpi/apei/ghes.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/interrupt.h>
2727
#include <linux/timer.h>
2828
#include <linux/cper.h>
29+
#include <linux/cxl-event.h>
2930
#include <linux/platform_device.h>
3031
#include <linux/mutex.h>
3132
#include <linux/ratelimit.h>
@@ -657,6 +658,78 @@ static void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata,
657658
schedule_work(&entry->work);
658659
}
659660

661+
/*
662+
* Only a single callback can be registered for CXL CPER events.
663+
*/
664+
static DECLARE_RWSEM(cxl_cper_rw_sem);
665+
static cxl_cper_callback cper_callback;
666+
667+
/* CXL Event record UUIDs are formatted as GUIDs and reported in section type */
668+
669+
/*
670+
* General Media Event Record
671+
* CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
672+
*/
673+
#define CPER_SEC_CXL_GEN_MEDIA_GUID \
674+
GUID_INIT(0xfbcd0a77, 0xc260, 0x417f, \
675+
0x85, 0xa9, 0x08, 0x8b, 0x16, 0x21, 0xeb, 0xa6)
676+
677+
/*
678+
* DRAM Event Record
679+
* CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44
680+
*/
681+
#define CPER_SEC_CXL_DRAM_GUID \
682+
GUID_INIT(0x601dcbb3, 0x9c06, 0x4eab, \
683+
0xb8, 0xaf, 0x4e, 0x9b, 0xfb, 0x5c, 0x96, 0x24)
684+
685+
/*
686+
* Memory Module Event Record
687+
* CXL rev 3.0 section 8.2.9.2.1.3; Table 8-45
688+
*/
689+
#define CPER_SEC_CXL_MEM_MODULE_GUID \
690+
GUID_INIT(0xfe927475, 0xdd59, 0x4339, \
691+
0xa5, 0x86, 0x79, 0xba, 0xb1, 0x13, 0xb7, 0x74)
692+
693+
static void cxl_cper_post_event(enum cxl_event_type event_type,
694+
struct cxl_cper_event_rec *rec)
695+
{
696+
if (rec->hdr.length <= sizeof(rec->hdr) ||
697+
rec->hdr.length > sizeof(*rec)) {
698+
pr_err(FW_WARN "CXL CPER Invalid section length (%u)\n",
699+
rec->hdr.length);
700+
return;
701+
}
702+
703+
if (!(rec->hdr.validation_bits & CPER_CXL_COMP_EVENT_LOG_VALID)) {
704+
pr_err(FW_WARN "CXL CPER invalid event\n");
705+
return;
706+
}
707+
708+
guard(rwsem_read)(&cxl_cper_rw_sem);
709+
if (cper_callback)
710+
cper_callback(event_type, rec);
711+
}
712+
713+
int cxl_cper_register_callback(cxl_cper_callback callback)
714+
{
715+
guard(rwsem_write)(&cxl_cper_rw_sem);
716+
if (cper_callback)
717+
return -EINVAL;
718+
cper_callback = callback;
719+
return 0;
720+
}
721+
EXPORT_SYMBOL_NS_GPL(cxl_cper_register_callback, CXL);
722+
723+
int cxl_cper_unregister_callback(cxl_cper_callback callback)
724+
{
725+
guard(rwsem_write)(&cxl_cper_rw_sem);
726+
if (callback != cper_callback)
727+
return -EINVAL;
728+
cper_callback = NULL;
729+
return 0;
730+
}
731+
EXPORT_SYMBOL_NS_GPL(cxl_cper_unregister_callback, CXL);
732+
660733
static bool ghes_do_proc(struct ghes *ghes,
661734
const struct acpi_hest_generic_status *estatus)
662735
{
@@ -690,6 +763,22 @@ static bool ghes_do_proc(struct ghes *ghes,
690763
}
691764
else if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) {
692765
queued = ghes_handle_arm_hw_error(gdata, sev);
766+
} else if (guid_equal(sec_type, &CPER_SEC_CXL_GEN_MEDIA_GUID)) {
767+
struct cxl_cper_event_rec *rec =
768+
acpi_hest_get_payload(gdata);
769+
770+
cxl_cper_post_event(CXL_CPER_EVENT_GEN_MEDIA, rec);
771+
} else if (guid_equal(sec_type, &CPER_SEC_CXL_DRAM_GUID)) {
772+
struct cxl_cper_event_rec *rec =
773+
acpi_hest_get_payload(gdata);
774+
775+
cxl_cper_post_event(CXL_CPER_EVENT_DRAM, rec);
776+
} else if (guid_equal(sec_type,
777+
&CPER_SEC_CXL_MEM_MODULE_GUID)) {
778+
struct cxl_cper_event_rec *rec =
779+
acpi_hest_get_payload(gdata);
780+
781+
cxl_cper_post_event(CXL_CPER_EVENT_MEM_MODULE, rec);
693782
} else {
694783
void *err = acpi_hest_get_payload(gdata);
695784

include/linux/cxl-event.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,54 @@ struct cxl_event_record_raw {
107107
union cxl_event event;
108108
} __packed;
109109

110+
enum cxl_event_type {
111+
CXL_CPER_EVENT_GEN_MEDIA,
112+
CXL_CPER_EVENT_DRAM,
113+
CXL_CPER_EVENT_MEM_MODULE,
114+
};
115+
116+
#define CPER_CXL_DEVICE_ID_VALID BIT(0)
117+
#define CPER_CXL_DEVICE_SN_VALID BIT(1)
118+
#define CPER_CXL_COMP_EVENT_LOG_VALID BIT(2)
119+
struct cxl_cper_event_rec {
120+
struct {
121+
u32 length;
122+
u64 validation_bits;
123+
struct cper_cxl_event_devid {
124+
u16 vendor_id;
125+
u16 device_id;
126+
u8 func_num;
127+
u8 device_num;
128+
u8 bus_num;
129+
u16 segment_num;
130+
u16 slot_num; /* bits 2:0 reserved */
131+
u8 reserved;
132+
} __packed device_id;
133+
struct cper_cxl_event_sn {
134+
u32 lower_dw;
135+
u32 upper_dw;
136+
} __packed dev_serial_num;
137+
} __packed hdr;
138+
139+
union cxl_event event;
140+
} __packed;
141+
142+
typedef void (*cxl_cper_callback)(enum cxl_event_type type,
143+
struct cxl_cper_event_rec *rec);
144+
145+
#ifdef CONFIG_ACPI_APEI_GHES
146+
int cxl_cper_register_callback(cxl_cper_callback callback);
147+
int cxl_cper_unregister_callback(cxl_cper_callback callback);
148+
#else
149+
static inline int cxl_cper_register_callback(cxl_cper_callback callback)
150+
{
151+
return 0;
152+
}
153+
154+
static inline int cxl_cper_unregister_callback(cxl_cper_callback callback)
155+
{
156+
return 0;
157+
}
158+
#endif
159+
110160
#endif /* _LINUX_CXL_EVENT_H */

0 commit comments

Comments
 (0)