From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E611C169C4 for ; Tue, 29 Jan 2019 09:17:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CBFCB20857 for ; Tue, 29 Jan 2019 09:17:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BTMng8Zt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727902AbfA2JRQ (ORCPT ); Tue, 29 Jan 2019 04:17:16 -0500 Received: from merlin.infradead.org ([205.233.59.134]:56034 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbfA2JRQ (ORCPT ); Tue, 29 Jan 2019 04:17:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=BJMUvg/CR/J/FTTeRVwuPO441iWkQaRJqE7SHDwiBH0=; b=BTMng8Zt4YGsWCz0SDz9CxjOe b2kOToLlULXE32sucigzTF3YLeT7JXxW+CLHv96L6ybBemEQhiePPeY6ODlzO78AbXX200k4ewrAP wAhiip51YanzBy/H+ams0t353rVG7NeA/y/Irs7bHGBe8Fjb6AzPFRvEO7XcxaUGwFgZ7QFNrNrKu BdoRalIdQ0rDGvSCHU9wLSQgQ17WoTEiCCzN8N+BhB7/tKrjtODLb+gg43g9s0OAkR6x5MAow1CzQ 5QiUTRZL+LtyZcWr3rlC9tUxp2p0kkIdjcJbTs1EIeqDwrKh+9YYd6+EBiP47h+a9mT7oU/gfSOZ/ xHzDZSiLA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1goPVo-0008Bw-5g; Tue, 29 Jan 2019 09:16:56 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C6A9A25E14D6D; Tue, 29 Jan 2019 10:16:54 +0100 (CET) Date: Tue, 29 Jan 2019 10:16:54 +0100 From: Peter Zijlstra To: Alexei Starovoitov Cc: Alexei Starovoitov , davem@davemloft.net, daniel@iogearbox.net, jakub.kicinski@netronome.com, netdev@vger.kernel.org, kernel-team@fb.com, mingo@redhat.com, will.deacon@arm.com, Paul McKenney , jannh@google.com Subject: Re: bpf memory model. Was: [PATCH v4 bpf-next 1/9] bpf: introduce bpf_spin_lock Message-ID: <20190129091654.GD28485@hirez.programming.kicks-ass.net> References: <20190124041403.2100609-1-ast@kernel.org> <20190124041403.2100609-2-ast@kernel.org> <20190124180109.GA27771@hirez.programming.kicks-ass.net> <20190124235857.xyb5xx2ufr6x5mbt@ast-mbp.dhcp.thefacebook.com> <20190125102312.GC4500@hirez.programming.kicks-ass.net> <20190126001725.roqqfrpysyljqiqx@ast-mbp.dhcp.thefacebook.com> <20190128092408.GD28467@hirez.programming.kicks-ass.net> <20190128215623.6eqskzhklydhympa@ast-mbp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190128215623.6eqskzhklydhympa@ast-mbp> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, Jan 28, 2019 at 01:56:24PM -0800, Alexei Starovoitov wrote: > On Mon, Jan 28, 2019 at 10:24:08AM +0100, Peter Zijlstra wrote: > > Ah, but the loop won't be in the BPF program itself. The BPF program > > would only have had the BPF_SPIN_LOCK instruction, the JIT them emits > > code similar to queued_spin_lock()/queued_spin_unlock() (or calls to > > out-of-line versions of them). > > As I said we considered exactly that and such approach has a lot of downsides > comparing with the helper approach. > Pretty much every time new feature is added we're evaluating whether it > should be new instruction or new helper. 99% of the time we go with new helper. Ah; it seems I'm confused on helper vs instruction. As in, I've no idea what a helper is. > > There isn't anything that mandates the JIT uses the exact same locking > > routines the interpreter does, is there? > > sure. This bpf_spin_lock() helper can be optimized whichever way the kernel wants. > Like bpf_map_lookup_elem() call is _inlined_ by the verifier for certain map types. > JITs don't even need to do anything. It looks like function call from bpf prog > point of view, but in JITed code it is a sequence of native instructions. > > Say tomorrow we find out that bpf_prog->bpf_spin_lock()->queued_spin_lock() > takes too much time then we can inline fast path of queued_spin_lock > directly into bpf prog and save function call cost. OK, so then the JIT can optimize helpers. Would it not make sense to have the simple test-and-set spinlock in the generic code and have the JITs use arch_spinlock_t where appropriate?