Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp880401imw; Fri, 15 Jul 2022 14:51:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sSEi1sWfVHkb9t2V44MCwfMbAl2kLZj7SzIhMq6KfnJJEZG37nF1dpD930Qzs9iPOeafjE X-Received: by 2002:a17:907:3e15:b0:72b:879a:eec7 with SMTP id hp21-20020a1709073e1500b0072b879aeec7mr15241186ejc.136.1657921894030; Fri, 15 Jul 2022 14:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657921894; cv=none; d=google.com; s=arc-20160816; b=MRYXcbUPK/oVn52BaTS0lZkEgEe05LXhZhLFdPRMoWbnZzDxzKzWYsnjO3ugLrCxED LynebD+SS0r91oB4jeWAzjhqfhsyP73m4kt29yVBbGHYoZiuRl2xwSLhlgr7N20aVQ7S 7QB/leMk1CWNVJhmWd0QwGzUPYYGvJcaeASUUcig/Dqi57Ncrh4VCgodfjz4kxa79g2F +BwNLY9bUrNIJNKZiRXM89ciNkkgSBOdtACzuu1+S8ZvXPXk4zGos4ZFDOB+BoPHbcvI UYf8Wk7E5V6Yd3rsSf0yXxZdmNGC6BTlyzTk+wmdRkB0cgTdkQBc5sBXMZnafW1unPJ4 IBqQ== 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; bh=B7nMtu1OZKs8wDevGDd2TL/HZwxPu6KE6qPfSYaKpbI=; b=FhlF2p7wFSGTeIMRURsEd3VVDJYg8EW7aScC7yzieTSsNfHas2RYwernGgZ6vkMJIc e3cjsRlHHVH8rw9WWCkU3y8e7rRzXOsqUXMG8CeFx/gRJWQUZK5Ji5fGK/SzGDXYdQjJ 0nbgq6NgQkzCSr3H5NYSzKbsHUD4gcYPKOaJq25ybMzhMMfpxyqKXpXlgZp+pZVjoZ/6 NeJblZb9CI9wCaRLlQbq39v0HmeMu0lW1mSIh5PVV2wNV9xprRzcwc0YR7Vv72u2u/V2 T7A7F728ORd0nX7pf9GhaYO0zLHwYp4IuI+WCZCOu4qaM5ZjTJ0/7WH9FDHCA92Ug9v2 AFCg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd30-20020a170907969e00b0072b3305dbbesi8924749ejc.520.2022.07.15.14.51.08; Fri, 15 Jul 2022 14:51:34 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229597AbiGOV30 (ORCPT + 99 others); Fri, 15 Jul 2022 17:29:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbiGOV3Z (ORCPT ); Fri, 15 Jul 2022 17:29:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95ED474786; Fri, 15 Jul 2022 14:29:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 329A861874; Fri, 15 Jul 2022 21:29:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CF20C341C6; Fri, 15 Jul 2022 21:29:21 +0000 (UTC) Date: Fri, 15 Jul 2022 17:29:19 -0400 From: Steven Rostedt To: Song Liu Cc: Song Liu , Networking , bpf , lkml , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Kernel Team , "jolsa@kernel.org" , "mhiramat@kernel.org" Subject: Re: [PATCH v2 bpf-next 3/5] ftrace: introduce FTRACE_OPS_FL_SHARE_IPMODIFY Message-ID: <20220715172919.76d60b47@gandalf.local.home> In-Reply-To: <6271DEDF-F585-4A3B-90BF-BA2EB76DDC01@fb.com> References: <20220602193706.2607681-1-song@kernel.org> <20220602193706.2607681-4-song@kernel.org> <20220713203343.4997eb71@rorschach.local.home> <20220714204817.2889e280@rorschach.local.home> <6A7EF1C7-471B-4652-99C1-87C72C223C59@fb.com> <20220714224646.62d49e36@rorschach.local.home> <170BE89A-101C-4B25-A664-5E47A902DB83@fb.com> <0CE9BF90-B8CE-40F6-A431-459936157B78@fb.com> <20220715151217.141dc98f@gandalf.local.home> <0EB34157-8BCA-47FC-B78F-AA8FE45A1707@fb.com> <20220715155953.4fb692e2@gandalf.local.home> <6271DEDF-F585-4A3B-90BF-BA2EB76DDC01@fb.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 Fri, 15 Jul 2022 20:21:49 +0000 Song Liu wrote: > >>> Wouldn't this need to be done anyway if BPF was first and live kernel > >>> patching needed the update? An -EAGAIN would not suffice. > >> > >> prepare_direct_functions_for_ipmodify handles BPF-first-livepatch-later > >> case. The benefit of prepare_direct_functions_for_ipmodify() is that it > >> holds direct_mutex before ftrace_lock, and keeps holding it if necessary. > >> This is enough to make sure we don't need the wash-rinse-repeat. > >> > >> OTOH, if we wait until __ftrace_hash_update_ipmodify(), we already hold > >> ftrace_lock, but not direct_mutex. To make changes to bpf trampoline, we > >> have to unlock ftrace_lock and lock direct_mutex to avoid deadlock. > >> However, this means we will need the wash-rinse-repeat. > > What do you think about the prepare_direct_functions_for_ipmodify() > approach? If this is not ideal, maybe we can simplify it so that it only > holds direct_mutex (when necessary). The benefit is that we are sure > direct_mutex is already held in __ftrace_hash_update_ipmodify(). However, > I think it is not safe to unlock ftrace_lock in __ftrace_hash_update_ipmodify(). > We can get parallel do_for_each_ftrace_rec(), which is dangerous, no? I'm fine with it. But one nit on the logic: > int register_ftrace_function(struct ftrace_ops *ops) > + __releases(&direct_mutex) > { > + bool direct_mutex_locked; > int ret; > > ftrace_ops_init(ops); > > + ret = prepare_direct_functions_for_ipmodify(ops); > + if (ret < 0) > + return ret; > + > + direct_mutex_locked = ret == 1; > + Please make the above: if (ret < 0) return ret; else if (ret == 1) direct_mutex_locked = true; It's much easier to read that way. -- Steve > mutex_lock(&ftrace_lock); > > ret = ftrace_startup(ops, 0); > > mutex_unlock(&ftrace_lock); > > + if (direct_mutex_locked) > + mutex_unlock(&direct_mutex); > return ret; > } > EXPORT_SYMBOL_GPL(register_ftrace_function); > --