xref: /openbmc/linux/fs/pstore/platform.c (revision 94160062396d7e7cff4ed69320ffc5e22d51a0ab)
145051539SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2ca01d6ddSTony Luck /*
3ca01d6ddSTony Luck  * Persistent Storage - platform driver interface parts.
4ca01d6ddSTony Luck  *
5f29e5956SAnton Vorontsov  * Copyright (C) 2007-2008 Google, Inc.
6ca01d6ddSTony Luck  * Copyright (C) 2010 Intel Corporation <tony.luck@intel.com>
7ca01d6ddSTony Luck  */
8ca01d6ddSTony Luck 
9ef748853SFabian Frederick #define pr_fmt(fmt) "pstore: " fmt
10ef748853SFabian Frederick 
11ca01d6ddSTony Luck #include <linux/atomic.h>
12ca01d6ddSTony Luck #include <linux/types.h>
13ca01d6ddSTony Luck #include <linux/errno.h>
14ca01d6ddSTony Luck #include <linux/init.h>
15ca01d6ddSTony Luck #include <linux/kmsg_dump.h>
16f29e5956SAnton Vorontsov #include <linux/console.h>
17104fd0b5SYuxiao Zhang #include <linux/mm.h>
18ca01d6ddSTony Luck #include <linux/module.h>
19ca01d6ddSTony Luck #include <linux/pstore.h>
20ca01d6ddSTony Luck #include <linux/string.h>
216dda9266SLuck, Tony #include <linux/timer.h>
22ca01d6ddSTony Luck #include <linux/slab.h>
23ca01d6ddSTony Luck #include <linux/uaccess.h>
24a3f5f075SAnton Vorontsov #include <linux/jiffies.h>
25438b8050SArd Biesheuvel #include <linux/vmalloc.h>
266dda9266SLuck, Tony #include <linux/workqueue.h>
27438b8050SArd Biesheuvel #include <linux/zlib.h>
28ca01d6ddSTony Luck 
29ca01d6ddSTony Luck #include "internal.h"
30ca01d6ddSTony Luck 
31ca01d6ddSTony Luck /*
326dda9266SLuck, Tony  * We defer making "oops" entries appear in pstore - see
336dda9266SLuck, Tony  * whether the system is actually still running well enough
346dda9266SLuck, Tony  * to let someone see the entry
356dda9266SLuck, Tony  */
36521f7288SAnton Vorontsov static int pstore_update_ms = -1;
37a3f5f075SAnton Vorontsov module_param_named(update_ms, pstore_update_ms, int, 0600);
38a3f5f075SAnton Vorontsov MODULE_PARM_DESC(update_ms, "milliseconds before pstore updates its content "
39521f7288SAnton Vorontsov 		 "(default is -1, which means runtime updates are disabled; "
4078c83c82SKees Cook 		 "enabling this option may not be safe; it may lead to further "
41521f7288SAnton Vorontsov 		 "corruption on Oopses)");
426dda9266SLuck, Tony 
43f0f23e54SJoel Fernandes (Google) /* Names should be in the same order as the enum pstore_type_id */
44f0f23e54SJoel Fernandes (Google) static const char * const pstore_type_names[] = {
45f0f23e54SJoel Fernandes (Google) 	"dmesg",
46f0f23e54SJoel Fernandes (Google) 	"mce",
47f0f23e54SJoel Fernandes (Google) 	"console",
48f0f23e54SJoel Fernandes (Google) 	"ftrace",
49f0f23e54SJoel Fernandes (Google) 	"rtas",
50f0f23e54SJoel Fernandes (Google) 	"powerpc-ofw",
51f0f23e54SJoel Fernandes (Google) 	"powerpc-common",
52f0f23e54SJoel Fernandes (Google) 	"pmsg",
53f0f23e54SJoel Fernandes (Google) 	"powerpc-opal",
54f0f23e54SJoel Fernandes (Google) };
55f0f23e54SJoel Fernandes (Google) 
566dda9266SLuck, Tony static int pstore_new_entry;
576dda9266SLuck, Tony 
5824ed960aSKees Cook static void pstore_timefunc(struct timer_list *);
591d27e3e2SKees Cook static DEFINE_TIMER(pstore_timer, pstore_timefunc);
606dda9266SLuck, Tony 
616dda9266SLuck, Tony static void pstore_dowork(struct work_struct *);
626dda9266SLuck, Tony static DECLARE_WORK(pstore_work, pstore_dowork);
636dda9266SLuck, Tony 
646dda9266SLuck, Tony /*
656248a066SKees Cook  * psinfo_lock protects "psinfo" during calls to
666248a066SKees Cook  * pstore_register(), pstore_unregister(), and
676248a066SKees Cook  * the filesystem mount/unmount routines.
68ca01d6ddSTony Luck  */
69cab12fd0SKees Cook static DEFINE_MUTEX(psinfo_lock);
70060287b8SAnton Vorontsov struct pstore_info *psinfo;
71ca01d6ddSTony Luck 
72dee28e72SMatthew Garrett static char *backend;
73d973f7d8SKees Cook module_param(backend, charp, 0444);
74d973f7d8SKees Cook MODULE_PARM_DESC(backend, "specific backend to use");
75d973f7d8SKees Cook 
76438b8050SArd Biesheuvel /*
77438b8050SArd Biesheuvel  * pstore no longer implements compression via the crypto API, and only
78438b8050SArd Biesheuvel  * supports zlib deflate compression implemented using the zlib library
79438b8050SArd Biesheuvel  * interface. This removes additional complexity which is hard to justify for a
80438b8050SArd Biesheuvel  * diagnostic facility that has to operate in conditions where the system may
81438b8050SArd Biesheuvel  * have become unstable. Zlib deflate is comparatively small in terms of code
82438b8050SArd Biesheuvel  * size, and compresses ASCII text comparatively well. In terms of compression
83438b8050SArd Biesheuvel  * speed, deflate is not the best performer but for recording the log output on
84438b8050SArd Biesheuvel  * a kernel panic, this is not considered critical.
85438b8050SArd Biesheuvel  *
86438b8050SArd Biesheuvel  * The only remaining arguments supported by the compress= module parameter are
87438b8050SArd Biesheuvel  * 'deflate' and 'none'. To retain compatibility with existing installations,
88438b8050SArd Biesheuvel  * all other values are logged and replaced with 'deflate'.
89438b8050SArd Biesheuvel  */
90438b8050SArd Biesheuvel static char *compress = "deflate";
91d973f7d8SKees Cook module_param(compress, charp, 0444);
92d973f7d8SKees Cook MODULE_PARM_DESC(compress, "compression to use");
93dee28e72SMatthew Garrett 
948f5de3fdSGuilherme G. Piccoli /* How much of the kernel log to snapshot */
958f5de3fdSGuilherme G. Piccoli unsigned long kmsg_bytes = CONFIG_PSTORE_DEFAULT_KMSG_BYTES;
968f5de3fdSGuilherme G. Piccoli module_param(kmsg_bytes, ulong, 0444);
978f5de3fdSGuilherme G. Piccoli MODULE_PARM_DESC(kmsg_bytes, "amount of kernel log to snapshot (in bytes)");
988f5de3fdSGuilherme G. Piccoli 
99438b8050SArd Biesheuvel static void *compress_workspace;
1008cfc8ddcSGeliang Tang 
101*94160062SArd Biesheuvel /*
102*94160062SArd Biesheuvel  * Compression is only used for dmesg output, which consists of low-entropy
103*94160062SArd Biesheuvel  * ASCII text, and so we can assume worst-case 60%.
104*94160062SArd Biesheuvel  */
105*94160062SArd Biesheuvel #define DMESG_COMP_PERCENT	60
106*94160062SArd Biesheuvel 
107b0aad7a9SAruna Balakrishnaiah static char *big_oops_buf;
108*94160062SArd Biesheuvel static size_t max_compressed_size;
109b0aad7a9SAruna Balakrishnaiah 
110366f7e7aSLuck, Tony void pstore_set_kmsg_bytes(int bytes)
111ca01d6ddSTony Luck {
112366f7e7aSLuck, Tony 	kmsg_bytes = bytes;
113ca01d6ddSTony Luck }
114ca01d6ddSTony Luck 
115ca01d6ddSTony Luck /* Tag each group of saved records with a sequence number */
116ca01d6ddSTony Luck static int	oopscount;
117ca01d6ddSTony Luck 
118f0f23e54SJoel Fernandes (Google) const char *pstore_type_to_name(enum pstore_type_id type)
119f0f23e54SJoel Fernandes (Google) {
120f0f23e54SJoel Fernandes (Google) 	BUILD_BUG_ON(ARRAY_SIZE(pstore_type_names) != PSTORE_TYPE_MAX);
121f0f23e54SJoel Fernandes (Google) 
122f0f23e54SJoel Fernandes (Google) 	if (WARN_ON_ONCE(type >= PSTORE_TYPE_MAX))
123f0f23e54SJoel Fernandes (Google) 		return "unknown";
124f0f23e54SJoel Fernandes (Google) 
125f0f23e54SJoel Fernandes (Google) 	return pstore_type_names[type];
126f0f23e54SJoel Fernandes (Google) }
127f0f23e54SJoel Fernandes (Google) EXPORT_SYMBOL_GPL(pstore_type_to_name);
128f0f23e54SJoel Fernandes (Google) 
129f0f23e54SJoel Fernandes (Google) enum pstore_type_id pstore_name_to_type(const char *name)
130f0f23e54SJoel Fernandes (Google) {
131f0f23e54SJoel Fernandes (Google) 	int i;
132f0f23e54SJoel Fernandes (Google) 
133f0f23e54SJoel Fernandes (Google) 	for (i = 0; i < PSTORE_TYPE_MAX; i++) {
134f0f23e54SJoel Fernandes (Google) 		if (!strcmp(pstore_type_names[i], name))
135f0f23e54SJoel Fernandes (Google) 			return i;
136f0f23e54SJoel Fernandes (Google) 	}
137f0f23e54SJoel Fernandes (Google) 
138f0f23e54SJoel Fernandes (Google) 	return PSTORE_TYPE_MAX;
139f0f23e54SJoel Fernandes (Google) }
140f0f23e54SJoel Fernandes (Google) EXPORT_SYMBOL_GPL(pstore_name_to_type);
141f0f23e54SJoel Fernandes (Google) 
14278c83c82SKees Cook static void pstore_timer_kick(void)
14378c83c82SKees Cook {
14478c83c82SKees Cook 	if (pstore_update_ms < 0)
14578c83c82SKees Cook 		return;
14678c83c82SKees Cook 
14778c83c82SKees Cook 	mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms));
14878c83c82SKees Cook }
14978c83c82SKees Cook 
1508126b1c7SJann Horn static bool pstore_cannot_block_path(enum kmsg_dump_reason reason)
151ea84b580SKees Cook {
1528126b1c7SJann Horn 	/*
1538126b1c7SJann Horn 	 * In case of NMI path, pstore shouldn't be blocked
1548126b1c7SJann Horn 	 * regardless of reason.
1558126b1c7SJann Horn 	 */
1569f244e9cSSeiji Aguchi 	if (in_nmi())
1579f244e9cSSeiji Aguchi 		return true;
1589f244e9cSSeiji Aguchi 
1599f244e9cSSeiji Aguchi 	switch (reason) {
1609f244e9cSSeiji Aguchi 	/* In panic case, other cpus are stopped by smp_send_stop(). */
1619f244e9cSSeiji Aguchi 	case KMSG_DUMP_PANIC:
1628126b1c7SJann Horn 	/*
1638126b1c7SJann Horn 	 * Emergency restart shouldn't be blocked by spinning on
1648126b1c7SJann Horn 	 * pstore_info::buf_lock.
1658126b1c7SJann Horn 	 */
1669f244e9cSSeiji Aguchi 	case KMSG_DUMP_EMERG:
1679f244e9cSSeiji Aguchi 		return true;
1689f244e9cSSeiji Aguchi 	default:
1699f244e9cSSeiji Aguchi 		return false;
1709f244e9cSSeiji Aguchi 	}
1719f244e9cSSeiji Aguchi }
1729f244e9cSSeiji Aguchi 
1738cfc8ddcSGeliang Tang static int pstore_compress(const void *in, void *out,
174cb3bee03SGeliang Tang 			   unsigned int inlen, unsigned int outlen)
1758cfc8ddcSGeliang Tang {
176438b8050SArd Biesheuvel 	struct z_stream_s zstream = {
177438b8050SArd Biesheuvel 		.next_in	= in,
178438b8050SArd Biesheuvel 		.avail_in	= inlen,
179438b8050SArd Biesheuvel 		.next_out	= out,
180438b8050SArd Biesheuvel 		.avail_out	= outlen,
181438b8050SArd Biesheuvel 		.workspace	= compress_workspace,
182438b8050SArd Biesheuvel 	};
183cb3bee03SGeliang Tang 	int ret;
184cb3bee03SGeliang Tang 
18519d8e914SJiri Bohac 	if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS))
186fd49e032SMatteo Croce 		return -EINVAL;
187fd49e032SMatteo Croce 
188438b8050SArd Biesheuvel 	ret = zlib_deflateInit2(&zstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
189438b8050SArd Biesheuvel 				-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
190438b8050SArd Biesheuvel 	if (ret != Z_OK)
191438b8050SArd Biesheuvel 		return -EINVAL;
1928cfc8ddcSGeliang Tang 
193438b8050SArd Biesheuvel 	ret = zlib_deflate(&zstream, Z_FINISH);
194438b8050SArd Biesheuvel 	if (ret != Z_STREAM_END)
195438b8050SArd Biesheuvel 		return -EINVAL;
196438b8050SArd Biesheuvel 
197438b8050SArd Biesheuvel 	ret = zlib_deflateEnd(&zstream);
198438b8050SArd Biesheuvel 	if (ret != Z_OK)
199438b8050SArd Biesheuvel 		pr_warn_once("zlib_deflateEnd() failed: %d\n", ret);
200438b8050SArd Biesheuvel 
201438b8050SArd Biesheuvel 	return zstream.total_out;
202cb3bee03SGeliang Tang }
203cb3bee03SGeliang Tang 
2048cfc8ddcSGeliang Tang static void allocate_buf_for_compression(void)
2058cfc8ddcSGeliang Tang {
206*94160062SArd Biesheuvel 	size_t compressed_size;
20795047b05SKees Cook 	char *buf;
20895047b05SKees Cook 
209438b8050SArd Biesheuvel 	/* Skip if not built-in or compression disabled. */
210438b8050SArd Biesheuvel 	if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !compress ||
211438b8050SArd Biesheuvel 	    !strcmp(compress, "none")) {
212438b8050SArd Biesheuvel 		compress = NULL;
213cb3bee03SGeliang Tang 		return;
214438b8050SArd Biesheuvel 	}
215cb3bee03SGeliang Tang 
216438b8050SArd Biesheuvel 	if (strcmp(compress, "deflate")) {
217438b8050SArd Biesheuvel 		pr_err("Unsupported compression '%s', falling back to deflate\n",
218438b8050SArd Biesheuvel 		       compress);
219438b8050SArd Biesheuvel 		compress = "deflate";
220cb3bee03SGeliang Tang 	}
221cb3bee03SGeliang Tang 
2221756ddeaSArd Biesheuvel 	/*
2231756ddeaSArd Biesheuvel 	 * The compression buffer only needs to be as large as the maximum
2241756ddeaSArd Biesheuvel 	 * uncompressed record size, since any record that would be expanded by
2251756ddeaSArd Biesheuvel 	 * compression is just stored uncompressed.
2261756ddeaSArd Biesheuvel 	 */
227*94160062SArd Biesheuvel 	compressed_size = (psinfo->bufsize * 100) / DMESG_COMP_PERCENT;
228*94160062SArd Biesheuvel 	buf = kvzalloc(compressed_size, GFP_KERNEL);
22995047b05SKees Cook 	if (!buf) {
2301756ddeaSArd Biesheuvel 		pr_err("Failed %zu byte compression buffer allocation for: %s\n",
2311756ddeaSArd Biesheuvel 		       psinfo->bufsize, compress);
232cb3bee03SGeliang Tang 		return;
2338cfc8ddcSGeliang Tang 	}
23495047b05SKees Cook 
235438b8050SArd Biesheuvel 	compress_workspace =
236438b8050SArd Biesheuvel 		vmalloc(zlib_deflate_workspacesize(MAX_WBITS, DEF_MEM_LEVEL));
237438b8050SArd Biesheuvel 	if (!compress_workspace) {
238438b8050SArd Biesheuvel 		pr_err("Failed to allocate zlib deflate workspace\n");
239104fd0b5SYuxiao Zhang 		kvfree(buf);
24095047b05SKees Cook 		return;
24195047b05SKees Cook 	}
24295047b05SKees Cook 
24395047b05SKees Cook 	/* A non-NULL big_oops_buf indicates compression is available. */
24495047b05SKees Cook 	big_oops_buf = buf;
245*94160062SArd Biesheuvel 	max_compressed_size = compressed_size;
24695047b05SKees Cook 
2471756ddeaSArd Biesheuvel 	pr_info("Using crash dump compression: %s\n", compress);
2488cfc8ddcSGeliang Tang }
2498cfc8ddcSGeliang Tang 
2508cfc8ddcSGeliang Tang static void free_buf_for_compression(void)
2518cfc8ddcSGeliang Tang {
252438b8050SArd Biesheuvel 	if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && compress_workspace) {
253438b8050SArd Biesheuvel 		vfree(compress_workspace);
254438b8050SArd Biesheuvel 		compress_workspace = NULL;
255a9fb94a9SPi-Hsun Shih 	}
256438b8050SArd Biesheuvel 
257104fd0b5SYuxiao Zhang 	kvfree(big_oops_buf);
258cb3bee03SGeliang Tang 	big_oops_buf = NULL;
259*94160062SArd Biesheuvel 	max_compressed_size = 0;
260b0aad7a9SAruna Balakrishnaiah }
261b0aad7a9SAruna Balakrishnaiah 
262e581ca81SKees Cook void pstore_record_init(struct pstore_record *record,
263e581ca81SKees Cook 			struct pstore_info *psinfo)
264e581ca81SKees Cook {
265e581ca81SKees Cook 	memset(record, 0, sizeof(*record));
266e581ca81SKees Cook 
267e581ca81SKees Cook 	record->psi = psinfo;
268c7f3c595SKees Cook 
269c7f3c595SKees Cook 	/* Report zeroed timestamp if called before timekeeping has resumed. */
2707aaa822eSKees Cook 	record->time = ns_to_timespec64(ktime_get_real_fast_ns());
271e581ca81SKees Cook }
272e581ca81SKees Cook 
273ca01d6ddSTony Luck /*
2740eed84ffSKees Cook  * callback from kmsg_dump. Save as much as we can (up to kmsg_bytes) from the
2750eed84ffSKees Cook  * end of the buffer.
276ca01d6ddSTony Luck  */
277ca01d6ddSTony Luck static void pstore_dump(struct kmsg_dumper *dumper,
278e2ae715dSKay Sievers 			enum kmsg_dump_reason reason)
279ca01d6ddSTony Luck {
280f9f3f02dSJohn Ogness 	struct kmsg_dump_iter iter;
281e2ae715dSKay Sievers 	unsigned long	total = 0;
282381b872cSSeiji Aguchi 	const char	*why;
283b94fdd07SMatthew Garrett 	unsigned int	part = 1;
2848126b1c7SJann Horn 	unsigned long	flags = 0;
28538b91847SGuilherme G. Piccoli 	int		saved_ret = 0;
286e2ae715dSKay Sievers 	int		ret;
287ca01d6ddSTony Luck 
288fb13cb8aSKees Cook 	why = kmsg_dump_reason_str(reason);
2899f6af27fSTony Luck 
2908126b1c7SJann Horn 	if (pstore_cannot_block_path(reason)) {
2918126b1c7SJann Horn 		if (!spin_trylock_irqsave(&psinfo->buf_lock, flags)) {
2928126b1c7SJann Horn 			pr_err("dump skipped in %s path because of concurrent dump\n",
293ea84b580SKees Cook 					in_nmi() ? "NMI" : why);
294959217c8SLi Pengcheng 			return;
2959f244e9cSSeiji Aguchi 		}
2968126b1c7SJann Horn 	} else {
2978126b1c7SJann Horn 		spin_lock_irqsave(&psinfo->buf_lock, flags);
298ea84b580SKees Cook 	}
299ea84b580SKees Cook 
300f9f3f02dSJohn Ogness 	kmsg_dump_rewind(&iter);
301f9f3f02dSJohn Ogness 
302ca01d6ddSTony Luck 	oopscount++;
303ca01d6ddSTony Luck 	while (total < kmsg_bytes) {
304e2ae715dSKay Sievers 		char *dst;
30576cc9580SKees Cook 		size_t dst_size;
30676cc9580SKees Cook 		int header_size;
307b0aad7a9SAruna Balakrishnaiah 		int zipped_len = -1;
30876cc9580SKees Cook 		size_t dump_size;
309e581ca81SKees Cook 		struct pstore_record record;
310e581ca81SKees Cook 
311e581ca81SKees Cook 		pstore_record_init(&record, psinfo);
312e581ca81SKees Cook 		record.type = PSTORE_TYPE_DMESG;
313e581ca81SKees Cook 		record.count = oopscount;
314e581ca81SKees Cook 		record.reason = reason;
315e581ca81SKees Cook 		record.part = part;
316e581ca81SKees Cook 		record.buf = psinfo->buf;
317e2ae715dSKay Sievers 
3181756ddeaSArd Biesheuvel 		dst = big_oops_buf ?: psinfo->buf;
319*94160062SArd Biesheuvel 		dst_size = max_compressed_size ?: psinfo->bufsize;
320235f6d15SNamhyung Kim 
32176cc9580SKees Cook 		/* Write dump header. */
32276cc9580SKees Cook 		header_size = snprintf(dst, dst_size, "%s#%d Part%u\n", why,
32376cc9580SKees Cook 				 oopscount, part);
32476cc9580SKees Cook 		dst_size -= header_size;
325b0aad7a9SAruna Balakrishnaiah 
32676cc9580SKees Cook 		/* Write dump contents. */
327f9f3f02dSJohn Ogness 		if (!kmsg_dump_get_buffer(&iter, true, dst + header_size,
32876cc9580SKees Cook 					  dst_size, &dump_size))
329b0aad7a9SAruna Balakrishnaiah 			break;
330b0aad7a9SAruna Balakrishnaiah 
331ea84b580SKees Cook 		if (big_oops_buf) {
332b0aad7a9SAruna Balakrishnaiah 			zipped_len = pstore_compress(dst, psinfo->buf,
33376cc9580SKees Cook 						header_size + dump_size,
33476cc9580SKees Cook 						psinfo->bufsize);
335b0aad7a9SAruna Balakrishnaiah 
336b0aad7a9SAruna Balakrishnaiah 			if (zipped_len > 0) {
33776cc9580SKees Cook 				record.compressed = true;
33876cc9580SKees Cook 				record.size = zipped_len;
339b0aad7a9SAruna Balakrishnaiah 			} else {
340*94160062SArd Biesheuvel 				/*
341*94160062SArd Biesheuvel 				 * Compression failed, so the buffer is most
342*94160062SArd Biesheuvel 				 * likely filled with binary data that does not
343*94160062SArd Biesheuvel 				 * compress as well as ASCII text. Copy as much
344*94160062SArd Biesheuvel 				 * of the uncompressed data as possible into
345*94160062SArd Biesheuvel 				 * the pstore record, and discard the rest.
346*94160062SArd Biesheuvel 				 */
347*94160062SArd Biesheuvel 				record.size = psinfo->bufsize;
348*94160062SArd Biesheuvel 				memcpy(psinfo->buf, dst, psinfo->bufsize);
349b0aad7a9SAruna Balakrishnaiah 			}
350b0aad7a9SAruna Balakrishnaiah 		} else {
35176cc9580SKees Cook 			record.size = header_size + dump_size;
352b0aad7a9SAruna Balakrishnaiah 		}
353b0aad7a9SAruna Balakrishnaiah 
35476cc9580SKees Cook 		ret = psinfo->write(&record);
35578c83c82SKees Cook 		if (ret == 0 && reason == KMSG_DUMP_OOPS) {
3566dda9266SLuck, Tony 			pstore_new_entry = 1;
35778c83c82SKees Cook 			pstore_timer_kick();
35838b91847SGuilherme G. Piccoli 		} else {
35938b91847SGuilherme G. Piccoli 			/* Preserve only the first non-zero returned value. */
36038b91847SGuilherme G. Piccoli 			if (!saved_ret)
36138b91847SGuilherme G. Piccoli 				saved_ret = ret;
36278c83c82SKees Cook 		}
363e2ae715dSKay Sievers 
36476cc9580SKees Cook 		total += record.size;
36556280682SMatthew Garrett 		part++;
366ca01d6ddSTony Luck 	}
3678126b1c7SJann Horn 	spin_unlock_irqrestore(&psinfo->buf_lock, flags);
36838b91847SGuilherme G. Piccoli 
36938b91847SGuilherme G. Piccoli 	if (saved_ret) {
37038b91847SGuilherme G. Piccoli 		pr_err_once("backend (%s) writing error (%d)\n", psinfo->name,
37138b91847SGuilherme G. Piccoli 			    saved_ret);
37238b91847SGuilherme G. Piccoli 	}
373ca01d6ddSTony Luck }
374ca01d6ddSTony Luck 
375ca01d6ddSTony Luck static struct kmsg_dumper pstore_dumper = {
376ca01d6ddSTony Luck 	.dump = pstore_dump,
377ca01d6ddSTony Luck };
378ca01d6ddSTony Luck 
379306e5c2aSGeliang Tang /*
380306e5c2aSGeliang Tang  * Register with kmsg_dump to save last part of console log on panic.
381306e5c2aSGeliang Tang  */
38218730411SGeliang Tang static void pstore_register_kmsg(void)
38318730411SGeliang Tang {
38418730411SGeliang Tang 	kmsg_dump_register(&pstore_dumper);
38518730411SGeliang Tang }
38618730411SGeliang Tang 
387ee1d2674SGeliang Tang static void pstore_unregister_kmsg(void)
388ee1d2674SGeliang Tang {
389ee1d2674SGeliang Tang 	kmsg_dump_unregister(&pstore_dumper);
390ee1d2674SGeliang Tang }
391ee1d2674SGeliang Tang 
392f29e5956SAnton Vorontsov #ifdef CONFIG_PSTORE_CONSOLE
393f29e5956SAnton Vorontsov static void pstore_console_write(struct console *con, const char *s, unsigned c)
394f29e5956SAnton Vorontsov {
395e581ca81SKees Cook 	struct pstore_record record;
396f29e5956SAnton Vorontsov 
3974c6c4d34SYue Hu 	if (!c)
3984c6c4d34SYue Hu 		return;
3994c6c4d34SYue Hu 
400e581ca81SKees Cook 	pstore_record_init(&record, psinfo);
401e581ca81SKees Cook 	record.type = PSTORE_TYPE_CONSOLE;
402e581ca81SKees Cook 
403b10b4711SKees Cook 	record.buf = (char *)s;
404b10b4711SKees Cook 	record.size = c;
4054c9ec219SKees Cook 	psinfo->write(&record);
406f29e5956SAnton Vorontsov }
407f29e5956SAnton Vorontsov 
408f29e5956SAnton Vorontsov static struct console pstore_console = {
409f29e5956SAnton Vorontsov 	.write	= pstore_console_write,
410f29e5956SAnton Vorontsov 	.index	= -1,
411f29e5956SAnton Vorontsov };
412f29e5956SAnton Vorontsov 
413f29e5956SAnton Vorontsov static void pstore_register_console(void)
414f29e5956SAnton Vorontsov {
415d195c390SKees Cook 	/* Show which backend is going to get console writes. */
416d195c390SKees Cook 	strscpy(pstore_console.name, psinfo->name,
417d195c390SKees Cook 		sizeof(pstore_console.name));
418b7753fc7SKees Cook 	/*
419b7753fc7SKees Cook 	 * Always initialize flags here since prior unregister_console()
420b7753fc7SKees Cook 	 * calls may have changed settings (specifically CON_ENABLED).
421b7753fc7SKees Cook 	 */
422b7753fc7SKees Cook 	pstore_console.flags = CON_PRINTBUFFER | CON_ENABLED | CON_ANYTIME;
423f29e5956SAnton Vorontsov 	register_console(&pstore_console);
424f29e5956SAnton Vorontsov }
425ee1d2674SGeliang Tang 
426ee1d2674SGeliang Tang static void pstore_unregister_console(void)
427ee1d2674SGeliang Tang {
428ee1d2674SGeliang Tang 	unregister_console(&pstore_console);
429ee1d2674SGeliang Tang }
430f29e5956SAnton Vorontsov #else
431f29e5956SAnton Vorontsov static void pstore_register_console(void) {}
432ee1d2674SGeliang Tang static void pstore_unregister_console(void) {}
433f29e5956SAnton Vorontsov #endif
434f29e5956SAnton Vorontsov 
4354c9ec219SKees Cook static int pstore_write_user_compat(struct pstore_record *record,
436fdd03118SKees Cook 				    const char __user *buf)
4375bf6d1b9SMark Salyzyn {
43830800d99SKees Cook 	int ret = 0;
4395bf6d1b9SMark Salyzyn 
44030800d99SKees Cook 	if (record->buf)
44130800d99SKees Cook 		return -EINVAL;
4425bf6d1b9SMark Salyzyn 
443104fd0b5SYuxiao Zhang 	record->buf = vmemdup_user(buf, record->size);
444dfd6fa39SHirofumi Nakagawa 	if (IS_ERR(record->buf)) {
445077090afSGeliang Tang 		ret = PTR_ERR(record->buf);
44630800d99SKees Cook 		goto out;
4475bf6d1b9SMark Salyzyn 	}
44830800d99SKees Cook 
4494c9ec219SKees Cook 	ret = record->psi->write(record);
45030800d99SKees Cook 
451104fd0b5SYuxiao Zhang 	kvfree(record->buf);
452077090afSGeliang Tang out:
45330800d99SKees Cook 	record->buf = NULL;
45430800d99SKees Cook 
45530800d99SKees Cook 	return unlikely(ret < 0) ? ret : record->size;
4565bf6d1b9SMark Salyzyn }
4575bf6d1b9SMark Salyzyn 
458ca01d6ddSTony Luck /*
459ca01d6ddSTony Luck  * platform specific persistent storage driver registers with
460ca01d6ddSTony Luck  * us here. If pstore is already mounted, call the platform
461ca01d6ddSTony Luck  * read function right away to populate the file system. If not
462ca01d6ddSTony Luck  * then the pstore mount code will call us later to fill out
463ca01d6ddSTony Luck  * the file system.
464ca01d6ddSTony Luck  */
465ca01d6ddSTony Luck int pstore_register(struct pstore_info *psi)
466ca01d6ddSTony Luck {
4670d7cd09aSKees Cook 	if (backend && strcmp(backend, psi->name)) {
468d85644dcSGuilherme G. Piccoli 		pr_warn("backend '%s' already in use: ignoring '%s'\n",
469d85644dcSGuilherme G. Piccoli 			backend, psi->name);
470d85644dcSGuilherme G. Piccoli 		return -EBUSY;
4710d7cd09aSKees Cook 	}
4728e48b1a8SLenny Szubowicz 
4734c9ec219SKees Cook 	/* Sanity check flags. */
4744c9ec219SKees Cook 	if (!psi->flags) {
4754c9ec219SKees Cook 		pr_warn("backend '%s' must support at least one frontend\n",
4764c9ec219SKees Cook 			psi->name);
4774c9ec219SKees Cook 		return -EINVAL;
4784c9ec219SKees Cook 	}
4794c9ec219SKees Cook 
4804c9ec219SKees Cook 	/* Check for required functions. */
4814c9ec219SKees Cook 	if (!psi->read || !psi->write) {
4824c9ec219SKees Cook 		pr_warn("backend '%s' must implement read() and write()\n",
4834c9ec219SKees Cook 			psi->name);
4844c9ec219SKees Cook 		return -EINVAL;
4854c9ec219SKees Cook 	}
4864c9ec219SKees Cook 
487cab12fd0SKees Cook 	mutex_lock(&psinfo_lock);
488ca01d6ddSTony Luck 	if (psinfo) {
4890d7cd09aSKees Cook 		pr_warn("backend '%s' already loaded: ignoring '%s'\n",
4900d7cd09aSKees Cook 			psinfo->name, psi->name);
491cab12fd0SKees Cook 		mutex_unlock(&psinfo_lock);
492ca01d6ddSTony Luck 		return -EBUSY;
493ca01d6ddSTony Luck 	}
494dee28e72SMatthew Garrett 
4954c9ec219SKees Cook 	if (!psi->write_user)
4964c9ec219SKees Cook 		psi->write_user = pstore_write_user_compat;
497ca01d6ddSTony Luck 	psinfo = psi;
498f6f82851SKees Cook 	mutex_init(&psinfo->read_mutex);
4998126b1c7SJann Horn 	spin_lock_init(&psinfo->buf_lock);
500ca01d6ddSTony Luck 
5018880fa32SKees Cook 	if (psi->flags & PSTORE_FLAGS_DMESG)
502b0aad7a9SAruna Balakrishnaiah 		allocate_buf_for_compression();
503b0aad7a9SAruna Balakrishnaiah 
5046dda9266SLuck, Tony 	pstore_get_records(0);
505ca01d6ddSTony Luck 
5063524e688SPavel Tatashin 	if (psi->flags & PSTORE_FLAGS_DMESG) {
5073524e688SPavel Tatashin 		pstore_dumper.max_reason = psinfo->max_reason;
50818730411SGeliang Tang 		pstore_register_kmsg();
5093524e688SPavel Tatashin 	}
510c950fd6fSNamhyung Kim 	if (psi->flags & PSTORE_FLAGS_CONSOLE)
511f29e5956SAnton Vorontsov 		pstore_register_console();
512c950fd6fSNamhyung Kim 	if (psi->flags & PSTORE_FLAGS_FTRACE)
51365f8c95eSAnton Vorontsov 		pstore_register_ftrace();
514c950fd6fSNamhyung Kim 	if (psi->flags & PSTORE_FLAGS_PMSG)
5159d5438f4SMark Salyzyn 		pstore_register_pmsg();
516ca01d6ddSTony Luck 
5176330d553SKees Cook 	/* Start watching for new records, if desired. */
51878c83c82SKees Cook 	pstore_timer_kick();
5196dda9266SLuck, Tony 
52042222c2aSWang Long 	/*
52142222c2aSWang Long 	 * Update the module parameter backend, so it is visible
52242222c2aSWang Long 	 * through /sys/module/pstore/parameters/backend
52342222c2aSWang Long 	 */
524563ca40dSKees Cook 	backend = kstrdup(psi->name, GFP_KERNEL);
52542222c2aSWang Long 
526ef748853SFabian Frederick 	pr_info("Registered %s as persistent store backend\n", psi->name);
5278e48b1a8SLenny Szubowicz 
5286248a066SKees Cook 	mutex_unlock(&psinfo_lock);
529ca01d6ddSTony Luck 	return 0;
530ca01d6ddSTony Luck }
531ca01d6ddSTony Luck EXPORT_SYMBOL_GPL(pstore_register);
532ca01d6ddSTony Luck 
533ee1d2674SGeliang Tang void pstore_unregister(struct pstore_info *psi)
534ee1d2674SGeliang Tang {
5356248a066SKees Cook 	/* It's okay to unregister nothing. */
5366248a066SKees Cook 	if (!psi)
5376248a066SKees Cook 		return;
5386248a066SKees Cook 
5396248a066SKees Cook 	mutex_lock(&psinfo_lock);
5406248a066SKees Cook 
5416248a066SKees Cook 	/* Only one backend can be registered at a time. */
5426248a066SKees Cook 	if (WARN_ON(psi != psinfo)) {
5436248a066SKees Cook 		mutex_unlock(&psinfo_lock);
5446248a066SKees Cook 		return;
5456248a066SKees Cook 	}
5466248a066SKees Cook 
54778c83c82SKees Cook 	/* Unregister all callbacks. */
548c950fd6fSNamhyung Kim 	if (psi->flags & PSTORE_FLAGS_PMSG)
549ee1d2674SGeliang Tang 		pstore_unregister_pmsg();
550c950fd6fSNamhyung Kim 	if (psi->flags & PSTORE_FLAGS_FTRACE)
551ee1d2674SGeliang Tang 		pstore_unregister_ftrace();
552c950fd6fSNamhyung Kim 	if (psi->flags & PSTORE_FLAGS_CONSOLE)
553ee1d2674SGeliang Tang 		pstore_unregister_console();
554c950fd6fSNamhyung Kim 	if (psi->flags & PSTORE_FLAGS_DMESG)
555ee1d2674SGeliang Tang 		pstore_unregister_kmsg();
556ee1d2674SGeliang Tang 
55778c83c82SKees Cook 	/* Stop timer and make sure all work has finished. */
55878c83c82SKees Cook 	del_timer_sync(&pstore_timer);
55978c83c82SKees Cook 	flush_work(&pstore_work);
56078c83c82SKees Cook 
561609e28bbSKees Cook 	/* Remove all backend records from filesystem tree. */
562609e28bbSKees Cook 	pstore_put_backend_records(psi);
563609e28bbSKees Cook 
564ee1d2674SGeliang Tang 	free_buf_for_compression();
565ee1d2674SGeliang Tang 
566ee1d2674SGeliang Tang 	psinfo = NULL;
567563ca40dSKees Cook 	kfree(backend);
568ee1d2674SGeliang Tang 	backend = NULL;
5696a14f198SGuilherme G. Piccoli 
5706a14f198SGuilherme G. Piccoli 	pr_info("Unregistered %s as persistent store backend\n", psi->name);
5716248a066SKees Cook 	mutex_unlock(&psinfo_lock);
572ee1d2674SGeliang Tang }
573ee1d2674SGeliang Tang EXPORT_SYMBOL_GPL(pstore_unregister);
574ee1d2674SGeliang Tang 
575438b8050SArd Biesheuvel static void decompress_record(struct pstore_record *record,
576438b8050SArd Biesheuvel 			      struct z_stream_s *zstream)
577634f8f51SKees Cook {
578bdabc8e7SKees Cook 	int ret;
579634f8f51SKees Cook 	int unzipped_len;
580bdabc8e7SKees Cook 	char *unzipped, *workspace;
581*94160062SArd Biesheuvel 	size_t max_uncompressed_size;
582634f8f51SKees Cook 
58319d8e914SJiri Bohac 	if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !record->compressed)
5844a16d1cbSAnkit Kumar 		return;
5854a16d1cbSAnkit Kumar 
586634f8f51SKees Cook 	/* Only PSTORE_TYPE_DMESG support compression. */
5874a16d1cbSAnkit Kumar 	if (record->type != PSTORE_TYPE_DMESG) {
588634f8f51SKees Cook 		pr_warn("ignored compressed record type %d\n", record->type);
589634f8f51SKees Cook 		return;
590634f8f51SKees Cook 	}
591634f8f51SKees Cook 
592bdabc8e7SKees Cook 	/* Missing compression buffer means compression was not initialized. */
593438b8050SArd Biesheuvel 	if (!zstream->workspace) {
594bdabc8e7SKees Cook 		pr_warn("no decompression method initialized!\n");
595634f8f51SKees Cook 		return;
596634f8f51SKees Cook 	}
597634f8f51SKees Cook 
598438b8050SArd Biesheuvel 	ret = zlib_inflateReset(zstream);
599438b8050SArd Biesheuvel 	if (ret != Z_OK) {
600438b8050SArd Biesheuvel 		pr_err("zlib_inflateReset() failed, ret = %d!\n", ret);
601438b8050SArd Biesheuvel 		return;
602438b8050SArd Biesheuvel 	}
603438b8050SArd Biesheuvel 
604bdabc8e7SKees Cook 	/* Allocate enough space to hold max decompression and ECC. */
605*94160062SArd Biesheuvel 	max_uncompressed_size = 3 * psinfo->bufsize;
606*94160062SArd Biesheuvel 	workspace = kvzalloc(max_uncompressed_size + record->ecc_notice_size,
6077e8cc8dcSKees Cook 			     GFP_KERNEL);
608bdabc8e7SKees Cook 	if (!workspace)
609bdabc8e7SKees Cook 		return;
610bdabc8e7SKees Cook 
611438b8050SArd Biesheuvel 	zstream->next_in	= record->buf;
612438b8050SArd Biesheuvel 	zstream->avail_in	= record->size;
613438b8050SArd Biesheuvel 	zstream->next_out	= workspace;
614*94160062SArd Biesheuvel 	zstream->avail_out	= max_uncompressed_size;
615438b8050SArd Biesheuvel 
616438b8050SArd Biesheuvel 	ret = zlib_inflate(zstream, Z_FINISH);
617438b8050SArd Biesheuvel 	if (ret != Z_STREAM_END) {
618*94160062SArd Biesheuvel 		pr_err_ratelimited("zlib_inflate() failed, ret = %d!\n", ret);
619104fd0b5SYuxiao Zhang 		kvfree(workspace);
6207e8cc8dcSKees Cook 		return;
6217e8cc8dcSKees Cook 	}
6227e8cc8dcSKees Cook 
623438b8050SArd Biesheuvel 	unzipped_len = zstream->total_out;
624438b8050SArd Biesheuvel 
6257e8cc8dcSKees Cook 	/* Append ECC notice to decompressed buffer. */
626bdabc8e7SKees Cook 	memcpy(workspace + unzipped_len, record->buf + record->size,
627634f8f51SKees Cook 	       record->ecc_notice_size);
6287e8cc8dcSKees Cook 
629bdabc8e7SKees Cook 	/* Copy decompressed contents into an minimum-sized allocation. */
630104fd0b5SYuxiao Zhang 	unzipped = kvmemdup(workspace, unzipped_len + record->ecc_notice_size,
631bdabc8e7SKees Cook 			    GFP_KERNEL);
632104fd0b5SYuxiao Zhang 	kvfree(workspace);
633bdabc8e7SKees Cook 	if (!unzipped)
634bdabc8e7SKees Cook 		return;
635bdabc8e7SKees Cook 
636bdabc8e7SKees Cook 	/* Swap out compressed contents with decompressed contents. */
637104fd0b5SYuxiao Zhang 	kvfree(record->buf);
638bdabc8e7SKees Cook 	record->buf = unzipped;
639634f8f51SKees Cook 	record->size = unzipped_len;
640634f8f51SKees Cook 	record->compressed = false;
641634f8f51SKees Cook }
642634f8f51SKees Cook 
643ca01d6ddSTony Luck /*
6443a7d2fd1SKees Cook  * Read all the records from one persistent store backend. Create
6456dda9266SLuck, Tony  * files in our filesystem.  Don't warn about -EEXIST errors
6466dda9266SLuck, Tony  * when we are re-scanning the backing store looking to add new
6476dda9266SLuck, Tony  * error records.
648ca01d6ddSTony Luck  */
6493a7d2fd1SKees Cook void pstore_get_backend_records(struct pstore_info *psi,
6503a7d2fd1SKees Cook 				struct dentry *root, int quiet)
651ca01d6ddSTony Luck {
6522a2b0acfSKees Cook 	int failed = 0;
653656de42eSKees Cook 	unsigned int stop_loop = 65536;
654438b8050SArd Biesheuvel 	struct z_stream_s zstream = {};
655ca01d6ddSTony Luck 
6563a7d2fd1SKees Cook 	if (!psi || !root)
657ca01d6ddSTony Luck 		return;
658ca01d6ddSTony Luck 
659438b8050SArd Biesheuvel 	if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && compress) {
660438b8050SArd Biesheuvel 		zstream.workspace = kvmalloc(zlib_inflate_workspacesize(),
661438b8050SArd Biesheuvel 					     GFP_KERNEL);
662438b8050SArd Biesheuvel 		zlib_inflateInit2(&zstream, -DEF_WBITS);
663438b8050SArd Biesheuvel 	}
664438b8050SArd Biesheuvel 
665f6f82851SKees Cook 	mutex_lock(&psi->read_mutex);
6662174f6dfSKees Cook 	if (psi->open && psi->open(psi))
66706cf91b4SChen Gong 		goto out;
66806cf91b4SChen Gong 
6691dfff7ddSKees Cook 	/*
6701dfff7ddSKees Cook 	 * Backend callback read() allocates record.buf. decompress_record()
6711dfff7ddSKees Cook 	 * may reallocate record.buf. On success, pstore_mkfile() will keep
6721dfff7ddSKees Cook 	 * the record.buf, so free it only on failure.
6731dfff7ddSKees Cook 	 */
674656de42eSKees Cook 	for (; stop_loop; stop_loop--) {
6752a2b0acfSKees Cook 		struct pstore_record *record;
6762a2b0acfSKees Cook 		int rc;
6772a2b0acfSKees Cook 
6782a2b0acfSKees Cook 		record = kzalloc(sizeof(*record), GFP_KERNEL);
6792a2b0acfSKees Cook 		if (!record) {
6802a2b0acfSKees Cook 			pr_err("out of memory creating record\n");
6812a2b0acfSKees Cook 			break;
6822a2b0acfSKees Cook 		}
683e581ca81SKees Cook 		pstore_record_init(record, psi);
6842a2b0acfSKees Cook 
6852a2b0acfSKees Cook 		record->size = psi->read(record);
6862a2b0acfSKees Cook 
6872a2b0acfSKees Cook 		/* No more records left in backend? */
688f6525b96SDouglas Anderson 		if (record->size <= 0) {
689f6525b96SDouglas Anderson 			kfree(record);
6902a2b0acfSKees Cook 			break;
691f6525b96SDouglas Anderson 		}
6922a2b0acfSKees Cook 
693438b8050SArd Biesheuvel 		decompress_record(record, &zstream);
6943a7d2fd1SKees Cook 		rc = pstore_mkfile(root, record);
6951dfff7ddSKees Cook 		if (rc) {
69683f70f07SKees Cook 			/* pstore_mkfile() did not take record, so free it. */
697104fd0b5SYuxiao Zhang 			kvfree(record->buf);
6988ca869b2SArd Biesheuvel 			kfree(record->priv);
69983f70f07SKees Cook 			kfree(record);
7001dfff7ddSKees Cook 			if (rc != -EEXIST || !quiet)
7011dfff7ddSKees Cook 				failed++;
7021dfff7ddSKees Cook 		}
703ca01d6ddSTony Luck 	}
7042174f6dfSKees Cook 	if (psi->close)
70506cf91b4SChen Gong 		psi->close(psi);
70606cf91b4SChen Gong out:
707f6f82851SKees Cook 	mutex_unlock(&psi->read_mutex);
708ca01d6ddSTony Luck 
709438b8050SArd Biesheuvel 	if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && compress) {
710438b8050SArd Biesheuvel 		if (zlib_inflateEnd(&zstream) != Z_OK)
711438b8050SArd Biesheuvel 			pr_warn("zlib_inflateEnd() failed\n");
712438b8050SArd Biesheuvel 		kvfree(zstream.workspace);
713438b8050SArd Biesheuvel 	}
714438b8050SArd Biesheuvel 
715ca01d6ddSTony Luck 	if (failed)
716656de42eSKees Cook 		pr_warn("failed to create %d record(s) from '%s'\n",
717ca01d6ddSTony Luck 			failed, psi->name);
718656de42eSKees Cook 	if (!stop_loop)
719656de42eSKees Cook 		pr_err("looping? Too many records seen from '%s'\n",
720656de42eSKees Cook 			psi->name);
721ca01d6ddSTony Luck }
722ca01d6ddSTony Luck 
7236dda9266SLuck, Tony static void pstore_dowork(struct work_struct *work)
7246dda9266SLuck, Tony {
7256dda9266SLuck, Tony 	pstore_get_records(1);
7266dda9266SLuck, Tony }
7276dda9266SLuck, Tony 
72824ed960aSKees Cook static void pstore_timefunc(struct timer_list *unused)
7296dda9266SLuck, Tony {
7306dda9266SLuck, Tony 	if (pstore_new_entry) {
7316dda9266SLuck, Tony 		pstore_new_entry = 0;
7326dda9266SLuck, Tony 		schedule_work(&pstore_work);
7336dda9266SLuck, Tony 	}
7346dda9266SLuck, Tony 
73578c83c82SKees Cook 	pstore_timer_kick();
7366dda9266SLuck, Tony }
7376dda9266SLuck, Tony 
738cb095afdSKees Cook static int __init pstore_init(void)
739cb095afdSKees Cook {
740cb095afdSKees Cook 	int ret;
741cb095afdSKees Cook 
742cb095afdSKees Cook 	ret = pstore_init_fs();
743cb095afdSKees Cook 	if (ret)
7448a57d6d4Schenqiwu 		free_buf_for_compression();
745cb095afdSKees Cook 
7468a57d6d4Schenqiwu 	return ret;
747cb095afdSKees Cook }
74841603165SJoel Fernandes (Google) late_initcall(pstore_init);
749cb095afdSKees Cook 
750cb095afdSKees Cook static void __exit pstore_exit(void)
751cb095afdSKees Cook {
752cb095afdSKees Cook 	pstore_exit_fs();
753cb095afdSKees Cook }
754cb095afdSKees Cook module_exit(pstore_exit)
755cb095afdSKees Cook 
756cb095afdSKees Cook MODULE_AUTHOR("Tony Luck <tony.luck@intel.com>");
757cb095afdSKees Cook MODULE_LICENSE("GPL");
758