Commit cb03dc094ad4bfb8223d02b28e2374c51e4c31fb

Authored by Linus Torvalds

Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fixes from Peter Anvin:
 "Another set of fixes, the biggest bit of this is yet another tweak to
  the UEFI anti-bricking code; apparently we finally got some feedback
  from Samsung as to what makes at least their systems fail.  This set
  should actually fix the boot regressions that some other systems (e.g.
  SGI) have exhibited.

  Other than that, there is a patch to avoid a panic with particularly
  unhappy memory layouts and two minor protocol fixes which may or may
  not be manifest bugs"

* 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86: Fix typo in kexec register clearing
  x86, relocs: Move __vvar_page from S_ABS to S_REL
  Modify UEFI anti-bricking code
  x86: Fix adjust_range_size_mask calling position

Showing 7 changed files Side-by-side Diff

arch/x86/boot/compressed/eboot.c
... ... @@ -251,51 +251,6 @@
251 251 *size = len;
252 252 }
253 253  
254   -static efi_status_t setup_efi_vars(struct boot_params *params)
255   -{
256   - struct setup_data *data;
257   - struct efi_var_bootdata *efidata;
258   - u64 store_size, remaining_size, var_size;
259   - efi_status_t status;
260   -
261   - if (sys_table->runtime->hdr.revision < EFI_2_00_SYSTEM_TABLE_REVISION)
262   - return EFI_UNSUPPORTED;
263   -
264   - data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
265   -
266   - while (data && data->next)
267   - data = (struct setup_data *)(unsigned long)data->next;
268   -
269   - status = efi_call_phys4((void *)sys_table->runtime->query_variable_info,
270   - EFI_VARIABLE_NON_VOLATILE |
271   - EFI_VARIABLE_BOOTSERVICE_ACCESS |
272   - EFI_VARIABLE_RUNTIME_ACCESS, &store_size,
273   - &remaining_size, &var_size);
274   -
275   - if (status != EFI_SUCCESS)
276   - return status;
277   -
278   - status = efi_call_phys3(sys_table->boottime->allocate_pool,
279   - EFI_LOADER_DATA, sizeof(*efidata), &efidata);
280   -
281   - if (status != EFI_SUCCESS)
282   - return status;
283   -
284   - efidata->data.type = SETUP_EFI_VARS;
285   - efidata->data.len = sizeof(struct efi_var_bootdata) -
286   - sizeof(struct setup_data);
287   - efidata->data.next = 0;
288   - efidata->store_size = store_size;
289   - efidata->remaining_size = remaining_size;
290   - efidata->max_var_size = var_size;
291   -
292   - if (data)
293   - data->next = (unsigned long)efidata;
294   - else
295   - params->hdr.setup_data = (unsigned long)efidata;
296   -
297   -}
298   -
299 254 static efi_status_t setup_efi_pci(struct boot_params *params)
300 255 {
301 256 efi_pci_io_protocol *pci;
... ... @@ -1201,8 +1156,6 @@
1201 1156 goto fail;
1202 1157  
1203 1158 setup_graphics(boot_params);
1204   -
1205   - setup_efi_vars(boot_params);
1206 1159  
1207 1160 setup_efi_pci(boot_params);
1208 1161  
arch/x86/include/asm/efi.h
... ... @@ -102,13 +102,6 @@
102 102 extern void efi_unmap_memmap(void);
103 103 extern void efi_memory_uc(u64 addr, unsigned long size);
104 104  
105   -struct efi_var_bootdata {
106   - struct setup_data data;
107   - u64 store_size;
108   - u64 remaining_size;
109   - u64 max_var_size;
110   -};
111   -
112 105 #ifdef CONFIG_EFI
113 106  
114 107 static inline bool efi_is_native(void)
arch/x86/include/uapi/asm/bootparam.h
... ... @@ -6,7 +6,6 @@
6 6 #define SETUP_E820_EXT 1
7 7 #define SETUP_DTB 2
8 8 #define SETUP_PCI 3
9   -#define SETUP_EFI_VARS 4
10 9  
11 10 /* ram_size flags */
12 11 #define RAMDISK_IMAGE_START_MASK 0x07FF
arch/x86/kernel/relocate_kernel_64.S
... ... @@ -160,7 +160,7 @@
160 160 xorq %rbp, %rbp
161 161 xorq %r8, %r8
162 162 xorq %r9, %r9
163   - xorq %r10, %r9
  163 + xorq %r10, %r10
164 164 xorq %r11, %r11
165 165 xorq %r12, %r12
166 166 xorq %r13, %r13
... ... @@ -277,6 +277,9 @@
277 277 end_pfn = limit_pfn;
278 278 nr_range = save_mr(mr, nr_range, start_pfn, end_pfn, 0);
279 279  
  280 + if (!after_bootmem)
  281 + adjust_range_page_size_mask(mr, nr_range);
  282 +
280 283 /* try to merge same page size and continuous */
281 284 for (i = 0; nr_range > 1 && i < nr_range - 1; i++) {
282 285 unsigned long old_start;
... ... @@ -290,9 +293,6 @@
290 293 mr[i--].start = old_start;
291 294 nr_range--;
292 295 }
293   -
294   - if (!after_bootmem)
295   - adjust_range_page_size_mask(mr, nr_range);
296 296  
297 297 for (i = 0; i < nr_range; i++)
298 298 printk(KERN_DEBUG " [mem %#010lx-%#010lx] page %s\n",
arch/x86/platform/efi/efi.c
... ... @@ -42,7 +42,6 @@
42 42 #include <linux/io.h>
43 43 #include <linux/reboot.h>
44 44 #include <linux/bcd.h>
45   -#include <linux/ucs2_string.h>
46 45  
47 46 #include <asm/setup.h>
48 47 #include <asm/efi.h>
49 48  
... ... @@ -54,13 +53,13 @@
54 53  
55 54 #define EFI_DEBUG 1
56 55  
57   -/*
58   - * There's some additional metadata associated with each
59   - * variable. Intel's reference implementation is 60 bytes - bump that
60   - * to account for potential alignment constraints
61   - */
62   -#define VAR_METADATA_SIZE 64
  56 +#define EFI_MIN_RESERVE 5120
63 57  
  58 +#define EFI_DUMMY_GUID \
  59 + EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9)
  60 +
  61 +static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 };
  62 +
64 63 struct efi __read_mostly efi = {
65 64 .mps = EFI_INVALID_TABLE_ADDR,
66 65 .acpi = EFI_INVALID_TABLE_ADDR,
... ... @@ -79,13 +78,6 @@
79 78 static struct efi efi_phys __initdata;
80 79 static efi_system_table_t efi_systab __initdata;
81 80  
82   -static u64 efi_var_store_size;
83   -static u64 efi_var_remaining_size;
84   -static u64 efi_var_max_var_size;
85   -static u64 boot_used_size;
86   -static u64 boot_var_size;
87   -static u64 active_size;
88   -
89 81 unsigned long x86_efi_facility;
90 82  
91 83 /*
... ... @@ -188,53 +180,8 @@
188 180 efi_char16_t *name,
189 181 efi_guid_t *vendor)
190 182 {
191   - efi_status_t status;
192   - static bool finished = false;
193   - static u64 var_size;
194   -
195   - status = efi_call_virt3(get_next_variable,
196   - name_size, name, vendor);
197   -
198   - if (status == EFI_NOT_FOUND) {
199   - finished = true;
200   - if (var_size < boot_used_size) {
201   - boot_var_size = boot_used_size - var_size;
202   - active_size += boot_var_size;
203   - } else {
204   - printk(KERN_WARNING FW_BUG "efi: Inconsistent initial sizes\n");
205   - }
206   - }
207   -
208   - if (boot_used_size && !finished) {
209   - unsigned long size = 0;
210   - u32 attr;
211   - efi_status_t s;
212   - void *tmp;
213   -
214   - s = virt_efi_get_variable(name, vendor, &attr, &size, NULL);
215   -
216   - if (s != EFI_BUFFER_TOO_SMALL || !size)
217   - return status;
218   -
219   - tmp = kmalloc(size, GFP_ATOMIC);
220   -
221   - if (!tmp)
222   - return status;
223   -
224   - s = virt_efi_get_variable(name, vendor, &attr, &size, tmp);
225   -
226   - if (s == EFI_SUCCESS && (attr & EFI_VARIABLE_NON_VOLATILE)) {
227   - var_size += size;
228   - var_size += ucs2_strsize(name, 1024);
229   - active_size += size;
230   - active_size += VAR_METADATA_SIZE;
231   - active_size += ucs2_strsize(name, 1024);
232   - }
233   -
234   - kfree(tmp);
235   - }
236   -
237   - return status;
  183 + return efi_call_virt3(get_next_variable,
  184 + name_size, name, vendor);
238 185 }
239 186  
240 187 static efi_status_t virt_efi_set_variable(efi_char16_t *name,
... ... @@ -243,34 +190,9 @@
243 190 unsigned long data_size,
244 191 void *data)
245 192 {
246   - efi_status_t status;
247   - u32 orig_attr = 0;
248   - unsigned long orig_size = 0;
249   -
250   - status = virt_efi_get_variable(name, vendor, &orig_attr, &orig_size,
251   - NULL);
252   -
253   - if (status != EFI_BUFFER_TOO_SMALL)
254   - orig_size = 0;
255   -
256   - status = efi_call_virt5(set_variable,
257   - name, vendor, attr,
258   - data_size, data);
259   -
260   - if (status == EFI_SUCCESS) {
261   - if (orig_size) {
262   - active_size -= orig_size;
263   - active_size -= ucs2_strsize(name, 1024);
264   - active_size -= VAR_METADATA_SIZE;
265   - }
266   - if (data_size) {
267   - active_size += data_size;
268   - active_size += ucs2_strsize(name, 1024);
269   - active_size += VAR_METADATA_SIZE;
270   - }
271   - }
272   -
273   - return status;
  193 + return efi_call_virt5(set_variable,
  194 + name, vendor, attr,
  195 + data_size, data);
274 196 }
275 197  
276 198 static efi_status_t virt_efi_query_variable_info(u32 attr,
... ... @@ -786,9 +708,6 @@
786 708 char vendor[100] = "unknown";
787 709 int i = 0;
788 710 void *tmp;
789   - struct setup_data *data;
790   - struct efi_var_bootdata *efi_var_data;
791   - u64 pa_data;
792 711  
793 712 #ifdef CONFIG_X86_32
794 713 if (boot_params.efi_info.efi_systab_hi ||
... ... @@ -806,22 +725,6 @@
806 725 if (efi_systab_init(efi_phys.systab))
807 726 return;
808 727  
809   - pa_data = boot_params.hdr.setup_data;
810   - while (pa_data) {
811   - data = early_ioremap(pa_data, sizeof(*efi_var_data));
812   - if (data->type == SETUP_EFI_VARS) {
813   - efi_var_data = (struct efi_var_bootdata *)data;
814   -
815   - efi_var_store_size = efi_var_data->store_size;
816   - efi_var_remaining_size = efi_var_data->remaining_size;
817   - efi_var_max_var_size = efi_var_data->max_var_size;
818   - }
819   - pa_data = data->next;
820   - early_iounmap(data, sizeof(*efi_var_data));
821   - }
822   -
823   - boot_used_size = efi_var_store_size - efi_var_remaining_size;
824   -
825 728 set_bit(EFI_SYSTEM_TABLES, &x86_efi_facility);
826 729  
827 730 /*
... ... @@ -1085,6 +988,13 @@
1085 988 runtime_code_page_mkexec();
1086 989  
1087 990 kfree(new_memmap);
  991 +
  992 + /* clean DUMMY object */
  993 + efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID,
  994 + EFI_VARIABLE_NON_VOLATILE |
  995 + EFI_VARIABLE_BOOTSERVICE_ACCESS |
  996 + EFI_VARIABLE_RUNTIME_ACCESS,
  997 + 0, NULL);
1088 998 }
1089 999  
1090 1000 /*
1091 1001  
1092 1002  
1093 1003  
1094 1004  
1095 1005  
... ... @@ -1136,33 +1046,65 @@
1136 1046 efi_status_t status;
1137 1047 u64 storage_size, remaining_size, max_size;
1138 1048  
  1049 + if (!(attributes & EFI_VARIABLE_NON_VOLATILE))
  1050 + return 0;
  1051 +
1139 1052 status = efi.query_variable_info(attributes, &storage_size,
1140 1053 &remaining_size, &max_size);
1141 1054 if (status != EFI_SUCCESS)
1142 1055 return status;
1143 1056  
1144   - if (!max_size && remaining_size > size)
1145   - printk_once(KERN_ERR FW_BUG "Broken EFI implementation"
1146   - " is returning MaxVariableSize=0\n");
1147 1057 /*
1148 1058 * Some firmware implementations refuse to boot if there's insufficient
1149 1059 * space in the variable store. We account for that by refusing the
1150 1060 * write if permitting it would reduce the available space to under
1151   - * 50%. However, some firmware won't reclaim variable space until
1152   - * after the used (not merely the actively used) space drops below
1153   - * a threshold. We can approximate that case with the value calculated
1154   - * above. If both the firmware and our calculations indicate that the
1155   - * available space would drop below 50%, refuse the write.
  1061 + * 5KB. This figure was provided by Samsung, so should be safe.
1156 1062 */
  1063 + if ((remaining_size - size < EFI_MIN_RESERVE) &&
  1064 + !efi_no_storage_paranoia) {
1157 1065  
1158   - if (!storage_size || size > remaining_size ||
1159   - (max_size && size > max_size))
1160   - return EFI_OUT_OF_RESOURCES;
  1066 + /*
  1067 + * Triggering garbage collection may require that the firmware
  1068 + * generate a real EFI_OUT_OF_RESOURCES error. We can force
  1069 + * that by attempting to use more space than is available.
  1070 + */
  1071 + unsigned long dummy_size = remaining_size + 1024;
  1072 + void *dummy = kmalloc(dummy_size, GFP_ATOMIC);
1161 1073  
1162   - if (!efi_no_storage_paranoia &&
1163   - ((active_size + size + VAR_METADATA_SIZE > storage_size / 2) &&
1164   - (remaining_size - size < storage_size / 2)))
1165   - return EFI_OUT_OF_RESOURCES;
  1074 + status = efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID,
  1075 + EFI_VARIABLE_NON_VOLATILE |
  1076 + EFI_VARIABLE_BOOTSERVICE_ACCESS |
  1077 + EFI_VARIABLE_RUNTIME_ACCESS,
  1078 + dummy_size, dummy);
  1079 +
  1080 + if (status == EFI_SUCCESS) {
  1081 + /*
  1082 + * This should have failed, so if it didn't make sure
  1083 + * that we delete it...
  1084 + */
  1085 + efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID,
  1086 + EFI_VARIABLE_NON_VOLATILE |
  1087 + EFI_VARIABLE_BOOTSERVICE_ACCESS |
  1088 + EFI_VARIABLE_RUNTIME_ACCESS,
  1089 + 0, dummy);
  1090 + }
  1091 +
  1092 + /*
  1093 + * The runtime code may now have triggered a garbage collection
  1094 + * run, so check the variable info again
  1095 + */
  1096 + status = efi.query_variable_info(attributes, &storage_size,
  1097 + &remaining_size, &max_size);
  1098 +
  1099 + if (status != EFI_SUCCESS)
  1100 + return status;
  1101 +
  1102 + /*
  1103 + * There still isn't enough room, so return an error
  1104 + */
  1105 + if (remaining_size - size < EFI_MIN_RESERVE)
  1106 + return EFI_OUT_OF_RESOURCES;
  1107 + }
1166 1108  
1167 1109 return EFI_SUCCESS;
1168 1110 }
arch/x86/tools/relocs.c
... ... @@ -42,9 +42,6 @@
42 42 "^(xen_irq_disable_direct_reloc$|"
43 43 "xen_save_fl_direct_reloc$|"
44 44 "VDSO|"
45   -#if ELF_BITS == 64
46   - "__vvar_page|"
47   -#endif
48 45 "__crc_)",
49 46  
50 47 /*
... ... @@ -72,6 +69,7 @@
72 69 "__per_cpu_load|"
73 70 "init_per_cpu__.*|"
74 71 "__end_rodata_hpage_align|"
  72 + "__vvar_page|"
75 73 #endif
76 74 "_end)$"
77 75 };