Skip to contentSkip to conversation

x86, tboot: provide debugfs interfaces to access TXT log

PATCH Superseded Qiaowei Ren 3 participants 4 messages Jun 23, 2013 – Jun 24, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, tboot: provide debugfs interfaces to access TXT log

These logs come from tboot (Trusted Boot, an open source, pre-kernel/VMM module that uses Intel TXT to perform a measured and verified launch of an OS kernel/VMM.).

---
 arch/x86/kernel/tboot.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
arch/x86/kernel/tboot.c +70 -0
index f84fe00..dd6f198 100644
@@ -31,6 +31,7 @@
 #include <linux/pfn.h>
 #include <linux/mm.h>
 #include <linux/tboot.h>
+#include <linux/debugfs.h>
 
 #include <asm/realmode.h>
 #include <asm/processor.h>
@@ -338,6 +339,70 @@ static struct notifier_block tboot_cpu_notifier __cpuinitdata =
 	.notifier_call = tboot_cpu_callback,
 };
 
+#if defined(CONFIG_DEBUG_FS)
+
+#define TBOOT_LOG_UUID	{0x26, 0x25, 0x19, 0xc0, 0x30, 0x6b, 0xb4, 0x4d, \
+			 0x4c, 0x84, 0xa3, 0xe9, 0x53, 0xb8, 0x81, 0x74}
+#define TBOOT_SERIAL_LOG_ADDR	0x60000
+#define TBOOT_SERIAL_LOG_SIZE	0x08000
+
+static uint8_t tboot_log_uuid[16] = TBOOT_LOG_UUID;
+
+struct tboot_log {
+	uint8_t		uuid[16];
+	uint32_t	max_size;
+	uint32_t	curr_pos;
+	char		buf[];
+};
+
+static struct tboot_log *get_log(void)
+{
+	struct tboot_log *log;
+
+	log = (struct tboot_log *)ioremap_nocache(TBOOT_SERIAL_LOG_ADDR,
+						  TBOOT_SERIAL_LOG_SIZE);
+	if (!log)
+		return NULL;
+
+	if (memcmp(&tboot_log_uuid, &log->uuid, sizeof(log->uuid))) {
+		iounmap(log);
+		return NULL;
+	}
+
+	return log;
+}
+
+static ssize_t tboot_log_read(struct file *file, char __user *user_buf,
+			      size_t count, loff_t *ppos)
+{
+	struct tboot_log *log;
+
+	log = get_log();
+	if (!log)
+		return -EFAULT;
+
+	if (*ppos >= log->max_size)
+		return 0;
+
+	if (*ppos + count > log->max_size)
+		count = log->max_size - *ppos;
+
+	if (copy_to_user(user_buf, log->buf + *ppos, count))
+		return -EFAULT;
+
+	*ppos += count;
+
+	iounmap(log);
+	return count;
+}
+
+static const struct file_operations tboot_log_fops = {
+	.read = tboot_log_read,
+	.llseek = default_llseek,
+};
+
+#endif /* CONFIG_DEBUG_FS */
+
 static __init int tboot_late_init(void)
 {
 	if (!tboot_enabled())
@@ -348,6 +413,11 @@ static __init int tboot_late_init(void)
 	atomic_set(&ap_wfs_count, 0);
 	register_hotcpu_notifier(&tboot_cpu_notifier);
 
+#if defined(CONFIG_DEBUG_FS)
+	debugfs_create_file("tboot_log", S_IRUSR,
+			arch_debugfs_dir, NULL, &tboot_log_fops);
+#endif
+
 	acpi_os_set_prepare_sleep(&tboot_sleep);
 	return 0;
 }
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 3 lines · Qiaowei Ren

These logs come from tboot (Trusted Boot, an open source, pre-kernel/VMM module that uses Intel TXT to perform a measured and verified launch of an OS kernel/VMM.).

[]

arch/x86/kernel/tboot.c

Quoted 1 line
arch/x86/kernel/tboot.c +0 -0

[]

arch/x86/kernel/tboot.c static struct notifier_block tboot_cpu_notifier __cpuinitdata = · line 363

Quoted 6 lines
arch/x86/kernel/tboot.c +6 -0
+static struct tboot_log *get_log(void)
+{
+	struct tboot_log *log;
+
+	log = (struct tboot_log *)ioremap_nocache(TBOOT_SERIAL_LOG_ADDR,
+						  TBOOT_SERIAL_LOG_SIZE);

You might want to fix the sparse errors.
CHECK arch/x86/kernel/tboot.c
arch/x86/kernel/tboot.c:362:16: warning: cast removes address space of expression arch/x86/kernel/tboot.c:368:25: warning: incorrect type in argument 1 (different address spaces)
arch/x86/kernel/tboot.c:368:25: expected void volatile [noderef] <asn:2>*addr
arch/x86/kernel/tboot.c:368:25: got struct tboot_log *[assigned] log
arch/x86/kernel/tboot.c:395:17: warning: incorrect type in argument 1 (different address spaces)
arch/x86/kernel/tboot.c:395:17: expected void volatile [noderef] <asn:2>*addr
arch/x86/kernel/tboot.c:395:17: got struct tboot_log *[assigned] log
arch/x86/kernel/tboot.c:479:16: warning: incorrect type in assignment (different address spaces)
arch/x86/kernel/tboot.c:479:16: expected void *config
arch/x86/kernel/tboot.c:479:16: got void [noderef] <asn:2>*
arch/x86/kernel/tboot.c:485:19: warning: incorrect type in assignment (different address spaces)
arch/x86/kernel/tboot.c:485:19: expected void *heap_base
arch/x86/kernel/tboot.c:485:19: got void [noderef] <asn:2>*
arch/x86/kernel/tboot.c:487:17: warning: incorrect type in argument 1 (different address spaces)
arch/x86/kernel/tboot.c:487:17: expected void volatile [noderef] <asn:2>*addr
arch/x86/kernel/tboot.c:487:17: got void *config

#2 lore raw
Quoted 24 lines · Joe Perches
Quoted 3 lines · Qiaowei Ren

These logs come from tboot (Trusted Boot, an open source, pre-kernel/VMM module that uses Intel TXT to perform a measured and verified launch of an OS kernel/VMM.).

[]

arch/x86/kernel/tboot.c

Quoted 1 line
arch/x86/kernel/tboot.c +0 -0

[]

arch/x86/kernel/tboot.c static struct notifier_block tboot_cpu_notifier __cpuinitdata = · line 363

Quoted 6 lines
arch/x86/kernel/tboot.c +6 -0
+static struct tboot_log *get_log(void)
+{
+	struct tboot_log *log;
+
+	log = (struct tboot_log *)ioremap_nocache(TBOOT_SERIAL_LOG_ADDR,
+						  TBOOT_SERIAL_LOG_SIZE);

You might want to fix the sparse errors.
CHECK arch/x86/kernel/tboot.c
arch/x86/kernel/tboot.c:362:16: warning: cast removes address space of expression arch/x86/kernel/tboot.c:368:25: warning: incorrect type in argument 1 (different address spaces)
arch/x86/kernel/tboot.c:368:25: expected void volatile [noderef] <asn:2>*addr
arch/x86/kernel/tboot.c:368:25: got struct tboot_log *[assigned] log
arch/x86/kernel/tboot.c:395:17: warning: incorrect type in argument 1 (different address spaces)
arch/x86/kernel/tboot.c:395:17: expected void volatile [noderef] <asn:2>*addr
arch/x86/kernel/tboot.c:395:17: got struct tboot_log *[assigned] log
arch/x86/kernel/tboot.c:479:16: warning: incorrect type in assignment (different address spaces)

Quoted 10 lines

arch/x86/kernel/tboot.c:479:16: expected void *config
arch/x86/kernel/tboot.c:479:16: got void [noderef] <asn:2>*
arch/x86/kernel/tboot.c:485:19: warning: incorrect type in assignment (different address spaces)
arch/x86/kernel/tboot.c:485:19: expected void *heap_base
arch/x86/kernel/tboot.c:485:19: got void [noderef] <asn:2>*
arch/x86/kernel/tboot.c:487:17: warning: incorrect type in argument 1 (different address spaces)
arch/x86/kernel/tboot.c:487:17: expected void volatile [noderef] <asn:2>*addr
arch/x86/kernel/tboot.c:487:17: got void *config

Well, I guess that I can use iomem related interface to fix these warnings caused by sparse.

Thanks,
Qiaowei

#3 lore raw
Quoted 4 lines · Ren Qiaowei
Quoted 1 line

Well, I guess that I can use iomem related interface to fix these warnings caused by sparse.

And you SHOULD. Passing around pointers to I/O space without even annotating them isn't really very clean.

-hpa