From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::d44; helo=mail-io1-xd44.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 0F19A21B02822 for ; Wed, 19 Sep 2018 17:09:03 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id u12-v6so949924ioc.11 for ; Wed, 19 Sep 2018 17:09:03 -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=rLaXUJGz33il5ON14INEvWi++AB8Yv+2MBTEqgCQqQ4=; b=LxJNzn6VkEma1+dgKX/6uCNZbrMRwEKv9Fpc6rIaEzKmlc2fCqB6IbUmsvcr/mLS8O N/It4RrozTCJRpDAeCJ5P3yCqpWJdXXrEGYtgqLtsU+bCKINx41Ip39louRwmAhhoLem 5udhjJhYRUVx+IcE1GtKo4YMg2+zC6UqhNwMo= 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=rLaXUJGz33il5ON14INEvWi++AB8Yv+2MBTEqgCQqQ4=; b=P4TniyNukP99XNNExhrfNubjiTCgnpfWvjoRe3Vi/Ynvo4l/6tCD5VzwJrfT2TksVs 40LoTcJVoR/zkslYxhWcioaM9fLs9OhFQNgxm0FERuXUmg4PByQnE0vMFDt1xM9VY/aJ cKJ+x05HLMIVKlcszFAFaBF/xxWcNF8iu5WdFrwDw1wKrKdnpriqfBZZBbiwp2ZfE/l2 qom/Ka12sX4FxK2GcWHigt3fmeqKNNnC0uEh0OjxeXIVLZ2HVUCgNXXgoZIJk6dsXp0d 5I7MP+zVJmBTnWNbZ3JwuIbbBU03cjZSyneVcfLPRARU5zumiryxFxT4bWs2PnBMCEHJ YcyQ== X-Gm-Message-State: APzg51CBO9PyFj2V2LdUMQeEF3oMVCO8sZqwzkMoJJER7As4/I4YL0sl kH77kDf8jWxZKZCUqD7WSJ6InkKN3+Er9UX+oLFDhQ== X-Google-Smtp-Source: ANB0VdYl86alpB2IxhspuHEqiLuaQzJm/1eVnddgVXsiRX36kDC8GJ3Bvbt4rZQjKqA2RDr78dycHhZTIdK4RA3aWDs= X-Received: by 2002:a6b:be83:: with SMTP id o125-v6mr30976958iof.173.1537402143156; Wed, 19 Sep 2018 17:09:03 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:2848:0:0:0:0:0 with HTTP; Wed, 19 Sep 2018 17:09:02 -0700 (PDT) In-Reply-To: <0203a14be46555436db1c8d5e58064ae@mail.gmail.com> References: <0203a14be46555436db1c8d5e58064ae@mail.gmail.com> From: Ard Biesheuvel Date: Wed, 19 Sep 2018 17:09:02 -0700 Message-ID: To: Vladimir Olovyannikov Cc: "edk2-devel@lists.01.org" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: Stack issue after warm UEFI reset and MMU enabling on an Armv8 platform 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: , X-List-Received-Date: Thu, 20 Sep 2018 00:09:04 -0000 Content-Type: text/plain; charset="UTF-8" On 19 September 2018 at 16:58, Vladimir Olovyannikov < vladimir.olovyannikov@broadcom.com> wrote: > >From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > >Sent: Wednesday, September 19, 2018 4:38 PM > >To: Vladimir Olovyannikov > >Cc: edk2-devel@lists.01.org > >Subject: Re: Stack issue after warm UEFI reset and MMU enabling on an > Armv8 > >platform > > > >On 19 September 2018 at 15:55, Vladimir Olovyannikov > > wrote: > >>Hi All, > > >>I need UEFI experts help on the problem with Armv8 board on warm UEFI > >>reset. > >>Cold reset works fine. > > >>Here is how I set up a warm reset: > > >>STATIC > >>EFI_STATUS > >>ShutdownUefiBootServices ( > >> VOID > >> ) > >>{ > >> EFI_STATUS Status; > >> UINTN MemoryMapSize; > >> EFI_MEMORY_DESCRIPTOR *MemoryMap; > >> UINTN MapKey; > >> UINTN DescriptorSize; > >> UINT32 DescriptorVersion; > >> UINTN Pages; > > >> MemoryMap = NULL; > >> MemoryMapSize = 0; > >> Pages = 0; > >> > >> do { > >> Status = gBS->GetMemoryMap ( > >> &MemoryMapSize, > >> MemoryMap, > >> &MapKey, > >> &DescriptorSize, > >> &DescriptorVersion > >> ); > >> if (Status == EFI_BUFFER_TOO_SMALL) { > >> > >> Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1; > >> MemoryMap = AllocatePages (Pages); > >> > >> // > >> // Get System MemoryMap > >> // > >> Status = gBS->GetMemoryMap ( > >> &MemoryMapSize, > >> MemoryMap, > >> &MapKey, > >> &DescriptorSize, > >> &DescriptorVersion > >> ); > >> } > >> > >> // Don't do anything between the GetMemoryMap() and > ExitBootServices() > >> if (!EFI_ERROR(Status)) { > >> Status = gBS->ExitBootServices (gImageHandle, MapKey); > >> if (EFI_ERROR(Status)) { > >> FreePages (MemoryMap, Pages); > >> MemoryMap = NULL; > >> MemoryMapSize = 0; > >> } > >> } > >> } while (EFI_ERROR(Status)); > >> > >> return Status; > >>} > >> > >>Then perform > >>ArmCleanDataCache (); > >>ArmInvalidateDataCache (); > >>ArmDisableInstructionCache (); > >>ArmInvalidateInstructionCache (); > > >These don't do anything useful on ARM. You can only reliably perform cache > >maintenance by virtual address. > So, should I just remove them altogether? > > >>ArmDisableMmu (); > > >... so after this call returns, all bets are off with regards to whether > >what is popped from the stack is actually what we pushed when we entered > >the function. > OK, thank you for explanation. > But this call returns back into ResetLib implementation as it should, and > then there is a direct jump to the start of FV. > Am I doing anything wrong here? > Then, up to the point of enabling of MMU the stack is OK. But right after > enabling MMU it points at _ModuleEntryPoint end of function in > DxeCoreEntryPoint.c > Am I missing anything? Maybe some stack cleanup before jumping to the start > of FV? > > I guess you should be disabling interrupts as well. And quiesce all DMA capable devices like network controllers that may corrupt your memory.