From patchwork Wed Apr 10 09:02:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1083264 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.b="QkhIdsJX"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44fJ9t4KPRz9s0W for ; Wed, 10 Apr 2019 19:04:02 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2A9E8C21E02; Wed, 10 Apr 2019 09:03:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B9915C21E1E; Wed, 10 Apr 2019 09:03:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6C4B6C21DCA; Wed, 10 Apr 2019 09:03:15 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lists.denx.de (Postfix) with ESMTPS id 2393CC21CB1 for ; Wed, 10 Apr 2019 09:03:15 +0000 (UTC) Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3A926wG004909; Wed, 10 Apr 2019 11:03:12 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=xsssFZ7YCzVAZqhHosNMDTPXSRDOxlPqGtZX3edow6M=; b=QkhIdsJXFOcqK6Z9iLQjfD8gp5fW0JE+dcSubjmmJI2a1+B3M8kKuv7UMv/RL7d1CSOQ cVFh7dqOHqAphwvtNFTU6jwg3+4lKzrlcNDeyC/We2K7zw2vddSruR32ArRBjcQJZ6oY jGTwGufh7xcvyLttDbhDu9dpgcJnHpEZPuHMS4+y95CHIV7ri1e52X/hjbV9Yk0AMXKX U0BvK9tgCcZfJKc0fSnHN8O9mh1o/Rr+4HV1yjANJZyTuzS7qdNqqsmrdka2TwbsY0X4 GaMCBlImRC26Z6P9L+oOuVmFrVZj0df+YtoSVwFXs/qOnDT0ALY5qaYu3WOM0xxeFpUN og== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2rpr7wq1c2-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 10 Apr 2019 11:03:12 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A914343; Wed, 10 Apr 2019 09:03:11 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas22.st.com [10.75.90.92]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4F695127E; Wed, 10 Apr 2019 09:03:10 +0000 (GMT) Received: from SAFEX1HUBCAS24.st.com (10.75.90.95) by Safex1hubcas22.st.com (10.75.90.92) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 10 Apr 2019 11:03:10 +0200 Received: from localhost (10.201.23.85) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 10 Apr 2019 11:03:09 +0200 From: Patrick Delaunay To: Date: Wed, 10 Apr 2019 11:02:59 +0200 Message-ID: <1554886979-22890-3-git-send-email-patrick.delaunay@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1554886979-22890-1-git-send-email-patrick.delaunay@st.com> References: <1554886979-22890-1-git-send-email-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.85] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-04-10_05:, , signatures=0 Cc: U-Boot STM32 , Heinrich Schuchardt , Alexander Graf , Ilias Apalodimas Subject: [U-Boot] [PATCH 3/3] efi: update virtual address in efi_mem_carve_out X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Handle virtual address in efi_mem_carve_out function when a new region is created to avoid issue in EFI memory map. Signed-off-by: Patrick Delaunay --- Issue detected during test of test of UEFI on ev1/dk2 boards. For debug purpose, I add the dump of the map in efi_mem_sort: static void efi_mem_sort(void) { ..... int i = 0; printf("-- %s -------------------\n", __func__ ); list_for_each(lhandle, &efi_mem) { struct efi_mem_list *lmem; struct efi_mem_desc *cur; lmem = list_entry(lhandle, struct efi_mem_list, link); cur = &lmem->desc; printf("%02d: va %08x pa %08x size %08x (%04x pages) => va end %08x attribute = %llx type=%d\n", i++, (u32)cur->virtual_start, (u32)cur->physical_start, (u32)(cur->num_pages << EFI_PAGE_SHIFT), (u32)cur->num_pages, (u32) (cur->virtual_start + (cur->num_pages << EFI_PAGE_SHIFT)), cur->attribute, cur->type); } } I get the memory layout (for EV1): 00: va fcf87000 pa fff92000 size 0006e000 (006e pages) => va end fcff5000 attribute = 8 type=2 01: va fff91000 pa fff91000 size 00001000 (0001 pages) => va end fff92000 attribute = 8000000000000008 type=5 02: va fcf87000 pa fcf87000 size 0300a000 (300a pages) => va end fff91000 attribute = 8 type=2 03: va fcf86000 pa fcf86000 size 00001000 (0001 pages) => va end fcf87000 attribute = 8000000000000008 type=6 04: va fcf46000 pa fcf7d000 size 00009000 (0009 pages) => va end fcf4f000 attribute = 8 type=0 05: va fcf7c000 pa fcf7c000 size 00001000 (0001 pages) => va end fcf7d000 attribute = 8000000000000008 type=6 06: va fcf46000 pa fcf77000 size 00005000 (0005 pages) => va end fcf4b000 attribute = 8 type=0 07: va c0000000 pa c0000000 size 3cf77000 (3cf77 pages) => va end fcf77000 attribute = 8 type=7 But for some region virtual address (va) != physical address (pa) After check of the code, the virtual address is not correctly managed when new region is created. I don't sure that could be a issue, but I solve the issue with the proposed patch: 00: va fff92000 pa fff92000 size 0006e000 (006e pages) => va end 00000000 attribute = 8 type=2 01: va fff91000 pa fff91000 size 00001000 (0001 pages) => va end fff92000 attribute = 8000000000000008 type=5 02: va fcf87000 pa fcf87000 size 0300a000 (300a pages) => va end fff91000 attribute = 8 type=2 03: va fcf86000 pa fcf86000 size 00001000 (0001 pages) => va end fcf87000 attribute = 8000000000000008 type=6 04: va fcf7d000 pa fcf7d000 size 00009000 (0009 pages) => va end fcf86000 attribute = 8 type=0 05: va fcf7c000 pa fcf7c000 size 00001000 (0001 pages) => va end fcf7d000 attribute = 8000000000000008 type=6 06: va fcf77000 pa fcf77000 size 00005000 (0005 pages) => va end fcf7c000 attribute = 8 type=0 07: va c0000000 pa c0000000 size 3cf77000 (3cf77 pages) => va end fcf77000 attribute = 8 type=7 The virtual address are now correct. PS: I don't found more elegant code to update the virtual address but I avoid to force virtual_address = physical address in this function. lib/efi_loader/efi_memory.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 81dc5fc..a47adef 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -168,6 +168,16 @@ static s64 efi_mem_carve_out(struct efi_mem_list *map, free(map); } else { map->desc.physical_start = carve_end; + if (carve_end == map_end) + map->desc.virtual_start = + map_desc->virtual_start + + (map_desc->num_pages << EFI_PAGE_SHIFT); + else + map->desc.virtual_start = + carve_desc->virtual_start + + (carve_desc->num_pages << + EFI_PAGE_SHIFT); + map->desc.num_pages = (map_end - carve_end) >> EFI_PAGE_SHIFT; } @@ -186,6 +196,11 @@ static s64 efi_mem_carve_out(struct efi_mem_list *map, newmap = calloc(1, sizeof(*newmap)); newmap->desc = map->desc; newmap->desc.physical_start = carve_start; + if (carve_start == map_start) + newmap->desc.virtual_start = map_desc->virtual_start; + else + newmap->desc.virtual_start = carve_desc->virtual_start; + newmap->desc.num_pages = (map_end - carve_start) >> EFI_PAGE_SHIFT; /* Insert before current entry (descending address order) */ list_add_tail(&newmap->link, &map->link);