Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4919634imw; Tue, 19 Jul 2022 16:17:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uOVay1vhs+8x1UipCZP5KbLYWAf1Fn37ctwCcVjHpOX2XshGBi+7j3aACZge4c6qskX1mk X-Received: by 2002:a05:6402:88e:b0:43b:b6d6:f14f with SMTP id e14-20020a056402088e00b0043bb6d6f14fmr1838552edy.417.1658272648285; Tue, 19 Jul 2022 16:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658272648; cv=none; d=google.com; s=arc-20160816; b=aH8pgEiora/KFxhEQdbJ+CCWWn5IKGgutlalRLegQSRpLEaL+2IuYS71Batbzu+fRY /XmDBV8v76Rh4rpoEQTs5sUPSXiRuGBtd7Esves95Lcp9bu1nTA6ZJfrZ1tvXqiSyYDd QEaMAggEW7KivLYWKfhsWYu24sXflejAAvDiDFlNfT6umGRfbS0ZKKYZToChAzlP7edA uqBVT2urbcQddLooLZmxpIGg+GlnjEYYIn7dkufM+oWFm7w1j3jksrt+nZvkkCQOXnXs EdTS98ItQfWPRK5jd5qfhAzBR+tinHmAwNBaDikyR01OZhvvoY2Yzg/OAkJhxUWjveCb 0vvg== 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=7z5XuKHVOm+o5exk9i4NZGt6/rc6NRoWvCue+TkCaCY=; b=fH6tOLPlmOZe6RnCBhD+5Zsfo+odMO/HuoctmYB0nNozhn+kZ7mYOLyYI7RnVg2ElG HltuAHjWtqxYsgItUQDP0WwCQC6vANBiuq9Hzt7HKMbdT6+oP2yGbUXaUYVKniVzXbwV bCMQofNWBXP2pUg/avncwZi5bQFiW7xK1w0Tgf8UdGXHqNDOYtWK1sNZVqJYjS1XeQZz IVGT+IPCQNNYgsPrnfG+n+Mp3mtWOaNt9UgXGjyIbrSF5OrP+GsUs1nB3qb90tmCB8+D i/EvRD+zXmoIKFcEnAqQDqG38okxF3gJ0HpsHXtg+Ac/oLlfhCGA8cnpe5z7BNFnbeHy KLGQ== 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 r25-20020a170906365900b0072b1cf39434si3867260ejb.961.2022.07.19.16.17.04; Tue, 19 Jul 2022 16:17:28 -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 S237785AbiGSXEk (ORCPT + 99 others); Tue, 19 Jul 2022 19:04:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbiGSXE0 (ORCPT ); Tue, 19 Jul 2022 19:04:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A882B5C945; Tue, 19 Jul 2022 16:04:25 -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 663EFB81DAD; Tue, 19 Jul 2022 23:04:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C2C0C341C6; Tue, 19 Jul 2022 23:04:22 +0000 (UTC) Date: Tue, 19 Jul 2022 19:04:20 -0400 From: Steven Rostedt To: Song Liu Cc: Song Liu , "bpf@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "live-patching@vger.kernel.org" , "daniel@iogearbox.net" , Kernel Team , "jolsa@kernel.org" Subject: Re: [PATCH v4 bpf-next 2/4] ftrace: allow IPMODIFY and DIRECT ops on the same function Message-ID: <20220719190420.2121c659@gandalf.local.home> In-Reply-To: References: <20220718055449.3960512-1-song@kernel.org> <20220718055449.3960512-3-song@kernel.org> <20220719142856.7d87ea6d@gandalf.local.home> 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 Tue, 19 Jul 2022 22:57:52 +0000 Song Liu wrote: > >> + hash = ops->func_hash->filter_hash; > >> + size = 1 << hash->size_bits; > >> + for (i = 0; i < size; i++) { > >> + hlist_for_each_entry(entry, &hash->buckets[i], hlist) { > >> + unsigned long ip = entry->ip; > >> + bool found_op = false; > >> + > >> + mutex_lock(&ftrace_lock); > >> + do_for_each_ftrace_op(op, ftrace_ops_list) { > >> + if (!(op->flags & FTRACE_OPS_FL_DIRECT)) > >> + continue; > >> + if (ops_references_ip(op, ip)) { > >> + found_op = true; > >> + break; > > > > I think you want a goto here. The macros "do_for_each_ftrace_op() { .. } > > while_for_each_ftrace_op()" is a double loop. The break just moves to the > > next set of pages and does not break out of the outer loop. > > Hmmm... really? I didn't see it ... > > > #define do_for_each_ftrace_op(op, list) \ > op = rcu_dereference_raw_check(list); \ > do > > #define while_for_each_ftrace_op(op) \ > while (likely(op = rcu_dereference_raw_check((op)->next)) && \ > unlikely((op) != &ftrace_list_end)) > > Did I miss something...? Bah, you're right. I was confusing it with do_for_each_ftrace_rec(), which *is* a double loop. Never mind ;-) > > > > > goto out_loop; > > > >> + } > >> + } while_for_each_ftrace_op(op); > > [...] > > > > >> mutex_lock(&ftrace_lock); > >> > >> ret = ftrace_startup(ops, 0); > >> > >> mutex_unlock(&ftrace_lock); > >> > >> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS > >> + if (direct_mutex_locked) > >> + mutex_unlock(&direct_mutex); > >> +#endif > > > > Change this to: > > > > out_unlock: > > mutex_unlock(&direct_mutex); > > > > We still need #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS, as > direct_mutex is not defined without that config. Ah, right. I just meant to get rid of the if statement. To keep the code clean, perhaps we should have: #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS # define lock_direct_mutex() mutex_lock(&direct_mutex) # define unlock_direct_mutex() mutex_unlock(&direct_mutex) #else # define lock_direct_mutex() do { } while (0) # define unlock_direct_mutex() do { } while (0) #endif And use that here. -- Steve