From patchwork Tue Nov 20 14:33:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151590 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp681630ljp; Tue, 20 Nov 2018 06:39:34 -0800 (PST) X-Google-Smtp-Source: AJdET5dgoJY9KtM/w0OMRgM5HxMp1TTJH7xpOTZUCydeIhjSmDHaD/eV8xQYUZM9okw4M2I9py+B X-Received: by 2002:a62:470f:: with SMTP id u15-v6mr2433562pfa.107.1542724774365; Tue, 20 Nov 2018 06:39:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542724774; cv=none; d=google.com; s=arc-20160816; b=i7OBvuJui7anqmi6gfF9UgQ7mZ9ty3vVI37VwG5SpqRiJOlw8kaaeIbKJ9pPh5hnoa SGgdBDoF6MvM5E9CmgZuBo8hP+6/V4zhOOOsPSh2SWCgayZ2yyLQH/DQzSDRpTssm0hC bqlcmPJZ6HgIZ/CP1qLON4W7Uty9jl0qttMHVxWU0CVpe1eDeuE7BHHZKMO+V9O4e8DK IBddpBQnrXkrv3XHohxqnf/O+DEVDgiCwFkslv8msguUDlBViTdXTbhh4g7+BgV21xf3 k+6WamPocSAAsidpUStekeEcTfxObRF/l+bn4EL/S03JPvOe36dT3NuNRtXZ5mZimp0c MRTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to; bh=XOclhvyXsy7rML+jQRhepUB2ZVxtUPiJf1wXFy3Mz+w=; b=N2WRriz39twUYxxzlWhR24eSLvq8vq6JVOrvZe+o6j0/BHwVz1ya3sSQAPfdvKzmRZ dCr/ogVSrYEJOWUvwxFWe3BXUCSZrmQJs0Tl6Kik8NQgXMJog0RPU/9+zqTptoca5Wg7 wK+iphrZPkfTeDC1H5xJnUnNPlesSV4qi+kc+mfKl2MedCaKOJad60SHnCfTetWfr1eP LBhlpo2d9ILsW8HgzBLNayA0ULfhY4hR1sbk6ne/2yGHTNV/CXV1lngmqnD7BDygdvjF rowYvw9tz0tAcGuNTPeNuY8m0elV+4j3099DJg6ZAIRvhHBg0gEbkWstNmEpW+17lErk kMrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JoEfPZkd; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id e2si41080906pgs.94.2018.11.20.06.39.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 06:39:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JoEfPZkd; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8B5BC21959CB2; Tue, 20 Nov 2018 06:39:32 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::542; helo=mail-ed1-x542.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0E48A21193595 for ; Tue, 20 Nov 2018 06:33:05 -0800 (PST) Received: by mail-ed1-x542.google.com with SMTP id x30so2118871edx.2 for ; Tue, 20 Nov 2018 06:33: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; bh=omYC6H03Zl6GRTSYqWgPpv2S7sGzXTD8F3QggdI55rI=; b=JoEfPZkdbPNkEP+IMsc+mGLmOurAwnsFl1xffPudAj2d2+TAmR1+7RxUBDKNMgKZwQ V3r8AUnvXGIdYZhtslsC6D/h6xXG/rnAcp89DV6kohBwK5GaYw+tN3lja0f1CGcdNmnM cQzUWHnd6+NC/lm3YJ5StHyBFe8XJq1qveDNo= 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=omYC6H03Zl6GRTSYqWgPpv2S7sGzXTD8F3QggdI55rI=; b=LMhpWsOFWerzQDL59UdYlnhMOXvT7m6bzRI4K2r6/8oUxfeq6wV6jVM4Ybh90c8h/D 4IM0nomf5RFPaXWW7F0NtmxPIcHiDRNzxUhkXBj1E8e/Ti4HNsfM/SOcXsITg0ZfBMcv C8cux+ApBPyrQyW6zZ/xezikRACg1HrdqEcXlV2nJOf3ayy9ZCrfCkqz2cn+phtxN405 5t4HgsiJ7GAJUt37J78nFfn5Q9Z0whDmO/p/wkyth7kypc5j1z1hIaMLQLa0dDToFk8d 7hXubKxV7jJqml0k8l2Ghz9+BqNCtJgqkfIAZ7sWkZLtxuDYMP8vEfVHSpZjMOUCZ2NT LwGA== X-Gm-Message-State: AA+aEWYaADJsAh0IIjHqliccA5kbOj2smEYtqW1LEs4Ma4fNJhtUzQPR 8/ibHAFveJfT7k/OdUPl90n1wR5slk1yxA== X-Received: by 2002:a50:89e1:: with SMTP id h30mr2519324edh.28.1542724383879; Tue, 20 Nov 2018 06:33:03 -0800 (PST) Received: from mba13.wifi.ns.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id d2sm7817233eda.92.2018.11.20.06.33.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 06:33:02 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 20 Nov 2018 15:33:00 +0100 Message-Id: <20181120143300.26751-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Subject: [edk2] [PATCH] ArmPkg/ArmSmcPsciResetSystemLib: add missing call to ExitBootServices() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Our poor man's implementation of EnterS3WithImmediateWake () currently sets a high TPL level to disable interrupts, and simply calls the PEI entrypoint again after disabling the MMU. Unfortunately, this is not sufficient: DMA capable devices such as network controllers or USB controllers may still be enabled and writing to memory, e.g., in response to incoming network packets. So instead, do the full ExitBootServices() dance: allocate space and get the memory map, call ExitBootServices(), and in case it fails, get the memory map again and call ExitBootServices() again. This ensures that all cleanup related to DMA capable devices is performed before doing the warm reset. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmPkg/Include/Library/ArmLib.h | 1 + ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c | 51 ++++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm diff --git a/ArmPkg/Include/Library/ArmLib.h b/ArmPkg/Include/Library/ArmLib.h index e46df447b33d..ffda50e9d767 100644 --- a/ArmPkg/Include/Library/ArmLib.h +++ b/ArmPkg/Include/Library/ArmLib.h @@ -59,6 +59,7 @@ typedef enum { typedef struct { EFI_PHYSICAL_ADDRESS PhysicalBase; + EFI_VIRTUAL_ADDRESS VirtualBase; UINT64 Length; ARM_MEMORY_REGION_ATTRIBUTES Attributes; } ARM_MEMORY_REGION_DESCRIPTOR; diff --git a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c index 10ceafd14d5d..c9c42ab3b244 100644 --- a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c +++ b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c @@ -1,7 +1,7 @@ /** @file ResetSystemLib implementation using PSCI calls - Copyright (c) 2017, Linaro Ltd. All rights reserved.
+ Copyright (c) 2017 - 2018, Linaro Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -92,7 +92,13 @@ EnterS3WithImmediateWake ( VOID ) { - VOID (*Reset)(VOID); + VOID (*Reset)(VOID); + EFI_PHYSICAL_ADDRESS Alloc; + EFI_MEMORY_DESCRIPTOR *MemMap; + UINTN MemMapSize; + UINTN MapKey, DescriptorSize; + UINT32 DescriptorVersion; + EFI_STATUS Status; if (FeaturePcdGet (PcdArmReenterPeiForCapsuleWarmReboot) && !EfiAtRuntime ()) { @@ -103,7 +109,46 @@ EnterS3WithImmediateWake ( // Reset = (VOID (*)(VOID))(UINTN)FixedPcdGet64 (PcdFvBaseAddress); - gBS->RaiseTPL (TPL_HIGH_LEVEL); + // + // Obtain the size of the memory map + // + MemMapSize = 0; + Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, + &DescriptorVersion); + ASSERT (Status == EFI_BUFFER_TOO_SMALL); + + // + // Add some slack to the allocation to cater for changes in the memory + // map if ExitBootServices () fails the first time around. + // + MemMapSize += SIZE_4KB; + Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, + EFI_SIZE_TO_PAGES (MemMapSize), &Alloc); + ASSERT_EFI_ERROR (Status); + + MemMap = (EFI_MEMORY_DESCRIPTOR *)(UINTN)Alloc; + + Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, + &DescriptorVersion); + ASSERT_EFI_ERROR (Status); + + Status = gBS->ExitBootServices (gImageHandle, MapKey); + if (EFI_ERROR (Status)) { + // + // ExitBootServices () may fail the first time around if an event fired + // right after the call to GetMemoryMap() which allocated or freed memory. + // Since that first call to ExitBootServices () will disarm the timer, + // this is guaranteed not to happen again, so one additional attempt + // should suffice. + // + Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, + &DescriptorVersion); + ASSERT_EFI_ERROR (Status); + + Status = gBS->ExitBootServices (gImageHandle, MapKey); + ASSERT_EFI_ERROR (Status); + } + ArmDisableMmu (); Reset (); }