[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201204195149.611-4-nramas@linux.microsoft.com>
Date: Fri, 4 Dec 2020 11:51:44 -0800
From: Lakshmi Ramasubramanian <nramas@...ux.microsoft.com>
To: zohar@...ux.ibm.com, bauerman@...ux.ibm.com, robh@...nel.org,
gregkh@...uxfoundation.org, james.morse@....com,
catalin.marinas@....com, sashal@...nel.org, will@...nel.org,
mpe@...erman.id.au, benh@...nel.crashing.org, paulus@...ba.org,
robh+dt@...nel.org, frowand.list@...il.com,
vincenzo.frascino@....com, mark.rutland@....com,
dmitry.kasatkin@...il.com, jmorris@...ei.org, serge@...lyn.com,
pasha.tatashin@...een.com, allison@...utok.net,
kstewart@...uxfoundation.org, takahiro.akashi@...aro.org,
tglx@...utronix.de, masahiroy@...nel.org, bhsharma@...hat.com,
mbrugger@...e.com, hsinyi@...omium.org, tao.li@...o.com,
christophe.leroy@....fr
Cc: linux-integrity@...r.kernel.org, linux-kernel@...r.kernel.org,
devicetree@...r.kernel.org, prsriva@...ux.microsoft.com,
balajib@...ux.microsoft.com
Subject: [PATCH v10 3/8] powerpc: Move ima buffer functions to drivers/of/kexec.c
The functions do_get_kexec_buffer() and get_addr_size_cells(),
defined in arch/powerpc/kexec/ima.c, retrieve the address and size
of the given property from the device tree blob. These functions do
not have architecture specific code, but are currently limited to
powerpc. do_get_kexec_buffer() correctly handles a device tree property
that is a child node of the root node, but not anything other than
the immediate root child nodes.
Move architecture independent functions get_ima_kexec_buffer() and
get_root_addr_size_cells() to "drivers/of/kexec.c". These functions
retrieve the chosen node "linux,ima-kexec-buffer" from the device tree,
and return the address and size of the buffer used for carrying forward
the IMA measurement log across kexec system call.
Co-developed-by: Prakhar Srivastava <prsriva@...ux.microsoft.com>
Signed-off-by: Prakhar Srivastava <prsriva@...ux.microsoft.com>
Signed-off-by: Lakshmi Ramasubramanian <nramas@...ux.microsoft.com>
---
drivers/of/kexec.c | 70 +++++++++++++++++++++++++++++++++++++++++++
include/linux/kexec.h | 3 ++
2 files changed, 73 insertions(+)
diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
index b7d59105fcb8..516b86f7113a 100644
--- a/drivers/of/kexec.c
+++ b/drivers/of/kexec.c
@@ -59,3 +59,73 @@ int delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size)
return -ENOENT;
}
+
+/**
+ * get_root_addr_size_cells - Get address and size of root node
+ *
+ * @addr_cells: Return address of the root node
+ * @size_cells: Return size of the root node
+ *
+ * Return: 0 on success, or negative errno on error.
+ */
+int get_root_addr_size_cells(int *addr_cells, int *size_cells)
+{
+ struct device_node *root;
+
+ if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC))
+ return -EOPNOTSUPP;
+
+ root = of_find_node_by_path("/");
+ if (!root)
+ return -EINVAL;
+
+ *addr_cells = of_n_addr_cells(root);
+ *size_cells = of_n_size_cells(root);
+
+ of_node_put(root);
+
+ return 0;
+}
+
+/**
+ * get_ima_kexec_buffer - Get address and size of IMA kexec buffer
+ *
+ * @fdt: Flattened Device Tree
+ * @chosen_node: Offset of chosen node in the FDT
+ * @addr: Return address of the node
+ * @size: Return size of the node
+ *
+ * Return: 0 on success, or negative errno on error.
+ */
+int get_ima_kexec_buffer(void *fdt, int chosen_node,
+ unsigned long *addr, size_t *size)
+{
+ const void *prop;
+ int addr_cells, size_cells, prop_len;
+ int rc;
+
+ if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC))
+ return -EOPNOTSUPP;
+
+ rc = get_root_addr_size_cells(&addr_cells, &size_cells);
+ if (rc)
+ return rc;
+
+ if (fdt)
+ prop = fdt_getprop(fdt, chosen_node,
+ "linux,ima-kexec-buffer", &prop_len);
+ else
+ prop = of_get_property(of_chosen,
+ "linux,ima-kexec-buffer", &prop_len);
+
+ if (!prop)
+ return -ENOENT;
+
+ if (prop_len < 4 * (addr_cells + size_cells))
+ return -EINVAL;
+
+ *addr = of_read_number(prop, addr_cells);
+ *size = of_read_number(prop + 4 * addr_cells, size_cells);
+
+ return 0;
+}
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index d0234c4815da..10ff704ab670 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -408,6 +408,9 @@ static inline int kexec_crash_loaded(void) { return 0; }
#endif /* CONFIG_KEXEC_CORE */
#if defined(CONFIG_OF_FLATTREE)
+extern int get_root_addr_size_cells(int *addr_cells, int *size_cells);
+extern int get_ima_kexec_buffer(void *fdt, int chosen_node,
+ unsigned long *addr, size_t *size);
extern int delete_fdt_mem_rsv(void *fdt, unsigned long start,
unsigned long size);
#endif /* CONFIG_OF_FLATTREE */
--
2.29.2
Powered by blists - more mailing lists