Skip to content

Commit 3408fef

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 Ingo Molnar: "An initrd microcode loading fix, and an SMP bootup topology setup fix to resolve crashes on SGI/UV systems if the BIOS is configured in a certain way" * 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/smp: Fix __max_logical_packages value setup x86/microcode/AMD: Fix initrd loading with CONFIG_RANDOMIZE_MEMORY=y
2 parents b061b4f + 7b0501b commit 3408fef

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ void load_ucode_amd_ap(void)
355355
unsigned int cpu = smp_processor_id();
356356
struct equiv_cpu_entry *eq;
357357
struct microcode_amd *mc;
358+
u8 *cont = container;
358359
u32 rev, eax;
359360
u16 eq_id;
360361

@@ -371,8 +372,11 @@ void load_ucode_amd_ap(void)
371372
if (check_current_patch_level(&rev, false))
372373
return;
373374

375+
/* Add CONFIG_RANDOMIZE_MEMORY offset. */
376+
cont += PAGE_OFFSET - __PAGE_OFFSET_BASE;
377+
374378
eax = cpuid_eax(0x00000001);
375-
eq = (struct equiv_cpu_entry *)(container + CONTAINER_HDR_SZ);
379+
eq = (struct equiv_cpu_entry *)(cont + CONTAINER_HDR_SZ);
376380

377381
eq_id = find_equiv_id(eq, eax);
378382
if (!eq_id)
@@ -434,6 +438,9 @@ int __init save_microcode_in_initrd_amd(void)
434438
else
435439
container = cont_va;
436440

441+
/* Add CONFIG_RANDOMIZE_MEMORY offset. */
442+
container += PAGE_OFFSET - __PAGE_OFFSET_BASE;
443+
437444
eax = cpuid_eax(0x00000001);
438445
eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff);
439446

arch/x86/kernel/smpboot.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ EXPORT_PER_CPU_SYMBOL(cpu_info);
100100
/* Logical package management. We might want to allocate that dynamically */
101101
static int *physical_to_logical_pkg __read_mostly;
102102
static unsigned long *physical_package_map __read_mostly;;
103-
static unsigned long *logical_package_map __read_mostly;
104103
static unsigned int max_physical_pkg_id __read_mostly;
105104
unsigned int __max_logical_packages __read_mostly;
106105
EXPORT_SYMBOL(__max_logical_packages);
106+
static unsigned int logical_packages __read_mostly;
107+
static bool logical_packages_frozen __read_mostly;
107108

108109
/* Maximum number of SMT threads on any online core */
109110
int __max_smt_threads __read_mostly;
@@ -277,14 +278,14 @@ int topology_update_package_map(unsigned int apicid, unsigned int cpu)
277278
if (test_and_set_bit(pkg, physical_package_map))
278279
goto found;
279280

280-
new = find_first_zero_bit(logical_package_map, __max_logical_packages);
281-
if (new >= __max_logical_packages) {
281+
if (logical_packages_frozen) {
282282
physical_to_logical_pkg[pkg] = -1;
283-
pr_warn("APIC(%x) Package %u exceeds logical package map\n",
283+
pr_warn("APIC(%x) Package %u exceeds logical package max\n",
284284
apicid, pkg);
285285
return -ENOSPC;
286286
}
287-
set_bit(new, logical_package_map);
287+
288+
new = logical_packages++;
288289
pr_info("APIC(%x) Converting physical %u to logical package %u\n",
289290
apicid, pkg, new);
290291
physical_to_logical_pkg[pkg] = new;
@@ -341,6 +342,7 @@ static void __init smp_init_package_map(void)
341342
}
342343

343344
__max_logical_packages = DIV_ROUND_UP(total_cpus, ncpus);
345+
logical_packages = 0;
344346

345347
/*
346348
* Possibly larger than what we need as the number of apic ids per
@@ -352,10 +354,6 @@ static void __init smp_init_package_map(void)
352354
memset(physical_to_logical_pkg, 0xff, size);
353355
size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long);
354356
physical_package_map = kzalloc(size, GFP_KERNEL);
355-
size = BITS_TO_LONGS(__max_logical_packages) * sizeof(unsigned long);
356-
logical_package_map = kzalloc(size, GFP_KERNEL);
357-
358-
pr_info("Max logical packages: %u\n", __max_logical_packages);
359357

360358
for_each_present_cpu(cpu) {
361359
unsigned int apicid = apic->cpu_present_to_apicid(cpu);
@@ -369,6 +367,15 @@ static void __init smp_init_package_map(void)
369367
set_cpu_possible(cpu, false);
370368
set_cpu_present(cpu, false);
371369
}
370+
371+
if (logical_packages > __max_logical_packages) {
372+
pr_warn("Detected more packages (%u), then computed by BIOS data (%u).\n",
373+
logical_packages, __max_logical_packages);
374+
logical_packages_frozen = true;
375+
__max_logical_packages = logical_packages;
376+
}
377+
378+
pr_info("Max logical packages: %u\n", __max_logical_packages);
372379
}
373380

374381
void __init smp_store_boot_cpu_info(void)

0 commit comments

Comments
 (0)