pstore updates for v5.11-rc1

- Clean up unused but exposed API (Christoph Hellwig)
 - Provide KCONFIG for default size of kmsg buffer (Vasile-Laurentiu Stanimir)
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAl/ZGkcACgkQiXL039xt
 wCYNARAAsKPjvbUboWV7+77TgpK70F0yAxgDOSvaWx0jVGAZl/PR/Flq0/aXFw8d
 5KrvfqHsM9cvAVU1useFFbHlt31VvvL9Aws3sbuHMOr4Frw3ENjfj1hc/VmwY7Oc
 dBg73WF2IBgQW60JldO2qUzfJuGLTFDwfe8Ba3r906OpVbA1ibMt+lE1C5cdhZFE
 iAhP2FqHpJAPpSEPyHqGpMDfqHx3Ercvmjcq+HX6P+9u+tKMderlYimMhOos0Px3
 v0k8hAUyy+FXy9VNueJ4ljMhUQyiJ2YWba5vqqAlYoCy+rLmaGqbR5yg5lefjpQ9
 Ht7c20Lp9d/OMr8W2b89mHd1YCLh910CPeu21NVMQYB/MeOqwnkl34aSwgX/kMgn
 4Pdsq4gdrsIlyrloqiePibF+eLpEaEbF4IzQarekJ6Y4D7XlPeUS+RlJ/2BS6cfy
 1UXF+S8LjGW7Drh8a6Kqx/sZy9iM6gpR91YLFpOB4tJarKGh6s8A1UKJRqVj7Rp/
 LaDuyYKxAlGvUrYX2LsAptkRrC+6U7QU2xUzAKKGcwXIwBMlr6stk5QFbdOJcW9T
 wUvPx1MCqu0ZtA/L7da6Gj3N/ApcxdT0lPrm/l7meWSM/farxbiyNKczKuTt74Uz
 nMFEwJ+gFoeyM73EUcMThIj1ZhdznuyEG2MtmhuhqH/+0IK17wI=
 =3Lhs
 -----END PGP SIGNATURE-----

Merge tag 'pstore-v5.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull pstore updates from Kees Cook:

 - Clean up unused but exposed API (Christoph Hellwig)

 - Provide KCONFIG for default size of kmsg buffer (Vasile-Laurentiu
   Stanimir)

* tag 'pstore-v5.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  pstore: Move kmsg_bytes default into Kconfig
  pstore/blk: remove {un,}register_pstore_blk
  pstore/blk: update the command line example
  pstore/zone: cap the maximum device size
This commit is contained in:
Linus Torvalds 2020-12-16 11:25:16 -08:00
commit ba1d41a55e
8 changed files with 26 additions and 123 deletions

View File

@ -35,7 +35,7 @@ module parameters have priority over Kconfig.
Here is an example for module parameters:: Here is an example for module parameters::
pstore_blk.blkdev=179:7 pstore_blk.kmsg_size=64 pstore_blk.blkdev=/dev/mmcblk0p7 pstore_blk.kmsg_size=64 best_effort=y
The detail of each configurations may be of interest to you. The detail of each configurations may be of interest to you.
@ -151,10 +151,7 @@ otherwise KMSG_DUMP_MAX.
Configurations for driver Configurations for driver
------------------------- -------------------------
Only a block device driver cares about these configurations. A block device A device driver uses ``register_pstore_device`` with
driver uses ``register_pstore_blk`` to register to pstore/blk.
A non-block device driver uses ``register_pstore_device`` with
``struct pstore_device_info`` to register to pstore/blk. ``struct pstore_device_info`` to register to pstore/blk.
.. kernel-doc:: fs/pstore/blk.c .. kernel-doc:: fs/pstore/blk.c

View File

@ -14,6 +14,14 @@ config PSTORE
If you don't have a platform persistent store driver, If you don't have a platform persistent store driver,
say N. say N.
config PSTORE_DEFAULT_KMSG_BYTES
int "Default kernel log storage space" if EXPERT
depends on PSTORE
default "10240"
help
Defines default size of pstore kernel log storage.
Can be enlarged if needed, not recommended to shrink it.
config PSTORE_DEFLATE_COMPRESS config PSTORE_DEFLATE_COMPRESS
tristate "DEFLATE (ZLIB) compression" tristate "DEFLATE (ZLIB) compression"
default y default y

View File

@ -90,7 +90,6 @@ MODULE_PARM_DESC(blkdev, "block device for pstore storage");
static DEFINE_MUTEX(pstore_blk_lock); static DEFINE_MUTEX(pstore_blk_lock);
static struct block_device *psblk_bdev; static struct block_device *psblk_bdev;
static struct pstore_zone_info *pstore_zone_info; static struct pstore_zone_info *pstore_zone_info;
static pstore_blk_panic_write_op blkdev_panic_write;
struct bdev_info { struct bdev_info {
dev_t devt; dev_t devt;
@ -341,24 +340,11 @@ static ssize_t psblk_generic_blk_write(const char *buf, size_t bytes,
return ret; return ret;
} }
static ssize_t psblk_blk_panic_write(const char *buf, size_t size, /*
loff_t off) * This takes its configuration only from the module parameters now.
{ * See psblk_get_bdev() and blkdev.
int ret; */
static int __register_pstore_blk(void)
if (!blkdev_panic_write)
return -EOPNOTSUPP;
/* size and off must align to SECTOR_SIZE for block device */
ret = blkdev_panic_write(buf, off >> SECTOR_SHIFT,
size >> SECTOR_SHIFT);
/* try next zone */
if (ret == -ENOMSG)
return ret;
return ret ? -EIO : size;
}
static int __register_pstore_blk(struct pstore_blk_info *info)
{ {
char bdev_name[BDEVNAME_SIZE]; char bdev_name[BDEVNAME_SIZE];
struct block_device *bdev; struct block_device *bdev;
@ -378,68 +364,34 @@ static int __register_pstore_blk(struct pstore_blk_info *info)
} }
/* only allow driver matching the @blkdev */ /* only allow driver matching the @blkdev */
if (!binfo.devt || (!best_effort && if (!binfo.devt) {
MAJOR(binfo.devt) != info->major)) { pr_debug("no major\n");
pr_debug("invalid major %u (expect %u)\n",
info->major, MAJOR(binfo.devt));
ret = -ENODEV; ret = -ENODEV;
goto err_put_bdev; goto err_put_bdev;
} }
/* psblk_bdev must be assigned before register to pstore/blk */ /* psblk_bdev must be assigned before register to pstore/blk */
psblk_bdev = bdev; psblk_bdev = bdev;
blkdev_panic_write = info->panic_write;
/* Copy back block device details. */
info->devt = binfo.devt;
info->nr_sects = binfo.nr_sects;
info->start_sect = binfo.start_sect;
memset(&dev, 0, sizeof(dev)); memset(&dev, 0, sizeof(dev));
dev.total_size = info->nr_sects << SECTOR_SHIFT; dev.total_size = binfo.nr_sects << SECTOR_SHIFT;
dev.flags = info->flags;
dev.read = psblk_generic_blk_read; dev.read = psblk_generic_blk_read;
dev.write = psblk_generic_blk_write; dev.write = psblk_generic_blk_write;
dev.erase = NULL;
dev.panic_write = info->panic_write ? psblk_blk_panic_write : NULL;
ret = __register_pstore_device(&dev); ret = __register_pstore_device(&dev);
if (ret) if (ret)
goto err_put_bdev; goto err_put_bdev;
bdevname(bdev, bdev_name); bdevname(bdev, bdev_name);
pr_info("attached %s%s\n", bdev_name, pr_info("attached %s (no dedicated panic_write!)\n", bdev_name);
info->panic_write ? "" : " (no dedicated panic_write!)");
return 0; return 0;
err_put_bdev: err_put_bdev:
psblk_bdev = NULL; psblk_bdev = NULL;
blkdev_panic_write = NULL;
psblk_put_bdev(bdev, holder); psblk_put_bdev(bdev, holder);
return ret; return ret;
} }
/**
* register_pstore_blk() - register block device to pstore/blk
*
* @info: details on the desired block device interface
*
* Return:
* * 0 - OK
* * Others - something error.
*/
int register_pstore_blk(struct pstore_blk_info *info)
{
int ret;
mutex_lock(&pstore_blk_lock);
ret = __register_pstore_blk(info);
mutex_unlock(&pstore_blk_lock);
return ret;
}
EXPORT_SYMBOL_GPL(register_pstore_blk);
static void __unregister_pstore_blk(unsigned int major) static void __unregister_pstore_blk(unsigned int major)
{ {
struct pstore_device_info dev = { .read = psblk_generic_blk_read }; struct pstore_device_info dev = { .read = psblk_generic_blk_read };
@ -449,24 +401,10 @@ static void __unregister_pstore_blk(unsigned int major)
if (psblk_bdev && MAJOR(psblk_bdev->bd_dev) == major) { if (psblk_bdev && MAJOR(psblk_bdev->bd_dev) == major) {
__unregister_pstore_device(&dev); __unregister_pstore_device(&dev);
psblk_put_bdev(psblk_bdev, holder); psblk_put_bdev(psblk_bdev, holder);
blkdev_panic_write = NULL;
psblk_bdev = NULL; psblk_bdev = NULL;
} }
} }
/**
* unregister_pstore_blk() - unregister block device from pstore/blk
*
* @major: the major device number of device
*/
void unregister_pstore_blk(unsigned int major)
{
mutex_lock(&pstore_blk_lock);
__unregister_pstore_blk(major);
mutex_unlock(&pstore_blk_lock);
}
EXPORT_SYMBOL_GPL(unregister_pstore_blk);
/* get information of pstore/blk */ /* get information of pstore/blk */
int pstore_blk_get_config(struct pstore_blk_config *info) int pstore_blk_get_config(struct pstore_blk_config *info)
{ {
@ -483,12 +421,11 @@ EXPORT_SYMBOL_GPL(pstore_blk_get_config);
static int __init pstore_blk_init(void) static int __init pstore_blk_init(void)
{ {
struct pstore_blk_info info = { };
int ret = 0; int ret = 0;
mutex_lock(&pstore_blk_lock); mutex_lock(&pstore_blk_lock);
if (!pstore_zone_info && best_effort && blkdev[0]) if (!pstore_zone_info && best_effort && blkdev[0])
ret = __register_pstore_blk(&info); ret = __register_pstore_blk();
mutex_unlock(&pstore_blk_lock); mutex_unlock(&pstore_blk_lock);
return ret; return ret;

View File

@ -266,7 +266,7 @@ static void parse_options(char *options)
*/ */
static int pstore_show_options(struct seq_file *m, struct dentry *root) static int pstore_show_options(struct seq_file *m, struct dentry *root)
{ {
if (kmsg_bytes != PSTORE_DEFAULT_KMSG_BYTES) if (kmsg_bytes != CONFIG_PSTORE_DEFAULT_KMSG_BYTES)
seq_printf(m, ",kmsg_bytes=%lu", kmsg_bytes); seq_printf(m, ",kmsg_bytes=%lu", kmsg_bytes);
return 0; return 0;
} }

View File

@ -6,7 +6,6 @@
#include <linux/time.h> #include <linux/time.h>
#include <linux/pstore.h> #include <linux/pstore.h>
#define PSTORE_DEFAULT_KMSG_BYTES 10240
extern unsigned long kmsg_bytes; extern unsigned long kmsg_bytes;
#ifdef CONFIG_PSTORE_FTRACE #ifdef CONFIG_PSTORE_FTRACE

View File

@ -101,7 +101,7 @@ static char *big_oops_buf;
static size_t big_oops_buf_sz; static size_t big_oops_buf_sz;
/* How much of the console log to snapshot */ /* How much of the console log to snapshot */
unsigned long kmsg_bytes = PSTORE_DEFAULT_KMSG_BYTES; unsigned long kmsg_bytes = CONFIG_PSTORE_DEFAULT_KMSG_BYTES;
void pstore_set_kmsg_bytes(int bytes) void pstore_set_kmsg_bytes(int bytes)
{ {

View File

@ -1299,6 +1299,10 @@ int register_pstore_zone(struct pstore_zone_info *info)
pr_warn("total_size must be >= 4096\n"); pr_warn("total_size must be >= 4096\n");
return -EINVAL; return -EINVAL;
} }
if (info->total_size > SZ_128M) {
pr_warn("capping size to 128MiB\n");
info->total_size = SZ_128M;
}
if (!info->kmsg_size && !info->pmsg_size && !info->console_size && if (!info->kmsg_size && !info->pmsg_size && !info->console_size &&
!info->ftrace_size) { !info->ftrace_size) {

View File

@ -7,48 +7,6 @@
#include <linux/pstore.h> #include <linux/pstore.h>
#include <linux/pstore_zone.h> #include <linux/pstore_zone.h>
/**
* typedef pstore_blk_panic_write_op - panic write operation to block device
*
* @buf: the data to write
* @start_sect: start sector to block device
* @sects: sectors count on buf
*
* Return: On success, zero should be returned. Others excluding -ENOMSG
* mean error. -ENOMSG means to try next zone.
*
* Panic write to block device must be aligned to SECTOR_SIZE.
*/
typedef int (*pstore_blk_panic_write_op)(const char *buf, sector_t start_sect,
sector_t sects);
/**
* struct pstore_blk_info - pstore/blk registration details
*
* @major: Which major device number to support with pstore/blk
* @flags: The supported PSTORE_FLAGS_* from linux/pstore.h.
* @panic_write:The write operation only used for the panic case.
* This can be NULL, but is recommended to avoid losing
* crash data if the kernel's IO path or work queues are
* broken during a panic.
* @devt: The dev_t that pstore/blk has attached to.
* @nr_sects: Number of sectors on @devt.
* @start_sect: Starting sector on @devt.
*/
struct pstore_blk_info {
unsigned int major;
unsigned int flags;
pstore_blk_panic_write_op panic_write;
/* Filled in by pstore/blk after registration. */
dev_t devt;
sector_t nr_sects;
sector_t start_sect;
};
int register_pstore_blk(struct pstore_blk_info *info);
void unregister_pstore_blk(unsigned int major);
/** /**
* struct pstore_device_info - back-end pstore/blk driver structure. * struct pstore_device_info - back-end pstore/blk driver structure.
* *