Received: by 10.192.165.156 with SMTP id m28csp1202822imm; Wed, 11 Apr 2018 14:29:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx49yAG3SLWijQMfduYRf2pBbhB9AqMWZ+myGHdZNGobZ7j3Z4XJ7IfxKdZzz3PzenYrny8tb X-Received: by 10.101.101.66 with SMTP id a2mr4674015pgw.223.1523482190058; Wed, 11 Apr 2018 14:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523482190; cv=none; d=google.com; s=arc-20160816; b=c+dCMNvaVm9KBXiWkdSxW0DMC1UAmzJGVJR5x48P1VXza4js5hDXKxIRkurguRXShf cqCqCezTZ2UShBCVI0UC0Coxbx/8QYeZVKARTQSqb7e5moXuxkJnZAJFP/5xcRjS6Bg7 2CHmLMlW1Pn/c5R5KFkVUskmZJ4G0ODe8ZYU2IBzq9T/vyMoG4iqef3JbOCWRQ2+2HiW JeMVNNk3EAof16P2UVN6q/Q/CipW8BTZG+v98etWhJCqDSfDP1LYQUCXwzga9Vdn6Og0 PUiBN16RiaYsbrqp19fbv3uPmcLJ7Hw3O3fgsB4VFP8pEo7ToOvPWG9V00XoI4msZKLE +XGA== 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:arc-authentication-results; bh=zeY5PgYx3J1HL4Uq3+o53KMijd4dNdeP4q4lVq6KsmA=; b=VtaXAg1scRDHJFOcQ3dGtocIJA4fc41KhePVgZLP+UQ88kWFD1T4YxKT4hn/QsjG0P HePBsbpsivA+lOo7U8waqfZWSTc2l6icqpBjaXuyViy3xvbJ2UrhCIhohe8eHDiWlM9D XaYId+QjGgMV8vg424hantSVWILo2+/dzs5AAnqjdsrfFH53QveMX/5LfuKd+L83klOF TNfMaFCPN8mKoMXkPeI7pQMcvN1c5pHBxhmtAmn/44VhOmnSNWU51ULuANi7w2QQqEPS 1jWfFgtfQCi+zW2hiRvvpcIc0dYIUkY7h1L4i3QeHifZbkSrF+we7VoSJTtZlMJ5RwkX IUrw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e15-v6si1720166pli.163.2018.04.11.14.29.13; Wed, 11 Apr 2018 14:29:50 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755224AbeDKVWI (ORCPT + 99 others); Wed, 11 Apr 2018 17:22:08 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47496 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754281AbeDKSjG (ORCPT ); Wed, 11 Apr 2018 14:39:06 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C13E11DAE0; Wed, 11 Apr 2018 18:39:05 +0000 (UTC) Received: from sandy.ghostprotocols.net (ovpn-112-4.gru2.redhat.com [10.97.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2598215CDAF; Wed, 11 Apr 2018 18:39:04 +0000 (UTC) Received: by sandy.ghostprotocols.net (Postfix, from userid 1000) id 5DB704BDB; Wed, 11 Apr 2018 15:39:02 -0300 (BRT) Date: Wed, 11 Apr 2018 15:39:02 -0300 From: Arnaldo Carvalho de Melo To: Yonghong Song Cc: Alexei Starovoitov , Daniel Borkmann , David Miller , Peter Zijlstra , Ingo Molnar , acme@kernel.org, "linux-kernel@vger.kernel.org" Subject: Re: bpf: handling non BPF register names in inline assembly with -target bpf Message-ID: <20180411183902.GC12166@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.20 (2009-12-10) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 11 Apr 2018 18:39:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 11 Apr 2018 18:39:05 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'acme@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Apr 11, 2018 at 09:37:46AM -0700, Yonghong Song escreveu: > Hi, Arnaldo, > When I studied the bpf compilation issue with latest linus/net-next > kernel (https://patchwork.kernel.org/patch/10333829/), an alternative > approach I tried is to use __BPF__ macro. You mean you used an alternative approach that does _not_ use the __BPF__ macro, right? I looked at the patch and yeah, looks sane as well, since the kernel build process already defines that CC_HAVE_ASM_GOTO, checking if gcc has that feature, etc. > The following patch introduced "#ifndef __BPF__" in > arch/x86/include/asm/asm.h for some inline assembly related to x86 > "esp" register name. > ========== > commit ca26cffa4e4aaeb09bb9e308f95c7835cb149248 > Author: Arnaldo Carvalho de Melo > Date: Mon Dec 4 13:08:47 2017 -0300 > > x86/asm: Allow again using asm.h when building for the 'bpf' > clang target > > Up to f5caf621ee35 ("x86/asm: Fix inline asm call constraints > for Clang") > we were able to use x86 headers to build to the 'bpf' clang target, as > done by the BPF code in tools/perf/. > ... > diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h > index 219faae..386a690 100644 > --- a/arch/x86/include/asm/asm.h > +++ b/arch/x86/include/asm/asm.h > @@ -136,6 +136,7 @@ > #endif > > #ifndef __ASSEMBLY__ > +#ifndef __BPF__ > /* > * This output constraint should be used for any inline asm which > has a "call" > * instruction. Otherwise the asm may be inserted before the frame > pointer > @@ -145,5 +146,6 @@ > register unsigned long current_stack_pointer asm(_ASM_SP); > #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer) > #endif > +#endif > ... > ========== > > I just landed a clang patch (clang 7.0.0 trunk) > https://reviews.llvm.org/rL329823 > which will permit bpf clang target to accept ANY register > names. In this case, the inline assembly will be accepted by clang > and will be thrown away since variable current_stack_pointer is > not used in bpf programs. Ok, then that ifndef __BPF__ above will not be needed anymore, but only people with clang > that version will be able to build tools/perf/ > If the inline assembly is indeed for BPF program, later llc > AsmParser will do syntax and semantics checking again. > > With the above clang patch, the above "#ifndef __BPF__" can be removed. > You can decide when is the appropriate time to use latest clang compiler > and remove the above "#ifndef __BPF__". So are you proposing that we have something similar to that CC_HAVE_ASM_GOTO check in the kernel main Makefile, to define something like CC_HAVE_ASM_REGS (or some better name), i.e. something like: # check for 'asm(_ASM_SP)' ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/cc-asm-regs.sh $(CC) $(KBUILD_CFLAGS)), y) CC_HAVE_ASM_REGS := 1 KBUILD_CFLAGS += -DCC_HAVE_ASM_REGS KBUILD_AFLAGS += -DCC_HAVE_ASM_REGS endif ? - Arnaldo