Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2631118imm; Sun, 7 Oct 2018 08:18:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV60GEkFgWMg54LMB70wdBDUhJ330KP1ots0245JdpeXzahRGoRbyNIlOk1N7TLRmLRv2gsIh X-Received: by 2002:a63:ed55:: with SMTP id m21-v6mr17789328pgk.147.1538925515420; Sun, 07 Oct 2018 08:18:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538925515; cv=none; d=google.com; s=arc-20160816; b=Myxt1pxC0k+VAoMPX2X8Zb2ALDJLgNBHdxgzU3oWaLnU+Tn7oFYkTTS2wVWeyKK5l1 6ssUlybfPoGgG8q8ACj+ELv5/CCZxkthMhd9mdzlsxObKZ47b8C3ULvnCCBs3AwFSCvL KjjXGANC8T4UA6i161xW2SOacgD62M45z+gHTBsPQpSXfMmz4B7FazmcRbr/Litiec38 n9wG90JmK7ymEzGgnyaGfa1ufCW8NwZ2a2l4HoTKBx2+N5vyp/+BQbfAvKhkbSKa9W0K En8iGD8YzIisfAvkh9aASKvph424PaMdFoHcMd6+czOj285yw2VIKlvy1+s/SWg6tjbT n4BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=NTI7ojoNCv+lEXqZB/Cgffczp+jFB8qa0nLKsObCZ/0=; b=jZ+Pu7ZtihhjYOvi+vdN5WNeNtQsjxdIg69JXt1vv1elDaEGFjoKwICZnVX8hgQC8p cYCZwee7YIC+5uQbmuBfJmLkicC5/GmLG7LrI9Bl36hJZ8+xXOu0Z/3BuzQesvpk9oSq gka/qHvtwaHbjN26tz3qo3NS2JFovishyQxlnVQgRl1EtSfG7SnsJGml4h4GJtYxQcSn cw7mlYmcKusGbrF7xi1t+KtrXH9Bx27P7tZsjFIDp5rt3zhF4luNNjygspT8gSfjAyZz 5zTFYVBlZvUzqvf1ALbfVkUle4lCBRtg1qbVMe0CCwOVlEJ9PqbEIfphcoi9qt7vQ0Rc HLJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6-v6si13888133pgb.333.2018.10.07.08.18.05; Sun, 07 Oct 2018 08:18:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728294AbeJGWZe (ORCPT + 99 others); Sun, 7 Oct 2018 18:25:34 -0400 Received: from gate.crashing.org ([63.228.1.57]:48864 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727517AbeJGWZe (ORCPT ); Sun, 7 Oct 2018 18:25:34 -0400 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w97FEZLq003379; Sun, 7 Oct 2018 10:14:36 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id w97FETEB003319; Sun, 7 Oct 2018 10:14:29 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Sun, 7 Oct 2018 10:14:28 -0500 From: Segher Boessenkool To: Borislav Petkov Cc: gcc@gcc.gnu.org, Richard Biener , Michael Matz , Nadav Amit , Ingo Molnar , linux-kernel@vger.kernel.org, x86@kernel.org, Masahiro Yamada , Sam Ravnborg , Alok Kataria , Christopher Li , Greg Kroah-Hartman , "H. Peter Anvin" , Jan Beulich , Josh Poimboeuf , Juergen Gross , Kate Stewart , Kees Cook , linux-sparse@vger.kernel.org, Peter Zijlstra , Philippe Ombredanne , Thomas Gleixner , virtualization@lists.linux-foundation.org, Linus Torvalds , Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org Subject: Re: PROPOSAL: Extend inline asm syntax with size spec Message-ID: <20181007151427.GK29268@gate.crashing.org> References: <20181003213100.189959-1-namit@vmware.com> <20181007091805.GA30687@zn.tnic> <20181007132228.GJ29268@gate.crashing.org> <20181007141349.GD30687@zn.tnic> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181007141349.GD30687@zn.tnic> User-Agent: Mutt/1.4.2.3i Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 07, 2018 at 04:13:49PM +0200, Borislav Petkov wrote: > On Sun, Oct 07, 2018 at 08:22:28AM -0500, Segher Boessenkool wrote: > > GCC already estimates the *size* of inline asm, and this is required > > *for correctness*. > > I didn't say it didn't - but the heuristic could use improving. How? It is as sharp an estimate as can be *already*: number of insns times maximum size per insn. If you get this wrong, conditional branches (and similar things, but conditional branches usually hit first, and hurt most) will stop working correctly, unless binutils uses relaxation for those on your architecture (most don't). > > So I guess the real issue is that the inline asm size estimate for x86 > > isn't very good (since it has to be pessimistic, and x86 insns can be > > huge)? > > Well, the size thing could be just a "parameter" or "hint" of sorts, to > tell gcc to inline the function X which is inlining the asm statement > into the function Y which is calling function X. If you look at the > patchset, it is moving everything to asm macros where gcc is apparently > able to do better inlining. Yes, that will cause fewer problems I think: do not override size _at all_, but give a hint to the inliner. > > > 3) asm ("...") __attribute__((asm_size())); > > > > Eww. > > Why? Attributes are clumsy and clunky and kludgy. It never is well-defined how attributes interact, and the more attributes we define and use, the more that matters. > > More precise *size* estimates, yes. And if the user lies he should not > > be surprised to get assembler errors, etc. > > Yes. > > Another option would be if gcc parses the inline asm directly and > does a more precise size estimation. Which is a lot more involved and > complicated solution so I guess we wanna look at the simpler ones first. > > :-) Which is *impossible* to do. Inline assembler is free-form text. > > I don't like 2) either. But 1) looks interesting, depends what its > > semantics would be? "Don't count this insn's size for inlining decisions", > > maybe? > > Or simply "this asm statement has a size of 1" to mean, inline it > everywhere. Which has the same caveats as above. "Has minimum length" then (size 1 cannot work on most archs). > > Another option is to just force inlining for those few functions where > > GCC currently makes an inlining decision you don't like. Or are there > > more than a few? > > I'm afraid they're more than a few and this should work automatically, > if possible. Would counting *all* asms as having minimum length for inlining decisions work? Will that give bad side effects? Or since this problem is quite specific to x86, maybe some target hook is wanted? Things work quite well elsewhere as-is, degrading that is not a good idea. Segher