Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4714633imm; Fri, 18 May 2018 09:26:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpVVe7rvlpyXBC3NjwKkn+fiuwybGrsgmAGwI530KULGgBcwrXME+0NzJqugvZeFzedOfft X-Received: by 2002:a62:a096:: with SMTP id p22-v6mr10178874pfl.9.1526660764288; Fri, 18 May 2018 09:26:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526660764; cv=none; d=google.com; s=arc-20160816; b=WjNDWDJZ9/3enay1xtfvE4OJDx8bxk4JvxOEmheLq1fW5qK25MksshVXad/NF/nYKu k2oHAaMEVQIzYg2bvsPiut3YxQR0H7qxtmGj8LURjt8sJy9V+7f/zgC3k1g2sV4xoJgB /hImXLJp4k1PSzp4W3Z4LQQwdCRtNamAL4hXi6+Eo/Bg7ZxG7wH5B8BgUWzn7uVgzmjz I6j0gDnX9nOapq/gtYQ56nVQ4wYYlLa63DorTs7joO0hmwdR4A28844sG38Zw/12TA/M kaKECUeFDvuwQgSkl/oyYLOTORhBiMyaNSxjzrVlM5SSw8av04MUezfxwGmaC87KTlKi qjDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=Ym5icwRLLVWO4IeNKKpG6Tr+eeV0Xmxr3qIiBfTbPOI=; b=kgQ69Wm70hhxPkTJ4ds3Kz+/jXhpeBl9qwZeaZ2iiJWEkFZU3oFNVWvbu24DLl1Bw5 E/EgN3Tgw8tYOuZBHjLVDx3u1xIxcj5QvZnPVYrvTgsUzd51OWoJGpPBn4utJx1mqweI 9EJX/TczJAQ7H7cvXNN3u95VmSmGJmvZ/K6K/w4l8JfG7A8hOxVjAWs3kYxxh6LJ/ryw qii3qb62BB1L0PRFA3nLbgMFORT3UpUPA4ZIfyLd0rDxCnnYHsXFV3r2Aw514yIYdWlt RTFpv02CXYLEL4cDLkP+t4p7vX1fWlAAtngo1wkv5RxrHX3VMulcgzatPApYcEeJMGdp ERIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=fflmLci6; 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 r3-v6si6190076pgf.621.2018.05.18.09.25.49; Fri, 18 May 2018 09:26:04 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=fflmLci6; 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 S1751914AbeERQY2 (ORCPT + 99 others); Fri, 18 May 2018 12:24:28 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:36787 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750957AbeERQY0 (ORCPT ); Fri, 18 May 2018 12:24:26 -0400 Received: by mail-it0-f67.google.com with SMTP id e20-v6so13849919itc.1 for ; Fri, 18 May 2018 09:24:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ym5icwRLLVWO4IeNKKpG6Tr+eeV0Xmxr3qIiBfTbPOI=; b=fflmLci6X9CX+JlPU80SyTX/qv4QlcY+14dqzhqHiWNT6gY68JdCqD/SuGmd9IqOGh k711UT5PMW2/ey/STswJL4GhWKncqG8ohlbm6mjGw3loo0NdgGyOIJU9fbm/wpXP7XoE acDv/jfA/+aqlmGs4La6fALtvChviN4uLVhlg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ym5icwRLLVWO4IeNKKpG6Tr+eeV0Xmxr3qIiBfTbPOI=; b=chJos3nF31gWUK4zZaB+B1H75E1UUqVTl/U/qafqVsMVMZZx4WlIYE/Eiw/vyJYi8E 8F5E6Jt8V+jb2f/BnHORqR1PO5AAbqFa2yqQD+60l0+k4MAVJoyh1KqGl8U6sm24g5r/ PmYTfLsf+9lNvGmOdafPPxp6UQbsEmBxKJ+jym98tPkCM8yI/CmP4cge05yGCx0ui/kr agRObI6te17UqIDVjkHgOszOUXbiLF+gs7HTzNksv08Im+sFfgjaInkyR929GLQR6wCd WyhR05pY4ZcG+5O6jlGVPtLODMlp1EsdyoKB1ub4FhssFr0saVXXc/fBEn9HBkrq3v2S mytw== X-Gm-Message-State: ALKqPwdw7eI4vLPXCgTNsChQoi0PGMEDwjr/bHdyoWIbIFrcbDCikLjA /C0coeIOmEph3W9B/TxrHQK/N3vEHUIYXCrTwUI= X-Received: by 2002:a24:2213:: with SMTP id o19-v6mr7674005ito.16.1526660665752; Fri, 18 May 2018 09:24:25 -0700 (PDT) MIME-Version: 1.0 References: <20180517161402.78089-1-namit@vmware.com> <20180517161402.78089-3-namit@vmware.com> <20180518075853.GD12217@hirez.programming.kicks-ass.net> In-Reply-To: <20180518075853.GD12217@hirez.programming.kicks-ass.net> From: Linus Torvalds Date: Fri, 18 May 2018 09:24:14 -0700 Message-ID: Subject: Re: [PATCH 2/6] x86: bug: prevent gcc distortions To: Peter Zijlstra Cc: namit@vmware.com, Linux Kernel Mailing List , "the arch/x86 maintainers" , Nadav Amit , Thomas Gleixner , Ingo Molnar , Peter Anvin , Josh Poimboeuf Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 18, 2018 at 12:59 AM Peter Zijlstra wrote: > This is an awesome hack, but is there really nothing we can do to make > it more readable? Esp, that global asm doing the macro definition is a > pain to read. I actually find that macro to be *more* legible than what we do now, although I'm not enamored with the pseudo-operation name ("__BUG_FLAGS"). That said, the C header code itself I don't love. I wonder if we should just introduce a new assembler header file, and get it included when processing compiler-generated asm. We already do that for our _real_ *.S files, with a number of our header files having constants and code for the asm case too, not just C. But we could have an header file that has these kinds of macros (or "pseudo-instructions") for assembly language cases, and then we could just rely on them in inline asm. Because if you want to see illegible, look at what we currently generate: # kernel/exit.c:1761: BUG(); #APP # 1761 "kernel/exit.c" 1 1: .byte 0x0f, 0x0b .pushsection __bug_table,"aw" 2: .long 1b - 2b # bug_entry::bug_addr .long .LC0 - 2b # bug_entry::file # .word 1761 # bug_entry::line # .word 0 # bug_entry::flags # .org 2b+12 # .popsection # 0 "" 2 # 1761 "kernel/exit.c" 1 180: # .pushsection .discard.unreachable .long 180b - . # .popsection # 0 "" 2 #NO_APP and tell me that's legible.. Of course, I'm probably one of the few people who actually look at the generated asm fairly regularly. So a few macros that we can use in inline asm definitely wouldn't hurt legibility. And if we actually can put them in a header file as legible code - instead of having to wrap them in a global "asm()" macro in C code, they'd probably be legible at a source level too. It's not just the bug_flags cases. It's things like jump labels too: # ./arch/x86/include/asm/jump_label.h:36: asm_volatile_goto("1:" #APP # 36 "./arch/x86/include/asm/jump_label.h" 1 1:.byte 0x0f,0x1f,0x44,0x00,0 .pushsection __jump_table, "aw" .balign 8 .quad 1b, .L71, __tracepoint_sched_process_free+8 + 0 #,, .popsection # 0 "" 2 #NO_APP and atomics: # ./arch/x86/include/asm/atomic.h:122: GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", e); #APP # 122 "./arch/x86/include/asm/atomic.h" 1 .pushsection .smp_locks,"a" .balign 4 .long 671f - . .popsection 671: lock; decl -2336(%rbp) # _7->counter /* output condition code e*/ # 0 "" 2 # ./include/linux/sched/task.h:95: if (atomic_dec_and_test(&t->usage)) #NO_APP where I suspect we could hide the whole "lock" magic in a macro, and make this much more legible. Maybe? I think it might be worth trying. It's possible that the macro games themselves would just cause enough pain to make any gains go away. Linus