From owner-freebsd-arch@FreeBSD.ORG Fri Aug 2 16:59:44 2013 Return-Path: Delivered-To: freebsd-arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7F77B4DF; Fri, 2 Aug 2013 16:59:44 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B070C20D7; Fri, 2 Aug 2013 16:59:13 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id r72Gx7QY001570; Fri, 2 Aug 2013 19:59:07 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua r72Gx7QY001570 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id r72Gwax0001554; Fri, 2 Aug 2013 19:58:36 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 2 Aug 2013 19:58:36 +0300 From: Konstantin Belousov To: Ian Lepore Subject: Re: Fwd: Use of the PC value in interrupt/exception handlers Message-ID: <20130802165836.GC4972@kib.kiev.ua> References: <1375457493.45247.249.camel@revolution.hippie.lan> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="c/lwuELUGxxkaMpf" Content-Disposition: inline In-Reply-To: <1375457493.45247.249.camel@revolution.hippie.lan> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: freebsd-arch@FreeBSD.org, Sorav Bansal , Piyus Kedia X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Aug 2013 16:59:44 -0000 --c/lwuELUGxxkaMpf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 02, 2013 at 09:31:33AM -0600, Ian Lepore wrote: > On Fri, 2013-08-02 at 19:08 +0900, Piyus Kedia wrote: > > Dear all, > >=20 > > We are working on developing a dynamic binary translator for the kernel. > > Towards this, we wanted to confirm if the interrupted PC value pushed on > > stack by an interrupt/exception is used by the interrupt/exception > > handlers? For example, is the PC value compared against a fixed address= to > > determine the handler behaviour (like > > Linux's page fault handler compares the faulting PC against an exception > > table, to allow functions like copy_from_user to fault). > >=20 > > Basically, we are wondering if it is safe to replace the pushed PC valu= e on > > stack by another value. This would be safe if the PC value is only used= for > > returning from interrupt, or for reading contents at that PC address (e= =2Eg., > > to decode the instruction at current PC). It would be unsafe if the val= ue > > of the address itself is meaningful to the handler. > >=20 > > We found that in FreeBSD segment-not-present exception handler checks t= he > > trapped PC value against some fixed kernel PC by looking at the code, > > except that it is only used for debugging purposes. It would be nice if > > somebody could also confirm this. > >=20 > > Thanks, > > Piyus >=20 > For the ARM architectures which use Restartable Atomic Sequences (RAS) > to implement atomic operations, examining the value of the saved PC and > possibly modifying it is how RAS works. See the PUSHFRAMEINSVC macro in > sys/arm/include/asmacros.h. =20 >=20 > In a nutshell, the RAS code works by having userland code store the > begin/end addresses of a small block of code that must be executed to > completion without interruption to be correct. If an exception or > interrupt happens while the PC is in that range, the exception-entry > code implemented by PUSHFRAMEINSVC modifies the saved PC so that on > return to userland, execution resumes at the beginning of the atomic > sequence. This reminds of me the following MIPS code: http://svnweb.freebsd.org/base?view=3Drevision&revision=3D226517 --c/lwuELUGxxkaMpf Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJR++U8AAoJEJDCuSvBvK1BfG4P/1k47DWq0o1wSy3K0+9ri0g3 388Q1phR8IdJGDVTrf5ZzbuQi0tNL3Knyu9hL3deMG/1LXWByojOVxffycLwYCJo K+8Wie47QJO9ZFN6mks0NN7Q3NBeXC07RIN7ShPg+bTEUIzNbsytG+WlMNAqddis NP9l/XEYWHlXZNOGzuQhk9IrXKqI1w+9IY0xYOzpnre9YSHeVGDyzuhroX0xKXpP l5wbki2VKBncXb/4lpSNoQP50UgxiQgZqjsuQG9LTa1PhwyxJBjiVcjwFkDjs1Od pcKJdOnbjKzfQP+BDwS2x6v9Wl6ikxixIJ0WS9Eb6RuhiwRX8kpYGBdhlJ7Qms3f U4L+xYZriycnozUh4b3vzVfU7WwT4OBJysT7plqzMbfUNPa3N5lUgQj66SGjH0KY eV1BKsw1MPIIszAWRZ6vm4Ryri5rqvpj3/WiWoh2w6LizCNFQVhHmfnHaepYoNyx bfuUKVOdLgSZl7B7jcYygrybPFauakFTD7BbJhYObWZlXHCTirhK/8qRZAE3bhgq nuREPzE4x1s8elWvZIyy+jrwFseQvAcuYUnumXy0knylwfJ76qszfmUZ4BtVxVT7 fr8TDjNz9npVu7K4dN5K8hFg9D96pQqvfNsj7qJIc3/Rh4YP6FezxNZza/5h6HDx 42+ZbLht+U9okAeMkICO =EBhZ -----END PGP SIGNATURE----- --c/lwuELUGxxkaMpf--