Received: from eggs.gnu.org ([2001:4830:134:3::10]:33484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dumb5-00022s-Gh for qemu-devel@nongnu.org; Wed, 20 Sep 2017 17:31:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dumb2-0000WV-7E for qemu-devel@nongnu.org; Wed, 20 Sep 2017 17:31:55 -0400 Received: from mx2.suse.de ([195.135.220.15]:55446 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dumb2-0000Sh-0D for qemu-devel@nongnu.org; Wed, 20 Sep 2017 17:31:52 -0400 References: <4d10cdd2-233c-46ac-926b-d4254b017c78@bitwagon.com> From: Alexander Graf Message-ID: Date: Wed, 20 Sep 2017 23:31:44 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] qemu-arm SIGSEGV for self-modifying code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , John Reiser Cc: QEMU Developers , Richard Henderson On 20.09.17 20:04, Peter Maydell wrote: > On 20 September 2017 at 18:05, John Reiser wrote: >> Yes, the SEGV occurs on the store, "long" before the re-written >> instruction ever is executed > > OK, I've identified the immediate cause for this SEGV. > > (1) when the guest initially mmap()s at 0xf7000000 and > above we pass that through to the host as an mmap rwx > (2) later, the guest wants to execute from some part > of this region; QEMU marks those pages as non-writable > so that we can catch guest writes and invalidate our > translated code cache (we then mark the page writable > and resume the guest code). This is a host page at a time, > so it covers the memory we're trying to modify > (3) when the translated guest code writes to the memory, > we get a host SIGSEGV, which is expected. Unfortunately > we then fail to recognize it as a case of a guest > write to a page that QEMU marked non-writeable. > (4) The reason we don't recognize the address is that > our test for "is this valid" (h2g_valid()) checks that the > guest address is within the chunk of the host address > space that we've carved out for the guest, and the > amount of space we carve out for that is 0xf7000000. > So guest execution above that won't work properly > (really we should probably fail the mmap() rather than > letting it succeed but misbehave). > > I don't really know why we use 0xf7000000 as our > reserved_va value here, though. Alex, you added that > years ago, can you remember why you used that value? IIRC I wanted to map the full 32 bits of address space possibly in use by a 32bit application, but leave some room for something, but I don't remember what that something was :) Alex