hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/x86/kernel/tboot.c
....@@ -1,25 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * tboot.c: main implementation of helper functions used by kernel for
34 * runtime support of Intel(R) Trusted Execution Technology
45 *
56 * Copyright (c) 2006-2009, Intel Corporation
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms and conditions of the GNU General Public License,
9
- * version 2, as published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope it will be useful, but WITHOUT
12
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
- * more details.
15
- *
16
- * You should have received a copy of the GNU General Public License along with
17
- * this program; if not, write to the Free Software Foundation, Inc.,
18
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19
- *
207 */
218
22
-#include <linux/dma_remapping.h>
9
+#include <linux/intel-iommu.h>
2310 #include <linux/init_task.h>
2411 #include <linux/spinlock.h>
2512 #include <linux/export.h>
....@@ -36,7 +23,6 @@
3623 #include <asm/realmode.h>
3724 #include <asm/processor.h>
3825 #include <asm/bootparam.h>
39
-#include <asm/pgtable.h>
4026 #include <asm/pgalloc.h>
4127 #include <asm/swiotlb.h>
4228 #include <asm/fixmap.h>
....@@ -48,8 +34,7 @@
4834 #include "../realmode/rm/wakeup.h"
4935
5036 /* Global pointer to shared data; NULL means no measured launch. */
51
-struct tboot *tboot __read_mostly;
52
-EXPORT_SYMBOL(tboot);
37
+static struct tboot *tboot __read_mostly;
5338
5439 /* timeout for APs (in secs) to enter wait-for-SIPI state during shutdown */
5540 #define AP_WAIT_TIMEOUT 1
....@@ -58,6 +43,11 @@
5843 #define pr_fmt(fmt) "tboot: " fmt
5944
6045 static u8 tboot_uuid[16] __initdata = TBOOT_UUID;
46
+
47
+bool tboot_enabled(void)
48
+{
49
+ return tboot != NULL;
50
+}
6151
6252 void __init tboot_probe(void)
6353 {
....@@ -70,7 +60,7 @@
7060 */
7161 if (!e820__mapped_any(boot_params.tboot_addr,
7262 boot_params.tboot_addr, E820_TYPE_RESERVED)) {
73
- pr_warning("non-0 tboot_addr but it is not of type E820_TYPE_RESERVED\n");
63
+ pr_warn("non-0 tboot_addr but it is not of type E820_TYPE_RESERVED\n");
7464 return;
7565 }
7666
....@@ -78,13 +68,12 @@
7868 set_fixmap(FIX_TBOOT_BASE, boot_params.tboot_addr);
7969 tboot = (struct tboot *)fix_to_virt(FIX_TBOOT_BASE);
8070 if (memcmp(&tboot_uuid, &tboot->uuid, sizeof(tboot->uuid))) {
81
- pr_warning("tboot at 0x%llx is invalid\n",
82
- boot_params.tboot_addr);
71
+ pr_warn("tboot at 0x%llx is invalid\n", boot_params.tboot_addr);
8372 tboot = NULL;
8473 return;
8574 }
8675 if (tboot->version < 5) {
87
- pr_warning("tboot version is invalid: %u\n", tboot->version);
76
+ pr_warn("tboot version is invalid: %u\n", tboot->version);
8877 tboot = NULL;
8978 return;
9079 }
....@@ -104,7 +93,8 @@
10493 .pgd = swapper_pg_dir,
10594 .mm_users = ATOMIC_INIT(2),
10695 .mm_count = ATOMIC_INIT(1),
107
- .mmap_sem = __RWSEM_INITIALIZER(init_mm.mmap_sem),
96
+ .write_protect_seq = SEQCNT_ZERO(tboot_mm.write_protect_seq),
97
+ MMAP_LOCK_INITIALIZER(init_mm)
10898 .page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock),
10999 .mmlist = LIST_HEAD_INIT(init_mm.mmlist),
110100 };
....@@ -302,7 +292,7 @@
302292
303293 if (sleep_state >= ACPI_S_STATE_COUNT ||
304294 acpi_shutdown_map[sleep_state] == -1) {
305
- pr_warning("unsupported sleep state 0x%x\n", sleep_state);
295
+ pr_warn("unsupported sleep state 0x%x\n", sleep_state);
306296 return -1;
307297 }
308298
....@@ -315,7 +305,7 @@
315305 if (!tboot_enabled())
316306 return 0;
317307
318
- pr_warning("tboot is not able to suspend on platforms with reduced hardware sleep (ACPIv5)");
308
+ pr_warn("tboot is not able to suspend on platforms with reduced hardware sleep (ACPIv5)");
319309 return -ENODEV;
320310 }
321311
....@@ -333,7 +323,7 @@
333323 }
334324
335325 if (timeout)
336
- pr_warning("tboot wait for APs timeout\n");
326
+ pr_warn("tboot wait for APs timeout\n");
337327
338328 return !(atomic_read((atomic_t *)&tboot->num_in_wfs) == num_aps);
339329 }
....@@ -368,7 +358,7 @@
368358 void *kbuf;
369359 int ret = -EFAULT;
370360
371
- log_base = ioremap_nocache(TBOOT_SERIAL_LOG_ADDR, TBOOT_SERIAL_LOG_SIZE);
361
+ log_base = ioremap(TBOOT_SERIAL_LOG_ADDR, TBOOT_SERIAL_LOG_SIZE);
372362 if (!log_base)
373363 return ret;
374364
....@@ -525,16 +515,10 @@
525515 if (!tboot_enabled())
526516 return 0;
527517
528
- if (intel_iommu_tboot_noforce)
529
- return 1;
530
-
531
- if (no_iommu || swiotlb || dmar_disabled)
532
- pr_warning("Forcing Intel-IOMMU to enabled\n");
518
+ if (no_iommu || dmar_disabled)
519
+ pr_warn("Forcing Intel-IOMMU to enabled\n");
533520
534521 dmar_disabled = 0;
535
-#ifdef CONFIG_SWIOTLB
536
- swiotlb = 0;
537
-#endif
538522 no_iommu = 0;
539523
540524 return 1;