Skip to content

Commit 06b31bd

Browse files
committed
Merge tag 'x86-urgent-2025-04-26' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull misc x86 fixes from Ingo Molnar: - Fix 32-bit kernel boot crash if passed physical memory with more than 32 address bits - Fix Xen PV crash - Work around build bug in certain limited build environments - Fix CTEST instruction decoding in insn_decoder_test * tag 'x86-urgent-2025-04-26' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/insn: Fix CTEST instruction decoding x86/boot: Work around broken busybox 'truncate' tool x86/mm: Fix _pgd_alloc() for Xen PV mode x86/e820: Discard high memory that can't be addressed by 32-bit systems
2 parents 3d23ef0 + 85fd85b commit 06b31bd

File tree

8 files changed

+30
-19
lines changed

8 files changed

+30
-19
lines changed

arch/x86/boot/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ KBUILD_CFLAGS += $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
5959
$(obj)/bzImage: asflags-y := $(SVGA_MODE)
6060

6161
quiet_cmd_image = BUILD $@
62-
cmd_image = cp $< $@; truncate -s %4K $@; cat $(obj)/vmlinux.bin >>$@
62+
cmd_image = (dd if=$< bs=4k conv=sync status=none; cat $(filter-out $<,$(real-prereqs))) >$@
6363

6464
$(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin FORCE
6565
$(call if_changed,image)

arch/x86/include/asm/pgalloc.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <linux/mm.h> /* for struct page */
77
#include <linux/pagemap.h>
88

9+
#include <asm/cpufeature.h>
10+
911
#define __HAVE_ARCH_PTE_ALLOC_ONE
1012
#define __HAVE_ARCH_PGD_FREE
1113
#include <asm-generic/pgalloc.h>
@@ -29,16 +31,17 @@ static inline void paravirt_release_pud(unsigned long pfn) {}
2931
static inline void paravirt_release_p4d(unsigned long pfn) {}
3032
#endif
3133

32-
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
3334
/*
34-
* Instead of one PGD, we acquire two PGDs. Being order-1, it is
35-
* both 8k in size and 8k-aligned. That lets us just flip bit 12
36-
* in a pointer to swap between the two 4k halves.
35+
* In case of Page Table Isolation active, we acquire two PGDs instead of one.
36+
* Being order-1, it is both 8k in size and 8k-aligned. That lets us just
37+
* flip bit 12 in a pointer to swap between the two 4k halves.
3738
*/
38-
#define PGD_ALLOCATION_ORDER 1
39-
#else
40-
#define PGD_ALLOCATION_ORDER 0
41-
#endif
39+
static inline unsigned int pgd_allocation_order(void)
40+
{
41+
if (cpu_feature_enabled(X86_FEATURE_PTI))
42+
return 1;
43+
return 0;
44+
}
4245

4346
/*
4447
* Allocate and free page tables.

arch/x86/kernel/e820.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,14 @@ void __init e820__memblock_setup(void)
12991299
memblock_add(entry->addr, entry->size);
13001300
}
13011301

1302+
/*
1303+
* 32-bit systems are limited to 4BG of memory even with HIGHMEM and
1304+
* to even less without it.
1305+
* Discard memory after max_pfn - the actual limit detected at runtime.
1306+
*/
1307+
if (IS_ENABLED(CONFIG_X86_32))
1308+
memblock_remove(PFN_PHYS(max_pfn), -1);
1309+
13021310
/* Throw away partial pages: */
13031311
memblock_trim_memory(PAGE_SIZE);
13041312

arch/x86/kernel/machine_kexec_32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void load_segments(void)
4242

4343
static void machine_kexec_free_page_tables(struct kimage *image)
4444
{
45-
free_pages((unsigned long)image->arch.pgd, PGD_ALLOCATION_ORDER);
45+
free_pages((unsigned long)image->arch.pgd, pgd_allocation_order());
4646
image->arch.pgd = NULL;
4747
#ifdef CONFIG_X86_PAE
4848
free_page((unsigned long)image->arch.pmd0);
@@ -59,7 +59,7 @@ static void machine_kexec_free_page_tables(struct kimage *image)
5959
static int machine_kexec_alloc_page_tables(struct kimage *image)
6060
{
6161
image->arch.pgd = (pgd_t *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
62-
PGD_ALLOCATION_ORDER);
62+
pgd_allocation_order());
6363
#ifdef CONFIG_X86_PAE
6464
image->arch.pmd0 = (pmd_t *)get_zeroed_page(GFP_KERNEL);
6565
image->arch.pmd1 = (pmd_t *)get_zeroed_page(GFP_KERNEL);

arch/x86/lib/x86-opcode-map.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,8 @@ AVXcode: 4
996996
83: Grp1 Ev,Ib (1A),(es)
997997
# CTESTSCC instructions are: CTESTB, CTESTBE, CTESTF, CTESTL, CTESTLE, CTESTNB, CTESTNBE, CTESTNL,
998998
# CTESTNLE, CTESTNO, CTESTNS, CTESTNZ, CTESTO, CTESTS, CTESTT, CTESTZ
999-
84: CTESTSCC (ev)
1000-
85: CTESTSCC (es) | CTESTSCC (66),(es)
999+
84: CTESTSCC Eb,Gb (ev)
1000+
85: CTESTSCC Ev,Gv (es) | CTESTSCC Ev,Gv (66),(es)
10011001
88: POPCNT Gv,Ev (es) | POPCNT Gv,Ev (66),(es)
10021002
8f: POP2 Bq,Rq (000),(11B),(ev)
10031003
a5: SHLD Ev,Gv,CL (es) | SHLD Ev,Gv,CL (66),(es)

arch/x86/mm/pgtable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static inline pgd_t *_pgd_alloc(struct mm_struct *mm)
360360
* We allocate one page for pgd.
361361
*/
362362
if (!SHARED_KERNEL_PMD)
363-
return __pgd_alloc(mm, PGD_ALLOCATION_ORDER);
363+
return __pgd_alloc(mm, pgd_allocation_order());
364364

365365
/*
366366
* Now PAE kernel is not running as a Xen domain. We can allocate
@@ -380,7 +380,7 @@ static inline void _pgd_free(struct mm_struct *mm, pgd_t *pgd)
380380

381381
static inline pgd_t *_pgd_alloc(struct mm_struct *mm)
382382
{
383-
return __pgd_alloc(mm, PGD_ALLOCATION_ORDER);
383+
return __pgd_alloc(mm, pgd_allocation_order());
384384
}
385385

386386
static inline void _pgd_free(struct mm_struct *mm, pgd_t *pgd)

arch/x86/platform/efi/efi_64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int __init efi_alloc_page_tables(void)
7373
gfp_t gfp_mask;
7474

7575
gfp_mask = GFP_KERNEL | __GFP_ZERO;
76-
efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER);
76+
efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, pgd_allocation_order());
7777
if (!efi_pgd)
7878
goto fail;
7979

@@ -96,7 +96,7 @@ int __init efi_alloc_page_tables(void)
9696
if (pgtable_l5_enabled())
9797
free_page((unsigned long)pgd_page_vaddr(*pgd));
9898
free_pgd:
99-
free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
99+
free_pages((unsigned long)efi_pgd, pgd_allocation_order());
100100
fail:
101101
return -ENOMEM;
102102
}

tools/arch/x86/lib/x86-opcode-map.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,8 @@ AVXcode: 4
996996
83: Grp1 Ev,Ib (1A),(es)
997997
# CTESTSCC instructions are: CTESTB, CTESTBE, CTESTF, CTESTL, CTESTLE, CTESTNB, CTESTNBE, CTESTNL,
998998
# CTESTNLE, CTESTNO, CTESTNS, CTESTNZ, CTESTO, CTESTS, CTESTT, CTESTZ
999-
84: CTESTSCC (ev)
1000-
85: CTESTSCC (es) | CTESTSCC (66),(es)
999+
84: CTESTSCC Eb,Gb (ev)
1000+
85: CTESTSCC Ev,Gv (es) | CTESTSCC Ev,Gv (66),(es)
10011001
88: POPCNT Gv,Ev (es) | POPCNT Gv,Ev (66),(es)
10021002
8f: POP2 Bq,Rq (000),(11B),(ev)
10031003
a5: SHLD Ev,Gv,CL (es) | SHLD Ev,Gv,CL (66),(es)

0 commit comments

Comments
 (0)