All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>, Wei Liu <wl@xen.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Ross Lagerwall <ross.lagerwall@citrix.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v2 1/5] x86/livepatch: set function alignment to ensure minimal function size
Date: Thu, 30 Nov 2023 18:37:35 +0100	[thread overview]
Message-ID: <ZWjIX0Jo5gW5SEDr@macbook> (raw)
In-Reply-To: <a65aafed-68c0-41dd-bf4d-3eeff87dd5d3@suse.com>

On Thu, Nov 30, 2023 at 05:55:07PM +0100, Jan Beulich wrote:
> On 28.11.2023 11:03, Roger Pau Monne wrote:
> > The minimal function size requirements for livepatch are either 5 bytes (for
> > jmp) or 9 bytes (for endbr + jmp).  Ensure that functions are always at least
> > that size by requesting the compiled to align the functions to 8 or 16 bytes,
> > depending on whether Xen is build with IBT support.
> 
> How is alignment going to enforce minimum function size? If a function is
> last in a section, there may not be any padding added (ahead of linking at
> least). The trailing padding also isn't part of the function.

If each function lives in it's own section (by using
-ffunction-sections), and each section is aligned, then I think we can
guarantee that there will always be enough padding space?

Even the last function/section on the .text block would still be
aligned, and as long as the function alignment <= SECTION_ALIGN
there will be enough padding left.  I should add some build time
assert that CONFIG_CC_FUNCTION_ALIGNMENT <= SECTION_ALIGN.

While the trailing padding is not part of the function itself, I don't
see issues in overwriting it with the replacement function code.

> > Note that it's possible for the compiler to end up using a higher function
> > alignment regardless of the passed value, so this change just make sure that
> > the minimum required for livepatch to work is present.
> > 
> > Since the option (-falign-functions) is supported by both minimal required
> > compiler versions of clang and gcc there's no need to add a test to check for
> > its presence.
> > 
> > The alignment is currently only implemented for livepatch on x86, I'm unsure
> > whether ARM has a mandatory function alignment high enough to cover for the
> > space required by the replacement instruction(s).
> 
> Indeed I was wondering whether this shouldn't be generalized, if indeed
> required.

Well, more than required it's nice to have in order to avoid failures.
The checks in the livepatch code will trigger if there's not enough
space to apply the replacement code.

Thanks, Roger.


  reply	other threads:[~2023-11-30 18:58 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28 10:03 [PATCH v2 0/5] xen/x86: add testing for self modifying code and livepatch Roger Pau Monne
2023-11-28 10:03 ` [PATCH v2 1/5] x86/livepatch: set function alignment to ensure minimal function size Roger Pau Monne
2023-11-30 16:55   ` Jan Beulich
2023-11-30 17:37     ` Roger Pau Monné [this message]
2023-12-01  6:53       ` Jan Beulich
2023-12-01  8:50         ` Roger Pau Monné
2023-12-01  9:41           ` Jan Beulich
2023-12-01 10:21             ` Roger Pau Monné
2023-12-01 10:59               ` Jan Beulich
2023-12-01 11:31                 ` Roger Pau Monné
2023-12-01 12:59                   ` Jan Beulich
2023-12-05 13:42   ` Andrew Cooper
2023-12-05 15:01     ` Roger Pau Monné
2023-12-05 15:14       ` Jan Beulich
2023-12-05 15:36         ` Roger Pau Monné
2023-12-05 15:45           ` Jan Beulich
2023-11-28 10:03 ` [PATCH v2 2/5] automation/alpine: add elfutils-dev Roger Pau Monne
2023-11-30  2:56   ` Stefano Stabellini
2023-11-28 10:03 ` [PATCH v2 3/5] xen/x86: introduce self modifying code test Roger Pau Monne
2023-11-30  2:58   ` Stefano Stabellini
2023-12-01 11:52     ` Roger Pau Monné
2023-11-30 17:02   ` Jan Beulich
2023-12-01 12:08     ` Roger Pau Monné
2023-12-02  2:36       ` Stefano Stabellini
2023-11-28 10:03 ` [PATCH v2 4/5] x86/livepatch: introduce a basic live patch test to gitlab CI Roger Pau Monne
2023-12-05 11:49   ` Jan Beulich
2023-12-05 13:08     ` Roger Pau Monné
2023-12-05 13:23       ` Jan Beulich
2023-11-28 10:03 ` [PATCH v2 5/5] automation: add x86-64 livepatching test Roger Pau Monne
2023-11-30  3:03   ` Stefano Stabellini
2023-12-13 10:55     ` Roger Pau Monné
2023-12-14  2:08       ` Stefano Stabellini

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=ZWjIX0Jo5gW5SEDr@macbook \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=konrad.wilk@oracle.com \
    --cc=ross.lagerwall@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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 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.