Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3411415imm; Sun, 13 May 2018 10:44:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo1LBn/LURAWvU9w/9H97K8HQWaYjHOG88y0NLBF2Ejjp244lDf4W2yJlx2L/6ob/YwoqGz X-Received: by 2002:a17:902:1023:: with SMTP id b32-v6mr6601618pla.145.1526233458653; Sun, 13 May 2018 10:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526233458; cv=none; d=google.com; s=arc-20160816; b=0IfmkiLI2hWzXJGGUu34+3vJBI3IgQ7X6GU254ctDJ2A4gyEjWgZVKWTw5Vjyd1D6y DcEUKzgJYeKtaqgBSf91+pKLZpt4GapRn+ivBdOsL423PejKIH3j0PxCCAP+ljabUPUs U+nx+dei7Ex+JqSWNwVCjoaKtOPomOxzQeQF4Q/hRNMkUvrVh+IJwTa2K7ynknHMzup9 dyTzvylnwnunnaQhZH8/weXsc+Z05klPNuyO2yuYPjLXTl523QtiCrYP3AI6rtj3S4Po QDJJFtKFBwZBLFdZns7IhrLIEv/SzJktl8KOqz5SH2j6GI3dwqkNuVCU7jDEd9aJCN/8 6c+g== 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:dkim-signature:arc-authentication-results; bh=evMVBq6L/Q0iVblqVLHR1azbvHM0rC9x5PDOAiK8QFA=; b=s28o3x/QQUYkMKnTEHNtZJiWD6dLPMnnVxylclHjPndjrvbZ85ES89bEKQS6tNdJ6W 7SYh1NOc6lRYJUIfTNITGuI8mFGfdSPUcy7nFzr+xJxUhticr+ipTXKxUqIy5i0AJmVp NJMAaBZ7H2P324CGgnWoVpTB08riH7rRJxFf/Oldu3QO6Q8cw2bw5bfFsAGEJfX4THNV V7RqVWFTlf9PcLMWb/XbZKRrw+86blqK331hyksoZq+5FEQwe+viXNzXY/sRifvyZjGM SGdyQqsUpici5oWtJrgL9Fp41VUxwLBRSR5q9Z/gC9f0Uh00CNUFVwuMC7JVZ3GTrVUH CJLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=X8uquL3D; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w68-v6si7911093pfb.325.2018.05.13.10.44.02; Sun, 13 May 2018 10:44:18 -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=@gmail.com header.s=20161025 header.b=X8uquL3D; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751596AbeEMRn4 (ORCPT + 99 others); Sun, 13 May 2018 13:43:56 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:38862 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751263AbeEMRny (ORCPT ); Sun, 13 May 2018 13:43:54 -0400 Received: by mail-pl0-f68.google.com with SMTP id c11-v6so6040710plr.5; Sun, 13 May 2018 10:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=evMVBq6L/Q0iVblqVLHR1azbvHM0rC9x5PDOAiK8QFA=; b=X8uquL3DxlZa6Rfct+Ke78TbRJZZ14mWn78+tA/S+G6TNc36FtPr6pna+h75gWWfcc YL1RKri8yr8YsMySQ/bEnei0CNAr5IwPdDqyoHrQXP92WvWmvWFGHoIunPVNklYrYSOj VrvM7aGqCz7uPeWQOM4cAzHIbKYGhDNf5EzG4yy2nGsyez/zlhjckkRvlH/330yeihuy C0+YEJrqSbAvXNKekI8IEAQgxkqN2x09SE1VojlLUaeK3V91L8mGohwP9Lg2u9bqUwuB eJmEW3mWX+Pwedfu52yb4e2xUjW6+psfU2SQFBIALHTTfV2LraLv3rxmLIe3vFFI944f AkRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=evMVBq6L/Q0iVblqVLHR1azbvHM0rC9x5PDOAiK8QFA=; b=V4bkyLvVqs3RAGgTK53UFpvcGBBYH++qKWGEmH7nolHkQIYcy1ItEqOQ1O+dHiaWya VN5cCss4dG0aqt4/eQCT+Y/L+PRHO5kIFn2UkEsy3XVLJlY51Z2m01p2S60jAvLIxQEJ 83obhzqyY2cLwPdPQIyGthQcy1olxegkuSyrsKgYlG9dOfmhQIMdTEh4rHcLbIKjwyT7 n7v//3F4YFdtO6EeEAI9akVqh7ajWiQpS9hhpUAqhawMAQaiST3felf1QPONXmBICzAC 2q5QvBOcDWQSdviGVd38on0CS6HNZG9K78kPAyZYiSH+21PE+NcNfAW+ckmGG2jtb39S 4rvg== X-Gm-Message-State: ALKqPwefYuJXwAo3bp/8Jo9CDO+H6wTWvVOgElrwhJbHg/AvoFytquSs BEvWEWy3FulEJNlXbSZ9AYM= X-Received: by 2002:a17:902:8b82:: with SMTP id ay2-v6mr6525644plb.295.1526233433493; Sun, 13 May 2018 10:43:53 -0700 (PDT) Received: from ast-mbp ([2620:10d:c090:180::1:daac]) by smtp.gmail.com with ESMTPSA id o88-v6sm15246393pfa.29.2018.05.13.10.43.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 May 2018 10:43:52 -0700 (PDT) Date: Sun, 13 May 2018 10:43:50 -0700 From: Alexei Starovoitov To: Thomas Gleixner Cc: Borislav Petkov , Peter Zijlstra , Yonghong Song , Ingo Molnar , Linus Torvalds , Alexei Starovoitov , Daniel Borkmann , LKML , X86 ML , Network Development , Kernel Team Subject: Re: [PATCH bpf v3] x86/cpufeature: bpf hack for clang not supporting asm goto Message-ID: <20180513174348.eoh2lrhzqbmqb5nc@ast-mbp> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 12, 2018 at 10:30:02PM +0200, Thomas Gleixner wrote: > On Sat, 12 May 2018, Alexei Starovoitov wrote: > > On Thu, May 10, 2018 at 10:58 AM, Alexei Starovoitov > > wrote: > > > I see no option, but to fix the kernel. > > > Regardless whether it's called user space breakage or kernel breakage. > > There is a big difference. If you are abusing a kernel internal header in a > user space tool, then there is absolutely ZERO excuse for requesting that > the header in question has to be modified. > > But yes, the situation is slightly different here because tools which > create trace event magic _HAVE_ to pull in kernel headers. At the same time > these tools depend on a compiler which failed to implement asm_goto for > fricking 8 years. As a maintainer of a piece of llvm codebase I have to say that this bullying tactic has the opposite effect. The inline asm is processed by gcc and llvm very differently. gcc is leaking internal backend implementation details into inline asm syntax. It makes little sense for llvm to do the same, since compiler codegen is completely different. gcc doesn't have integrated assembler whereas llvm not only can parse asm, but can potentially optimize it as well. Instead of demanding asm-goto that matches gcc one to one it's better to work with the community to define the syntax that works for both kernel and llvm. > So while Boris is right, that nothing has to fiddle with a kernel only > header, I grumpily agree with you that we need a workaround in the kernel > for this particular issue. > > > could you please ack the patch or better yet take it into tip tree > > and send to Linus asap ? > > Nope. The patch is a horrible hack. > > Why the heck do we need that extra fugly define? That has exactly zero > value simply because we already have a define which denotes availablity of > ASM GOTO: CC_HAVE_ASM_GOTO. I agree. That's why the v1 patch that was using CC_HAVE_ASM_GOTO was better: https://patchwork.kernel.org/patch/10333829/ I'm fine on adding a warning to it though. > In case of samples/bpf/ and libbcc the compile does not go through the > arch/x86 Makefile which stops the build anyway when ASM_GOTO is > missing. Those builds merily pull in the headers and have their own build > magic, which is broken btw: Changing a kernel header which gets pulled into > the build does not rebuild anything in samples/bpf. Qualitee.. > > So we can just use CC_HAVE_ASM_GOTO and be done with it. > > But we also want the tools which needs this to be aware of this. Peter > requested -D __BPF__ several times which got ignored. It's not too much of > a request to add that. quite the opposite. It was explained already why -D__BPF__ makes little sense. It's like saying that -D__arm__ has to be specified in command line. clang automatically adds -D__arm__ when '-target arm' is used and adds -D__BPF__ when '-target bpf' is used. For samples/bpf, libbcc and other cases we have to use -target native. If we do '-target native -D__BPF__' that's just like trying to compile kernel headers with '-target x86 -D__arm__'. Absurd. > Find a patch which deos exactly this for samples/bpf, but also allows other > tools to build with a warning emitted so they get fixed. agree > Thanks, > > tglx > > 8<---------------- > --- a/arch/x86/include/asm/cpufeature.h > +++ b/arch/x86/include/asm/cpufeature.h > @@ -140,6 +140,20 @@ extern void clear_cpu_cap(struct cpuinfo > > #define setup_force_cpu_bug(bit) setup_force_cpu_cap(bit) > > +#ifndef CC_HAVE_ASM_GOTO > + > +/* > + * Workaround for the sake of BPF compilation which utilizes kernel > + * headers, but clang does not support ASM GOTO and fails the build. > + */ > +#ifndef __BPF__ > +#warning "Compiler lacks ASM_GOTO support. Add -D __BPF__ to your compiler arguments" > +#endif Agree. The warning makes sense to me, but it has to be different macro name. How about -D__BPF_TRACING__ or -D__BPF_KPROBES__ or something similar ? Such name will also make it clear that only tracing bpf programs need this. Networking programs shouldn't be including kernel headers. There was never a need, but since the tracing progs are often used as an example people copy paste makefiles too. We tried to document it as much as possible, but people still use 'clang -target native -I/kernel/includes bpf_prog.c -emit-llvm | llc -march=bpf' in their builds. (sometimes as a workaround for setups where clang is older version, but llc/llvm is new) Now they will see this warning and it will force them to think whether they actually need the kernel headers. > + > +#define static_cpu_has(bit) boot_cpu_has(bit) > + > +#else > + > /* > * Static testing of CPU features. Used the same as boot_cpu_has(). > * These will statically patch the target code for additional > @@ -195,6 +209,7 @@ static __always_inline __pure bool _stat > boot_cpu_has(bit) : \ > _static_cpu_has(bit) \ > ) > +#endif > > #define cpu_has_bug(c, bit) cpu_has(c, (bit)) > #define set_cpu_bug(c, bit) set_cpu_cap(c, (bit)) > --- a/samples/bpf/Makefile > +++ b/samples/bpf/Makefile > @@ -255,7 +255,7 @@ verify_target_bpf: verify_cmds > $(obj)/%.o: $(src)/%.c > $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \ > -I$(srctree)/tools/testing/selftests/bpf/ \ > - -D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \ > + -D__KERNEL__ -D__BPF__ -Wno-unused-value -Wno-pointer-sign \ Yep. In samples/bpf and libbcc we can selectively add -D__BPF_TRACING__ I think sysdig and other folks can live with that as well. Agree?