From: cyril@ti.com (Cyril Chemparathy)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 01/22] ARM: add mechanism for late code patching
Date: Sun, 12 Aug 2012 14:13:57 -0400 [thread overview]
Message-ID: <5027F265.4030501@ti.com> (raw)
In-Reply-To: <alpine.LFD.2.02.1208112220400.5231@xanadu.home>
On 08/11/12 22:22, Nicolas Pitre wrote:
> On Fri, 10 Aug 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 .runtime.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>
>
> Reviewed-by: Nicolas Pitre <nico@linaro.org>
>
Thanks.
I've been looking at the compiler emitted code, and had to make a couple
of changes to keep things streamlined...
[...]
>> +#define early_patch_imm8(insn, to, from, sym, offset) \
>> + early_patch_stub(PATCH_IMM8, \
>> + /* code */ \
>> + "ldr %0, =" __stringify(sym + offset) "\n" \
>> + "ldr %0, [%0]\n" \
>> + insn " %0, %1, %0\n", \
>> + /* patch_data */ \
>> + ".long " __stringify(sym + offset) "\n" \
>> + insn " %0, %1, %2\n", \
>> + : "=&r" (to) \
>> + : "r" (from), "I" (__IMM8), "m" (sym) \
>> + : "cc")
First, the "m" operand modifier for "sym" forces GCC to emit code to
load the address of the symbol into a register. I've replaced this with
"i" (&(sym) to make that go away. With this, the emitted code doesn't
contain any such unexpected nonsense.
Second, marking the "to" operand as early clobber makes the compiler
generate horrid register moves around the assembly block, even when it
has registers to spare. Simply adding a temporary variable does a much
much better job, especially since this temporary register is used only
in the patched-out "early" code.
Thanks
-- Cyril.
WARNING: multiple messages have this Message-ID (diff)
From: Cyril Chemparathy <cyril@ti.com>
To: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>, <arnd@arndb.de>,
<catalin.marinas@arm.com>, <grant.likely@secretlab.ca>,
<linux@arm.linux.org.uk>, <will.deacon@arm.com>
Subject: Re: [PATCH v2 01/22] ARM: add mechanism for late code patching
Date: Sun, 12 Aug 2012 14:13:57 -0400 [thread overview]
Message-ID: <5027F265.4030501@ti.com> (raw)
In-Reply-To: <alpine.LFD.2.02.1208112220400.5231@xanadu.home>
On 08/11/12 22:22, Nicolas Pitre wrote:
> On Fri, 10 Aug 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 .runtime.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>
>
> Reviewed-by: Nicolas Pitre <nico@linaro.org>
>
Thanks.
I've been looking at the compiler emitted code, and had to make a couple
of changes to keep things streamlined...
[...]
>> +#define early_patch_imm8(insn, to, from, sym, offset) \
>> + early_patch_stub(PATCH_IMM8, \
>> + /* code */ \
>> + "ldr %0, =" __stringify(sym + offset) "\n" \
>> + "ldr %0, [%0]\n" \
>> + insn " %0, %1, %0\n", \
>> + /* patch_data */ \
>> + ".long " __stringify(sym + offset) "\n" \
>> + insn " %0, %1, %2\n", \
>> + : "=&r" (to) \
>> + : "r" (from), "I" (__IMM8), "m" (sym) \
>> + : "cc")
First, the "m" operand modifier for "sym" forces GCC to emit code to
load the address of the symbol into a register. I've replaced this with
"i" (&(sym) to make that go away. With this, the emitted code doesn't
contain any such unexpected nonsense.
Second, marking the "to" operand as early clobber makes the compiler
generate horrid register moves around the assembly block, even when it
has registers to spare. Simply adding a temporary variable does a much
much better job, especially since this temporary register is used only
in the patched-out "early" code.
Thanks
-- Cyril.
next prev parent reply other threads:[~2012-08-12 18:13 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-11 1:24 [PATCH v2 00/22] Introducing the TI Keystone platform Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-11 1:24 ` [PATCH v2 01/22] ARM: add mechanism for late code patching Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 2:22 ` Nicolas Pitre
2012-08-12 2:22 ` Nicolas Pitre
2012-08-12 18:13 ` Cyril Chemparathy [this message]
2012-08-12 18:13 ` Cyril Chemparathy
2012-08-11 1:24 ` [PATCH v2 02/22] ARM: add self test for runtime patch mechanism Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 2:35 ` Nicolas Pitre
2012-08-12 2:35 ` Nicolas Pitre
2012-08-12 16:32 ` Cyril Chemparathy
2012-08-12 16:32 ` Cyril Chemparathy
2012-08-13 3:19 ` Nicolas Pitre
2012-08-13 3:19 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 03/22] ARM: use late patch framework for phys-virt patching Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 3:03 ` Nicolas Pitre
2012-08-12 3:03 ` Nicolas Pitre
2012-08-12 17:34 ` Cyril Chemparathy
2012-08-12 17:34 ` Cyril Chemparathy
2012-08-13 3:32 ` Nicolas Pitre
2012-08-13 3:32 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 04/22] ARM: LPAE: use phys_addr_t on virt <--> phys conversion Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 3:04 ` Nicolas Pitre
2012-08-12 3:04 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 05/22] ARM: LPAE: support 64-bit virt_to_phys patching Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 3:39 ` Nicolas Pitre
2012-08-12 3:39 ` Nicolas Pitre
2012-08-12 23:27 ` Cyril Chemparathy
2012-08-12 23:27 ` Cyril Chemparathy
2012-08-13 4:03 ` Nicolas Pitre
2012-08-13 4:03 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 06/22] ARM: LPAE: use signed arithmetic for mask definitions Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 3:57 ` Nicolas Pitre
2012-08-12 3:57 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 07/22] ARM: LPAE: use phys_addr_t in alloc_init_pud() Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-11 1:24 ` [PATCH v2 08/22] ARM: LPAE: use phys_addr_t in free_memmap() Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-11 1:24 ` [PATCH v2 09/22] ARM: LPAE: use phys_addr_t for initrd location and size Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 3:58 ` Nicolas Pitre
2012-08-12 3:58 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 10/22] ARM: LPAE: use phys_addr_t in switch_mm() Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 4:04 ` Nicolas Pitre
2012-08-12 4:04 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 11/22] ARM: LPAE: use 64-bit accessors for TTBR registers Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 4:11 ` Nicolas Pitre
2012-08-12 4:11 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 12/22] ARM: LPAE: define ARCH_LOW_ADDRESS_LIMIT for bootmem Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-11 1:24 ` [PATCH v2 13/22] ARM: LPAE: factor out T1SZ and TTBR1 computations Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 4:19 ` Nicolas Pitre
2012-08-12 4:19 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 14/22] ARM: LPAE: accomodate >32-bit addresses for page table base Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-11 1:24 ` [PATCH v2 15/22] ARM: mm: use physical addresses in highmem sanity checks Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 4:29 ` Nicolas Pitre
2012-08-12 4:29 ` Nicolas Pitre
2012-08-11 1:24 ` [PATCH v2 16/22] ARM: mm: cleanup checks for membank overlap with vmalloc area Cyril Chemparathy
2012-08-11 1:24 ` Cyril Chemparathy
2012-08-12 4:36 ` Nicolas Pitre
2012-08-12 4:36 ` Nicolas Pitre
2012-09-10 17:43 ` Cyril Chemparathy
2012-09-10 17:43 ` Cyril Chemparathy
2012-09-10 18:07 ` Nicolas Pitre
2012-09-10 18:07 ` Nicolas Pitre
2012-08-11 1:25 ` [PATCH v2 17/22] ARM: mm: clean up membank size limit checks Cyril Chemparathy
2012-08-11 1:25 ` Cyril Chemparathy
2012-08-11 1:25 ` [PATCH v2 18/22] ARM: add virt_to_idmap for interconnect aliasing Cyril Chemparathy
2012-08-11 1:25 ` Cyril Chemparathy
2012-08-11 1:25 ` [PATCH v2 19/22] ARM: recreate kernel mappings in early_paging_init() Cyril Chemparathy
2012-08-11 1:25 ` Cyril Chemparathy
2012-08-11 1:25 ` [RFC v2 20/22] ARM: keystone: introducing TI Keystone platform Cyril Chemparathy
2012-08-11 1:26 ` Cyril Chemparathy
2012-08-11 1:25 ` [RFC v2 21/22] ARM: keystone: enable SMP on Keystone machines Cyril Chemparathy
2012-08-11 1:25 ` Cyril Chemparathy
2012-08-11 1:25 ` [RFC v2 22/22] ARM: keystone: add switch over to high physical address range Cyril Chemparathy
2012-08-11 1:25 ` Cyril Chemparathy
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=5027F265.4030501@ti.com \
--to=cyril@ti.com \
--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 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.