tpm: Add new vTPM device driver for PPC64
Subsystems (2)
Ashley Lai
Appliedcover tpm: Add new vTPM device driver for PPC64
These patches add support for IBM vTPM for PPC64. This new device driver works on firmware that supports vTPM (firmware release 740 or higher).
Tested on Power7+ system with firmware level ZM770_001.
Applied to Kent Yoder patch to modularize event log located at:
https://github.com/shpedoikal/linux/tree/tpmdd-next
Ashley Lai (3):
drivers/char/tpm: Add new device driver to support IBM vTPM
PPC64: Add support for instantiating SML from Open Firmware drivers/char/tpm: Add securityfs support for event log
arch/powerpc/kernel/prom_init.c | 64 ++++ drivers/char/tpm/Kconfig | 8 + drivers/char/tpm/Makefile | 9 +- drivers/char/tpm/tpm.h | 13 +- drivers/char/tpm/tpm_eventlog.c | 7 + drivers/char/tpm/tpm_eventlog.h | 24 ++ drivers/char/tpm/tpm_ibmvtpm.c | 750 +++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm_ibmvtpm.h | 83 ++++ drivers/char/tpm/tpm_noeventlog.c | 21 + drivers/char/tpm/tpm_of.c | 68 ++++ 10 files changed, 1034 insertions(+), 13 deletions(-) create mode 100644 drivers/char/tpm/tpm_ibmvtpm.c create mode 100644 drivers/char/tpm/tpm_ibmvtpm.h create mode 100644 drivers/char/tpm/tpm_noeventlog.c create mode 100644 drivers/char/tpm/tpm_of.c
PATCH 1/3 drivers/char/tpm: Add new device driver to support IBM vTPM
This patch adds a new device driver to support IBM virtual TPM (vTPM) for PPC64. This driver provides TPM functionalities by communicating with the vTPM adjunct through Hypervisor calls (Hcalls) and Command/Response Queue (CRQ) commands.
--- drivers/char/tpm/Kconfig | 8 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm.h | 1 + drivers/char/tpm/tpm_ibmvtpm.c | 750 ++++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm_ibmvtpm.h | 83 +++++ 5 files changed, 843 insertions(+), 0 deletions(-) create mode 100644 drivers/char/tpm/tpm_ibmvtpm.c create mode 100644 drivers/char/tpm/tpm_ibmvtpm.h
drivers/char/tpm/Kconfig +8 -0
@@ -73,4 +73,12 @@ config TCG_INFINEON Further information on this driver and the supported hardware can be found at http://www.trust.rub.de/projects/linux-device-driver-infineon-tpm/ +config TCG_IBMVTPM + tristate "IBM VTPM Interface" + depends on PPC64 + ---help--- + If you have IBM virtual TPM (VTPM) support say Yes and it + will be accessible from within Linux. To compile this driver + as a module, choose M here; the module will be called tpm_ibmvtpm. + endif # TCG_TPM
drivers/char/tpm/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o obj-$(CONFIG_TCG_NSC) += tpm_nsc.o obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o +obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o
drivers/char/tpm/tpm.h +1 -0
@@ -94,6 +94,7 @@ struct tpm_vendor_specific {bool timeout_adjusted;unsigned long duration[3 ];/* jiffies */ bool duration_adjusted; +void *data;wait_queue_head_t read_queue;wait_queue_head_t int_queue;
drivers/char/tpm/tpm_ibmvtpm.c new file +750 -0
750 lines not on this page · raw message
drivers/char/tpm/tpm_ibmvtpm.h new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 2/3 PPC64: Add support for instantiating SML from Open Firmware
In reply to Ashley LaiThis patch instantiate Stored Measurement Log (SML) and put the log address and size in the device tree.
--- arch/powerpc/kernel/prom_init.c | 64 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 64 insertions(+), 0 deletions(-)
arch/powerpc/kernel/prom_init.c +64 -0
@@ -1624,6 +1624,65 @@ static void __init prom_instantiate_rtas(void)#ifdef CONFIG_PPC64 /* +* Allocate room for and instantiate Stored Measurement Log (SML) +*/ +static void __init prom_instantiate_sml (void ) +{ +phandle ibmvtpm_node; +ihandle ibmvtpm_inst; +u32 entry =0 , size =0 ; +u64 base; + +prom_debug ("prom_instantiate_sml: start...\n" ); + + ibmvtpm_node =call_prom ("finddevice" ,1 ,1 ,ADDR ("/ibm,vtpm" )); +prom_debug ("ibmvtpm_node: %x\n" , ibmvtpm_node); +if (!PHANDLE_VALID (ibmvtpm_node)) +return ; + + ibmvtpm_inst =call_prom ("open" ,1 ,1 ,ADDR ("/ibm,vtpm" )); +if (!IHANDLE_VALID (ibmvtpm_inst)) { +prom_printf ("opening vtpm package failed (%x)\n" , ibmvtpm_inst); +return ; + } + +if (call_prom_ret ("call-method" ,2 ,2 , &size, +ADDR ("sml-get-handover-size" ), + ibmvtpm_inst) !=0 ) { +prom_printf ("SML get handover size failed\n" ); +return ; + } +if (size ==0 ) +return ; + + base =alloc_down (size,PAGE_SIZE ,0 ); +if (base ==0 ) +prom_panic ("Could not allocate memory for sml\n" ); + +prom_printf ("instantiating sml at 0x%x..." , base); + +if (call_prom_ret ("call-method" ,4 ,2 , &entry, +ADDR ("sml-handover" ), + ibmvtpm_inst, size, base) !=0 || entry ==0 ) { +prom_printf ("SML handover failed\n" ); +return ; + } +prom_printf (" done\n" ); + +reserve_mem (base, size); + +prom_setprop (ibmvtpm_node,"/ibm,vtpm" ,"linux,sml-base" , + &base,sizeof (base)); +prom_setprop (ibmvtpm_node,"/ibm,vtpm" ,"linux,sml-size" , + &size,sizeof (size)); + +prom_debug ("sml base = 0x%x\n" , base); +prom_debug ("sml size = 0x%x\n" , (long )size); + +prom_debug ("prom_instantiate_sml: end...\n" ); +} + +/* * Allocate room for and initialize TCE tables */ static void __init prom_initialize_tce_table (void )
@@ -2916,6 +2975,11 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,prom_instantiate_opal ();#endif +#ifdef CONFIG_PPC64 +/* instantiate sml */ +prom_instantiate_sml (); +#endif +/* * On non-powermacs, put all CPUs in spin-loops. *
Signature · 1 line
1.7.1
PATCH 3/3 drivers/char/tpm: Add securityfs support for event log
In reply to Ashley LaiThis patch retrieves the event log from the device tree and the event log data will be displayed through securityfs.
--- drivers/char/tpm/Makefile | 8 ++++- drivers/char/tpm/tpm.h | 12 ------ drivers/char/tpm/tpm_eventlog.c | 7 ++++ drivers/char/tpm/tpm_eventlog.h | 24 +++++++++++++ drivers/char/tpm/tpm_noeventlog.c | 21 +++++++++++ drivers/char/tpm/tpm_of.c | 68 +++++++++++++++++++++++++++++++++++++ 6 files changed, 127 insertions(+), 13 deletions(-) create mode 100644 drivers/char/tpm/tpm_noeventlog.c create mode 100644 drivers/char/tpm/tpm_of.c
drivers/char/tpm/Makefile +7 -1
@@ -2,9 +2,15 @@ # Makefile for the kernel tpm device drivers. # obj-$(CONFIG_TCG_TPM) += tpm.o +obj-$(CONFIG_TCG_TPM) += tpm_bios.o ifdef CONFIG_ACPI - obj-$(CONFIG_TCG_TPM) += tpm_bios.o tpm_bios-objs += tpm_eventlog.o tpm_acpi.o +else +ifdef CONFIG_TCG_IBMVTPM + tpm_bios-objs += tpm_eventlog.o tpm_of.o +else + tpm_bios-objs += tpm_eventlog.o tpm_noeventlog.o +endif endif obj-$(CONFIG_TCG_TIS) += tpm_tis.o obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o
drivers/char/tpm/tpm.h +0 -12
@@ -304,15 +304,3 @@ extern int tpm_pm_suspend(struct device *, pm_message_t);extern int tpm_pm_resume (struct device *);extern int wait_for_tpm_stat (struct tpm_chip *,u8 ,unsigned long ,wait_queue_head_t *); -#ifdef CONFIG_ACPI -extern struct dentry **tpm_bios_log_setup (char *); -extern void tpm_bios_log_teardown (struct dentry **); -#else -static inline struct dentry **tpm_bios_log_setup (char *name) -{ -return NULL ; -} -static inline void tpm_bios_log_teardown (struct dentry **dir) -{ -} -#endif
drivers/char/tpm/tpm_eventlog.c +7 -0
@@ -24,6 +24,7 @@#include <linux/security.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/of.h> #include "tpm.h" #include "tpm_eventlog.h"
@@ -369,6 +370,9 @@ struct dentry **tpm_bios_log_setup(char *name) {struct dentry **ret =NULL , *tpm_dir, *bin_file, *ascii_file; +if (TPM_NO_EVENT_LOG ) +return NULL ; + tpm_dir =securityfs_create_dir (name,NULL );if (is_bad (tpm_dir)) goto out;
@@ -412,6 +416,9 @@ void tpm_bios_log_teardown(struct dentry **lst) {int i; +if (TPM_NO_EVENT_LOG ) +return ; +for (i =0 ; i <3 ; i++)securityfs_remove (lst[i]); }
drivers/char/tpm/tpm_eventlog.h +24 -0
@@ -68,4 +68,28 @@ enum tcpa_pc_event_ids { };int read_log (struct tpm_bios_log *log); + +#if defined(CONFIG_ACPI ) || defined(CONFIG_PPC64 ) +extern struct dentry **tpm_bios_log_setup (char *); +extern void tpm_bios_log_teardown (struct dentry **); +#else +static inline struct dentry **tpm_bios_log_setup (char *name) +{ +return NULL ; +} +static inline void tpm_bios_log_teardown (struct dentry **dir) +{ +} +#endif + +#ifdef CONFIG_PPC64 +#define TPM_NO_EVENT_LOG !of_find_node_by_name(NULL, "ibm,vtpm") +#else +#ifdef CONFIG_ACPI +#define TPM_NO_EVENT_LOG 0 +#else +#define TPM_NO_EVENT_LOG 1 +#endif +#endif +#endif
drivers/char/tpm/tpm_noeventlog.c new file +21 -0
@@ -0,0 +1,21 @@ +/* +* Copyright (C) 2012 IBM Corporation +* +* Author: Ashley Lai <[email protected]> +* +* Maintained by: <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +*/ + +#include <linux/slab.h> +#include "tpm_eventlog.h" + +int read_log (struct tpm_bios_log *log) +{ +return -EINVAL ; +}
drivers/char/tpm/tpm_of.c new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH 3/3] drivers/char/tpm: Add securityfs support for event log
Hi Ashley,
Quoted 7 lines
drivers/char/tpm/Makefile +0
-0@@ -2,9 +2,15 @@ # Makefile for the kernel tpm device drivers. #
drivers/char/tpm/Makefile line 12
Quoted 10 lines
drivers/char/tpm/Makefile +6
-1obj-$(CONFIG_TCG_TPM) += tpm.o +obj-$(CONFIG_TCG_TPM) += tpm_bios.o ifdef CONFIG_ACPI - obj-$(CONFIG_TCG_TPM) += tpm_bios.o tpm_bios-objs += tpm_eventlog.o tpm_acpi.o +else +ifdef CONFIG_TCG_IBMVTPM + tpm_bios-objs += tpm_eventlog.o tpm_of.o +else + tpm_bios-objs += tpm_eventlog.o tpm_noeventlog.o
tpm_eventlog.c is included in all cases here...
Quoted 11 lines
drivers/char/tpm/tpm_eventlog.h +3
-0@@ -68,4 +68,28 @@ enum tcpa_pc_event_ids { };int read_log (struct tpm_bios_log *log); + +#if defined(CONFIG_ACPI ) || defined(CONFIG_PPC64 ) +extern struct dentry **tpm_bios_log_setup (char *);
drivers/char/tpm/tpm_eventlog.h enum tcpa_pc_event_ids { · line 83
Quoted 10 lines
drivers/char/tpm/tpm_eventlog.h +10
-0+extern void tpm_bios_log_teardown (struct dentry **); +#else +static inline struct dentry **tpm_bios_log_setup (char *name) +{ +return NULL ; +} +static inline void tpm_bios_log_teardown (struct dentry **dir) +{ +} +#endif
But here, without acpi or ppc64, we compile in stubs, which breaks
things. It looks like we don't need these stubs at all anymore, and can rely on TPM_NO_EVENT_LOG to bail out in the cases on x86 where ACPI is disabled.
Kent
Quoted 117 lines
drivers/char/tpm/tpm_eventlog.h +11
-0+ +#ifdef CONFIG_PPC64 +#define TPM_NO_EVENT_LOG !of_find_node_by_name(NULL, "ibm,vtpm") +#else +#ifdef CONFIG_ACPI +#define TPM_NO_EVENT_LOG 0 +#else +#define TPM_NO_EVENT_LOG 1 +#endif +#endif +#endif drivers/char/tpm/tpm_noeventlog.c new file +21
-0@@ -0,0 +1,21 @@ +/* +* Copyright (C) 2012 IBM Corporation +* +* Author: Ashley Lai <[email protected]> +* +* Maintained by: <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +*/ + +#include <linux/slab.h> +#include "tpm_eventlog.h" + +int read_log (struct tpm_bios_log *log) +{ +return -EINVAL ; +}drivers/char/tpm/tpm_of.c new file +68
-0@@ -0,0 +1,68 @@ +/* +* Copyright 2012 IBM Corporation +* +* Author: Ashley Lai <[email protected]> +* +* Maintained by: <[email protected]> +* +* Read the event log created by the firmware on PPC64 +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +*/ + +#include <linux/slab.h> +#include <linux/of.h> + +#include "tpm.h" +#include "tpm_eventlog.h" + +int read_log (struct tpm_bios_log *log) +{ +struct device_node *np; +const u32 *sizep; +const __be64 *basep; + +if (log->bios_event_log !=NULL ) { +pr_err ("%s: ERROR - Eventlog already initialized\n" , __func__); +return -EFAULT ; + } + + np =of_find_node_by_name (NULL ,"ibm,vtpm" ); +if (!np) { +pr_err ("%s: ERROR - IBMVTPM not supported\n" , __func__); +return -ENODEV ; + } + + sizep =of_get_property (np,"linux,sml-size" ,NULL ); +if (sizep ==NULL ) { +pr_err ("%s: ERROR - SML size not found\n" , __func__); +return -EIO ; + } +if (*sizep ==0 ) { +pr_err ("%s: ERROR - event log area empty\n" , __func__); +return -EIO ; + } + + basep =of_get_property (np,"linux,sml-base" ,NULL ); +if (basep ==NULL ) { +pr_err (KERN_ERR "%s: ERROR - SML not found\n" , __func__); +return -EIO ; + } + + log->bios_event_log =kmalloc (*sizep,GFP_KERNEL ); +if (!log->bios_event_log) { +pr_err ("%s: ERROR - Not enough memory for BIOS measurements\n" , + __func__); +return -ENOMEM ; + } + + log->bios_event_log_end = log->bios_event_log + *sizep; + +memcpy (log->bios_event_log,__va (be64_to_cpup (basep)), *sizep); + +return 0 ; +}Signature · 1 line
1.7.1
Re: [PATCH 3/3] drivers/char/tpm: Add securityfs support for event log
Hi Kent,
Quoted 22 lines
drivers/char/tpm/Makefile line 12
Quoted 4 lines
drivers/char/tpm/Makefile +4
-0+ifdef CONFIG_TCG_IBMVTPM + tpm_bios-objs += tpm_eventlog.o tpm_of.o +else + tpm_bios-objs += tpm_eventlog.o tpm_noeventlog.o
tpm_eventlog.cis included in all cases here...drivers/char/tpm/tpm_eventlog.h enum tcpa_pc_event_ids { · line 83
Quoted 8 lines
drivers/char/tpm/tpm_eventlog.h +8
-0+static inline struct dentry **tpm_bios_log_setup (char *name) +{ +return NULL ; +} +static inline void tpm_bios_log_teardown (struct dentry **dir) +{ +} +#endif But here, without acpi or ppc64, we compile in stubs, which breaks
things. It looks like we don't need these stubs at all anymore, and can rely onTPM_NO_EVENT_LOGto bail out in the cases on x86 where ACPI is disabled.
Quoted 1 line
Kent
Thanks for testing it out. I will fix it in the next version.
--Ashley
Re: [PATCH 3/3] drivers/char/tpm: Add securityfs support for event log
In reply to Ashley LaiHi Kent,
Thanks for looking into it. I'll fix in the next version.
Sorry if you got this message twice. I have some issues with my mail server.
Thanks,
--Ashley Lai