Received: from eggs.gnu.org ([2001:4830:134:3::10]:53703) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSol8-0004tJ-CP for qemu-devel@nongnu.org; Tue, 03 Mar 2015 10:29:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YSol4-000598-Ar for qemu-devel@nongnu.org; Tue, 03 Mar 2015 10:29:22 -0500 Received: from greensocs.com ([193.104.36.180]:17505) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSol4-00058j-0U for qemu-devel@nongnu.org; Tue, 03 Mar 2015 10:29:18 -0500 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) From: Mark Burton In-Reply-To: Date: Tue, 3 Mar 2015 16:29:13 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <711BBCAD-9514-4523-A456-AD4F397C41CD@greensocs.com> References: <1421428797-23697-1-git-send-email-fred.konrad@greensocs.com> <1421428797-23697-2-git-send-email-fred.konrad@greensocs.com> <54EF614B.1010607@greensocs.com> <73E10212-3603-4B64-BA61-66607C12A16A@greensocs.com> Subject: Re: [Qemu-devel] [RFC 01/10] target-arm: protect cpu_exclusive_*. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: mttcg@listserver.greensocs.com, "J. Kiszka" , Alexander Graf , QEMU Developers , Paolo Bonzini , =?utf-8?Q?KONRAD_Fr=C3=A9d=C3=A9ric?= Hi Peter, thanks for the feedback So - what we have discovered - using the slow path as discussed has a = significant performance hit (no surprise), likewise the user-mode exit = mechanism. However we are investigating that in parallel... However, for now, we have left the TCG doing the majority of the work.=20= (This was supposed to be the =E2=80=98quick an easy=E2=80=99 approach - = we have already discussed better approaches to atomic instructions at = length - but they are even more invasive!) we have tried several schemes, and not found anything totally = satisfactory: we have a gremlin. There seems to be a race condition = somewhere effectively means that the guest =E2=80=98ticket=E2=80=99 = mechanism inside the guest kernel goes off by one, and therefore the = guest kernel stalls as it never gets the ticket it=E2=80=99s looking = for=E2=80=A6. (it=E2=80=99s off by one in the =E2=80=98one too few=E2=80=99= sense, both CPU=E2=80=99s end up looking for tickets that are higher = than the current finished ticket)... The mechanism to hand out the tickets is of course a LDREX/STREX, = leading us to believe that is the cause of our problems, however I am = increasingly sceptical. Our scheme is actually quite simple now: We keep the same overall scheme as exits upstream today - we store the = address and value. We provide a lock which is used for LDREX, STREX, CLREX, and in the = raise_exception code. For LDREX we check that no other CPU is tagging the address. Because of = the lock, we can be sure no STREX is executing so we are always safe to = =E2=80=98steal=E2=80=99 a tag from another CPU (which is what the ARM = ARM defines). STREX and CLREX are similar to upstream... We are also careful to invalidate the address tag if we take an = exception. The drawback of this scheme is of course that we are not totally = protected against non exclusive writes, which could potentially fall = between our reading a value and checking it against our saved value. But = I am not convinced that is our problem (I have checked to make sure we = dont get non exclusive writes). This scheme would seem to be elegant and simple - but it suffers from = the one small drawback of still having the issue as above=E2=80=A6 Cheers Mark. ps. on our bug - we believe somehow the STREX is being marked as failed, = but actually succeeds to write something. There are only 3 ways the = strex can fail: 1/ the address doesn't match - in which case no ST will be attempted 2/ the value doesn't match - which means - no ST attempted 3/ the store starts, but causes a TLB fill/exception=E2=80=A6 The 3rd has 2 possibilities - the TLB is filled, and the store goes = ahead totally normally - there should be no =E2=80=98fail=E2=80=99 - or = an exception is generated in which case we will long jump away and never = return.=20 Am I missing something? >>=20 >>=20 > On 2 Mar 2015, at 13:27, Peter Maydell = wrote: >=20 > On 27 February 2015 at 16:54, Mark Burton = wrote: >>=20 >>> On 26 Feb 2015, at 23:56, Peter Maydell = wrote: >>> cpu_physical_memory_rw would bypass the TLB and so be much slower. >>> Make sure you use the functions which go via the TLB if you do >>> this in a helper (and remember that they will longjmp out on a >>> tlb miss!) >>=20 >> At this point speed isn=E2=80=99t our main concern - it=E2=80=99s = simplicity of implementation - we want it to work, then we can worry = about a better implementation (which likely should not go this path at = all - as discussed above). >> Given that - isn=E2=80=99t it reasonable to pass through = cpu_physical_memory_rw - and hence not have to worry about the long jump = ? Or am I missing something? >=20 > If you use cpu_physical_memory_rw you need to do the > virt-to-phys translation by hand (preferably via the TLB). > That might be something you needed to do anyway if we want > to have architecturally correct monitors that work on > physaddrs rather than vaddrs, but if not then the two > step process is a bit awkward. >=20 >>> Pretty sure we've already discussed how the current ldrex/strex >>> implementation is not architecturally correct. I think this is >>> another of those areas. >>=20 >> We have indeed discussed this - but this is a surprise. >=20 > You're right that I didn't specifically realise this exact > part of our incorrectness earlier. >=20 > -- PMM +44 (0)20 7100 3485 x 210 +33 (0)5 33 52 01 77x 210 +33 (0)603762104 mark.burton