2019-02-02 10:41:15 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
2013-02-08 15:48:51 +00:00
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pstore.h>
|
2013-05-01 17:51:54 -07:00
|
|
|
#include <linux/slab.h>
|
2013-04-30 11:30:24 +01:00
|
|
|
#include <linux/ucs2_string.h>
|
2013-02-08 15:48:51 +00:00
|
|
|
|
module: Convert symbol namespace to string literal
Clean up the existing export namespace code along the same lines of
commit 33def8498fdd ("treewide: Convert macro and uses of __section(foo)
to __section("foo")") and for the same reason, it is not desired for the
namespace argument to be a macro expansion itself.
Scripted using
git grep -l -e MODULE_IMPORT_NS -e EXPORT_SYMBOL_NS | while read file;
do
awk -i inplace '
/^#define EXPORT_SYMBOL_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/^#define MODULE_IMPORT_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/MODULE_IMPORT_NS/ {
$0 = gensub(/MODULE_IMPORT_NS\(([^)]*)\)/, "MODULE_IMPORT_NS(\"\\1\")", "g");
}
/EXPORT_SYMBOL_NS/ {
if ($0 ~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+),/) {
if ($0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/ &&
$0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(\)/ &&
$0 !~ /^my/) {
getline line;
gsub(/[[:space:]]*\\$/, "");
gsub(/[[:space:]]/, "", line);
$0 = $0 " " line;
}
$0 = gensub(/(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/,
"\\1(\\2, \"\\3\")", "g");
}
}
{ print }' $file;
done
Requested-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://mail.google.com/mail/u/2/#inbox/FMfcgzQXKWgMmjdFwwdsfgxzKpVHWPlc
Acked-by: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-12-02 15:59:47 +01:00
|
|
|
MODULE_IMPORT_NS("EFIVAR");
|
2022-06-20 13:21:26 +02:00
|
|
|
|
2017-05-19 13:21:07 -07:00
|
|
|
#define DUMP_NAME_LEN 66
|
2013-02-08 15:48:51 +00:00
|
|
|
|
efi: pstore: Add module parameter for setting the record size
By default, the efi-pstore backend hardcode the UEFI variable size
as 1024 bytes. The historical reasons for that were discussed by
Ard in threads [0][1]:
"there is some cargo cult from prehistoric EFI times going
on here, it seems. Or maybe just misinterpretation of the maximum
size for the variable *name* vs the variable itself.".
"OVMF has
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400
where the first one is without secure boot and the second with secure
boot. Interestingly, the default is
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400
so this is probably where this 1k number comes from."
With that, and since there is not such a limit in the UEFI spec, we
have the confidence to hereby add a module parameter to enable advanced
users to change the UEFI record size for efi-pstore data collection,
this way allowing a much easier reading of the collected log, which
wouldn't be scattered anymore among many small files.
Through empirical analysis we observed that extreme low values (like 8
bytes) could eventually cause writing issues, so given that and the OVMF
default discussed, we limited the minimum value to 1024 bytes, which also
is still the default.
[0] https://lore.kernel.org/lkml/CAMj1kXF4UyRMh2Y_KakeNBHvkHhTtavASTAxXinDO1rhPe_wYg@mail.gmail.com/
[1] https://lore.kernel.org/lkml/CAMj1kXFy-2KddGu+dgebAdU9v2sindxVoiHLWuVhqYw+R=kqng@mail.gmail.com/
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2022-11-01 15:48:07 -03:00
|
|
|
static unsigned int record_size = 1024;
|
|
|
|
module_param(record_size, uint, 0444);
|
|
|
|
MODULE_PARM_DESC(record_size, "size of each pstore UEFI var (in bytes, min/default=1024)");
|
2020-09-23 09:56:14 +02:00
|
|
|
|
2013-02-08 15:48:51 +00:00
|
|
|
#define PSTORE_EFI_ATTRIBUTES \
|
|
|
|
(EFI_VARIABLE_NON_VOLATILE | \
|
|
|
|
EFI_VARIABLE_BOOTSERVICE_ACCESS | \
|
|
|
|
EFI_VARIABLE_RUNTIME_ACCESS)
|
|
|
|
|
2024-01-03 15:40:32 -03:00
|
|
|
static bool pstore_disable = IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
|
|
|
|
|
|
|
|
static int efivars_pstore_init(void);
|
|
|
|
static void efivars_pstore_exit(void);
|
|
|
|
|
|
|
|
static int efi_pstore_disable_set(const char *val, const struct kernel_param *kp)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
bool old_pstore_disable = pstore_disable;
|
|
|
|
|
|
|
|
err = param_set_bool(val, kp);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (old_pstore_disable != pstore_disable) {
|
|
|
|
if (pstore_disable)
|
|
|
|
efivars_pstore_exit();
|
|
|
|
else
|
|
|
|
efivars_pstore_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct kernel_param_ops pstore_disable_ops = {
|
|
|
|
.set = efi_pstore_disable_set,
|
|
|
|
.get = param_get_bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_param_cb(pstore_disable, &pstore_disable_ops, &pstore_disable, 0644);
|
|
|
|
__MODULE_PARM_TYPE(pstore_disable, "bool");
|
|
|
|
|
2013-02-08 15:48:51 +00:00
|
|
|
static int efi_pstore_open(struct pstore_info *psi)
|
|
|
|
{
|
2022-06-20 13:21:26 +02:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = efivar_lock();
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
efi: pstore: Add module parameter for setting the record size
By default, the efi-pstore backend hardcode the UEFI variable size
as 1024 bytes. The historical reasons for that were discussed by
Ard in threads [0][1]:
"there is some cargo cult from prehistoric EFI times going
on here, it seems. Or maybe just misinterpretation of the maximum
size for the variable *name* vs the variable itself.".
"OVMF has
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400
where the first one is without secure boot and the second with secure
boot. Interestingly, the default is
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400
so this is probably where this 1k number comes from."
With that, and since there is not such a limit in the UEFI spec, we
have the confidence to hereby add a module parameter to enable advanced
users to change the UEFI record size for efi-pstore data collection,
this way allowing a much easier reading of the collected log, which
wouldn't be scattered anymore among many small files.
Through empirical analysis we observed that extreme low values (like 8
bytes) could eventually cause writing issues, so given that and the OVMF
default discussed, we limited the minimum value to 1024 bytes, which also
is still the default.
[0] https://lore.kernel.org/lkml/CAMj1kXF4UyRMh2Y_KakeNBHvkHhTtavASTAxXinDO1rhPe_wYg@mail.gmail.com/
[1] https://lore.kernel.org/lkml/CAMj1kXFy-2KddGu+dgebAdU9v2sindxVoiHLWuVhqYw+R=kqng@mail.gmail.com/
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2022-11-01 15:48:07 -03:00
|
|
|
psi->data = kzalloc(record_size, GFP_KERNEL);
|
2022-06-20 13:21:26 +02:00
|
|
|
if (!psi->data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-02-08 15:48:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efi_pstore_close(struct pstore_info *psi)
|
|
|
|
{
|
2022-06-20 13:21:26 +02:00
|
|
|
efivar_unlock();
|
|
|
|
kfree(psi->data);
|
2013-02-08 15:48:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-14 15:50:52 -07:00
|
|
|
static inline u64 generic_id(u64 timestamp, unsigned int part, int count)
|
2013-11-29 15:58:57 +08:00
|
|
|
{
|
2018-05-14 15:50:52 -07:00
|
|
|
return (timestamp * 100 + part) * 1000 + count;
|
2013-11-29 15:58:57 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
static int efi_pstore_read_func(struct pstore_record *record,
|
|
|
|
efi_char16_t *varname)
|
2013-02-08 15:48:51 +00:00
|
|
|
{
|
efi: pstore: Add module parameter for setting the record size
By default, the efi-pstore backend hardcode the UEFI variable size
as 1024 bytes. The historical reasons for that were discussed by
Ard in threads [0][1]:
"there is some cargo cult from prehistoric EFI times going
on here, it seems. Or maybe just misinterpretation of the maximum
size for the variable *name* vs the variable itself.".
"OVMF has
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400
where the first one is without secure boot and the second with secure
boot. Interestingly, the default is
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400
so this is probably where this 1k number comes from."
With that, and since there is not such a limit in the UEFI spec, we
have the confidence to hereby add a module parameter to enable advanced
users to change the UEFI record size for efi-pstore data collection,
this way allowing a much easier reading of the collected log, which
wouldn't be scattered anymore among many small files.
Through empirical analysis we observed that extreme low values (like 8
bytes) could eventually cause writing issues, so given that and the OVMF
default discussed, we limited the minimum value to 1024 bytes, which also
is still the default.
[0] https://lore.kernel.org/lkml/CAMj1kXF4UyRMh2Y_KakeNBHvkHhTtavASTAxXinDO1rhPe_wYg@mail.gmail.com/
[1] https://lore.kernel.org/lkml/CAMj1kXFy-2KddGu+dgebAdU9v2sindxVoiHLWuVhqYw+R=kqng@mail.gmail.com/
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2022-11-01 15:48:07 -03:00
|
|
|
unsigned long wlen, size = record_size;
|
2013-08-16 13:57:51 -07:00
|
|
|
char name[DUMP_NAME_LEN], data_type;
|
2022-06-20 13:21:26 +02:00
|
|
|
efi_status_t status;
|
2013-02-08 15:48:51 +00:00
|
|
|
int cnt;
|
|
|
|
unsigned int part;
|
2018-05-14 15:50:52 -07:00
|
|
|
u64 time;
|
2013-02-08 15:48:51 +00:00
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
ucs2_as_utf8(name, varname, DUMP_NAME_LEN);
|
2013-02-08 15:48:51 +00:00
|
|
|
|
2018-05-14 15:50:52 -07:00
|
|
|
if (sscanf(name, "dump-type%u-%u-%d-%llu-%c",
|
2017-03-03 22:09:18 -08:00
|
|
|
&record->type, &part, &cnt, &time, &data_type) == 5) {
|
|
|
|
record->id = generic_id(time, part, cnt);
|
2017-05-18 13:07:49 -07:00
|
|
|
record->part = part;
|
2017-03-03 22:09:18 -08:00
|
|
|
record->count = cnt;
|
|
|
|
record->time.tv_sec = time;
|
|
|
|
record->time.tv_nsec = 0;
|
2013-08-16 13:57:51 -07:00
|
|
|
if (data_type == 'C')
|
2017-03-03 22:09:18 -08:00
|
|
|
record->compressed = true;
|
2013-08-16 13:57:51 -07:00
|
|
|
else
|
2017-03-03 22:09:18 -08:00
|
|
|
record->compressed = false;
|
|
|
|
record->ecc_notice_size = 0;
|
2018-05-14 15:50:52 -07:00
|
|
|
} else if (sscanf(name, "dump-type%u-%u-%d-%llu",
|
2017-03-03 22:09:18 -08:00
|
|
|
&record->type, &part, &cnt, &time) == 4) {
|
|
|
|
record->id = generic_id(time, part, cnt);
|
2017-05-18 13:07:49 -07:00
|
|
|
record->part = part;
|
2017-03-03 22:09:18 -08:00
|
|
|
record->count = cnt;
|
|
|
|
record->time.tv_sec = time;
|
|
|
|
record->time.tv_nsec = 0;
|
|
|
|
record->compressed = false;
|
|
|
|
record->ecc_notice_size = 0;
|
2018-05-14 15:50:52 -07:00
|
|
|
} else if (sscanf(name, "dump-type%u-%u-%llu",
|
2017-03-03 22:09:18 -08:00
|
|
|
&record->type, &part, &time) == 3) {
|
2013-02-08 15:48:51 +00:00
|
|
|
/*
|
|
|
|
* Check if an old format,
|
|
|
|
* which doesn't support holding
|
|
|
|
* multiple logs, remains.
|
|
|
|
*/
|
2017-03-03 22:09:18 -08:00
|
|
|
record->id = generic_id(time, part, 0);
|
2017-05-18 13:07:49 -07:00
|
|
|
record->part = part;
|
2017-03-03 22:09:18 -08:00
|
|
|
record->count = 0;
|
|
|
|
record->time.tv_sec = time;
|
|
|
|
record->time.tv_nsec = 0;
|
|
|
|
record->compressed = false;
|
|
|
|
record->ecc_notice_size = 0;
|
2013-02-08 15:48:51 +00:00
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
record->buf = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (!record->buf)
|
|
|
|
return -ENOMEM;
|
efivars, efi-pstore: Hold off deletion of sysfs entry until the scan is completed
Currently, when mounting pstore file system, a read callback of
efi_pstore driver runs mutiple times as below.
- In the first read callback, scan efivar_sysfs_list from head and pass
a kmsg buffer of a entry to an upper pstore layer.
- In the second read callback, rescan efivar_sysfs_list from the entry
and pass another kmsg buffer to it.
- Repeat the scan and pass until the end of efivar_sysfs_list.
In this process, an entry is read across the multiple read function
calls. To avoid race between the read and erasion, the whole process
above is protected by a spinlock, holding in open() and releasing in
close().
At the same time, kmemdup() is called to pass the buffer to pstore
filesystem during it. And then, it causes a following lockdep warning.
To make the dynamic memory allocation runnable without taking spinlock,
holding off a deletion of sysfs entry if it happens while scanning it
via efi_pstore, and deleting it after the scan is completed.
To implement it, this patch introduces two flags, scanning and deleting,
to efivar_entry.
On the code basis, it seems that all the scanning and deleting logic is
not needed because __efivars->lock are not dropped when reading from the
EFI variable store.
But, the scanning and deleting logic is still needed because an
efi-pstore and a pstore filesystem works as follows.
In case an entry(A) is found, the pointer is saved to psi->data. And
efi_pstore_read() passes the entry(A) to a pstore filesystem by
releasing __efivars->lock.
And then, the pstore filesystem calls efi_pstore_read() again and the
same entry(A), which is saved to psi->data, is used for resuming to scan
a sysfs-list.
So, to protect the entry(A), the logic is needed.
[ 1.143710] ------------[ cut here ]------------
[ 1.144058] WARNING: CPU: 1 PID: 1 at kernel/lockdep.c:2740 lockdep_trace_alloc+0x104/0x110()
[ 1.144058] DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))
[ 1.144058] Modules linked in:
[ 1.144058] CPU: 1 PID: 1 Comm: systemd Not tainted 3.11.0-rc5 #2
[ 1.144058] 0000000000000009 ffff8800797e9ae0 ffffffff816614a5 ffff8800797e9b28
[ 1.144058] ffff8800797e9b18 ffffffff8105510d 0000000000000080 0000000000000046
[ 1.144058] 00000000000000d0 00000000000003af ffffffff81ccd0c0 ffff8800797e9b78
[ 1.144058] Call Trace:
[ 1.144058] [<ffffffff816614a5>] dump_stack+0x54/0x74
[ 1.144058] [<ffffffff8105510d>] warn_slowpath_common+0x7d/0xa0
[ 1.144058] [<ffffffff8105517c>] warn_slowpath_fmt+0x4c/0x50
[ 1.144058] [<ffffffff8131290f>] ? vsscanf+0x57f/0x7b0
[ 1.144058] [<ffffffff810bbd74>] lockdep_trace_alloc+0x104/0x110
[ 1.144058] [<ffffffff81192da0>] __kmalloc_track_caller+0x50/0x280
[ 1.144058] [<ffffffff815147bb>] ? efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff8115b260>] kmemdup+0x20/0x50
[ 1.144058] [<ffffffff815147bb>] efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff81514800>] ? efi_pstore_read_func.part.1+0x170/0x170
[ 1.144058] [<ffffffff815148b4>] efi_pstore_read_func+0xb4/0xe0
[ 1.144058] [<ffffffff81512b7b>] __efivar_entry_iter+0xfb/0x120
[ 1.144058] [<ffffffff8151428f>] efi_pstore_read+0x3f/0x50
[ 1.144058] [<ffffffff8128d7ba>] pstore_get_records+0x9a/0x150
[ 1.158207] [<ffffffff812af25c>] ? selinux_d_instantiate+0x1c/0x20
[ 1.158207] [<ffffffff8128ce30>] ? parse_options+0x80/0x80
[ 1.158207] [<ffffffff8128ced5>] pstore_fill_super+0xa5/0xc0
[ 1.158207] [<ffffffff811ae7d2>] mount_single+0xa2/0xd0
[ 1.158207] [<ffffffff8128ccf8>] pstore_mount+0x18/0x20
[ 1.158207] [<ffffffff811ae8b9>] mount_fs+0x39/0x1b0
[ 1.158207] [<ffffffff81160550>] ? __alloc_percpu+0x10/0x20
[ 1.158207] [<ffffffff811c9493>] vfs_kern_mount+0x63/0xf0
[ 1.158207] [<ffffffff811cbb0e>] do_mount+0x23e/0xa20
[ 1.158207] [<ffffffff8115b51b>] ? strndup_user+0x4b/0xf0
[ 1.158207] [<ffffffff811cc373>] SyS_mount+0x83/0xc0
[ 1.158207] [<ffffffff81673cc2>] system_call_fastpath+0x16/0x1b
[ 1.158207] ---[ end trace 61981bc62de9f6f4 ]---
Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com>
Tested-by: Madper Xie <cxie@redhat.com>
Cc: stable@kernel.org
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
2013-10-30 15:27:26 -04:00
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
status = efivar_get_variable(varname, &LINUX_EFI_CRASH_GUID, NULL,
|
|
|
|
&size, record->buf);
|
|
|
|
if (status != EFI_SUCCESS) {
|
|
|
|
kfree(record->buf);
|
2024-05-19 13:33:53 -03:00
|
|
|
return efi_status_to_err(status);
|
efivars, efi-pstore: Hold off deletion of sysfs entry until the scan is completed
Currently, when mounting pstore file system, a read callback of
efi_pstore driver runs mutiple times as below.
- In the first read callback, scan efivar_sysfs_list from head and pass
a kmsg buffer of a entry to an upper pstore layer.
- In the second read callback, rescan efivar_sysfs_list from the entry
and pass another kmsg buffer to it.
- Repeat the scan and pass until the end of efivar_sysfs_list.
In this process, an entry is read across the multiple read function
calls. To avoid race between the read and erasion, the whole process
above is protected by a spinlock, holding in open() and releasing in
close().
At the same time, kmemdup() is called to pass the buffer to pstore
filesystem during it. And then, it causes a following lockdep warning.
To make the dynamic memory allocation runnable without taking spinlock,
holding off a deletion of sysfs entry if it happens while scanning it
via efi_pstore, and deleting it after the scan is completed.
To implement it, this patch introduces two flags, scanning and deleting,
to efivar_entry.
On the code basis, it seems that all the scanning and deleting logic is
not needed because __efivars->lock are not dropped when reading from the
EFI variable store.
But, the scanning and deleting logic is still needed because an
efi-pstore and a pstore filesystem works as follows.
In case an entry(A) is found, the pointer is saved to psi->data. And
efi_pstore_read() passes the entry(A) to a pstore filesystem by
releasing __efivars->lock.
And then, the pstore filesystem calls efi_pstore_read() again and the
same entry(A), which is saved to psi->data, is used for resuming to scan
a sysfs-list.
So, to protect the entry(A), the logic is needed.
[ 1.143710] ------------[ cut here ]------------
[ 1.144058] WARNING: CPU: 1 PID: 1 at kernel/lockdep.c:2740 lockdep_trace_alloc+0x104/0x110()
[ 1.144058] DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))
[ 1.144058] Modules linked in:
[ 1.144058] CPU: 1 PID: 1 Comm: systemd Not tainted 3.11.0-rc5 #2
[ 1.144058] 0000000000000009 ffff8800797e9ae0 ffffffff816614a5 ffff8800797e9b28
[ 1.144058] ffff8800797e9b18 ffffffff8105510d 0000000000000080 0000000000000046
[ 1.144058] 00000000000000d0 00000000000003af ffffffff81ccd0c0 ffff8800797e9b78
[ 1.144058] Call Trace:
[ 1.144058] [<ffffffff816614a5>] dump_stack+0x54/0x74
[ 1.144058] [<ffffffff8105510d>] warn_slowpath_common+0x7d/0xa0
[ 1.144058] [<ffffffff8105517c>] warn_slowpath_fmt+0x4c/0x50
[ 1.144058] [<ffffffff8131290f>] ? vsscanf+0x57f/0x7b0
[ 1.144058] [<ffffffff810bbd74>] lockdep_trace_alloc+0x104/0x110
[ 1.144058] [<ffffffff81192da0>] __kmalloc_track_caller+0x50/0x280
[ 1.144058] [<ffffffff815147bb>] ? efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff8115b260>] kmemdup+0x20/0x50
[ 1.144058] [<ffffffff815147bb>] efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff81514800>] ? efi_pstore_read_func.part.1+0x170/0x170
[ 1.144058] [<ffffffff815148b4>] efi_pstore_read_func+0xb4/0xe0
[ 1.144058] [<ffffffff81512b7b>] __efivar_entry_iter+0xfb/0x120
[ 1.144058] [<ffffffff8151428f>] efi_pstore_read+0x3f/0x50
[ 1.144058] [<ffffffff8128d7ba>] pstore_get_records+0x9a/0x150
[ 1.158207] [<ffffffff812af25c>] ? selinux_d_instantiate+0x1c/0x20
[ 1.158207] [<ffffffff8128ce30>] ? parse_options+0x80/0x80
[ 1.158207] [<ffffffff8128ced5>] pstore_fill_super+0xa5/0xc0
[ 1.158207] [<ffffffff811ae7d2>] mount_single+0xa2/0xd0
[ 1.158207] [<ffffffff8128ccf8>] pstore_mount+0x18/0x20
[ 1.158207] [<ffffffff811ae8b9>] mount_fs+0x39/0x1b0
[ 1.158207] [<ffffffff81160550>] ? __alloc_percpu+0x10/0x20
[ 1.158207] [<ffffffff811c9493>] vfs_kern_mount+0x63/0xf0
[ 1.158207] [<ffffffff811cbb0e>] do_mount+0x23e/0xa20
[ 1.158207] [<ffffffff8115b51b>] ? strndup_user+0x4b/0xf0
[ 1.158207] [<ffffffff811cc373>] SyS_mount+0x83/0xc0
[ 1.158207] [<ffffffff81673cc2>] system_call_fastpath+0x16/0x1b
[ 1.158207] ---[ end trace 61981bc62de9f6f4 ]---
Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com>
Tested-by: Madper Xie <cxie@redhat.com>
Cc: stable@kernel.org
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
2013-10-30 15:27:26 -04:00
|
|
|
}
|
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
/*
|
|
|
|
* Store the name of the variable in the pstore_record priv field, so
|
|
|
|
* we can reuse it later if we need to delete the EFI variable from the
|
|
|
|
* variable store.
|
|
|
|
*/
|
|
|
|
wlen = (ucs2_strnlen(varname, DUMP_NAME_LEN) + 1) * sizeof(efi_char16_t);
|
|
|
|
record->priv = kmemdup(varname, wlen, GFP_KERNEL);
|
|
|
|
if (!record->priv) {
|
|
|
|
kfree(record->buf);
|
|
|
|
return -ENOMEM;
|
efivars, efi-pstore: Hold off deletion of sysfs entry until the scan is completed
Currently, when mounting pstore file system, a read callback of
efi_pstore driver runs mutiple times as below.
- In the first read callback, scan efivar_sysfs_list from head and pass
a kmsg buffer of a entry to an upper pstore layer.
- In the second read callback, rescan efivar_sysfs_list from the entry
and pass another kmsg buffer to it.
- Repeat the scan and pass until the end of efivar_sysfs_list.
In this process, an entry is read across the multiple read function
calls. To avoid race between the read and erasion, the whole process
above is protected by a spinlock, holding in open() and releasing in
close().
At the same time, kmemdup() is called to pass the buffer to pstore
filesystem during it. And then, it causes a following lockdep warning.
To make the dynamic memory allocation runnable without taking spinlock,
holding off a deletion of sysfs entry if it happens while scanning it
via efi_pstore, and deleting it after the scan is completed.
To implement it, this patch introduces two flags, scanning and deleting,
to efivar_entry.
On the code basis, it seems that all the scanning and deleting logic is
not needed because __efivars->lock are not dropped when reading from the
EFI variable store.
But, the scanning and deleting logic is still needed because an
efi-pstore and a pstore filesystem works as follows.
In case an entry(A) is found, the pointer is saved to psi->data. And
efi_pstore_read() passes the entry(A) to a pstore filesystem by
releasing __efivars->lock.
And then, the pstore filesystem calls efi_pstore_read() again and the
same entry(A), which is saved to psi->data, is used for resuming to scan
a sysfs-list.
So, to protect the entry(A), the logic is needed.
[ 1.143710] ------------[ cut here ]------------
[ 1.144058] WARNING: CPU: 1 PID: 1 at kernel/lockdep.c:2740 lockdep_trace_alloc+0x104/0x110()
[ 1.144058] DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))
[ 1.144058] Modules linked in:
[ 1.144058] CPU: 1 PID: 1 Comm: systemd Not tainted 3.11.0-rc5 #2
[ 1.144058] 0000000000000009 ffff8800797e9ae0 ffffffff816614a5 ffff8800797e9b28
[ 1.144058] ffff8800797e9b18 ffffffff8105510d 0000000000000080 0000000000000046
[ 1.144058] 00000000000000d0 00000000000003af ffffffff81ccd0c0 ffff8800797e9b78
[ 1.144058] Call Trace:
[ 1.144058] [<ffffffff816614a5>] dump_stack+0x54/0x74
[ 1.144058] [<ffffffff8105510d>] warn_slowpath_common+0x7d/0xa0
[ 1.144058] [<ffffffff8105517c>] warn_slowpath_fmt+0x4c/0x50
[ 1.144058] [<ffffffff8131290f>] ? vsscanf+0x57f/0x7b0
[ 1.144058] [<ffffffff810bbd74>] lockdep_trace_alloc+0x104/0x110
[ 1.144058] [<ffffffff81192da0>] __kmalloc_track_caller+0x50/0x280
[ 1.144058] [<ffffffff815147bb>] ? efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff8115b260>] kmemdup+0x20/0x50
[ 1.144058] [<ffffffff815147bb>] efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff81514800>] ? efi_pstore_read_func.part.1+0x170/0x170
[ 1.144058] [<ffffffff815148b4>] efi_pstore_read_func+0xb4/0xe0
[ 1.144058] [<ffffffff81512b7b>] __efivar_entry_iter+0xfb/0x120
[ 1.144058] [<ffffffff8151428f>] efi_pstore_read+0x3f/0x50
[ 1.144058] [<ffffffff8128d7ba>] pstore_get_records+0x9a/0x150
[ 1.158207] [<ffffffff812af25c>] ? selinux_d_instantiate+0x1c/0x20
[ 1.158207] [<ffffffff8128ce30>] ? parse_options+0x80/0x80
[ 1.158207] [<ffffffff8128ced5>] pstore_fill_super+0xa5/0xc0
[ 1.158207] [<ffffffff811ae7d2>] mount_single+0xa2/0xd0
[ 1.158207] [<ffffffff8128ccf8>] pstore_mount+0x18/0x20
[ 1.158207] [<ffffffff811ae8b9>] mount_fs+0x39/0x1b0
[ 1.158207] [<ffffffff81160550>] ? __alloc_percpu+0x10/0x20
[ 1.158207] [<ffffffff811c9493>] vfs_kern_mount+0x63/0xf0
[ 1.158207] [<ffffffff811cbb0e>] do_mount+0x23e/0xa20
[ 1.158207] [<ffffffff8115b51b>] ? strndup_user+0x4b/0xf0
[ 1.158207] [<ffffffff811cc373>] SyS_mount+0x83/0xc0
[ 1.158207] [<ffffffff81673cc2>] system_call_fastpath+0x16/0x1b
[ 1.158207] ---[ end trace 61981bc62de9f6f4 ]---
Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com>
Tested-by: Madper Xie <cxie@redhat.com>
Cc: stable@kernel.org
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
2013-10-30 15:27:26 -04:00
|
|
|
}
|
2022-06-20 13:21:26 +02:00
|
|
|
|
efivars, efi-pstore: Hold off deletion of sysfs entry until the scan is completed
Currently, when mounting pstore file system, a read callback of
efi_pstore driver runs mutiple times as below.
- In the first read callback, scan efivar_sysfs_list from head and pass
a kmsg buffer of a entry to an upper pstore layer.
- In the second read callback, rescan efivar_sysfs_list from the entry
and pass another kmsg buffer to it.
- Repeat the scan and pass until the end of efivar_sysfs_list.
In this process, an entry is read across the multiple read function
calls. To avoid race between the read and erasion, the whole process
above is protected by a spinlock, holding in open() and releasing in
close().
At the same time, kmemdup() is called to pass the buffer to pstore
filesystem during it. And then, it causes a following lockdep warning.
To make the dynamic memory allocation runnable without taking spinlock,
holding off a deletion of sysfs entry if it happens while scanning it
via efi_pstore, and deleting it after the scan is completed.
To implement it, this patch introduces two flags, scanning and deleting,
to efivar_entry.
On the code basis, it seems that all the scanning and deleting logic is
not needed because __efivars->lock are not dropped when reading from the
EFI variable store.
But, the scanning and deleting logic is still needed because an
efi-pstore and a pstore filesystem works as follows.
In case an entry(A) is found, the pointer is saved to psi->data. And
efi_pstore_read() passes the entry(A) to a pstore filesystem by
releasing __efivars->lock.
And then, the pstore filesystem calls efi_pstore_read() again and the
same entry(A), which is saved to psi->data, is used for resuming to scan
a sysfs-list.
So, to protect the entry(A), the logic is needed.
[ 1.143710] ------------[ cut here ]------------
[ 1.144058] WARNING: CPU: 1 PID: 1 at kernel/lockdep.c:2740 lockdep_trace_alloc+0x104/0x110()
[ 1.144058] DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))
[ 1.144058] Modules linked in:
[ 1.144058] CPU: 1 PID: 1 Comm: systemd Not tainted 3.11.0-rc5 #2
[ 1.144058] 0000000000000009 ffff8800797e9ae0 ffffffff816614a5 ffff8800797e9b28
[ 1.144058] ffff8800797e9b18 ffffffff8105510d 0000000000000080 0000000000000046
[ 1.144058] 00000000000000d0 00000000000003af ffffffff81ccd0c0 ffff8800797e9b78
[ 1.144058] Call Trace:
[ 1.144058] [<ffffffff816614a5>] dump_stack+0x54/0x74
[ 1.144058] [<ffffffff8105510d>] warn_slowpath_common+0x7d/0xa0
[ 1.144058] [<ffffffff8105517c>] warn_slowpath_fmt+0x4c/0x50
[ 1.144058] [<ffffffff8131290f>] ? vsscanf+0x57f/0x7b0
[ 1.144058] [<ffffffff810bbd74>] lockdep_trace_alloc+0x104/0x110
[ 1.144058] [<ffffffff81192da0>] __kmalloc_track_caller+0x50/0x280
[ 1.144058] [<ffffffff815147bb>] ? efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff8115b260>] kmemdup+0x20/0x50
[ 1.144058] [<ffffffff815147bb>] efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff81514800>] ? efi_pstore_read_func.part.1+0x170/0x170
[ 1.144058] [<ffffffff815148b4>] efi_pstore_read_func+0xb4/0xe0
[ 1.144058] [<ffffffff81512b7b>] __efivar_entry_iter+0xfb/0x120
[ 1.144058] [<ffffffff8151428f>] efi_pstore_read+0x3f/0x50
[ 1.144058] [<ffffffff8128d7ba>] pstore_get_records+0x9a/0x150
[ 1.158207] [<ffffffff812af25c>] ? selinux_d_instantiate+0x1c/0x20
[ 1.158207] [<ffffffff8128ce30>] ? parse_options+0x80/0x80
[ 1.158207] [<ffffffff8128ced5>] pstore_fill_super+0xa5/0xc0
[ 1.158207] [<ffffffff811ae7d2>] mount_single+0xa2/0xd0
[ 1.158207] [<ffffffff8128ccf8>] pstore_mount+0x18/0x20
[ 1.158207] [<ffffffff811ae8b9>] mount_fs+0x39/0x1b0
[ 1.158207] [<ffffffff81160550>] ? __alloc_percpu+0x10/0x20
[ 1.158207] [<ffffffff811c9493>] vfs_kern_mount+0x63/0xf0
[ 1.158207] [<ffffffff811cbb0e>] do_mount+0x23e/0xa20
[ 1.158207] [<ffffffff8115b51b>] ? strndup_user+0x4b/0xf0
[ 1.158207] [<ffffffff811cc373>] SyS_mount+0x83/0xc0
[ 1.158207] [<ffffffff81673cc2>] system_call_fastpath+0x16/0x1b
[ 1.158207] ---[ end trace 61981bc62de9f6f4 ]---
Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com>
Tested-by: Madper Xie <cxie@redhat.com>
Cc: stable@kernel.org
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
2013-10-30 15:27:26 -04:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2017-03-03 22:09:18 -08:00
|
|
|
static ssize_t efi_pstore_read(struct pstore_record *record)
|
2013-02-08 15:48:51 +00:00
|
|
|
{
|
2022-06-20 13:21:26 +02:00
|
|
|
efi_char16_t *varname = record->psi->data;
|
|
|
|
efi_guid_t guid = LINUX_EFI_CRASH_GUID;
|
|
|
|
unsigned long varname_size;
|
|
|
|
efi_status_t status;
|
2013-02-08 15:48:51 +00:00
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
for (;;) {
|
2024-03-28 21:50:30 +01:00
|
|
|
/*
|
|
|
|
* A small set of old UEFI implementations reject sizes
|
|
|
|
* above a certain threshold, the lowest seen in the wild
|
|
|
|
* is 512.
|
|
|
|
*
|
|
|
|
* TODO: Commonize with the iteration implementation in
|
|
|
|
* fs/efivarfs to keep all the quirks in one place.
|
|
|
|
*/
|
|
|
|
varname_size = 512;
|
efivars, efi-pstore: Hold off deletion of sysfs entry until the scan is completed
Currently, when mounting pstore file system, a read callback of
efi_pstore driver runs mutiple times as below.
- In the first read callback, scan efivar_sysfs_list from head and pass
a kmsg buffer of a entry to an upper pstore layer.
- In the second read callback, rescan efivar_sysfs_list from the entry
and pass another kmsg buffer to it.
- Repeat the scan and pass until the end of efivar_sysfs_list.
In this process, an entry is read across the multiple read function
calls. To avoid race between the read and erasion, the whole process
above is protected by a spinlock, holding in open() and releasing in
close().
At the same time, kmemdup() is called to pass the buffer to pstore
filesystem during it. And then, it causes a following lockdep warning.
To make the dynamic memory allocation runnable without taking spinlock,
holding off a deletion of sysfs entry if it happens while scanning it
via efi_pstore, and deleting it after the scan is completed.
To implement it, this patch introduces two flags, scanning and deleting,
to efivar_entry.
On the code basis, it seems that all the scanning and deleting logic is
not needed because __efivars->lock are not dropped when reading from the
EFI variable store.
But, the scanning and deleting logic is still needed because an
efi-pstore and a pstore filesystem works as follows.
In case an entry(A) is found, the pointer is saved to psi->data. And
efi_pstore_read() passes the entry(A) to a pstore filesystem by
releasing __efivars->lock.
And then, the pstore filesystem calls efi_pstore_read() again and the
same entry(A), which is saved to psi->data, is used for resuming to scan
a sysfs-list.
So, to protect the entry(A), the logic is needed.
[ 1.143710] ------------[ cut here ]------------
[ 1.144058] WARNING: CPU: 1 PID: 1 at kernel/lockdep.c:2740 lockdep_trace_alloc+0x104/0x110()
[ 1.144058] DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))
[ 1.144058] Modules linked in:
[ 1.144058] CPU: 1 PID: 1 Comm: systemd Not tainted 3.11.0-rc5 #2
[ 1.144058] 0000000000000009 ffff8800797e9ae0 ffffffff816614a5 ffff8800797e9b28
[ 1.144058] ffff8800797e9b18 ffffffff8105510d 0000000000000080 0000000000000046
[ 1.144058] 00000000000000d0 00000000000003af ffffffff81ccd0c0 ffff8800797e9b78
[ 1.144058] Call Trace:
[ 1.144058] [<ffffffff816614a5>] dump_stack+0x54/0x74
[ 1.144058] [<ffffffff8105510d>] warn_slowpath_common+0x7d/0xa0
[ 1.144058] [<ffffffff8105517c>] warn_slowpath_fmt+0x4c/0x50
[ 1.144058] [<ffffffff8131290f>] ? vsscanf+0x57f/0x7b0
[ 1.144058] [<ffffffff810bbd74>] lockdep_trace_alloc+0x104/0x110
[ 1.144058] [<ffffffff81192da0>] __kmalloc_track_caller+0x50/0x280
[ 1.144058] [<ffffffff815147bb>] ? efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff8115b260>] kmemdup+0x20/0x50
[ 1.144058] [<ffffffff815147bb>] efi_pstore_read_func.part.1+0x12b/0x170
[ 1.144058] [<ffffffff81514800>] ? efi_pstore_read_func.part.1+0x170/0x170
[ 1.144058] [<ffffffff815148b4>] efi_pstore_read_func+0xb4/0xe0
[ 1.144058] [<ffffffff81512b7b>] __efivar_entry_iter+0xfb/0x120
[ 1.144058] [<ffffffff8151428f>] efi_pstore_read+0x3f/0x50
[ 1.144058] [<ffffffff8128d7ba>] pstore_get_records+0x9a/0x150
[ 1.158207] [<ffffffff812af25c>] ? selinux_d_instantiate+0x1c/0x20
[ 1.158207] [<ffffffff8128ce30>] ? parse_options+0x80/0x80
[ 1.158207] [<ffffffff8128ced5>] pstore_fill_super+0xa5/0xc0
[ 1.158207] [<ffffffff811ae7d2>] mount_single+0xa2/0xd0
[ 1.158207] [<ffffffff8128ccf8>] pstore_mount+0x18/0x20
[ 1.158207] [<ffffffff811ae8b9>] mount_fs+0x39/0x1b0
[ 1.158207] [<ffffffff81160550>] ? __alloc_percpu+0x10/0x20
[ 1.158207] [<ffffffff811c9493>] vfs_kern_mount+0x63/0xf0
[ 1.158207] [<ffffffff811cbb0e>] do_mount+0x23e/0xa20
[ 1.158207] [<ffffffff8115b51b>] ? strndup_user+0x4b/0xf0
[ 1.158207] [<ffffffff811cc373>] SyS_mount+0x83/0xc0
[ 1.158207] [<ffffffff81673cc2>] system_call_fastpath+0x16/0x1b
[ 1.158207] ---[ end trace 61981bc62de9f6f4 ]---
Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com>
Tested-by: Madper Xie <cxie@redhat.com>
Cc: stable@kernel.org
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
2013-10-30 15:27:26 -04:00
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
/*
|
|
|
|
* If this is the first read() call in the pstore enumeration,
|
|
|
|
* varname will be the empty string, and the GetNextVariable()
|
|
|
|
* runtime service call will return the first EFI variable in
|
|
|
|
* its own enumeration order, ignoring the guid argument.
|
|
|
|
*
|
|
|
|
* Subsequent calls to GetNextVariable() must pass the name and
|
|
|
|
* guid values returned by the previous call, which is why we
|
|
|
|
* store varname in record->psi->data. Given that we only
|
|
|
|
* enumerate variables with the efi-pstore GUID, there is no
|
|
|
|
* need to record the guid return value.
|
|
|
|
*/
|
|
|
|
status = efivar_get_next_variable(&varname_size, varname, &guid);
|
|
|
|
if (status == EFI_NOT_FOUND)
|
|
|
|
return 0;
|
2017-03-03 22:09:18 -08:00
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
if (status != EFI_SUCCESS)
|
2024-05-19 13:33:53 -03:00
|
|
|
return efi_status_to_err(status);
|
2022-06-20 13:21:26 +02:00
|
|
|
|
|
|
|
/* skip variables that don't concern us */
|
|
|
|
if (efi_guidcmp(guid, LINUX_EFI_CRASH_GUID))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return efi_pstore_read_func(record, varname);
|
2017-03-03 22:09:18 -08:00
|
|
|
}
|
2013-02-08 15:48:51 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 23:28:53 -08:00
|
|
|
static int efi_pstore_write(struct pstore_record *record)
|
2013-02-08 15:48:51 +00:00
|
|
|
{
|
|
|
|
char name[DUMP_NAME_LEN];
|
|
|
|
efi_char16_t efi_name[DUMP_NAME_LEN];
|
2022-06-20 13:21:26 +02:00
|
|
|
efi_status_t status;
|
|
|
|
int i;
|
2013-02-08 15:48:51 +00:00
|
|
|
|
2017-05-18 13:07:49 -07:00
|
|
|
record->id = generic_id(record->time.tv_sec, record->part,
|
|
|
|
record->count);
|
|
|
|
|
2017-05-19 13:21:07 -07:00
|
|
|
/* Since we copy the entire length of name, make sure it is wiped. */
|
|
|
|
memset(name, 0, sizeof(name));
|
|
|
|
|
2018-05-14 15:50:52 -07:00
|
|
|
snprintf(name, sizeof(name), "dump-type%u-%u-%d-%lld-%c",
|
2017-03-03 23:28:53 -08:00
|
|
|
record->type, record->part, record->count,
|
2018-05-14 15:50:52 -07:00
|
|
|
(long long)record->time.tv_sec,
|
|
|
|
record->compressed ? 'C' : 'D');
|
2013-02-08 15:48:51 +00:00
|
|
|
|
|
|
|
for (i = 0; i < DUMP_NAME_LEN; i++)
|
|
|
|
efi_name[i] = name[i];
|
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
if (efivar_trylock())
|
|
|
|
return -EBUSY;
|
|
|
|
status = efivar_set_variable_locked(efi_name, &LINUX_EFI_CRASH_GUID,
|
|
|
|
PSTORE_EFI_ATTRIBUTES,
|
|
|
|
record->size, record->psi->buf,
|
|
|
|
true);
|
|
|
|
efivar_unlock();
|
2024-05-19 13:33:53 -03:00
|
|
|
return efi_status_to_err(status);
|
2013-02-08 15:48:51 +00:00
|
|
|
};
|
|
|
|
|
2017-05-19 13:21:07 -07:00
|
|
|
static int efi_pstore_erase(struct pstore_record *record)
|
|
|
|
{
|
2022-06-20 13:21:26 +02:00
|
|
|
efi_status_t status;
|
2017-05-19 13:21:07 -07:00
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
status = efivar_set_variable(record->priv, &LINUX_EFI_CRASH_GUID,
|
|
|
|
PSTORE_EFI_ATTRIBUTES, 0, NULL);
|
2017-05-19 13:21:07 -07:00
|
|
|
|
2022-06-20 13:21:26 +02:00
|
|
|
if (status != EFI_SUCCESS && status != EFI_NOT_FOUND)
|
2024-05-19 13:33:53 -03:00
|
|
|
return efi_status_to_err(status);
|
2022-06-20 13:21:26 +02:00
|
|
|
return 0;
|
2013-02-08 15:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pstore_info efi_pstore_info = {
|
|
|
|
.owner = THIS_MODULE,
|
2022-10-06 19:42:11 -03:00
|
|
|
.name = KBUILD_MODNAME,
|
2016-07-28 00:08:25 +09:00
|
|
|
.flags = PSTORE_FLAGS_DMESG,
|
2013-02-08 15:48:51 +00:00
|
|
|
.open = efi_pstore_open,
|
|
|
|
.close = efi_pstore_close,
|
|
|
|
.read = efi_pstore_read,
|
|
|
|
.write = efi_pstore_write,
|
|
|
|
.erase = efi_pstore_erase,
|
|
|
|
};
|
|
|
|
|
2024-01-03 15:40:32 -03:00
|
|
|
static int efivars_pstore_init(void)
|
2013-02-08 15:48:51 +00:00
|
|
|
{
|
2022-06-20 13:21:26 +02:00
|
|
|
if (!efivar_supports_writes())
|
2013-02-08 15:48:51 +00:00
|
|
|
return 0;
|
|
|
|
|
2024-01-03 15:40:32 -03:00
|
|
|
if (pstore_disable)
|
2013-02-08 15:48:51 +00:00
|
|
|
return 0;
|
|
|
|
|
efi: pstore: Add module parameter for setting the record size
By default, the efi-pstore backend hardcode the UEFI variable size
as 1024 bytes. The historical reasons for that were discussed by
Ard in threads [0][1]:
"there is some cargo cult from prehistoric EFI times going
on here, it seems. Or maybe just misinterpretation of the maximum
size for the variable *name* vs the variable itself.".
"OVMF has
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400
where the first one is without secure boot and the second with secure
boot. Interestingly, the default is
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400
so this is probably where this 1k number comes from."
With that, and since there is not such a limit in the UEFI spec, we
have the confidence to hereby add a module parameter to enable advanced
users to change the UEFI record size for efi-pstore data collection,
this way allowing a much easier reading of the collected log, which
wouldn't be scattered anymore among many small files.
Through empirical analysis we observed that extreme low values (like 8
bytes) could eventually cause writing issues, so given that and the OVMF
default discussed, we limited the minimum value to 1024 bytes, which also
is still the default.
[0] https://lore.kernel.org/lkml/CAMj1kXF4UyRMh2Y_KakeNBHvkHhTtavASTAxXinDO1rhPe_wYg@mail.gmail.com/
[1] https://lore.kernel.org/lkml/CAMj1kXFy-2KddGu+dgebAdU9v2sindxVoiHLWuVhqYw+R=kqng@mail.gmail.com/
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2022-11-01 15:48:07 -03:00
|
|
|
/*
|
|
|
|
* Notice that 1024 is the minimum here to prevent issues with
|
|
|
|
* decompression algorithms that were spotted during tests;
|
|
|
|
* even in the case of not using compression, smaller values would
|
|
|
|
* just pollute more the pstore FS with many small collected files.
|
|
|
|
*/
|
|
|
|
if (record_size < 1024)
|
|
|
|
record_size = 1024;
|
|
|
|
|
|
|
|
efi_pstore_info.buf = kmalloc(record_size, GFP_KERNEL);
|
2013-02-08 15:48:51 +00:00
|
|
|
if (!efi_pstore_info.buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
efi: pstore: Add module parameter for setting the record size
By default, the efi-pstore backend hardcode the UEFI variable size
as 1024 bytes. The historical reasons for that were discussed by
Ard in threads [0][1]:
"there is some cargo cult from prehistoric EFI times going
on here, it seems. Or maybe just misinterpretation of the maximum
size for the variable *name* vs the variable itself.".
"OVMF has
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
OvmfPkg/OvmfPkgX64.dsc:
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400
where the first one is without secure boot and the second with secure
boot. Interestingly, the default is
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400
so this is probably where this 1k number comes from."
With that, and since there is not such a limit in the UEFI spec, we
have the confidence to hereby add a module parameter to enable advanced
users to change the UEFI record size for efi-pstore data collection,
this way allowing a much easier reading of the collected log, which
wouldn't be scattered anymore among many small files.
Through empirical analysis we observed that extreme low values (like 8
bytes) could eventually cause writing issues, so given that and the OVMF
default discussed, we limited the minimum value to 1024 bytes, which also
is still the default.
[0] https://lore.kernel.org/lkml/CAMj1kXF4UyRMh2Y_KakeNBHvkHhTtavASTAxXinDO1rhPe_wYg@mail.gmail.com/
[1] https://lore.kernel.org/lkml/CAMj1kXFy-2KddGu+dgebAdU9v2sindxVoiHLWuVhqYw+R=kqng@mail.gmail.com/
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2022-11-01 15:48:07 -03:00
|
|
|
efi_pstore_info.bufsize = record_size;
|
2013-02-08 15:48:51 +00:00
|
|
|
|
2013-06-28 16:14:11 -04:00
|
|
|
if (pstore_register(&efi_pstore_info)) {
|
|
|
|
kfree(efi_pstore_info.buf);
|
|
|
|
efi_pstore_info.buf = NULL;
|
|
|
|
efi_pstore_info.bufsize = 0;
|
|
|
|
}
|
2013-02-08 15:48:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-01-03 15:40:32 -03:00
|
|
|
static void efivars_pstore_exit(void)
|
2013-02-08 15:48:51 +00:00
|
|
|
{
|
2015-11-07 12:43:48 +08:00
|
|
|
if (!efi_pstore_info.bufsize)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pstore_unregister(&efi_pstore_info);
|
|
|
|
kfree(efi_pstore_info.buf);
|
|
|
|
efi_pstore_info.buf = NULL;
|
|
|
|
efi_pstore_info.bufsize = 0;
|
2013-02-08 15:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(efivars_pstore_init);
|
|
|
|
module_exit(efivars_pstore_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("EFI variable backend for pstore");
|
|
|
|
MODULE_LICENSE("GPL");
|
2015-09-28 01:44:16 +01:00
|
|
|
MODULE_ALIAS("platform:efivars");
|