Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2416116pxb; Sat, 30 Jan 2021 01:48:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXGLPJiQJu1/nLdkTGKJvQaMH2vd1fNxn7mWOlrskyx1YUgDzRyQ0opyHqLCV6FM5nrYOv X-Received: by 2002:a17:906:2a06:: with SMTP id j6mr8076673eje.164.1612000124252; Sat, 30 Jan 2021 01:48:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612000124; cv=none; d=google.com; s=arc-20160816; b=wwKf4iIvpSkD2+HpxVt5OkeIIF09Ppe6kFdU+VUBsGSyft9FtLnSBggEuE8AkSU1dE LG7yoDeGJ/3pnP6v1VeVSE080liUbct54eP34x8Raa1NfRHKVU0mI2ukQBMjBpsOGc8x 9Jj8f0+zKFkn9wpiZ7rswyDvxllBTImgyp1om/G/WQaBd2AvbAFDmfghVHq8xFzWuKn5 PZNZzikfTvLT9BNXvuthIlcaovuTPBv+IFH7AzP8ZZUmPdsHO2IH1D+VzqrlMTamm7aL gZhjQOVObdRCqsxreQbkXmvOtFF8XJ4W9AuTl4wRxJFd5TrQB8q9BsY1kCvhxD5rkfeG 8Lbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fxxmy0+c2BO16EPS4+AnuzVSZ0E7CPss9SONuFG9YHI=; b=p3Z9zwn4fV+5d2rqbauSE6exhN6PjAALSMaCu0CXyL+lMWqvZrXnsUIYsFQaPK+8J2 btVshc1eGiL7sv0N28vyh9xxchCBY3fFFSRnx6iqEUeMJx8MOv0t8nroPxand5bfV32Z 5Kp4b7qDxy/HhQy4r7nkTW0R8OwIsTOniC5v7U7GNDSthhASRCpypUwCg9GFOqfunOfp /m0+TzOwC9biuL0XoxnNmJwT2p/MXTRNDAlFVhoEWuayIinTqTRML9UK3XjiaqZ4PvXe mHuLOpRDPhDUlD74MDhAzjYxFJKjnAfocWGYITXBa/s5+/U6dcBJI9Eb1x2ujCA2g/dE hVZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PEGwURYi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f22si6634150edw.413.2021.01.30.01.48.20; Sat, 30 Jan 2021 01:48:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PEGwURYi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231969AbhA3Jpa (ORCPT + 99 others); Sat, 30 Jan 2021 04:45:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233436AbhA3DJ7 (ORCPT ); Fri, 29 Jan 2021 22:09:59 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6298AC061794; Fri, 29 Jan 2021 19:08:44 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id md11so6761507pjb.0; Fri, 29 Jan 2021 19:08:44 -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; bh=fxxmy0+c2BO16EPS4+AnuzVSZ0E7CPss9SONuFG9YHI=; b=PEGwURYigrOxtk6A4BMnJcnVgyrOUdWGAsh7VPX3Te6XTPF3Fv8Ujuh3Is2A/i6bxl Dh96clPK2Qsu3As+pokjdjH+CqDxLUNtORvzUEzSaXQLI7cQcU9UlugfdHEZ31zX2fWl 3oXK+GaB/SXdsdkZWViVT3auEdgzXejg+3Vmpw/ERdAxjR+/wNg3SMJE0HQ7i0oAzEQv 0H20zJnkVoJ5GxJ1y7c1vhxQxA7ELWn/xv0qAWR3RV6fFD2pNkMK9xtwhZKzAtn+Lwqv jqDk8V8x+Kc663xwpwhQuR0INWZPBovJdT/ZcOqHwT7F4iQEsteTEB1meazJyQC3kGd0 BBvA== 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; bh=fxxmy0+c2BO16EPS4+AnuzVSZ0E7CPss9SONuFG9YHI=; b=NFH1ZoKFQNk+3u6rmIlFYocdBqdiorOHIPqzK6H/bHTbV/cZsXzrl4JCAq4su+oMF+ UWx8OprY8+8RjWUq5ayX2tjs9eGWTttptI1hgEw17M8V0icEE2+hwqMqmlwFRU70Z2VO KOc6GGxIZA8QpeZrElXpC25/KhzPquNCULswd0vnMpdHcziynYiAdgwUzMUZWu9wUWIz MnOcidp4JrBRBthtwz/DFwnqO1WgmWnPr3aprNpICSoZAHyfxl9Fg9vb1ly23X/2srPR hFdcNnR4U6sPMC3CZ12CmZgDQQOTdZClQiuBvKE3fZYYiazMfnq9ZJPGXr+ywaqXkC2B 2vzQ== X-Gm-Message-State: AOAM533+tAa+nflD7Mg6t8d0f7lDweBGuMr1iICl6/59+3BvrRAG4Ziv ow9JHm5msO4SkLPBv/2OLVQ= X-Received: by 2002:a17:90a:4494:: with SMTP id t20mr7280543pjg.155.1611976123785; Fri, 29 Jan 2021 19:08:43 -0800 (PST) Received: from ast-mbp.dhcp.thefacebook.com ([2620:10d:c090:400::5:a3a0]) by smtp.gmail.com with ESMTPSA id u31sm10527671pgl.9.2021.01.29.19.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jan 2021 19:08:42 -0800 (PST) Date: Fri, 29 Jan 2021 19:08:40 -0800 From: Alexei Starovoitov To: Masami Hiramatsu Cc: Peter Zijlstra , Steven Rostedt , Nikolay Borisov , LKML , Alexei Starovoitov , bpf , Josh Poimboeuf Subject: Re: kprobes broken since 0d00449c7a28 ("x86: Replace ist_enter() with nmi_enter()") Message-ID: <20210130030840.hodq2ixpkdoue5jd@ast-mbp.dhcp.thefacebook.com> References: <20210129013452.njuh3fomws62m4rc@ast-mbp.dhcp.thefacebook.com> <20210129224011.81bcdb3eba1227c414e69e1f@kernel.org> <20210129105952.74dc8464@gandalf.local.home> <20210129162438.GC8912@worktop.programming.kicks-ass.net> <20210129175943.GH8912@worktop.programming.kicks-ass.net> <20210130110249.61fdad8f0cfe51a121c72302@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210130110249.61fdad8f0cfe51a121c72302@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 30, 2021 at 11:02:49AM +0900, Masami Hiramatsu wrote: > On Fri, 29 Jan 2021 18:59:43 +0100 > Peter Zijlstra wrote: > > > On Fri, Jan 29, 2021 at 09:45:48AM -0800, Alexei Starovoitov wrote: > > > Same things apply to bpf side. We can statically prove safety for > > > ftrace and kprobe attaching whereas to deal with NMI situation we > > > have to use run-time checks for recursion prevention, etc. > > > > I have no idea what you're saying. You can attach to functions that are > > called with random locks held, you can create kprobes in some very > > sensitive places. > > > > What can you staticlly prove about that? > > For the bpf and the kprobe tracer, if a probe hits in the NMI context, > it can call the handler with another handler processing events. > > kprobes is carefully avoiding the deadlock by checking recursion > with per-cpu variable. But if the handler is shared with the other events > like tracepoints, it needs to its own recursion cheker too. > > So, Alexei, maybe you need something like this instead of in_nmi() check. > > DEFINE_PER_CPU(bool, under_running_bpf); > > common_handler() > { > if (__this_cpu_read(under_running_bpf)) > return; > __this_cpu_write(under_running_bpf, true); > /* execute bpf prog */ > __this_cpu_write(under_running_bpf, false); > } > > Does this work for you? This exactly check is already in trace_call_bpf. Right after if (in_nmi()). See bpf_prog_active. It serves different purpose though. Simply removing if (in_nmi()) from trace_call_bpf is a bit scary. I need to analyze all code paths first.