linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: dave.martin@linaro.org (Dave Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv2 4/6] ARM: extract out code patch function from kprobes
Date: Mon, 30 Jan 2012 17:00:06 +0000	[thread overview]
Message-ID: <20120130170006.GD2248@linaro.org> (raw)
In-Reply-To: <1327757725-10114-5-git-send-email-rabin@rab.in>

On Sat, Jan 28, 2012 at 07:05:23PM +0530, Rabin Vincent wrote:
> Extract out the code patching code from kprobes so that it can be used
> from the jump label code.  Additionally, the separated code:
> 
>  - Uses the IS_ENABLED() macros instead of the #ifdefs for THUMB2
>    support
> 
>  - Unifies the two separate functions in kprobes, providing one function
>    that uses stop_machine() internally, and one that can be called from
>    stop_machine() directly
> 
>  - Patches the text on all CPUs only on processors requiring software
>    broadcasting of cache operations
> 
> Cc: Jon Medhurst <tixy@yxit.co.uk>
> Signed-off-by: Rabin Vincent <rabin@rab.in>
> ---
>  arch/arm/kernel/Makefile  |    3 +-
>  arch/arm/kernel/kprobes.c |   86 ++++++++++++--------------------------------
>  arch/arm/kernel/patch.c   |   73 ++++++++++++++++++++++++++++++++++++++
>  arch/arm/kernel/patch.h   |    7 ++++
>  4 files changed, 106 insertions(+), 63 deletions(-)
>  create mode 100644 arch/arm/kernel/patch.c
>  create mode 100644 arch/arm/kernel/patch.h

[...]

> diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
> new file mode 100644
> index 0000000..30eff23
> --- /dev/null
> +++ b/arch/arm/kernel/patch.c
> @@ -0,0 +1,73 @@

[...]

> +void __kprobes __patch_text(void *addr, unsigned int insn)
> +{
> +	bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
> +	int size;
> +
> +	if (thumb2 && __opcode_is_thumb16(insn)) {
> +		*(u16 *)addr = __opcode_to_mem_thumb16(insn);
> +		size = sizeof(u16);
> +	} else if (thumb2 && ((uintptr_t)addr & 2)) {
> +		u16 *addrh = addr;
> +
> +		addrh[0] = __opcode_thumb32_first(insn);
> +		addrh[1] = __opcode_thumb32_second(insn);

It looks like we never convert to memory byte order in this case.

If not, should this be as follows?

	addrh[0] = __opcode_to_mem_thumb16(__opcode_thumb32_first(insn));
	addrh[1] = __opcode_to_mem_thumb16(__opcode_thumb32_second(insn));

> +
> +		size = sizeof(u32);
> +	} else {
> +		if (thumb2)
> +			insn = __opcode_to_mem_thumb32(insn);
> +		else
> +			insn = __opcode_to_mem_arm(insn);
> +
> +		*(u32 *)addr = insn;
> +		size = sizeof(u32);
> +	}
> +
> +	flush_icache_range((uintptr_t)(addr),
> +			   (uintptr_t)(addr) + size);
> +}

[...]

Cheers
---Dave

  reply	other threads:[~2012-01-30 17:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-28 13:35 [PATCHv2 0/6] ARM: jump label support Rabin Vincent
2012-01-28 13:35 ` [PATCHv2 1/6] ARM: ftrace: remove useless memory checks Rabin Vincent
2012-02-20 16:16   ` Russell King - ARM Linux
2012-02-22 14:13     ` Rabin Vincent
2012-02-22 21:28       ` Russell King - ARM Linux
2012-02-24 16:48         ` Rabin Vincent
2012-02-27 11:21           ` Russell King - ARM Linux
2012-01-28 13:35 ` [PATCHv2 2/6] ARM: ftrace: use canonical Thumb-2 wide instruction format Rabin Vincent
2012-01-30 16:54   ` Dave Martin
2012-01-28 13:35 ` [PATCHv2 3/6] ARM: extract out insn generation code from ftrace Rabin Vincent
2012-01-28 13:35 ` [PATCHv2 4/6] ARM: extract out code patch function from kprobes Rabin Vincent
2012-01-30 17:00   ` Dave Martin [this message]
2012-02-07 16:07     ` [PATCHv3] " Rabin Vincent
2012-01-31 18:32   ` [PATCHv2 4/6] " Tixy
2012-01-28 13:35 ` [PATCHv2 5/6] jump label: detect %c support for ARM Rabin Vincent
2012-02-07 16:18   ` Rabin Vincent
2012-02-07 18:04     ` Jason Baron
2012-02-20 17:21   ` Russell King - ARM Linux
2012-02-22 13:32     ` Rabin Vincent
2012-01-28 13:35 ` [PATCHv2 6/6] ARM: add jump label support Rabin Vincent
2012-02-15 17:00   ` [PATCHv3] " Rabin Vincent
2012-02-29 15:24     ` Rabin Vincent
2012-02-29 15:47       ` Jason Baron
2012-01-31  8:23 ` [PATCHv2 0/6] ARM: " Jon Medhurst (Tixy)
2012-01-31 11:11   ` Dave Martin

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=20120130170006.GD2248@linaro.org \
    --to=dave.martin@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).