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=-3.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_NEOMUTT 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 4EB33C282D7 for ; Wed, 30 Jan 2019 21:34:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02CF42184D for ; Wed, 30 Jan 2019 21:34:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i78FL0h+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388180AbfA3VeX (ORCPT ); Wed, 30 Jan 2019 16:34:23 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:32956 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730971AbfA3VeW (ORCPT ); Wed, 30 Jan 2019 16:34:22 -0500 Received: by mail-pf1-f196.google.com with SMTP id c123so440352pfb.0 for ; Wed, 30 Jan 2019 13:34:22 -0800 (PST) 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=QYvBrXqES9Ed5Zc0Ey9V+aQ65H4Y2fDZXFcIDYlo3VU=; b=i78FL0h+ztZFUKdgpILEXGcwyDevlAWE2+v1vGTafUDlZrvgYt+/l7+vOOdlAR59JI 0H4jTqShg0DPQwHBIfCvBhVYBErDucv88r151UDt0K3zsTmotznmde23TIR5pk9OZfKK EfzNm3vBV6BR95t8QNLkK1Bm6Bo37Mfs23YaltDZDKynEbE5FiTUE2HiIpF8BGb/eIjz ZUFE9ApMwac809a4048wxYXhZ2uGxIV684YUnmiCg3meeyDGTFbzi3dI9RLWaUgf2v6g 5YAH6OcL4R/dEVZBP3MP1Eq0I7yYJmj/YM/RgKEuNRp3I28RrL0NXisN/2KXsJk1KQyl Fy2Q== 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=QYvBrXqES9Ed5Zc0Ey9V+aQ65H4Y2fDZXFcIDYlo3VU=; b=QJxra+4oucvsrFzYuEBC0i2qlOrZX11X4tacmFsrMizNu84bHaO0ZJBMWlQXK4V9io oA2deJyu86hBHEBiJXn3MJ04EyF0Is7qQIZLyN8DnyLd3vOpMbJcRDvwwiwNkhIUOYjx GE5xoybWQptC2KNyzarEMYwvjmuM+SMmIvT19Lq5/u+RpwMODoCbL+oimlx3io9oIxa6 QRLaxwySY5YWH6ESTg59RdVhYn/lRhxDWIRehsFwWCKd/LJcLlml68ErhB7aPf/boePf AP5IipbI00cyhL80GBgXKPhOUZHrunKRntfdkRhjE5nbnztuC5wRVFxWGJs7LXcdy0l+ uc6A== X-Gm-Message-State: AJcUukdMy0O7qtx+WYP2FZoG7cdDkL6364hA3EyKtYvJvs4ctmTAPVF8 S8CD0M2iGnWBgy4GnTTk6Vk= X-Google-Smtp-Source: ALg8bN5AtgttuoLDTVbCAoTyq8JeX04zMcs3js6PQLd1Lzc9GnjsxKYHEi92JwcJ880E5cNre4ta1A== X-Received: by 2002:a63:df50:: with SMTP id h16mr29411298pgj.421.1548884061737; Wed, 30 Jan 2019 13:34:21 -0800 (PST) Received: from ast-mbp.dhcp.thefacebook.com ([2620:10d:c090:180::1:9e50]) by smtp.gmail.com with ESMTPSA id u186sm3421201pfu.51.2019.01.30.13.34.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 13:34:20 -0800 (PST) Date: Wed, 30 Jan 2019 13:34:19 -0800 From: Alexei Starovoitov To: Peter Zijlstra 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: <20190130213418.gxbyfbmuiohn7vj4@ast-mbp.dhcp.thefacebook.com> References: <20190128025010.342241-1-ast@kernel.org> <20190128025010.342241-2-ast@kernel.org> <20190130210529.GI2278@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190130210529.GI2278@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20180223 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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! Probably needs a kconfig change somewhere too... I'll play with it... > +} > + > +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. Should it be atomic_cond_read_relaxed(l, (!VAL)); like qspinlock.c does ?