From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB7FD13D284 for ; Thu, 13 Jun 2024 07:33:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718263986; cv=none; b=kh4vy5QRZQ3+ys6TcL4DvRrofaPldoKrIHY3+wFwEkdvgy3Ip9yYsb9LG6tvjNxJhfRV1M+COSRzkeYPtZ1srVQi+L4Xiz5mVoZm9QRHUfYBDXzaNfWDnVrZLVcuYbOZ0dp2BdihBLTWbyK63NbJ4azvwtyzg3wyEWUt/zAbjdc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718263986; c=relaxed/simple; bh=SouKpCcGuPU35PuUtIVf4fx8/4KFcZyhXdY05tRopyw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g2c0LSU34eK7ek6ZlnF/7HPho7O7QAMAft4K8XfYtEraLTseJYbdjdGwOul4piHKKL4EUN5eXTD0xQhiMw3ZxsJ4RuLyX4gRwaITAd9y8MjygPNpN1R9l+s0/tGUOie/+Mebfz0pcHVZ+SJfCn55jSj+FQb7CPakxaRERs6I2Rg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=QEL/Uk7Z; arc=none smtp.client-ip=209.85.167.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="QEL/Uk7Z" Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3d227b1f4f0so332944b6e.3 for ; Thu, 13 Jun 2024 00:33:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1718263984; x=1718868784; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wBQdisfSIcfLCxaUXLlDTwMoYdzfD8LhoeZl0/Tj/fA=; b=QEL/Uk7ZD6LChocsuRx8DGib7mYz/agiiOA4cuCMSzE6VALVR8vRf2Kx+zKWaujhI9 yuDkqrrNDECuba7iq0M1mofzKy/wU7q0QnwFAnbpby8xZh6Yk0Q+Was9NNSHGHeXZX+z N3+gdssm46pHgmwhTXISOoIcKTI7EMqDuF3QuNiELdJkUApcd0wbiZhJJpZd1tiQ6ZpY ZANvJZ7ZE6Wd3/K9hGmmRHz2QFKVnJ/N/mAZZG0VGKb3e10fzwU0wnbKBmYDPf3uweGz LNPMMa+I6w/Fa97/0ll92ggyrqCZzCVBwcZc4hAVwlB7Nnxf/wZIYIZhG6NSQDBJBR3c JgKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718263984; x=1718868784; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wBQdisfSIcfLCxaUXLlDTwMoYdzfD8LhoeZl0/Tj/fA=; b=mb4bdp7IfHMhyWB+nDkojQg741e70froY+IJQ3XPPROvwAhM2ih+sxsnvD97B8tBAh Ot2olsoWqN9db9y2z1EJPreVEUMFGQGGAsOCDx1335CB/Hzuao0AA+gD1gmJAXw/lUmf 8P6QxBR9oRDBAegTts/cx7BYaAKZRpLD6lR9Vrh8IviyIlYbjzx+Sa7gUUwrgeGn8UWo VTajG9kI6E8RL740JHg7aEA56tv1wLnN1iSE2KxTKLm07UGXW/F9vR35j1uJaeztGnTy 8rmaBNtku3TdNnSntlRlIPmDH9UnW+67Qr3ijNqWHxxwn/J3hi6270DjGX3XD0wMeFLY 6r1Q== X-Forwarded-Encrypted: i=1; AJvYcCWgQyUP9wSRvbY/gnOTc3r7ENTsF3NjoiNrIigygYi/2bI40/Y8HY6u1EuIfLJxx5uMIGrsRINg6KqWK5JvA+mc0014Bg== X-Gm-Message-State: AOJu0YxlIdvZnquvPxH/ZhxzfF8S904+QIzx14tPSWnCDbqFXd85I/cw YA0qXVWqSxWuWAswnpDy/6gUvuWc/cuMPDzin2mCNPst/DdbtABWIg0m6retIuA= X-Google-Smtp-Source: AGHT+IHI/57UF4ERYhNsT8IgBFHVZFnNkvkL7rNY4vjoxvdn096FWUD3qDYx3RYqModhDDSYikhCvg== X-Received: by 2002:a05:6870:4412:b0:254:6eb5:ab2f with SMTP id 586e51a60fabf-25514afc016mr4471125fac.6.1718263983791; Thu, 13 Jun 2024 00:33:03 -0700 (PDT) Received: from [127.0.1.1] (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705cc78a1a0sm730028b3a.0.2024.06.13.00.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 00:33:03 -0700 (PDT) From: Andy Chiu Date: Thu, 13 Jun 2024 15:11:11 +0800 Subject: [PATCH 6/8] riscv: ftrace: do not use stop_machine to update code Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240613-dev-andyc-dyn-ftrace-v4-v1-6-1a538e12c01e@sifive.com> References: <20240613-dev-andyc-dyn-ftrace-v4-v1-0-1a538e12c01e@sifive.com> In-Reply-To: <20240613-dev-andyc-dyn-ftrace-v4-v1-0-1a538e12c01e@sifive.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Zong Li , Steven Rostedt , Masami Hiramatsu , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Puranjay Mohan Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, llvm@lists.linux.dev, Andy Chiu X-Mailer: b4 0.12.4 Now it is safe to remove dependency from stop_machine() for us to patch code in ftrace. Signed-off-by: Andy Chiu --- arch/riscv/kernel/ftrace.c | 53 ++++------------------------------------------ 1 file changed, 4 insertions(+), 49 deletions(-) diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c index f3b09f2d3ecc..9a421e151b1d 100644 --- a/arch/riscv/kernel/ftrace.c +++ b/arch/riscv/kernel/ftrace.c @@ -13,23 +13,13 @@ #include #ifdef CONFIG_DYNAMIC_FTRACE -void ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex) +void arch_ftrace_update_code(int command) { mutex_lock(&text_mutex); - - /* - * The code sequences we use for ftrace can't be patched while the - * kernel is running, so we need to use stop_machine() to modify them - * for now. This doesn't play nice with text_mutex, we use this flag - * to elide the check. - */ - riscv_patch_in_stop_machine = true; -} - -void ftrace_arch_code_modify_post_process(void) __releases(&text_mutex) -{ - riscv_patch_in_stop_machine = false; + command |= FTRACE_MAY_SLEEP; + ftrace_modify_all_code(command); mutex_unlock(&text_mutex); + flush_icache_all(); } static int ftrace_check_current_call(unsigned long hook_pos, @@ -158,41 +148,6 @@ int ftrace_update_ftrace_func(ftrace_func_t func) return __ftrace_modify_call_site(&ftrace_call_dest, func, true); } -struct ftrace_modify_param { - int command; - atomic_t cpu_count; -}; - -static int __ftrace_modify_code(void *data) -{ - struct ftrace_modify_param *param = data; - - if (atomic_inc_return(¶m->cpu_count) == num_online_cpus()) { - ftrace_modify_all_code(param->command); - /* - * Make sure the patching store is effective *before* we - * increment the counter which releases all waiting CPUs - * by using the release variant of atomic increment. The - * release pairs with the call to local_flush_icache_all() - * on the waiting CPU. - */ - atomic_inc_return_release(¶m->cpu_count); - } else { - while (atomic_read(¶m->cpu_count) <= num_online_cpus()) - cpu_relax(); - } - - local_flush_icache_all(); - - return 0; -} - -void arch_ftrace_update_code(int command) -{ - struct ftrace_modify_param param = { command, ATOMIC_INIT(0) }; - - stop_machine(__ftrace_modify_code, ¶m, cpu_online_mask); -} #endif #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS -- 2.43.0