Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2089874rwd; Wed, 17 May 2023 05:45:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7hik2wWoTgeUs12/3U6biHnRU/XZUZwbmDvyPQ35RW4tsGQRcMmyOP6blhl4a7A+h/aPH9 X-Received: by 2002:a05:6a20:6a22:b0:101:7703:3376 with SMTP id p34-20020a056a206a2200b0010177033376mr2648969pzk.4.1684327549671; Wed, 17 May 2023 05:45:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684327549; cv=none; d=google.com; s=arc-20160816; b=wsnJl4BhOthKxeqFmnt/zsu8xt+Q5WxBpGigPDHXsUDFfXKZ2uPLIKWUhoqBWxPExj G/INNxQDiBLC2t3NwvkMf/XcQ/JGbmm29KJu9M0oHD98hxQdJOefPxWsIoVyvABfZ8OK WDMdlRqCLUCeM4oIgicflt6y2hgHXZcO3Tce+0xYWekYf7oC3+XZQ+pqD70L+R/HdzFC E+s5AMjqpI3a3e7xd9S3SqYZNnjJMH7N4ADXDajsbDjb+jsIf7zDPzb4ihC0CGgG6i6i H3uorsM0Z9kKMn6I6f+lVmkysJjztTtdJ8JdnfeAKa6x/f/A1XCT2pfT6AAyZvrtrtEK lAbA== 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:date:from:dkim-signature; bh=zG7OAtWW1ntr+yw/2O/iG28G8+bEDuvHfZ1bydZEJAA=; b=qLOtUgVFHRzKuk1tAbVSJhhWIWMHy86am7cUwQ2amJIrQOUMu38NfqgFP0OcY9Gjmt GunmZmshuu2XbaJ6BpmlSW6t8UEejsAXdfiGRMvdlOzauJ5ynmWehne4OdG0tR4XqB5+ DYeei4mCSBIS6CIWkDfcYS7vvjgSd73a/M93dHzOaDI7m/8mRL/Z8PE330LZF3kD9E2z Hp9fKXNR29zDDRcUxB/U4uOM+9QWqjxE7ssFljySa1cVreC3cUDhaksyiDCR6/+1I9o4 Y1nzBUnzjI4SoYy+AR2sTperVsviTtSDSsecY9VU0CyY5hzxMNkZN9HawwmR2IQjTgQ5 i8QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=WxpIe5pM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020aa79605000000b00644c36e2079si21844549pfg.92.2023.05.17.05.45.35; Wed, 17 May 2023 05:45:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=WxpIe5pM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231705AbjEQMaL (ORCPT + 99 others); Wed, 17 May 2023 08:30:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbjEQMaJ (ORCPT ); Wed, 17 May 2023 08:30:09 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 348B41720; Wed, 17 May 2023 05:30:07 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-50db91640d3so1066374a12.0; Wed, 17 May 2023 05:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684326605; x=1686918605; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=zG7OAtWW1ntr+yw/2O/iG28G8+bEDuvHfZ1bydZEJAA=; b=WxpIe5pMxx0VA25leALbaHV7URbrgAZQgUBOO+Dm/oEU4zI7xovBGNR0Fqdj3S0U5D +wX/5bbik+VhVwaVqkhO/m/bAJfyUm6S98KhIjZNjJmORqxyH79So3CJNh8nGmLwlmzz 0gEEtIchHsxOUZ+D/QMa8VshbsujBhVWd+NHfczwXI7dwfKp3Ud2ghErffmsQNPHs3QT 3SC5awUHHfdaGU5KKUxQh4cPlmsVI8rB9OtER/noYauADAGyKyMVc8GF2mViI2dv+f9X nQofY16nsB6wxSSeolmYXUVITJPW4DgOomnU4IAy50pVTuxZt0MURD8TkOrG9H68lWX2 mDig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684326605; x=1686918605; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zG7OAtWW1ntr+yw/2O/iG28G8+bEDuvHfZ1bydZEJAA=; b=G5elhPSq27nzaGlBsTXeBHPHQrxMTdcLAmhRFEvpUfnuB8qS2viFF4wlNT7vJMvN/7 ToHzXONZ+gxs9JO/JF0X246L5oYvw4QGOWZynrV48Q4nfwqr75Hi32jhqAEi9oXo/NPj 3RfuzSIzkKY/ERmICwTn+N0BQN4IaqRuriDXv/i+khZfdAzifJa9/Ux7WkMetT1KNfry bvWnwLs5hebnK+wXFsBHUgEBUKCC7SyRmPx+7NcOy+cnUEuFC4TYJZM3wouESrYsgoIA 7J56jaFnDD9LUMquu/JTUkrEWi4zaQRy6Rxm7zmwZPprtUP3mT77C4F5PMsSf9wyStZq 2mOQ== X-Gm-Message-State: AC+VfDwScL5eZL9S1th8wE5t9bQvOCIExXlEUWq2+tQ+clKl9jOA/OVr uEqgaYyt9z99aUTlyjrbFoo= X-Received: by 2002:aa7:d1c5:0:b0:510:d075:9e13 with SMTP id g5-20020aa7d1c5000000b00510d0759e13mr1374346edp.22.1684326605340; Wed, 17 May 2023 05:30:05 -0700 (PDT) Received: from krava (2001-1ae9-1c2-4c00-726e-c10f-8833-ff22.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:726e:c10f:8833:ff22]) by smtp.gmail.com with ESMTPSA id u15-20020aa7db8f000000b0050bc863d32asm9472513edt.27.2023.05.17.05.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 05:30:05 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Wed, 17 May 2023 14:30:02 +0200 To: Masami Hiramatsu Cc: Jiri Olsa , Ze Gao , Steven Rostedt , Albert Ou , Alexander Gordeev , Alexei Starovoitov , Borislav Petkov , Christian Borntraeger , Dave Hansen , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , Palmer Dabbelt , Paul Walmsley , Sven Schnelle , Thomas Gleixner , Vasily Gorbik , x86@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Conor Dooley , Yonghong Song , Ze Gao Subject: Re: [PATCH v3 2/4] fprobe: make fprobe_kprobe_handler recursion free Message-ID: References: <20230517034510.15639-1-zegao@tencent.com> <20230517034510.15639-3-zegao@tencent.com> <20230517204236.e0f579399e5a69505a4ec7ef@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230517204236.e0f579399e5a69505a4ec7ef@kernel.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 17, 2023 at 08:42:36PM +0900, Masami Hiramatsu wrote: > On Wed, 17 May 2023 12:47:42 +0200 > Jiri Olsa wrote: > > > On Wed, May 17, 2023 at 11:45:07AM +0800, Ze Gao wrote: > > > Current implementation calls kprobe related functions before doing > > > ftrace recursion check in fprobe_kprobe_handler, which opens door > > > to kernel crash due to stack recursion if preempt_count_{add, sub} > > > is traceable in kprobe_busy_{begin, end}. > > > > > > Things goes like this without this patch quoted from Steven: > > > " > > > fprobe_kprobe_handler() { > > > kprobe_busy_begin() { > > > preempt_disable() { > > > preempt_count_add() { <-- trace > > > fprobe_kprobe_handler() { > > > [ wash, rinse, repeat, CRASH!!! ] > > > " > > > > > > By refactoring the common part out of fprobe_kprobe_handler and > > > fprobe_handler and call ftrace recursion detection at the very beginning, > > > the whole fprobe_kprobe_handler is free from recursion. > > > > > > Signed-off-by: Ze Gao > > > Acked-by: Masami Hiramatsu (Google) > > > Link: https://lore.kernel.org/linux-trace-kernel/20230516071830.8190-3-zegao@tencent.com > > > --- > > > kernel/trace/fprobe.c | 59 ++++++++++++++++++++++++++++++++----------- > > > 1 file changed, 44 insertions(+), 15 deletions(-) > > > > > > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c > > > index 9abb3905bc8e..097c740799ba 100644 > > > --- a/kernel/trace/fprobe.c > > > +++ b/kernel/trace/fprobe.c > > > @@ -20,30 +20,22 @@ struct fprobe_rethook_node { > > > char data[]; > > > }; > > > > > > -static void fprobe_handler(unsigned long ip, unsigned long parent_ip, > > > - struct ftrace_ops *ops, struct ftrace_regs *fregs) > > > +static inline void __fprobe_handler(unsigned long ip, unsigned long > > > + parent_ip, struct ftrace_ops *ops, struct ftrace_regs *fregs) > > > { > > > struct fprobe_rethook_node *fpr; > > > struct rethook_node *rh = NULL; > > > struct fprobe *fp; > > > void *entry_data = NULL; > > > - int bit, ret; > > > + int ret; > > > > > > > this change uncovered bug for me introduced by [1] > > > > the bpf's kprobe multi uses either fprobe's entry_handler or exit_handler, > > so the 'ret' value is undefined for return probe path and occasionally we > > won't setup rethook and miss the return probe > > Oops, I missed to push my fix. > > https://lore.kernel.org/all/168100731160.79534.374827110083836722.stgit@devnote2/ > > > > > we can either squash this change into your patch or I can make separate > > patch for that.. but given that [1] is quite recent we could just silently > > fix that ;-) > > Jiri, I think the above will fix the issue, right? yes, it's the same fix, great, thanks jirka > > > > > jirka > > > > > > [1] 39d954200bf6 fprobe: Skip exit_handler if entry_handler returns !0 > > > > --- > > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c > > index 9abb3905bc8e..293184227394 100644 > > --- a/kernel/trace/fprobe.c > > +++ b/kernel/trace/fprobe.c > > @@ -27,7 +27,7 @@ static void fprobe_handler(unsigned long ip, unsigned long parent_ip, > > struct rethook_node *rh = NULL; > > struct fprobe *fp; > > void *entry_data = NULL; > > - int bit, ret; > > + int bit, ret = 0; > > > > fp = container_of(ops, struct fprobe, ops); > > if (fprobe_disabled(fp)) > > > > > > > -- > Masami Hiramatsu (Google)