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 46E05C282C0 for ; Fri, 25 Jan 2019 08:39:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 174922084A for ; Fri, 25 Jan 2019 08:39:08 +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="jl4rJSmO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726926AbfAYIjH (ORCPT ); Fri, 25 Jan 2019 03:39:07 -0500 Received: from merlin.infradead.org ([205.233.59.134]:39268 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbfAYIjG (ORCPT ); Fri, 25 Jan 2019 03:39:06 -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=EZwHg7Hd00AeQkH0Aos81Jq+WOvoFY6Rz7x21g30Qms=; b=jl4rJSmOqCY7jfiz0D6YPbJW8 mHubmeFUwHS4P9QMY+gYJ1WXrpPljYn4l7+jkCQDmVMSyIPwG664AdYyYMsXtgCh4sax4alijgCGQ mDpy1bIcoX3Jy4qD5hVWCiphS28xJOx8lUayPwc3vRpYPCLuHA+H70O5MkUWAR4rCNhiWuy7zIdQK iJQzfdu7aQD0mFUYUj6RKu2A8436bfPYxBLFse9xlFLXftlXtwOlR+wuY2FMpKUY+hQ4vKPAdjuLy FBaxiFKE8C88OBAUv+Xp0Aw9FIuS29VcuZFR2HC+lZs8oPoxmZIy8caDlegKjq8ntd9YR2HkxqRC9 yowXz5HTg==; 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 1gmx0i-00034N-N2; Fri, 25 Jan 2019 08:38:48 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 200BF20D1512E; Fri, 25 Jan 2019 09:38:46 +0100 (CET) Date: Fri, 25 Jan 2019 09:38:46 +0100 From: Peter Zijlstra To: Alexei Starovoitov Cc: Eric Dumazet , 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: [PATCH v4 bpf-next 1/9] bpf: introduce bpf_spin_lock Message-ID: <20190125083846.GJ17749@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> <395a3741-70c9-c345-08a4-77bc3bd3cae2@gmail.com> <20190125023402.34a5k62furpdismi@ast-mbp.dhcp.thefacebook.com> <9e1fa851-e189-ab17-ae34-236cc6b5a8b4@gmail.com> <20190125025659.netyncl6vvtbv6oj@ast-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190125025659.netyncl6vvtbv6oj@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 Thu, Jan 24, 2019 at 06:57:00PM -0800, Alexei Starovoitov wrote: > On Thu, Jan 24, 2019 at 06:44:20PM -0800, Eric Dumazet wrote: > > Let see if we understood this well. > > > > 1. create perf event PERF_TYPE_HARDWARE:PERF_COUNT_HW_CPU_CYCLES > > 2. attach bpf probram to this event > > 3. since that's a hw event, the bpf program is executed in NMI context > > 4. the bpf program calls bpf_get_stackid to record the trace in a bpf map > > 5. bpf_get_stackid calls pcpu_freelist_pop and pcpu_freelist_push from NMI How is this not a straight up bug? NMI code should not ever call code that uses spinlocks. > > 6. userspace calls sys_bpf(bpf_map_lookup_elem) which calls bpf_stackmap_copy which can call pcpu_freelist_push > > argh. lookup cmd is missing __this_cpu_inc(bpf_prog_active); like update/delete do. > Will fix. > > > It seems pcpu_freelist_pop and pcpu_freelist_push are not NMI safe, > > so what prevents bad things to happen ? > > nmi checks for bpf_prog_active==0. See bpf_overflow_handler. yuck yuck yuck.. That's horrific :-( That means the whole BPF crud is unreliable and events can go randomly missing.