Received: by 2002:a17:906:acd:b0:a66:557b:2f6e with SMTP id z13csp223170ejf; Thu, 6 Jun 2024 04:03:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVKxR7fbOjCFRR5G64o6RPxbV00et4/bnim5k38Nyzd7/lKSM4su3Uriz0OD/N6PxeiFmytlc1/zzdFvHMwKTgy2XxW20As X-Google-Smtp-Source: AGHT+IHU1nXOUy+G4h8LZvl1WKCnxHbOzzLAvugyG/YC6mcXlQ8rJk4NCK5pDbRXMLAqPA/G8Tt6 X-Received: by 2002:a05:6870:46ac:b0:24f:e73a:2b6f with SMTP id 586e51a60fabf-25122693c28mr5788474fac.13.1717671834244; Thu, 06 Jun 2024 04:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717671834; cv=none; d=google.com; s=arc-20160816; b=zEvRnJuOgmF386fzoj0sswwtzNyfyes1Yy8Mak0HmAMUjnbC+qH8IiEY7PDNwUayWN QzNCHGAqErlM8rnyiBe22X6RcG5Em9DtvI5u7h2TAiOX1ltYAYXeJjvw8nkBZP8sVbr/ 9aOt3rRJDkKeZ71gVB4NUIPNWd7fiTbIoXSab6gvd0EcchAHVLNxkOECJN83Lo5j4S8V F5ksrrR0wlNnzcfwhU2YqDZuzvSGUkcYJme46xiCAMQT2gIgdphRvlDCvpzUWff2DGor KyHLuVWjarDQGtkuv0uuU9fgp6SNwUGZp9TPUJNvsy6tuW0IYg5OKra2R9zleJqucyuC hK9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=YDtFm+bfOyx7ii8ukPFhPK6OMhezvNjUdfnyr+Oqe5I=; fh=vlqnGXo4l0RfOTwzk8NVSFjBcNQwvS2lHCaiKpL8Osg=; b=cHijlLzyS8oX1SqNEWjhAnyf/o0ibOUuceMrpXr2OJ0uBdfsq+VpehwT2sCMeFTC9C pWUEJvi+vnqriBbvpd3sVtjfWUw1s7QPyxOWb/enJpL5QkjV0CoD7CrZK29tSEEhmZeQ HLMTBITf1v4seqDP3ytYm9HJgIktlbVNZh/G31nfL03Qv1pZSyTkpbkvCr+TvEty58uE Dg2ovFSxeowZoJABG7/CO3s7rhv1aONU3dRZAids4yw7oOtbsrxCoQzkrfIlaTWEnbxq aicnViMvCumtrEVsYucm5pGIc6xrkJ2vCWBTADYOZT64HtRS3Ee1nysz5Re96CBIODgh ANsw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Lw/Q8hAX"; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-44038b5f3d9si10890851cf.556.2024.06.06.04.03.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Jun 2024 04:03:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Lw/Q8hAX"; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFAu4-0006OL-E0; Thu, 06 Jun 2024 07:03:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFAu0-0006MI-0l for qemu-arm@nongnu.org; Thu, 06 Jun 2024 07:03:29 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sFAtu-0007zb-18 for qemu-arm@nongnu.org; Thu, 06 Jun 2024 07:03:24 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42138eadf64so9313135e9.3 for ; Thu, 06 Jun 2024 04:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717671800; x=1718276600; darn=nongnu.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=YDtFm+bfOyx7ii8ukPFhPK6OMhezvNjUdfnyr+Oqe5I=; b=Lw/Q8hAX2TK7JWZW+adv63l8NPOx7qwADGoez3UsbGyv0wcWcJnN+0OLo+z59BvYkr q6lIrD5LBzLwTZlY1FUNE4Dyn9OgD5IbXbLvFau0smgaD0UJlTp0k30YjvENfWuMypaZ PUg9GphvKu2fbU6+luii/s4Xb5sFZ5x/D+koSApD06d2Y74M54uncKjn3077bURi+i8X BzytwoQcGuo6RhqZSFOg7mYNVjjzYp4QI7ssIUknUxAQ7c+LTXUCWyGhqZEsHhTIpQT2 8NQPvRHZDdwuaq+NX/DInsHZuJctcudnJSfv7zLVuvBdBn+8SNhzeDgRRzUb+f1er+as UeEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717671800; x=1718276600; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YDtFm+bfOyx7ii8ukPFhPK6OMhezvNjUdfnyr+Oqe5I=; b=TxqOe97VuNegd+htt6pHJXW1gRLixnXwC1suMeeY51NkTw9mCcm7UCvm2gslZqbNPe WIEYDtdDpfk5O4vCVZ6PEMpwgqEGS4OfohVisqCyXNFQE4Nwrt06FLAQqEPXPfivoQIn zSj1Y04CWOI36t/ObUyMWbYIC6McOJmRi2yA2jN9rZTgMjgGshAhJheCuNHz3St0G7mt darQ31MOueSb9eSLwp3IUphLjlDsO6pdGg0bQUllttTV8VC9munk9XdsKRo9HKVRc1bY 0JC1091NKtNWdXAc0h/maSuuKEvEoytGo1q7Zv8632TZ7/zwBn6jZws5txv/7LYJupYI DLkQ== X-Forwarded-Encrypted: i=1; AJvYcCXLKgXLCxYcg2uK+kAcEj4tf6PNTD+wWcnTGKr6LnJ67D4T5MmXGihjYoR02Wes/c6pQKJ5PTxMP42M4RzlUT0K7xlE X-Gm-Message-State: AOJu0YzpOLOUvqqY4dSsIFpXMYt1CfRTeBKVXbtbR3u1XYBpVCwkaDua CfnMXSiRCt9TOetnvLccpLHS4yc3UbDBD25/9PrtbFrtYqdQ0JmxzR4wDAtzWDc= X-Received: by 2002:a5d:4ec6:0:b0:35d:bed3:634e with SMTP id ffacd0b85a97d-35e8833a0ffmr3705182f8f.30.1717671800194; Thu, 06 Jun 2024 04:03:20 -0700 (PDT) Received: from myrica ([2.221.137.100]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35ef5d29b1bsm1258845f8f.3.2024.06.06.04.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 04:03:19 -0700 (PDT) Date: Thu, 6 Jun 2024 12:03:34 +0100 From: Jean-Philippe Brucker To: Gavin Shan Cc: Itaru Kitayama , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm , Richard Henderson , Ard Biesheuvel Subject: Re: Unexpected error in rme_configure_one() at ../target/arm/kvm-rme.c:159 Message-ID: <20240606110334.GA3707954@myrica> References: <20240531150922.GA83195@myrica> <20240603082402.GA25688@myrica> <2c81cb47-b9bc-4875-a7fb-49c3a8ab6713@redhat.com> <20240604111517.GB875061@myrica> <20240605155608.GA3251699@myrica> <1089f920-aff9-4d16-829d-5d058908a11e@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1089f920-aff9-4d16-829d-5d058908a11e@redhat.com> Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: WeOAXNNMBk/w On Thu, Jun 06, 2024 at 03:05:02PM +1000, Gavin Shan wrote: > > This commit moves the page tables from .rodata to .data. When linking > > IdMap.obj into ArmPlatformPrePeiCore.dll, the alignment of the .text > > section changes from 0x1000 to 0x800. This change comes from the linker > > script putting .rodata into .text. I don't know why the included .rodata > > alignment affects the .text alignment, but I don't think it matters here. > > > > In GenFw, ScanSections64() calculates a mCoffAlignment as the max > > .text/.data/.hii section alignement. Since with this commit, .data > > alignement (0x1000) becomes larger than .text (0x800), it picks 0x1000 as > > the output text offset, and then WriteSections64() complains that this > > offset isn't equal to the input .text alignment modulo 0x1000. > > > > The linker script says: > > > > /* > > * The alignment of the .data section should be less than or equal to the > > * alignment of the .text section. This ensures that the relative offset > > * between these sections is the same in the ELF and the PE/COFF versions of > > * this binary. > > */ > > > > but that's not what we're getting. I don't have a fix yet, other than > > forcing the .text and .data alignment to 4k. > > > > Jean, thanks for your explanation. Right, the issue is caused by mismatched > alignments for ELF and PE/COFF sections. I ever dumped the variables at the > failing point, showing the mismatched alignments (0x800 vs 0x1000). Apart from > that, the virtual address of 'text' section is aligned to 0x800 instead of > 0x1000 after ArmPlatformPrePeiCore.dll is dumped by 'readelf'. > > SecHdr->sh_addr: 0x800 <<< Mismatched alignment between ELF and PE/COFF > SecOffset: 0x1000 > SymShdr->sh_addr: 0x800 > mCoffSectionsOffset[Sym->st_shndx]: 0x1000 > GenFw: ERROR 3000: Invalid > WriteSections64(): /home/gavin/sandbox/CCA/edk2-guest/Build/ArmVirtQemu-AARCH64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll AARCH64 small code model requires identical ELF and PE/COFF section offsets modulo 4 KB. > > # readelf -S Build/ArmVirtQemu-AARCH64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll > Section Headers: > [Nr] Name Type Address Offset > Size EntSize Flags Link Info Align > [ 0] NULL 0000000000000000 00000000 > 0000000000000000 0000000000000000 0 0 0 > [ 1] .text PROGBITS 0000000000000800 00000800 <<< Aligned to 0x800 > 00000000000051b8 0000000000000000 AX 0 0 2048 > > With the following changes, I'm able to build the firmware successfully. I don't > see how COMMONPAGESIZE is sorted out because I don't find its definition in the > source code. It's a ld builtin, set on the command-line with "-z common-page-size=X" by Conf/tools_def.txt, in this case I believe DEBUG_GCC5_AARCH64_DLINK_XIPFLAGS. > > diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds > index 9f27e83bb0..5463df47a9 100644 > --- a/BaseTools/Scripts/GccBase.lds > +++ b/BaseTools/Scripts/GccBase.lds > @@ -20,7 +20,8 @@ SECTIONS { > */ > . = PECOFF_HEADER_SIZE; > - .text : ALIGN(CONSTANT(COMMONPAGESIZE)) { > + /* .text : ALIGN(CONSTANT(COMMONPAGESIZE)) { */^M > + .text : ALIGN(4096) {^M Build (after clean) fails for me if I only change the .text alignment, I need .data as well. So changing Conf/tools_def.txt is easier. I'll try to find a proper fix but it will take me some time to understand GenFw. > > > > Note that the guest edk2 is optional and experimental, you can use direct > > > > kernel boot to get a working demo quicker. > > > > > > > > > > I never did this before. Could you please provide the detailed steps on this? > > > > Removing the -bios parameter to QEMU should be enough. You can also add > > 'earlycon' to -append to show early boot errors. > > > > I didn't get a chance to try this yet since the host can't be brought up now. > I will try this later. I originally thought some sort of boot wrapper is needed > so that the kernel image has the capability to boot itself. For example, Mark > Rutland's boot wrapper [1] can be leveraged in this case. I don't think Image has > the capability to boot itself, right? Yes QEMU can set up everything so that the Image boots on its own. What the boot-wrapper does is minimal hardware initialization, handling PSCI calls and passing the DTB pointer in x0. But that's only needed when using the Arm FastModel (boot-wrapper is a lightweight firmware specifically for the FastModel). QEMU can do all that itself so you can boot a kernel without any firmware. Using edk2 in the Realm guest will be needed for example to boot a distro image which contains the kernel, but direct kernel boot is useful both for prototyping and real-life use cases like confidential containers and some cloud VMs. Thanks, Jean > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git > > Thanks, > Gavin >