From: Stefano Stabellini Subject: Re: [PATCH] xen/arm64: Use __flush_dcache_area instead of __flush_dcache_all Date: Wed, 15 Oct 2014 16:02:52 +0100 Message-ID: References: <20141007104035.GB24725@leverpostej> <20141014092106.GF16598@leverpostej> <1413279323.1497.27.camel@citrix.com> <20141014103233.GH16598@leverpostej> <1413283177.10417.34.camel@citrix.com> <20141014112333.GJ16598@leverpostej> <1413291289.10417.46.camel@citrix.com> <20141014143002.GA1995@leverpostej> <20141014170753.GA4517@leverpostej> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="1342847746-1781307396-1413385372=:17038" Return-path: In-Reply-To: <20141014170753.GA4517@leverpostej> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Mark Rutland Cc: Ian Campbell , "julien.grall@linaro.org" , "xen-devel@lists.xen.org" , Roy Franz , "suravee.suthikulpanit@amd.com" , "stefano.stabellini@eu.citrix.com" List-Id: xen-devel@lists.xenproject.org --1342847746-1781307396-1413385372=:17038 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: QUOTED-PRINTABLE On Tue, 14 Oct 2014, Mark Rutland wrote: > [...] >=20 > > >> > As far as I am aware, UEFI may have an arbitrary set of mapping= s > > >> > present during boot services time, with arbitrary drivers activ= e. > > >> > That means that UEFI can create dirty cache entries concurrentl= y with > > >> > the bootloader, in addition to the usual clean entries that can= be > > >> > allocated at any time thanks to speculative fetches. > >=20 > > UEFI specifies that memory in the EFI memory map is flat mapped, but > > I'd have to look to see if > > it prohibits other mappings in addition to that. Other mappings are > > implementation > > dependent (devices, etc. or memory not in the EFI memory map.) >=20 > Regardless of the set of mapping that may exist, the key point is that > we don't know what may have been allocated into a cache. Any portion of > memory could have entries in the cache hierarchy, which could be clean > or dirty. >=20 > > In reviewing the Aarch64 specific portion of the spec (section 2.3.6 > > Aarch64 Platforms) > > it says in part: > >=20 > > =C2=B7 Implementations of boot services will enable architecturally > > manageable caches and TLBs i.e. > > those that can be managed directly using implementation independent > > registers using > > mechanisms and procedures defined in the ARM Architecture Reference > > Manual. They should > > not enable caches requiring platform information to manage or invoke > > non-architectural cache/ > > TLB lockdown mechanisms. > >=20 > > Does this imply that system level caches should not be enabled? >=20 > Arguably yes, but on a technicality no, because it's possible to flush > them by VA (albeit extremely slowly). I think that this point should really be clearer at the spec level. > >> > So while we're in the bootloader, any system level caches can hav= e > > >> > entries allocated to it, and as those aren't architected the on= ly > > >> > thing we can do is flush those by VA for the portions we care a= bout. > >=20 > > Maybe the firmware is 'wrong' to enable these caches? >=20 > It is certainly arguable. >=20 > > Are we guaranteed that these caches can be disabled on all > > implementations? >=20 > I believe on some implementations the non-secure side will not have > access to the control registers. Beyond that I don't know. >=20 > > Updating/clarifying the spec to have these disabled could simplify the > > problem a bit. >=20 > Possibly, yes. I'm not sure what we'd clarify it to say, however. We should start a discussion about this with the relevant parties. > > >> > So we can have "initially consistent", but that might not be usefu= l. > > >> > > >> Hrm, yes, rather unfortunate. > > >> > > >> > > > >> > > > There are a tonne of subtleties here, and certain properties w= e would > > >> > > > like (e.g. a completely clean cache hierarchy upon entry to th= e OS) > > >> > > > aren't necessarily possible to provide in general (thanks to t= he wonders > > >> > > > of non-architected system level caches, interaction with bootl= oaders, > > >> > > > etc). > > >> > > > > >> > > I suppose it is easier for the UEFI implementation, since it kno= ws the > > >> > > platform it runs on and there knows about the caches. Harder for= the > > >> > > stub though :-/ > > >> > > > >> > Yeah. System-level caches interact badly with pretty much any scen= ario > > >> > where ownership of the MMU is transferred (UEFI boot, kexec), and = there > > >> > doesn't seem to be a single agent that can be charged with ownersh= ip of > > >> > maintenance. > > >> > > > >> > This is something I've been meaning to revisit, but it takes a whi= le to > > >> > get back up to speed on the minutiae of the cache architecture and= the > > >> > rules for memory attributes, and I haven't had the time recently. > > >> > > > >> > We do have a very heavy hammer that we know will work: flushing th= e > > >> > memory by PA in the stub once the MMU and caches are disabled. A > > >> > back-of-the-envelope calculation shows that could take minutes to = issue > > >> > on a server machine (say 2GHz, with 16GB of RAM), so that's very m= uch a > > >> > last resort. > > >> > > >> Ouch... > > > > > > Looking at that again, I was off by an order of 1000, and that actual= ly > > > comes to about 0.13 seconds (though solely for CMO issue). So that mi= ght > > > not be as blunt as I made it out to be, but it's still not great as > > > platforms get larger. > >=20 > > I think we should be able to limit the memory we need to flush, as > > there should be no > > need to flush the free memory, just what is in use. I think that good > > portions, if not all of that > > could be flushed from the C code with caches enabled, as we know they w= on't be > > modified after that point (FDT, initrd, etc.) We can do this in C > > code after calling > > ExitBootServices(), and immediately before calling the Xen entry point > > efi_xen_start(). > > There are no EFI calls in this path between the last bit of C code and > > the disabling > > of caches and MMU, so I think we should be able to identify if > > anything would need > > to be flushed in the ASM code with caches off. >=20 > I agree the vast majority of this maintenance could be done by C code. >=20 > There might be a need to flush that free memory, depending on how it is > mapped, unless you are proposing a lazy flush-before-use strategy. Is it actually safe to only flush what we use (DTB, Xen, initrd, Linux)? What if the firmware wrote something else (ACPI tables?) that we might have to access? What if the firmware wrote something else that we don't care about? Xen scrubs all ram early at boot, so this last point might not be an issue. --1342847746-1781307396-1413385372=:17038 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --1342847746-1781307396-1413385372=:17038--