Skip to contentSkip to conversation

x86 fixes

GIT PULL New Ingo Molnar 3 participants 3 messages May 6, 2015 – May 8, 2015

Subsystems (5)
x86 x86 MM EFI Locking primitives +1 more subsystems
lore
Share & tools
lore
#0 lore raw

Linus,

Please pull the latest x86-urgent-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-urgent-for-linus

# HEAD: c88d47480d300eaad80c213d50c9bf6077fc49bc x86/fpu: Always restore_xinit_state() when use_eager_cpu()

EFI fixes, and FPU fix, a ticket spinlock boundary condition fix and two build fixes.

out-of-topic modifications in x86-urgent-for-linus:
-----------------------------------------------------
drivers/firmware/efi/runtime-map.c # d67e199611b9: efi: Fix error handling in a
fs/efivarfs/super.c # c57dcb566d3d: efivarfs: Ensure VariableNam

Thanks,

Ingo

------------------>
Bobby Powers (1):
x86/fpu: Always restore_xinit_state() when use_eager_cpu()

Dan Carpenter (1):
efi: Fix error handling in add_sysfs_runtime_map_entry()

Ingo Molnar (1):
x86/mm: Clean up types in xlate_dev_mem_ptr()

Marc Dionne (1):
x86: Make cpu_tss available to external modules

Ross Lagerwall (1):
efivarfs: Ensure VariableName is NUL-terminated

Roy Franz (1):
x86/efi: Store upper bits of command line buffer address in ext_cmd_line_ptr

Tahsin Erdogan (1):
x86/spinlocks: Fix regression in spinlock contention detection

 arch/x86/boot/compressed/eboot.c   |  2 ++
 arch/x86/include/asm/spinlock.h    |  2 +-
 arch/x86/kernel/process.c          | 14 ++++++++------
 arch/x86/mm/ioremap.c              | 14 ++++++++------
 drivers/firmware/efi/runtime-map.c |  6 +++---
 fs/efivarfs/super.c                |  2 +-
 6 files changed, 23 insertions(+), 17 deletions(-)
arch/x86/boot/compressed/eboot.c +2 -0
index ef17683484e9..48304b89b601 100644
@@ -1109,6 +1109,8 @@ struct boot_params *make_boot_params(struct efi_config *c)
 	if (!cmdline_ptr)
 		goto fail;
 	hdr->cmd_line_ptr = (unsigned long)cmdline_ptr;
+	/* Fill in upper bits of command line address, NOP on 32 bit  */
+	boot_params->ext_cmd_line_ptr = (u64)(unsigned long)cmdline_ptr >> 32;
 
 	hdr->ramdisk_image = 0;
 	hdr->ramdisk_size = 0;
arch/x86/include/asm/spinlock.h +1 -1
index cf87de3fc390..64b611782ef0 100644
@@ -169,7 +169,7 @@ static inline int arch_spin_is_contended(arch_spinlock_t *lock)
 	struct __raw_tickets tmp = READ_ONCE(lock->tickets);
 
 	tmp.head &= ~TICKET_SLOWPATH_FLAG;
-	return (tmp.tail - tmp.head) > TICKET_LOCK_INC;
+	return (__ticket_t)(tmp.tail - tmp.head) > TICKET_LOCK_INC;
 }
 #define arch_spin_is_contended	arch_spin_is_contended
 
arch/x86/kernel/process.c +8 -6
index 8213da62b1b7..6e338e3b1dc0 100644
@@ -57,7 +57,7 @@ __visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss) = {
 	.io_bitmap		= { [0 ... IO_BITMAP_LONGS] = ~0 },
 #endif
 };
-EXPORT_PER_CPU_SYMBOL_GPL(cpu_tss);
+EXPORT_PER_CPU_SYMBOL(cpu_tss);
 
 #ifdef CONFIG_X86_64
 static DEFINE_PER_CPU(unsigned char, is_idle);
@@ -156,11 +156,13 @@ void flush_thread(void)
 		/* FPU state will be reallocated lazily at the first use. */
 		drop_fpu(tsk);
 		free_thread_xstate(tsk);
-	} else if (!used_math()) {
-		/* kthread execs. TODO: cleanup this horror. */
-		if (WARN_ON(init_fpu(tsk)))
-			force_sig(SIGKILL, tsk);
-		user_fpu_begin();
+	} else {
+		if (!tsk_used_math(tsk)) {
+			/* kthread execs. TODO: cleanup this horror. */
+			if (WARN_ON(init_fpu(tsk)))
+				force_sig(SIGKILL, tsk);
+			user_fpu_begin();
+		}
 		restore_init_xstate();
 	}
 }
arch/x86/mm/ioremap.c +8 -6
index fdf617c00e2f..4bf037b20f47 100644
@@ -332,18 +332,20 @@ EXPORT_SYMBOL(iounmap);
  */
 void *xlate_dev_mem_ptr(phys_addr_t phys)
 {
-	void *addr;
-	unsigned long start = phys & PAGE_MASK;
+	unsigned long start  = phys &  PAGE_MASK;
+	unsigned long offset = phys & ~PAGE_MASK;
+	unsigned long vaddr;
 
 	/* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
 	if (page_is_ram(start >> PAGE_SHIFT))
 		return __va(phys);
 
-	addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
-	if (addr)
-		addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
+	vaddr = (unsigned long)ioremap_cache(start, PAGE_SIZE);
+	/* Only add the offset on success and return NULL if the ioremap() failed: */
+	if (vaddr)
+		vaddr += offset;
 
-	return addr;
+	return (void *)vaddr;
 }
 
 void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
drivers/firmware/efi/runtime-map.c +3 -3
index 87b8e3b900d2..5c55227a34c8 100644
@@ -120,7 +120,8 @@ add_sysfs_runtime_map_entry(struct kobject *kobj, int nr)
 	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
 	if (!entry) {
 		kset_unregister(map_kset);
-		return entry;
+		map_kset = NULL;
+		return ERR_PTR(-ENOMEM);
 	}
 
 	memcpy(&entry->md, efi_runtime_map + nr * efi_memdesc_size,
@@ -132,6 +133,7 @@ add_sysfs_runtime_map_entry(struct kobject *kobj, int nr)
 	if (ret) {
 		kobject_put(&entry->kobj);
 		kset_unregister(map_kset);
+		map_kset = NULL;
 		return ERR_PTR(ret);
 	}
 
@@ -195,8 +197,6 @@ int __init efi_runtime_map_init(struct kobject *efi_kobj)
 		entry = *(map_entries + j);
 		kobject_put(&entry->kobj);
 	}
-	if (map_kset)
-		kset_unregister(map_kset);
 out:
 	return ret;
 }
fs/efivarfs/super.c +1 -1
index ddbce42548c9..acf9a67f6770 100644
@@ -121,7 +121,7 @@ static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
 	int len, i;
 	int err = -ENOMEM;
 
-	entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
 	if (!entry)
 		return err;
 
#1 lore raw

Ugh, I pulled, but:

Quoted 9 lines · Ingo Molnar

Ingo Molnar (1):
x86/mm: Clean up types in xlate_dev_mem_ptr()

arch/x86/mm/ioremap.c +0 -0
index fdf617c00e2f..4bf037b20f47 100644

arch/x86/mm/ioremap.c EXPORT_SYMBOL(iounmap); · line 337

Quoted 6 lines
arch/x86/mm/ioremap.c +3 -0
@@ -332,18 +332,20 @@ EXPORT_SYMBOL(iounmap);
  */
 void *xlate_dev_mem_ptr(phys_addr_t phys)
 {
+       unsigned long start  = phys &  PAGE_MASK;
+       unsigned long offset = phys & ~PAGE_MASK;
+       unsigned long vaddr;

That "unsigned long vaddr" is just stupid and not a cleanup.

It causes two pointless casts:

arch/x86/mm/ioremap.c EXPORT_SYMBOL(iounmap); · line 348

Quoted 6 lines
arch/x86/mm/ioremap.c +5 -0
+       vaddr = (unsigned long)ioremap_cache(start, PAGE_SIZE);
+       /* Only add the offset on success and return NULL if the ioremap() failed: */
+       if (vaddr)
+               vaddr += offset;
 
+       return (void *)vaddr;

neither of which is helpful in the least. And the "vaddr += offset" would work equally well in "void *", gcc is perfectly happy to treat "void *" arithmetic as byte offsets, it's both documented and already extensively used in the kernel.

So the cleanup to use "start/offset" is a good cleanup, but you should have kept "addr" as a pointer.

Linus

#2 lore raw

PATCH 1/1 x86/mm: Clean up types in xlate_dev_mem_ptr() some more

Quoted 28 lines · Linus Torvalds

Ugh, I pulled, but:

Quoted 9 lines · Ingo Molnar

Ingo Molnar (1):
x86/mm: Clean up types in xlate_dev_mem_ptr()

arch/x86/mm/ioremap.c +0 -0
index fdf617c00e2f..4bf037b20f47 100644

arch/x86/mm/ioremap.c EXPORT_SYMBOL(iounmap); · line 337

Quoted 6 lines
arch/x86/mm/ioremap.c +3 -0
@@ -332,18 +332,20 @@ EXPORT_SYMBOL(iounmap);
  */
 void *xlate_dev_mem_ptr(phys_addr_t phys)
 {
+       unsigned long start  = phys &  PAGE_MASK;
+       unsigned long offset = phys & ~PAGE_MASK;
+       unsigned long vaddr;

That "unsigned long vaddr" is just stupid and not a cleanup.

It causes two pointless casts:

Quoted 5 lines
arch/x86/mm/ioremap.c +4 -0
+       vaddr = (unsigned long)ioremap_cache(start, PAGE_SIZE);
+       /* Only add the offset on success and return NULL if the ioremap() failed: */
+       if (vaddr)
+               vaddr += offset;
 
Quoted 6 lines

arch/x86/mm/ioremap.c EXPORT_SYMBOL(iounmap); · line 343

Quoted 1 line
arch/x86/mm/ioremap.c +1 -0
+       return (void *)vaddr;

neither of which is helpful in the least. And the "vaddr += offset" would work equally well in "void *", gcc is perfectly happy to treat "void *" arithmetic as byte offsets, it's both documented and already extensively used in the kernel.

Yeah, not sure why I didn't notice that, I love void * arithmetics.

Quoted 2 lines

So the cleanup to use "start/offset" is a good cleanup, but you should have kept "addr" as a pointer.

Something like the patch below?

Thanks,

Ingo

===================>

Quoted 1 line

From 562bfca4c80175d1d18eef5c3f4bb8dda53c03e4 Mon Sep 17 00:00:00 2001

From: Ingo Molnar <[email protected]>
Date: Fri, 8 May 2015 12:43:53 +0200
Subject: [PATCH] x86/mm: Clean up types in xlate_dev_mem_ptr() some more

So Linus noticed that in:

94d4b4765b7d ("x86/mm: Clean up types in xlate_dev_mem_ptr()")

... I added two nonsensical casts, due to the poor type choice for 'vaddr'.

Change it to 'void *' and take advantage of void * arithmetics.

This removes the casts.

( Also remove a nonsensical return line from unxlate_dev_mem_ptr()
while at it. )

Cc Borislav Petkov <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/mm/ioremap.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/mm/ioremap.c +3 -4
index 70e7444c6835..27ff21216dfa 100644
@@ -353,18 +353,18 @@ void *xlate_dev_mem_ptr(phys_addr_t phys)
 {
 	unsigned long start  = phys &  PAGE_MASK;
 	unsigned long offset = phys & ~PAGE_MASK;
-	unsigned long vaddr;
+	void *vaddr;
 
 	/* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
 	if (page_is_ram(start >> PAGE_SHIFT))
 		return __va(phys);
 
-	vaddr = (unsigned long)ioremap_cache(start, PAGE_SIZE);
+	vaddr = ioremap_cache(start, PAGE_SIZE);
 	/* Only add the offset on success and return NULL if the ioremap() failed: */
 	if (vaddr)
 		vaddr += offset;
 
-	return (void *)vaddr;
+	return vaddr;
 }
 
 void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
@@ -373,7 +373,6 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
 		return;
 
 	iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
-	return;
 }
 
 static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;