From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A7F1C4361B for ; Mon, 14 Dec 2020 19:26:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4C60224B0 for ; Mon, 14 Dec 2020 19:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440987AbgLNTZh (ORCPT ); Mon, 14 Dec 2020 14:25:37 -0500 Received: from linux.microsoft.com ([13.77.154.182]:58122 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408896AbgLNTTt (ORCPT ); Mon, 14 Dec 2020 14:19:49 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id EA49720B7185; Mon, 14 Dec 2020 11:19:07 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EA49720B7185 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607973548; bh=13oyFSjeebmBVRsX5qnb18X54SDtFubLxPq4ZGVsI8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hCB9lgLh1jdL2MRlI/RAaPjwafQihv0aFHamvmZqwq223axDuTS3j3n/u3uOG6jO6 Rkpwen20NvQWotHMD8yISBOliqfm0W3jV06XA6pzzNh12hdmEbnZo6dhFlo444+OiY 9GYDdbyrvgdQMkPwPR9R13ibaD8W7RFXHbdxwBNU= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, takahiro.akashi@linaro.org, gregkh@linuxfoundation.org, will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au Cc: james.morse@arm.com, sashal@kernel.org, benh@kernel.crashing.org, paulus@samba.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr, prsriva@linux.microsoft.com, balajib@linux.microsoft.com, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Subject: [PATCH v11 2/8] powerpc: Move ima buffer functions to drivers/of/kexec.c Date: Mon, 14 Dec 2020 11:18:48 -0800 Message-Id: <20201214191854.9050-3-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201214191854.9050-1-nramas@linux.microsoft.com> References: <20201214191854.9050-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org 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 Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian --- drivers/of/kexec.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 3 ++ 2 files changed, 71 insertions(+) diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c index 66787be081fe..9af5371340b1 100644 --- a/drivers/of/kexec.c +++ b/drivers/of/kexec.c @@ -30,6 +30,10 @@ /** * fdt_find_and_del_mem_rsv - delete memory reservation with given address and size * + * @fdt: Flattened Device Tree to update + * @start: Starting address of the reservation to delete + * @size: Size of the reservation to delete + * * Return: 0 on success, or negative errno on error. */ static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned long size) @@ -226,3 +230,67 @@ int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt, return 0; } + +/** + * 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; + + 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; + + 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/of.h b/include/linux/of.h index 3375f5295875..fb2ef274135d 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -562,6 +562,9 @@ struct kimage; int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt, unsigned long initrd_load_addr, unsigned long initrd_len, const char *cmdline); +int get_root_addr_size_cells(int *addr_cells, int *size_cells); +int get_ima_kexec_buffer(void *fdt, int chosen_node, + unsigned long *addr, size_t *size); #else /* CONFIG_OF */ -- 2.29.2 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9500BC2BB48 for ; Mon, 14 Dec 2020 19:20:41 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44CA722473 for ; Mon, 14 Dec 2020 19:20:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44CA722473 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5LzBd6A4NjdSY3w+KTEB7T8cjYXcVOri6JTb/pUl9C0=; b=x48+m0IdwBRTv/ae0I7njwPNw womlJUXGF5O/hWYFd3HehRY1OWDe9quTw4CJaU291Ane3s3QHcLylTw6gmRZkPjG4H1I/31fOfXjj OdULKjvx/s0QLhClnct/V2DZGu7DbJdb2yl0ymj4FhJ5l+wuBalnqBLKV4fH/jUS9IqMeIzo80Hb6 uuwOwmcB7y9HrDgMmAC5lYE7DolfLpUBwCwCTvQYqkOoK/jgO2ogZUs/m78Zzs0oUqYdCpTdeNlbG 2nxBn8ttc3I1Vu3q3WxOixh8InojmBM5zvh8PDV/JeM6DUhdq8nrB9XX8TZzq1dQIBFxaxOe5MCp8 Pp77uA5hw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kotNS-0002op-9O; Mon, 14 Dec 2020 19:19:22 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kotNF-0002ks-Ou for linux-arm-kernel@lists.infradead.org; Mon, 14 Dec 2020 19:19:11 +0000 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id EA49720B7185; Mon, 14 Dec 2020 11:19:07 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EA49720B7185 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607973548; bh=13oyFSjeebmBVRsX5qnb18X54SDtFubLxPq4ZGVsI8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hCB9lgLh1jdL2MRlI/RAaPjwafQihv0aFHamvmZqwq223axDuTS3j3n/u3uOG6jO6 Rkpwen20NvQWotHMD8yISBOliqfm0W3jV06XA6pzzNh12hdmEbnZo6dhFlo444+OiY 9GYDdbyrvgdQMkPwPR9R13ibaD8W7RFXHbdxwBNU= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, takahiro.akashi@linaro.org, gregkh@linuxfoundation.org, will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au Subject: [PATCH v11 2/8] powerpc: Move ima buffer functions to drivers/of/kexec.c Date: Mon, 14 Dec 2020 11:18:48 -0800 Message-Id: <20201214191854.9050-3-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201214191854.9050-1-nramas@linux.microsoft.com> References: <20201214191854.9050-1-nramas@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201214_141909_957547_476BA3BA X-CRM114-Status: GOOD ( 16.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, benh@kernel.crashing.org, bhsharma@redhat.com, tao.li@vivo.com, paulus@samba.org, vincenzo.frascino@arm.com, frowand.list@gmail.com, sashal@kernel.org, masahiroy@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, serge@hallyn.com, devicetree@vger.kernel.org, pasha.tatashin@soleen.com, prsriva@linux.microsoft.com, hsinyi@chromium.org, allison@lohutok.net, christophe.leroy@c-s.fr, mbrugger@suse.com, balajib@linux.microsoft.com, dmitry.kasatkin@gmail.com, linux-kernel@vger.kernel.org, james.morse@arm.com, linux-integrity@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian --- drivers/of/kexec.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 3 ++ 2 files changed, 71 insertions(+) diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c index 66787be081fe..9af5371340b1 100644 --- a/drivers/of/kexec.c +++ b/drivers/of/kexec.c @@ -30,6 +30,10 @@ /** * fdt_find_and_del_mem_rsv - delete memory reservation with given address and size * + * @fdt: Flattened Device Tree to update + * @start: Starting address of the reservation to delete + * @size: Size of the reservation to delete + * * Return: 0 on success, or negative errno on error. */ static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned long size) @@ -226,3 +230,67 @@ int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt, return 0; } + +/** + * 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; + + 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; + + 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/of.h b/include/linux/of.h index 3375f5295875..fb2ef274135d 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -562,6 +562,9 @@ struct kimage; int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt, unsigned long initrd_load_addr, unsigned long initrd_len, const char *cmdline); +int get_root_addr_size_cells(int *addr_cells, int *size_cells); +int get_ima_kexec_buffer(void *fdt, int chosen_node, + unsigned long *addr, size_t *size); #else /* CONFIG_OF */ -- 2.29.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel