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 tag 'x86-urgent-2021-11-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fixes from Thomas Gleixner:

- Move the command line preparation and the early command line parsing
earlier so that the command line parameters which affect
early_reserve_memory(), e.g. efi=nosftreserve, are taken into
account. This was broken when the invocation of
early_reserve_memory() was moved recently.

- Use an atomic type for the SGX page accounting, which is read and
written locklessly, to plug various race conditions related to it.

* tag 'x86-urgent-2021-11-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86/sgx: Fix free page accounting
x86/boot: Pull up cmdline preparation and early param parsing

+45 -33
+6 -6
arch/x86/kernel/cpu/sgx/main.c
··· 28 28 static LIST_HEAD(sgx_active_page_list); 29 29 static DEFINE_SPINLOCK(sgx_reclaimer_lock); 30 30 31 - /* The free page list lock protected variables prepend the lock. */ 32 - static unsigned long sgx_nr_free_pages; 31 + static atomic_long_t sgx_nr_free_pages = ATOMIC_LONG_INIT(0); 33 32 34 33 /* Nodes with one or more EPC sections. */ 35 34 static nodemask_t sgx_numa_mask; ··· 402 403 403 404 spin_lock(&node->lock); 404 405 list_add_tail(&epc_page->list, &node->free_page_list); 405 - sgx_nr_free_pages++; 406 406 spin_unlock(&node->lock); 407 + atomic_long_inc(&sgx_nr_free_pages); 407 408 } 408 409 } 409 410 410 411 static bool sgx_should_reclaim(unsigned long watermark) 411 412 { 412 - return sgx_nr_free_pages < watermark && !list_empty(&sgx_active_page_list); 413 + return atomic_long_read(&sgx_nr_free_pages) < watermark && 414 + !list_empty(&sgx_active_page_list); 413 415 } 414 416 415 417 static int ksgxd(void *p) ··· 471 471 472 472 page = list_first_entry(&node->free_page_list, struct sgx_epc_page, list); 473 473 list_del_init(&page->list); 474 - sgx_nr_free_pages--; 475 474 476 475 spin_unlock(&node->lock); 476 + atomic_long_dec(&sgx_nr_free_pages); 477 477 478 478 return page; 479 479 } ··· 625 625 spin_lock(&node->lock); 626 626 627 627 list_add_tail(&page->list, &node->free_page_list); 628 - sgx_nr_free_pages++; 629 628 630 629 spin_unlock(&node->lock); 630 + atomic_long_inc(&sgx_nr_free_pages); 631 631 } 632 632 633 633 static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size,
+39 -27
arch/x86/kernel/setup.c
··· 742 742 return 0; 743 743 } 744 744 745 + static char *prepare_command_line(void) 746 + { 747 + #ifdef CONFIG_CMDLINE_BOOL 748 + #ifdef CONFIG_CMDLINE_OVERRIDE 749 + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 750 + #else 751 + if (builtin_cmdline[0]) { 752 + /* append boot loader cmdline to builtin */ 753 + strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 754 + strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 755 + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 756 + } 757 + #endif 758 + #endif 759 + 760 + strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 761 + 762 + parse_early_param(); 763 + 764 + return command_line; 765 + } 766 + 745 767 /* 746 768 * Determine if we were loaded by an EFI loader. If so, then we have also been 747 769 * passed the efi memmap, systab, etc., so we should use these data structures ··· 853 831 x86_init.oem.arch_setup(); 854 832 855 833 /* 834 + * x86_configure_nx() is called before parse_early_param() (called by 835 + * prepare_command_line()) to detect whether hardware doesn't support 836 + * NX (so that the early EHCI debug console setup can safely call 837 + * set_fixmap()). It may then be called again from within noexec_setup() 838 + * during parsing early parameters to honor the respective command line 839 + * option. 840 + */ 841 + x86_configure_nx(); 842 + 843 + /* 844 + * This parses early params and it needs to run before 845 + * early_reserve_memory() because latter relies on such settings 846 + * supplied as early params. 847 + */ 848 + *cmdline_p = prepare_command_line(); 849 + 850 + /* 856 851 * Do some memory reservations *before* memory is added to memblock, so 857 852 * memblock allocations won't overwrite it. 858 853 * ··· 901 862 data_resource.end = __pa_symbol(_edata)-1; 902 863 bss_resource.start = __pa_symbol(__bss_start); 903 864 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 865 932 866 #ifdef CONFIG_MEMORY_HOTPLUG 933 867 /*