Skip to content

Commit 4fedcde

Browse files
committed
Merge branch 'x86/urgent' into x86/cache
Pick up pending upstream fixes to meet dependencies
2 parents 515f045 + ea136a1 commit 4fedcde

File tree

13 files changed

+71
-47
lines changed

13 files changed

+71
-47
lines changed

arch/x86/include/asm/fpu/internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static inline void __fpregs_load_activate(void)
536536
struct fpu *fpu = &current->thread.fpu;
537537
int cpu = smp_processor_id();
538538

539-
if (WARN_ON_ONCE(current->mm == NULL))
539+
if (WARN_ON_ONCE(current->flags & PF_KTHREAD))
540540
return;
541541

542542
if (!fpregs_state_valid(fpu, cpu)) {
@@ -567,11 +567,11 @@ static inline void __fpregs_load_activate(void)
567567
* otherwise.
568568
*
569569
* The FPU context is only stored/restored for a user task and
570-
* ->mm is used to distinguish between kernel and user threads.
570+
* PF_KTHREAD is used to distinguish between kernel and user threads.
571571
*/
572572
static inline void switch_fpu_prepare(struct fpu *old_fpu, int cpu)
573573
{
574-
if (static_cpu_has(X86_FEATURE_FPU) && current->mm) {
574+
if (static_cpu_has(X86_FEATURE_FPU) && !(current->flags & PF_KTHREAD)) {
575575
if (!copy_fpregs_to_fpstate(old_fpu))
576576
old_fpu->last_cpu = -1;
577577
else

arch/x86/include/asm/intel-family.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252

5353
#define INTEL_FAM6_CANNONLAKE_MOBILE 0x66
5454

55+
#define INTEL_FAM6_ICELAKE_X 0x6A
56+
#define INTEL_FAM6_ICELAKE_XEON_D 0x6C
57+
#define INTEL_FAM6_ICELAKE_DESKTOP 0x7D
5558
#define INTEL_FAM6_ICELAKE_MOBILE 0x7E
5659

5760
/* "Small Core" Processors (Atom) */

arch/x86/kernel/apic/apic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,8 @@ static void apic_pending_intr_clear(void)
14641464
if (queued) {
14651465
if (boot_cpu_has(X86_FEATURE_TSC) && cpu_khz) {
14661466
ntsc = rdtsc();
1467-
max_loops = (cpu_khz << 10) - (ntsc - tsc);
1467+
max_loops = (long long)cpu_khz << 10;
1468+
max_loops -= ntsc - tsc;
14681469
} else {
14691470
max_loops--;
14701471
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,13 +789,16 @@ static struct syscore_ops mc_syscore_ops = {
789789
.resume = mc_bp_resume,
790790
};
791791

792-
static int mc_cpu_online(unsigned int cpu)
792+
static int mc_cpu_starting(unsigned int cpu)
793793
{
794-
struct device *dev;
795-
796-
dev = get_cpu_device(cpu);
797794
microcode_update_cpu(cpu);
798795
pr_debug("CPU%d added\n", cpu);
796+
return 0;
797+
}
798+
799+
static int mc_cpu_online(unsigned int cpu)
800+
{
801+
struct device *dev = get_cpu_device(cpu);
799802

800803
if (sysfs_create_group(&dev->kobj, &mc_attr_group))
801804
pr_err("Failed to create group for CPU%d\n", cpu);
@@ -872,6 +875,8 @@ int __init microcode_init(void)
872875
goto out_ucode_group;
873876

874877
register_syscore_ops(&mc_syscore_ops);
878+
cpuhp_setup_state_nocalls(CPUHP_AP_MICROCODE_LOADER, "x86/microcode:starting",
879+
mc_cpu_starting, NULL);
875880
cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/microcode:online",
876881
mc_cpu_online, mc_cpu_down_prep);
877882

arch/x86/kernel/cpu/resctrl/monitor.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
360360
struct list_head *head;
361361
struct rdtgroup *entry;
362362

363+
if (!is_mbm_local_enabled())
364+
return;
365+
363366
r_mba = &rdt_resources_all[RDT_RESOURCE_MBA];
364367
closid = rgrp->closid;
365368
rmid = rgrp->mon.rmid;

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,12 @@ static int rdt_bit_usage_show(struct kernfs_open_file *of,
796796
struct seq_file *seq, void *v)
797797
{
798798
struct rdt_resource *r = of->kn->parent->priv;
799-
u32 sw_shareable = 0, hw_shareable = 0;
800-
u32 exclusive = 0, pseudo_locked = 0;
799+
/*
800+
* Use unsigned long even though only 32 bits are used to ensure
801+
* test_bit() is used safely.
802+
*/
803+
unsigned long sw_shareable = 0, hw_shareable = 0;
804+
unsigned long exclusive = 0, pseudo_locked = 0;
801805
struct rdt_domain *dom;
802806
int i, hwb, swb, excl, psl;
803807
enum rdtgrp_mode mode;
@@ -842,10 +846,10 @@ static int rdt_bit_usage_show(struct kernfs_open_file *of,
842846
}
843847
for (i = r->cache.cbm_len - 1; i >= 0; i--) {
844848
pseudo_locked = dom->plr ? dom->plr->cbm : 0;
845-
hwb = test_bit(i, (unsigned long *)&hw_shareable);
846-
swb = test_bit(i, (unsigned long *)&sw_shareable);
847-
excl = test_bit(i, (unsigned long *)&exclusive);
848-
psl = test_bit(i, (unsigned long *)&pseudo_locked);
849+
hwb = test_bit(i, &hw_shareable);
850+
swb = test_bit(i, &sw_shareable);
851+
excl = test_bit(i, &exclusive);
852+
psl = test_bit(i, &pseudo_locked);
849853
if (hwb && swb)
850854
seq_putc(seq, 'X');
851855
else if (hwb && !swb)
@@ -2486,26 +2490,19 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
24862490
*/
24872491
static void cbm_ensure_valid(u32 *_val, struct rdt_resource *r)
24882492
{
2489-
/*
2490-
* Convert the u32 _val to an unsigned long required by all the bit
2491-
* operations within this function. No more than 32 bits of this
2492-
* converted value can be accessed because all bit operations are
2493-
* additionally provided with cbm_len that is initialized during
2494-
* hardware enumeration using five bits from the EAX register and
2495-
* thus never can exceed 32 bits.
2496-
*/
2497-
unsigned long *val = (unsigned long *)_val;
2493+
unsigned long val = *_val;
24982494
unsigned int cbm_len = r->cache.cbm_len;
24992495
unsigned long first_bit, zero_bit;
25002496

2501-
if (*val == 0)
2497+
if (val == 0)
25022498
return;
25032499

2504-
first_bit = find_first_bit(val, cbm_len);
2505-
zero_bit = find_next_zero_bit(val, cbm_len, first_bit);
2500+
first_bit = find_first_bit(&val, cbm_len);
2501+
zero_bit = find_next_zero_bit(&val, cbm_len, first_bit);
25062502

25072503
/* Clear any remaining bits to ensure contiguous region */
2508-
bitmap_clear(val, zero_bit, cbm_len - zero_bit);
2504+
bitmap_clear(&val, zero_bit, cbm_len - zero_bit);
2505+
*_val = (u32)val;
25092506
}
25102507

25112508
/*
@@ -2534,7 +2531,12 @@ static int __init_one_rdt_domain(struct rdt_domain *d, struct rdt_resource *r,
25342531
if (closid_allocated(i) && i != closid) {
25352532
mode = rdtgroup_mode_by_closid(i);
25362533
if (mode == RDT_MODE_PSEUDO_LOCKSETUP)
2537-
break;
2534+
/*
2535+
* ctrl values for locksetup aren't relevant
2536+
* until the schemata is written, and the mode
2537+
* becomes RDT_MODE_PSEUDO_LOCKED.
2538+
*/
2539+
continue;
25382540
/*
25392541
* If CDP is active include peer domain's
25402542
* usage to ensure there is no overlap

arch/x86/kernel/fpu/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void __kernel_fpu_begin(void)
102102

103103
kernel_fpu_disable();
104104

105-
if (current->mm) {
105+
if (!(current->flags & PF_KTHREAD)) {
106106
if (!test_thread_flag(TIF_NEED_FPU_LOAD)) {
107107
set_thread_flag(TIF_NEED_FPU_LOAD);
108108
/*

arch/x86/kernel/fpu/signal.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/compat.h>
77
#include <linux/cpu.h>
8+
#include <linux/pagemap.h>
89

910
#include <asm/fpu/internal.h>
1011
#include <asm/fpu/signal.h>
@@ -61,6 +62,11 @@ static inline int save_fsave_header(struct task_struct *tsk, void __user *buf)
6162
struct user_i387_ia32_struct env;
6263
struct _fpstate_32 __user *fp = buf;
6364

65+
fpregs_lock();
66+
if (!test_thread_flag(TIF_NEED_FPU_LOAD))
67+
copy_fxregs_to_kernel(&tsk->thread.fpu);
68+
fpregs_unlock();
69+
6470
convert_from_fxsr(&env, tsk);
6571

6672
if (__copy_to_user(buf, &env, sizeof(env)) ||
@@ -189,15 +195,7 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
189195
fpregs_unlock();
190196

191197
if (ret) {
192-
int aligned_size;
193-
int nr_pages;
194-
195-
aligned_size = offset_in_page(buf_fx) + fpu_user_xstate_size;
196-
nr_pages = DIV_ROUND_UP(aligned_size, PAGE_SIZE);
197-
198-
ret = get_user_pages_unlocked((unsigned long)buf_fx, nr_pages,
199-
NULL, FOLL_WRITE);
200-
if (ret == nr_pages)
198+
if (!fault_in_pages_writeable(buf_fx, fpu_user_xstate_size))
201199
goto retry;
202200
return -EFAULT;
203201
}

arch/x86/kernel/kgdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
758758
BREAK_INSTR_SIZE);
759759
bpt->type = BP_POKE_BREAKPOINT;
760760

761-
return err;
761+
return 0;
762762
}
763763

764764
int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)

arch/x86/mm/kasan_init_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static inline p4d_t *early_p4d_offset(pgd_t *pgd, unsigned long addr)
199199
if (!pgtable_l5_enabled())
200200
return (p4d_t *)pgd;
201201

202-
p4d = __pa_nodebug(pgd_val(*pgd)) & PTE_PFN_MASK;
202+
p4d = pgd_val(*pgd) & PTE_PFN_MASK;
203203
p4d += __START_KERNEL_map - phys_base;
204204
return (p4d_t *)p4d + p4d_index(addr);
205205
}

arch/x86/mm/kaslr.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static __initdata struct kaslr_memory_region {
5252
} kaslr_regions[] = {
5353
{ &page_offset_base, 0 },
5454
{ &vmalloc_base, 0 },
55-
{ &vmemmap_base, 1 },
55+
{ &vmemmap_base, 0 },
5656
};
5757

5858
/* Get size in bytes used by the memory region */
@@ -78,6 +78,7 @@ void __init kernel_randomize_memory(void)
7878
unsigned long rand, memory_tb;
7979
struct rnd_state rand_state;
8080
unsigned long remain_entropy;
81+
unsigned long vmemmap_size;
8182

8283
vaddr_start = pgtable_l5_enabled() ? __PAGE_OFFSET_BASE_L5 : __PAGE_OFFSET_BASE_L4;
8384
vaddr = vaddr_start;
@@ -109,6 +110,14 @@ void __init kernel_randomize_memory(void)
109110
if (memory_tb < kaslr_regions[0].size_tb)
110111
kaslr_regions[0].size_tb = memory_tb;
111112

113+
/*
114+
* Calculate the vmemmap region size in TBs, aligned to a TB
115+
* boundary.
116+
*/
117+
vmemmap_size = (kaslr_regions[0].size_tb << (TB_SHIFT - PAGE_SHIFT)) *
118+
sizeof(struct page);
119+
kaslr_regions[2].size_tb = DIV_ROUND_UP(vmemmap_size, 1UL << TB_SHIFT);
120+
112121
/* Calculate entropy available between regions */
113122
remain_entropy = vaddr_end - vaddr_start;
114123
for (i = 0; i < ARRAY_SIZE(kaslr_regions); i++)

include/linux/cpuhotplug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ enum cpuhp_state {
101101
CPUHP_AP_IRQ_BCM2836_STARTING,
102102
CPUHP_AP_IRQ_MIPS_GIC_STARTING,
103103
CPUHP_AP_ARM_MVEBU_COHERENCY,
104+
CPUHP_AP_MICROCODE_LOADER,
104105
CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING,
105106
CPUHP_AP_PERF_X86_STARTING,
106107
CPUHP_AP_PERF_X86_AMD_IBS_STARTING,

mm/vmalloc.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,9 +2123,9 @@ static inline void set_area_direct_map(const struct vm_struct *area,
21232123
/* Handle removing and resetting vm mappings related to the vm_struct. */
21242124
static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages)
21252125
{
2126-
unsigned long addr = (unsigned long)area->addr;
21272126
unsigned long start = ULONG_MAX, end = 0;
21282127
int flush_reset = area->flags & VM_FLUSH_RESET_PERMS;
2128+
int flush_dmap = 0;
21292129
int i;
21302130

21312131
/*
@@ -2135,8 +2135,8 @@ static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages)
21352135
* execute permissions, without leaving a RW+X window.
21362136
*/
21372137
if (flush_reset && !IS_ENABLED(CONFIG_ARCH_HAS_SET_DIRECT_MAP)) {
2138-
set_memory_nx(addr, area->nr_pages);
2139-
set_memory_rw(addr, area->nr_pages);
2138+
set_memory_nx((unsigned long)area->addr, area->nr_pages);
2139+
set_memory_rw((unsigned long)area->addr, area->nr_pages);
21402140
}
21412141

21422142
remove_vm_area(area->addr);
@@ -2160,9 +2160,11 @@ static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages)
21602160
* the vm_unmap_aliases() flush includes the direct map.
21612161
*/
21622162
for (i = 0; i < area->nr_pages; i++) {
2163-
if (page_address(area->pages[i])) {
2163+
unsigned long addr = (unsigned long)page_address(area->pages[i]);
2164+
if (addr) {
21642165
start = min(addr, start);
2165-
end = max(addr, end);
2166+
end = max(addr + PAGE_SIZE, end);
2167+
flush_dmap = 1;
21662168
}
21672169
}
21682170

@@ -2172,7 +2174,7 @@ static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages)
21722174
* reset the direct map permissions to the default.
21732175
*/
21742176
set_area_direct_map(area, set_direct_map_invalid_noflush);
2175-
_vm_unmap_aliases(start, end, 1);
2177+
_vm_unmap_aliases(start, end, flush_dmap);
21762178
set_area_direct_map(area, set_direct_map_default_noflush);
21772179
}
21782180

0 commit comments

Comments
 (0)