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 41CBFC282C3 for ; Thu, 24 Jan 2019 18:57:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0FA85218CD for ; Thu, 24 Jan 2019 18:57:10 +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="R0icm7cn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729122AbfAXS5I (ORCPT ); Thu, 24 Jan 2019 13:57:08 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:52472 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725916AbfAXS5H (ORCPT ); Thu, 24 Jan 2019 13:57:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=nLUlDMNbMXGrYKr1A8zcqqpJ1tTCtN8d/0e7okAN4a8=; b=R0icm7cnYXE+eJfQN950ciyzn zB8HSjmgsO70sMrmS9yDcuYIhDWNEJbziz8fu/JGjLIT1hZ8RNrgVNMucqF7XsLjtBbpsHstR0Si6 mMQgtUKAbP6+1DHYOjbFoxhZ00cefFkrNJ4OF0psaF577XQZeavo2IpH85aDw16mYL/z69wQKeVbc Nd06dWTk6aqdTbCX37Luxm0tzkFD2NRuT1qtsfrPci96KB3Oq0q8bQlHhNueb0K4D0tgD8zLY4vIb EkTDI2dKwgOPIz+7oVlSpSFZYyJ7x5H5N26gWfphzmb+dYK9YFX6AM3W9jlgOhZcz9Q5nltrch16Y QERuzDwqQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gmkBK-0004we-Uw; Thu, 24 Jan 2019 18:56:55 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 76B7D20D15129; Thu, 24 Jan 2019 19:56:52 +0100 (CET) Date: Thu, 24 Jan 2019 19:56:52 +0100 From: Peter Zijlstra To: Alexei Starovoitov Cc: 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: [PATCH v4 bpf-next 1/9] bpf: introduce bpf_spin_lock Message-ID: <20190124185652.GB17767@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190124180109.GA27771@hirez.programming.kicks-ass.net> 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 Thu, Jan 24, 2019 at 07:01:09PM +0100, Peter Zijlstra wrote: > > Thanks for having kernel/locking people on Cc... > > On Wed, Jan 23, 2019 at 08:13:55PM -0800, Alexei Starovoitov wrote: > > > Implementation details: > > - on !SMP bpf_spin_lock() becomes nop > > Because no BPF program is preemptible? I don't see any assertions or > even a comment that says this code is non-preemptible. > > AFAICT some of the BPF_RUN_PROG things are under rcu_read_lock() only, > which is not sufficient. > > > - on architectures that don't support queued_spin_lock trivial lock is used. > > Note that arch_spin_lock cannot be used, since not all archs agree that > > zero == unlocked and sizeof(arch_spinlock_t) != sizeof(__u32). > > I really don't much like direct usage of qspinlock; esp. not as a > surprise. > > Why does it matter if 0 means unlocked; that's what > __ARCH_SPIN_LOCK_UNLOCKED is for. > > I get the sizeof(__u32) thing, but why not key off of that? > > > Next steps: > > - allow bpf_spin_lock in other map types (like cgroup local storage) > > - introduce BPF_F_LOCK flag for bpf_map_update() syscall and helper > > to request kernel to grab bpf_spin_lock before rewriting the value. > > That will serialize access to map elements. > > So clearly this map stuff is shared between bpf proglets, otherwise > there would not be a need for locking. But what happens if one is from > task context and another from IRQ context? > > I don't see a local_irq_save()/restore() anywhere. What avoids the > trivial lock inversion? > Also; what about BPF running from NMI context and using locks?