Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33DA3C001E0 for ; Fri, 28 Jul 2023 08:38:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BBD258685B; Fri, 28 Jul 2023 10:38:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="afI+y7nz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B46AA86885; Fri, 28 Jul 2023 10:38:30 +0200 (CEST) Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4C4F9865EB for ; Fri, 28 Jul 2023 10:38:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=n-jain1@ti.com Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 36S8cDuT015133; Fri, 28 Jul 2023 03:38:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1690533493; bh=6mPNA9KFgBNlaC1AdF9DLQej3IErMuZCsCUJNaC4jwk=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=afI+y7nzS4AYOwJXbzWHIS7/+mboMeiMNM+XmgibeEEueRUziDv0I+5l0QFHN7Wi5 Jke/0DYHEG/f3Tpt/6G1CjQDsZbCk8w/m/inRWkI0Rt68hs2Dvwgg7SYSdDMxNUo9X k0cP9D+wd6GnjQrUDsKy7fxFDLvb+AS6x8eymwKo= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 36S8cDfu000713 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 28 Jul 2023 03:38:13 -0500 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Fri, 28 Jul 2023 03:38:11 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Fri, 28 Jul 2023 03:38:11 -0500 Received: from [172.24.227.117] (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 36S8c7Ua045257; Fri, 28 Jul 2023 03:38:08 -0500 Message-ID: <7b7e65d4-1d7e-9196-bd28-7c4e849b6e72@ti.com> Date: Fri, 28 Jul 2023 14:08:07 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 5/9] board_f: Fix corruption of relocaddr Content-Language: en-US From: Nikhil M Jain To: Simon Glass CC: Devarsh Thakkar , U-Boot Mailing List , Bin Meng , Michal Suchanek , Ovidiu Panait , =?UTF-8?Q?Pali_Roh=c3=a1r?= , Rasmus Villemoes , Stefan Roese , "Raghavendra, Vignesh" , "Luthra, Jai" , "Bhatia, Aradhya" References: <20230724145210.304917-1-sjg@chromium.org> <20230724145210.304917-5-sjg@chromium.org> <7ebbe689-4419-765a-d890-3b9d371c8afc@ti.com> <5b5a2692-2590-bdf3-c255-3a402aa47225@ti.com> In-Reply-To: <5b5a2692-2590-bdf3-c255-3a402aa47225@ti.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On 28/07/23 14:05, Nikhil M Jain wrote: > Hi Simon, > > On 27/07/23 23:31, Simon Glass wrote: >> Hi Nikhil, >> >> On Wed, 26 Jul 2023 at 23:22, Nikhil M Jain wrote: >>> >>> Hi Simon, >>> >>> On 27/07/23 06:23, Simon Glass wrote: >>>> Hi Devarsh, >>>> >>>> On Wed, 26 Jul 2023 at 05:09, Devarsh Thakkar wrote: >>>>> >>>>> Hi Simon, >>>>> >>>>> On 26/07/23 02:58, Simon Glass wrote: >>>>>> Hi Devarsh, >>>>>> >>>>>> On Tue, 25 Jul 2023 at 03:21, Devarsh Thakkar >>>>>> wrote: >>>>>>> >>>>>>> Hi Simon, >>>>>>> >>>>>>> On 24/07/23 20:22, Simon Glass wrote: >>>>>>>> When the video framebuffer comes from the bloblist, we should >>>>>>>> not change >>>>>>>> relocaddr to this address, since it interfers with the normal >>>>>>>> memory >>>>>>>> allocation. >>>>>>>> >>>>>>>> This fixes a boot loop in qemu-x86_64 >>>>>>>> >>>>>>>> Signed-off-by: Simon Glass >>>>>>>> Fixes: 5bc610a7d9d ("common: board_f: Pass frame buffer info >>>>>>>> from SPL to u-boot") >>>>>>>> --- >>>>>>>> >>>>>>>>    common/board_f.c | 1 - >>>>>>>>    1 file changed, 1 deletion(-) >>>>>>>> >>>>>>>> diff --git a/common/board_f.c b/common/board_f.c >>>>>>>> index 7d2c380e91e2..5c8646b22283 100644 >>>>>>>> --- a/common/board_f.c >>>>>>>> +++ b/common/board_f.c >>>>>>>> @@ -419,7 +419,6 @@ static int reserve_video(void) >>>>>>>>                 if (!ho) >>>>>>>>                         return log_msg_ret("blf", -ENOENT); >>>>>>>>                 video_reserve_from_bloblist(ho); >>>>>>>> -             gd->relocaddr = ho->fb; >>>>>>> >>>>>>> I think this change was done as relocaddr pointer was required to >>>>>>> be updated >>>>>>> to move after frame-buffer reserved area to ensure that any >>>>>>> further memory >>>>>>> reservations done using gd->relocaddr (for e.g. in >>>>>>> reserve_trace/uboot/malloc) >>>>>>> don't overlap with frame-buffer reserved area passed from blob, >>>>>>> so I think >>>>>>> removing this line may cause further memory reservations to >>>>>>> overlap with >>>>>>> reserved framebuffer. >>>>>>> >>>>>>> Could you please confirm? >>>>>> >>>>>> SPL and U-Boot have different memory layouts. The current code is >>>>>> interrupting U-Boot's careful building up of chunks of memory used >>>>>> for >>>>>> different purposes. >>>>>> >>>>> >>>>> But it is possible they could be using similar memory layout for some >>>>> components like framebuffer. >>>>> For e.g. in our case we are using same video_reserve func in A53 >>>>> SPL too >>>>> and which allocates framebuffer from gd->relocaddr as seen here: >>>>> >>>>> https://source.denx.de/u-boot/u-boot/-/blob/v2023.10-rc1/common/board_f.c?ref_type=tags#L427 >>>> >>>> Even if it is similar, the point is that U-Boot proper needs to do its >>>> own allocation stuff. >>>> >>>> Of course, if SPL sets up the video, it will provide the framebuffer >>>> address, but only that. The other addresses need to be done using the >>>> normal mechanism. >>>> >>>>> >>>>>> The video memory has already been allocated by SPL, so we don't need >>>>>> to insert a new one here, as your code demonstrates. >>>>>> >>>>> >>>>> Agreed. >>>>> >>>>>> But also we have no way of knowing if it is legal to relocate U-Boot >>>>>> (and various other things) just below the frame buffer chosen by SPL. >>>>>> >>>>> >>>>> Yes, so i suppose your case is that framebuffer address which is >>>>> being passed >>>>> by SPL is totally disjoint and too far away from gd->relocaddr, for >>>>> e.g. it is >>>>> at the start (or bottom of DDR) and doesn't interfere with >>>>> gd->relocaddr in >>>>> any manner since relocaddr points to ramtop (i.e. near to end >>>>> address of DDR). >>>>> >>>>> In that case I agree it doesn't make sense to move relocaddr to >>>>> ho->fb. >>>>> >>>>> But for the scenario where gd->relocaddr and ho->fb are nearby >>>>> there is every >>>>> possibility that gd->relocaddr may overlap with framebuffer, also >>>>> the code in >>>>> reserve_trace, reserve_uboot doesn't have any intelligence or check >>>>> that it is >>>>> overlapping with framebuffer area or not. >>>>> >>>>> I think one thing that can probably be done here is to have a check >>>>> that if >>>>> passed framebuffer area falls within current relocaddr region, then >>>>> update the >>>>> relocaddr else don't touch relocaddr : >>>>> >>>>> if (ho->fb <= gd->relocaddr - ho->size) Just a small correction here if (ho->fb >= gd->relocaddr - ho->size) >>>>>     //It means framebuffer are is overlapping with current >>>>> relocaddr so update >>>>> relocaddr >>>>>       gd->relocaddr = ho->fb > > We should go ahead with this check because it won't disrupt u-boot's > allocation of memory and will allow both the cases if a platform is > using same memory layout or different memory layout across SPL and > u-boot proper. Below are the logs for both scenarios. > > https://gist.github.com/NikMJain/aca198ae77b6f1855459bc8fbdd683df > >>>>> else >>>>>     //don't update gd->relocaddr since ho->fb is disjoint to >>>>> gd->relocaddr >>>>> >>>>> Could you please share your opinion on this and if above logic >>>>> suffice your >>>>> case too ? >>>> >>>> I don't think this line is needed at all, which is why this patch >>>> removes it. What problem are you seeing? >>>> >>> Across SPL stage and U-boot we are keeping same memory layout and >>> ensuring that same memory regions are used, this way it doesn't >>> interfere in the way of u-boot while allocating memory regions for >>> various purposes. This allowed us to display splash screen without any >>> flicker across the stages. >>> >>> Now if you remove the line  gd->relocaddr = ho->fb, the frame buffer >>> region will be used for reserving memory for other purposes which >>> corrupts the frame buffer. >>> >>> One solution which we are planning to implement is move the ram_top to a >>> lower address leaving out a region for video buffer and u-boot can do >>> the allocation from the new ram_top address without spl video handoff >>> interfering in the u-boot's allocation of memory.The region above the >>> ram_top can be used for video. >>> >>> Present Scenario >>> +---------------------+ram_top >>> |                     | >>> |      page_table     | >>> |                     | >>> |                     | >>> +---------------------+ >>> |                     | >>> |                     | >>> |                     | >>> |                     | >>> |                     | >>> |  video frame buffer | >>> |                     | >>> |                     | >>> |                     | >>> |                     | >>> |                     | >>> |                     | >>> +---------------------+ >>> |                     | >>> |                     | >>> |    reserve_trace    | >>> |                     | >>> |                     | >>> |                     | >>> +---------------------+ >>> >>> >>> Proposed Solution >>> +---------------------+ >>> |                     | >>> |                     | >>> |                     | >>> |                     | >>> |                     | >>> | video frame buffer  | >>> |                     | >>> |                     | >>> |                     | >>> |                     | >>> |                     | >>> +---------------------+ram_top >>> |                     | >>> |                     | >>> |      page_table     | >>> |                     | >>> |                     | >>> |                     | >>> +---------------------+ >>> |                     | >>> |                     | >>> |    reserve_trace    | >>> |                     | >>> |                     | >>> +---------------------+ >> >> Sure, whatever you need to do is fine. You could pass the ram top from >> SPL to U-Boot perhaps. >> > > In this solution problem arises when user doesn't want's to hand-off > buffer, the frame buffer region will be reallocated by u-boot or will > require us to hard code buffer address, which we don't want to do. > >> Regards, >> Simon > > Thanks, > Nikhil