Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 251a8cfe authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'please-pull-pstore_mevent' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux

Pull pstore fixes from Tony Luck:
 "Patch series to allow EFI variable backend to pstore to hold multiple
  records."

* tag 'please-pull-pstore_mevent' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux:
  efi_pstore: Add a format check for an existing variable name at erasing time
  efi_pstore: Add a format check for an existing variable name at reading time
  efi_pstore: Add a sequence counter to a variable name
  efi_pstore: Add ctime to argument of erase callback
  efi_pstore: Remove a logic erasing entries from a write callback to hold multiple logs
  efi_pstore: Add a logic erasing entries to an erase callback
  efi_pstore: Check remaining space with QueryVariableInfo() before writing data
parents 70f2836d f94ec0c0
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -931,14 +931,14 @@ static int erst_check_table(struct acpi_table_erst *erst_tab)

static int erst_open_pstore(struct pstore_info *psi);
static int erst_close_pstore(struct pstore_info *psi);
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, int *count,
			   struct timespec *time, char **buf,
			   struct pstore_info *psi);
static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
		       u64 *id, unsigned int part,
		       u64 *id, unsigned int part, int count,
		       size_t size, struct pstore_info *psi);
static int erst_clearer(enum pstore_type_id type, u64 id,
			struct pstore_info *psi);
static int erst_clearer(enum pstore_type_id type, u64 id, int count,
			struct timespec time, struct pstore_info *psi);

static struct pstore_info erst_info = {
	.owner		= THIS_MODULE,
@@ -987,7 +987,7 @@ static int erst_close_pstore(struct pstore_info *psi)
	return 0;
}

static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, int *count,
			   struct timespec *time, char **buf,
			   struct pstore_info *psi)
{
@@ -1055,7 +1055,7 @@ out:
}

static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
		       u64 *id, unsigned int part,
		       u64 *id, unsigned int part, int count,
		       size_t size, struct pstore_info *psi)
{
	struct cper_pstore_record *rcd = (struct cper_pstore_record *)
@@ -1101,8 +1101,8 @@ static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
	return ret;
}

static int erst_clearer(enum pstore_type_id type, u64 id,
			struct pstore_info *psi)
static int erst_clearer(enum pstore_type_id type, u64 id, int count,
			struct timespec time, struct pstore_info *psi)
{
	return erst_clear(id);
}
+114 −49
Original line number Diff line number Diff line
@@ -658,13 +658,14 @@ static int efi_pstore_close(struct pstore_info *psi)
}

static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
			       struct timespec *timespec,
			       int *count, struct timespec *timespec,
			       char **buf, struct pstore_info *psi)
{
	efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
	struct efivars *efivars = psi->data;
	char name[DUMP_NAME_LEN];
	int i;
	int cnt;
	unsigned int part, size;
	unsigned long time;

@@ -674,10 +675,30 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
			for (i = 0; i < DUMP_NAME_LEN; i++) {
				name[i] = efivars->walk_entry->var.VariableName[i];
			}
			if (sscanf(name, "dump-type%u-%u-%lu", type, &part, &time) == 3) {
			if (sscanf(name, "dump-type%u-%u-%d-%lu",
				   type, &part, &cnt, &time) == 4) {
				*id = part;
				*count = cnt;
				timespec->tv_sec = time;
				timespec->tv_nsec = 0;
			} else if (sscanf(name, "dump-type%u-%u-%lu",
				   type, &part, &time) == 3) {
				/*
				 * Check if an old format,
				 * which doesn't support holding
				 * multiple logs, remains.
				 */
				*id = part;
				*count = 0;
				timespec->tv_sec = time;
				timespec->tv_nsec = 0;
			} else {
				efivars->walk_entry = list_entry(
						efivars->walk_entry->list.next,
						struct efivar_entry, list);
				continue;
			}

			get_var_data_locked(efivars, &efivars->walk_entry->var);
			size = efivars->walk_entry->var.DataSize;
			*buf = kmalloc(size, GFP_KERNEL);
@@ -685,11 +706,11 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
				return -ENOMEM;
			memcpy(*buf, efivars->walk_entry->var.Data,
			       size);
				efivars->walk_entry = list_entry(efivars->walk_entry->list.next,
			efivars->walk_entry = list_entry(
					efivars->walk_entry->list.next,
					struct efivar_entry, list);
			return size;
		}
		}
		efivars->walk_entry = list_entry(efivars->walk_entry->list.next,
						 struct efivar_entry, list);
	}
@@ -698,26 +719,77 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,

static int efi_pstore_write(enum pstore_type_id type,
		enum kmsg_dump_reason reason, u64 *id,
		unsigned int part, size_t size, struct pstore_info *psi)
		unsigned int part, int count, size_t size,
		struct pstore_info *psi)
{
	char name[DUMP_NAME_LEN];
	char stub_name[DUMP_NAME_LEN];
	efi_char16_t efi_name[DUMP_NAME_LEN];
	efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
	struct efivars *efivars = psi->data;
	struct efivar_entry *entry, *found = NULL;
	int i, ret = 0;
	u64 storage_space, remaining_space, max_variable_size;
	efi_status_t status = EFI_NOT_FOUND;

	spin_lock(&efivars->lock);

	sprintf(stub_name, "dump-type%u-%u-", type, part);
	sprintf(name, "%s%lu", stub_name, get_seconds());
	/*
	 * Check if there is a space enough to log.
	 * size: a size of logging data
	 * DUMP_NAME_LEN * 2: a maximum size of variable name
	 */
	status = efivars->ops->query_variable_info(PSTORE_EFI_ATTRIBUTES,
						   &storage_space,
						   &remaining_space,
						   &max_variable_size);
	if (status || remaining_space < size + DUMP_NAME_LEN * 2) {
		spin_unlock(&efivars->lock);
		*id = part;
		return -ENOSPC;
	}

	sprintf(name, "dump-type%u-%u-%d-%lu", type, part, count,
		get_seconds());

	for (i = 0; i < DUMP_NAME_LEN; i++)
		efi_name[i] = name[i];

	efivars->ops->set_variable(efi_name, &vendor, PSTORE_EFI_ATTRIBUTES,
				   size, psi->buf);

	spin_unlock(&efivars->lock);

	if (size)
		ret = efivar_create_sysfs_entry(efivars,
					  utf16_strsize(efi_name,
							DUMP_NAME_LEN * 2),
					  efi_name, &vendor);

	*id = part;
	return ret;
};

static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
			    struct timespec time, struct pstore_info *psi)
{
	char name[DUMP_NAME_LEN];
	efi_char16_t efi_name[DUMP_NAME_LEN];
	char name_old[DUMP_NAME_LEN];
	efi_char16_t efi_name_old[DUMP_NAME_LEN];
	efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
	struct efivars *efivars = psi->data;
	struct efivar_entry *entry, *found = NULL;
	int i;

	sprintf(name, "dump-type%u-%u-%d-%lu", type, (unsigned int)id, count,
		time.tv_sec);

	spin_lock(&efivars->lock);

	for (i = 0; i < DUMP_NAME_LEN; i++)
		efi_name[i] = stub_name[i];
		efi_name[i] = name[i];

	/*
	 * Clean up any entries with the same name
	 * Clean up an entry with the same name
	 */

	list_for_each_entry(entry, &efivars->list, list) {
@@ -726,11 +798,22 @@ static int efi_pstore_write(enum pstore_type_id type,
		if (efi_guidcmp(entry->var.VendorGuid, vendor))
			continue;
		if (utf16_strncmp(entry->var.VariableName, efi_name,
				  utf16_strlen(efi_name)))
			continue;
		/* Needs to be a prefix */
		if (entry->var.VariableName[utf16_strlen(efi_name)] == 0)
				  utf16_strlen(efi_name))) {
			/*
			 * Check if an old format,
			 * which doesn't support holding
			 * multiple logs, remains.
			 */
			sprintf(name_old, "dump-type%u-%u-%lu", type,
				(unsigned int)id, time.tv_sec);

			for (i = 0; i < DUMP_NAME_LEN; i++)
				efi_name_old[i] = name_old[i];

			if (utf16_strncmp(entry->var.VariableName, efi_name_old,
					  utf16_strlen(efi_name_old)))
				continue;
		}

		/* found */
		found = entry;
@@ -738,37 +821,17 @@ static int efi_pstore_write(enum pstore_type_id type,
					   &entry->var.VendorGuid,
					   PSTORE_EFI_ATTRIBUTES,
					   0, NULL);
		break;
	}

	if (found)
		list_del(&found->list);

	for (i = 0; i < DUMP_NAME_LEN; i++)
		efi_name[i] = name[i];

	efivars->ops->set_variable(efi_name, &vendor, PSTORE_EFI_ATTRIBUTES,
				   size, psi->buf);

	spin_unlock(&efivars->lock);

	if (found)
		efivar_unregister(found);

	if (size)
		ret = efivar_create_sysfs_entry(efivars,
					  utf16_strsize(efi_name,
							DUMP_NAME_LEN * 2),
					  efi_name, &vendor);

	*id = part;
	return ret;
};

static int efi_pstore_erase(enum pstore_type_id type, u64 id,
			    struct pstore_info *psi)
{
	efi_pstore_write(type, 0, &id, (unsigned int)id, 0, psi);

	return 0;
}
#else
@@ -782,7 +845,7 @@ static int efi_pstore_close(struct pstore_info *psi)
	return 0;
}

static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type, int *count,
			       struct timespec *timespec,
			       char **buf, struct pstore_info *psi)
{
@@ -791,13 +854,14 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,

static int efi_pstore_write(enum pstore_type_id type,
		enum kmsg_dump_reason reason, u64 *id,
		unsigned int part, size_t size, struct pstore_info *psi)
		unsigned int part, int count, size_t size,
		struct pstore_info *psi)
{
	return 0;
}

static int efi_pstore_erase(enum pstore_type_id type, u64 id,
			    struct pstore_info *psi)
static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
			    struct timespec time, struct pstore_info *psi)
{
	return 0;
}
@@ -1237,6 +1301,7 @@ efivars_init(void)
	ops.get_variable = efi.get_variable;
	ops.set_variable = efi.set_variable;
	ops.get_next_variable = efi.get_next_variable;
	ops.query_variable_info = efi.query_variable_info;
	error = register_efivars(&__efivars, &ops, efi_kobj);
	if (error)
		goto err_put;
+5 −2
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ struct pstore_private {
	struct pstore_info *psi;
	enum pstore_type_id type;
	u64	id;
	int	count;
	ssize_t	size;
	char	data[];
};
@@ -175,7 +176,8 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
	struct pstore_private *p = dentry->d_inode->i_private;

	if (p->psi->erase)
		p->psi->erase(p->type, p->id, p->psi);
		p->psi->erase(p->type, p->id, p->count,
			      dentry->d_inode->i_ctime, p->psi);

	return simple_unlink(dir, dentry);
}
@@ -270,7 +272,7 @@ int pstore_is_mounted(void)
 * Load it up with "size" bytes of data from "buf".
 * Set the mtime & ctime to the date that this record was originally stored.
 */
int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,
		  char *data, size_t size, struct timespec time,
		  struct pstore_info *psi)
{
@@ -306,6 +308,7 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
		goto fail_alloc;
	private->type = type;
	private->id = id;
	private->count = count;
	private->psi = psi;

	switch (type) {
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ extern struct pstore_info *psinfo;
extern void	pstore_set_kmsg_bytes(int);
extern void	pstore_get_records(int);
extern int	pstore_mkfile(enum pstore_type_id, char *psname, u64 id,
			      char *data, size_t size,
			      int count, char *data, size_t size,
			      struct timespec time, struct pstore_info *psi);
extern int	pstore_is_mounted(void);

+7 −6
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
			break;

		ret = psinfo->write(PSTORE_TYPE_DMESG, reason, &id, part,
				    hsize + len, psinfo);
				    oopscount, hsize + len, psinfo);
		if (ret == 0 && reason == KMSG_DUMP_OOPS && pstore_is_mounted())
			pstore_new_entry = 1;

@@ -173,7 +173,7 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
			spin_lock_irqsave(&psinfo->buf_lock, flags);
		}
		memcpy(psinfo->buf, s, c);
		psinfo->write(PSTORE_TYPE_CONSOLE, 0, &id, 0, c, psinfo);
		psinfo->write(PSTORE_TYPE_CONSOLE, 0, &id, 0, 0, c, psinfo);
		spin_unlock_irqrestore(&psinfo->buf_lock, flags);
		s += c;
		c = e - s;
@@ -197,7 +197,7 @@ static void pstore_register_console(void) {}

static int pstore_write_compat(enum pstore_type_id type,
			       enum kmsg_dump_reason reason,
			       u64 *id, unsigned int part,
			       u64 *id, unsigned int part, int count,
			       size_t size, struct pstore_info *psi)
{
	return psi->write_buf(type, reason, id, part, psinfo->buf, size, psi);
@@ -267,6 +267,7 @@ void pstore_get_records(int quiet)
	char			*buf = NULL;
	ssize_t			size;
	u64			id;
	int			count;
	enum pstore_type_id	type;
	struct timespec		time;
	int			failed = 0, rc;
@@ -278,9 +279,9 @@ void pstore_get_records(int quiet)
	if (psi->open && psi->open(psi))
		goto out;

	while ((size = psi->read(&id, &type, &time, &buf, psi)) > 0) {
		rc = pstore_mkfile(type, psi->name, id, buf, (size_t)size,
				  time, psi);
	while ((size = psi->read(&id, &type, &count, &time, &buf, psi)) > 0) {
		rc = pstore_mkfile(type, psi->name, id, count, buf,
				  (size_t)size, time, psi);
		kfree(buf);
		buf = NULL;
		if (rc && (rc != -EEXIST || !quiet))
Loading