Skip to content

Commit

Permalink
Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/l…
Browse files Browse the repository at this point in the history
…inux/kernel/git/tip/tip

Pull x86 fixes from Peter Anvin:
 "Several boot fixes (MacBook, legacy EFI bootloaders), another
  please-don't-brick fix, and some minor stuff."

* 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86: Do not try to sync identity map for non-mapped pages
  x86, doc: Be explicit about what the x86 struct boot_params requires
  x86: Don't clear efi_info even if the sentinel hits
  x86, mm: Make sure to find a 2M free block for the first mapped area
  x86: Fix 32-bit *_cpu_data initializers
  efivarfs: return accurate error code in efivarfs_fill_super()
  efivars: efivarfs_valid_name() should handle pstore syntax
  efi: be more paranoid about available space when creating variables
  iommu, x86: Add DMA remap fault reason
  x86, smpboot: Remove unused variable
  • Loading branch information
torvalds committed Mar 7, 2013
2 parents af2841c + cc67708 commit 47b3bc9
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 43 deletions.
20 changes: 18 additions & 2 deletions arch/x86/include/asm/bootparam_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,29 @@
* analysis of kexec-tools; if other broken bootloaders initialize a
* different set of fields we will need to figure out how to disambiguate.
*
* Note: efi_info is commonly left uninitialized, but that field has a
* private magic, so it is better to leave it unchanged.
*/
static void sanitize_boot_params(struct boot_params *boot_params)
{
/*
* IMPORTANT NOTE TO BOOTLOADER AUTHORS: do not simply clear
* this field. The purpose of this field is to guarantee
* compliance with the x86 boot spec located in
* Documentation/x86/boot.txt . That spec says that the
* *whole* structure should be cleared, after which only the
* portion defined by struct setup_header (boot_params->hdr)
* should be copied in.
*
* If you're having an issue because the sentinel is set, you
* need to change the whole structure to be cleared, not this
* (or any other) individual field, or you will soon have
* problems again.
*/
if (boot_params->sentinel) {
/*fields in boot_params are not valid, clear them */
/* fields in boot_params are left uninitialized, clear them */
memset(&boot_params->olpc_ofw_header, 0,
(char *)&boot_params->alt_mem_k -
(char *)&boot_params->efi_info -
(char *)&boot_params->olpc_ofw_header);
memset(&boot_params->kbd_status, 0,
(char *)&boot_params->hdr -
Expand Down
10 changes: 8 additions & 2 deletions arch/x86/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,15 @@ static struct resource bss_resource = {

#ifdef CONFIG_X86_32
/* cpu data as detected by the assembly code in head.S */
struct cpuinfo_x86 new_cpu_data __cpuinitdata = {0, 0, 0, 0, -1, 1, 0, 0, -1};
struct cpuinfo_x86 new_cpu_data __cpuinitdata = {
.wp_works_ok = -1,
.fdiv_bug = -1,
};
/* common cpu data for all cpus */
struct cpuinfo_x86 boot_cpu_data __read_mostly = {0, 0, 0, 0, -1, 1, 0, 0, -1};
struct cpuinfo_x86 boot_cpu_data __read_mostly = {
.wp_works_ok = -1,
.fdiv_bug = -1,
};
EXPORT_SYMBOL(boot_cpu_data);

unsigned int def_to_bigsmp;
Expand Down
3 changes: 1 addition & 2 deletions arch/x86/kernel/smpboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1365,9 +1365,8 @@ static inline void mwait_play_dead(void)
unsigned int eax, ebx, ecx, edx;
unsigned int highest_cstate = 0;
unsigned int highest_subcstate = 0;
int i;
void *mwait_ptr;
struct cpuinfo_x86 *c = __this_cpu_ptr(&cpu_info);
int i;

if (!this_cpu_has(X86_FEATURE_MWAIT))
return;
Expand Down
5 changes: 2 additions & 3 deletions arch/x86/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,8 @@ void __init init_mem_mapping(void)
/* the ISA range is always mapped regardless of memory holes */
init_memory_mapping(0, ISA_END_ADDRESS);

/* xen has big range in reserved near end of ram, skip it at first */
addr = memblock_find_in_range(ISA_END_ADDRESS, end, PMD_SIZE,
PAGE_SIZE);
/* xen has big range in reserved near end of ram, skip it at first.*/
addr = memblock_find_in_range(ISA_END_ADDRESS, end, PMD_SIZE, PMD_SIZE);
real_end = addr + PMD_SIZE;

/* step_size need to be small so pgt_buf from BRK could cover it */
Expand Down
7 changes: 7 additions & 0 deletions arch/x86/mm/pat.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,13 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
if (base > __pa(high_memory-1))
return 0;

/*
* some areas in the middle of the kernel identity range
* are not mapped, like the PCI space.
*/
if (!page_is_ram(base >> PAGE_SHIFT))
return 0;

id_sz = (__pa(high_memory-1) <= base + size) ?
__pa(high_memory) - base :
size;
Expand Down
130 changes: 96 additions & 34 deletions drivers/firmware/efivars.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,44 @@ get_var_data(struct efivars *efivars, struct efi_variable *var)
return status;
}

static efi_status_t
check_var_size_locked(struct efivars *efivars, u32 attributes,
unsigned long size)
{
u64 storage_size, remaining_size, max_size;
efi_status_t status;
const struct efivar_operations *fops = efivars->ops;

if (!efivars->ops->query_variable_info)
return EFI_UNSUPPORTED;

status = fops->query_variable_info(attributes, &storage_size,
&remaining_size, &max_size);

if (status != EFI_SUCCESS)
return status;

if (!storage_size || size > remaining_size || size > max_size ||
(remaining_size - size) < (storage_size / 2))
return EFI_OUT_OF_RESOURCES;

return status;
}


static efi_status_t
check_var_size(struct efivars *efivars, u32 attributes, unsigned long size)
{
efi_status_t status;
unsigned long flags;

spin_lock_irqsave(&efivars->lock, flags);
status = check_var_size_locked(efivars, attributes, size);
spin_unlock_irqrestore(&efivars->lock, flags);

return status;
}

static ssize_t
efivar_guid_read(struct efivar_entry *entry, char *buf)
{
Expand Down Expand Up @@ -547,11 +585,16 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
}

spin_lock_irq(&efivars->lock);
status = efivars->ops->set_variable(new_var->VariableName,
&new_var->VendorGuid,
new_var->Attributes,
new_var->DataSize,
new_var->Data);

status = check_var_size_locked(efivars, new_var->Attributes,
new_var->DataSize + utf16_strsize(new_var->VariableName, 1024));

if (status == EFI_SUCCESS || status == EFI_UNSUPPORTED)
status = efivars->ops->set_variable(new_var->VariableName,
&new_var->VendorGuid,
new_var->Attributes,
new_var->DataSize,
new_var->Data);

spin_unlock_irq(&efivars->lock);

Expand Down Expand Up @@ -702,8 +745,7 @@ static ssize_t efivarfs_file_write(struct file *file,
u32 attributes;
struct inode *inode = file->f_mapping->host;
unsigned long datasize = count - sizeof(attributes);
unsigned long newdatasize;
u64 storage_size, remaining_size, max_size;
unsigned long newdatasize, varsize;
ssize_t bytes = 0;

if (count < sizeof(attributes))
Expand All @@ -722,28 +764,18 @@ static ssize_t efivarfs_file_write(struct file *file,
* amounts of memory. Pick a default size of 64K if
* QueryVariableInfo() isn't supported by the firmware.
*/
spin_lock_irq(&efivars->lock);

if (!efivars->ops->query_variable_info)
status = EFI_UNSUPPORTED;
else {
const struct efivar_operations *fops = efivars->ops;
status = fops->query_variable_info(attributes, &storage_size,
&remaining_size, &max_size);
}

spin_unlock_irq(&efivars->lock);
varsize = datasize + utf16_strsize(var->var.VariableName, 1024);
status = check_var_size(efivars, attributes, varsize);

if (status != EFI_SUCCESS) {
if (status != EFI_UNSUPPORTED)
return efi_status_to_err(status);

remaining_size = 65536;
if (datasize > 65536)
return -ENOSPC;
}

if (datasize > remaining_size)
return -ENOSPC;

data = kmalloc(datasize, GFP_KERNEL);
if (!data)
return -ENOMEM;
Expand All @@ -765,6 +797,19 @@ static ssize_t efivarfs_file_write(struct file *file,
*/
spin_lock_irq(&efivars->lock);

/*
* Ensure that the available space hasn't shrunk below the safe level
*/

status = check_var_size_locked(efivars, attributes, varsize);

if (status != EFI_SUCCESS && status != EFI_UNSUPPORTED) {
spin_unlock_irq(&efivars->lock);
kfree(data);

return efi_status_to_err(status);
}

status = efivars->ops->set_variable(var->var.VariableName,
&var->var.VendorGuid,
attributes, datasize,
Expand Down Expand Up @@ -929,8 +974,8 @@ static bool efivarfs_valid_name(const char *str, int len)
if (len < GUID_LEN + 2)
return false;

/* GUID should be right after the first '-' */
if (s - 1 != strchr(str, '-'))
/* GUID must be preceded by a '-' */
if (*(s - 1) != '-')
return false;

/*
Expand Down Expand Up @@ -1118,15 +1163,22 @@ static struct dentry_operations efivarfs_d_ops = {

static struct dentry *efivarfs_alloc_dentry(struct dentry *parent, char *name)
{
struct dentry *d;
struct qstr q;
int err;

q.name = name;
q.len = strlen(name);

if (efivarfs_d_hash(NULL, NULL, &q))
return NULL;
err = efivarfs_d_hash(NULL, NULL, &q);
if (err)
return ERR_PTR(err);

d = d_alloc(parent, &q);
if (d)
return d;

return d_alloc(parent, &q);
return ERR_PTR(-ENOMEM);
}

static int efivarfs_fill_super(struct super_block *sb, void *data, int silent)
Expand All @@ -1136,6 +1188,7 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent)
struct efivar_entry *entry, *n;
struct efivars *efivars = &__efivars;
char *name;
int err = -ENOMEM;

efivarfs_sb = sb;

Expand Down Expand Up @@ -1186,8 +1239,10 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent)
goto fail_name;

dentry = efivarfs_alloc_dentry(root, name);
if (!dentry)
if (IS_ERR(dentry)) {
err = PTR_ERR(dentry);
goto fail_inode;
}

/* copied by the above to local storage in the dentry. */
kfree(name);
Expand All @@ -1214,7 +1269,7 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent)
fail_name:
kfree(name);
fail:
return -ENOMEM;
return err;
}

static struct dentry *efivarfs_mount(struct file_system_type *fs_type,
Expand Down Expand Up @@ -1345,7 +1400,6 @@ static int efi_pstore_write(enum pstore_type_id type,
efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
struct efivars *efivars = psi->data;
int i, ret = 0;
u64 storage_space, remaining_space, max_variable_size;
efi_status_t status = EFI_NOT_FOUND;
unsigned long flags;

Expand All @@ -1365,11 +1419,11 @@ static int efi_pstore_write(enum pstore_type_id type,
* 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) {

status = check_var_size_locked(efivars, PSTORE_EFI_ATTRIBUTES,
size + DUMP_NAME_LEN * 2);

if (status) {
spin_unlock_irqrestore(&efivars->lock, flags);
*id = part;
return -ENOSPC;
Expand Down Expand Up @@ -1544,6 +1598,14 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
return -EINVAL;
}

status = check_var_size_locked(efivars, new_var->Attributes,
new_var->DataSize + utf16_strsize(new_var->VariableName, 1024));

if (status && status != EFI_UNSUPPORTED) {
spin_unlock_irq(&efivars->lock);
return efi_status_to_err(status);
}

/* now *really* create the variable via EFI */
status = efivars->ops->set_variable(new_var->VariableName,
&new_var->VendorGuid,
Expand Down
1 change: 1 addition & 0 deletions drivers/iommu/dmar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ static const char *dma_remap_fault_reasons[] =
"non-zero reserved fields in RTP",
"non-zero reserved fields in CTP",
"non-zero reserved fields in PTE",
"PCE for translation request specifies blocking",
};

static const char *irq_remap_fault_reasons[] =
Expand Down
Loading

0 comments on commit 47b3bc9

Please sign in to comment.