Skip to contentSkip to conversation

vTPM: fix memory allocation flag for rtce buffer at kernel boot

PATCH New Hon Ching(Vicky) Lo 1 participant 4 messages Oct 8, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vTPM: fix memory allocation flag for rtce buffer at kernel boot

At ibm vtpm initialzation, tpm_ibmvtpm_probe() registers its interrupt handler, ibmvtpm_interrupt, which calls ibmvtpm_crq_process to allocate memory for rtce buffer. The current code uses 'GFP_KERNEL' as the type of kernel memory allocation, which resulted a warning at kernel/lockdep.c. This patch uses 'GFP_ATOMIC' instead so that the allocation is high-priority and does not sleep.

---
 drivers/char/tpm/tpm_ibmvtpm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/char/tpm/tpm_ibmvtpm.c +1 -1
index 27ebf95..3e6a226 100644
@@ -491,7 +491,7 @@ static void ibmvtpm_crq_process(struct ibmvtpm_crq *crq,
 			}
 			ibmvtpm->rtce_size = be16_to_cpu(crq->len);
 			ibmvtpm->rtce_buf = kmalloc(ibmvtpm->rtce_size,
-						    GFP_KERNEL);
+						    GFP_ATOMIC);
 			if (!ibmvtpm->rtce_buf) {
 				dev_err(ibmvtpm->dev, "Failed to allocate memory for rtce buffer\n");
 				return;
Signature · 1 line
1.7.1
#1 lore raw

PATCH v2 1/3 vTPM: fix searching for the right vTPM node in device tree

Replace all occurrences of '/ibm,vtpm' with '/vdevice/vtpm', as only the latter is ganranteed to be available for the client OS. The '/ibm,vtpm' node should only be used by Open Firmware, which is susceptible to changes.

---
 arch/powerpc/kernel/prom_init.c |    8 ++++----
 drivers/char/tpm/tpm_of.c       |    2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/kernel/prom_init.c +4 -4
index 1a85d8f..b9b6bb1 100644
@@ -1422,12 +1422,12 @@ static void __init prom_instantiate_sml(void)
 
 	prom_debug("prom_instantiate_sml: start...\n");
 
-	ibmvtpm_node = call_prom("finddevice", 1, 1, ADDR("/ibm,vtpm"));
+	ibmvtpm_node = call_prom("finddevice", 1, 1, ADDR("/vdevice/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"));
+	ibmvtpm_inst = call_prom("open", 1, 1, ADDR("/vdevice/vtpm"));
 	if (!IHANDLE_VALID(ibmvtpm_inst)) {
 		prom_printf("opening vtpm package failed (%x)\n", ibmvtpm_inst);
 		return;
@@ -1456,9 +1456,9 @@ static void __init prom_instantiate_sml(void)
 
 	reserve_mem(base, size);
 
-	prom_setprop(ibmvtpm_node, "/ibm,vtpm", "linux,sml-base",
+	prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-base",
 		     &base, sizeof(base));
-	prom_setprop(ibmvtpm_node, "/ibm,vtpm", "linux,sml-size",
+	prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-size",
 		     &size, sizeof(size));
 
 	prom_debug("sml base     = 0x%x\n", base);
drivers/char/tpm/tpm_of.c +1 -1
index 62a22ce..6c73199 100644
@@ -31,7 +31,7 @@ int read_log(struct tpm_bios_log *log)
 		return -EFAULT;
 	}
 
-	np = of_find_node_by_name(NULL, "ibm,vtpm");
+	np = of_find_node_by_name(NULL, "vtpm");
 	if (!np) {
 		pr_err("%s: ERROR - IBMVTPM not supported\n", __func__);
 		return -ENODEV;
Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 2/3 vTPM: reformat event log to be byte-aligned

In reply to Hon Ching(Vicky) Lo

The event log generated by OpenFirmware in PowerPC is 4-byte aligned. This patch reformats the log to be byte-aligned for the Linux client.

---
 arch/powerpc/kernel/prom_init.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
arch/powerpc/kernel/prom_init.c +12 -1
index b9b6bb1..8a5c248 100644
@@ -1417,8 +1417,9 @@ static void __init prom_instantiate_sml(void)
 {
 	phandle ibmvtpm_node;
 	ihandle ibmvtpm_inst;
-	u32 entry = 0, size = 0;
+	u32 entry = 0, size = 0, succ = 0;
 	u64 base;
+	__be32 val;
 
 	prom_debug("prom_instantiate_sml: start...\n");
 
@@ -1433,6 +1434,16 @@ static void __init prom_instantiate_sml(void)
 		return;
 	}
 
+	if (prom_getprop(ibmvtpm_node, "ibm,sml-efi-reformat-supported",
+			 &val, sizeof(val)) != PROM_ERROR) {
+		if (call_prom_ret("call-method", 2, 2, &succ,
+				  ADDR("reformat-sml-to-efi-alignment"),
+				  ibmvtpm_inst) != 0 || succ == 0) {
+			prom_printf("Reformat SML to EFI alignment failed\n");
+			return;
+		}
+	}
+
 	if (call_prom_ret("call-method", 2, 2, &size,
 			  ADDR("sml-get-handover-size"),
 			  ibmvtpm_inst) != 0 || size == 0) {
Signature · 1 line
1.7.1
#3 lore raw

PATCH v2 3/3 vTPM: get the buffer allocated for event log instead of the actual log

In reply to Hon Ching(Vicky) Lo

The OS should ask Power Firmware (PFW) for the size of the buffer allocated for the event log, instead of the size of the actual event log. It then passes the buffer adddress and size to PFW in the handover process, into which PFW copies the log.

---
 arch/powerpc/kernel/prom_init.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
arch/powerpc/kernel/prom_init.c +15 -6
index 8a5c248..08fe5e7 100644
@@ -1442,13 +1442,20 @@ static void __init prom_instantiate_sml(void)
 			prom_printf("Reformat SML to EFI alignment failed\n");
 			return;
 		}
-	}
 
-	if (call_prom_ret("call-method", 2, 2, &size,
-			  ADDR("sml-get-handover-size"),
-			  ibmvtpm_inst) != 0 || size == 0) {
-		prom_printf("SML get handover size failed\n");
-		return;
+		if (call_prom_ret("call-method", 2, 2, &size,
+				  ADDR("sml-get-allocated-size"),
+				  ibmvtpm_inst) != 0 || size == 0) {
+			prom_printf("SML get allocated size failed\n");
+			return;
+		}
+	} else {
+		if (call_prom_ret("call-method", 2, 2, &size,
+				  ADDR("sml-get-handover-size"),
+				  ibmvtpm_inst) != 0 || size == 0) {
+			prom_printf("SML get handover size failed\n");
+			return;
+		}
 	}
 
 	base = alloc_down(size, PAGE_SIZE, 0);
@@ -1457,6 +1464,8 @@ static void __init prom_instantiate_sml(void)
 
 	prom_printf("instantiating sml at 0x%x...", base);
 
+	memset((void *)base, 0, size);
+
 	if (call_prom_ret("call-method", 4, 2, &entry,
 			  ADDR("sml-handover"),
 			  ibmvtpm_inst, size, base) != 0 || entry == 0) {
Signature · 1 line
1.7.1