From owner-freebsd-sparc64@FreeBSD.ORG Mon Aug 13 17:50:03 2007 Return-Path: Delivered-To: freebsd-sparc64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7968616A418 for ; Mon, 13 Aug 2007 17:50:03 +0000 (UTC) (envelope-from michiel@boland.org) Received: from neerbosch.nijmegen.internl.net (neerbosch.nijmegen.internl.net [217.149.193.38]) by mx1.freebsd.org (Postfix) with ESMTP id 0AC7E13C459 for ; Mon, 13 Aug 2007 17:50:02 +0000 (UTC) (envelope-from michiel@boland.org) Received: from neerbosch.nijmegen.internl.net by neerbosch.nijmegen.internl.net via neerbosch.nijmegen.internl.net [217.149.193.38] with ESMTP for id l7DHSvc0010688 (8.13.4/1.4); Mon, 13 Aug 2007 19:28:57 +0200 (MEST) Received: from localhost by neerbosch.nijmegen.internl.net via mboland@localhost with ESMTP for id l7DHSvtr010685 (8.13.4/2.02); Mon, 13 Aug 2007 19:28:57 +0200 (MEST) X-Authentication-Warning: neerbosch.nijmegen.internl.net: mboland owned process doing -bs Date: Mon, 13 Aug 2007 19:28:57 +0200 (MEST) From: Michiel Boland To: freebsd-sparc64@freebsd.org Message-ID: MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="-559023410-851401618-1187026137=:5737" Subject: problem with user trap handlers in -CURRENT X-BeenThere: freebsd-sparc64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the Sparc List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Aug 2007 17:50:03 -0000 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---559023410-851401618-1187026137=:5737 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Hi. First, I would like to point out that I'm not at all an expert on sparc64, so please excuse me if I express myself a bit awkwardly. Now the problem. As you may or may not know, -CURRENT on sparc64 is broken in the sense that you can no longer ssh into a box that has UsePrivilegeSeparation yes in sshd_config. For more details, see http://lists.freebsd.org/pipermail/freebsd-current/2007-July/074569.html and http://lists.freebsd.org/pipermail/freebsd-current/2007-August/075996.html At the root of all this lies what I think is a fundamental problem with the way that alignment traps are handled. Attached you will find (unless the list software decides to eat it) a program that demonstrates what I mean. It creates a deliberate unaligned access trap. The idea is that the trap handler then emulates the load/store in software. This is done in __unaligned_fixup in src/lib/libc/sparc64/sys/__sparc_utrap_align.c. Unfortunately this emulation will not work if the trap is taken in the delay slot right after a return instruction, and the faulting address is on the stack of the procedure from which the processor just returned. This is because the contents of the stack are overwritten with a trap frame, at which point the emulation code will store an erroneous value. This is why the attached program outputs expected 37, got 0 instead of nothing, which it should do. (Surprise your friends: link traptest statically. It will then print a different value each time it is run. :) The assembler code generated by gcc looks like o2: save %sp, -208, %sp add %fp, 2019, %l0 add %l0, %i0, %l0 add %fp, 2027, %o0 call o3, 0 mov %l0, %o1 ldsb [%fp+2027], %g1 cmp %g1, 0 add %fp, 2019, %g1 movne %icc, %l0, %g1 return %i7+8 ldsw [%g1], %o0 <----- trap is taken here ^^^^^ this location will be overwritten by the trap frame I'm not sure how to work around this. I guess one solution would be to tell gcc not to generate these kinds of instruction combinations. But also I am wondering why FreeBSD attempts to emulate unaligned loads and stores in the first place. If I run traptest on Solaris, it crashes immediately with SIGBUS. I would have guessed it would do the same on FreeBSD. So I was a bit surprised that it ran at all. Is it not easier to just not handle unaligned traps at all and simply let programs crash? Or did someone already try this in the past, and too many things broke after that? Also I would assume that if you enforce that all memory access be aligned, and hence cut out all the (slow) emulation, you get at least a theoretical spead increase. Cheers Michiel ---559023410-851401618-1187026137=:5737 Content-Type: TEXT/PLAIN; charset=US-ASCII; name=traptest.c Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=traptest.c I2luY2x1ZGUgPHN0ZGlvLmg+DQoNCiNpZm5kZWYgTUFHSUNfTlVNQkVSDQoj ZGVmaW5lIE1B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