mbox series

[0/2] riscv: improve __ex_table section handling

Message ID 20210809012509.4983c1d6@xhacker (mailing list archive)
Headers show
Series riscv: improve __ex_table section handling | expand

Message

Jisheng Zhang Aug. 8, 2021, 5:25 p.m. UTC
From: Jisheng Zhang <jszhang@kernel.org>

Enable BUILDTIME_TABLE_SORT to sort the exception table at build time
then move exception table to RO_DATA segment.

Jisheng Zhang (2):
  riscv: Enable BUILDTIME_TABLE_SORT
  riscv: Move EXCEPTION_TABLE to RO_DATA segment

 arch/riscv/Kconfig                  | 1 +
 arch/riscv/kernel/vmlinux-xip.lds.S | 1 -
 arch/riscv/kernel/vmlinux.lds.S     | 4 ++--
 scripts/sorttable.c                 | 1 +
 4 files changed, 4 insertions(+), 3 deletions(-)

Comments

Palmer Dabbelt Aug. 26, 2021, 6:47 a.m. UTC | #1
On Sun, 08 Aug 2021 10:25:09 PDT (-0700), jszhang3@mail.ustc.edu.cn wrote:
> From: Jisheng Zhang <jszhang@kernel.org>
>
> Enable BUILDTIME_TABLE_SORT to sort the exception table at build time
> then move exception table to RO_DATA segment.
>
> Jisheng Zhang (2):
>   riscv: Enable BUILDTIME_TABLE_SORT
>   riscv: Move EXCEPTION_TABLE to RO_DATA segment
>
>  arch/riscv/Kconfig                  | 1 +
>  arch/riscv/kernel/vmlinux-xip.lds.S | 1 -
>  arch/riscv/kernel/vmlinux.lds.S     | 4 ++--
>  scripts/sorttable.c                 | 1 +
>  4 files changed, 4 insertions(+), 3 deletions(-)

This seems reasonable, but it's failing for some configurations (at 
least tinyconfig) saying there is no __ex_table.  I'm not entirely sure 
how that comes about, as we've got them for futexes and uaccess.

Maybe the right thing to do here is to fix scripts/sorttable.c so it can 
handle files with nothing to sort?  I think it's just as simple as a 
successful early out like this

diff --git a/scripts/sorttable.h b/scripts/sorttable.h
index a2baa2fefb13..207ddeddb506 100644
--- a/scripts/sorttable.h
+++ b/scripts/sorttable.h
@@ -294,8 +294,9 @@ static int do_sort(Elf_Ehdr *ehdr,
                goto out;
        }
 #endif
+       /* If there is no __ex_table section there is no work do to. */
        if (!extab_sec) {
-               fprintf(stderr, "no __ex_table in file: %s\n", fname);
+               rc = 0;
                goto out;
        }

I'm not entirely sure though -- my logic is essentially just "there's no 
__ex_table, so there's nothing to sort, so just don't try".

All the configurations I can actually boot have an __ex_table, so I'm 
not sure how to test that.
Jisheng Zhang Aug. 26, 2021, 2:06 p.m. UTC | #2
On Wed, 25 Aug 2021 23:47:02 -0700 (PDT)
Palmer Dabbelt <palmer@dabbelt.com> wrote:

> On Sun, 08 Aug 2021 10:25:09 PDT (-0700), jszhang3@mail.ustc.edu.cn wrote:
> > From: Jisheng Zhang <jszhang@kernel.org>
> >
> > Enable BUILDTIME_TABLE_SORT to sort the exception table at build time
> > then move exception table to RO_DATA segment.
> >
> > Jisheng Zhang (2):
> >   riscv: Enable BUILDTIME_TABLE_SORT
> >   riscv: Move EXCEPTION_TABLE to RO_DATA segment
> >
> >  arch/riscv/Kconfig                  | 1 +
> >  arch/riscv/kernel/vmlinux-xip.lds.S | 1 -
> >  arch/riscv/kernel/vmlinux.lds.S     | 4 ++--
> >  scripts/sorttable.c                 | 1 +
> >  4 files changed, 4 insertions(+), 3 deletions(-)  
> 
> This seems reasonable, but it's failing for some configurations (at 
> least tinyconfig) saying there is no __ex_table.  I'm not entirely sure 

Nice catch! tinyconfig in riscv means NOMMU which indicates no __ex_table at all.
It seems we have to only enable BUILDTIME_TABLE_SORT for MMU case.

will send out V2 soon.

Thanks

> how that comes about, as we've got them for futexes and uaccess.
> 
> Maybe the right thing to do here is to fix scripts/sorttable.c so it can 
> handle files with nothing to sort?  I think it's just as simple as a 
> successful early out like this
> 
> diff --git a/scripts/sorttable.h b/scripts/sorttable.h
> index a2baa2fefb13..207ddeddb506 100644
> --- a/scripts/sorttable.h
> +++ b/scripts/sorttable.h
> @@ -294,8 +294,9 @@ static int do_sort(Elf_Ehdr *ehdr,
>                 goto out;
>         }
>  #endif
> +       /* If there is no __ex_table section there is no work do to. */
>         if (!extab_sec) {
> -               fprintf(stderr, "no __ex_table in file: %s\n", fname);
> +               rc = 0;
>                 goto out;
>         }
> 
> I'm not entirely sure though -- my logic is essentially just "there's no 
> __ex_table, so there's nothing to sort, so just don't try".
> 
> All the configurations I can actually boot have an __ex_table, so I'm 
> not sure how to test that.
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv