All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Jiri Slaby <jslaby@suse.cz>
Cc: linux-kernel@vger.kernel.org, jirislaby@gmail.com,
	Vojtech Pavlik <vojtech@suse.cz>, Michael Matz <matz@suse.de>,
	Jiri Kosina <jkosina@suse.cz>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [RFC 03/16] kgr: initial code
Date: Wed, 30 Apr 2014 10:56:02 -0400	[thread overview]
Message-ID: <20140430105602.1bed3090@gandalf.local.home> (raw)
In-Reply-To: <1398868249-26169-4-git-send-email-jslaby@suse.cz>

On Wed, 30 Apr 2014 16:30:36 +0200
Jiri Slaby <jslaby@suse.cz> wrote:

> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 25d2c6f7325e..789a4c870ab3 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -130,6 +130,7 @@ config X86
>  	select HAVE_CC_STACKPROTECTOR
>  	select GENERIC_CPU_AUTOPROBE
>  	select HAVE_ARCH_AUDITSYSCALL
> +	select HAVE_KGR
>  
>  config INSTRUCTION_DECODER
>  	def_bool y
> @@ -263,6 +264,7 @@ config ARCH_SUPPORTS_UPROBES
>  
>  source "init/Kconfig"
>  source "kernel/Kconfig.freezer"
> +source "kernel/Kconfig.kgr"
>  
>  menu "Processor type and features"
>  
> diff --git a/arch/x86/include/asm/kgr.h b/arch/x86/include/asm/kgr.h
> new file mode 100644
> index 000000000000..172f7b966bb5
> --- /dev/null
> +++ b/arch/x86/include/asm/kgr.h
> @@ -0,0 +1,39 @@
> +#ifndef ASM_KGR_H
> +#define ASM_KGR_H
> +
> +#include <linux/linkage.h>
> +
> +/*
> + * The stub needs to modify the RIP value stored in struct pt_regs
> + * so that ftrace redirects the execution properly.
> + */
> +#define KGR_STUB_ARCH_SLOW(_name, _new_function)			\
> +static void _new_function ##_stub_slow (unsigned long ip, unsigned long parent_ip,	\
> +		struct ftrace_ops *ops, struct pt_regs *regs)		\
> +{									\
> +	struct kgr_loc_caches *c = ops->private;			\
> +									\
> +	if (task_thread_info(current)->kgr_in_progress && current->mm) {\
> +		pr_info("kgr: slow stub: calling old code at %lx\n",	\
> +				c->old);				\
> +		regs->ip = c->old + MCOUNT_INSN_SIZE;			\
> +	} else {							\
> +		pr_info("kgr: slow stub: calling new code at %lx\n",	\
> +				c->new);				\
> +		regs->ip = c->new;					\
> +	}								\
> +}
> +
> +#define KGR_STUB_ARCH_FAST(_name, _new_function)			\
> +static void _new_function ##_stub_fast (unsigned long ip,		\
> +		unsigned long parent_ip, struct ftrace_ops *ops,	\
> +		struct pt_regs *regs)					\
> +{									\
> +	struct kgr_loc_caches *c = ops->private;			\
> +									\
> +	BUG_ON(!c->new);				\
> +	pr_info("kgr: fast stub: calling new code at %lx\n", c->new); \
> +	regs->ip = c->new;				\
> +}
> +
> +#endif
> diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
> index 47e5de25ba79..1fdc144dcc9c 100644
> --- a/arch/x86/include/asm/thread_info.h
> +++ b/arch/x86/include/asm/thread_info.h
> @@ -35,6 +35,7 @@ struct thread_info {
>  	void __user		*sysenter_return;
>  	unsigned int		sig_on_uaccess_error:1;
>  	unsigned int		uaccess_err:1;	/* uaccess failed */
> +	unsigned short		kgr_in_progress;
>  };
>  
>  #define INIT_THREAD_INFO(tsk)			\
> diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
> index 9f6b9341950f..0db0437967a2 100644
> --- a/arch/x86/kernel/asm-offsets.c
> +++ b/arch/x86/kernel/asm-offsets.c
> @@ -32,6 +32,7 @@ void common(void) {
>  	OFFSET(TI_flags, thread_info, flags);
>  	OFFSET(TI_status, thread_info, status);
>  	OFFSET(TI_addr_limit, thread_info, addr_limit);
> +	OFFSET(TI_kgr_in_progress, thread_info, kgr_in_progress);
>  
>  	BLANK();
>  	OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
> diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
> index 1e96c3628bf2..a03b1e9d2de3 100644
> --- a/arch/x86/kernel/entry_64.S
> +++ b/arch/x86/kernel/entry_64.S
> @@ -615,6 +615,7 @@ GLOBAL(system_call_after_swapgs)
>  	movq  %rax,ORIG_RAX-ARGOFFSET(%rsp)
>  	movq  %rcx,RIP-ARGOFFSET(%rsp)
>  	CFI_REL_OFFSET rip,RIP-ARGOFFSET
> +	movw $0, TI_kgr_in_progress+THREAD_INFO(%rsp,RIP-ARGOFFSET)

Why is this not a entry flag? Because you just added a store into a
fast path of the kernel for something that will be hardly ever used.


>  	testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
>  	jnz tracesys
>  system_call_fastpath:
> @@ -639,6 +640,7 @@ sysret_check:
>  	LOCKDEP_SYS_EXIT
>  	DISABLE_INTERRUPTS(CLBR_NONE)
>  	TRACE_IRQS_OFF
> +	movw $0, TI_kgr_in_progress+THREAD_INFO(%rsp,RIP-ARGOFFSET)
>  	movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
>  	andl %edi,%edx
>  	jnz  sysret_careful
> @@ -761,6 +763,7 @@ GLOBAL(int_ret_from_sys_call)
>  GLOBAL(int_with_check)
>  	LOCKDEP_SYS_EXIT_IRQ
>  	GET_THREAD_INFO(%rcx)
> +	movw $0, TI_kgr_in_progress(%rcx)
>  	movl TI_flags(%rcx),%edx
>  	andl %edi,%edx
>  	jnz   int_careful
> diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
> index 040681928e9d..df6425d44fa0 100644
> --- a/arch/x86/kernel/x8664_ksyms_64.c
> +++ b/arch/x86/kernel/x8664_ksyms_64.c
> @@ -3,6 +3,7 @@
>  
>  #include <linux/module.h>
>  #include <linux/smp.h>
> +#include <linux/kgr.h>
>  
>  #include <net/checksum.h>
>  
> diff --git a/include/linux/kgr.h b/include/linux/kgr.h
> new file mode 100644
> index 000000000000..d72add7f3d5d
> --- /dev/null
> +++ b/include/linux/kgr.h
> @@ -0,0 +1,71 @@
> +#ifndef LINUX_KGR_H
> +#define LINUX_KGR_H
> +
> +#include <linux/init.h>
> +#include <linux/ftrace.h>
> +
> +#include <asm/kgr.h>
> +
> +#ifdef CONFIG_KGR
> +
> +#define KGR_TIMEOUT 30
> +#define KGR_DEBUG 1
> +
> +#ifdef KGR_DEBUG
> +#define kgr_debug(args...)	\
> +	pr_info(args);
> +#else
> +#define kgr_debug(args...) { }
> +#endif

Why not just use pr_debug(), as that's not defined unless you add DEBUG
as a define anyway?

-- Steve

> +
> +struct kgr_patch {
> +	char reserved;
> +	const struct kgr_patch_fun {
> +		const char *name;
> +		const char *new_name;
> +		void *new_function;
> +		struct ftrace_ops *ftrace_ops_slow;
> +		struct ftrace_ops *ftrace_ops_fast;
> +
> +	} *patches[];
> +};
> +
> +/*

  reply	other threads:[~2014-04-30 14:56 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-30 14:30 [RFC 00/16] kGraft Jiri Slaby
2014-04-30 14:30 ` [RFC 01/16] ftrace: Add function to find fentry of function Jiri Slaby
2014-04-30 14:48   ` Steven Rostedt
2014-04-30 14:58     ` Jiri Slaby
2014-04-30 14:30 ` [RFC 02/16] ftrace: Make ftrace_is_dead available globally Jiri Slaby
2014-04-30 14:30 ` [RFC 03/16] kgr: initial code Jiri Slaby
2014-04-30 14:56   ` Steven Rostedt [this message]
2014-04-30 14:57     ` Jiri Slaby
2014-05-01 20:20   ` Andi Kleen
2014-05-01 20:37     ` Jiri Kosina
2014-05-14  9:28   ` Aravinda Prasad
2014-05-14 10:12     ` Jiri Slaby
2014-05-14 10:41       ` Aravinda Prasad
2014-05-14 10:44         ` Jiri Slaby
2014-05-14 11:19           ` Aravinda Prasad
2014-05-20 11:36     ` Jiri Slaby
2014-05-21 18:28       ` Aravinda Prasad
2014-05-26  8:50       ` Jiri Kosina
2014-04-30 14:30 ` [RFC 04/16] kgr: add testing kgraft patch Jiri Slaby
2014-05-06 11:03   ` Pavel Machek
2014-05-12 12:50     ` Jiri Slaby
2014-04-30 14:30 ` [RFC 05/16] kgr: update Kconfig documentation Jiri Slaby
2014-05-03 14:32   ` Randy Dunlap
2014-04-30 14:30 ` [RFC 06/16] kgr: add Documentation Jiri Slaby
2014-05-06 11:03   ` Pavel Machek
2014-05-09  9:31     ` kgr: dealing with optimalizations? (was Re: [RFC 06/16] kgr: add Documentat)ion Pavel Machek
2014-05-09 12:22       ` Michael Matz
2014-04-30 14:30 ` [RFC 07/16] kgr: trigger the first check earlier Jiri Slaby
2014-04-30 14:30 ` [RFC 08/16] kgr: sched.h, introduce kgr_task_safe helper Jiri Slaby
2014-04-30 14:30 ` [RFC 09/16] kgr: mark task_safe in some kthreads Jiri Slaby
2014-04-30 15:49   ` Greg Kroah-Hartman
2014-04-30 16:55   ` Paul E. McKenney
2014-04-30 18:33     ` Vojtech Pavlik
2014-04-30 19:07       ` Paul E. McKenney
2014-05-01 14:24   ` Tejun Heo
2014-05-01 20:17     ` Jiri Kosina
2014-05-01 21:02       ` Tejun Heo
2014-05-01 21:09         ` Tejun Heo
2014-05-14 14:59           ` Jiri Slaby
2014-05-14 15:15             ` Vojtech Pavlik
2014-05-14 15:30               ` Paul E. McKenney
2014-05-14 16:32               ` Tejun Heo
2014-05-15  3:53                 ` Mike Galbraith
2014-05-15  4:06                   ` Tejun Heo
2014-05-15  4:46                     ` Mike Galbraith
2014-05-15  4:50                       ` Tejun Heo
2014-05-15  5:04                         ` Mike Galbraith
2014-05-15  5:09                           ` Tejun Heo
2014-05-15  5:32                             ` Mike Galbraith
2014-05-15  6:05                               ` Tejun Heo
2014-05-15  6:32                                 ` Mike Galbraith
2014-04-30 14:30 ` [RFC 10/16] kgr: kthreads support Jiri Slaby
2014-04-30 14:30 ` [RFC 11/16] kgr: handle irqs Jiri Slaby
2014-04-30 14:30 ` [RFC 12/16] kgr: add tools Jiri Slaby
2014-05-06 11:03   ` Pavel Machek
2014-04-30 14:30 ` [RFC 13/16] kgr: add MAINTAINERS entry Jiri Slaby
2014-04-30 14:30 ` [RFC 14/16] kgr: x86: refuse to build without fentry support Jiri Slaby
2014-04-30 14:30 ` [RFC 15/16] kgr: add procfs interface for per-process 'kgr_in_progress' Jiri Slaby
2014-04-30 14:30 ` [RFC 16/16] kgr: make a per-process 'in progress' flag a single bit Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140430105602.1bed3090@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=fweisbec@gmail.com \
    --cc=jirislaby@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matz@suse.de \
    --cc=mingo@redhat.com \
    --cc=vojtech@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.