Merge tag 'x86_urgent_for_v5.16_rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fixes from Borislav Petkov:

- Prevent potential undefined behavior due to shifting pkey constants
into the sign bit

- Move the EFI memory reservation code *after* the efi= cmdline parsing
has happened

- Revert two commits which turned out to be the wrong direction to
chase when accommodating early memblock reservations consolidation
and command line parameters parsing

* tag 'x86_urgent_for_v5.16_rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86/pkey: Fix undefined behaviour with PKRU_WD_BIT
x86/boot: Move EFI range reservation after cmdline parsing
Revert "x86/boot: Pull up cmdline preparation and early param parsing"
Revert "x86/boot: Mark prepare_command_line() __init"

Changed files
+32 -44
arch
x86
include
asm
kernel
+2 -2
arch/x86/include/asm/pkru.h
··· 4 4 5 5 #include <asm/cpufeature.h> 6 6 7 - #define PKRU_AD_BIT 0x1 8 - #define PKRU_WD_BIT 0x2 7 + #define PKRU_AD_BIT 0x1u 8 + #define PKRU_WD_BIT 0x2u 9 9 #define PKRU_BITS_PER_PKEY 2 10 10 11 11 #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
+30 -42
arch/x86/kernel/setup.c
··· 713 713 714 714 early_reserve_initrd(); 715 715 716 - if (efi_enabled(EFI_BOOT)) 717 - efi_memblock_x86_reserve_range(); 718 - 719 716 memblock_x86_reserve_range_setup_data(); 720 717 721 718 reserve_ibft_region(); ··· 737 740 } 738 741 739 742 return 0; 740 - } 741 - 742 - static char * __init prepare_command_line(void) 743 - { 744 - #ifdef CONFIG_CMDLINE_BOOL 745 - #ifdef CONFIG_CMDLINE_OVERRIDE 746 - strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 747 - #else 748 - if (builtin_cmdline[0]) { 749 - /* append boot loader cmdline to builtin */ 750 - strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 751 - strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 752 - strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 753 - } 754 - #endif 755 - #endif 756 - 757 - strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 758 - 759 - parse_early_param(); 760 - 761 - return command_line; 762 743 } 763 744 764 745 /* ··· 828 853 x86_init.oem.arch_setup(); 829 854 830 855 /* 831 - * x86_configure_nx() is called before parse_early_param() (called by 832 - * prepare_command_line()) to detect whether hardware doesn't support 833 - * NX (so that the early EHCI debug console setup can safely call 834 - * set_fixmap()). It may then be called again from within noexec_setup() 835 - * during parsing early parameters to honor the respective command line 836 - * option. 837 - */ 838 - x86_configure_nx(); 839 - 840 - /* 841 - * This parses early params and it needs to run before 842 - * early_reserve_memory() because latter relies on such settings 843 - * supplied as early params. 844 - */ 845 - *cmdline_p = prepare_command_line(); 846 - 847 - /* 848 856 * Do some memory reservations *before* memory is added to memblock, so 849 857 * memblock allocations won't overwrite it. 850 858 * ··· 859 901 data_resource.end = __pa_symbol(_edata)-1; 860 902 bss_resource.start = __pa_symbol(__bss_start); 861 903 bss_resource.end = __pa_symbol(__bss_stop)-1; 904 + 905 + #ifdef CONFIG_CMDLINE_BOOL 906 + #ifdef CONFIG_CMDLINE_OVERRIDE 907 + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 908 + #else 909 + if (builtin_cmdline[0]) { 910 + /* append boot loader cmdline to builtin */ 911 + strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 912 + strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 913 + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 914 + } 915 + #endif 916 + #endif 917 + 918 + strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 919 + *cmdline_p = command_line; 920 + 921 + /* 922 + * x86_configure_nx() is called before parse_early_param() to detect 923 + * whether hardware doesn't support NX (so that the early EHCI debug 924 + * console setup can safely call set_fixmap()). It may then be called 925 + * again from within noexec_setup() during parsing early parameters 926 + * to honor the respective command line option. 927 + */ 928 + x86_configure_nx(); 929 + 930 + parse_early_param(); 931 + 932 + if (efi_enabled(EFI_BOOT)) 933 + efi_memblock_x86_reserve_range(); 862 934 863 935 #ifdef CONFIG_MEMORY_HOTPLUG 864 936 /*