Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp286057rwd; Wed, 24 May 2023 18:22:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5nKMA7J3rxlCy7apDgpY0/Rflf+OFFfpErziTlq3ug9lG1XJqdm7QJGXKl5LQZOmHEuNLd X-Received: by 2002:a05:6a00:15c2:b0:636:f899:46a0 with SMTP id o2-20020a056a0015c200b00636f89946a0mr6628295pfu.15.1684977756835; Wed, 24 May 2023 18:22:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684977756; cv=none; d=google.com; s=arc-20160816; b=Co4dmTmhmfxEroOHPIVfJVejZ+81JxzO8XO411CXa7iyCdwp/vqvYd3AySWmUTaTHG GK1OgyhEt4A6SnrZy0s/TW6jA7WnRsQixjB2N2Kbfy6+GMshthpT0K/JyCxebjtfjyhC MsSjn6IRqwpmrpikrHkxNmfdD2EhTBpaxYtxAv85IPZqKa1lgE0P+TTaUq02R6Raf4dw 04k8yC8e7D4BZIR0KzikUusrFTdQqdlhJqmQgg6AR+0XBR0+pDXqHyplbfHzo5YNL8v2 V2U0ECVtdqb4UwQEuHkV9Pjua1l7JaMS6tx7m9zXvtQ3bM1b/rRstYnIOG+CUQRjEyqD 3xKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=GYXORPH9Aa0sbSNOwTnYvmbKlPz6c29vHnbAXsZauHI=; b=yVrH7oIhQXyty6kz+XBB7WQyKZnfXHM0PUzB5ZFjTbcjc4eWnGOtsqSGPDSgx8+/Jj 4TzAeI7KJb5svDUCEXIoyZF0EEw1OxT9LtCDGLAPW1UqgV2YP+Elh5//JoLxw15YLw56 U+FThIEugj0TPdf1eFiPRzJibjqhVXWG/J3g0MIhTy9GQgDcAOiaPbRra4ofM+oTw4jV +FOLLsIRUdjjQo4e+pWkyjt7UUdPFp04wYURKx8uYOWzETjyAL1G80oCZ2+gW7+3hcos jePSWQxxKh3V3jAtnC05/6+Rla9lx5waLE2py7MuKR/q0hBPJPcdiOrnXa8H86fszQLJ 2Wcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="eLDNp/Bs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r6-20020aa79ec6000000b006455a24291dsi170017pfq.368.2023.05.24.18.22.24; Wed, 24 May 2023 18:22:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="eLDNp/Bs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232941AbjEYAYS (ORCPT + 99 others); Wed, 24 May 2023 20:24:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbjEYAYQ (ORCPT ); Wed, 24 May 2023 20:24:16 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07C8E99; Wed, 24 May 2023 17:24:15 -0700 (PDT) Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34P0IoxI015451; Thu, 25 May 2023 00:23:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pp1; bh=GYXORPH9Aa0sbSNOwTnYvmbKlPz6c29vHnbAXsZauHI=; b=eLDNp/BskAxxEEIV5595cp3/gJeXOpQs+h+/NAXtLLMTdI523m7Fjo5fa8dhl4BCMoAe qOjEwwRp8kjnxtmHhQrT5s/VJuc2fjp8VK9fbseBX4mEgy6YHymSS0jaWkPCFUVcuohv dUXszQOUavnKBWnd7RUCh42cEkDWPo0S2NuvrI1W1DISIDztnDeydaw6b1rXHluM7Chc HRgyJTbLnWY0qssMXcxL/ZBYDkyz40bXQ5IZ9eL/xao1ihhBPoYgy0WaLaivOumgSXQ6 N5b6WNWdbVOmv62dJMG0DeoKNKLBlihXu3f/scQETm+CP/bdNOue6dGuFZpI1E/5EtnN mQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qsw14r1wq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 May 2023 00:23:55 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34P0JbuN017418; Thu, 25 May 2023 00:23:55 GMT Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qsw14r1wd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 May 2023 00:23:55 +0000 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34OKD9wR030486; Thu, 25 May 2023 00:23:53 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([9.208.129.114]) by ppma04wdc.us.ibm.com (PPS) with ESMTPS id 3qppe7pxbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 May 2023 00:23:53 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34P0NpVV30736832 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 May 2023 00:23:52 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CFD0B5803F; Thu, 25 May 2023 00:23:51 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F00D358056; Thu, 25 May 2023 00:23:50 +0000 (GMT) Received: from [9.47.158.152] (unknown [9.47.158.152]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 25 May 2023 00:23:50 +0000 (GMT) Message-ID: Date: Wed, 24 May 2023 20:23:50 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH v9 3/4] of: kexec: Refactor IMA buffer related functions to make them reusable Content-Language: en-US To: Jerry Snitselaar Cc: kexec@lists.infradead.org, devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nayna@linux.ibm.com, nasastry@in.ibm.com, mpe@ellerman.id.au, Rob Herring , Frank Rowand , Mimi Zohar , Rob Herring , Nageswara R Sastry , Coiby Xu References: <20230418134409.177485-1-stefanb@linux.ibm.com> <20230418134409.177485-4-stefanb@linux.ibm.com> From: Stefan Berger In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DqJp5bfZGdppm45NHAZGUR2XEZATPYuN X-Proofpoint-ORIG-GUID: MK9BHyVxceNUUI8v3cNO18slT98UCmiu Content-Transfer-Encoding: 7bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-24_17,2023-05-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1011 lowpriorityscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 impostorscore=0 mlxscore=0 adultscore=0 priorityscore=1501 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305240202 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/24/23 19:16, Jerry Snitselaar wrote: > On Tue, Apr 18, 2023 at 09:44:08AM -0400, Stefan Berger wrote: >> Refactor IMA buffer related functions to make them reusable for carrying >> TPM logs across kexec. >> >> Signed-off-by: Stefan Berger >> Cc: Rob Herring >> Cc: Frank Rowand >> Cc: Mimi Zohar >> Reviewed-by: Mimi Zohar >> Reviewed-by: Rob Herring >> Tested-by: Nageswara R Sastry >> Tested-by: Coiby Xu >> > > Reviewed-by: Jerry Snitselaar Thanks a lot for looking at the patches. Unfortunately this series only resolves the issue with the newer kexec call but we have seen systems where the older one is used for setting a crash kernel and when the crash happens we're back to square one. I have been trying to embed the log into the memory of the flattened of-device tree but that also turns out to be not so straight forward. Stefan >> --- >> v6: >> - Add __init to get_kexec_buffer as suggested by Jonathan >> >> v5: >> - Rebased on Jonathan McDowell's commit "b69a2afd5afc x86/kexec: Carry >> forward IMA measurement log on kexec" >> v4: >> - Move debug output into setup_buffer() >> --- >> drivers/of/kexec.c | 126 ++++++++++++++++++++++++++------------------- >> 1 file changed, 74 insertions(+), 52 deletions(-) >> >> diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c >> index 1373d7e0a9b3..fa8c0c75adf9 100644 >> --- a/drivers/of/kexec.c >> +++ b/drivers/of/kexec.c >> @@ -117,45 +117,57 @@ static int do_get_kexec_buffer(const void *prop, int len, unsigned long *addr, >> } >> >> #ifdef CONFIG_HAVE_IMA_KEXEC >> -/** >> - * ima_get_kexec_buffer - get IMA buffer from the previous kernel >> - * @addr: On successful return, set to point to the buffer contents. >> - * @size: On successful return, set to the buffer size. >> - * >> - * Return: 0 on success, negative errno on error. >> - */ >> -int __init ima_get_kexec_buffer(void **addr, size_t *size) >> +static int __init get_kexec_buffer(const char *name, unsigned long *addr, >> + size_t *size) >> { >> int ret, len; >> - unsigned long tmp_addr; >> unsigned long start_pfn, end_pfn; >> - size_t tmp_size; >> const void *prop; >> >> - prop = of_get_property(of_chosen, "linux,ima-kexec-buffer", &len); >> + prop = of_get_property(of_chosen, name, &len); >> if (!prop) >> return -ENOENT; >> >> - ret = do_get_kexec_buffer(prop, len, &tmp_addr, &tmp_size); >> + ret = do_get_kexec_buffer(prop, len, addr, size); >> if (ret) >> return ret; >> >> - /* Do some sanity on the returned size for the ima-kexec buffer */ >> - if (!tmp_size) >> + /* Do some sanity on the returned size for the kexec buffer */ >> + if (!*size) >> return -ENOENT; >> >> /* >> * Calculate the PFNs for the buffer and ensure >> * they are with in addressable memory. >> */ >> - start_pfn = PHYS_PFN(tmp_addr); >> - end_pfn = PHYS_PFN(tmp_addr + tmp_size - 1); >> + start_pfn = PHYS_PFN(*addr); >> + end_pfn = PHYS_PFN(*addr + *size - 1); >> if (!page_is_ram(start_pfn) || !page_is_ram(end_pfn)) { >> - pr_warn("IMA buffer at 0x%lx, size = 0x%zx beyond memory\n", >> - tmp_addr, tmp_size); >> + pr_warn("%s buffer at 0x%lx, size = 0x%zx beyond memory\n", >> + name, *addr, *size); >> return -EINVAL; >> } >> >> + return 0; >> +} >> + >> +/** >> + * ima_get_kexec_buffer - get IMA buffer from the previous kernel >> + * @addr: On successful return, set to point to the buffer contents. >> + * @size: On successful return, set to the buffer size. >> + * >> + * Return: 0 on success, negative errno on error. >> + */ >> +int __init ima_get_kexec_buffer(void **addr, size_t *size) >> +{ >> + int ret; >> + unsigned long tmp_addr; >> + size_t tmp_size; >> + >> + ret = get_kexec_buffer("linux,ima-kexec-buffer", &tmp_addr, &tmp_size); >> + if (ret) >> + return ret; >> + >> *addr = __va(tmp_addr); >> *size = tmp_size; >> >> @@ -188,72 +200,82 @@ int __init ima_free_kexec_buffer(void) >> } >> #endif >> >> -/** >> - * remove_ima_buffer - remove the IMA buffer property and reservation from @fdt >> - * >> - * @fdt: Flattened Device Tree to update >> - * @chosen_node: Offset to the chosen node in the device tree >> - * >> - * The IMA measurement buffer is of no use to a subsequent kernel, so we always >> - * remove it from the device tree. >> - */ >> -static void remove_ima_buffer(void *fdt, int chosen_node) >> +static int remove_buffer(void *fdt, int chosen_node, const char *name) >> { >> int ret, len; >> unsigned long addr; >> size_t size; >> const void *prop; >> >> - if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC)) >> - return; >> - >> - prop = fdt_getprop(fdt, chosen_node, "linux,ima-kexec-buffer", &len); >> + prop = fdt_getprop(fdt, chosen_node, name, &len); >> if (!prop) >> - return; >> + return -ENOENT; >> >> ret = do_get_kexec_buffer(prop, len, &addr, &size); >> - fdt_delprop(fdt, chosen_node, "linux,ima-kexec-buffer"); >> + fdt_delprop(fdt, chosen_node, name); >> if (ret) >> - return; >> + return ret; >> >> ret = fdt_find_and_del_mem_rsv(fdt, addr, size); >> if (!ret) >> - pr_debug("Removed old IMA buffer reservation.\n"); >> + pr_debug("Remove old %s buffer reserveration", name); >> + return ret; >> } >> >> -#ifdef CONFIG_IMA_KEXEC >> /** >> - * setup_ima_buffer - add IMA buffer information to the fdt >> - * @image: kexec image being loaded. >> - * @fdt: Flattened device tree for the next kernel. >> - * @chosen_node: Offset to the chosen node. >> + * remove_ima_buffer - remove the IMA buffer property and reservation from @fdt >> * >> - * Return: 0 on success, or negative errno on error. >> + * @fdt: Flattened Device Tree to update >> + * @chosen_node: Offset to the chosen node in the device tree >> + * >> + * The IMA measurement buffer is of no use to a subsequent kernel, so we always >> + * remove it from the device tree. >> */ >> -static int setup_ima_buffer(const struct kimage *image, void *fdt, >> - int chosen_node) >> +static void remove_ima_buffer(void *fdt, int chosen_node) >> +{ >> + if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC)) >> + return; >> + >> + remove_buffer(fdt, chosen_node, "linux,ima-kexec-buffer"); >> +} >> + >> +#ifdef CONFIG_IMA_KEXEC >> +static int setup_buffer(void *fdt, int chosen_node, const char *name, >> + phys_addr_t addr, size_t size) >> { >> int ret; >> >> - if (!image->ima_buffer_size) >> + if (!size) >> return 0; >> >> ret = fdt_appendprop_addrrange(fdt, 0, chosen_node, >> - "linux,ima-kexec-buffer", >> - image->ima_buffer_addr, >> - image->ima_buffer_size); >> + name, addr, size); >> if (ret < 0) >> return -EINVAL; >> >> - ret = fdt_add_mem_rsv(fdt, image->ima_buffer_addr, >> - image->ima_buffer_size); >> + ret = fdt_add_mem_rsv(fdt, addr, size); >> if (ret) >> return -EINVAL; >> >> - pr_debug("IMA buffer at 0x%pa, size = 0x%zx\n", >> - &image->ima_buffer_addr, image->ima_buffer_size); >> + pr_debug("%s at 0x%pa, size = 0x%zx\n", name, &addr, size); >> >> return 0; >> + >> +} >> + >> +/** >> + * setup_ima_buffer - add IMA buffer information to the fdt >> + * @image: kexec image being loaded. >> + * @fdt: Flattened device tree for the next kernel. >> + * @chosen_node: Offset to the chosen node. >> + * >> + * Return: 0 on success, or negative errno on error. >> + */ >> +static int setup_ima_buffer(const struct kimage *image, void *fdt, >> + int chosen_node) >> +{ >> + return setup_buffer(fdt, chosen_node, "linux,ima-kexec-buffer", >> + image->ima_buffer_addr, image->ima_buffer_size); >> } >> #else /* CONFIG_IMA_KEXEC */ >> static inline int setup_ima_buffer(const struct kimage *image, void *fdt, >> -- >> 2.38.1 >> > > > _______________________________________________ > kexec mailing list > kexec@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kexec