From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.1556.1589476894564309554 for ; Thu, 14 May 2020 10:21:34 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 374321042; Thu, 14 May 2020 10:21:33 -0700 (PDT) Received: from [192.168.1.81] (unknown [10.37.8.255]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1B36C3F71E; Thu, 14 May 2020 10:21:30 -0700 (PDT) Subject: Re: [PATCH v1 03/11] MdePkg: Base Memory Lib instance using MMIO From: "Ard Biesheuvel" To: Sami Mujawar , devel@edk2.groups.io Cc: leif@nuviainc.com, michael.d.kinney@intel.com, liming.gao@intel.com, Alexandru.Elisei@arm.com, Andre.Przywara@arm.com, Matteo.Carlini@arm.com, Laura.Moretta@arm.com, nd@arm.com References: <20200514084019.71368-1-sami.mujawar@arm.com> <20200514084019.71368-4-sami.mujawar@arm.com> <97b8028a-018f-0f91-90ab-a336b0c2ba24@arm.com> Message-ID: Date: Thu, 14 May 2020 19:21:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <97b8028a-018f-0f91-90ab-a336b0c2ba24@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 5/14/20 11:22 AM, Ard Biesheuvel wrote: > Hi Sami, >=20 > On 5/14/20 10:40 AM, Sami Mujawar wrote: >> Some device drivers perform copy operations on >> device memory, e.g. device drivers for a Flash >> device. On some architectures unaligned access >> to device memory regions is not permitted. To >> add to this if the device is virtualised then >> there are further restrictions on the type of >> load/store operations that can be performed >> on the device memory regions, e.g. on AARCH64, >> Pre/Post index or LDP operations cannot be >> used, as a trap to EL2 does not provide the >> syndrome information to the hypervisor. >> >=20 > We are conflating two different things here: > - the use of unaligned accesses to read from device memory > - the use of load/store instructions that have multiple output=20 > registers, making it very difficult to emulate them in a virtual machin= e=20 > context. >=20 > I though that for the kvmtool port, we addressed the second issue by=20 > using a read-only memslot for the NOR flash when it is in array mode?=20 > IIRC, the issue only affects reads, as all writes to NOR flash device=20 > memory are already done using the proper MMIO accessors. If those MMIO=20 > accessors compile to something that does not work under emulation, you=20 > should be use the special IoLib implementation that exists for this use= =20 > case: >=20 > =C2=A0 MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicArmVirt.inf >=20 > So that leaves the issue of unaligned accesses to device memory. This=20 > should not happen unless you are using BaseMemoryLibOptDxe for AARCH64,= =20 > which deliberately uses overlapping loads and stores for performance.=20 > Any BASE library is built with -mstrict-align, and so any other C code=20 > implementation of BaseMemoryLib should work fine for reading for a=20 > read-only memslot mapped using device attributes. >=20 > So in summary, I don't think we need this library. >=20 BTW I think the AlignedCopyMem() introduction predates the changes to=20 use -mstrict-align for BASE libraries, and to use the ordinary=20 BaseMemoryLib implementation for DXE_RUNTIME_DRIVER modules on AArch64.