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 A4A91C282C7 for ; Thu, 31 Jan 2019 08:50:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 87A7A2087F for ; Thu, 31 Jan 2019 08:50:50 +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="g4k+NB3c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730734AbfAaIup (ORCPT ); Thu, 31 Jan 2019 03:50:45 -0500 Received: from merlin.infradead.org ([205.233.59.134]:58586 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728746AbfAaIuM (ORCPT ); Thu, 31 Jan 2019 03:50:12 -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=+6HucafRcQ+5O7XlIqoh1nvg6r0l2sTMSd1FUgxBaPc=; b=g4k+NB3c1ffUWt7fn9SEBjiyK nrCfkGpx7h7pP9OYok76xtkvjQBUsBMnPV1fFl3zr735VoVCrfaNKQu8kM2k4mh8jGynm/GMwuwrd SIJAbzn6BPCAt6il8bO4A5D7JyiMkKB7qJ0ORwch0EyJ32EM4EHAJZMuq0SK10iYoG2YBmJU2+jB0 uYRFP/DbBJ59pQgZsdxVU0Sz+XJdgSu4CykgMkCEEWlbEdjmONyCgQ6Qlt+v3V03RK4OOeBI6LzKE 2NScd4JhXwaECubl2V2dL8TiwxKRFSKWgi1IDOuuh7v5NNCZroApONFGbZWY26R6ExszRZYEGDW77 8Nn+14gLQ==; 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 1gp82l-00033u-CT; Thu, 31 Jan 2019 08:49:55 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A02B220276ABC; Thu, 31 Jan 2019 09:49:52 +0100 (CET) Date: Thu, 31 Jan 2019 09:49:52 +0100 From: Peter Zijlstra To: Alexei Starovoitov Cc: Alexei Starovoitov , davem@davemloft.net, daniel@iogearbox.net, jannh@google.com, paulmck@linux.ibm.com, will.deacon@arm.com, mingo@redhat.com, netdev@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH v5 bpf-next 1/9] bpf: introduce bpf_spin_lock Message-ID: <20190131084952.GG2296@hirez.programming.kicks-ass.net> References: <20190128025010.342241-1-ast@kernel.org> <20190128025010.342241-2-ast@kernel.org> <20190130210529.GI2278@hirez.programming.kicks-ass.net> <20190130213418.gxbyfbmuiohn7vj4@ast-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190130213418.gxbyfbmuiohn7vj4@ast-mbp.dhcp.thefacebook.com> 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 Wed, Jan 30, 2019 at 01:34:19PM -0800, Alexei Starovoitov wrote: > On Wed, Jan 30, 2019 at 10:05:29PM +0100, Peter Zijlstra wrote: > > > > Would something like the below work for you instead? > > > > I find it easier to read, and the additional CONFIG symbol would give > > architectures (say ARM) an easy way to force the issue. > > > > > > --- a/kernel/bpf/helpers.c > > +++ b/kernel/bpf/helpers.c > > @@ -221,6 +221,72 @@ const struct bpf_func_proto bpf_get_curr > > .arg2_type = ARG_CONST_SIZE, > > }; > > > > +#if defined(CONFIG_QUEUED_SPINLOCKS) || defined(CONFIG_BPF_ARCH_SPINLOCK) > > + > > +static inline void __bpf_spin_lock(struct bpf_spin_lock *lock) > > +{ > > + arch_spinlock_t *l = (void *)lock; > > + BUILD_BUG_ON(sizeof(*l) != sizeof(__u32)); > > + if (1) { > > + union { > > + __u32 val; > > + arch_spinlock_t lock; > > + } u = { .lock = __ARCH_SPIN_LOCK_UNLOCKED }; > > + compiletime_assert(u.val == 0, "__ARCH_SPIN_LOCK_UNLOCKED not 0"); > > + } > > + arch_spin_lock(l); > > And archs can select CONFIG_BPF_ARCH_SPINLOCK when they don't > use qspinlock and their arch_spinlock_t is compatible ? > Nice. I like the idea! Exactly, took me a little while to come up with that test for __ARCH_SPIN_LOCK_UNLOCKED, but it now checks for both assumptions, so no surprises when people get it wrong by accident. > > +} > > + > > +static inline void __bpf_spin_unlock(struct bpf_spin_lock *lock) > > +{ > > + arch_spinlock_t *l = (void *)lock; > > + arch_spin_unlock(l); > > +} > > + > > +#else > > + > > +static inline void __bpf_spin_lock(struct bpf_spin_lock *lock) > > +{ > > + atomic_t *l = (void *)lock; > > + do { > > + atomic_cond_read_relaxed(l, !VAL); > > wow. that's quite a macro magic. Yeah, C sucks for not having lambdas, this was the best we could come up with. This basically allows architectures to optimize the wait-for-variable-to-change thing. Currently only ARM64 does that, I have a horrible horrible patch that makes x86 use MONITOR/MWAIT for this, and I suppose POWER should use it but doesn't. > Should it be > atomic_cond_read_relaxed(l, (!VAL)); > like qspinlock.c does ? Extra parens doesn't hurt of course, but I don't think it's strictly needed, the atomic_cond_read_*() wrappers already add extra parent before passing it on to smp_cond_load_*().