Skip to content

Commit 328c633

Browse files
committed
Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Thomas writes: "A set of fixes for x86: - Resolve the kvmclock regression on AMD systems with memory encryption enabled. The rework of the kvmclock memory allocation during early boot results in encrypted storage, which is not shareable with the hypervisor. Create a new section for this data which is mapped unencrypted and take care that the later allocations for shared kvmclock memory is unencrypted as well. - Fix the build regression in the paravirt code introduced by the recent spectre v2 updates. - Ensure that the initial static page tables cover the fixmap space correctly so early console always works. This worked so far by chance, but recent modifications to the fixmap layout can - depending on kernel configuration - move the relevant entries to a different place which is not covered by the initial static page tables. - Address the regressions and issues which got introduced with the recent extensions to the Intel Recource Director Technology code. - Update maintainer entries to document reality" * 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/mm: Expand static page table for fixmap space MAINTAINERS: Add X86 MM entry x86/intel_rdt: Add Reinette as co-maintainer for RDT MAINTAINERS: Add Borislav to the x86 maintainers x86/paravirt: Fix some warning messages x86/intel_rdt: Fix incorrect loop end condition x86/intel_rdt: Fix exclusive mode handling of MBA resource x86/intel_rdt: Fix incorrect loop end condition x86/intel_rdt: Do not allow pseudo-locking of MBA resource x86/intel_rdt: Fix unchecked MSR access x86/intel_rdt: Fix invalid mode warning when multiple resources are managed x86/intel_rdt: Global closid helper to support future fixes x86/intel_rdt: Fix size reporting of MBA resource x86/intel_rdt: Fix data type in parsing callbacks x86/kvm: Use __bss_decrypted attribute in shared variables x86/mm: Add .bss..decrypted section to hold shared variables
2 parents 52890d2 + 05ab1d8 commit 328c633

File tree

16 files changed

+245
-39
lines changed

16 files changed

+245
-39
lines changed

MAINTAINERS

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12260,6 +12260,7 @@ F: Documentation/networking/rds.txt
1226012260

1226112261
RDT - RESOURCE ALLOCATION
1226212262
M: Fenghua Yu <fenghua.yu@intel.com>
12263+
M: Reinette Chatre <reinette.chatre@intel.com>
1226312264
L: linux-kernel@vger.kernel.org
1226412265
S: Supported
1226512266
F: arch/x86/kernel/cpu/intel_rdt*
@@ -15912,6 +15913,7 @@ F: net/x25/
1591215913
X86 ARCHITECTURE (32-BIT AND 64-BIT)
1591315914
M: Thomas Gleixner <tglx@linutronix.de>
1591415915
M: Ingo Molnar <mingo@redhat.com>
15916+
M: Borislav Petkov <bp@alien8.de>
1591515917
R: "H. Peter Anvin" <hpa@zytor.com>
1591615918
M: x86@kernel.org
1591715919
L: linux-kernel@vger.kernel.org
@@ -15940,6 +15942,15 @@ M: Borislav Petkov <bp@alien8.de>
1594015942
S: Maintained
1594115943
F: arch/x86/kernel/cpu/microcode/*
1594215944

15945+
X86 MM
15946+
M: Dave Hansen <dave.hansen@linux.intel.com>
15947+
M: Andy Lutomirski <luto@kernel.org>
15948+
M: Peter Zijlstra <peterz@infradead.org>
15949+
L: linux-kernel@vger.kernel.org
15950+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/mm
15951+
S: Maintained
15952+
F: arch/x86/mm/
15953+
1594315954
X86 PLATFORM DRIVERS
1594415955
M: Darren Hart <dvhart@infradead.org>
1594515956
M: Andy Shevchenko <andy@infradead.org>

arch/x86/include/asm/fixmap.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
#ifndef _ASM_X86_FIXMAP_H
1515
#define _ASM_X86_FIXMAP_H
1616

17+
/*
18+
* Exposed to assembly code for setting up initial page tables. Cannot be
19+
* calculated in assembly code (fixmap entries are an enum), but is sanity
20+
* checked in the actual fixmap C code to make sure that the fixmap is
21+
* covered fully.
22+
*/
23+
#define FIXMAP_PMD_NUM 2
24+
/* fixmap starts downwards from the 507th entry in level2_fixmap_pgt */
25+
#define FIXMAP_PMD_TOP 507
26+
1727
#ifndef __ASSEMBLY__
1828
#include <linux/kernel.h>
1929
#include <asm/acpi.h>

arch/x86/include/asm/mem_encrypt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size);
4848

4949
/* Architecture __weak replacement functions */
5050
void __init mem_encrypt_init(void);
51+
void __init mem_encrypt_free_decrypted_mem(void);
5152

5253
bool sme_active(void);
5354
bool sev_active(void);
5455

56+
#define __bss_decrypted __attribute__((__section__(".bss..decrypted")))
57+
5558
#else /* !CONFIG_AMD_MEM_ENCRYPT */
5659

5760
#define sme_me_mask 0ULL
@@ -77,6 +80,8 @@ early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0;
7780
static inline int __init
7881
early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; }
7982

83+
#define __bss_decrypted
84+
8085
#endif /* CONFIG_AMD_MEM_ENCRYPT */
8186

8287
/*
@@ -88,6 +93,8 @@ early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0;
8893
#define __sme_pa(x) (__pa(x) | sme_me_mask)
8994
#define __sme_pa_nodebug(x) (__pa_nodebug(x) | sme_me_mask)
9095

96+
extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypted_unused[];
97+
9198
#endif /* __ASSEMBLY__ */
9299

93100
#endif /* __X86_MEM_ENCRYPT_H__ */

arch/x86/include/asm/pgtable_64.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <asm/processor.h>
1515
#include <linux/bitops.h>
1616
#include <linux/threads.h>
17+
#include <asm/fixmap.h>
1718

1819
extern p4d_t level4_kernel_pgt[512];
1920
extern p4d_t level4_ident_pgt[512];
@@ -22,7 +23,7 @@ extern pud_t level3_ident_pgt[512];
2223
extern pmd_t level2_kernel_pgt[512];
2324
extern pmd_t level2_fixmap_pgt[512];
2425
extern pmd_t level2_ident_pgt[512];
25-
extern pte_t level1_fixmap_pgt[512];
26+
extern pte_t level1_fixmap_pgt[512 * FIXMAP_PMD_NUM];
2627
extern pgd_t init_top_pgt[];
2728

2829
#define swapper_pg_dir init_top_pgt

arch/x86/kernel/cpu/intel_rdt.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ static inline bool is_mbm_event(int e)
382382
e <= QOS_L3_MBM_LOCAL_EVENT_ID);
383383
}
384384

385+
struct rdt_parse_data {
386+
struct rdtgroup *rdtgrp;
387+
char *buf;
388+
};
389+
385390
/**
386391
* struct rdt_resource - attributes of an RDT resource
387392
* @rid: The index of the resource
@@ -423,16 +428,19 @@ struct rdt_resource {
423428
struct rdt_cache cache;
424429
struct rdt_membw membw;
425430
const char *format_str;
426-
int (*parse_ctrlval) (void *data, struct rdt_resource *r,
427-
struct rdt_domain *d);
431+
int (*parse_ctrlval)(struct rdt_parse_data *data,
432+
struct rdt_resource *r,
433+
struct rdt_domain *d);
428434
struct list_head evt_list;
429435
int num_rmid;
430436
unsigned int mon_scale;
431437
unsigned long fflags;
432438
};
433439

434-
int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d);
435-
int parse_bw(void *_buf, struct rdt_resource *r, struct rdt_domain *d);
440+
int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
441+
struct rdt_domain *d);
442+
int parse_bw(struct rdt_parse_data *data, struct rdt_resource *r,
443+
struct rdt_domain *d);
436444

437445
extern struct mutex rdtgroup_mutex;
438446

@@ -536,6 +544,7 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp);
536544
void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp);
537545
struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r);
538546
int update_domains(struct rdt_resource *r, int closid);
547+
int closids_supported(void);
539548
void closid_free(int closid);
540549
int alloc_rmid(void);
541550
void free_rmid(u32 rmid);

arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
6464
return true;
6565
}
6666

67-
int parse_bw(void *_buf, struct rdt_resource *r, struct rdt_domain *d)
67+
int parse_bw(struct rdt_parse_data *data, struct rdt_resource *r,
68+
struct rdt_domain *d)
6869
{
69-
unsigned long data;
70-
char *buf = _buf;
70+
unsigned long bw_val;
7171

7272
if (d->have_new_ctrl) {
7373
rdt_last_cmd_printf("duplicate domain %d\n", d->id);
7474
return -EINVAL;
7575
}
7676

77-
if (!bw_validate(buf, &data, r))
77+
if (!bw_validate(data->buf, &bw_val, r))
7878
return -EINVAL;
79-
d->new_ctrl = data;
79+
d->new_ctrl = bw_val;
8080
d->have_new_ctrl = true;
8181

8282
return 0;
@@ -123,18 +123,13 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
123123
return true;
124124
}
125125

126-
struct rdt_cbm_parse_data {
127-
struct rdtgroup *rdtgrp;
128-
char *buf;
129-
};
130-
131126
/*
132127
* Read one cache bit mask (hex). Check that it is valid for the current
133128
* resource type.
134129
*/
135-
int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d)
130+
int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
131+
struct rdt_domain *d)
136132
{
137-
struct rdt_cbm_parse_data *data = _data;
138133
struct rdtgroup *rdtgrp = data->rdtgrp;
139134
u32 cbm_val;
140135

@@ -195,11 +190,17 @@ int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d)
195190
static int parse_line(char *line, struct rdt_resource *r,
196191
struct rdtgroup *rdtgrp)
197192
{
198-
struct rdt_cbm_parse_data data;
193+
struct rdt_parse_data data;
199194
char *dom = NULL, *id;
200195
struct rdt_domain *d;
201196
unsigned long dom_id;
202197

198+
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&
199+
r->rid == RDT_RESOURCE_MBA) {
200+
rdt_last_cmd_puts("Cannot pseudo-lock MBA resource\n");
201+
return -EINVAL;
202+
}
203+
203204
next:
204205
if (!line || line[0] == '\0')
205206
return 0;

arch/x86/kernel/cpu/intel_rdt_rdtgroup.c

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ void rdt_last_cmd_printf(const char *fmt, ...)
9797
* limited as the number of resources grows.
9898
*/
9999
static int closid_free_map;
100+
static int closid_free_map_len;
101+
102+
int closids_supported(void)
103+
{
104+
return closid_free_map_len;
105+
}
100106

101107
static void closid_init(void)
102108
{
@@ -111,6 +117,7 @@ static void closid_init(void)
111117

112118
/* CLOSID 0 is always reserved for the default group */
113119
closid_free_map &= ~1;
120+
closid_free_map_len = rdt_min_closid;
114121
}
115122

116123
static int closid_alloc(void)
@@ -802,7 +809,7 @@ static int rdt_bit_usage_show(struct kernfs_open_file *of,
802809
sw_shareable = 0;
803810
exclusive = 0;
804811
seq_printf(seq, "%d=", dom->id);
805-
for (i = 0; i < r->num_closid; i++, ctrl++) {
812+
for (i = 0; i < closids_supported(); i++, ctrl++) {
806813
if (!closid_allocated(i))
807814
continue;
808815
mode = rdtgroup_mode_by_closid(i);
@@ -989,7 +996,7 @@ bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
989996

990997
/* Check for overlap with other resource groups */
991998
ctrl = d->ctrl_val;
992-
for (i = 0; i < r->num_closid; i++, ctrl++) {
999+
for (i = 0; i < closids_supported(); i++, ctrl++) {
9931000
ctrl_b = (unsigned long *)ctrl;
9941001
mode = rdtgroup_mode_by_closid(i);
9951002
if (closid_allocated(i) && i != closid &&
@@ -1024,16 +1031,27 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)
10241031
{
10251032
int closid = rdtgrp->closid;
10261033
struct rdt_resource *r;
1034+
bool has_cache = false;
10271035
struct rdt_domain *d;
10281036

10291037
for_each_alloc_enabled_rdt_resource(r) {
1038+
if (r->rid == RDT_RESOURCE_MBA)
1039+
continue;
1040+
has_cache = true;
10301041
list_for_each_entry(d, &r->domains, list) {
10311042
if (rdtgroup_cbm_overlaps(r, d, d->ctrl_val[closid],
1032-
rdtgrp->closid, false))
1043+
rdtgrp->closid, false)) {
1044+
rdt_last_cmd_puts("schemata overlaps\n");
10331045
return false;
1046+
}
10341047
}
10351048
}
10361049

1050+
if (!has_cache) {
1051+
rdt_last_cmd_puts("cannot be exclusive without CAT/CDP\n");
1052+
return false;
1053+
}
1054+
10371055
return true;
10381056
}
10391057

@@ -1085,7 +1103,6 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
10851103
rdtgrp->mode = RDT_MODE_SHAREABLE;
10861104
} else if (!strcmp(buf, "exclusive")) {
10871105
if (!rdtgroup_mode_test_exclusive(rdtgrp)) {
1088-
rdt_last_cmd_printf("schemata overlaps\n");
10891106
ret = -EINVAL;
10901107
goto out;
10911108
}
@@ -1155,8 +1172,8 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
11551172
struct rdt_resource *r;
11561173
struct rdt_domain *d;
11571174
unsigned int size;
1158-
bool sep = false;
1159-
u32 cbm;
1175+
bool sep;
1176+
u32 ctrl;
11601177

11611178
rdtgrp = rdtgroup_kn_lock_live(of->kn);
11621179
if (!rdtgrp) {
@@ -1174,15 +1191,21 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
11741191
}
11751192

11761193
for_each_alloc_enabled_rdt_resource(r) {
1194+
sep = false;
11771195
seq_printf(s, "%*s:", max_name_width, r->name);
11781196
list_for_each_entry(d, &r->domains, list) {
11791197
if (sep)
11801198
seq_putc(s, ';');
11811199
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
11821200
size = 0;
11831201
} else {
1184-
cbm = d->ctrl_val[rdtgrp->closid];
1185-
size = rdtgroup_cbm_to_size(r, d, cbm);
1202+
ctrl = (!is_mba_sc(r) ?
1203+
d->ctrl_val[rdtgrp->closid] :
1204+
d->mbps_val[rdtgrp->closid]);
1205+
if (r->rid == RDT_RESOURCE_MBA)
1206+
size = ctrl;
1207+
else
1208+
size = rdtgroup_cbm_to_size(r, d, ctrl);
11861209
}
11871210
seq_printf(s, "%d=%u", d->id, size);
11881211
sep = true;
@@ -2336,12 +2359,18 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
23362359
u32 *ctrl;
23372360

23382361
for_each_alloc_enabled_rdt_resource(r) {
2362+
/*
2363+
* Only initialize default allocations for CBM cache
2364+
* resources
2365+
*/
2366+
if (r->rid == RDT_RESOURCE_MBA)
2367+
continue;
23392368
list_for_each_entry(d, &r->domains, list) {
23402369
d->have_new_ctrl = false;
23412370
d->new_ctrl = r->cache.shareable_bits;
23422371
used_b = r->cache.shareable_bits;
23432372
ctrl = d->ctrl_val;
2344-
for (i = 0; i < r->num_closid; i++, ctrl++) {
2373+
for (i = 0; i < closids_supported(); i++, ctrl++) {
23452374
if (closid_allocated(i) && i != closid) {
23462375
mode = rdtgroup_mode_by_closid(i);
23472376
if (mode == RDT_MODE_PSEUDO_LOCKSETUP)
@@ -2373,6 +2402,12 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
23732402
}
23742403

23752404
for_each_alloc_enabled_rdt_resource(r) {
2405+
/*
2406+
* Only initialize default allocations for CBM cache
2407+
* resources
2408+
*/
2409+
if (r->rid == RDT_RESOURCE_MBA)
2410+
continue;
23762411
ret = update_domains(r, rdtgrp->closid);
23772412
if (ret < 0) {
23782413
rdt_last_cmd_puts("failed to initialize allocations\n");

arch/x86/kernel/head64.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <asm/bootparam_utils.h>
3636
#include <asm/microcode.h>
3737
#include <asm/kasan.h>
38+
#include <asm/fixmap.h>
3839

3940
/*
4041
* Manage page tables very early on.
@@ -112,6 +113,7 @@ static bool __head check_la57_support(unsigned long physaddr)
112113
unsigned long __head __startup_64(unsigned long physaddr,
113114
struct boot_params *bp)
114115
{
116+
unsigned long vaddr, vaddr_end;
115117
unsigned long load_delta, *p;
116118
unsigned long pgtable_flags;
117119
pgdval_t *pgd;
@@ -165,7 +167,8 @@ unsigned long __head __startup_64(unsigned long physaddr,
165167
pud[511] += load_delta;
166168

167169
pmd = fixup_pointer(level2_fixmap_pgt, physaddr);
168-
pmd[506] += load_delta;
170+
for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--)
171+
pmd[i] += load_delta;
169172

170173
/*
171174
* Set up the identity mapping for the switchover. These
@@ -234,6 +237,21 @@ unsigned long __head __startup_64(unsigned long physaddr,
234237
/* Encrypt the kernel and related (if SME is active) */
235238
sme_encrypt_kernel(bp);
236239

240+
/*
241+
* Clear the memory encryption mask from the .bss..decrypted section.
242+
* The bss section will be memset to zero later in the initialization so
243+
* there is no need to zero it after changing the memory encryption
244+
* attribute.
245+
*/
246+
if (mem_encrypt_active()) {
247+
vaddr = (unsigned long)__start_bss_decrypted;
248+
vaddr_end = (unsigned long)__end_bss_decrypted;
249+
for (; vaddr < vaddr_end; vaddr += PMD_SIZE) {
250+
i = pmd_index(vaddr);
251+
pmd[i] -= sme_get_me_mask();
252+
}
253+
}
254+
237255
/*
238256
* Return the SME encryption mask (if SME is active) to be used as a
239257
* modifier for the initial pgdir entry programmed into CR3.

0 commit comments

Comments
 (0)