From patchwork Thu Nov 8 18:45:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 150590 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1189441ljp; Thu, 8 Nov 2018 10:46:08 -0800 (PST) X-Google-Smtp-Source: AJdET5cLB+Auw5wmLJ/ae81J9J9r2z8bayEi1MtwSF+82kUAbGfhC10YRD7sWf3BOTzEvu1o8y+n X-Received: by 2002:a17:902:5c4:: with SMTP id f62-v6mr5747497plf.18.1541702768796; Thu, 08 Nov 2018 10:46:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541702768; cv=none; d=google.com; s=arc-20160816; b=v3AmyBa2JUaYvZgF2sWmdkabbr0joS4AlTTaHMLkgc7p28Bf+oql+TbWZEJ8tGl/6u ELtGmH1+xxR7xwOWJ6DPboqi68aQGfeKy/mmhxCioZ3FsNeZo6HYiVlQGvhYJxpMo3wO V8IkimqIN9gxYj0/VbsGTfkCiaIDiS7Z9ghZ/aCXkcm8CC8V5O/U5CF6GPD/qkT+HY4t +L2gZ/mpdyi7Xc+GKOvINg2Ihdni/UhTDx55l9sImDw3ITrGE99Ul1Dh9aRbehePayLF aD+T70x+pwHjp1G4vDzJemNPsASQws5umG2trkzpBIwtq/bT7I6VR6SbnC0bauUB2CxF YuLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=svv4icOA/PLLp4pWg49FRxBLSDkgY5saoGFcbE40oh0=; b=xEwmvXj3gGC743uu7YupcRnDuIO8rv4VFUAPe6+fJ6sARrq8IAzWkekIWaltdVYtwz BkiSn5BI41d3R+KcUTomkwDha9Zm97tQZqXICz9BkVLIhgSeLgulGc7I3GQhC/dQxnAl CSaiO+WYXbDWm+o+kV5X844JPCevQbSJ/HMq6rijSxTL3lBZbN0uoe7Ttmt9e4ki1ihJ VJ8dapTfQWm5cO2Teitl1IB/wCgvYLNKTjKLcETU90gB7Cd44xVXl47vJLbWhxYO7awg 0gxtWBU+RRX+Znq3RC9veP0LR31RzxApj3FhDGCeuGlO6dN58awxHFS3xDYLBiFflhZI o28w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dRf+KSMM; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i25-v6si4199518pgi.426.2018.11.08.10.46.08; Thu, 08 Nov 2018 10:46:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dRf+KSMM; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727369AbeKIEWy (ORCPT + 15 others); Thu, 8 Nov 2018 23:22:54 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40347 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727005AbeKIEWy (ORCPT ); Thu, 8 Nov 2018 23:22:54 -0500 Received: by mail-wm1-f66.google.com with SMTP id b203-v6so2183677wme.5 for ; Thu, 08 Nov 2018 10:46:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=svv4icOA/PLLp4pWg49FRxBLSDkgY5saoGFcbE40oh0=; b=dRf+KSMMrld5OgIhDJ/OqLb00o/KqD8/6q93P7oq+4tOz2OdBnTK2ivy2bXIO2kN8L yAD+tvB1QVu6S3aB/GNxNrSaVwWkkb6F40wgV3POYECPjRJng+GnJB4XCiUO/YlNfg/4 bHAk5fnqvEZRL9vBYSfUGrieyBlVap0XsqYo0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=svv4icOA/PLLp4pWg49FRxBLSDkgY5saoGFcbE40oh0=; b=D/1WRVuC3fYlgw7V4oMI4i1BwpxmO/5ITE5QoeAySH3XgMaV5vhWU4/ZbQMomLYArR PYAIQFW0NFdMUK7dAh4gQEmA2Cag7xzdkJ9fkptp9cxhn/4dIWs52eVkrDE0e5t9kStJ b9KtsPPVe6Ho8CSPUFMx4YphUC6U7AuIQ4LHvdJASY041Aaioysfm5LHYDAxIPVK8iUO tB8fi4T8lz1i7ocXpAFK7Iz6FhW+nEiT8DmNu6OTvnpiiYZNhr1V0XcFxY8aC7WgvczM Bs9qF6QJAMvfJY7B8LTlq+tAJDBeolxikxgiTCW/aOFqaBJSt/pCxKDs5pGAmHr3wp5A 1N4Q== X-Gm-Message-State: AGRZ1gJg5GOwBIGs8mnzi8n0jYA8Mh1H1yYYzLAFOnD8njZwrqiby3ab SCv2upfBod3VpdRjw56d+ZrpIw== X-Received: by 2002:a1c:2283:: with SMTP id i125-v6mr2298238wmi.42.1541702764925; Thu, 08 Nov 2018 10:46:04 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:744a:cf78:9aaa:a66d]) by smtp.gmail.com with ESMTPSA id r2-v6sm2821050wrq.1.2018.11.08.10.46.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 10:46:04 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, marc.zyngier@arm.com, mark.rutland@arm.com, leif.lindholm@linaro.org, Ard Biesheuvel , stable@vger.kernel.org Subject: [PATCH 2/2] efi/arm: libstub: pack FDT after populating it Date: Thu, 8 Nov 2018 19:45:52 +0100 Message-Id: <20181108184552.14366-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108184552.14366-1-ard.biesheuvel@linaro.org> References: <20181108184552.14366-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.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: # v4.12+ Fixes: 24d7c494ce46 ("efi/arm-stub: Round up FDT allocation to mapping size") Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/fdt.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.19.1 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: