Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp769553imw; Fri, 15 Jul 2022 12:30:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uN9qLVnLMWifTmcnPeEUo+Mfk0SjqkqNp1Kvu0EQZ+cCx1og+eQEg/Vhq/1YkioG23kU/R X-Received: by 2002:a17:90b:4c91:b0:1ef:f85b:6342 with SMTP id my17-20020a17090b4c9100b001eff85b6342mr24363128pjb.75.1657913455616; Fri, 15 Jul 2022 12:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657913455; cv=none; d=google.com; s=arc-20160816; b=IGaQkJ6RBD+W6bLWi2LW5ZLN5fNfWoigTvgCyZQrjoNq7KBQhQQUD/lmWDXsK23JWh jddgOylA7Wsu40PNPVD9i8rPQbRhQ5jLeZsKm/LUM4Qs9hmTmuMuLMglyOvKpA70X8kQ RkxHLbXWZBXu0RCewhwwCv9njwRpQ3ShwSCVfiEYLtsSsQucLIeqm7gezXYzvJ/gxcww 72bwS9FWbE36KI0ADUbMXYGErSPqSuCKmj4BIG4mhdfneNAuk7leRbHFOm1S9Jzxi9ga g3bGel5aaEjK+4o6p8f+zJp9zNPzRcQ7RlhagVjcuAiAksxKQYOt0Ba2BSJhYtxEejeI lAiA== 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=GpesU9yYSg3o826VqR9MoffuNfjv6ha7Q6V1JFa7eco=; b=BtwfcqN/Q/mXtk7tz+mz2kUe/oz/hkTmYKhRgXm9iMyaOJH4LsYgbJuDXPgyL9xbZa reqIHds1nsIXo2Jj+4xtlMAlFX7xPq3P95VuqD30u2Fh7cWF+QpZALvW7Mcwag9rjLNK H54cPFRYsdgpk4DzLMhxME6/kZ2w34VVQueEJTwGJCfAxzGrXWL67kfzl0VYt0Cvs+XA cnp31BbW6glElin+0QTOCuXB3txcCITZx6qMUwcVjqu2wzKjVAqpyjL0MN9+2FZUqiCx cKuWPhshwI/OEN2EajmDUy+Yz4hBJdRDlLbZFhMY/Uat3wDgBTP9rZ61H/AjnwwwYRqn uMzg== 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 j6-20020a056a00174600b005183434ec7csi7441080pfc.363.2022.07.15.12.30.40; Fri, 15 Jul 2022 12:30:55 -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 S230412AbiGOTM0 (ORCPT + 99 others); Fri, 15 Jul 2022 15:12:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbiGOTMX (ORCPT ); Fri, 15 Jul 2022 15:12:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EECC040BF7; Fri, 15 Jul 2022 12:12:22 -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 ams.source.kernel.org (Postfix) with ESMTPS id 9E7EBB82E16; Fri, 15 Jul 2022 19:12:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30CBCC34115; Fri, 15 Jul 2022 19:12:19 +0000 (UTC) Date: Fri, 15 Jul 2022 15:12:17 -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: <20220715151217.141dc98f@gandalf.local.home> In-Reply-To: <0CE9BF90-B8CE-40F6-A431-459936157B78@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> 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 17:42:55 +0000 Song Liu wrote: > A quick update and ask for feedback/clarification. > > Based on my understanding, you recommended calling ops_func() from > __ftrace_hash_update_ipmodify() and in ops_func() the direct trampoline > may make changes to the trampoline. Did I get this right? > > > I am going towards this direction, but hit some issue. Specifically, in > __ftrace_hash_update_ipmodify(), ftrace_lock is already locked, so the > direct trampoline cannot easily make changes with > modify_ftrace_direct_multi(), which locks both direct_mutex and > ftrace_mutex. > > One solution would be have no-lock version of all the functions called > by modify_ftrace_direct_multi(), but that's a lot of functions and the > code will be pretty ugly. The alternative would be the logic in v2: > __ftrace_hash_update_ipmodify() returns -EAGAIN, and we make changes to > the direct trampoline in other places: > > 1) if DIRECT ops attached first, the trampoline is updated in > prepare_direct_functions_for_ipmodify(), see 3/5 of v2; > > 2) if IPMODIFY ops attached first, the trampoline is updated in > bpf_trampoline_update(), see "goto again" path in 5/5 of v2. > > Overall, I think this way is still cleaner. What do you think about this? What about if we release the lock when doing the callback? Then we just need to make sure things are the same after reacquiring the lock, and if they are different, we release the lock again and do the callback with the new update. Wash, rinse, repeat, until the state is the same before and after the callback with locks acquired? This is a common way to handle callbacks that need to do something that takes the lock held before doing a callback. The reason I say this, is because the more we can keep the accounting inside of ftrace the better. Wouldn't this need to be done anyway if BPF was first and live kernel patching needed the update? An -EAGAIN would not suffice. -- Steve