linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: linux-efi@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>, linux-kernel@vger.kernel.org
Subject: [PATCH 3/5] efi/arm: libstub: pack FDT after populating it
Date: Wed, 14 Nov 2018 09:55:42 -0800	[thread overview]
Message-ID: <20181114175544.12860-4-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20181114175544.12860-1-ard.biesheuvel@linaro.org>

Commit 24d7c494ce46 ("efi/arm-stub: Round up FDT allocation to mapping
size") increased the allocation size for the FDT image created by the
stub to a fixed value of 2 MB, to simplify the former code that made
several attempts with increasing values for the size. This is reasonable
given that the allocation is of type EFI_LOADER_DATA, which is released
to the kernel unless it is explicitly memblock_reserve()d by the early
boot code.

However, this allocation size leaked into the 'size' field of the FDT
header metadata, and so the entire allocation remains occupied by the
device tree binary, even if most of it is not used to store device tree
information.

So call fdt_pack() to shrink the FDT data structure to its minimum size
after populating all the fields, so that the remaining memory is no
longer wasted.

Cc: <stable@vger.kernel.org> # v4.12+
Fixes: 24d7c494ce46 ("efi/arm-stub: Round up FDT allocation to mapping size")
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 drivers/firmware/efi/libstub/fdt.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c
index 8830fa601e45..0c0d2312f4a8 100644
--- a/drivers/firmware/efi/libstub/fdt.c
+++ b/drivers/firmware/efi/libstub/fdt.c
@@ -158,6 +158,10 @@ static efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
 			return efi_status;
 		}
 	}
+
+	/* shrink the FDT back to its minimum size */
+	fdt_pack(fdt);
+
 	return EFI_SUCCESS;
 
 fdt_set_fail:
-- 
2.17.1


  parent reply	other threads:[~2018-11-14 17:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-14 17:55 [GIT PULL 0/5] EFI fixes for v4.20 Ard Biesheuvel
2018-11-14 17:55 ` [PATCH 1/5] efi: Fix debugobjects warning on efi_rts_work Ard Biesheuvel
2018-11-15  9:09   ` [tip:efi/urgent] efi: Fix debugobjects warning on 'efi_rts_work' tip-bot for Waiman Long
2018-11-14 17:55 ` [PATCH 2/5] efi: arm: revert deferred unmap of early memmap mapping Ard Biesheuvel
2018-11-15  9:10   ` [tip:efi/urgent] efi/arm: Revert " tip-bot for Ard Biesheuvel
2018-11-14 17:55 ` Ard Biesheuvel [this message]
2018-11-15  9:11   ` [tip:efi/urgent] efi/arm/libstub: Pack FDT after populating it tip-bot for Ard Biesheuvel
2018-11-14 17:55 ` [PATCH 4/5] efi/arm: defer persistent reservations until after paging_init() Ard Biesheuvel
2018-11-15  9:11   ` [tip:efi/urgent] efi/arm: Defer " tip-bot for Ard Biesheuvel
2018-11-14 17:55 ` [PATCH 5/5] efi: permit calling efi_mem_reserve_persistent from atomic context Ard Biesheuvel
2018-11-15  9:12   ` [tip:efi/urgent] efi: Permit calling efi_mem_reserve_persistent() " tip-bot for Ard Biesheuvel
2018-11-27 18:59   ` [PATCH 5/5] efi: permit calling efi_mem_reserve_persistent " Jeremy Linton
2018-11-27 19:16     ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181114175544.12860-4-ard.biesheuvel@linaro.org \
    --to=ard.biesheuvel@linaro.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).