From: cyril@ti•com (Cyril Chemparathy)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH 01/22] ARM: add mechanism for late code patching
Date: Sun, 5 Aug 2012 09:56:20 -0400 [thread overview]
Message-ID: <501E7B84.1050201@ti.com> (raw)
In-Reply-To: <alpine.LFD.2.02.1208040045360.5231@xanadu.home>
Hi Nicolas,
On 8/4/2012 1:38 AM, Nicolas Pitre wrote:
> On Tue, 31 Jul 2012, Cyril Chemparathy wrote:
>
>> The original phys_to_virt/virt_to_phys patching implementation relied on early
>> patching prior to MMU initialization. On PAE systems running out of >4G
>> address space, this would have entailed an additional round of patching after
>> switching over to the high address space.
>>
>> The approach implemented here conceptually extends the original PHYS_OFFSET
>> patching implementation with the introduction of "early" patch stubs. Early
>> patch code is required to be functional out of the box, even before the patch
>> is applied. This is implemented by inserting functional (but inefficient)
>> load code into the .patch.code init section. Having functional code out of
>> the box then allows us to defer the init time patch application until later
>> in the init sequence.
>>
>> In addition to fitting better with our need for physical address-space
>> switch-over, this implementation should be somewhat more extensible by virtue
>> of its more readable (and hackable) C implementation. This should prove
>> useful for other similar init time specialization needs, especially in light
>> of our multi-platform kernel initiative.
>>
>> This code has been boot tested in both ARM and Thumb-2 modes on an ARMv7
>> (Cortex-A8) device.
>>
>> Note: the obtuse use of stringified symbols in patch_stub() and
>> early_patch_stub() is intentional. Theoretically this should have been
>> accomplished with formal operands passed into the asm block, but this requires
>> the use of the 'c' modifier for instantiating the long (e.g. .long %c0).
>> However, the 'c' modifier has been found to ICE certain versions of GCC, and
>> therefore we resort to stringified symbols here.
>>
>> Signed-off-by: Cyril Chemparathy <cyril@ti•com>
>
> This looks very nice. Comments below.
>
>> ---
>> arch/arm/include/asm/patch.h | 123 +++++++++++++++++++++++++++++
>
> Please find a better name for this file. "patch" is way too generic and
> commonly referring to something different. "runtime-patching" or similar
> would be more descriptive.
>
Sure. Does init-patch sound about right? We need to reflect the fact
that this is intended for init-time patching only.
>> arch/arm/kernel/module.c | 4 +
>> arch/arm/kernel/setup.c | 175 +++++++++++++++++++++++++++++++++++++++++
>
> This is complex enough to waarrant aa separate source file. Please move
> those additions out from setup.c. Given a good name for the header file
> above, the c file could share the same name.
>
Sure.
>> new file mode 100644
>> index 0000000..a89749f
>> --- /dev/null
>> +++ b/arch/arm/include/asm/patch.h
>> @@ -0,0 +1,123 @@
>> +/*
>> + * arch/arm/include/asm/patch.h
>> + *
>> + * Copyright (C) 2012, Texas Instruments
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 as
>> + * published by the Free Software Foundation.
>> + *
>> + * Note: this file should not be included by non-asm/.h files
>> + */
>> +#ifndef __ASM_ARM_PATCH_H
>> +#define __ASM_ARM_PATCH_H
>> +
>> +#include <linux/stringify.h>
>> +
>> +#ifndef __ASSEMBLY__
>> +
>> extern unsigned __patch_table_begin, __patch_table_end;
>
> You could use "exttern void __patch_table_begin" so those symbols don't
> get any type that could be misused by mistake, while you still can take
> their addresses.
>
Sure.
>> +
>> +struct patch_info {
>> + u32 type;
>> + u32 size;
>
> Given the possibly large number of table entries, some effort at making
> those entries as compact as possible should be considered. For instance,
> the type and size fields could be u8's and insn_end pointer replaced
> with another size expressed as an u8. By placing all the u8's together
> they would occupy a single word by themselves. The assembly stub would
> only need a .align statement to reflect the c structure's padding.
>
Thanks, will try and pack this struct up.
> [...]
>
> Did you verify with some test program that your patching routines do
> produce the same opcodes as the assembled equivalent for all possible
> shift values? Especially for Thumb2 code which isn't as trivial to get
> right as the ARM one.
>
Not quite all, but I'm sure I can conjure up an off-line test harness to
do so.
Much appreciated feedback. Thanks for taking a look.
--
Thanks
- Cyril
next prev parent reply other threads:[~2012-08-05 13:56 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-31 23:04 [PATCH 00/22] Introducing the TI Keystone platform Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 01/22] ARM: add mechanism for late code patching Cyril Chemparathy
2012-08-04 5:38 ` Nicolas Pitre
2012-08-05 13:56 ` Cyril Chemparathy [this message]
2012-08-07 22:52 ` Cyril Chemparathy
2012-08-08 5:56 ` Nicolas Pitre
2012-08-08 13:18 ` Cyril Chemparathy
2012-08-08 13:55 ` Nicolas Pitre
2012-08-08 16:05 ` Russell King - ARM Linux
2012-08-08 16:56 ` Nicolas Pitre
2012-08-09 6:59 ` Tixy
2012-08-06 11:12 ` Russell King - ARM Linux
2012-08-06 13:19 ` Cyril Chemparathy
2012-08-06 13:26 ` Russell King - ARM Linux
2012-08-06 13:38 ` Cyril Chemparathy
2012-08-06 18:02 ` Nicolas Pitre
2012-07-31 23:04 ` [PATCH 02/22] ARM: use late patch framework for phys-virt patching Cyril Chemparathy
2012-08-04 6:15 ` Nicolas Pitre
2012-08-05 14:03 ` Cyril Chemparathy
2012-08-06 2:06 ` Nicolas Pitre
2012-07-31 23:04 ` [PATCH 03/22] ARM: LPAE: use phys_addr_t on virt <--> phys conversion Cyril Chemparathy
2012-08-04 6:24 ` Nicolas Pitre
2012-08-05 14:05 ` Cyril Chemparathy
2012-08-06 11:14 ` Russell King - ARM Linux
2012-08-06 13:30 ` Cyril Chemparathy
2012-08-09 14:10 ` Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 04/22] ARM: LPAE: support 64-bit virt/phys patching Cyril Chemparathy
2012-08-04 6:49 ` Nicolas Pitre
2012-08-05 14:21 ` Cyril Chemparathy
2012-08-06 2:19 ` Nicolas Pitre
2012-07-31 23:04 ` [PATCH 05/22] ARM: LPAE: use signed arithmetic for mask definitions Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 06/22] ARM: LPAE: use phys_addr_t in alloc_init_pud() Cyril Chemparathy
2012-08-01 12:08 ` Sergei Shtylyov
2012-08-01 15:42 ` Cyril Chemparathy
2012-08-04 6:51 ` Nicolas Pitre
2012-07-31 23:04 ` [PATCH 07/22] ARM: LPAE: use phys_addr_t in free_memmap() Cyril Chemparathy
2012-08-04 6:54 ` Nicolas Pitre
2012-07-31 23:04 ` [PATCH 08/22] ARM: LPAE: use phys_addr_t for initrd location and size Cyril Chemparathy
2012-08-04 6:57 ` Nicolas Pitre
2012-08-05 14:23 ` Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 09/22] ARM: LPAE: use 64-bit pgd physical address in switch_mm() Cyril Chemparathy
2012-08-04 7:04 ` Nicolas Pitre
2012-08-05 14:29 ` Cyril Chemparathy
2012-08-06 2:35 ` Nicolas Pitre
2012-07-31 23:04 ` [PATCH 10/22] ARM: LPAE: use 64-bit accessors for TTBR registers Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 11/22] ARM: LPAE: define ARCH_LOW_ADDRESS_LIMIT for bootmem Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 12/22] ARM: LPAE: factor out T1SZ and TTBR1 computations Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 13/22] ARM: LPAE: allow proc override of TTB setup Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 14/22] ARM: LPAE: accomodate >32-bit addresses for page table base Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 15/22] ARM: mm: use physical addresses in highmem sanity checks Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 16/22] ARM: mm: cleanup checks for membank overlap with vmalloc area Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 17/22] ARM: mm: clean up membank size limit checks Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 18/22] ARM: add virt_to_idmap for interconnect aliasing Cyril Chemparathy
2012-07-31 23:04 ` [PATCH 19/22] ARM: recreate kernel mappings in early_paging_init() Cyril Chemparathy
2012-07-31 23:05 ` [RFC 21/22] ARM: keystone: enable SMP on Keystone machines Cyril Chemparathy
2012-07-31 23:05 ` [RFC 22/22] ARM: keystone: add switch over to high physical address range Cyril Chemparathy
2012-07-31 23:06 ` [RFC 20/22] ARM: keystone: introducing TI Keystone platform Cyril Chemparathy
2012-07-31 23:16 ` Arnd Bergmann
2012-08-01 15:41 ` Cyril Chemparathy
2012-08-01 17:20 ` Arnd Bergmann
2012-08-04 8:39 ` [PATCH 00/22] Introducing the " Russell King - ARM Linux
2012-08-05 15:10 ` Cyril Chemparathy
2012-08-08 15:43 ` Catalin Marinas
2012-08-08 13:57 ` Will Deacon
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=501E7B84.1050201@ti.com \
--to=cyril@ti$(echo .)com \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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