Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4391860pxb; Mon, 21 Feb 2022 20:04:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJywnfP2x9M69boYm0kYGvBJkngj4GMqtSUvnQNIErZSdLfOikduLdd+SRCpWouegIRZBKSJ X-Received: by 2002:a17:903:41c6:b0:14d:54cf:9a50 with SMTP id u6-20020a17090341c600b0014d54cf9a50mr21648568ple.79.1645502666085; Mon, 21 Feb 2022 20:04:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645502666; cv=none; d=google.com; s=arc-20160816; b=gYfjiW9GkQcegrD/3mrGL5mY0vgoZj96c+5UvRAI0xNECpjPXcDtgFtJJ1RtBTxLaU 0VZt876/p4NsEy4zD6iDbX/xv00ZPp7ItEiR+tJAJHcHXeB+enL0OxkGs7Fwf0pStfKG DF2pQroRJskqKBd7hESWi7yKoOaV02BqQdWQx3fy9SG0hssNO3UEUe6X+QFyV80tPQQN MSbg5JTyfy/tCexhF/D7DaXrvfmtjoiRSJnWzvRGGUfPchZbnoEEDK/OxkOPcBNIT6vu OdireopwcLeV2qqCIs8n/ZxK6BPm3KswimeRXrmpNlJ+hJcVtxWrxgsWsXzvZGmvkV40 cR/w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZkmXQazLaNBZCVsKzfI0TVSPaWqCg9x6ItnIcYeIqug=; b=btfmKRrDQBstXLIr/1J2ZgkMBo3JCyxpAvk6aV04zkgoibEMRUAmHt6BIdof/+RJLi cZn2Iu+JKaUhiOp+iJI5aBzrb/4Mkj13svjRB4gQ90+hQIM6yPaHmULf0xZitx2z2YpL aB4Gd/qNKx3+6KHIc1ZY5Ryk3wF7Apa6LsaVMLX43ZUqp+wr9LXPvSMNmQUXqE9GRIxV Xg9H0YSQ56gV1lvmWkJfF55k1vnJtQ1bmTArkd8l5SfCgbbxnEb5PlLXand12WlCnud7 ntqTLoI96fCqUobix1pGPYQmRqjIWrrWQM0TNPv2Xd6YQ6i4O+Hb19PLcJsfdzTybViG 3+7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=diDoW3ab; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u10si35719349plg.402.2022.02.21.20.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:04:26 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=diDoW3ab; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 075DC60076; Mon, 21 Feb 2022 20:04:14 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347590AbiBUJIt (ORCPT + 99 others); Mon, 21 Feb 2022 04:08:49 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346895AbiBUJDi (ORCPT ); Mon, 21 Feb 2022 04:03:38 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B5B72DA85; Mon, 21 Feb 2022 00:58:34 -0800 (PST) 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 6623461206; Mon, 21 Feb 2022 08:58:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EAE6C340E9; Mon, 21 Feb 2022 08:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645433898; bh=OOrcJLBMRnTKw4MRosAxas59uUfWSypDD+WFBvZegyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=diDoW3abBYu4M6Ds/jscgADtme5qcfrk+JHozIIefvJ70i8lNex9RRLYWTC7JhAPn NEr8csxVi02KGmAvEUPoicwTewHdm2mA3eqoUoAXkbPD3mvYJhWJYjoiSPBf6TlQ3Q InVIKpRhGWmK0DFxaWgTU0aE8iSpnF7nNV/tvxDM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Amit Daniel Kachhap , Ard Biesheuvel , Miroslav Benes , "Steven Rostedt (VMware)" , Torsten Duwe , Sven Schnelle , Ingo Molnar , Stephen Boyd Subject: [PATCH 5.4 23/80] ftrace: add ftrace_init_nop() Date: Mon, 21 Feb 2022 09:49:03 +0100 Message-Id: <20220221084916.342830178@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Mark Rutland commit fbf6c73c5b264c25484fa9f449b5546569fe11f0 upstream. Architectures may need to perform special initialization of ftrace callsites, and today they do so by special-casing ftrace_make_nop() when the expected branch address is MCOUNT_ADDR. In some cases (e.g. for patchable-function-entry), we don't have an mcount-like symbol and don't want a synthetic MCOUNT_ADDR, but we may need to perform some initialization of callsites. To make it possible to separate initialization from runtime modification, and to handle cases without an mcount-like symbol, this patch adds an optional ftrace_init_nop() function that architectures can implement, which does not pass a branch address. Where an architecture does not provide ftrace_init_nop(), we will fall back to the existing behaviour of calling ftrace_make_nop() with MCOUNT_ADDR. At the same time, ftrace_code_disable() is renamed to ftrace_nop_initialize() to make it clearer that it is intended to intialize a callsite into a disabled state, and is not for disabling a callsite that has been runtime enabled. The kerneldoc description of rec arguments is updated to cover non-mcount callsites. Signed-off-by: Mark Rutland Reviewed-by: Amit Daniel Kachhap Reviewed-by: Ard Biesheuvel Reviewed-by: Miroslav Benes Reviewed-by: Steven Rostedt (VMware) Reviewed-by: Torsten Duwe Tested-by: Amit Daniel Kachhap Tested-by: Sven Schnelle Tested-by: Torsten Duwe Cc: Ingo Molnar Cc: Stephen Boyd Signed-off-by: Greg Kroah-Hartman --- include/linux/ftrace.h | 35 ++++++++++++++++++++++++++++++++--- kernel/trace/ftrace.c | 6 +++--- 2 files changed, 35 insertions(+), 6 deletions(-) --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -499,7 +499,7 @@ static inline int ftrace_disable_ftrace_ /** * ftrace_make_nop - convert code into nop * @mod: module structure if called by module load initialization - * @rec: the mcount call site record + * @rec: the call site record (e.g. mcount/fentry) * @addr: the address that the call site should be calling * * This is a very sensitive operation and great care needs @@ -520,9 +520,38 @@ static inline int ftrace_disable_ftrace_ extern int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long addr); + +/** + * ftrace_init_nop - initialize a nop call site + * @mod: module structure if called by module load initialization + * @rec: the call site record (e.g. mcount/fentry) + * + * This is a very sensitive operation and great care needs + * to be taken by the arch. The operation should carefully + * read the location, check to see if what is read is indeed + * what we expect it to be, and then on success of the compare, + * it should write to the location. + * + * The code segment at @rec->ip should contain the contents created by + * the compiler + * + * Return must be: + * 0 on success + * -EFAULT on error reading the location + * -EINVAL on a failed compare of the contents + * -EPERM on error writing to the location + * Any other value will be considered a failure. + */ +#ifndef ftrace_init_nop +static inline int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec) +{ + return ftrace_make_nop(mod, rec, MCOUNT_ADDR); +} +#endif + /** * ftrace_make_call - convert a nop call site into a call to addr - * @rec: the mcount call site record + * @rec: the call site record (e.g. mcount/fentry) * @addr: the address that the call site should call * * This is a very sensitive operation and great care needs @@ -545,7 +574,7 @@ extern int ftrace_make_call(struct dyn_f #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS /** * ftrace_modify_call - convert from one addr to another (no nop) - * @rec: the mcount call site record + * @rec: the call site record (e.g. mcount/fentry) * @old_addr: the address expected to be currently called to * @addr: the address to change to * --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -2520,14 +2520,14 @@ struct dyn_ftrace *ftrace_rec_iter_recor } static int -ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec) +ftrace_nop_initialize(struct module *mod, struct dyn_ftrace *rec) { int ret; if (unlikely(ftrace_disabled)) return 0; - ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR); + ret = ftrace_init_nop(mod, rec); if (ret) { ftrace_bug_type = FTRACE_BUG_INIT; ftrace_bug(ret, rec); @@ -2969,7 +2969,7 @@ static int ftrace_update_code(struct mod * to the NOP instructions. */ if (!__is_defined(CC_USING_NOP_MCOUNT) && - !ftrace_code_disable(mod, p)) + !ftrace_nop_initialize(mod, p)) break; update_cnt++;