Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1225199ybh; Tue, 10 Mar 2020 17:40:37 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtc9dpKLUVjp6+sGMMGHFL4rp4ryW6pAXdTTni7FGmDmww4ZsGPD3RNvZAsBWa6NLYoU96H X-Received: by 2002:aca:1b09:: with SMTP id b9mr247220oib.170.1583887237288; Tue, 10 Mar 2020 17:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583887237; cv=none; d=google.com; s=arc-20160816; b=d6VskfTDPDmaLTcy7pc9t1ACDZfxAk8Ok2JrrWk0h0liWNAWSvWNPcRfhaRLFVUO0X nUSP+wmqfcSxE82nwS0t/mfPC9O0ZFELu7a0M011vhNAl3GonGvq+wNmwoJ0UJ4JV5K5 iMsGEYieJWc9ea+BC6tirHorsN0DxNTS1ncTlA0UdSgSIN9GumKlj3qlYHpaoluFzCiW WheR+rjDWxJQ1jEPx1inLAJYDEhxTDrYW1QeYg1PKYBge+2eu9HA3rzwSb/3lmgzQb2u IzoN2bnrdpaYu8N61Ny2LI5+Mf7N3muzf4kaqqKlbVcE5JeBJAep+Im+N6mWjZFFsM25 diCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=U7LALiVWnzC6Qqk8on30unANb+95Awa8y5B50fzooEw=; b=AqicEnSTrgvh4teWY/SgFUIXcoSI4ss3Xb6Rq6hq+8mI70y8WJqvoxSJ2p+E9zrmJv re14j94H7NmIwUNqqR2yqxTU4SKAuVxgZJqLOjkfOItHsXKK1XxrQUMRg+bfb+7m3iE3 UDY6LE08DvJvfWJKxIaL7XyZsIRl+YTyJThs8qw2SKIIwvfAi1fura+2pZHHdQk9kVD0 IUy0bP5bgdvNQdnluFS+rKeRLoSVL7lwPns+TMPMCqGMgOx9d8zcMSX6i1qAzxBg3M+T qpIpapZJLneN44g0ILpY6PeCgYCHsb0LjFEKGvKOwZhlogw9TpPNw3PNnCUJJKQm9SgE 8vgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=quq+3ext; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r7si245345oic.229.2020.03.10.17.40.24; Tue, 10 Mar 2020 17:40:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=quq+3ext; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727894AbgCKAhn (ORCPT + 99 others); Tue, 10 Mar 2020 20:37:43 -0400 Received: from mail.efficios.com ([167.114.26.124]:59034 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726380AbgCKAhn (ORCPT ); Tue, 10 Mar 2020 20:37:43 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id E7596274CD6; Tue, 10 Mar 2020 20:37:41 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id mJln51YZFwyu; Tue, 10 Mar 2020 20:37:41 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 9825F274CD5; Tue, 10 Mar 2020 20:37:41 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 9825F274CD5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1583887061; bh=U7LALiVWnzC6Qqk8on30unANb+95Awa8y5B50fzooEw=; h=Date:From:To:Message-ID:MIME-Version; b=quq+3extVd1A47yffX1wsAG3fOcc5745ii4EGJDOwqVXggQnIG6DPa/lgcO8dtg4E gIEHrpjlWFTtkqD4ZQQewWAY/0fQPeG4RfbU195kEUXLNB4MnW0B1y+XLZQr9RAKCK UReuqrFBrfI3seiptMl3l5e5hsn4D6H1CQNxEGjrj4d2mz43/216H5d5T/kaDjwpEz jjf97Pp0Je94eXw9YKRahysJkEyR/Cs/M+bbfMT3M/+rYsPvDQG7juDeTVnkm2JMwd onMpmkOkCX5xmZV+3YWmhRZkXx2QAtXOBkzmxTsBPrXoIZp0fP5tkjw3a2Khnm9yku TuFBz91uXJKXQ== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id R9pO-4JRyErH; Tue, 10 Mar 2020 20:37:41 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id 8626E275011; Tue, 10 Mar 2020 20:37:41 -0400 (EDT) Date: Tue, 10 Mar 2020 20:37:41 -0400 (EDT) From: Mathieu Desnoyers To: Masami Hiramatsu Cc: rostedt , Thomas Gleixner , linux-kernel , Peter Zijlstra , Alexei Starovoitov , paulmck , "Joel Fernandes, Google" , Frederic Weisbecker , Jason Wessel Message-ID: <831351096.24668.1583887061530.JavaMail.zimbra@efficios.com> In-Reply-To: <20200311091815.fce458348bb7641b60f600d9@kernel.org> References: <87mu8p797b.fsf@nanos.tec.linutronix.de> <87fteh73sp.fsf@nanos.tec.linutronix.de> <20200310170951.87c29e9c1cfbddd93ccd92b3@kernel.org> <87pndk5tb4.fsf@nanos.tec.linutronix.de> <450878559.23455.1583854311078.JavaMail.zimbra@efficios.com> <20200310114657.099122fd@gandalf.local.home> <1760242532.23694.1583857291763.JavaMail.zimbra@efficios.com> <20200311091815.fce458348bb7641b60f600d9@kernel.org> Subject: Re: Instrumentation and RCU MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3901 (ZimbraWebClient - FF73 (Linux)/8.8.15_GA_3895) Thread-Topic: Instrumentation and RCU Thread-Index: hz+zwspBrcoLTdRQIpEDllLfCMkCTw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Mar 10, 2020, at 8:18 PM, Masami Hiramatsu mhiramat@kernel.org wrote: [...] >> An approach where the "in_tracer" flag is tested and set by the instrumentation >> (function tracer, kprobes, tracepoints) would work here. Let's say the beginning >> of the int3 ISR is part of the code which is invisible to instrumentation, and >> before we issue rcu_nmi_enter(), we handle the in_tracer flag: >> >> rcu_nmi_enter(); >> >> (recursion_ctx->in_tracer == false) >> set recursion_ctx->in_tracer = true >> do_int3() { >> rcu_nmi_enter(); >> >> if (recursion_ctx->in_tracer == true) >> iret >> >> We can change "in_tracer" for "in_breakpoint", "in_tracepoint" and >> "in_function_trace" if we ever want to allow different types of instrumentation >> to nest. I'm not sure whether this is useful or not through. > > Kprobes already has its own "in_kprobe" flag, and the recursion path is > not so simple. Since the int3 replaces the original instruction, we have to > execute the original instruction with single-step and fixup. > > This means it involves do_debug() too. Thus, we can not do iret directly > from do_int3 like above, but if recursion happens, we have no way to > recover to origonal execution path (and call BUG()). I think that all the code involved when hitting a breakpoint which would be the minimal subset required to act as if the kprobe was not there in the first place (single-step, fixup) should be hidden from kprobes instrumentation. I suspect this is the current intent today with noprobe annotations, but Thomas' proposal brings this a step further. However, any other kprobe code (and tracer callbacks) beyond that minimalistic "effect-less" kprobe could be protected by a per-recursion-context in_kprobe flag. > As my previous email, I showed a patch which is something like > "bust_kprobes()" for oops path. That is not safe but no other way to escape > from this recursion hell. (Maybe we can try to call it instead of calling > BUG() so that the kernel can continue to run, but I'm not sure we can > safely make the pagetable to readonly again.) As long as we provide a minimalistic "effect-less" kprobe implementation in a non-instrumentable section which can be used whenever we are in a recursion scenario, I think we could achieve something recursion-free without requiring a bust_kprobes() work-around. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com