Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932145AbbG0Wnb (ORCPT ); Mon, 27 Jul 2015 18:43:31 -0400 Received: from mail-lb0-f170.google.com ([209.85.217.170]:33960 "EHLO mail-lb0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932124AbbG0Wn3 (ORCPT ); Mon, 27 Jul 2015 18:43:29 -0400 MIME-Version: 1.0 In-Reply-To: <55B69CED.8050709@zytor.com> References: <1438019319-19731-1-git-send-email-uros_bizjak1@t-2.net> <55B680D8.5070702@zytor.com> <55B696B2.3000702@kernel.org> <55B69CED.8050709@zytor.com> From: Andy Lutomirski Date: Mon, 27 Jul 2015 15:43:08 -0700 Message-ID: Subject: Re: ASM flags in general To: "H. Peter Anvin" Cc: Andy Lutomirski , Uros Bizjak , "linux-kernel@vger.kernel.org" , X86 ML , Uros Bizjak , Ingo Molnar Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2648 Lines: 78 On Mon, Jul 27, 2015 at 2:04 PM, H. Peter Anvin wrote: > 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. Wouldn't asm goto be just as good (assuming it supported the right constraints)? In principle, this: if (put_user(...)) goto error; if (put_user(...)) goto error; should optimize to: mov [...] _ASM_EXTABLE(...) mov [...] _ASM_EXTABLE(...) ... extable_landing_pad: jmp error IOW, I think that GCC's optimizer should be good enough to keep the error paths out of line and maybe even to coalesce them, > > 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. Yeah, this wouldn't be as good as asm goto. --Andy -- 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/