Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1324886 > unrolled thread
| Started by | Paul Burton <paul.burton@imgtec.com> |
|---|---|
| First post | 2016-02-03 04:50 +0100 |
| Last post | 2016-02-03 04:50 +0100 |
| Articles | 8 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH 0/5] Support new MIPSr6 relocations Paul Burton <paul.burton@imgtec.com> - 2016-02-03 04:50 +0100
[PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc Paul Burton <paul.burton@imgtec.com> - 2016-02-03 04:50 +0100
Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-02-03 11:30 +0100
Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc Paul Burton <paul.burton@imgtec.com> - 2016-02-03 11:40 +0100
Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-02-03 11:40 +0100
Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc Paul Burton <paul.burton@imgtec.com> - 2016-02-03 11:50 +0100
Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc James Hogan <james.hogan@imgtec.com> - 2016-02-03 13:50 +0100
[PATCH 3/5] MIPS: Add support for 64-bit R6 ELF relocations Paul Burton <paul.burton@imgtec.com> - 2016-02-03 04:50 +0100
| From | Paul Burton <paul.burton@imgtec.com> |
|---|---|
| Date | 2016-02-03 04:50 +0100 |
| Subject | [PATCH 0/5] Support new MIPSr6 relocations |
| Message-ID | <qXWC5-4X7-3@gated-at.bofh.it> |
MIPSr6 introduced a few new relocations that may be present in loadable kernel modules. This series introduces support for them in both their rel & rela forms for MIPS32 & MIPS64 kernels respectively, and ensures that any future missing relocs cause module loading to fail gracefully. Paul Burton (3): MIPS: Bail on unsupported module relocs MIPS: Support R_MIPS_PC16 rel-style reloc MIPS: Implement MIPSr6 R_MIPS_PC2x rel-style relocs Steven J. Hill (2): MIPS: module-rela: Make consistent use of pr_*() MIPS: Add support for 64-bit R6 ELF relocations arch/mips/include/asm/elf.h | 5 +++ arch/mips/kernel/module-rela.c | 96 ++++++++++++++++++++++++++++++++++++++---- arch/mips/kernel/module.c | 85 +++++++++++++++++++++++++++++++++++-- 3 files changed, 173 insertions(+), 13 deletions(-) -- 2.7.0
[toc] | [next] | [standalone]
| From | Paul Burton <paul.burton@imgtec.com> |
|---|---|
| Date | 2016-02-03 04:50 +0100 |
| Subject | [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc |
| Message-ID | <qXWC5-4X7-9@gated-at.bofh.it> |
| In reply to | #1324886 |
MIPS32 code uses rel-style relocs, and MIPS32r6 modules may include the
R_MIPS_PC16 relocation. We thus need to support R_MIPS_PC16 rel-style
relocations in order to load MIPS32r6 kernel modules. This patch adds
such support, which is similar to the rela-style R_MIPS_PC16 support but
making use of the implicit addend from the instruction encoding.
Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---
arch/mips/kernel/module.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
index 2adf572..f2de9b8 100644
--- a/arch/mips/kernel/module.c
+++ b/arch/mips/kernel/module.c
@@ -183,13 +183,25 @@ out_danger:
return -ENOEXEC;
}
+static int apply_r_mips_pc16_rel(struct module *me, u32 *location, Elf_Addr v)
+{
+ u16 val;
+
+ val = *location;
+ val += (v - (Elf_Addr)location) >> 2;
+ *location = (*location & 0xffff0000) | val;
+
+ return 0;
+}
+
static int (*reloc_handlers_rel[]) (struct module *me, u32 *location,
Elf_Addr v) = {
[R_MIPS_NONE] = apply_r_mips_none,
[R_MIPS_32] = apply_r_mips_32_rel,
[R_MIPS_26] = apply_r_mips_26_rel,
[R_MIPS_HI16] = apply_r_mips_hi16_rel,
- [R_MIPS_LO16] = apply_r_mips_lo16_rel
+ [R_MIPS_LO16] = apply_r_mips_lo16_rel,
+ [R_MIPS_PC16] = apply_r_mips_pc16_rel,
};
int apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
--
2.7.0
[toc] | [prev] | [next] | [standalone]
| From | Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> |
|---|---|
| Date | 2016-02-03 11:30 +0100 |
| Subject | Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc |
| Message-ID | <qY2Rd-H6-23@gated-at.bofh.it> |
| In reply to | #1324887 |
Hello.
On 2/3/2016 6:44 AM, Paul Burton wrote:
> MIPS32 code uses rel-style relocs, and MIPS32r6 modules may include the
> R_MIPS_PC16 relocation. We thus need to support R_MIPS_PC16 rel-style
> relocations in order to load MIPS32r6 kernel modules. This patch adds
> such support, which is similar to the rela-style R_MIPS_PC16 support but
R_MIPS_LO16, you mean?
> making use of the implicit addend from the instruction encoding.
>
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> ---
>
> arch/mips/kernel/module.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
> index 2adf572..f2de9b8 100644
> --- a/arch/mips/kernel/module.c
> +++ b/arch/mips/kernel/module.c
> @@ -183,13 +183,25 @@ out_danger:
> return -ENOEXEC;
> }
>
> +static int apply_r_mips_pc16_rel(struct module *me, u32 *location, Elf_Addr v)
> +{
> + u16 val;
> +
> + val = *location;
> + val += (v - (Elf_Addr)location) >> 2;
> + *location = (*location & 0xffff0000) | val;
> +
> + return 0;
> +}
> +
> static int (*reloc_handlers_rel[]) (struct module *me, u32 *location,
> Elf_Addr v) = {
> [R_MIPS_NONE] = apply_r_mips_none,
> [R_MIPS_32] = apply_r_mips_32_rel,
> [R_MIPS_26] = apply_r_mips_26_rel,
> [R_MIPS_HI16] = apply_r_mips_hi16_rel,
> - [R_MIPS_LO16] = apply_r_mips_lo16_rel
> + [R_MIPS_LO16] = apply_r_mips_lo16_rel,
> + [R_MIPS_PC16] = apply_r_mips_pc16_rel,
> };
>
> int apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
MBR, Sergei
[toc] | [prev] | [next] | [standalone]
| From | Paul Burton <paul.burton@imgtec.com> |
|---|---|
| Date | 2016-02-03 11:40 +0100 |
| Subject | Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc |
| Message-ID | <qY30S-K9-7@gated-at.bofh.it> |
| In reply to | #1325159 |
On Wed, Feb 03, 2016 at 01:25:57PM +0300, Sergei Shtylyov wrote:
> Hello.
>
> On 2/3/2016 6:44 AM, Paul Burton wrote:
> >MIPS32 code uses rel-style relocs, and MIPS32r6 modules may include the
> >R_MIPS_PC16 relocation. We thus need to support R_MIPS_PC16 rel-style
> >relocations in order to load MIPS32r6 kernel modules. This patch adds
> >such support, which is similar to the rela-style R_MIPS_PC16 support but
>
> R_MIPS_LO16, you mean?
Hi Sergei,
No, I mean it's similar to the R_MIPS_PC16 code in module-rela.c. That
is, its rela-style equivalent (rather than rel-style as here).
Thanks,
Paul
[toc] | [prev] | [next] | [standalone]
| From | Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> |
|---|---|
| Date | 2016-02-03 11:40 +0100 |
| Subject | Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc |
| Message-ID | <qY30S-K9-19@gated-at.bofh.it> |
| In reply to | #1325174 |
On 2/3/2016 1:32 PM, Paul Burton wrote:
>>> MIPS32 code uses rel-style relocs, and MIPS32r6 modules may include the
>>> R_MIPS_PC16 relocation. We thus need to support R_MIPS_PC16 rel-style
>>> relocations in order to load MIPS32r6 kernel modules. This patch adds
>>> such support, which is similar to the rela-style R_MIPS_PC16 support but
>>
>> R_MIPS_LO16, you mean?
>
> Hi Sergei,
>
> No, I mean it's similar to the R_MIPS_PC16 code in module-rela.c. That
> is, its rela-style equivalent (rather than rel-style as here).
But you're *adding* R_MIPS_PC16, no?
> Thanks,
> Paul
MBR, Sergei
[toc] | [prev] | [next] | [standalone]
| From | Paul Burton <paul.burton@imgtec.com> |
|---|---|
| Date | 2016-02-03 11:50 +0100 |
| Subject | Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc |
| Message-ID | <qY3ay-Nu-17@gated-at.bofh.it> |
| In reply to | #1325178 |
On Wed, Feb 03, 2016 at 01:36:00PM +0300, Sergei Shtylyov wrote:
> On 2/3/2016 1:32 PM, Paul Burton wrote:
>
> >>>MIPS32 code uses rel-style relocs, and MIPS32r6 modules may include the
> >>>R_MIPS_PC16 relocation. We thus need to support R_MIPS_PC16 rel-style
> >>>relocations in order to load MIPS32r6 kernel modules. This patch adds
> >>>such support, which is similar to the rela-style R_MIPS_PC16 support but
> >>
> >> R_MIPS_LO16, you mean?
> >
> >Hi Sergei,
> >
> >No, I mean it's similar to the R_MIPS_PC16 code in module-rela.c. That
> >is, its rela-style equivalent (rather than rel-style as here).
>
> But you're *adding* R_MIPS_PC16, no?
Yup, this patch is adding R_MIPS_PC16 to module.c & it's similar to
R_MIPS_PC16 in module-rela.c.
(Incidentally I think we could tidy up the duplication between the two
files, but that can come later...)
Thanks,
Paul
[toc] | [prev] | [next] | [standalone]
| From | James Hogan <james.hogan@imgtec.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | Re: [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc |
| Message-ID | <qY52I-212-53@gated-at.bofh.it> |
| In reply to | #1324887 |
[Multipart message — attachments visible in raw view] — view raw
On Wed, Feb 03, 2016 at 03:44:44AM +0000, Paul Burton wrote:
> MIPS32 code uses rel-style relocs, and MIPS32r6 modules may include the
> R_MIPS_PC16 relocation. We thus need to support R_MIPS_PC16 rel-style
> relocations in order to load MIPS32r6 kernel modules. This patch adds
> such support, which is similar to the rela-style R_MIPS_PC16 support but
> making use of the implicit addend from the instruction encoding.
>
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> ---
>
> arch/mips/kernel/module.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
> index 2adf572..f2de9b8 100644
> --- a/arch/mips/kernel/module.c
> +++ b/arch/mips/kernel/module.c
> @@ -183,13 +183,25 @@ out_danger:
> return -ENOEXEC;
> }
>
> +static int apply_r_mips_pc16_rel(struct module *me, u32 *location, Elf_Addr v)
> +{
> + u16 val;
> +
> + val = *location;
> + val += (v - (Elf_Addr)location) >> 2;
> + *location = (*location & 0xffff0000) | val;
Looks correct, but presumably this could benefit from some sanity
checking like the other patches.
Cheers
James
> +
> + return 0;
> +}
> +
> static int (*reloc_handlers_rel[]) (struct module *me, u32 *location,
> Elf_Addr v) = {
> [R_MIPS_NONE] = apply_r_mips_none,
> [R_MIPS_32] = apply_r_mips_32_rel,
> [R_MIPS_26] = apply_r_mips_26_rel,
> [R_MIPS_HI16] = apply_r_mips_hi16_rel,
> - [R_MIPS_LO16] = apply_r_mips_lo16_rel
> + [R_MIPS_LO16] = apply_r_mips_lo16_rel,
> + [R_MIPS_PC16] = apply_r_mips_pc16_rel,
> };
>
> int apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
> --
> 2.7.0
>
>
[toc] | [prev] | [next] | [standalone]
| From | Paul Burton <paul.burton@imgtec.com> |
|---|---|
| Date | 2016-02-03 04:50 +0100 |
| Subject | [PATCH 3/5] MIPS: Add support for 64-bit R6 ELF relocations |
| Message-ID | <qXWC6-4X7-15@gated-at.bofh.it> |
| In reply to | #1324886 |
From: "Steven J. Hill" <Steven.Hill@imgtec.com>
This patch fixes MIPS64r6 kernel modules by adding new ELF
relocations. Toolchains that compile 64-bit R6 binaries emit
two new ELF relocations R_MIPS_PC21_S2 and R_MIPS_PC26_S2.
The pre-existing R_MIPS_PC16 ELF relocation is also emitted.
Signed-off-by: Steven J. Hill <Steven.Hill@imgtec.com>
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---
arch/mips/include/asm/elf.h | 5 +++
arch/mips/kernel/module-rela.c | 69 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
index cefb7a5..7cec234 100644
--- a/arch/mips/include/asm/elf.h
+++ b/arch/mips/include/asm/elf.h
@@ -111,6 +111,11 @@
#define R_MIPS_CALLHI16 30
#define R_MIPS_CALLLO16 31
/*
+ * Introduced for MIPSr6.
+ */
+#define R_MIPS_PC21_S2 60
+#define R_MIPS_PC26_S2 61
+/*
* This range is reserved for vendor specific relocations.
*/
#define R_MIPS_LOVENDOR 100
diff --git a/arch/mips/kernel/module-rela.c b/arch/mips/kernel/module-rela.c
index f1ff64b..2dbe1b0 100644
--- a/arch/mips/kernel/module-rela.c
+++ b/arch/mips/kernel/module-rela.c
@@ -16,6 +16,7 @@
* Copyright (C) 2001 Rusty Russell.
* Copyright (C) 2003, 2004 Ralf Baechle (ralf@linux-mips.org)
* Copyright (C) 2005 Thiemo Seufer
+ * Copyright (C) 2015 Imagination Technologies Ltd.
*/
#include <linux/elf.h>
@@ -65,6 +66,27 @@ static int apply_r_mips_lo16_rela(struct module *me, u32 *location, Elf_Addr v)
return 0;
}
+static int apply_r_mips_pc16_rela(struct module *me, u32 *location, Elf_Addr v)
+{
+ long offset;
+
+ if (v % 4) {
+ pr_err("module %s: dangerous R_MIPS_PC16 RELA relocation\n",
+ me->name);
+ return -ENOEXEC;
+ }
+
+ offset = ((long)v - (long)location) >> 2;
+ if (offset != (int16_t)offset) {
+ pr_err("module %s: relocation overflow\n", me->name);
+ return -ENOEXEC;
+ }
+
+ *location = (*location & ~0xffff) | (offset & 0xffff);
+
+ return 0;
+}
+
static int apply_r_mips_64_rela(struct module *me, u32 *location, Elf_Addr v)
{
*(Elf_Addr *)location = v;
@@ -90,6 +112,48 @@ static int apply_r_mips_highest_rela(struct module *me, u32 *location,
return 0;
}
+static int apply_r_mips_pc21_rela(struct module *me, u32 *location, Elf_Addr v)
+{
+ long offset;
+
+ if (v % 4) {
+ pr_err("module %s: dangerous R_MIPS_PC21 RELA relocation\n",
+ me->name);
+ return -ENOEXEC;
+ }
+
+ offset = ((long)v - (long)location) >> 2;
+ if ((offset >> 20) > 0 || (offset >> 20) < -1) {
+ pr_err("module %s: relocation overflow\n", me->name);
+ return -ENOEXEC;
+ }
+
+ *location = (*location & ~0x001fffff) | (offset & 0x001fffff);
+
+ return 0;
+}
+
+static int apply_r_mips_pc26_rela(struct module *me, u32 *location, Elf_Addr v)
+{
+ long offset;
+
+ if (v % 4) {
+ pr_err("module %s: dangerous R_MIPS_PC26 RELA relocation\n",
+ me->name);
+ return -ENOEXEC;
+ }
+
+ offset = ((long)v - (long)location) >> 2;
+ if ((offset >> 25) > 0 || (offset >> 25) < -1) {
+ pr_err("module %s: relocation overflow\n", me->name);
+ return -ENOEXEC;
+ }
+
+ *location = (*location & ~0x03ffffff) | (offset & 0x03ffffff);
+
+ return 0;
+}
+
static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
Elf_Addr v) = {
[R_MIPS_NONE] = apply_r_mips_none,
@@ -97,9 +161,12 @@ static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
[R_MIPS_26] = apply_r_mips_26_rela,
[R_MIPS_HI16] = apply_r_mips_hi16_rela,
[R_MIPS_LO16] = apply_r_mips_lo16_rela,
+ [R_MIPS_PC16] = apply_r_mips_pc16_rela,
[R_MIPS_64] = apply_r_mips_64_rela,
[R_MIPS_HIGHER] = apply_r_mips_higher_rela,
- [R_MIPS_HIGHEST] = apply_r_mips_highest_rela
+ [R_MIPS_HIGHEST] = apply_r_mips_highest_rela,
+ [R_MIPS_PC21_S2] = apply_r_mips_pc21_rela,
+ [R_MIPS_PC26_S2] = apply_r_mips_pc26_rela,
};
int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
--
2.7.0
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web