Skip to content

Commit 69575d3

Browse files
shane-wangH. Peter Anvin
authored andcommitted
x86, intel_txt: clean up the impact on generic code, unbreak non-x86
Move tboot.h from asm to linux to fix the build errors of intel_txt patch on non-X86 platforms. Remove the tboot code from generic code init/main.c and kernel/cpu.c. Signed-off-by: Shane Wang <shane.wang@intel.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
1 parent 62a3207 commit 69575d3

12 files changed

Lines changed: 70 additions & 74 deletions

File tree

‎arch/x86/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ config ARCH_SUPPORTS_OPTIMIZED_INLINING
178178
config ARCH_SUPPORTS_DEBUG_PAGEALLOC
179179
def_bool y
180180

181+
config HAVE_INTEL_TXT
182+
def_bool y
183+
depends on EXPERIMENTAL && DMAR && ACPI
184+
181185
# Use the generic interrupt handling code in kernel/irq/:
182186
config GENERIC_HARDIRQS
183187
bool

‎arch/x86/kernel/reboot.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/init.h>
44
#include <linux/pm.h>
55
#include <linux/efi.h>
6+
#include <linux/tboot.h>
67
#include <acpi/reboot.h>
78
#include <asm/io.h>
89
#include <asm/apic.h>
@@ -24,8 +25,6 @@
2425
# include <asm/iommu.h>
2526
#endif
2627

27-
#include <asm/tboot.h>
28-
2928
/*
3029
* Power off function, if any
3130
*/

‎arch/x86/kernel/setup.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
#include <linux/percpu.h>
6868
#include <linux/crash_dump.h>
69+
#include <linux/tboot.h>
6970

7071
#include <video/edid.h>
7172

@@ -145,8 +146,6 @@ struct boot_params __initdata boot_params;
145146
struct boot_params boot_params;
146147
#endif
147148

148-
#include <asm/tboot.h>
149-
150149
/*
151150
* Machine setup..
152151
*/

‎arch/x86/kernel/smpboot.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <linux/bootmem.h>
4848
#include <linux/err.h>
4949
#include <linux/nmi.h>
50+
#include <linux/tboot.h>
5051

5152
#include <asm/acpi.h>
5253
#include <asm/desc.h>
@@ -62,7 +63,6 @@
6263
#include <asm/vmi.h>
6364
#include <asm/apic.h>
6465
#include <asm/setup.h>
65-
#include <asm/tboot.h>
6666
#include <asm/uv/uv.h>
6767
#include <linux/mc146818rtc.h>
6868

‎arch/x86/kernel/tboot.c‎

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
#include <linux/dma_remapping.h>
2323
#include <linux/init_task.h>
2424
#include <linux/spinlock.h>
25+
#include <linux/delay.h>
2526
#include <linux/sched.h>
2627
#include <linux/init.h>
2728
#include <linux/dmar.h>
29+
#include <linux/cpu.h>
2830
#include <linux/pfn.h>
2931
#include <linux/mm.h>
32+
#include <linux/tboot.h>
3033

3134
#include <asm/trampoline.h>
3235
#include <asm/processor.h>
@@ -36,7 +39,6 @@
3639
#include <asm/fixmap.h>
3740
#include <asm/proto.h>
3841
#include <asm/setup.h>
39-
#include <asm/tboot.h>
4042
#include <asm/e820.h>
4143
#include <asm/io.h>
4244

@@ -154,13 +156,10 @@ static int map_tboot_pages(unsigned long vaddr, unsigned long start_pfn,
154156
return 0;
155157
}
156158

157-
void tboot_create_trampoline(void)
159+
static void tboot_create_trampoline(void)
158160
{
159161
u32 map_base, map_size;
160162

161-
if (!tboot_enabled())
162-
return;
163-
164163
/* Create identity map for tboot shutdown code. */
165164
map_base = PFN_DOWN(tboot->tboot_base);
166165
map_size = PFN_UP(tboot->tboot_size);
@@ -295,21 +294,58 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
295294
tboot_shutdown(acpi_shutdown_map[sleep_state]);
296295
}
297296

298-
int tboot_wait_for_aps(int num_aps)
297+
static atomic_t ap_wfs_count;
298+
299+
static int tboot_wait_for_aps(int num_aps)
299300
{
300301
unsigned long timeout;
301302

303+
timeout = AP_WAIT_TIMEOUT*HZ;
304+
while (atomic_read((atomic_t *)&tboot->num_in_wfs) != num_aps &&
305+
timeout) {
306+
mdelay(1);
307+
timeout--;
308+
}
309+
310+
if (timeout)
311+
pr_warning("tboot wait for APs timeout\n");
312+
313+
return !(atomic_read((atomic_t *)&tboot->num_in_wfs) == num_aps);
314+
}
315+
316+
static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
317+
unsigned long action, void *hcpu)
318+
{
319+
switch (action) {
320+
case CPU_DYING:
321+
atomic_inc(&ap_wfs_count);
322+
if (num_online_cpus() == 1)
323+
if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
324+
return NOTIFY_BAD;
325+
break;
326+
}
327+
return NOTIFY_OK;
328+
}
329+
330+
static struct notifier_block tboot_cpu_notifier __cpuinitdata =
331+
{
332+
.notifier_call = tboot_cpu_callback,
333+
};
334+
335+
static __init int tboot_late_init(void)
336+
{
302337
if (!tboot_enabled())
303338
return 0;
304339

305-
timeout = jiffies + AP_WAIT_TIMEOUT*HZ;
306-
while (atomic_read((atomic_t *)&tboot->num_in_wfs) != num_aps &&
307-
time_before(jiffies, timeout))
308-
cpu_relax();
340+
tboot_create_trampoline();
309341

310-
return time_before(jiffies, timeout) ? 0 : 1;
342+
atomic_set(&ap_wfs_count, 0);
343+
register_hotcpu_notifier(&tboot_cpu_notifier);
344+
return 0;
311345
}
312346

347+
late_initcall(tboot_late_init);
348+
313349
/*
314350
* TXT configuration registers (offsets from TXT_{PUB, PRIV}_CONFIG_REGS_BASE)
315351
*/

‎drivers/acpi/acpica/hwsleep.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include <acpi/acpi.h>
4646
#include "accommon.h"
4747
#include "actables.h"
48-
#include <asm/tboot.h>
48+
#include <linux/tboot.h>
4949

5050
#define _COMPONENT ACPI_HARDWARE
5151
ACPI_MODULE_NAME("hwsleep")

‎drivers/pci/dmar.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <linux/timer.h>
3434
#include <linux/irq.h>
3535
#include <linux/interrupt.h>
36-
#include <asm/tboot.h>
36+
#include <linux/tboot.h>
3737

3838
#undef PREFIX
3939
#define PREFIX "DMAR:"

‎drivers/pci/intel-iommu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#include <linux/iommu.h>
3838
#include <linux/intel-iommu.h>
3939
#include <linux/sysdev.h>
40+
#include <linux/tboot.h>
4041
#include <asm/cacheflush.h>
41-
#include <asm/tboot.h>
4242
#include <asm/iommu.h>
4343
#include "pci.h"
4444

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
*
2121
*/
2222

23-
#ifndef _ASM_TBOOT_H
24-
#define _ASM_TBOOT_H
25-
26-
#include <acpi/acpi.h>
23+
#ifndef _LINUX_TBOOT_H
24+
#define _LINUX_TBOOT_H
2725

2826
/* these must have the values from 0-5 in this order */
2927
enum {
@@ -36,7 +34,7 @@ enum {
3634
};
3735

3836
#ifdef CONFIG_INTEL_TXT
39-
37+
#include <acpi/acpi.h>
4038
/* used to communicate between tboot and the launched kernel */
4139

4240
#define TB_KEY_SIZE 64 /* 512 bits */
@@ -144,54 +142,21 @@ static inline int tboot_enabled(void)
144142
}
145143

146144
extern void tboot_probe(void);
147-
extern void tboot_create_trampoline(void);
148145
extern void tboot_shutdown(u32 shutdown_type);
149146
extern void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control);
150-
extern int tboot_wait_for_aps(int num_aps);
151147
extern struct acpi_table_header *tboot_get_dmar_table(
152148
struct acpi_table_header *dmar_tbl);
153149
extern int tboot_force_iommu(void);
154150

155-
#else /* CONFIG_INTEL_TXT */
156-
157-
static inline int tboot_enabled(void)
158-
{
159-
return 0;
160-
}
161-
162-
static inline void tboot_probe(void)
163-
{
164-
}
165-
166-
static inline void tboot_create_trampoline(void)
167-
{
168-
}
169-
170-
static inline void tboot_shutdown(u32 shutdown_type)
171-
{
172-
}
173-
174-
static inline void tboot_sleep(u8 sleep_state, u32 pm1a_control,
175-
u32 pm1b_control)
176-
{
177-
}
178-
179-
static inline int tboot_wait_for_aps(int num_aps)
180-
{
181-
return 0;
182-
}
151+
#else
183152

184-
static inline struct acpi_table_header *tboot_get_dmar_table(
185-
struct acpi_table_header *dmar_tbl)
186-
{
187-
return dmar_tbl;
188-
}
189-
190-
static inline int tboot_force_iommu(void)
191-
{
192-
return 0;
193-
}
153+
#define tboot_probe() do { } while (0)
154+
#define tboot_shutdown(shutdown_type) do { } while (0)
155+
#define tboot_sleep(sleep_state, pm1a_control, pm1b_control) \
156+
do { } while (0)
157+
#define tboot_get_dmar_table(dmar_tbl) (dmar_tbl)
158+
#define tboot_force_iommu() 0
194159

195160
#endif /* !CONFIG_INTEL_TXT */
196161

197-
#endif /* _ASM_TBOOT_H */
162+
#endif /* _LINUX_TBOOT_H */

‎init/main.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
#include <asm/io.h>
7474
#include <asm/bugs.h>
7575
#include <asm/setup.h>
76-
#include <asm/tboot.h>
7776
#include <asm/sections.h>
7877
#include <asm/cacheflush.h>
7978

@@ -716,8 +715,6 @@ asmlinkage void __init start_kernel(void)
716715

717716
ftrace_init();
718717

719-
tboot_create_trampoline();
720-
721718
/* Do the rest non-__init'ed, we're now alive */
722719
rest_init();
723720
}

0 commit comments

Comments
 (0)