Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3888697pxb; Mon, 1 Feb 2021 07:14:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwc75Lhq379EELvD/kXFuGWMIornnC1t8e8a4iuU5tLOZb6AZ+8RxAcfZJ+vOodc69wI9zq X-Received: by 2002:a17:906:3ad0:: with SMTP id z16mr18346316ejd.72.1612192463470; Mon, 01 Feb 2021 07:14:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612192463; cv=none; d=google.com; s=arc-20160816; b=zWwlY4ZNWyl1wto1a4YdSEfCwafBHHn+gA1u1u/OeA8RhI/dzG/QVbjZa7DI4iTOi3 cDiHnHY0E1oqBVuGWG+A3/CWhCY8I6Qx7f5ChdVKYnXy1GI3Cp4iPl3lLe4kpAaa/O/+ 5fB0wyqSkCzFOmYYNgFtU3R1SdOyvNF9O0z8twODHioXQeRXH2FF+7TpvyooKADrHHoO yEs4a68BXV1kzRSU5aLkLLyzaD2RYGg8bvgPXcZhtQse52sdEtm/xQ1Ni0Pe/vwroGkB 8bxar2/OHuQFDYg+3faJ1UDwcrLhXRhHU90OEWIH34zx8+ojjwExRINBtimjWesO5uai E4RQ== 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=zlVAX8xA4SNjp5tbNci+ISIeQR4oPtz8i8hJo3x8U4M=; b=wOvx27M+ZQhfQRB1JuODu0JDybjnKwyc+3ISl350/f009/ajD/vfSN6CnzeVG04Tsm rsgBeSQ7lC2TSp3fPJmQNwkXGUzZXqhDxepD9o9p0m9FUafrvgJkLjJu4oIXFSJ9QZ3v PoiYEFWleWRxKzJBdOMcAfsE7Zh1rpUwfiMU2uuNTm+ywyXdU5aCTM0h+x40ShfTOL13 l4nIhYy93rc8uGT1UGIHWSMfPg+J/3IjbT5E+MJ888/yqRGpteSrKbquTgdbcOklv+9K fETwV9GX1t8UR9mbAci9ZvStllT3iyy0+L34lGLVe92TYJRyt5hExgu1DCgZFB1JiK+M Oy1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a18si10748071ejr.276.2021.02.01.07.13.58; Mon, 01 Feb 2021 07:14:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231467AbhBAPJf (ORCPT + 99 others); Mon, 1 Feb 2021 10:09:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:37360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbhBAPGd (ORCPT ); Mon, 1 Feb 2021 10:06:33 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 68A6764DAD; Mon, 1 Feb 2021 14:56:14 +0000 (UTC) Date: Mon, 1 Feb 2021 09:56:12 -0500 From: Steven Rostedt To: Jinyang He Cc: Thomas Bogendoerfer , Ingo Molnar , Wu Zhangjin , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Huacai Chen , Jiaxun Yang , Tiezhu Yang Subject: Re: [PATCH 3/3] MIPS: ftrace: Add DYNAMIC_FTRACE_WITH_REGS support Message-ID: <20210201095612.62e62544@gandalf.local.home> In-Reply-To: <1612080878-5426-3-git-send-email-hejinyang@loongson.cn> References: <1612080878-5426-1-git-send-email-hejinyang@loongson.cn> <1612080878-5426-3-git-send-email-hejinyang@loongson.cn> 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 31 Jan 2021 16:14:38 +0800 Jinyang He wrote: > In the past, we have always used the address of _mcount as the address of > ftrace_caller. It reduces one ftrace_modify_code operation when do ftrace > on modules on 64Bit platform in this way. In order to provide > DYNAMIC_FTRACE_WITH_REGS, we have to take _mcount out of ftrace_caller and > add a new definition of _mcount. It is necessary to modify 2 instructions. > Also add the definition of ftrace_regs_caller. ftrace_regs_caller will > store and restore more registers. Of course, some functions in ftrace.c > also need to consider ftrace_regs_caller. Modify these functions and add > the related code of ftrace_regs_caller. Note, while you are making these changes, you may want to look at the new feature of ftrace that has HAVE_DYNAMIC_FTRACE_WITH_ARGS. I noticed that with x86 (and probably all other archs), you need to save the arguments before calling the ftrace callbacks in the ftrace trampoline. If done properly, this means that the callbacks should be able to access the function arguments. What happens then, it structures the arguments in a way that if the function was called with "WITH_REGS" set, its the full pt_regs structure. Otherwise, it's a partial structure called "ftrace_regs". See arch/x86/include/asm/ftrace.h for ftrace_regs. Then the ftrace_regs is passed to the callback instead of pt_regs (for all callbacks!). If a callback has the REGS flag set (ftrace_caller_regs), then to get the pt_regs, it needs to call: struct pt_regs *regs = arch_ftrace_get_regs(ftrace_regs); Where arch_ftrace_get_regs() returns the full pt_regs if the callback was called from a ftrace_caller_regs trampoline, otherwise it must return NULL. The reason to return NULL is that we don't want callbacks using pt_regs, thinking it's fully populated when it is not. But if HAVE_DYNAMIC_FTRACE_ARGS is set, then all ftrace callbacks (regardless of REGS flag being set) has access to the arguments from the ftrace_regs. -- Steve