Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+245 -39
+11
MAINTAINERS
··· 12260 12260 12261 12261 RDT - RESOURCE ALLOCATION 12262 12262 M: Fenghua Yu <fenghua.yu@intel.com> 12263 + M: Reinette Chatre <reinette.chatre@intel.com> 12263 12264 L: linux-kernel@vger.kernel.org 12264 12265 S: Supported 12265 12266 F: arch/x86/kernel/cpu/intel_rdt* ··· 15913 15912 X86 ARCHITECTURE (32-BIT AND 64-BIT) 15914 15913 M: Thomas Gleixner <tglx@linutronix.de> 15915 15914 M: Ingo Molnar <mingo@redhat.com> 15915 + M: Borislav Petkov <bp@alien8.de> 15916 15916 R: "H. Peter Anvin" <hpa@zytor.com> 15917 15917 M: x86@kernel.org 15918 15918 L: linux-kernel@vger.kernel.org ··· 15941 15939 M: Borislav Petkov <bp@alien8.de> 15942 15940 S: Maintained 15943 15941 F: arch/x86/kernel/cpu/microcode/* 15942 + 15943 + X86 MM 15944 + M: Dave Hansen <dave.hansen@linux.intel.com> 15945 + M: Andy Lutomirski <luto@kernel.org> 15946 + M: Peter Zijlstra <peterz@infradead.org> 15947 + L: linux-kernel@vger.kernel.org 15948 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/mm 15949 + S: Maintained 15950 + F: arch/x86/mm/ 15944 15951 15945 15952 X86 PLATFORM DRIVERS 15946 15953 M: Darren Hart <dvhart@infradead.org>
+10
arch/x86/include/asm/fixmap.h
··· 14 14 #ifndef _ASM_X86_FIXMAP_H 15 15 #define _ASM_X86_FIXMAP_H 16 16 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 + 17 27 #ifndef __ASSEMBLY__ 18 28 #include <linux/kernel.h> 19 29 #include <asm/acpi.h>
+7
arch/x86/include/asm/mem_encrypt.h
··· 48 48 49 49 /* Architecture __weak replacement functions */ 50 50 void __init mem_encrypt_init(void); 51 + void __init mem_encrypt_free_decrypted_mem(void); 51 52 52 53 bool sme_active(void); 53 54 bool sev_active(void); 55 + 56 + #define __bss_decrypted __attribute__((__section__(".bss..decrypted"))) 54 57 55 58 #else /* !CONFIG_AMD_MEM_ENCRYPT */ 56 59 ··· 80 77 static inline int __init 81 78 early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; } 82 79 80 + #define __bss_decrypted 81 + 83 82 #endif /* CONFIG_AMD_MEM_ENCRYPT */ 84 83 85 84 /* ··· 92 87 */ 93 88 #define __sme_pa(x) (__pa(x) | sme_me_mask) 94 89 #define __sme_pa_nodebug(x) (__pa_nodebug(x) | sme_me_mask) 90 + 91 + extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypted_unused[]; 95 92 96 93 #endif /* __ASSEMBLY__ */ 97 94
+2 -1
arch/x86/include/asm/pgtable_64.h
··· 14 14 #include <asm/processor.h> 15 15 #include <linux/bitops.h> 16 16 #include <linux/threads.h> 17 + #include <asm/fixmap.h> 17 18 18 19 extern p4d_t level4_kernel_pgt[512]; 19 20 extern p4d_t level4_ident_pgt[512]; ··· 23 22 extern pmd_t level2_kernel_pgt[512]; 24 23 extern pmd_t level2_fixmap_pgt[512]; 25 24 extern pmd_t level2_ident_pgt[512]; 26 - extern pte_t level1_fixmap_pgt[512]; 25 + extern pte_t level1_fixmap_pgt[512 * FIXMAP_PMD_NUM]; 27 26 extern pgd_t init_top_pgt[]; 28 27 29 28 #define swapper_pg_dir init_top_pgt
+13 -4
arch/x86/kernel/cpu/intel_rdt.h
··· 382 382 e <= QOS_L3_MBM_LOCAL_EVENT_ID); 383 383 } 384 384 385 + struct rdt_parse_data { 386 + struct rdtgroup *rdtgrp; 387 + char *buf; 388 + }; 389 + 385 390 /** 386 391 * struct rdt_resource - attributes of an RDT resource 387 392 * @rid: The index of the resource ··· 428 423 struct rdt_cache cache; 429 424 struct rdt_membw membw; 430 425 const char *format_str; 431 - int (*parse_ctrlval) (void *data, struct rdt_resource *r, 432 - struct rdt_domain *d); 426 + int (*parse_ctrlval)(struct rdt_parse_data *data, 427 + struct rdt_resource *r, 428 + struct rdt_domain *d); 433 429 struct list_head evt_list; 434 430 int num_rmid; 435 431 unsigned int mon_scale; 436 432 unsigned long fflags; 437 433 }; 438 434 439 - int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d); 440 - int parse_bw(void *_buf, struct rdt_resource *r, struct rdt_domain *d); 435 + int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r, 436 + struct rdt_domain *d); 437 + int parse_bw(struct rdt_parse_data *data, struct rdt_resource *r, 438 + struct rdt_domain *d); 441 439 442 440 extern struct mutex rdtgroup_mutex; 443 441 ··· 544 536 void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp); 545 537 struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r); 546 538 int update_domains(struct rdt_resource *r, int closid); 539 + int closids_supported(void); 547 540 void closid_free(int closid); 548 541 int alloc_rmid(void); 549 542 void free_rmid(u32 rmid);
+14 -13
arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
··· 64 64 return true; 65 65 } 66 66 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) 68 69 { 69 - unsigned long data; 70 - char *buf = _buf; 70 + unsigned long bw_val; 71 71 72 72 if (d->have_new_ctrl) { 73 73 rdt_last_cmd_printf("duplicate domain %d\n", d->id); 74 74 return -EINVAL; 75 75 } 76 76 77 - if (!bw_validate(buf, &data, r)) 77 + if (!bw_validate(data->buf, &bw_val, r)) 78 78 return -EINVAL; 79 - d->new_ctrl = data; 79 + d->new_ctrl = bw_val; 80 80 d->have_new_ctrl = true; 81 81 82 82 return 0; ··· 123 123 return true; 124 124 } 125 125 126 - struct rdt_cbm_parse_data { 127 - struct rdtgroup *rdtgrp; 128 - char *buf; 129 - }; 130 - 131 126 /* 132 127 * Read one cache bit mask (hex). Check that it is valid for the current 133 128 * resource type. 134 129 */ 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) 136 132 { 137 - struct rdt_cbm_parse_data *data = _data; 138 133 struct rdtgroup *rdtgrp = data->rdtgrp; 139 134 u32 cbm_val; 140 135 ··· 190 195 static int parse_line(char *line, struct rdt_resource *r, 191 196 struct rdtgroup *rdtgrp) 192 197 { 193 - struct rdt_cbm_parse_data data; 198 + struct rdt_parse_data data; 194 199 char *dom = NULL, *id; 195 200 struct rdt_domain *d; 196 201 unsigned long dom_id; 202 + 203 + if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP && 204 + r->rid == RDT_RESOURCE_MBA) { 205 + rdt_last_cmd_puts("Cannot pseudo-lock MBA resource\n"); 206 + return -EINVAL; 207 + } 197 208 198 209 next: 199 210 if (!line || line[0] == '\0')
+44 -9
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
··· 97 97 * limited as the number of resources grows. 98 98 */ 99 99 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 + } 100 106 101 107 static void closid_init(void) 102 108 { ··· 117 111 118 112 /* CLOSID 0 is always reserved for the default group */ 119 113 closid_free_map &= ~1; 114 + closid_free_map_len = rdt_min_closid; 120 115 } 121 116 122 117 static int closid_alloc(void) ··· 809 802 sw_shareable = 0; 810 803 exclusive = 0; 811 804 seq_printf(seq, "%d=", dom->id); 812 - for (i = 0; i < r->num_closid; i++, ctrl++) { 805 + for (i = 0; i < closids_supported(); i++, ctrl++) { 813 806 if (!closid_allocated(i)) 814 807 continue; 815 808 mode = rdtgroup_mode_by_closid(i); ··· 996 989 997 990 /* Check for overlap with other resource groups */ 998 991 ctrl = d->ctrl_val; 999 - for (i = 0; i < r->num_closid; i++, ctrl++) { 992 + for (i = 0; i < closids_supported(); i++, ctrl++) { 1000 993 ctrl_b = (unsigned long *)ctrl; 1001 994 mode = rdtgroup_mode_by_closid(i); 1002 995 if (closid_allocated(i) && i != closid && ··· 1031 1024 { 1032 1025 int closid = rdtgrp->closid; 1033 1026 struct rdt_resource *r; 1027 + bool has_cache = false; 1034 1028 struct rdt_domain *d; 1035 1029 1036 1030 for_each_alloc_enabled_rdt_resource(r) { 1031 + if (r->rid == RDT_RESOURCE_MBA) 1032 + continue; 1033 + has_cache = true; 1037 1034 list_for_each_entry(d, &r->domains, list) { 1038 1035 if (rdtgroup_cbm_overlaps(r, d, d->ctrl_val[closid], 1039 - rdtgrp->closid, false)) 1036 + rdtgrp->closid, false)) { 1037 + rdt_last_cmd_puts("schemata overlaps\n"); 1040 1038 return false; 1039 + } 1041 1040 } 1041 + } 1042 + 1043 + if (!has_cache) { 1044 + rdt_last_cmd_puts("cannot be exclusive without CAT/CDP\n"); 1045 + return false; 1042 1046 } 1043 1047 1044 1048 return true; ··· 1103 1085 rdtgrp->mode = RDT_MODE_SHAREABLE; 1104 1086 } else if (!strcmp(buf, "exclusive")) { 1105 1087 if (!rdtgroup_mode_test_exclusive(rdtgrp)) { 1106 - rdt_last_cmd_printf("schemata overlaps\n"); 1107 1088 ret = -EINVAL; 1108 1089 goto out; 1109 1090 } ··· 1172 1155 struct rdt_resource *r; 1173 1156 struct rdt_domain *d; 1174 1157 unsigned int size; 1175 - bool sep = false; 1176 - u32 cbm; 1158 + bool sep; 1159 + u32 ctrl; 1177 1160 1178 1161 rdtgrp = rdtgroup_kn_lock_live(of->kn); 1179 1162 if (!rdtgrp) { ··· 1191 1174 } 1192 1175 1193 1176 for_each_alloc_enabled_rdt_resource(r) { 1177 + sep = false; 1194 1178 seq_printf(s, "%*s:", max_name_width, r->name); 1195 1179 list_for_each_entry(d, &r->domains, list) { 1196 1180 if (sep) ··· 1199 1181 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) { 1200 1182 size = 0; 1201 1183 } else { 1202 - cbm = d->ctrl_val[rdtgrp->closid]; 1203 - size = rdtgroup_cbm_to_size(r, d, cbm); 1184 + ctrl = (!is_mba_sc(r) ? 1185 + d->ctrl_val[rdtgrp->closid] : 1186 + d->mbps_val[rdtgrp->closid]); 1187 + if (r->rid == RDT_RESOURCE_MBA) 1188 + size = ctrl; 1189 + else 1190 + size = rdtgroup_cbm_to_size(r, d, ctrl); 1204 1191 } 1205 1192 seq_printf(s, "%d=%u", d->id, size); 1206 1193 sep = true; ··· 2359 2336 u32 *ctrl; 2360 2337 2361 2338 for_each_alloc_enabled_rdt_resource(r) { 2339 + /* 2340 + * Only initialize default allocations for CBM cache 2341 + * resources 2342 + */ 2343 + if (r->rid == RDT_RESOURCE_MBA) 2344 + continue; 2362 2345 list_for_each_entry(d, &r->domains, list) { 2363 2346 d->have_new_ctrl = false; 2364 2347 d->new_ctrl = r->cache.shareable_bits; 2365 2348 used_b = r->cache.shareable_bits; 2366 2349 ctrl = d->ctrl_val; 2367 - for (i = 0; i < r->num_closid; i++, ctrl++) { 2350 + for (i = 0; i < closids_supported(); i++, ctrl++) { 2368 2351 if (closid_allocated(i) && i != closid) { 2369 2352 mode = rdtgroup_mode_by_closid(i); 2370 2353 if (mode == RDT_MODE_PSEUDO_LOCKSETUP) ··· 2402 2373 } 2403 2374 2404 2375 for_each_alloc_enabled_rdt_resource(r) { 2376 + /* 2377 + * Only initialize default allocations for CBM cache 2378 + * resources 2379 + */ 2380 + if (r->rid == RDT_RESOURCE_MBA) 2381 + continue; 2405 2382 ret = update_domains(r, rdtgrp->closid); 2406 2383 if (ret < 0) { 2407 2384 rdt_last_cmd_puts("failed to initialize allocations\n");
+19 -1
arch/x86/kernel/head64.c
··· 35 35 #include <asm/bootparam_utils.h> 36 36 #include <asm/microcode.h> 37 37 #include <asm/kasan.h> 38 + #include <asm/fixmap.h> 38 39 39 40 /* 40 41 * Manage page tables very early on. ··· 113 112 unsigned long __head __startup_64(unsigned long physaddr, 114 113 struct boot_params *bp) 115 114 { 115 + unsigned long vaddr, vaddr_end; 116 116 unsigned long load_delta, *p; 117 117 unsigned long pgtable_flags; 118 118 pgdval_t *pgd; ··· 167 165 pud[511] += load_delta; 168 166 169 167 pmd = fixup_pointer(level2_fixmap_pgt, physaddr); 170 - pmd[506] += load_delta; 168 + for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--) 169 + pmd[i] += load_delta; 171 170 172 171 /* 173 172 * Set up the identity mapping for the switchover. These ··· 236 233 237 234 /* Encrypt the kernel and related (if SME is active) */ 238 235 sme_encrypt_kernel(bp); 236 + 237 + /* 238 + * Clear the memory encryption mask from the .bss..decrypted section. 239 + * The bss section will be memset to zero later in the initialization so 240 + * there is no need to zero it after changing the memory encryption 241 + * attribute. 242 + */ 243 + if (mem_encrypt_active()) { 244 + vaddr = (unsigned long)__start_bss_decrypted; 245 + vaddr_end = (unsigned long)__end_bss_decrypted; 246 + for (; vaddr < vaddr_end; vaddr += PMD_SIZE) { 247 + i = pmd_index(vaddr); 248 + pmd[i] -= sme_get_me_mask(); 249 + } 250 + } 239 251 240 252 /* 241 253 * Return the SME encryption mask (if SME is active) to be used as a
+12 -4
arch/x86/kernel/head_64.S
··· 24 24 #include "../entry/calling.h" 25 25 #include <asm/export.h> 26 26 #include <asm/nospec-branch.h> 27 + #include <asm/fixmap.h> 27 28 28 29 #ifdef CONFIG_PARAVIRT 29 30 #include <asm/asm-offsets.h> ··· 446 445 KERNEL_IMAGE_SIZE/PMD_SIZE) 447 446 448 447 NEXT_PAGE(level2_fixmap_pgt) 449 - .fill 506,8,0 450 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC 451 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */ 452 - .fill 5,8,0 448 + .fill (512 - 4 - FIXMAP_PMD_NUM),8,0 449 + pgtno = 0 450 + .rept (FIXMAP_PMD_NUM) 451 + .quad level1_fixmap_pgt + (pgtno << PAGE_SHIFT) - __START_KERNEL_map \ 452 + + _PAGE_TABLE_NOENC; 453 + pgtno = pgtno + 1 454 + .endr 455 + /* 6 MB reserved space + a 2MB hole */ 456 + .fill 4,8,0 453 457 454 458 NEXT_PAGE(level1_fixmap_pgt) 459 + .rept (FIXMAP_PMD_NUM) 455 460 .fill 512,8,0 461 + .endr 456 462 457 463 #undef PMDS 458 464
+49 -3
arch/x86/kernel/kvmclock.c
··· 28 28 #include <linux/sched/clock.h> 29 29 #include <linux/mm.h> 30 30 #include <linux/slab.h> 31 + #include <linux/set_memory.h> 31 32 32 33 #include <asm/hypervisor.h> 33 34 #include <asm/mem_encrypt.h> ··· 62 61 (PAGE_SIZE / sizeof(struct pvclock_vsyscall_time_info)) 63 62 64 63 static struct pvclock_vsyscall_time_info 65 - hv_clock_boot[HVC_BOOT_ARRAY_SIZE] __aligned(PAGE_SIZE); 66 - static struct pvclock_wall_clock wall_clock; 64 + hv_clock_boot[HVC_BOOT_ARRAY_SIZE] __bss_decrypted __aligned(PAGE_SIZE); 65 + static struct pvclock_wall_clock wall_clock __bss_decrypted; 67 66 static DEFINE_PER_CPU(struct pvclock_vsyscall_time_info *, hv_clock_per_cpu); 67 + static struct pvclock_vsyscall_time_info *hvclock_mem; 68 68 69 69 static inline struct pvclock_vcpu_time_info *this_cpu_pvti(void) 70 70 { ··· 238 236 native_machine_shutdown(); 239 237 } 240 238 239 + static void __init kvmclock_init_mem(void) 240 + { 241 + unsigned long ncpus; 242 + unsigned int order; 243 + struct page *p; 244 + int r; 245 + 246 + if (HVC_BOOT_ARRAY_SIZE >= num_possible_cpus()) 247 + return; 248 + 249 + ncpus = num_possible_cpus() - HVC_BOOT_ARRAY_SIZE; 250 + order = get_order(ncpus * sizeof(*hvclock_mem)); 251 + 252 + p = alloc_pages(GFP_KERNEL, order); 253 + if (!p) { 254 + pr_warn("%s: failed to alloc %d pages", __func__, (1U << order)); 255 + return; 256 + } 257 + 258 + hvclock_mem = page_address(p); 259 + 260 + /* 261 + * hvclock is shared between the guest and the hypervisor, must 262 + * be mapped decrypted. 263 + */ 264 + if (sev_active()) { 265 + r = set_memory_decrypted((unsigned long) hvclock_mem, 266 + 1UL << order); 267 + if (r) { 268 + __free_pages(p, order); 269 + hvclock_mem = NULL; 270 + pr_warn("kvmclock: set_memory_decrypted() failed. Disabling\n"); 271 + return; 272 + } 273 + } 274 + 275 + memset(hvclock_mem, 0, PAGE_SIZE << order); 276 + } 277 + 241 278 static int __init kvm_setup_vsyscall_timeinfo(void) 242 279 { 243 280 #ifdef CONFIG_X86_64 ··· 291 250 292 251 kvm_clock.archdata.vclock_mode = VCLOCK_PVCLOCK; 293 252 #endif 253 + 254 + kvmclock_init_mem(); 255 + 294 256 return 0; 295 257 } 296 258 early_initcall(kvm_setup_vsyscall_timeinfo); ··· 313 269 /* Use the static page for the first CPUs, allocate otherwise */ 314 270 if (cpu < HVC_BOOT_ARRAY_SIZE) 315 271 p = &hv_clock_boot[cpu]; 272 + else if (hvclock_mem) 273 + p = hvclock_mem + cpu - HVC_BOOT_ARRAY_SIZE; 316 274 else 317 - p = kzalloc(sizeof(*p), GFP_KERNEL); 275 + return -ENOMEM; 318 276 319 277 per_cpu(hv_clock_per_cpu, cpu) = p; 320 278 return p ? 0 : -ENOMEM;
+2 -2
arch/x86/kernel/paravirt.c
··· 91 91 92 92 if (len < 5) { 93 93 #ifdef CONFIG_RETPOLINE 94 - WARN_ONCE("Failing to patch indirect CALL in %ps\n", (void *)addr); 94 + WARN_ONCE(1, "Failing to patch indirect CALL in %ps\n", (void *)addr); 95 95 #endif 96 96 return len; /* call too long for patch site */ 97 97 } ··· 111 111 112 112 if (len < 5) { 113 113 #ifdef CONFIG_RETPOLINE 114 - WARN_ONCE("Failing to patch indirect JMP in %ps\n", (void *)addr); 114 + WARN_ONCE(1, "Failing to patch indirect JMP in %ps\n", (void *)addr); 115 115 #endif 116 116 return len; /* call too long for patch site */ 117 117 }
+19
arch/x86/kernel/vmlinux.lds.S
··· 65 65 #define ALIGN_ENTRY_TEXT_BEGIN . = ALIGN(PMD_SIZE); 66 66 #define ALIGN_ENTRY_TEXT_END . = ALIGN(PMD_SIZE); 67 67 68 + /* 69 + * This section contains data which will be mapped as decrypted. Memory 70 + * encryption operates on a page basis. Make this section PMD-aligned 71 + * to avoid splitting the pages while mapping the section early. 72 + * 73 + * Note: We use a separate section so that only this section gets 74 + * decrypted to avoid exposing more than we wish. 75 + */ 76 + #define BSS_DECRYPTED \ 77 + . = ALIGN(PMD_SIZE); \ 78 + __start_bss_decrypted = .; \ 79 + *(.bss..decrypted); \ 80 + . = ALIGN(PAGE_SIZE); \ 81 + __start_bss_decrypted_unused = .; \ 82 + . = ALIGN(PMD_SIZE); \ 83 + __end_bss_decrypted = .; \ 84 + 68 85 #else 69 86 70 87 #define X86_ALIGN_RODATA_BEGIN ··· 91 74 92 75 #define ALIGN_ENTRY_TEXT_BEGIN 93 76 #define ALIGN_ENTRY_TEXT_END 77 + #define BSS_DECRYPTED 94 78 95 79 #endif 96 80 ··· 373 355 __bss_start = .; 374 356 *(.bss..page_aligned) 375 357 *(.bss) 358 + BSS_DECRYPTED 376 359 . = ALIGN(PAGE_SIZE); 377 360 __bss_stop = .; 378 361 }
+4
arch/x86/mm/init.c
··· 815 815 set_memory_np_noalias(begin_ul, len_pages); 816 816 } 817 817 818 + void __weak mem_encrypt_free_decrypted_mem(void) { } 819 + 818 820 void __ref free_initmem(void) 819 821 { 820 822 e820__reallocate_tables(); 823 + 824 + mem_encrypt_free_decrypted_mem(); 821 825 822 826 free_kernel_image_pages(&__init_begin, &__init_end); 823 827 }
+24
arch/x86/mm/mem_encrypt.c
··· 348 348 EXPORT_SYMBOL(sev_active); 349 349 350 350 /* Architecture __weak replacement functions */ 351 + void __init mem_encrypt_free_decrypted_mem(void) 352 + { 353 + unsigned long vaddr, vaddr_end, npages; 354 + int r; 355 + 356 + vaddr = (unsigned long)__start_bss_decrypted_unused; 357 + vaddr_end = (unsigned long)__end_bss_decrypted; 358 + npages = (vaddr_end - vaddr) >> PAGE_SHIFT; 359 + 360 + /* 361 + * The unused memory range was mapped decrypted, change the encryption 362 + * attribute from decrypted to encrypted before freeing it. 363 + */ 364 + if (mem_encrypt_active()) { 365 + r = set_memory_encrypted(vaddr, npages); 366 + if (r) { 367 + pr_warn("failed to free unused decrypted pages\n"); 368 + return; 369 + } 370 + } 371 + 372 + free_init_pages("unused decrypted", vaddr, vaddr_end); 373 + } 374 + 351 375 void __init mem_encrypt_init(void) 352 376 { 353 377 if (!sme_me_mask)
+9
arch/x86/mm/pgtable.c
··· 637 637 { 638 638 unsigned long address = __fix_to_virt(idx); 639 639 640 + #ifdef CONFIG_X86_64 641 + /* 642 + * Ensure that the static initial page tables are covering the 643 + * fixmap completely. 644 + */ 645 + BUILD_BUG_ON(__end_of_permanent_fixed_addresses > 646 + (FIXMAP_PMD_NUM * PTRS_PER_PTE)); 647 + #endif 648 + 640 649 if (idx >= __end_of_fixed_addresses) { 641 650 BUG(); 642 651 return;
+6 -2
arch/x86/xen/mmu_pv.c
··· 1907 1907 /* L3_k[511] -> level2_fixmap_pgt */ 1908 1908 convert_pfn_mfn(level3_kernel_pgt); 1909 1909 1910 - /* L3_k[511][506] -> level1_fixmap_pgt */ 1910 + /* L3_k[511][508-FIXMAP_PMD_NUM ... 507] -> level1_fixmap_pgt */ 1911 1911 convert_pfn_mfn(level2_fixmap_pgt); 1912 1912 1913 1913 /* We get [511][511] and have Xen's version of level2_kernel_pgt */ ··· 1952 1952 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO); 1953 1953 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO); 1954 1954 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO); 1955 - set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO); 1955 + 1956 + for (i = 0; i < FIXMAP_PMD_NUM; i++) { 1957 + set_page_prot(level1_fixmap_pgt + i * PTRS_PER_PTE, 1958 + PAGE_KERNEL_RO); 1959 + } 1956 1960 1957 1961 /* Pin down new L4 */ 1958 1962 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,