2 * MCE event pool management in MCE context
4 * Copyright (C) 2015 Intel Corp.
5 * Author: Chen, Gong <gong.chen@linux.intel.com>
7 * This file is licensed under GPLv2.
11 #include <linux/genalloc.h>
12 #include <linux/llist.h>
13 #include "mce-internal.h"
16 * printk() is not safe in MCE context. This is a lock-less memory allocator
17 * used to save error information organized in a lock-less list.
19 * This memory pool is only to be used to save MCE records in MCE context.
20 * MCE events are rare, so a fixed size memory pool should be enough. Use
21 * 2 pages to save MCE events for now (~80 MCE records at most).
23 #define MCE_POOLSZ (2 * PAGE_SIZE)
25 static struct gen_pool
*mce_evt_pool
;
26 static LLIST_HEAD(mce_event_llist
);
27 static char gen_pool_buf
[MCE_POOLSZ
];
29 void mce_gen_pool_process(void)
31 struct llist_node
*head
;
32 struct mce_evt_llist
*node
;
35 head
= llist_del_all(&mce_event_llist
);
39 head
= llist_reverse_order(head
);
40 llist_for_each_entry(node
, head
, llnode
) {
42 atomic_notifier_call_chain(&x86_mce_decoder_chain
, 0, mce
);
43 gen_pool_free(mce_evt_pool
, (unsigned long)node
, sizeof(*node
));
47 bool mce_gen_pool_empty(void)
49 return llist_empty(&mce_event_llist
);
52 int mce_gen_pool_add(struct mce
*mce
)
54 struct mce_evt_llist
*node
;
59 node
= (void *)gen_pool_alloc(mce_evt_pool
, sizeof(*node
));
61 pr_warn_ratelimited("MCE records pool full!\n");
65 memcpy(&node
->mce
, mce
, sizeof(*mce
));
66 llist_add(&node
->llnode
, &mce_event_llist
);
71 static int mce_gen_pool_create(void)
73 struct gen_pool
*tmpp
;
76 tmpp
= gen_pool_create(ilog2(sizeof(struct mce_evt_llist
)), -1);
80 ret
= gen_pool_add(tmpp
, (unsigned long)gen_pool_buf
, MCE_POOLSZ
, -1);
82 gen_pool_destroy(tmpp
);
92 int mce_gen_pool_init(void)
94 /* Just init mce_gen_pool once. */
98 return mce_gen_pool_create();