Skip to content

Commit 19caf58

Browse files
committed
Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Thomas Gleixner: "A set of x86 fixes: - Prevent potential NULL pointer dereferences in the HPET and HyperV code - Exclude the GART aperture from /proc/kcore to prevent kernel crashes on access - Use the correct macros for Cyrix I/O on Geode processors - Remove yet another kernel address printk leak - Announce microcode reload completion as requested by quite some people. Microcode loading has become popular recently. - Some 'Make Clang' happy fixlets - A few cleanups for recently added code" * 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/gart: Exclude GART aperture from kcore x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error x86/mm/pti: Make local symbols static x86/cpu/cyrix: Remove {get,set}Cx86_old macros used for Cyrix processors x86/cpu/cyrix: Use correct macros for Cyrix calls on Geode processors x86/microcode: Announce reload operation's completion x86/hyperv: Prevent potential NULL pointer dereference x86/hpet: Prevent potential NULL pointer dereference x86/lib: Fix indentation issue, remove extra tab x86/boot: Restrict header scope to make Clang happy x86/mm: Don't leak kernel addresses x86/cpufeature: Fix various quality problems in the <asm/cpu_device_hd.h> header
2 parents a75eda7 + ffc8599 commit 19caf58

File tree

14 files changed

+81
-58
lines changed

14 files changed

+81
-58
lines changed

arch/x86/boot/string.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
*/
1414

1515
#include <linux/types.h>
16-
#include <linux/kernel.h>
16+
#include <linux/compiler.h>
1717
#include <linux/errno.h>
18+
#include <linux/limits.h>
1819
#include <asm/asm.h>
1920
#include "ctype.h"
2021
#include "string.h"

arch/x86/hyperv/hv_init.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ static int hv_cpu_init(unsigned int cpu)
103103
u64 msr_vp_index;
104104
struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()];
105105
void **input_arg;
106+
struct page *pg;
106107

107108
input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
108-
*input_arg = page_address(alloc_page(GFP_KERNEL));
109+
pg = alloc_page(GFP_KERNEL);
110+
if (unlikely(!pg))
111+
return -ENOMEM;
112+
*input_arg = page_address(pg);
109113

110114
hv_get_vp_index(msr_vp_index);
111115

arch/x86/include/asm/cpu_device_id.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
#ifndef _CPU_DEVICE_ID
3-
#define _CPU_DEVICE_ID 1
2+
#ifndef _ASM_X86_CPU_DEVICE_ID
3+
#define _ASM_X86_CPU_DEVICE_ID
44

55
/*
66
* Declare drivers belonging to specific x86 CPUs
@@ -9,8 +9,6 @@
99

1010
#include <linux/mod_devicetable.h>
1111

12-
extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
13-
1412
/*
1513
* Match specific microcode revisions.
1614
*
@@ -22,21 +20,22 @@ extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
2220
*/
2321

2422
struct x86_cpu_desc {
25-
__u8 x86_family;
26-
__u8 x86_vendor;
27-
__u8 x86_model;
28-
__u8 x86_stepping;
29-
__u32 x86_microcode_rev;
23+
u8 x86_family;
24+
u8 x86_vendor;
25+
u8 x86_model;
26+
u8 x86_stepping;
27+
u32 x86_microcode_rev;
3028
};
3129

32-
#define INTEL_CPU_DESC(mod, step, rev) { \
33-
.x86_family = 6, \
34-
.x86_vendor = X86_VENDOR_INTEL, \
35-
.x86_model = mod, \
36-
.x86_stepping = step, \
37-
.x86_microcode_rev = rev, \
30+
#define INTEL_CPU_DESC(model, stepping, revision) { \
31+
.x86_family = 6, \
32+
.x86_vendor = X86_VENDOR_INTEL, \
33+
.x86_model = (model), \
34+
.x86_stepping = (stepping), \
35+
.x86_microcode_rev = (revision), \
3836
}
3937

38+
extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
4039
extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table);
4140

42-
#endif
41+
#endif /* _ASM_X86_CPU_DEVICE_ID */

arch/x86/include/asm/processor-cyrix.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@
33
* NSC/Cyrix CPU indexed register access. Must be inlined instead of
44
* macros to ensure correct access ordering
55
* Access order is always 0x22 (=offset), 0x23 (=value)
6-
*
7-
* When using the old macros a line like
8-
* setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);
9-
* gets expanded to:
10-
* do {
11-
* outb((CX86_CCR2), 0x22);
12-
* outb((({
13-
* outb((CX86_CCR2), 0x22);
14-
* inb(0x23);
15-
* }) | 0x88), 0x23);
16-
* } while (0);
17-
*
18-
* which in fact violates the access order (= 0x22, 0x22, 0x23, 0x23).
196
*/
207

218
static inline u8 getCx86(u8 reg)
@@ -29,11 +16,3 @@ static inline void setCx86(u8 reg, u8 data)
2916
outb(reg, 0x22);
3017
outb(data, 0x23);
3118
}
32-
33-
#define getCx86_old(reg) ({ outb((reg), 0x22); inb(0x23); })
34-
35-
#define setCx86_old(reg, data) do { \
36-
outb((reg), 0x22); \
37-
outb((data), 0x23); \
38-
} while (0)
39-

arch/x86/kernel/aperture_64.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define pr_fmt(fmt) "AGP: " fmt
1515

1616
#include <linux/kernel.h>
17+
#include <linux/kcore.h>
1718
#include <linux/types.h>
1819
#include <linux/init.h>
1920
#include <linux/memblock.h>
@@ -57,7 +58,7 @@ int fallback_aper_force __initdata;
5758

5859
int fix_aperture __initdata = 1;
5960

60-
#ifdef CONFIG_PROC_VMCORE
61+
#if defined(CONFIG_PROC_VMCORE) || defined(CONFIG_PROC_KCORE)
6162
/*
6263
* If the first kernel maps the aperture over e820 RAM, the kdump kernel will
6364
* use the same range because it will remain configured in the northbridge.
@@ -66,20 +67,25 @@ int fix_aperture __initdata = 1;
6667
*/
6768
static unsigned long aperture_pfn_start, aperture_page_count;
6869

69-
static int gart_oldmem_pfn_is_ram(unsigned long pfn)
70+
static int gart_mem_pfn_is_ram(unsigned long pfn)
7071
{
7172
return likely((pfn < aperture_pfn_start) ||
7273
(pfn >= aperture_pfn_start + aperture_page_count));
7374
}
7475

75-
static void exclude_from_vmcore(u64 aper_base, u32 aper_order)
76+
static void __init exclude_from_core(u64 aper_base, u32 aper_order)
7677
{
7778
aperture_pfn_start = aper_base >> PAGE_SHIFT;
7879
aperture_page_count = (32 * 1024 * 1024) << aper_order >> PAGE_SHIFT;
79-
WARN_ON(register_oldmem_pfn_is_ram(&gart_oldmem_pfn_is_ram));
80+
#ifdef CONFIG_PROC_VMCORE
81+
WARN_ON(register_oldmem_pfn_is_ram(&gart_mem_pfn_is_ram));
82+
#endif
83+
#ifdef CONFIG_PROC_KCORE
84+
WARN_ON(register_mem_pfn_is_ram(&gart_mem_pfn_is_ram));
85+
#endif
8086
}
8187
#else
82-
static void exclude_from_vmcore(u64 aper_base, u32 aper_order)
88+
static void exclude_from_core(u64 aper_base, u32 aper_order)
8389
{
8490
}
8591
#endif
@@ -474,7 +480,7 @@ int __init gart_iommu_hole_init(void)
474480
* may have allocated the range over its e820 RAM
475481
* and fixed up the northbridge
476482
*/
477-
exclude_from_vmcore(last_aper_base, last_aper_order);
483+
exclude_from_core(last_aper_base, last_aper_order);
478484

479485
return 1;
480486
}
@@ -520,7 +526,7 @@ int __init gart_iommu_hole_init(void)
520526
* overlap with the first kernel's memory. We can't access the
521527
* range through vmcore even though it should be part of the dump.
522528
*/
523-
exclude_from_vmcore(aper_alloc, aper_order);
529+
exclude_from_core(aper_alloc, aper_order);
524530

525531
/* Fix up the north bridges */
526532
for (i = 0; i < amd_nb_bus_dev_ranges[i].dev_limit; i++) {

arch/x86/kernel/cpu/cyrix.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void set_cx86_reorder(void)
124124
setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
125125

126126
/* Load/Store Serialize to mem access disable (=reorder it) */
127-
setCx86_old(CX86_PCR0, getCx86_old(CX86_PCR0) & ~0x80);
127+
setCx86(CX86_PCR0, getCx86(CX86_PCR0) & ~0x80);
128128
/* set load/store serialize from 1GB to 4GB */
129129
ccr3 |= 0xe0;
130130
setCx86(CX86_CCR3, ccr3);
@@ -135,11 +135,11 @@ static void set_cx86_memwb(void)
135135
pr_info("Enable Memory-Write-back mode on Cyrix/NSC processor.\n");
136136

137137
/* CCR2 bit 2: unlock NW bit */
138-
setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) & ~0x04);
138+
setCx86(CX86_CCR2, getCx86(CX86_CCR2) & ~0x04);
139139
/* set 'Not Write-through' */
140140
write_cr0(read_cr0() | X86_CR0_NW);
141141
/* CCR2 bit 2: lock NW bit and set WT1 */
142-
setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) | 0x14);
142+
setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x14);
143143
}
144144

145145
/*
@@ -153,14 +153,14 @@ static void geode_configure(void)
153153
local_irq_save(flags);
154154

155155
/* Suspend on halt power saving and enable #SUSP pin */
156-
setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) | 0x88);
156+
setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);
157157

158158
ccr3 = getCx86(CX86_CCR3);
159159
setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
160160

161161

162162
/* FPU fast, DTE cache, Mem bypass */
163-
setCx86_old(CX86_CCR4, getCx86_old(CX86_CCR4) | 0x38);
163+
setCx86(CX86_CCR4, getCx86(CX86_CCR4) | 0x38);
164164
setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
165165

166166
set_cx86_memwb();
@@ -296,7 +296,7 @@ static void init_cyrix(struct cpuinfo_x86 *c)
296296
/* GXm supports extended cpuid levels 'ala' AMD */
297297
if (c->cpuid_level == 2) {
298298
/* Enable cxMMX extensions (GX1 Datasheet 54) */
299-
setCx86_old(CX86_CCR7, getCx86_old(CX86_CCR7) | 1);
299+
setCx86(CX86_CCR7, getCx86(CX86_CCR7) | 1);
300300

301301
/*
302302
* GXm : 0x30 ... 0x5f GXm datasheet 51
@@ -319,7 +319,7 @@ static void init_cyrix(struct cpuinfo_x86 *c)
319319
if (dir1 > 7) {
320320
dir0_msn++; /* M II */
321321
/* Enable MMX extensions (App note 108) */
322-
setCx86_old(CX86_CCR7, getCx86_old(CX86_CCR7)|1);
322+
setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1);
323323
} else {
324324
/* A 6x86MX - it has the bug. */
325325
set_cpu_bug(c, X86_BUG_COMA);

arch/x86/kernel/cpu/microcode/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,8 @@ static int microcode_reload_late(void)
608608
if (ret > 0)
609609
microcode_check();
610610

611+
pr_info("Reload completed, microcode revision: 0x%x\n", boot_cpu_data.microcode);
612+
611613
return ret;
612614
}
613615

arch/x86/kernel/hpet.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ int __init hpet_enable(void)
905905
return 0;
906906

907907
hpet_set_mapping();
908+
if (!hpet_virt_address)
909+
return 0;
908910

909911
/*
910912
* Read the period and check for a sane value:

arch/x86/kernel/hw_breakpoint.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,
354354
#endif
355355
default:
356356
WARN_ON_ONCE(1);
357+
return -EINVAL;
357358
}
358359

359360
/*

arch/x86/kernel/mpparse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ static int __init smp_scan_config(unsigned long base, unsigned long length)
598598
mpf_base = base;
599599
mpf_found = true;
600600

601-
pr_info("found SMP MP-table at [mem %#010lx-%#010lx] mapped at [%p]\n",
602-
base, base + sizeof(*mpf) - 1, mpf);
601+
pr_info("found SMP MP-table at [mem %#010lx-%#010lx]\n",
602+
base, base + sizeof(*mpf) - 1);
603603

604604
memblock_reserve(base, sizeof(*mpf));
605605
if (mpf->physptr)

arch/x86/lib/csum-partial_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static unsigned do_csum(const unsigned char *buff, unsigned len)
9494
: "m" (*(unsigned long *)buff),
9595
"r" (zero), "0" (result));
9696
--count;
97-
buff += 8;
97+
buff += 8;
9898
}
9999
result = add32_with_carry(result>>32,
100100
result&0xffffffff);

arch/x86/mm/pti.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void __init pti_print_if_secure(const char *reason)
7777
pr_info("%s\n", reason);
7878
}
7979

80-
enum pti_mode {
80+
static enum pti_mode {
8181
PTI_AUTO = 0,
8282
PTI_FORCE_OFF,
8383
PTI_FORCE_ON
@@ -602,7 +602,7 @@ static void pti_clone_kernel_text(void)
602602
set_memory_global(start, (end_global - start) >> PAGE_SHIFT);
603603
}
604604

605-
void pti_set_kernel_image_nonglobal(void)
605+
static void pti_set_kernel_image_nonglobal(void)
606606
{
607607
/*
608608
* The identity map is created with PMDs, regardless of the

fs/proc/kcore.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@ static LIST_HEAD(kclist_head);
5454
static DECLARE_RWSEM(kclist_lock);
5555
static int kcore_need_update = 1;
5656

57+
/*
58+
* Returns > 0 for RAM pages, 0 for non-RAM pages, < 0 on error
59+
* Same as oldmem_pfn_is_ram in vmcore
60+
*/
61+
static int (*mem_pfn_is_ram)(unsigned long pfn);
62+
63+
int __init register_mem_pfn_is_ram(int (*fn)(unsigned long pfn))
64+
{
65+
if (mem_pfn_is_ram)
66+
return -EBUSY;
67+
mem_pfn_is_ram = fn;
68+
return 0;
69+
}
70+
71+
static int pfn_is_ram(unsigned long pfn)
72+
{
73+
if (mem_pfn_is_ram)
74+
return mem_pfn_is_ram(pfn);
75+
else
76+
return 1;
77+
}
78+
5779
/* This doesn't grab kclist_lock, so it should only be used at init time. */
5880
void __init kclist_add(struct kcore_list *new, void *addr, size_t size,
5981
int type)
@@ -465,6 +487,11 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
465487
goto out;
466488
}
467489
m = NULL; /* skip the list anchor */
490+
} else if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) {
491+
if (clear_user(buffer, tsz)) {
492+
ret = -EFAULT;
493+
goto out;
494+
}
468495
} else if (m->type == KCORE_VMALLOC) {
469496
vread(buf, (char *)start, tsz);
470497
/* we have to zero-fill user buffer even if no read */

include/linux/kcore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void kclist_add_remap(struct kcore_list *m, void *addr, void *vaddr, size_t sz)
4444
m->vaddr = (unsigned long)vaddr;
4545
kclist_add(m, addr, sz, KCORE_REMAP);
4646
}
47+
48+
extern int __init register_mem_pfn_is_ram(int (*fn)(unsigned long pfn));
4749
#else
4850
static inline
4951
void kclist_add(struct kcore_list *new, void *addr, size_t size, int type)

0 commit comments

Comments
 (0)