From: Jiri Slaby <jirislaby@kernel.org>
To: Ard Biesheuvel <ardb+git@google.com>, linux-kernel@vger.kernel.org
Cc: x86@kernel.org, Ard Biesheuvel <ardb@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>, Song Liu <song@kernel.org>,
Ricardo Ribalda <ribalda@kernel.org>,
Fangrui Song <maskray@google.com>,
Arthur Eubanks <aeubanks@google.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] x86/purgatory: Switch to the position-independent small code model
Date: Fri, 19 Apr 2024 13:35:44 +0200 [thread overview]
Message-ID: <3f23b551-4815-4a06-9217-ff5beeb80df2@kernel.org> (raw)
In-Reply-To: <20240418201705.3673200-2-ardb+git@google.com>
On 18. 04. 24, 22:17, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
>
> On x86, the ordinary, position dependent 'small' and 'kernel' code models only
> support placement of the executable in 32-bit addressable memory, due to
> the use of 32-bit signed immediates to generate references to global
> variables. For the kernel, this implies that all global variables must
> reside in the top 2 GiB of the kernel virtual address space, where the
> implicit address bits 63:32 are equal to sign bit 31.
>
> This means the kernel code model is not suitable for other bare metal
> executables such as the kexec purgatory, which can be placed arbitrarily
> in the physical address space, where its address may no longer be
> representable as a sign extended 32-bit quantity. For this reason,
> commit
>
> e16c2983fba0 ("x86/purgatory: Change compiler flags from -mcmodel=kernel to -mcmodel=large to fix kexec relocation errors")
>
> switched to the 'large' code model, which uses 64-bit immediates for all
> symbol references, including function calls, in order to avoid relying
> on any assumptions regarding proximity of symbols in the final
> executable.
>
> The large code model is rarely used, clunky and the least likely to
> operate in a similar fashion when comparing GCC and Clang, so it is best
> avoided. This is especially true now that Clang 18 has started to emit
> executable code in two separate sections (.text and .ltext), which
> triggers an issue in the kexec loading code at runtime.
>
> Instead, use the position independent small code model, which makes no
> assumptions about placement but only about proximity, where all
> referenced symbols must be within -/+ 2 GiB, i.e., in range for a
> RIP-relative reference. Use hidden visibility to suppress the use of a
> GOT, which carries absolute addresses that are not covered by static ELF
> relocations, and is therefore incompatible with the kexec loader's
> relocation logic.
FWIW:
Fixes: https://bugzilla.suse.com/show_bug.cgi?id=1211853
thanks,
--
js
suse labs
next prev parent reply other threads:[~2024-04-19 11:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-18 20:17 Ard Biesheuvel
2024-04-18 20:36 ` Nick Desaulniers
2024-04-18 20:46 ` Fangrui Song
2024-04-20 15:29 ` Borislav Petkov
2024-04-20 15:51 ` Ard Biesheuvel
2024-04-18 20:37 ` Nathan Chancellor
2024-04-19 11:35 ` Jiri Slaby [this message]
2024-04-20 13:17 ` Borislav Petkov
2024-04-29 12:05 ` Michael Matz
2024-04-29 12:30 ` Borislav Petkov
2024-04-30 5:15 ` Jiri Slaby
2024-04-30 13:15 ` Michael Matz
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=3f23b551-4815-4a06-9217-ff5beeb80df2@kernel.org \
--to=jirislaby@kernel.org \
--cc=aeubanks@google.com \
--cc=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maskray@google.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=ribalda@kernel.org \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
--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
Powered by JetHome