public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: James Hogan <james.hogan@imgtec.com>
To: Paul Burton <paul.burton@imgtec.com>
Cc: <linux-mips@linux-mips.org>, Ralf Baechle <ralf@linux-mips.org>,
	"Andrey Konovalov" <adech.fo@gmail.com>,
	Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	<linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 5/5] MIPS: Implement MIPSr6 R_MIPS_PC2x rel-style relocs
Date: Wed, 3 Feb 2016 12:47:50 +0000	[thread overview]
Message-ID: <20160203124750.GD5464@jhogan-linux.le.imgtec.org> (raw)
In-Reply-To: <1454471085-20963-6-git-send-email-paul.burton@imgtec.com>

[-- Attachment #1: Type: text/plain, Size: 2867 bytes --]

On Wed, Feb 03, 2016 at 03:44:45AM +0000, Paul Burton wrote:
> MIPS32r6 code makes use of rel-stye relocations & may contain the new
> relocations R_MIPS_PC21_S2 or R_MIPS_PC26_S2 which were introduced with
> MIPSr6. Implement support for those relocations such that we can load
> MIPS32r6 kernel modules.
> 
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>

Looks good to me,
Reviewed-by: James Hogan <james.hogan@imgtec.com>

Cheers
James

> 
> ---
> 
>  arch/mips/kernel/module.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
> index f2de9b8..d62fd56 100644
> --- a/arch/mips/kernel/module.c
> +++ b/arch/mips/kernel/module.c
> @@ -194,6 +194,56 @@ static int apply_r_mips_pc16_rel(struct module *me, u32 *location, Elf_Addr v)
>  	return 0;
>  }
>  
> +static int apply_r_mips_pc21_rel(struct module *me, u32 *location, Elf_Addr v)
> +{
> +	long offset;
> +
> +	if (v % 4) {
> +		pr_err("module %s: dangerous R_MIPS_PC21 REL relocation\n",
> +		       me->name);
> +		return -ENOEXEC;
> +	}
> +
> +	/* retrieve & sign extend implicit addend */
> +	offset = *location & 0x1fffff;
> +	offset |= (offset & BIT(20)) ? (~0l & ~0x1fffffl) : 0;
> +
> +	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_rel(struct module *me, u32 *location, Elf_Addr v)
> +{
> +	long offset;
> +
> +	if (v % 4) {
> +		pr_err("module %s: dangerous R_MIPS_PC26 REL relocation\n",
> +		       me->name);
> +		return -ENOEXEC;
> +	}
> +
> +	/* retrieve & sign extend implicit addend */
> +	offset = *location & 0x3ffffff;
> +	offset |= (offset & BIT(25)) ? (~0l & ~0x3ffffffl) : 0;
> +
> +	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_rel[]) (struct module *me, u32 *location,
>  				Elf_Addr v) = {
>  	[R_MIPS_NONE]		= apply_r_mips_none,
> @@ -202,6 +252,8 @@ static int (*reloc_handlers_rel[]) (struct module *me, u32 *location,
>  	[R_MIPS_HI16]		= apply_r_mips_hi16_rel,
>  	[R_MIPS_LO16]		= apply_r_mips_lo16_rel,
>  	[R_MIPS_PC16]		= apply_r_mips_pc16_rel,
> +	[R_MIPS_PC21_S2]	= apply_r_mips_pc21_rel,
> +	[R_MIPS_PC26_S2]	= apply_r_mips_pc26_rel,
>  };
>  
>  int apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
> -- 
> 2.7.0
> 
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

      reply	other threads:[~2016-02-03 12:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03  3:44 [PATCH 0/5] Support new MIPSr6 relocations Paul Burton
2016-02-03  3:44 ` [PATCH 1/5] MIPS: Bail on unsupported module relocs Paul Burton
2016-02-03 12:23   ` James Hogan
2016-02-03 12:24   ` Maciej W. Rozycki
2016-02-03 16:15     ` Paul Burton
2016-02-03 16:55       ` Maciej W. Rozycki
2016-02-03  3:44 ` [PATCH 2/5] MIPS: module-rela: Make consistent use of pr_*() Paul Burton
2016-02-03  3:44 ` [PATCH 3/5] MIPS: Add support for 64-bit R6 ELF relocations Paul Burton
2016-02-03  3:44 ` [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc Paul Burton
2016-02-03 10:25   ` Sergei Shtylyov
2016-02-03 10:32     ` Paul Burton
2016-02-03 10:36       ` Sergei Shtylyov
2016-02-03 10:48         ` Paul Burton
2016-02-03 12:49   ` James Hogan
2016-02-03  3:44 ` [PATCH 5/5] MIPS: Implement MIPSr6 R_MIPS_PC2x rel-style relocs Paul Burton
2016-02-03 12:47   ` James Hogan [this message]

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=20160203124750.GD5464@jhogan-linux.le.imgtec.org \
    --to=james.hogan@imgtec.com \
    --cc=adech.fo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=paul.burton@imgtec.com \
    --cc=ralf@linux-mips.org \
    --cc=ryabinin.a.a@gmail.com \
    /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