mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Nick Desaulniers <ndesaulniers@google.com>, corbet@lwn.net
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH] Documentation: x86: exception-tables: document CONFIG_BUILDTIME_TABLE_SORT
Date: Mon, 23 Mar 2020 17:41:46 -0700	[thread overview]
Message-ID: <6e26c798-1439-2bbd-6801-8fd21c4e6926@zytor.com> (raw)
In-Reply-To: <20200323232214.24939-1-ndesaulniers@google.com>

On 2020-03-23 16:22, Nick Desaulniers wrote:
> Provide more information about __ex_table sorting post link.
> 
> The exception tables and fixup tables use a commonly recurring pattern
> in the kernel of storing the address of labels as date in custom ELF
> sections, then finding these sections, iterating elements within them,
> and possibly revisiting them or modifying the data at these addresses.
> 
> Sorting readonly arrays to minimize runtime penalties is quite clever.
> 
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  Documentation/x86/exception-tables.rst | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/Documentation/x86/exception-tables.rst b/Documentation/x86/exception-tables.rst
> index ed6d4b0cf62c..15455b2f7ba8 100644
> --- a/Documentation/x86/exception-tables.rst
> +++ b/Documentation/x86/exception-tables.rst
> @@ -257,6 +257,9 @@ the fault, in our case the actual value is c0199ff5:
>  the original assembly code: > 3:      movl $-14,%eax
>  and linked in vmlinux     : > c0199ff5 <.fixup+10b5> movl   $0xfffffff2,%eax
>  
> +If the fixup was able to handle the exception, control flow may be returned
> +to the instruction after the one that triggered the fault, ie. local label 2b.
> +
>  The assembly code::
>  
>   > .section __ex_table,"a"
> @@ -344,3 +347,9 @@ pointer which points to one of:
>       it as special.
>  
>  More functions can easily be added.
> +
> +CONFIG_BUILDTIME_TABLE_SORT allows the __ex_table section to be sorted post
> +link of the kernel image, via a host utility scripts/sorttable. It will set the
> +symbol main_extable_sort_needed to 0, avoiding sorting the __ex_table section
> +at boot time. With the exception table sorted, at runtime when an exception
> +occurs we can quickly lookup the __ex_table entry via binary search.
> 

It is more than that. It not only saves the boot execution time needed
to sort the table, but it is required for early exception handling to
work -- and in the x86 code, we use the exception handling *extremely*
early (on i386 before paging is even turned on!), long before the kernel
would have had any opportunity to sort it.

So it is not just performance; it is also a correctness issue.

	-hpa


  reply	other threads:[~2020-03-24  0:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23 23:22 Nick Desaulniers
2020-03-24  0:41 ` H. Peter Anvin [this message]
2020-03-27  0:09   ` [PATCH v2] " Nick Desaulniers
2020-03-27 16:52     ` Jonathan Corbet

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=6e26c798-1439-2bbd-6801-8fd21c4e6926@zytor.com \
    --to=hpa@zytor.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=ndesaulniers@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®