Skip to content

Commit 9c6ee01

Browse files
committed
Merge branch 'for-linus' of git://git.armlinux.org.uk/~rmk/linux-arm
Pull ARM updates from Russell King: "Lots of little things this time: - allow modules to be autoloaded according to the HWCAP feature bits (used primarily for crypto modules) - split module core and init PLT sections, since the core code and init code could be placed far apart, and the PLT sections need to be local to the code block. - three patches from Chris Brandt to allow Cortex-A9 L2 cache optimisations to be disabled where a SoC didn't wire up the out of band signals. - NoMMU compliance fixes, avoiding corruption of vector table which is not being used at this point, and avoiding possible register state corruption when switching mode. - fixmap memory attribute compliance update. - remove unnecessary locking from update_sections_early() - ftrace fix for DEBUG_RODATA with !FRAME_POINTER" * 'for-linus' of git://git.armlinux.org.uk/~rmk/linux-arm: ARM: 8672/1: mm: remove tasklist locking from update_sections_early() ARM: 8671/1: V7M: Preserve registers across switch from Thread to Handler mode ARM: 8670/1: V7M: Do not corrupt vector table around v7m_invalidate_l1 call ARM: 8668/1: ftrace: Fix dynamic ftrace with DEBUG_RODATA and !FRAME_POINTER ARM: 8667/3: Fix memory attribute inconsistencies when using fixmap ARM: 8663/1: wire up HWCAP/HWCAP2 feature bits to the CPU modalias ARM: 8666/1: mm: dump: Add domain to output ARM: 8662/1: module: split core and init PLT sections ARM: 8661/1: dts: r7s72100: add l2 cache ARM: 8660/1: shmobile: r7s72100: Enable L2 cache ARM: 8659/1: l2c: allow CA9 optimizations to be disabled
2 parents d9dc089 + c92a90a commit 9c6ee01

16 files changed

Lines changed: 212 additions & 59 deletions

File tree

‎Documentation/devicetree/bindings/arm/l2c2x0.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ Optional properties:
9090
- arm,standby-mode: L2 standby mode enable. Value <0> (forcibly disable),
9191
<1> (forcibly enable), property absent (OS specific behavior,
9292
preferably retain firmware settings)
93+
- arm,early-bresp-disable : Disable the CA9 optimization Early BRESP (PL310)
94+
- arm,full-line-zero-disable : Disable the CA9 optimization Full line of zero
95+
write (PL310)
9396

9497
Example:
9598

‎arch/arm/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ config ARM
2727
select GENERIC_ALLOCATOR
2828
select GENERIC_ATOMIC64 if (CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI)
2929
select GENERIC_CLOCKEVENTS_BROADCAST if SMP
30+
select GENERIC_CPU_AUTOPROBE
3031
select GENERIC_EARLY_IOREMAP
3132
select GENERIC_IDLE_POLL_SETUP
3233
select GENERIC_IRQ_PROBE

‎arch/arm/boot/dts/r7s72100.dtsi‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
compatible = "arm,cortex-a9";
178178
reg = <0>;
179179
clock-frequency = <400000000>;
180+
next-level-cache = <&L2>;
180181
};
181182
};
182183

@@ -368,6 +369,16 @@
368369
<0xe8202000 0x1000>;
369370
};
370371

372+
L2: cache-controller@3ffff000 {
373+
compatible = "arm,pl310-cache";
374+
reg = <0x3ffff000 0x1000>;
375+
interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
376+
arm,early-bresp-disable;
377+
arm,full-line-zero-disable;
378+
cache-unified;
379+
cache-level = <2>;
380+
};
381+
371382
i2c0: i2c@fcfee000 {
372383
#address-cells = <1>;
373384
#size-cells = <0>;

‎arch/arm/include/asm/cpufeature.h‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (C) 2017 Linaro Ltd. <ard.biesheuvel@linaro.org>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*/
8+
9+
#ifndef __ASM_CPUFEATURE_H
10+
#define __ASM_CPUFEATURE_H
11+
12+
#include <linux/log2.h>
13+
#include <asm/hwcap.h>
14+
15+
/*
16+
* Due to the fact that ELF_HWCAP is a 32-bit type on ARM, and given the number
17+
* of optional CPU features it defines, ARM's CPU hardware capability bits have
18+
* been distributed over separate elf_hwcap and elf_hwcap2 variables, each of
19+
* which covers a subset of the available CPU features.
20+
*
21+
* Currently, only a few of those are suitable for automatic module loading
22+
* (which is the primary use case of this facility) and those happen to be all
23+
* covered by HWCAP2. So let's only cover those via the cpu_feature()
24+
* convenience macro for now (which is used by module_cpu_feature_match()).
25+
* However, all capabilities are exposed via the modalias, and can be matched
26+
* using an explicit MODULE_DEVICE_TABLE() that uses __hwcap_feature() directly.
27+
*/
28+
#define MAX_CPU_FEATURES 64
29+
#define __hwcap_feature(x) ilog2(HWCAP_ ## x)
30+
#define __hwcap2_feature(x) (32 + ilog2(HWCAP2_ ## x))
31+
#define cpu_feature(x) __hwcap2_feature(x)
32+
33+
static inline bool cpu_have_feature(unsigned int num)
34+
{
35+
return num < 32 ? elf_hwcap & BIT(num) : elf_hwcap2 & BIT(num - 32);
36+
}
37+
38+
#endif

‎arch/arm/include/asm/fixmap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static const enum fixed_addresses __end_of_fixed_addresses =
4141

4242
#define FIXMAP_PAGE_COMMON (L_PTE_YOUNG | L_PTE_PRESENT | L_PTE_XN | L_PTE_DIRTY)
4343

44-
#define FIXMAP_PAGE_NORMAL (FIXMAP_PAGE_COMMON | L_PTE_MT_WRITEBACK)
44+
#define FIXMAP_PAGE_NORMAL (pgprot_kernel | L_PTE_XN)
4545
#define FIXMAP_PAGE_RO (FIXMAP_PAGE_NORMAL | L_PTE_RDONLY)
4646

4747
/* Used by set_fixmap_(io|nocache), both meant for mapping a device */

‎arch/arm/include/asm/module.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ enum {
1818
};
1919
#endif
2020

21+
struct mod_plt_sec {
22+
struct elf32_shdr *plt;
23+
int plt_count;
24+
};
25+
2126
struct mod_arch_specific {
2227
#ifdef CONFIG_ARM_UNWIND
2328
struct unwind_table *unwind[ARM_SEC_MAX];
2429
#endif
2530
#ifdef CONFIG_ARM_MODULE_PLTS
26-
struct elf32_shdr *plt;
27-
int plt_count;
31+
struct mod_plt_sec core;
32+
struct mod_plt_sec init;
2833
#endif
2934
};
3035

‎arch/arm/kernel/ftrace.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
#endif
3030

3131
#ifdef CONFIG_DYNAMIC_FTRACE
32-
#ifdef CONFIG_OLD_MCOUNT
33-
#define OLD_MCOUNT_ADDR ((unsigned long) mcount)
34-
#define OLD_FTRACE_ADDR ((unsigned long) ftrace_caller_old)
35-
36-
#define OLD_NOP 0xe1a00000 /* mov r0, r0 */
3732

3833
static int __ftrace_modify_code(void *data)
3934
{
@@ -51,6 +46,12 @@ void arch_ftrace_update_code(int command)
5146
stop_machine(__ftrace_modify_code, &command, NULL);
5247
}
5348

49+
#ifdef CONFIG_OLD_MCOUNT
50+
#define OLD_MCOUNT_ADDR ((unsigned long) mcount)
51+
#define OLD_FTRACE_ADDR ((unsigned long) ftrace_caller_old)
52+
53+
#define OLD_NOP 0xe1a00000 /* mov r0, r0 */
54+
5455
static unsigned long ftrace_nop_replace(struct dyn_ftrace *rec)
5556
{
5657
return rec->arch.old_mcount ? OLD_NOP : NOP;

‎arch/arm/kernel/module-plts.c‎

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
2+
* Copyright (C) 2014-2017 Linaro Ltd. <ard.biesheuvel@linaro.org>
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License version 2 as
@@ -31,19 +31,27 @@ struct plt_entries {
3131
u32 lit[PLT_ENT_COUNT];
3232
};
3333

34+
static bool in_init(const struct module *mod, unsigned long loc)
35+
{
36+
return loc - (u32)mod->init_layout.base < mod->init_layout.size;
37+
}
38+
3439
u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val)
3540
{
36-
struct plt_entries *plt = (struct plt_entries *)mod->arch.plt->sh_addr;
41+
struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core :
42+
&mod->arch.init;
43+
44+
struct plt_entries *plt = (struct plt_entries *)pltsec->plt->sh_addr;
3745
int idx = 0;
3846

3947
/*
4048
* Look for an existing entry pointing to 'val'. Given that the
4149
* relocations are sorted, this will be the last entry we allocated.
4250
* (if one exists).
4351
*/
44-
if (mod->arch.plt_count > 0) {
45-
plt += (mod->arch.plt_count - 1) / PLT_ENT_COUNT;
46-
idx = (mod->arch.plt_count - 1) % PLT_ENT_COUNT;
52+
if (pltsec->plt_count > 0) {
53+
plt += (pltsec->plt_count - 1) / PLT_ENT_COUNT;
54+
idx = (pltsec->plt_count - 1) % PLT_ENT_COUNT;
4755

4856
if (plt->lit[idx] == val)
4957
return (u32)&plt->ldr[idx];
@@ -53,8 +61,8 @@ u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val)
5361
plt++;
5462
}
5563

56-
mod->arch.plt_count++;
57-
BUG_ON(mod->arch.plt_count * PLT_ENT_SIZE > mod->arch.plt->sh_size);
64+
pltsec->plt_count++;
65+
BUG_ON(pltsec->plt_count * PLT_ENT_SIZE > pltsec->plt->sh_size);
5866

5967
if (!idx)
6068
/* Populate a new set of entries */
@@ -129,7 +137,7 @@ static bool duplicate_rel(Elf32_Addr base, const Elf32_Rel *rel, int num)
129137

130138
/* Count how many PLT entries we may need */
131139
static unsigned int count_plts(const Elf32_Sym *syms, Elf32_Addr base,
132-
const Elf32_Rel *rel, int num)
140+
const Elf32_Rel *rel, int num, Elf32_Word dstidx)
133141
{
134142
unsigned int ret = 0;
135143
const Elf32_Sym *s;
@@ -144,13 +152,17 @@ static unsigned int count_plts(const Elf32_Sym *syms, Elf32_Addr base,
144152
case R_ARM_THM_JUMP24:
145153
/*
146154
* We only have to consider branch targets that resolve
147-
* to undefined symbols. This is not simply a heuristic,
148-
* it is a fundamental limitation, since the PLT itself
149-
* is part of the module, and needs to be within range
150-
* as well, so modules can never grow beyond that limit.
155+
* to symbols that are defined in a different section.
156+
* This is not simply a heuristic, it is a fundamental
157+
* limitation, since there is no guaranteed way to emit
158+
* PLT entries sufficiently close to the branch if the
159+
* section size exceeds the range of a branch
160+
* instruction. So ignore relocations against defined
161+
* symbols if they live in the same section as the
162+
* relocation target.
151163
*/
152164
s = syms + ELF32_R_SYM(rel[i].r_info);
153-
if (s->st_shndx != SHN_UNDEF)
165+
if (s->st_shndx == dstidx)
154166
break;
155167

156168
/*
@@ -161,7 +173,12 @@ static unsigned int count_plts(const Elf32_Sym *syms, Elf32_Addr base,
161173
* So we need to support them, but there is no need to
162174
* take them into consideration when trying to optimize
163175
* this code. So let's only check for duplicates when
164-
* the addend is zero.
176+
* the addend is zero. (Note that calls into the core
177+
* module via init PLT entries could involve section
178+
* relative symbol references with non-zero addends, for
179+
* which we may end up emitting duplicates, but the init
180+
* PLT is released along with the rest of the .init
181+
* region as soon as module loading completes.)
165182
*/
166183
if (!is_zero_addend_relocation(base, rel + i) ||
167184
!duplicate_rel(base, rel, i))
@@ -174,7 +191,8 @@ static unsigned int count_plts(const Elf32_Sym *syms, Elf32_Addr base,
174191
int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
175192
char *secstrings, struct module *mod)
176193
{
177-
unsigned long plts = 0;
194+
unsigned long core_plts = 0;
195+
unsigned long init_plts = 0;
178196
Elf32_Shdr *s, *sechdrs_end = sechdrs + ehdr->e_shnum;
179197
Elf32_Sym *syms = NULL;
180198

@@ -184,13 +202,15 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
184202
*/
185203
for (s = sechdrs; s < sechdrs_end; ++s) {
186204
if (strcmp(".plt", secstrings + s->sh_name) == 0)
187-
mod->arch.plt = s;
205+
mod->arch.core.plt = s;
206+
else if (strcmp(".init.plt", secstrings + s->sh_name) == 0)
207+
mod->arch.init.plt = s;
188208
else if (s->sh_type == SHT_SYMTAB)
189209
syms = (Elf32_Sym *)s->sh_addr;
190210
}
191211

192-
if (!mod->arch.plt) {
193-
pr_err("%s: module PLT section missing\n", mod->name);
212+
if (!mod->arch.core.plt || !mod->arch.init.plt) {
213+
pr_err("%s: module PLT section(s) missing\n", mod->name);
194214
return -ENOEXEC;
195215
}
196216
if (!syms) {
@@ -213,16 +233,29 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
213233
/* sort by type and symbol index */
214234
sort(rels, numrels, sizeof(Elf32_Rel), cmp_rel, NULL);
215235

216-
plts += count_plts(syms, dstsec->sh_addr, rels, numrels);
236+
if (strncmp(secstrings + dstsec->sh_name, ".init", 5) != 0)
237+
core_plts += count_plts(syms, dstsec->sh_addr, rels,
238+
numrels, s->sh_info);
239+
else
240+
init_plts += count_plts(syms, dstsec->sh_addr, rels,
241+
numrels, s->sh_info);
217242
}
218243

219-
mod->arch.plt->sh_type = SHT_NOBITS;
220-
mod->arch.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC;
221-
mod->arch.plt->sh_addralign = L1_CACHE_BYTES;
222-
mod->arch.plt->sh_size = round_up(plts * PLT_ENT_SIZE,
223-
sizeof(struct plt_entries));
224-
mod->arch.plt_count = 0;
225-
226-
pr_debug("%s: plt=%x\n", __func__, mod->arch.plt->sh_size);
244+
mod->arch.core.plt->sh_type = SHT_NOBITS;
245+
mod->arch.core.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC;
246+
mod->arch.core.plt->sh_addralign = L1_CACHE_BYTES;
247+
mod->arch.core.plt->sh_size = round_up(core_plts * PLT_ENT_SIZE,
248+
sizeof(struct plt_entries));
249+
mod->arch.core.plt_count = 0;
250+
251+
mod->arch.init.plt->sh_type = SHT_NOBITS;
252+
mod->arch.init.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC;
253+
mod->arch.init.plt->sh_addralign = L1_CACHE_BYTES;
254+
mod->arch.init.plt->sh_size = round_up(init_plts * PLT_ENT_SIZE,
255+
sizeof(struct plt_entries));
256+
mod->arch.init.plt_count = 0;
257+
258+
pr_debug("%s: plt=%x, init.plt=%x\n", __func__,
259+
mod->arch.core.plt->sh_size, mod->arch.init.plt->sh_size);
227260
return 0;
228261
}

‎arch/arm/kernel/module.lds‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
SECTIONS {
22
.plt : { BYTE(0) }
3+
.init.plt : { BYTE(0) }
34
}

‎arch/arm/kernel/setup.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ __setup("fpe=", fpe_setup);
8080

8181
extern void init_default_cache_policy(unsigned long);
8282
extern void paging_init(const struct machine_desc *desc);
83-
extern void early_paging_init(const struct machine_desc *);
83+
extern void early_mm_init(const struct machine_desc *);
8484
extern void adjust_lowmem_bounds(void);
8585
extern enum reboot_mode reboot_mode;
8686
extern void setup_dma_zone(const struct machine_desc *desc);
@@ -1088,7 +1088,7 @@ void __init setup_arch(char **cmdline_p)
10881088
parse_early_param();
10891089

10901090
#ifdef CONFIG_MMU
1091-
early_paging_init(mdesc);
1091+
early_mm_init(mdesc);
10921092
#endif
10931093
setup_dma_zone(mdesc);
10941094
xen_early_init();

0 commit comments

Comments
 (0)