From: cyril@ti.com (Cyril Chemparathy)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 01/17] ARM: add mechanism for late code patching
Date: Fri, 21 Sep 2012 18:30:25 -0400 [thread overview]
Message-ID: <505CEA81.2000804@ti.com> (raw)
In-Reply-To: <alpine.LFD.2.02.1209211355490.6667@xanadu.home>
On 9/21/2012 2:09 PM, Nicolas Pitre wrote:
> On Tue, 11 Sep 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>
>
> I know I provided review before, but here's another nit I'd like fixed:
>
Fixed for v4. Thanks.
>> --- /dev/null
>> +++ b/arch/arm/include/asm/runtime-patch.h
>> @@ -0,0 +1,208 @@
>> +/*
>> + * arch/arm/include/asm/runtime-patch.h
>> + * Note: this file should not be included by non-asm/.h files
>> + *
>> + * Copyright 2012 Texas Instruments, Inc.
>> + *
>> + * This program is free software; you can redistribute it and/or modify it
>> + * under the terms and conditions of the GNU General Public License,
>> + * version 2, as published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope it will be useful, but WITHOUT
>> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
>> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
>> + * more details.
>> + *
>> + * You should have received a copy of the GNU General Public License along with
>> + * this program. If not, see <http://www.gnu.org/licenses/>.
>> + */
>> +#ifndef __ASM_ARM_RUNTIME_PATCH_H
>> +#define __ASM_ARM_RUNTIME_PATCH_H
>> +
>> +#include <linux/stringify.h>
>> +
>> +#ifndef __ASSEMBLY__
>> +
>> +#ifdef CONFIG_ARM_RUNTIME_PATCH
>
> [...]
>
>> +#else
>> +
>> +static inline int runtime_patch(const void *table, unsigned size)
>> +{
>> + return 0;
>> +}
>
> This is wrong. If runtime_patch() is ever called when
> CONFIG_ARM_RUNTIME_PATCH is not set, then i'd better return an error and
> not pretend it performed the requested action. Returning -ENOSYS would
> be appropriate.
>
> This is especially important in the following context:
>
>> --- a/arch/arm/kernel/module.c
>> +++ b/arch/arm/kernel/module.c
>> @@ -321,6 +322,12 @@ int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
>> if (s)
>> fixup_pv_table((void *)s->sh_addr, s->sh_size);
>> #endif
>> + s = find_mod_section(hdr, sechdrs, ".runtime.patch.table");
>> + if (s) {
>> + err = runtime_patch((void *)s->sh_addr, s->sh_size);
>> + if (err)
>> + return err;
>> + }
>
> Despite the vermagic check, If ever a .runtime.patch.table section is
> found in a module to be loaded in a kernel with no support for it then
> it is best to return an error than see the kernel crashing later on when
> the fallback stubs have been discarded.
>
>
> Nicolas
>
--
Thanks
- Cyril
next prev parent reply other threads:[~2012-09-21 22:30 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-11 17:38 [PATCH v3 00/17] LPAE fixes and extensions for Keystone Cyril Chemparathy
2012-09-11 17:38 ` [PATCH v3 01/17] ARM: add mechanism for late code patching Cyril Chemparathy
2012-09-21 18:09 ` Nicolas Pitre
2012-09-21 22:30 ` Cyril Chemparathy [this message]
2012-09-11 17:39 ` [PATCH v3 02/17] ARM: add self test for runtime patch mechanism Cyril Chemparathy
2012-09-21 17:40 ` Nicolas Pitre
2012-09-21 22:25 ` Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 03/17] ARM: use late patch framework for phys-virt patching Cyril Chemparathy
2012-09-21 18:15 ` Nicolas Pitre
2012-09-11 17:39 ` [PATCH v3 04/17] ARM: LPAE: use phys_addr_t on virt <--> phys conversion Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 05/17] ARM: LPAE: support 64-bit virt_to_phys patching Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 06/17] ARM: LPAE: use signed arithmetic for mask definitions Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 07/17] ARM: LPAE: use phys_addr_t in alloc_init_pud() Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 08/17] ARM: LPAE: use phys_addr_t in free_memmap() Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 09/17] ARM: LPAE: use phys_addr_t for initrd location and size Cyril Chemparathy
2012-09-21 18:30 ` Nicolas Pitre
2012-09-11 17:39 ` [PATCH v3 10/17] ARM: LPAE: use phys_addr_t in switch_mm() Cyril Chemparathy
2012-09-21 18:33 ` Nicolas Pitre
2012-09-21 18:41 ` Russell King - ARM Linux
2012-09-21 18:53 ` Nicolas Pitre
2012-09-11 17:39 ` [PATCH v3 11/17] ARM: LPAE: use 64-bit accessors for TTBR registers Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 12/17] ARM: LPAE: define ARCH_LOW_ADDRESS_LIMIT for bootmem Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 13/17] ARM: LPAE: factor out T1SZ and TTBR1 computations Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 14/17] ARM: LPAE: accomodate >32-bit addresses for page table base Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 15/17] ARM: mm: use physical addresses in highmem sanity checks Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 16/17] ARM: mm: cleanup checks for membank overlap with vmalloc area Cyril Chemparathy
2012-09-11 17:39 ` [PATCH v3 17/17] ARM: mm: clean up membank size limit checks Cyril Chemparathy
2012-09-21 18:42 ` Nicolas Pitre
2012-09-21 22:49 ` 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=505CEA81.2000804@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 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).