Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp649330pxu; Fri, 4 Dec 2020 11:56:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFI8wv5G6U18p94UXtXdoBngdAZ8sjH6IK0X4eHKry/x2zk72UogpSlNRI/WcewCYe3oT0 X-Received: by 2002:aa7:c558:: with SMTP id s24mr9253367edr.257.1607111816102; Fri, 04 Dec 2020 11:56:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607111816; cv=none; d=google.com; s=arc-20160816; b=IMydyf4plAu0YZz9j2bGp3nZejAuLKSxfisbLeP16WLilXDusjEF2hlOLDTg1YeuiQ Si5p+UxSxOcIHJUwIkicEktC4RyJAfO/TtRndIj9SMykcH16bF7K8RHVT5eSaZmBNxVW 7o4E6duHPPZWWAQEvkD1UheUcgHSJRyEkUhJrZgqLWqM9X9YLwBty+6lFd1M859Gyi3h sd90/oG9yAeZ59QcZ1DgpNNiRSb+goDPKW+kcX4QZIb2lsqR41F35q5U1N3Pu9yEQNeZ 5hB/9L/FrdeNYCnjzzaitdde9QGmwMHzGkK0op7AMc98Xl2qR6ndLVliuKdCkuRVWo1x PIaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=QjzwkKap5j6BGZIXUMFZtVLppXuA87W5hY580CxO5Fg=; b=Y08BDMNXrvRtqjrbQf4M036N1KqKBGAuSb7Yn82iLH7gW9fQBPaGgtaK9awRqA3srv h3B3OXlOXIEuAZwtl85JHUWdEfh/3AJ4dVHBRTx93OVxzpW5+oZ4qEBTR0qYBeAyvQ7I c4BfgNeyUH1Uf+fRp0X3sBsY9uBzoZOHF0vad/UHJzBlMzr/6y2D8jexXOre7ehwUxhQ 0r5zTbz7yC1T3VOQCpm8RxXr95OtmOC1RzGfm2yK/skITaZPOnfOSKajqD2dv2aYy4r+ LBg0pLHyzeJoVX33XiBoUjnh7qrdybHgQOgqpGkMTSa5VbZ2FW8iH/UZ91qy3A4QgROY w8WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=JsemOQH9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oi22si2320058ejb.690.2020.12.04.11.56.33; Fri, 04 Dec 2020 11:56:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=JsemOQH9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730875AbgLDTwo (ORCPT + 99 others); Fri, 4 Dec 2020 14:52:44 -0500 Received: from linux.microsoft.com ([13.77.154.182]:52672 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730647AbgLDTwi (ORCPT ); Fri, 4 Dec 2020 14:52:38 -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 26F0820B7187; Fri, 4 Dec 2020 11:51:57 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 26F0820B7187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607111517; bh=QjzwkKap5j6BGZIXUMFZtVLppXuA87W5hY580CxO5Fg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JsemOQH9A0VzQkpzu03at+NXfh706D2DoAoDdrG1/MmUhSONyN2/YTRZXVoXyQ5qW QirUmFfkFCoE9TbQUEtDcbIJysS5MV1n6YhCF9SgBjjaQSgTaEjPSgSu/8KLYVc6yr E/V1PcoQJRM/YLEXSx3DOw9eUrApETd35T5b+7Z4= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, gregkh@linuxfoundation.org, james.morse@arm.com, catalin.marinas@arm.com, sashal@kernel.org, will@kernel.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, robh+dt@kernel.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, kstewart@linuxfoundation.org, takahiro.akashi@linaro.org, tglx@linutronix.de, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [PATCH v10 3/8] powerpc: Move ima buffer functions to drivers/of/kexec.c Date: Fri, 4 Dec 2020 11:51:44 -0800 Message-Id: <20201204195149.611-4-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204195149.611-1-nramas@linux.microsoft.com> References: <20201204195149.611-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 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