All of lore.kernel.org
 help / color / mirror / Atom feed
* [question] insert ko failed because count_plts return 0 when CONFIG_RANDOMIZE_BASE is not set
@ 2021-03-24  7:27 ` chenjun (AM)
  0 siblings, 0 replies; 8+ messages in thread
From: chenjun (AM) @ 2021-03-24  7:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Ard Biesheuvel, Will Deacon
  Cc: Catalin Marinas, Xiangrui (Euler), liuyanshi, wuzengkun

Hi

I make a Image for arm64 (without CONFIG_RANDOMIZE_BASE). And a ko (13M) 
can not be inserted.

WARNING: CPU: 2 PID: 1998 at arch/arm64/kernel/module-plts.c:39
module_emit_plt_entry+0x100/0x118
..
Call trace:
module_emit_plt_entry+0x100/0x118
apply_relocate_add+0x34c/0x570
..

I think the problem is that:
in apply_relocate_add:
                  case R_AARCH64_CALL26:
                      ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 2, 26,
                                               AARCH64_INSN_IMM_26);

                      if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
                          ovf == -ERANGE) {
                              val = module_emit_plt_entry(me, sechdrs, 
loc, &rel[i], sym); realoc_insn_imm return -ERANGE (because the ko is 
too big?)

in module_emit_plt_entry:
WARN_ON(pltsec->plt_num_entries > pltsec->plt_max_entries)
pltsec->plt_max_entries is 0 if CONFIG_RANDOMIZE_BASE is not be set.

a257e02 arm64/kernel: don't ban ADRP to work around Cortex-A53 erratum
#843419
   static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int 
num,
-                              Elf64_Word dstidx)
+                              Elf64_Word dstidx, Elf_Shdr *dstsec)
   {
..
                  switch (ELF64_R_TYPE(rela[i].r_info)) {
                  case R_AARCH64_JUMP26:
                  case R_AARCH64_CALL26:
+                       if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE))
+                               break;
+

Why we need break if !IS_ENABLED(CONFIG_RANDOMIZE_BASE)? or any 
restrictions on ko?

I comment out this part of the code. the ko could be inserted, and seems 
to work well. So is it a accepted way? or any solution for my case?

--
Regards
Chen Jun


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [question] insert ko failed because count_plts return 0 when CONFIG_RANDOMIZE_BASE is not set
@ 2021-03-24  7:27 ` chenjun (AM)
  0 siblings, 0 replies; 8+ messages in thread
From: chenjun (AM) @ 2021-03-24  7:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Ard Biesheuvel, Will Deacon
  Cc: Catalin Marinas, Xiangrui (Euler), liuyanshi, wuzengkun

Hi

I make a Image for arm64 (without CONFIG_RANDOMIZE_BASE). And a ko (13M) 
can not be inserted.

WARNING: CPU: 2 PID: 1998 at arch/arm64/kernel/module-plts.c:39
module_emit_plt_entry+0x100/0x118
...
Call trace:
module_emit_plt_entry+0x100/0x118
apply_relocate_add+0x34c/0x570
...

I think the problem is that:
in apply_relocate_add:
                  case R_AARCH64_CALL26:
                      ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 2, 26,
                                               AARCH64_INSN_IMM_26);

                      if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
                          ovf == -ERANGE) {
                              val = module_emit_plt_entry(me, sechdrs, 
loc, &rel[i], sym); realoc_insn_imm return -ERANGE (because the ko is 
too big?)

in module_emit_plt_entry:
WARN_ON(pltsec->plt_num_entries > pltsec->plt_max_entries)
pltsec->plt_max_entries is 0 if CONFIG_RANDOMIZE_BASE is not be set.

a257e02 arm64/kernel: don't ban ADRP to work around Cortex-A53 erratum
#843419
   static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int 
num,
-                              Elf64_Word dstidx)
+                              Elf64_Word dstidx, Elf_Shdr *dstsec)
   {
...
                  switch (ELF64_R_TYPE(rela[i].r_info)) {
                  case R_AARCH64_JUMP26:
                  case R_AARCH64_CALL26:
+                       if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE))
+                               break;
+

Why we need break if !IS_ENABLED(CONFIG_RANDOMIZE_BASE)? or any 
restrictions on ko?

I comment out this part of the code. the ko could be inserted, and seems 
to work well. So is it a accepted way? or any solution for my case?

--
Regards
Chen Jun


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [question] insert ko failed because count_plts return 0 when CONFIG_RANDOMIZE_BASE is not set
  2021-03-24  7:27 ` chenjun (AM)
@ 2021-03-24  8:29   ` Ard Biesheuvel
  -1 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2021-03-24  8:29 UTC (permalink / raw)
  To: chenjun (AM)
  Cc: linux-kernel, linux-arm-kernel, Will Deacon, Catalin Marinas,
	Xiangrui (Euler),
	liuyanshi, wuzengkun

On Wed, 24 Mar 2021 at 08:27, chenjun (AM) <chenjun102@huawei.com> wrote:
>
> Hi
>
> I make a Image for arm64 (without CONFIG_RANDOMIZE_BASE). And a ko (13M)
> can not be inserted.
>

How many large modules have you loaded already? The module region is
only 128 MB, so if your modules are huge, you may run out of space.

Please check the kernel VA address and the load address of the module,
and check whether they are more than 128 MB apart.


> WARNING: CPU: 2 PID: 1998 at arch/arm64/kernel/module-plts.c:39
> module_emit_plt_entry+0x100/0x118
> ...
> Call trace:
> module_emit_plt_entry+0x100/0x118
> apply_relocate_add+0x34c/0x570
> ...
>
> I think the problem is that:
> in apply_relocate_add:
>                   case R_AARCH64_CALL26:
>                       ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 2, 26,
>                                                AARCH64_INSN_IMM_26);
>
>                       if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
>                           ovf == -ERANGE) {
>                               val = module_emit_plt_entry(me, sechdrs,
> loc, &rel[i], sym); realoc_insn_imm return -ERANGE (because the ko is
> too big?)
>
> in module_emit_plt_entry:
> WARN_ON(pltsec->plt_num_entries > pltsec->plt_max_entries)
> pltsec->plt_max_entries is 0 if CONFIG_RANDOMIZE_BASE is not be set.
>
> a257e02 arm64/kernel: don't ban ADRP to work around Cortex-A53 erratum
> #843419
>    static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int
> num,
> -                              Elf64_Word dstidx)
> +                              Elf64_Word dstidx, Elf_Shdr *dstsec)
>    {
> ...
>                   switch (ELF64_R_TYPE(rela[i].r_info)) {
>                   case R_AARCH64_JUMP26:
>                   case R_AARCH64_CALL26:
> +                       if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE))
> +                               break;
> +
>
> Why we need break if !IS_ENABLED(CONFIG_RANDOMIZE_BASE)? or any
> restrictions on ko?
>
> I comment out this part of the code. the ko could be inserted, and seems
> to work well. So is it a accepted way? or any solution for my case?
>
> --
> Regards
> Chen Jun
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [question] insert ko failed because count_plts return 0 when CONFIG_RANDOMIZE_BASE is not set
@ 2021-03-24  8:29   ` Ard Biesheuvel
  0 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2021-03-24  8:29 UTC (permalink / raw)
  To: chenjun (AM)
  Cc: linux-kernel, linux-arm-kernel, Will Deacon, Catalin Marinas,
	Xiangrui (Euler),
	liuyanshi, wuzengkun

On Wed, 24 Mar 2021 at 08:27, chenjun (AM) <chenjun102@huawei.com> wrote:
>
> Hi
>
> I make a Image for arm64 (without CONFIG_RANDOMIZE_BASE). And a ko (13M)
> can not be inserted.
>

How many large modules have you loaded already? The module region is
only 128 MB, so if your modules are huge, you may run out of space.

Please check the kernel VA address and the load address of the module,
and check whether they are more than 128 MB apart.


> WARNING: CPU: 2 PID: 1998 at arch/arm64/kernel/module-plts.c:39
> module_emit_plt_entry+0x100/0x118
> ...
> Call trace:
> module_emit_plt_entry+0x100/0x118
> apply_relocate_add+0x34c/0x570
> ...
>
> I think the problem is that:
> in apply_relocate_add:
>                   case R_AARCH64_CALL26:
>                       ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 2, 26,
>                                                AARCH64_INSN_IMM_26);
>
>                       if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
>                           ovf == -ERANGE) {
>                               val = module_emit_plt_entry(me, sechdrs,
> loc, &rel[i], sym); realoc_insn_imm return -ERANGE (because the ko is
> too big?)
>
> in module_emit_plt_entry:
> WARN_ON(pltsec->plt_num_entries > pltsec->plt_max_entries)
> pltsec->plt_max_entries is 0 if CONFIG_RANDOMIZE_BASE is not be set.
>
> a257e02 arm64/kernel: don't ban ADRP to work around Cortex-A53 erratum
> #843419
>    static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int
> num,
> -                              Elf64_Word dstidx)
> +                              Elf64_Word dstidx, Elf_Shdr *dstsec)
>    {
> ...
>                   switch (ELF64_R_TYPE(rela[i].r_info)) {
>                   case R_AARCH64_JUMP26:
>                   case R_AARCH64_CALL26:
> +                       if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE))
> +                               break;
> +
>
> Why we need break if !IS_ENABLED(CONFIG_RANDOMIZE_BASE)? or any
> restrictions on ko?
>
> I comment out this part of the code. the ko could be inserted, and seems
> to work well. So is it a accepted way? or any solution for my case?
>
> --
> Regards
> Chen Jun
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [question] insert ko failed because count_plts return 0 when CONFIG_RANDOMIZE_BASE is not set
  2021-03-24  8:29   ` Ard Biesheuvel
@ 2021-03-25  6:21     ` chenjun (AM)
  -1 siblings, 0 replies; 8+ messages in thread
From: chenjun (AM) @ 2021-03-25  6:21 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arm-kernel, Will Deacon, Catalin Marinas,
	Xiangrui (Euler),
	liuyanshi, wuzengkun

在 2021/3/24 16:29, Ard Biesheuvel 写道:
> On Wed, 24 Mar 2021 at 08:27, chenjun (AM) <chenjun102@huawei.com> wrote:
>>
>> Hi
>>
>> I make a Image for arm64 (without CONFIG_RANDOMIZE_BASE). And a ko (13M)
>> can not be inserted.
>>
> 
> How many large modules have you loaded already? The module region is
> only 128 MB, so if your modules are huge, you may run out of space.
> 
> Please check the kernel VA address and the load address of the module,
> and check whether they are more than 128 MB apart.
>

Thanks Ard

I will check it.

One more question, why is CONFIG_ARM64_MODULE_PLTS depended on 
CONFIG_RANDOMIZE_BASE?

> 
>> WARNING: CPU: 2 PID: 1998 at arch/arm64/kernel/module-plts.c:39
>> module_emit_plt_entry+0x100/0x118
>> ...
>> Call trace:
>> module_emit_plt_entry+0x100/0x118
>> apply_relocate_add+0x34c/0x570
>> ...
>>
>> I think the problem is that:
>> in apply_relocate_add:
>>                    case R_AARCH64_CALL26:
>>                        ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 2, 26,
>>                                                 AARCH64_INSN_IMM_26);
>>
>>                        if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
>>                            ovf == -ERANGE) {
>>                                val = module_emit_plt_entry(me, sechdrs,
>> loc, &rel[i], sym); realoc_insn_imm return -ERANGE (because the ko is
>> too big?)
>>
>> in module_emit_plt_entry:
>> WARN_ON(pltsec->plt_num_entries > pltsec->plt_max_entries)
>> pltsec->plt_max_entries is 0 if CONFIG_RANDOMIZE_BASE is not be set.
>>
>> a257e02 arm64/kernel: don't ban ADRP to work around Cortex-A53 erratum
>> #843419
>>     static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int
>> num,
>> -                              Elf64_Word dstidx)
>> +                              Elf64_Word dstidx, Elf_Shdr *dstsec)
>>     {
>> ...
>>                    switch (ELF64_R_TYPE(rela[i].r_info)) {
>>                    case R_AARCH64_JUMP26:
>>                    case R_AARCH64_CALL26:
>> +                       if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE))
>> +                               break;
>> +
>>
>> Why we need break if !IS_ENABLED(CONFIG_RANDOMIZE_BASE)? or any
>> restrictions on ko?
>>
>> I comment out this part of the code. the ko could be inserted, and seems
>> to work well. So is it a accepted way? or any solution for my case?
>>
>> --
>> Regards
>> Chen Jun
>>
> 


-- 
Regards
Chen Jun

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [question] insert ko failed because count_plts return 0 when CONFIG_RANDOMIZE_BASE is not set
@ 2021-03-25  6:21     ` chenjun (AM)
  0 siblings, 0 replies; 8+ messages in thread
From: chenjun (AM) @ 2021-03-25  6:21 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arm-kernel, Will Deacon, Catalin Marinas,
	Xiangrui (Euler),
	liuyanshi, wuzengkun

在 2021/3/24 16:29, Ard Biesheuvel 写道:
> On Wed, 24 Mar 2021 at 08:27, chenjun (AM) <chenjun102@huawei.com> wrote:
>>
>> Hi
>>
>> I make a Image for arm64 (without CONFIG_RANDOMIZE_BASE). And a ko (13M)
>> can not be inserted.
>>
> 
> How many large modules have you loaded already? The module region is
> only 128 MB, so if your modules are huge, you may run out of space.
> 
> Please check the kernel VA address and the load address of the module,
> and check whether they are more than 128 MB apart.
>

Thanks Ard

I will check it.

One more question, why is CONFIG_ARM64_MODULE_PLTS depended on 
CONFIG_RANDOMIZE_BASE?

> 
>> WARNING: CPU: 2 PID: 1998 at arch/arm64/kernel/module-plts.c:39
>> module_emit_plt_entry+0x100/0x118
>> ...
>> Call trace:
>> module_emit_plt_entry+0x100/0x118
>> apply_relocate_add+0x34c/0x570
>> ...
>>
>> I think the problem is that:
>> in apply_relocate_add:
>>                    case R_AARCH64_CALL26:
>>                        ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 2, 26,
>>                                                 AARCH64_INSN_IMM_26);
>>
>>                        if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
>>                            ovf == -ERANGE) {
>>                                val = module_emit_plt_entry(me, sechdrs,
>> loc, &rel[i], sym); realoc_insn_imm return -ERANGE (because the ko is
>> too big?)
>>
>> in module_emit_plt_entry:
>> WARN_ON(pltsec->plt_num_entries > pltsec->plt_max_entries)
>> pltsec->plt_max_entries is 0 if CONFIG_RANDOMIZE_BASE is not be set.
>>
>> a257e02 arm64/kernel: don't ban ADRP to work around Cortex-A53 erratum
>> #843419
>>     static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int
>> num,
>> -                              Elf64_Word dstidx)
>> +                              Elf64_Word dstidx, Elf_Shdr *dstsec)
>>     {
>> ...
>>                    switch (ELF64_R_TYPE(rela[i].r_info)) {
>>                    case R_AARCH64_JUMP26:
>>                    case R_AARCH64_CALL26:
>> +                       if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE))
>> +                               break;
>> +
>>
>> Why we need break if !IS_ENABLED(CONFIG_RANDOMIZE_BASE)? or any
>> restrictions on ko?
>>
>> I comment out this part of the code. the ko could be inserted, and seems
>> to work well. So is it a accepted way? or any solution for my case?
>>
>> --
>> Regards
>> Chen Jun
>>
> 


-- 
Regards
Chen Jun

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [question] insert ko failed because count_plts return 0 when CONFIG_RANDOMIZE_BASE is not set
  2021-03-25  6:21     ` chenjun (AM)
@ 2021-03-25  7:35       ` Ard Biesheuvel
  -1 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2021-03-25  7:35 UTC (permalink / raw)
  To: chenjun (AM)
  Cc: linux-kernel, linux-arm-kernel, Will Deacon, Catalin Marinas,
	Xiangrui (Euler),
	liuyanshi, wuzengkun

On Thu, 25 Mar 2021 at 07:22, chenjun (AM) <chenjun102@huawei.com> wrote:
>
> 在 2021/3/24 16:29, Ard Biesheuvel 写道:
> > On Wed, 24 Mar 2021 at 08:27, chenjun (AM) <chenjun102@huawei.com> wrote:
> >>
> >> Hi
> >>
> >> I make a Image for arm64 (without CONFIG_RANDOMIZE_BASE). And a ko (13M)
> >> can not be inserted.
> >>
> >
> > How many large modules have you loaded already? The module region is
> > only 128 MB, so if your modules are huge, you may run out of space.
> >
> > Please check the kernel VA address and the load address of the module,
> > and check whether they are more than 128 MB apart.
> >
>
> Thanks Ard
>
> I will check it.
>
> One more question, why is CONFIG_ARM64_MODULE_PLTS depended on
> CONFIG_RANDOMIZE_BASE?
>

Because modules should never go out of branching range if the
placement is not randomized and the total size of all modules does not
exceed 128 MB.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [question] insert ko failed because count_plts return 0 when CONFIG_RANDOMIZE_BASE is not set
@ 2021-03-25  7:35       ` Ard Biesheuvel
  0 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2021-03-25  7:35 UTC (permalink / raw)
  To: chenjun (AM)
  Cc: linux-kernel, linux-arm-kernel, Will Deacon, Catalin Marinas,
	Xiangrui (Euler),
	liuyanshi, wuzengkun

On Thu, 25 Mar 2021 at 07:22, chenjun (AM) <chenjun102@huawei.com> wrote:
>
> 在 2021/3/24 16:29, Ard Biesheuvel 写道:
> > On Wed, 24 Mar 2021 at 08:27, chenjun (AM) <chenjun102@huawei.com> wrote:
> >>
> >> Hi
> >>
> >> I make a Image for arm64 (without CONFIG_RANDOMIZE_BASE). And a ko (13M)
> >> can not be inserted.
> >>
> >
> > How many large modules have you loaded already? The module region is
> > only 128 MB, so if your modules are huge, you may run out of space.
> >
> > Please check the kernel VA address and the load address of the module,
> > and check whether they are more than 128 MB apart.
> >
>
> Thanks Ard
>
> I will check it.
>
> One more question, why is CONFIG_ARM64_MODULE_PLTS depended on
> CONFIG_RANDOMIZE_BASE?
>

Because modules should never go out of branching range if the
placement is not randomized and the total size of all modules does not
exceed 128 MB.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-25  7:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24  7:27 [question] insert ko failed because count_plts return 0 when CONFIG_RANDOMIZE_BASE is not set chenjun (AM)
2021-03-24  7:27 ` chenjun (AM)
2021-03-24  8:29 ` Ard Biesheuvel
2021-03-24  8:29   ` Ard Biesheuvel
2021-03-25  6:21   ` chenjun (AM)
2021-03-25  6:21     ` chenjun (AM)
2021-03-25  7:35     ` Ard Biesheuvel
2021-03-25  7:35       ` Ard Biesheuvel

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.