From patchwork Wed Feb 1 13:11:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 93022 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2311387obz; Wed, 1 Feb 2017 05:12:10 -0800 (PST) X-Received: by 10.84.236.76 with SMTP id h12mr4350747pln.173.1485954730903; Wed, 01 Feb 2017 05:12:10 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y87si19077926pff.250.2017.02.01.05.12.10; Wed, 01 Feb 2017 05:12:10 -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=neutral (body hash did not verify) header.i=@linaro.org; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751172AbdBANLm (ORCPT + 2 others); Wed, 1 Feb 2017 08:11:42 -0500 Received: from mail-wm0-f49.google.com ([74.125.82.49]:36737 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751041AbdBANLj (ORCPT ); Wed, 1 Feb 2017 08:11:39 -0500 Received: by mail-wm0-f49.google.com with SMTP id c85so38536088wmi.1 for ; Wed, 01 Feb 2017 05:11:39 -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; bh=7+PYZMCN7IMmuzsq7p9AmbiOQ5VfckpdHFrCryhWTRI=; b=Nuc1/ds6FSB4Dy+NCIZwDS8If268OFHpCuKyN3zRvjGU1kCXLmi0/eh/e74zOCbdOX IqpySac7cqwfuafK0OgGopFjoIYJdXdeSZXqXXNTBIu3Ast4/7CGLJxxlynYNIJMCI4J 4ZuvnDxxas5thaxfMvLtM4WzdmzAJJoYsyHTE= 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; bh=7+PYZMCN7IMmuzsq7p9AmbiOQ5VfckpdHFrCryhWTRI=; b=hrz9nH9Jbb5KE2oQOZA0LmJ5s4c06ajYYNGepcMvLFBLgojJpFGQKeFCX314WrG3wz cYlTuie9fRORBhzrlsAogdHXrjnmovJ/uYhV89xQZJTy1kTfzWstJ+IFEhhXA0RNjJ4G b6n6imacuQ2t1XsZ82pqEu7lHHlmQ4s1EKeN5QRgP5TO0O8WbT0Je+Lv2W9hXh7qRuU2 HUTMVOJVJC0JA7qBjfOCD8DpnGHy/iP2vtbBy3pp/OhntwKrGmW9D1nkN1ysswixVpMS N1WDNAJeTrqI1V64JSmlUI4iSQlfHuizI5/2BgH8ft92EF6PKcfHT4J2LeuJfGef5l4B H1+A== X-Gm-Message-State: AIkVDXIDyyNSuBsg8OrPV9/nTJISxvy4kM42huDzi9kVvwVoJ3oiLvzrjA/dZpVFcvCiAQyV X-Received: by 10.28.20.144 with SMTP id 138mr17549516wmu.41.1485954698341; Wed, 01 Feb 2017 05:11:38 -0800 (PST) Received: from localhost.localdomain ([105.130.17.13]) by smtp.gmail.com with ESMTPSA id 40sm34210105wry.22.2017.02.01.05.11.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Feb 2017 05:11:37 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: leif.lindholm@linaro.org, matt@codeblueprint.co.uk, james.morse@arm.com, riku.voipio@linaro.org, Ard Biesheuvel Subject: [PATCH] efi: fdt: avoid FDT manipulation after ExitBootServices() Date: Wed, 1 Feb 2017 13:11:33 +0000 Message-Id: <1485954693-25750-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Some AArch64 UEFI implementations disable the MMU in ExitBootServices(), after which unaligned accesses to RAM are no longer supported. Commit abfb7b686a3e ("efi/libstub/arm*: Pass latest memory map to the kernel") fixed an issue in the memory map handling of the stub FDT code, but inadvertently created an issue with such firmwares, by moving some of the FDT manipulation to after the invocation of ExitBootServices(). However, the stub's libfdt implementation uses the ordinary, accelerated string functions, which rely on hardware handling of unaligned accesses, resulting in alignment faults when executed with the MMU off. Whether disabling the MMU in ExitBootServices() complies with the UEFI spec is unclear, but it is a reality we have to deal with, given that it wasn't a problem before commit abfb7b686a3e was applied. So fix the situation by moving the update_fdt_memmap() into the callback invoked by efi_exit_boot_services() right before it hits the button. Fixes: abfb7b686a3e ("efi/libstub/arm*: Pass latest memory map to the kernel") Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/fdt.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Tested-by: Riku Voipio diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c index 921dfa047202..260c4b4b492e 100644 --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -187,6 +187,7 @@ static efi_status_t update_fdt_memmap(void *fdt, struct efi_boot_memmap *map) struct exit_boot_struct { efi_memory_desc_t *runtime_map; int *runtime_entry_count; + void *new_fdt_addr; }; static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg, @@ -202,7 +203,7 @@ static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg, efi_get_virtmap(*map->map, *map->map_size, *map->desc_size, p->runtime_map, p->runtime_entry_count); - return EFI_SUCCESS; + return update_fdt_memmap(p->new_fdt_addr, map); } /* @@ -300,22 +301,13 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, priv.runtime_map = runtime_map; priv.runtime_entry_count = &runtime_entry_count; + priv.new_fdt_addr = (void *)*new_fdt_addr; status = efi_exit_boot_services(sys_table, handle, &map, &priv, exit_boot_func); if (status == EFI_SUCCESS) { efi_set_virtual_address_map_t *svam; - status = update_fdt_memmap((void *)*new_fdt_addr, &map); - if (status != EFI_SUCCESS) { - /* - * The kernel won't get far without the memory map, but - * may still be able to print something meaningful so - * return success here. - */ - return EFI_SUCCESS; - } - /* Install the new virtual address map */ svam = sys_table->runtime->set_virtual_address_map; status = svam(runtime_entry_count * desc_size, desc_size,