From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4001:c0b::244; helo=mail-it0-x244.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-it0-x244.google.com (mail-it0-x244.google.com [IPv6:2607:f8b0:4001:c0b::244]) (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 1AC8C210F52B9 for ; Wed, 6 Jun 2018 05:10:00 -0700 (PDT) Received: by mail-it0-x244.google.com with SMTP id a195-v6so7686524itd.3 for ; Wed, 06 Jun 2018 05:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=KaOfAyXHeXsEuvMRaxb87KoYPS+z9g6XHZ7SGDNx5X4=; b=O/E/0p02seoXs1V08o9sZT0vTDfp6QnWjIip2SV/eF3zwJablihv8LhYMLaUq+5Gwv /XX2Ls5KdJGa2YjgAcPRBZYqhs/b3Y5xawvvQ7Oncle810FN037xA+wlkcrqtozAZzpc 3MbmBxSne3B0HkUxNRmJGeLLzaP22o+vPM3e4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=KaOfAyXHeXsEuvMRaxb87KoYPS+z9g6XHZ7SGDNx5X4=; b=MY+5EWnPc0CD8YpoBIadp0QGCWXHaHGBjk+bUbRgrgB3J9SspGdrqCtGDZahXwof1g H/NkA9ci8P1+cicN0R7DpXuMX82Ma/oZpSaJ1tylwLnxZN+bnyD/svpTiEsBw+5b5i6H lSpkX3VoLKlaAy0WtefyHbeDXwb7KwQIk+B/6ZIQtHLTKYzoHMmTdUZEBpTKMGo5ddkG bl68vTnNlU17OL6o46zNejaa9fI8r6CLBZLYh5y0MZ4CI2RFi/5/Kb5DmFG4czS3kUza 3xcCXvK6Zlv3HWMlFNqzc5jMJiSki33E5oTxvLJn9MFnozHw/3HICnuEn95emFB2Voa8 LCEg== X-Gm-Message-State: APt69E06gKzrmLnZZtFXQJcNCX12cAOuE1IlgV5433pIbY1GBf1gN2Nq KQFrYyi46lJk1fxG3VLGVhtYz6sY19d49qqhJi1UfUAm X-Google-Smtp-Source: ADUXVKIsUnvRIOydjq2EObZY+adma5VkeexUs9zbtyvX2Xn0IiSk3qDmYjNP/PLHCjSdjmiMkMTWgRIih/Y8xycJxag= X-Received: by 2002:a24:534e:: with SMTP id n75-v6mr2253440itb.138.1528286999945; Wed, 06 Jun 2018 05:09:59 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bb86:0:0:0:0:0 with HTTP; Wed, 6 Jun 2018 05:09:59 -0700 (PDT) In-Reply-To: <20180606095235.20822-1-ard.biesheuvel@linaro.org> References: <20180606095235.20822-1-ard.biesheuvel@linaro.org> From: Ard Biesheuvel Date: Wed, 6 Jun 2018 14:09:59 +0200 Message-ID: To: "edk2-devel@lists.01.org" Cc: Leif Lindholm , "Yao, Jiewen" , Ruiyu Ni , "Zeng, Star" , "Kinney, Michael D" , "Gao, Liming" , Ard Biesheuvel Subject: Re: [PATCH] MdeModulePkg/CapsulePei: clean Dcache before consuming capsule data X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jun 2018 12:10:01 -0000 Content-Type: text/plain; charset="UTF-8" On 6 June 2018 at 11:52, Ard Biesheuvel wrote: > When capsule updates are staged for processing after a warm reboot, > they are copied into memory with the MMU and caches enabled. When > the capsule PEI gets around to coalescing the capsule, the MMU and > caches may still be disabled, and so on architectures where uncached > accesses are incoherent with the caches (such as ARM and AARCH64), > we may read stale data if we don't clean the caches to memory first. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel Leif asked me to include a note why this cannot be done when UpdateCapsule() is called. """ Note that this cache maintenance cannot be done during the invocation of UpdateCapsule(), since the ScatterGatherList structures are only identified by physical address, and at runtime, the firmware doesn't know whether and where this memory is mapped, and cache maintenance requires a virtual address. """ > --- > MdeModulePkg/Universal/CapsulePei/CapsulePei.inf | 1 + > MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c | 4 ++++ > 2 files changed, 5 insertions(+) > > diff --git a/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf b/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf > index c54bc21a95a8..594e110d1f8a 100644 > --- a/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf > +++ b/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf > @@ -48,6 +48,7 @@ [Packages] > > [LibraryClasses] > BaseLib > + CacheMaintenanceLib > HobLib > BaseMemoryLib > PeiServicesLib > diff --git a/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c b/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c > index 3e7054cd38a9..1730f925adc5 100644 > --- a/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c > +++ b/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c > @@ -27,6 +27,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > #include > > #include > +#include > #include > #include > #include > @@ -283,6 +284,9 @@ ValidateCapsuleByMemoryResource ( > DEBUG ((EFI_D_INFO, "Address(0x%lx) Size(0x%lx) in MemoryResource[0x%x] - Start(0x%lx) Length(0x%lx)\n", > Address, Size, > Index, MemoryResource[Index].PhysicalStart, MemoryResource[Index].ResourceLength)); > + > + WriteBackDataCacheRange ((VOID *)(UINTN)Address, Size); > + > return TRUE; > } > } > -- > 2.17.0 >