Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp221074lqq; Thu, 13 Jun 2024 00:35:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXA4Wb3NP/yQ2S2g3JW7crwu4dPK3CWNf8Sc4uCux99ALtguIog2MyvrjoYrt47C/+G3wpsEsSf93RnKU7YaH+n1JRRpbiqwwt20Xrs5Q== X-Google-Smtp-Source: AGHT+IEfpMl0Zd154N8JT1X2GYySleYqK5JRBi11qVRMx6FAbToBrZ5+xqqZd2yt5DKPKKD78jlR X-Received: by 2002:a05:6a00:4b44:b0:704:205d:2323 with SMTP id d2e1a72fcca58-705bceab006mr4387758b3a.32.1718264148077; Thu, 13 Jun 2024 00:35:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718264148; cv=pass; d=google.com; s=arc-20160816; b=J6BvBVlMNsk0fLh3+dtJgAjjDjePcI7A++g2WdJ/jjm3/F9MoAsBkuMKxgT0J0h9QD D9d2z8mFgqtD9yW4UmtySjKorTAm1LbkJLECzgt3U0rj/2AkVK5jcS1IDsC/wySgZKzo ma4K6/lYxCOS1+IDpjZwNFlwvlUzUjIUTItcYMBvqg6d31Y7XG1dYm+wLqy1D3ytdY3E p/X2uMCMgTp5KEwQUy6sO+Zxl0eehB0qzecnDrUEcexCDP7XfJiH0MzyOAmOXotCnnNm xYEOcM3l9M8gdpLuRqtitvEf2ucwTFviL/XYw+ADvXWlG1EC9e+G6sWQEuPWxf5Q7rmB ie8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=wBQdisfSIcfLCxaUXLlDTwMoYdzfD8LhoeZl0/Tj/fA=; fh=GkwkGQLRlVNRcXvErqrHwgFCgVt3YCl98x0vW1KG4Ao=; b=kCyMPJW+rRIPI17AEuUc5thfl7EgXxcWCj23YXKIAQRgEMg5VbFPXbt/hlbZnMmlop zF1fk5WjZq5NE9Z+xIk6Anx7S1FeMFGbnzuhPi1ZWIxvjfuKWB51OWHCOdTFbvc9IYJ8 4xYDMPkIR2gSsJu3R5iE93RJdAsfd3WrtaKV2vZB86xr92P3BIK02+Z4johsR8jq4bVH i3VhJj+AKe5bfOQDtQEArHcPDto65ikyTX1ItjsOh+Q4apmi5Embuoe5gVmTYEPi/PNc fIM2ldPoeWk2ecBj7Q5xTlt4IjHO5HeYNFTmWGcC96I1w0/2aRMZ4inzj2JRGg0tzZDd MHAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="SzAw/VIh"; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-212716-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212716-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d2e1a72fcca58-705cf0edec7si548353b3a.247.2024.06.13.00.35.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 00:35:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212716-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="SzAw/VIh"; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-212716-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212716-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E19A7B22DC9 for ; Thu, 13 Jun 2024 07:34:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 449EC13C8FE; Thu, 13 Jun 2024 07:33:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="SzAw/VIh" Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (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 CC5AF13D285 for ; Thu, 13 Jun 2024 07:33:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718263986; cv=none; b=eZUoDLhHUI8XbU79FHmS2FBrmQf4PZvlIMPmZQT+v5OQu0NQ9PAwh/JIUByjAzG1TWf5bmVJS5VS8hW5GmsiEH4FCBTOGr6fVKWY1JuqDadoM1bCA5o/OOvFegM4uHP4IbRK3qRRmh3Empj4eIfvSb9EHUS7zSGFQievV2lYSrc= 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=SzAw/VIh; arc=none smtp.client-ip=209.85.167.170 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 Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3d227b1f4f0so332945b6e.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=vger.kernel.org; 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=SzAw/VIhC4REKBJ25UHy2FmqHs22MQouk4M6ydVgr0GxqXQse27QzsYNXGavBehRpz 1NfVjDQQDqSG4QnUBbU36L9kJHu3hyqAXJQoF3+f0dzFXDb+6uDulxdBrb0mhDIPVIa2 pFcmLnD0Ttfc+/+NF12SO/MV4iElDkZkQfn/iYUGVtiYXPB2gH8G27tMmz/iB4P6YHp0 aEH02aL8OjI1KJwB7H1m1rqAuPxHZDYbEPzKVptmGwq8uHbLAcNEcIdsXR1snexZRtiM 8t0whC4n9dKfOoAKBe9QGUuv/1uWefl4Ul8VL4NTwxs2i+w+IRUwPUVceqzRBE1SaIby FVMA== 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=LYuQPPeTMCdFUim3JQiPxk5GzD60Y+1N0+bLqcqzhKeQFNZtYMdFvBtSrDBsQBdvyD RQwLIdXhO2gDlwR0Bue8OLYceYggsj2leO10ZZcIs06LY5jgMhDc1MJKca8UJdwUtwvP I09cWpA4cDZ74ufMleCE7obEfRlZIG1qRtvuhA42oOluMYiLoYc2BkiNx4dL0VSgBkeP mx+H7KKQtNWfIY+UlzfJSoccptNxRfBIvxRRto5tQqwqYrS2Qmfq6QWbfwccVd/tHvq4 xTrlovFmmLjglsXMdbngBzlIPxpJYRWVVTlpthtyNmg6qeigihVKxhBE25ot85Y4vQCz WpkQ== X-Forwarded-Encrypted: i=1; AJvYcCUnk3qXiBOMCyNHHHBWYLSSyBYaBiccX5TA2LVkWT5622yD5ybkmtTzsl6i0Pxp1XAu0Wx4R9XxJD3NJfBu18sLAi6Ynr762AmjQI3S X-Gm-Message-State: AOJu0YwTENk85oKRGc8a3nxUIS8dsWevpo5h5vu8WeJdReLmSdmoElvZ n6s/ZsmXmQ+QkfQVosEKtpArRvdobIWg7PLCvyTgdluqd9nW3Ufijm+hxRh5igY= 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: linux-kernel@vger.kernel.org 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