Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752417AbbKKR1I (ORCPT ); Wed, 11 Nov 2015 12:27:08 -0500 Received: from mail-pa0-f48.google.com ([209.85.220.48]:34814 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751881AbbKKR1G (ORCPT ); Wed, 11 Nov 2015 12:27:06 -0500 Date: Wed, 11 Nov 2015 09:27:00 -0800 From: Alexei Starovoitov To: Will Deacon Cc: Daniel Borkmann , Peter Zijlstra , Arnd Bergmann , "Shi, Yang" , linaro-kernel@lists.linaro.org, Eric Dumazet , Z Lim , Alexei Starovoitov , LKML , Network Development , Xi Wang , Catalin Marinas , "linux-arm-kernel@lists.infradead.org" , yhs@plumgrid.com, bblanco@plumgrid.com Subject: Re: [PATCH 2/2] arm64: bpf: add BPF XADD instruction Message-ID: <20151111172659.GA86334@ast-mbp.thefacebook.com> References: <4902833.k8y8bz0YLV@wuerfel> <20151111102406.GB9562@arm.com> <56431B83.5060500@iogearbox.net> <20151111115851.GE9562@arm.com> <564332B0.2090103@iogearbox.net> <20151111123831.GJ9562@arm.com> <20151111125807.GP17308@twins.programming.kicks-ass.net> <56436420.9090401@iogearbox.net> <20151111162341.GN9562@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151111162341.GN9562@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1729 Lines: 42 On Wed, Nov 11, 2015 at 04:23:41PM +0000, Will Deacon wrote: > > If we're going to document it, a bug tracker might be a good place to > start. The behaviour, as it stands, is broken wrt the definition of the > __sync primitives. That is, there is no way to build __sync_fetch_and_add > out of BPF_XADD without changing its semantics. BPF_XADD == atomic_add() in kernel. period. we are not going to deprecate it or introduce something else. Semantics of __sync* or atomic in C standard and/or gcc/llvm has nothing to do with this. arm64 JIT needs to JIT bpf_xadd insn equivalent to the code of atomic_add() which is 'stadd' in armv8.1. The cpu check can be done by jit and for older cpus just fall back to interpreter. trivial. > We could fix this by either: > > (1) Defining BPF_XADD to match __sync_fetch_and_add (including memory > barriers). nope. > (2) Introducing some new BPF_ atomics, that map to something like the > C11 __atomic builtins and deprecating BPF_XADD in favour of these. nope. > (3) Introducing new source-language intrinsics to match what BPF can do > (unlikely to be popular). llvm's __sync intrinsic is used temporarily until we have time to do new intrinsic in llvm that matches kernel's atomic_add() properly. It will be done similar to llvm-bpf load_byte/word intrinsics. Note that we've been hiding it under lock_xadd() wrapper, like here: https://github.com/iovisor/bcc/blob/master/examples/networking/tunnel_monitor/monitor.c#L130 -- 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/