Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2266403pxb; Fri, 29 Jan 2021 19:09:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLF1/hseMpNUSHyUb/BsmCrIMF/ToUZk/ke2SvMrNF6fHyx1VVncAb9cwahnarYE042Vfj X-Received: by 2002:a17:906:2b9b:: with SMTP id m27mr7476074ejg.92.1611976148044; Fri, 29 Jan 2021 19:09:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611976148; cv=none; d=google.com; s=arc-20160816; b=c3PoYNcc/wOcjnkJrihKnxYCDpG2S28NLGTG83LWEGM+msumKhzPoXMCX7XAgHOV5B LZpJTvBLc1oeb5d2pTtm1azIEv69zhVR8nxXXPOkp7vYJ4X8pcw6UfRE+0or0za2JrUJ bOCcY06XvOezqkWWdrTFBqfXC/hf1Zv3QZRQCzNg7dZw23ahKOPUia7XbO6nivV2hM4w alKoqFqkEvx2R5sAjTou8OW76N9dBXtRZFD/uZLG9HrospV5M3ZEAalblJpcW/JAYAgQ SwatPxPzjumzcHtKzzsx07jRWhmDFohe1/GeNJ6n0ZvJSd2949t68RRC9lmR06570VMh ji4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=dLLGZj/7AS+kJeqmdEgLIDfC0G6VPy+D6Ek9bnWYD1w=; b=LH29ydx9XpLW3YN/K7+WEmbvBbCBEEY1sZQgMi/FvwSMYP4XpE7+a78DCRSUO5ST6j 5zQ54Cj1wHgMkejCnDyG+LSOn7wCFWy9GHeINK+LTPkloWCWVHECiP0hln4IIELNHn0Y iKWLsTwJIH3bz9NpIA1pA7PxFR897inWesu0OfQw5NHxe53V2cKh3UPbz6wSPoSvogZ5 +/WmO0zMBOgDTPfQM2m7ZzowiKe9HZO2Nvpvczoxr+hjJZuWMA1FMu2tNXBu8W7M4pvH ud/fRqN7/yANTsXDsv/zTUR1Nl8+lj5Wx62HIW5n3Fzuq3/NAFUwnv7Mq650r0gdJizf yVyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZGY3sYfF; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v5si6411989eda.107.2021.01.29.19.08.29; Fri, 29 Jan 2021 19:09:08 -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=@kernel.org header.s=k20201202 header.b=ZGY3sYfF; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233319AbhA3Cvf (ORCPT + 99 others); Fri, 29 Jan 2021 21:51:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:58498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233135AbhA3COp (ORCPT ); Fri, 29 Jan 2021 21:14:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BCF7064E02; Sat, 30 Jan 2021 02:02:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611972174; bh=lbJlMuUVFRumkCODX2oNdPrWomOmGRFVYk+u+Pk4cAk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ZGY3sYfFNa8fp2aAB7QLpHVEhVZfaU9pRHb/XZXWcaPO81ej2FYIvulA9wfawyD3N qtYRYJf+IncguHjJ0fRU20bfEjPhsdYcj5nNmKQAqwtRTYRg8J1Qp2EU0pX7oz6Nqi PUMmDr+AvXUvhJWKCpiRpjI09v1HXI/hR22+7BUHxUvD4nOJBEa33MQr4GavsSms65 myoccoR/EgHkx4Htx+6rqwBz4b8vl5LmMqqmGb3qQMDMXcj/Wb20q/KrGLswHuK11f jkzrBJutMwuQckXyhXsqR/6pRfaE2WX9dr+0gtDA/NAe0rnK4++6EQM79SBeOmk28K +OEGQIn2h6Zmw== Date: Sat, 30 Jan 2021 11:02:49 +0900 From: Masami Hiramatsu To: Peter Zijlstra Cc: Alexei Starovoitov , Steven Rostedt , Masami Hiramatsu , Nikolay Borisov , LKML , Alexei Starovoitov , bpf , Josh Poimboeuf Subject: Re: kprobes broken since 0d00449c7a28 ("x86: Replace ist_enter() with nmi_enter()") Message-Id: <20210130110249.61fdad8f0cfe51a121c72302@kernel.org> In-Reply-To: <20210129175943.GH8912@worktop.programming.kicks-ass.net> References: <20210128123842.c9e33949e62f504b84bfadf5@gmail.com> <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> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Thank you, -- Masami Hiramatsu