From patchwork Wed Nov 14 17:55:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151108 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5992695ljp; Wed, 14 Nov 2018 09:56:04 -0800 (PST) X-Google-Smtp-Source: AJdET5dQhtLJVc6YV3BsFx8ObuzD4/7TjF2euTvBeHnI4MlJ+gnUT6qRTXUCdMtuWVv5mrP1BLhv X-Received: by 2002:a65:6684:: with SMTP id b4mr2657508pgw.55.1542218164255; Wed, 14 Nov 2018 09:56:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542218164; cv=none; d=google.com; s=arc-20160816; b=NQNrWZYAcfwGT2OlvU7KmXzJu3da6OBXMOEk0G5YDtnCjFBvcTFp61LvyPL+xt7edt hujDPPK5vxKdSDnvF4a+5AIy5t3YoRK7kqav8/MgiV04LrGa3eHT+6INp3Sfhsn+Td5i vdhlkcnvloOyrV92+It1DPEe7RYThY33Bhh3/Nds1+7KQP1Soc9oNj/ZLHsT/7o9OYt9 6bUXUoJiIW6j8OJU3J/U6Ibal4OR86mN7krHsdon9cESCRL7dNhmJDvxeXMEGUciSlzM OOPZIfUn8EaLqUy1EETo7CXiWXLaycwniha/c5D3ldqwzQ2aWtxlJsRBaroRiZvjauGR PfHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=cOfTDhyV/l13Z99YOBzTU4ASBnqPM4veTV3UrpNLU8U=; b=Q8p3rW8hbn4+ExY2Cj3bFdpZXpxC9ygvIqc4kcbDW4KIpuNDriOU2kkcsG1rakHy1u SDDdH0rBlhdRtGCjmexHKvbOXfhHJmLdEsrtZc89MKpaMPA+f2+ZYvp8MP28cTt0j3em UAa5oL8XGvw6jWLg3isUwaJxwOjuAGBCipclTQqhZXSopADeVfLq1It5jcPb0cj9Mix4 pho3fDnogyeOiVmsIk4EMabXwDkCSQdZlWk1YS1xJyWqNndLakHmgkW43OfB/Mi6/iVD cfk3lKqxq+QkBmxy/iswIy0Cw91LMU/bC4FTuBvmpW5uo6mzjiDe8w61qkwSa6xda6UU 5BAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LUmQUVU4; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 r12si24051442pgf.22.2018.11.14.09.56.04; Wed, 14 Nov 2018 09:56:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=LUmQUVU4; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 S1731710AbeKOEAN (ORCPT + 3 others); Wed, 14 Nov 2018 23:00:13 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34129 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732981AbeKOEAM (ORCPT ); Wed, 14 Nov 2018 23:00:12 -0500 Received: by mail-pg1-f195.google.com with SMTP id 17so7438206pgg.1 for ; Wed, 14 Nov 2018 09:56:01 -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; bh=cOfTDhyV/l13Z99YOBzTU4ASBnqPM4veTV3UrpNLU8U=; b=LUmQUVU4WyCs9MbRR4tnyN+m/kS3DLPM5Mvp6v9xlpe0WJ2amPcqceJxIFHZdIFjIs QndZSuuA7NjrYNIjrEuVE8m5/o+knkWZmJehE0m1TjvDZ2VgbovIZJKEYb62+Xjj+9JY 9RNIsJC2lq8l0zkrqYHRb9cgrkj/kpEWhtygo= 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; bh=cOfTDhyV/l13Z99YOBzTU4ASBnqPM4veTV3UrpNLU8U=; b=rpX2sHXXTML2KpWZSOjpe5Cfho5K6mZemCFDJBxtr5c0IEQelb7pCmzxZviL1M5SNd cOQVzVHnji9nDMuOHZcB5n6CUmkokVXpYNXNbTMcv0vYujiqbqXYi7wweNaBKLT3ZINA JBLXlXbFty6WR7YXPf4VT1m4KcfkfyMaiax+vYzU7n01s7rtbcVION2QwVN/PQINXDDR Kd1uIlufo1SFPxBIMmXNj/KTP1pkMjhnsJKWb/3Dua8UMBwaW0RPwzBd2rtGhQeI8NCP 0iMpooToiIxW6sU9hnZOls4+y45x/9DtZMKgSiJ97jJOVBjtmTWx782QhjHzPjAc0Y4B rsYg== X-Gm-Message-State: AGRZ1gK6n7nj8bxgiQpQ9NGOPt9GI1omgjGjVqaJe8vnnV1Rf2C7GuMr r3tCN4eKyBnUTCiecjN2wfjOP9LmQ2ll6w== X-Received: by 2002:a63:e80e:: with SMTP id s14mr2670371pgh.30.1542218160608; Wed, 14 Nov 2018 09:56:00 -0800 (PST) Received: from mba13.psav.com ([64.114.255.97]) by smtp.gmail.com with ESMTPSA id i2-v6sm21301738pgq.35.2018.11.14.09.55.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 09:55:59 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , 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 Message-Id: <20181114175544.12860-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114175544.12860-1-ard.biesheuvel@linaro.org> References: <20181114175544.12860-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@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.17.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: