Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp828979pxb; Tue, 9 Feb 2021 13:43:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJw94Kmj/VFTZutFlThnVE/AKK4Hg1T5TIJ2QzR3r6F2ywIWlULoa2Zomodwh+GUSIx+bt0w X-Received: by 2002:a17:906:cc50:: with SMTP id mm16mr24442069ejb.366.1612907024531; Tue, 09 Feb 2021 13:43:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612907024; cv=none; d=google.com; s=arc-20160816; b=VwXttn1Go2SFAkYPfr0RYZM7QfQvc6QzHhARL2M98AcM9Ql9ZpIEOVClhd+BfqaAGy 5A5QFFhwRpkEYEb8N+LXdnrPOHRDIdgiSXCksGWwI1LSEutqN+WlUunOfwruGP001bi0 s6vdJV5p9wakeaAO1YehQ1Vn/iCrZUL2fjoMnFQUpfTBqSw+bs64ja3Oyw/iCusmRWPP 24MarePzoc6+pHqYTF27eWaL0oB75PApprCm/Twwk5lFBmMQyjRJZOEj1CaefUwrYRKW bNijalkGl7dnDgolOfYevMrtHhxjAu8sOeex63rvmE6g+Wx+SGEIHsSKSa3PMaSWLsuC BW6Q== 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=JLtKdep8ljX0R5HJlVcxKOGy6sWLOe65FEwvEma/Tow=; b=PxTTYTAqIY3STO3M1QpogJ9yfWQSs+GyvPJtqluqNUZTUmEzy45Q2YPLPPqpunLTPF kmKTDC1EUcCnThwhmhqw46buI3R7PshQwO7ON7V1xUm8jV3MJqU95/yj6oP5Trxkz8sg Zm7c2hXHgVaD5X71iPKcqSo44kZppC0G2tMynDzrN/PW8RlInCm5kJfiM1Wrd6vszqGW igvCCHbLPIsfaX9o5VR6qjn/PjQ7VXBkEzpr/PSzEkn6acRTpKldk9aHUaPUqv7akL2l J7mmpqfCr4MslAs3sGEhroBJmryND7LVCj+VldklSnVXTz1N/sHdzYFtV5kN5dFSmX/z lhOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=PBD7RXYs; 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 p5si15166321edq.266.2021.02.09.13.43.20; Tue, 09 Feb 2021 13:43:44 -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=PBD7RXYs; 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 S234102AbhBIVi6 (ORCPT + 99 others); Tue, 9 Feb 2021 16:38:58 -0500 Received: from linux.microsoft.com ([13.77.154.182]:35218 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233600AbhBITHl (ORCPT ); Tue, 9 Feb 2021 14:07:41 -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 4D95C20B57A6; Tue, 9 Feb 2021 10:22:34 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4D95C20B57A6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1612894954; bh=JLtKdep8ljX0R5HJlVcxKOGy6sWLOe65FEwvEma/Tow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PBD7RXYsF8q0LZAzmADiN7/ouC8eUXPAzLUM05ZQ6i1VYiQNuC+r/YCxt1nKOk1f5 rCeNY0xD+383Qk5t1gRfsIBsy5bPSbaGG9xtfejxVbWqX37Fvgu7la2cpXm0SZaEJN 1DZIiFMdApEwIY0nvoaKKjQmCCCFHAks4YQngC+k= 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, joe@perches.com, 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, 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, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v17 08/10] kexec: Use fdt_appendprop_addrrange() to add ima buffer to FDT Date: Tue, 9 Feb 2021 10:21:58 -0800 Message-Id: <20210209182200.30606-9-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210209182200.30606-1-nramas@linux.microsoft.com> References: <20210209182200.30606-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 fdt_appendprop_addrrange() function adds a property, with the given name, to the device tree at the given node offset, and also sets the address and size of the property. This function should be used to add "linux,ima-kexec-buffer" property to the device tree and set the address and size of the IMA measurement buffer, instead of using custom function. Use fdt_appendprop_addrrange() to add "linux,ima-kexec-buffer" property to the device tree. This property holds the address and size of the IMA measurement buffer that needs to be passed from the current kernel to the next kernel across kexec system call. Remove custom code that is used in setup_ima_buffer() to add "linux,ima-kexec-buffer" property to the device tree. Co-developed-by: Prakhar Srivastava Signed-off-by: Prakhar Srivastava Signed-off-by: Lakshmi Ramasubramanian Reviewed-by: Thiago Jung Bauermann --- drivers/of/kexec.c | 57 ++++------------------------------------------ 1 file changed, 5 insertions(+), 52 deletions(-) diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c index c601b5af4a88..c53746b9b168 100644 --- a/drivers/of/kexec.c +++ b/drivers/of/kexec.c @@ -232,36 +232,6 @@ int of_ima_add_kexec_buffer(struct kimage *image, return 0; } -/** - * write_number - Convert number to big-endian format - * - * @p: Buffer to write the number to - * @value: Number to convert - * @cells: Number of cells - * - * Return: 0 on success, or negative errno on error. - */ -static int write_number(void *p, u64 value, int cells) -{ - if (cells == 1) { - u32 tmp; - - if (value > U32_MAX) - return -EINVAL; - - tmp = cpu_to_be32(value); - memcpy(p, &tmp, sizeof(tmp)); - } else if (cells == 2) { - u64 tmp; - - tmp = cpu_to_be64(value); - memcpy(p, &tmp, sizeof(tmp)); - } else - return -EINVAL; - - return 0; -} - /** * setup_ima_buffer - add IMA buffer information to the fdt * @image: kexec image being loaded. @@ -273,32 +243,15 @@ static int write_number(void *p, u64 value, int cells) static int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node) { - int ret, addr_cells, size_cells, entry_size; - u8 value[16]; + int ret; if (!image->ima_buffer_size) return 0; - ret = get_addr_size_cells(&addr_cells, &size_cells); - if (ret) - return ret; - - entry_size = 4 * (addr_cells + size_cells); - - if (entry_size > sizeof(value)) - return -EINVAL; - - ret = write_number(value, image->ima_buffer_addr, addr_cells); - if (ret) - return ret; - - ret = write_number(value + 4 * addr_cells, image->ima_buffer_size, - size_cells); - if (ret) - return ret; - - ret = fdt_setprop(fdt, chosen_node, "linux,ima-kexec-buffer", value, - entry_size); + ret = fdt_appendprop_addrrange(fdt, 0, chosen_node, + "linux,ima-kexec-buffer", + image->ima_buffer_addr, + image->ima_buffer_size); if (ret < 0) return -EINVAL; -- 2.30.0