Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754644AbbG0VE5 (ORCPT ); Mon, 27 Jul 2015 17:04:57 -0400 Received: from terminus.zytor.com ([198.137.202.10]:39272 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750915AbbG0VE4 (ORCPT ); Mon, 27 Jul 2015 17:04:56 -0400 Message-ID: <55B69CED.8050709@zytor.com> Date: Mon, 27 Jul 2015 14:04:45 -0700 From: "H. Peter Anvin" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Andy Lutomirski , Uros Bizjak , linux-kernel@vger.kernel.org CC: x86@kernel.org, Uros Bizjak , Ingo Molnar Subject: Re: ASM flags in general References: <1438019319-19731-1-git-send-email-uros_bizjak1@t-2.net> <55B680D8.5070702@zytor.com> <55B696B2.3000702@kernel.org> In-Reply-To: <55B696B2.3000702@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1996 Lines: 52 On 07/27/2015 01:38 PM, Andy Lutomirski wrote: > > As long as we're thinking about this stuff, there are bunch of places > where we use exception fixups and do awful things involving translating > them to error codes. Ideally they'd use as goto instead, but last time > I checked, GCC was quite picky and didn't like output constraints and > asm goto at the same time. Maybe GCC could fix this at some point, but > using condition code outputs might be reasonable, too. > > Doing this would make put_user_ex and similar completely unnecessary, I > think. > No, I think this is wrong. Exceptions and flags are almost each others opposites. Since C doesn't have native exception handling (except setjmp/longjmp) we pretty much hack it. asm goto() would indeed be the better way to do this, but again, would in most cases require asm goto to support outputs. However, get_user_ex and put_user_ex we really don't want to go away. They produce extremely efficient code -- just a bunch of mov operations -- for the common path, and that's the way we like it. That being said, there probably are a couple of patterns where we could do, say "stc" in the exception path, and emit CF as an output: bool err; int errno; asm volatile("xor %1,%1\n" /* Clears CF */ "1: something %3,%0\n"/* Leaves CF unchanged, or clears */ "2:\n" ".section .fixup.\"ax\"\n" "3: mov %4,%1\n" " stc\n" " jmp 2b" _ASM_EXTABLE(1b,3b) : "=X" (output), "=r" (errno), "=@ccc" (err) : "Y" (input), "i" (-EIO)); This would make "err" immediately testable. However, it also might make gcc generate extra code to save and restore err, since it wouldn't understand the invariant that err = !!errno. -hpa -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/